]> git.sur5r.net Git - freertos/blob - FreeRTOS-Plus/Source/WolfSSL/cyassl/ctaocrypt/rsa.h
Rename the CyaSSL directory to WolfSSL
[freertos] / FreeRTOS-Plus / Source / WolfSSL / cyassl / ctaocrypt / rsa.h
1 /* rsa.h
2  *
3  * Copyright (C) 2006-2014 wolfSSL Inc.
4  *
5  * This file is part of CyaSSL.
6  *
7  * CyaSSL 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  * CyaSSL 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-1301, USA
20  */
21
22 #ifndef NO_RSA
23
24 #ifndef CTAO_CRYPT_RSA_H
25 #define CTAO_CRYPT_RSA_H
26
27 #include <cyassl/ctaocrypt/types.h>
28 #include <cyassl/ctaocrypt/integer.h>
29 #include <cyassl/ctaocrypt/random.h>
30
31 #ifdef __cplusplus
32     extern "C" {
33 #endif
34
35 #define CYASSL_RSA_CAVIUM_MAGIC 0xBEEF0006
36
37 enum {
38     RSA_PUBLIC   = 0,
39     RSA_PRIVATE  = 1
40 };
41
42 /* RSA */
43 typedef struct RsaKey {
44     mp_int n, e, d, p, q, dP, dQ, u;
45     int   type;                               /* public or private */
46     void* heap;                               /* for user memory overrides */
47 #ifdef HAVE_CAVIUM
48     int    devId;           /* nitrox device id */
49     word32 magic;           /* using cavium magic */
50     word64 contextHandle;   /* nitrox context memory handle */
51     byte*  c_n;             /* cavium byte buffers for key parts */
52     byte*  c_e;
53     byte*  c_d;
54     byte*  c_p;
55     byte*  c_q;
56     byte*  c_dP;
57     byte*  c_dQ;
58     byte*  c_u;             /* sizes in bytes */
59     word16 c_nSz, c_eSz, c_dSz, c_pSz, c_qSz, c_dP_Sz, c_dQ_Sz, c_uSz;
60 #endif
61 } RsaKey;
62
63
64 CYASSL_API int  InitRsaKey(RsaKey* key, void*);
65 CYASSL_API int  FreeRsaKey(RsaKey* key);
66
67 CYASSL_API int  RsaPublicEncrypt(const byte* in, word32 inLen, byte* out,
68                                  word32 outLen, RsaKey* key, RNG* rng);
69 CYASSL_API int  RsaPrivateDecryptInline(byte* in, word32 inLen, byte** out,
70                                         RsaKey* key);
71 CYASSL_API int  RsaPrivateDecrypt(const byte* in, word32 inLen, byte* out,
72                                   word32 outLen, RsaKey* key);
73 CYASSL_API int  RsaSSL_Sign(const byte* in, word32 inLen, byte* out,
74                             word32 outLen, RsaKey* key, RNG* rng);
75 CYASSL_API int  RsaSSL_VerifyInline(byte* in, word32 inLen, byte** out,
76                                     RsaKey* key);
77 CYASSL_API int  RsaSSL_Verify(const byte* in, word32 inLen, byte* out,
78                               word32 outLen, RsaKey* key);
79 CYASSL_API int  RsaEncryptSize(RsaKey* key);
80
81 CYASSL_API int RsaPrivateKeyDecode(const byte* input, word32* inOutIdx, RsaKey*,
82                                    word32);
83 CYASSL_API int RsaPublicKeyDecode(const byte* input, word32* inOutIdx, RsaKey*,
84                                   word32);
85 #ifdef CYASSL_KEY_GEN
86     CYASSL_API int MakeRsaKey(RsaKey* key, int size, long e, RNG* rng);
87     CYASSL_API int RsaKeyToDer(RsaKey*, byte* output, word32 inLen);
88 #endif
89
90 #ifdef HAVE_CAVIUM
91     CYASSL_API int  RsaInitCavium(RsaKey*, int);
92     CYASSL_API void RsaFreeCavium(RsaKey*);
93 #endif
94
95
96 #ifdef HAVE_FIPS
97     /* fips wrapper calls, user can call direct */
98     CYASSL_API int  InitRsaKey_fips(RsaKey* key, void*);
99     CYASSL_API int  FreeRsaKey_fips(RsaKey* key);
100
101     CYASSL_API int  RsaPublicEncrypt_fips(const byte* in,word32 inLen,byte* out,
102                                  word32 outLen, RsaKey* key, RNG* rng);
103     CYASSL_API int  RsaPrivateDecryptInline_fips(byte* in, word32 inLen,
104                                                  byte** out, RsaKey* key);
105     CYASSL_API int  RsaPrivateDecrypt_fips(const byte* in, word32 inLen,
106                                            byte* out,word32 outLen,RsaKey* key);
107     CYASSL_API int  RsaSSL_Sign_fips(const byte* in, word32 inLen, byte* out,
108                             word32 outLen, RsaKey* key, RNG* rng);
109     CYASSL_API int  RsaSSL_VerifyInline_fips(byte* in, word32 inLen, byte** out,
110                                     RsaKey* key);
111     CYASSL_API int  RsaSSL_Verify_fips(const byte* in, word32 inLen, byte* out,
112                               word32 outLen, RsaKey* key);
113     CYASSL_API int  RsaEncryptSize_fips(RsaKey* key);
114
115     CYASSL_API int RsaPrivateKeyDecode_fips(const byte* input, word32* inOutIdx,
116                                             RsaKey*, word32);
117     CYASSL_API int RsaPublicKeyDecode_fips(const byte* input, word32* inOutIdx,
118                                            RsaKey*, word32);
119     #ifndef FIPS_NO_WRAPPERS
120         /* if not impl or fips.c impl wrapper force fips calls if fips build */
121         #define InitRsaKey              InitRsaKey_fips 
122         #define FreeRsaKey              FreeRsaKey_fips 
123         #define RsaPublicEncrypt        RsaPublicEncrypt_fips 
124         #define RsaPrivateDecryptInline RsaPrivateDecryptInline_fips 
125         #define RsaPrivateDecrypt       RsaPrivateDecrypt_fips 
126         #define RsaSSL_Sign             RsaSSL_Sign_fips
127         #define RsaSSL_VerifyInline     RsaSSL_VerifyInline_fips
128         #define RsaSSL_Verify           RsaSSL_Verify_fips
129         #define RsaEncryptSize          RsaEncryptSize_fips
130         /* no implicit KeyDecodes since in asn.c (not rsa.c) */
131     #endif /* FIPS_NO_WRAPPERS */
132
133 #endif /* HAVE_FIPS */
134
135
136 #ifdef __cplusplus
137     } /* extern "C" */
138 #endif
139
140 #endif /* CTAO_CRYPT_RSA_H */
141
142 #endif /* NO_RSA */