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

Commit e14e61e9 authored by Linus Torvalds's avatar Linus Torvalds
Browse files
* git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6: (57 commits)
  crypto: aes - Precompute tables
  crypto: talitos - Ack done interrupt in isr instead of tasklet
  crypto: testmgr - Correct comment about deflate parameters
  crypto: salsa20 - Remove private wrappers around various operations
  crypto: des3_ede - permit weak keys unless REQ_WEAK_KEY set
  crypto: sha512 - Switch to shash 
  crypto: sha512 - Move message schedule W[80] to static percpu area
  crypto: michael_mic - Switch to shash
  crypto: wp512 - Switch to shash
  crypto: tgr192 - Switch to shash
  crypto: sha256 - Switch to shash
  crypto: md5 - Switch to shash
  crypto: md4 - Switch to shash
  crypto: sha1 - Switch to shash
  crypto: rmd320 - Switch to shash
  crypto: rmd256 - Switch to shash
  crypto: rmd160 - Switch to shash
  crypto: rmd128 - Switch to shash
  crypto: null - Switch to shash
  crypto: hash - Make setkey optional
  ...
parents cb10ea54 0ee4a969
Loading
Loading
Loading
Loading
+61 −60
Original line number Diff line number Diff line
@@ -6,13 +6,22 @@
 * Intel(R) 64 and IA-32 Architectures Software Developer's Manual
 * Volume 2A: Instruction Set Reference, A-M
 *
 * Copyright (c) 2008 Austin Zhang <austin_zhang@linux.intel.com>
 * Copyright (c) 2008 Kent Liu <kent.liu@intel.com>
 * Copyright (C) 2008 Intel Corporation
 * Authors: Austin Zhang <austin_zhang@linux.intel.com>
 *          Kent Liu <kent.liu@intel.com>
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the Free
 * Software Foundation; either version 2 of the License, or (at your option)
 * any later version.
 * under the terms and conditions of the GNU General Public License,
 * version 2, as published by the Free Software Foundation.
 *
 * This program is distributed in the hope it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
 *
 */
#include <linux/init.h>
@@ -75,99 +84,92 @@ static u32 __pure crc32c_intel_le_hw(u32 crc, unsigned char const *p, size_t len
 * If your algorithm starts with ~0, then XOR with ~0 before you set
 * the seed.
 */
static int crc32c_intel_setkey(struct crypto_ahash *hash, const u8 *key,
static int crc32c_intel_setkey(struct crypto_shash *hash, const u8 *key,
			unsigned int keylen)
{
	u32 *mctx = crypto_ahash_ctx(hash);
	u32 *mctx = crypto_shash_ctx(hash);

	if (keylen != sizeof(u32)) {
		crypto_ahash_set_flags(hash, CRYPTO_TFM_RES_BAD_KEY_LEN);
		crypto_shash_set_flags(hash, CRYPTO_TFM_RES_BAD_KEY_LEN);
		return -EINVAL;
	}
	*mctx = le32_to_cpup((__le32 *)key);
	return 0;
}

static int crc32c_intel_init(struct ahash_request *req)
static int crc32c_intel_init(struct shash_desc *desc)
{
	u32 *mctx = crypto_ahash_ctx(crypto_ahash_reqtfm(req));
	u32 *crcp = ahash_request_ctx(req);
	u32 *mctx = crypto_shash_ctx(desc->tfm);
	u32 *crcp = shash_desc_ctx(desc);

	*crcp = *mctx;

	return 0;
}

static int crc32c_intel_update(struct ahash_request *req)
static int crc32c_intel_update(struct shash_desc *desc, const u8 *data,
			       unsigned int len)
{
	struct crypto_hash_walk walk;
	u32 *crcp = ahash_request_ctx(req);
	u32 crc = *crcp;
	int nbytes;

	for (nbytes = crypto_hash_walk_first(req, &walk); nbytes;
	   nbytes = crypto_hash_walk_done(&walk, 0))
	crc = crc32c_intel_le_hw(crc, walk.data, nbytes);
	u32 *crcp = shash_desc_ctx(desc);

	*crcp = crc;
	*crcp = crc32c_intel_le_hw(*crcp, data, len);
	return 0;
}

static int crc32c_intel_final(struct ahash_request *req)
static int __crc32c_intel_finup(u32 *crcp, const u8 *data, unsigned int len,
				u8 *out)
{
	u32 *crcp = ahash_request_ctx(req);

	*(__le32 *)req->result = ~cpu_to_le32p(crcp);
	*(__le32 *)out = ~cpu_to_le32(crc32c_intel_le_hw(*crcp, data, len));
	return 0;
}

static int crc32c_intel_digest(struct ahash_request *req)
static int crc32c_intel_finup(struct shash_desc *desc, const u8 *data,
			      unsigned int len, u8 *out)
{
	struct crypto_hash_walk walk;
	u32 *mctx = crypto_ahash_ctx(crypto_ahash_reqtfm(req));
	u32 crc = *mctx;
	int nbytes;
	return __crc32c_intel_finup(shash_desc_ctx(desc), data, len, out);
}

	for (nbytes = crypto_hash_walk_first(req, &walk); nbytes;
	   nbytes = crypto_hash_walk_done(&walk, 0))
		crc = crc32c_intel_le_hw(crc, walk.data, nbytes);
static int crc32c_intel_final(struct shash_desc *desc, u8 *out)
{
	u32 *crcp = shash_desc_ctx(desc);

	*(__le32 *)req->result = ~cpu_to_le32(crc);
	*(__le32 *)out = ~cpu_to_le32p(crcp);
	return 0;
}

static int crc32c_intel_digest(struct shash_desc *desc, const u8 *data,
			       unsigned int len, u8 *out)
{
	return __crc32c_intel_finup(crypto_shash_ctx(desc->tfm), data, len,
				    out);
}

static int crc32c_intel_cra_init(struct crypto_tfm *tfm)
{
	u32 *key = crypto_tfm_ctx(tfm);

	*key = ~0;

	tfm->crt_ahash.reqsize = sizeof(u32);

	return 0;
}

static struct crypto_alg alg = {
static struct shash_alg alg = {
	.setkey			=	crc32c_intel_setkey,
	.init			=	crc32c_intel_init,
	.update			=	crc32c_intel_update,
	.final			=	crc32c_intel_final,
	.finup			=	crc32c_intel_finup,
	.digest			=	crc32c_intel_digest,
	.descsize		=	sizeof(u32),
	.digestsize		=	CHKSUM_DIGEST_SIZE,
	.base			=	{
		.cra_name		=	"crc32c",
		.cra_driver_name	=	"crc32c-intel",
		.cra_priority		=	200,
	.cra_flags              =       CRYPTO_ALG_TYPE_AHASH,
		.cra_blocksize		=	CHKSUM_BLOCK_SIZE,
	.cra_alignmask          =       3,
		.cra_ctxsize		=	sizeof(u32),
		.cra_module		=	THIS_MODULE,
	.cra_list               =       LIST_HEAD_INIT(alg.cra_list),
		.cra_init		=	crc32c_intel_cra_init,
	.cra_type               =       &crypto_ahash_type,
	.cra_u                  =       {
		.ahash = {
			.digestsize    =       CHKSUM_DIGEST_SIZE,
			.setkey        =       crc32c_intel_setkey,
			.init          =       crc32c_intel_init,
			.update        =       crc32c_intel_update,
			.final         =       crc32c_intel_final,
			.digest        =       crc32c_intel_digest,
		}
	}
};

@@ -175,14 +177,14 @@ static struct crypto_alg alg = {
static int __init crc32c_intel_mod_init(void)
{
	if (cpu_has_xmm4_2)
		return crypto_register_alg(&alg);
		return crypto_register_shash(&alg);
	else
		return -ENODEV;
}

static void __exit crc32c_intel_mod_fini(void)
{
	crypto_unregister_alg(&alg);
	crypto_unregister_shash(&alg);
}

module_init(crc32c_intel_mod_init);
@@ -194,4 +196,3 @@ MODULE_LICENSE("GPL");

MODULE_ALIAS("crc32c");
MODULE_ALIAS("crc32c-intel");
+14 −15
Original line number Diff line number Diff line
@@ -102,6 +102,7 @@ config CRYPTO_NULL
	tristate "Null algorithms"
	select CRYPTO_ALGAPI
	select CRYPTO_BLKCIPHER
	select CRYPTO_HASH
	help
	  These are 'Null' algorithms, used by IPsec, which do nothing.

@@ -256,12 +257,10 @@ comment "Digest"
config CRYPTO_CRC32C
	tristate "CRC32c CRC algorithm"
	select CRYPTO_HASH
	select LIBCRC32C
	help
	  Castagnoli, et al Cyclic Redundancy-Check Algorithm.  Used
	  by iSCSI for header and data digests and by others.
	  See Castagnoli93.  This implementation uses lib/libcrc32c.
	  Module will be crc32c.
	  See Castagnoli93.  Module will be crc32c.

config CRYPTO_CRC32C_INTEL
	tristate "CRC32c INTEL hardware acceleration"
@@ -277,19 +276,19 @@ config CRYPTO_CRC32C_INTEL

config CRYPTO_MD4
	tristate "MD4 digest algorithm"
	select CRYPTO_ALGAPI
	select CRYPTO_HASH
	help
	  MD4 message digest algorithm (RFC1320).

config CRYPTO_MD5
	tristate "MD5 digest algorithm"
	select CRYPTO_ALGAPI
	select CRYPTO_HASH
	help
	  MD5 message digest algorithm (RFC1321).

config CRYPTO_MICHAEL_MIC
	tristate "Michael MIC keyed digest algorithm"
	select CRYPTO_ALGAPI
	select CRYPTO_HASH
	help
	  Michael MIC is used for message integrity protection in TKIP
	  (IEEE 802.11i). This algorithm is required for TKIP, but it
@@ -298,7 +297,7 @@ config CRYPTO_MICHAEL_MIC

config CRYPTO_RMD128
	tristate "RIPEMD-128 digest algorithm"
	select CRYPTO_ALGAPI
	select CRYPTO_HASH
	help
	  RIPEMD-128 (ISO/IEC 10118-3:2004).

@@ -311,7 +310,7 @@ config CRYPTO_RMD128

config CRYPTO_RMD160
	tristate "RIPEMD-160 digest algorithm"
	select CRYPTO_ALGAPI
	select CRYPTO_HASH
	help
	  RIPEMD-160 (ISO/IEC 10118-3:2004).

@@ -328,7 +327,7 @@ config CRYPTO_RMD160

config CRYPTO_RMD256
	tristate "RIPEMD-256 digest algorithm"
	select CRYPTO_ALGAPI
	select CRYPTO_HASH
	help
	  RIPEMD-256 is an optional extension of RIPEMD-128 with a
	  256 bit hash. It is intended for applications that require
@@ -340,7 +339,7 @@ config CRYPTO_RMD256

config CRYPTO_RMD320
	tristate "RIPEMD-320 digest algorithm"
	select CRYPTO_ALGAPI
	select CRYPTO_HASH
	help
	  RIPEMD-320 is an optional extension of RIPEMD-160 with a
	  320 bit hash. It is intended for applications that require
@@ -352,13 +351,13 @@ config CRYPTO_RMD320

config CRYPTO_SHA1
	tristate "SHA1 digest algorithm"
	select CRYPTO_ALGAPI
	select CRYPTO_HASH
	help
	  SHA-1 secure hash standard (FIPS 180-1/DFIPS 180-2).

config CRYPTO_SHA256
	tristate "SHA224 and SHA256 digest algorithm"
	select CRYPTO_ALGAPI
	select CRYPTO_HASH
	help
	  SHA256 secure hash standard (DFIPS 180-2).

@@ -370,7 +369,7 @@ config CRYPTO_SHA256

config CRYPTO_SHA512
	tristate "SHA384 and SHA512 digest algorithms"
	select CRYPTO_ALGAPI
	select CRYPTO_HASH
	help
	  SHA512 secure hash standard (DFIPS 180-2).

@@ -382,7 +381,7 @@ config CRYPTO_SHA512

config CRYPTO_TGR192
	tristate "Tiger digest algorithms"
	select CRYPTO_ALGAPI
	select CRYPTO_HASH
	help
	  Tiger hash algorithm 192, 160 and 128-bit hashes

@@ -395,7 +394,7 @@ config CRYPTO_TGR192

config CRYPTO_WP512
	tristate "Whirlpool digest algorithms"
	select CRYPTO_ALGAPI
	select CRYPTO_HASH
	help
	  Whirlpool hash algorithm 512, 384 and 256-bit hashes

+1 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ obj-$(CONFIG_CRYPTO_SEQIV) += seqiv.o

crypto_hash-objs := hash.o
crypto_hash-objs += ahash.o
crypto_hash-objs += shash.o
obj-$(CONFIG_CRYPTO_HASH2) += crypto_hash.o

cryptomgr-objs := algboss.o testmgr.o
+1055 −90

File changed.

Preview size limit exceeded, changes collapsed.

+37 −1
Original line number Diff line number Diff line
@@ -112,6 +112,22 @@ int crypto_hash_walk_first(struct ahash_request *req,
}
EXPORT_SYMBOL_GPL(crypto_hash_walk_first);

int crypto_hash_walk_first_compat(struct hash_desc *hdesc,
				  struct crypto_hash_walk *walk,
				  struct scatterlist *sg, unsigned int len)
{
	walk->total = len;

	if (!walk->total)
		return 0;

	walk->alignmask = crypto_hash_alignmask(hdesc->tfm);
	walk->sg = sg;
	walk->flags = hdesc->flags;

	return hash_walk_new_entry(walk);
}

static int ahash_setkey_unaligned(struct crypto_ahash *tfm, const u8 *key,
				unsigned int keylen)
{
@@ -146,6 +162,26 @@ static int ahash_setkey(struct crypto_ahash *tfm, const u8 *key,
	return ahash->setkey(tfm, key, keylen);
}

static int ahash_nosetkey(struct crypto_ahash *tfm, const u8 *key,
			  unsigned int keylen)
{
	return -ENOSYS;
}

int crypto_ahash_import(struct ahash_request *req, const u8 *in)
{
	struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
	struct ahash_alg *alg = crypto_ahash_alg(tfm);

	memcpy(ahash_request_ctx(req), in, crypto_ahash_reqsize(tfm));

	if (alg->reinit)
		alg->reinit(req);

	return 0;
}
EXPORT_SYMBOL_GPL(crypto_ahash_import);

static unsigned int crypto_ahash_ctxsize(struct crypto_alg *alg, u32 type,
					u32 mask)
{
@@ -164,7 +200,7 @@ static int crypto_init_ahash_ops(struct crypto_tfm *tfm, u32 type, u32 mask)
	crt->update = alg->update;
	crt->final  = alg->final;
	crt->digest = alg->digest;
	crt->setkey = ahash_setkey;
	crt->setkey = alg->setkey ? ahash_setkey : ahash_nosetkey;
	crt->digestsize = alg->digestsize;

	return 0;
Loading