diff options
author | bcook <> | 2015-12-09 14:07:55 +0000 |
---|---|---|
committer | bcook <> | 2015-12-09 14:07:55 +0000 |
commit | 3b38beae4913121962004a094d64b29030a1ba28 (patch) | |
tree | 1fd23b20d3830264a735dfa139cc354f0d92098e | |
parent | 52aece27155bb299c87b2af8d286f2cef62fb70a (diff) | |
download | openbsd-3b38beae4913121962004a094d64b29030a1ba28.tar.gz openbsd-3b38beae4913121962004a094d64b29030a1ba28.tar.bz2 openbsd-3b38beae4913121962004a094d64b29030a1ba28.zip |
Change the counter argument for CRYPTO_chacha_20 to be 64-bits on all platforms.
The recently-added EVP_aead_chacha20_poly1305_ietf() function, which implements
informational RFC 7539, "ChaCha20 and Poly1305 for IETF Protocols", needs a
64-bit counter to avoid truncation on 32-bit platforms.
The existing TLS ChaCha20-Poly1305 ciphersuite is not impacted by this, but
making this change requires an ABI bump.
ok jsing@, "Looks sane" beck@
-rw-r--r-- | src/lib/libcrypto/chacha/chacha.c | 6 | ||||
-rw-r--r-- | src/lib/libcrypto/chacha/chacha.h | 5 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/chacha/chacha.c | 6 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/chacha/chacha.h | 5 |
4 files changed, 12 insertions, 10 deletions
diff --git a/src/lib/libcrypto/chacha/chacha.c b/src/lib/libcrypto/chacha/chacha.c index b8422306fa..0c384ab88a 100644 --- a/src/lib/libcrypto/chacha/chacha.c +++ b/src/lib/libcrypto/chacha/chacha.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: chacha.c,v 1.6 2014/07/08 14:30:23 bcook Exp $ */ | 1 | /* $OpenBSD: chacha.c,v 1.7 2015/12/09 14:07:55 bcook Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> |
4 | * | 4 | * |
@@ -57,7 +57,7 @@ ChaCha(ChaCha_ctx *ctx, unsigned char *out, const unsigned char *in, size_t len) | |||
57 | 57 | ||
58 | void | 58 | void |
59 | CRYPTO_chacha_20(unsigned char *out, const unsigned char *in, size_t len, | 59 | CRYPTO_chacha_20(unsigned char *out, const unsigned char *in, size_t len, |
60 | const unsigned char key[32], const unsigned char iv[8], size_t counter) | 60 | const unsigned char key[32], const unsigned char iv[8], uint64_t counter) |
61 | { | 61 | { |
62 | struct chacha_ctx ctx; | 62 | struct chacha_ctx ctx; |
63 | 63 | ||
@@ -70,7 +70,7 @@ CRYPTO_chacha_20(unsigned char *out, const unsigned char *in, size_t len, | |||
70 | chacha_ivsetup(&ctx, iv, NULL); | 70 | chacha_ivsetup(&ctx, iv, NULL); |
71 | if (counter != 0) { | 71 | if (counter != 0) { |
72 | ctx.input[12] = (uint32_t)counter; | 72 | ctx.input[12] = (uint32_t)counter; |
73 | ctx.input[13] = (uint32_t)(((uint64_t)counter) >> 32); | 73 | ctx.input[13] = (uint32_t)(counter >> 32); |
74 | } | 74 | } |
75 | 75 | ||
76 | chacha_encrypt_bytes(&ctx, in, out, (uint32_t)len); | 76 | chacha_encrypt_bytes(&ctx, in, out, (uint32_t)len); |
diff --git a/src/lib/libcrypto/chacha/chacha.h b/src/lib/libcrypto/chacha/chacha.h index 8af5ef856f..8d94e626f8 100644 --- a/src/lib/libcrypto/chacha/chacha.h +++ b/src/lib/libcrypto/chacha/chacha.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: chacha.h,v 1.6 2014/07/25 14:04:51 jsing Exp $ */ | 1 | /* $OpenBSD: chacha.h,v 1.7 2015/12/09 14:07:55 bcook Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> |
4 | * | 4 | * |
@@ -25,6 +25,7 @@ | |||
25 | #endif | 25 | #endif |
26 | 26 | ||
27 | #include <stddef.h> | 27 | #include <stddef.h> |
28 | #include <stdint.h> | ||
28 | 29 | ||
29 | #ifdef __cplusplus | 30 | #ifdef __cplusplus |
30 | extern "C" { | 31 | extern "C" { |
@@ -44,7 +45,7 @@ void ChaCha(ChaCha_ctx *ctx, unsigned char *out, const unsigned char *in, | |||
44 | size_t len); | 45 | size_t len); |
45 | 46 | ||
46 | void CRYPTO_chacha_20(unsigned char *out, const unsigned char *in, size_t len, | 47 | void CRYPTO_chacha_20(unsigned char *out, const unsigned char *in, size_t len, |
47 | const unsigned char key[32], const unsigned char iv[8], size_t counter); | 48 | const unsigned char key[32], const unsigned char iv[8], uint64_t counter); |
48 | 49 | ||
49 | #ifdef __cplusplus | 50 | #ifdef __cplusplus |
50 | } | 51 | } |
diff --git a/src/lib/libssl/src/crypto/chacha/chacha.c b/src/lib/libssl/src/crypto/chacha/chacha.c index b8422306fa..0c384ab88a 100644 --- a/src/lib/libssl/src/crypto/chacha/chacha.c +++ b/src/lib/libssl/src/crypto/chacha/chacha.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: chacha.c,v 1.6 2014/07/08 14:30:23 bcook Exp $ */ | 1 | /* $OpenBSD: chacha.c,v 1.7 2015/12/09 14:07:55 bcook Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> |
4 | * | 4 | * |
@@ -57,7 +57,7 @@ ChaCha(ChaCha_ctx *ctx, unsigned char *out, const unsigned char *in, size_t len) | |||
57 | 57 | ||
58 | void | 58 | void |
59 | CRYPTO_chacha_20(unsigned char *out, const unsigned char *in, size_t len, | 59 | CRYPTO_chacha_20(unsigned char *out, const unsigned char *in, size_t len, |
60 | const unsigned char key[32], const unsigned char iv[8], size_t counter) | 60 | const unsigned char key[32], const unsigned char iv[8], uint64_t counter) |
61 | { | 61 | { |
62 | struct chacha_ctx ctx; | 62 | struct chacha_ctx ctx; |
63 | 63 | ||
@@ -70,7 +70,7 @@ CRYPTO_chacha_20(unsigned char *out, const unsigned char *in, size_t len, | |||
70 | chacha_ivsetup(&ctx, iv, NULL); | 70 | chacha_ivsetup(&ctx, iv, NULL); |
71 | if (counter != 0) { | 71 | if (counter != 0) { |
72 | ctx.input[12] = (uint32_t)counter; | 72 | ctx.input[12] = (uint32_t)counter; |
73 | ctx.input[13] = (uint32_t)(((uint64_t)counter) >> 32); | 73 | ctx.input[13] = (uint32_t)(counter >> 32); |
74 | } | 74 | } |
75 | 75 | ||
76 | chacha_encrypt_bytes(&ctx, in, out, (uint32_t)len); | 76 | chacha_encrypt_bytes(&ctx, in, out, (uint32_t)len); |
diff --git a/src/lib/libssl/src/crypto/chacha/chacha.h b/src/lib/libssl/src/crypto/chacha/chacha.h index 8af5ef856f..8d94e626f8 100644 --- a/src/lib/libssl/src/crypto/chacha/chacha.h +++ b/src/lib/libssl/src/crypto/chacha/chacha.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: chacha.h,v 1.6 2014/07/25 14:04:51 jsing Exp $ */ | 1 | /* $OpenBSD: chacha.h,v 1.7 2015/12/09 14:07:55 bcook Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> |
4 | * | 4 | * |
@@ -25,6 +25,7 @@ | |||
25 | #endif | 25 | #endif |
26 | 26 | ||
27 | #include <stddef.h> | 27 | #include <stddef.h> |
28 | #include <stdint.h> | ||
28 | 29 | ||
29 | #ifdef __cplusplus | 30 | #ifdef __cplusplus |
30 | extern "C" { | 31 | extern "C" { |
@@ -44,7 +45,7 @@ void ChaCha(ChaCha_ctx *ctx, unsigned char *out, const unsigned char *in, | |||
44 | size_t len); | 45 | size_t len); |
45 | 46 | ||
46 | void CRYPTO_chacha_20(unsigned char *out, const unsigned char *in, size_t len, | 47 | void CRYPTO_chacha_20(unsigned char *out, const unsigned char *in, size_t len, |
47 | const unsigned char key[32], const unsigned char iv[8], size_t counter); | 48 | const unsigned char key[32], const unsigned char iv[8], uint64_t counter); |
48 | 49 | ||
49 | #ifdef __cplusplus | 50 | #ifdef __cplusplus |
50 | } | 51 | } |