diff options
Diffstat (limited to '')
| -rw-r--r-- | src/lib/libcrypto/aes/aes_wrap.c | 129 | ||||
| -rw-r--r-- | src/lib/libssl/src/crypto/aes/aes_wrap.c | 129 | ||||
| -rw-r--r-- | src/regress/lib/libcrypto/aeswrap/Makefile | 7 | ||||
| -rw-r--r-- | src/regress/lib/libcrypto/aeswrap/aes_wrap.c | 181 |
4 files changed, 182 insertions, 264 deletions
diff --git a/src/lib/libcrypto/aes/aes_wrap.c b/src/lib/libcrypto/aes/aes_wrap.c index 4a830da7e4..0e8836d8f2 100644 --- a/src/lib/libcrypto/aes/aes_wrap.c +++ b/src/lib/libcrypto/aes/aes_wrap.c | |||
| @@ -130,132 +130,3 @@ AES_unwrap_key(AES_KEY *key, const unsigned char *iv, unsigned char *out, | |||
| 130 | } | 130 | } |
| 131 | return inlen; | 131 | return inlen; |
| 132 | } | 132 | } |
| 133 | |||
| 134 | #ifdef AES_WRAP_TEST | ||
| 135 | |||
| 136 | int | ||
| 137 | AES_wrap_unwrap_test(const unsigned char *kek, int keybits, | ||
| 138 | const unsigned char *iv, const unsigned char *eout, | ||
| 139 | const unsigned char *key, int keylen) | ||
| 140 | { | ||
| 141 | unsigned char *otmp = NULL, *ptmp = NULL; | ||
| 142 | int r, ret = 0; | ||
| 143 | AES_KEY wctx; | ||
| 144 | otmp = malloc(keylen + 8); | ||
| 145 | ptmp = malloc(keylen); | ||
| 146 | if (!otmp || !ptmp) | ||
| 147 | return 0; | ||
| 148 | if (AES_set_encrypt_key(kek, keybits, &wctx)) | ||
| 149 | goto err; | ||
| 150 | r = AES_wrap_key(&wctx, iv, otmp, key, keylen); | ||
| 151 | if (r <= 0) | ||
| 152 | goto err; | ||
| 153 | |||
| 154 | if (eout && memcmp(eout, otmp, keylen)) | ||
| 155 | goto err; | ||
| 156 | |||
| 157 | if (AES_set_decrypt_key(kek, keybits, &wctx)) | ||
| 158 | goto err; | ||
| 159 | r = AES_unwrap_key(&wctx, iv, ptmp, otmp, r); | ||
| 160 | |||
| 161 | if (memcmp(key, ptmp, keylen)) | ||
| 162 | goto err; | ||
| 163 | |||
| 164 | ret = 1; | ||
| 165 | |||
| 166 | err: | ||
| 167 | free(otmp); | ||
| 168 | free(ptmp); | ||
| 169 | |||
| 170 | return ret; | ||
| 171 | } | ||
| 172 | |||
| 173 | |||
| 174 | int | ||
| 175 | main(int argc, char **argv) | ||
| 176 | { | ||
| 177 | static const unsigned char kek[] = { | ||
| 178 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, | ||
| 179 | 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, | ||
| 180 | 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, | ||
| 181 | 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f | ||
| 182 | }; | ||
| 183 | |||
| 184 | static const unsigned char key[] = { | ||
| 185 | 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, | ||
| 186 | 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, | ||
| 187 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, | ||
| 188 | 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f | ||
| 189 | }; | ||
| 190 | |||
| 191 | static const unsigned char e1[] = { | ||
| 192 | 0x1f, 0xa6, 0x8b, 0x0a, 0x81, 0x12, 0xb4, 0x47, | ||
| 193 | 0xae, 0xf3, 0x4b, 0xd8, 0xfb, 0x5a, 0x7b, 0x82, | ||
| 194 | 0x9d, 0x3e, 0x86, 0x23, 0x71, 0xd2, 0xcf, 0xe5 | ||
| 195 | }; | ||
| 196 | |||
| 197 | static const unsigned char e2[] = { | ||
| 198 | 0x96, 0x77, 0x8b, 0x25, 0xae, 0x6c, 0xa4, 0x35, | ||
| 199 | 0xf9, 0x2b, 0x5b, 0x97, 0xc0, 0x50, 0xae, 0xd2, | ||
| 200 | 0x46, 0x8a, 0xb8, 0xa1, 0x7a, 0xd8, 0x4e, 0x5d | ||
| 201 | }; | ||
| 202 | |||
| 203 | static const unsigned char e3[] = { | ||
| 204 | 0x64, 0xe8, 0xc3, 0xf9, 0xce, 0x0f, 0x5b, 0xa2, | ||
| 205 | 0x63, 0xe9, 0x77, 0x79, 0x05, 0x81, 0x8a, 0x2a, | ||
| 206 | 0x93, 0xc8, 0x19, 0x1e, 0x7d, 0x6e, 0x8a, 0xe7 | ||
| 207 | }; | ||
| 208 | |||
| 209 | static const unsigned char e4[] = { | ||
| 210 | 0x03, 0x1d, 0x33, 0x26, 0x4e, 0x15, 0xd3, 0x32, | ||
| 211 | 0x68, 0xf2, 0x4e, 0xc2, 0x60, 0x74, 0x3e, 0xdc, | ||
| 212 | 0xe1, 0xc6, 0xc7, 0xdd, 0xee, 0x72, 0x5a, 0x93, | ||
| 213 | 0x6b, 0xa8, 0x14, 0x91, 0x5c, 0x67, 0x62, 0xd2 | ||
| 214 | }; | ||
| 215 | |||
| 216 | static const unsigned char e5[] = { | ||
| 217 | 0xa8, 0xf9, 0xbc, 0x16, 0x12, 0xc6, 0x8b, 0x3f, | ||
| 218 | 0xf6, 0xe6, 0xf4, 0xfb, 0xe3, 0x0e, 0x71, 0xe4, | ||
| 219 | 0x76, 0x9c, 0x8b, 0x80, 0xa3, 0x2c, 0xb8, 0x95, | ||
| 220 | 0x8c, 0xd5, 0xd1, 0x7d, 0x6b, 0x25, 0x4d, 0xa1 | ||
| 221 | }; | ||
| 222 | |||
| 223 | static const unsigned char e6[] = { | ||
| 224 | 0x28, 0xc9, 0xf4, 0x04, 0xc4, 0xb8, 0x10, 0xf4, | ||
| 225 | 0xcb, 0xcc, 0xb3, 0x5c, 0xfb, 0x87, 0xf8, 0x26, | ||
| 226 | 0x3f, 0x57, 0x86, 0xe2, 0xd8, 0x0e, 0xd3, 0x26, | ||
| 227 | 0xcb, 0xc7, 0xf0, 0xe7, 0x1a, 0x99, 0xf4, 0x3b, | ||
| 228 | 0xfb, 0x98, 0x8b, 0x9b, 0x7a, 0x02, 0xdd, 0x21 | ||
| 229 | }; | ||
| 230 | |||
| 231 | AES_KEY wctx, xctx; | ||
| 232 | int ret, nfailures = 0; | ||
| 233 | ret = AES_wrap_unwrap_test(kek, 128, NULL, e1, key, 16); | ||
| 234 | if (ret == 0) | ||
| 235 | nfailures++; | ||
| 236 | fprintf(stderr, "Key test result %d\n", ret); | ||
| 237 | ret = AES_wrap_unwrap_test(kek, 192, NULL, e2, key, 16); | ||
| 238 | if (ret == 0) | ||
| 239 | nfailures++; | ||
| 240 | fprintf(stderr, "Key test result %d\n", ret); | ||
| 241 | ret = AES_wrap_unwrap_test(kek, 256, NULL, e3, key, 16); | ||
| 242 | if (ret == 0) | ||
| 243 | nfailures++; | ||
| 244 | fprintf(stderr, "Key test result %d\n", ret); | ||
| 245 | ret = AES_wrap_unwrap_test(kek, 192, NULL, e4, key, 24); | ||
| 246 | if (ret == 0) | ||
| 247 | nfailures++; | ||
| 248 | fprintf(stderr, "Key test result %d\n", ret); | ||
| 249 | ret = AES_wrap_unwrap_test(kek, 256, NULL, e5, key, 24); | ||
| 250 | if (ret == 0) | ||
| 251 | nfailures++; | ||
| 252 | fprintf(stderr, "Key test result %d\n", ret); | ||
| 253 | ret = AES_wrap_unwrap_test(kek, 256, NULL, e6, key, 32); | ||
| 254 | if (ret == 0) | ||
| 255 | nfailures++; | ||
| 256 | fprintf(stderr, "Key test result %d\n", ret); | ||
| 257 | |||
| 258 | return nfailures; | ||
| 259 | } | ||
| 260 | |||
| 261 | #endif | ||
diff --git a/src/lib/libssl/src/crypto/aes/aes_wrap.c b/src/lib/libssl/src/crypto/aes/aes_wrap.c index 4a830da7e4..0e8836d8f2 100644 --- a/src/lib/libssl/src/crypto/aes/aes_wrap.c +++ b/src/lib/libssl/src/crypto/aes/aes_wrap.c | |||
| @@ -130,132 +130,3 @@ AES_unwrap_key(AES_KEY *key, const unsigned char *iv, unsigned char *out, | |||
| 130 | } | 130 | } |
| 131 | return inlen; | 131 | return inlen; |
| 132 | } | 132 | } |
| 133 | |||
| 134 | #ifdef AES_WRAP_TEST | ||
| 135 | |||
| 136 | int | ||
| 137 | AES_wrap_unwrap_test(const unsigned char *kek, int keybits, | ||
| 138 | const unsigned char *iv, const unsigned char *eout, | ||
| 139 | const unsigned char *key, int keylen) | ||
| 140 | { | ||
| 141 | unsigned char *otmp = NULL, *ptmp = NULL; | ||
| 142 | int r, ret = 0; | ||
| 143 | AES_KEY wctx; | ||
| 144 | otmp = malloc(keylen + 8); | ||
| 145 | ptmp = malloc(keylen); | ||
| 146 | if (!otmp || !ptmp) | ||
| 147 | return 0; | ||
| 148 | if (AES_set_encrypt_key(kek, keybits, &wctx)) | ||
| 149 | goto err; | ||
| 150 | r = AES_wrap_key(&wctx, iv, otmp, key, keylen); | ||
| 151 | if (r <= 0) | ||
| 152 | goto err; | ||
| 153 | |||
| 154 | if (eout && memcmp(eout, otmp, keylen)) | ||
| 155 | goto err; | ||
| 156 | |||
| 157 | if (AES_set_decrypt_key(kek, keybits, &wctx)) | ||
| 158 | goto err; | ||
| 159 | r = AES_unwrap_key(&wctx, iv, ptmp, otmp, r); | ||
| 160 | |||
| 161 | if (memcmp(key, ptmp, keylen)) | ||
| 162 | goto err; | ||
| 163 | |||
| 164 | ret = 1; | ||
| 165 | |||
| 166 | err: | ||
| 167 | free(otmp); | ||
| 168 | free(ptmp); | ||
| 169 | |||
| 170 | return ret; | ||
| 171 | } | ||
| 172 | |||
| 173 | |||
| 174 | int | ||
| 175 | main(int argc, char **argv) | ||
| 176 | { | ||
| 177 | static const unsigned char kek[] = { | ||
| 178 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, | ||
| 179 | 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, | ||
| 180 | 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, | ||
| 181 | 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f | ||
| 182 | }; | ||
| 183 | |||
| 184 | static const unsigned char key[] = { | ||
| 185 | 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, | ||
| 186 | 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, | ||
| 187 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, | ||
| 188 | 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f | ||
| 189 | }; | ||
| 190 | |||
| 191 | static const unsigned char e1[] = { | ||
| 192 | 0x1f, 0xa6, 0x8b, 0x0a, 0x81, 0x12, 0xb4, 0x47, | ||
| 193 | 0xae, 0xf3, 0x4b, 0xd8, 0xfb, 0x5a, 0x7b, 0x82, | ||
| 194 | 0x9d, 0x3e, 0x86, 0x23, 0x71, 0xd2, 0xcf, 0xe5 | ||
| 195 | }; | ||
| 196 | |||
| 197 | static const unsigned char e2[] = { | ||
| 198 | 0x96, 0x77, 0x8b, 0x25, 0xae, 0x6c, 0xa4, 0x35, | ||
| 199 | 0xf9, 0x2b, 0x5b, 0x97, 0xc0, 0x50, 0xae, 0xd2, | ||
| 200 | 0x46, 0x8a, 0xb8, 0xa1, 0x7a, 0xd8, 0x4e, 0x5d | ||
| 201 | }; | ||
| 202 | |||
| 203 | static const unsigned char e3[] = { | ||
| 204 | 0x64, 0xe8, 0xc3, 0xf9, 0xce, 0x0f, 0x5b, 0xa2, | ||
| 205 | 0x63, 0xe9, 0x77, 0x79, 0x05, 0x81, 0x8a, 0x2a, | ||
| 206 | 0x93, 0xc8, 0x19, 0x1e, 0x7d, 0x6e, 0x8a, 0xe7 | ||
| 207 | }; | ||
| 208 | |||
| 209 | static const unsigned char e4[] = { | ||
| 210 | 0x03, 0x1d, 0x33, 0x26, 0x4e, 0x15, 0xd3, 0x32, | ||
| 211 | 0x68, 0xf2, 0x4e, 0xc2, 0x60, 0x74, 0x3e, 0xdc, | ||
| 212 | 0xe1, 0xc6, 0xc7, 0xdd, 0xee, 0x72, 0x5a, 0x93, | ||
| 213 | 0x6b, 0xa8, 0x14, 0x91, 0x5c, 0x67, 0x62, 0xd2 | ||
| 214 | }; | ||
| 215 | |||
| 216 | static const unsigned char e5[] = { | ||
| 217 | 0xa8, 0xf9, 0xbc, 0x16, 0x12, 0xc6, 0x8b, 0x3f, | ||
| 218 | 0xf6, 0xe6, 0xf4, 0xfb, 0xe3, 0x0e, 0x71, 0xe4, | ||
| 219 | 0x76, 0x9c, 0x8b, 0x80, 0xa3, 0x2c, 0xb8, 0x95, | ||
| 220 | 0x8c, 0xd5, 0xd1, 0x7d, 0x6b, 0x25, 0x4d, 0xa1 | ||
| 221 | }; | ||
| 222 | |||
| 223 | static const unsigned char e6[] = { | ||
| 224 | 0x28, 0xc9, 0xf4, 0x04, 0xc4, 0xb8, 0x10, 0xf4, | ||
| 225 | 0xcb, 0xcc, 0xb3, 0x5c, 0xfb, 0x87, 0xf8, 0x26, | ||
| 226 | 0x3f, 0x57, 0x86, 0xe2, 0xd8, 0x0e, 0xd3, 0x26, | ||
| 227 | 0xcb, 0xc7, 0xf0, 0xe7, 0x1a, 0x99, 0xf4, 0x3b, | ||
| 228 | 0xfb, 0x98, 0x8b, 0x9b, 0x7a, 0x02, 0xdd, 0x21 | ||
| 229 | }; | ||
| 230 | |||
| 231 | AES_KEY wctx, xctx; | ||
| 232 | int ret, nfailures = 0; | ||
| 233 | ret = AES_wrap_unwrap_test(kek, 128, NULL, e1, key, 16); | ||
| 234 | if (ret == 0) | ||
| 235 | nfailures++; | ||
| 236 | fprintf(stderr, "Key test result %d\n", ret); | ||
| 237 | ret = AES_wrap_unwrap_test(kek, 192, NULL, e2, key, 16); | ||
| 238 | if (ret == 0) | ||
| 239 | nfailures++; | ||
| 240 | fprintf(stderr, "Key test result %d\n", ret); | ||
| 241 | ret = AES_wrap_unwrap_test(kek, 256, NULL, e3, key, 16); | ||
| 242 | if (ret == 0) | ||
| 243 | nfailures++; | ||
| 244 | fprintf(stderr, "Key test result %d\n", ret); | ||
| 245 | ret = AES_wrap_unwrap_test(kek, 192, NULL, e4, key, 24); | ||
| 246 | if (ret == 0) | ||
| 247 | nfailures++; | ||
| 248 | fprintf(stderr, "Key test result %d\n", ret); | ||
| 249 | ret = AES_wrap_unwrap_test(kek, 256, NULL, e5, key, 24); | ||
| 250 | if (ret == 0) | ||
| 251 | nfailures++; | ||
| 252 | fprintf(stderr, "Key test result %d\n", ret); | ||
| 253 | ret = AES_wrap_unwrap_test(kek, 256, NULL, e6, key, 32); | ||
| 254 | if (ret == 0) | ||
| 255 | nfailures++; | ||
| 256 | fprintf(stderr, "Key test result %d\n", ret); | ||
| 257 | |||
| 258 | return nfailures; | ||
| 259 | } | ||
| 260 | |||
| 261 | #endif | ||
diff --git a/src/regress/lib/libcrypto/aeswrap/Makefile b/src/regress/lib/libcrypto/aeswrap/Makefile index 63770a5c7d..c869e5f4d2 100644 --- a/src/regress/lib/libcrypto/aeswrap/Makefile +++ b/src/regress/lib/libcrypto/aeswrap/Makefile | |||
| @@ -1,11 +1,6 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1 2014/04/22 21:27:15 miod Exp $ | 1 | # $OpenBSD: Makefile,v 1.2 2014/05/30 15:17:43 jsing Exp $ |
| 2 | 2 | ||
| 3 | PROG= aes_wrap | 3 | PROG= aes_wrap |
| 4 | CRYPTO= ${.CURDIR}/../../../../lib/libssl/src/crypto | ||
| 5 | CFLAGS+= -DAES_WRAP_TEST | ||
| 6 | CFLAGS+= -I${CRYPTO} -I${CRYPTO}/aes | ||
| 7 | .PATH: ${CRYPTO}/aes | ||
| 8 | |||
| 9 | LDADD= -lcrypto | 4 | LDADD= -lcrypto |
| 10 | DPADD= ${LIBCRYPTO} | 5 | DPADD= ${LIBCRYPTO} |
| 11 | 6 | ||
diff --git a/src/regress/lib/libcrypto/aeswrap/aes_wrap.c b/src/regress/lib/libcrypto/aeswrap/aes_wrap.c new file mode 100644 index 0000000000..b5157d715c --- /dev/null +++ b/src/regress/lib/libcrypto/aeswrap/aes_wrap.c | |||
| @@ -0,0 +1,181 @@ | |||
| 1 | /* crypto/aes/aes_wrap.c */ | ||
| 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | ||
| 3 | * project. | ||
| 4 | */ | ||
| 5 | /* ==================================================================== | ||
| 6 | * Copyright (c) 2008 The OpenSSL Project. All rights reserved. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * | ||
| 12 | * 1. Redistributions of source code must retain the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer. | ||
| 14 | * | ||
| 15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 16 | * notice, this list of conditions and the following disclaimer in | ||
| 17 | * the documentation and/or other materials provided with the | ||
| 18 | * distribution. | ||
| 19 | * | ||
| 20 | * 3. All advertising materials mentioning features or use of this | ||
| 21 | * software must display the following acknowledgment: | ||
| 22 | * "This product includes software developed by the OpenSSL Project | ||
| 23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 24 | * | ||
| 25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 26 | * endorse or promote products derived from this software without | ||
| 27 | * prior written permission. For written permission, please contact | ||
| 28 | * licensing@OpenSSL.org. | ||
| 29 | * | ||
| 30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 31 | * nor may "OpenSSL" appear in their names without prior written | ||
| 32 | * permission of the OpenSSL Project. | ||
| 33 | * | ||
| 34 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 35 | * acknowledgment: | ||
| 36 | * "This product includes software developed by the OpenSSL Project | ||
| 37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 38 | * | ||
| 39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 51 | * ==================================================================== | ||
| 52 | */ | ||
| 53 | |||
| 54 | #include <stdio.h> | ||
| 55 | #include <stdlib.h> | ||
| 56 | |||
| 57 | #include <openssl/aes.h> | ||
| 58 | |||
| 59 | int | ||
| 60 | AES_wrap_unwrap_test(const unsigned char *kek, int keybits, | ||
| 61 | const unsigned char *iv, const unsigned char *eout, | ||
| 62 | const unsigned char *key, int keylen) | ||
| 63 | { | ||
| 64 | unsigned char *otmp = NULL, *ptmp = NULL; | ||
| 65 | int r, ret = 0; | ||
| 66 | AES_KEY wctx; | ||
| 67 | otmp = malloc(keylen + 8); | ||
| 68 | ptmp = malloc(keylen); | ||
| 69 | if (!otmp || !ptmp) | ||
| 70 | return 0; | ||
| 71 | if (AES_set_encrypt_key(kek, keybits, &wctx)) | ||
| 72 | goto err; | ||
| 73 | r = AES_wrap_key(&wctx, iv, otmp, key, keylen); | ||
| 74 | if (r <= 0) | ||
| 75 | goto err; | ||
| 76 | |||
| 77 | if (eout && memcmp(eout, otmp, keylen)) | ||
| 78 | goto err; | ||
| 79 | |||
| 80 | if (AES_set_decrypt_key(kek, keybits, &wctx)) | ||
| 81 | goto err; | ||
| 82 | r = AES_unwrap_key(&wctx, iv, ptmp, otmp, r); | ||
| 83 | |||
| 84 | if (memcmp(key, ptmp, keylen)) | ||
| 85 | goto err; | ||
| 86 | |||
| 87 | ret = 1; | ||
| 88 | |||
| 89 | err: | ||
| 90 | free(otmp); | ||
| 91 | free(ptmp); | ||
| 92 | |||
| 93 | return ret; | ||
| 94 | } | ||
| 95 | |||
| 96 | int | ||
| 97 | main(int argc, char **argv) | ||
| 98 | { | ||
| 99 | static const unsigned char kek[] = { | ||
| 100 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, | ||
| 101 | 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, | ||
| 102 | 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, | ||
| 103 | 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f | ||
| 104 | }; | ||
| 105 | |||
| 106 | static const unsigned char key[] = { | ||
| 107 | 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, | ||
| 108 | 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, | ||
| 109 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, | ||
| 110 | 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f | ||
| 111 | }; | ||
| 112 | |||
| 113 | static const unsigned char e1[] = { | ||
| 114 | 0x1f, 0xa6, 0x8b, 0x0a, 0x81, 0x12, 0xb4, 0x47, | ||
| 115 | 0xae, 0xf3, 0x4b, 0xd8, 0xfb, 0x5a, 0x7b, 0x82, | ||
| 116 | 0x9d, 0x3e, 0x86, 0x23, 0x71, 0xd2, 0xcf, 0xe5 | ||
| 117 | }; | ||
| 118 | |||
| 119 | static const unsigned char e2[] = { | ||
| 120 | 0x96, 0x77, 0x8b, 0x25, 0xae, 0x6c, 0xa4, 0x35, | ||
| 121 | 0xf9, 0x2b, 0x5b, 0x97, 0xc0, 0x50, 0xae, 0xd2, | ||
| 122 | 0x46, 0x8a, 0xb8, 0xa1, 0x7a, 0xd8, 0x4e, 0x5d | ||
| 123 | }; | ||
| 124 | |||
| 125 | static const unsigned char e3[] = { | ||
| 126 | 0x64, 0xe8, 0xc3, 0xf9, 0xce, 0x0f, 0x5b, 0xa2, | ||
| 127 | 0x63, 0xe9, 0x77, 0x79, 0x05, 0x81, 0x8a, 0x2a, | ||
| 128 | 0x93, 0xc8, 0x19, 0x1e, 0x7d, 0x6e, 0x8a, 0xe7 | ||
| 129 | }; | ||
| 130 | |||
| 131 | static const unsigned char e4[] = { | ||
| 132 | 0x03, 0x1d, 0x33, 0x26, 0x4e, 0x15, 0xd3, 0x32, | ||
| 133 | 0x68, 0xf2, 0x4e, 0xc2, 0x60, 0x74, 0x3e, 0xdc, | ||
| 134 | 0xe1, 0xc6, 0xc7, 0xdd, 0xee, 0x72, 0x5a, 0x93, | ||
| 135 | 0x6b, 0xa8, 0x14, 0x91, 0x5c, 0x67, 0x62, 0xd2 | ||
| 136 | }; | ||
| 137 | |||
| 138 | static const unsigned char e5[] = { | ||
| 139 | 0xa8, 0xf9, 0xbc, 0x16, 0x12, 0xc6, 0x8b, 0x3f, | ||
| 140 | 0xf6, 0xe6, 0xf4, 0xfb, 0xe3, 0x0e, 0x71, 0xe4, | ||
| 141 | 0x76, 0x9c, 0x8b, 0x80, 0xa3, 0x2c, 0xb8, 0x95, | ||
| 142 | 0x8c, 0xd5, 0xd1, 0x7d, 0x6b, 0x25, 0x4d, 0xa1 | ||
| 143 | }; | ||
| 144 | |||
| 145 | static const unsigned char e6[] = { | ||
| 146 | 0x28, 0xc9, 0xf4, 0x04, 0xc4, 0xb8, 0x10, 0xf4, | ||
| 147 | 0xcb, 0xcc, 0xb3, 0x5c, 0xfb, 0x87, 0xf8, 0x26, | ||
| 148 | 0x3f, 0x57, 0x86, 0xe2, 0xd8, 0x0e, 0xd3, 0x26, | ||
| 149 | 0xcb, 0xc7, 0xf0, 0xe7, 0x1a, 0x99, 0xf4, 0x3b, | ||
| 150 | 0xfb, 0x98, 0x8b, 0x9b, 0x7a, 0x02, 0xdd, 0x21 | ||
| 151 | }; | ||
| 152 | |||
| 153 | AES_KEY wctx, xctx; | ||
| 154 | int ret, nfailures = 0; | ||
| 155 | ret = AES_wrap_unwrap_test(kek, 128, NULL, e1, key, 16); | ||
| 156 | if (ret == 0) | ||
| 157 | nfailures++; | ||
| 158 | fprintf(stderr, "Key test result %d\n", ret); | ||
| 159 | ret = AES_wrap_unwrap_test(kek, 192, NULL, e2, key, 16); | ||
| 160 | if (ret == 0) | ||
| 161 | nfailures++; | ||
| 162 | fprintf(stderr, "Key test result %d\n", ret); | ||
| 163 | ret = AES_wrap_unwrap_test(kek, 256, NULL, e3, key, 16); | ||
| 164 | if (ret == 0) | ||
| 165 | nfailures++; | ||
| 166 | fprintf(stderr, "Key test result %d\n", ret); | ||
| 167 | ret = AES_wrap_unwrap_test(kek, 192, NULL, e4, key, 24); | ||
| 168 | if (ret == 0) | ||
| 169 | nfailures++; | ||
| 170 | fprintf(stderr, "Key test result %d\n", ret); | ||
| 171 | ret = AES_wrap_unwrap_test(kek, 256, NULL, e5, key, 24); | ||
| 172 | if (ret == 0) | ||
| 173 | nfailures++; | ||
| 174 | fprintf(stderr, "Key test result %d\n", ret); | ||
| 175 | ret = AES_wrap_unwrap_test(kek, 256, NULL, e6, key, 32); | ||
| 176 | if (ret == 0) | ||
| 177 | nfailures++; | ||
| 178 | fprintf(stderr, "Key test result %d\n", ret); | ||
| 179 | |||
| 180 | return nfailures; | ||
| 181 | } | ||
