aboutsummaryrefslogtreecommitdiffstats
path: root/crypto/sha1_generic.c
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/sha1_generic.c')
-rw-r--r--crypto/sha1_generic.c56
1 files changed, 31 insertions, 25 deletions
diff --git a/crypto/sha1_generic.c b/crypto/sha1_generic.c
index c7c6899e1fca..9efef20454cb 100644
--- a/crypto/sha1_generic.c
+++ b/crypto/sha1_generic.c
@@ -16,10 +16,10 @@
16 * any later version. 16 * any later version.
17 * 17 *
18 */ 18 */
19#include <crypto/internal/hash.h>
19#include <linux/init.h> 20#include <linux/init.h>
20#include <linux/module.h> 21#include <linux/module.h>
21#include <linux/mm.h> 22#include <linux/mm.h>
22#include <linux/crypto.h>
23#include <linux/cryptohash.h> 23#include <linux/cryptohash.h>
24#include <linux/types.h> 24#include <linux/types.h>
25#include <crypto/sha.h> 25#include <crypto/sha.h>
@@ -31,9 +31,10 @@ struct sha1_ctx {
31 u8 buffer[64]; 31 u8 buffer[64];
32}; 32};
33 33
34static void sha1_init(struct crypto_tfm *tfm) 34static int sha1_init(struct shash_desc *desc)
35{ 35{
36 struct sha1_ctx *sctx = crypto_tfm_ctx(tfm); 36 struct sha1_ctx *sctx = shash_desc_ctx(desc);
37
37 static const struct sha1_ctx initstate = { 38 static const struct sha1_ctx initstate = {
38 0, 39 0,
39 { SHA1_H0, SHA1_H1, SHA1_H2, SHA1_H3, SHA1_H4 }, 40 { SHA1_H0, SHA1_H1, SHA1_H2, SHA1_H3, SHA1_H4 },
@@ -41,12 +42,14 @@ static void sha1_init(struct crypto_tfm *tfm)
41 }; 42 };
42 43
43 *sctx = initstate; 44 *sctx = initstate;
45
46 return 0;
44} 47}
45 48
46static void sha1_update(struct crypto_tfm *tfm, const u8 *data, 49static int sha1_update(struct shash_desc *desc, const u8 *data,
47 unsigned int len) 50 unsigned int len)
48{ 51{
49 struct sha1_ctx *sctx = crypto_tfm_ctx(tfm); 52 struct sha1_ctx *sctx = shash_desc_ctx(desc);
50 unsigned int partial, done; 53 unsigned int partial, done;
51 const u8 *src; 54 const u8 *src;
52 55
@@ -74,13 +77,15 @@ static void sha1_update(struct crypto_tfm *tfm, const u8 *data,
74 partial = 0; 77 partial = 0;
75 } 78 }
76 memcpy(sctx->buffer + partial, src, len - done); 79 memcpy(sctx->buffer + partial, src, len - done);
80
81 return 0;
77} 82}
78 83
79 84
80/* Add padding and return the message digest. */ 85/* Add padding and return the message digest. */
81static void sha1_final(struct crypto_tfm *tfm, u8 *out) 86static int sha1_final(struct shash_desc *desc, u8 *out)
82{ 87{
83 struct sha1_ctx *sctx = crypto_tfm_ctx(tfm); 88 struct sha1_ctx *sctx = shash_desc_ctx(desc);
84 __be32 *dst = (__be32 *)out; 89 __be32 *dst = (__be32 *)out;
85 u32 i, index, padlen; 90 u32 i, index, padlen;
86 __be64 bits; 91 __be64 bits;
@@ -91,10 +96,10 @@ static void sha1_final(struct crypto_tfm *tfm, u8 *out)
91 /* Pad out to 56 mod 64 */ 96 /* Pad out to 56 mod 64 */
92 index = sctx->count & 0x3f; 97 index = sctx->count & 0x3f;
93 padlen = (index < 56) ? (56 - index) : ((64+56) - index); 98 padlen = (index < 56) ? (56 - index) : ((64+56) - index);
94 sha1_update(tfm, padding, padlen); 99 sha1_update(desc, padding, padlen);
95 100
96 /* Append length */ 101 /* Append length */
97 sha1_update(tfm, (const u8 *)&bits, sizeof(bits)); 102 sha1_update(desc, (const u8 *)&bits, sizeof(bits));
98 103
99 /* Store state in digest */ 104 /* Store state in digest */
100 for (i = 0; i < 5; i++) 105 for (i = 0; i < 5; i++)
@@ -102,32 +107,33 @@ static void sha1_final(struct crypto_tfm *tfm, u8 *out)
102 107
103 /* Wipe context */ 108 /* Wipe context */
104 memset(sctx, 0, sizeof *sctx); 109 memset(sctx, 0, sizeof *sctx);
110
111 return 0;
105} 112}
106 113
107static struct crypto_alg alg = { 114static struct shash_alg alg = {
108 .cra_name = "sha1", 115 .digestsize = SHA1_DIGEST_SIZE,
109 .cra_driver_name= "sha1-generic", 116 .init = sha1_init,
110 .cra_flags = CRYPTO_ALG_TYPE_DIGEST, 117 .update = sha1_update,
111 .cra_blocksize = SHA1_BLOCK_SIZE, 118 .final = sha1_final,
112 .cra_ctxsize = sizeof(struct sha1_ctx), 119 .descsize = sizeof(struct sha1_ctx),
113 .cra_module = THIS_MODULE, 120 .base = {
114 .cra_alignmask = 3, 121 .cra_name = "sha1",
115 .cra_list = LIST_HEAD_INIT(alg.cra_list), 122 .cra_driver_name= "sha1-generic",
116 .cra_u = { .digest = { 123 .cra_flags = CRYPTO_ALG_TYPE_SHASH,
117 .dia_digestsize = SHA1_DIGEST_SIZE, 124 .cra_blocksize = SHA1_BLOCK_SIZE,
118 .dia_init = sha1_init, 125 .cra_module = THIS_MODULE,
119 .dia_update = sha1_update, 126 }
120 .dia_final = sha1_final } }
121}; 127};
122 128
123static int __init sha1_generic_mod_init(void) 129static int __init sha1_generic_mod_init(void)
124{ 130{
125 return crypto_register_alg(&alg); 131 return crypto_register_shash(&alg);
126} 132}
127 133
128static void __exit sha1_generic_mod_fini(void) 134static void __exit sha1_generic_mod_fini(void)
129{ 135{
130 crypto_unregister_alg(&alg); 136 crypto_unregister_shash(&alg);
131} 137}
132 138
133module_init(sha1_generic_mod_init); 139module_init(sha1_generic_mod_init);