des_s390.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594
  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/crypto.h>
  19. #include <crypto/algapi.h>
  20. #include <crypto/des.h>
  21. #include "crypt_s390.h"
  22. #define DES3_KEY_SIZE (3 * DES_KEY_SIZE)
  23. static u8 *ctrblk;
  24. struct s390_des_ctx {
  25. u8 iv[DES_BLOCK_SIZE];
  26. u8 key[DES3_KEY_SIZE];
  27. };
  28. static int des_setkey(struct crypto_tfm *tfm, const u8 *key,
  29. unsigned int key_len)
  30. {
  31. struct s390_des_ctx *ctx = crypto_tfm_ctx(tfm);
  32. u32 *flags = &tfm->crt_flags;
  33. u32 tmp[DES_EXPKEY_WORDS];
  34. /* check for weak keys */
  35. if (!des_ekey(tmp, key) && (*flags & CRYPTO_TFM_REQ_WEAK_KEY)) {
  36. *flags |= CRYPTO_TFM_RES_WEAK_KEY;
  37. return -EINVAL;
  38. }
  39. memcpy(ctx->key, key, key_len);
  40. return 0;
  41. }
  42. static void des_encrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
  43. {
  44. struct s390_des_ctx *ctx = crypto_tfm_ctx(tfm);
  45. crypt_s390_km(KM_DEA_ENCRYPT, ctx->key, out, in, DES_BLOCK_SIZE);
  46. }
  47. static void des_decrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
  48. {
  49. struct s390_des_ctx *ctx = crypto_tfm_ctx(tfm);
  50. crypt_s390_km(KM_DEA_DECRYPT, 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 = CRYPT_S390_PRIORITY,
  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, long func,
  71. u8 *key, struct blkcipher_walk *walk)
  72. {
  73. int ret = blkcipher_walk_virt(desc, walk);
  74. unsigned int nbytes;
  75. while ((nbytes = walk->nbytes)) {
  76. /* only use complete blocks */
  77. unsigned int n = nbytes & ~(DES_BLOCK_SIZE - 1);
  78. u8 *out = walk->dst.virt.addr;
  79. u8 *in = walk->src.virt.addr;
  80. ret = crypt_s390_km(func, key, out, in, n);
  81. if (ret < 0 || ret != n)
  82. return -EIO;
  83. nbytes &= DES_BLOCK_SIZE - 1;
  84. ret = blkcipher_walk_done(desc, walk, nbytes);
  85. }
  86. return ret;
  87. }
  88. static int cbc_desall_crypt(struct blkcipher_desc *desc, long func,
  89. u8 *iv, struct blkcipher_walk *walk)
  90. {
  91. int ret = blkcipher_walk_virt(desc, walk);
  92. unsigned int nbytes = walk->nbytes;
  93. if (!nbytes)
  94. goto out;
  95. memcpy(iv, walk->iv, DES_BLOCK_SIZE);
  96. do {
  97. /* only use complete blocks */
  98. unsigned int n = nbytes & ~(DES_BLOCK_SIZE - 1);
  99. u8 *out = walk->dst.virt.addr;
  100. u8 *in = walk->src.virt.addr;
  101. ret = crypt_s390_kmc(func, iv, out, in, n);
  102. if (ret < 0 || ret != n)
  103. return -EIO;
  104. nbytes &= DES_BLOCK_SIZE - 1;
  105. ret = blkcipher_walk_done(desc, walk, nbytes);
  106. } while ((nbytes = walk->nbytes));
  107. memcpy(walk->iv, iv, DES_BLOCK_SIZE);
  108. out:
  109. return ret;
  110. }
  111. static int ecb_des_encrypt(struct blkcipher_desc *desc,
  112. struct scatterlist *dst, struct scatterlist *src,
  113. unsigned int nbytes)
  114. {
  115. struct s390_des_ctx *ctx = crypto_blkcipher_ctx(desc->tfm);
  116. struct blkcipher_walk walk;
  117. blkcipher_walk_init(&walk, dst, src, nbytes);
  118. return ecb_desall_crypt(desc, KM_DEA_ENCRYPT, ctx->key, &walk);
  119. }
  120. static int ecb_des_decrypt(struct blkcipher_desc *desc,
  121. struct scatterlist *dst, struct scatterlist *src,
  122. unsigned int nbytes)
  123. {
  124. struct s390_des_ctx *ctx = crypto_blkcipher_ctx(desc->tfm);
  125. struct blkcipher_walk walk;
  126. blkcipher_walk_init(&walk, dst, src, nbytes);
  127. return ecb_desall_crypt(desc, KM_DEA_DECRYPT, ctx->key, &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 = CRYPT_S390_COMPOSITE_PRIORITY,
  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 s390_des_ctx *ctx = crypto_blkcipher_ctx(desc->tfm);
  153. struct blkcipher_walk walk;
  154. blkcipher_walk_init(&walk, dst, src, nbytes);
  155. return cbc_desall_crypt(desc, KMC_DEA_ENCRYPT, ctx->iv, &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 s390_des_ctx *ctx = crypto_blkcipher_ctx(desc->tfm);
  162. struct blkcipher_walk walk;
  163. blkcipher_walk_init(&walk, dst, src, nbytes);
  164. return cbc_desall_crypt(desc, KMC_DEA_DECRYPT, ctx->iv, &walk);
  165. }
  166. static struct crypto_alg cbc_des_alg = {
  167. .cra_name = "cbc(des)",
  168. .cra_driver_name = "cbc-des-s390",
  169. .cra_priority = CRYPT_S390_COMPOSITE_PRIORITY,
  170. .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER,
  171. .cra_blocksize = DES_BLOCK_SIZE,
  172. .cra_ctxsize = sizeof(struct s390_des_ctx),
  173. .cra_type = &crypto_blkcipher_type,
  174. .cra_module = THIS_MODULE,
  175. .cra_u = {
  176. .blkcipher = {
  177. .min_keysize = DES_KEY_SIZE,
  178. .max_keysize = DES_KEY_SIZE,
  179. .ivsize = DES_BLOCK_SIZE,
  180. .setkey = des_setkey,
  181. .encrypt = cbc_des_encrypt,
  182. .decrypt = cbc_des_decrypt,
  183. }
  184. }
  185. };
  186. /*
  187. * RFC2451:
  188. *
  189. * For DES-EDE3, there is no known need to reject weak or
  190. * complementation keys. Any weakness is obviated by the use of
  191. * multiple keys.
  192. *
  193. * However, if the first two or last two independent 64-bit keys are
  194. * equal (k1 == k2 or k2 == k3), then the DES3 operation is simply the
  195. * same as DES. Implementers MUST reject keys that exhibit this
  196. * property.
  197. *
  198. */
  199. static int des3_setkey(struct crypto_tfm *tfm, const u8 *key,
  200. unsigned int key_len)
  201. {
  202. struct s390_des_ctx *ctx = crypto_tfm_ctx(tfm);
  203. u32 *flags = &tfm->crt_flags;
  204. if (!(memcmp(key, &key[DES_KEY_SIZE], DES_KEY_SIZE) &&
  205. memcmp(&key[DES_KEY_SIZE], &key[DES_KEY_SIZE * 2],
  206. DES_KEY_SIZE)) &&
  207. (*flags & CRYPTO_TFM_REQ_WEAK_KEY)) {
  208. *flags |= CRYPTO_TFM_RES_WEAK_KEY;
  209. return -EINVAL;
  210. }
  211. memcpy(ctx->key, key, key_len);
  212. return 0;
  213. }
  214. static void des3_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
  215. {
  216. struct s390_des_ctx *ctx = crypto_tfm_ctx(tfm);
  217. crypt_s390_km(KM_TDEA_192_ENCRYPT, ctx->key, dst, src, DES_BLOCK_SIZE);
  218. }
  219. static void des3_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
  220. {
  221. struct s390_des_ctx *ctx = crypto_tfm_ctx(tfm);
  222. crypt_s390_km(KM_TDEA_192_DECRYPT, ctx->key, dst, src, DES_BLOCK_SIZE);
  223. }
  224. static struct crypto_alg des3_alg = {
  225. .cra_name = "des3_ede",
  226. .cra_driver_name = "des3_ede-s390",
  227. .cra_priority = CRYPT_S390_PRIORITY,
  228. .cra_flags = CRYPTO_ALG_TYPE_CIPHER,
  229. .cra_blocksize = DES_BLOCK_SIZE,
  230. .cra_ctxsize = sizeof(struct s390_des_ctx),
  231. .cra_module = THIS_MODULE,
  232. .cra_u = {
  233. .cipher = {
  234. .cia_min_keysize = DES3_KEY_SIZE,
  235. .cia_max_keysize = DES3_KEY_SIZE,
  236. .cia_setkey = des3_setkey,
  237. .cia_encrypt = des3_encrypt,
  238. .cia_decrypt = des3_decrypt,
  239. }
  240. }
  241. };
  242. static int ecb_des3_encrypt(struct blkcipher_desc *desc,
  243. struct scatterlist *dst, struct scatterlist *src,
  244. unsigned int nbytes)
  245. {
  246. struct s390_des_ctx *ctx = crypto_blkcipher_ctx(desc->tfm);
  247. struct blkcipher_walk walk;
  248. blkcipher_walk_init(&walk, dst, src, nbytes);
  249. return ecb_desall_crypt(desc, KM_TDEA_192_ENCRYPT, ctx->key, &walk);
  250. }
  251. static int ecb_des3_decrypt(struct blkcipher_desc *desc,
  252. struct scatterlist *dst, struct scatterlist *src,
  253. unsigned int nbytes)
  254. {
  255. struct s390_des_ctx *ctx = crypto_blkcipher_ctx(desc->tfm);
  256. struct blkcipher_walk walk;
  257. blkcipher_walk_init(&walk, dst, src, nbytes);
  258. return ecb_desall_crypt(desc, KM_TDEA_192_DECRYPT, ctx->key, &walk);
  259. }
  260. static struct crypto_alg ecb_des3_alg = {
  261. .cra_name = "ecb(des3_ede)",
  262. .cra_driver_name = "ecb-des3_ede-s390",
  263. .cra_priority = CRYPT_S390_COMPOSITE_PRIORITY,
  264. .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER,
  265. .cra_blocksize = DES_BLOCK_SIZE,
  266. .cra_ctxsize = sizeof(struct s390_des_ctx),
  267. .cra_type = &crypto_blkcipher_type,
  268. .cra_module = THIS_MODULE,
  269. .cra_u = {
  270. .blkcipher = {
  271. .min_keysize = DES3_KEY_SIZE,
  272. .max_keysize = DES3_KEY_SIZE,
  273. .setkey = des3_setkey,
  274. .encrypt = ecb_des3_encrypt,
  275. .decrypt = ecb_des3_decrypt,
  276. }
  277. }
  278. };
  279. static int cbc_des3_encrypt(struct blkcipher_desc *desc,
  280. struct scatterlist *dst, struct scatterlist *src,
  281. unsigned int nbytes)
  282. {
  283. struct s390_des_ctx *ctx = crypto_blkcipher_ctx(desc->tfm);
  284. struct blkcipher_walk walk;
  285. blkcipher_walk_init(&walk, dst, src, nbytes);
  286. return cbc_desall_crypt(desc, KMC_TDEA_192_ENCRYPT, ctx->iv, &walk);
  287. }
  288. static int cbc_des3_decrypt(struct blkcipher_desc *desc,
  289. struct scatterlist *dst, struct scatterlist *src,
  290. unsigned int nbytes)
  291. {
  292. struct s390_des_ctx *ctx = crypto_blkcipher_ctx(desc->tfm);
  293. struct blkcipher_walk walk;
  294. blkcipher_walk_init(&walk, dst, src, nbytes);
  295. return cbc_desall_crypt(desc, KMC_TDEA_192_DECRYPT, ctx->iv, &walk);
  296. }
  297. static struct crypto_alg cbc_des3_alg = {
  298. .cra_name = "cbc(des3_ede)",
  299. .cra_driver_name = "cbc-des3_ede-s390",
  300. .cra_priority = CRYPT_S390_COMPOSITE_PRIORITY,
  301. .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER,
  302. .cra_blocksize = DES_BLOCK_SIZE,
  303. .cra_ctxsize = sizeof(struct s390_des_ctx),
  304. .cra_type = &crypto_blkcipher_type,
  305. .cra_module = THIS_MODULE,
  306. .cra_u = {
  307. .blkcipher = {
  308. .min_keysize = DES3_KEY_SIZE,
  309. .max_keysize = DES3_KEY_SIZE,
  310. .ivsize = DES_BLOCK_SIZE,
  311. .setkey = des3_setkey,
  312. .encrypt = cbc_des3_encrypt,
  313. .decrypt = cbc_des3_decrypt,
  314. }
  315. }
  316. };
  317. static int ctr_desall_crypt(struct blkcipher_desc *desc, long func,
  318. struct s390_des_ctx *ctx, struct blkcipher_walk *walk)
  319. {
  320. int ret = blkcipher_walk_virt_block(desc, walk, DES_BLOCK_SIZE);
  321. unsigned int i, n, nbytes;
  322. u8 buf[DES_BLOCK_SIZE];
  323. u8 *out, *in;
  324. memcpy(ctrblk, walk->iv, DES_BLOCK_SIZE);
  325. while ((nbytes = walk->nbytes) >= DES_BLOCK_SIZE) {
  326. out = walk->dst.virt.addr;
  327. in = walk->src.virt.addr;
  328. while (nbytes >= DES_BLOCK_SIZE) {
  329. /* align to block size, max. PAGE_SIZE */
  330. n = (nbytes > PAGE_SIZE) ? PAGE_SIZE :
  331. nbytes & ~(DES_BLOCK_SIZE - 1);
  332. for (i = DES_BLOCK_SIZE; i < n; i += DES_BLOCK_SIZE) {
  333. memcpy(ctrblk + i, ctrblk + i - DES_BLOCK_SIZE,
  334. DES_BLOCK_SIZE);
  335. crypto_inc(ctrblk + i, DES_BLOCK_SIZE);
  336. }
  337. ret = crypt_s390_kmctr(func, ctx->key, out, in, n, ctrblk);
  338. if (ret < 0 || ret != n)
  339. return -EIO;
  340. if (n > DES_BLOCK_SIZE)
  341. memcpy(ctrblk, ctrblk + n - DES_BLOCK_SIZE,
  342. DES_BLOCK_SIZE);
  343. crypto_inc(ctrblk, DES_BLOCK_SIZE);
  344. out += n;
  345. in += n;
  346. nbytes -= n;
  347. }
  348. ret = blkcipher_walk_done(desc, walk, nbytes);
  349. }
  350. /* final block may be < DES_BLOCK_SIZE, copy only nbytes */
  351. if (nbytes) {
  352. out = walk->dst.virt.addr;
  353. in = walk->src.virt.addr;
  354. ret = crypt_s390_kmctr(func, ctx->key, buf, in,
  355. DES_BLOCK_SIZE, ctrblk);
  356. if (ret < 0 || ret != DES_BLOCK_SIZE)
  357. return -EIO;
  358. memcpy(out, buf, nbytes);
  359. crypto_inc(ctrblk, DES_BLOCK_SIZE);
  360. ret = blkcipher_walk_done(desc, walk, 0);
  361. }
  362. memcpy(walk->iv, ctrblk, DES_BLOCK_SIZE);
  363. return ret;
  364. }
  365. static int ctr_des_encrypt(struct blkcipher_desc *desc,
  366. struct scatterlist *dst, struct scatterlist *src,
  367. unsigned int nbytes)
  368. {
  369. struct s390_des_ctx *ctx = crypto_blkcipher_ctx(desc->tfm);
  370. struct blkcipher_walk walk;
  371. blkcipher_walk_init(&walk, dst, src, nbytes);
  372. return ctr_desall_crypt(desc, KMCTR_DEA_ENCRYPT, ctx, &walk);
  373. }
  374. static int ctr_des_decrypt(struct blkcipher_desc *desc,
  375. struct scatterlist *dst, struct scatterlist *src,
  376. unsigned int nbytes)
  377. {
  378. struct s390_des_ctx *ctx = crypto_blkcipher_ctx(desc->tfm);
  379. struct blkcipher_walk walk;
  380. blkcipher_walk_init(&walk, dst, src, nbytes);
  381. return ctr_desall_crypt(desc, KMCTR_DEA_DECRYPT, ctx, &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 = CRYPT_S390_COMPOSITE_PRIORITY,
  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 s390_des_ctx *ctx = crypto_blkcipher_ctx(desc->tfm);
  408. struct blkcipher_walk walk;
  409. blkcipher_walk_init(&walk, dst, src, nbytes);
  410. return ctr_desall_crypt(desc, KMCTR_TDEA_192_ENCRYPT, ctx, &walk);
  411. }
  412. static int ctr_des3_decrypt(struct blkcipher_desc *desc,
  413. struct scatterlist *dst, struct scatterlist *src,
  414. unsigned int nbytes)
  415. {
  416. struct s390_des_ctx *ctx = crypto_blkcipher_ctx(desc->tfm);
  417. struct blkcipher_walk walk;
  418. blkcipher_walk_init(&walk, dst, src, nbytes);
  419. return ctr_desall_crypt(desc, KMCTR_TDEA_192_DECRYPT, ctx, &walk);
  420. }
  421. static struct crypto_alg ctr_des3_alg = {
  422. .cra_name = "ctr(des3_ede)",
  423. .cra_driver_name = "ctr-des3_ede-s390",
  424. .cra_priority = CRYPT_S390_COMPOSITE_PRIORITY,
  425. .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER,
  426. .cra_blocksize = 1,
  427. .cra_ctxsize = sizeof(struct s390_des_ctx),
  428. .cra_type = &crypto_blkcipher_type,
  429. .cra_module = THIS_MODULE,
  430. .cra_u = {
  431. .blkcipher = {
  432. .min_keysize = DES3_KEY_SIZE,
  433. .max_keysize = DES3_KEY_SIZE,
  434. .ivsize = DES_BLOCK_SIZE,
  435. .setkey = des3_setkey,
  436. .encrypt = ctr_des3_encrypt,
  437. .decrypt = ctr_des3_decrypt,
  438. }
  439. }
  440. };
  441. static int __init des_s390_init(void)
  442. {
  443. int ret;
  444. if (!crypt_s390_func_available(KM_DEA_ENCRYPT, CRYPT_S390_MSA) ||
  445. !crypt_s390_func_available(KM_TDEA_192_ENCRYPT, CRYPT_S390_MSA))
  446. return -EOPNOTSUPP;
  447. ret = crypto_register_alg(&des_alg);
  448. if (ret)
  449. goto des_err;
  450. ret = crypto_register_alg(&ecb_des_alg);
  451. if (ret)
  452. goto ecb_des_err;
  453. ret = crypto_register_alg(&cbc_des_alg);
  454. if (ret)
  455. goto cbc_des_err;
  456. ret = crypto_register_alg(&des3_alg);
  457. if (ret)
  458. goto des3_err;
  459. ret = crypto_register_alg(&ecb_des3_alg);
  460. if (ret)
  461. goto ecb_des3_err;
  462. ret = crypto_register_alg(&cbc_des3_alg);
  463. if (ret)
  464. goto cbc_des3_err;
  465. if (crypt_s390_func_available(KMCTR_DEA_ENCRYPT,
  466. CRYPT_S390_MSA | CRYPT_S390_MSA4) &&
  467. crypt_s390_func_available(KMCTR_TDEA_192_ENCRYPT,
  468. CRYPT_S390_MSA | CRYPT_S390_MSA4)) {
  469. ret = crypto_register_alg(&ctr_des_alg);
  470. if (ret)
  471. goto ctr_des_err;
  472. ret = crypto_register_alg(&ctr_des3_alg);
  473. if (ret)
  474. goto ctr_des3_err;
  475. ctrblk = (u8 *) __get_free_page(GFP_KERNEL);
  476. if (!ctrblk) {
  477. ret = -ENOMEM;
  478. goto ctr_mem_err;
  479. }
  480. }
  481. out:
  482. return ret;
  483. ctr_mem_err:
  484. crypto_unregister_alg(&ctr_des3_alg);
  485. ctr_des3_err:
  486. crypto_unregister_alg(&ctr_des_alg);
  487. ctr_des_err:
  488. crypto_unregister_alg(&cbc_des3_alg);
  489. cbc_des3_err:
  490. crypto_unregister_alg(&ecb_des3_alg);
  491. ecb_des3_err:
  492. crypto_unregister_alg(&des3_alg);
  493. des3_err:
  494. crypto_unregister_alg(&cbc_des_alg);
  495. cbc_des_err:
  496. crypto_unregister_alg(&ecb_des_alg);
  497. ecb_des_err:
  498. crypto_unregister_alg(&des_alg);
  499. des_err:
  500. goto out;
  501. }
  502. static void __exit des_s390_exit(void)
  503. {
  504. if (ctrblk) {
  505. crypto_unregister_alg(&ctr_des_alg);
  506. crypto_unregister_alg(&ctr_des3_alg);
  507. free_page((unsigned long) ctrblk);
  508. }
  509. crypto_unregister_alg(&cbc_des3_alg);
  510. crypto_unregister_alg(&ecb_des3_alg);
  511. crypto_unregister_alg(&des3_alg);
  512. crypto_unregister_alg(&cbc_des_alg);
  513. crypto_unregister_alg(&ecb_des_alg);
  514. crypto_unregister_alg(&des_alg);
  515. }
  516. module_init(des_s390_init);
  517. module_exit(des_s390_exit);
  518. MODULE_ALIAS("des");
  519. MODULE_ALIAS("des3_ede");
  520. MODULE_LICENSE("GPL");
  521. MODULE_DESCRIPTION("DES & Triple DES EDE Cipher Algorithms");