diff options
author | Cyrille Pitchen <cyrille.pitchen@atmel.com> | 2017-01-26 11:07:49 -0500 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2017-02-03 05:16:12 -0500 |
commit | f07cebad63b28562d030eee8c762833eca50e46e (patch) | |
tree | 60241c43a632391eccaea51b583f53a4d55fb74e /drivers/crypto/atmel-sha.c | |
parent | b5ce82a7b4938f278fc6da28ce00da34e7a0773c (diff) |
crypto: atmel-sha - redefine SHA_FLAGS_SHA* flags to match SHA_MR_ALGO_SHA*
This patch modifies the SHA_FLAGS_SHA* flags: those algo flags are now
organized as values of a single bitfield instead of individual bits.
This allows to reduce the number of bits needed to encode all possible
values. Also the new values match the SHA_MR_ALGO_SHA* values hence
the algorithm bitfield of the SHA_MR register could simply be set with:
mr = (mr & ~SHA_FLAGS_ALGO_MASK) | (ctx->flags & SHA_FLAGS_ALGO_MASK)
Signed-off-by: Cyrille Pitchen <cyrille.pitchen@atmel.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'drivers/crypto/atmel-sha.c')
-rw-r--r-- | drivers/crypto/atmel-sha.c | 45 |
1 files changed, 32 insertions, 13 deletions
diff --git a/drivers/crypto/atmel-sha.c b/drivers/crypto/atmel-sha.c index 643d79a05dda..b29a4e5bc404 100644 --- a/drivers/crypto/atmel-sha.c +++ b/drivers/crypto/atmel-sha.c | |||
@@ -51,14 +51,16 @@ | |||
51 | #define SHA_FLAGS_CPU BIT(5) | 51 | #define SHA_FLAGS_CPU BIT(5) |
52 | #define SHA_FLAGS_DMA_READY BIT(6) | 52 | #define SHA_FLAGS_DMA_READY BIT(6) |
53 | 53 | ||
54 | /* bits[10:8] are reserved. */ | ||
55 | #define SHA_FLAGS_ALGO_MASK SHA_MR_ALGO_MASK | ||
56 | #define SHA_FLAGS_SHA1 SHA_MR_ALGO_SHA1 | ||
57 | #define SHA_FLAGS_SHA256 SHA_MR_ALGO_SHA256 | ||
58 | #define SHA_FLAGS_SHA384 SHA_MR_ALGO_SHA384 | ||
59 | #define SHA_FLAGS_SHA512 SHA_MR_ALGO_SHA512 | ||
60 | #define SHA_FLAGS_SHA224 SHA_MR_ALGO_SHA224 | ||
61 | |||
54 | #define SHA_FLAGS_FINUP BIT(16) | 62 | #define SHA_FLAGS_FINUP BIT(16) |
55 | #define SHA_FLAGS_SG BIT(17) | 63 | #define SHA_FLAGS_SG BIT(17) |
56 | #define SHA_FLAGS_ALGO_MASK GENMASK(22, 18) | ||
57 | #define SHA_FLAGS_SHA1 BIT(18) | ||
58 | #define SHA_FLAGS_SHA224 BIT(19) | ||
59 | #define SHA_FLAGS_SHA256 BIT(20) | ||
60 | #define SHA_FLAGS_SHA384 BIT(21) | ||
61 | #define SHA_FLAGS_SHA512 BIT(22) | ||
62 | #define SHA_FLAGS_ERROR BIT(23) | 64 | #define SHA_FLAGS_ERROR BIT(23) |
63 | #define SHA_FLAGS_PAD BIT(24) | 65 | #define SHA_FLAGS_PAD BIT(24) |
64 | #define SHA_FLAGS_RESTORE BIT(25) | 66 | #define SHA_FLAGS_RESTORE BIT(25) |
@@ -264,7 +266,9 @@ static void atmel_sha_fill_padding(struct atmel_sha_reqctx *ctx, int length) | |||
264 | bits[1] = cpu_to_be64(size[0] << 3); | 266 | bits[1] = cpu_to_be64(size[0] << 3); |
265 | bits[0] = cpu_to_be64(size[1] << 3 | size[0] >> 61); | 267 | bits[0] = cpu_to_be64(size[1] << 3 | size[0] >> 61); |
266 | 268 | ||
267 | if (ctx->flags & (SHA_FLAGS_SHA384 | SHA_FLAGS_SHA512)) { | 269 | switch (ctx->flags & SHA_FLAGS_ALGO_MASK) { |
270 | case SHA_FLAGS_SHA384: | ||
271 | case SHA_FLAGS_SHA512: | ||
268 | index = ctx->bufcnt & 0x7f; | 272 | index = ctx->bufcnt & 0x7f; |
269 | padlen = (index < 112) ? (112 - index) : ((128+112) - index); | 273 | padlen = (index < 112) ? (112 - index) : ((128+112) - index); |
270 | *(ctx->buffer + ctx->bufcnt) = 0x80; | 274 | *(ctx->buffer + ctx->bufcnt) = 0x80; |
@@ -272,7 +276,9 @@ static void atmel_sha_fill_padding(struct atmel_sha_reqctx *ctx, int length) | |||
272 | memcpy(ctx->buffer + ctx->bufcnt + padlen, bits, 16); | 276 | memcpy(ctx->buffer + ctx->bufcnt + padlen, bits, 16); |
273 | ctx->bufcnt += padlen + 16; | 277 | ctx->bufcnt += padlen + 16; |
274 | ctx->flags |= SHA_FLAGS_PAD; | 278 | ctx->flags |= SHA_FLAGS_PAD; |
275 | } else { | 279 | break; |
280 | |||
281 | default: | ||
276 | index = ctx->bufcnt & 0x3f; | 282 | index = ctx->bufcnt & 0x3f; |
277 | padlen = (index < 56) ? (56 - index) : ((64+56) - index); | 283 | padlen = (index < 56) ? (56 - index) : ((64+56) - index); |
278 | *(ctx->buffer + ctx->bufcnt) = 0x80; | 284 | *(ctx->buffer + ctx->bufcnt) = 0x80; |
@@ -280,6 +286,7 @@ static void atmel_sha_fill_padding(struct atmel_sha_reqctx *ctx, int length) | |||
280 | memcpy(ctx->buffer + ctx->bufcnt + padlen, &bits[1], 8); | 286 | memcpy(ctx->buffer + ctx->bufcnt + padlen, &bits[1], 8); |
281 | ctx->bufcnt += padlen + 8; | 287 | ctx->bufcnt += padlen + 8; |
282 | ctx->flags |= SHA_FLAGS_PAD; | 288 | ctx->flags |= SHA_FLAGS_PAD; |
289 | break; | ||
283 | } | 290 | } |
284 | } | 291 | } |
285 | 292 | ||
@@ -828,16 +835,28 @@ static void atmel_sha_copy_ready_hash(struct ahash_request *req) | |||
828 | if (!req->result) | 835 | if (!req->result) |
829 | return; | 836 | return; |
830 | 837 | ||
831 | if (ctx->flags & SHA_FLAGS_SHA1) | 838 | switch (ctx->flags & SHA_FLAGS_ALGO_MASK) { |
839 | default: | ||
840 | case SHA_FLAGS_SHA1: | ||
832 | memcpy(req->result, ctx->digest, SHA1_DIGEST_SIZE); | 841 | memcpy(req->result, ctx->digest, SHA1_DIGEST_SIZE); |
833 | else if (ctx->flags & SHA_FLAGS_SHA224) | 842 | break; |
843 | |||
844 | case SHA_FLAGS_SHA224: | ||
834 | memcpy(req->result, ctx->digest, SHA224_DIGEST_SIZE); | 845 | memcpy(req->result, ctx->digest, SHA224_DIGEST_SIZE); |
835 | else if (ctx->flags & SHA_FLAGS_SHA256) | 846 | break; |
847 | |||
848 | case SHA_FLAGS_SHA256: | ||
836 | memcpy(req->result, ctx->digest, SHA256_DIGEST_SIZE); | 849 | memcpy(req->result, ctx->digest, SHA256_DIGEST_SIZE); |
837 | else if (ctx->flags & SHA_FLAGS_SHA384) | 850 | break; |
851 | |||
852 | case SHA_FLAGS_SHA384: | ||
838 | memcpy(req->result, ctx->digest, SHA384_DIGEST_SIZE); | 853 | memcpy(req->result, ctx->digest, SHA384_DIGEST_SIZE); |
839 | else | 854 | break; |
855 | |||
856 | case SHA_FLAGS_SHA512: | ||
840 | memcpy(req->result, ctx->digest, SHA512_DIGEST_SIZE); | 857 | memcpy(req->result, ctx->digest, SHA512_DIGEST_SIZE); |
858 | break; | ||
859 | } | ||
841 | } | 860 | } |
842 | 861 | ||
843 | static int atmel_sha_finish(struct ahash_request *req) | 862 | static int atmel_sha_finish(struct ahash_request *req) |