SmartSnippets DA1459x SDK
crypto_ec.h
Go to the documentation of this file.
1 
44 #ifndef CRYPTO_EC_H_
45 #define CRYPTO_EC_H_
46 
47 #include <stdint.h>
49 #include <hw_ecc_curves.h>
51 #if dg_USE_UECC_LIB
52 //This is needed because uECC curve datatype is part of crypto_uecc_curve structure.
53 #include "uECC.h"
54 #endif
55 
59 typedef struct {
60 #if dg_USE_HW_ECC
61  const uint8_t *q;
62  const uint8_t *n;
63  const uint8_t *Gx;
64  const uint8_t *Gy;
65  const uint8_t *a;
66  const uint8_t *b;
67  uint32_t cmd;
68 #endif
69  uint8_t o_sz;
71 #if dg_USE_UECC_LIB
72  uECC_Curve crypto_uecc_curve;
73 #endif
75 
76 
77 #if dg_ALLOW_DYNAMIC_LIB_PROVIDER
78 
81 CRYPTO_ECC_PROVIDER_RET crypto_ecc_set_curve_lib_provider(CRYPTO_ECC_CURVE curve_type, ECC_CRYPTO_LIB_PROVIDER lib_provider_input);
82 #endif
83 
88 
102 
115 
129 CRYPTO_ECC_PROVIDER_RET crypto_ecc_compute_shared_secret(crypto_ec_params_t *curve, uint8_t *d, uint8_t *Qp, uint8_t *s);
130 
131 
132 #if dg_USE_HW_ECC
133 #define _CRYPTO_EC_CMD(_sb, _sa, _os, _f) \
134  ((_sb << ECC_ECC_COMMAND_REG_ECC_SignB_Pos) | (_sa << ECC_ECC_COMMAND_REG_ECC_SignA_Pos) | \
135  (_os << ECC_ECC_COMMAND_REG_ECC_SizeOfOperands_Pos) | (_f << ECC_ECC_COMMAND_REG_ECC_Field_Pos))
136 
142 #define CRYPTO_EC_PARAMS_SECP192R1 \
143  { hw_ecc_p192_q, hw_ecc_p192_n, hw_ecc_p192_Gx, hw_ecc_p192_Gy, hw_ecc_p192_a, hw_ecc_p192_b, \
144  _CRYPTO_EC_CMD(HW_ECC_CMD_SIGNB_POS, HW_ECC_CMD_SIGNA_POS, HW_ECC_CMD_OP_SIZE_256B, HW_ECC_CMD_FIELD_FP), 24, ECC_CRYPTO_SECP192R1 }
145 
151 #define CRYPTO_EC_PARAMS_SECP224R1 \
152  { hw_ecc_p224_q, hw_ecc_p224_n, hw_ecc_p224_Gx, hw_ecc_p224_Gy, hw_ecc_p224_a, hw_ecc_p224_b, \
153  _CRYPTO_EC_CMD(HW_ECC_CMD_SIGNB_POS, HW_ECC_CMD_SIGNA_POS, HW_ECC_CMD_OP_SIZE_256B, HW_ECC_CMD_FIELD_FP), 28, ECC_CRYPTO_SECP224R1 }
154 
160 #define CRYPTO_EC_PARAMS_SECP256R1 \
161  { hw_ecc_p256_q, hw_ecc_p256_n, hw_ecc_p256_Gx, hw_ecc_p256_Gy, hw_ecc_p256_a, hw_ecc_p256_b, \
162  _CRYPTO_EC_CMD(HW_ECC_CMD_SIGNB_POS, HW_ECC_CMD_SIGNA_POS, HW_ECC_CMD_OP_SIZE_256B, HW_ECC_CMD_FIELD_FP), 32, ECC_CRYPTO_SECP256R1 }
163 
169 #define CRYPTO_EC_PARAMS_CURVE25519 \
170  { hw_ecc_curve25519_p, NULL, hw_ecc_curve25519_G, NULL, hw_ecc_curve25519_a24, NULL, \
171  _CRYPTO_EC_CMD(HW_ECC_CMD_SIGNB_POS, HW_ECC_CMD_SIGNA_POS, HW_ECC_CMD_OP_SIZE_256B, HW_ECC_CMD_FIELD_FP), 32, ECC_CRYPTO_CURVE25519 }
172 
173 #endif /*dg_USE_HW_ECC*/
174 
175 #endif /* CRYPTO_EC_H_ */
176 
crypto_ec_params_t::type
CRYPTO_ECC_CURVE type
Definition: crypto_ec.h:70
CRYPTO_ECC_PROVIDER_RET
CRYPTO_ECC_PROVIDER_RET
ECC Provider API return codes.
Definition: crypto_ecc_provider_params.h:77
crypto_ecc_curve_init
CRYPTO_ECC_PROVIDER_RET crypto_ecc_curve_init(crypto_ec_params_t *curve, CRYPTO_ECC_CURVE curve_type)
Initialize ecc_curve.
crypto_ec_params_t::crypto_uecc_curve
uECC_Curve crypto_uecc_curve
Definition: crypto_ec.h:72
crypto_ecc_compute_shared_secret
CRYPTO_ECC_PROVIDER_RET crypto_ecc_compute_shared_secret(crypto_ec_params_t *curve, uint8_t *d, uint8_t *Qp, uint8_t *s)
Compute shared secret key ecc primitive.
crypto_ec_params_t::o_sz
uint8_t o_sz
Definition: crypto_ec.h:69
ECC_CRYPTO_LIB_PROVIDER
ECC_CRYPTO_LIB_PROVIDER
ECC library providers.
Definition: crypto_ecc_provider_params.h:54
crypto_ecc_provider_params.h
Elliptic curves parameters.
crypto_ecc_provider_function_map.h
ECC curvetype - libprovider mapping macro definitions.
crypto_ecc_compute_private_key
CRYPTO_ECC_PROVIDER_RET crypto_ecc_compute_private_key(crypto_ec_params_t *curve, uint8_t *d)
Compute private key ecc primitive.
crypto_ecc_compute_public_key
CRYPTO_ECC_PROVIDER_RET crypto_ecc_compute_public_key(crypto_ec_params_t *curve, uint8_t *d, uint8_t *Q)
Compute public key ecc primitive.
CRYPTO_ECC_CURVE
CRYPTO_ECC_CURVE
ECC supported curves type.
Definition: crypto_ecc_provider_params.h:64
crypto_ec_params_t
Elliptic curve parameters.
Definition: crypto_ec.h:59