Simon Josefsson wrote:
> I'm not sure what you are referring to here. What I think the code
> is assuming is that we know exactly how the DSA S-exp outputs looks
> like,
The assumption is about how the r and s integer data is stored in the
sexp (leading 0 byte) and I think it'd be better to only use the MPI
API to fetch them.
Simon Josefsson wrote:
> So rather than having me revert the patch I pushed and cause more
> confusion, let's see if you can test the new patch (post it to the
> list?) and let you/Peter push that.
*nods* Yes, no need to revert. The suggested patch is attached,
although it may apply only without Kamil's patch attached.
//Peter
diff --git a/src/libgcrypt.c b/src/libgcrypt.c
index b06be42..819df81 100644
--- a/src/libgcrypt.c
+++ b/src/libgcrypt.c
@@ -401,6 +401,7 @@ _libssh2_dsa_sha1_sign(libssh2_dsa_ctx * dsactx,
unsigned char zhash[SHA_DIGEST_LENGTH + 1];
gcry_sexp_t sig_sexp;
gcry_sexp_t data;
+ gcry_mpi_t tmpi;
int ret;
const char *tmp;
size_t size;
@@ -425,40 +426,45 @@ _libssh2_dsa_sha1_sign(libssh2_dsa_ctx * dsactx,
}
memset(sig, 0, 40);
+ ret = -1;
/* Extract R. */
data = gcry_sexp_find_token(sig_sexp, "r", 0);
- if (!data) {
- ret = -1;
+ if (!data)
goto out;
- }
- tmp = gcry_sexp_nth_data(data, 1, &size);
- if (!tmp || size < 1 || size > 20) {
- ret = -1;
+ tmpi = gcry_sexp_nth_mpi(data, 1, GCRYMPI_FMT_USG);
+ if (!tmpi)
goto out;
- }
- memcpy(sig + (20 - size), tmp, size);
+ gcry_mpi_print(GCRYMPI_FMT_STD, sig, 20, &size, tmpi);
+ if (size < 1)
+ goto out;
+ else if (size < 20) {
+ memmove(sig + (20 - size), sig, size);
+ memset(sig, 0, (20 - size));
+ }
gcry_sexp_release(data);
/* Extract S. */
data = gcry_sexp_find_token(sig_sexp, "s", 0);
- if (!data) {
- ret = -1;
+ if (!data)
goto out;
- }
- tmp = gcry_sexp_nth_data(data, 1, &size);
- if (!tmp || size < 1 || size > 20) {
- ret = -1;
+ tmpi = gcry_sexp_nth_mpi(data, 1, GCRYMPI_FMT_USG);
+ if (!tmpi)
goto out;
- }
- memcpy(sig + 20 + (20 - size), tmp, size);
+ gcry_mpi_print(GCRYMPI_FMT_STD, sig + 20, 20, &size, tmpi);
+ if (size < 1)
+ goto out;
+ else if (size < 20) {
+ memmove(sig + 20 + (20 - size), sig + 20, size);
+ memset(sig + 20, 0, (20 - size));
+ }
ret = 0;
out:
_______________________________________________
libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel