1 // SPDX-License-Identifier: GPL-2.0-or-later 1 2 /* 3 * Cryptographic API for the 842 software comp 4 * 5 * Copyright (C) IBM Corporation, 2011-2015 6 * 7 * Original Authors: Robert Jennings <rcj@linu 8 * Seth Jennings <sjenning@l 9 * 10 * Rewrite: Dan Streetman <ddstreet@ieee.org> 11 * 12 * This is the software implementation of comp 13 * the 842 format. This uses the software 842 14 * only a reference implementation, and is ver 15 * software compressors. You probably do not 16 * compression. If you have access to the Pow 17 * want to use the 842 hardware compression in 18 * drivers/crypto/nx/nx-842-crypto.c 19 */ 20 21 #include <linux/init.h> 22 #include <linux/module.h> 23 #include <linux/crypto.h> 24 #include <linux/sw842.h> 25 #include <crypto/internal/scompress.h> 26 27 struct crypto842_ctx { 28 void *wmem; /* working memory for 29 }; 30 31 static void *crypto842_alloc_ctx(struct crypto 32 { 33 void *ctx; 34 35 ctx = kmalloc(SW842_MEM_COMPRESS, GFP_ 36 if (!ctx) 37 return ERR_PTR(-ENOMEM); 38 39 return ctx; 40 } 41 42 static int crypto842_init(struct crypto_tfm *t 43 { 44 struct crypto842_ctx *ctx = crypto_tfm 45 46 ctx->wmem = crypto842_alloc_ctx(NULL); 47 if (IS_ERR(ctx->wmem)) 48 return -ENOMEM; 49 50 return 0; 51 } 52 53 static void crypto842_free_ctx(struct crypto_s 54 { 55 kfree(ctx); 56 } 57 58 static void crypto842_exit(struct crypto_tfm * 59 { 60 struct crypto842_ctx *ctx = crypto_tfm 61 62 crypto842_free_ctx(NULL, ctx->wmem); 63 } 64 65 static int crypto842_compress(struct crypto_tf 66 const u8 *src, u 67 u8 *dst, unsigne 68 { 69 struct crypto842_ctx *ctx = crypto_tfm 70 71 return sw842_compress(src, slen, dst, 72 } 73 74 static int crypto842_scompress(struct crypto_s 75 const u8 *src, 76 u8 *dst, unsign 77 { 78 return sw842_compress(src, slen, dst, 79 } 80 81 static int crypto842_decompress(struct crypto_ 82 const u8 *src, 83 u8 *dst, unsig 84 { 85 return sw842_decompress(src, slen, dst 86 } 87 88 static int crypto842_sdecompress(struct crypto 89 const u8 *src 90 u8 *dst, unsi 91 { 92 return sw842_decompress(src, slen, dst 93 } 94 95 static struct crypto_alg alg = { 96 .cra_name = "842", 97 .cra_driver_name = "842-generic 98 .cra_priority = 100, 99 .cra_flags = CRYPTO_ALG_T 100 .cra_ctxsize = sizeof(struc 101 .cra_module = THIS_MODULE, 102 .cra_init = crypto842_in 103 .cra_exit = crypto842_ex 104 .cra_u = { .compress 105 .coa_compress = crypto842_co 106 .coa_decompress = crypto842_de 107 }; 108 109 static struct scomp_alg scomp = { 110 .alloc_ctx = crypto842_al 111 .free_ctx = crypto842_fr 112 .compress = crypto842_sc 113 .decompress = crypto842_sd 114 .base = { 115 .cra_name = "842", 116 .cra_driver_name = "842-scomp" 117 .cra_priority = 100, 118 .cra_module = THIS_MODULE 119 } 120 }; 121 122 static int __init crypto842_mod_init(void) 123 { 124 int ret; 125 126 ret = crypto_register_alg(&alg); 127 if (ret) 128 return ret; 129 130 ret = crypto_register_scomp(&scomp); 131 if (ret) { 132 crypto_unregister_alg(&alg); 133 return ret; 134 } 135 136 return ret; 137 } 138 subsys_initcall(crypto842_mod_init); 139 140 static void __exit crypto842_mod_exit(void) 141 { 142 crypto_unregister_alg(&alg); 143 crypto_unregister_scomp(&scomp); 144 } 145 module_exit(crypto842_mod_exit); 146 147 MODULE_LICENSE("GPL"); 148 MODULE_DESCRIPTION("842 Software Compression A 149 MODULE_ALIAS_CRYPTO("842"); 150 MODULE_ALIAS_CRYPTO("842-generic"); 151 MODULE_AUTHOR("Dan Streetman <ddstreet@ieee.or 152
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.