OLD | NEW |
1 /* crypto/aes/aes_wrap.c */ | 1 /* crypto/aes/aes_wrap.c */ |
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 */ |
5 /* ==================================================================== | 5 /* ==================================================================== |
6 * Copyright (c) 2008 The OpenSSL Project. All rights reserved. | 6 * Copyright (c) 2008 The OpenSSL Project. All rights reserved. |
7 * | 7 * |
8 * Redistribution and use in source and binary forms, with or without | 8 * Redistribution and use in source and binary forms, with or without |
9 * modification, are permitted provided that the following conditions | 9 * modification, are permitted provided that the following conditions |
10 * are met: | 10 * are met: |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 for (j = 0; j < 6; j++) | 78 for (j = 0; j < 6; j++) |
79 { | 79 { |
80 R = out + 8; | 80 R = out + 8; |
81 for (i = 0; i < inlen; i += 8, t++, R += 8) | 81 for (i = 0; i < inlen; i += 8, t++, R += 8) |
82 { | 82 { |
83 memcpy(B + 8, R, 8); | 83 memcpy(B + 8, R, 8); |
84 AES_encrypt(B, B, key); | 84 AES_encrypt(B, B, key); |
85 A[7] ^= (unsigned char)(t & 0xff); | 85 A[7] ^= (unsigned char)(t & 0xff); |
86 if (t > 0xff) | 86 if (t > 0xff) |
87 { | 87 { |
88 » » » » A[6] ^= (unsigned char)((t & 0xff) >> 8); | 88 » » » » A[6] ^= (unsigned char)((t >> 8) & 0xff); |
89 » » » » A[5] ^= (unsigned char)((t & 0xff) >> 16); | 89 » » » » A[5] ^= (unsigned char)((t >> 16) & 0xff); |
90 » » » » A[4] ^= (unsigned char)((t & 0xff) >> 24); | 90 » » » » A[4] ^= (unsigned char)((t >> 24) & 0xff); |
91 } | 91 } |
92 memcpy(R, B + 8, 8); | 92 memcpy(R, B + 8, 8); |
93 } | 93 } |
94 } | 94 } |
95 memcpy(out, A, 8); | 95 memcpy(out, A, 8); |
96 return inlen + 8; | 96 return inlen + 8; |
97 } | 97 } |
98 | 98 |
99 int AES_unwrap_key(AES_KEY *key, const unsigned char *iv, | 99 int AES_unwrap_key(AES_KEY *key, const unsigned char *iv, |
100 unsigned char *out, | 100 unsigned char *out, |
(...skipping 11 matching lines...) Expand all Loading... |
112 memcpy(A, in, 8); | 112 memcpy(A, in, 8); |
113 memcpy(out, in + 8, inlen); | 113 memcpy(out, in + 8, inlen); |
114 for (j = 0; j < 6; j++) | 114 for (j = 0; j < 6; j++) |
115 { | 115 { |
116 R = out + inlen - 8; | 116 R = out + inlen - 8; |
117 for (i = 0; i < inlen; i += 8, t--, R -= 8) | 117 for (i = 0; i < inlen; i += 8, t--, R -= 8) |
118 { | 118 { |
119 A[7] ^= (unsigned char)(t & 0xff); | 119 A[7] ^= (unsigned char)(t & 0xff); |
120 if (t > 0xff) | 120 if (t > 0xff) |
121 { | 121 { |
122 » » » » A[6] ^= (unsigned char)((t & 0xff) >> 8); | 122 » » » » A[6] ^= (unsigned char)((t >> 8) & 0xff); |
123 » » » » A[5] ^= (unsigned char)((t & 0xff) >> 16); | 123 » » » » A[5] ^= (unsigned char)((t >> 16) & 0xff); |
124 » » » » A[4] ^= (unsigned char)((t & 0xff) >> 24); | 124 » » » » A[4] ^= (unsigned char)((t >> 24) & 0xff); |
125 } | 125 } |
126 memcpy(B + 8, R, 8); | 126 memcpy(B + 8, R, 8); |
127 AES_decrypt(B, B, key); | 127 AES_decrypt(B, B, key); |
128 memcpy(R, B + 8, 8); | 128 memcpy(R, B + 8, 8); |
129 } | 129 } |
130 } | 130 } |
131 if (!iv) | 131 if (!iv) |
132 iv = default_iv; | 132 iv = default_iv; |
133 if (memcmp(A, iv, 8)) | 133 if (memcmp(A, iv, 8)) |
134 { | 134 { |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 ret = AES_wrap_unwrap_test(kek, 192, NULL, e4, key, 24); | 250 ret = AES_wrap_unwrap_test(kek, 192, NULL, e4, key, 24); |
251 fprintf(stderr, "Key test result %d\n", ret); | 251 fprintf(stderr, "Key test result %d\n", ret); |
252 ret = AES_wrap_unwrap_test(kek, 256, NULL, e5, key, 24); | 252 ret = AES_wrap_unwrap_test(kek, 256, NULL, e5, key, 24); |
253 fprintf(stderr, "Key test result %d\n", ret); | 253 fprintf(stderr, "Key test result %d\n", ret); |
254 ret = AES_wrap_unwrap_test(kek, 256, NULL, e6, key, 32); | 254 ret = AES_wrap_unwrap_test(kek, 256, NULL, e6, key, 32); |
255 fprintf(stderr, "Key test result %d\n", ret); | 255 fprintf(stderr, "Key test result %d\n", ret); |
256 } | 256 } |
257 | 257 |
258 | 258 |
259 #endif | 259 #endif |
OLD | NEW |