]> git.baikalelectronics.ru Git - arm-tf.git/commitdiff
refactor(auth)!: unify REGISTER_CRYPTO_LIB
authorYann Gautier <yann.gautier@st.com>
Wed, 15 Mar 2023 10:31:25 +0000 (11:31 +0100)
committerManish V Badarkhe <Manish.Badarkhe@arm.com>
Fri, 21 Apr 2023 08:46:01 +0000 (09:46 +0100)
Have only one definition for REGISTER_CRYPTO_LIB macro, with all the
possible fields. Worst case adds 4 u64 to crypto_lib_desc.
While at it, correct some MISRA violations:
MC3R1.R12.1: (advisory) The precedence of operators within expressions
should be made explicit.

Signed-off-by: Yann Gautier <yann.gautier@st.com>
Change-Id: I1342a20e6eef2354753182c2a81ff959e03e5c81

drivers/auth/cryptocell/712/cryptocell_crypto.c
drivers/auth/cryptocell/713/cryptocell_crypto.c
drivers/auth/mbedtls/mbedtls_crypto.c
drivers/nxp/crypto/caam/src/auth/nxp_crypto.c
include/drivers/auth/crypto_mod.h
plat/st/common/stm32mp_crypto_lib.c

index b6a3f7bdad1b1ec0810af9ba1f5930f0077d638b..bba13f8bb39f1ae136245732c78d3b5f997525d7 100644 (file)
@@ -330,5 +330,5 @@ static int verify_hash(void *data_ptr, unsigned int data_len,
 /*
  * Register crypto library descriptor
  */
-REGISTER_CRYPTO_LIB(LIB_NAME, init, verify_signature, verify_hash, NULL, NULL);
+REGISTER_CRYPTO_LIB(LIB_NAME, init, verify_signature, verify_hash, NULL, NULL, NULL);
 
index 506cf1cf595e665717983a5c73ef011b26e9d789..6601b3a882cd5f4b075d69dba53ced9d15905b5d 100644 (file)
@@ -302,4 +302,4 @@ static int verify_hash(void *data_ptr, unsigned int data_len,
 /*
  * Register crypto library descriptor
  */
-REGISTER_CRYPTO_LIB(LIB_NAME, init, verify_signature, verify_hash, NULL, NULL);
+REGISTER_CRYPTO_LIB(LIB_NAME, init, verify_signature, verify_hash, NULL, NULL, NULL);
index df4763d9b7361ca718b09d94c17509446211a51f..6d6364f326ee75a2e649ea49ce523f3c4c949ef8 100644 (file)
@@ -403,11 +403,12 @@ REGISTER_CRYPTO_LIB(LIB_NAME, init, verify_signature, verify_hash, calc_hash,
 #endif
 #elif CRYPTO_SUPPORT == CRYPTO_AUTH_VERIFY_ONLY
 #if TF_MBEDTLS_USE_AES_GCM
-REGISTER_CRYPTO_LIB(LIB_NAME, init, verify_signature, verify_hash,
+REGISTER_CRYPTO_LIB(LIB_NAME, init, verify_signature, verify_hash, NULL,
                    auth_decrypt, NULL);
 #else
-REGISTER_CRYPTO_LIB(LIB_NAME, init, verify_signature, verify_hash, NULL, NULL);
+REGISTER_CRYPTO_LIB(LIB_NAME, init, verify_signature, verify_hash, NULL,
+                   NULL, NULL);
 #endif
 #elif CRYPTO_SUPPORT == CRYPTO_HASH_CALC_ONLY
-REGISTER_CRYPTO_LIB(LIB_NAME, init, calc_hash);
+REGISTER_CRYPTO_LIB(LIB_NAME, init, NULL, NULL, calc_hash, NULL, NULL);
 #endif /* CRYPTO_SUPPORT == CRYPTO_AUTH_VERIFY_AND_HASH_CALC */
index a7fb898b0f29000f2fead6fa4e426141d6cdef0d..408d974aab1388507e26235381dcac45edba7cb8 100644 (file)
@@ -120,4 +120,4 @@ static int verify_hash(void *data_ptr, unsigned int data_len,
 /*
  * Register crypto library descriptor
  */
-REGISTER_CRYPTO_LIB(LIB_NAME, init, verify_signature, verify_hash, NULL, NULL);
+REGISTER_CRYPTO_LIB(LIB_NAME, init, verify_signature, verify_hash, NULL, NULL, NULL);
index 498fdcb7948351891df6854f600c99045aba082a..00ea8c6208d71141f9c173c35e9c5f18f7b20ccc 100644 (file)
@@ -52,8 +52,6 @@ typedef struct crypto_lib_desc_s {
 
        /* Verify a digital signature. Return one of the
         * 'enum crypto_ret_value' options */
-#if CRYPTO_SUPPORT == CRYPTO_AUTH_VERIFY_ONLY || \
-CRYPTO_SUPPORT == CRYPTO_AUTH_VERIFY_AND_HASH_CALC
        int (*verify_signature)(void *data_ptr, unsigned int data_len,
                                void *sig_ptr, unsigned int sig_len,
                                void *sig_alg, unsigned int sig_alg_len,
@@ -62,17 +60,11 @@ CRYPTO_SUPPORT == CRYPTO_AUTH_VERIFY_AND_HASH_CALC
        /* Verify a hash. Return one of the 'enum crypto_ret_value' options */
        int (*verify_hash)(void *data_ptr, unsigned int data_len,
                           void *digest_info_ptr, unsigned int digest_info_len);
-#endif /* CRYPTO_SUPPORT == CRYPTO_AUTH_VERIFY_ONLY || \
-         CRYPTO_SUPPORT == CRYPTO_AUTH_VERIFY_AND_HASH_CALC */
 
-#if CRYPTO_SUPPORT == CRYPTO_HASH_CALC_ONLY || \
-CRYPTO_SUPPORT == CRYPTO_AUTH_VERIFY_AND_HASH_CALC
        /* Calculate a hash. Return hash value */
        int (*calc_hash)(enum crypto_md_algo md_alg, void *data_ptr,
                         unsigned int data_len,
                         unsigned char output[CRYPTO_MD_MAX_SIZE]);
-#endif /* CRYPTO_SUPPORT == CRYPTO_HASH_CALC_ONLY || \
-         CRYPTO_SUPPORT == CRYPTO_AUTH_VERIFY_AND_HASH_CALC */
 
        /* Convert Public key (optional) */
        int (*convert_pk)(void *full_pk_ptr, unsigned int full_pk_len,
@@ -98,16 +90,16 @@ static inline void crypto_mod_init(void)
 }
 #endif /* CRYPTO_SUPPORT */
 
-#if CRYPTO_SUPPORT == CRYPTO_AUTH_VERIFY_ONLY || \
-CRYPTO_SUPPORT == CRYPTO_AUTH_VERIFY_AND_HASH_CALC
+#if (CRYPTO_SUPPORT == CRYPTO_AUTH_VERIFY_ONLY) || \
+    (CRYPTO_SUPPORT == CRYPTO_AUTH_VERIFY_AND_HASH_CALC)
 int crypto_mod_verify_signature(void *data_ptr, unsigned int data_len,
                                void *sig_ptr, unsigned int sig_len,
                                void *sig_alg_ptr, unsigned int sig_alg_len,
                                void *pk_ptr, unsigned int pk_len);
 int crypto_mod_verify_hash(void *data_ptr, unsigned int data_len,
                           void *digest_info_ptr, unsigned int digest_info_len);
-#endif /* CRYPTO_SUPPORT == CRYPTO_AUTH_VERIFY_ONLY || \
-         CRYPTO_SUPPORT == CRYPTO_AUTH_VERIFY_AND_HASH_CALC */
+#endif /* (CRYPTO_SUPPORT == CRYPTO_AUTH_VERIFY_ONLY) || \
+         (CRYPTO_SUPPORT == CRYPTO_AUTH_VERIFY_AND_HASH_CALC) */
 
 int crypto_mod_auth_decrypt(enum crypto_dec_algo dec_algo, void *data_ptr,
                            size_t len, const void *key, unsigned int key_len,
@@ -115,18 +107,17 @@ int crypto_mod_auth_decrypt(enum crypto_dec_algo dec_algo, void *data_ptr,
                            unsigned int iv_len, const void *tag,
                            unsigned int tag_len);
 
-#if CRYPTO_SUPPORT == CRYPTO_HASH_CALC_ONLY || \
-CRYPTO_SUPPORT == CRYPTO_AUTH_VERIFY_AND_HASH_CALC
+#if (CRYPTO_SUPPORT == CRYPTO_HASH_CALC_ONLY) || \
+    (CRYPTO_SUPPORT == CRYPTO_AUTH_VERIFY_AND_HASH_CALC)
 int crypto_mod_calc_hash(enum crypto_md_algo alg, void *data_ptr,
                         unsigned int data_len,
                         unsigned char output[CRYPTO_MD_MAX_SIZE]);
-#endif /* CRYPTO_SUPPORT == CRYPTO_HASH_CALC_ONLY || \
-         CRYPTO_SUPPORT == CRYPTO_AUTH_VERIFY_AND_HASH_CALC */
+#endif /* (CRYPTO_SUPPORT == CRYPTO_HASH_CALC_ONLY) || \
+         (CRYPTO_SUPPORT == CRYPTO_AUTH_VERIFY_AND_HASH_CALC) */
 
 int crypto_mod_convert_pk(void *full_pk_ptr, unsigned int full_pk_len,
                          void **hashed_pk_ptr, unsigned int *hashed_pk_len);
 
-#if CRYPTO_SUPPORT == CRYPTO_AUTH_VERIFY_AND_HASH_CALC
 /* Macro to register a cryptographic library */
 #define REGISTER_CRYPTO_LIB(_name, _init, _verify_signature, _verify_hash, \
                            _calc_hash, _auth_decrypt, _convert_pk) \
@@ -139,25 +130,6 @@ int crypto_mod_convert_pk(void *full_pk_ptr, unsigned int full_pk_len,
                .auth_decrypt = _auth_decrypt, \
                .convert_pk = _convert_pk \
        }
-#elif CRYPTO_SUPPORT == CRYPTO_AUTH_VERIFY_ONLY
-#define REGISTER_CRYPTO_LIB(_name, _init, _verify_signature, _verify_hash, \
-                           _auth_decrypt, _convert_pk) \
-       const crypto_lib_desc_t crypto_lib_desc = { \
-               .name = _name, \
-               .init = _init, \
-               .verify_signature = _verify_signature, \
-               .verify_hash = _verify_hash, \
-               .auth_decrypt = _auth_decrypt, \
-               .convert_pk = _convert_pk \
-       }
-#elif CRYPTO_SUPPORT == CRYPTO_HASH_CALC_ONLY
-#define REGISTER_CRYPTO_LIB(_name, _init, _calc_hash) \
-       const crypto_lib_desc_t crypto_lib_desc = { \
-               .name = _name, \
-               .init = _init, \
-               .calc_hash = _calc_hash, \
-       }
-#endif /* CRYPTO_SUPPORT == CRYPTO_AUTH_VERIFY_AND_HASH_CALC */
 
 extern const crypto_lib_desc_t crypto_lib_desc;
 
index 373a0081500884732d25e501fe51c5503287179c..ea2b8dbf86da0accb3909c1df4fdcffc54f32833 100644 (file)
@@ -650,6 +650,7 @@ REGISTER_CRYPTO_LIB("stm32_crypto_lib",
                    crypto_lib_init,
                    crypto_verify_signature,
                    crypto_verify_hash,
+                   NULL,
                    crypto_auth_decrypt,
                    crypto_convert_pk);
 
@@ -659,5 +660,6 @@ REGISTER_CRYPTO_LIB("stm32_crypto_lib",
                    crypto_verify_signature,
                    crypto_verify_hash,
                    NULL,
+                   NULL,
                    crypto_convert_pk);
 #endif