diff --git a/ChangeLog b/ChangeLog index 53cb48a7fb04e56ce88d4d9b408b29d2d2212ba1..a4e5633e09acdc27e1124987ea14d837362cb3eb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2014-04-25 Niels Möller <nisse@lysator.liu.se> + * All hash-related files: Renamed all _DATA_SIZE constants to + _BLOCK_SIZE, for consistency. Old names kept for backwards + compatibility. + * nettle.texinfo (CCM): Documentation for CCM mode, contributed by Owen Kirby. diff --git a/examples/nettle-benchmark.c b/examples/nettle-benchmark.c index f1f9f599cb06e354602b49d8a549a7780345023a..847b80c11dc5c3ac1ee352fca14ab720374f16a1 100644 --- a/examples/nettle-benchmark.c +++ b/examples/nettle-benchmark.c @@ -410,7 +410,7 @@ time_umac(void) info.update = (nettle_hash_update_func *) umac32_update; info.data = data; - display("umac32", "update", UMAC_DATA_SIZE, + display("umac32", "update", UMAC_BLOCK_SIZE, time_function(bench_hash, &info)); umac64_set_key (&ctx64, key); @@ -418,7 +418,7 @@ time_umac(void) info.update = (nettle_hash_update_func *) umac64_update; info.data = data; - display("umac64", "update", UMAC_DATA_SIZE, + display("umac64", "update", UMAC_BLOCK_SIZE, time_function(bench_hash, &info)); umac96_set_key (&ctx96, key); @@ -426,7 +426,7 @@ time_umac(void) info.update = (nettle_hash_update_func *) umac96_update; info.data = data; - display("umac96", "update", UMAC_DATA_SIZE, + display("umac96", "update", UMAC_BLOCK_SIZE, time_function(bench_hash, &info)); umac128_set_key (&ctx128, key); @@ -434,7 +434,7 @@ time_umac(void) info.update = (nettle_hash_update_func *) umac128_update; info.data = data; - display("umac128", "update", UMAC_DATA_SIZE, + display("umac128", "update", UMAC_BLOCK_SIZE, time_function(bench_hash, &info)); } @@ -677,7 +677,7 @@ static void bench_sha1_compress(void) { uint32_t state[_SHA1_DIGEST_LENGTH]; - uint8_t data[SHA1_DATA_SIZE]; + uint8_t data[SHA1_BLOCK_SIZE]; double t; TIME_CYCLES (t, _nettle_sha1_compress(state, data)); diff --git a/gosthash94.c b/gosthash94.c index a671b4fee6a5e3a7848c6d7eb584a1e82e05f1d0..e60c9ae5cddf0c324a0a53aa45ccf1f7580d628c 100644 --- a/gosthash94.c +++ b/gosthash94.c @@ -533,7 +533,7 @@ gosthash94_update (struct gosthash94_ctx *ctx, /* fill partial block */ if (index) { - unsigned left = GOSTHASH94_DATA_SIZE - index; + unsigned left = GOSTHASH94_BLOCK_SIZE - index; memcpy (ctx->message + index, msg, (length < left ? length : left)); if (length < left) return; @@ -543,11 +543,11 @@ gosthash94_update (struct gosthash94_ctx *ctx, msg += left; length -= left; } - while (length >= GOSTHASH94_DATA_SIZE) + while (length >= GOSTHASH94_BLOCK_SIZE) { gost_compute_sum_and_hash (ctx, msg); - msg += GOSTHASH94_DATA_SIZE; - length -= GOSTHASH94_DATA_SIZE; + msg += GOSTHASH94_BLOCK_SIZE; + length -= GOSTHASH94_BLOCK_SIZE; } if (length) { diff --git a/gosthash94.h b/gosthash94.h index 5a1978e610a60e2ed868d2e7be34a61c72a79b18..8e9d49fefb1bdf65ccae726555b499ab4a8927d7 100644 --- a/gosthash94.h +++ b/gosthash94.h @@ -72,14 +72,16 @@ extern "C" { #define gosthash94_update nettle_gosthash94_update #define gosthash94_digest nettle_gosthash94_digest -#define GOSTHASH94_DATA_SIZE 32 +#define GOSTHASH94_BLOCK_SIZE 32 #define GOSTHASH94_DIGEST_SIZE 32 +/* For backwards compatibility */ +#define GOSTHASH94_DATA_SIZE GOSTHASH94_BLOCK_SIZE struct gosthash94_ctx { uint32_t hash[8]; /* algorithm 256-bit state */ uint32_t sum[8]; /* sum of processed message blocks */ - uint8_t message[GOSTHASH94_DATA_SIZE]; /* 256-bit buffer for leftovers */ + uint8_t message[GOSTHASH94_BLOCK_SIZE]; /* 256-bit buffer for leftovers */ uint64_t length; /* number of processed bytes */ }; diff --git a/md2.c b/md2.c index 19d870e15bf35203611604ebf64863e04405b118..a0cb1b64a15cbb834c62a3c5f39267777fd619f7 100644 --- a/md2.c +++ b/md2.c @@ -87,21 +87,21 @@ md2_transform(struct md2_ctx *ctx, const uint8_t *data) unsigned i; uint8_t t; - memcpy(ctx->X + 16, data, MD2_DATA_SIZE); + memcpy(ctx->X + 16, data, MD2_BLOCK_SIZE); for (i = 0, t = ctx->C[15]; - i<MD2_DATA_SIZE; i++) + i<MD2_BLOCK_SIZE; i++) { - ctx->X[2 * MD2_DATA_SIZE + i] - = ctx->X[i] ^ ctx->X[MD2_DATA_SIZE + i]; + ctx->X[2 * MD2_BLOCK_SIZE + i] + = ctx->X[i] ^ ctx->X[MD2_BLOCK_SIZE + i]; t = (ctx->C[i] ^= S[data[i]^t]); } for (i = t = 0; - i< MD2_DATA_SIZE + 2; + i< MD2_BLOCK_SIZE + 2; t = (t + i) & 0xff, i++) { unsigned j; - for (j = 0; j < 3 * MD2_DATA_SIZE; j++) + for (j = 0; j < 3 * MD2_BLOCK_SIZE; j++) t = (ctx->X[j] ^= S[t]); } } @@ -129,7 +129,7 @@ md2_digest(struct md2_ctx *ctx, assert(length <= MD2_DIGEST_SIZE); - left = MD2_DATA_SIZE - ctx->index; + left = MD2_BLOCK_SIZE - ctx->index; memset(ctx->block + ctx->index, left, left); md2_transform(ctx, ctx->block); diff --git a/md2.h b/md2.h index fe7013f601fb58d844fbe7cac6d393f0af726aaa..560b2cbc6728e2fd8137d9941aad663982c3d150 100644 --- a/md2.h +++ b/md2.h @@ -46,13 +46,15 @@ extern "C" { #define md2_digest nettle_md2_digest #define MD2_DIGEST_SIZE 16 -#define MD2_DATA_SIZE 16 +#define MD2_BLOCK_SIZE 16 +/* For backwards compatibility */ +#define MD2_DATA_SIZE MD2_BLOCK_SIZE struct md2_ctx { - uint8_t C[MD2_DATA_SIZE]; - uint8_t X[3 * MD2_DATA_SIZE]; - uint8_t block[MD2_DATA_SIZE]; /* Block buffer */ + uint8_t C[MD2_BLOCK_SIZE]; + uint8_t X[3 * MD2_BLOCK_SIZE]; + uint8_t block[MD2_BLOCK_SIZE]; /* Block buffer */ unsigned index; /* Into buffer */ }; diff --git a/md4.h b/md4.h index d90ff2faa3b463beda677fcc3c04252ccbff4534..f199a80e63befc423acc7574847396a6c20cfe1e 100644 --- a/md4.h +++ b/md4.h @@ -46,7 +46,9 @@ extern "C" { #define md4_digest nettle_md4_digest #define MD4_DIGEST_SIZE 16 -#define MD4_DATA_SIZE 64 +#define MD4_BLOCK_SIZE 64 +/* For backwards compatibility */ +#define MD4_DATA_SIZE MD4_BLOCK_SIZE /* Digest is kept internally as 4 32-bit words. */ #define _MD4_DIGEST_LENGTH 4 @@ -56,7 +58,7 @@ struct md4_ctx { uint32_t state[_MD4_DIGEST_LENGTH]; uint64_t count; /* Block count */ - uint8_t block[MD4_DATA_SIZE]; /* Block buffer */ + uint8_t block[MD4_BLOCK_SIZE]; /* Block buffer */ unsigned index; /* Into buffer */ }; diff --git a/md5.c b/md5.c index a518e65e79b93663816b0e0a3ce7d6d2a3e72ae2..142b112e1950d79f1c9b1f5dcd654ff85714b3dc 100644 --- a/md5.c +++ b/md5.c @@ -85,7 +85,7 @@ md5_digest(struct md5_ctx *ctx, /* There are 512 = 2^9 bits in one block */ bit_count = (ctx->count << 9) | (ctx->index << 3); - LE_WRITE_UINT64(ctx->block + (MD5_DATA_SIZE - 8), bit_count); + LE_WRITE_UINT64(ctx->block + (MD5_BLOCK_SIZE - 8), bit_count); _nettle_md5_compress(ctx->state, ctx->block); _nettle_write_le32(length, digest, ctx->state); diff --git a/md5.h b/md5.h index 7a37872b7e7af4db183893a9d8dda30709804c40..040cf9dea9112489c420c51a6ada8f435d7d2aba 100644 --- a/md5.h +++ b/md5.h @@ -46,7 +46,9 @@ extern "C" { #define md5_digest nettle_md5_digest #define MD5_DIGEST_SIZE 16 -#define MD5_DATA_SIZE 64 +#define MD5_BLOCK_SIZE 64 +/* For backwards compatibility */ +#define MD5_DATA_SIZE MD5_BLOCK_SIZE /* Digest is kept internally as 4 32-bit words. */ #define _MD5_DIGEST_LENGTH 4 @@ -55,7 +57,7 @@ struct md5_ctx { uint32_t state[_MD5_DIGEST_LENGTH]; uint64_t count; /* Block count */ - uint8_t block[MD5_DATA_SIZE]; /* Block buffer */ + uint8_t block[MD5_BLOCK_SIZE]; /* Block buffer */ unsigned index; /* Into buffer */ }; diff --git a/nettle-meta.h b/nettle-meta.h index c10dcbde3b3fe8ccb54f611fd3a73c7c709f2949..23a47ed9c6b5e11914d2c335e3bfe55b3bf33dba 100644 --- a/nettle-meta.h +++ b/nettle-meta.h @@ -108,7 +108,7 @@ struct nettle_hash #name, \ sizeof(struct name##_ctx), \ NAME##_DIGEST_SIZE, \ - NAME##_DATA_SIZE, \ + NAME##_BLOCK_SIZE, \ (nettle_hash_init_func *) name##_init, \ (nettle_hash_update_func *) name##_update, \ (nettle_hash_digest_func *) name##_digest \ diff --git a/nettle.texinfo b/nettle.texinfo index 9bd08d51c7417b5ac16d5a20d34a6addb1aad231..f7d78e2a8733c199eb1fddc097860b49e0f4f4bc 100644 --- a/nettle.texinfo +++ b/nettle.texinfo @@ -428,7 +428,7 @@ bits, or 32 octets. Nettle defines SHA256 in @file{<nettle/sha2.h>}. The size of a SHA256 digest, i.e. 32. @end defvr -@defvr Constant SHA256_DATA_SIZE +@defvr Constant SHA256_BLOCK_SIZE The internal block size of SHA256. Useful for some special constructions, in particular HMAC-SHA256. @end defvr @@ -469,7 +469,7 @@ compatibility). The size of a SHA224 digest, i.e. 28. @end defvr -@defvr Constant SHA224_DATA_SIZE +@defvr Constant SHA224_BLOCK_SIZE The internal block size of SHA224. Useful for some special constructions, in particular HMAC-SHA224. @end defvr @@ -508,7 +508,7 @@ octets. Nettle defines SHA512 in @file{<nettle/sha2.h>} (and in The size of a SHA512 digest, i.e. 64. @end defvr -@defvr Constant SHA512_DATA_SIZE +@defvr Constant SHA512_BLOCK_SIZE The internal block size of SHA512, 128. Useful for some special constructions, in particular HMAC-SHA512. @end defvr @@ -554,10 +554,10 @@ identifiers for other purposes. So avoid doing that. The digest size for each variant, i.e., 28, 32, and 48, respectively. @end defvr -@defvr Constant SHA512_224_DATA_SIZE -@defvrx Constant SHA512_256_DATA_SIZE -@defvrx Constant SHA384_DATA_SIZE -The internal block size, same as SHA512_DATA_SIZE, i.e., 128. Useful for +@defvr Constant SHA512_224_BLOCK_SIZE +@defvrx Constant SHA512_256_BLOCK_SIZE +@defvrx Constant SHA384_BLOCK_SIZE +The internal block size, same as SHA512_BLOCK_SIZE, i.e., 128. Useful for some special constructions, in particular HMAC-SHA384. @end defvr @@ -606,7 +606,7 @@ Nettle defines SHA3-224 in @file{<nettle/sha3.h>}. The size of a SHA3_224 digest, i.e., 28. @end defvr -@defvr Constant SHA3_224_DATA_SIZE +@defvr Constant SHA3_224_BLOCK_SIZE The internal block size of SHA3_224. @end defvr @@ -641,7 +641,7 @@ Nettle defines SHA3-256 in @file{<nettle/sha3.h>}. The size of a SHA3_256 digest, i.e., 32. @end defvr -@defvr Constant SHA3_256_DATA_SIZE +@defvr Constant SHA3_256_BLOCK_SIZE The internal block size of SHA3_256. @end defvr @@ -675,7 +675,7 @@ Nettle defines SHA3-384 in @file{<nettle/sha3.h>}. The size of a SHA3_384 digest, i.e., 48. @end defvr -@defvr Constant SHA3_384_DATA_SIZE +@defvr Constant SHA3_384_BLOCK_SIZE The internal block size of SHA3_384. @end defvr @@ -709,7 +709,7 @@ Nettle defines SHA3-512 in @file{<nettle/sha3.h>}. The size of a SHA3_512 digest, i.e. 64. @end defvr -@defvr Constant SHA3_512_DATA_SIZE +@defvr Constant SHA3_512_BLOCK_SIZE The internal block size of SHA3_512. @end defvr @@ -757,7 +757,7 @@ described in @cite{RFC 1321}. It outputs message digests of 128 bits, or The size of an MD5 digest, i.e. 16. @end defvr -@defvr Constant MD5_DATA_SIZE +@defvr Constant MD5_BLOCK_SIZE The internal block size of MD5. Useful for some special constructions, in particular HMAC-MD5. @end defvr @@ -801,7 +801,7 @@ Nettle defines MD2 in @file{<nettle/md2.h>}. The size of an MD2 digest, i.e. 16. @end defvr -@defvr Constant MD2_DATA_SIZE +@defvr Constant MD2_BLOCK_SIZE The internal block size of MD2. @end defvr @@ -838,7 +838,7 @@ existing applications and protocols. The size of an MD4 digest, i.e. 16. @end defvr -@defvr Constant MD4_DATA_SIZE +@defvr Constant MD4_BLOCK_SIZE The internal block size of MD4. @end defvr @@ -875,7 +875,7 @@ RIPEMD160 in @file{nettle/ripemd160.h}. The size of a RIPEMD160 digest, i.e. 20. @end defvr -@defvr Constant RIPEMD160_DATA_SIZE +@defvr Constant RIPEMD160_BLOCK_SIZE The internal block size of RIPEMD160. @end defvr @@ -911,7 +911,7 @@ in @file{<nettle/sha.h>}, for backwards compatibility). The size of a SHA1 digest, i.e. 20. @end defvr -@defvr Constant SHA1_DATA_SIZE +@defvr Constant SHA1_BLOCK_SIZE The internal block size of SHA1. Useful for some special constructions, in particular HMAC-SHA1. @end defvr @@ -949,7 +949,7 @@ Nettle defines GOSTHASH94 in @file{<nettle/gosthash94.h>}. The size of a GOSTHASH94 digest, i.e. 32. @end defvr -@defvr Constant GOSTHASH94_DATA_SIZE +@defvr Constant GOSTHASH94_BLOCK_SIZE The internal block size of GOSTHASH94, i.e., 32. @end defvr @@ -2743,7 +2743,7 @@ The size of an UMAC96 digest, 12. @defvr Constant UMAC128_DIGEST_SIZE The size of an UMAC128 digest, 16. @end defvr -@defvr Constant UMAC_DATA_SIZE +@defvr Constant UMAC_BLOCK_SIZE The internal block size of UMAC. @end defvr diff --git a/ripemd160.h b/ripemd160.h index 86012d13d409d6f86628fbb2f33e3d0e394a8e89..80d1d8a759005878d958eb08bd907f4a3c0cd4a9 100644 --- a/ripemd160.h +++ b/ripemd160.h @@ -48,7 +48,9 @@ extern "C" { /* RIPEMD160 */ #define RIPEMD160_DIGEST_SIZE 20 -#define RIPEMD160_DATA_SIZE 64 +#define RIPEMD160_BLOCK_SIZE 64 +/* For backwards compatibility */ +#define RIPEMD160_DATA_SIZE RIPEMD160_BLOCK_SIZE /* Digest is kept internally as 5 32-bit words. */ #define _RIPEMD160_DIGEST_LENGTH 5 @@ -57,7 +59,7 @@ struct ripemd160_ctx { uint32_t state[_RIPEMD160_DIGEST_LENGTH]; uint64_t count; /* 64-bit block count */ - uint8_t block[RIPEMD160_DATA_SIZE]; + uint8_t block[RIPEMD160_BLOCK_SIZE]; unsigned int index; }; diff --git a/sha1.c b/sha1.c index 615212a503193949de251e4459087405e684a4a2..a585727ef6b1a1524e352620dad943e550751d6d 100644 --- a/sha1.c +++ b/sha1.c @@ -92,7 +92,7 @@ sha1_digest(struct sha1_ctx *ctx, bit_count = (ctx->count << 9) | (ctx->index << 3); /* append the 64 bit count */ - WRITE_UINT64(ctx->block + (SHA1_DATA_SIZE - 8), bit_count); + WRITE_UINT64(ctx->block + (SHA1_BLOCK_SIZE - 8), bit_count); _nettle_sha1_compress(ctx->state, ctx->block); _nettle_write_be32(length, digest, ctx->state); diff --git a/sha1.h b/sha1.h index 94711bfabe3c41758c95c4fc4c36b4e1f017aaa1..7500d0c25bead51e8370339cded7f656a7d26fbe 100644 --- a/sha1.h +++ b/sha1.h @@ -48,7 +48,9 @@ extern "C" { /* SHA1 */ #define SHA1_DIGEST_SIZE 20 -#define SHA1_DATA_SIZE 64 +#define SHA1_BLOCK_SIZE 64 +/* For backwards compatibility */ +#define SHA1_DATA_SIZE SHA1_BLOCK_SIZE /* Digest is kept internally as 5 32-bit words. */ #define _SHA1_DIGEST_LENGTH 5 @@ -57,7 +59,7 @@ struct sha1_ctx { uint32_t state[_SHA1_DIGEST_LENGTH]; /* State variables */ uint64_t count; /* 64-bit block count */ - uint8_t block[SHA1_DATA_SIZE]; /* SHA1 data buffer */ + uint8_t block[SHA1_BLOCK_SIZE]; /* SHA1 data buffer */ unsigned int index; /* index into buffer */ }; diff --git a/sha2.h b/sha2.h index acbcc16dd89080b107219cca28cfff8d8b76e5b9..6537c0eceb64d18ad3ce8db685be1cc8e9940838 100644 --- a/sha2.h +++ b/sha2.h @@ -56,10 +56,16 @@ extern "C" { #define sha512_256_init nettle_sha512_256_init #define sha512_256_digest nettle_sha512_256_digest +/* For backwards compatibility */ +#define SHA224_DATA_SIZE SHA256_BLOCK_SIZE +#define SHA256_DATA_SIZE SHA256_BLOCK_SIZE +#define SHA512_DATA_SIZE SHA512_BLOCK_SIZE +#define SHA384_DATA_SIZE SHA512_BLOCK_SIZE + /* SHA256 */ #define SHA256_DIGEST_SIZE 32 -#define SHA256_DATA_SIZE 64 +#define SHA256_BLOCK_SIZE 64 /* Digest is kept internally as 8 32-bit words. */ #define _SHA256_DIGEST_LENGTH 8 @@ -68,7 +74,7 @@ struct sha256_ctx { uint32_t state[_SHA256_DIGEST_LENGTH]; /* State variables */ uint64_t count; /* 64-bit block count */ - uint8_t block[SHA256_DATA_SIZE]; /* SHA256 data buffer */ + uint8_t block[SHA256_BLOCK_SIZE]; /* SHA256 data buffer */ unsigned int index; /* index into buffer */ }; @@ -95,7 +101,7 @@ _nettle_sha256_compress(uint32_t *state, const uint8_t *data, const uint32_t *k) /* SHA224, a truncated SHA256 with different initial state. */ #define SHA224_DIGEST_SIZE 28 -#define SHA224_DATA_SIZE SHA256_DATA_SIZE +#define SHA224_BLOCK_SIZE SHA256_BLOCK_SIZE #define sha224_ctx sha256_ctx void @@ -112,7 +118,7 @@ sha224_digest(struct sha256_ctx *ctx, /* SHA512 */ #define SHA512_DIGEST_SIZE 64 -#define SHA512_DATA_SIZE 128 +#define SHA512_BLOCK_SIZE 128 /* Digest is kept internally as 8 64-bit words. */ #define _SHA512_DIGEST_LENGTH 8 @@ -121,7 +127,7 @@ struct sha512_ctx { uint64_t state[_SHA512_DIGEST_LENGTH]; /* State variables */ uint64_t count_low, count_high; /* 128-bit block count */ - uint8_t block[SHA512_DATA_SIZE]; /* SHA512 data buffer */ + uint8_t block[SHA512_BLOCK_SIZE]; /* SHA512 data buffer */ unsigned int index; /* index into buffer */ }; @@ -148,7 +154,7 @@ _nettle_sha512_compress(uint64_t *state, const uint8_t *data, const uint64_t *k) /* SHA384, a truncated SHA512 with different initial state. */ #define SHA384_DIGEST_SIZE 48 -#define SHA384_DATA_SIZE SHA512_DATA_SIZE +#define SHA384_BLOCK_SIZE SHA512_BLOCK_SIZE #define sha384_ctx sha512_ctx void @@ -166,7 +172,7 @@ sha384_digest(struct sha512_ctx *ctx, with different initial states. */ #define SHA512_224_DIGEST_SIZE 28 -#define SHA512_224_DATA_SIZE SHA512_DATA_SIZE +#define SHA512_224_BLOCK_SIZE SHA512_BLOCK_SIZE #define sha512_224_ctx sha512_ctx void @@ -180,7 +186,7 @@ sha512_224_digest(struct sha512_224_ctx *ctx, uint8_t *digest); #define SHA512_256_DIGEST_SIZE 32 -#define SHA512_256_DATA_SIZE SHA512_DATA_SIZE +#define SHA512_256_BLOCK_SIZE SHA512_BLOCK_SIZE #define sha512_256_ctx sha512_ctx void diff --git a/sha256.c b/sha256.c index 975d13aaf884d19d0634824590e7442da574a2ec..c632b7f4f41a53f509ac68a3826b3d8d23e28e70 100644 --- a/sha256.c +++ b/sha256.c @@ -116,7 +116,7 @@ sha256_write_digest(struct sha256_ctx *ctx, /* This is slightly inefficient, as the numbers are converted to big-endian format, and will be converted back by the compression function. It's probably not worth the effort to fix this. */ - WRITE_UINT64(ctx->block + (SHA256_DATA_SIZE - 8), bit_count); + WRITE_UINT64(ctx->block + (SHA256_BLOCK_SIZE - 8), bit_count); COMPRESS(ctx, ctx->block); _nettle_write_be32(length, digest, ctx->state); diff --git a/sha3-224.c b/sha3-224.c index b4bb23b46c6cde06bdb5e2f49e8285a0db510f50..83fce158e7c5b72596f5371764d68b073a78dd8e 100644 --- a/sha3-224.c +++ b/sha3-224.c @@ -53,7 +53,7 @@ sha3_224_update (struct sha3_224_ctx *ctx, size_t length, const uint8_t *data) { - ctx->index = _sha3_update (&ctx->state, SHA3_224_DATA_SIZE, ctx->block, + ctx->index = _sha3_update (&ctx->state, SHA3_224_BLOCK_SIZE, ctx->block, ctx->index, length, data); } @@ -62,7 +62,7 @@ sha3_224_digest(struct sha3_224_ctx *ctx, size_t length, uint8_t *digest) { - _sha3_pad (&ctx->state, SHA3_224_DATA_SIZE, ctx->block, ctx->index); + _sha3_pad (&ctx->state, SHA3_224_BLOCK_SIZE, ctx->block, ctx->index); _nettle_write_le64 (length, digest, ctx->state.a); sha3_224_init (ctx); } diff --git a/sha3-256.c b/sha3-256.c index d0a00e2bdf1998a866fe0c5525b625ca1ef0a5d9..ca9b02095c6b6a5fd4db590530f606c13581b758 100644 --- a/sha3-256.c +++ b/sha3-256.c @@ -53,7 +53,7 @@ sha3_256_update (struct sha3_256_ctx *ctx, size_t length, const uint8_t *data) { - ctx->index = _sha3_update (&ctx->state, SHA3_256_DATA_SIZE, ctx->block, + ctx->index = _sha3_update (&ctx->state, SHA3_256_BLOCK_SIZE, ctx->block, ctx->index, length, data); } @@ -62,7 +62,7 @@ sha3_256_digest(struct sha3_256_ctx *ctx, size_t length, uint8_t *digest) { - _sha3_pad (&ctx->state, SHA3_256_DATA_SIZE, ctx->block, ctx->index); + _sha3_pad (&ctx->state, SHA3_256_BLOCK_SIZE, ctx->block, ctx->index); _nettle_write_le64 (length, digest, ctx->state.a); sha3_256_init (ctx); } diff --git a/sha3-384.c b/sha3-384.c index 245faaed039faa20f8e97bf3cf42a018426d4b5c..148ba1d3e805bf7b5c3e030903462e8a58104636 100644 --- a/sha3-384.c +++ b/sha3-384.c @@ -53,7 +53,7 @@ sha3_384_update (struct sha3_384_ctx *ctx, size_t length, const uint8_t *data) { - ctx->index = _sha3_update (&ctx->state, SHA3_384_DATA_SIZE, ctx->block, + ctx->index = _sha3_update (&ctx->state, SHA3_384_BLOCK_SIZE, ctx->block, ctx->index, length, data); } @@ -62,7 +62,7 @@ sha3_384_digest(struct sha3_384_ctx *ctx, size_t length, uint8_t *digest) { - _sha3_pad (&ctx->state, SHA3_384_DATA_SIZE, ctx->block, ctx->index); + _sha3_pad (&ctx->state, SHA3_384_BLOCK_SIZE, ctx->block, ctx->index); _nettle_write_le64 (length, digest, ctx->state.a); sha3_384_init (ctx); } diff --git a/sha3-512.c b/sha3-512.c index 7a6de38bc3393f1dee46062c993f10a85dc1f003..145662b0d7e68672af3c0d34490061885995e69f 100644 --- a/sha3-512.c +++ b/sha3-512.c @@ -53,7 +53,7 @@ sha3_512_update (struct sha3_512_ctx *ctx, size_t length, const uint8_t *data) { - ctx->index = _sha3_update (&ctx->state, SHA3_512_DATA_SIZE, ctx->block, + ctx->index = _sha3_update (&ctx->state, SHA3_512_BLOCK_SIZE, ctx->block, ctx->index, length, data); } @@ -62,7 +62,7 @@ sha3_512_digest(struct sha3_512_ctx *ctx, size_t length, uint8_t *digest) { - _sha3_pad (&ctx->state, SHA3_512_DATA_SIZE, ctx->block, ctx->index); + _sha3_pad (&ctx->state, SHA3_512_BLOCK_SIZE, ctx->block, ctx->index); _nettle_write_le64 (length, digest, ctx->state.a); sha3_512_init (ctx); } diff --git a/sha3.h b/sha3.h index 897bbdd5fe565572c694f7ff869a9b532ddd8b19..6435ad62dc4cb3846964d584e779f31af30e4784 100644 --- a/sha3.h +++ b/sha3.h @@ -85,23 +85,28 @@ _sha3_pad (struct sha3_state *state, size). */ #define SHA3_224_DIGEST_SIZE 28 -#define SHA3_224_DATA_SIZE 144 +#define SHA3_224_BLOCK_SIZE 144 #define SHA3_256_DIGEST_SIZE 32 -#define SHA3_256_DATA_SIZE 136 +#define SHA3_256_BLOCK_SIZE 136 #define SHA3_384_DIGEST_SIZE 48 -#define SHA3_384_DATA_SIZE 104 +#define SHA3_384_BLOCK_SIZE 104 #define SHA3_512_DIGEST_SIZE 64 -#define SHA3_512_DATA_SIZE 72 +#define SHA3_512_BLOCK_SIZE 72 +/* For backwards compatibility */ +#define SHA3_224_DATA_SIZE SHA3_224_BLOCK_SIZE +#define SHA3_256_DATA_SIZE SHA3_256_BLOCK_SIZE +#define SHA3_384_DATA_SIZE SHA3_384_BLOCK_SIZE +#define SHA3_512_DATA_SIZE SHA3_512_BLOCK_SIZE struct sha3_224_ctx { struct sha3_state state; unsigned index; - uint8_t block[SHA3_224_DATA_SIZE]; + uint8_t block[SHA3_224_BLOCK_SIZE]; }; void @@ -121,7 +126,7 @@ struct sha3_256_ctx { struct sha3_state state; unsigned index; - uint8_t block[SHA3_256_DATA_SIZE]; + uint8_t block[SHA3_256_BLOCK_SIZE]; }; void @@ -141,7 +146,7 @@ struct sha3_384_ctx { struct sha3_state state; unsigned index; - uint8_t block[SHA3_384_DATA_SIZE]; + uint8_t block[SHA3_384_BLOCK_SIZE]; }; void @@ -161,7 +166,7 @@ struct sha3_512_ctx { struct sha3_state state; unsigned index; - uint8_t block[SHA3_512_DATA_SIZE]; + uint8_t block[SHA3_512_BLOCK_SIZE]; }; void diff --git a/sha512-224-meta.c b/sha512-224-meta.c index f86e5992b886ad83f2a06d67775aa64740c70a93..24c42bfc23d9edaa1583878d41e08ecb6a10eb58 100644 --- a/sha512-224-meta.c +++ b/sha512-224-meta.c @@ -41,7 +41,7 @@ const struct nettle_hash nettle_sha512_224 = { "sha512-224", sizeof(struct sha512_ctx), SHA512_224_DIGEST_SIZE, - SHA512_224_DATA_SIZE, + SHA512_224_BLOCK_SIZE, (nettle_hash_init_func *) sha512_224_init, (nettle_hash_update_func *) sha512_224_update, (nettle_hash_digest_func *) sha512_224_digest diff --git a/sha512-256-meta.c b/sha512-256-meta.c index c1733a3861e4f0ba1ee37641a3ba4fb4457b2cb5..37d17c3518783dbe5612866759a6ba75b02f9005 100644 --- a/sha512-256-meta.c +++ b/sha512-256-meta.c @@ -41,7 +41,7 @@ const struct nettle_hash nettle_sha512_256 = { "sha512-256", sizeof(struct sha512_ctx), SHA512_256_DIGEST_SIZE, - SHA512_256_DATA_SIZE, + SHA512_256_BLOCK_SIZE, (nettle_hash_init_func *) sha512_256_init, (nettle_hash_update_func *) sha512_256_update, (nettle_hash_digest_func *) sha512_256_digest diff --git a/sha512.c b/sha512.c index e01658ced8bfb77e97b3134f393d8a62fca0fd4b..249c4f057a9b7231713d6efe759df0af0ea71729 100644 --- a/sha512.c +++ b/sha512.c @@ -172,8 +172,8 @@ sha512_write_digest(struct sha512_ctx *ctx, /* This is slightly inefficient, as the numbers are converted to big-endian format, and will be converted back by the compression function. It's probably not worth the effort to fix this. */ - WRITE_UINT64(ctx->block + (SHA512_DATA_SIZE - 16), high); - WRITE_UINT64(ctx->block + (SHA512_DATA_SIZE - 8), low); + WRITE_UINT64(ctx->block + (SHA512_BLOCK_SIZE - 16), high); + WRITE_UINT64(ctx->block + (SHA512_BLOCK_SIZE - 8), low); COMPRESS(ctx, ctx->block); words = length / 8; diff --git a/umac-set-key.c b/umac-set-key.c index fa4ca6b78e0fa5bdcdb4a3caa43e736614f9c239..13a9589c8924def59fce479e0a653eceb90f1f5a 100644 --- a/umac-set-key.c +++ b/umac-set-key.c @@ -86,7 +86,7 @@ _umac_set_key (uint32_t *l1_key, uint32_t *l2_key, aes128_set_encrypt_key (aes, key); - size = UMAC_DATA_SIZE / 4 + 4*(n-1); + size = UMAC_BLOCK_SIZE / 4 + 4*(n-1); umac_kdf (aes, 1, size * sizeof(uint32_t), (uint8_t *) l1_key); BE_SWAP32_N (size, l1_key); diff --git a/umac.h b/umac.h index 7749353b22ed3390fa49cb43badf58bebd22b53c..1136fcdc167ab6f38b1cb98a4bee9a17ed392820 100644 --- a/umac.h +++ b/umac.h @@ -74,11 +74,13 @@ extern "C" { #define UMAC64_DIGEST_SIZE 8 #define UMAC96_DIGEST_SIZE 12 #define UMAC128_DIGEST_SIZE 16 -#define UMAC_DATA_SIZE 1024 +#define UMAC_BLOCK_SIZE 1024 +/* For backwards compatibility */ +#define UMAC_DATA_SIZE UMAC_BLOCK_SIZE /* Subkeys and state for UMAC with tag size 32*n bits. */ #define _UMAC_STATE(n) \ - uint32_t l1_key[UMAC_DATA_SIZE/4 + 4*((n)-1)]; \ + uint32_t l1_key[UMAC_BLOCK_SIZE/4 + 4*((n)-1)]; \ /* Keys in 32-bit pieces, high first */ \ uint32_t l2_key[6*(n)]; \ uint64_t l3_key1[8*(n)]; \ @@ -99,7 +101,7 @@ extern "C" { unsigned index; \ /* Complete blocks processed */ \ uint64_t count; \ - uint8_t block[UMAC_DATA_SIZE] + uint8_t block[UMAC_BLOCK_SIZE] #define _UMAC_NONCE_CACHED 0x80 diff --git a/umac128.c b/umac128.c index 688f7519a95fbb96c802d289132f9c0678433315..d0c607e87399eb8b45e16ebc6e32fc55c1b03c0a 100644 --- a/umac128.c +++ b/umac128.c @@ -69,11 +69,11 @@ umac128_set_nonce (struct umac128_ctx *ctx, #define UMAC128_BLOCK(ctx, block) do { \ uint64_t __umac128_y[4]; \ - _umac_nh_n (__umac128_y, 4, ctx->l1_key, UMAC_DATA_SIZE, block); \ - __umac128_y[0] += 8*UMAC_DATA_SIZE; \ - __umac128_y[1] += 8*UMAC_DATA_SIZE; \ - __umac128_y[2] += 8*UMAC_DATA_SIZE; \ - __umac128_y[3] += 8*UMAC_DATA_SIZE; \ + _umac_nh_n (__umac128_y, 4, ctx->l1_key, UMAC_BLOCK_SIZE, block); \ + __umac128_y[0] += 8*UMAC_BLOCK_SIZE; \ + __umac128_y[1] += 8*UMAC_BLOCK_SIZE; \ + __umac128_y[2] += 8*UMAC_BLOCK_SIZE; \ + __umac128_y[3] += 8*UMAC_BLOCK_SIZE; \ _umac_l2 (ctx->l2_key, ctx->l2_state, 4, ctx->count++, __umac128_y); \ } while (0) diff --git a/umac32.c b/umac32.c index 427c500ec9d3fe23a15e3fdbf3a7765001e2bd82..32f34c39503b958eafb7f6afd171779fc70c7a0f 100644 --- a/umac32.c +++ b/umac32.c @@ -72,8 +72,8 @@ umac32_set_nonce (struct umac32_ctx *ctx, #define UMAC32_BLOCK(ctx, block) do { \ uint64_t __umac32_y \ - = _umac_nh (ctx->l1_key, UMAC_DATA_SIZE, block) \ - + 8*UMAC_DATA_SIZE ; \ + = _umac_nh (ctx->l1_key, UMAC_BLOCK_SIZE, block) \ + + 8*UMAC_BLOCK_SIZE ; \ _umac_l2 (ctx->l2_key, ctx->l2_state, 1, ctx->count++, &__umac32_y); \ } while (0) diff --git a/umac64.c b/umac64.c index 179df9a0f7ae0bfb0c5bb9725282c3f10339b2cf..a1122cb19439f48a0599d07b82898eed81f28178 100644 --- a/umac64.c +++ b/umac64.c @@ -72,9 +72,9 @@ umac64_set_nonce (struct umac64_ctx *ctx, #define UMAC64_BLOCK(ctx, block) do { \ uint64_t __umac64_y[2]; \ - _umac_nh_n (__umac64_y, 2, ctx->l1_key, UMAC_DATA_SIZE, block); \ - __umac64_y[0] += 8*UMAC_DATA_SIZE; \ - __umac64_y[1] += 8*UMAC_DATA_SIZE; \ + _umac_nh_n (__umac64_y, 2, ctx->l1_key, UMAC_BLOCK_SIZE, block); \ + __umac64_y[0] += 8*UMAC_BLOCK_SIZE; \ + __umac64_y[1] += 8*UMAC_BLOCK_SIZE; \ _umac_l2 (ctx->l2_key, ctx->l2_state, 2, ctx->count++, __umac64_y); \ } while (0) diff --git a/umac96.c b/umac96.c index d4d9b88acb0f31e46b82d10723acf77be9ebddd8..8d72f1bf8ccb3f800d801c6bca7032366cd4420d 100644 --- a/umac96.c +++ b/umac96.c @@ -69,10 +69,10 @@ umac96_set_nonce (struct umac96_ctx *ctx, #define UMAC96_BLOCK(ctx, block) do { \ uint64_t __umac96_y[3]; \ - _umac_nh_n (__umac96_y, 3, ctx->l1_key, UMAC_DATA_SIZE, block); \ - __umac96_y[0] += 8*UMAC_DATA_SIZE; \ - __umac96_y[1] += 8*UMAC_DATA_SIZE; \ - __umac96_y[2] += 8*UMAC_DATA_SIZE; \ + _umac_nh_n (__umac96_y, 3, ctx->l1_key, UMAC_BLOCK_SIZE, block); \ + __umac96_y[0] += 8*UMAC_BLOCK_SIZE; \ + __umac96_y[1] += 8*UMAC_BLOCK_SIZE; \ + __umac96_y[2] += 8*UMAC_BLOCK_SIZE; \ _umac_l2 (ctx->l2_key, ctx->l2_state, 3, ctx->count++, __umac96_y); \ } while (0)