diff options
Diffstat (limited to 'crypto/digest.c')
| -rw-r--r-- | crypto/digest.c | 51 |
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 | ||
| 21 | static void init(struct crypto_tfm *tfm) | 21 | static 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 | ||
| 26 | static void update(struct crypto_tfm *tfm, | 26 | 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,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 | ||
| 55 | static void final(struct crypto_tfm *tfm, u8 *out) | 66 | static 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 | ||
| 60 | static int setkey(struct crypto_tfm *tfm, const u8 *key, unsigned int keylen) | 79 | static 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 | ||
| 69 | static void digest(struct crypto_tfm *tfm, | 87 | static 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 | ||
| 86 | int crypto_init_digest_flags(struct crypto_tfm *tfm, u32 flags) | 95 | int crypto_init_digest_flags(struct crypto_tfm *tfm, u32 flags) |
