Skip to content

Commit 560c06a

Browse files
committed
[CRYPTO] api: Get rid of flags argument to setkey
Now that the tfm is passed directly to setkey instead of the ctx, we no longer need to pass the &tfm->crt_flags pointer. This patch also gets rid of a few unnecessary checks on the key length for ciphers as the cipher layer guarantees that the key length is within the bounds specified by the algorithm. Rather than testing dia_setkey every time, this patch does it only once during crypto_alloc_tfm. The redundant check from crypto_digest_setkey is also removed. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent 25cdbcd commit 560c06a

24 files changed

Lines changed: 63 additions & 92 deletions

File tree

‎arch/i386/crypto/aes.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,12 +379,13 @@ static void gen_tabs(void)
379379
}
380380

381381
static int aes_set_key(struct crypto_tfm *tfm, const u8 *in_key,
382-
unsigned int key_len, u32 *flags)
382+
unsigned int key_len)
383383
{
384384
int i;
385385
u32 ss[8];
386386
struct aes_ctx *ctx = crypto_tfm_ctx(tfm);
387387
const __le32 *key = (const __le32 *)in_key;
388+
u32 *flags = &tfm->crt_flags;
388389

389390
/* encryption schedule */
390391

‎arch/s390/crypto/aes_s390.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,10 @@ struct s390_aes_ctx {
3838
};
3939

4040
static int aes_set_key(struct crypto_tfm *tfm, const u8 *in_key,
41-
unsigned int key_len, u32 *flags)
41+
unsigned int key_len)
4242
{
4343
struct s390_aes_ctx *sctx = crypto_tfm_ctx(tfm);
44+
u32 *flags = &tfm->crt_flags;
4445

4546
switch (key_len) {
4647
case 16:

‎arch/s390/crypto/des_s390.c‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,10 @@ struct crypt_s390_des3_192_ctx {
4545
};
4646

4747
static int des_setkey(struct crypto_tfm *tfm, const u8 *key,
48-
unsigned int keylen, u32 *flags)
48+
unsigned int keylen)
4949
{
5050
struct crypt_s390_des_ctx *dctx = crypto_tfm_ctx(tfm);
51+
u32 *flags = &tfm->crt_flags;
5152
int ret;
5253

5354
/* test if key is valid (not a weak key) */
@@ -167,11 +168,12 @@ static struct crypto_alg des_alg = {
167168
*
168169
*/
169170
static int des3_128_setkey(struct crypto_tfm *tfm, const u8 *key,
170-
unsigned int keylen, u32 *flags)
171+
unsigned int keylen)
171172
{
172173
int i, ret;
173174
struct crypt_s390_des3_128_ctx *dctx = crypto_tfm_ctx(tfm);
174-
const u8* temp_key = key;
175+
const u8 *temp_key = key;
176+
u32 *flags = &tfm->crt_flags;
175177

176178
if (!(memcmp(key, &key[DES_KEY_SIZE], DES_KEY_SIZE))) {
177179
*flags |= CRYPTO_TFM_RES_BAD_KEY_SCHED;
@@ -303,11 +305,12 @@ static struct crypto_alg des3_128_alg = {
303305
*
304306
*/
305307
static int des3_192_setkey(struct crypto_tfm *tfm, const u8 *key,
306-
unsigned int keylen, u32 *flags)
308+
unsigned int keylen)
307309
{
308310
int i, ret;
309311
struct crypt_s390_des3_192_ctx *dctx = crypto_tfm_ctx(tfm);
310-
const u8* temp_key = key;
312+
const u8 *temp_key = key;
313+
u32 *flags = &tfm->crt_flags;
311314

312315
if (!(memcmp(key, &key[DES_KEY_SIZE], DES_KEY_SIZE) &&
313316
memcmp(&key[DES_KEY_SIZE], &key[DES_KEY_SIZE * 2],

‎arch/x86_64/crypto/aes.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,13 +228,14 @@ static void __init gen_tabs(void)
228228
}
229229

230230
static int aes_set_key(struct crypto_tfm *tfm, const u8 *in_key,
231-
unsigned int key_len, u32 *flags)
231+
unsigned int key_len)
232232
{
233233
struct aes_ctx *ctx = crypto_tfm_ctx(tfm);
234234
const __le32 *key = (const __le32 *)in_key;
235+
u32 *flags = &tfm->crt_flags;
235236
u32 i, j, t, u, v, w;
236237

237-
if (key_len != 16 && key_len != 24 && key_len != 32) {
238+
if (key_len % 8) {
238239
*flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
239240
return -EINVAL;
240241
}

‎crypto/aes.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,13 +249,14 @@ gen_tabs (void)
249249
}
250250

251251
static int aes_set_key(struct crypto_tfm *tfm, const u8 *in_key,
252-
unsigned int key_len, u32 *flags)
252+
unsigned int key_len)
253253
{
254254
struct aes_ctx *ctx = crypto_tfm_ctx(tfm);
255255
const __le32 *key = (const __le32 *)in_key;
256+
u32 *flags = &tfm->crt_flags;
256257
u32 i, t, u, v, w;
257258

258-
if (key_len != 16 && key_len != 24 && key_len != 32) {
259+
if (key_len % 8) {
259260
*flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
260261
return -EINVAL;
261262
}

‎crypto/anubis.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,10 +461,11 @@ static const u32 rc[] = {
461461
};
462462

463463
static int anubis_setkey(struct crypto_tfm *tfm, const u8 *in_key,
464-
unsigned int key_len, u32 *flags)
464+
unsigned int key_len)
465465
{
466466
struct anubis_ctx *ctx = crypto_tfm_ctx(tfm);
467467
const __be32 *key = (const __be32 *)in_key;
468+
u32 *flags = &tfm->crt_flags;
468469
int N, R, i, r;
469470
u32 kappa[ANUBIS_MAX_N];
470471
u32 inter[ANUBIS_MAX_N];

‎crypto/arc4.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ struct arc4_ctx {
2525
};
2626

2727
static int arc4_set_key(struct crypto_tfm *tfm, const u8 *in_key,
28-
unsigned int key_len, u32 *flags)
28+
unsigned int key_len)
2929
{
3030
struct arc4_ctx *ctx = crypto_tfm_ctx(tfm);
3131
int i, j = 0, k = 0;

‎crypto/blowfish.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -399,8 +399,7 @@ static void bf_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
399399
/*
400400
* Calculates the blowfish S and P boxes for encryption and decryption.
401401
*/
402-
static int bf_setkey(struct crypto_tfm *tfm, const u8 *key,
403-
unsigned int keylen, u32 *flags)
402+
static int bf_setkey(struct crypto_tfm *tfm, const u8 *key, unsigned int keylen)
404403
{
405404
struct bf_ctx *ctx = crypto_tfm_ctx(tfm);
406405
u32 *P = ctx->p;

‎crypto/cast5.c‎

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -769,20 +769,14 @@ static void key_schedule(u32 * x, u32 * z, u32 * k)
769769
}
770770

771771

772-
static int cast5_setkey(struct crypto_tfm *tfm, const u8 *key,
773-
unsigned key_len, u32 *flags)
772+
static int cast5_setkey(struct crypto_tfm *tfm, const u8 *key, unsigned key_len)
774773
{
775774
struct cast5_ctx *c = crypto_tfm_ctx(tfm);
776775
int i;
777776
u32 x[4];
778777
u32 z[4];
779778
u32 k[16];
780779
__be32 p_key[4];
781-
782-
if (key_len < 5 || key_len > 16) {
783-
*flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
784-
return -EINVAL;
785-
}
786780

787781
c->rr = key_len <= 10 ? 1 : 0;
788782

‎crypto/cast6.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,14 +382,15 @@ static inline void W(u32 *key, unsigned int i) {
382382
}
383383

384384
static int cast6_setkey(struct crypto_tfm *tfm, const u8 *in_key,
385-
unsigned key_len, u32 *flags)
385+
unsigned key_len)
386386
{
387387
int i;
388388
u32 key[8];
389389
__be32 p_key[8]; /* padded key */
390390
struct cast6_ctx *c = crypto_tfm_ctx(tfm);
391+
u32 *flags = &tfm->crt_flags;
391392

392-
if (key_len < 16 || key_len > 32 || key_len % 4 != 0) {
393+
if (key_len % 4 != 0) {
393394
*flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
394395
return -EINVAL;
395396
}

0 commit comments

Comments
 (0)