6
* Author: JuanJo Ciarlante <jjo-ipsec@mendoza.gov.ar>
8
* This program is free software; you can redistribute it and/or modify it
9
* under the terms of the GNU General Public License as published by the
10
* Free Software Foundation; either version 2 of the License, or (at your
11
* option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
13
* This program is distributed in the hope that it will be useful, but
14
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21
* Heavily inspired in loop_AES
23
#define CBC_IMPL_BLK16(name, ctx_type, addr_type, enc_func, dec_func) \
24
int name(ctx_type *ctx, const u_int8_t * in, u_int8_t * out, int ilen, const u_int8_t * iv, int encrypt) { \
26
const u_int32_t *iv_i; \
27
if ((ilen) % 16) return 0; \
32
iv_i=(const u_int32_t*) iv; \
34
iv_i=(const u_int32_t*) (out-16); \
35
*((u_int32_t *)(&out[ 0])) = iv_i[0]^*((const u_int32_t *)(&in[ 0])); \
36
*((u_int32_t *)(&out[ 4])) = iv_i[1]^*((const u_int32_t *)(&in[ 4])); \
37
*((u_int32_t *)(&out[ 8])) = iv_i[2]^*((const u_int32_t *)(&in[ 8])); \
38
*((u_int32_t *)(&out[12])) = iv_i[3]^*((const u_int32_t *)(&in[12])); \
39
enc_func(ctx, (addr_type) out, (addr_type) out); \
49
dec_func(ctx, (const addr_type) in, (addr_type) out); \
51
iv_i=(const u_int32_t*) (iv); \
53
iv_i=(const u_int32_t*) (in-16); \
54
*((u_int32_t *)(&out[ 0])) ^= iv_i[0]; \
55
*((u_int32_t *)(&out[ 4])) ^= iv_i[1]; \
56
*((u_int32_t *)(&out[ 8])) ^= iv_i[2]; \
57
*((u_int32_t *)(&out[12])) ^= iv_i[3]; \
65
#define CBC_IMPL_BLK8(name, ctx_type, addr_type, enc_func, dec_func) \
66
int name(ctx_type *ctx, u_int8_t * in, u_int8_t * out, int ilen, const u_int8_t * iv, int encrypt) { \
68
const u_int32_t *iv_i; \
69
if ((ilen) % 8) return 0; \
74
iv_i=(const u_int32_t*) iv; \
76
iv_i=(const u_int32_t*) (out-8); \
77
*((u_int32_t *)(&out[ 0])) = iv_i[0]^*((const u_int32_t *)(&in[ 0])); \
78
*((u_int32_t *)(&out[ 4])) = iv_i[1]^*((const u_int32_t *)(&in[ 4])); \
79
enc_func(ctx, (addr_type)out, (addr_type)out); \
89
dec_func(ctx, (const addr_type)in, (addr_type)out); \
91
iv_i=(const u_int32_t*) (iv); \
93
iv_i=(const u_int32_t*) (in-8); \
94
*((u_int32_t *)(&out[ 0])) ^= iv_i[0]; \
95
*((u_int32_t *)(&out[ 4])) ^= iv_i[1]; \
103
#define CBC_DECL(name, ctx_type) \
104
int name(ctx_type *ctx, u_int8_t * in, u_int8_t * out, int ilen, const u_int8_t * iv, int encrypt)
107
CBC_IMPL_BLK16(AES_cbc_encrypt, aes_context, u_int8_t *, aes_encrypt, aes_decrypt);
108
CBC_DECL(AES_cbc_encrypt, aes_context);
110
#endif /* _CBC_GENERIC_H */