diff options
author | Jussi Kivilinna <jussi.kivilinna@iki.fi> | 2013-05-21 10:10:49 -0400 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2013-05-28 03:43:05 -0400 |
commit | a710f761fc9ae5728765a5917f8beabb49f98483 (patch) | |
tree | 80d291557c53a8d68aeae3d9a39d8a0f719e683c /arch/x86/crypto | |
parent | 340991e30ccef7b983cf2814ecea610504f5d059 (diff) |
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.
Cc: Tim Chen <tim.c.chen@linux.intel.com>
Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'arch/x86/crypto')
-rw-r--r-- | arch/x86/crypto/sha256_ssse3_glue.c | 57 |
1 files changed, 52 insertions, 5 deletions
diff --git a/arch/x86/crypto/sha256_ssse3_glue.c b/arch/x86/crypto/sha256_ssse3_glue.c index 597d4da69656..50226c4b86ed 100644 --- a/arch/x86/crypto/sha256_ssse3_glue.c +++ b/arch/x86/crypto/sha256_ssse3_glue.c | |||
@@ -187,7 +187,36 @@ static int sha256_ssse3_import(struct shash_desc *desc, const void *in) | |||
187 | return 0; | 187 | return 0; |
188 | } | 188 | } |
189 | 189 | ||
190 | static struct shash_alg alg = { | 190 | static int sha224_ssse3_init(struct shash_desc *desc) |
191 | { | ||
192 | struct sha256_state *sctx = shash_desc_ctx(desc); | ||
193 | |||
194 | sctx->state[0] = SHA224_H0; | ||
195 | sctx->state[1] = SHA224_H1; | ||
196 | sctx->state[2] = SHA224_H2; | ||
197 | sctx->state[3] = SHA224_H3; | ||
198 | sctx->state[4] = SHA224_H4; | ||
199 | sctx->state[5] = SHA224_H5; | ||
200 | sctx->state[6] = SHA224_H6; | ||
201 | sctx->state[7] = SHA224_H7; | ||
202 | sctx->count = 0; | ||
203 | |||
204 | return 0; | ||
205 | } | ||
206 | |||
207 | static int sha224_ssse3_final(struct shash_desc *desc, u8 *hash) | ||
208 | { | ||
209 | u8 D[SHA256_DIGEST_SIZE]; | ||
210 | |||
211 | sha256_ssse3_final(desc, D); | ||
212 | |||
213 | memcpy(hash, D, SHA224_DIGEST_SIZE); | ||
214 | memset(D, 0, SHA256_DIGEST_SIZE); | ||
215 | |||
216 | return 0; | ||
217 | } | ||
218 | |||
219 | static struct shash_alg algs[] = { { | ||
191 | .digestsize = SHA256_DIGEST_SIZE, | 220 | .digestsize = SHA256_DIGEST_SIZE, |
192 | .init = sha256_ssse3_init, | 221 | .init = sha256_ssse3_init, |
193 | .update = sha256_ssse3_update, | 222 | .update = sha256_ssse3_update, |
@@ -204,7 +233,24 @@ static struct shash_alg alg = { | |||
204 | .cra_blocksize = SHA256_BLOCK_SIZE, | 233 | .cra_blocksize = SHA256_BLOCK_SIZE, |
205 | .cra_module = THIS_MODULE, | 234 | .cra_module = THIS_MODULE, |
206 | } | 235 | } |
207 | }; | 236 | }, { |
237 | .digestsize = SHA224_DIGEST_SIZE, | ||
238 | .init = sha224_ssse3_init, | ||
239 | .update = sha256_ssse3_update, | ||
240 | .final = sha224_ssse3_final, | ||
241 | .export = sha256_ssse3_export, | ||
242 | .import = sha256_ssse3_import, | ||
243 | .descsize = sizeof(struct sha256_state), | ||
244 | .statesize = sizeof(struct sha256_state), | ||
245 | .base = { | ||
246 | .cra_name = "sha224", | ||
247 | .cra_driver_name = "sha224-ssse3", | ||
248 | .cra_priority = 150, | ||
249 | .cra_flags = CRYPTO_ALG_TYPE_SHASH, | ||
250 | .cra_blocksize = SHA224_BLOCK_SIZE, | ||
251 | .cra_module = THIS_MODULE, | ||
252 | } | ||
253 | } }; | ||
208 | 254 | ||
209 | #ifdef CONFIG_AS_AVX | 255 | #ifdef CONFIG_AS_AVX |
210 | static bool __init avx_usable(void) | 256 | static bool __init avx_usable(void) |
@@ -227,7 +273,7 @@ static bool __init avx_usable(void) | |||
227 | 273 | ||
228 | static int __init sha256_ssse3_mod_init(void) | 274 | static int __init sha256_ssse3_mod_init(void) |
229 | { | 275 | { |
230 | /* test for SSE3 first */ | 276 | /* test for SSSE3 first */ |
231 | if (cpu_has_ssse3) | 277 | if (cpu_has_ssse3) |
232 | sha256_transform_asm = sha256_transform_ssse3; | 278 | sha256_transform_asm = sha256_transform_ssse3; |
233 | 279 | ||
@@ -254,7 +300,7 @@ static int __init sha256_ssse3_mod_init(void) | |||
254 | else | 300 | else |
255 | #endif | 301 | #endif |
256 | pr_info("Using SSSE3 optimized SHA-256 implementation\n"); | 302 | pr_info("Using SSSE3 optimized SHA-256 implementation\n"); |
257 | return crypto_register_shash(&alg); | 303 | return crypto_register_shashes(algs, ARRAY_SIZE(algs)); |
258 | } | 304 | } |
259 | pr_info("Neither AVX nor SSSE3 is available/usable.\n"); | 305 | pr_info("Neither AVX nor SSSE3 is available/usable.\n"); |
260 | 306 | ||
@@ -263,7 +309,7 @@ static int __init sha256_ssse3_mod_init(void) | |||
263 | 309 | ||
264 | static void __exit sha256_ssse3_mod_fini(void) | 310 | static void __exit sha256_ssse3_mod_fini(void) |
265 | { | 311 | { |
266 | crypto_unregister_shash(&alg); | 312 | crypto_unregister_shashes(algs, ARRAY_SIZE(algs)); |
267 | } | 313 | } |
268 | 314 | ||
269 | module_init(sha256_ssse3_mod_init); | 315 | module_init(sha256_ssse3_mod_init); |
@@ -273,3 +319,4 @@ MODULE_LICENSE("GPL"); | |||
273 | MODULE_DESCRIPTION("SHA256 Secure Hash Algorithm, Supplemental SSE3 accelerated"); | 319 | MODULE_DESCRIPTION("SHA256 Secure Hash Algorithm, Supplemental SSE3 accelerated"); |
274 | 320 | ||
275 | MODULE_ALIAS("sha256"); | 321 | MODULE_ALIAS("sha256"); |
322 | MODULE_ALIAS("sha384"); | ||