diff options
author | Gary R Hook <gary.hook@amd.com> | 2017-07-25 15:21:34 -0400 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2017-08-03 21:27:43 -0400 |
commit | 7f7216cfaf3f07a41fe6e88b779bdc9690c2d515 (patch) | |
tree | e24603f4ffad3638f334c2fb2d73c4147a921afc | |
parent | 47f27f160be6d26d61d3e75923e635e4e6c099fb (diff) |
crypto: ccp - Rework the unit-size check for XTS-AES
The CCP supports a limited set of unit-size values. Change the check
for this parameter such that acceptable values match the enumeration.
Then clarify the conditions under which we must use the fallback
implementation.
Signed-off-by: Gary R Hook <gary.hook@amd.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
-rw-r--r-- | drivers/crypto/ccp/ccp-crypto-aes-xts.c | 57 |
1 files changed, 20 insertions, 37 deletions
diff --git a/drivers/crypto/ccp/ccp-crypto-aes-xts.c b/drivers/crypto/ccp/ccp-crypto-aes-xts.c index 2b5d3a62fad9..5c2df880ab48 100644 --- a/drivers/crypto/ccp/ccp-crypto-aes-xts.c +++ b/drivers/crypto/ccp/ccp-crypto-aes-xts.c | |||
@@ -39,46 +39,26 @@ struct ccp_unit_size_map { | |||
39 | u32 value; | 39 | u32 value; |
40 | }; | 40 | }; |
41 | 41 | ||
42 | static struct ccp_unit_size_map unit_size_map[] = { | 42 | static struct ccp_unit_size_map xts_unit_sizes[] = { |
43 | { | 43 | { |
44 | .size = 4096, | 44 | .size = 16, |
45 | .value = CCP_XTS_AES_UNIT_SIZE_4096, | 45 | .value = CCP_XTS_AES_UNIT_SIZE_16, |
46 | }, | ||
47 | { | ||
48 | .size = 2048, | ||
49 | .value = CCP_XTS_AES_UNIT_SIZE_2048, | ||
50 | }, | ||
51 | { | ||
52 | .size = 1024, | ||
53 | .value = CCP_XTS_AES_UNIT_SIZE_1024, | ||
54 | }, | 46 | }, |
55 | { | 47 | { |
56 | .size = 512, | 48 | .size = 512, |
57 | .value = CCP_XTS_AES_UNIT_SIZE_512, | 49 | .value = CCP_XTS_AES_UNIT_SIZE_512, |
58 | }, | 50 | }, |
59 | { | 51 | { |
60 | .size = 256, | 52 | .size = 1024, |
61 | .value = CCP_XTS_AES_UNIT_SIZE__LAST, | 53 | .value = CCP_XTS_AES_UNIT_SIZE_1024, |
62 | }, | ||
63 | { | ||
64 | .size = 128, | ||
65 | .value = CCP_XTS_AES_UNIT_SIZE__LAST, | ||
66 | }, | ||
67 | { | ||
68 | .size = 64, | ||
69 | .value = CCP_XTS_AES_UNIT_SIZE__LAST, | ||
70 | }, | ||
71 | { | ||
72 | .size = 32, | ||
73 | .value = CCP_XTS_AES_UNIT_SIZE__LAST, | ||
74 | }, | 54 | }, |
75 | { | 55 | { |
76 | .size = 16, | 56 | .size = 2048, |
77 | .value = CCP_XTS_AES_UNIT_SIZE_16, | 57 | .value = CCP_XTS_AES_UNIT_SIZE_2048, |
78 | }, | 58 | }, |
79 | { | 59 | { |
80 | .size = 1, | 60 | .size = 4096, |
81 | .value = CCP_XTS_AES_UNIT_SIZE__LAST, | 61 | .value = CCP_XTS_AES_UNIT_SIZE_4096, |
82 | }, | 62 | }, |
83 | }; | 63 | }; |
84 | 64 | ||
@@ -138,16 +118,19 @@ static int ccp_aes_xts_crypt(struct ablkcipher_request *req, | |||
138 | if (!req->info) | 118 | if (!req->info) |
139 | return -EINVAL; | 119 | return -EINVAL; |
140 | 120 | ||
121 | /* Check conditions under which the CCP can fulfill a request. The | ||
122 | * device can handle input plaintext of a length that is a multiple | ||
123 | * of the unit_size, bug the crypto implementation only supports | ||
124 | * the unit_size being equal to the input length. This limits the | ||
125 | * number of scenarios we can handle. | ||
126 | */ | ||
141 | unit_size = CCP_XTS_AES_UNIT_SIZE__LAST; | 127 | unit_size = CCP_XTS_AES_UNIT_SIZE__LAST; |
142 | if (req->nbytes <= unit_size_map[0].size) { | 128 | for (unit = 0; unit < ARRAY_SIZE(xts_unit_sizes); unit++) { |
143 | for (unit = 0; unit < ARRAY_SIZE(unit_size_map); unit++) { | 129 | if (req->nbytes == xts_unit_sizes[unit].size) { |
144 | if (!(req->nbytes & (unit_size_map[unit].size - 1))) { | 130 | unit_size = unit; |
145 | unit_size = unit_size_map[unit].value; | 131 | break; |
146 | break; | ||
147 | } | ||
148 | } | 132 | } |
149 | } | 133 | } |
150 | |||
151 | if ((unit_size == CCP_XTS_AES_UNIT_SIZE__LAST) || | 134 | if ((unit_size == CCP_XTS_AES_UNIT_SIZE__LAST) || |
152 | (ctx->u.aes.key_len != AES_KEYSIZE_128)) { | 135 | (ctx->u.aes.key_len != AES_KEYSIZE_128)) { |
153 | SKCIPHER_REQUEST_ON_STACK(subreq, ctx->u.aes.tfm_skcipher); | 136 | SKCIPHER_REQUEST_ON_STACK(subreq, ctx->u.aes.tfm_skcipher); |