022-0003-crypto-crypto4xx-convert-to-skcipher.patch 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578
  1. From ce05ffe10457bda487fa049016a6ba79934bdece Mon Sep 17 00:00:00 2001
  2. From: Christian Lamparter <[email protected]>
  3. Date: Thu, 19 Apr 2018 18:41:52 +0200
  4. Subject: [PATCH 3/8] crypto: crypto4xx - convert to skcipher
  5. The ablkcipher APIs have been effectively deprecated since [1].
  6. This patch converts the crypto4xx driver to the new skcipher APIs.
  7. [1] <https://www.spinics.net/lists/linux-crypto/msg18133.html>
  8. Signed-off-by: Christian Lamparter <[email protected]>
  9. Signed-off-by: Herbert Xu <[email protected]>
  10. ---
  11. drivers/crypto/amcc/crypto4xx_alg.c | 60 ++++---
  12. drivers/crypto/amcc/crypto4xx_core.c | 255 +++++++++++++--------------
  13. drivers/crypto/amcc/crypto4xx_core.h | 25 +--
  14. 3 files changed, 163 insertions(+), 177 deletions(-)
  15. --- a/drivers/crypto/amcc/crypto4xx_alg.c
  16. +++ b/drivers/crypto/amcc/crypto4xx_alg.c
  17. @@ -31,6 +31,7 @@
  18. #include <crypto/gcm.h>
  19. #include <crypto/sha.h>
  20. #include <crypto/ctr.h>
  21. +#include <crypto/skcipher.h>
  22. #include "crypto4xx_reg_def.h"
  23. #include "crypto4xx_core.h"
  24. #include "crypto4xx_sa.h"
  25. @@ -74,36 +75,37 @@ static void set_dynamic_sa_command_1(str
  26. sa->sa_command_1.bf.copy_hdr = cp_hdr;
  27. }
  28. -static inline int crypto4xx_crypt(struct ablkcipher_request *req,
  29. +static inline int crypto4xx_crypt(struct skcipher_request *req,
  30. const unsigned int ivlen, bool decrypt)
  31. {
  32. - struct crypto4xx_ctx *ctx = crypto_tfm_ctx(req->base.tfm);
  33. + struct crypto_skcipher *cipher = crypto_skcipher_reqtfm(req);
  34. + struct crypto4xx_ctx *ctx = crypto_skcipher_ctx(cipher);
  35. __le32 iv[ivlen];
  36. if (ivlen)
  37. - crypto4xx_memcpy_to_le32(iv, req->info, ivlen);
  38. + crypto4xx_memcpy_to_le32(iv, req->iv, ivlen);
  39. return crypto4xx_build_pd(&req->base, ctx, req->src, req->dst,
  40. - req->nbytes, iv, ivlen, decrypt ? ctx->sa_in : ctx->sa_out,
  41. + req->cryptlen, iv, ivlen, decrypt ? ctx->sa_in : ctx->sa_out,
  42. ctx->sa_len, 0);
  43. }
  44. -int crypto4xx_encrypt_noiv(struct ablkcipher_request *req)
  45. +int crypto4xx_encrypt_noiv(struct skcipher_request *req)
  46. {
  47. return crypto4xx_crypt(req, 0, false);
  48. }
  49. -int crypto4xx_encrypt_iv(struct ablkcipher_request *req)
  50. +int crypto4xx_encrypt_iv(struct skcipher_request *req)
  51. {
  52. return crypto4xx_crypt(req, AES_IV_SIZE, false);
  53. }
  54. -int crypto4xx_decrypt_noiv(struct ablkcipher_request *req)
  55. +int crypto4xx_decrypt_noiv(struct skcipher_request *req)
  56. {
  57. return crypto4xx_crypt(req, 0, true);
  58. }
  59. -int crypto4xx_decrypt_iv(struct ablkcipher_request *req)
  60. +int crypto4xx_decrypt_iv(struct skcipher_request *req)
  61. {
  62. return crypto4xx_crypt(req, AES_IV_SIZE, true);
  63. }
  64. @@ -111,20 +113,19 @@ int crypto4xx_decrypt_iv(struct ablkciph
  65. /**
  66. * AES Functions
  67. */
  68. -static int crypto4xx_setkey_aes(struct crypto_ablkcipher *cipher,
  69. +static int crypto4xx_setkey_aes(struct crypto_skcipher *cipher,
  70. const u8 *key,
  71. unsigned int keylen,
  72. unsigned char cm,
  73. u8 fb)
  74. {
  75. - struct crypto_tfm *tfm = crypto_ablkcipher_tfm(cipher);
  76. - struct crypto4xx_ctx *ctx = crypto_tfm_ctx(tfm);
  77. + struct crypto4xx_ctx *ctx = crypto_skcipher_ctx(cipher);
  78. struct dynamic_sa_ctl *sa;
  79. int rc;
  80. if (keylen != AES_KEYSIZE_256 &&
  81. keylen != AES_KEYSIZE_192 && keylen != AES_KEYSIZE_128) {
  82. - crypto_ablkcipher_set_flags(cipher,
  83. + crypto_skcipher_set_flags(cipher,
  84. CRYPTO_TFM_RES_BAD_KEY_LEN);
  85. return -EINVAL;
  86. }
  87. @@ -164,39 +165,38 @@ static int crypto4xx_setkey_aes(struct c
  88. return 0;
  89. }
  90. -int crypto4xx_setkey_aes_cbc(struct crypto_ablkcipher *cipher,
  91. +int crypto4xx_setkey_aes_cbc(struct crypto_skcipher *cipher,
  92. const u8 *key, unsigned int keylen)
  93. {
  94. return crypto4xx_setkey_aes(cipher, key, keylen, CRYPTO_MODE_CBC,
  95. CRYPTO_FEEDBACK_MODE_NO_FB);
  96. }
  97. -int crypto4xx_setkey_aes_cfb(struct crypto_ablkcipher *cipher,
  98. +int crypto4xx_setkey_aes_cfb(struct crypto_skcipher *cipher,
  99. const u8 *key, unsigned int keylen)
  100. {
  101. return crypto4xx_setkey_aes(cipher, key, keylen, CRYPTO_MODE_CFB,
  102. CRYPTO_FEEDBACK_MODE_128BIT_CFB);
  103. }
  104. -int crypto4xx_setkey_aes_ecb(struct crypto_ablkcipher *cipher,
  105. +int crypto4xx_setkey_aes_ecb(struct crypto_skcipher *cipher,
  106. const u8 *key, unsigned int keylen)
  107. {
  108. return crypto4xx_setkey_aes(cipher, key, keylen, CRYPTO_MODE_ECB,
  109. CRYPTO_FEEDBACK_MODE_NO_FB);
  110. }
  111. -int crypto4xx_setkey_aes_ofb(struct crypto_ablkcipher *cipher,
  112. +int crypto4xx_setkey_aes_ofb(struct crypto_skcipher *cipher,
  113. const u8 *key, unsigned int keylen)
  114. {
  115. return crypto4xx_setkey_aes(cipher, key, keylen, CRYPTO_MODE_OFB,
  116. CRYPTO_FEEDBACK_MODE_64BIT_OFB);
  117. }
  118. -int crypto4xx_setkey_rfc3686(struct crypto_ablkcipher *cipher,
  119. +int crypto4xx_setkey_rfc3686(struct crypto_skcipher *cipher,
  120. const u8 *key, unsigned int keylen)
  121. {
  122. - struct crypto_tfm *tfm = crypto_ablkcipher_tfm(cipher);
  123. - struct crypto4xx_ctx *ctx = crypto_tfm_ctx(tfm);
  124. + struct crypto4xx_ctx *ctx = crypto_skcipher_ctx(cipher);
  125. int rc;
  126. rc = crypto4xx_setkey_aes(cipher, key, keylen - CTR_RFC3686_NONCE_SIZE,
  127. @@ -210,31 +210,33 @@ int crypto4xx_setkey_rfc3686(struct cryp
  128. return 0;
  129. }
  130. -int crypto4xx_rfc3686_encrypt(struct ablkcipher_request *req)
  131. +int crypto4xx_rfc3686_encrypt(struct skcipher_request *req)
  132. {
  133. - struct crypto4xx_ctx *ctx = crypto_tfm_ctx(req->base.tfm);
  134. + struct crypto_skcipher *cipher = crypto_skcipher_reqtfm(req);
  135. + struct crypto4xx_ctx *ctx = crypto_skcipher_ctx(cipher);
  136. __le32 iv[AES_IV_SIZE / 4] = {
  137. ctx->iv_nonce,
  138. - cpu_to_le32p((u32 *) req->info),
  139. - cpu_to_le32p((u32 *) (req->info + 4)),
  140. + cpu_to_le32p((u32 *) req->iv),
  141. + cpu_to_le32p((u32 *) (req->iv + 4)),
  142. cpu_to_le32(1) };
  143. return crypto4xx_build_pd(&req->base, ctx, req->src, req->dst,
  144. - req->nbytes, iv, AES_IV_SIZE,
  145. + req->cryptlen, iv, AES_IV_SIZE,
  146. ctx->sa_out, ctx->sa_len, 0);
  147. }
  148. -int crypto4xx_rfc3686_decrypt(struct ablkcipher_request *req)
  149. +int crypto4xx_rfc3686_decrypt(struct skcipher_request *req)
  150. {
  151. - struct crypto4xx_ctx *ctx = crypto_tfm_ctx(req->base.tfm);
  152. + struct crypto_skcipher *cipher = crypto_skcipher_reqtfm(req);
  153. + struct crypto4xx_ctx *ctx = crypto_skcipher_ctx(cipher);
  154. __le32 iv[AES_IV_SIZE / 4] = {
  155. ctx->iv_nonce,
  156. - cpu_to_le32p((u32 *) req->info),
  157. - cpu_to_le32p((u32 *) (req->info + 4)),
  158. + cpu_to_le32p((u32 *) req->iv),
  159. + cpu_to_le32p((u32 *) (req->iv + 4)),
  160. cpu_to_le32(1) };
  161. return crypto4xx_build_pd(&req->base, ctx, req->src, req->dst,
  162. - req->nbytes, iv, AES_IV_SIZE,
  163. + req->cryptlen, iv, AES_IV_SIZE,
  164. ctx->sa_out, ctx->sa_len, 0);
  165. }
  166. --- a/drivers/crypto/amcc/crypto4xx_core.c
  167. +++ b/drivers/crypto/amcc/crypto4xx_core.c
  168. @@ -41,6 +41,7 @@
  169. #include <crypto/gcm.h>
  170. #include <crypto/sha.h>
  171. #include <crypto/scatterwalk.h>
  172. +#include <crypto/skcipher.h>
  173. #include <crypto/internal/aead.h>
  174. #include <crypto/internal/skcipher.h>
  175. #include "crypto4xx_reg_def.h"
  176. @@ -526,21 +527,19 @@ static void crypto4xx_ret_sg_desc(struct
  177. }
  178. }
  179. -static void crypto4xx_ablkcipher_done(struct crypto4xx_device *dev,
  180. +static void crypto4xx_cipher_done(struct crypto4xx_device *dev,
  181. struct pd_uinfo *pd_uinfo,
  182. struct ce_pd *pd)
  183. {
  184. - struct crypto4xx_ctx *ctx;
  185. - struct ablkcipher_request *ablk_req;
  186. + struct skcipher_request *req;
  187. struct scatterlist *dst;
  188. dma_addr_t addr;
  189. - ablk_req = ablkcipher_request_cast(pd_uinfo->async_req);
  190. - ctx = crypto_tfm_ctx(ablk_req->base.tfm);
  191. + req = skcipher_request_cast(pd_uinfo->async_req);
  192. if (pd_uinfo->using_sd) {
  193. - crypto4xx_copy_pkt_to_dst(dev, pd, pd_uinfo, ablk_req->nbytes,
  194. - ablk_req->dst);
  195. + crypto4xx_copy_pkt_to_dst(dev, pd, pd_uinfo,
  196. + req->cryptlen, req->dst);
  197. } else {
  198. dst = pd_uinfo->dest_va;
  199. addr = dma_map_page(dev->core_dev->device, sg_page(dst),
  200. @@ -549,8 +548,8 @@ static void crypto4xx_ablkcipher_done(st
  201. crypto4xx_ret_sg_desc(dev, pd_uinfo);
  202. if (pd_uinfo->state & PD_ENTRY_BUSY)
  203. - ablkcipher_request_complete(ablk_req, -EINPROGRESS);
  204. - ablkcipher_request_complete(ablk_req, 0);
  205. + skcipher_request_complete(req, -EINPROGRESS);
  206. + skcipher_request_complete(req, 0);
  207. }
  208. static void crypto4xx_ahash_done(struct crypto4xx_device *dev,
  209. @@ -641,8 +640,8 @@ static void crypto4xx_pd_done(struct cry
  210. struct pd_uinfo *pd_uinfo = &dev->pdr_uinfo[idx];
  211. switch (crypto_tfm_alg_type(pd_uinfo->async_req->tfm)) {
  212. - case CRYPTO_ALG_TYPE_ABLKCIPHER:
  213. - crypto4xx_ablkcipher_done(dev, pd_uinfo, pd);
  214. + case CRYPTO_ALG_TYPE_SKCIPHER:
  215. + crypto4xx_cipher_done(dev, pd_uinfo, pd);
  216. break;
  217. case CRYPTO_ALG_TYPE_AEAD:
  218. crypto4xx_aead_done(dev, pd_uinfo, pd);
  219. @@ -936,15 +935,14 @@ static void crypto4xx_ctx_init(struct cr
  220. ctx->sa_len = 0;
  221. }
  222. -static int crypto4xx_ablk_init(struct crypto_tfm *tfm)
  223. +static int crypto4xx_sk_init(struct crypto_skcipher *sk)
  224. {
  225. - struct crypto_alg *alg = tfm->__crt_alg;
  226. + struct skcipher_alg *alg = crypto_skcipher_alg(sk);
  227. struct crypto4xx_alg *amcc_alg;
  228. - struct crypto4xx_ctx *ctx = crypto_tfm_ctx(tfm);
  229. + struct crypto4xx_ctx *ctx = crypto_skcipher_ctx(sk);
  230. amcc_alg = container_of(alg, struct crypto4xx_alg, alg.u.cipher);
  231. crypto4xx_ctx_init(amcc_alg, ctx);
  232. - tfm->crt_ablkcipher.reqsize = sizeof(struct crypto4xx_ctx);
  233. return 0;
  234. }
  235. @@ -953,9 +951,11 @@ static void crypto4xx_common_exit(struct
  236. crypto4xx_free_sa(ctx);
  237. }
  238. -static void crypto4xx_ablk_exit(struct crypto_tfm *tfm)
  239. +static void crypto4xx_sk_exit(struct crypto_skcipher *sk)
  240. {
  241. - crypto4xx_common_exit(crypto_tfm_ctx(tfm));
  242. + struct crypto4xx_ctx *ctx = crypto_skcipher_ctx(sk);
  243. +
  244. + crypto4xx_common_exit(ctx);
  245. }
  246. static int crypto4xx_aead_init(struct crypto_aead *tfm)
  247. @@ -1012,7 +1012,7 @@ static int crypto4xx_register_alg(struct
  248. break;
  249. default:
  250. - rc = crypto_register_alg(&alg->alg.u.cipher);
  251. + rc = crypto_register_skcipher(&alg->alg.u.cipher);
  252. break;
  253. }
  254. @@ -1041,7 +1041,7 @@ static void crypto4xx_unregister_alg(str
  255. break;
  256. default:
  257. - crypto_unregister_alg(&alg->alg.u.cipher);
  258. + crypto_unregister_skcipher(&alg->alg.u.cipher);
  259. }
  260. kfree(alg);
  261. }
  262. @@ -1103,126 +1103,109 @@ static irqreturn_t crypto4xx_ce_interrup
  263. */
  264. static struct crypto4xx_alg_common crypto4xx_alg[] = {
  265. /* Crypto AES modes */
  266. - { .type = CRYPTO_ALG_TYPE_ABLKCIPHER, .u.cipher = {
  267. - .cra_name = "cbc(aes)",
  268. - .cra_driver_name = "cbc-aes-ppc4xx",
  269. - .cra_priority = CRYPTO4XX_CRYPTO_PRIORITY,
  270. - .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER |
  271. - CRYPTO_ALG_ASYNC |
  272. - CRYPTO_ALG_KERN_DRIVER_ONLY,
  273. - .cra_blocksize = AES_BLOCK_SIZE,
  274. - .cra_ctxsize = sizeof(struct crypto4xx_ctx),
  275. - .cra_type = &crypto_ablkcipher_type,
  276. - .cra_init = crypto4xx_ablk_init,
  277. - .cra_exit = crypto4xx_ablk_exit,
  278. - .cra_module = THIS_MODULE,
  279. - .cra_u = {
  280. - .ablkcipher = {
  281. - .min_keysize = AES_MIN_KEY_SIZE,
  282. - .max_keysize = AES_MAX_KEY_SIZE,
  283. - .ivsize = AES_IV_SIZE,
  284. - .setkey = crypto4xx_setkey_aes_cbc,
  285. - .encrypt = crypto4xx_encrypt_iv,
  286. - .decrypt = crypto4xx_decrypt_iv,
  287. - }
  288. - }
  289. - }},
  290. - { .type = CRYPTO_ALG_TYPE_ABLKCIPHER, .u.cipher = {
  291. - .cra_name = "cfb(aes)",
  292. - .cra_driver_name = "cfb-aes-ppc4xx",
  293. - .cra_priority = CRYPTO4XX_CRYPTO_PRIORITY,
  294. - .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER |
  295. - CRYPTO_ALG_ASYNC |
  296. - CRYPTO_ALG_KERN_DRIVER_ONLY,
  297. - .cra_blocksize = AES_BLOCK_SIZE,
  298. - .cra_ctxsize = sizeof(struct crypto4xx_ctx),
  299. - .cra_type = &crypto_ablkcipher_type,
  300. - .cra_init = crypto4xx_ablk_init,
  301. - .cra_exit = crypto4xx_ablk_exit,
  302. - .cra_module = THIS_MODULE,
  303. - .cra_u = {
  304. - .ablkcipher = {
  305. - .min_keysize = AES_MIN_KEY_SIZE,
  306. - .max_keysize = AES_MAX_KEY_SIZE,
  307. - .ivsize = AES_IV_SIZE,
  308. - .setkey = crypto4xx_setkey_aes_cfb,
  309. - .encrypt = crypto4xx_encrypt_iv,
  310. - .decrypt = crypto4xx_decrypt_iv,
  311. - }
  312. - }
  313. + { .type = CRYPTO_ALG_TYPE_SKCIPHER, .u.cipher = {
  314. + .base = {
  315. + .cra_name = "cbc(aes)",
  316. + .cra_driver_name = "cbc-aes-ppc4xx",
  317. + .cra_priority = CRYPTO4XX_CRYPTO_PRIORITY,
  318. + .cra_flags = CRYPTO_ALG_TYPE_SKCIPHER |
  319. + CRYPTO_ALG_ASYNC |
  320. + CRYPTO_ALG_KERN_DRIVER_ONLY,
  321. + .cra_blocksize = AES_BLOCK_SIZE,
  322. + .cra_ctxsize = sizeof(struct crypto4xx_ctx),
  323. + .cra_module = THIS_MODULE,
  324. + },
  325. + .min_keysize = AES_MIN_KEY_SIZE,
  326. + .max_keysize = AES_MAX_KEY_SIZE,
  327. + .ivsize = AES_IV_SIZE,
  328. + .setkey = crypto4xx_setkey_aes_cbc,
  329. + .encrypt = crypto4xx_encrypt_iv,
  330. + .decrypt = crypto4xx_decrypt_iv,
  331. + .init = crypto4xx_sk_init,
  332. + .exit = crypto4xx_sk_exit,
  333. } },
  334. - { .type = CRYPTO_ALG_TYPE_ABLKCIPHER, .u.cipher = {
  335. - .cra_name = "rfc3686(ctr(aes))",
  336. - .cra_driver_name = "rfc3686-ctr-aes-ppc4xx",
  337. - .cra_priority = CRYPTO4XX_CRYPTO_PRIORITY,
  338. - .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER |
  339. - CRYPTO_ALG_ASYNC |
  340. - CRYPTO_ALG_KERN_DRIVER_ONLY,
  341. - .cra_blocksize = AES_BLOCK_SIZE,
  342. - .cra_ctxsize = sizeof(struct crypto4xx_ctx),
  343. - .cra_type = &crypto_ablkcipher_type,
  344. - .cra_init = crypto4xx_ablk_init,
  345. - .cra_exit = crypto4xx_ablk_exit,
  346. - .cra_module = THIS_MODULE,
  347. - .cra_u = {
  348. - .ablkcipher = {
  349. - .min_keysize = AES_MIN_KEY_SIZE +
  350. - CTR_RFC3686_NONCE_SIZE,
  351. - .max_keysize = AES_MAX_KEY_SIZE +
  352. - CTR_RFC3686_NONCE_SIZE,
  353. - .ivsize = CTR_RFC3686_IV_SIZE,
  354. - .setkey = crypto4xx_setkey_rfc3686,
  355. - .encrypt = crypto4xx_rfc3686_encrypt,
  356. - .decrypt = crypto4xx_rfc3686_decrypt,
  357. - }
  358. - }
  359. + { .type = CRYPTO_ALG_TYPE_SKCIPHER, .u.cipher = {
  360. + .base = {
  361. + .cra_name = "cfb(aes)",
  362. + .cra_driver_name = "cfb-aes-ppc4xx",
  363. + .cra_priority = CRYPTO4XX_CRYPTO_PRIORITY,
  364. + .cra_flags = CRYPTO_ALG_TYPE_SKCIPHER |
  365. + CRYPTO_ALG_ASYNC |
  366. + CRYPTO_ALG_KERN_DRIVER_ONLY,
  367. + .cra_blocksize = AES_BLOCK_SIZE,
  368. + .cra_ctxsize = sizeof(struct crypto4xx_ctx),
  369. + .cra_module = THIS_MODULE,
  370. + },
  371. + .min_keysize = AES_MIN_KEY_SIZE,
  372. + .max_keysize = AES_MAX_KEY_SIZE,
  373. + .ivsize = AES_IV_SIZE,
  374. + .setkey = crypto4xx_setkey_aes_cfb,
  375. + .encrypt = crypto4xx_encrypt_iv,
  376. + .decrypt = crypto4xx_decrypt_iv,
  377. + .init = crypto4xx_sk_init,
  378. + .exit = crypto4xx_sk_exit,
  379. } },
  380. - { .type = CRYPTO_ALG_TYPE_ABLKCIPHER, .u.cipher = {
  381. - .cra_name = "ecb(aes)",
  382. - .cra_driver_name = "ecb-aes-ppc4xx",
  383. - .cra_priority = CRYPTO4XX_CRYPTO_PRIORITY,
  384. - .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER |
  385. - CRYPTO_ALG_ASYNC |
  386. - CRYPTO_ALG_KERN_DRIVER_ONLY,
  387. - .cra_blocksize = AES_BLOCK_SIZE,
  388. - .cra_ctxsize = sizeof(struct crypto4xx_ctx),
  389. - .cra_type = &crypto_ablkcipher_type,
  390. - .cra_init = crypto4xx_ablk_init,
  391. - .cra_exit = crypto4xx_ablk_exit,
  392. - .cra_module = THIS_MODULE,
  393. - .cra_u = {
  394. - .ablkcipher = {
  395. - .min_keysize = AES_MIN_KEY_SIZE,
  396. - .max_keysize = AES_MAX_KEY_SIZE,
  397. - .setkey = crypto4xx_setkey_aes_ecb,
  398. - .encrypt = crypto4xx_encrypt_noiv,
  399. - .decrypt = crypto4xx_decrypt_noiv,
  400. - }
  401. - }
  402. + { .type = CRYPTO_ALG_TYPE_SKCIPHER, .u.cipher = {
  403. + .base = {
  404. + .cra_name = "rfc3686(ctr(aes))",
  405. + .cra_driver_name = "rfc3686-ctr-aes-ppc4xx",
  406. + .cra_priority = CRYPTO4XX_CRYPTO_PRIORITY,
  407. + .cra_flags = CRYPTO_ALG_TYPE_SKCIPHER |
  408. + CRYPTO_ALG_ASYNC |
  409. + CRYPTO_ALG_KERN_DRIVER_ONLY,
  410. + .cra_blocksize = AES_BLOCK_SIZE,
  411. + .cra_ctxsize = sizeof(struct crypto4xx_ctx),
  412. + .cra_module = THIS_MODULE,
  413. + },
  414. + .min_keysize = AES_MIN_KEY_SIZE + CTR_RFC3686_NONCE_SIZE,
  415. + .max_keysize = AES_MAX_KEY_SIZE + CTR_RFC3686_NONCE_SIZE,
  416. + .ivsize = CTR_RFC3686_IV_SIZE,
  417. + .setkey = crypto4xx_setkey_rfc3686,
  418. + .encrypt = crypto4xx_rfc3686_encrypt,
  419. + .decrypt = crypto4xx_rfc3686_decrypt,
  420. + .init = crypto4xx_sk_init,
  421. + .exit = crypto4xx_sk_exit,
  422. } },
  423. - { .type = CRYPTO_ALG_TYPE_ABLKCIPHER, .u.cipher = {
  424. - .cra_name = "ofb(aes)",
  425. - .cra_driver_name = "ofb-aes-ppc4xx",
  426. - .cra_priority = CRYPTO4XX_CRYPTO_PRIORITY,
  427. - .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER |
  428. - CRYPTO_ALG_ASYNC |
  429. - CRYPTO_ALG_KERN_DRIVER_ONLY,
  430. - .cra_blocksize = AES_BLOCK_SIZE,
  431. - .cra_ctxsize = sizeof(struct crypto4xx_ctx),
  432. - .cra_type = &crypto_ablkcipher_type,
  433. - .cra_init = crypto4xx_ablk_init,
  434. - .cra_exit = crypto4xx_ablk_exit,
  435. - .cra_module = THIS_MODULE,
  436. - .cra_u = {
  437. - .ablkcipher = {
  438. - .min_keysize = AES_MIN_KEY_SIZE,
  439. - .max_keysize = AES_MAX_KEY_SIZE,
  440. - .ivsize = AES_IV_SIZE,
  441. - .setkey = crypto4xx_setkey_aes_ofb,
  442. - .encrypt = crypto4xx_encrypt_iv,
  443. - .decrypt = crypto4xx_decrypt_iv,
  444. - }
  445. - }
  446. + { .type = CRYPTO_ALG_TYPE_SKCIPHER, .u.cipher = {
  447. + .base = {
  448. + .cra_name = "ecb(aes)",
  449. + .cra_driver_name = "ecb-aes-ppc4xx",
  450. + .cra_priority = CRYPTO4XX_CRYPTO_PRIORITY,
  451. + .cra_flags = CRYPTO_ALG_TYPE_SKCIPHER |
  452. + CRYPTO_ALG_ASYNC |
  453. + CRYPTO_ALG_KERN_DRIVER_ONLY,
  454. + .cra_blocksize = AES_BLOCK_SIZE,
  455. + .cra_ctxsize = sizeof(struct crypto4xx_ctx),
  456. + .cra_module = THIS_MODULE,
  457. + },
  458. + .min_keysize = AES_MIN_KEY_SIZE,
  459. + .max_keysize = AES_MAX_KEY_SIZE,
  460. + .setkey = crypto4xx_setkey_aes_ecb,
  461. + .encrypt = crypto4xx_encrypt_noiv,
  462. + .decrypt = crypto4xx_decrypt_noiv,
  463. + .init = crypto4xx_sk_init,
  464. + .exit = crypto4xx_sk_exit,
  465. + } },
  466. + { .type = CRYPTO_ALG_TYPE_SKCIPHER, .u.cipher = {
  467. + .base = {
  468. + .cra_name = "ofb(aes)",
  469. + .cra_driver_name = "ofb-aes-ppc4xx",
  470. + .cra_priority = CRYPTO4XX_CRYPTO_PRIORITY,
  471. + .cra_flags = CRYPTO_ALG_TYPE_SKCIPHER |
  472. + CRYPTO_ALG_ASYNC |
  473. + CRYPTO_ALG_KERN_DRIVER_ONLY,
  474. + .cra_blocksize = AES_BLOCK_SIZE,
  475. + .cra_ctxsize = sizeof(struct crypto4xx_ctx),
  476. + .cra_module = THIS_MODULE,
  477. + },
  478. + .min_keysize = AES_MIN_KEY_SIZE,
  479. + .max_keysize = AES_MAX_KEY_SIZE,
  480. + .ivsize = AES_IV_SIZE,
  481. + .setkey = crypto4xx_setkey_aes_ofb,
  482. + .encrypt = crypto4xx_encrypt_iv,
  483. + .decrypt = crypto4xx_decrypt_iv,
  484. + .init = crypto4xx_sk_init,
  485. + .exit = crypto4xx_sk_exit,
  486. } },
  487. /* AEAD */
  488. --- a/drivers/crypto/amcc/crypto4xx_core.h
  489. +++ b/drivers/crypto/amcc/crypto4xx_core.h
  490. @@ -25,6 +25,7 @@
  491. #include <linux/ratelimit.h>
  492. #include <crypto/internal/hash.h>
  493. #include <crypto/internal/aead.h>
  494. +#include <crypto/internal/skcipher.h>
  495. #include "crypto4xx_reg_def.h"
  496. #include "crypto4xx_sa.h"
  497. @@ -134,7 +135,7 @@ struct crypto4xx_ctx {
  498. struct crypto4xx_alg_common {
  499. u32 type;
  500. union {
  501. - struct crypto_alg cipher;
  502. + struct skcipher_alg cipher;
  503. struct ahash_alg hash;
  504. struct aead_alg aead;
  505. } u;
  506. @@ -158,22 +159,22 @@ int crypto4xx_build_pd(struct crypto_asy
  507. const struct dynamic_sa_ctl *sa,
  508. const unsigned int sa_len,
  509. const unsigned int assoclen);
  510. -int crypto4xx_setkey_aes_cbc(struct crypto_ablkcipher *cipher,
  511. +int crypto4xx_setkey_aes_cbc(struct crypto_skcipher *cipher,
  512. const u8 *key, unsigned int keylen);
  513. -int crypto4xx_setkey_aes_cfb(struct crypto_ablkcipher *cipher,
  514. +int crypto4xx_setkey_aes_cfb(struct crypto_skcipher *cipher,
  515. const u8 *key, unsigned int keylen);
  516. -int crypto4xx_setkey_aes_ecb(struct crypto_ablkcipher *cipher,
  517. +int crypto4xx_setkey_aes_ecb(struct crypto_skcipher *cipher,
  518. const u8 *key, unsigned int keylen);
  519. -int crypto4xx_setkey_aes_ofb(struct crypto_ablkcipher *cipher,
  520. +int crypto4xx_setkey_aes_ofb(struct crypto_skcipher *cipher,
  521. const u8 *key, unsigned int keylen);
  522. -int crypto4xx_setkey_rfc3686(struct crypto_ablkcipher *cipher,
  523. +int crypto4xx_setkey_rfc3686(struct crypto_skcipher *cipher,
  524. const u8 *key, unsigned int keylen);
  525. -int crypto4xx_encrypt_iv(struct ablkcipher_request *req);
  526. -int crypto4xx_decrypt_iv(struct ablkcipher_request *req);
  527. -int crypto4xx_encrypt_noiv(struct ablkcipher_request *req);
  528. -int crypto4xx_decrypt_noiv(struct ablkcipher_request *req);
  529. -int crypto4xx_rfc3686_encrypt(struct ablkcipher_request *req);
  530. -int crypto4xx_rfc3686_decrypt(struct ablkcipher_request *req);
  531. +int crypto4xx_encrypt_iv(struct skcipher_request *req);
  532. +int crypto4xx_decrypt_iv(struct skcipher_request *req);
  533. +int crypto4xx_encrypt_noiv(struct skcipher_request *req);
  534. +int crypto4xx_decrypt_noiv(struct skcipher_request *req);
  535. +int crypto4xx_rfc3686_encrypt(struct skcipher_request *req);
  536. +int crypto4xx_rfc3686_decrypt(struct skcipher_request *req);
  537. int crypto4xx_sha1_alg_init(struct crypto_tfm *tfm);
  538. int crypto4xx_hash_digest(struct ahash_request *req);
  539. int crypto4xx_hash_final(struct ahash_request *req);