cryptoCell.h
1 /* cryptoCell.h
2  *
3  * Copyright (C) 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 WOLFSSL_CRYPTOCELL_H
23 #define WOLFSSL_CRYPTOCELL_H
24 
25 #if defined(WOLFSSL_CRYPTOCELL)
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 
31 
32 #include "sns_silib.h"
33 
34 #ifndef NO_SHA256
35  #include "crys_hash.h"
36  #include "crys_hash_error.h"
37  /* largest possible input data on CC310 DMA. */
38  #define CC310_MAX_LENGTH_DMA (0xFFFF)
39 #endif
40 
41 #ifndef NO_AES
42  #include "ssi_aes.h"
43 
44  typedef struct aes_context_t {
45  SaSiAesUserContext_t user_ctx; /* CC310 AES User context */
46  SaSiAesUserKeyData_t key; /* CC310 AES key structure */
47  SaSiAesEncryptMode_t mode; /* encrypt or decrypt */
48  } aes_context_t;
49  #define CC310_MAX_LENGTH_DMA_AES (0xFFF0)
50 #endif /* NO_AES */
51 
52 #if !defined(WC_NO_RNG)
53  #if defined(WOLFSSL_nRF5x_SDK_15_2)
54 
55 /* To fix warning. MIN/MAX are defined in tfm.h and Nordic (re)defines them */
56  #undef MIN
57  #undef MAX
58 /* includes to use RNG on the nRF52 */
59  #include "nrf_drv_rng.h"
60  #include "nrf_assert.h"
61  #endif
62 
63  /*RNG Global variables*/
64  extern CRYS_RND_State_t wc_rndState;
65  extern CRYS_RND_WorkBuff_t wc_rndWorkBuff;
66  extern SaSiRndGenerateVectWorkFunc_t wc_rndGenVectFunc;
67  int cc310_random_generate(byte* output, word32 size);
68 #endif
69 
70 #ifndef NO_RSA
71  #include "crys_rsa_types.h"
72  #include "crys_rnd.h"
73  #include "crys_rsa_schemes.h"
74  #include "crys_rsa_kg.h"
75  #include "crys_rsa_build.h"
76 
77  typedef struct rsa_context_t {
78  CRYS_RSAUserPrivKey_t privKey;
79  CRYS_RSAUserPubKey_t pubKey;
80  } rsa_context_t;
81 CRYS_RSA_HASH_OpMode_t cc310_hashModeRSA(enum wc_HashType hash_type, int isHashed);
82 #endif
83 
84 #ifdef HAVE_ECC
85  #include "crys_ecpki_kg.h"
86  #include "crys_ecpki_dh.h"
87  #include "crys_ecpki_build.h"
88  #include "crys_ecpki_domain.h"
89  #include "crys_ecpki_ecdsa.h"
90 
91  typedef struct ecc_context_t {
92  CRYS_ECPKI_UserPrivKey_t privKey;
93  CRYS_ECPKI_UserPublKey_t pubKey;
94  } ecc_context_t;
95 
96 CRYS_ECPKI_DomainID_t cc310_mapCurve(int curve_id);
97 CRYS_ECPKI_HASH_OpMode_t cc310_hashModeECC(int hash_size);
98 #endif /* HAVE_ECC */
99 
100 #if !defined(NO_CRYPT_BENCHMARK) && defined(WOLFSSL_nRF5x_SDK_15_2)
101  /* includes to use Real-time counter (RTC) on nRF52840 */
102  #include "nrf_gpio.h"
103  #include "nrf_drv_rtc.h"
104  #include "nrf_drv_clock.h"
105  #include "boards.h"
106  #include <stdint.h>
107  #include <stdbool.h>
108 #endif /* NO_CRYPT_BENCHMARK && WOLFSSL_nRF5x_SDK_15_2*/
109 
110 int cc310_Init(void);
111 void cc310_Free(void);
112 
113 #ifdef __cplusplus
114 }
115 #endif
116 #endif /* WOLFSSL_CRYPTOCELL */
117 #endif /* WOLFSSL_CRYPTOCELL_H */
Definition: cryptoCell.h:44
Definition: cryptoCell.h:77
Definition: cryptoCell.h:91