From a78265874b34c2885ceb32e839698b2a892b274e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20M=C3=B6ller?= Date: Fri, 26 Apr 2013 14:39:27 +0200 Subject: [PATCH] Use size_t for bignums, rsa and dsa. --- bignum.c | 28 ++++++++++++++-------------- bignum.h | 14 +++++++------- dsa-sign.c | 2 +- dsa-verify.c | 2 +- dsa.h | 8 ++++---- examples/rsa-decrypt.c | 2 +- pkcs1-decrypt.c | 8 ++++---- pkcs1-encrypt.c | 8 ++++---- pkcs1-rsa-digest.c | 4 ++-- pkcs1-rsa-md5.c | 4 ++-- pkcs1-rsa-sha1.c | 4 ++-- pkcs1-rsa-sha256.c | 4 ++-- pkcs1-rsa-sha512.c | 4 ++-- pkcs1.h | 28 ++++++++++++++-------------- rsa-decrypt-tr.c | 2 +- rsa-decrypt.c | 2 +- rsa-encrypt.c | 2 +- rsa-pkcs1-sign-tr.c | 2 +- rsa-pkcs1-sign.c | 2 +- rsa-pkcs1-verify.c | 2 +- rsa.c | 4 ++-- rsa.h | 20 ++++++++++---------- sexp2dsa.c | 4 ++-- sexp2rsa.c | 2 +- testsuite/rsa-encrypt-test.c | 6 +++--- 25 files changed, 84 insertions(+), 84 deletions(-) diff --git a/bignum.c b/bignum.c index bf0a48cb..68d15261 100644 --- a/bignum.c +++ b/bignum.c @@ -46,7 +46,7 @@ */ /* Including extra sign bit, if needed. Also one byte for zero. */ -unsigned +size_t nettle_mpz_sizeinbase_256_s(const mpz_t x) { if (mpz_sgn(x) >= 0) @@ -54,7 +54,7 @@ nettle_mpz_sizeinbase_256_s(const mpz_t x) else { /* We'll output ~~x, so we need as many bits as for ~x */ - unsigned size; + size_t size; mpz_t c; mpz_init(c); @@ -66,24 +66,24 @@ nettle_mpz_sizeinbase_256_s(const mpz_t x) } } -unsigned +size_t nettle_mpz_sizeinbase_256_u(const mpz_t x) { return (mpz_sizeinbase(x,2) + 7) / 8; } static void -nettle_mpz_to_octets(unsigned length, uint8_t *s, +nettle_mpz_to_octets(size_t length, uint8_t *s, const mpz_t x, uint8_t sign) { uint8_t *dst = s + length - 1; - unsigned size = mpz_size(x); - unsigned i; + size_t size = mpz_size(x); + size_t i; for (i = 0; isize, random_ctx, random, diff --git a/rsa-pkcs1-sign-tr.c b/rsa-pkcs1-sign-tr.c index 5efc1550..16de2f93 100644 --- a/rsa-pkcs1-sign-tr.c +++ b/rsa-pkcs1-sign-tr.c @@ -35,7 +35,7 @@ int rsa_pkcs1_sign_tr(const struct rsa_public_key *pub, const struct rsa_private_key *key, void *random_ctx, nettle_random_func *random, - unsigned length, const uint8_t *digest_info, + size_t length, const uint8_t *digest_info, mpz_t s) { mpz_t ri; diff --git a/rsa-pkcs1-sign.c b/rsa-pkcs1-sign.c index 9162cfcb..5ca9b2f9 100644 --- a/rsa-pkcs1-sign.c +++ b/rsa-pkcs1-sign.c @@ -33,7 +33,7 @@ int rsa_pkcs1_sign(const struct rsa_private_key *key, - unsigned length, const uint8_t *digest_info, + size_t length, const uint8_t *digest_info, mpz_t s) { if (pkcs1_rsa_digest_encode (s, key->size, length, digest_info)) diff --git a/rsa-pkcs1-verify.c b/rsa-pkcs1-verify.c index 038166d0..968fd969 100644 --- a/rsa-pkcs1-verify.c +++ b/rsa-pkcs1-verify.c @@ -33,7 +33,7 @@ int rsa_pkcs1_verify(const struct rsa_public_key *key, - unsigned length, const uint8_t *digest_info, + size_t length, const uint8_t *digest_info, const mpz_t s) { int res; diff --git a/rsa.c b/rsa.c index e303a8c2..08b95c01 100644 --- a/rsa.c +++ b/rsa.c @@ -52,11 +52,11 @@ rsa_public_key_clear(struct rsa_public_key *key) /* Computes the size, in octets, of a the modulo. Returns 0 if the * modulo is too small to be useful. */ -unsigned +size_t _rsa_check_size(mpz_t n) { /* Round upwards */ - unsigned size = (mpz_sizeinbase(n, 2) + 7) / 8; + size_t size = (mpz_sizeinbase(n, 2) + 7) / 8; if (size < RSA_MINIMUM_N_OCTETS) return 0; diff --git a/rsa.h b/rsa.h index 3ad7e9ab..38455a70 100644 --- a/rsa.h +++ b/rsa.h @@ -95,7 +95,7 @@ struct rsa_public_key { /* Size of the modulo, in octets. This is also the size of all * signatures that are created or verified with this key. */ - unsigned size; + size_t size; /* Modulo */ mpz_t n; @@ -106,7 +106,7 @@ struct rsa_public_key struct rsa_private_key { - unsigned size; + size_t size; /* d is filled in by the key generation function; otherwise it's * completely unused. */ @@ -174,18 +174,18 @@ rsa_private_key_prepare(struct rsa_private_key *key); /* PKCS#1 style signatures */ int rsa_pkcs1_sign(const struct rsa_private_key *key, - unsigned length, const uint8_t *digest_info, + size_t length, const uint8_t *digest_info, mpz_t s); int rsa_pkcs1_sign_tr(const struct rsa_public_key *pub, const struct rsa_private_key *key, void *random_ctx, nettle_random_func *random, - unsigned length, const uint8_t *digest_info, + size_t length, const uint8_t *digest_info, mpz_t s); int rsa_pkcs1_verify(const struct rsa_public_key *key, - unsigned length, const uint8_t *digest_info, + size_t length, const uint8_t *digest_info, const mpz_t signature); int @@ -281,7 +281,7 @@ int rsa_encrypt(const struct rsa_public_key *key, /* For padding */ void *random_ctx, nettle_random_func *random, - unsigned length, const uint8_t *cleartext, + size_t length, const uint8_t *cleartext, mpz_t cipher); /* Message must point to a buffer of size *LENGTH. KEY->size is enough @@ -291,7 +291,7 @@ rsa_encrypt(const struct rsa_public_key *key, * didn't fit. */ int rsa_decrypt(const struct rsa_private_key *key, - unsigned *length, uint8_t *cleartext, + size_t *length, uint8_t *cleartext, const mpz_t ciphertext); /* Timing-resistant version, using randomized RSA blinding. */ @@ -299,7 +299,7 @@ int rsa_decrypt_tr(const struct rsa_public_key *pub, const struct rsa_private_key *key, void *random_ctx, nettle_random_func *random, - unsigned *length, uint8_t *message, + size_t *length, uint8_t *message, const mpz_t gibberish); /* Compute x, the e:th root of m. Calling it with x == m is allowed. */ @@ -364,7 +364,7 @@ int rsa_keypair_from_sexp(struct rsa_public_key *pub, struct rsa_private_key *priv, unsigned limit, - unsigned length, const uint8_t *expr); + size_t length, const uint8_t *expr); /* Keys in PKCS#1 format. */ @@ -402,7 +402,7 @@ _rsa_verify(const struct rsa_public_key *key, const mpz_t m, const mpz_t s); -unsigned +size_t _rsa_check_size(mpz_t n); void diff --git a/sexp2dsa.c b/sexp2dsa.c index a4208854..538f9cec 100644 --- a/sexp2dsa.c +++ b/sexp2dsa.c @@ -78,7 +78,7 @@ int dsa_sha1_keypair_from_sexp(struct dsa_public_key *pub, struct dsa_private_key *priv, unsigned p_max_bits, - unsigned length, const uint8_t *expr) + size_t length, const uint8_t *expr) { struct sexp_iterator i; @@ -92,7 +92,7 @@ int dsa_sha256_keypair_from_sexp(struct dsa_public_key *pub, struct dsa_private_key *priv, unsigned p_max_bits, - unsigned length, const uint8_t *expr) + size_t length, const uint8_t *expr) { struct sexp_iterator i; diff --git a/sexp2rsa.c b/sexp2rsa.c index 7dc6d681..177a494f 100644 --- a/sexp2rsa.c +++ b/sexp2rsa.c @@ -89,7 +89,7 @@ int rsa_keypair_from_sexp(struct rsa_public_key *pub, struct rsa_private_key *priv, unsigned limit, - unsigned length, const uint8_t *expr) + size_t length, const uint8_t *expr) { struct sexp_iterator i; static const uint8_t * const names[3] diff --git a/testsuite/rsa-encrypt-test.c b/testsuite/rsa-encrypt-test.c index c7b616c9..7104e24b 100644 --- a/testsuite/rsa-encrypt-test.c +++ b/testsuite/rsa-encrypt-test.c @@ -12,10 +12,10 @@ test_main(void) /* FIXME: How is this spelled? */ const uint8_t *msg = "Squemish ossifrage"; - unsigned msg_length; + size_t msg_length; uint8_t *decrypted; - unsigned decrypted_length; + size_t decrypted_length; uint8_t after; mpz_t gibberish; @@ -30,7 +30,7 @@ test_main(void) msg_length = strlen(msg); if (verbose) - fprintf(stderr, "msg: `%s', length = %d\n", msg, msg_length); + fprintf(stderr, "msg: `%s', length = %d\n", msg, (int) msg_length); ASSERT(rsa_encrypt(&pub, &lfib, (nettle_random_func *) knuth_lfib_random, -- GitLab