diff options
Diffstat (limited to 'net/mac80211/aes_ccm.c')
-rw-r--r-- | net/mac80211/aes_ccm.c | 51 |
1 files changed, 25 insertions, 26 deletions
diff --git a/net/mac80211/aes_ccm.c b/net/mac80211/aes_ccm.c index 4d4c2dfcf9a0..a87cb3ba2df6 100644 --- a/net/mac80211/aes_ccm.c +++ b/net/mac80211/aes_ccm.c | |||
@@ -16,31 +16,28 @@ | |||
16 | #include "key.h" | 16 | #include "key.h" |
17 | #include "aes_ccm.h" | 17 | #include "aes_ccm.h" |
18 | 18 | ||
19 | 19 | static void aes_ccm_prepare(struct crypto_cipher *tfm, u8 *scratch, u8 *a) | |
20 | static void ieee80211_aes_encrypt(struct crypto_cipher *tfm, | ||
21 | const u8 pt[16], u8 ct[16]) | ||
22 | { | ||
23 | crypto_cipher_encrypt_one(tfm, ct, pt); | ||
24 | } | ||
25 | |||
26 | |||
27 | static inline void aes_ccm_prepare(struct crypto_cipher *tfm, u8 *b_0, u8 *aad, | ||
28 | u8 *b, u8 *s_0, u8 *a) | ||
29 | { | 20 | { |
30 | int i; | 21 | int i; |
22 | u8 *b_0, *aad, *b, *s_0; | ||
31 | 23 | ||
32 | ieee80211_aes_encrypt(tfm, b_0, b); | 24 | b_0 = scratch + 3 * AES_BLOCK_LEN; |
25 | aad = scratch + 4 * AES_BLOCK_LEN; | ||
26 | b = scratch; | ||
27 | s_0 = scratch + AES_BLOCK_LEN; | ||
28 | |||
29 | crypto_cipher_encrypt_one(tfm, b, b_0); | ||
33 | 30 | ||
34 | /* Extra Authenticate-only data (always two AES blocks) */ | 31 | /* Extra Authenticate-only data (always two AES blocks) */ |
35 | for (i = 0; i < AES_BLOCK_LEN; i++) | 32 | for (i = 0; i < AES_BLOCK_LEN; i++) |
36 | aad[i] ^= b[i]; | 33 | aad[i] ^= b[i]; |
37 | ieee80211_aes_encrypt(tfm, aad, b); | 34 | crypto_cipher_encrypt_one(tfm, b, aad); |
38 | 35 | ||
39 | aad += AES_BLOCK_LEN; | 36 | aad += AES_BLOCK_LEN; |
40 | 37 | ||
41 | for (i = 0; i < AES_BLOCK_LEN; i++) | 38 | for (i = 0; i < AES_BLOCK_LEN; i++) |
42 | aad[i] ^= b[i]; | 39 | aad[i] ^= b[i]; |
43 | ieee80211_aes_encrypt(tfm, aad, a); | 40 | crypto_cipher_encrypt_one(tfm, a, aad); |
44 | 41 | ||
45 | /* Mask out bits from auth-only-b_0 */ | 42 | /* Mask out bits from auth-only-b_0 */ |
46 | b_0[0] &= 0x07; | 43 | b_0[0] &= 0x07; |
@@ -48,24 +45,26 @@ static inline void aes_ccm_prepare(struct crypto_cipher *tfm, u8 *b_0, u8 *aad, | |||
48 | /* S_0 is used to encrypt T (= MIC) */ | 45 | /* S_0 is used to encrypt T (= MIC) */ |
49 | b_0[14] = 0; | 46 | b_0[14] = 0; |
50 | b_0[15] = 0; | 47 | b_0[15] = 0; |
51 | ieee80211_aes_encrypt(tfm, b_0, s_0); | 48 | crypto_cipher_encrypt_one(tfm, s_0, b_0); |
52 | } | 49 | } |
53 | 50 | ||
54 | 51 | ||
55 | void ieee80211_aes_ccm_encrypt(struct crypto_cipher *tfm, u8 *scratch, | 52 | void ieee80211_aes_ccm_encrypt(struct crypto_cipher *tfm, u8 *scratch, |
56 | u8 *b_0, u8 *aad, u8 *data, size_t data_len, | 53 | u8 *data, size_t data_len, |
57 | u8 *cdata, u8 *mic) | 54 | u8 *cdata, u8 *mic) |
58 | { | 55 | { |
59 | int i, j, last_len, num_blocks; | 56 | int i, j, last_len, num_blocks; |
60 | u8 *pos, *cpos, *b, *s_0, *e; | 57 | u8 *pos, *cpos, *b, *s_0, *e, *b_0, *aad; |
61 | 58 | ||
62 | b = scratch; | 59 | b = scratch; |
63 | s_0 = scratch + AES_BLOCK_LEN; | 60 | s_0 = scratch + AES_BLOCK_LEN; |
64 | e = scratch + 2 * AES_BLOCK_LEN; | 61 | e = scratch + 2 * AES_BLOCK_LEN; |
62 | b_0 = scratch + 3 * AES_BLOCK_LEN; | ||
63 | aad = scratch + 4 * AES_BLOCK_LEN; | ||
65 | 64 | ||
66 | num_blocks = DIV_ROUND_UP(data_len, AES_BLOCK_LEN); | 65 | num_blocks = DIV_ROUND_UP(data_len, AES_BLOCK_LEN); |
67 | last_len = data_len % AES_BLOCK_LEN; | 66 | last_len = data_len % AES_BLOCK_LEN; |
68 | aes_ccm_prepare(tfm, b_0, aad, b, s_0, b); | 67 | aes_ccm_prepare(tfm, scratch, b); |
69 | 68 | ||
70 | /* Process payload blocks */ | 69 | /* Process payload blocks */ |
71 | pos = data; | 70 | pos = data; |
@@ -77,11 +76,11 @@ void ieee80211_aes_ccm_encrypt(struct crypto_cipher *tfm, u8 *scratch, | |||
77 | /* Authentication followed by encryption */ | 76 | /* Authentication followed by encryption */ |
78 | for (i = 0; i < blen; i++) | 77 | for (i = 0; i < blen; i++) |
79 | b[i] ^= pos[i]; | 78 | b[i] ^= pos[i]; |
80 | ieee80211_aes_encrypt(tfm, b, b); | 79 | crypto_cipher_encrypt_one(tfm, b, b); |
81 | 80 | ||
82 | b_0[14] = (j >> 8) & 0xff; | 81 | b_0[14] = (j >> 8) & 0xff; |
83 | b_0[15] = j & 0xff; | 82 | b_0[15] = j & 0xff; |
84 | ieee80211_aes_encrypt(tfm, b_0, e); | 83 | crypto_cipher_encrypt_one(tfm, e, b_0); |
85 | for (i = 0; i < blen; i++) | 84 | for (i = 0; i < blen; i++) |
86 | *cpos++ = *pos++ ^ e[i]; | 85 | *cpos++ = *pos++ ^ e[i]; |
87 | } | 86 | } |
@@ -92,19 +91,20 @@ void ieee80211_aes_ccm_encrypt(struct crypto_cipher *tfm, u8 *scratch, | |||
92 | 91 | ||
93 | 92 | ||
94 | int ieee80211_aes_ccm_decrypt(struct crypto_cipher *tfm, u8 *scratch, | 93 | int ieee80211_aes_ccm_decrypt(struct crypto_cipher *tfm, u8 *scratch, |
95 | u8 *b_0, u8 *aad, u8 *cdata, size_t data_len, | 94 | u8 *cdata, size_t data_len, u8 *mic, u8 *data) |
96 | u8 *mic, u8 *data) | ||
97 | { | 95 | { |
98 | int i, j, last_len, num_blocks; | 96 | int i, j, last_len, num_blocks; |
99 | u8 *pos, *cpos, *b, *s_0, *a; | 97 | u8 *pos, *cpos, *b, *s_0, *a, *b_0, *aad; |
100 | 98 | ||
101 | b = scratch; | 99 | b = scratch; |
102 | s_0 = scratch + AES_BLOCK_LEN; | 100 | s_0 = scratch + AES_BLOCK_LEN; |
103 | a = scratch + 2 * AES_BLOCK_LEN; | 101 | a = scratch + 2 * AES_BLOCK_LEN; |
102 | b_0 = scratch + 3 * AES_BLOCK_LEN; | ||
103 | aad = scratch + 4 * AES_BLOCK_LEN; | ||
104 | 104 | ||
105 | num_blocks = DIV_ROUND_UP(data_len, AES_BLOCK_LEN); | 105 | num_blocks = DIV_ROUND_UP(data_len, AES_BLOCK_LEN); |
106 | last_len = data_len % AES_BLOCK_LEN; | 106 | last_len = data_len % AES_BLOCK_LEN; |
107 | aes_ccm_prepare(tfm, b_0, aad, b, s_0, a); | 107 | aes_ccm_prepare(tfm, scratch, a); |
108 | 108 | ||
109 | /* Process payload blocks */ | 109 | /* Process payload blocks */ |
110 | cpos = cdata; | 110 | cpos = cdata; |
@@ -116,13 +116,12 @@ int ieee80211_aes_ccm_decrypt(struct crypto_cipher *tfm, u8 *scratch, | |||
116 | /* Decryption followed by authentication */ | 116 | /* Decryption followed by authentication */ |
117 | b_0[14] = (j >> 8) & 0xff; | 117 | b_0[14] = (j >> 8) & 0xff; |
118 | b_0[15] = j & 0xff; | 118 | b_0[15] = j & 0xff; |
119 | ieee80211_aes_encrypt(tfm, b_0, b); | 119 | crypto_cipher_encrypt_one(tfm, b, b_0); |
120 | for (i = 0; i < blen; i++) { | 120 | for (i = 0; i < blen; i++) { |
121 | *pos = *cpos++ ^ b[i]; | 121 | *pos = *cpos++ ^ b[i]; |
122 | a[i] ^= *pos++; | 122 | a[i] ^= *pos++; |
123 | } | 123 | } |
124 | 124 | crypto_cipher_encrypt_one(tfm, a, a); | |
125 | ieee80211_aes_encrypt(tfm, a, a); | ||
126 | } | 125 | } |
127 | 126 | ||
128 | for (i = 0; i < CCMP_MIC_LEN; i++) { | 127 | for (i = 0; i < CCMP_MIC_LEN; i++) { |