提交 4946510b 编写于 作者: A Adrian-Ken Rueegsegger 提交者: Herbert Xu

crypto: wp512 - Switch to shash

This patch changes wp512, wp384 and wp256 to the new shash interface.
Signed-off-by: NAdrian-Ken Rueegsegger <ken@codelabs.ch>
Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
上级 f63fbd3d
...@@ -394,7 +394,7 @@ config CRYPTO_TGR192 ...@@ -394,7 +394,7 @@ config CRYPTO_TGR192
config CRYPTO_WP512 config CRYPTO_WP512
tristate "Whirlpool digest algorithms" tristate "Whirlpool digest algorithms"
select CRYPTO_ALGAPI select CRYPTO_HASH
help help
Whirlpool hash algorithm 512, 384 and 256-bit hashes Whirlpool hash algorithm 512, 384 and 256-bit hashes
......
...@@ -19,11 +19,11 @@ ...@@ -19,11 +19,11 @@
* (at your option) any later version. * (at your option) any later version.
* *
*/ */
#include <crypto/internal/hash.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/mm.h> #include <linux/mm.h>
#include <asm/byteorder.h> #include <asm/byteorder.h>
#include <linux/crypto.h>
#include <linux/types.h> #include <linux/types.h>
#define WP512_DIGEST_SIZE 64 #define WP512_DIGEST_SIZE 64
...@@ -980,8 +980,8 @@ static void wp512_process_buffer(struct wp512_ctx *wctx) { ...@@ -980,8 +980,8 @@ static void wp512_process_buffer(struct wp512_ctx *wctx) {
} }
static void wp512_init(struct crypto_tfm *tfm) { static int wp512_init(struct shash_desc *desc) {
struct wp512_ctx *wctx = crypto_tfm_ctx(tfm); struct wp512_ctx *wctx = shash_desc_ctx(desc);
int i; int i;
memset(wctx->bitLength, 0, 32); memset(wctx->bitLength, 0, 32);
...@@ -990,12 +990,14 @@ static void wp512_init(struct crypto_tfm *tfm) { ...@@ -990,12 +990,14 @@ static void wp512_init(struct crypto_tfm *tfm) {
for (i = 0; i < 8; i++) { for (i = 0; i < 8; i++) {
wctx->hash[i] = 0L; wctx->hash[i] = 0L;
} }
return 0;
} }
static void wp512_update(struct crypto_tfm *tfm, const u8 *source, static int wp512_update(struct shash_desc *desc, const u8 *source,
unsigned int len) unsigned int len)
{ {
struct wp512_ctx *wctx = crypto_tfm_ctx(tfm); struct wp512_ctx *wctx = shash_desc_ctx(desc);
int sourcePos = 0; int sourcePos = 0;
unsigned int bits_len = len * 8; // convert to number of bits unsigned int bits_len = len * 8; // convert to number of bits
int sourceGap = (8 - ((int)bits_len & 7)) & 7; int sourceGap = (8 - ((int)bits_len & 7)) & 7;
...@@ -1051,11 +1053,12 @@ static void wp512_update(struct crypto_tfm *tfm, const u8 *source, ...@@ -1051,11 +1053,12 @@ static void wp512_update(struct crypto_tfm *tfm, const u8 *source,
wctx->bufferBits = bufferBits; wctx->bufferBits = bufferBits;
wctx->bufferPos = bufferPos; wctx->bufferPos = bufferPos;
return 0;
} }
static void wp512_final(struct crypto_tfm *tfm, u8 *out) static int wp512_final(struct shash_desc *desc, u8 *out)
{ {
struct wp512_ctx *wctx = crypto_tfm_ctx(tfm); struct wp512_ctx *wctx = shash_desc_ctx(desc);
int i; int i;
u8 *buffer = wctx->buffer; u8 *buffer = wctx->buffer;
u8 *bitLength = wctx->bitLength; u8 *bitLength = wctx->bitLength;
...@@ -1084,89 +1087,95 @@ static void wp512_final(struct crypto_tfm *tfm, u8 *out) ...@@ -1084,89 +1087,95 @@ static void wp512_final(struct crypto_tfm *tfm, u8 *out)
digest[i] = cpu_to_be64(wctx->hash[i]); digest[i] = cpu_to_be64(wctx->hash[i]);
wctx->bufferBits = bufferBits; wctx->bufferBits = bufferBits;
wctx->bufferPos = bufferPos; wctx->bufferPos = bufferPos;
return 0;
} }
static void wp384_final(struct crypto_tfm *tfm, u8 *out) static int wp384_final(struct shash_desc *desc, u8 *out)
{ {
u8 D[64]; u8 D[64];
wp512_final(tfm, D); wp512_final(desc, D);
memcpy (out, D, WP384_DIGEST_SIZE); memcpy (out, D, WP384_DIGEST_SIZE);
memset (D, 0, WP512_DIGEST_SIZE); memset (D, 0, WP512_DIGEST_SIZE);
return 0;
} }
static void wp256_final(struct crypto_tfm *tfm, u8 *out) static int wp256_final(struct shash_desc *desc, u8 *out)
{ {
u8 D[64]; u8 D[64];
wp512_final(tfm, D); wp512_final(desc, D);
memcpy (out, D, WP256_DIGEST_SIZE); memcpy (out, D, WP256_DIGEST_SIZE);
memset (D, 0, WP512_DIGEST_SIZE); memset (D, 0, WP512_DIGEST_SIZE);
return 0;
} }
static struct crypto_alg wp512 = { static struct shash_alg wp512 = {
.cra_name = "wp512", .digestsize = WP512_DIGEST_SIZE,
.cra_flags = CRYPTO_ALG_TYPE_DIGEST, .init = wp512_init,
.cra_blocksize = WP512_BLOCK_SIZE, .update = wp512_update,
.cra_ctxsize = sizeof(struct wp512_ctx), .final = wp512_final,
.cra_module = THIS_MODULE, .descsize = sizeof(struct wp512_ctx),
.cra_list = LIST_HEAD_INIT(wp512.cra_list), .base = {
.cra_u = { .digest = { .cra_name = "wp512",
.dia_digestsize = WP512_DIGEST_SIZE, .cra_flags = CRYPTO_ALG_TYPE_SHASH,
.dia_init = wp512_init, .cra_blocksize = WP512_BLOCK_SIZE,
.dia_update = wp512_update, .cra_module = THIS_MODULE,
.dia_final = wp512_final } } }
}; };
static struct crypto_alg wp384 = { static struct shash_alg wp384 = {
.cra_name = "wp384", .digestsize = WP384_DIGEST_SIZE,
.cra_flags = CRYPTO_ALG_TYPE_DIGEST, .init = wp512_init,
.cra_blocksize = WP512_BLOCK_SIZE, .update = wp512_update,
.cra_ctxsize = sizeof(struct wp512_ctx), .final = wp384_final,
.cra_module = THIS_MODULE, .descsize = sizeof(struct wp512_ctx),
.cra_list = LIST_HEAD_INIT(wp384.cra_list), .base = {
.cra_u = { .digest = { .cra_name = "wp384",
.dia_digestsize = WP384_DIGEST_SIZE, .cra_flags = CRYPTO_ALG_TYPE_SHASH,
.dia_init = wp512_init, .cra_blocksize = WP512_BLOCK_SIZE,
.dia_update = wp512_update, .cra_module = THIS_MODULE,
.dia_final = wp384_final } } }
}; };
static struct crypto_alg wp256 = { static struct shash_alg wp256 = {
.cra_name = "wp256", .digestsize = WP256_DIGEST_SIZE,
.cra_flags = CRYPTO_ALG_TYPE_DIGEST, .init = wp512_init,
.cra_blocksize = WP512_BLOCK_SIZE, .update = wp512_update,
.cra_ctxsize = sizeof(struct wp512_ctx), .final = wp256_final,
.cra_module = THIS_MODULE, .descsize = sizeof(struct wp512_ctx),
.cra_list = LIST_HEAD_INIT(wp256.cra_list), .base = {
.cra_u = { .digest = { .cra_name = "wp256",
.dia_digestsize = WP256_DIGEST_SIZE, .cra_flags = CRYPTO_ALG_TYPE_SHASH,
.dia_init = wp512_init, .cra_blocksize = WP512_BLOCK_SIZE,
.dia_update = wp512_update, .cra_module = THIS_MODULE,
.dia_final = wp256_final } } }
}; };
static int __init wp512_mod_init(void) static int __init wp512_mod_init(void)
{ {
int ret = 0; int ret = 0;
ret = crypto_register_alg(&wp512); ret = crypto_register_shash(&wp512);
if (ret < 0) if (ret < 0)
goto out; goto out;
ret = crypto_register_alg(&wp384); ret = crypto_register_shash(&wp384);
if (ret < 0) if (ret < 0)
{ {
crypto_unregister_alg(&wp512); crypto_unregister_shash(&wp512);
goto out; goto out;
} }
ret = crypto_register_alg(&wp256); ret = crypto_register_shash(&wp256);
if (ret < 0) if (ret < 0)
{ {
crypto_unregister_alg(&wp512); crypto_unregister_shash(&wp512);
crypto_unregister_alg(&wp384); crypto_unregister_shash(&wp384);
} }
out: out:
return ret; return ret;
...@@ -1174,9 +1183,9 @@ static int __init wp512_mod_init(void) ...@@ -1174,9 +1183,9 @@ static int __init wp512_mod_init(void)
static void __exit wp512_mod_fini(void) static void __exit wp512_mod_fini(void)
{ {
crypto_unregister_alg(&wp512); crypto_unregister_shash(&wp512);
crypto_unregister_alg(&wp384); crypto_unregister_shash(&wp384);
crypto_unregister_alg(&wp256); crypto_unregister_shash(&wp256);
} }
MODULE_ALIAS("wp384"); MODULE_ALIAS("wp384");
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册