crypto: s390 - extend crypto facility check

The specification which crypto facility is required for an algorithm is added
as a parameter to the availability check which is done before an algorithm is
registered. With this change it is easier to add new algorithms that require
different facilities.

Signed-off-by: Jan Glauber <jang@linux.vnet.ibm.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
This commit is contained in:
Jan Glauber 2011-04-19 21:29:14 +02:00 committed by Herbert Xu
parent ba0e14acc4
commit 1822bc9093
7 changed files with 20 additions and 12 deletions

View File

@ -508,11 +508,11 @@ static int __init aes_s390_init(void)
{ {
int ret; int ret;
if (crypt_s390_func_available(KM_AES_128_ENCRYPT)) if (crypt_s390_func_available(KM_AES_128_ENCRYPT, CRYPT_S390_MSA))
keylen_flag |= AES_KEYLEN_128; keylen_flag |= AES_KEYLEN_128;
if (crypt_s390_func_available(KM_AES_192_ENCRYPT)) if (crypt_s390_func_available(KM_AES_192_ENCRYPT, CRYPT_S390_MSA))
keylen_flag |= AES_KEYLEN_192; keylen_flag |= AES_KEYLEN_192;
if (crypt_s390_func_available(KM_AES_256_ENCRYPT)) if (crypt_s390_func_available(KM_AES_256_ENCRYPT, CRYPT_S390_MSA))
keylen_flag |= AES_KEYLEN_256; keylen_flag |= AES_KEYLEN_256;
if (!keylen_flag) if (!keylen_flag)

View File

@ -24,6 +24,10 @@
#define CRYPT_S390_PRIORITY 300 #define CRYPT_S390_PRIORITY 300
#define CRYPT_S390_COMPOSITE_PRIORITY 400 #define CRYPT_S390_COMPOSITE_PRIORITY 400
#define CRYPT_S390_MSA 0x1
#define CRYPT_S390_MSA3 0x2
#define CRYPT_S390_MSA4 0x4
/* s390 cryptographic operations */ /* s390 cryptographic operations */
enum crypt_s390_operations { enum crypt_s390_operations {
CRYPT_S390_KM = 0x0100, CRYPT_S390_KM = 0x0100,
@ -291,13 +295,17 @@ static inline int crypt_s390_kmac(long func, void *param,
* *
* Returns 1 if func available; 0 if func or op in general not available * Returns 1 if func available; 0 if func or op in general not available
*/ */
static inline int crypt_s390_func_available(int func) static inline int crypt_s390_func_available(int func,
unsigned int facility_mask)
{ {
unsigned char status[16]; unsigned char status[16];
int ret; int ret;
/* check if CPACF facility (bit 17) is available */ if (facility_mask & CRYPT_S390_MSA && !test_facility(17))
if (!test_facility(17)) return 0;
if (facility_mask & CRYPT_S390_MSA3 && !test_facility(76))
return 0;
if (facility_mask & CRYPT_S390_MSA4 && !test_facility(77))
return 0; return 0;
switch (func & CRYPT_S390_OP_MASK) { switch (func & CRYPT_S390_OP_MASK) {

View File

@ -381,8 +381,8 @@ static int des_s390_init(void)
{ {
int ret; int ret;
if (!crypt_s390_func_available(KM_DEA_ENCRYPT) || if (!crypt_s390_func_available(KM_DEA_ENCRYPT, CRYPT_S390_MSA) ||
!crypt_s390_func_available(KM_TDEA_192_ENCRYPT)) !crypt_s390_func_available(KM_TDEA_192_ENCRYPT, CRYPT_S390_MSA))
return -EOPNOTSUPP; return -EOPNOTSUPP;
ret = crypto_register_alg(&des_alg); ret = crypto_register_alg(&des_alg);

View File

@ -166,7 +166,7 @@ static int __init prng_init(void)
int ret; int ret;
/* check if the CPU has a PRNG */ /* check if the CPU has a PRNG */
if (!crypt_s390_func_available(KMC_PRNG)) if (!crypt_s390_func_available(KMC_PRNG, CRYPT_S390_MSA))
return -EOPNOTSUPP; return -EOPNOTSUPP;
if (prng_chunk_size < 8) if (prng_chunk_size < 8)

View File

@ -90,7 +90,7 @@ static struct shash_alg alg = {
static int __init sha1_s390_init(void) static int __init sha1_s390_init(void)
{ {
if (!crypt_s390_func_available(KIMD_SHA_1)) if (!crypt_s390_func_available(KIMD_SHA_1, CRYPT_S390_MSA))
return -EOPNOTSUPP; return -EOPNOTSUPP;
return crypto_register_shash(&alg); return crypto_register_shash(&alg);
} }

View File

@ -86,7 +86,7 @@ static struct shash_alg alg = {
static int sha256_s390_init(void) static int sha256_s390_init(void)
{ {
if (!crypt_s390_func_available(KIMD_SHA_256)) if (!crypt_s390_func_available(KIMD_SHA_256, CRYPT_S390_MSA))
return -EOPNOTSUPP; return -EOPNOTSUPP;
return crypto_register_shash(&alg); return crypto_register_shash(&alg);

View File

@ -132,7 +132,7 @@ static int __init init(void)
{ {
int ret; int ret;
if (!crypt_s390_func_available(KIMD_SHA_512)) if (!crypt_s390_func_available(KIMD_SHA_512, CRYPT_S390_MSA))
return -EOPNOTSUPP; return -EOPNOTSUPP;
if ((ret = crypto_register_shash(&sha512_alg)) < 0) if ((ret = crypto_register_shash(&sha512_alg)) < 0)
goto out; goto out;