des_s390.c 15 KB

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