Skip to content

Commit

Permalink
Merge git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6
Browse files Browse the repository at this point in the history
* 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
  ...
  • Loading branch information
torvalds committed Dec 28, 2008
2 parents cb10ea5 + 0ee4a96 commit e14e61e
Show file tree
Hide file tree
Showing 44 changed files with 3,331 additions and 1,420 deletions.
121 changes: 61 additions & 60 deletions arch/x86/crypto/crc32c-intel.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>
* Copyright (c) 2008 Kent Liu <[email protected]>
* Copyright (C) 2008 Intel Corporation
* Authors: Austin Zhang <[email protected]>
* Kent Liu <[email protected]>
*
* 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>
Expand Down Expand Up @@ -75,114 +84,107 @@ 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 = {
.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,
}
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_blocksize = CHKSUM_BLOCK_SIZE,
.cra_ctxsize = sizeof(u32),
.cra_module = THIS_MODULE,
.cra_init = crc32c_intel_cra_init,
}
};


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);
Expand All @@ -194,4 +196,3 @@ MODULE_LICENSE("GPL");

MODULE_ALIAS("crc32c");
MODULE_ALIAS("crc32c-intel");

29 changes: 14 additions & 15 deletions crypto/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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"
Expand All @@ -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
Expand All @@ -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).

Expand All @@ -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).

Expand All @@ -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
Expand All @@ -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
Expand All @@ -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).

Expand All @@ -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).

Expand All @@ -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

Expand All @@ -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

Expand Down
1 change: 1 addition & 0 deletions crypto/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit e14e61e

Please sign in to comment.