summaryrefslogtreecommitdiff
path: root/components
diff options
context:
space:
mode:
authorTangyuxin <[email protected]>2022-05-28 10:02:19 +0800
committerGitHub <[email protected]>2022-05-28 10:02:19 +0800
commitccfd2c3b285feb108469a6947859c3729f265ea1 (patch)
tree0d70b9db8183cd2cb1c855bd076d2ffdd42a52c2 /components
parent9d5302d7fbcd506c380ab78ac86af34d8080e7bf (diff)
[drivers][hwcrypto] Correct function return value definition (#5984)
Diffstat (limited to 'components')
-rw-r--r--components/drivers/hwcrypto/hw_bignum.c9
-rw-r--r--components/drivers/hwcrypto/hw_bignum.h6
2 files changed, 9 insertions, 6 deletions
diff --git a/components/drivers/hwcrypto/hw_bignum.c b/components/drivers/hwcrypto/hw_bignum.c
index 0488a16f08..bc729ebf36 100644
--- a/components/drivers/hwcrypto/hw_bignum.c
+++ b/components/drivers/hwcrypto/hw_bignum.c
@@ -78,6 +78,7 @@ void rt_hwcrypto_bignum_free(struct hw_bignum_mpi *n)
{
if (n)
{
+ rt_memset(n->p, 0xFF, n->total);
rt_free(n->p);
n->sign = 0;
n->total = 0;
@@ -144,9 +145,9 @@ int rt_hwcrypto_bignum_export_bin(struct hw_bignum_mpi *n, rt_uint8_t *buf, int
* @param buf Buffer for the binary number
* @param len Length of the buffer
*
- * @return RT_EOK on success.
+ * @return import length.
*/
-rt_err_t rt_hwcrypto_bignum_import_bin(struct hw_bignum_mpi *n, rt_uint8_t *buf, int len)
+int rt_hwcrypto_bignum_import_bin(struct hw_bignum_mpi *n, rt_uint8_t *buf, int len)
{
int cp_len, i, j;
void *temp_p;
@@ -162,11 +163,13 @@ rt_err_t rt_hwcrypto_bignum_import_bin(struct hw_bignum_mpi *n, rt_uint8_t *buf,
{
return 0;
}
- rt_memset(temp_p, 0, len);
rt_free(n->p);
n->p = temp_p;
n->total = len;
}
+
+ n->sign = 1;
+ rt_memset(n->p, 0, n->total);
cp_len = n->total > len ? len : n->total;
for(i = cp_len, j = 0; i > 0; i--, j++)
diff --git a/components/drivers/hwcrypto/hw_bignum.h b/components/drivers/hwcrypto/hw_bignum.h
index 442b28f558..5d4d15a1e4 100644
--- a/components/drivers/hwcrypto/hw_bignum.h
+++ b/components/drivers/hwcrypto/hw_bignum.h
@@ -22,7 +22,7 @@ struct hwcrypto_bignum;
/* bignum obj */
struct hw_bignum_mpi
{
- int sign; /**< integer sign */
+ int sign; /**< integer sign. -1 or 1 */
rt_size_t total; /**< total of limbs */
rt_uint8_t *p; /**< pointer to limbs */
};
@@ -108,9 +108,9 @@ int rt_hwcrypto_bignum_export_bin(struct hw_bignum_mpi *n, rt_uint8_t *buf, int
* @param buf Buffer for the binary number
* @param len Length of the buffer
*
- * @return RT_EOK on success.
+ * @return import length.
*/
-rt_err_t rt_hwcrypto_bignum_import_bin(struct hw_bignum_mpi *n, rt_uint8_t *buf, int len);
+int rt_hwcrypto_bignum_import_bin(struct hw_bignum_mpi *n, rt_uint8_t *buf, int len);
/**
* @brief x = a + b