Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d09f51b6 authored by David S. Miller's avatar David S. Miller
Browse files

Merge master.kernel.org:/pub/scm/linux/kernel/git/herbert/crypto-2.6

Conflicts:

	crypto/Kconfig
parents 1b1ac759 e559e91c
Loading
Loading
Loading
Loading
+1 −5
Original line number Diff line number Diff line
@@ -12,9 +12,7 @@ source "crypto/async_tx/Kconfig"
#
# Cryptographic API Configuration
#
menu "Cryptographic options"

config CRYPTO
menuconfig CRYPTO
	bool "Cryptographic API"
	help
	  This option provides the core Cryptographic API.
@@ -473,5 +471,3 @@ config CRYPTO_TEST
source "drivers/crypto/Kconfig"

endif	# if CRYPTO

endmenu
+29 −2
Original line number Diff line number Diff line
@@ -19,16 +19,41 @@
#include <linux/module.h>
#include <linux/seq_file.h>

static int setkey_unaligned(struct crypto_ablkcipher *tfm, const u8 *key, unsigned int keylen)
{
	struct ablkcipher_alg *cipher = crypto_ablkcipher_alg(tfm);
	unsigned long alignmask = crypto_ablkcipher_alignmask(tfm);
	int ret;
	u8 *buffer, *alignbuffer;
	unsigned long absize;

	absize = keylen + alignmask;
	buffer = kmalloc(absize, GFP_ATOMIC);
	if (!buffer)
		return -ENOMEM;

	alignbuffer = (u8 *)ALIGN((unsigned long)buffer, alignmask + 1);
	memcpy(alignbuffer, key, keylen);
	ret = cipher->setkey(tfm, alignbuffer, keylen);
	memset(alignbuffer, 0, absize);
	kfree(buffer);
	return ret;
}

static int setkey(struct crypto_ablkcipher *tfm, const u8 *key,
		  unsigned int keylen)
{
	struct ablkcipher_alg *cipher = crypto_ablkcipher_alg(tfm);
	unsigned long alignmask = crypto_ablkcipher_alignmask(tfm);

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

	if ((unsigned long)key & alignmask)
		return setkey_unaligned(tfm, key, keylen);

	return cipher->setkey(tfm, key, keylen);
}

@@ -66,9 +91,11 @@ static void crypto_ablkcipher_show(struct seq_file *m, struct crypto_alg *alg)
	seq_printf(m, "min keysize  : %u\n", ablkcipher->min_keysize);
	seq_printf(m, "max keysize  : %u\n", ablkcipher->max_keysize);
	seq_printf(m, "ivsize       : %u\n", ablkcipher->ivsize);
	if (ablkcipher->queue) {
		seq_printf(m, "qlen         : %u\n", ablkcipher->queue->qlen);
		seq_printf(m, "max qlen     : %u\n", ablkcipher->queue->max_qlen);
	}
}

const struct crypto_type crypto_ablkcipher_type = {
	.ctxsize = crypto_ablkcipher_ctxsize,
+2 −2
Original line number Diff line number Diff line
@@ -34,7 +34,7 @@ void crypto_larval_error(const char *name, u32 type, u32 mask)
	if (alg) {
		if (crypto_is_larval(alg)) {
			struct crypto_larval *larval = (void *)alg;
			complete(&larval->completion);
			complete_all(&larval->completion);
		}
		crypto_mod_put(alg);
	}
@@ -164,7 +164,7 @@ static int __crypto_register_alg(struct crypto_alg *alg,
				continue;

			larval->adult = alg;
			complete(&larval->completion);
			complete_all(&larval->completion);
			continue;
		}

+1 −1
Original line number Diff line number Diff line
@@ -144,7 +144,7 @@ static void crypto_larval_kill(struct crypto_alg *alg)
	down_write(&crypto_alg_sem);
	list_del(&alg->cra_list);
	up_write(&crypto_alg_sem);
	complete(&larval->completion);
	complete_all(&larval->completion);
	crypto_alg_put(alg);
}

+25 −0
Original line number Diff line number Diff line
@@ -336,16 +336,41 @@ static int blkcipher_walk_first(struct blkcipher_desc *desc,
	return blkcipher_walk_next(desc, walk);
}

static int setkey_unaligned(struct crypto_tfm *tfm, const u8 *key, unsigned int keylen)
{
	struct blkcipher_alg *cipher = &tfm->__crt_alg->cra_blkcipher;
	unsigned long alignmask = crypto_tfm_alg_alignmask(tfm);
	int ret;
	u8 *buffer, *alignbuffer;
	unsigned long absize;

	absize = keylen + alignmask;
	buffer = kmalloc(absize, GFP_ATOMIC);
	if (!buffer)
		return -ENOMEM;

	alignbuffer = (u8 *)ALIGN((unsigned long)buffer, alignmask + 1);
	memcpy(alignbuffer, key, keylen);
	ret = cipher->setkey(tfm, alignbuffer, keylen);
	memset(alignbuffer, 0, absize);
	kfree(buffer);
	return ret;
}

static int setkey(struct crypto_tfm *tfm, const u8 *key,
		  unsigned int keylen)
{
	struct blkcipher_alg *cipher = &tfm->__crt_alg->cra_blkcipher;
	unsigned long alignmask = crypto_tfm_alg_alignmask(tfm);

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

	if ((unsigned long)key & alignmask)
		return setkey_unaligned(tfm, key, keylen);

	return cipher->setkey(tfm, key, keylen);
}

Loading