Skip to content

Commit 7c39017

Browse files
minipliherbertx
authored andcommitted
crypto: sha1 - export sha1_update for reuse
Export the update function as crypto_sha1_update() to not have the need to reimplement the same algorithm for each SHA-1 implementation. This way the generic SHA-1 implementation can be used as fallback for other implementations that fail to run under certain circumstances, like the need for an FPU context while executing in IRQ context. Signed-off-by: Mathias Krause <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent b64dc04 commit 7c39017

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

crypto/sha1_generic.c

+5-4
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ static int sha1_init(struct shash_desc *desc)
3636
return 0;
3737
}
3838

39-
static int sha1_update(struct shash_desc *desc, const u8 *data,
39+
int crypto_sha1_update(struct shash_desc *desc, const u8 *data,
4040
unsigned int len)
4141
{
4242
struct sha1_state *sctx = shash_desc_ctx(desc);
@@ -71,6 +71,7 @@ static int sha1_update(struct shash_desc *desc, const u8 *data,
7171

7272
return 0;
7373
}
74+
EXPORT_SYMBOL(crypto_sha1_update);
7475

7576

7677
/* Add padding and return the message digest. */
@@ -87,10 +88,10 @@ static int sha1_final(struct shash_desc *desc, u8 *out)
8788
/* Pad out to 56 mod 64 */
8889
index = sctx->count & 0x3f;
8990
padlen = (index < 56) ? (56 - index) : ((64+56) - index);
90-
sha1_update(desc, padding, padlen);
91+
crypto_sha1_update(desc, padding, padlen);
9192

9293
/* Append length */
93-
sha1_update(desc, (const u8 *)&bits, sizeof(bits));
94+
crypto_sha1_update(desc, (const u8 *)&bits, sizeof(bits));
9495

9596
/* Store state in digest */
9697
for (i = 0; i < 5; i++)
@@ -121,7 +122,7 @@ static int sha1_import(struct shash_desc *desc, const void *in)
121122
static struct shash_alg alg = {
122123
.digestsize = SHA1_DIGEST_SIZE,
123124
.init = sha1_init,
124-
.update = sha1_update,
125+
.update = crypto_sha1_update,
125126
.final = sha1_final,
126127
.export = sha1_export,
127128
.import = sha1_import,

include/crypto/sha.h

+3
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,7 @@ struct sha512_state {
8282
u8 buf[SHA512_BLOCK_SIZE];
8383
};
8484

85+
extern int crypto_sha1_update(struct shash_desc *desc, const u8 *data,
86+
unsigned int len);
87+
8588
#endif

0 commit comments

Comments
 (0)