des_s390.c 16 KB

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