diff options
author | Herbert Xu <herbert@gondor.apana.org.au> | 2006-05-16 08:09:29 -0400 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2006-06-26 03:34:39 -0400 |
commit | 6c2bb98bc33ae33c7a33a133a4cd5a06395fece5 (patch) | |
tree | 96684cd2c473cd05d651ce1fa3dd72b1b4b19b09 /crypto/sha256.c | |
parent | 43600106e32809a4dead79fec67a63e9860e3d5d (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/sha256.c')
-rw-r--r-- | crypto/sha256.c | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/crypto/sha256.c b/crypto/sha256.c index 4533a0564895..bc71d85a7d02 100644 --- a/crypto/sha256.c +++ b/crypto/sha256.c | |||
@@ -230,9 +230,9 @@ static void sha256_transform(u32 *state, const u8 *input) | |||
230 | memset(W, 0, 64 * sizeof(u32)); | 230 | memset(W, 0, 64 * sizeof(u32)); |
231 | } | 231 | } |
232 | 232 | ||
233 | static void sha256_init(void *ctx) | 233 | static void sha256_init(struct crypto_tfm *tfm) |
234 | { | 234 | { |
235 | struct sha256_ctx *sctx = ctx; | 235 | struct sha256_ctx *sctx = crypto_tfm_ctx(tfm); |
236 | sctx->state[0] = H0; | 236 | sctx->state[0] = H0; |
237 | sctx->state[1] = H1; | 237 | sctx->state[1] = H1; |
238 | sctx->state[2] = H2; | 238 | sctx->state[2] = H2; |
@@ -244,9 +244,10 @@ static void sha256_init(void *ctx) | |||
244 | sctx->count[0] = sctx->count[1] = 0; | 244 | sctx->count[0] = sctx->count[1] = 0; |
245 | } | 245 | } |
246 | 246 | ||
247 | static void sha256_update(void *ctx, const u8 *data, unsigned int len) | 247 | static void sha256_update(struct crypto_tfm *tfm, const u8 *data, |
248 | unsigned int len) | ||
248 | { | 249 | { |
249 | struct sha256_ctx *sctx = ctx; | 250 | struct sha256_ctx *sctx = crypto_tfm_ctx(tfm); |
250 | unsigned int i, index, part_len; | 251 | unsigned int i, index, part_len; |
251 | 252 | ||
252 | /* Compute number of bytes mod 128 */ | 253 | /* Compute number of bytes mod 128 */ |
@@ -276,9 +277,9 @@ static void sha256_update(void *ctx, const u8 *data, unsigned int len) | |||
276 | memcpy(&sctx->buf[index], &data[i], len-i); | 277 | memcpy(&sctx->buf[index], &data[i], len-i); |
277 | } | 278 | } |
278 | 279 | ||
279 | static void sha256_final(void* ctx, u8 *out) | 280 | static void sha256_final(struct crypto_tfm *tfm, u8 *out) |
280 | { | 281 | { |
281 | struct sha256_ctx *sctx = ctx; | 282 | struct sha256_ctx *sctx = crypto_tfm_ctx(tfm); |
282 | __be32 *dst = (__be32 *)out; | 283 | __be32 *dst = (__be32 *)out; |
283 | __be32 bits[2]; | 284 | __be32 bits[2]; |
284 | unsigned int index, pad_len; | 285 | unsigned int index, pad_len; |
@@ -292,10 +293,10 @@ static void sha256_final(void* ctx, u8 *out) | |||
292 | /* Pad out to 56 mod 64. */ | 293 | /* Pad out to 56 mod 64. */ |
293 | index = (sctx->count[0] >> 3) & 0x3f; | 294 | index = (sctx->count[0] >> 3) & 0x3f; |
294 | pad_len = (index < 56) ? (56 - index) : ((64+56) - index); | 295 | pad_len = (index < 56) ? (56 - index) : ((64+56) - index); |
295 | sha256_update(sctx, padding, pad_len); | 296 | sha256_update(tfm, padding, pad_len); |
296 | 297 | ||
297 | /* Append length (before padding) */ | 298 | /* Append length (before padding) */ |
298 | sha256_update(sctx, (const u8 *)bits, sizeof(bits)); | 299 | sha256_update(tfm, (const u8 *)bits, sizeof(bits)); |
299 | 300 | ||
300 | /* Store state in digest */ | 301 | /* Store state in digest */ |
301 | for (i = 0; i < 8; i++) | 302 | for (i = 0; i < 8; i++) |