10 #include <linux/kernel.h>
11 #include <linux/types.h>
14 #include <crypto/aes.h>
30 crypto_cipher_encrypt_one(tfm, b, b_0);
35 crypto_cipher_encrypt_one(tfm, b, aad);
41 crypto_cipher_encrypt_one(tfm, a, aad);
49 crypto_cipher_encrypt_one(tfm, s_0, b_0);
57 int i,
j, last_len, num_blocks;
58 u8 *
pos, *cpos, *
b, *s_0, *
e, *b_0;
67 aes_ccm_prepare(tfm, scratch, b);
72 for (j = 1; j <= num_blocks; j++) {
73 int blen = (j == num_blocks && last_len) ?
74 last_len : AES_BLOCK_SIZE;
77 for (i = 0; i < blen; i++)
79 crypto_cipher_encrypt_one(tfm, b, b);
81 b_0[14] = (j >> 8) & 0xff;
83 crypto_cipher_encrypt_one(tfm, e, b_0);
84 for (i = 0; i < blen; i++)
85 *cpos++ = *pos++ ^ e[i];
89 mic[i] = b[i] ^ s_0[i];
96 int i,
j, last_len, num_blocks;
97 u8 *
pos, *cpos, *
b, *s_0, *
a, *b_0;
106 aes_ccm_prepare(tfm, scratch, a);
111 for (j = 1; j <= num_blocks; j++) {
112 int blen = (j == num_blocks && last_len) ?
113 last_len : AES_BLOCK_SIZE;
116 b_0[14] = (j >> 8) & 0xff;
118 crypto_cipher_encrypt_one(tfm, b, b_0);
119 for (i = 0; i < blen; i++) {
120 *pos = *cpos++ ^ b[
i];
123 crypto_cipher_encrypt_one(tfm, a, a);
127 if ((mic[i] ^ s_0[i]) != a[i])
149 crypto_free_cipher(tfm);