Commit 75fa6750 authored by Niels Möller's avatar Niels Möller
Browse files

* bignum.c (nettle_mpz_sizeinbase_256_u): New name, was

nettle_mpz_sizeinbase_256. Updated all callers.

Rev: src/nettle/bignum-random.c:1.2
Rev: src/nettle/dsa-keygen.c:1.4
Rev: src/nettle/dsa.c:1.3
Rev: src/nettle/pgp-encode.c:1.3
Rev: src/nettle/rsa-compat.c:1.5
Rev: src/nettle/rsa-encrypt.c:1.3
Rev: src/nettle/rsa_md5.c:1.7
Rev: src/nettle/rsa_sha1.c:1.7
parent d33e5b41
...@@ -43,7 +43,7 @@ nettle_mpz_random_size(mpz_t x, ...@@ -43,7 +43,7 @@ nettle_mpz_random_size(mpz_t x,
random(ctx, length, data); random(ctx, length, data);
nettle_mpz_set_str_256(x, length, data); nettle_mpz_set_str_256_u(x, length, data);
if (bits % 8) if (bits % 8)
mpz_fdiv_r_2exp(x, x, bits); mpz_fdiv_r_2exp(x, x, bits);
......
...@@ -102,7 +102,7 @@ dsa_nist_gen(mpz_t p, mpz_t q, ...@@ -102,7 +102,7 @@ dsa_nist_gen(mpz_t p, mpz_t q,
h1[0] |= 0x80; h1[0] |= 0x80;
h1[SHA1_DIGEST_SIZE - 1] |= 1; h1[SHA1_DIGEST_SIZE - 1] |= 1;
nettle_mpz_set_str_256(q, SHA1_DIGEST_SIZE, h1); nettle_mpz_set_str_256_u(q, SHA1_DIGEST_SIZE, h1);
/* The spec says that we should use 18 iterations of /* The spec says that we should use 18 iterations of
* miller-rabin. For performance, we want to do some trial * miller-rabin. For performance, we want to do some trial
...@@ -134,7 +134,7 @@ dsa_nist_gen(mpz_t p, mpz_t q, ...@@ -134,7 +134,7 @@ dsa_nist_gen(mpz_t p, mpz_t q,
mpz_add_ui(t, t, j + k); mpz_add_ui(t, t, j + k);
hash(t, buffer + ( (n-k) * SHA1_DIGEST_SIZE)); hash(t, buffer + ( (n-k) * SHA1_DIGEST_SIZE));
} }
nettle_mpz_set_str_256(p, size, buffer); nettle_mpz_set_str_256_u(p, size, buffer);
mpz_fdiv_r_2exp(p, p, L); mpz_fdiv_r_2exp(p, p, L);
mpz_setbit(p, L-1); mpz_setbit(p, L-1);
......
...@@ -85,7 +85,7 @@ _dsa_hash(mpz_t x, struct sha1_ctx *hash) ...@@ -85,7 +85,7 @@ _dsa_hash(mpz_t x, struct sha1_ctx *hash)
uint8_t digest[SHA1_DIGEST_SIZE]; uint8_t digest[SHA1_DIGEST_SIZE];
sha1_digest(hash, sizeof(digest), digest); sha1_digest(hash, sizeof(digest), digest);
nettle_mpz_set_str_256(x, sizeof(digest), digest); nettle_mpz_set_str_256_u(x, sizeof(digest), digest);
} }
#endif /* WITH_PUBLIC_KEY */ #endif /* WITH_PUBLIC_KEY */
...@@ -72,7 +72,7 @@ pgp_put_mpi(struct nettle_buffer *buffer, mpz_t x) ...@@ -72,7 +72,7 @@ pgp_put_mpi(struct nettle_buffer *buffer, mpz_t x)
if (!p) if (!p)
return 0; return 0;
nettle_mpz_set_str_256(x, octets, p); nettle_mpz_set_str_256_u(x, octets, p);
return 1; return 1;
} }
......
...@@ -61,16 +61,16 @@ R_SignFinal(R_SIGNATURE_CTX *ctx, ...@@ -61,16 +61,16 @@ R_SignFinal(R_SIGNATURE_CTX *ctx,
struct rsa_private_key k; struct rsa_private_key k;
int res; int res;
nettle_mpz_init_set_str_256(k.p, nettle_mpz_init_set_str_256_u(k.p,
MAX_RSA_MODULUS_LEN, key->prime[0]); MAX_RSA_MODULUS_LEN, key->prime[0]);
nettle_mpz_init_set_str_256(k.q, nettle_mpz_init_set_str_256_u(k.q,
MAX_RSA_MODULUS_LEN, key->prime[1]); MAX_RSA_MODULUS_LEN, key->prime[1]);
nettle_mpz_init_set_str_256(k.a, nettle_mpz_init_set_str_256_u(k.a,
MAX_RSA_MODULUS_LEN, key->primeExponent[0]); MAX_RSA_MODULUS_LEN, key->primeExponent[0]);
nettle_mpz_init_set_str_256(k.b, nettle_mpz_init_set_str_256_u(k.b,
MAX_RSA_MODULUS_LEN, key->primeExponent[1]); MAX_RSA_MODULUS_LEN, key->primeExponent[1]);
nettle_mpz_init_set_str_256(k.c, nettle_mpz_init_set_str_256_u(k.c,
MAX_RSA_MODULUS_LEN, key->coefficient); MAX_RSA_MODULUS_LEN, key->coefficient);
if (rsa_prepare_private_key(&k) && (k.size <= MAX_RSA_MODULUS_LEN)) if (rsa_prepare_private_key(&k) && (k.size <= MAX_RSA_MODULUS_LEN))
{ {
...@@ -124,17 +124,17 @@ R_VerifyFinal(R_SIGNATURE_CTX *ctx, ...@@ -124,17 +124,17 @@ R_VerifyFinal(R_SIGNATURE_CTX *ctx,
struct rsa_public_key k; struct rsa_public_key k;
int res; int res;
nettle_mpz_init_set_str_256(k.n, nettle_mpz_init_set_str_256_u(k.n,
MAX_RSA_MODULUS_LEN, key->modulus); MAX_RSA_MODULUS_LEN, key->modulus);
nettle_mpz_init_set_str_256(k.e, nettle_mpz_init_set_str_256_u(k.e,
MAX_RSA_MODULUS_LEN, key->exponent); MAX_RSA_MODULUS_LEN, key->exponent);
if (rsa_prepare_public_key(&k) && (k.size == length)) if (rsa_prepare_public_key(&k) && (k.size == length))
{ {
mpz_t s; mpz_t s;
nettle_mpz_init_set_str_256(s, nettle_mpz_init_set_str_256_u(s,
k.size, signature); k.size, signature);
res = rsa_md5_verify(&k, &ctx->hash, s) res = rsa_md5_verify(&k, &ctx->hash, s)
? RE_SUCCESS : RE_SIGNATURE; ? RE_SUCCESS : RE_SIGNATURE;
......
...@@ -70,7 +70,7 @@ rsa_encrypt(const struct rsa_public_key *key, ...@@ -70,7 +70,7 @@ rsa_encrypt(const struct rsa_public_key *key,
memcpy(em + 1 + padding, message, length); memcpy(em + 1 + padding, message, length);
nettle_mpz_set_str_256(gibbberish, key->size - 1, em); nettle_mpz_set_str_256_u(gibbberish, key->size - 1, em);
mpz_powm(gibbberish, gibbberish, key->e, key->n); mpz_powm(gibbberish, gibbberish, key->e, key->n);
return 1; return 1;
......
...@@ -128,7 +128,7 @@ pkcs1_encode_md5(mpz_t m, unsigned length, struct md5_ctx *hash) ...@@ -128,7 +128,7 @@ pkcs1_encode_md5(mpz_t m, unsigned length, struct md5_ctx *hash)
em[0] = 1; em[0] = 1;
memset(em + 1, 0xff, i - 1); memset(em + 1, 0xff, i - 1);
nettle_mpz_set_str_256(m, length, em); nettle_mpz_set_str_256_u(m, length, em);
} }
#endif /* WITH_PUBLIC_KEY */ #endif /* WITH_PUBLIC_KEY */
...@@ -128,7 +128,7 @@ pkcs1_encode_sha1(mpz_t m, unsigned length, struct sha1_ctx *hash) ...@@ -128,7 +128,7 @@ pkcs1_encode_sha1(mpz_t m, unsigned length, struct sha1_ctx *hash)
em[0] = 1; em[0] = 1;
memset(em + 1, 0xff, i - 1); memset(em + 1, 0xff, i - 1);
nettle_mpz_set_str_256(m, length, em); nettle_mpz_set_str_256_u(m, length, em);
} }
#endif /* WITH_PUBLIC_KEY */ #endif /* WITH_PUBLIC_KEY */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment