3 * Copyright (C) 2006-2014 wolfSSL Inc.
5 * This file is part of CyaSSL.
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.
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.
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
24 #ifndef CTAO_CRYPT_RSA_H
25 #define CTAO_CRYPT_RSA_H
27 #include <cyassl/ctaocrypt/types.h>
28 #include <cyassl/ctaocrypt/integer.h>
29 #include <cyassl/ctaocrypt/random.h>
35 #define CYASSL_RSA_CAVIUM_MAGIC 0xBEEF0006
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 */
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 */
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;
64 CYASSL_API int InitRsaKey(RsaKey* key, void*);
65 CYASSL_API int FreeRsaKey(RsaKey* key);
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,
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,
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);
81 CYASSL_API int RsaPrivateKeyDecode(const byte* input, word32* inOutIdx, RsaKey*,
83 CYASSL_API int RsaPublicKeyDecode(const byte* input, word32* inOutIdx, RsaKey*,
86 CYASSL_API int MakeRsaKey(RsaKey* key, int size, long e, RNG* rng);
87 CYASSL_API int RsaKeyToDer(RsaKey*, byte* output, word32 inLen);
91 CYASSL_API int RsaInitCavium(RsaKey*, int);
92 CYASSL_API void RsaFreeCavium(RsaKey*);
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);
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,
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);
115 CYASSL_API int RsaPrivateKeyDecode_fips(const byte* input, word32* inOutIdx,
117 CYASSL_API int RsaPublicKeyDecode_fips(const byte* input, word32* inOutIdx,
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 */
133 #endif /* HAVE_FIPS */
140 #endif /* CTAO_CRYPT_RSA_H */