|
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 | {
|
@@ -149,6 +153,41 @@ MODULE_ALIAS_CRYPTO("compress_null");
|
149 | 153 | MODULE_ALIAS_CRYPTO("digest_null");
|
150 | 154 | MODULE_ALIAS_CRYPTO("cipher_null");
|
151 | 155 |
|
| 156 | +struct crypto_blkcipher *crypto_get_default_null_skcipher(void) |
| 157 | +{ |
| 158 | + struct crypto_blkcipher *tfm; |
| 159 | + |
| 160 | + mutex_lock(&crypto_default_null_skcipher_lock); |
| 161 | + tfm = crypto_default_null_skcipher; |
| 162 | + |
| 163 | + if (!tfm) { |
| 164 | + tfm = crypto_alloc_blkcipher("ecb(cipher_null)", 0, 0); |
| 165 | + if (IS_ERR(tfm)) |
| 166 | + goto unlock; |
| 167 | + |
| 168 | + crypto_default_null_skcipher = tfm; |
| 169 | + } |
| 170 | + |
| 171 | + crypto_default_null_skcipher_refcnt++; |
| 172 | + |
| 173 | +unlock: |
| 174 | + mutex_unlock(&crypto_default_null_skcipher_lock); |
| 175 | + |
| 176 | + return tfm; |
| 177 | +} |
| 178 | +EXPORT_SYMBOL_GPL(crypto_get_default_null_skcipher); |
| 179 | + |
| 180 | +void crypto_put_default_null_skcipher(void) |
| 181 | +{ |
| 182 | + mutex_lock(&crypto_default_null_skcipher_lock); |
| 183 | + if (!--crypto_default_null_skcipher_refcnt) { |
| 184 | + crypto_free_blkcipher(crypto_default_null_skcipher); |
| 185 | + crypto_default_null_skcipher = NULL; |
| 186 | + } |
| 187 | + mutex_unlock(&crypto_default_null_skcipher_lock); |
| 188 | +} |
| 189 | +EXPORT_SYMBOL_GPL(crypto_put_default_null_skcipher); |
| 190 | + |
152 | 191 | static int __init crypto_null_mod_init(void)
|
153 | 192 | {
|
154 | 193 | int ret = 0;
|
|
0 commit comments