staging: lustre: libcfs: add new definitions for cfs_crypto api
authorAndreas Dilger <andreas.dilger@intel.com>
Sat, 26 Mar 2016 19:40:48 +0000 (15:40 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 29 Mar 2016 19:06:51 +0000 (12:06 -0700)
Add CFS_HASH_ALG_UNKOWN for unknown hash names instead of
using "0xFF" directly. Define the max digestsize the cfs
crypto api can handle.

Signed-off-by: Andreas Dilger <andreas.dilger@intel.com>
Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-5053
Reviewed-on: http://review.whamcloud.com/9990
Reviewed-by: Bob Glossman <bob.glossman@intel.com>
Reviewed-by: James Simmons <uja.ornl@gmail.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/lustre/include/linux/libcfs/libcfs_crypto.h
drivers/staging/lustre/lnet/libcfs/linux/linux-crypto.c

index 0782bfb11ffa9dbb347aee30092978adb12d15d1..921aa7cbff976d660ec96992c55562cb8e96ce69 100644 (file)
@@ -46,7 +46,8 @@ enum cfs_crypto_hash_alg {
        CFS_HASH_ALG_SHA384,
        CFS_HASH_ALG_SHA512,
        CFS_HASH_ALG_CRC32C,
-       CFS_HASH_ALG_MAX
+       CFS_HASH_ALG_MAX,
+       CFS_HASH_ALG_UNKNOWN    = 0xff
 };
 
 static struct cfs_crypto_hash_type hash_types[] = {
@@ -59,8 +60,12 @@ static struct cfs_crypto_hash_type hash_types[] = {
        [CFS_HASH_ALG_SHA256]  = { "sha256",   0,     32 },
        [CFS_HASH_ALG_SHA384]  = { "sha384",   0,     48 },
        [CFS_HASH_ALG_SHA512]  = { "sha512",   0,     64 },
+       [CFS_HASH_ALG_MAX]      = { NULL,       0,      64 },
 };
 
+/* Maximum size of hash_types[].cht_size */
+#define CFS_CRYPTO_HASH_DIGESTSIZE_MAX 64
+
 /**
  * Return hash algorithm information for the specified algorithm identifier
  *
@@ -131,7 +136,7 @@ static inline unsigned char cfs_crypto_hash_alg(const char *algname)
        for (i = 0; i < CFS_HASH_ALG_MAX; i++)
                if (!strcmp(hash_types[i].cht_name, algname))
                        break;
-       return (i == CFS_HASH_ALG_MAX ? 0xFF : i);
+       return (i == CFS_HASH_ALG_MAX ? CFS_HASH_ALG_UNKNOWN : i);
 }
 
 int cfs_crypto_hash_digest(unsigned char hash_alg,
index 1a9eb77ec9868fb1f319ccedb40f290c397c5a99..b4e203dacd3892a62ea4c60031ba5c1eaff96fec 100644 (file)
@@ -316,8 +316,8 @@ static void cfs_crypto_performance_test(unsigned char hash_alg,
        unsigned long              start, end;
        int                          bcount, err = 0;
        int                          sec = 1; /* do test only 1 sec */
-       unsigned char              hash[64];
-       unsigned int                hash_len = 64;
+       unsigned char hash[CFS_CRYPTO_HASH_DIGESTSIZE_MAX];
+       unsigned int hash_len = sizeof(hash);
 
        for (start = jiffies, end = start + sec * HZ, bcount = 0;
             time_before(jiffies, end); bcount++) {