aboutsummaryrefslogtreecommitdiffstats
path: root/arch
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2006-08-13 00:16:39 -0400
committerHerbert Xu <herbert@gondor.apana.org.au>2006-09-20 21:41:02 -0400
commit560c06ae1ab7c677002ea3b6ac83521bf12ee07d (patch)
tree374ed69a7e23ba9d07458d20672aac6ae552ae51 /arch
parent25cdbcd9e5d20e431f829cafce48a418830011f4 (diff)
[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>
Diffstat (limited to 'arch')
-rw-r--r--arch/i386/crypto/aes.c3
-rw-r--r--arch/s390/crypto/aes_s390.c3
-rw-r--r--arch/s390/crypto/des_s390.c13
-rw-r--r--arch/x86_64/crypto/aes.c5
4 files changed, 15 insertions, 9 deletions
diff --git a/arch/i386/crypto/aes.c b/arch/i386/crypto/aes.c
index d3806daa3de3..49aad9397f10 100644
--- a/arch/i386/crypto/aes.c
+++ b/arch/i386/crypto/aes.c
@@ -379,12 +379,13 @@ static void gen_tabs(void)
379} 379}
380 380
381static int aes_set_key(struct crypto_tfm *tfm, const u8 *in_key, 381static int aes_set_key(struct crypto_tfm *tfm, const u8 *in_key,
382 unsigned int key_len, u32 *flags) 382 unsigned int key_len)
383{ 383{
384 int i; 384 int i;
385 u32 ss[8]; 385 u32 ss[8];
386 struct aes_ctx *ctx = crypto_tfm_ctx(tfm); 386 struct aes_ctx *ctx = crypto_tfm_ctx(tfm);
387 const __le32 *key = (const __le32 *)in_key; 387 const __le32 *key = (const __le32 *)in_key;
388 u32 *flags = &tfm->crt_flags;
388 389
389 /* encryption schedule */ 390 /* encryption schedule */
390 391
diff --git a/arch/s390/crypto/aes_s390.c b/arch/s390/crypto/aes_s390.c
index 5713c7e5bd16..c7c43c9de0d9 100644
--- a/arch/s390/crypto/aes_s390.c
+++ b/arch/s390/crypto/aes_s390.c
@@ -38,9 +38,10 @@ struct s390_aes_ctx {
38}; 38};
39 39
40static int aes_set_key(struct crypto_tfm *tfm, const u8 *in_key, 40static int aes_set_key(struct crypto_tfm *tfm, const u8 *in_key,
41 unsigned int key_len, u32 *flags) 41 unsigned int key_len)
42{ 42{
43 struct s390_aes_ctx *sctx = crypto_tfm_ctx(tfm); 43 struct s390_aes_ctx *sctx = crypto_tfm_ctx(tfm);
44 u32 *flags = &tfm->crt_flags;
44 45
45 switch (key_len) { 46 switch (key_len) {
46 case 16: 47 case 16:
diff --git a/arch/s390/crypto/des_s390.c b/arch/s390/crypto/des_s390.c
index b3f7496a79b4..170757b3451d 100644
--- a/arch/s390/crypto/des_s390.c
+++ b/arch/s390/crypto/des_s390.c
@@ -45,9 +45,10 @@ struct crypt_s390_des3_192_ctx {
45}; 45};
46 46
47static int des_setkey(struct crypto_tfm *tfm, const u8 *key, 47static int des_setkey(struct crypto_tfm *tfm, const u8 *key,
48 unsigned int keylen, u32 *flags) 48 unsigned int keylen)
49{ 49{
50 struct crypt_s390_des_ctx *dctx = crypto_tfm_ctx(tfm); 50 struct crypt_s390_des_ctx *dctx = crypto_tfm_ctx(tfm);
51 u32 *flags = &tfm->crt_flags;
51 int ret; 52 int ret;
52 53
53 /* test if key is valid (not a weak key) */ 54 /* test if key is valid (not a weak key) */
@@ -167,11 +168,12 @@ static struct crypto_alg des_alg = {
167 * 168 *
168 */ 169 */
169static int des3_128_setkey(struct crypto_tfm *tfm, const u8 *key, 170static int des3_128_setkey(struct crypto_tfm *tfm, const u8 *key,
170 unsigned int keylen, u32 *flags) 171 unsigned int keylen)
171{ 172{
172 int i, ret; 173 int i, ret;
173 struct crypt_s390_des3_128_ctx *dctx = crypto_tfm_ctx(tfm); 174 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;
175 177
176 if (!(memcmp(key, &key[DES_KEY_SIZE], DES_KEY_SIZE))) { 178 if (!(memcmp(key, &key[DES_KEY_SIZE], DES_KEY_SIZE))) {
177 *flags |= CRYPTO_TFM_RES_BAD_KEY_SCHED; 179 *flags |= CRYPTO_TFM_RES_BAD_KEY_SCHED;
@@ -303,11 +305,12 @@ static struct crypto_alg des3_128_alg = {
303 * 305 *
304 */ 306 */
305static int des3_192_setkey(struct crypto_tfm *tfm, const u8 *key, 307static int des3_192_setkey(struct crypto_tfm *tfm, const u8 *key,
306 unsigned int keylen, u32 *flags) 308 unsigned int keylen)
307{ 309{
308 int i, ret; 310 int i, ret;
309 struct crypt_s390_des3_192_ctx *dctx = crypto_tfm_ctx(tfm); 311 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;
311 314
312 if (!(memcmp(key, &key[DES_KEY_SIZE], DES_KEY_SIZE) && 315 if (!(memcmp(key, &key[DES_KEY_SIZE], DES_KEY_SIZE) &&
313 memcmp(&key[DES_KEY_SIZE], &key[DES_KEY_SIZE * 2], 316 memcmp(&key[DES_KEY_SIZE], &key[DES_KEY_SIZE * 2],
diff --git a/arch/x86_64/crypto/aes.c b/arch/x86_64/crypto/aes.c
index 68866fab37aa..5cdb13ea5cc2 100644
--- a/arch/x86_64/crypto/aes.c
+++ b/arch/x86_64/crypto/aes.c
@@ -228,13 +228,14 @@ static void __init gen_tabs(void)
228} 228}
229 229
230static int aes_set_key(struct crypto_tfm *tfm, const u8 *in_key, 230static int aes_set_key(struct crypto_tfm *tfm, const u8 *in_key,
231 unsigned int key_len, u32 *flags) 231 unsigned int key_len)
232{ 232{
233 struct aes_ctx *ctx = crypto_tfm_ctx(tfm); 233 struct aes_ctx *ctx = crypto_tfm_ctx(tfm);
234 const __le32 *key = (const __le32 *)in_key; 234 const __le32 *key = (const __le32 *)in_key;
235 u32 *flags = &tfm->crt_flags;
235 u32 i, j, t, u, v, w; 236 u32 i, j, t, u, v, w;
236 237
237 if (key_len != 16 && key_len != 24 && key_len != 32) { 238 if (key_len % 8) {
238 *flags |= CRYPTO_TFM_RES_BAD_KEY_LEN; 239 *flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
239 return -EINVAL; 240 return -EINVAL;
240 } 241 }