Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

crypto: null - Add default null skcipher

This patch adds a default null skcipher for users such as gcm
to perform copies on SG lists.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

+42
+39
crypto/crypto_null.c
··· 25 25 #include <linux/mm.h> 26 26 #include <linux/string.h> 27 27 28 + static DEFINE_MUTEX(crypto_default_null_skcipher_lock); 29 + static struct crypto_blkcipher *crypto_default_null_skcipher; 30 + static int crypto_default_null_skcipher_refcnt; 31 + 28 32 static int null_compress(struct crypto_tfm *tfm, const u8 *src, 29 33 unsigned int slen, u8 *dst, unsigned int *dlen) 30 34 { ··· 152 148 MODULE_ALIAS_CRYPTO("compress_null"); 153 149 MODULE_ALIAS_CRYPTO("digest_null"); 154 150 MODULE_ALIAS_CRYPTO("cipher_null"); 151 + 152 + struct crypto_blkcipher *crypto_get_default_null_skcipher(void) 153 + { 154 + struct crypto_blkcipher *tfm; 155 + 156 + mutex_lock(&crypto_default_null_skcipher_lock); 157 + tfm = crypto_default_null_skcipher; 158 + 159 + if (!tfm) { 160 + tfm = crypto_alloc_blkcipher("ecb(cipher_null)", 0, 0); 161 + if (IS_ERR(tfm)) 162 + goto unlock; 163 + 164 + crypto_default_null_skcipher = tfm; 165 + } 166 + 167 + crypto_default_null_skcipher_refcnt++; 168 + 169 + unlock: 170 + mutex_unlock(&crypto_default_null_skcipher_lock); 171 + 172 + return tfm; 173 + } 174 + EXPORT_SYMBOL_GPL(crypto_get_default_null_skcipher); 175 + 176 + void crypto_put_default_null_skcipher(void) 177 + { 178 + mutex_lock(&crypto_default_null_skcipher_lock); 179 + if (!--crypto_default_null_skcipher_refcnt) { 180 + crypto_free_blkcipher(crypto_default_null_skcipher); 181 + crypto_default_null_skcipher = NULL; 182 + } 183 + mutex_unlock(&crypto_default_null_skcipher_lock); 184 + } 185 + EXPORT_SYMBOL_GPL(crypto_put_default_null_skcipher); 155 186 156 187 static int __init crypto_null_mod_init(void) 157 188 {
+3
include/crypto/null.h
··· 8 8 #define NULL_DIGEST_SIZE 0 9 9 #define NULL_IV_SIZE 0 10 10 11 + struct crypto_blkcipher *crypto_get_default_null_skcipher(void); 12 + void crypto_put_default_null_skcipher(void); 13 + 11 14 #endif