Skip to content

Commit d35d245

Browse files
committed
crypto: null - Switch to shash
This patch changes digest_null to the new shash interface. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent 3751f40 commit d35d245

2 files changed

Lines changed: 42 additions & 23 deletions

File tree

‎crypto/Kconfig‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ config CRYPTO_NULL
102102
tristate "Null algorithms"
103103
select CRYPTO_ALGAPI
104104
select CRYPTO_BLKCIPHER
105+
select CRYPTO_HASH
105106
help
106107
These are 'Null' algorithms, used by IPsec, which do nothing.
107108

‎crypto/crypto_null.c‎

Lines changed: 41 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
*
1818
*/
1919

20+
#include <crypto/internal/hash.h>
2021
#include <crypto/internal/skcipher.h>
2122
#include <linux/init.h>
2223
#include <linux/module.h>
@@ -38,15 +39,31 @@ static int null_compress(struct crypto_tfm *tfm, const u8 *src,
3839
return 0;
3940
}
4041

41-
static void null_init(struct crypto_tfm *tfm)
42-
{ }
42+
static int null_init(struct shash_desc *desc)
43+
{
44+
return 0;
45+
}
4346

44-
static void null_update(struct crypto_tfm *tfm, const u8 *data,
45-
unsigned int len)
46-
{ }
47+
static int null_update(struct shash_desc *desc, const u8 *data,
48+
unsigned int len)
49+
{
50+
return 0;
51+
}
4752

48-
static void null_final(struct crypto_tfm *tfm, u8 *out)
49-
{ }
53+
static int null_final(struct shash_desc *desc, u8 *out)
54+
{
55+
return 0;
56+
}
57+
58+
static int null_digest(struct shash_desc *desc, const u8 *data,
59+
unsigned int len, u8 *out)
60+
{
61+
return 0;
62+
}
63+
64+
static int null_hash_setkey(struct crypto_shash *tfm, const u8 *key,
65+
unsigned int keylen)
66+
{ return 0; }
5067

5168
static int null_setkey(struct crypto_tfm *tfm, const u8 *key,
5269
unsigned int keylen)
@@ -89,19 +106,20 @@ static struct crypto_alg compress_null = {
89106
.coa_decompress = null_compress } }
90107
};
91108

92-
static struct crypto_alg digest_null = {
93-
.cra_name = "digest_null",
94-
.cra_flags = CRYPTO_ALG_TYPE_DIGEST,
95-
.cra_blocksize = NULL_BLOCK_SIZE,
96-
.cra_ctxsize = 0,
97-
.cra_module = THIS_MODULE,
98-
.cra_list = LIST_HEAD_INIT(digest_null.cra_list),
99-
.cra_u = { .digest = {
100-
.dia_digestsize = NULL_DIGEST_SIZE,
101-
.dia_setkey = null_setkey,
102-
.dia_init = null_init,
103-
.dia_update = null_update,
104-
.dia_final = null_final } }
109+
static struct shash_alg digest_null = {
110+
.digestsize = NULL_DIGEST_SIZE,
111+
.setkey = null_hash_setkey,
112+
.init = null_init,
113+
.update = null_update,
114+
.finup = null_digest,
115+
.digest = null_digest,
116+
.final = null_final,
117+
.base = {
118+
.cra_name = "digest_null",
119+
.cra_flags = CRYPTO_ALG_TYPE_SHASH,
120+
.cra_blocksize = NULL_BLOCK_SIZE,
121+
.cra_module = THIS_MODULE,
122+
}
105123
};
106124

107125
static struct crypto_alg cipher_null = {
@@ -154,7 +172,7 @@ static int __init crypto_null_mod_init(void)
154172
if (ret < 0)
155173
goto out_unregister_cipher;
156174

157-
ret = crypto_register_alg(&digest_null);
175+
ret = crypto_register_shash(&digest_null);
158176
if (ret < 0)
159177
goto out_unregister_skcipher;
160178

@@ -166,7 +184,7 @@ static int __init crypto_null_mod_init(void)
166184
return ret;
167185

168186
out_unregister_digest:
169-
crypto_unregister_alg(&digest_null);
187+
crypto_unregister_shash(&digest_null);
170188
out_unregister_skcipher:
171189
crypto_unregister_alg(&skcipher_null);
172190
out_unregister_cipher:
@@ -177,7 +195,7 @@ static int __init crypto_null_mod_init(void)
177195
static void __exit crypto_null_mod_fini(void)
178196
{
179197
crypto_unregister_alg(&compress_null);
180-
crypto_unregister_alg(&digest_null);
198+
crypto_unregister_shash(&digest_null);
181199
crypto_unregister_alg(&skcipher_null);
182200
crypto_unregister_alg(&cipher_null);
183201
}

0 commit comments

Comments
 (0)