forked from torvalds/linux
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6
* 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
Showing
44 changed files
with
3,331 additions
and
1,420 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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> | ||
|
@@ -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); | ||
|
@@ -194,4 +196,3 @@ MODULE_LICENSE("GPL"); | |
|
||
MODULE_ALIAS("crc32c"); | ||
MODULE_ALIAS("crc32c-intel"); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.