27 #include "in_compile.h" 35 #define ECC_CTRL 0x00000000UL 36 #define ECC_ENTRY_PNT 0x00000004UL 37 #define ECC_RTN_CODE 0x00000008UL 38 #define ECC_BUILD_CONFIG 0x0000000CUL 39 #define ECC_STACK_PNTR 0x00000010UL 40 #define ECC_INSTR_SINCE_GO 0x00000014UL 41 #define ECC_CONFIG 0x0000001CUL 42 #define ECC_STAT 0x00000020UL 43 #define ECC_FLAGS 0x00000024UL 44 #define ECC_WATCHDOG 0x00000028UL 45 #define ECC_CYCLES_SINCE_GO 0x0000002CUL 46 #define ECC_INDEX_I 0x00000030UL 47 #define ECC_INDEX_J 0x00000034UL 48 #define ECC_INDEX_K 0x00000038UL 49 #define ECC_INDEX_L 0x0000003CUL 50 #define ECC_IRQ_EN 0x00000040UL 51 #define ECC_JMP_PROB 0x00000044UL 52 #define ECC_JMP_PROB_LFSR 0x00000048UL 53 #define ECC_BANK_SW_A 0x00000050UL 54 #define ECC_BANK_SW_B 0x00000054UL 55 #define ECC_BANK_SW_C 0x00000058UL 56 #define ECC_BANK_SW_D 0x0000005CUL 57 #define ECC_Reserve1 0x00000000UL 58 #define ECC_Reserve2 0x00000000UL 60 #define ECC_CTRL_GO 0x80000000UL 61 #define ECC_CTRL_STOP 0x08000000UL 62 #define ECC_CTRL_BASE_RADIX 0x00000700UL 63 #define ECC_CTRL_PARTIAL_RADIX 0x000000FFUL 65 static INLINE
void ecc_go(
void)
67 uint32_t reg = RD_WORD(ECC_BASE + ECC_CTRL);
69 WR_WORD(ECC_BASE + ECC_CTRL, reg);
72 static INLINE
void ecc_halt(
void)
74 uint32_t reg = RD_WORD(ECC_BASE + ECC_CTRL);
76 WR_WORD(ECC_BASE + ECC_CTRL, reg);
79 static INLINE
void ecc_base_radix(
int radix)
81 uint32_t reg = RD_WORD(ECC_BASE + ECC_CTRL);
82 reg &= ~ECC_CTRL_BASE_RADIX;
84 WR_WORD(ECC_BASE + ECC_CTRL, reg);
87 static INLINE
void ecc_partial_radix(
int radix)
89 uint32_t reg = RD_WORD(ECC_BASE + ECC_CTRL);
90 reg &= ~ECC_CTRL_PARTIAL_RADIX;
92 WR_WORD(ECC_BASE + ECC_CTRL, reg);
95 #define ECC_ENTRY_PNT_ADDR 0x00000FFFUL 97 static INLINE
void ecc_entry_addr(uint32_t addr)
99 uint32_t reg = RD_WORD(ECC_BASE + ECC_ENTRY_PNT);
100 reg &= ~ECC_ENTRY_PNT_ADDR;
102 WR_WORD(ECC_BASE + ECC_ENTRY_PNT, reg);
105 static INLINE
int ecc_rtn_busy(
void)
107 return ((RD_WORD(ECC_BASE + ECC_RTN_CODE) >> 31) & 1);
110 static INLINE
int ecc_rtn_irq(
void)
112 return ((RD_WORD(ECC_BASE + ECC_RTN_CODE) >> 30) & 1);
115 static INLINE
int ecc_rtn_zero(
void)
117 return ((RD_WORD(ECC_BASE + ECC_RTN_CODE) >> 28) & 1);
120 #define ECC_RTN_REASON_NORMAL_STOP 0 121 #define ECC_RTN_REASON_INVALID_OP_CODE 1 122 #define ECC_RTN_REASON_STACK_OVF 2 123 #define ECC_RTN_REASON_STACK_UNF 3 124 #define ECC_RTN_REASON_WDT 4 125 #define ECC_RTN_REASON_HOST_REQ 5 127 static INLINE
int ecc_rtn_reason(
void)
129 return ((RD_WORD(ECC_BASE + ECC_RTN_CODE) >> 16) & 0xFF);
132 static INLINE
void ecc_stack_pntr_clear(
void)
134 WR_WORD(ECC_BASE + ECC_STACK_PNTR, 0);
137 #define ECC_CONFIG_ENDIAN_SWAP (1 << 26) 139 static INLINE
void ecc_config_endian_swap(
void)
141 uint32_t reg = RD_WORD(ECC_BASE + ECC_CONFIG);
142 reg ^= ECC_CONFIG_ENDIAN_SWAP;
143 WR_WORD(ECC_BASE + ECC_CONFIG, reg);
146 #define ECC_STAT_DONE 0x40000000UL 148 static INLINE uint32_t ecc_stat(
void)
150 return RD_WORD(ECC_BASE + ECC_STAT);
153 static INLINE
void ecc_stat_ack_irq(
void)
155 uint32_t reg = RD_WORD(ECC_BASE + ECC_STAT);
157 WR_WORD(ECC_BASE + ECC_STAT, reg);
160 static INLINE
void ecc_irq_enable(
void)
162 uint32_t reg = RD_WORD(ECC_BASE + ECC_IRQ_EN);
164 WR_WORD(ECC_BASE + ECC_IRQ_EN, reg);
167 static INLINE
void ecc_irq_disable(
void)
169 uint32_t reg = RD_WORD( + ECC_IRQ_EN);
171 WR_WORD(ECC_BASE + ECC_IRQ_EN, reg);
174 #define ECC_FLAG_ZERO 0x1 175 #define ECC_FLAG_MEM_TEST 0x2 176 #define ECC_FLAG_BORROW 0x4 177 #define ECC_FLAG_CARRY 0x8 179 static INLINE uint32_t ecc_flag(
void)
181 return RD_WORD(ECC_BASE + ECC_FLAGS);
184 static INLINE
void ecc_flag_clear(
void)
186 WR_WORD(ECC_BASE + ECC_FLAGS, 0);
189 static INLINE
void ecc_stack_clear(
void)
191 WR_WORD(ECC_BASE + ECC_STACK_PNTR, 0);
194 static INLINE
void ecc_mem_en(
void)
196 WR_WORD(GLOBAL_REG_AES_ECC_MEM_SEL, GLOBAL_REG_AES_ECC_MEM_SEL_DEFAULT);
199 static INLINE
int ecc_mem_aes(
void)
201 return ((RD_WORD(GLOBAL_REG_AES_ECC_MEM_SEL) & GLOBAL_REG_AES_ECC_MEM_SEL_CTL_AES_ECC_MEM_SEL) ? 1 : 0);
204 static INLINE
int ecc_reset_get(
void)
206 return ((RD_WORD(GLOBAL_REG_RESET_CTRL_6) & GLOBAL_REG_RESET_CTRL_6_CTL_RESET_6_D0_SECURITY_CORE_ECC_PCLK_RSTN_REG) ? 1 : 0);
209 static INLINE
void ecc_reset_set_0(
void)
211 WR_WORD(GLOBAL_REG_RESET_CTRL_6, (RD_WORD(GLOBAL_REG_RESET_CTRL_6) & ~GLOBAL_REG_RESET_CTRL_6_CTL_RESET_6_D0_SECURITY_CORE_ECC_PCLK_RSTN_REG));
214 static INLINE
void ecc_reset_set_1(
void)
216 WR_WORD(GLOBAL_REG_RESET_CTRL_6, (RD_WORD(GLOBAL_REG_RESET_CTRL_6) | GLOBAL_REG_RESET_CTRL_6_CTL_RESET_6_D0_SECURITY_CORE_ECC_PCLK_RSTN_REG));
220 #define ECC_A0_BASE (ECC_BASE + 0x400) 221 #define ECC_B0_BASE (ECC_BASE + 0x800) 222 #define ECC_C0_BASE (ECC_BASE + 0xC00) 223 #define ECC_D0_BASE (ECC_BASE + 0x1000) 225 #define ECC_FW_BASE (ECC_BASE + 0x4000) 227 #define ECC_FW_ENTRY_CALC_MP 0x10 228 #define ECC_FW_ENTRY_CALC_R_INV 0x11 229 #define ECC_FW_ENTRY_CALC_R_SQR 0x12 230 #define ECC_FW_ENTRY_IS_A_M3 0x1d 231 #define ECC_FW_ENTRY_IS_P_EQUAL_Q 0x1b 232 #define ECC_FW_ENTRY_IS_P_REFLECT_Q 0x1c 233 #define ECC_FW_ENTRY_MODADD 0xb 234 #define ECC_FW_ENTRY_MODDIV 0xd 235 #define ECC_FW_ENTRY_MODINV 0xe 236 #define ECC_FW_ENTRY_MODMULT 0xa 237 #define ECC_FW_ENTRY_MODSUB 0xc 238 #define ECC_FW_ENTRY_MULT 0x13 239 #define ECC_FW_ENTRY_PADD 0x17 240 #define ECC_FW_ENTRY_PADD_STD_PRJ 0x18 241 #define ECC_FW_ENTRY_PDBL 0x15 242 #define ECC_FW_ENTRY_PDBL_STD_PRJ 0x16 243 #define ECC_FW_ENTRY_PMULT 0x14 244 #define ECC_FW_ENTRY_PVER 0x19 245 #define ECC_FW_ENTRY_REDUCE 0xf 246 #define ECC_FW_ENTRY_SHAMIR 0x1e 247 #define ECC_FW_ENTRY_STD_PRJ_TO_AFFINE 0x1a 328 int hal_ecc_r_inv_mod_m_non_block(uint16_t size,
const uint8_t *m, uint8_t *r_inv,
void (*callback)(
int status));
345 int hal_ecc_m_prime_block(uint16_t size,
const uint8_t *r_inv,
const uint8_t *m, uint8_t *mp, uint32_t tmo);
346 int hal_ecc_m_prime_non_block(uint16_t size,
const uint8_t *r_inv,
const uint8_t *m, uint8_t *mp,
void (*callback)(
int status));
365 int hal_ecc_r_sqr_mod_m_non_block(uint16_t size,
const uint8_t *r_inv,
const uint8_t *m, uint8_t *r_sqr,
void (*callback)(
int status));
386 int hal_ecc_mod_mult_block(uint16_t size,
const uint8_t *x,
const uint8_t *y,
const uint8_t *m,
const uint8_t *mp,
const uint8_t *r_sqr, uint8_t *c, uint32_t tmo);
387 int hal_ecc_mod_mult_non_block(uint16_t size,
const uint8_t *x,
const uint8_t *y,
const uint8_t *m,
const uint8_t *mp,
const uint8_t *r_sqr, uint8_t *c,
void (*callback)(
int status));
405 int hal_ecc_mod_add_block(uint16_t size,
const uint8_t *x,
const uint8_t *y,
const uint8_t *m, uint8_t *c, uint32_t tmo);
406 int hal_ecc_mod_add_non_block(uint16_t size,
const uint8_t *x,
const uint8_t *y,
const uint8_t *m, uint8_t *c,
void (*callback)(
int status));
424 int hal_ecc_mod_sub_block(uint16_t size,
const uint8_t *x,
const uint8_t *y,
const uint8_t *m, uint8_t *c, uint32_t tmo);
425 int hal_ecc_mod_sub_non_block(uint16_t size,
const uint8_t *x,
const uint8_t *y,
const uint8_t *m, uint8_t *c,
void (*callback)(
int status));
443 int hal_ecc_mod_div_block(uint16_t size,
const uint8_t *y,
const uint8_t *x,
const uint8_t *m, uint8_t *c, uint32_t tmo);
444 int hal_ecc_mod_div_non_block(uint16_t size,
const uint8_t *y,
const uint8_t *x,
const uint8_t *m, uint8_t *c,
void (*callback)(
int status));
462 int hal_ecc_mod_inv_block(uint16_t size,
const uint8_t *x,
const uint8_t *m, uint8_t *c, uint32_t tmo);
463 int hal_ecc_mod_inv_non_block(uint16_t size,
const uint8_t *x,
const uint8_t *m, uint8_t *c,
void (*callback)(
int status));
488 int hal_ecc_pmult_block(uint16_t size,
const uint8_t *Px,
const uint8_t *Py,
const uint8_t *a,
const uint8_t *w,
489 const uint8_t *p,
const uint8_t *mp,
const uint8_t *r_sqr,
const uint8_t *k, uint8_t *Rx, uint8_t *Ry, uint32_t tmo);
490 int hal_ecc_pmult_non_block(uint16_t size,
const uint8_t *Px,
const uint8_t *Py,
const uint8_t *a,
const uint8_t *w,
491 const uint8_t *p,
const uint8_t *mp,
const uint8_t *r_sqr,
const uint8_t *k, uint8_t *Rx, uint8_t *Ry,
void (*callback)(
int status));
516 int hal_ecc_padd_block(uint16_t size,
const uint8_t *Px,
const uint8_t *Py,
const uint8_t *Qx,
const uint8_t *Qy,
const uint8_t *a,
const uint8_t *p,
517 const uint8_t *mp,
const uint8_t *r_sqr, uint8_t *Rx, uint8_t *Ry, uint32_t tmo);
518 int hal_ecc_padd_non_block(uint16_t size,
const uint8_t *Px,
const uint8_t *Py,
const uint8_t *Qx,
const uint8_t *Qy,
const uint8_t *a,
const uint8_t *p,
519 const uint8_t *mp,
const uint8_t *r_sqr, uint8_t *Rx, uint8_t *Ry,
void (*callback)(
int status));
541 int hal_ecc_pdbl_block(uint16_t size,
const uint8_t *Px,
const uint8_t *Py,
const uint8_t *a,
const uint8_t *p,
const uint8_t *mp,
542 const uint8_t *r_sqr, uint8_t *Rx, uint8_t *Ry, uint32_t tmo);
543 int hal_ecc_pdbl_non_block(uint16_t size,
const uint8_t *Px,
const uint8_t *Py,
const uint8_t *a,
const uint8_t *p,
const uint8_t *mp,
544 const uint8_t *r_sqr, uint8_t *Rx, uint8_t *Ry,
void (*callback)(
int status));
564 int hal_ecc_pver_block(uint16_t size,
const uint8_t *Px,
const uint8_t *Py,
const uint8_t *a,
const uint8_t *b,
const uint8_t *p,
const uint8_t *mp,
565 const uint8_t *r_sqr, uint32_t tmo);
566 int hal_ecc_pver_non_block(uint16_t size,
const uint8_t *Px,
const uint8_t *Py,
const uint8_t *a,
const uint8_t *b,
const uint8_t *p,
const uint8_t *mp,
567 const uint8_t *r_sqr,
void (*callback)(
int status));
592 int hal_ecc_shamir_block(uint16_t size,
const uint8_t *Px,
const uint8_t *Py,
const uint8_t *Qx,
const uint8_t *Qy,
const uint8_t *a,
const uint8_t *k,
593 const uint8_t *l,
const uint8_t *p,
const uint8_t *mp,
const uint8_t *r_sqr, uint8_t *Rx, uint8_t *Ry, uint32_t tmo);
594 int hal_ecc_shamir_non_block(uint16_t size,
const uint8_t *Px,
const uint8_t *Py,
const uint8_t *Qx,
const uint8_t *Qy,
const uint8_t *a,
const uint8_t *k,
595 const uint8_t *l,
const uint8_t *p,
const uint8_t *mp,
const uint8_t *r_sqr, uint8_t *Rx, uint8_t *Ry,
void (*callback)(
int status));
int hal_ecc_is_open(void)
Ecc and Aes shared the same HW memory. This is to inform AES that Ecc currently is using the HW memor...
int hal_ecc_open(int int_priority)
Initialize ECC driver. : All the Ecc APIs will be blocked call if "callback" function is not specifie...
ecc_result_status
ECC function status return.
Definition: hal_ecc.h:250
int hal_ecc_mod_sub_block(uint16_t size, const uint8_t *x, const uint8_t *y, const uint8_t *m, uint8_t *c, uint32_t tmo)
Subtracts two integers, each of a size contained in the operand size set, over the modular field m...
Error, ECC driver don't have enough resource.
Definition: hal_ecc.h:256
Error, ECC bad state.
Definition: hal_ecc.h:258
Error, ECC driver not initialized.
Definition: hal_ecc.h:254
Error, invalid elliptic curve (EC) point. Point is not on elliptic curve.
Definition: hal_ecc.h:262
int hal_ecc_mod_inv_block(uint16_t size, const uint8_t *x, const uint8_t *m, uint8_t *c, uint32_t tmo)
Calculates the inversion of an integer, of a size contained in the operand size set, over the modular field m. (1 / x) mod m.
Error, ECC operation returned abnormal stop condition.
Definition: hal_ecc.h:260
int hal_ecc_pver_block(uint16_t size, const uint8_t *Px, const uint8_t *Py, const uint8_t *a, const uint8_t *b, const uint8_t *p, const uint8_t *mp, const uint8_t *r_sqr, uint32_t tmo)
Computes y2 == x3 + ax + b mod p and verified LHS == RHS.
int hal_ecc_pdbl_block(uint16_t size, const uint8_t *Px, const uint8_t *Py, const uint8_t *a, const uint8_t *p, const uint8_t *mp, const uint8_t *r_sqr, uint8_t *Rx, uint8_t *Ry, uint32_t tmo)
Computes the EC Point Doubling over the curve y2 = x3 + ax + b mod p. R = 2P.
int hal_ecc_r_inv_mod_m_block(uint16_t size, const uint8_t *m, uint8_t *r_inv, uint32_t tmo)
Computes the modular inverse of r. (1/(r mod m))
No errors, good status.
Definition: hal_ecc.h:252
int hal_ecc_shamir_block(uint16_t size, const uint8_t *Px, const uint8_t *Py, const uint8_t *Qx, const uint8_t *Qy, const uint8_t *a, const uint8_t *k, const uint8_t *l, const uint8_t *p, const uint8_t *mp, const uint8_t *r_sqr, uint8_t *Rx, uint8_t *Ry, uint32_t tmo)
Calculate R = kP + lQ using Shamir's Trick.
int hal_ecc_mod_div_block(uint16_t size, const uint8_t *y, const uint8_t *x, const uint8_t *m, uint8_t *c, uint32_t tmo)
Divides one integer by another, each of a size contained in the operand size set, over the modular fi...
int hal_ecc_mod_mult_block(uint16_t size, const uint8_t *x, const uint8_t *y, const uint8_t *m, const uint8_t *mp, const uint8_t *r_sqr, uint8_t *c, uint32_t tmo)
Multiplies two integers, each of a size contained in the operand size set, over the modular field m...
int hal_ecc_pmult_block(uint16_t size, const uint8_t *Px, const uint8_t *Py, const uint8_t *a, const uint8_t *w, const uint8_t *p, const uint8_t *mp, const uint8_t *r_sqr, const uint8_t *k, uint8_t *Rx, uint8_t *Ry, uint32_t tmo)
Computes the ECC Point Multiplication over the curve y^2 = x^3 + ax + b mod p. R = 2P...
int hal_ecc_padd_block(uint16_t size, const uint8_t *Px, const uint8_t *Py, const uint8_t *Qx, const uint8_t *Qy, const uint8_t *a, const uint8_t *p, const uint8_t *mp, const uint8_t *r_sqr, uint8_t *Rx, uint8_t *Ry, uint32_t tmo)
Computes the ECC Point Addition over the curve y^2 = x^3 + ax + b mod p. R = P + Q.
Error, ECC return pending.
Definition: hal_ecc.h:268
int hal_ecc_mod_add_block(uint16_t size, const uint8_t *x, const uint8_t *y, const uint8_t *m, uint8_t *c, uint32_t tmo)
Adds two integers, each of a size contained in the operand size set, over the modular (x + y) mod m...
Error, invalid ECC size parameter.
Definition: hal_ecc.h:264
Error, return from HW.
Definition: hal_ecc.h:272
Error, ECC return pending.
Definition: hal_ecc.h:270
int hal_ecc_m_prime_block(uint16_t size, const uint8_t *r_inv, const uint8_t *m, uint8_t *mp, uint32_t tmo)
Computes the Montgomery residue constant. (m')
int hal_ecc_close(void)
De-Initialize ECC driver.
int hal_ecc_r_sqr_mod_m_block(uint16_t size, const uint8_t *r_inv, const uint8_t *m, uint8_t *r_sqr, uint32_t tmo)
Computes the Montgomery residue conversion constant. (r^2) mod m.
Error, AES using the HW memory.
Definition: hal_ecc.h:266