gd32w5xx_crypto_pkc.h
Go to the documentation of this file.
1 /**
2  * @file gd32w5xx_crypto_pkc.h
3  * @brief GD32W5 public-key hardware accelerator (PKCAU)
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2024 Oryx Embedded SARL. All rights reserved.
10  *
11  * This file is part of CycloneCRYPTO Open.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26  *
27  * @author Oryx Embedded SARL (www.oryx-embedded.com)
28  * @version 2.4.4
29  **/
30 
31 #ifndef _GD32W5XX_CRYPTO_PKC_H
32 #define _GD32W5XX_CRYPTO_PKC_H
33 
34 //Dependencies
35 #include "core/crypto.h"
36 
37 //Public-key hardware accelerator
38 #ifndef GD32W5XX_CRYPTO_PKC_SUPPORT
39  #define GD32W5XX_CRYPTO_PKC_SUPPORT DISABLED
40 #elif (GD32W5XX_CRYPTO_PKC_SUPPORT != ENABLED && GD32W5XX_CRYPTO_PKC_SUPPORT != DISABLED)
41  #error GD32W5XX_CRYPTO_PKC_SUPPORT parameter is not valid
42 #endif
43 
44 //Maximum RSA operand size, in bits
45 #define PKCAU_MAX_ROS 3136
46 //Maximum ECC operand size, in bits
47 #define PKCAU_MAX_EOS 640
48 
49 //PKCAU RAM
50 #define PKCAU_RAM ((volatile uint32_t *) (PKCAU_BASE + 0x0400))
51 
52 //PKCAU RAM offset
53 #define PKCAU_RAM_OFFSET(n) (((n) - 0x0400) / sizeof(uint32_t))
54 
55 //Arithmetic multiplication parameters
56 #define PKCAU_ARITH_MUL_IN_OP_LEN PKCAU_RAM_OFFSET(0x0404)
57 #define PKCAU_ARITH_MUL_IN_A PKCAU_RAM_OFFSET(0x08B4)
58 #define PKCAU_ARITH_MUL_IN_B PKCAU_RAM_OFFSET(0x0A44)
59 #define PKCAU_ARITH_MUL_OUT_R PKCAU_RAM_OFFSET(0x0BD0)
60 
61 //Modular exponentiation parameters
62 #define PKCAU_MOD_EXP_IN_EXP_LEN PKCAU_RAM_OFFSET(0x0400)
63 #define PKCAU_MOD_EXP_IN_OP_LEN PKCAU_RAM_OFFSET(0x0404)
64 #define PKCAU_MOD_EXP_IN_A PKCAU_RAM_OFFSET(0x0A44)
65 #define PKCAU_MOD_EXP_IN_E PKCAU_RAM_OFFSET(0x0BD0)
66 #define PKCAU_MOD_EXP_IN_N PKCAU_RAM_OFFSET(0x0D5C)
67 #define PKCAU_MOD_EXP_OUT_R PKCAU_RAM_OFFSET(0x0724)
68 
69 //RSA CRT exponentiation parameters
70 #define PKCAU_RSA_CRT_EXP_IN_MOD_LEN PKCAU_RAM_OFFSET(0x0404)
71 #define PKCAU_RSA_CRT_EXP_IN_DP PKCAU_RAM_OFFSET(0x065C)
72 #define PKCAU_RSA_CRT_EXP_IN_DQ PKCAU_RAM_OFFSET(0x0BD0)
73 #define PKCAU_RSA_CRT_EXP_IN_QINV PKCAU_RAM_OFFSET(0x07EC)
74 #define PKCAU_RSA_CRT_EXP_IN_P PKCAU_RAM_OFFSET(0x097C)
75 #define PKCAU_RSA_CRT_EXP_IN_Q PKCAU_RAM_OFFSET(0x0D5C)
76 #define PKCAU_RSA_CRT_EXP_IN_A PKCAU_RAM_OFFSET(0x0EEC)
77 #define PKCAU_RSA_CRT_EXP_OUT_R PKCAU_RAM_OFFSET(0x0724)
78 
79 //ECC scalar multiplication parameters
80 #define PKCAU_ECC_MUL_IN_SCALAR_LEN PKCAU_RAM_OFFSET(0x0400)
81 #define PKCAU_ECC_MUL_IN_MOD_LEN PKCAU_RAM_OFFSET(0x0404)
82 #define PKCAU_ECC_MUL_IN_A_SIGN PKCAU_RAM_OFFSET(0x0408)
83 #define PKCAU_ECC_MUL_IN_A PKCAU_RAM_OFFSET(0x040C)
84 #define PKCAU_ECC_MUL_IN_P PKCAU_RAM_OFFSET(0x0460)
85 #define PKCAU_ECC_MUL_IN_K PKCAU_RAM_OFFSET(0x0508)
86 #define PKCAU_ECC_MUL_IN_X PKCAU_RAM_OFFSET(0x055C)
87 #define PKCAU_ECC_MUL_IN_Y PKCAU_RAM_OFFSET(0x05B0)
88 #define PKCAU_ECC_MUL_OUT_X PKCAU_RAM_OFFSET(0x055C)
89 #define PKCAU_ECC_MUL_OUT_Y PKCAU_RAM_OFFSET(0x05B0)
90 
91 //ECDSA sign parameters
92 #define PKCAU_ECDSA_SIGN_IN_ORDER_LEN PKCAU_RAM_OFFSET(0x0400)
93 #define PKCAU_ECDSA_SIGN_IN_MOD_LEN PKCAU_RAM_OFFSET(0x0404)
94 #define PKCAU_ECDSA_SIGN_IN_A_SIGN PKCAU_RAM_OFFSET(0x0408)
95 #define PKCAU_ECDSA_SIGN_IN_A PKCAU_RAM_OFFSET(0x040C)
96 #define PKCAU_ECDSA_SIGN_IN_P PKCAU_RAM_OFFSET(0x0460)
97 #define PKCAU_ECDSA_SIGN_IN_K PKCAU_RAM_OFFSET(0x0508)
98 #define PKCAU_ECDSA_SIGN_IN_GX PKCAU_RAM_OFFSET(0x055C)
99 #define PKCAU_ECDSA_SIGN_IN_GY PKCAU_RAM_OFFSET(0x05B0)
100 #define PKCAU_ECDSA_SIGN_IN_Z PKCAU_RAM_OFFSET(0x0DE8)
101 #define PKCAU_ECDSA_SIGN_IN_D PKCAU_RAM_OFFSET(0x0E3C)
102 #define PKCAU_ECDSA_SIGN_IN_N PKCAU_RAM_OFFSET(0x0E94)
103 #define PKCAU_ECDSA_SIGN_OUT_R PKCAU_RAM_OFFSET(0x0700)
104 #define PKCAU_ECDSA_SIGN_OUT_S PKCAU_RAM_OFFSET(0x0754)
105 #define PKCAU_ECDSA_SIGN_OUT_ERROR PKCAU_RAM_OFFSET(0x0EE8)
106 
107 //ECDSA verification parameters
108 #define PKCAU_ECDSA_VERIF_IN_ORDER_LEN PKCAU_RAM_OFFSET(0x0404)
109 #define PKCAU_ECDSA_VERIF_IN_MOD_LEN PKCAU_RAM_OFFSET(0x04B4)
110 #define PKCAU_ECDSA_VERIF_IN_A_SIGN PKCAU_RAM_OFFSET(0x045C)
111 #define PKCAU_ECDSA_VERIF_IN_A PKCAU_RAM_OFFSET(0x0460)
112 #define PKCAU_ECDSA_VERIF_IN_P PKCAU_RAM_OFFSET(0x04B8)
113 #define PKCAU_ECDSA_VERIF_IN_GX PKCAU_RAM_OFFSET(0x05E8)
114 #define PKCAU_ECDSA_VERIF_IN_GY PKCAU_RAM_OFFSET(0x063C)
115 #define PKCAU_ECDSA_VERIF_IN_S PKCAU_RAM_OFFSET(0x0A44)
116 #define PKCAU_ECDSA_VERIF_IN_N PKCAU_RAM_OFFSET(0x0D5C)
117 #define PKCAU_ECDSA_VERIF_IN_QX PKCAU_RAM_OFFSET(0x0F40)
118 #define PKCAU_ECDSA_VERIF_IN_QY PKCAU_RAM_OFFSET(0x0F94)
119 #define PKCAU_ECDSA_VERIF_IN_Z PKCAU_RAM_OFFSET(0x0FE8)
120 #define PKCAU_ECDSA_VERIF_IN_R PKCAU_RAM_OFFSET(0x1098)
121 #define PKCAU_ECDSA_VERIF_OUT_RES PKCAU_RAM_OFFSET(0x05B0)
122 
123 //PKCAU status codes
124 #define PKCAU_STATUS_SUCCESS 0x00000000
125 #define PKCAU_STATUS_INVALID 0xFFFFFFFF
126 
127 //C++ guard
128 #ifdef __cplusplus
129 extern "C" {
130 #endif
131 
132 //PKCAU related functions
133 error_t pkcauInit(void);
134 
135 //C++ guard
136 #ifdef __cplusplus
137 }
138 #endif
139 
140 #endif
error_t
Error codes.
Definition: error.h:43
General definitions for cryptographic algorithms.
error_t pkcauInit(void)
PKCAU module initialization.