mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-11-01 02:40:12 +08:00
[components][drivers] 硬件大数适应性调整
This commit is contained in:
1 parent
91c858ead2
commit
ab7c1530ea
4 files changed
+122
-182
No files matched your search
@@ -278,7 +278,7 @@ menu "Using Hardware Crypto drivers"
|
||||
int "IV max size"
|
||||
default "16"
|
||||
|
||||
config HWCRYPTO_KEYBIT_MAX_SIZE
|
||||
config RT_HWCRYPTO_KEYBIT_MAX_SIZE
|
||||
int "Key max bit length"
|
||||
default 256
|
||||
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -22,34 +22,35 @@ struct hwcrypto_bignum;
|
||||
/* bignum obj */
|
||||
struct hw_bignum_mpi
|
||||
{
|
||||
rt_size_t total; /**< Total length of data */
|
||||
rt_ubase_t *p; /**< pointer to data */
|
||||
int sign; /**< integer sign */
|
||||
rt_size_t total; /**< total of limbs */
|
||||
rt_uint8_t *p; /**< pointer to limbs */
|
||||
};
|
||||
|
||||
struct hwcrypto_bignum_ops
|
||||
{
|
||||
rt_err_t (*add)(struct hwcrypto_bignum *bignum_ctx,
|
||||
struct hw_bignum_mpi *a,
|
||||
const struct hw_bignum_mpi *b,
|
||||
const struct hw_bignum_mpi *c); /**< a = b + c */
|
||||
struct hw_bignum_mpi *x,
|
||||
const struct hw_bignum_mpi *a,
|
||||
const struct hw_bignum_mpi *b); /**< x = a + b */
|
||||
rt_err_t (*sub)(struct hwcrypto_bignum *bignum_ctx,
|
||||
struct hw_bignum_mpi *a,
|
||||
const struct hw_bignum_mpi *b,
|
||||
const struct hw_bignum_mpi *c); /**< a = b - c */
|
||||
struct hw_bignum_mpi *x,
|
||||
const struct hw_bignum_mpi *a,
|
||||
const struct hw_bignum_mpi *b); /**< x = a - b */
|
||||
rt_err_t (*mul)(struct hwcrypto_bignum *bignum_ctx,
|
||||
struct hw_bignum_mpi *a,
|
||||
const struct hw_bignum_mpi *b,
|
||||
const struct hw_bignum_mpi *c); /**< a = b * c */
|
||||
struct hw_bignum_mpi *x,
|
||||
const struct hw_bignum_mpi *a,
|
||||
const struct hw_bignum_mpi *b); /**< x = a * b */
|
||||
rt_err_t (*mulmod)(struct hwcrypto_bignum *bignum_ctx,
|
||||
struct hw_bignum_mpi *a,
|
||||
struct hw_bignum_mpi *x,
|
||||
const struct hw_bignum_mpi *a,
|
||||
const struct hw_bignum_mpi *b,
|
||||
const struct hw_bignum_mpi *c,
|
||||
const struct hw_bignum_mpi *d); /**< a = b * c (mod d) */
|
||||
const struct hw_bignum_mpi *c); /**< x = a * b (mod c) */
|
||||
rt_err_t (*exptmod)(struct hwcrypto_bignum *bignum_ctx,
|
||||
struct hw_bignum_mpi *a,
|
||||
struct hw_bignum_mpi *x,
|
||||
const struct hw_bignum_mpi *a,
|
||||
const struct hw_bignum_mpi *b,
|
||||
const struct hw_bignum_mpi *c,
|
||||
const struct hw_bignum_mpi *d); /**< a = b ^ c (mod d) */
|
||||
const struct hw_bignum_mpi *c); /**< x = a ^ b (mod c) */
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -69,11 +70,9 @@ struct hwcrypto_bignum
|
||||
rt_err_t rt_hwcrypto_bignum_default(struct rt_hwcrypto_device *device);
|
||||
|
||||
/**
|
||||
* @brief Allocate memory for bignum
|
||||
*
|
||||
* @return Pointer to allocated bignum obj
|
||||
* @brief Init bignum obj
|
||||
*/
|
||||
struct hw_bignum_mpi *rt_hwcrypto_bignum_alloc(void);
|
||||
void rt_hwcrypto_bignum_init(struct hw_bignum_mpi *n);
|
||||
|
||||
/**
|
||||
* @brief free a bignum obj
|
||||
@@ -92,18 +91,18 @@ void rt_hwcrypto_bignum_free(struct hw_bignum_mpi *n);
|
||||
int rt_hwcrypto_bignum_get_len(const struct hw_bignum_mpi *n);
|
||||
|
||||
/**
|
||||
* @brief Get length of bignum as an unsigned binary buffer
|
||||
* @brief Export n into unsigned binary data, big endian
|
||||
*
|
||||
* @param n bignum obj
|
||||
* @param buf Buffer for the binary number
|
||||
* @param len Length of the buffer
|
||||
*
|
||||
* @return binary buffer Length
|
||||
* @return export bin length
|
||||
*/
|
||||
int rt_hwcrypto_bignum_get_bin(struct hw_bignum_mpi *n, rt_uint8_t *buf, int len);
|
||||
int rt_hwcrypto_bignum_export_bin(struct hw_bignum_mpi *n, rt_uint8_t *buf, int len);
|
||||
|
||||
/**
|
||||
* @brief Set binary buffer to unsigned bignum
|
||||
* @brief Import n from unsigned binary data, big endian
|
||||
*
|
||||
* @param n bignum obj
|
||||
* @param buf Buffer for the binary number
|
||||
@@ -111,31 +110,10 @@ int rt_hwcrypto_bignum_get_bin(struct hw_bignum_mpi *n, rt_uint8_t *buf, int len
|
||||
*
|
||||
* @return RT_EOK on success.
|
||||
*/
|
||||
rt_err_t rt_hwcrypto_bignum_set_bin(struct hw_bignum_mpi *n, rt_uint8_t *buf, int len);
|
||||
rt_err_t rt_hwcrypto_bignum_import_bin(struct hw_bignum_mpi *n, rt_uint8_t *buf, int len);
|
||||
|
||||
/**
|
||||
* @brief Unsigned comparison
|
||||
*
|
||||
* @param a bignum obj
|
||||
* @param b bignum obj
|
||||
*
|
||||
* @return 0 is equal
|
||||
*/
|
||||
int rt_hwcrypto_bignum_cmp(const struct hw_bignum_mpi *a,
|
||||
const struct hw_bignum_mpi *b);
|
||||
|
||||
/**
|
||||
* @brief Compare bignum to standard Unsigned integer
|
||||
*
|
||||
* @param a bignum obj
|
||||
* @param b Unsigned integer
|
||||
*
|
||||
* @return 0 is equal
|
||||
*/
|
||||
int rt_hwcrypto_bignum_cmp_d(const struct hw_bignum_mpi *a, unsigned long b);
|
||||
|
||||
/**
|
||||
* @brief a = b + c
|
||||
* @brief x = a + b
|
||||
*
|
||||
* @param a bignum obj
|
||||
* @param b bignum obj
|
||||
@@ -143,12 +121,12 @@ int rt_hwcrypto_bignum_cmp_d(const struct hw_bignum_mpi *a, unsigned long b);
|
||||
*
|
||||
* @return RT_EOK on success.
|
||||
*/
|
||||
rt_err_t rt_hwcrypto_bignum_add(struct hw_bignum_mpi *a,
|
||||
const struct hw_bignum_mpi *b,
|
||||
const struct hw_bignum_mpi *c);
|
||||
rt_err_t rt_hwcrypto_bignum_add(struct hw_bignum_mpi *x,
|
||||
const struct hw_bignum_mpi *a,
|
||||
const struct hw_bignum_mpi *b);
|
||||
|
||||
/**
|
||||
* @brief a = b - c
|
||||
* @brief x = a - b
|
||||
*
|
||||
* @param a bignum obj
|
||||
* @param b bignum obj
|
||||
@@ -156,12 +134,12 @@ rt_err_t rt_hwcrypto_bignum_add(struct hw_bignum_mpi *a,
|
||||
*
|
||||
* @return RT_EOK on success.
|
||||
*/
|
||||
rt_err_t rt_hwcrypto_bignum_sub(struct hw_bignum_mpi *a,
|
||||
const struct hw_bignum_mpi *b,
|
||||
const struct hw_bignum_mpi *c);
|
||||
rt_err_t rt_hwcrypto_bignum_sub(struct hw_bignum_mpi *x,
|
||||
const struct hw_bignum_mpi *a,
|
||||
const struct hw_bignum_mpi *b);
|
||||
|
||||
/**
|
||||
* @brief a = b * c
|
||||
* @brief x = a * b
|
||||
*
|
||||
* @param a bignum obj
|
||||
* @param b bignum obj
|
||||
@@ -169,12 +147,12 @@ rt_err_t rt_hwcrypto_bignum_sub(struct hw_bignum_mpi *a,
|
||||
*
|
||||
* @return RT_EOK on success.
|
||||
*/
|
||||
rt_err_t rt_hwcrypto_bignum_mul(struct hw_bignum_mpi *a,
|
||||
const struct hw_bignum_mpi *b,
|
||||
const struct hw_bignum_mpi *c);
|
||||
rt_err_t rt_hwcrypto_bignum_mul(struct hw_bignum_mpi *x,
|
||||
const struct hw_bignum_mpi *a,
|
||||
const struct hw_bignum_mpi *b);
|
||||
|
||||
/**
|
||||
* @brief a = b * c (mod d)
|
||||
* @brief x = a * b (mod c)
|
||||
*
|
||||
* @param a bignum obj
|
||||
* @param b bignum obj
|
||||
@@ -182,13 +160,13 @@ rt_err_t rt_hwcrypto_bignum_mul(struct hw_bignum_mpi *a,
|
||||
*
|
||||
* @return RT_EOK on success.
|
||||
*/
|
||||
rt_err_t rt_hwcrypto_bignum_mulmod(struct hw_bignum_mpi *a,
|
||||
rt_err_t rt_hwcrypto_bignum_mulmod(struct hw_bignum_mpi *x,
|
||||
const struct hw_bignum_mpi *a,
|
||||
const struct hw_bignum_mpi *b,
|
||||
const struct hw_bignum_mpi *c,
|
||||
const struct hw_bignum_mpi *d);
|
||||
const struct hw_bignum_mpi *c);
|
||||
|
||||
/**
|
||||
* @brief a = b ^ c (mod d)
|
||||
* @brief x = a ^ b (mod c)
|
||||
*
|
||||
* @param a bignum obj
|
||||
* @param b bignum obj
|
||||
@@ -196,10 +174,10 @@ rt_err_t rt_hwcrypto_bignum_mulmod(struct hw_bignum_mpi *a,
|
||||
*
|
||||
* @return RT_EOK on success.
|
||||
*/
|
||||
rt_err_t bignum_exptmod(struct hw_bignum_mpi *a,
|
||||
const struct hw_bignum_mpi *b,
|
||||
const struct hw_bignum_mpi *c,
|
||||
const struct hw_bignum_mpi *d);
|
||||
rt_err_t rt_hwcrypto_bignum_exptmod(struct hw_bignum_mpi *x,
|
||||
const struct hw_bignum_mpi *a,
|
||||
const struct hw_bignum_mpi *b,
|
||||
const struct hw_bignum_mpi *c);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -101,7 +101,7 @@ void rt_hwcrypto_hash_reset(struct rt_hwcrypto_ctx *ctx);
|
||||
*
|
||||
* @return RT_EOK on success.
|
||||
*/
|
||||
rt_err_t rt_hwcrypto_hash_type(struct rt_hwcrypto_ctx *ctx, hwcrypto_type type);
|
||||
rt_err_t rt_hwcrypto_hash_set_type(struct rt_hwcrypto_ctx *ctx, hwcrypto_type type);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user