diff options
| author | Mauro Carvalho Chehab <mchehab@osg.samsung.com> | 2015-04-21 05:33:03 -0400 |
|---|---|---|
| committer | Mauro Carvalho Chehab <mchehab@osg.samsung.com> | 2015-04-21 08:44:55 -0400 |
| commit | 64131a87f2aae2ed9e05d8227c5b009ca6c50d98 (patch) | |
| tree | fdea23fd59216120bf54a48c60ca24489a733f14 /include/crypto | |
| parent | 676ee36be04985062522804c2de04f0764212be6 (diff) | |
| parent | 2c33ce009ca2389dbf0535d0672214d09738e35e (diff) | |
Merge branch 'drm-next-merged' of git://people.freedesktop.org/~airlied/linux into v4l_for_linus
* 'drm-next-merged' of git://people.freedesktop.org/~airlied/linux: (9717 commits)
media-bus: Fixup RGB444_1X12, RGB565_1X16, and YUV8_1X24 media bus format
hexdump: avoid warning in test function
fs: take i_mutex during prepare_binprm for set[ug]id executables
smp: Fix error case handling in smp_call_function_*()
iommu-common: Fix PARISC compile-time warnings
sparc: Make LDC use common iommu poll management functions
sparc: Make sparc64 use scalable lib/iommu-common.c functions
Break up monolithic iommu table/lock into finer graularity pools and lock
sparc: Revert generic IOMMU allocator.
tools/power turbostat: correct dumped pkg-cstate-limit value
tools/power turbostat: calculate TSC frequency from CPUID(0x15) on SKL
tools/power turbostat: correct DRAM RAPL units on recent Xeon processors
tools/power turbostat: Initial Skylake support
tools/power turbostat: Use $(CURDIR) instead of $(PWD) and add support for O= option in Makefile
tools/power turbostat: modprobe msr, if needed
tools/power turbostat: dump MSR_TURBO_RATIO_LIMIT2
tools/power turbostat: use new MSR_TURBO_RATIO_LIMIT names
Bluetooth: hidp: Fix regression with older userspace and flags validation
config: Enable NEED_DMA_MAP_STATE by default when SWIOTLB is selected
perf/x86/intel/pt: Fix and clean up error handling in pt_event_add()
...
That solves several merge conflicts:
Documentation/DocBook/media/v4l/subdev-formats.xml
Documentation/devicetree/bindings/vendor-prefixes.txt
drivers/staging/media/mn88473/mn88473.c
include/linux/kconfig.h
include/uapi/linux/media-bus-format.h
The ones at subdev-formats.xml and media-bus-format.h are not trivial.
That's why we opted to merge from DRM.
Diffstat (limited to 'include/crypto')
| -rw-r--r-- | include/crypto/algapi.h | 2 | ||||
| -rw-r--r-- | include/crypto/if_alg.h | 4 | ||||
| -rw-r--r-- | include/crypto/rng.h | 3 | ||||
| -rw-r--r-- | include/crypto/sha.h | 15 | ||||
| -rw-r--r-- | include/crypto/sha1_base.h | 106 | ||||
| -rw-r--r-- | include/crypto/sha256_base.h | 128 | ||||
| -rw-r--r-- | include/crypto/sha512_base.h | 131 |
7 files changed, 382 insertions, 7 deletions
diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h index 623a59c1ff5a..0ecb7688af71 100644 --- a/include/crypto/algapi.h +++ b/include/crypto/algapi.h | |||
| @@ -137,7 +137,7 @@ struct crypto_template *crypto_lookup_template(const char *name); | |||
| 137 | 137 | ||
| 138 | int crypto_register_instance(struct crypto_template *tmpl, | 138 | int crypto_register_instance(struct crypto_template *tmpl, |
| 139 | struct crypto_instance *inst); | 139 | struct crypto_instance *inst); |
| 140 | int crypto_unregister_instance(struct crypto_alg *alg); | 140 | int crypto_unregister_instance(struct crypto_instance *inst); |
| 141 | 141 | ||
| 142 | int crypto_init_spawn(struct crypto_spawn *spawn, struct crypto_alg *alg, | 142 | int crypto_init_spawn(struct crypto_spawn *spawn, struct crypto_alg *alg, |
| 143 | struct crypto_instance *inst, u32 mask); | 143 | struct crypto_instance *inst, u32 mask); |
diff --git a/include/crypto/if_alg.h b/include/crypto/if_alg.h index 178525e5f430..018afb264ac2 100644 --- a/include/crypto/if_alg.h +++ b/include/crypto/if_alg.h | |||
| @@ -58,8 +58,9 @@ struct af_alg_type { | |||
| 58 | }; | 58 | }; |
| 59 | 59 | ||
| 60 | struct af_alg_sgl { | 60 | struct af_alg_sgl { |
| 61 | struct scatterlist sg[ALG_MAX_PAGES]; | 61 | struct scatterlist sg[ALG_MAX_PAGES + 1]; |
| 62 | struct page *pages[ALG_MAX_PAGES]; | 62 | struct page *pages[ALG_MAX_PAGES]; |
| 63 | unsigned int npages; | ||
| 63 | }; | 64 | }; |
| 64 | 65 | ||
| 65 | int af_alg_register_type(const struct af_alg_type *type); | 66 | int af_alg_register_type(const struct af_alg_type *type); |
| @@ -70,6 +71,7 @@ int af_alg_accept(struct sock *sk, struct socket *newsock); | |||
| 70 | 71 | ||
| 71 | int af_alg_make_sg(struct af_alg_sgl *sgl, struct iov_iter *iter, int len); | 72 | int af_alg_make_sg(struct af_alg_sgl *sgl, struct iov_iter *iter, int len); |
| 72 | void af_alg_free_sg(struct af_alg_sgl *sgl); | 73 | void af_alg_free_sg(struct af_alg_sgl *sgl); |
| 74 | void af_alg_link_sg(struct af_alg_sgl *sgl_prev, struct af_alg_sgl *sgl_new); | ||
| 73 | 75 | ||
| 74 | int af_alg_cmsg_send(struct msghdr *msg, struct af_alg_control *con); | 76 | int af_alg_cmsg_send(struct msghdr *msg, struct af_alg_control *con); |
| 75 | 77 | ||
diff --git a/include/crypto/rng.h b/include/crypto/rng.h index a16fb10142bf..6e28ea5be9f1 100644 --- a/include/crypto/rng.h +++ b/include/crypto/rng.h | |||
| @@ -103,8 +103,7 @@ static inline void crypto_free_rng(struct crypto_rng *tfm) | |||
| 103 | * This function fills the caller-allocated buffer with random numbers using the | 103 | * This function fills the caller-allocated buffer with random numbers using the |
| 104 | * random number generator referenced by the cipher handle. | 104 | * random number generator referenced by the cipher handle. |
| 105 | * | 105 | * |
| 106 | * Return: > 0 function was successful and returns the number of generated | 106 | * Return: 0 function was successful; < 0 if an error occurred |
| 107 | * bytes; < 0 if an error occurred | ||
| 108 | */ | 107 | */ |
| 109 | static inline int crypto_rng_get_bytes(struct crypto_rng *tfm, | 108 | static inline int crypto_rng_get_bytes(struct crypto_rng *tfm, |
| 110 | u8 *rdata, unsigned int dlen) | 109 | u8 *rdata, unsigned int dlen) |
diff --git a/include/crypto/sha.h b/include/crypto/sha.h index 190f8a0e0242..dd7905a3c22e 100644 --- a/include/crypto/sha.h +++ b/include/crypto/sha.h | |||
| @@ -65,20 +65,20 @@ | |||
| 65 | #define SHA512_H7 0x5be0cd19137e2179ULL | 65 | #define SHA512_H7 0x5be0cd19137e2179ULL |
| 66 | 66 | ||
| 67 | struct sha1_state { | 67 | struct sha1_state { |
| 68 | u64 count; | ||
| 69 | u32 state[SHA1_DIGEST_SIZE / 4]; | 68 | u32 state[SHA1_DIGEST_SIZE / 4]; |
| 69 | u64 count; | ||
| 70 | u8 buffer[SHA1_BLOCK_SIZE]; | 70 | u8 buffer[SHA1_BLOCK_SIZE]; |
| 71 | }; | 71 | }; |
| 72 | 72 | ||
| 73 | struct sha256_state { | 73 | struct sha256_state { |
| 74 | u64 count; | ||
| 75 | u32 state[SHA256_DIGEST_SIZE / 4]; | 74 | u32 state[SHA256_DIGEST_SIZE / 4]; |
| 75 | u64 count; | ||
| 76 | u8 buf[SHA256_BLOCK_SIZE]; | 76 | u8 buf[SHA256_BLOCK_SIZE]; |
| 77 | }; | 77 | }; |
| 78 | 78 | ||
| 79 | struct sha512_state { | 79 | struct sha512_state { |
| 80 | u64 count[2]; | ||
| 81 | u64 state[SHA512_DIGEST_SIZE / 8]; | 80 | u64 state[SHA512_DIGEST_SIZE / 8]; |
| 81 | u64 count[2]; | ||
| 82 | u8 buf[SHA512_BLOCK_SIZE]; | 82 | u8 buf[SHA512_BLOCK_SIZE]; |
| 83 | }; | 83 | }; |
| 84 | 84 | ||
| @@ -87,9 +87,18 @@ struct shash_desc; | |||
| 87 | extern int crypto_sha1_update(struct shash_desc *desc, const u8 *data, | 87 | extern int crypto_sha1_update(struct shash_desc *desc, const u8 *data, |
| 88 | unsigned int len); | 88 | unsigned int len); |
| 89 | 89 | ||
| 90 | extern int crypto_sha1_finup(struct shash_desc *desc, const u8 *data, | ||
| 91 | unsigned int len, u8 *hash); | ||
| 92 | |||
| 90 | extern int crypto_sha256_update(struct shash_desc *desc, const u8 *data, | 93 | extern int crypto_sha256_update(struct shash_desc *desc, const u8 *data, |
| 91 | unsigned int len); | 94 | unsigned int len); |
| 92 | 95 | ||
| 96 | extern int crypto_sha256_finup(struct shash_desc *desc, const u8 *data, | ||
| 97 | unsigned int len, u8 *hash); | ||
| 98 | |||
| 93 | extern int crypto_sha512_update(struct shash_desc *desc, const u8 *data, | 99 | extern int crypto_sha512_update(struct shash_desc *desc, const u8 *data, |
| 94 | unsigned int len); | 100 | unsigned int len); |
| 101 | |||
| 102 | extern int crypto_sha512_finup(struct shash_desc *desc, const u8 *data, | ||
| 103 | unsigned int len, u8 *hash); | ||
| 95 | #endif | 104 | #endif |
diff --git a/include/crypto/sha1_base.h b/include/crypto/sha1_base.h new file mode 100644 index 000000000000..d0df431f9a97 --- /dev/null +++ b/include/crypto/sha1_base.h | |||
| @@ -0,0 +1,106 @@ | |||
| 1 | /* | ||
| 2 | * sha1_base.h - core logic for SHA-1 implementations | ||
| 3 | * | ||
| 4 | * Copyright (C) 2015 Linaro Ltd <ard.biesheuvel@linaro.org> | ||
| 5 | * | ||
| 6 | * This program is free software; you can redistribute it and/or modify | ||
| 7 | * it under the terms of the GNU General Public License version 2 as | ||
| 8 | * published by the Free Software Foundation. | ||
| 9 | */ | ||
| 10 | |||
| 11 | #include <crypto/internal/hash.h> | ||
| 12 | #include <crypto/sha.h> | ||
| 13 | #include <linux/crypto.h> | ||
| 14 | #include <linux/module.h> | ||
| 15 | |||
| 16 | #include <asm/unaligned.h> | ||
| 17 | |||
| 18 | typedef void (sha1_block_fn)(struct sha1_state *sst, u8 const *src, int blocks); | ||
| 19 | |||
| 20 | static inline int sha1_base_init(struct shash_desc *desc) | ||
| 21 | { | ||
| 22 | struct sha1_state *sctx = shash_desc_ctx(desc); | ||
| 23 | |||
| 24 | sctx->state[0] = SHA1_H0; | ||
| 25 | sctx->state[1] = SHA1_H1; | ||
| 26 | sctx->state[2] = SHA1_H2; | ||
| 27 | sctx->state[3] = SHA1_H3; | ||
| 28 | sctx->state[4] = SHA1_H4; | ||
| 29 | sctx->count = 0; | ||
| 30 | |||
| 31 | return 0; | ||
| 32 | } | ||
| 33 | |||
| 34 | static inline int sha1_base_do_update(struct shash_desc *desc, | ||
| 35 | const u8 *data, | ||
| 36 | unsigned int len, | ||
| 37 | sha1_block_fn *block_fn) | ||
| 38 | { | ||
| 39 | struct sha1_state *sctx = shash_desc_ctx(desc); | ||
| 40 | unsigned int partial = sctx->count % SHA1_BLOCK_SIZE; | ||
| 41 | |||
| 42 | sctx->count += len; | ||
| 43 | |||
| 44 | if (unlikely((partial + len) >= SHA1_BLOCK_SIZE)) { | ||
| 45 | int blocks; | ||
| 46 | |||
| 47 | if (partial) { | ||
| 48 | int p = SHA1_BLOCK_SIZE - partial; | ||
| 49 | |||
| 50 | memcpy(sctx->buffer + partial, data, p); | ||
| 51 | data += p; | ||
| 52 | len -= p; | ||
| 53 | |||
| 54 | block_fn(sctx, sctx->buffer, 1); | ||
| 55 | } | ||
| 56 | |||
| 57 | blocks = len / SHA1_BLOCK_SIZE; | ||
| 58 | len %= SHA1_BLOCK_SIZE; | ||
| 59 | |||
| 60 | if (blocks) { | ||
| 61 | block_fn(sctx, data, blocks); | ||
| 62 | data += blocks * SHA1_BLOCK_SIZE; | ||
| 63 | } | ||
| 64 | partial = 0; | ||
| 65 | } | ||
| 66 | if (len) | ||
| 67 | memcpy(sctx->buffer + partial, data, len); | ||
| 68 | |||
| 69 | return 0; | ||
| 70 | } | ||
| 71 | |||
| 72 | static inline int sha1_base_do_finalize(struct shash_desc *desc, | ||
| 73 | sha1_block_fn *block_fn) | ||
| 74 | { | ||
| 75 | const int bit_offset = SHA1_BLOCK_SIZE - sizeof(__be64); | ||
| 76 | struct sha1_state *sctx = shash_desc_ctx(desc); | ||
| 77 | __be64 *bits = (__be64 *)(sctx->buffer + bit_offset); | ||
| 78 | unsigned int partial = sctx->count % SHA1_BLOCK_SIZE; | ||
| 79 | |||
| 80 | sctx->buffer[partial++] = 0x80; | ||
| 81 | if (partial > bit_offset) { | ||
| 82 | memset(sctx->buffer + partial, 0x0, SHA1_BLOCK_SIZE - partial); | ||
| 83 | partial = 0; | ||
| 84 | |||
| 85 | block_fn(sctx, sctx->buffer, 1); | ||
| 86 | } | ||
| 87 | |||
| 88 | memset(sctx->buffer + partial, 0x0, bit_offset - partial); | ||
| 89 | *bits = cpu_to_be64(sctx->count << 3); | ||
| 90 | block_fn(sctx, sctx->buffer, 1); | ||
| 91 | |||
| 92 | return 0; | ||
| 93 | } | ||
| 94 | |||
| 95 | static inline int sha1_base_finish(struct shash_desc *desc, u8 *out) | ||
| 96 | { | ||
| 97 | struct sha1_state *sctx = shash_desc_ctx(desc); | ||
| 98 | __be32 *digest = (__be32 *)out; | ||
| 99 | int i; | ||
| 100 | |||
| 101 | for (i = 0; i < SHA1_DIGEST_SIZE / sizeof(__be32); i++) | ||
| 102 | put_unaligned_be32(sctx->state[i], digest++); | ||
| 103 | |||
| 104 | *sctx = (struct sha1_state){}; | ||
| 105 | return 0; | ||
| 106 | } | ||
diff --git a/include/crypto/sha256_base.h b/include/crypto/sha256_base.h new file mode 100644 index 000000000000..d1f2195bb7de --- /dev/null +++ b/include/crypto/sha256_base.h | |||
| @@ -0,0 +1,128 @@ | |||
| 1 | /* | ||
| 2 | * sha256_base.h - core logic for SHA-256 implementations | ||
| 3 | * | ||
| 4 | * Copyright (C) 2015 Linaro Ltd <ard.biesheuvel@linaro.org> | ||
| 5 | * | ||
| 6 | * This program is free software; you can redistribute it and/or modify | ||
| 7 | * it under the terms of the GNU General Public License version 2 as | ||
| 8 | * published by the Free Software Foundation. | ||
| 9 | */ | ||
| 10 | |||
| 11 | #include <crypto/internal/hash.h> | ||
| 12 | #include <crypto/sha.h> | ||
| 13 | #include <linux/crypto.h> | ||
| 14 | #include <linux/module.h> | ||
| 15 | |||
| 16 | #include <asm/unaligned.h> | ||
| 17 | |||
| 18 | typedef void (sha256_block_fn)(struct sha256_state *sst, u8 const *src, | ||
| 19 | int blocks); | ||
| 20 | |||
| 21 | static inline int sha224_base_init(struct shash_desc *desc) | ||
| 22 | { | ||
| 23 | struct sha256_state *sctx = shash_desc_ctx(desc); | ||
| 24 | |||
| 25 | sctx->state[0] = SHA224_H0; | ||
| 26 | sctx->state[1] = SHA224_H1; | ||
| 27 | sctx->state[2] = SHA224_H2; | ||
| 28 | sctx->state[3] = SHA224_H3; | ||
| 29 | sctx->state[4] = SHA224_H4; | ||
| 30 | sctx->state[5] = SHA224_H5; | ||
| 31 | sctx->state[6] = SHA224_H6; | ||
| 32 | sctx->state[7] = SHA224_H7; | ||
| 33 | sctx->count = 0; | ||
| 34 | |||
| 35 | return 0; | ||
| 36 | } | ||
| 37 | |||
| 38 | static inline int sha256_base_init(struct shash_desc *desc) | ||
| 39 | { | ||
| 40 | struct sha256_state *sctx = shash_desc_ctx(desc); | ||
| 41 | |||
| 42 | sctx->state[0] = SHA256_H0; | ||
| 43 | sctx->state[1] = SHA256_H1; | ||
| 44 | sctx->state[2] = SHA256_H2; | ||
| 45 | sctx->state[3] = SHA256_H3; | ||
| 46 | sctx->state[4] = SHA256_H4; | ||
| 47 | sctx->state[5] = SHA256_H5; | ||
| 48 | sctx->state[6] = SHA256_H6; | ||
| 49 | sctx->state[7] = SHA256_H7; | ||
| 50 | sctx->count = 0; | ||
| 51 | |||
| 52 | return 0; | ||
| 53 | } | ||
| 54 | |||
| 55 | static inline int sha256_base_do_update(struct shash_desc *desc, | ||
| 56 | const u8 *data, | ||
| 57 | unsigned int len, | ||
| 58 | sha256_block_fn *block_fn) | ||
| 59 | { | ||
| 60 | struct sha256_state *sctx = shash_desc_ctx(desc); | ||
| 61 | unsigned int partial = sctx->count % SHA256_BLOCK_SIZE; | ||
| 62 | |||
| 63 | sctx->count += len; | ||
| 64 | |||
| 65 | if (unlikely((partial + len) >= SHA256_BLOCK_SIZE)) { | ||
| 66 | int blocks; | ||
| 67 | |||
| 68 | if (partial) { | ||
| 69 | int p = SHA256_BLOCK_SIZE - partial; | ||
| 70 | |||
| 71 | memcpy(sctx->buf + partial, data, p); | ||
| 72 | data += p; | ||
| 73 | len -= p; | ||
| 74 | |||
| 75 | block_fn(sctx, sctx->buf, 1); | ||
| 76 | } | ||
| 77 | |||
| 78 | blocks = len / SHA256_BLOCK_SIZE; | ||
| 79 | len %= SHA256_BLOCK_SIZE; | ||
| 80 | |||
| 81 | if (blocks) { | ||
| 82 | block_fn(sctx, data, blocks); | ||
| 83 | data += blocks * SHA256_BLOCK_SIZE; | ||
| 84 | } | ||
| 85 | partial = 0; | ||
| 86 | } | ||
| 87 | if (len) | ||
| 88 | memcpy(sctx->buf + partial, data, len); | ||
| 89 | |||
| 90 | return 0; | ||
| 91 | } | ||
| 92 | |||
| 93 | static inline int sha256_base_do_finalize(struct shash_desc *desc, | ||
| 94 | sha256_block_fn *block_fn) | ||
| 95 | { | ||
| 96 | const int bit_offset = SHA256_BLOCK_SIZE - sizeof(__be64); | ||
| 97 | struct sha256_state *sctx = shash_desc_ctx(desc); | ||
| 98 | __be64 *bits = (__be64 *)(sctx->buf + bit_offset); | ||
| 99 | unsigned int partial = sctx->count % SHA256_BLOCK_SIZE; | ||
| 100 | |||
| 101 | sctx->buf[partial++] = 0x80; | ||
| 102 | if (partial > bit_offset) { | ||
| 103 | memset(sctx->buf + partial, 0x0, SHA256_BLOCK_SIZE - partial); | ||
| 104 | partial = 0; | ||
| 105 | |||
| 106 | block_fn(sctx, sctx->buf, 1); | ||
| 107 | } | ||
| 108 | |||
| 109 | memset(sctx->buf + partial, 0x0, bit_offset - partial); | ||
| 110 | *bits = cpu_to_be64(sctx->count << 3); | ||
| 111 | block_fn(sctx, sctx->buf, 1); | ||
| 112 | |||
| 113 | return 0; | ||
| 114 | } | ||
| 115 | |||
| 116 | static inline int sha256_base_finish(struct shash_desc *desc, u8 *out) | ||
| 117 | { | ||
| 118 | unsigned int digest_size = crypto_shash_digestsize(desc->tfm); | ||
| 119 | struct sha256_state *sctx = shash_desc_ctx(desc); | ||
| 120 | __be32 *digest = (__be32 *)out; | ||
| 121 | int i; | ||
| 122 | |||
| 123 | for (i = 0; digest_size > 0; i++, digest_size -= sizeof(__be32)) | ||
| 124 | put_unaligned_be32(sctx->state[i], digest++); | ||
| 125 | |||
| 126 | *sctx = (struct sha256_state){}; | ||
| 127 | return 0; | ||
| 128 | } | ||
diff --git a/include/crypto/sha512_base.h b/include/crypto/sha512_base.h new file mode 100644 index 000000000000..6c5341e005ea --- /dev/null +++ b/include/crypto/sha512_base.h | |||
| @@ -0,0 +1,131 @@ | |||
| 1 | /* | ||
| 2 | * sha512_base.h - core logic for SHA-512 implementations | ||
| 3 | * | ||
| 4 | * Copyright (C) 2015 Linaro Ltd <ard.biesheuvel@linaro.org> | ||
| 5 | * | ||
| 6 | * This program is free software; you can redistribute it and/or modify | ||
| 7 | * it under the terms of the GNU General Public License version 2 as | ||
| 8 | * published by the Free Software Foundation. | ||
| 9 | */ | ||
| 10 | |||
| 11 | #include <crypto/internal/hash.h> | ||
| 12 | #include <crypto/sha.h> | ||
| 13 | #include <linux/crypto.h> | ||
| 14 | #include <linux/module.h> | ||
| 15 | |||
| 16 | #include <asm/unaligned.h> | ||
| 17 | |||
| 18 | typedef void (sha512_block_fn)(struct sha512_state *sst, u8 const *src, | ||
| 19 | int blocks); | ||
| 20 | |||
| 21 | static inline int sha384_base_init(struct shash_desc *desc) | ||
| 22 | { | ||
| 23 | struct sha512_state *sctx = shash_desc_ctx(desc); | ||
| 24 | |||
| 25 | sctx->state[0] = SHA384_H0; | ||
| 26 | sctx->state[1] = SHA384_H1; | ||
| 27 | sctx->state[2] = SHA384_H2; | ||
| 28 | sctx->state[3] = SHA384_H3; | ||
| 29 | sctx->state[4] = SHA384_H4; | ||
| 30 | sctx->state[5] = SHA384_H5; | ||
| 31 | sctx->state[6] = SHA384_H6; | ||
| 32 | sctx->state[7] = SHA384_H7; | ||
| 33 | sctx->count[0] = sctx->count[1] = 0; | ||
| 34 | |||
| 35 | return 0; | ||
| 36 | } | ||
| 37 | |||
| 38 | static inline int sha512_base_init(struct shash_desc *desc) | ||
| 39 | { | ||
| 40 | struct sha512_state *sctx = shash_desc_ctx(desc); | ||
| 41 | |||
| 42 | sctx->state[0] = SHA512_H0; | ||
| 43 | sctx->state[1] = SHA512_H1; | ||
| 44 | sctx->state[2] = SHA512_H2; | ||
| 45 | sctx->state[3] = SHA512_H3; | ||
| 46 | sctx->state[4] = SHA512_H4; | ||
| 47 | sctx->state[5] = SHA512_H5; | ||
| 48 | sctx->state[6] = SHA512_H6; | ||
| 49 | sctx->state[7] = SHA512_H7; | ||
| 50 | sctx->count[0] = sctx->count[1] = 0; | ||
| 51 | |||
| 52 | return 0; | ||
| 53 | } | ||
| 54 | |||
| 55 | static inline int sha512_base_do_update(struct shash_desc *desc, | ||
| 56 | const u8 *data, | ||
| 57 | unsigned int len, | ||
| 58 | sha512_block_fn *block_fn) | ||
| 59 | { | ||
| 60 | struct sha512_state *sctx = shash_desc_ctx(desc); | ||
| 61 | unsigned int partial = sctx->count[0] % SHA512_BLOCK_SIZE; | ||
| 62 | |||
| 63 | sctx->count[0] += len; | ||
| 64 | if (sctx->count[0] < len) | ||
| 65 | sctx->count[1]++; | ||
| 66 | |||
| 67 | if (unlikely((partial + len) >= SHA512_BLOCK_SIZE)) { | ||
| 68 | int blocks; | ||
| 69 | |||
| 70 | if (partial) { | ||
| 71 | int p = SHA512_BLOCK_SIZE - partial; | ||
| 72 | |||
| 73 | memcpy(sctx->buf + partial, data, p); | ||
| 74 | data += p; | ||
| 75 | len -= p; | ||
| 76 | |||
| 77 | block_fn(sctx, sctx->buf, 1); | ||
| 78 | } | ||
| 79 | |||
| 80 | blocks = len / SHA512_BLOCK_SIZE; | ||
| 81 | len %= SHA512_BLOCK_SIZE; | ||
| 82 | |||
| 83 | if (blocks) { | ||
| 84 | block_fn(sctx, data, blocks); | ||
| 85 | data += blocks * SHA512_BLOCK_SIZE; | ||
| 86 | } | ||
| 87 | partial = 0; | ||
| 88 | } | ||
| 89 | if (len) | ||
| 90 | memcpy(sctx->buf + partial, data, len); | ||
| 91 | |||
| 92 | return 0; | ||
| 93 | } | ||
| 94 | |||
| 95 | static inline int sha512_base_do_finalize(struct shash_desc *desc, | ||
| 96 | sha512_block_fn *block_fn) | ||
| 97 | { | ||
| 98 | const int bit_offset = SHA512_BLOCK_SIZE - sizeof(__be64[2]); | ||
| 99 | struct sha512_state *sctx = shash_desc_ctx(desc); | ||
| 100 | __be64 *bits = (__be64 *)(sctx->buf + bit_offset); | ||
| 101 | unsigned int partial = sctx->count[0] % SHA512_BLOCK_SIZE; | ||
| 102 | |||
| 103 | sctx->buf[partial++] = 0x80; | ||
| 104 | if (partial > bit_offset) { | ||
| 105 | memset(sctx->buf + partial, 0x0, SHA512_BLOCK_SIZE - partial); | ||
| 106 | partial = 0; | ||
| 107 | |||
| 108 | block_fn(sctx, sctx->buf, 1); | ||
| 109 | } | ||
| 110 | |||
| 111 | memset(sctx->buf + partial, 0x0, bit_offset - partial); | ||
| 112 | bits[0] = cpu_to_be64(sctx->count[1] << 3 | sctx->count[0] >> 61); | ||
| 113 | bits[1] = cpu_to_be64(sctx->count[0] << 3); | ||
| 114 | block_fn(sctx, sctx->buf, 1); | ||
| 115 | |||
| 116 | return 0; | ||
| 117 | } | ||
| 118 | |||
| 119 | static inline int sha512_base_finish(struct shash_desc *desc, u8 *out) | ||
| 120 | { | ||
| 121 | unsigned int digest_size = crypto_shash_digestsize(desc->tfm); | ||
| 122 | struct sha512_state *sctx = shash_desc_ctx(desc); | ||
| 123 | __be64 *digest = (__be64 *)out; | ||
| 124 | int i; | ||
| 125 | |||
| 126 | for (i = 0; digest_size > 0; i++, digest_size -= sizeof(__be64)) | ||
| 127 | put_unaligned_be64(sctx->state[i], digest++); | ||
| 128 | |||
| 129 | *sctx = (struct sha512_state){}; | ||
| 130 | return 0; | ||
| 131 | } | ||
