]> the.earth.li Git - onak.git/blobdiff - sigcheck.c
0.6.3 release
[onak.git] / sigcheck.c
index 74c2e2bf295cd24ceca0b98ba7c6f54a2c28d0cc..c1a7ce541f3931aaa40640919dec99b810b8f794 100644 (file)
@@ -278,7 +278,7 @@ static onak_status_t onak_parse_key_material(struct openpgp_packet *pk,
        return ret;
 }
 
-onak_status_t onak_check_hash_sig(struct openpgp_publickey *sigkey,
+onak_status_t onak_check_hash_sig(struct openpgp_packet *sigkey,
                struct openpgp_packet *sig,
                uint8_t *hash,
                uint8_t hashtype)
@@ -289,9 +289,10 @@ onak_status_t onak_check_hash_sig(struct openpgp_publickey *sigkey,
        uint8_t sigkeytype;
        uint8_t edsig[64];
        int len, ofs;
+       size_t count;
        mpz_t s;
 
-       ret = onak_parse_key_material(sigkey->publickey, &pubkey);
+       ret = onak_parse_key_material(sigkey, &pubkey);
        if (ret != ONAK_E_OK) {
                return ret;
        }
@@ -361,8 +362,22 @@ onak_status_t onak_check_hash_sig(struct openpgp_publickey *sigkey,
                MPI_TO_MPZ(sig, dsasig.r);
                if (ret == ONAK_E_OK)
                        MPI_TO_MPZ(sig, dsasig.s);
-               mpz_export(edsig, NULL, 1, 1, 0, 0, dsasig.r);
-               mpz_export(&edsig[32], NULL, 1, 1, 0, 0, dsasig.s);
+               mpz_export(edsig, &count, 1, 1, 0, 0, dsasig.r);
+               if (count < 32) {
+                       memmove(&edsig[32 - count], edsig, count);
+                       while (count < 32) {
+                               count++;
+                               edsig[32 - count] = 0;
+                       }
+               }
+               mpz_export(&edsig[32], &count, 1, 1, 0, 0, dsasig.s);
+               if (count < 32) {
+                       memmove(&edsig[32 - count], edsig, count);
+                       while (count < 32) {
+                               count++;
+                               edsig[32 - count] = 0;
+                       }
+               }
                break;
        case OPENPGP_PKALGO_RSA:
        case OPENPGP_PKALGO_RSA_SIGN: