/* ================================================================== >>>>>>>>>>>>>>>>>>>>>>> COPYRIGHT NOTICE <<<<<<<<<<<<<<<<<<<<<<<<< ------------------------------------------------------------------ Copyright (c) 2019-2020 by Lattice Semiconductor Corporation ALL RIGHTS RESERVED ------------------------------------------------------------------ IMPORTANT: THIS FILE IS USED BY OR GENERATED BY the LATTICE PROPELâ„¢ DEVELOPMENT SUITE, WHICH INCLUDES PROPEL BUILDER AND PROPEL SDK. Lattice grants permission to use this code pursuant to the terms of the Lattice Propel License Agreement. DISCLAIMER: LATTICE MAKES NO WARRANTIES ON THIS FILE OR ITS CONTENTS, WHETHER EXPRESSED, IMPLIED, STATUTORY, OR IN ANY PROVISION OF THE LATTICE PROPEL LICENSE AGREEMENT OR COMMUNICATION WITH LICENSEE, AND LATTICE SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. LATTICE DOES NOT WARRANT THAT THE FUNCTIONS CONTAINED HEREIN WILL MEET LICENSEE 'S REQUIREMENTS, OR THAT LICENSEE' S OPERATION OF ANY DEVICE, SOFTWARE OR SYSTEM USING THIS FILE OR ITS CONTENTS WILL BE UNINTERRUPTED OR ERROR FREE, OR THAT DEFECTS HEREIN WILL BE CORRECTED. LICENSEE ASSUMES RESPONSIBILITY FOR SELECTION OF MATERIALS TO ACHIEVE ITS INTENDED RESULTS, AND FOR THE PROPER INSTALLATION, USE, AND RESULTS OBTAINED THEREFROM. LICENSEE ASSUMES THE ENTIRE RISK OF THE FILE AND ITS CONTENTS PROVING DEFECTIVE OR FAILING TO PERFORM PROPERLY AND IN SUCH EVENT, LICENSEE SHALL ASSUME THE ENTIRE COST AND RISK OF ANY REPAIR, SERVICE, CORRECTION, OR ANY OTHER LIABILITIES OR DAMAGES CAUSED BY OR ASSOCIATED WITH THE SOFTWARE.IN NO EVENT SHALL LATTICE BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS FILE OR ITS CONTENTS, EVEN IF LATTICE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. LATTICE 'S SOLE LIABILITY, AND LICENSEE' S SOLE REMEDY, IS SET FORTH ABOVE. LATTICE DOES NOT WARRANT OR REPRESENT THAT THIS FILE, ITS CONTENTS OR USE THEREOF DOES NOT INFRINGE ON THIRD PARTIES' INTELLECTUAL PROPERTY RIGHTS, INCLUDING ANY PATENT. IT IS THE USER' S RESPONSIBILITY TO VERIFY THE USER SOFTWARE DESIGN FOR CONSISTENCY AND FUNCTIONALITY THROUGH THE USE OF FORMAL SOFTWARE VALIDATION METHODS. ------------------------------------------------------------------ ================================================================== */ #ifndef ESB_H_ #define ESB_H_ #define NUM_ECC_DIGITS 32 #define NUM_DIGEST_INT 16 // Digest 16 int extern struct esb_instance esb_machxo3d_esb; typedef struct EccPoint { unsigned char x[NUM_ECC_DIGITS]; unsigned char y[NUM_ECC_DIGITS]; } EccPoint; enum esb_state { ESB_RO_GP0_READY = 0xB0, ESB_RO_GP0_BUSY = 0xB1, ESB_RO_GP0_DONE = 0xB2, }; struct sha256_ctx { unsigned char *data_in; unsigned int length; unsigned int *digest_out; //[NUM_DIGEST_INT]; unsigned char (*spiRead2ESB_fun) (void *this_spi, unsigned int addr, unsigned int len, unsigned char addr4B); void *spi_master; unsigned int start_address; unsigned int image_size; unsigned char addr4B; }; struct esb_instance { char *instance_name; unsigned int base_addr; }; #define ESB_PORT_WISHBONE (2) #define ESB_PORT_HSP (3) unsigned char esb_init(struct esb_instance *this_esb, unsigned int base_addr); unsigned char esb_mux_port_sel(struct esb_instance *this_esb, unsigned int sel_port); unsigned char esb_switch_idle(struct esb_instance *this_esb); unsigned char esb_trng32bits_get(struct esb_instance *this_esb, unsigned int *trn_value); unsigned char esb_nonce_get(struct esb_instance *this_esb, unsigned char p_trn[16]); unsigned char esb_trng256bits_get(struct esb_instance *this_esb, unsigned char p_trn[32]); //Key Exchange unsigned char esb_pubkey_derive(struct esb_instance *this_esb, EccPoint * p_publicKey, unsigned char p_privateKey[NUM_ECC_DIGITS]); unsigned char esb_ecdh_get(struct esb_instance *this_esb, unsigned char p_secret[NUM_ECC_DIGITS], EccPoint * p_publicKey, unsigned char p_privateKey[NUM_ECC_DIGITS]); //AES unsigned char esb_aes(struct esb_instance *this_esb, unsigned char *key, unsigned char *bufferIn, unsigned char *bufferOut, unsigned int decrypt); unsigned char esb_sha256(struct esb_instance *this_esb, struct sha256_ctx *ctx); unsigned char esb_esdsa_verify(struct esb_instance *this_esb, unsigned int digest[], unsigned int pub_key[], unsigned int signature[], unsigned char *auth_pass); unsigned char get_nonce(struct esb_instance *this_esb, unsigned char p_trn[16]); #endif /* ESB_ECDH_H_ */