This is a port of cyaSSL 2.7.0.

Dependents:   CyaSSL_DTLS_Cellular CyaSSL_DTLS_Ethernet

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers rsa.h Source File

rsa.h

00001 /* rsa.h
00002  *
00003  * Copyright (C) 2006-2013 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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 void InitRsaKey(RsaKey* key, void*);
00065 CYASSL_API void 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 __cplusplus
00097     } /* extern "C" */
00098 #endif
00099 
00100 #endif /* CTAO_CRYPT_RSA_H */
00101 
00102 #endif /* NO_RSA */