]>
git.ipfire.org Git - people/ms/strongswan.git/blob - lib/libcrypto/libaes/aes_xcbc_mac.c
2 #include <linux/types.h>
3 #include <linux/kernel.h>
12 #include "aes_xcbc_mac.h"
14 int AES_xcbc_mac_set_key(aes_context_mac
*ctxm
, const u_int8_t
*key
, int keylen
)
18 { 0x01010101, 0x01010101, 0x01010101, 0x01010101 },
19 { 0x02020202, 0x02020202, 0x02020202, 0x02020202 },
20 { 0x03030303, 0x03030303, 0x03030303, 0x03030303 },
22 aes_set_key(&ctxm
->ctx_k1
, key
, keylen
, 0);
23 aes_encrypt(&ctxm
->ctx_k1
, (u_int8_t
*) kn
[0], (u_int8_t
*) kn
[0]);
24 aes_encrypt(&ctxm
->ctx_k1
, (u_int8_t
*) kn
[1], (u_int8_t
*) ctxm
->k2
);
25 aes_encrypt(&ctxm
->ctx_k1
, (u_int8_t
*) kn
[2], (u_int8_t
*) ctxm
->k3
);
26 aes_set_key(&ctxm
->ctx_k1
, (u_int8_t
*) kn
[0], 16, 0);
29 static void do_pad_xor(u_int8_t
*out
, const u_int8_t
*in
, int len
) {
31 for (pos
=1; pos
<= 16; pos
++, in
++, out
++) {
35 DEBUG(printf("put 0x80 at pos=%d\n", pos
));
41 static void xor_block(aes_block res
, const aes_block op
) {
47 int AES_xcbc_mac_hash(const aes_context_mac
*ctxm
, const u_int8_t
* in
, int ilen
, u_int8_t hash
[16]) {
49 u_int32_t out
[4] = { 0, 0, 0, 0 };
50 for (; ilen
> 16 ; ilen
-=16) {
51 xor_block(out
, (const u_int32_t
*) &in
[0]);
52 aes_encrypt(&ctxm
->ctx_k1
, in
, (u_int8_t
*)&out
[0]);
55 do_pad_xor((u_int8_t
*)&out
, in
, ilen
);
57 DEBUG(printf("using k3\n"));
58 xor_block(out
, ctxm
->k3
);
62 DEBUG(printf("using k2\n"));
63 xor_block(out
, ctxm
->k2
);
65 aes_encrypt(&ctxm
->ctx_k1
, (u_int8_t
*)out
, hash
);