Skip to content

Commit 973fb3f

Browse files
committed
crypto: skcipher - Add default key size helper
While converting ecryptfs over to skcipher I found that it needs to pick a default key size if one isn't given. Rather than having it poke into the guts of the algorithm to get max_keysize, let's provide a helper that is meant to give a sane default (just in case we ever get an algorithm that has no maximum key size). Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent 7768fb2 commit 973fb3f

2 files changed

Lines changed: 10 additions & 5 deletions

File tree

‎crypto/skcipher.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ static int crypto_init_skcipher_ops_blkcipher(struct crypto_tfm *tfm)
118118
skcipher->decrypt = skcipher_decrypt_blkcipher;
119119

120120
skcipher->ivsize = crypto_blkcipher_ivsize(blkcipher);
121-
skcipher->has_setkey = calg->cra_blkcipher.max_keysize;
121+
skcipher->keysize = calg->cra_blkcipher.max_keysize;
122122

123123
return 0;
124124
}
@@ -211,7 +211,7 @@ static int crypto_init_skcipher_ops_ablkcipher(struct crypto_tfm *tfm)
211211
skcipher->ivsize = crypto_ablkcipher_ivsize(ablkcipher);
212212
skcipher->reqsize = crypto_ablkcipher_reqsize(ablkcipher) +
213213
sizeof(struct ablkcipher_request);
214-
skcipher->has_setkey = calg->cra_ablkcipher.max_keysize;
214+
skcipher->keysize = calg->cra_ablkcipher.max_keysize;
215215

216216
return 0;
217217
}

‎include/crypto/skcipher.h‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ struct crypto_skcipher {
6060

6161
unsigned int ivsize;
6262
unsigned int reqsize;
63-
64-
bool has_setkey;
63+
unsigned int keysize;
6564

6665
struct crypto_tfm base;
6766
};
@@ -309,7 +308,13 @@ static inline int crypto_skcipher_setkey(struct crypto_skcipher *tfm,
309308

310309
static inline bool crypto_skcipher_has_setkey(struct crypto_skcipher *tfm)
311310
{
312-
return tfm->has_setkey;
311+
return tfm->keysize;
312+
}
313+
314+
static inline unsigned int crypto_skcipher_default_keysize(
315+
struct crypto_skcipher *tfm)
316+
{
317+
return tfm->keysize;
313318
}
314319

315320
/**

0 commit comments

Comments
 (0)