diff options
author | tb <> | 2018-10-20 15:53:09 +0000 |
---|---|---|
committer | tb <> | 2018-10-20 15:53:09 +0000 |
commit | 108b29f9d3967dd1e6f2189a83fe627e333b132d (patch) | |
tree | c1c9cf6f754c100c2d8aadb09fc31faf71b335c2 | |
parent | bd9d0fa01a7b5e725f3ae942e2d42284412f124f (diff) | |
download | openbsd-108b29f9d3967dd1e6f2189a83fe627e333b132d.tar.gz openbsd-108b29f9d3967dd1e6f2189a83fe627e333b132d.tar.bz2 openbsd-108b29f9d3967dd1e6f2189a83fe627e333b132d.zip |
RFC 3394 section 2 states that we need at least two 64 bit blocks
for wrapping and, accordingly, three 64 bit blocks for unwrapping.
That is: we need at least 16 bytes for wrapping and 24 bytes for
unwrapping. This also matches the lower bounds that OpenSSL have
in their CRYPTO_128_{un,}wrap() functions.
In fact, if we pass an input with 'inlen < 8' to AES_unwrap_key(),
this results in a segfault since then inlen -= 8 underflows.
Found while playing with the Wycheproof keywrap test vectors.
ok bcook
-rw-r--r-- | src/lib/libcrypto/aes/aes_wrap.c | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/lib/libcrypto/aes/aes_wrap.c b/src/lib/libcrypto/aes/aes_wrap.c index ac2f83a993..b7e08ab75f 100644 --- a/src/lib/libcrypto/aes/aes_wrap.c +++ b/src/lib/libcrypto/aes/aes_wrap.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: aes_wrap.c,v 1.10 2015/09/10 15:56:24 jsing Exp $ */ | 1 | /* $OpenBSD: aes_wrap.c,v 1.11 2018/10/20 15:53:09 tb Exp $ */ |
2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL |
3 | * project. | 3 | * project. |
4 | */ | 4 | */ |
@@ -66,7 +66,8 @@ AES_wrap_key(AES_KEY *key, const unsigned char *iv, unsigned char *out, | |||
66 | { | 66 | { |
67 | unsigned char *A, B[16], *R; | 67 | unsigned char *A, B[16], *R; |
68 | unsigned int i, j, t; | 68 | unsigned int i, j, t; |
69 | if ((inlen & 0x7) || (inlen < 8)) | 69 | |
70 | if ((inlen & 0x7) || (inlen < 16)) | ||
70 | return -1; | 71 | return -1; |
71 | A = B; | 72 | A = B; |
72 | t = 1; | 73 | t = 1; |
@@ -100,11 +101,10 @@ AES_unwrap_key(AES_KEY *key, const unsigned char *iv, unsigned char *out, | |||
100 | { | 101 | { |
101 | unsigned char *A, B[16], *R; | 102 | unsigned char *A, B[16], *R; |
102 | unsigned int i, j, t; | 103 | unsigned int i, j, t; |
103 | inlen -= 8; | 104 | |
104 | if (inlen & 0x7) | 105 | if ((inlen & 0x7) || (inlen < 24)) |
105 | return -1; | ||
106 | if (inlen < 8) | ||
107 | return -1; | 106 | return -1; |
107 | inlen -= 8; | ||
108 | A = B; | 108 | A = B; |
109 | t = 6 * (inlen >> 3); | 109 | t = 6 * (inlen >> 3); |
110 | memcpy(A, in, 8); | 110 | memcpy(A, in, 8); |