Skip to content

Commit d09f51b

Browse files
author
David S. Miller
committed
Merge master.kernel.org:/pub/scm/linux/kernel/git/herbert/crypto-2.6
Conflicts: crypto/Kconfig
2 parents 1b1ac75 + e559e91 commit d09f51b

File tree

8 files changed

+125
-34
lines changed

8 files changed

+125
-34
lines changed

crypto/Kconfig

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ source "crypto/async_tx/Kconfig"
1212
#
1313
# Cryptographic API Configuration
1414
#
15-
menu "Cryptographic options"
16-
17-
config CRYPTO
15+
menuconfig CRYPTO
1816
bool "Cryptographic API"
1917
help
2018
This option provides the core Cryptographic API.
@@ -473,5 +471,3 @@ config CRYPTO_TEST
473471
source "drivers/crypto/Kconfig"
474472

475473
endif # if CRYPTO
476-
477-
endmenu

crypto/ablkcipher.c

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,41 @@
1919
#include <linux/module.h>
2020
#include <linux/seq_file.h>
2121

22+
static int setkey_unaligned(struct crypto_ablkcipher *tfm, const u8 *key, unsigned int keylen)
23+
{
24+
struct ablkcipher_alg *cipher = crypto_ablkcipher_alg(tfm);
25+
unsigned long alignmask = crypto_ablkcipher_alignmask(tfm);
26+
int ret;
27+
u8 *buffer, *alignbuffer;
28+
unsigned long absize;
29+
30+
absize = keylen + alignmask;
31+
buffer = kmalloc(absize, GFP_ATOMIC);
32+
if (!buffer)
33+
return -ENOMEM;
34+
35+
alignbuffer = (u8 *)ALIGN((unsigned long)buffer, alignmask + 1);
36+
memcpy(alignbuffer, key, keylen);
37+
ret = cipher->setkey(tfm, alignbuffer, keylen);
38+
memset(alignbuffer, 0, absize);
39+
kfree(buffer);
40+
return ret;
41+
}
42+
2243
static int setkey(struct crypto_ablkcipher *tfm, const u8 *key,
2344
unsigned int keylen)
2445
{
2546
struct ablkcipher_alg *cipher = crypto_ablkcipher_alg(tfm);
47+
unsigned long alignmask = crypto_ablkcipher_alignmask(tfm);
2648

2749
if (keylen < cipher->min_keysize || keylen > cipher->max_keysize) {
2850
crypto_ablkcipher_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
2951
return -EINVAL;
3052
}
3153

54+
if ((unsigned long)key & alignmask)
55+
return setkey_unaligned(tfm, key, keylen);
56+
3257
return cipher->setkey(tfm, key, keylen);
3358
}
3459

@@ -66,8 +91,10 @@ static void crypto_ablkcipher_show(struct seq_file *m, struct crypto_alg *alg)
6691
seq_printf(m, "min keysize : %u\n", ablkcipher->min_keysize);
6792
seq_printf(m, "max keysize : %u\n", ablkcipher->max_keysize);
6893
seq_printf(m, "ivsize : %u\n", ablkcipher->ivsize);
69-
seq_printf(m, "qlen : %u\n", ablkcipher->queue->qlen);
70-
seq_printf(m, "max qlen : %u\n", ablkcipher->queue->max_qlen);
94+
if (ablkcipher->queue) {
95+
seq_printf(m, "qlen : %u\n", ablkcipher->queue->qlen);
96+
seq_printf(m, "max qlen : %u\n", ablkcipher->queue->max_qlen);
97+
}
7198
}
7299

73100
const struct crypto_type crypto_ablkcipher_type = {

crypto/algapi.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ void crypto_larval_error(const char *name, u32 type, u32 mask)
3434
if (alg) {
3535
if (crypto_is_larval(alg)) {
3636
struct crypto_larval *larval = (void *)alg;
37-
complete(&larval->completion);
37+
complete_all(&larval->completion);
3838
}
3939
crypto_mod_put(alg);
4040
}
@@ -164,7 +164,7 @@ static int __crypto_register_alg(struct crypto_alg *alg,
164164
continue;
165165

166166
larval->adult = alg;
167-
complete(&larval->completion);
167+
complete_all(&larval->completion);
168168
continue;
169169
}
170170

crypto/api.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ static void crypto_larval_kill(struct crypto_alg *alg)
144144
down_write(&crypto_alg_sem);
145145
list_del(&alg->cra_list);
146146
up_write(&crypto_alg_sem);
147-
complete(&larval->completion);
147+
complete_all(&larval->completion);
148148
crypto_alg_put(alg);
149149
}
150150

crypto/blkcipher.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,16 +336,41 @@ static int blkcipher_walk_first(struct blkcipher_desc *desc,
336336
return blkcipher_walk_next(desc, walk);
337337
}
338338

339+
static int setkey_unaligned(struct crypto_tfm *tfm, const u8 *key, unsigned int keylen)
340+
{
341+
struct blkcipher_alg *cipher = &tfm->__crt_alg->cra_blkcipher;
342+
unsigned long alignmask = crypto_tfm_alg_alignmask(tfm);
343+
int ret;
344+
u8 *buffer, *alignbuffer;
345+
unsigned long absize;
346+
347+
absize = keylen + alignmask;
348+
buffer = kmalloc(absize, GFP_ATOMIC);
349+
if (!buffer)
350+
return -ENOMEM;
351+
352+
alignbuffer = (u8 *)ALIGN((unsigned long)buffer, alignmask + 1);
353+
memcpy(alignbuffer, key, keylen);
354+
ret = cipher->setkey(tfm, alignbuffer, keylen);
355+
memset(alignbuffer, 0, absize);
356+
kfree(buffer);
357+
return ret;
358+
}
359+
339360
static int setkey(struct crypto_tfm *tfm, const u8 *key,
340361
unsigned int keylen)
341362
{
342363
struct blkcipher_alg *cipher = &tfm->__crt_alg->cra_blkcipher;
364+
unsigned long alignmask = crypto_tfm_alg_alignmask(tfm);
343365

344366
if (keylen < cipher->min_keysize || keylen > cipher->max_keysize) {
345367
tfm->crt_flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
346368
return -EINVAL;
347369
}
348370

371+
if ((unsigned long)key & alignmask)
372+
return setkey_unaligned(tfm, key, keylen);
373+
349374
return cipher->setkey(tfm, key, keylen);
350375
}
351376

crypto/cipher.c

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,43 @@
2020
#include <linux/string.h>
2121
#include "internal.h"
2222

23+
static int setkey_unaligned(struct crypto_tfm *tfm, const u8 *key, unsigned int keylen)
24+
{
25+
struct cipher_alg *cia = &tfm->__crt_alg->cra_cipher;
26+
unsigned long alignmask = crypto_tfm_alg_alignmask(tfm);
27+
int ret;
28+
u8 *buffer, *alignbuffer;
29+
unsigned long absize;
30+
31+
absize = keylen + alignmask;
32+
buffer = kmalloc(absize, GFP_ATOMIC);
33+
if (!buffer)
34+
return -ENOMEM;
35+
36+
alignbuffer = (u8 *)ALIGN((unsigned long)buffer, alignmask + 1);
37+
memcpy(alignbuffer, key, keylen);
38+
ret = cia->cia_setkey(tfm, alignbuffer, keylen);
39+
memset(alignbuffer, 0, absize);
40+
kfree(buffer);
41+
return ret;
42+
43+
}
44+
2345
static int setkey(struct crypto_tfm *tfm, const u8 *key, unsigned int keylen)
2446
{
2547
struct cipher_alg *cia = &tfm->__crt_alg->cra_cipher;
26-
48+
unsigned long alignmask = crypto_tfm_alg_alignmask(tfm);
49+
2750
tfm->crt_flags &= ~CRYPTO_TFM_RES_MASK;
2851
if (keylen < cia->cia_min_keysize || keylen > cia->cia_max_keysize) {
2952
tfm->crt_flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
3053
return -EINVAL;
31-
} else
32-
return cia->cia_setkey(tfm, key, keylen);
54+
}
55+
56+
if ((unsigned long)key & alignmask)
57+
return setkey_unaligned(tfm, key, keylen);
58+
59+
return cia->cia_setkey(tfm, key, keylen);
3360
}
3461

3562
static void cipher_crypt_unaligned(void (*fn)(struct crypto_tfm *, u8 *,

crypto/hash.c

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,42 @@ static unsigned int crypto_hash_ctxsize(struct crypto_alg *alg, u32 type,
2222
return alg->cra_ctxsize;
2323
}
2424

25+
static int hash_setkey_unaligned(struct crypto_hash *crt, const u8 *key,
26+
unsigned int keylen)
27+
{
28+
struct crypto_tfm *tfm = crypto_hash_tfm(crt);
29+
struct hash_alg *alg = &tfm->__crt_alg->cra_hash;
30+
unsigned long alignmask = crypto_hash_alignmask(crt);
31+
int ret;
32+
u8 *buffer, *alignbuffer;
33+
unsigned long absize;
34+
35+
absize = keylen + alignmask;
36+
buffer = kmalloc(absize, GFP_ATOMIC);
37+
if (!buffer)
38+
return -ENOMEM;
39+
40+
alignbuffer = (u8 *)ALIGN((unsigned long)buffer, alignmask + 1);
41+
memcpy(alignbuffer, key, keylen);
42+
ret = alg->setkey(crt, alignbuffer, keylen);
43+
memset(alignbuffer, 0, absize);
44+
kfree(buffer);
45+
return ret;
46+
}
47+
48+
static int hash_setkey(struct crypto_hash *crt, const u8 *key,
49+
unsigned int keylen)
50+
{
51+
struct crypto_tfm *tfm = crypto_hash_tfm(crt);
52+
struct hash_alg *alg = &tfm->__crt_alg->cra_hash;
53+
unsigned long alignmask = crypto_hash_alignmask(crt);
54+
55+
if ((unsigned long)key & alignmask)
56+
return hash_setkey_unaligned(crt, key, keylen);
57+
58+
return alg->setkey(crt, key, keylen);
59+
}
60+
2561
static int crypto_init_hash_ops(struct crypto_tfm *tfm, u32 type, u32 mask)
2662
{
2763
struct hash_tfm *crt = &tfm->crt_hash;
@@ -34,7 +70,7 @@ static int crypto_init_hash_ops(struct crypto_tfm *tfm, u32 type, u32 mask)
3470
crt->update = alg->update;
3571
crt->final = alg->final;
3672
crt->digest = alg->digest;
37-
crt->setkey = alg->setkey;
73+
crt->setkey = hash_setkey;
3874
crt->digestsize = alg->digestsize;
3975

4076
return 0;

include/linux/crypto.h

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -295,28 +295,8 @@ struct blkcipher_tfm {
295295
};
296296

297297
struct cipher_tfm {
298-
void *cit_iv;
299-
unsigned int cit_ivsize;
300-
u32 cit_mode;
301298
int (*cit_setkey)(struct crypto_tfm *tfm,
302299
const u8 *key, unsigned int keylen);
303-
int (*cit_encrypt)(struct crypto_tfm *tfm,
304-
struct scatterlist *dst,
305-
struct scatterlist *src,
306-
unsigned int nbytes);
307-
int (*cit_encrypt_iv)(struct crypto_tfm *tfm,
308-
struct scatterlist *dst,
309-
struct scatterlist *src,
310-
unsigned int nbytes, u8 *iv);
311-
int (*cit_decrypt)(struct crypto_tfm *tfm,
312-
struct scatterlist *dst,
313-
struct scatterlist *src,
314-
unsigned int nbytes);
315-
int (*cit_decrypt_iv)(struct crypto_tfm *tfm,
316-
struct scatterlist *dst,
317-
struct scatterlist *src,
318-
unsigned int nbytes, u8 *iv);
319-
void (*cit_xor_block)(u8 *dst, const u8 *src);
320300
void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
321301
void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
322302
};

0 commit comments

Comments
 (0)