aboutsummaryrefslogtreecommitdiffstats
path: root/crypto/digest.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@g5.osdl.org>2006-06-26 14:03:29 -0400
committerLinus Torvalds <torvalds@g5.osdl.org>2006-06-26 14:03:29 -0400
commit972d19e837833b93466c6f6a8ef2a7d653000aa3 (patch)
tree069258492d5347cf440b8240dadfa20621f54842 /crypto/digest.c
parentcdf4f383a4b0ffbf458f65380ecffbeee1f79841 (diff)
parentb9d0a25a484a90c1d60b974d115eff2fe580ce16 (diff)
Merge master.kernel.org:/pub/scm/linux/kernel/git/herbert/crypto-2.6
* master.kernel.org:/pub/scm/linux/kernel/git/herbert/crypto-2.6: [CRYPTO] tcrypt: Forbid tcrypt from being built-in [CRYPTO] aes: Add wrappers for assembly routines [CRYPTO] tcrypt: Speed benchmark support for digest algorithms [CRYPTO] tcrypt: Return -EAGAIN from module_init() [CRYPTO] api: Allow replacement when registering new algorithms [CRYPTO] api: Removed const from cra_name/cra_driver_name [CRYPTO] api: Added cra_init/cra_exit [CRYPTO] api: Fixed incorrect passing of context instead of tfm [CRYPTO] padlock: Rearrange context structure to reduce code size [CRYPTO] all: Pass tfm instead of ctx to algorithms [CRYPTO] digest: Remove unnecessary zeroing during init [CRYPTO] aes-i586: Get rid of useless function wrappers [CRYPTO] digest: Add alignment handling [CRYPTO] khazad: Use 32-bit reads on key
Diffstat (limited to 'crypto/digest.c')
-rw-r--r--crypto/digest.c51
1 files changed, 30 insertions, 21 deletions
diff --git a/crypto/digest.c b/crypto/digest.c
index d9b6ac9dbf8d..603006a7bef2 100644
--- a/crypto/digest.c
+++ b/crypto/digest.c
@@ -20,13 +20,14 @@
20 20
21static void init(struct crypto_tfm *tfm) 21static void init(struct crypto_tfm *tfm)
22{ 22{
23 tfm->__crt_alg->cra_digest.dia_init(crypto_tfm_ctx(tfm)); 23 tfm->__crt_alg->cra_digest.dia_init(tfm);
24} 24}
25 25
26static void update(struct crypto_tfm *tfm, 26static void update(struct crypto_tfm *tfm,
27 struct scatterlist *sg, unsigned int nsg) 27 struct scatterlist *sg, unsigned int nsg)
28{ 28{
29 unsigned int i; 29 unsigned int i;
30 unsigned int alignmask = crypto_tfm_alg_alignmask(tfm);
30 31
31 for (i = 0; i < nsg; i++) { 32 for (i = 0; i < nsg; i++) {
32 33
@@ -38,12 +39,22 @@ static void update(struct crypto_tfm *tfm,
38 unsigned int bytes_from_page = min(l, ((unsigned int) 39 unsigned int bytes_from_page = min(l, ((unsigned int)
39 (PAGE_SIZE)) - 40 (PAGE_SIZE)) -
40 offset); 41 offset);
41 char *p = crypto_kmap(pg, 0) + offset; 42 char *src = crypto_kmap(pg, 0);
43 char *p = src + offset;
42 44
43 tfm->__crt_alg->cra_digest.dia_update 45 if (unlikely(offset & alignmask)) {
44 (crypto_tfm_ctx(tfm), p, 46 unsigned int bytes =
45 bytes_from_page); 47 alignmask + 1 - (offset & alignmask);
46 crypto_kunmap(p, 0); 48 bytes = min(bytes, bytes_from_page);
49 tfm->__crt_alg->cra_digest.dia_update(tfm, p,
50 bytes);
51 p += bytes;
52 bytes_from_page -= bytes;
53 l -= bytes;
54 }
55 tfm->__crt_alg->cra_digest.dia_update(tfm, p,
56 bytes_from_page);
57 crypto_kunmap(src, 0);
47 crypto_yield(tfm); 58 crypto_yield(tfm);
48 offset = 0; 59 offset = 0;
49 pg++; 60 pg++;
@@ -54,7 +65,15 @@ static void update(struct crypto_tfm *tfm,
54 65
55static void final(struct crypto_tfm *tfm, u8 *out) 66static void final(struct crypto_tfm *tfm, u8 *out)
56{ 67{
57 tfm->__crt_alg->cra_digest.dia_final(crypto_tfm_ctx(tfm), out); 68 unsigned long alignmask = crypto_tfm_alg_alignmask(tfm);
69 if (unlikely((unsigned long)out & alignmask)) {
70 unsigned int size = crypto_tfm_alg_digestsize(tfm);
71 u8 buffer[size + alignmask];
72 u8 *dst = (u8 *)ALIGN((unsigned long)buffer, alignmask + 1);
73 tfm->__crt_alg->cra_digest.dia_final(tfm, dst);
74 memcpy(out, dst, size);
75 } else
76 tfm->__crt_alg->cra_digest.dia_final(tfm, out);
58} 77}
59 78
60static int setkey(struct crypto_tfm *tfm, const u8 *key, unsigned int keylen) 79static int setkey(struct crypto_tfm *tfm, const u8 *key, unsigned int keylen)
@@ -62,25 +81,15 @@ static int setkey(struct crypto_tfm *tfm, const u8 *key, unsigned int keylen)
62 u32 flags; 81 u32 flags;
63 if (tfm->__crt_alg->cra_digest.dia_setkey == NULL) 82 if (tfm->__crt_alg->cra_digest.dia_setkey == NULL)
64 return -ENOSYS; 83 return -ENOSYS;
65 return tfm->__crt_alg->cra_digest.dia_setkey(crypto_tfm_ctx(tfm), 84 return tfm->__crt_alg->cra_digest.dia_setkey(tfm, key, keylen, &flags);
66 key, keylen, &flags);
67} 85}
68 86
69static void digest(struct crypto_tfm *tfm, 87static void digest(struct crypto_tfm *tfm,
70 struct scatterlist *sg, unsigned int nsg, u8 *out) 88 struct scatterlist *sg, unsigned int nsg, u8 *out)
71{ 89{
72 unsigned int i; 90 init(tfm);
73 91 update(tfm, sg, nsg);
74 tfm->crt_digest.dit_init(tfm); 92 final(tfm, out);
75
76 for (i = 0; i < nsg; i++) {
77 char *p = crypto_kmap(sg[i].page, 0) + sg[i].offset;
78 tfm->__crt_alg->cra_digest.dia_update(crypto_tfm_ctx(tfm),
79 p, sg[i].length);
80 crypto_kunmap(p, 0);
81 crypto_yield(tfm);
82 }
83 crypto_digest_final(tfm, out);
84} 93}
85 94
86int crypto_init_digest_flags(struct crypto_tfm *tfm, u32 flags) 95int crypto_init_digest_flags(struct crypto_tfm *tfm, u32 flags)