OLD | NEW |
1 /* crypto/aes/aes_ige.c -*- mode:C; c-file-style: "eay" -*- */ | 1 /* crypto/aes/aes_ige.c -*- mode:C; c-file-style: "eay" -*- */ |
2 /* ==================================================================== | 2 /* ==================================================================== |
3 * Copyright (c) 2006 The OpenSSL Project. All rights reserved. | 3 * Copyright (c) 2006 The OpenSSL Project. All rights reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * | 8 * |
9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 #define load_block(d, s) (d) = *(const aes_block_t *)(s) | 70 #define load_block(d, s) (d) = *(const aes_block_t *)(s) |
71 #define store_block(d, s) *(aes_block_t *)(d) = (s) | 71 #define store_block(d, s) *(aes_block_t *)(d) = (s) |
72 #else | 72 #else |
73 #define load_block(d, s) memcpy((d).data, (s), AES_BLOCK_SIZE) | 73 #define load_block(d, s) memcpy((d).data, (s), AES_BLOCK_SIZE) |
74 #define store_block(d, s) memcpy((d), (s).data, AES_BLOCK_SIZE) | 74 #define store_block(d, s) memcpy((d), (s).data, AES_BLOCK_SIZE) |
75 #endif | 75 #endif |
76 | 76 |
77 /* N.B. The IV for this mode is _twice_ the block size */ | 77 /* N.B. The IV for this mode is _twice_ the block size */ |
78 | 78 |
79 void AES_ige_encrypt(const unsigned char *in, unsigned char *out, | 79 void AES_ige_encrypt(const unsigned char *in, unsigned char *out, |
80 » » » » » const unsigned long length, const AES_K
EY *key, | 80 » » » » » size_t length, const AES_KEY *key, |
81 unsigned char *ivec, const int enc) | 81 unsigned char *ivec, const int enc) |
82 { | 82 { |
83 » unsigned long n; | 83 » size_t n; |
84 » unsigned long len; | 84 » size_t len = length; |
85 | 85 |
86 OPENSSL_assert(in && out && key && ivec); | 86 OPENSSL_assert(in && out && key && ivec); |
87 OPENSSL_assert((AES_ENCRYPT == enc)||(AES_DECRYPT == enc)); | 87 OPENSSL_assert((AES_ENCRYPT == enc)||(AES_DECRYPT == enc)); |
88 OPENSSL_assert((length%AES_BLOCK_SIZE) == 0); | 88 OPENSSL_assert((length%AES_BLOCK_SIZE) == 0); |
89 | 89 |
90 len = length / AES_BLOCK_SIZE; | 90 len = length / AES_BLOCK_SIZE; |
91 | 91 |
92 if (AES_ENCRYPT == enc) | 92 if (AES_ENCRYPT == enc) |
93 { | 93 { |
94 if (in != out && | 94 if (in != out && |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 } | 204 } |
205 | 205 |
206 /* | 206 /* |
207 * Note that its effectively impossible to do biIGE in anything other | 207 * Note that its effectively impossible to do biIGE in anything other |
208 * than a single pass, so no provision is made for chaining. | 208 * than a single pass, so no provision is made for chaining. |
209 */ | 209 */ |
210 | 210 |
211 /* N.B. The IV for this mode is _four times_ the block size */ | 211 /* N.B. The IV for this mode is _four times_ the block size */ |
212 | 212 |
213 void AES_bi_ige_encrypt(const unsigned char *in, unsigned char *out, | 213 void AES_bi_ige_encrypt(const unsigned char *in, unsigned char *out, |
214 » » » » » » const unsigned long length, cons
t AES_KEY *key, | 214 » » » » » » size_t length, const AES_KEY *ke
y, |
215 const AES_KEY *key2, const unsig
ned char *ivec, | 215 const AES_KEY *key2, const unsig
ned char *ivec, |
216 const int enc) | 216 const int enc) |
217 { | 217 { |
218 » unsigned long n; | 218 » size_t n; |
219 » unsigned long len = length; | 219 » size_t len = length; |
220 unsigned char tmp[AES_BLOCK_SIZE]; | 220 unsigned char tmp[AES_BLOCK_SIZE]; |
221 unsigned char tmp2[AES_BLOCK_SIZE]; | 221 unsigned char tmp2[AES_BLOCK_SIZE]; |
222 unsigned char tmp3[AES_BLOCK_SIZE]; | 222 unsigned char tmp3[AES_BLOCK_SIZE]; |
223 unsigned char prev[AES_BLOCK_SIZE]; | 223 unsigned char prev[AES_BLOCK_SIZE]; |
224 const unsigned char *iv; | 224 const unsigned char *iv; |
225 const unsigned char *iv2; | 225 const unsigned char *iv2; |
226 | 226 |
227 OPENSSL_assert(in && out && key && ivec); | 227 OPENSSL_assert(in && out && key && ivec); |
228 OPENSSL_assert((AES_ENCRYPT == enc)||(AES_DECRYPT == enc)); | 228 OPENSSL_assert((AES_ENCRYPT == enc)||(AES_DECRYPT == enc)); |
229 OPENSSL_assert((length%AES_BLOCK_SIZE) == 0); | 229 OPENSSL_assert((length%AES_BLOCK_SIZE) == 0); |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 out[n] ^= iv[n]; | 314 out[n] ^= iv[n]; |
315 memcpy(tmp3, tmp2, AES_BLOCK_SIZE); | 315 memcpy(tmp3, tmp2, AES_BLOCK_SIZE); |
316 iv = tmp3; | 316 iv = tmp3; |
317 iv2 = out; | 317 iv2 = out; |
318 len -= AES_BLOCK_SIZE; | 318 len -= AES_BLOCK_SIZE; |
319 in += AES_BLOCK_SIZE; | 319 in += AES_BLOCK_SIZE; |
320 out += AES_BLOCK_SIZE; | 320 out += AES_BLOCK_SIZE; |
321 } | 321 } |
322 } | 322 } |
323 } | 323 } |
OLD | NEW |