Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[CRYPTO] sha384: Hardware acceleration for s390

Exploit the System z10 hardware acceleration for SHA384.

Signed-off-by: Jan Glauber <jang@linux.vnet.ibm.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

authored by

Jan Glauber and committed by
Herbert Xu
4e2c6d7f 291dc7c0

+54 -9
+50 -7
arch/s390/crypto/sha512_s390.c
··· 1 1 /* 2 2 * Cryptographic API. 3 3 * 4 - * s390 implementation of the SHA512 Secure Hash Algorithm. 4 + * s390 implementation of the SHA512 and SHA38 Secure Hash Algorithm. 5 5 * 6 6 * Copyright IBM Corp. 2007 7 7 * Author(s): Jan Glauber (jang@de.ibm.com) ··· 35 35 ctx->func = KIMD_SHA_512; 36 36 } 37 37 38 - static struct crypto_alg alg = { 38 + static struct crypto_alg sha512_alg = { 39 39 .cra_name = "sha512", 40 40 .cra_driver_name = "sha512-s390", 41 41 .cra_priority = CRYPT_S390_PRIORITY, ··· 43 43 .cra_blocksize = SHA512_BLOCK_SIZE, 44 44 .cra_ctxsize = sizeof(struct s390_sha_ctx), 45 45 .cra_module = THIS_MODULE, 46 - .cra_list = LIST_HEAD_INIT(alg.cra_list), 46 + .cra_list = LIST_HEAD_INIT(sha512_alg.cra_list), 47 47 .cra_u = { .digest = { 48 48 .dia_digestsize = SHA512_DIGEST_SIZE, 49 49 .dia_init = sha512_init, ··· 51 51 .dia_final = s390_sha_final } } 52 52 }; 53 53 54 + MODULE_ALIAS("sha512"); 55 + 56 + static void sha384_init(struct crypto_tfm *tfm) 57 + { 58 + struct s390_sha_ctx *ctx = crypto_tfm_ctx(tfm); 59 + 60 + *(__u64 *)&ctx->state[0] = 0xcbbb9d5dc1059ed8ULL; 61 + *(__u64 *)&ctx->state[2] = 0x629a292a367cd507ULL; 62 + *(__u64 *)&ctx->state[4] = 0x9159015a3070dd17ULL; 63 + *(__u64 *)&ctx->state[6] = 0x152fecd8f70e5939ULL; 64 + *(__u64 *)&ctx->state[8] = 0x67332667ffc00b31ULL; 65 + *(__u64 *)&ctx->state[10] = 0x8eb44a8768581511ULL; 66 + *(__u64 *)&ctx->state[12] = 0xdb0c2e0d64f98fa7ULL; 67 + *(__u64 *)&ctx->state[14] = 0x47b5481dbefa4fa4ULL; 68 + ctx->count = 0; 69 + ctx->func = KIMD_SHA_512; 70 + } 71 + 72 + static struct crypto_alg sha384_alg = { 73 + .cra_name = "sha384", 74 + .cra_driver_name = "sha384-s390", 75 + .cra_priority = CRYPT_S390_PRIORITY, 76 + .cra_flags = CRYPTO_ALG_TYPE_DIGEST, 77 + .cra_blocksize = SHA384_BLOCK_SIZE, 78 + .cra_ctxsize = sizeof(struct s390_sha_ctx), 79 + .cra_module = THIS_MODULE, 80 + .cra_list = LIST_HEAD_INIT(sha384_alg.cra_list), 81 + .cra_u = { .digest = { 82 + .dia_digestsize = SHA384_DIGEST_SIZE, 83 + .dia_init = sha384_init, 84 + .dia_update = s390_sha_update, 85 + .dia_final = s390_sha_final } } 86 + }; 87 + 88 + MODULE_ALIAS("sha384"); 89 + 54 90 static int __init init(void) 55 91 { 92 + int ret; 93 + 56 94 if (!crypt_s390_func_available(KIMD_SHA_512)) 57 95 return -EOPNOTSUPP; 58 - return crypto_register_alg(&alg); 96 + if ((ret = crypto_register_alg(&sha512_alg)) < 0) 97 + goto out; 98 + if ((ret = crypto_register_alg(&sha384_alg)) < 0) 99 + crypto_unregister_alg(&sha512_alg); 100 + out: 101 + return ret; 59 102 } 60 103 61 104 static void __exit fini(void) 62 105 { 63 - crypto_unregister_alg(&alg); 106 + crypto_unregister_alg(&sha512_alg); 107 + crypto_unregister_alg(&sha384_alg); 64 108 } 65 109 66 110 module_init(init); 67 111 module_exit(fini); 68 112 69 - MODULE_ALIAS("sha512"); 70 113 MODULE_LICENSE("GPL"); 71 - MODULE_DESCRIPTION("SHA512 Secure Hash Algorithm"); 114 + MODULE_DESCRIPTION("SHA512 and SHA-384 Secure Hash Algorithm");
+4 -2
drivers/crypto/Kconfig
··· 102 102 security against collision attacks. 103 103 104 104 config CRYPTO_SHA512_S390 105 - tristate "SHA512 digest algorithm" 105 + tristate "SHA384 and SHA512 digest algorithm" 106 106 depends on S390 107 107 select CRYPTO_ALGAPI 108 108 help ··· 110 110 SHA512 secure hash standard. 111 111 112 112 This version of SHA implements a 512 bit hash with 256 bits of 113 - security against collision attacks. 113 + security against collision attacks. The code also includes SHA-384, 114 + a 384 bit hash with 192 bits of security against collision attacks. 115 + 114 116 115 117 config CRYPTO_DES_S390 116 118 tristate "DES and Triple DES cipher algorithms"