Fork of CyaSSL for my specific settings
Fork of CyaSSL by
Embed:
(wiki syntax)
Show/hide line numbers
rsa.h
00001 /* rsa.h 00002 * 00003 * Copyright (C) 2006-2014 wolfSSL Inc. 00004 * 00005 * This file is part of CyaSSL. 00006 * 00007 * CyaSSL is free software; you can redistribute it and/or modify 00008 * it under the terms of the GNU General Public License as published by 00009 * the Free Software Foundation; either version 2 of the License, or 00010 * (at your option) any later version. 00011 * 00012 * CyaSSL is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU General Public License 00018 * along with this program; if not, write to the Free Software 00019 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 00020 */ 00021 00022 #ifndef NO_RSA 00023 00024 #ifndef CTAO_CRYPT_RSA_H 00025 #define CTAO_CRYPT_RSA_H 00026 00027 #include <cyassl/ctaocrypt/types.h> 00028 #include <cyassl/ctaocrypt/integer.h> 00029 #include <cyassl/ctaocrypt/random.h> 00030 00031 #ifdef __cplusplus 00032 extern "C" { 00033 #endif 00034 00035 #define CYASSL_RSA_CAVIUM_MAGIC 0xBEEF0006 00036 00037 enum { 00038 RSA_PUBLIC = 0, 00039 RSA_PRIVATE = 1 00040 }; 00041 00042 /* RSA */ 00043 typedef struct RsaKey { 00044 mp_int n, e, d, p, q, dP, dQ, u; 00045 int type; /* public or private */ 00046 void* heap; /* for user memory overrides */ 00047 #ifdef HAVE_CAVIUM 00048 int devId; /* nitrox device id */ 00049 word32 magic; /* using cavium magic */ 00050 word64 contextHandle; /* nitrox context memory handle */ 00051 byte* c_n; /* cavium byte buffers for key parts */ 00052 byte* c_e; 00053 byte* c_d; 00054 byte* c_p; 00055 byte* c_q; 00056 byte* c_dP; 00057 byte* c_dQ; 00058 byte* c_u; /* sizes in bytes */ 00059 word16 c_nSz, c_eSz, c_dSz, c_pSz, c_qSz, c_dP_Sz, c_dQ_Sz, c_uSz; 00060 #endif 00061 } RsaKey; 00062 00063 00064 CYASSL_API int InitRsaKey(RsaKey* key, void*); 00065 CYASSL_API int FreeRsaKey(RsaKey* key); 00066 00067 CYASSL_API int RsaPublicEncrypt(const byte* in, word32 inLen, byte* out, 00068 word32 outLen, RsaKey* key, RNG* rng); 00069 CYASSL_API int RsaPrivateDecryptInline(byte* in, word32 inLen, byte** out, 00070 RsaKey* key); 00071 CYASSL_API int RsaPrivateDecrypt(const byte* in, word32 inLen, byte* out, 00072 word32 outLen, RsaKey* key); 00073 CYASSL_API int RsaSSL_Sign(const byte* in, word32 inLen, byte* out, 00074 word32 outLen, RsaKey* key, RNG* rng); 00075 CYASSL_API int RsaSSL_VerifyInline(byte* in, word32 inLen, byte** out, 00076 RsaKey* key); 00077 CYASSL_API int RsaSSL_Verify(const byte* in, word32 inLen, byte* out, 00078 word32 outLen, RsaKey* key); 00079 CYASSL_API int RsaEncryptSize(RsaKey* key); 00080 00081 CYASSL_API int RsaPrivateKeyDecode(const byte* input, word32* inOutIdx, RsaKey*, 00082 word32); 00083 CYASSL_API int RsaPublicKeyDecode(const byte* input, word32* inOutIdx, RsaKey*, 00084 word32); 00085 #ifdef CYASSL_KEY_GEN 00086 CYASSL_API int MakeRsaKey(RsaKey* key, int size, long e, RNG* rng); 00087 CYASSL_API int RsaKeyToDer(RsaKey*, byte* output, word32 inLen); 00088 #endif 00089 00090 #ifdef HAVE_CAVIUM 00091 CYASSL_API int RsaInitCavium(RsaKey*, int); 00092 CYASSL_API void RsaFreeCavium(RsaKey*); 00093 #endif 00094 00095 00096 #ifdef HAVE_FIPS 00097 /* fips wrapper calls, user can call direct */ 00098 CYASSL_API int InitRsaKey_fips(RsaKey* key, void*); 00099 CYASSL_API int FreeRsaKey_fips(RsaKey* key); 00100 00101 CYASSL_API int RsaPublicEncrypt_fips(const byte* in,word32 inLen,byte* out, 00102 word32 outLen, RsaKey* key, RNG* rng); 00103 CYASSL_API int RsaPrivateDecryptInline_fips(byte* in, word32 inLen, 00104 byte** out, RsaKey* key); 00105 CYASSL_API int RsaPrivateDecrypt_fips(const byte* in, word32 inLen, 00106 byte* out,word32 outLen,RsaKey* key); 00107 CYASSL_API int RsaSSL_Sign_fips(const byte* in, word32 inLen, byte* out, 00108 word32 outLen, RsaKey* key, RNG* rng); 00109 CYASSL_API int RsaSSL_VerifyInline_fips(byte* in, word32 inLen, byte** out, 00110 RsaKey* key); 00111 CYASSL_API int RsaSSL_Verify_fips(const byte* in, word32 inLen, byte* out, 00112 word32 outLen, RsaKey* key); 00113 CYASSL_API int RsaEncryptSize_fips(RsaKey* key); 00114 00115 CYASSL_API int RsaPrivateKeyDecode_fips(const byte* input, word32* inOutIdx, 00116 RsaKey*, word32); 00117 CYASSL_API int RsaPublicKeyDecode_fips(const byte* input, word32* inOutIdx, 00118 RsaKey*, word32); 00119 #ifndef FIPS_NO_WRAPPERS 00120 /* if not impl or fips.c impl wrapper force fips calls if fips build */ 00121 #define InitRsaKey InitRsaKey_fips 00122 #define FreeRsaKey FreeRsaKey_fips 00123 #define RsaPublicEncrypt RsaPublicEncrypt_fips 00124 #define RsaPrivateDecryptInline RsaPrivateDecryptInline_fips 00125 #define RsaPrivateDecrypt RsaPrivateDecrypt_fips 00126 #define RsaSSL_Sign RsaSSL_Sign_fips 00127 #define RsaSSL_VerifyInline RsaSSL_VerifyInline_fips 00128 #define RsaSSL_Verify RsaSSL_Verify_fips 00129 #define RsaEncryptSize RsaEncryptSize_fips 00130 /* no implicit KeyDecodes since in asn.c (not rsa.c) */ 00131 #endif /* FIPS_NO_WRAPPERS */ 00132 00133 #endif /* HAVE_FIPS */ 00134 00135 00136 #ifdef __cplusplus 00137 } /* extern "C" */ 00138 #endif 00139 00140 #endif /* CTAO_CRYPT_RSA_H */ 00141 00142 #endif /* NO_RSA */ 00143
Generated on Tue Jul 12 2022 21:40:05 by 1.7.2