1
0

100-remove-cryptoapi-dependencies.patch 13 KB

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