wolfSSL SSL/TLS library, support up to TLS1.3

Dependents:   CyaSSL-Twitter-OAuth4Tw Example-client-tls-cert TwitterReader TweetTest ... more

Committer:
wolfSSL
Date:
Fri Jun 26 00:39:20 2015 +0000
Revision:
0:d92f9d21154c
wolfSSL 3.6.0

Who changed what in which revision?

UserRevisionLine numberNew contents of line
wolfSSL 0:d92f9d21154c 1 /* rsa.h
wolfSSL 0:d92f9d21154c 2 *
wolfSSL 0:d92f9d21154c 3 * Copyright (C) 2006-2015 wolfSSL Inc.
wolfSSL 0:d92f9d21154c 4 *
wolfSSL 0:d92f9d21154c 5 * This file is part of wolfSSL. (formerly known as CyaSSL)
wolfSSL 0:d92f9d21154c 6 *
wolfSSL 0:d92f9d21154c 7 * wolfSSL is free software; you can redistribute it and/or modify
wolfSSL 0:d92f9d21154c 8 * it under the terms of the GNU General Public License as published by
wolfSSL 0:d92f9d21154c 9 * the Free Software Foundation; either version 2 of the License, or
wolfSSL 0:d92f9d21154c 10 * (at your option) any later version.
wolfSSL 0:d92f9d21154c 11 *
wolfSSL 0:d92f9d21154c 12 * wolfSSL is distributed in the hope that it will be useful,
wolfSSL 0:d92f9d21154c 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
wolfSSL 0:d92f9d21154c 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
wolfSSL 0:d92f9d21154c 15 * GNU General Public License for more details.
wolfSSL 0:d92f9d21154c 16 *
wolfSSL 0:d92f9d21154c 17 * You should have received a copy of the GNU General Public License
wolfSSL 0:d92f9d21154c 18 * along with this program; if not, write to the Free Software
wolfSSL 0:d92f9d21154c 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
wolfSSL 0:d92f9d21154c 20 */
wolfSSL 0:d92f9d21154c 21
wolfSSL 0:d92f9d21154c 22 #ifndef WOLF_CRYPT_RSA_H
wolfSSL 0:d92f9d21154c 23 #define WOLF_CRYPT_RSA_H
wolfSSL 0:d92f9d21154c 24
wolfSSL 0:d92f9d21154c 25 #include <wolfssl/wolfcrypt/types.h>
wolfSSL 0:d92f9d21154c 26
wolfSSL 0:d92f9d21154c 27 #ifndef NO_RSA
wolfSSL 0:d92f9d21154c 28
wolfSSL 0:d92f9d21154c 29 #ifdef HAVE_FIPS
wolfSSL 0:d92f9d21154c 30 /* for fips @wc_fips */
wolfSSL 0:d92f9d21154c 31 #include <cyassl/ctaocrypt/rsa.h>
wolfSSL 0:d92f9d21154c 32 #if defined(CYASSL_KEY_GEN) && !defined(WOLFSSL_KEY_GEN)
wolfSSL 0:d92f9d21154c 33 #define WOLFSSL_KEY_GEN
wolfSSL 0:d92f9d21154c 34 #endif
wolfSSL 0:d92f9d21154c 35 #else
wolfSSL 0:d92f9d21154c 36 #include <wolfssl/wolfcrypt/integer.h>
wolfSSL 0:d92f9d21154c 37 #include <wolfssl/wolfcrypt/random.h>
wolfSSL 0:d92f9d21154c 38 #endif /* HAVE_FIPS */
wolfSSL 0:d92f9d21154c 39
wolfSSL 0:d92f9d21154c 40 #ifdef __cplusplus
wolfSSL 0:d92f9d21154c 41 extern "C" {
wolfSSL 0:d92f9d21154c 42 #endif
wolfSSL 0:d92f9d21154c 43
wolfSSL 0:d92f9d21154c 44 #ifndef HAVE_FIPS /* avoid redefinition of structs */
wolfSSL 0:d92f9d21154c 45 #define WOLFSSL_RSA_CAVIUM_MAGIC 0xBEEF0006
wolfSSL 0:d92f9d21154c 46
wolfSSL 0:d92f9d21154c 47 enum {
wolfSSL 0:d92f9d21154c 48 RSA_PUBLIC = 0,
wolfSSL 0:d92f9d21154c 49 RSA_PRIVATE = 1
wolfSSL 0:d92f9d21154c 50 };
wolfSSL 0:d92f9d21154c 51
wolfSSL 0:d92f9d21154c 52 /* RSA */
wolfSSL 0:d92f9d21154c 53 typedef struct RsaKey {
wolfSSL 0:d92f9d21154c 54 mp_int n, e, d, p, q, dP, dQ, u;
wolfSSL 0:d92f9d21154c 55 int type; /* public or private */
wolfSSL 0:d92f9d21154c 56 void* heap; /* for user memory overrides */
wolfSSL 0:d92f9d21154c 57 #ifdef HAVE_CAVIUM
wolfSSL 0:d92f9d21154c 58 int devId; /* nitrox device id */
wolfSSL 0:d92f9d21154c 59 word32 magic; /* using cavium magic */
wolfSSL 0:d92f9d21154c 60 word64 contextHandle; /* nitrox context memory handle */
wolfSSL 0:d92f9d21154c 61 byte* c_n; /* cavium byte buffers for key parts */
wolfSSL 0:d92f9d21154c 62 byte* c_e;
wolfSSL 0:d92f9d21154c 63 byte* c_d;
wolfSSL 0:d92f9d21154c 64 byte* c_p;
wolfSSL 0:d92f9d21154c 65 byte* c_q;
wolfSSL 0:d92f9d21154c 66 byte* c_dP;
wolfSSL 0:d92f9d21154c 67 byte* c_dQ;
wolfSSL 0:d92f9d21154c 68 byte* c_u; /* sizes in bytes */
wolfSSL 0:d92f9d21154c 69 word16 c_nSz, c_eSz, c_dSz, c_pSz, c_qSz, c_dP_Sz, c_dQ_Sz, c_uSz;
wolfSSL 0:d92f9d21154c 70 #endif
wolfSSL 0:d92f9d21154c 71 } RsaKey;
wolfSSL 0:d92f9d21154c 72 #endif /*HAVE_FIPS */
wolfSSL 0:d92f9d21154c 73
wolfSSL 0:d92f9d21154c 74
wolfSSL 0:d92f9d21154c 75 WOLFSSL_API int wc_InitRsaKey(RsaKey* key, void*);
wolfSSL 0:d92f9d21154c 76 WOLFSSL_API int wc_FreeRsaKey(RsaKey* key);
wolfSSL 0:d92f9d21154c 77
wolfSSL 0:d92f9d21154c 78 WOLFSSL_API int wc_RsaPublicEncrypt(const byte* in, word32 inLen, byte* out,
wolfSSL 0:d92f9d21154c 79 word32 outLen, RsaKey* key, RNG* rng);
wolfSSL 0:d92f9d21154c 80 WOLFSSL_API int wc_RsaPrivateDecryptInline(byte* in, word32 inLen, byte** out,
wolfSSL 0:d92f9d21154c 81 RsaKey* key);
wolfSSL 0:d92f9d21154c 82 WOLFSSL_API int wc_RsaPrivateDecrypt(const byte* in, word32 inLen, byte* out,
wolfSSL 0:d92f9d21154c 83 word32 outLen, RsaKey* key);
wolfSSL 0:d92f9d21154c 84 WOLFSSL_API int wc_RsaSSL_Sign(const byte* in, word32 inLen, byte* out,
wolfSSL 0:d92f9d21154c 85 word32 outLen, RsaKey* key, RNG* rng);
wolfSSL 0:d92f9d21154c 86 WOLFSSL_API int wc_RsaSSL_VerifyInline(byte* in, word32 inLen, byte** out,
wolfSSL 0:d92f9d21154c 87 RsaKey* key);
wolfSSL 0:d92f9d21154c 88 WOLFSSL_API int wc_RsaSSL_Verify(const byte* in, word32 inLen, byte* out,
wolfSSL 0:d92f9d21154c 89 word32 outLen, RsaKey* key);
wolfSSL 0:d92f9d21154c 90 WOLFSSL_API int wc_RsaEncryptSize(RsaKey* key);
wolfSSL 0:d92f9d21154c 91
wolfSSL 0:d92f9d21154c 92 #ifndef HAVE_FIPS /* to avoid asn duplicate symbols @wc_fips */
wolfSSL 0:d92f9d21154c 93 WOLFSSL_API int wc_RsaPrivateKeyDecode(const byte* input, word32* inOutIdx,
wolfSSL 0:d92f9d21154c 94 RsaKey*, word32);
wolfSSL 0:d92f9d21154c 95 WOLFSSL_API int wc_RsaPublicKeyDecode(const byte* input, word32* inOutIdx,
wolfSSL 0:d92f9d21154c 96 RsaKey*, word32);
wolfSSL 0:d92f9d21154c 97 WOLFSSL_API int wc_RsaPublicKeyDecodeRaw(const byte* n, word32 nSz,
wolfSSL 0:d92f9d21154c 98 const byte* e, word32 eSz, RsaKey* key);
wolfSSL 0:d92f9d21154c 99 #ifdef WOLFSSL_KEY_GEN
wolfSSL 0:d92f9d21154c 100 WOLFSSL_API int wc_RsaKeyToDer(RsaKey*, byte* output, word32 inLen);
wolfSSL 0:d92f9d21154c 101 #endif
wolfSSL 0:d92f9d21154c 102 #endif /* HAVE_FIPS*/
wolfSSL 0:d92f9d21154c 103 WOLFSSL_API int wc_RsaFlattenPublicKey(RsaKey*, byte*, word32*, byte*,
wolfSSL 0:d92f9d21154c 104 word32*);
wolfSSL 0:d92f9d21154c 105
wolfSSL 0:d92f9d21154c 106 #ifdef WOLFSSL_KEY_GEN
wolfSSL 0:d92f9d21154c 107 WOLFSSL_API int wc_MakeRsaKey(RsaKey* key, int size, long e, RNG* rng);
wolfSSL 0:d92f9d21154c 108 #endif
wolfSSL 0:d92f9d21154c 109
wolfSSL 0:d92f9d21154c 110 #ifdef HAVE_CAVIUM
wolfSSL 0:d92f9d21154c 111 WOLFSSL_API int wc_RsaInitCavium(RsaKey*, int);
wolfSSL 0:d92f9d21154c 112 WOLFSSL_API void wc_RsaFreeCavium(RsaKey*);
wolfSSL 0:d92f9d21154c 113 #endif
wolfSSL 0:d92f9d21154c 114
wolfSSL 0:d92f9d21154c 115 #ifdef __cplusplus
wolfSSL 0:d92f9d21154c 116 } /* extern "C" */
wolfSSL 0:d92f9d21154c 117 #endif
wolfSSL 0:d92f9d21154c 118
wolfSSL 0:d92f9d21154c 119 #endif /* NO_RSA */
wolfSSL 0:d92f9d21154c 120 #endif /* WOLF_CRYPT_RSA_H */
wolfSSL 0:d92f9d21154c 121
wolfSSL 0:d92f9d21154c 122