summaryrefslogtreecommitdiff
path: root/pkcs1-rsa-md5.c
diff options
context:
space:
mode:
authorNiels Möller <nisse@lysator.liu.se>2010-03-24 15:41:41 +0100
committerNiels Möller <nisse@lysator.liu.se>2010-03-24 15:41:41 +0100
commitc72c16b7e66b88ac37081caa53f30fe51fcad0a0 (patch)
treef3df0bc2de339debaaa9e0fa1149551aad52c34c /pkcs1-rsa-md5.c
parent153141e709a3a1548215fb63a1b840fc27d6e90e (diff)
downloadnettle-c72c16b7e66b88ac37081caa53f30fe51fcad0a0.tar.gz
Interface change, let all rsa signature functions have a return value.
Rev: nettle/ChangeLog:1.54 Rev: nettle/NEWS:1.4 Rev: nettle/examples/rsa-sign.c:1.2 Rev: nettle/pgp-encode.c:1.3 Rev: nettle/pkcs1-rsa-md5.c:1.3 Rev: nettle/pkcs1-rsa-sha1.c:1.3 Rev: nettle/pkcs1-rsa-sha256.c:1.3 Rev: nettle/pkcs1-rsa-sha512.c:1.2 Rev: nettle/pkcs1.c:1.3 Rev: nettle/pkcs1.h:1.3 Rev: nettle/rsa-compat.c:1.3 Rev: nettle/rsa-md5-sign.c:1.3 Rev: nettle/rsa-md5-verify.c:1.3 Rev: nettle/rsa-sha1-sign.c:1.3 Rev: nettle/rsa-sha1-verify.c:1.3 Rev: nettle/rsa-sha256-sign.c:1.3 Rev: nettle/rsa-sha256-verify.c:1.3 Rev: nettle/rsa-sha512-sign.c:1.2 Rev: nettle/rsa-sha512-verify.c:1.2 Rev: nettle/rsa.h:1.4 Rev: nettle/testsuite/cxx-test.cxx:1.3 Rev: nettle/testsuite/pkcs1-test.c:1.3 Rev: nettle/testsuite/testutils.c:1.5
Diffstat (limited to 'pkcs1-rsa-md5.c')
-rw-r--r--pkcs1-rsa-md5.c48
1 files changed, 28 insertions, 20 deletions
diff --git a/pkcs1-rsa-md5.c b/pkcs1-rsa-md5.c
index 1b9af157..eff25fa4 100644
--- a/pkcs1-rsa-md5.c
+++ b/pkcs1-rsa-md5.c
@@ -61,32 +61,40 @@ md5_prefix[] =
/* Here comes the raw hash value */
};
-void
-pkcs1_rsa_md5_encode(mpz_t m, unsigned length, struct md5_ctx *hash)
+int
+pkcs1_rsa_md5_encode(mpz_t m, unsigned size, struct md5_ctx *hash)
{
TMP_DECL(em, uint8_t, NETTLE_MAX_BIGNUM_BITS / 8);
- TMP_ALLOC(em, length);
+ TMP_ALLOC(em, size);
- assert(length >= MD5_DIGEST_SIZE);
- pkcs1_signature_prefix(length - MD5_DIGEST_SIZE, em,
- sizeof(md5_prefix),
- md5_prefix);
-
- md5_digest(hash, MD5_DIGEST_SIZE, em + length - MD5_DIGEST_SIZE);
- nettle_mpz_set_str_256_u(m, length, em);
+ if (pkcs1_signature_prefix(size, em,
+ sizeof(md5_prefix),
+ md5_prefix,
+ MD5_DIGEST_SIZE))
+ {
+ md5_digest(hash, MD5_DIGEST_SIZE, em + size - MD5_DIGEST_SIZE);
+ nettle_mpz_set_str_256_u(m, size, em);
+ return 1;
+ }
+ else
+ return 0;
}
-void
-pkcs1_rsa_md5_encode_digest(mpz_t m, unsigned length, const uint8_t *digest)
+int
+pkcs1_rsa_md5_encode_digest(mpz_t m, unsigned size, const uint8_t *digest)
{
TMP_DECL(em, uint8_t, NETTLE_MAX_BIGNUM_BITS / 8);
- TMP_ALLOC(em, length);
+ TMP_ALLOC(em, size);
- assert(length >= MD5_DIGEST_SIZE);
- pkcs1_signature_prefix(length - MD5_DIGEST_SIZE, em,
- sizeof(md5_prefix),
- md5_prefix);
-
- memcpy(em + length - MD5_DIGEST_SIZE, digest, MD5_DIGEST_SIZE);
- nettle_mpz_set_str_256_u(m, length, em);
+ if (pkcs1_signature_prefix(size, em,
+ sizeof(md5_prefix),
+ md5_prefix,
+ MD5_DIGEST_SIZE))
+ {
+ memcpy(em + size - MD5_DIGEST_SIZE, digest, MD5_DIGEST_SIZE);
+ nettle_mpz_set_str_256_u(m, size, em);
+ return 1;
+ }
+ else
+ return 0;
}