aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/crypto/amcc
diff options
context:
space:
mode:
authorChristian Lamparter <chunkeey@googlemail.com>2017-08-25 09:47:21 -0400
committerHerbert Xu <herbert@gondor.apana.org.au>2017-09-22 05:43:18 -0400
commitf2a13e7cba9e2b16f4888fbd9cf2bc25b95945be (patch)
treee9abdc7d67cbb2db42d2a73a7910102b51e0f5dc /drivers/crypto/amcc
parent249c8d98ea339325dca481d5dae93686cd494059 (diff)
crypto: crypto4xx - enable AES RFC3686, ECB, CFB and OFB offloads
The crypto engine supports more than just aes-cbc. This patch enables the remaining AES block cipher modes that pass the testmanager's test vectors. Signed-off-by: Christian Lamparter <chunkeey@googlemail.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'drivers/crypto/amcc')
-rw-r--r--drivers/crypto/amcc/crypto4xx_alg.c66
-rw-r--r--drivers/crypto/amcc/crypto4xx_core.c98
-rw-r--r--drivers/crypto/amcc/crypto4xx_core.h10
-rw-r--r--drivers/crypto/amcc/crypto4xx_sa.h3
4 files changed, 177 insertions, 0 deletions
diff --git a/drivers/crypto/amcc/crypto4xx_alg.c b/drivers/crypto/amcc/crypto4xx_alg.c
index 599b6326c3fb..c9597824a515 100644
--- a/drivers/crypto/amcc/crypto4xx_alg.c
+++ b/drivers/crypto/amcc/crypto4xx_alg.c
@@ -28,6 +28,7 @@
28#include <crypto/algapi.h> 28#include <crypto/algapi.h>
29#include <crypto/aes.h> 29#include <crypto/aes.h>
30#include <crypto/sha.h> 30#include <crypto/sha.h>
31#include <crypto/ctr.h>
31#include "crypto4xx_reg_def.h" 32#include "crypto4xx_reg_def.h"
32#include "crypto4xx_core.h" 33#include "crypto4xx_core.h"
33#include "crypto4xx_sa.h" 34#include "crypto4xx_sa.h"
@@ -171,6 +172,71 @@ int crypto4xx_setkey_aes_cbc(struct crypto_ablkcipher *cipher,
171 CRYPTO_FEEDBACK_MODE_NO_FB); 172 CRYPTO_FEEDBACK_MODE_NO_FB);
172} 173}
173 174
175int crypto4xx_setkey_aes_cfb(struct crypto_ablkcipher *cipher,
176 const u8 *key, unsigned int keylen)
177{
178 return crypto4xx_setkey_aes(cipher, key, keylen, CRYPTO_MODE_CFB,
179 CRYPTO_FEEDBACK_MODE_128BIT_CFB);
180}
181
182int crypto4xx_setkey_aes_ecb(struct crypto_ablkcipher *cipher,
183 const u8 *key, unsigned int keylen)
184{
185 return crypto4xx_setkey_aes(cipher, key, keylen, CRYPTO_MODE_ECB,
186 CRYPTO_FEEDBACK_MODE_NO_FB);
187}
188
189int crypto4xx_setkey_aes_ofb(struct crypto_ablkcipher *cipher,
190 const u8 *key, unsigned int keylen)
191{
192 return crypto4xx_setkey_aes(cipher, key, keylen, CRYPTO_MODE_OFB,
193 CRYPTO_FEEDBACK_MODE_64BIT_OFB);
194}
195
196int crypto4xx_setkey_rfc3686(struct crypto_ablkcipher *cipher,
197 const u8 *key, unsigned int keylen)
198{
199 struct crypto_tfm *tfm = crypto_ablkcipher_tfm(cipher);
200 struct crypto4xx_ctx *ctx = crypto_tfm_ctx(tfm);
201 int rc;
202
203 rc = crypto4xx_setkey_aes(cipher, key, keylen - CTR_RFC3686_NONCE_SIZE,
204 CRYPTO_MODE_CTR, CRYPTO_FEEDBACK_MODE_NO_FB);
205 if (rc)
206 return rc;
207
208 memcpy(ctx->state_record,
209 key + keylen - CTR_RFC3686_NONCE_SIZE, CTR_RFC3686_NONCE_SIZE);
210
211 return 0;
212}
213
214int crypto4xx_rfc3686_encrypt(struct ablkcipher_request *req)
215{
216 struct crypto4xx_ctx *ctx = crypto_tfm_ctx(req->base.tfm);
217 __be32 iv[AES_IV_SIZE / 4] = { *(u32 *)ctx->state_record,
218 *(u32 *) req->info, *(u32 *) (req->info + 4), cpu_to_be32(1) };
219
220 ctx->direction = DIR_OUTBOUND;
221 ctx->pd_ctl = 1;
222
223 return crypto4xx_build_pd(&req->base, ctx, req->src, req->dst,
224 req->nbytes, iv, AES_IV_SIZE);
225}
226
227int crypto4xx_rfc3686_decrypt(struct ablkcipher_request *req)
228{
229 struct crypto4xx_ctx *ctx = crypto_tfm_ctx(req->base.tfm);
230 __be32 iv[AES_IV_SIZE / 4] = { *(u32 *)ctx->state_record,
231 *(u32 *) req->info, *(u32 *) (req->info + 4), cpu_to_be32(1) };
232
233 ctx->direction = DIR_INBOUND;
234 ctx->pd_ctl = 1;
235
236 return crypto4xx_build_pd(&req->base, ctx, req->src, req->dst,
237 req->nbytes, iv, AES_IV_SIZE);
238}
239
174/** 240/**
175 * HASH SHA1 Functions 241 * HASH SHA1 Functions
176 */ 242 */
diff --git a/drivers/crypto/amcc/crypto4xx_core.c b/drivers/crypto/amcc/crypto4xx_core.c
index 9e96af725b31..3c086cf7b052 100644
--- a/drivers/crypto/amcc/crypto4xx_core.c
+++ b/drivers/crypto/amcc/crypto4xx_core.c
@@ -36,6 +36,7 @@
36#include <asm/dcr-regs.h> 36#include <asm/dcr-regs.h>
37#include <asm/cacheflush.h> 37#include <asm/cacheflush.h>
38#include <crypto/aes.h> 38#include <crypto/aes.h>
39#include <crypto/ctr.h>
39#include <crypto/sha.h> 40#include <crypto/sha.h>
40#include "crypto4xx_reg_def.h" 41#include "crypto4xx_reg_def.h"
41#include "crypto4xx_core.h" 42#include "crypto4xx_core.h"
@@ -1133,6 +1134,103 @@ struct crypto4xx_alg_common crypto4xx_alg[] = {
1133 } 1134 }
1134 } 1135 }
1135 }}, 1136 }},
1137 { .type = CRYPTO_ALG_TYPE_ABLKCIPHER, .u.cipher = {
1138 .cra_name = "cfb(aes)",
1139 .cra_driver_name = "cfb-aes-ppc4xx",
1140 .cra_priority = CRYPTO4XX_CRYPTO_PRIORITY,
1141 .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER |
1142 CRYPTO_ALG_ASYNC |
1143 CRYPTO_ALG_KERN_DRIVER_ONLY,
1144 .cra_blocksize = AES_BLOCK_SIZE,
1145 .cra_ctxsize = sizeof(struct crypto4xx_ctx),
1146 .cra_type = &crypto_ablkcipher_type,
1147 .cra_init = crypto4xx_alg_init,
1148 .cra_exit = crypto4xx_alg_exit,
1149 .cra_module = THIS_MODULE,
1150 .cra_u = {
1151 .ablkcipher = {
1152 .min_keysize = AES_MIN_KEY_SIZE,
1153 .max_keysize = AES_MAX_KEY_SIZE,
1154 .ivsize = AES_IV_SIZE,
1155 .setkey = crypto4xx_setkey_aes_cfb,
1156 .encrypt = crypto4xx_encrypt,
1157 .decrypt = crypto4xx_decrypt,
1158 }
1159 }
1160 } },
1161 { .type = CRYPTO_ALG_TYPE_ABLKCIPHER, .u.cipher = {
1162 .cra_name = "rfc3686(ctr(aes))",
1163 .cra_driver_name = "rfc3686-ctr-aes-ppc4xx",
1164 .cra_priority = CRYPTO4XX_CRYPTO_PRIORITY,
1165 .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER |
1166 CRYPTO_ALG_ASYNC |
1167 CRYPTO_ALG_KERN_DRIVER_ONLY,
1168 .cra_blocksize = AES_BLOCK_SIZE,
1169 .cra_ctxsize = sizeof(struct crypto4xx_ctx),
1170 .cra_type = &crypto_ablkcipher_type,
1171 .cra_init = crypto4xx_alg_init,
1172 .cra_exit = crypto4xx_alg_exit,
1173 .cra_module = THIS_MODULE,
1174 .cra_u = {
1175 .ablkcipher = {
1176 .min_keysize = AES_MIN_KEY_SIZE +
1177 CTR_RFC3686_NONCE_SIZE,
1178 .max_keysize = AES_MAX_KEY_SIZE +
1179 CTR_RFC3686_NONCE_SIZE,
1180 .ivsize = CTR_RFC3686_IV_SIZE,
1181 .setkey = crypto4xx_setkey_rfc3686,
1182 .encrypt = crypto4xx_rfc3686_encrypt,
1183 .decrypt = crypto4xx_rfc3686_decrypt,
1184 }
1185 }
1186 } },
1187 { .type = CRYPTO_ALG_TYPE_ABLKCIPHER, .u.cipher = {
1188 .cra_name = "ecb(aes)",
1189 .cra_driver_name = "ecb-aes-ppc4xx",
1190 .cra_priority = CRYPTO4XX_CRYPTO_PRIORITY,
1191 .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER |
1192 CRYPTO_ALG_ASYNC |
1193 CRYPTO_ALG_KERN_DRIVER_ONLY,
1194 .cra_blocksize = AES_BLOCK_SIZE,
1195 .cra_ctxsize = sizeof(struct crypto4xx_ctx),
1196 .cra_type = &crypto_ablkcipher_type,
1197 .cra_init = crypto4xx_alg_init,
1198 .cra_exit = crypto4xx_alg_exit,
1199 .cra_module = THIS_MODULE,
1200 .cra_u = {
1201 .ablkcipher = {
1202 .min_keysize = AES_MIN_KEY_SIZE,
1203 .max_keysize = AES_MAX_KEY_SIZE,
1204 .setkey = crypto4xx_setkey_aes_ecb,
1205 .encrypt = crypto4xx_encrypt,
1206 .decrypt = crypto4xx_decrypt,
1207 }
1208 }
1209 } },
1210 { .type = CRYPTO_ALG_TYPE_ABLKCIPHER, .u.cipher = {
1211 .cra_name = "ofb(aes)",
1212 .cra_driver_name = "ofb-aes-ppc4xx",
1213 .cra_priority = CRYPTO4XX_CRYPTO_PRIORITY,
1214 .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER |
1215 CRYPTO_ALG_ASYNC |
1216 CRYPTO_ALG_KERN_DRIVER_ONLY,
1217 .cra_blocksize = AES_BLOCK_SIZE,
1218 .cra_ctxsize = sizeof(struct crypto4xx_ctx),
1219 .cra_type = &crypto_ablkcipher_type,
1220 .cra_init = crypto4xx_alg_init,
1221 .cra_exit = crypto4xx_alg_exit,
1222 .cra_module = THIS_MODULE,
1223 .cra_u = {
1224 .ablkcipher = {
1225 .min_keysize = AES_MIN_KEY_SIZE,
1226 .max_keysize = AES_MAX_KEY_SIZE,
1227 .ivsize = AES_IV_SIZE,
1228 .setkey = crypto4xx_setkey_aes_cbc,
1229 .encrypt = crypto4xx_encrypt,
1230 .decrypt = crypto4xx_decrypt,
1231 }
1232 }
1233 } },
1136}; 1234};
1137 1235
1138/** 1236/**
diff --git a/drivers/crypto/amcc/crypto4xx_core.h b/drivers/crypto/amcc/crypto4xx_core.h
index e3b822907197..f886b8bdc868 100644
--- a/drivers/crypto/amcc/crypto4xx_core.h
+++ b/drivers/crypto/amcc/crypto4xx_core.h
@@ -171,8 +171,18 @@ u32 crypto4xx_build_pd(struct crypto_async_request *req,
171 void *iv, u32 iv_len); 171 void *iv, u32 iv_len);
172int crypto4xx_setkey_aes_cbc(struct crypto_ablkcipher *cipher, 172int crypto4xx_setkey_aes_cbc(struct crypto_ablkcipher *cipher,
173 const u8 *key, unsigned int keylen); 173 const u8 *key, unsigned int keylen);
174int crypto4xx_setkey_aes_cfb(struct crypto_ablkcipher *cipher,
175 const u8 *key, unsigned int keylen);
176int crypto4xx_setkey_aes_ecb(struct crypto_ablkcipher *cipher,
177 const u8 *key, unsigned int keylen);
178int crypto4xx_setkey_aes_ofb(struct crypto_ablkcipher *cipher,
179 const u8 *key, unsigned int keylen);
180int crypto4xx_setkey_rfc3686(struct crypto_ablkcipher *cipher,
181 const u8 *key, unsigned int keylen);
174int crypto4xx_encrypt(struct ablkcipher_request *req); 182int crypto4xx_encrypt(struct ablkcipher_request *req);
175int crypto4xx_decrypt(struct ablkcipher_request *req); 183int crypto4xx_decrypt(struct ablkcipher_request *req);
184int crypto4xx_rfc3686_encrypt(struct ablkcipher_request *req);
185int crypto4xx_rfc3686_decrypt(struct ablkcipher_request *req);
176int crypto4xx_sha1_alg_init(struct crypto_tfm *tfm); 186int crypto4xx_sha1_alg_init(struct crypto_tfm *tfm);
177int crypto4xx_hash_digest(struct ahash_request *req); 187int crypto4xx_hash_digest(struct ahash_request *req);
178int crypto4xx_hash_final(struct ahash_request *req); 188int crypto4xx_hash_final(struct ahash_request *req);
diff --git a/drivers/crypto/amcc/crypto4xx_sa.h b/drivers/crypto/amcc/crypto4xx_sa.h
index 3c3dfcaf4e0f..7cc04f1ff8a0 100644
--- a/drivers/crypto/amcc/crypto4xx_sa.h
+++ b/drivers/crypto/amcc/crypto4xx_sa.h
@@ -112,6 +112,9 @@ union sa_command_0 {
112 112
113#define CRYPTO_MODE_ECB 0 113#define CRYPTO_MODE_ECB 0
114#define CRYPTO_MODE_CBC 1 114#define CRYPTO_MODE_CBC 1
115#define CRYPTO_MODE_OFB 2
116#define CRYPTO_MODE_CFB 3
117#define CRYPTO_MODE_CTR 4
115 118
116#define CRYPTO_FEEDBACK_MODE_NO_FB 0 119#define CRYPTO_FEEDBACK_MODE_NO_FB 0
117#define CRYPTO_FEEDBACK_MODE_64BIT_OFB 0 120#define CRYPTO_FEEDBACK_MODE_64BIT_OFB 0