sp.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447
  1. /* sp.h
  2. *
  3. * Copyright (C) 2006-2023 wolfSSL Inc.
  4. *
  5. * This file is part of wolfSSL.
  6. *
  7. * wolfSSL is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * wolfSSL is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
  20. */
  21. #ifndef WOLF_CRYPT_SP_H
  22. #define WOLF_CRYPT_SP_H
  23. #include <wolfssl/wolfcrypt/types.h>
  24. #include <wolfssl/wolfcrypt/settings.h>
  25. #if defined(WOLFSSL_HAVE_SP_RSA) || defined(WOLFSSL_HAVE_SP_DH) || \
  26. defined(WOLFSSL_HAVE_SP_ECC)
  27. #ifdef _WIN32_WCE
  28. typedef __int8 int8_t;
  29. typedef __int32 int32_t;
  30. typedef __int64 int64_t;
  31. typedef unsigned __int8 uint8_t;
  32. typedef unsigned __int32 uint32_t;
  33. typedef unsigned __int64 uint64_t;
  34. #elif !defined(WOLFSSL_LINUXKM)
  35. #include <stdint.h>
  36. #endif
  37. #include <wolfssl/wolfcrypt/wolfmath.h>
  38. #include <wolfssl/wolfcrypt/sp_int.h>
  39. #if defined(HAVE_ECC) && defined(WOLFSSL_HAVE_SP_ECC)
  40. #include <wolfssl/wolfcrypt/ecc.h>
  41. #else
  42. #undef WOLFSSL_HAVE_SP_ECC
  43. #endif
  44. #ifdef noinline
  45. #define SP_NOINLINE noinline
  46. #elif defined(_MSC_VER)
  47. #define SP_NOINLINE __declspec(noinline)
  48. #elif defined(__ICCARM__) || defined(__IAR_SYSTEMS_ICC__)
  49. #define SP_NOINLINE _Pragma("inline = never")
  50. #elif defined(__GNUC__) || defined(__KEIL__) || defined(__DCC__)
  51. #define SP_NOINLINE __attribute__((noinline))
  52. #else
  53. #define SP_NOINLINE
  54. #endif
  55. #ifdef __cplusplus
  56. extern "C" {
  57. #endif
  58. #ifdef WOLFSSL_HAVE_SP_RSA
  59. /* non-const versions only needed for inlined ARM assembly */
  60. #if defined(HAVE_FIPS_VERSION) && HAVE_FIPS_VERSION == 2 \
  61. && ( defined(WOLFSSL_SP_ARM32_ASM) || defined(WOLFSSL_SP_ARM64_ASM) )
  62. WOLFSSL_LOCAL int sp_RsaPublic_2048(const byte* in, word32 inLen,
  63. mp_int* em, mp_int* mm, byte* out, word32* outLen);
  64. WOLFSSL_LOCAL int sp_RsaPrivate_2048(const byte* in, word32 inLen,
  65. mp_int* dm, mp_int* pm, mp_int* qm, mp_int* dpm, mp_int* dqm, mp_int* qim,
  66. mp_int* mm, byte* out, word32* outLen);
  67. WOLFSSL_LOCAL int sp_RsaPublic_3072(const byte* in, word32 inLen,
  68. mp_int* em, mp_int* mm, byte* out, word32* outLen);
  69. WOLFSSL_LOCAL int sp_RsaPrivate_3072(const byte* in, word32 inLen,
  70. mp_int* dm, mp_int* pm, mp_int* qm, mp_int* dpm, mp_int* dqm, mp_int* qim,
  71. mp_int* mm, byte* out, word32* outLen);
  72. WOLFSSL_LOCAL int sp_RsaPublic_4096(const byte* in, word32 inLen,
  73. mp_int* em, mp_int* mm, byte* out, word32* outLen);
  74. WOLFSSL_LOCAL int sp_RsaPrivate_4096(const byte* in, word32 inLen,
  75. mp_int* dm, mp_int* pm, mp_int* qm, mp_int* dpm, mp_int* dqm, mp_int* qim,
  76. mp_int* mm, byte* out, word32* outLen);
  77. #else
  78. WOLFSSL_LOCAL int sp_RsaPublic_2048(const byte* in, word32 inLen,
  79. const mp_int* em, const mp_int* mm, byte* out, word32* outLen);
  80. WOLFSSL_LOCAL int sp_RsaPrivate_2048(const byte* in, word32 inLen,
  81. const mp_int* dm, const mp_int* pm, const mp_int* qm, const mp_int* dpm,
  82. const mp_int* dqm, const mp_int* qim, const mp_int* mm, byte* out,
  83. word32* outLen);
  84. WOLFSSL_LOCAL int sp_RsaPublic_3072(const byte* in, word32 inLen,
  85. const mp_int* em, const mp_int* mm, byte* out, word32* outLen);
  86. WOLFSSL_LOCAL int sp_RsaPrivate_3072(const byte* in, word32 inLen,
  87. const mp_int* dm, const mp_int* pm, const mp_int* qm, const mp_int* dpm,
  88. const mp_int* dqm, const mp_int* qim, const mp_int* mm, byte* out,
  89. word32* outLen);
  90. WOLFSSL_LOCAL int sp_RsaPublic_4096(const byte* in, word32 inLen,
  91. const mp_int* em, const mp_int* mm, byte* out, word32* outLen);
  92. WOLFSSL_LOCAL int sp_RsaPrivate_4096(const byte* in, word32 inLen,
  93. const mp_int* dm, const mp_int* pm, const mp_int* qm, const mp_int* dpm,
  94. const mp_int* dqm, const mp_int* qim, const mp_int* mm, byte* out,
  95. word32* outLen);
  96. #endif /* HAVE_FIPS_VERSION && HAVE_FIPS_VERSION == 2 && !WOLFSSL_SP_ARM[32|64]_ASM */
  97. #endif /* WOLFSSL_HAVE_SP_RSA */
  98. #if defined(WOLFSSL_HAVE_SP_DH) || defined(WOLFSSL_HAVE_SP_RSA)
  99. /* non-const versions only needed for inlined ARM assembly */
  100. #if defined(HAVE_FIPS_VERSION) && HAVE_FIPS_VERSION == 2 \
  101. && ( defined(WOLFSSL_SP_ARM32_ASM) || defined(WOLFSSL_SP_ARM64_ASM) )
  102. WOLFSSL_LOCAL int sp_ModExp_1024(mp_int* base, mp_int* exp, mp_int* mod,
  103. mp_int* res);
  104. WOLFSSL_LOCAL int sp_ModExp_1536(mp_int* base, mp_int* exp, mp_int* mod,
  105. mp_int* res);
  106. WOLFSSL_LOCAL int sp_ModExp_2048(mp_int* base, mp_int* exp, mp_int* mod,
  107. mp_int* res);
  108. WOLFSSL_LOCAL int sp_ModExp_3072(mp_int* base, mp_int* exp, mp_int* mod,
  109. mp_int* res);
  110. WOLFSSL_LOCAL int sp_ModExp_4096(mp_int* base, mp_int* exp, mp_int* mod,
  111. mp_int* res);
  112. #else
  113. WOLFSSL_LOCAL int sp_ModExp_1024(const mp_int* base, const mp_int* exp,
  114. const mp_int* mod, mp_int* res);
  115. WOLFSSL_LOCAL int sp_ModExp_1536(const mp_int* base, const mp_int* exp,
  116. const mp_int* mod, mp_int* res);
  117. WOLFSSL_LOCAL int sp_ModExp_2048(const mp_int* base, const mp_int* exp,
  118. const mp_int* mod, mp_int* res);
  119. WOLFSSL_LOCAL int sp_ModExp_3072(const mp_int* base, const mp_int* exp,
  120. const mp_int* mod, mp_int* res);
  121. WOLFSSL_LOCAL int sp_ModExp_4096(const mp_int* base, const mp_int* exp,
  122. const mp_int* mod, mp_int* res);
  123. #endif /* HAVE_FIPS_VERSION && HAVE_FIPS_VERSION == 2 && !WOLFSSL_SP_ARM[32|64]_ASM */
  124. #endif
  125. #ifdef WOLFSSL_HAVE_SP_DH
  126. /* non-const versions only needed for inlined ARM assembly */
  127. #if defined(HAVE_FIPS_VERSION) && HAVE_FIPS_VERSION == 2 \
  128. && ( defined(WOLFSSL_SP_ARM32_ASM) || defined(WOLFSSL_SP_ARM64_ASM) )
  129. WOLFSSL_LOCAL int sp_DhExp_2048(mp_int* base, const byte* exp, word32 expLen,
  130. mp_int* mod, byte* out, word32* outLen);
  131. WOLFSSL_LOCAL int sp_DhExp_3072(mp_int* base, const byte* exp, word32 expLen,
  132. mp_int* mod, byte* out, word32* outLen);
  133. WOLFSSL_LOCAL int sp_DhExp_4096(mp_int* base, const byte* exp, word32 expLen,
  134. mp_int* mod, byte* out, word32* outLen);
  135. #else
  136. WOLFSSL_LOCAL int sp_DhExp_2048(const mp_int* base, const byte* exp,
  137. word32 expLen, const mp_int* mod, byte* out, word32* outLen);
  138. WOLFSSL_LOCAL int sp_DhExp_3072(const mp_int* base, const byte* exp,
  139. word32 expLen, const mp_int* mod, byte* out, word32* outLen);
  140. WOLFSSL_LOCAL int sp_DhExp_4096(const mp_int* base, const byte* exp,
  141. word32 expLen, const mp_int* mod, byte* out, word32* outLen);
  142. #endif /* HAVE_FIPS_VERSION && HAVE_FIPS_VERSION == 2 && !WOLFSSL_SP_ARM[32|64]_ASM */
  143. #endif /* WOLFSSL_HAVE_SP_DH */
  144. #ifdef WOLFSSL_HAVE_SP_ECC
  145. /* non-const versions only needed for inlined ARM assembly */
  146. #if defined(HAVE_FIPS_VERSION) && HAVE_FIPS_VERSION == 2 \
  147. && ( defined(WOLFSSL_SP_ARM32_ASM) || defined(WOLFSSL_SP_ARM64_ASM) )
  148. int sp_ecc_mulmod_256(mp_int* km, ecc_point* gm, ecc_point* rm, int map,
  149. void* heap);
  150. int sp_ecc_mulmod_base_256(mp_int* km, ecc_point* rm, int map, void* heap);
  151. int sp_ecc_make_key_256(WC_RNG* rng, mp_int* priv, ecc_point* pub, void* heap);
  152. int sp_ecc_secret_gen_256(mp_int* priv, ecc_point* pub, byte* out,
  153. word32* outlen, void* heap);
  154. int sp_ecc_sign_256(const byte* hash, word32 hashLen, WC_RNG* rng, mp_int* priv,
  155. mp_int* rm, mp_int* sm, mp_int* km, void* heap);
  156. int sp_ecc_verify_256(const byte* hash, word32 hashLen, mp_int* pX, mp_int* pY,
  157. mp_int* pZ, mp_int* r, mp_int* sm, int* res, void* heap);
  158. int sp_ecc_is_point_256(mp_int* pX, mp_int* pY);
  159. int sp_ecc_check_key_256(mp_int* pX, mp_int* pY, mp_int* privm, void* heap);
  160. int sp_ecc_proj_add_point_256(mp_int* pX, mp_int* pY, mp_int* pZ,
  161. mp_int* qX, mp_int* qY, mp_int* qZ,
  162. mp_int* rX, mp_int* rY, mp_int* rZ);
  163. int sp_ecc_proj_dbl_point_256(mp_int* pX, mp_int* pY, mp_int* pZ,
  164. mp_int* rX, mp_int* rY, mp_int* rZ);
  165. int sp_ecc_map_256(mp_int* pX, mp_int* pY, mp_int* pZ);
  166. int sp_ecc_uncompress_256(mp_int* xm, int odd, mp_int* ym);
  167. int sp_ecc_mulmod_384(mp_int* km, ecc_point* gm, ecc_point* rm, int map,
  168. void* heap);
  169. int sp_ecc_mulmod_base_384(mp_int* km, ecc_point* rm, int map, void* heap);
  170. int sp_ecc_make_key_384(WC_RNG* rng, mp_int* priv, ecc_point* pub, void* heap);
  171. int sp_ecc_secret_gen_384(mp_int* priv, ecc_point* pub, byte* out,
  172. word32* outlen, void* heap);
  173. int sp_ecc_sign_384(const byte* hash, word32 hashLen, WC_RNG* rng, mp_int* priv,
  174. mp_int* rm, mp_int* sm, mp_int* km, void* heap);
  175. int sp_ecc_verify_384(const byte* hash, word32 hashLen, mp_int* pX, mp_int* pY,
  176. mp_int* pZ, mp_int* r, mp_int* sm, int* res, void* heap);
  177. int sp_ecc_is_point_384(mp_int* pX, mp_int* pY);
  178. int sp_ecc_check_key_384(mp_int* pX, mp_int* pY, mp_int* privm, void* heap);
  179. int sp_ecc_proj_add_point_384(mp_int* pX, mp_int* pY, mp_int* pZ,
  180. mp_int* qX, mp_int* qY, mp_int* qZ,
  181. mp_int* rX, mp_int* rY, mp_int* rZ);
  182. int sp_ecc_proj_dbl_point_384(mp_int* pX, mp_int* pY, mp_int* pZ,
  183. mp_int* rX, mp_int* rY, mp_int* rZ);
  184. int sp_ecc_map_384(mp_int* pX, mp_int* pY, mp_int* pZ);
  185. int sp_ecc_uncompress_384(mp_int* xm, int odd, mp_int* ym);
  186. #else
  187. WOLFSSL_LOCAL int sp_ecc_mulmod_256(const mp_int* km, const ecc_point* gm,
  188. ecc_point* rm, int map, void* heap);
  189. WOLFSSL_LOCAL int sp_ecc_mulmod_add_256(const mp_int* km, const ecc_point* gm,
  190. const ecc_point* am, int inMont, ecc_point* rm, int map, void* heap);
  191. WOLFSSL_LOCAL int sp_ecc_mulmod_base_256(const mp_int* km, ecc_point* rm,
  192. int map, void* heap);
  193. WOLFSSL_LOCAL int sp_ecc_mulmod_base_add_256(const mp_int* km,
  194. const ecc_point* am, int inMont, ecc_point* rm, int map, void* heap);
  195. WOLFSSL_LOCAL int sp_ecc_make_key_256(WC_RNG* rng, mp_int* priv, ecc_point* pub,
  196. void* heap);
  197. WOLFSSL_LOCAL int sp_ecc_secret_gen_256(const mp_int* priv,
  198. const ecc_point* pub, byte* out, word32* outlen, void* heap);
  199. WOLFSSL_LOCAL int sp_ecc_sign_256(const byte* hash, word32 hashLen, WC_RNG* rng,
  200. const mp_int* priv, mp_int* rm, mp_int* sm, mp_int* km, void* heap);
  201. WOLFSSL_LOCAL int sp_ecc_verify_256(const byte* hash, word32 hashLen,
  202. const mp_int* pX, const mp_int* pY, const mp_int* pZ, const mp_int* r,
  203. const mp_int* sm, int* res, void* heap);
  204. WOLFSSL_LOCAL int sp_ecc_is_point_256(const mp_int* pX, const mp_int* pY);
  205. WOLFSSL_LOCAL int sp_ecc_check_key_256(const mp_int* pX, const mp_int* pY,
  206. const mp_int* privm, void* heap);
  207. WOLFSSL_LOCAL int sp_ecc_proj_add_point_256(mp_int* pX, mp_int* pY, mp_int* pZ,
  208. mp_int* qX, mp_int* qY, mp_int* qZ, mp_int* rX, mp_int* rY, mp_int* rZ);
  209. WOLFSSL_LOCAL int sp_ecc_proj_dbl_point_256(mp_int* pX, mp_int* pY, mp_int* pZ,
  210. mp_int* rX, mp_int* rY, mp_int* rZ);
  211. WOLFSSL_LOCAL int sp_ecc_map_256(mp_int* pX, mp_int* pY, mp_int* pZ);
  212. WOLFSSL_LOCAL int sp_ecc_uncompress_256(mp_int* xm, int odd, mp_int* ym);
  213. WOLFSSL_LOCAL int sp_ecc_mulmod_384(const mp_int* km, const ecc_point* gm,
  214. ecc_point* rm, int map, void* heap);
  215. WOLFSSL_LOCAL int sp_ecc_mulmod_add_384(const mp_int* km, const ecc_point* gm,
  216. const ecc_point* am, int inMont, ecc_point* rm, int map, void* heap);
  217. WOLFSSL_LOCAL int sp_ecc_mulmod_base_384(const mp_int* km, ecc_point* rm,
  218. int map, void* heap);
  219. WOLFSSL_LOCAL int sp_ecc_mulmod_base_add_384(const mp_int* km,
  220. const ecc_point* am, int inMont, ecc_point* rm, int map, void* heap);
  221. WOLFSSL_LOCAL int sp_ecc_make_key_384(WC_RNG* rng, mp_int* priv, ecc_point* pub, void* heap);
  222. WOLFSSL_LOCAL int sp_ecc_secret_gen_384(const mp_int* priv,
  223. const ecc_point* pub, byte* out, word32* outlen, void* heap);
  224. WOLFSSL_LOCAL int sp_ecc_sign_384(const byte* hash, word32 hashLen, WC_RNG* rng,
  225. const mp_int* priv, mp_int* rm, mp_int* sm, mp_int* km, void* heap);
  226. WOLFSSL_LOCAL int sp_ecc_verify_384(const byte* hash, word32 hashLen,
  227. const mp_int* pX, const mp_int* pY, const mp_int* pZ, const mp_int* r,
  228. const mp_int* sm, int* res, void* heap);
  229. WOLFSSL_LOCAL int sp_ecc_is_point_384(const mp_int* pX, const mp_int* pY);
  230. WOLFSSL_LOCAL int sp_ecc_check_key_384(const mp_int* pX, const mp_int* pY,
  231. const mp_int* privm, void* heap);
  232. WOLFSSL_LOCAL int sp_ecc_proj_add_point_384(mp_int* pX, mp_int* pY, mp_int* pZ,
  233. mp_int* qX, mp_int* qY, mp_int* qZ, mp_int* rX, mp_int* rY, mp_int* rZ);
  234. WOLFSSL_LOCAL int sp_ecc_proj_dbl_point_384(mp_int* pX, mp_int* pY, mp_int* pZ,
  235. mp_int* rX, mp_int* rY, mp_int* rZ);
  236. WOLFSSL_LOCAL int sp_ecc_map_384(mp_int* pX, mp_int* pY, mp_int* pZ);
  237. WOLFSSL_LOCAL int sp_ecc_uncompress_384(mp_int* xm, int odd, mp_int* ym);
  238. WOLFSSL_LOCAL int sp_ecc_mulmod_521(const mp_int* km, const ecc_point* gm,
  239. ecc_point* rm, int map, void* heap);
  240. WOLFSSL_LOCAL int sp_ecc_mulmod_add_521(const mp_int* km, const ecc_point* gm,
  241. const ecc_point* am, int inMont, ecc_point* rm, int map, void* heap);
  242. WOLFSSL_LOCAL int sp_ecc_mulmod_base_521(const mp_int* km, ecc_point* rm,
  243. int map, void* heap);
  244. WOLFSSL_LOCAL int sp_ecc_mulmod_base_add_521(const mp_int* km,
  245. const ecc_point* am, int inMont, ecc_point* rm, int map, void* heap);
  246. WOLFSSL_LOCAL int sp_ecc_make_key_521(WC_RNG* rng, mp_int* priv, ecc_point* pub, void* heap);
  247. WOLFSSL_LOCAL int sp_ecc_secret_gen_521(const mp_int* priv,
  248. const ecc_point* pub, byte* out, word32* outlen, void* heap);
  249. WOLFSSL_LOCAL int sp_ecc_sign_521(const byte* hash, word32 hashLen, WC_RNG* rng,
  250. const mp_int* priv, mp_int* rm, mp_int* sm, mp_int* km, void* heap);
  251. WOLFSSL_LOCAL int sp_ecc_verify_521(const byte* hash, word32 hashLen,
  252. const mp_int* pX, const mp_int* pY, const mp_int* pZ, const mp_int* r,
  253. const mp_int* sm, int* res, void* heap);
  254. WOLFSSL_LOCAL int sp_ecc_is_point_521(const mp_int* pX, const mp_int* pY);
  255. WOLFSSL_LOCAL int sp_ecc_check_key_521(const mp_int* pX, const mp_int* pY,
  256. const mp_int* privm, void* heap);
  257. WOLFSSL_LOCAL int sp_ecc_proj_add_point_521(mp_int* pX, mp_int* pY, mp_int* pZ,
  258. mp_int* qX, mp_int* qY, mp_int* qZ, mp_int* rX, mp_int* rY, mp_int* rZ);
  259. WOLFSSL_LOCAL int sp_ecc_proj_dbl_point_521(mp_int* pX, mp_int* pY, mp_int* pZ,
  260. mp_int* rX, mp_int* rY, mp_int* rZ);
  261. WOLFSSL_LOCAL int sp_ecc_map_521(mp_int* pX, mp_int* pY, mp_int* pZ);
  262. WOLFSSL_LOCAL int sp_ecc_uncompress_521(mp_int* xm, int odd, mp_int* ym);
  263. WOLFSSL_LOCAL int sp_ecc_mulmod_1024(const mp_int* km, const ecc_point* gm,
  264. ecc_point* rm, int map, void* heap);
  265. WOLFSSL_LOCAL int sp_ecc_mulmod_base_1024(const mp_int* km, ecc_point* rm,
  266. int map, void* heap);
  267. WOLFSSL_LOCAL int sp_ecc_mulmod_base_add_1024(const mp_int* km,
  268. const ecc_point* am, int inMont, ecc_point* rm, int map, void* heap);
  269. WOLFSSL_LOCAL int sp_ecc_gen_table_1024(const ecc_point* gm, byte* table,
  270. word32* len, void* heap);
  271. WOLFSSL_LOCAL int sp_ecc_mulmod_table_1024(const mp_int* km,
  272. const ecc_point* gm, byte* table, ecc_point* r, int map, void* heap);
  273. WOLFSSL_LOCAL int sp_ModExp_Fp_star_1024(const mp_int* base, mp_int* exp,
  274. mp_int* res);
  275. WOLFSSL_LOCAL int sp_Pairing_1024(const ecc_point* p, const ecc_point* q,
  276. mp_int* res);
  277. WOLFSSL_LOCAL int sp_Pairing_gen_precomp_1024(const ecc_point* p, byte* table,
  278. word32* len);
  279. WOLFSSL_LOCAL int sp_Pairing_precomp_1024(const ecc_point* p,
  280. const ecc_point* q, mp_int* res, const byte* table, word32 len);
  281. WOLFSSL_LOCAL int sp_ecc_is_point_1024(const mp_int* pX, const mp_int* pY);
  282. WOLFSSL_LOCAL int sp_ecc_check_key_1024(const mp_int* pX, const mp_int* pY,
  283. const mp_int* privm, void* heap);
  284. WOLFSSL_LOCAL int sp_ecc_mulmod_sm2_256(const mp_int* km, const ecc_point* gm,
  285. ecc_point* rm, int map, void* heap);
  286. WOLFSSL_LOCAL int sp_ecc_mulmod_add_sm2_256(const mp_int* km, const ecc_point* gm,
  287. const ecc_point* am, int inMont, ecc_point* rm, int map, void* heap);
  288. WOLFSSL_LOCAL int sp_ecc_mulmod_base_sm2_256(const mp_int* km, ecc_point* rm,
  289. int map, void* heap);
  290. WOLFSSL_LOCAL int sp_ecc_mulmod_base_add_sm2_256(const mp_int* km,
  291. const ecc_point* am, int inMont, ecc_point* rm, int map, void* heap);
  292. WOLFSSL_LOCAL int sp_ecc_make_key_sm2_256(WC_RNG* rng, mp_int* priv,
  293. ecc_point* pub, void* heap);
  294. WOLFSSL_LOCAL int sp_ecc_secret_gen_sm2_256(const mp_int* priv,
  295. const ecc_point* pub, byte* out, word32* outlen, void* heap);
  296. WOLFSSL_LOCAL int sp_ecc_sign_sm2_256(const byte* hash, word32 hashLen,
  297. WC_RNG* rng, const mp_int* priv, mp_int* rm, mp_int* sm, mp_int* km,
  298. void* heap);
  299. WOLFSSL_LOCAL int sp_ecc_verify_sm2_256(const byte* hash, word32 hashLen,
  300. const mp_int* pX, const mp_int* pY, const mp_int* pZ, const mp_int* r,
  301. const mp_int* sm, int* res, void* heap);
  302. WOLFSSL_LOCAL int sp_ecc_is_point_sm2_256(const mp_int* pX, const mp_int* pY);
  303. WOLFSSL_LOCAL int sp_ecc_check_key_sm2_256(const mp_int* pX, const mp_int* pY,
  304. const mp_int* privm, void* heap);
  305. WOLFSSL_LOCAL int sp_ecc_proj_add_point_sm2_256(mp_int* pX, mp_int* pY,
  306. mp_int* pZ, mp_int* qX, mp_int* qY, mp_int* qZ, mp_int* rX, mp_int* rY,
  307. mp_int* rZ);
  308. WOLFSSL_LOCAL int sp_ecc_proj_dbl_point_sm2_256(mp_int* pX, mp_int* pY,
  309. mp_int* pZ, mp_int* rX, mp_int* rY, mp_int* rZ);
  310. WOLFSSL_LOCAL int sp_ecc_map_sm2_256(mp_int* pX, mp_int* pY, mp_int* pZ);
  311. WOLFSSL_LOCAL int sp_ecc_uncompress_sm2_256(mp_int* xm, int odd, mp_int* ym);
  312. #endif /* HAVE_FIPS_VERSION && HAVE_FIPS_VERSION == 2 && !WOLFSSL_SP_ARM[32|64]_ASM */
  313. #ifdef WOLFSSL_SP_NONBLOCK
  314. WOLFSSL_LOCAL int sp_ecc_make_key_256_nb(sp_ecc_ctx_t* sp_ctx, WC_RNG* rng,
  315. mp_int* priv, ecc_point* pub, void* heap);
  316. WOLFSSL_LOCAL int sp_ecc_secret_gen_256_nb(sp_ecc_ctx_t* sp_ctx,
  317. const mp_int* priv, const ecc_point* pub, byte* out, word32* outLen,
  318. void* heap);
  319. WOLFSSL_LOCAL int sp_ecc_sign_256_nb(sp_ecc_ctx_t* ctx, const byte* hash,
  320. word32 hashLen, WC_RNG* rng, mp_int* priv, mp_int* rm, mp_int* sm,
  321. mp_int* km, void* heap);
  322. WOLFSSL_LOCAL int sp_ecc_verify_256_nb(sp_ecc_ctx_t* ctx, const byte* hash,
  323. word32 hashLen, const mp_int* pX, const mp_int* pY, const mp_int* pZ,
  324. const mp_int* r, const mp_int* sm, int* res, void* heap);
  325. WOLFSSL_LOCAL int sp_ecc_make_key_384_nb(sp_ecc_ctx_t* sp_ctx, WC_RNG* rng,
  326. mp_int* priv, ecc_point* pub, void* heap);
  327. WOLFSSL_LOCAL int sp_ecc_secret_gen_384_nb(sp_ecc_ctx_t* sp_ctx,
  328. const mp_int* priv, const ecc_point* pub, byte* out, word32* outLen,
  329. void* heap);
  330. WOLFSSL_LOCAL int sp_ecc_sign_384_nb(sp_ecc_ctx_t* ctx, const byte* hash,
  331. word32 hashLen, WC_RNG* rng, mp_int* priv, mp_int* rm, mp_int* sm,
  332. mp_int* km, void* heap);
  333. WOLFSSL_LOCAL int sp_ecc_verify_384_nb(sp_ecc_ctx_t* ctx, const byte* hash,
  334. word32 hashLen, const mp_int* pX, const mp_int* pY, const mp_int* pZ,
  335. const mp_int* r, const mp_int* sm, int* res, void* heap);
  336. WOLFSSL_LOCAL int sp_ecc_make_key_521_nb(sp_ecc_ctx_t* sp_ctx, WC_RNG* rng,
  337. mp_int* priv, ecc_point* pub, void* heap);
  338. WOLFSSL_LOCAL int sp_ecc_secret_gen_521_nb(sp_ecc_ctx_t* sp_ctx,
  339. const mp_int* priv, const ecc_point* pub, byte* out, word32* outLen,
  340. void* heap);
  341. WOLFSSL_LOCAL int sp_ecc_sign_521_nb(sp_ecc_ctx_t* ctx, const byte* hash,
  342. word32 hashLen, WC_RNG* rng, mp_int* priv, mp_int* rm, mp_int* sm,
  343. mp_int* km, void* heap);
  344. WOLFSSL_LOCAL int sp_ecc_verify_521_nb(sp_ecc_ctx_t* ctx, const byte* hash,
  345. word32 hashLen, const mp_int* pX, const mp_int* pY, const mp_int* pZ,
  346. const mp_int* r, const mp_int* sm, int* res, void* heap);
  347. #endif /* WOLFSSL_SP_NONBLOCK */
  348. #ifdef HAVE_ECC_SM2
  349. WOLFSSL_LOCAL int sp_ecc_mulmod_sm2_256(mp_int* km, ecc_point* gm,
  350. ecc_point* rm, int map, void* heap);
  351. WOLFSSL_LOCAL int sp_ecc_mulmod_base_sm2_256(mp_int* km, ecc_point* rm, int map,
  352. void* heap);
  353. WOLFSSL_LOCAL int sp_ecc_make_key_sm2_256(WC_RNG* rng, mp_int* priv,
  354. ecc_point* pub, void* heap);
  355. WOLFSSL_LOCAL int sp_ecc_secret_gen_sm2_256(mp_int* priv, ecc_point* pub,
  356. byte* out, word32* outlen, void* heap);
  357. WOLFSSL_LOCAL int sp_ecc_sign_sm2_256(const byte* hash, word32 hashLen,
  358. WC_RNG* rng, mp_int* priv, mp_int* rm, mp_int* sm, mp_int* km, void* heap);
  359. WOLFSSL_LOCAL int sp_ecc_verify_sm2_256(const byte* hash, word32 hashLen,
  360. mp_int* pX, mp_int* pY, mp_int* pZ, mp_int* r, mp_int* sm, int* res,
  361. void* heap);
  362. WOLFSSL_LOCAL int sp_ecc_is_point_sm2_256(mp_int* pX, mp_int* pY);
  363. WOLFSSL_LOCAL int sp_ecc_check_key_sm2_256(mp_int* pX, mp_int* pY,
  364. mp_int* privm, void* heap);
  365. WOLFSSL_LOCAL int sp_ecc_proj_add_point_sm2_256(mp_int* pX, mp_int* pY,
  366. mp_int* pZ, mp_int* qX, mp_int* qY, mp_int* qZ, mp_int* rX, mp_int* rY,
  367. mp_int* rZ);
  368. WOLFSSL_LOCAL int sp_ecc_proj_dbl_point_sm2_256(mp_int* pX, mp_int* pY,
  369. mp_int* pZ, mp_int* rX, mp_int* rY, mp_int* rZ);
  370. WOLFSSL_LOCAL int sp_ecc_map_sm2_256(mp_int* pX, mp_int* pY, mp_int* pZ);
  371. WOLFSSL_LOCAL int sp_ecc_uncompress_sm2_256(mp_int* xm, int odd, mp_int* ym);
  372. #endif
  373. #endif /* WOLFSSL_HAVE_SP_ECC */
  374. #ifdef __cplusplus
  375. } /* extern "C" */
  376. #endif
  377. #endif /* WOLFSSL_HAVE_SP_RSA || WOLFSSL_HAVE_SP_DH || WOLFSSL_HAVE_SP_ECC */
  378. #endif /* WOLF_CRYPT_SP_H */