ksdk_port.h
1 /* ksdk_port.h
2  *
3  * Copyright (C) 2006-2020 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 
22 #ifndef _KSDK_PORT_H_
23 #define _KSDK_PORT_H_
24 
25 #include <wolfssl/wolfcrypt/settings.h>
26 #ifdef USE_FAST_MATH
27  #include <wolfssl/wolfcrypt/tfm.h>
28 #elif defined WOLFSSL_SP_MATH
29  #include <wolfssl/wolfcrypt/sp_int.h>
30 #else
31  #include <wolfssl/wolfcrypt/integer.h>
32 #endif
33 #include <wolfssl/wolfcrypt/ecc.h>
36 
37 
38 /* API to init required hardware */
39 int ksdk_port_init(void);
40 
41 /* software algorithm, by wolfcrypt */
42 #if defined(FREESCALE_LTC_TFM)
43  int wolfcrypt_mp_mul(mp_int *A, mp_int *B, mp_int *C);
44  int wolfcrypt_mp_mod(mp_int *a, mp_int *b, mp_int *c);
45  int wolfcrypt_mp_mulmod(mp_int *a, mp_int *b, mp_int *c, mp_int *d);
46  int wolfcrypt_mp_mod(mp_int *a, mp_int *b, mp_int *c);
47  int wolfcrypt_mp_invmod(mp_int *a, mp_int *b, mp_int *c);
48  int wolfcrypt_mp_exptmod(mp_int *G, mp_int *X, mp_int *P, mp_int *Y);
49 
50  /* Exported mp_mulmod function */
51  int mp_mulmod(mp_int *a, mp_int *b, mp_int *c, mp_int *d);
52 
53 #endif /* FREESCALE_LTC_TFM */
54 
55 #if defined(FREESCALE_LTC_ECC)
56  #include "fsl_ltc.h"
57 
58  typedef enum _fsl_ltc_ecc_coordinate_system
59  {
60  kLTC_Weierstrass = 0U, /*< Point coordinates on an elliptic curve in Weierstrass form */
61  kLTC_Curve25519 = 1U, /*< Point coordinates on an Curve25519 elliptic curve in Montgomery form */
62  kLTC_Ed25519 = 2U, /*< Point coordinates on an Ed25519 elliptic curve in twisted Edwards form */
63  } fsl_ltc_ecc_coordinate_system_t;
64 
65  int wc_ecc_point_add(ecc_point *mG, ecc_point *mQ, ecc_point *mR, mp_int *m);
66 
67  #ifdef HAVE_CURVE25519
68  int wc_curve25519(ECPoint *q, byte *n, const ECPoint *p, fsl_ltc_ecc_coordinate_system_t type);
69  const ECPoint *wc_curve25519_GetBasePoint(void);
70  status_t LTC_PKHA_Curve25519ToWeierstrass(const ltc_pkha_ecc_point_t *ltcPointIn, ltc_pkha_ecc_point_t *ltcPointOut);
71  status_t LTC_PKHA_WeierstrassToCurve25519(const ltc_pkha_ecc_point_t *ltcPointIn, ltc_pkha_ecc_point_t *ltcPointOut);
72  status_t LTC_PKHA_Curve25519ComputeY(ltc_pkha_ecc_point_t *ltcPoint);
73  #endif
74 
75  #ifdef HAVE_ED25519
76  status_t LTC_PKHA_Ed25519ToWeierstrass(const ltc_pkha_ecc_point_t *ltcPointIn, ltc_pkha_ecc_point_t *ltcPointOut);
77  status_t LTC_PKHA_WeierstrassToEd25519(const ltc_pkha_ecc_point_t *ltcPointIn, ltc_pkha_ecc_point_t *ltcPointOut);
78  status_t LTC_PKHA_Ed25519_PointMul(const ltc_pkha_ecc_point_t *ltcPointIn,
79  const uint8_t *N,
80  size_t sizeN,
81  ltc_pkha_ecc_point_t *ltcPointOut,
82  fsl_ltc_ecc_coordinate_system_t typeOut);
83  const ltc_pkha_ecc_point_t *LTC_PKHA_Ed25519_BasePoint(void);
84  status_t LTC_PKHA_Ed25519_PointDecompress(const uint8_t *pubkey, size_t pubKeySize, ltc_pkha_ecc_point_t *ltcPointOut);
85  status_t LTC_PKHA_sc_reduce(uint8_t *a);
86  status_t LTC_PKHA_sc_muladd(uint8_t *s, const uint8_t *a, const uint8_t *b, const uint8_t *c);
87  status_t LTC_PKHA_SignatureForVerify(uint8_t *rcheck, const unsigned char *a, const unsigned char *b, ed25519_key *key);
88  status_t LTC_PKHA_Ed25519_Compress(const ltc_pkha_ecc_point_t *ltcPointIn, uint8_t *p);
89  #endif
90 
91 #endif /* FREESCALE_LTC_ECC */
92 
93 #endif /* _KSDK_PORT_H_ */
Definition: integer.h:200
Definition: ecc.h:332
Definition: ed25519.h:78
Definition: curve25519.h:62