des_s390.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Cryptographic API.
  4. *
  5. * s390 implementation of the DES Cipher Algorithm.
  6. *
  7. * Copyright IBM Corp. 2003, 2011
  8. * Author(s): Thomas Spatzier
  9. * Jan Glauber (jan.glauber@de.ibm.com)
  10. */
  11. #include <linux/init.h>
  12. #include <linux/module.h>
  13. #include <linux/cpufeature.h>
  14. #include <linux/crypto.h>
  15. #include <linux/fips.h>
  16. #include <crypto/algapi.h>
  17. #include <crypto/des.h>
  18. #include <asm/cpacf.h>
  19. #define DES3_KEY_SIZE (3 * DES_KEY_SIZE)
  20. static u8 *ctrblk;
  21. static DEFINE_SPINLOCK(ctrblk_lock);
  22. static cpacf_mask_t km_functions, kmc_functions, kmctr_functions;
  23. struct s390_des_ctx {
  24. u8 iv[DES_BLOCK_SIZE];
  25. u8 key[DES3_KEY_SIZE];
  26. };
  27. static int des_setkey(struct crypto_tfm *tfm, const u8 *key,
  28. unsigned int key_len)
  29. {
  30. struct s390_des_ctx *ctx = crypto_tfm_ctx(tfm);
  31. u32 tmp[DES_EXPKEY_WORDS];
  32. /* check for weak keys */
  33. if (!des_ekey(tmp, key) &&
  34. (tfm->crt_flags & CRYPTO_TFM_REQ_WEAK_KEY)) {
  35. tfm->crt_flags |= CRYPTO_TFM_RES_WEAK_KEY;
  36. return -EINVAL;
  37. }
  38. memcpy(ctx->key, key, key_len);
  39. return 0;
  40. }
  41. static void des_encrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
  42. {
  43. struct s390_des_ctx *ctx = crypto_tfm_ctx(tfm);
  44. cpacf_km(CPACF_KM_DEA, ctx->key, out, in, DES_BLOCK_SIZE);
  45. }
  46. static void des_decrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
  47. {
  48. struct s390_des_ctx *ctx = crypto_tfm_ctx(tfm);
  49. cpacf_km(CPACF_KM_DEA | CPACF_DECRYPT,
  50. ctx->key, out, in, DES_BLOCK_SIZE);
  51. }
  52. static struct crypto_alg des_alg = {
  53. .cra_name = "des",
  54. .cra_driver_name = "des-s390",
  55. .cra_priority = 300,
  56. .cra_flags = CRYPTO_ALG_TYPE_CIPHER,
  57. .cra_blocksize = DES_BLOCK_SIZE,
  58. .cra_ctxsize = sizeof(struct s390_des_ctx),
  59. .cra_module = THIS_MODULE,
  60. .cra_u = {
  61. .cipher = {
  62. .cia_min_keysize = DES_KEY_SIZE,
  63. .cia_max_keysize = DES_KEY_SIZE,
  64. .cia_setkey = des_setkey,
  65. .cia_encrypt = des_encrypt,
  66. .cia_decrypt = des_decrypt,
  67. }
  68. }
  69. };
  70. static int ecb_desall_crypt(struct blkcipher_desc *desc, unsigned long fc,
  71. struct blkcipher_walk *walk)
  72. {
  73. struct s390_des_ctx *ctx = crypto_blkcipher_ctx(desc->tfm);
  74. unsigned int nbytes, n;
  75. int ret;
  76. ret = blkcipher_walk_virt(desc, walk);
  77. while ((nbytes = walk->nbytes) >= DES_BLOCK_SIZE) {
  78. /* only use complete blocks */
  79. n = nbytes & ~(DES_BLOCK_SIZE - 1);
  80. cpacf_km(fc, ctx->key, walk->dst.virt.addr,
  81. walk->src.virt.addr, n);
  82. ret = blkcipher_walk_done(desc, walk, nbytes - n);
  83. }
  84. return ret;
  85. }
  86. static int cbc_desall_crypt(struct blkcipher_desc *desc, unsigned long fc,
  87. struct blkcipher_walk *walk)
  88. {
  89. struct s390_des_ctx *ctx = crypto_blkcipher_ctx(desc->tfm);
  90. unsigned int nbytes, n;
  91. int ret;
  92. struct {
  93. u8 iv[DES_BLOCK_SIZE];
  94. u8 key[DES3_KEY_SIZE];
  95. } param;
  96. ret = blkcipher_walk_virt(desc, walk);
  97. memcpy(param.iv, walk->iv, DES_BLOCK_SIZE);
  98. memcpy(param.key, ctx->key, DES3_KEY_SIZE);
  99. while ((nbytes = walk->nbytes) >= DES_BLOCK_SIZE) {
  100. /* only use complete blocks */
  101. n = nbytes & ~(DES_BLOCK_SIZE - 1);
  102. cpacf_kmc(fc, &param, walk->dst.virt.addr,
  103. walk->src.virt.addr, n);
  104. ret = blkcipher_walk_done(desc, walk, nbytes - n);
  105. }
  106. memcpy(walk->iv, param.iv, DES_BLOCK_SIZE);
  107. return ret;
  108. }
  109. static int ecb_des_encrypt(struct blkcipher_desc *desc,
  110. struct scatterlist *dst, struct scatterlist *src,
  111. unsigned int nbytes)
  112. {
  113. struct blkcipher_walk walk;
  114. blkcipher_walk_init(&walk, dst, src, nbytes);
  115. return ecb_desall_crypt(desc, CPACF_KM_DEA, &walk);
  116. }
  117. static int ecb_des_decrypt(struct blkcipher_desc *desc,
  118. struct scatterlist *dst, struct scatterlist *src,
  119. unsigned int nbytes)
  120. {
  121. struct blkcipher_walk walk;
  122. blkcipher_walk_init(&walk, dst, src, nbytes);
  123. return ecb_desall_crypt(desc, CPACF_KM_DEA | CPACF_DECRYPT, &walk);
  124. }
  125. static struct crypto_alg ecb_des_alg = {
  126. .cra_name = "ecb(des)",
  127. .cra_driver_name = "ecb-des-s390",
  128. .cra_priority = 400, /* combo: des + ecb */
  129. .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER,
  130. .cra_blocksize = DES_BLOCK_SIZE,
  131. .cra_ctxsize = sizeof(struct s390_des_ctx),
  132. .cra_type = &crypto_blkcipher_type,
  133. .cra_module = THIS_MODULE,
  134. .cra_u = {
  135. .blkcipher = {
  136. .min_keysize = DES_KEY_SIZE,
  137. .max_keysize = DES_KEY_SIZE,
  138. .setkey = des_setkey,
  139. .encrypt = ecb_des_encrypt,
  140. .decrypt = ecb_des_decrypt,
  141. }
  142. }
  143. };
  144. static int cbc_des_encrypt(struct blkcipher_desc *desc,
  145. struct scatterlist *dst, struct scatterlist *src,
  146. unsigned int nbytes)
  147. {
  148. struct blkcipher_walk walk;
  149. blkcipher_walk_init(&walk, dst, src, nbytes);
  150. return cbc_desall_crypt(desc, CPACF_KMC_DEA, &walk);
  151. }
  152. static int cbc_des_decrypt(struct blkcipher_desc *desc,
  153. struct scatterlist *dst, struct scatterlist *src,
  154. unsigned int nbytes)
  155. {
  156. struct blkcipher_walk walk;
  157. blkcipher_walk_init(&walk, dst, src, nbytes);
  158. return cbc_desall_crypt(desc, CPACF_KMC_DEA | CPACF_DECRYPT, &walk);
  159. }
  160. static struct crypto_alg cbc_des_alg = {
  161. .cra_name = "cbc(des)",
  162. .cra_driver_name = "cbc-des-s390",
  163. .cra_priority = 400, /* combo: des + cbc */
  164. .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER,
  165. .cra_blocksize = DES_BLOCK_SIZE,
  166. .cra_ctxsize = sizeof(struct s390_des_ctx),
  167. .cra_type = &crypto_blkcipher_type,
  168. .cra_module = THIS_MODULE,
  169. .cra_u = {
  170. .blkcipher = {
  171. .min_keysize = DES_KEY_SIZE,
  172. .max_keysize = DES_KEY_SIZE,
  173. .ivsize = DES_BLOCK_SIZE,
  174. .setkey = des_setkey,
  175. .encrypt = cbc_des_encrypt,
  176. .decrypt = cbc_des_decrypt,
  177. }
  178. }
  179. };
  180. /*
  181. * RFC2451:
  182. *
  183. * For DES-EDE3, there is no known need to reject weak or
  184. * complementation keys. Any weakness is obviated by the use of
  185. * multiple keys.
  186. *
  187. * However, if the first two or last two independent 64-bit keys are
  188. * equal (k1 == k2 or k2 == k3), then the DES3 operation is simply the
  189. * same as DES. Implementers MUST reject keys that exhibit this
  190. * property.
  191. *
  192. * In fips mode additinally check for all 3 keys are unique.
  193. *
  194. */
  195. static int des3_setkey(struct crypto_tfm *tfm, const u8 *key,
  196. unsigned int key_len)
  197. {
  198. struct s390_des_ctx *ctx = crypto_tfm_ctx(tfm);
  199. if (!(crypto_memneq(key, &key[DES_KEY_SIZE], DES_KEY_SIZE) &&
  200. crypto_memneq(&key[DES_KEY_SIZE], &key[DES_KEY_SIZE * 2],
  201. DES_KEY_SIZE)) &&
  202. (tfm->crt_flags & CRYPTO_TFM_REQ_WEAK_KEY)) {
  203. tfm->crt_flags |= CRYPTO_TFM_RES_WEAK_KEY;
  204. return -EINVAL;
  205. }
  206. /* in fips mode, ensure k1 != k2 and k2 != k3 and k1 != k3 */
  207. if (fips_enabled &&
  208. !(crypto_memneq(key, &key[DES_KEY_SIZE], DES_KEY_SIZE) &&
  209. crypto_memneq(&key[DES_KEY_SIZE], &key[DES_KEY_SIZE * 2],
  210. DES_KEY_SIZE) &&
  211. crypto_memneq(key, &key[DES_KEY_SIZE * 2], DES_KEY_SIZE))) {
  212. tfm->crt_flags |= CRYPTO_TFM_RES_WEAK_KEY;
  213. return -EINVAL;
  214. }
  215. memcpy(ctx->key, key, key_len);
  216. return 0;
  217. }
  218. static void des3_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
  219. {
  220. struct s390_des_ctx *ctx = crypto_tfm_ctx(tfm);
  221. cpacf_km(CPACF_KM_TDEA_192, ctx->key, dst, src, DES_BLOCK_SIZE);
  222. }
  223. static void des3_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
  224. {
  225. struct s390_des_ctx *ctx = crypto_tfm_ctx(tfm);
  226. cpacf_km(CPACF_KM_TDEA_192 | CPACF_DECRYPT,
  227. ctx->key, dst, src, DES_BLOCK_SIZE);
  228. }
  229. static struct crypto_alg des3_alg = {
  230. .cra_name = "des3_ede",
  231. .cra_driver_name = "des3_ede-s390",
  232. .cra_priority = 300,
  233. .cra_flags = CRYPTO_ALG_TYPE_CIPHER,
  234. .cra_blocksize = DES_BLOCK_SIZE,
  235. .cra_ctxsize = sizeof(struct s390_des_ctx),
  236. .cra_module = THIS_MODULE,
  237. .cra_u = {
  238. .cipher = {
  239. .cia_min_keysize = DES3_KEY_SIZE,
  240. .cia_max_keysize = DES3_KEY_SIZE,
  241. .cia_setkey = des3_setkey,
  242. .cia_encrypt = des3_encrypt,
  243. .cia_decrypt = des3_decrypt,
  244. }
  245. }
  246. };
  247. static int ecb_des3_encrypt(struct blkcipher_desc *desc,
  248. struct scatterlist *dst, struct scatterlist *src,
  249. unsigned int nbytes)
  250. {
  251. struct blkcipher_walk walk;
  252. blkcipher_walk_init(&walk, dst, src, nbytes);
  253. return ecb_desall_crypt(desc, CPACF_KM_TDEA_192, &walk);
  254. }
  255. static int ecb_des3_decrypt(struct blkcipher_desc *desc,
  256. struct scatterlist *dst, struct scatterlist *src,
  257. unsigned int nbytes)
  258. {
  259. struct blkcipher_walk walk;
  260. blkcipher_walk_init(&walk, dst, src, nbytes);
  261. return ecb_desall_crypt(desc, CPACF_KM_TDEA_192 | CPACF_DECRYPT,
  262. &walk);
  263. }
  264. static struct crypto_alg ecb_des3_alg = {
  265. .cra_name = "ecb(des3_ede)",
  266. .cra_driver_name = "ecb-des3_ede-s390",
  267. .cra_priority = 400, /* combo: des3 + ecb */
  268. .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER,
  269. .cra_blocksize = DES_BLOCK_SIZE,
  270. .cra_ctxsize = sizeof(struct s390_des_ctx),
  271. .cra_type = &crypto_blkcipher_type,
  272. .cra_module = THIS_MODULE,
  273. .cra_u = {
  274. .blkcipher = {
  275. .min_keysize = DES3_KEY_SIZE,
  276. .max_keysize = DES3_KEY_SIZE,
  277. .setkey = des3_setkey,
  278. .encrypt = ecb_des3_encrypt,
  279. .decrypt = ecb_des3_decrypt,
  280. }
  281. }
  282. };
  283. static int cbc_des3_encrypt(struct blkcipher_desc *desc,
  284. struct scatterlist *dst, struct scatterlist *src,
  285. unsigned int nbytes)
  286. {
  287. struct blkcipher_walk walk;
  288. blkcipher_walk_init(&walk, dst, src, nbytes);
  289. return cbc_desall_crypt(desc, CPACF_KMC_TDEA_192, &walk);
  290. }
  291. static int cbc_des3_decrypt(struct blkcipher_desc *desc,
  292. struct scatterlist *dst, struct scatterlist *src,
  293. unsigned int nbytes)
  294. {
  295. struct blkcipher_walk walk;
  296. blkcipher_walk_init(&walk, dst, src, nbytes);
  297. return cbc_desall_crypt(desc, CPACF_KMC_TDEA_192 | CPACF_DECRYPT,
  298. &walk);
  299. }
  300. static struct crypto_alg cbc_des3_alg = {
  301. .cra_name = "cbc(des3_ede)",
  302. .cra_driver_name = "cbc-des3_ede-s390",
  303. .cra_priority = 400, /* combo: des3 + cbc */
  304. .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER,
  305. .cra_blocksize = DES_BLOCK_SIZE,
  306. .cra_ctxsize = sizeof(struct s390_des_ctx),
  307. .cra_type = &crypto_blkcipher_type,
  308. .cra_module = THIS_MODULE,
  309. .cra_u = {
  310. .blkcipher = {
  311. .min_keysize = DES3_KEY_SIZE,
  312. .max_keysize = DES3_KEY_SIZE,
  313. .ivsize = DES_BLOCK_SIZE,
  314. .setkey = des3_setkey,
  315. .encrypt = cbc_des3_encrypt,
  316. .decrypt = cbc_des3_decrypt,
  317. }
  318. }
  319. };
  320. static unsigned int __ctrblk_init(u8 *ctrptr, u8 *iv, unsigned int nbytes)
  321. {
  322. unsigned int i, n;
  323. /* align to block size, max. PAGE_SIZE */
  324. n = (nbytes > PAGE_SIZE) ? PAGE_SIZE : nbytes & ~(DES_BLOCK_SIZE - 1);
  325. memcpy(ctrptr, iv, DES_BLOCK_SIZE);
  326. for (i = (n / DES_BLOCK_SIZE) - 1; i > 0; i--) {
  327. memcpy(ctrptr + DES_BLOCK_SIZE, ctrptr, DES_BLOCK_SIZE);
  328. crypto_inc(ctrptr + DES_BLOCK_SIZE, DES_BLOCK_SIZE);
  329. ctrptr += DES_BLOCK_SIZE;
  330. }
  331. return n;
  332. }
  333. static int ctr_desall_crypt(struct blkcipher_desc *desc, unsigned long fc,
  334. struct blkcipher_walk *walk)
  335. {
  336. struct s390_des_ctx *ctx = crypto_blkcipher_ctx(desc->tfm);
  337. u8 buf[DES_BLOCK_SIZE], *ctrptr;
  338. unsigned int n, nbytes;
  339. int ret, locked;
  340. locked = spin_trylock(&ctrblk_lock);
  341. ret = blkcipher_walk_virt_block(desc, walk, DES_BLOCK_SIZE);
  342. while ((nbytes = walk->nbytes) >= DES_BLOCK_SIZE) {
  343. n = DES_BLOCK_SIZE;
  344. if (nbytes >= 2*DES_BLOCK_SIZE && locked)
  345. n = __ctrblk_init(ctrblk, walk->iv, nbytes);
  346. ctrptr = (n > DES_BLOCK_SIZE) ? ctrblk : walk->iv;
  347. cpacf_kmctr(fc, ctx->key, walk->dst.virt.addr,
  348. walk->src.virt.addr, n, ctrptr);
  349. if (ctrptr == ctrblk)
  350. memcpy(walk->iv, ctrptr + n - DES_BLOCK_SIZE,
  351. DES_BLOCK_SIZE);
  352. crypto_inc(walk->iv, DES_BLOCK_SIZE);
  353. ret = blkcipher_walk_done(desc, walk, nbytes - n);
  354. }
  355. if (locked)
  356. spin_unlock(&ctrblk_lock);
  357. /* final block may be < DES_BLOCK_SIZE, copy only nbytes */
  358. if (nbytes) {
  359. cpacf_kmctr(fc, ctx->key, buf, walk->src.virt.addr,
  360. DES_BLOCK_SIZE, walk->iv);
  361. memcpy(walk->dst.virt.addr, buf, nbytes);
  362. crypto_inc(walk->iv, DES_BLOCK_SIZE);
  363. ret = blkcipher_walk_done(desc, walk, 0);
  364. }
  365. return ret;
  366. }
  367. static int ctr_des_encrypt(struct blkcipher_desc *desc,
  368. struct scatterlist *dst, struct scatterlist *src,
  369. unsigned int nbytes)
  370. {
  371. struct blkcipher_walk walk;
  372. blkcipher_walk_init(&walk, dst, src, nbytes);
  373. return ctr_desall_crypt(desc, CPACF_KMCTR_DEA, &walk);
  374. }
  375. static int ctr_des_decrypt(struct blkcipher_desc *desc,
  376. struct scatterlist *dst, struct scatterlist *src,
  377. unsigned int nbytes)
  378. {
  379. struct blkcipher_walk walk;
  380. blkcipher_walk_init(&walk, dst, src, nbytes);
  381. return ctr_desall_crypt(desc, CPACF_KMCTR_DEA | CPACF_DECRYPT, &walk);
  382. }
  383. static struct crypto_alg ctr_des_alg = {
  384. .cra_name = "ctr(des)",
  385. .cra_driver_name = "ctr-des-s390",
  386. .cra_priority = 400, /* combo: des + ctr */
  387. .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER,
  388. .cra_blocksize = 1,
  389. .cra_ctxsize = sizeof(struct s390_des_ctx),
  390. .cra_type = &crypto_blkcipher_type,
  391. .cra_module = THIS_MODULE,
  392. .cra_u = {
  393. .blkcipher = {
  394. .min_keysize = DES_KEY_SIZE,
  395. .max_keysize = DES_KEY_SIZE,
  396. .ivsize = DES_BLOCK_SIZE,
  397. .setkey = des_setkey,
  398. .encrypt = ctr_des_encrypt,
  399. .decrypt = ctr_des_decrypt,
  400. }
  401. }
  402. };
  403. static int ctr_des3_encrypt(struct blkcipher_desc *desc,
  404. struct scatterlist *dst, struct scatterlist *src,
  405. unsigned int nbytes)
  406. {
  407. struct blkcipher_walk walk;
  408. blkcipher_walk_init(&walk, dst, src, nbytes);
  409. return ctr_desall_crypt(desc, CPACF_KMCTR_TDEA_192, &walk);
  410. }
  411. static int ctr_des3_decrypt(struct blkcipher_desc *desc,
  412. struct scatterlist *dst, struct scatterlist *src,
  413. unsigned int nbytes)
  414. {
  415. struct blkcipher_walk walk;
  416. blkcipher_walk_init(&walk, dst, src, nbytes);
  417. return ctr_desall_crypt(desc, CPACF_KMCTR_TDEA_192 | CPACF_DECRYPT,
  418. &walk);
  419. }
  420. static struct crypto_alg ctr_des3_alg = {
  421. .cra_name = "ctr(des3_ede)",
  422. .cra_driver_name = "ctr-des3_ede-s390",
  423. .cra_priority = 400, /* combo: des3 + ede */
  424. .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER,
  425. .cra_blocksize = 1,
  426. .cra_ctxsize = sizeof(struct s390_des_ctx),
  427. .cra_type = &crypto_blkcipher_type,
  428. .cra_module = THIS_MODULE,
  429. .cra_u = {
  430. .blkcipher = {
  431. .min_keysize = DES3_KEY_SIZE,
  432. .max_keysize = DES3_KEY_SIZE,
  433. .ivsize = DES_BLOCK_SIZE,
  434. .setkey = des3_setkey,
  435. .encrypt = ctr_des3_encrypt,
  436. .decrypt = ctr_des3_decrypt,
  437. }
  438. }
  439. };
  440. static struct crypto_alg *des_s390_algs_ptr[8];
  441. static int des_s390_algs_num;
  442. static int des_s390_register_alg(struct crypto_alg *alg)
  443. {
  444. int ret;
  445. ret = crypto_register_alg(alg);
  446. if (!ret)
  447. des_s390_algs_ptr[des_s390_algs_num++] = alg;
  448. return ret;
  449. }
  450. static void des_s390_exit(void)
  451. {
  452. while (des_s390_algs_num--)
  453. crypto_unregister_alg(des_s390_algs_ptr[des_s390_algs_num]);
  454. if (ctrblk)
  455. free_page((unsigned long) ctrblk);
  456. }
  457. static int __init des_s390_init(void)
  458. {
  459. int ret;
  460. /* Query available functions for KM, KMC and KMCTR */
  461. cpacf_query(CPACF_KM, &km_functions);
  462. cpacf_query(CPACF_KMC, &kmc_functions);
  463. cpacf_query(CPACF_KMCTR, &kmctr_functions);
  464. if (cpacf_test_func(&km_functions, CPACF_KM_DEA)) {
  465. ret = des_s390_register_alg(&des_alg);
  466. if (ret)
  467. goto out_err;
  468. ret = des_s390_register_alg(&ecb_des_alg);
  469. if (ret)
  470. goto out_err;
  471. }
  472. if (cpacf_test_func(&kmc_functions, CPACF_KMC_DEA)) {
  473. ret = des_s390_register_alg(&cbc_des_alg);
  474. if (ret)
  475. goto out_err;
  476. }
  477. if (cpacf_test_func(&km_functions, CPACF_KM_TDEA_192)) {
  478. ret = des_s390_register_alg(&des3_alg);
  479. if (ret)
  480. goto out_err;
  481. ret = des_s390_register_alg(&ecb_des3_alg);
  482. if (ret)
  483. goto out_err;
  484. }
  485. if (cpacf_test_func(&kmc_functions, CPACF_KMC_TDEA_192)) {
  486. ret = des_s390_register_alg(&cbc_des3_alg);
  487. if (ret)
  488. goto out_err;
  489. }
  490. if (cpacf_test_func(&kmctr_functions, CPACF_KMCTR_DEA) ||
  491. cpacf_test_func(&kmctr_functions, CPACF_KMCTR_TDEA_192)) {
  492. ctrblk = (u8 *) __get_free_page(GFP_KERNEL);
  493. if (!ctrblk) {
  494. ret = -ENOMEM;
  495. goto out_err;
  496. }
  497. }
  498. if (cpacf_test_func(&kmctr_functions, CPACF_KMCTR_DEA)) {
  499. ret = des_s390_register_alg(&ctr_des_alg);
  500. if (ret)
  501. goto out_err;
  502. }
  503. if (cpacf_test_func(&kmctr_functions, CPACF_KMCTR_TDEA_192)) {
  504. ret = des_s390_register_alg(&ctr_des3_alg);
  505. if (ret)
  506. goto out_err;
  507. }
  508. return 0;
  509. out_err:
  510. des_s390_exit();
  511. return ret;
  512. }
  513. module_cpu_feature_match(MSA, des_s390_init);
  514. module_exit(des_s390_exit);
  515. MODULE_ALIAS_CRYPTO("des");
  516. MODULE_ALIAS_CRYPTO("des3_ede");
  517. MODULE_LICENSE("GPL");
  518. MODULE_DESCRIPTION("DES & Triple DES EDE Cipher Algorithms");