fix(st): allow crypto lib compilation in aarch64

Cast len with size_t, as it is unsigned long on Aarch64, and no more
unsigned int. Changing functions prototypes will not help as
.verify_signature awaits an unsigned int for its last parameter.

Signed-off-by: Yann Gautier <yann.gautier@foss.st.com>
Change-Id: I9332fd46301a9653af917802788fd97fe7c8a162
diff --git a/plat/st/common/stm32mp_crypto_lib.c b/plat/st/common/stm32mp_crypto_lib.c
index ea2b8db..b3b1d3d 100644
--- a/plat/st/common/stm32mp_crypto_lib.c
+++ b/plat/st/common/stm32mp_crypto_lib.c
@@ -80,7 +80,7 @@
 }
 
 static int get_plain_pk_from_asn1(void *pk_ptr, unsigned int pk_len, void **plain_pk,
-			   unsigned int *len, int *pk_alg)
+				  size_t *len, int *pk_alg)
 {
 	int ret;
 	mbedtls_pk_context mbedtls_pk = {0};
@@ -170,7 +170,15 @@
 static int crypto_convert_pk(void *full_pk_ptr, unsigned int full_pk_len,
 			     void **hashed_pk_ptr, unsigned int *hashed_pk_len)
 {
-	return get_plain_pk_from_asn1(full_pk_ptr, full_pk_len, hashed_pk_ptr, hashed_pk_len, NULL);
+	size_t len;
+	int ret;
+
+	ret = get_plain_pk_from_asn1(full_pk_ptr, full_pk_len, hashed_pk_ptr, &len, NULL);
+	if (ret == 0) {
+		*hashed_pk_len = (unsigned int)len;
+	}
+
+	return ret;
 }
 #else /* STM32MP_CRYPTO_ROM_LIB*/
 static uint32_t verify_signature(uint8_t *hash_in, uint8_t *pubkey_in,
@@ -226,7 +234,7 @@
 	static uint8_t st_pk[CRYPTO_PUBKEY_MAX_SIZE + sizeof(uint32_t)];
 	int ret;
 	void *plain_pk;
-	unsigned int len;
+	size_t len;
 	int curve_id;
 	uint32_t cid;
 
@@ -241,7 +249,7 @@
 	memcpy(st_pk + sizeof(cid), plain_pk, len);
 
 	*hashed_pk_ptr = st_pk;
-	*hashed_pk_len = len + sizeof(cid);
+	*hashed_pk_len = (unsigned int)(len + sizeof(cid));
 
 	return 0;
 }
@@ -339,15 +347,15 @@
 		return CRYPTO_ERR_SIGNATURE;
 	}
 
-	ret = get_plain_pk_from_asn1(pk_ptr, pk_len, &pk_ptr, &pk_len, &curve_id);
+	ret = get_plain_pk_from_asn1(pk_ptr, pk_len, &pk_ptr, &len, &curve_id);
 	if (ret != 0) {
 		VERBOSE("%s: get_plain_pk_from_asn1 (%d)\n", __func__, ret);
 		return CRYPTO_ERR_SIGNATURE;
 	}
 
 	/* We expect a known pk_len */
-	if (pk_len != sizeof(my_pk)) {
-		VERBOSE("%s: pk_len=%u sizeof(my_pk)=%zu)\n", __func__, pk_len, sizeof(my_pk));
+	if (len != sizeof(my_pk)) {
+		VERBOSE("%s: pk_len=%zu sizeof(my_pk)=%zu)\n", __func__, len, sizeof(my_pk));
 		return CRYPTO_ERR_SIGNATURE;
 	}
 
@@ -517,7 +525,7 @@
 	}
 
 	if (otp_len > (*key_len * CHAR_BIT)) {
-		VERBOSE("%s: length Error otp_len=%u key_len=%u\n", __func__,
+		VERBOSE("%s: length Error otp_len=%u key_len=%zu\n", __func__,
 			otp_len, *key_len * CHAR_BIT);
 		return -EINVAL;
 	}