Skip to content

Commit f2a13e7

Browse files
chunkeeyherbertx
authored andcommitted
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>
1 parent 249c8d9 commit f2a13e7

4 files changed

Lines changed: 177 additions & 0 deletions

File tree

‎drivers/crypto/amcc/crypto4xx_alg.c‎

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include <crypto/algapi.h>
2929
#include <crypto/aes.h>
3030
#include <crypto/sha.h>
31+
#include <crypto/ctr.h>
3132
#include "crypto4xx_reg_def.h"
3233
#include "crypto4xx_core.h"
3334
#include "crypto4xx_sa.h"
@@ -171,6 +172,71 @@ int crypto4xx_setkey_aes_cbc(struct crypto_ablkcipher *cipher,
171172
CRYPTO_FEEDBACK_MODE_NO_FB);
172173
}
173174

175+
int 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+
182+
int 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+
189+
int 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+
196+
int 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+
214+
int 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+
227+
int 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+
174240
/**
175241
* HASH SHA1 Functions
176242
*/

‎drivers/crypto/amcc/crypto4xx_core.c‎

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include <asm/dcr-regs.h>
3737
#include <asm/cacheflush.h>
3838
#include <crypto/aes.h>
39+
#include <crypto/ctr.h>
3940
#include <crypto/sha.h>
4041
#include "crypto4xx_reg_def.h"
4142
#include "crypto4xx_core.h"
@@ -1133,6 +1134,103 @@ struct crypto4xx_alg_common crypto4xx_alg[] = {
11331134
}
11341135
}
11351136
}},
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+
} },
11361234
};
11371235

11381236
/**

‎drivers/crypto/amcc/crypto4xx_core.h‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,18 @@ u32 crypto4xx_build_pd(struct crypto_async_request *req,
171171
void *iv, u32 iv_len);
172172
int crypto4xx_setkey_aes_cbc(struct crypto_ablkcipher *cipher,
173173
const u8 *key, unsigned int keylen);
174+
int crypto4xx_setkey_aes_cfb(struct crypto_ablkcipher *cipher,
175+
const u8 *key, unsigned int keylen);
176+
int crypto4xx_setkey_aes_ecb(struct crypto_ablkcipher *cipher,
177+
const u8 *key, unsigned int keylen);
178+
int crypto4xx_setkey_aes_ofb(struct crypto_ablkcipher *cipher,
179+
const u8 *key, unsigned int keylen);
180+
int crypto4xx_setkey_rfc3686(struct crypto_ablkcipher *cipher,
181+
const u8 *key, unsigned int keylen);
174182
int crypto4xx_encrypt(struct ablkcipher_request *req);
175183
int crypto4xx_decrypt(struct ablkcipher_request *req);
184+
int crypto4xx_rfc3686_encrypt(struct ablkcipher_request *req);
185+
int crypto4xx_rfc3686_decrypt(struct ablkcipher_request *req);
176186
int crypto4xx_sha1_alg_init(struct crypto_tfm *tfm);
177187
int crypto4xx_hash_digest(struct ahash_request *req);
178188
int crypto4xx_hash_final(struct ahash_request *req);

‎drivers/crypto/amcc/crypto4xx_sa.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ union sa_command_0 {
112112

113113
#define CRYPTO_MODE_ECB 0
114114
#define CRYPTO_MODE_CBC 1
115+
#define CRYPTO_MODE_OFB 2
116+
#define CRYPTO_MODE_CFB 3
117+
#define CRYPTO_MODE_CTR 4
115118

116119
#define CRYPTO_FEEDBACK_MODE_NO_FB 0
117120
#define CRYPTO_FEEDBACK_MODE_64BIT_OFB 0

0 commit comments

Comments
 (0)