From c87d9f38f8eef3bc65e2f00e061d471622979fac Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Tue, 1 Jul 2014 19:27:34 +0000 Subject: [PATCH 1/4] Having dead code in the tree is sad, but keeps the diff with the reference implementation to a minimum. --- .../crypto_generichash/blake2/ref/blake2b-ref.c | 11 ++++++----- .../crypto_generichash/blake2/ref/blake2s-ref.c | 11 ++++++----- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/libsodium/crypto_generichash/blake2/ref/blake2b-ref.c b/src/libsodium/crypto_generichash/blake2/ref/blake2b-ref.c index 1ae6b926..9cc7ede5 100644 --- a/src/libsodium/crypto_generichash/blake2/ref/blake2b-ref.c +++ b/src/libsodium/crypto_generichash/blake2/ref/blake2b-ref.c @@ -48,13 +48,13 @@ static inline int blake2b_set_lastnode( blake2b_state *S ) S->f[1] = ~0ULL; return 0; } - +#if 0 static inline int blake2b_clear_lastnode( blake2b_state *S ) { S->f[1] = 0ULL; return 0; } - +#endif /* Some helper functions, not necessarily useful */ static inline int blake2b_set_lastblock( blake2b_state *S ) { @@ -63,7 +63,7 @@ static inline int blake2b_set_lastblock( blake2b_state *S ) S->f[0] = ~0ULL; return 0; } - +#if 0 static inline int blake2b_clear_lastblock( blake2b_state *S ) { if( S->last_node ) blake2b_clear_lastnode( S ); @@ -71,7 +71,7 @@ static inline int blake2b_clear_lastblock( blake2b_state *S ) S->f[0] = 0ULL; return 0; } - +#endif static inline int blake2b_increment_counter( blake2b_state *S, const uint64_t inc ) { S->t[0] += inc; @@ -82,6 +82,7 @@ static inline int blake2b_increment_counter( blake2b_state *S, const uint64_t in // Parameter-related functions +#if 0 static inline int blake2b_param_set_digest_length( blake2b_param *P, const uint8_t digest_length ) { P->digest_length = digest_length; @@ -123,7 +124,7 @@ static inline int blake2b_param_set_inner_length( blake2b_param *P, const uint8_ P->inner_length = inner_length; return 0; } - +#endif static inline int blake2b_param_set_salt( blake2b_param *P, const uint8_t salt[BLAKE2B_SALTBYTES] ) { memcpy( P->salt, salt, BLAKE2B_SALTBYTES ); diff --git a/src/libsodium/crypto_generichash/blake2/ref/blake2s-ref.c b/src/libsodium/crypto_generichash/blake2/ref/blake2s-ref.c index 3103c31c..0e79aa52 100644 --- a/src/libsodium/crypto_generichash/blake2/ref/blake2s-ref.c +++ b/src/libsodium/crypto_generichash/blake2/ref/blake2s-ref.c @@ -44,13 +44,13 @@ static inline int blake2s_set_lastnode( blake2s_state *S ) S->f[1] = ~0U; return 0; } - +#if 0 static inline int blake2s_clear_lastnode( blake2s_state *S ) { S->f[1] = 0U; return 0; } - +#endif /* Some helper functions, not necessarily useful */ static inline int blake2s_set_lastblock( blake2s_state *S ) { @@ -59,7 +59,7 @@ static inline int blake2s_set_lastblock( blake2s_state *S ) S->f[0] = ~0U; return 0; } - +#if 0 static inline int blake2s_clear_lastblock( blake2s_state *S ) { if( S->last_node ) blake2s_clear_lastnode( S ); @@ -67,7 +67,7 @@ static inline int blake2s_clear_lastblock( blake2s_state *S ) S->f[0] = 0U; return 0; } - +#endif static inline int blake2s_increment_counter( blake2s_state *S, const uint32_t inc ) { S->t[0] += inc; @@ -76,6 +76,7 @@ static inline int blake2s_increment_counter( blake2s_state *S, const uint32_t in } // Parameter-related functions +#if 0 static inline int blake2s_param_set_digest_length( blake2s_param *P, const uint8_t digest_length ) { P->digest_length = digest_length; @@ -117,7 +118,7 @@ static inline int blake2s_param_set_inner_length( blake2s_param *P, const uint8_ P->inner_length = inner_length; return 0; } - +#endif static inline int blake2s_param_set_salt( blake2s_param *P, const uint8_t salt[BLAKE2S_SALTBYTES] ) { memcpy( P->salt, salt, BLAKE2S_SALTBYTES ); From 0e4f4d6205f6ce7db7c2fd04444bf1767437a904 Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Tue, 1 Jul 2014 19:33:59 +0000 Subject: [PATCH 2/4] Use unsigned types for sizes in tests. --- test/default/box_easy.c | 2 +- test/default/secretbox_easy.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/default/box_easy.c b/test/default/box_easy.c index 10319879..d3b899fc 100644 --- a/test/default/box_easy.c +++ b/test/default/box_easy.c @@ -47,7 +47,7 @@ unsigned char c[147 + crypto_box_MACBYTES]; int main(void) { - int i; + size_t i; crypto_box_easy(c, m, 131, nonce, bobpk, alicesk); for (i = 0; i < 131 + crypto_box_MACBYTES; ++i) { diff --git a/test/default/secretbox_easy.c b/test/default/secretbox_easy.c index 48f4e76a..dc3f3bd9 100644 --- a/test/default/secretbox_easy.c +++ b/test/default/secretbox_easy.c @@ -41,7 +41,7 @@ unsigned char mac[crypto_secretbox_MACBYTES]; int main(void) { - int i; + size_t i; crypto_secretbox_easy(c, m, 131, nonce, firstkey); for (i = 0;i < 131 + crypto_secretbox_MACBYTES; ++i) { From e3d915143a5590ed5a7781a6a90703dad1b10ce7 Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Tue, 1 Jul 2014 12:37:13 -0700 Subject: [PATCH 3/4] Use unsigned constants for all sizes --- .../sodium/crypto_pwhash_scryptsalsa208sha256.h | 12 ++++++------ .../include/sodium/crypto_scalarmult_curve25519.h | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/libsodium/include/sodium/crypto_pwhash_scryptsalsa208sha256.h b/src/libsodium/include/sodium/crypto_pwhash_scryptsalsa208sha256.h index 68bd5508..7de83955 100644 --- a/src/libsodium/include/sodium/crypto_pwhash_scryptsalsa208sha256.h +++ b/src/libsodium/include/sodium/crypto_pwhash_scryptsalsa208sha256.h @@ -12,27 +12,27 @@ extern "C" { #endif -#define crypto_pwhash_scryptsalsa208sha256_SALTBYTES 32 +#define crypto_pwhash_scryptsalsa208sha256_SALTBYTES 32U SODIUM_EXPORT size_t crypto_pwhash_scryptsalsa208sha256_saltbytes(void); -#define crypto_pwhash_scryptsalsa208sha256_STRBYTES 102 +#define crypto_pwhash_scryptsalsa208sha256_STRBYTES 102U SODIUM_EXPORT size_t crypto_pwhash_scryptsalsa208sha256_strbytes(void); -#define crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_INTERACTIVE 524288 +#define crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_INTERACTIVE 524288ULL SODIUM_EXPORT size_t crypto_pwhash_scryptsalsa208sha256_opslimit_interactive(void); -#define crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_INTERACTIVE 16777216 +#define crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_INTERACTIVE 16777216ULL SODIUM_EXPORT size_t crypto_pwhash_scryptsalsa208sha256_memlimit_interactive(void); -#define crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_SENSITIVE 33554432 +#define crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_SENSITIVE 33554432ULL SODIUM_EXPORT size_t crypto_pwhash_scryptsalsa208sha256_opslimit_sensitive(void); -#define crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_SENSITIVE 1073741824 +#define crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_SENSITIVE 1073741824ULL SODIUM_EXPORT size_t crypto_pwhash_scryptsalsa208sha256_memlimit_sensitive(void); diff --git a/src/libsodium/include/sodium/crypto_scalarmult_curve25519.h b/src/libsodium/include/sodium/crypto_scalarmult_curve25519.h index 50b6744a..c75d2242 100644 --- a/src/libsodium/include/sodium/crypto_scalarmult_curve25519.h +++ b/src/libsodium/include/sodium/crypto_scalarmult_curve25519.h @@ -9,11 +9,11 @@ extern "C" { #endif -#define crypto_scalarmult_curve25519_BYTES 32 +#define crypto_scalarmult_curve25519_BYTES 32U SODIUM_EXPORT size_t crypto_scalarmult_curve25519_bytes(void); -#define crypto_scalarmult_curve25519_SCALARBYTES 32 +#define crypto_scalarmult_curve25519_SCALARBYTES 32U SODIUM_EXPORT size_t crypto_scalarmult_curve25519_scalarbytes(void); From 1089ab4824c6ca3da837dca11c1e0a0b3295e028 Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Tue, 1 Jul 2014 16:35:34 -0700 Subject: [PATCH 4/4] Shave a few lines in the ChangeLog file --- ChangeLog | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index f5470681..69377fdf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,7 +1,6 @@ * Version 0.6.0 - - The ChaCha20 stream cipher has been added, as -crypto_stream_chacha20_* + - The ChaCha20 stream cipher has been added, as crypto_stream_chacha20_* - The ChaCha20Poly1305 AEAD construction has been implemented, as crypto_aead_chacha20poly1305_* - The _easy API does not require any heap allocations any more and @@ -17,15 +16,14 @@ allows setting individual parameters of the scrypt function. - New macros and functions for recommended crypto_pwhash_* parameters have been added. - Similarly to crypto_sign_seed_keypair(), crypto_box_seed_keypair() -has been introduced to deterministically generate a key pair from a -seed. +has been introduced to deterministically generate a key pair from a seed. - crypto_onetimeauth() now provides a streaming interface. - crypto_stream_chacha20_xor_ic() and crypto_stream_salsa20_xor_ic() have been added to use a non-zero initial block counter. - On Windows, CryptGenRandom() was replaced by RtlGenRandom(), which doesn't require the Crypt API. - - The high bit in curve25519 is masked instead of processing the -key as a 256-bit value. + - The high bit in curve25519 is masked instead of processing the key as +a 256-bit value. - The curve25519 ref implementation was replaced by the latest ref10 implementation from Supercop. - sodium_mlock() now prevents memory from being included in coredumps