crypto: s390 - extend crypto facility check
authorJan Glauber <jang@linux.vnet.ibm.com>
Tue, 19 Apr 2011 19:29:14 +0000 (21:29 +0200)
committerHerbert Xu <herbert@gondor.apana.org.au>
Wed, 4 May 2011 05:05:49 +0000 (15:05 +1000)
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>
arch/s390/crypto/aes_s390.c
arch/s390/crypto/crypt_s390.h
arch/s390/crypto/des_s390.c
arch/s390/crypto/prng.c
arch/s390/crypto/sha1_s390.c
arch/s390/crypto/sha256_s390.c
arch/s390/crypto/sha512_s390.c

index 58f46734465ffad0f7dcb8412799b747c923ffd2..fc97b949254f2fa51439772c3d10bcb43173ae23 100644 (file)
@@ -508,11 +508,11 @@ static int __init aes_s390_init(void)
 {
        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;
-       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;
-       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;
 
        if (!keylen_flag)
index 7ee9a1b4ad9f380a719efc27c5540c4c9b19f63e..4b8c96cab252d9c80083d396855abfc089f8961d 100644 (file)
 #define CRYPT_S390_PRIORITY 300
 #define CRYPT_S390_COMPOSITE_PRIORITY 400
 
+#define CRYPT_S390_MSA 0x1
+#define CRYPT_S390_MSA3        0x2
+#define CRYPT_S390_MSA4        0x4
+
 /* s390 cryptographic operations */
 enum crypt_s390_operations {
        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
  */
-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];
        int ret;
 
-       /* check if CPACF facility (bit 17) is available */
-       if (!test_facility(17))
+       if (facility_mask & CRYPT_S390_MSA && !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;
 
        switch (func & CRYPT_S390_OP_MASK) {
index cc5420118393472db02d967efd08602a99af7e73..1121e73115affadc2a500b2666deb9033ecbc8c1 100644 (file)
@@ -381,8 +381,8 @@ static int des_s390_init(void)
 {
        int ret;
 
-       if (!crypt_s390_func_available(KM_DEA_ENCRYPT) ||
-           !crypt_s390_func_available(KM_TDEA_192_ENCRYPT))
+       if (!crypt_s390_func_available(KM_DEA_ENCRYPT, CRYPT_S390_MSA) ||
+           !crypt_s390_func_available(KM_TDEA_192_ENCRYPT, CRYPT_S390_MSA))
                return -EOPNOTSUPP;
 
        ret = crypto_register_alg(&des_alg);
index 975e3ab13cb5477b29ac4ffd504d34e6cacd4325..0fc8115b0aeac36fe170d4b91ce4083126613b8a 100644 (file)
@@ -166,7 +166,7 @@ static int __init prng_init(void)
        int ret;
 
        /* 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;
 
        if (prng_chunk_size < 8)
index f6de7826c9790a26fa96f6a4b6d6294924fdb696..e9868c6e0a08c0868a65d64a3999e2a48d5ee31b 100644 (file)
@@ -90,7 +90,7 @@ static struct shash_alg alg = {
 
 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 crypto_register_shash(&alg);
 }
index 61a7db372121fc382727a568800934155ddd7eb6..5ed8d64fc2ed73525f8f3d002255a9c12d1dc7b8 100644 (file)
@@ -86,7 +86,7 @@ static struct shash_alg alg = {
 
 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 crypto_register_shash(&alg);
index 4bf73d0dc525c2cd210e08d0fa0d1a5db383f18c..32a81383b69c1b5036c12494802654ad453cbb19 100644 (file)
@@ -132,7 +132,7 @@ static int __init init(void)
 {
        int ret;
 
-       if (!crypt_s390_func_available(KIMD_SHA_512))
+       if (!crypt_s390_func_available(KIMD_SHA_512, CRYPT_S390_MSA))
                return -EOPNOTSUPP;
        if ((ret = crypto_register_shash(&sha512_alg)) < 0)
                goto out;