diff options
author | Niels Möller <nisse@lysator.liu.se> | 2010-03-24 15:41:41 +0100 |
---|---|---|
committer | Niels Möller <nisse@lysator.liu.se> | 2010-03-24 15:41:41 +0100 |
commit | c72c16b7e66b88ac37081caa53f30fe51fcad0a0 (patch) | |
tree | f3df0bc2de339debaaa9e0fa1149551aad52c34c /pkcs1-rsa-sha256.c | |
parent | 153141e709a3a1548215fb63a1b840fc27d6e90e (diff) | |
download | nettle-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-sha256.c')
-rw-r--r-- | pkcs1-rsa-sha256.c | 48 |
1 files changed, 28 insertions, 20 deletions
diff --git a/pkcs1-rsa-sha256.c b/pkcs1-rsa-sha256.c index 82c169a5..363f7847 100644 --- a/pkcs1-rsa-sha256.c +++ b/pkcs1-rsa-sha256.c @@ -59,32 +59,40 @@ sha256_prefix[] = /* Here comes the raw hash value */ }; -void -pkcs1_rsa_sha256_encode(mpz_t m, unsigned length, struct sha256_ctx *hash) +int +pkcs1_rsa_sha256_encode(mpz_t m, unsigned size, struct sha256_ctx *hash) { TMP_DECL(em, uint8_t, NETTLE_MAX_BIGNUM_BITS / 8); - TMP_ALLOC(em, length); + TMP_ALLOC(em, size); - assert(length >= SHA256_DIGEST_SIZE); - pkcs1_signature_prefix(length - SHA256_DIGEST_SIZE, em, - sizeof(sha256_prefix), - sha256_prefix); - - sha256_digest(hash, SHA256_DIGEST_SIZE, em + length - SHA256_DIGEST_SIZE); - nettle_mpz_set_str_256_u(m, length, em); + if (pkcs1_signature_prefix(size, em, + sizeof(sha256_prefix), + sha256_prefix, + SHA256_DIGEST_SIZE)) + { + sha256_digest(hash, SHA256_DIGEST_SIZE, em + size - SHA256_DIGEST_SIZE); + nettle_mpz_set_str_256_u(m, size, em); + return 1; + } + else + return 0; } -void -pkcs1_rsa_sha256_encode_digest(mpz_t m, unsigned length, const uint8_t *digest) +int +pkcs1_rsa_sha256_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 >= SHA256_DIGEST_SIZE); - pkcs1_signature_prefix(length - SHA256_DIGEST_SIZE, em, - sizeof(sha256_prefix), - sha256_prefix); - - memcpy(em + length - SHA256_DIGEST_SIZE, digest, SHA256_DIGEST_SIZE); - nettle_mpz_set_str_256_u(m, length, em); + if (pkcs1_signature_prefix(size, em, + sizeof(sha256_prefix), + sha256_prefix, + SHA256_DIGEST_SIZE)) + { + memcpy(em + size - SHA256_DIGEST_SIZE, digest, SHA256_DIGEST_SIZE); + nettle_mpz_set_str_256_u(m, size, em); + return 1; + } + else + return 0; } |