risc-v/esp32c3: Support ESP32-C3 RSA accelerator

This commit is contained in:
Liu Han 2021-06-09 20:17:54 +08:00 committed by Alan Carvalho de Assis
parent ba1f730528
commit 8eaaf6d462
8 changed files with 8244 additions and 0 deletions

View File

@ -300,6 +300,18 @@ config ESP32C3_AES_ACCELERATOR
bool "AES Accelerator"
default n
config ESP32C3_BIGNUM_ACCELERATOR
bool "BIGNUM Accelerator"
default n
---help---
Enable ESP32-C3 BIGNUM accelerator support.
config ESP32C3_RSA_ACCELERATOR
bool "RSA Accelerator"
default n
---help---
Enable ESP32-C3 RSA accelerator support.
endmenu # ESP32-C3 Peripheral Support
menu "I2C Configuration"
@ -813,4 +825,22 @@ config ESP32C3_AES_ACCELERATOR_TEST
endmenu # AES accelerator
menu "RSA Accelerate Configuration"
depends on ESP32C3_RSA_ACCELERATOR
config ESP32C3_RSA_ACCELERATOR_TEST
bool "RSA driver test"
default n
menu "BIGNUM"
depends on ESP32C3_BIGNUM_ACCELERATOR
config ESP32C3_BIGNUM_ACCELERATOR_TEST
bool "BIGNUM driver test"
default n
endmenu # ESP32C3_BIGNUM_ACCELERATOR
endmenu # ESP32C3_RSA_ACCELERATOR
endif # ARCH_CHIP_ESP32C3

View File

@ -109,6 +109,14 @@ ifeq ($(CONFIG_ESP32C3_RT_TIMER),y)
CHIP_CSRCS += esp32c3_rt_timer.c
endif
ifeq ($(CONFIG_ESP32C3_BIGNUM_ACCELERATOR),y)
CHIP_CSRCS += esp32c3_bignum.c
endif
ifeq ($(CONFIG_ESP32C3_RSA_ACCELERATOR),y)
CHIP_CSRCS += esp32c3_rsa.c
endif
ifeq ($(CONFIG_ESP32C3_FREERUN),y)
CHIP_CSRCS += esp32c3_freerun.c
endif

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,892 @@
/****************************************************************************
* arch/risc-v/src/esp32c3/esp32c3_bignum.h
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
#ifndef __ARCH_RISCV_SRC_ESP32C3_ESP32C3_BIGNUM_H
#define __ARCH_RISCV_SRC_ESP32C3_ESP32C3_BIGNUM_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <stddef.h>
#include <stdint.h>
#ifndef __ASSEMBLY__
#undef EXTERN
#if defined(__cplusplus)
#define EXTERN extern "C"
extern "C"
{
#else
#define EXTERN extern
#endif
/****************************************************************************
* Pre-processor Macros
****************************************************************************/
#define ESP32C3_ERR_MPI_FILE_IO_ERROR -0x0002 /**< An error occurred while reading from or writing to a file. */
#define ESP32C3_ERR_MPI_BAD_INPUT_DATA -0x0004 /**< Bad input parameters to function. */
#define ESP32C3_ERR_MPI_INVALID_CHARACTER -0x0006 /**< There is an invalid character in the digit string. */
#define ESP32C3_ERR_MPI_BUFFER_TOO_SMALL -0x0008 /**< The buffer is too small to write to. */
#define ESP32C3_ERR_MPI_NEGATIVE_VALUE -0x000A /**< The input arguments are negative or result in illegal output. */
#define ESP32C3_ERR_MPI_DIVISION_BY_ZERO -0x000C /**< The input argument for division is zero, which is not allowed. */
#define ESP32C3_ERR_MPI_NOT_ACCEPTABLE -0x000E /**< The input arguments are not acceptable. */
#define ESP32C3_ERR_MPI_ALLOC_FAILED -0x0010 /**< Memory allocation failed. */
#define ESP32C3_MPI_CHK(f, a) \
do \
{ \
ret = (f); \
if (ret != 0) \
{ \
goto a; \
} \
} \
while(0)
/* Maximum size MPIs are allowed to grow to in number of limbs. */
#define ESP32C3_MPI_MAX_LIMBS 10000
/* Maximum window size used for modular exponentiation */
#define ESP32C3_MPI_WINDOW_SIZE 6
/* Maximum size of MPIs allowed in bits and bytes for user-MPIs. */
#define ESP32C3_MPI_MAX_SIZE 1024
/**< Maximum number of bits for usable MPIs. */
#define ESP32C3_MPI_MAX_BITS (8 * ESP32C3_MPI_MAX_SIZE)
/****************************************************************************
* Public Types
****************************************************************************/
/* MPI structure */
struct esp32c3_mpi_s
{
int s; /* Sign: -1 if the mpi is negative, 1 otherwise */
size_t n; /* total number of limbs */
uint32_t *p; /* pointer to limbs */
};
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
/****************************************************************************
* Name: esp32c3_mpi_init
*
* Description:
* Initialize an MPI context
*
* Input Parameters:
* X - The MPI context to initialize
*
* Returned Value:
* None.
*
****************************************************************************/
void esp32c3_mpi_init(struct esp32c3_mpi_s *X);
/****************************************************************************
* Name: esp32c3_mpi_free
*
* Description:
* Frees the components of an MPI context
*
* Input Parameters:
* X - The MPI context to be cleared
*
* Returned Value:
* None.
*
****************************************************************************/
void esp32c3_mpi_free(struct esp32c3_mpi_s *X);
/****************************************************************************
* Name: esp32c3_mpi_grow
*
* Description:
* Enlarge an MPI to the specified number of limbs
*
* Input Parameters:
* X - The MPI context to grow
* nblimbs - The target number of limbs
*
* Returned Value:
* OK on success; Negated errno on failure.
*
****************************************************************************/
int esp32c3_mpi_grow(struct esp32c3_mpi_s *X, size_t nblimbs);
/****************************************************************************
* Name: esp32c3_mpi_shrink
*
* Description:
* Resizes an MPI downwards, keeping at least the specified number of limbs
*
* Input Parameters:
* X - The MPI context to shrink
* nblimbs - The minimum number of limbs
*
* Returned Value:
* OK on success; Negated errno on failure.
*
****************************************************************************/
int esp32c3_mpi_shrink(struct esp32c3_mpi_s *X, size_t nblimbs);
/****************************************************************************
* Name: esp32c3_mpi_copy
*
* Description:
* Copy the contents of Y into X
*
* Input Parameters:
* X - The destination MPI
* Y - The source MPI
*
* Returned Value:
* OK on success; Negated errno on failure.
*
****************************************************************************/
int esp32c3_mpi_copy(struct esp32c3_mpi_s *X,
const struct esp32c3_mpi_s *Y);
/****************************************************************************
* Name: esp32c3_mpi_swap
*
* Description:
* Swap the contents of X and Y
*
* Input Parameters:
* X - The first MPI
* nblimbs - The second MPI
*
* Returned Value:
* None.
*
****************************************************************************/
void esp32c3_mpi_swap(struct esp32c3_mpi_s *X,
struct esp32c3_mpi_s *Y);
/****************************************************************************
* Name: esp32c3_mpi_safe_cond_assign
*
* Description:
* Perform a safe conditional copy of MPI which doesn't
* reveal whether the condition was true or not.
*
* Input Parameters:
* X - The MPI to conditionally assign to
* Y - The MPI to be assigned from
* assign - The condition deciding whether perform the assignment or not
*
* Returned Value:
* OK on success; Negated errno on failure.
*
****************************************************************************/
int esp32c3_mpi_safe_cond_assign(struct esp32c3_mpi_s *X,
const struct esp32c3_mpi_s *Y,
unsigned char assign);
/****************************************************************************
* Name: esp32c3_mpi_safe_cond_swap
*
* Description:
* Perform a safe conditional swap which doesn't
* reveal whether the condition was true or not.
*
* Input Parameters:
* X - The first MPI
* Y - The second MPI
* swap - The condition deciding whether to perform the swap or not
*
* Returned Value:
* OK on success; Negated errno on failure.
*
****************************************************************************/
int esp32c3_mpi_safe_cond_swap(struct esp32c3_mpi_s *X,
struct esp32c3_mpi_s *Y,
unsigned char assign);
/****************************************************************************
* Name: esp32c3_mpi_lset
*
* Description:
* Set value from integer
*
* Input Parameters:
* X - The MPI to set
* z - The value to use
*
* Returned Value:
* OK on success; Negated errno on failure.
*
****************************************************************************/
int esp32c3_mpi_lset(struct esp32c3_mpi_s *X, int32_t z);
/****************************************************************************
* Name: esp32c3_mpi_get_bit
*
* Description:
* Get a specific bit from an MPI
*
* Input Parameters:
* X - The MPI context to query
* pos - Zero-based index of the bit to query
*
* Returned Value:
* OK on success; Negated errno on failure.
*
****************************************************************************/
int esp32c3_mpi_get_bit(const struct esp32c3_mpi_s *X, size_t pos);
/****************************************************************************
* Name: esp32c3_mpi_set_bit
*
* Description:
* Modify a specific bit in an MPI
*
* Input Parameters:
* X - The MPI context to modify
* pos - Zero-based index of the bit to modify
* val - The desired value of bit
*
* Returned Value:
* OK on success; Negated errno on failure.
*
****************************************************************************/
int esp32c3_mpi_set_bit(struct esp32c3_mpi_s *X,
size_t pos, unsigned char val);
/****************************************************************************
* Name: esp32c3_mpi_lsb
*
* Description:
* Return the number of bits of value
*
* Input Parameters:
* X - The MPI context to query
*
* Returned Value:
* The number of bits of value.
*
****************************************************************************/
size_t esp32c3_mpi_lsb(const struct esp32c3_mpi_s *X);
/****************************************************************************
* Name: esp32c3_mpi_bitlen
*
* Description:
* Return the number of bits up to and including the most
* significant bit of value
*
* Input Parameters:
* X - The MPI context to query
*
* Returned Value:
* The number of bits up and including the most significant bit of value.
*
****************************************************************************/
size_t esp32c3_mpi_bitlen(const struct esp32c3_mpi_s *X);
/****************************************************************************
* Name: esp32c3_mpi_size
*
* Description:
* Return the total size of an MPI value in bytes
*
* Input Parameters:
* X - The MPI context to query
*
* Returned Value:
* The least number of bytes capable of storing the absolute value.
*
****************************************************************************/
size_t esp32c3_mpi_size(const struct esp32c3_mpi_s *X);
/****************************************************************************
* Name: esp32c3_mpi_read_string
*
* Description:
* Import from an ASCII string
*
* Input Parameters:
* X - The destination MPI
* radix - The numeric base of the input string
* s - Null-terminated string buffer
*
* Returned Value:
* OK on success; Negated errno on failure.
*
****************************************************************************/
int esp32c3_mpi_read_string(struct esp32c3_mpi_s *X,
int radix, const char *s);
/****************************************************************************
* Name: esp32c3_mpi_write_string
*
* Description:
* Export an MPI to an ASCII string
*
* Input Parameters:
* X - The source MPI
* radix - The numeric base of the output string
* buf - The buffer to write the string to
* buflen - The available size in Bytes of buf
* olen - The address at which to store the length of the string written
*
* Returned Value:
* OK on success; Negated errno on failure.
*
****************************************************************************/
int esp32c3_mpi_write_string(const struct esp32c3_mpi_s *X, int radix,
char *buf, size_t buflen, size_t *olen);
/****************************************************************************
* Name: esp32c3_mpi_read_binary
*
* Description:
* Import an MPI from unsigned big endian binary data
*
* Input Parameters:
* X - The destination MPI
* buf - The input buffer
* buflen - The length of the input buffer
*
* Returned Value:
* OK on success; Negated errno on failure.
*
****************************************************************************/
int esp32c3_mpi_read_binary(struct esp32c3_mpi_s *X,
const unsigned char *buf, size_t buflen);
/****************************************************************************
* Name: esp32c3_mpi_write_binary
*
* Description:
* Export X into unsigned binary data, big endian
*
* Input Parameters:
* X - The source MPI
* buf - The output buffer
* buflen - The length of the output buffer
*
* Returned Value:
* OK on success; Negated errno on failure.
*
****************************************************************************/
int esp32c3_mpi_write_binary(const struct esp32c3_mpi_s *X,
unsigned char *buf, size_t buflen);
/****************************************************************************
* Name: esp32c3_mpi_shift_l
*
* Description:
* Perform a left-shift on an MPI: X <<= count
*
* Input Parameters:
* X - The MPI to shift
* count - The number of bits to shift by
*
* Returned Value:
* OK on success; Negated errno on failure.
*
****************************************************************************/
int esp32c3_mpi_shift_l(struct esp32c3_mpi_s *X, size_t count);
/****************************************************************************
* Name: esp32c3_mpi_shift_r
*
* Description:
* Perform a right-shift on an MPI: X >>= count
*
* Input Parameters:
* X - The MPI to shift
* count - The number of bits to shift by
*
* Returned Value:
* OK on success; Negated errno on failure.
*
****************************************************************************/
int esp32c3_mpi_shift_r(struct esp32c3_mpi_s *X, size_t count);
/****************************************************************************
* Name: esp32c3_mpi_cmp_abs
*
* Description:
* Compare the absolute values of two MPIs
*
* Input Parameters:
* X - The left-hand MPI
* Y - The right-hand MPI
*
* Returned Value:
* 1 if \p `|X|` is greater than \p `|Y|`.
* -1 if \p `|X|` is lesser than \p `|Y|`.
* 0 if \p `|X|` is equal to \p `|Y|`.
*
****************************************************************************/
int esp32c3_mpi_cmp_abs(const struct esp32c3_mpi_s *X,
const struct esp32c3_mpi_s *Y);
/****************************************************************************
* Name: esp32c3_mpi_cmp_mpi
*
* Description:
* Compare two MPIs.
*
* Input Parameters:
* X - The left-hand MPI
* Y - The right-hand MPI
*
* Returned Value:
* 1 if \p `X` is greater than \p `Y`.
* -1 if \p `X` is lesser than \p `Y`.
* 0 if \p `X` is equal to \p `Y`.
*
****************************************************************************/
int esp32c3_mpi_cmp_mpi(const struct esp32c3_mpi_s *X,
const struct esp32c3_mpi_s *Y);
/****************************************************************************
* Name: esp32c3_mpi_lt_mpi_ct
*
* Description:
* Check if an MPI is less than the other in constant time
*
* Input Parameters:
* X - The left-hand MPI
* Y - The right-hand MPI
* ret - The result of the comparison:
* 1 if \p X is less than \p Y.
* 0 if \p X is greater than or equal to \p Y.
*
* Returned Value:
* OK on success; Negated errno on failure.
*
****************************************************************************/
int esp32c3_mpi_lt_mpi_ct(const struct esp32c3_mpi_s *X,
const struct esp32c3_mpi_s *Y,
unsigned *ret);
/****************************************************************************
* Name: esp32c3_mpi_cmp_int
*
* Description:
* Compare an MPI with an integer
*
* Input Parameters:
* X - The left-hand MPI
* z - The integer value to compare \p X to
*
* Returned Value:
* \c 1 if \p X is greater than \p z.
* \c -1 if \p X is lesser than \p z.
* \c 0 if \p X is equal to \p z.
*
****************************************************************************/
int esp32c3_mpi_cmp_int(const struct esp32c3_mpi_s *X, int32_t z);
/****************************************************************************
* Name: esp32c3_mpi_add_abs
*
* Description:
* Perform an unsigned addition of MPIs: X = |A| + |B|
*
* Input Parameters:
* X - The left-hand MPI
* z - The integer value to compare \p X to.
*
* Returned Value:
* \c 1 if \p X is greater than \p z.
* \c -1 if \p X is lesser than \p z.
* \c 0 if \p X is equal to \p z.
*
****************************************************************************/
int esp32c3_mpi_add_abs(struct esp32c3_mpi_s *X,
const struct esp32c3_mpi_s *A,
const struct esp32c3_mpi_s *B);
/****************************************************************************
* Name: esp32c3_mpi_sub_abs
*
* Description:
* Perform an unsigned subtraction of MPIs: X = |A| - |B|
*
* Input Parameters:
* X - The destination MPI
* A - The minuend
* B - The subtrahend
*
* Returned Value:
* OK on success; Negated errno on failure.
*
****************************************************************************/
int esp32c3_mpi_sub_abs(struct esp32c3_mpi_s *X,
const struct esp32c3_mpi_s *A,
const struct esp32c3_mpi_s *B);
/****************************************************************************
* Name: esp32c3_mpi_add_mpi
*
* Description:
* Perform a signed addition of MPIs: X = A + B
*
* Input Parameters:
* X - The destination MPI
* A - The first summand
* B - The second summand
*
* Returned Value:
* OK on success; Negated errno on failure.
*
****************************************************************************/
int esp32c3_mpi_add_mpi(struct esp32c3_mpi_s *X,
const struct esp32c3_mpi_s *A,
const struct esp32c3_mpi_s *B);
/****************************************************************************
* Name: esp32c3_mpi_sub_mpi
*
* Description:
* Perform a signed subtraction of MPIs: X = A - B
*
* Input Parameters:
* X - The destination MPI
* A - The minuend
* B - The subtrahend
*
* Returned Value:
* OK on success; Negated errno on failure.
*
****************************************************************************/
int esp32c3_mpi_sub_mpi(struct esp32c3_mpi_s *X,
const struct esp32c3_mpi_s *A,
const struct esp32c3_mpi_s *B);
/****************************************************************************
* Name: esp32c3_mpi_add_int
*
* Description:
* Perform a signed addition of an MPI and an integer: X = A + b
*
* Input Parameters:
* X - The destination MPI
* A - The first summand
* b - The second summand
*
* Returned Value:
* OK on success; Negated errno on failure.
*
****************************************************************************/
int esp32c3_mpi_add_int(struct esp32c3_mpi_s *X,
const struct esp32c3_mpi_s *A,
int32_t b);
/****************************************************************************
* Name: esp32c3_mpi_sub_int
*
* Description:
* Perform a signed subtraction of an MPI and an integer: X = A - b
*
* Input Parameters:
* X - The destination MPI
* A - The minuend
* b - The subtrahend
*
* Returned Value:
* OK on success; Negated errno on failure.
*
****************************************************************************/
int esp32c3_mpi_sub_int(struct esp32c3_mpi_s *X,
const struct esp32c3_mpi_s *A,
int32_t b);
/****************************************************************************
* Name: esp32c3_mpi_mul_mpi
*
* Description:
* Perform a multiplication of two MPIs: Z = X * Y
*
* Input Parameters:
* Z - The destination MPI
* X - The first factor
* Y - The second factor
*
* Returned Value:
* OK on success; Negated errno on failure.
*
****************************************************************************/
int esp32c3_mpi_mul_mpi(struct esp32c3_mpi_s *X,
const struct esp32c3_mpi_s *A,
const struct esp32c3_mpi_s *B);
/****************************************************************************
* Name: esp32c3_mpi_mul_int
*
* Description:
* Perform a multiplication of an MPI with an unsigned integer: X = A * b
*
* Input Parameters:
* X - The destination MPI
* A - The first factor
* b - The second factor.
*
* Returned Value:
* OK on success; Negated errno on failure.
*
****************************************************************************/
int esp32c3_mpi_mul_int(struct esp32c3_mpi_s *X,
const struct esp32c3_mpi_s *A,
uint32_t b);
/****************************************************************************
* Name: esp32c3_mpi_div_mpi
*
* Description:
* Perform a division with remainder of two MPIs: A = Q * B + R
*
* Input Parameters:
* Q - The destination MPI for the quotient
* R - The destination MPI for the remainder value
* A - The dividend
* B - The divisor
*
* Returned Value:
* OK on success; Negated errno on failure.
*
****************************************************************************/
int esp32c3_mpi_div_mpi(struct esp32c3_mpi_s *Q,
struct esp32c3_mpi_s *R,
const struct esp32c3_mpi_s *A,
const struct esp32c3_mpi_s *B);
/****************************************************************************
* Name: esp32c3_mpi_div_int
*
* Description:
* Perform a division with remainder of an MPI by an integer: A = Q * b + R
*
* Input Parameters:
* Q - The destination MPI for the quotient
* R - The destination MPI for the remainder value
* A - The dividend
* B - The divisor
*
* Returned Value:
* OK on success; Negated errno on failure.
*
****************************************************************************/
int esp32c3_mpi_div_int(struct esp32c3_mpi_s *Q,
struct esp32c3_mpi_s *R,
const struct esp32c3_mpi_s *A,
int32_t b);
/****************************************************************************
* Name: esp32c3_mpi_mod_mpi
*
* Description:
* erform a modular reduction. R = A mod B
*
* Input Parameters:
* R - The destination MPI for the residue value
* A - The MPI to compute the residue of
* B - The base of the modular reduction
*
* Returned Value:
* OK on success; Negated errno on failure.
*
****************************************************************************/
int esp32c3_mpi_mod_mpi(struct esp32c3_mpi_s *R,
const struct esp32c3_mpi_s *A,
const struct esp32c3_mpi_s *B);
/****************************************************************************
* Name: esp32c3_mpi_mod_int
*
* Description:
* Perform a modular reduction with respect to an integer: r = A mod b
*
* Input Parameters:
* r - The address at which to store the residue
* A - The MPI to compute the residue of
* b - The integer base of the modular reduction
*
* Returned Value:
* OK on success; Negated errno on failure.
*
****************************************************************************/
int esp32c3_mpi_mod_int(uint32_t *r,
const struct esp32c3_mpi_s *A,
int32_t b);
/****************************************************************************
* Name: esp32c3_mpi_exp_mod
*
* Description:
* Perform a sliding-window exponentiation: X = A^E mod N
*
* Input Parameters:
* X - The destination MPI
* A - The base of the exponentiation
* E - The exponent MPI
* N - The base for the modular reduction
* _RR - A helper MPI depending solely on \p N which can be used to
* speed-up multiple modular exponentiations for the same value
* of \p N.
*
* Returned Value:
* OK on success; Negated errno on failure.
*
****************************************************************************/
int esp32c3_mpi_exp_mod(struct esp32c3_mpi_s *X,
const struct esp32c3_mpi_s *A,
const struct esp32c3_mpi_s *E,
const struct esp32c3_mpi_s *N,
struct esp32c3_mpi_s *_RR);
/****************************************************************************
* Name: esp32c3_mpi_gcd
*
* Description:
* Compute the greatest common divisor: G = gcd(A, B)
*
* Input Parameters:
* G - The destination MPI
* A - The first operand
* B - The second operand
*
* Returned Value:
* OK on success; Negated errno on failure.
*
****************************************************************************/
int esp32c3_mpi_gcd(struct esp32c3_mpi_s *G,
const struct esp32c3_mpi_s *A,
const struct esp32c3_mpi_s *B);
/****************************************************************************
* Name: esp32c3_mpi_fill_random
*
* Description:
* Fill an MPI with a number of random bytes
*
* Input Parameters:
* X - The destination MPI
* size - The number of random bytes to generate
* f_rng - The RNG function to use. This must not be \c NULL
* p_rng - The RNG parameter to be passed to \p f_rng
*
* Returned Value:
* OK on success; Negated errno on failure.
*
****************************************************************************/
int esp32c3_mpi_fill_random(struct esp32c3_mpi_s *X, size_t size,
int (*f_rng)(void *, unsigned char *, size_t),
void *p_rng);
/****************************************************************************
* Name: esp32c3_mpi_inv_mod
*
* Description:
* Compute the modular inverse: X = A^-1 mod N
*
* Input Parameters:
* X - The destination MPI
* A - The MPI to calculate the modular inverse of
* N - The base of the modular inversion
*
* Returned Value:
* OK on success; Negated errno on failure.
*
****************************************************************************/
int esp32c3_mpi_inv_mod(struct esp32c3_mpi_s *X,
const struct esp32c3_mpi_s *A,
const struct esp32c3_mpi_s *N);
#ifdef CONFIG_ESP32C3_BIGNUM_ACCELERATOR_TEST
/****************************************************************************
* Name: esp32c3_mpi_self_test
*
* Description:
* Checkup routine
*
* Input Parameters:
* verbose - The result output or not
*
* Returned Value:
* OK on success; Negated errno on failure.
*
****************************************************************************/
int esp32c3_mpi_self_test(int verbose);
#endif
#ifdef __cplusplus
}
#endif
#undef EXTERN
#endif /* __ASSEMBLY__ */
#endif /* __ARCH_RISCV_SRC_ESP32C3_ESP32C3_BIGNUM_H */

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,513 @@
/****************************************************************************
* arch/risc-v/src/esp32c3/esp32c3_rsa.h
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#ifndef __ARCH_RISCV_SRC_ESP32C3_ESP32C3_RSA_H
#define __ARCH_RISCV_SRC_ESP32C3_ESP32C3_RSA_H
#include <nuttx/config.h>
#include <stdint.h>
#include "esp32c3_bignum.h"
#ifndef __ASSEMBLY__
#undef EXTERN
#if defined(__cplusplus)
#define EXTERN extern "C"
extern "C"
{
#else
#define EXTERN extern
#endif
/****************************************************************************
* Pre-processor Macros
****************************************************************************/
/* RSA Error codes */
#define ESP32C3_ERR_RSA_BAD_INPUT_DATA -0x4080 /**< Bad input parameters to function. */
#define ESP32C3_ERR_RSA_INVALID_PADDING -0x4100 /**< Input data contains invalid padding and is rejected. */
#define ESP32C3_ERR_RSA_KEY_GEN_FAILED -0x4180 /**< Something failed during generation of a key. */
#define ESP32C3_ERR_RSA_KEY_CHECK_FAILED -0x4200 /**< Key failed to pass the validity check of the library. */
#define ESP32C3_ERR_RSA_PUBLIC_FAILED -0x4280 /**< The public key operation failed. */
#define ESP32C3_ERR_RSA_PRIVATE_FAILED -0x4300 /**< The private key operation failed. */
#define ESP32C3_ERR_RSA_VERIFY_FAILED -0x4380 /**< The PKCS#1 verification failed. */
#define ESP32C3_ERR_RSA_OUTPUT_TOO_LARGE -0x4400 /**< The output buffer for decryption is not large enough. */
#define ESP32C3_ERR_RSA_RNG_FAILED -0x4480 /**< The random generator failed to generate non-zeros. */
/* RSA constants */
#define ESP32C3_RSA_PUBLIC 0 /**< Request private key operation. */
#define ESP32C3_RSA_PRIVATE 1 /**< Request public key operation. */
#define ESP32C3_RSA_PKCS_V15 0 /**< Use PKCS#1 v1.5 encoding. */
#define ESP32C3_RSA_PKCS_V21 1 /**< Use PKCS#1 v2.1 encoding. */
#define ESP32C3_RSA_SIGN 1 /**< Identifier for RSA signature operations. */
#define ESP32C3_RSA_CRYPT 2 /**< Identifier for RSA encryption and decryption operations. */
#define ESP32C3_RSA_SALT_LEN_ANY -1
/****************************************************************************
* Public Types
****************************************************************************/
/**
* \brief - The RSA context structure.
*/
struct esp32c3_rsa_context_s
{
int ver; /* Always 0 */
size_t len; /* The size of \p N in Bytes */
struct esp32c3_mpi_s N; /* The public modulus */
struct esp32c3_mpi_s E; /* The public exponent */
struct esp32c3_mpi_s D; /* The private exponent */
struct esp32c3_mpi_s P; /* The first prime factor */
struct esp32c3_mpi_s Q; /* The second prime factor */
struct esp32c3_mpi_s DP; /* <code>D % (P - 1)</code> */
struct esp32c3_mpi_s DQ; /* <code>D % (Q - 1)</code> */
struct esp32c3_mpi_s QP; /* <code>1 / (Q % P)</code> */
struct esp32c3_mpi_s RN; /* cached <code>R^2 mod N</code> */
struct esp32c3_mpi_s RP; /* cached <code>R^2 mod P</code> */
struct esp32c3_mpi_s RQ; /* cached <code>R^2 mod Q</code> */
struct esp32c3_mpi_s VI; /* The cached blinding value */
struct esp32c3_mpi_s VF; /* The cached un-blinding value */
int padding; /* Selects padding mode */
int hash_id; /* Hash identifier */
};
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
/****************************************************************************
* Name: esp32c3_rsa_init
*
* Description:
* Initializes an RSA context
*
* Input Parameters:
* ctx - The RSA context to initialize
* padding - The padding mode to use
* hash_id - The hash identifier of
*
* Returned Value:
* None.
*
****************************************************************************/
void esp32c3_rsa_init(struct esp32c3_rsa_context_s *ctx,
int padding,
int hash_id);
/****************************************************************************
* Name: esp32c3_rsa_import
*
* Description:
* Imports a set of core parameters into an RSA context.
*
* Input Parameters:
* ctx - The initialized RSA context to store the parameters in
* N - The RSA modulus
* P - The first prime factor of \p N
* Q - The second prime factor of \p N
* D - The private exponent
* E - The public exponent
*
* Returned Value:
* OK on success; Negated errno on failure.
*
****************************************************************************/
int esp32c3_rsa_import(struct esp32c3_rsa_context_s *ctx,
const struct esp32c3_mpi_s *N,
const struct esp32c3_mpi_s *P,
const struct esp32c3_mpi_s *Q,
const struct esp32c3_mpi_s *D,
const struct esp32c3_mpi_s *E);
/****************************************************************************
* Name: esp32c3_rsa_import_raw
*
* Description:
* Imports core RSA parameters into an RSA context.
*
* Input Parameters:
* ctx - The initialized RSA context to store the parameters in
* N - The RSA modulus
* NL - The Byte length of \p N
* P - The first prime factor of \p N
* PL - The Byte length of \p P
* Q - The second prime factor of \p N
* QL - The Byte length of \p Q
* D - The private exponent
* DL - The Byte length of \p D
* E - The public exponent
* EL - The Byte length of \p E
*
* Returned Value:
* OK on success; Negated errno on failure.
*
****************************************************************************/
int esp32c3_rsa_import_raw(struct esp32c3_rsa_context_s *ctx,
unsigned char const *N, size_t NL,
unsigned char const *P, size_t PL,
unsigned char const *Q, size_t QL,
unsigned char const *D, size_t DL,
unsigned char const *E, size_t EL);
/****************************************************************************
* Name: esp32c3_rsa_complete
*
* Description:
* Completes an RSA context from a set of imported core parameters.
*
* Input Parameters:
* ctx - The initialized RSA context holding imported parameters
*
* Returned Value:
* OK on success; Negated errno on failure.
*
****************************************************************************/
int esp32c3_rsa_complete(struct esp32c3_rsa_context_s *ctx);
/****************************************************************************
* Name: esp32c3_rsa_export
*
* Description:
* Exports the core parameters of an RSA key.
*
* Input Parameters:
* ctx - The initialized RSA context
* N - The MPI to hold the RSA modulus
* P - The MPI to hold the first prime factor of \p N
* Q - The MPI to hold the second prime factor of \p N
* D - The MPI to hold the private exponent
* E - The MPI to hold the public exponent
*
* Returned Value:
* OK on success; Negated errno on failure.
*
****************************************************************************/
int esp32c3_rsa_export(const struct esp32c3_rsa_context_s *ctx,
struct esp32c3_mpi_s *N,
struct esp32c3_mpi_s *P,
struct esp32c3_mpi_s *Q,
struct esp32c3_mpi_s *D,
struct esp32c3_mpi_s *E);
/****************************************************************************
* Name: esp32c3_rsa_export_raw
*
* Description:
* Eexports core parameters of an RSA key in raw big-endian binary format.
*
* Input Parameters:
* ctx - The initialized RSA context
* N - The Byte array to store the RSA modulus
* NL - The size of the buffer for the modulus
* P - The Byte array to hold the first prime factor of \p N
* PL - The size of the buffer for the first prime factor
* Q - The Byte array to hold the second prime factor of \p N
* QL - The size of the buffer for the second prime factor
* D - The Byte array to hold the private exponent
* DL - The size of the buffer for the private exponent
* E - The Byte array to hold the public exponent
* EL - The size of the buffer for the public exponent
*
* Returned Value:
* OK on success; Negated errno on failure.
*
****************************************************************************/
int esp32c3_rsa_export_raw(const struct esp32c3_rsa_context_s *ctx,
unsigned char *N, size_t NL,
unsigned char *P, size_t PL,
unsigned char *Q, size_t QL,
unsigned char *D, size_t DL,
unsigned char *E, size_t EL);
/****************************************************************************
* Name: esp32c3_rsa_export_crt
*
* Description:
* Exports CRT parameters of a private RSA key.
*
* Input Parameters:
* ctx - The initialized RSA context
* DP - The MPI to hold \c D modulo `P-1`
* DQ - The MPI to hold \c D modulo `Q-1`
* QP - The MPI to hold modular inverse of \c Q modulo \c P
*
* Returned Value:
* OK on success; Negated errno on failure.
*
****************************************************************************/
int esp32c3_rsa_export_crt(const struct esp32c3_rsa_context_s *ctx,
struct esp32c3_mpi_s *DP,
struct esp32c3_mpi_s *DQ,
struct esp32c3_mpi_s *QP);
/****************************************************************************
* Name: esp32c3_rsa_set_padding
*
* Description:
* Sets padding for an already initialized RSA context.
*
* Input Parameters:
* ctx - The initialized RSA context to be configured
* padding - The padding mode to use
* hash_id - The hash identifier
*
* Returned Value:
* None.
*
****************************************************************************/
void esp32c3_rsa_set_padding(struct esp32c3_rsa_context_s *ctx,
int padding, int hash_id);
/****************************************************************************
* Name: esp32c3_rsa_get_len
*
* Description:
* Exports CRT parameters of a private RSA key.
*
* Input Parameters:
* ctx - The initialized RSA context
*
* Returned Value:
* length of the RSA modulus in Bytes.
*
****************************************************************************/
size_t esp32c3_rsa_get_len(const struct esp32c3_rsa_context_s *ctx);
/****************************************************************************
* Name: esp32c3_rsa_check_pubkey
*
* Description:
* checks if a context contains at least an RSA public key..
*
* Input Parameters:
* ctx - The initialized RSA context to check
*
* Returned Value:
* OK on success; Negated errno on failure.
*
****************************************************************************/
int esp32c3_rsa_check_pubkey(const struct esp32c3_rsa_context_s *ctx);
/****************************************************************************
* Name: esp32c3_rsa_check_privkey
*
* Description:
* Checks if a context contains at least an RSA private key
* and perform basic consistency checks.
*
* Input Parameters:
* ctx - The initialized RSA context to check
*
* Returned Value:
* OK on success; Negated errno on failure.
*
****************************************************************************/
int esp32c3_rsa_check_privkey(const struct esp32c3_rsa_context_s *ctx);
/****************************************************************************
* Name: esp32c3_rsa_check_pub_priv
*
* Description:
* Checks a public-private RSA key pair. It checks each of the contexts,
* and makes sure they match.
*
* Input Parameters:
* pub - The initialized RSA context holding the public key
* prv - The initialized RSA context holding the private key
*
* Returned Value:
* OK on success; Negated errno on failure.
*
****************************************************************************/
int esp32c3_rsa_check_pub_priv(const struct esp32c3_rsa_context_s *pub,
const struct esp32c3_rsa_context_s *prv);
/****************************************************************************
* Name: esp32c3_rsa_public
*
* Description:
* Performs an RSA public key operation.
*
* Input Parameters:
* ctx - The initialized RSA context to use
* input - The input buffer
* output - The output buffer
*
* Returned Value:
* OK on success; Negated errno on failure.
*
****************************************************************************/
int esp32c3_rsa_public(struct esp32c3_rsa_context_s *ctx,
const unsigned char *input,
unsigned char *output);
/****************************************************************************
* Name: esp32c3_rsa_private
*
* Description:
* Performs an RSA private key operation.
*
* Input Parameters:
* ctx - The initialized RSA context to use
* f_rng - The RNG function
* p_rng - The RNG context to pass to \p f_rng
* input - The input buffer
* output - The output buffer
*
* Returned Value:
* OK on success; Negated errno on failure.
*
****************************************************************************/
int esp32c3_rsa_private(struct esp32c3_rsa_context_s *ctx,
int (*f_rng)(void *, unsigned char *, size_t),
void *p_rng,
const unsigned char *input,
unsigned char *output);
/****************************************************************************
* Name: esp32c3_rsa_encrypt
*
* Description:
* Adds the message padding, then performs an RSA operation. It is the
* generic wrapper for performing a PKCS#1 encryption operation using the
* \p mode from the context.
*
* Input Parameters:
* ctx - The initialized RSA context to use
* f_rng - The RNG to use
* p_rng - The RNG context to be passed to \p f_rng
* mode - The mode of operation
* ilen - The length of the plaintext in Bytes
* input - The input data to encrypt
* output - The output buffer
*
* Returned Value:
* OK on success; Negated errno on failure.
*
****************************************************************************/
int esp32c3_rsa_encrypt(struct esp32c3_rsa_context_s *ctx,
int (*f_rng)(void *, unsigned char *, size_t),
void *p_rng,
int mode, size_t ilen,
const unsigned char *input,
unsigned char *output);
/****************************************************************************
* Name: esp32c3_rsa_decrypt
*
* Description:
* Performs an RSA operation, then removes the message padding.
*
* Input Parameters:
* ctx - The initialized RSA context to use
* f_rng - The RNG function
* p_rng - The RNG context to be passed to \p f_rng
* mode - The mode of operation
* olen - The point which to store the length of the plaintext
* input - The ciphertext buffer
* output - The buffer used to hold the plaintext
* output_max_len - The length in Bytes of the output buffer \p output
*
* Returned Value:
* OK on success; Negated errno on failure.
*
****************************************************************************/
int esp32c3_rsa_decrypt(struct esp32c3_rsa_context_s *ctx,
int (*f_rng)(void *, unsigned char *, size_t),
void *p_rng,
int mode, size_t *olen,
const unsigned char *input,
unsigned char *output,
size_t output_max_len);
/****************************************************************************
* Name: esp32c3_rsa_copy
*
* Description:
* Copies the components of an RSA context.
*
* Input Parameters:
* dst - The destination context
* src - The source context
*
* Returned Value:
* OK on success; Negated errno on failure.
*
****************************************************************************/
int esp32c3_rsa_copy(struct esp32c3_rsa_context_s *dst,
const struct esp32c3_rsa_context_s *src);
/****************************************************************************
* Name: esp32c3_rsa_free
*
* Description:
* Frees the components of an RSA key.
*
* Input Parameters:
* ctx - The RSA context to free
*
* Returned Value:
* None.
*
****************************************************************************/
void esp32c3_rsa_free(struct esp32c3_rsa_context_s *ctx);
#ifdef __cplusplus
}
#endif
#undef EXTERN
#endif /* __ASSEMBLY__ */
#endif /* __ARCH_RISCV_SRC_ESP32C3_ESP32C3_RSA_H */

View File

@ -0,0 +1,308 @@
/****************************************************************************
* arch/risc-v/src/esp32c3/hardware/esp32c3_rsa.h
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
#ifndef __ARCH_RISCV_SRC_ESP32C3_HARDWARE_ESP32C3_RSA_H
#define __ARCH_RISCV_SRC_ESP32C3_HARDWARE_ESP32C3_RSA_H
/****************************************************************************
* Included Files
****************************************************************************/
#include "esp32c3_soc.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* RSA_MEM_M_BLOCK_REG register
* Memory M
*/
#define RSA_MEM_M_BLOCK_REG (DR_REG_RSA_BASE + 0x0)
/* RSA_M_MEMORY : R/W; bitpos: [16:0]; default: 384;
* Memory M
*/
#define RSA_M_MEMORY 0x0001FFFF
#define RSA_M_MEMORY_M (RSA_M_MEMORY_V << RSA_M_MEMORY_S)
#define RSA_M_MEMORY_V 0x0001FFFF
#define RSA_M_MEMORY_S 0
/* RSA_MEM_RB_BLOCK_REG register
* Memory RB
*/
#define RSA_MEM_RB_BLOCK_REG (DR_REG_RSA_BASE + 0x200)
/* RSA_RB_MEMORY : R/W; bitpos: [16:0]; default: 384;
* Memory RB
*/
#define RSA_RB_MEMORY 0x0001FFFF
#define RSA_RB_MEMORY_M (RSA_RB_MEMORY_V << RSA_RB_MEMORY_S)
#define RSA_RB_MEMORY_V 0x0001FFFF
#define RSA_RB_MEMORY_S 0
/* RSA_MEM_Z_BLOCK_REG register
* Memory Z
*/
#define RSA_MEM_Z_BLOCK_REG (DR_REG_RSA_BASE + 0x200)
/* RSA_Z_MEMORY : R/W; bitpos: [16:0]; default: 384;
* Memory Z
*/
#define RSA_Z_MEMORY 0x0001FFFF
#define RSA_Z_MEMORY_M (RSA_Z_MEMORY_V << RSA_Z_MEMORY_S)
#define RSA_Z_MEMORY_V 0x0001FFFF
#define RSA_Z_MEMORY_S 0
/* RSA_MEM_Y_BLOCK_REG register
* Memory Y
*/
#define RSA_MEM_Y_BLOCK_REG (DR_REG_RSA_BASE + 0x400)
/* RSA_Y_MEMORY : R/W; bitpos: [16:0]; default: 384;
* Memory Y
*/
#define RSA_Y_MEMORY 0x0001FFFF
#define RSA_Y_MEMORY_M (RSA_Y_MEMORY_V << RSA_Y_MEMORY_S)
#define RSA_Y_MEMORY_V 0x0001FFFF
#define RSA_Y_MEMORY_S 0
/* RSA_MEM_X_BLOCK_REG register
* Memory X
*/
#define RSA_MEM_X_BLOCK_REG (DR_REG_RSA_BASE + 0x600)
/* RSA_X_MEMORY : R/W; bitpos: [16:0]; default: 384;
* Memory X
*/
#define RSA_X_MEMORY 0x0001FFFF
#define RSA_X_MEMORY_M (RSA_X_MEMORY_V << RSA_X_MEMORY_S)
#define RSA_X_MEMORY_V 0x0001FFFF
#define RSA_X_MEMORY_S 0
/* RSA_M_PRIME_REG register
* Register to store M'
*/
#define RSA_M_PRIME_REG (DR_REG_RSA_BASE + 0x800)
/* RSA_M_PRIME : R/W; bitpos: [31:0]; default: 0;
* Stores M'
*/
#define RSA_M_PRIME 0xFFFFFFFF
#define RSA_M_PRIME_M (RSA_M_PRIME_V << RSA_M_PRIME_S)
#define RSA_M_PRIME_V 0xFFFFFFFF
#define RSA_M_PRIME_S 0
/* RSA_MODE_REG register
* RSA length mode
*/
#define RSA_MODE_REG (DR_REG_RSA_BASE + 0x804)
/* RSA_MODE : R/W; bitpos: [6:0]; default: 0;
* Stores the mode of modular exponentiation.
*/
#define RSA_MODE 0x0000007F
#define RSA_MODE_M (RSA_MODE_V << RSA_MODE_S)
#define RSA_MODE_V 0x0000007F
#define RSA_MODE_S 0
/* RSA_CLEAN_REG register
* RSA clean register
*/
#define RSA_CLEAN_REG (DR_REG_RSA_BASE + 0x808)
/* RSA_CLEAN : RO; bitpos: [0]; default: 0;
* The content of this bit is 1 when memories complete initialization.
*/
#define RSA_CLEAN (BIT(0))
#define RSA_CLEAN_M (RSA_CLEAN_V << RSA_CLEAN_S)
#define RSA_CLEAN_V 0x00000001
#define RSA_CLEAN_S 0
/* RSA_MODEXP_START_REG register
* Modular exponentiation starting bit
*/
#define RSA_MODEXP_START_REG (DR_REG_RSA_BASE + 0x80c)
/* RSA_MODEXP_START : WO; bitpos: [0]; default: 0;
* Set this bit to 1 to start the modular exponentiation.
*/
#define RSA_MODEXP_START (BIT(0))
#define RSA_MODEXP_START_M (RSA_MODEXP_START_V << RSA_MODEXP_START_S)
#define RSA_MODEXP_START_V 0x00000001
#define RSA_MODEXP_START_S 0
/* RSA_MODMULT_START_REG register
* Modular multiplication starting bit
*/
#define RSA_MODMULT_START_REG (DR_REG_RSA_BASE + 0x810)
/* RSA_MODMULT_START : WO; bitpos: [0]; default: 0;
* Set this bit to 1 to start the modular multiplication.
*/
#define RSA_MODMULT_START (BIT(0))
#define RSA_MODMULT_START_M (RSA_MODMULT_START_V << RSA_MODMULT_START_S)
#define RSA_MODMULT_START_V 0x00000001
#define RSA_MODMULT_START_S 0
/* RSA_MULT_START_REG register
* Normal multiplicaiton starting bit
*/
#define RSA_MULT_START_REG (DR_REG_RSA_BASE + 0x814)
/* RSA_MULT_START : WO; bitpos: [0]; default: 0;
* Set this bit to 1 to start the multiplication.
*/
#define RSA_MULT_START (BIT(0))
#define RSA_MULT_START_M (RSA_MULT_START_V << RSA_MULT_START_S)
#define RSA_MULT_START_V 0x00000001
#define RSA_MULT_START_S 0
/* RSA_IDLE_REG register
* RSA idle register
*/
#define RSA_IDLE_REG (DR_REG_RSA_BASE + 0x818)
/* RSA_IDLE : RO; bitpos: [0]; default: 0;
* The content of this bit is 1 when the RSA accelerator is idle.
*/
#define RSA_IDLE (BIT(0))
#define RSA_IDLE_M (RSA_IDLE_V << RSA_IDLE_S)
#define RSA_IDLE_V 0x00000001
#define RSA_IDLE_S 0
/* RSA_CLEAR_INTERRUPT_REG register
* RSA clear interrupt register
*/
#define RSA_CLEAR_INTERRUPT_REG (DR_REG_RSA_BASE + 0x81c)
/* RSA_CLEAR_INTERRUPT : WO; bitpos: [0]; default: 0;
* Set this bit to 1 to clear the RSA interrupts.
*/
#define RSA_CLEAR_INTERRUPT (BIT(0))
#define RSA_CLEAR_INTERRUPT_M (RSA_CLEAR_INTERRUPT_V << RSA_CLEAR_INTERRUPT_S)
#define RSA_CLEAR_INTERRUPT_V 0x00000001
#define RSA_CLEAR_INTERRUPT_S 0
/* RSA_CONSTANT_TIME_REG register
* The constant_time option
*/
#define RSA_CONSTANT_TIME_REG (DR_REG_RSA_BASE + 0x820)
/* RSA_CONSTANT_TIME : R/W; bitpos: [0]; default: 1;
* Set this bit to 0 to enable the acceleration option of constant_time for
* modular exponentiation. Set to 1 to disable the acceleration (by default).
*/
#define RSA_CONSTANT_TIME (BIT(0))
#define RSA_CONSTANT_TIME_M (RSA_CONSTANT_TIME_V << RSA_CONSTANT_TIME_S)
#define RSA_CONSTANT_TIME_V 0x00000001
#define RSA_CONSTANT_TIME_S 0
/* RSA_SEARCH_ENABLE_REG register
* The search option
*/
#define RSA_SEARCH_ENABLE_REG (DR_REG_RSA_BASE + 0x824)
/* RSA_SEARCH_ENABLE : R/W; bitpos: [0]; default: 0;
* Set this bit to 1 to enable the acceleration option of search for modular
* exponentiation. Set to 0 to disable the acceleration (by default).
*/
#define RSA_SEARCH_ENABLE (BIT(0))
#define RSA_SEARCH_ENABLE_M (RSA_SEARCH_ENABLE_V << RSA_SEARCH_ENABLE_S)
#define RSA_SEARCH_ENABLE_V 0x00000001
#define RSA_SEARCH_ENABLE_S 0
/* RSA_SEARCH_POS_REG register
* The search position
*/
#define RSA_SEARCH_POS_REG (DR_REG_RSA_BASE + 0x828)
/* RSA_SEARCH_POS : R/W; bitpos: [11:0]; default: 0;
* Is used to configure the starting address when the acceleration option of
* search is used.
*/
#define RSA_SEARCH_POS 0x00000FFF
#define RSA_SEARCH_POS_M (RSA_SEARCH_POS_V << RSA_SEARCH_POS_S)
#define RSA_SEARCH_POS_V 0x00000FFF
#define RSA_SEARCH_POS_S 0
/* RSA_INTERRUPT_ENA_REG register
* RSA interrupt enable register
*/
#define RSA_INTERRUPT_ENA_REG (DR_REG_RSA_BASE + 0x82c)
/* RSA_INTERRUPT_ENA : R/W; bitpos: [0]; default: 0;
* Set this bit to 1 to enable the RSA interrupt. This option is enabled by
* default.
*/
#define RSA_INTERRUPT_ENA (BIT(0))
#define RSA_INTERRUPT_ENA_M (RSA_INTERRUPT_ENA_V << RSA_INTERRUPT_ENA_S)
#define RSA_INTERRUPT_ENA_V 0x00000001
#define RSA_INTERRUPT_ENA_S 0
/* RSA_DATE_REG register
* Version control register
*/
#define RSA_DATE_REG (DR_REG_RSA_BASE + 0x830)
/* RSA_DATE : R/W; bitpos: [29:0]; default: 538510373;
* Version control register
*/
#define RSA_DATE 0x3FFFFFFF
#define RSA_DATE_M (RSA_DATE_V << RSA_DATE_S)
#define RSA_DATE_V 0x3FFFFFFF
#define RSA_DATE_S 0
#endif /* __ARCH_RISCV_SRC_ESP32C3_HARDWARE_ESP32C3_RSA_H */

View File

@ -0,0 +1,51 @@
#
# This file is autogenerated: PLEASE DO NOT EDIT IT.
#
# You can use "make menuconfig" to make any modifications to the installed .config file.
# You can then do "make savedefconfig" to generate a new defconfig file that includes your
# modifications.
#
# CONFIG_NSH_ARGCAT is not set
# CONFIG_NSH_CMDOPT_HEXDUMP is not set
# CONFIG_NSH_CMDPARMS is not set
CONFIG_ARCH="risc-v"
CONFIG_ARCH_BOARD="esp32c3-devkit"
CONFIG_ARCH_BOARD_ESP32C3_DEVKIT=y
CONFIG_ARCH_CHIP="esp32c3"
CONFIG_ARCH_CHIP_ESP32C3=y
CONFIG_ARCH_CHIP_ESP32C3WROOM02=y
CONFIG_ARCH_INTERRUPTSTACK=1536
CONFIG_ARCH_RISCV=y
CONFIG_ARCH_STACKDUMP=y
CONFIG_BOARD_LOOPSPERMSEC=15000
CONFIG_BUILTIN=y
CONFIG_DEBUG_ASSERTIONS=y
CONFIG_DEBUG_FEATURES=y
CONFIG_DEV_ZERO=y
CONFIG_ESP32C3_BIGNUM_ACCELERATOR=y
CONFIG_ESP32C3_BIGNUM_ACCELERATOR_TEST=y
CONFIG_ESP32C3_RSA_ACCELERATOR=y
CONFIG_ESP32C3_RSA_ACCELERATOR_TEST=y
CONFIG_FS_PROCFS=y
CONFIG_IDLETHREAD_STACKSIZE=2048
CONFIG_INTELHEX_BINARY=y
CONFIG_LIBC_PERROR_STDOUT=y
CONFIG_LIBC_STRERROR=y
CONFIG_MAX_TASKS=16
CONFIG_NFILE_DESCRIPTORS_PER_BLOCK=6
CONFIG_NSH_ARCHINIT=y
CONFIG_NSH_BUILTIN_APPS=y
CONFIG_NSH_FILEIOSIZE=512
CONFIG_NSH_READLINE=y
CONFIG_NSH_STRERROR=y
CONFIG_PREALLOC_TIMERS=0
CONFIG_RAW_BINARY=y
CONFIG_RR_INTERVAL=200
CONFIG_SCHED_WAITPID=y
CONFIG_START_DAY=29
CONFIG_START_MONTH=11
CONFIG_START_YEAR=2019
CONFIG_SYSTEM_NSH=y
CONFIG_UART0_SERIAL_CONSOLE=y
CONFIG_USERMAIN_STACKSIZE=4096
CONFIG_USER_ENTRYPOINT="esp32c3_rsa_main"