A library for setting up Secure Socket Layer (SSL) connections and verifying remote hosts using certificates. Contains only the source files for mbed platform implementation of the library.
Dependents: HTTPClient-SSL HTTPClient-SSL HTTPClient-SSL HTTPClient-SSL
cyassl/ctaocrypt/rsa.h@6:cf58d49e1a86, 2015-03-23 (annotated)
- Committer:
- Mike Fiore
- Date:
- Mon Mar 23 16:51:07 2015 -0500
- Revision:
- 6:cf58d49e1a86
- Parent:
- 0:b86d15c6ba29
fix whitespace in sha512.c
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Vanger | 0:b86d15c6ba29 | 1 | /* rsa.h |
Vanger | 0:b86d15c6ba29 | 2 | * |
Vanger | 0:b86d15c6ba29 | 3 | * Copyright (C) 2006-2014 wolfSSL Inc. |
Vanger | 0:b86d15c6ba29 | 4 | * |
Vanger | 0:b86d15c6ba29 | 5 | * This file is part of CyaSSL. |
Vanger | 0:b86d15c6ba29 | 6 | * |
Vanger | 0:b86d15c6ba29 | 7 | * CyaSSL is free software; you can redistribute it and/or modify |
Vanger | 0:b86d15c6ba29 | 8 | * it under the terms of the GNU General Public License as published by |
Vanger | 0:b86d15c6ba29 | 9 | * the Free Software Foundation; either version 2 of the License, or |
Vanger | 0:b86d15c6ba29 | 10 | * (at your option) any later version. |
Vanger | 0:b86d15c6ba29 | 11 | * |
Vanger | 0:b86d15c6ba29 | 12 | * CyaSSL is distributed in the hope that it will be useful, |
Vanger | 0:b86d15c6ba29 | 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
Vanger | 0:b86d15c6ba29 | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
Vanger | 0:b86d15c6ba29 | 15 | * GNU General Public License for more details. |
Vanger | 0:b86d15c6ba29 | 16 | * |
Vanger | 0:b86d15c6ba29 | 17 | * You should have received a copy of the GNU General Public License |
Vanger | 0:b86d15c6ba29 | 18 | * along with this program; if not, write to the Free Software |
Vanger | 0:b86d15c6ba29 | 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
Vanger | 0:b86d15c6ba29 | 20 | */ |
Vanger | 0:b86d15c6ba29 | 21 | |
Vanger | 0:b86d15c6ba29 | 22 | #ifndef NO_RSA |
Vanger | 0:b86d15c6ba29 | 23 | |
Vanger | 0:b86d15c6ba29 | 24 | #ifndef CTAO_CRYPT_RSA_H |
Vanger | 0:b86d15c6ba29 | 25 | #define CTAO_CRYPT_RSA_H |
Vanger | 0:b86d15c6ba29 | 26 | |
Vanger | 0:b86d15c6ba29 | 27 | #include <cyassl/ctaocrypt/types.h> |
Vanger | 0:b86d15c6ba29 | 28 | #include <cyassl/ctaocrypt/integer.h> |
Vanger | 0:b86d15c6ba29 | 29 | #include <cyassl/ctaocrypt/random.h> |
Vanger | 0:b86d15c6ba29 | 30 | |
Vanger | 0:b86d15c6ba29 | 31 | #ifdef __cplusplus |
Vanger | 0:b86d15c6ba29 | 32 | extern "C" { |
Vanger | 0:b86d15c6ba29 | 33 | #endif |
Vanger | 0:b86d15c6ba29 | 34 | |
Vanger | 0:b86d15c6ba29 | 35 | #define CYASSL_RSA_CAVIUM_MAGIC 0xBEEF0006 |
Vanger | 0:b86d15c6ba29 | 36 | |
Vanger | 0:b86d15c6ba29 | 37 | enum { |
Vanger | 0:b86d15c6ba29 | 38 | RSA_PUBLIC = 0, |
Vanger | 0:b86d15c6ba29 | 39 | RSA_PRIVATE = 1 |
Vanger | 0:b86d15c6ba29 | 40 | }; |
Vanger | 0:b86d15c6ba29 | 41 | |
Vanger | 0:b86d15c6ba29 | 42 | /* RSA */ |
Vanger | 0:b86d15c6ba29 | 43 | typedef struct RsaKey { |
Vanger | 0:b86d15c6ba29 | 44 | mp_int n, e, d, p, q, dP, dQ, u; |
Vanger | 0:b86d15c6ba29 | 45 | int type; /* public or private */ |
Vanger | 0:b86d15c6ba29 | 46 | void* heap; /* for user memory overrides */ |
Vanger | 0:b86d15c6ba29 | 47 | #ifdef HAVE_CAVIUM |
Vanger | 0:b86d15c6ba29 | 48 | int devId; /* nitrox device id */ |
Vanger | 0:b86d15c6ba29 | 49 | word32 magic; /* using cavium magic */ |
Vanger | 0:b86d15c6ba29 | 50 | word64 contextHandle; /* nitrox context memory handle */ |
Vanger | 0:b86d15c6ba29 | 51 | byte* c_n; /* cavium byte buffers for key parts */ |
Vanger | 0:b86d15c6ba29 | 52 | byte* c_e; |
Vanger | 0:b86d15c6ba29 | 53 | byte* c_d; |
Vanger | 0:b86d15c6ba29 | 54 | byte* c_p; |
Vanger | 0:b86d15c6ba29 | 55 | byte* c_q; |
Vanger | 0:b86d15c6ba29 | 56 | byte* c_dP; |
Vanger | 0:b86d15c6ba29 | 57 | byte* c_dQ; |
Vanger | 0:b86d15c6ba29 | 58 | byte* c_u; /* sizes in bytes */ |
Vanger | 0:b86d15c6ba29 | 59 | word16 c_nSz, c_eSz, c_dSz, c_pSz, c_qSz, c_dP_Sz, c_dQ_Sz, c_uSz; |
Vanger | 0:b86d15c6ba29 | 60 | #endif |
Vanger | 0:b86d15c6ba29 | 61 | } RsaKey; |
Vanger | 0:b86d15c6ba29 | 62 | |
Vanger | 0:b86d15c6ba29 | 63 | |
Vanger | 0:b86d15c6ba29 | 64 | CYASSL_API int InitRsaKey(RsaKey* key, void*); |
Vanger | 0:b86d15c6ba29 | 65 | CYASSL_API int FreeRsaKey(RsaKey* key); |
Vanger | 0:b86d15c6ba29 | 66 | |
Vanger | 0:b86d15c6ba29 | 67 | CYASSL_API int RsaPublicEncrypt(const byte* in, word32 inLen, byte* out, |
Vanger | 0:b86d15c6ba29 | 68 | word32 outLen, RsaKey* key, RNG* rng); |
Vanger | 0:b86d15c6ba29 | 69 | CYASSL_API int RsaPrivateDecryptInline(byte* in, word32 inLen, byte** out, |
Vanger | 0:b86d15c6ba29 | 70 | RsaKey* key); |
Vanger | 0:b86d15c6ba29 | 71 | CYASSL_API int RsaPrivateDecrypt(const byte* in, word32 inLen, byte* out, |
Vanger | 0:b86d15c6ba29 | 72 | word32 outLen, RsaKey* key); |
Vanger | 0:b86d15c6ba29 | 73 | CYASSL_API int RsaSSL_Sign(const byte* in, word32 inLen, byte* out, |
Vanger | 0:b86d15c6ba29 | 74 | word32 outLen, RsaKey* key, RNG* rng); |
Vanger | 0:b86d15c6ba29 | 75 | CYASSL_API int RsaSSL_VerifyInline(byte* in, word32 inLen, byte** out, |
Vanger | 0:b86d15c6ba29 | 76 | RsaKey* key); |
Vanger | 0:b86d15c6ba29 | 77 | CYASSL_API int RsaSSL_Verify(const byte* in, word32 inLen, byte* out, |
Vanger | 0:b86d15c6ba29 | 78 | word32 outLen, RsaKey* key); |
Vanger | 0:b86d15c6ba29 | 79 | CYASSL_API int RsaEncryptSize(RsaKey* key); |
Vanger | 0:b86d15c6ba29 | 80 | |
Vanger | 0:b86d15c6ba29 | 81 | CYASSL_API int RsaPrivateKeyDecode(const byte* input, word32* inOutIdx, RsaKey*, |
Vanger | 0:b86d15c6ba29 | 82 | word32); |
Vanger | 0:b86d15c6ba29 | 83 | CYASSL_API int RsaPublicKeyDecode(const byte* input, word32* inOutIdx, RsaKey*, |
Vanger | 0:b86d15c6ba29 | 84 | word32); |
Vanger | 0:b86d15c6ba29 | 85 | CYASSL_API int RsaPublicKeyDecodeRaw(const byte* n, word32 nSz, const byte* e, |
Vanger | 0:b86d15c6ba29 | 86 | word32 eSz, RsaKey* key); |
Vanger | 0:b86d15c6ba29 | 87 | CYASSL_API int RsaFlattenPublicKey(RsaKey*, byte*, word32*, byte*, word32*); |
Vanger | 0:b86d15c6ba29 | 88 | |
Vanger | 0:b86d15c6ba29 | 89 | #ifdef CYASSL_KEY_GEN |
Vanger | 0:b86d15c6ba29 | 90 | CYASSL_API int MakeRsaKey(RsaKey* key, int size, long e, RNG* rng); |
Vanger | 0:b86d15c6ba29 | 91 | CYASSL_API int RsaKeyToDer(RsaKey*, byte* output, word32 inLen); |
Vanger | 0:b86d15c6ba29 | 92 | #endif |
Vanger | 0:b86d15c6ba29 | 93 | |
Vanger | 0:b86d15c6ba29 | 94 | #ifdef HAVE_CAVIUM |
Vanger | 0:b86d15c6ba29 | 95 | CYASSL_API int RsaInitCavium(RsaKey*, int); |
Vanger | 0:b86d15c6ba29 | 96 | CYASSL_API void RsaFreeCavium(RsaKey*); |
Vanger | 0:b86d15c6ba29 | 97 | #endif |
Vanger | 0:b86d15c6ba29 | 98 | |
Vanger | 0:b86d15c6ba29 | 99 | |
Vanger | 0:b86d15c6ba29 | 100 | #ifdef HAVE_FIPS |
Vanger | 0:b86d15c6ba29 | 101 | /* fips wrapper calls, user can call direct */ |
Vanger | 0:b86d15c6ba29 | 102 | CYASSL_API int InitRsaKey_fips(RsaKey* key, void*); |
Vanger | 0:b86d15c6ba29 | 103 | CYASSL_API int FreeRsaKey_fips(RsaKey* key); |
Vanger | 0:b86d15c6ba29 | 104 | |
Vanger | 0:b86d15c6ba29 | 105 | CYASSL_API int RsaPublicEncrypt_fips(const byte* in,word32 inLen,byte* out, |
Vanger | 0:b86d15c6ba29 | 106 | word32 outLen, RsaKey* key, RNG* rng); |
Vanger | 0:b86d15c6ba29 | 107 | CYASSL_API int RsaPrivateDecryptInline_fips(byte* in, word32 inLen, |
Vanger | 0:b86d15c6ba29 | 108 | byte** out, RsaKey* key); |
Vanger | 0:b86d15c6ba29 | 109 | CYASSL_API int RsaPrivateDecrypt_fips(const byte* in, word32 inLen, |
Vanger | 0:b86d15c6ba29 | 110 | byte* out,word32 outLen,RsaKey* key); |
Vanger | 0:b86d15c6ba29 | 111 | CYASSL_API int RsaSSL_Sign_fips(const byte* in, word32 inLen, byte* out, |
Vanger | 0:b86d15c6ba29 | 112 | word32 outLen, RsaKey* key, RNG* rng); |
Vanger | 0:b86d15c6ba29 | 113 | CYASSL_API int RsaSSL_VerifyInline_fips(byte* in, word32 inLen, byte** out, |
Vanger | 0:b86d15c6ba29 | 114 | RsaKey* key); |
Vanger | 0:b86d15c6ba29 | 115 | CYASSL_API int RsaSSL_Verify_fips(const byte* in, word32 inLen, byte* out, |
Vanger | 0:b86d15c6ba29 | 116 | word32 outLen, RsaKey* key); |
Vanger | 0:b86d15c6ba29 | 117 | CYASSL_API int RsaEncryptSize_fips(RsaKey* key); |
Vanger | 0:b86d15c6ba29 | 118 | |
Vanger | 0:b86d15c6ba29 | 119 | CYASSL_API int RsaPrivateKeyDecode_fips(const byte* input, word32* inOutIdx, |
Vanger | 0:b86d15c6ba29 | 120 | RsaKey*, word32); |
Vanger | 0:b86d15c6ba29 | 121 | CYASSL_API int RsaPublicKeyDecode_fips(const byte* input, word32* inOutIdx, |
Vanger | 0:b86d15c6ba29 | 122 | RsaKey*, word32); |
Vanger | 0:b86d15c6ba29 | 123 | #ifndef FIPS_NO_WRAPPERS |
Vanger | 0:b86d15c6ba29 | 124 | /* if not impl or fips.c impl wrapper force fips calls if fips build */ |
Vanger | 0:b86d15c6ba29 | 125 | #define InitRsaKey InitRsaKey_fips |
Vanger | 0:b86d15c6ba29 | 126 | #define FreeRsaKey FreeRsaKey_fips |
Vanger | 0:b86d15c6ba29 | 127 | #define RsaPublicEncrypt RsaPublicEncrypt_fips |
Vanger | 0:b86d15c6ba29 | 128 | #define RsaPrivateDecryptInline RsaPrivateDecryptInline_fips |
Vanger | 0:b86d15c6ba29 | 129 | #define RsaPrivateDecrypt RsaPrivateDecrypt_fips |
Vanger | 0:b86d15c6ba29 | 130 | #define RsaSSL_Sign RsaSSL_Sign_fips |
Vanger | 0:b86d15c6ba29 | 131 | #define RsaSSL_VerifyInline RsaSSL_VerifyInline_fips |
Vanger | 0:b86d15c6ba29 | 132 | #define RsaSSL_Verify RsaSSL_Verify_fips |
Vanger | 0:b86d15c6ba29 | 133 | #define RsaEncryptSize RsaEncryptSize_fips |
Vanger | 0:b86d15c6ba29 | 134 | /* no implicit KeyDecodes since in asn.c (not rsa.c) */ |
Vanger | 0:b86d15c6ba29 | 135 | #endif /* FIPS_NO_WRAPPERS */ |
Vanger | 0:b86d15c6ba29 | 136 | |
Vanger | 0:b86d15c6ba29 | 137 | #endif /* HAVE_FIPS */ |
Vanger | 0:b86d15c6ba29 | 138 | |
Vanger | 0:b86d15c6ba29 | 139 | |
Vanger | 0:b86d15c6ba29 | 140 | #ifdef __cplusplus |
Vanger | 0:b86d15c6ba29 | 141 | } /* extern "C" */ |
Vanger | 0:b86d15c6ba29 | 142 | #endif |
Vanger | 0:b86d15c6ba29 | 143 | |
Vanger | 0:b86d15c6ba29 | 144 | #endif /* CTAO_CRYPT_RSA_H */ |
Vanger | 0:b86d15c6ba29 | 145 | |
Vanger | 0:b86d15c6ba29 | 146 | #endif /* NO_RSA */ |