diff options
Diffstat (limited to 'crypto/digest.c')
-rw-r--r-- | crypto/digest.c | 42 |
1 files changed, 27 insertions, 15 deletions
diff --git a/crypto/digest.c b/crypto/digest.c index d9b6ac9dbf8d..062d0a5a2c89 100644 --- a/crypto/digest.c +++ b/crypto/digest.c | |||
@@ -27,6 +27,7 @@ static 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,24 @@ 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 | ||
45 | if (unlikely(offset & alignmask)) { | ||
46 | unsigned int bytes = | ||
47 | alignmask + 1 - (offset & alignmask); | ||
48 | bytes = min(bytes, bytes_from_page); | ||
49 | tfm->__crt_alg->cra_digest.dia_update | ||
50 | (crypto_tfm_ctx(tfm), p, | ||
51 | bytes); | ||
52 | p += bytes; | ||
53 | bytes_from_page -= bytes; | ||
54 | l -= bytes; | ||
55 | } | ||
43 | tfm->__crt_alg->cra_digest.dia_update | 56 | tfm->__crt_alg->cra_digest.dia_update |
44 | (crypto_tfm_ctx(tfm), p, | 57 | (crypto_tfm_ctx(tfm), p, |
45 | bytes_from_page); | 58 | bytes_from_page); |
46 | crypto_kunmap(p, 0); | 59 | crypto_kunmap(src, 0); |
47 | crypto_yield(tfm); | 60 | crypto_yield(tfm); |
48 | offset = 0; | 61 | offset = 0; |
49 | pg++; | 62 | pg++; |
@@ -54,7 +67,15 @@ static void update(struct crypto_tfm *tfm, | |||
54 | 67 | ||
55 | static void final(struct crypto_tfm *tfm, u8 *out) | 68 | static void final(struct crypto_tfm *tfm, u8 *out) |
56 | { | 69 | { |
57 | tfm->__crt_alg->cra_digest.dia_final(crypto_tfm_ctx(tfm), out); | 70 | unsigned long alignmask = crypto_tfm_alg_alignmask(tfm); |
71 | if (unlikely((unsigned long)out & alignmask)) { | ||
72 | unsigned int size = crypto_tfm_alg_digestsize(tfm); | ||
73 | u8 buffer[size + alignmask]; | ||
74 | u8 *dst = (u8 *)ALIGN((unsigned long)buffer, alignmask + 1); | ||
75 | tfm->__crt_alg->cra_digest.dia_final(crypto_tfm_ctx(tfm), dst); | ||
76 | memcpy(out, dst, size); | ||
77 | } else | ||
78 | tfm->__crt_alg->cra_digest.dia_final(crypto_tfm_ctx(tfm), out); | ||
58 | } | 79 | } |
59 | 80 | ||
60 | static int setkey(struct crypto_tfm *tfm, const u8 *key, unsigned int keylen) | 81 | static int setkey(struct crypto_tfm *tfm, const u8 *key, unsigned int keylen) |
@@ -69,18 +90,9 @@ static int setkey(struct crypto_tfm *tfm, const u8 *key, unsigned int keylen) | |||
69 | static void digest(struct crypto_tfm *tfm, | 90 | static void digest(struct crypto_tfm *tfm, |
70 | struct scatterlist *sg, unsigned int nsg, u8 *out) | 91 | struct scatterlist *sg, unsigned int nsg, u8 *out) |
71 | { | 92 | { |
72 | unsigned int i; | 93 | init(tfm); |
73 | 94 | update(tfm, sg, nsg); | |
74 | tfm->crt_digest.dit_init(tfm); | 95 | 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 | } | 96 | } |
85 | 97 | ||
86 | int crypto_init_digest_flags(struct crypto_tfm *tfm, u32 flags) | 98 | int crypto_init_digest_flags(struct crypto_tfm *tfm, u32 flags) |