Commit 3f4c5318 authored by Niels Möller's avatar Niels Möller

Helper hash_string: Delete length argument.

parent bceb555e
...@@ -3,6 +3,8 @@ ...@@ -3,6 +3,8 @@
* examples/hogweed-benchmark.c: Use uint8_t for curve25519 values. * examples/hogweed-benchmark.c: Use uint8_t for curve25519 values.
(bench_rsa_init): Use uint8_t for sexp strings. (bench_rsa_init): Use uint8_t for sexp strings.
(bench_dsa_init): Likewise. (bench_dsa_init): Likewise.
(hash_string): Delete length argument, calling strlen instead.
Cast string to const uint8_t *. Updated callers.
* examples/io.c (read_file): Use size_t for sizes, and uint8_t for * examples/io.c (read_file): Use size_t for sizes, and uint8_t for
the contents. the contents.
......
...@@ -90,13 +90,12 @@ xalloc (size_t size) ...@@ -90,13 +90,12 @@ xalloc (size_t size)
} }
static uint8_t * static uint8_t *
hash_string (const struct nettle_hash *hash, hash_string (const struct nettle_hash *hash, const char *s)
unsigned length, const char *s)
{ {
void *ctx = xalloc (hash->context_size); void *ctx = xalloc (hash->context_size);
uint8_t *digest = xalloc (hash->digest_size); uint8_t *digest = xalloc (hash->digest_size);
hash->init (ctx); hash->init (ctx);
hash->update (ctx, length, s); hash->update (ctx, strlen(s), (const uint8_t *) s);
hash->digest (ctx, hash->digest_size, digest); hash->digest (ctx, hash->digest_size, digest);
free (ctx); free (ctx);
...@@ -239,7 +238,7 @@ bench_rsa_init (unsigned size) ...@@ -239,7 +238,7 @@ bench_rsa_init (unsigned size)
&& rsa_keypair_from_sexp_alist (&ctx->pub, &ctx->key, 0, &i))) && rsa_keypair_from_sexp_alist (&ctx->pub, &ctx->key, 0, &i)))
die ("Internal error.\n"); die ("Internal error.\n");
ctx->digest = hash_string (&nettle_sha256, 3, "foo"); ctx->digest = hash_string (&nettle_sha256, "foo");
rsa_sha256_sign_digest (&ctx->key, ctx->digest, ctx->s); rsa_sha256_sign_digest (&ctx->key, ctx->digest, ctx->s);
...@@ -324,7 +323,7 @@ bench_dsa_init (unsigned size) ...@@ -324,7 +323,7 @@ bench_dsa_init (unsigned size)
0, DSA_SHA1_Q_BITS, &i)) ) 0, DSA_SHA1_Q_BITS, &i)) )
die ("Internal error.\n"); die ("Internal error.\n");
ctx->digest = hash_string (&nettle_sha1, 3, "foo"); ctx->digest = hash_string (&nettle_sha1, "foo");
dsa_sign (&ctx->params, ctx->key, dsa_sign (&ctx->params, ctx->key,
&ctx->lfib, (nettle_random_func *)knuth_lfib_random, &ctx->lfib, (nettle_random_func *)knuth_lfib_random,
...@@ -399,7 +398,7 @@ bench_ecdsa_init (unsigned size) ...@@ -399,7 +398,7 @@ bench_ecdsa_init (unsigned size)
xs = "8e8e07360350fb6b7ad8370cfd32fa8c6bba785e6e200599"; xs = "8e8e07360350fb6b7ad8370cfd32fa8c6bba785e6e200599";
ys = "7f82ddb58a43d59ff8dc66053002b918b99bd01bd68d6736"; ys = "7f82ddb58a43d59ff8dc66053002b918b99bd01bd68d6736";
zs = "f2e620e086d658b4b507996988480917640e4dc107808bdd"; zs = "f2e620e086d658b4b507996988480917640e4dc107808bdd";
ctx->digest = hash_string (&nettle_sha1, 3, "abc"); ctx->digest = hash_string (&nettle_sha1, "abc");
ctx->digest_size = 20; ctx->digest_size = 20;
break; break;
case 224: case 224:
...@@ -407,7 +406,7 @@ bench_ecdsa_init (unsigned size) ...@@ -407,7 +406,7 @@ bench_ecdsa_init (unsigned size)
xs = "993bf363f4f2bc0f255f22563980449164e9c894d9efd088d7b77334"; xs = "993bf363f4f2bc0f255f22563980449164e9c894d9efd088d7b77334";
ys = "b75fff9849997d02d135140e4d0030944589586e22df1fc4b629082a"; ys = "b75fff9849997d02d135140e4d0030944589586e22df1fc4b629082a";
zs = "cdfd01838247f5de3cc70b688418046f10a2bfaca6de9ec836d48c27"; zs = "cdfd01838247f5de3cc70b688418046f10a2bfaca6de9ec836d48c27";
ctx->digest = hash_string (&nettle_sha224, 3, "abc"); ctx->digest = hash_string (&nettle_sha224, "abc");
ctx->digest_size = 28; ctx->digest_size = 28;
break; break;
...@@ -417,7 +416,7 @@ bench_ecdsa_init (unsigned size) ...@@ -417,7 +416,7 @@ bench_ecdsa_init (unsigned size)
xs = "2442A5CC 0ECD015F A3CA31DC 8E2BBC70 BF42D60C BCA20085 E0822CB0 4235E970"; xs = "2442A5CC 0ECD015F A3CA31DC 8E2BBC70 BF42D60C BCA20085 E0822CB0 4235E970";
ys = "6FC98BD7 E50211A4 A27102FA 3549DF79 EBCB4BF2 46B80945 CDDFE7D5 09BBFD7D"; ys = "6FC98BD7 E50211A4 A27102FA 3549DF79 EBCB4BF2 46B80945 CDDFE7D5 09BBFD7D";
zs = "DC51D386 6A15BACD E33D96F9 92FCA99D A7E6EF09 34E70975 59C27F16 14C88A7F"; zs = "DC51D386 6A15BACD E33D96F9 92FCA99D A7E6EF09 34E70975 59C27F16 14C88A7F";
ctx->digest = hash_string (&nettle_sha256, 3, "abc"); ctx->digest = hash_string (&nettle_sha256, "abc");
ctx->digest_size = 32; ctx->digest_size = 32;
break; break;
case 384: case 384:
...@@ -428,7 +427,7 @@ bench_ecdsa_init (unsigned size) ...@@ -428,7 +427,7 @@ bench_ecdsa_init (unsigned size)
"3D383B91 C5E7EDAA 2B714CC9 9D5743CA"; "3D383B91 C5E7EDAA 2B714CC9 9D5743CA";
zs = "0BEB6466 34BA8773 5D77AE48 09A0EBEA 865535DE 4C1E1DCB 692E8470 8E81A5AF" zs = "0BEB6466 34BA8773 5D77AE48 09A0EBEA 865535DE 4C1E1DCB 692E8470 8E81A5AF"
"62E528C3 8B2A81B3 5309668D 73524D9F"; "62E528C3 8B2A81B3 5309668D 73524D9F";
ctx->digest = hash_string (&nettle_sha384, 3, "abc"); ctx->digest = hash_string (&nettle_sha384, "abc");
ctx->digest_size = 48; ctx->digest_size = 48;
break; break;
case 521: case 521:
...@@ -443,7 +442,7 @@ bench_ecdsa_init (unsigned size) ...@@ -443,7 +442,7 @@ bench_ecdsa_init (unsigned size)
"20597779 060A7FF9 D704ADF7 8B570FFA D6F062E9 5C7E0C5D 5481C5B1 53B48B37" "20597779 060A7FF9 D704ADF7 8B570FFA D6F062E9 5C7E0C5D 5481C5B1 53B48B37"
"5FA1"; "5FA1";
ctx->digest = hash_string (&nettle_sha512, 3, "abc"); ctx->digest = hash_string (&nettle_sha512, "abc");
ctx->digest_size = 64; ctx->digest_size = 64;
break; break;
default: default:
...@@ -526,7 +525,7 @@ bench_openssl_rsa_init (unsigned size) ...@@ -526,7 +525,7 @@ bench_openssl_rsa_init (unsigned size)
ctx->key = RSA_generate_key (size, 65537, NULL, NULL); ctx->key = RSA_generate_key (size, 65537, NULL, NULL);
ctx->ref = xalloc (RSA_size (ctx->key)); ctx->ref = xalloc (RSA_size (ctx->key));
ctx->signature = xalloc (RSA_size (ctx->key)); ctx->signature = xalloc (RSA_size (ctx->key));
ctx->digest = hash_string (&nettle_sha1, 3, "foo"); ctx->digest = hash_string (&nettle_sha1, "foo");
RSA_blinding_off(ctx->key); RSA_blinding_off(ctx->key);
if (! RSA_sign (NID_sha1, ctx->digest, SHA1_DIGEST_SIZE, if (! RSA_sign (NID_sha1, ctx->digest, SHA1_DIGEST_SIZE,
...@@ -585,27 +584,27 @@ bench_openssl_ecdsa_init (unsigned size) ...@@ -585,27 +584,27 @@ bench_openssl_ecdsa_init (unsigned size)
case 192: case 192:
ctx->key = EC_KEY_new_by_curve_name (NID_X9_62_prime192v1); ctx->key = EC_KEY_new_by_curve_name (NID_X9_62_prime192v1);
ctx->digest_length = 24; /* truncated */ ctx->digest_length = 24; /* truncated */
ctx->digest = hash_string (&nettle_sha224, 3, "abc"); ctx->digest = hash_string (&nettle_sha224, "abc");
break; break;
case 224: case 224:
ctx->key = EC_KEY_new_by_curve_name (NID_secp224r1); ctx->key = EC_KEY_new_by_curve_name (NID_secp224r1);
ctx->digest_length = SHA224_DIGEST_SIZE; ctx->digest_length = SHA224_DIGEST_SIZE;
ctx->digest = hash_string (&nettle_sha224, 3, "abc"); ctx->digest = hash_string (&nettle_sha224, "abc");
break; break;
case 256: case 256:
ctx->key = EC_KEY_new_by_curve_name (NID_X9_62_prime256v1); ctx->key = EC_KEY_new_by_curve_name (NID_X9_62_prime256v1);
ctx->digest_length = SHA256_DIGEST_SIZE; ctx->digest_length = SHA256_DIGEST_SIZE;
ctx->digest = hash_string (&nettle_sha256, 3, "abc"); ctx->digest = hash_string (&nettle_sha256, "abc");
break; break;
case 384: case 384:
ctx->key = EC_KEY_new_by_curve_name (NID_secp384r1); ctx->key = EC_KEY_new_by_curve_name (NID_secp384r1);
ctx->digest_length = SHA384_DIGEST_SIZE; ctx->digest_length = SHA384_DIGEST_SIZE;
ctx->digest = hash_string (&nettle_sha384, 3, "abc"); ctx->digest = hash_string (&nettle_sha384, "abc");
break; break;
case 521: case 521:
ctx->key = EC_KEY_new_by_curve_name (NID_secp521r1); ctx->key = EC_KEY_new_by_curve_name (NID_secp521r1);
ctx->digest_length = SHA512_DIGEST_SIZE; ctx->digest_length = SHA512_DIGEST_SIZE;
ctx->digest = hash_string (&nettle_sha512, 3, "abc"); ctx->digest = hash_string (&nettle_sha512, "abc");
break; break;
default: default:
die ("Internal error.\n"); die ("Internal error.\n");
......
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