2
0

100-remove-cryptoapi-dependencies.patch 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448
  1. --- a/net/mac80211/Kconfig
  2. +++ b/net/mac80211/Kconfig
  3. @@ -5,8 +5,6 @@ config MAC80211
  4. depends on CRYPTO
  5. depends on CRYPTO_ARC4
  6. depends on CRYPTO_AES
  7. - select BPAUTO_CRYPTO_CCM
  8. - depends on CRYPTO_GCM
  9. depends on CRYPTO_CMAC
  10. depends on CRC32
  11. ---help---
  12. --- a/net/mac80211/Makefile
  13. +++ b/net/mac80211/Makefile
  14. @@ -16,9 +16,7 @@ mac80211-y := \
  15. michael.o \
  16. tkip.o \
  17. aes_ccm.o \
  18. - aes_gcm.o \
  19. aes_cmac.o \
  20. - aes_gmac.o \
  21. fils_aead.o \
  22. cfg.o \
  23. ethtool.o \
  24. --- a/net/mac80211/aes_ccm.c
  25. +++ b/net/mac80211/aes_ccm.c
  26. @@ -13,103 +13,132 @@
  27. #include <linux/types.h>
  28. #include <linux/err.h>
  29. #include <crypto/aead.h>
  30. +#include <crypto/aes.h>
  31. #include <net/mac80211.h>
  32. #include "key.h"
  33. #include "aes_ccm.h"
  34. -int ieee80211_aes_ccm_encrypt(struct crypto_aead *tfm, u8 *b_0, u8 *aad,
  35. - u8 *data, size_t data_len, u8 *mic,
  36. - size_t mic_len)
  37. +static void aes_ccm_prepare(struct crypto_cipher *tfm, u8 *b_0, u8 *aad, u8 *s_0,
  38. + u8 *a, u8 *b)
  39. {
  40. - struct scatterlist sg[3];
  41. - struct aead_request *aead_req;
  42. - int reqsize = sizeof(*aead_req) + crypto_aead_reqsize(tfm);
  43. - u8 *__aad;
  44. + int i;
  45. - aead_req = kzalloc(reqsize + CCM_AAD_LEN, GFP_ATOMIC);
  46. - if (!aead_req)
  47. - return -ENOMEM;
  48. + crypto_cipher_encrypt_one(tfm, b, b_0);
  49. - __aad = (u8 *)aead_req + reqsize;
  50. - memcpy(__aad, aad, CCM_AAD_LEN);
  51. + /* Extra Authenticate-only data (always two AES blocks) */
  52. + for (i = 0; i < AES_BLOCK_SIZE; i++)
  53. + aad[i] ^= b[i];
  54. + crypto_cipher_encrypt_one(tfm, b, aad);
  55. - sg_init_table(sg, 3);
  56. - sg_set_buf(&sg[0], &__aad[2], be16_to_cpup((__be16 *)__aad));
  57. - sg_set_buf(&sg[1], data, data_len);
  58. - sg_set_buf(&sg[2], mic, mic_len);
  59. + aad += AES_BLOCK_SIZE;
  60. - aead_request_set_tfm(aead_req, tfm);
  61. - aead_request_set_crypt(aead_req, sg, sg, data_len, b_0);
  62. - aead_request_set_ad(aead_req, sg[0].length);
  63. + for (i = 0; i < AES_BLOCK_SIZE; i++)
  64. + aad[i] ^= b[i];
  65. + crypto_cipher_encrypt_one(tfm, a, aad);
  66. - crypto_aead_encrypt(aead_req);
  67. - kzfree(aead_req);
  68. + /* Mask out bits from auth-only-b_0 */
  69. + b_0[0] &= 0x07;
  70. - return 0;
  71. + /* S_0 is used to encrypt T (= MIC) */
  72. + b_0[14] = 0;
  73. + b_0[15] = 0;
  74. + crypto_cipher_encrypt_one(tfm, s_0, b_0);
  75. }
  76. -int ieee80211_aes_ccm_decrypt(struct crypto_aead *tfm, u8 *b_0, u8 *aad,
  77. - u8 *data, size_t data_len, u8 *mic,
  78. - size_t mic_len)
  79. +
  80. +void ieee80211_aes_ccm_encrypt(struct crypto_cipher *tfm, u8 *b_0, u8 *aad,
  81. + u8 *data, size_t data_len, u8 *mic,
  82. + size_t mic_len)
  83. {
  84. - struct scatterlist sg[3];
  85. - struct aead_request *aead_req;
  86. - int reqsize = sizeof(*aead_req) + crypto_aead_reqsize(tfm);
  87. - u8 *__aad;
  88. - int err;
  89. + int i, j, last_len, num_blocks;
  90. + u8 b[AES_BLOCK_SIZE];
  91. + u8 s_0[AES_BLOCK_SIZE];
  92. + u8 e[AES_BLOCK_SIZE];
  93. + u8 *pos, *cpos;
  94. - if (data_len == 0)
  95. - return -EINVAL;
  96. + num_blocks = DIV_ROUND_UP(data_len, AES_BLOCK_SIZE);
  97. + last_len = data_len % AES_BLOCK_SIZE;
  98. + aes_ccm_prepare(tfm, b_0, aad, s_0, b, b);
  99. - aead_req = kzalloc(reqsize + CCM_AAD_LEN, GFP_ATOMIC);
  100. - if (!aead_req)
  101. - return -ENOMEM;
  102. + /* Process payload blocks */
  103. + pos = data;
  104. + cpos = data;
  105. + for (j = 1; j <= num_blocks; j++) {
  106. + int blen = (j == num_blocks && last_len) ?
  107. + last_len : AES_BLOCK_SIZE;
  108. - __aad = (u8 *)aead_req + reqsize;
  109. - memcpy(__aad, aad, CCM_AAD_LEN);
  110. + /* Authentication followed by encryption */
  111. + for (i = 0; i < blen; i++)
  112. + b[i] ^= pos[i];
  113. + crypto_cipher_encrypt_one(tfm, b, b);
  114. - sg_init_table(sg, 3);
  115. - sg_set_buf(&sg[0], &__aad[2], be16_to_cpup((__be16 *)__aad));
  116. - sg_set_buf(&sg[1], data, data_len);
  117. - sg_set_buf(&sg[2], mic, mic_len);
  118. + b_0[14] = (j >> 8) & 0xff;
  119. + b_0[15] = j & 0xff;
  120. + crypto_cipher_encrypt_one(tfm, e, b_0);
  121. + for (i = 0; i < blen; i++)
  122. + *cpos++ = *pos++ ^ e[i];
  123. + }
  124. - aead_request_set_tfm(aead_req, tfm);
  125. - aead_request_set_crypt(aead_req, sg, sg, data_len + mic_len, b_0);
  126. - aead_request_set_ad(aead_req, sg[0].length);
  127. + for (i = 0; i < mic_len; i++)
  128. + mic[i] = b[i] ^ s_0[i];
  129. +}
  130. - err = crypto_aead_decrypt(aead_req);
  131. - kzfree(aead_req);
  132. +int ieee80211_aes_ccm_decrypt(struct crypto_cipher *tfm, u8 *b_0, u8 *aad,
  133. + u8 *data, size_t data_len, u8 *mic,
  134. + size_t mic_len)
  135. +{
  136. + int i, j, last_len, num_blocks;
  137. + u8 *pos, *cpos;
  138. + u8 a[AES_BLOCK_SIZE];
  139. + u8 b[AES_BLOCK_SIZE];
  140. + u8 s_0[AES_BLOCK_SIZE];
  141. - return err;
  142. + num_blocks = DIV_ROUND_UP(data_len, AES_BLOCK_SIZE);
  143. + last_len = data_len % AES_BLOCK_SIZE;
  144. + aes_ccm_prepare(tfm, b_0, aad, s_0, a, b);
  145. +
  146. + /* Process payload blocks */
  147. + cpos = data;
  148. + pos = data;
  149. + for (j = 1; j <= num_blocks; j++) {
  150. + int blen = (j == num_blocks && last_len) ?
  151. + last_len : AES_BLOCK_SIZE;
  152. +
  153. + /* Decryption followed by authentication */
  154. + b_0[14] = (j >> 8) & 0xff;
  155. + b_0[15] = j & 0xff;
  156. + crypto_cipher_encrypt_one(tfm, b, b_0);
  157. + for (i = 0; i < blen; i++) {
  158. + *pos = *cpos++ ^ b[i];
  159. + a[i] ^= *pos++;
  160. + }
  161. + crypto_cipher_encrypt_one(tfm, a, a);
  162. + }
  163. +
  164. + for (i = 0; i < mic_len; i++) {
  165. + if ((mic[i] ^ s_0[i]) != a[i])
  166. + return -1;
  167. + }
  168. +
  169. + return 0;
  170. }
  171. -struct crypto_aead *ieee80211_aes_key_setup_encrypt(const u8 key[],
  172. - size_t key_len,
  173. - size_t mic_len)
  174. +struct crypto_cipher *ieee80211_aes_key_setup_encrypt(const u8 key[],
  175. + size_t key_len,
  176. + size_t mic_len)
  177. {
  178. - struct crypto_aead *tfm;
  179. - int err;
  180. -
  181. - tfm = crypto_alloc_aead("ccm(aes)", 0, CRYPTO_ALG_ASYNC);
  182. - if (IS_ERR(tfm))
  183. - return tfm;
  184. + struct crypto_cipher *tfm;
  185. - err = crypto_aead_setkey(tfm, key, key_len);
  186. - if (err)
  187. - goto free_aead;
  188. - err = crypto_aead_setauthsize(tfm, mic_len);
  189. - if (err)
  190. - goto free_aead;
  191. + tfm = crypto_alloc_cipher("aes", 0, CRYPTO_ALG_ASYNC);
  192. + if (!IS_ERR(tfm))
  193. + crypto_cipher_setkey(tfm, key, key_len);
  194. return tfm;
  195. -
  196. -free_aead:
  197. - crypto_free_aead(tfm);
  198. - return ERR_PTR(err);
  199. }
  200. -void ieee80211_aes_key_free(struct crypto_aead *tfm)
  201. +
  202. +void ieee80211_aes_key_free(struct crypto_cipher *tfm)
  203. {
  204. - crypto_free_aead(tfm);
  205. + crypto_free_cipher(tfm);
  206. }
  207. --- a/net/mac80211/aes_gmac.h
  208. +++ b/net/mac80211/aes_gmac.h
  209. @@ -15,10 +15,22 @@
  210. #define GMAC_MIC_LEN 16
  211. #define GMAC_NONCE_LEN 12
  212. -struct crypto_aead *ieee80211_aes_gmac_key_setup(const u8 key[],
  213. - size_t key_len);
  214. -int ieee80211_aes_gmac(struct crypto_aead *tfm, const u8 *aad, u8 *nonce,
  215. - const u8 *data, size_t data_len, u8 *mic);
  216. -void ieee80211_aes_gmac_key_free(struct crypto_aead *tfm);
  217. +static inline struct crypto_aead *
  218. +ieee80211_aes_gmac_key_setup(const u8 key[], size_t key_len)
  219. +{
  220. + return NULL;
  221. +}
  222. +
  223. +static inline int
  224. +ieee80211_aes_gmac(struct crypto_aead *tfm, const u8 *aad, u8 *nonce,
  225. + const u8 *data, size_t data_len, u8 *mic)
  226. +{
  227. + return -EOPNOTSUPP;
  228. +}
  229. +
  230. +static inline void
  231. +ieee80211_aes_gmac_key_free(struct crypto_aead *tfm)
  232. +{
  233. +}
  234. #endif /* AES_GMAC_H */
  235. --- a/net/mac80211/key.h
  236. +++ b/net/mac80211/key.h
  237. @@ -88,7 +88,7 @@ struct ieee80211_key {
  238. * Management frames.
  239. */
  240. u8 rx_pn[IEEE80211_NUM_TIDS + 1][IEEE80211_CCMP_PN_LEN];
  241. - struct crypto_aead *tfm;
  242. + struct crypto_cipher *tfm;
  243. u32 replays; /* dot11RSNAStatsCCMPReplays */
  244. } ccmp;
  245. struct {
  246. --- a/net/mac80211/wpa.c
  247. +++ b/net/mac80211/wpa.c
  248. @@ -306,7 +306,8 @@ ieee80211_crypto_tkip_decrypt(struct iee
  249. }
  250. -static void ccmp_special_blocks(struct sk_buff *skb, u8 *pn, u8 *b_0, u8 *aad)
  251. +static void ccmp_special_blocks(struct sk_buff *skb, u8 *pn, u8 *b_0, u8 *aad,
  252. + u16 data_len)
  253. {
  254. __le16 mask_fc;
  255. int a4_included, mgmt;
  256. @@ -336,14 +337,8 @@ static void ccmp_special_blocks(struct s
  257. else
  258. qos_tid = 0;
  259. - /* In CCM, the initial vectors (IV) used for CTR mode encryption and CBC
  260. - * mode authentication are not allowed to collide, yet both are derived
  261. - * from this vector b_0. We only set L := 1 here to indicate that the
  262. - * data size can be represented in (L+1) bytes. The CCM layer will take
  263. - * care of storing the data length in the top (L+1) bytes and setting
  264. - * and clearing the other bits as is required to derive the two IVs.
  265. - */
  266. - b_0[0] = 0x1;
  267. + /* First block, b_0 */
  268. + b_0[0] = 0x59; /* flags: Adata: 1, M: 011, L: 001 */
  269. /* Nonce: Nonce Flags | A2 | PN
  270. * Nonce Flags: Priority (b0..b3) | Management (b4) | Reserved (b5..b7)
  271. @@ -351,6 +346,8 @@ static void ccmp_special_blocks(struct s
  272. b_0[1] = qos_tid | (mgmt << 4);
  273. memcpy(&b_0[2], hdr->addr2, ETH_ALEN);
  274. memcpy(&b_0[8], pn, IEEE80211_CCMP_PN_LEN);
  275. + /* l(m) */
  276. + put_unaligned_be16(data_len, &b_0[14]);
  277. /* AAD (extra authenticate-only data) / masked 802.11 header
  278. * FC | A1 | A2 | A3 | SC | [A4] | [QC] */
  279. @@ -407,7 +404,7 @@ static int ccmp_encrypt_skb(struct ieee8
  280. u8 *pos;
  281. u8 pn[6];
  282. u64 pn64;
  283. - u8 aad[CCM_AAD_LEN];
  284. + u8 aad[2 * AES_BLOCK_SIZE];
  285. u8 b_0[AES_BLOCK_SIZE];
  286. if (info->control.hw_key &&
  287. @@ -462,9 +459,11 @@ static int ccmp_encrypt_skb(struct ieee8
  288. return 0;
  289. pos += IEEE80211_CCMP_HDR_LEN;
  290. - ccmp_special_blocks(skb, pn, b_0, aad);
  291. - return ieee80211_aes_ccm_encrypt(key->u.ccmp.tfm, b_0, aad, pos, len,
  292. - skb_put(skb, mic_len), mic_len);
  293. + ccmp_special_blocks(skb, pn, b_0, aad, len);
  294. + ieee80211_aes_ccm_encrypt(key->u.ccmp.tfm, b_0, aad, pos, len,
  295. + skb_put(skb, mic_len), mic_len);
  296. +
  297. + return 0;
  298. }
  299. @@ -537,7 +536,7 @@ ieee80211_crypto_ccmp_decrypt(struct iee
  300. u8 aad[2 * AES_BLOCK_SIZE];
  301. u8 b_0[AES_BLOCK_SIZE];
  302. /* hardware didn't decrypt/verify MIC */
  303. - ccmp_special_blocks(skb, pn, b_0, aad);
  304. + ccmp_special_blocks(skb, pn, b_0, aad, data_len);
  305. if (ieee80211_aes_ccm_decrypt(
  306. key->u.ccmp.tfm, b_0, aad,
  307. @@ -639,7 +638,7 @@ static int gcmp_encrypt_skb(struct ieee8
  308. u8 *pos;
  309. u8 pn[6];
  310. u64 pn64;
  311. - u8 aad[GCM_AAD_LEN];
  312. + u8 aad[2 * AES_BLOCK_SIZE];
  313. u8 j_0[AES_BLOCK_SIZE];
  314. if (info->control.hw_key &&
  315. @@ -696,8 +695,10 @@ static int gcmp_encrypt_skb(struct ieee8
  316. pos += IEEE80211_GCMP_HDR_LEN;
  317. gcmp_special_blocks(skb, pn, j_0, aad);
  318. - return ieee80211_aes_gcm_encrypt(key->u.gcmp.tfm, j_0, aad, pos, len,
  319. - skb_put(skb, IEEE80211_GCMP_MIC_LEN));
  320. + ieee80211_aes_gcm_encrypt(key->u.gcmp.tfm, j_0, aad, pos, len,
  321. + skb_put(skb, IEEE80211_GCMP_MIC_LEN));
  322. +
  323. + return 0;
  324. }
  325. ieee80211_tx_result
  326. @@ -1121,9 +1122,9 @@ ieee80211_crypto_aes_gmac_encrypt(struct
  327. struct ieee80211_key *key = tx->key;
  328. struct ieee80211_mmie_16 *mmie;
  329. struct ieee80211_hdr *hdr;
  330. - u8 aad[GMAC_AAD_LEN];
  331. + u8 aad[20];
  332. u64 pn64;
  333. - u8 nonce[GMAC_NONCE_LEN];
  334. + u8 nonce[12];
  335. if (WARN_ON(skb_queue_len(&tx->skbs) != 1))
  336. return TX_DROP;
  337. @@ -1169,7 +1170,7 @@ ieee80211_crypto_aes_gmac_decrypt(struct
  338. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
  339. struct ieee80211_key *key = rx->key;
  340. struct ieee80211_mmie_16 *mmie;
  341. - u8 aad[GMAC_AAD_LEN], mic[GMAC_MIC_LEN], ipn[6], nonce[GMAC_NONCE_LEN];
  342. + u8 aad[20], mic[16], ipn[6], nonce[12];
  343. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  344. if (!ieee80211_is_mgmt(hdr->frame_control))
  345. --- a/net/mac80211/aes_ccm.h
  346. +++ b/net/mac80211/aes_ccm.h
  347. @@ -12,17 +12,15 @@
  348. #include <linux/crypto.h>
  349. -#define CCM_AAD_LEN 32
  350. -
  351. -struct crypto_aead *ieee80211_aes_key_setup_encrypt(const u8 key[],
  352. - size_t key_len,
  353. - size_t mic_len);
  354. -int ieee80211_aes_ccm_encrypt(struct crypto_aead *tfm, u8 *b_0, u8 *aad,
  355. - u8 *data, size_t data_len, u8 *mic,
  356. - size_t mic_len);
  357. -int ieee80211_aes_ccm_decrypt(struct crypto_aead *tfm, u8 *b_0, u8 *aad,
  358. +struct crypto_cipher *ieee80211_aes_key_setup_encrypt(const u8 key[],
  359. + size_t key_len,
  360. + size_t mic_len);
  361. +void ieee80211_aes_ccm_encrypt(struct crypto_cipher *tfm, u8 *b_0, u8 *aad,
  362. + u8 *data, size_t data_len, u8 *mic,
  363. + size_t mic_len);
  364. +int ieee80211_aes_ccm_decrypt(struct crypto_cipher *tfm, u8 *b_0, u8 *aad,
  365. u8 *data, size_t data_len, u8 *mic,
  366. size_t mic_len);
  367. -void ieee80211_aes_key_free(struct crypto_aead *tfm);
  368. +void ieee80211_aes_key_free(struct crypto_cipher *tfm);
  369. #endif /* AES_CCM_H */
  370. --- a/net/mac80211/aes_gcm.h
  371. +++ b/net/mac80211/aes_gcm.h
  372. @@ -11,14 +11,28 @@
  373. #include <linux/crypto.h>
  374. -#define GCM_AAD_LEN 32
  375. +static inline void
  376. +ieee80211_aes_gcm_encrypt(struct crypto_aead *tfm, u8 *j_0, u8 *aad,
  377. + u8 *data, size_t data_len, u8 *mic)
  378. +{
  379. +}
  380. -int ieee80211_aes_gcm_encrypt(struct crypto_aead *tfm, u8 *j_0, u8 *aad,
  381. - u8 *data, size_t data_len, u8 *mic);
  382. -int ieee80211_aes_gcm_decrypt(struct crypto_aead *tfm, u8 *j_0, u8 *aad,
  383. - u8 *data, size_t data_len, u8 *mic);
  384. -struct crypto_aead *ieee80211_aes_gcm_key_setup_encrypt(const u8 key[],
  385. - size_t key_len);
  386. -void ieee80211_aes_gcm_key_free(struct crypto_aead *tfm);
  387. +static inline int
  388. +ieee80211_aes_gcm_decrypt(struct crypto_aead *tfm, u8 *j_0, u8 *aad,
  389. + u8 *data, size_t data_len, u8 *mic)
  390. +{
  391. + return -EOPNOTSUPP;
  392. +}
  393. +
  394. +static inline struct crypto_aead *
  395. +ieee80211_aes_gcm_key_setup_encrypt(const u8 key[], size_t key_len)
  396. +{
  397. + return NULL;
  398. +}
  399. +
  400. +static inline void
  401. +ieee80211_aes_gcm_key_free(struct crypto_aead *tfm)
  402. +{
  403. +}
  404. #endif /* AES_GCM_H */