crypto: sha512_ssse3 - add sha384 support
Subsystems (2)
PATCH 1/2 crypto: sha512_ssse3 - add sha384 support
Add sha384 implementation to sha512_ssse3 module.
This also fixes sha512_ssse3 module autoloading issue when 'sha384' is used before 'sha512'. Previously in such case, just sha512_generic was loaded and not sha512_ssse3 (since it did not provide sha384). Now if 'sha512' was used after 'sha384' usage, sha512_ssse3 would remain unloaded. For example, this happens with tcrypt testing module since it tests 'sha384' before 'sha512'.
--- arch/x86/crypto/sha512_ssse3_glue.c | 58 ++++++++++++++++++++++++++++++++--- 1 file changed, 53 insertions(+), 5 deletions(-)
arch/x86/crypto/sha512_ssse3_glue.c +53 -5
@@ -194,7 +194,37 @@ static int sha512_ssse3_import(struct shash_desc *desc, const void *in)return 0 ; } -static struct shash_alg alg = { +static int sha384_ssse3_init (struct shash_desc *desc) +{ +struct sha512_state *sctx =shash_desc_ctx (desc); + + sctx->state[0 ] =SHA384_H0 ; + sctx->state[1 ] =SHA384_H1 ; + sctx->state[2 ] =SHA384_H2 ; + sctx->state[3 ] =SHA384_H3 ; + sctx->state[4 ] =SHA384_H4 ; + sctx->state[5 ] =SHA384_H5 ; + sctx->state[6 ] =SHA384_H6 ; + sctx->state[7 ] =SHA384_H7 ; + + sctx->count[0 ] = sctx->count[1 ] =0 ; + +return 0 ; +} + +static int sha384_ssse3_final (struct shash_desc *desc,u8 *hash) +{ +u8 D [SHA512_DIGEST_SIZE ]; + +sha512_ssse3_final (desc,D ); + +memcpy (hash,D ,SHA384_DIGEST_SIZE ); +memset (D ,0 ,SHA512_DIGEST_SIZE ); + +return 0 ; +} + +static struct shash_alg algs[] = { { .digestsize =SHA512_DIGEST_SIZE , .init = sha512_ssse3_init, .update = sha512_ssse3_update,
@@ -211,7 +241,24 @@ static struct shash_alg alg = { .cra_blocksize = SHA512_BLOCK_SIZE, .cra_module = THIS_MODULE, } -}; +}, { + .digestsize = SHA384_DIGEST_SIZE, + .init = sha384_ssse3_init, + .update = sha512_ssse3_update, + .final = sha384_ssse3_final, + .export = sha512_ssse3_export, + .import = sha512_ssse3_import, + .descsize = sizeof(struct sha512_state), + .statesize = sizeof(struct sha512_state), + .base = { + .cra_name = "sha384", + .cra_driver_name = "sha384-ssse3", + .cra_priority = 150, + .cra_flags = CRYPTO_ALG_TYPE_SHASH, + .cra_blocksize = SHA384_BLOCK_SIZE, + .cra_module = THIS_MODULE, + } +} };#ifdef CONFIG_AS_AVX static bool __init avx_usable (void )
@@ -234,7 +281,7 @@ static bool __init avx_usable(void)static int __init sha512_ssse3_mod_init (void ) { -/* test for SSE3 first */ +/* test for SSSE3 first */ if (cpu_has_ssse3) sha512_transform_asm = sha512_transform_ssse3;
@@ -261,7 +308,7 @@ static int __init sha512_ssse3_mod_init(void) else#endif pr_info ("Using SSSE3 optimized SHA-512 implementation\n" ); -return crypto_register_shash (&alg); +return crypto_register_shashes (algs,ARRAY_SIZE (algs)); }pr_info ("Neither AVX nor SSSE3 is available/usable.\n" );
@@ -270,7 +317,7 @@ static int __init sha512_ssse3_mod_init(void) static void __exit sha512_ssse3_mod_fini(void) { -crypto_unregister_shash (&alg); +crypto_unregister_shashes (algs,ARRAY_SIZE (algs)); }module_init (sha512_ssse3_mod_init);
@@ -280,3 +327,4 @@ MODULE_LICENSE("GPL");MODULE_DESCRIPTION ("SHA512 Secure Hash Algorithm, Supplemental SSE3 accelerated" );MODULE_ALIAS ("sha512" ); +MODULE_ALIAS ("sha384" );
PATCH 2/2 crypto: sha256_ssse3 - add sha224 support
Add sha224 implementation to sha256_ssse3 module.
This also fixes sha256_ssse3 module autoloading issue when 'sha224' is used before 'sha256'. Previously in such case, just sha256_generic was loaded and not sha256_ssse3 (since it did not provide sha224). Now if 'sha256' was used after 'sha224' usage, sha256_ssse3 would remain unloaded.
--- arch/x86/crypto/sha256_ssse3_glue.c | 57 ++++++++++++++++++++++++++++++++--- 1 file changed, 52 insertions(+), 5 deletions(-)
arch/x86/crypto/sha256_ssse3_glue.c +52 -5
@@ -187,7 +187,36 @@ static int sha256_ssse3_import(struct shash_desc *desc, const void *in)return 0 ; } -static struct shash_alg alg = { +static int sha224_ssse3_init (struct shash_desc *desc) +{ +struct sha256_state *sctx =shash_desc_ctx (desc); + + sctx->state[0 ] =SHA224_H0 ; + sctx->state[1 ] =SHA224_H1 ; + sctx->state[2 ] =SHA224_H2 ; + sctx->state[3 ] =SHA224_H3 ; + sctx->state[4 ] =SHA224_H4 ; + sctx->state[5 ] =SHA224_H5 ; + sctx->state[6 ] =SHA224_H6 ; + sctx->state[7 ] =SHA224_H7 ; + sctx->count =0 ; + +return 0 ; +} + +static int sha224_ssse3_final (struct shash_desc *desc,u8 *hash) +{ +u8 D [SHA256_DIGEST_SIZE ]; + +sha256_ssse3_final (desc,D ); + +memcpy (hash,D ,SHA224_DIGEST_SIZE ); +memset (D ,0 ,SHA256_DIGEST_SIZE ); + +return 0 ; +} + +static struct shash_alg algs[] = { { .digestsize =SHA256_DIGEST_SIZE , .init = sha256_ssse3_init, .update = sha256_ssse3_update,
@@ -204,7 +233,24 @@ static struct shash_alg alg = { .cra_blocksize = SHA256_BLOCK_SIZE, .cra_module = THIS_MODULE, } -}; +}, { + .digestsize = SHA224_DIGEST_SIZE, + .init = sha224_ssse3_init, + .update = sha256_ssse3_update, + .final = sha224_ssse3_final, + .export = sha256_ssse3_export, + .import = sha256_ssse3_import, + .descsize = sizeof(struct sha256_state), + .statesize = sizeof(struct sha256_state), + .base = { + .cra_name = "sha224", + .cra_driver_name = "sha224-ssse3", + .cra_priority = 150, + .cra_flags = CRYPTO_ALG_TYPE_SHASH, + .cra_blocksize = SHA224_BLOCK_SIZE, + .cra_module = THIS_MODULE, + } +} };#ifdef CONFIG_AS_AVX static bool __init avx_usable (void )
@@ -227,7 +273,7 @@ static bool __init avx_usable(void)static int __init sha256_ssse3_mod_init (void ) { -/* test for SSE3 first */ +/* test for SSSE3 first */ if (cpu_has_ssse3) sha256_transform_asm = sha256_transform_ssse3;
@@ -254,7 +300,7 @@ static int __init sha256_ssse3_mod_init(void) else#endif pr_info ("Using SSSE3 optimized SHA-256 implementation\n" ); -return crypto_register_shash (&alg); +return crypto_register_shashes (algs,ARRAY_SIZE (algs)); }pr_info ("Neither AVX nor SSSE3 is available/usable.\n" );
@@ -263,7 +309,7 @@ static int __init sha256_ssse3_mod_init(void) static void __exit sha256_ssse3_mod_fini(void) { -crypto_unregister_shash (&alg); +crypto_unregister_shashes (algs,ARRAY_SIZE (algs)); }module_init (sha256_ssse3_mod_init);
@@ -273,3 +319,4 @@ MODULE_LICENSE("GPL");MODULE_DESCRIPTION ("SHA256 Secure Hash Algorithm, Supplemental SSE3 accelerated" );MODULE_ALIAS ("sha256" ); +MODULE_ALIAS ("sha384" );
Herbert Xu
maintainerQuoted 10 lines · Jussi Kivilinna
Add sha384 implementation to
sha512_ssse3module.This also fixes
sha512_ssse3module autoloading issue when 'sha384' is used before 'sha512'. Previously in such case, justsha512_genericwas loaded and notsha512_ssse3(since it did not provide sha384). Now if 'sha512' was used after 'sha384' usage,sha512_ssse3would remain unloaded. For example, this happens with tcrypt testing module since it tests 'sha384' before 'sha512'.Cc Tim Chen <[email protected]>Signed-off-by Jussi Kivilinna <[email protected]>
Both patches applied. Thanks!
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt