aboutsummaryrefslogtreecommitdiffstats
path: root/crypto/sha512.c
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2006-05-16 08:09:29 -0400
committerHerbert Xu <herbert@gondor.apana.org.au>2006-06-26 03:34:39 -0400
commit6c2bb98bc33ae33c7a33a133a4cd5a06395fece5 (patch)
tree96684cd2c473cd05d651ce1fa3dd72b1b4b19b09 /crypto/sha512.c
parent43600106e32809a4dead79fec67a63e9860e3d5d (diff)
[CRYPTO] all: Pass tfm instead of ctx to algorithms
Up until now algorithms have been happy to get a context pointer since they know everything that's in the tfm already (e.g., alignment, block size). However, once we have parameterised algorithms, such information will be specific to each tfm. So the algorithm API needs to be changed to pass the tfm structure instead of the context pointer. This patch is basically a text substitution. The only tricky bit is the assembly routines that need to get the context pointer offset through asm-offsets.h. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'crypto/sha512.c')
-rw-r--r--crypto/sha512.c25
1 files changed, 12 insertions, 13 deletions
diff --git a/crypto/sha512.c b/crypto/sha512.c
index bc77a66d9de2..2dfe7f170b48 100644
--- a/crypto/sha512.c
+++ b/crypto/sha512.c
@@ -161,9 +161,9 @@ sha512_transform(u64 *state, u64 *W, const u8 *input)
161} 161}
162 162
163static void 163static void
164sha512_init(void *ctx) 164sha512_init(struct crypto_tfm *tfm)
165{ 165{
166 struct sha512_ctx *sctx = ctx; 166 struct sha512_ctx *sctx = crypto_tfm_ctx(tfm);
167 sctx->state[0] = H0; 167 sctx->state[0] = H0;
168 sctx->state[1] = H1; 168 sctx->state[1] = H1;
169 sctx->state[2] = H2; 169 sctx->state[2] = H2;
@@ -176,9 +176,9 @@ sha512_init(void *ctx)
176} 176}
177 177
178static void 178static void
179sha384_init(void *ctx) 179sha384_init(struct crypto_tfm *tfm)
180{ 180{
181 struct sha512_ctx *sctx = ctx; 181 struct sha512_ctx *sctx = crypto_tfm_ctx(tfm);
182 sctx->state[0] = HP0; 182 sctx->state[0] = HP0;
183 sctx->state[1] = HP1; 183 sctx->state[1] = HP1;
184 sctx->state[2] = HP2; 184 sctx->state[2] = HP2;
@@ -191,9 +191,9 @@ sha384_init(void *ctx)
191} 191}
192 192
193static void 193static void
194sha512_update(void *ctx, const u8 *data, unsigned int len) 194sha512_update(struct crypto_tfm *tfm, const u8 *data, unsigned int len)
195{ 195{
196 struct sha512_ctx *sctx = ctx; 196 struct sha512_ctx *sctx = crypto_tfm_ctx(tfm);
197 197
198 unsigned int i, index, part_len; 198 unsigned int i, index, part_len;
199 199
@@ -231,9 +231,9 @@ sha512_update(void *ctx, const u8 *data, unsigned int len)
231} 231}
232 232
233static void 233static void
234sha512_final(void *ctx, u8 *hash) 234sha512_final(struct crypto_tfm *tfm, u8 *hash)
235{ 235{
236 struct sha512_ctx *sctx = ctx; 236 struct sha512_ctx *sctx = crypto_tfm_ctx(tfm);
237 static u8 padding[128] = { 0x80, }; 237 static u8 padding[128] = { 0x80, };
238 __be64 *dst = (__be64 *)hash; 238 __be64 *dst = (__be64 *)hash;
239 __be32 bits[4]; 239 __be32 bits[4];
@@ -249,10 +249,10 @@ sha512_final(void *ctx, u8 *hash)
249 /* Pad out to 112 mod 128. */ 249 /* Pad out to 112 mod 128. */
250 index = (sctx->count[0] >> 3) & 0x7f; 250 index = (sctx->count[0] >> 3) & 0x7f;
251 pad_len = (index < 112) ? (112 - index) : ((128+112) - index); 251 pad_len = (index < 112) ? (112 - index) : ((128+112) - index);
252 sha512_update(sctx, padding, pad_len); 252 sha512_update(tfm, padding, pad_len);
253 253
254 /* Append length (before padding) */ 254 /* Append length (before padding) */
255 sha512_update(sctx, (const u8 *)bits, sizeof(bits)); 255 sha512_update(tfm, (const u8 *)bits, sizeof(bits));
256 256
257 /* Store state in digest */ 257 /* Store state in digest */
258 for (i = 0; i < 8; i++) 258 for (i = 0; i < 8; i++)
@@ -262,12 +262,11 @@ sha512_final(void *ctx, u8 *hash)
262 memset(sctx, 0, sizeof(struct sha512_ctx)); 262 memset(sctx, 0, sizeof(struct sha512_ctx));
263} 263}
264 264
265static void sha384_final(void *ctx, u8 *hash) 265static void sha384_final(struct crypto_tfm *tfm, u8 *hash)
266{ 266{
267 struct sha512_ctx *sctx = ctx;
268 u8 D[64]; 267 u8 D[64];
269 268
270 sha512_final(sctx, D); 269 sha512_final(tfm, D);
271 270
272 memcpy(hash, D, 48); 271 memcpy(hash, D, 48);
273 memset(D, 0, 64); 272 memset(D, 0, 64);