aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGary R Hook <gary.hook@amd.com>2017-07-25 15:21:43 -0400
committerHerbert Xu <herbert@gondor.apana.org.au>2017-08-03 21:27:44 -0400
commit5060ffc97bc6fdd31595b3ecbc027b0a8df94b5c (patch)
tree229f3e3163e3e29157551cbe9b04aaf56343d953
parent7f7216cfaf3f07a41fe6e88b779bdc9690c2d515 (diff)
crypto: ccp - Add XTS-AES-256 support for CCP version 5
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.c26
-rw-r--r--drivers/crypto/ccp/ccp-crypto.h2
-rw-r--r--drivers/crypto/ccp/ccp-ops.c2
3 files changed, 25 insertions, 5 deletions
diff --git a/drivers/crypto/ccp/ccp-crypto-aes-xts.c b/drivers/crypto/ccp/ccp-crypto-aes-xts.c
index 5c2df880ab48..94b5bcf5b628 100644
--- a/drivers/crypto/ccp/ccp-crypto-aes-xts.c
+++ b/drivers/crypto/ccp/ccp-crypto-aes-xts.c
@@ -80,19 +80,24 @@ static int ccp_aes_xts_setkey(struct crypto_ablkcipher *tfm, const u8 *key,
80{ 80{
81 struct crypto_tfm *xfm = crypto_ablkcipher_tfm(tfm); 81 struct crypto_tfm *xfm = crypto_ablkcipher_tfm(tfm);
82 struct ccp_ctx *ctx = crypto_tfm_ctx(xfm); 82 struct ccp_ctx *ctx = crypto_tfm_ctx(xfm);
83 unsigned int ccpversion = ccp_version();
83 int ret; 84 int ret;
84 85
85 ret = xts_check_key(xfm, key, key_len); 86 ret = xts_check_key(xfm, key, key_len);
86 if (ret) 87 if (ret)
87 return ret; 88 return ret;
88 89
89 /* Only support 128-bit AES key with a 128-bit Tweak key, 90 /* Version 3 devices support 128-bit keys; version 5 devices can
90 * otherwise use the fallback 91 * accommodate 128- and 256-bit keys.
91 */ 92 */
92 switch (key_len) { 93 switch (key_len) {
93 case AES_KEYSIZE_128 * 2: 94 case AES_KEYSIZE_128 * 2:
94 memcpy(ctx->u.aes.key, key, key_len); 95 memcpy(ctx->u.aes.key, key, key_len);
95 break; 96 break;
97 case AES_KEYSIZE_256 * 2:
98 if (ccpversion > CCP_VERSION(3, 0))
99 memcpy(ctx->u.aes.key, key, key_len);
100 break;
96 } 101 }
97 ctx->u.aes.key_len = key_len / 2; 102 ctx->u.aes.key_len = key_len / 2;
98 sg_init_one(&ctx->u.aes.key_sg, ctx->u.aes.key, key_len); 103 sg_init_one(&ctx->u.aes.key_sg, ctx->u.aes.key, key_len);
@@ -105,6 +110,8 @@ static int ccp_aes_xts_crypt(struct ablkcipher_request *req,
105{ 110{
106 struct ccp_ctx *ctx = crypto_tfm_ctx(req->base.tfm); 111 struct ccp_ctx *ctx = crypto_tfm_ctx(req->base.tfm);
107 struct ccp_aes_req_ctx *rctx = ablkcipher_request_ctx(req); 112 struct ccp_aes_req_ctx *rctx = ablkcipher_request_ctx(req);
113 unsigned int ccpversion = ccp_version();
114 unsigned int fallback = 0;
108 unsigned int unit; 115 unsigned int unit;
109 u32 unit_size; 116 u32 unit_size;
110 int ret; 117 int ret;
@@ -131,8 +138,19 @@ static int ccp_aes_xts_crypt(struct ablkcipher_request *req,
131 break; 138 break;
132 } 139 }
133 } 140 }
134 if ((unit_size == CCP_XTS_AES_UNIT_SIZE__LAST) || 141 /* The CCP has restrictions on block sizes. Also, a version 3 device
135 (ctx->u.aes.key_len != AES_KEYSIZE_128)) { 142 * only supports AES-128 operations; version 5 CCPs support both
143 * AES-128 and -256 operations.
144 */
145 if (unit_size == CCP_XTS_AES_UNIT_SIZE__LAST)
146 fallback = 1;
147 if ((ccpversion < CCP_VERSION(5, 0)) &&
148 (ctx->u.aes.key_len != AES_KEYSIZE_128))
149 fallback = 1;
150 if ((ctx->u.aes.key_len != AES_KEYSIZE_128) &&
151 (ctx->u.aes.key_len != AES_KEYSIZE_256))
152 fallback = 1;
153 if (fallback) {
136 SKCIPHER_REQUEST_ON_STACK(subreq, ctx->u.aes.tfm_skcipher); 154 SKCIPHER_REQUEST_ON_STACK(subreq, ctx->u.aes.tfm_skcipher);
137 155
138 /* Use the fallback to process the request for any 156 /* Use the fallback to process the request for any
diff --git a/drivers/crypto/ccp/ccp-crypto.h b/drivers/crypto/ccp/ccp-crypto.h
index 67c7620029e3..b9fd090c46c2 100644
--- a/drivers/crypto/ccp/ccp-crypto.h
+++ b/drivers/crypto/ccp/ccp-crypto.h
@@ -99,7 +99,7 @@ struct ccp_aes_ctx {
99 99
100 struct scatterlist key_sg; 100 struct scatterlist key_sg;
101 unsigned int key_len; 101 unsigned int key_len;
102 u8 key[AES_MAX_KEY_SIZE]; 102 u8 key[AES_MAX_KEY_SIZE * 2];
103 103
104 u8 nonce[CTR_RFC3686_NONCE_SIZE]; 104 u8 nonce[CTR_RFC3686_NONCE_SIZE];
105 105
diff --git a/drivers/crypto/ccp/ccp-ops.c b/drivers/crypto/ccp/ccp-ops.c
index 10e3be8d93ce..cc16cb0fc3af 100644
--- a/drivers/crypto/ccp/ccp-ops.c
+++ b/drivers/crypto/ccp/ccp-ops.c
@@ -1065,6 +1065,8 @@ static int ccp_run_xts_aes_cmd(struct ccp_cmd_queue *cmd_q,
1065 1065
1066 if (xts->key_len == AES_KEYSIZE_128) 1066 if (xts->key_len == AES_KEYSIZE_128)
1067 aestype = CCP_AES_TYPE_128; 1067 aestype = CCP_AES_TYPE_128;
1068 else if (xts->key_len == AES_KEYSIZE_256)
1069 aestype = CCP_AES_TYPE_256;
1068 else 1070 else
1069 return -EINVAL; 1071 return -EINVAL;
1070 1072