fork of cyassl-lib
Dependents: TLS_cyassl TLS_cyassl
cyassl/ctaocrypt/rsa.h@4:f377303c41be, 2013-09-16 (annotated)
- Committer:
- feb11
- Date:
- Mon Sep 16 09:53:35 2013 +0000
- Revision:
- 4:f377303c41be
- Parent:
- 0:714293de3836
changed settings
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ashleymills | 0:714293de3836 | 1 | /* rsa.h |
ashleymills | 0:714293de3836 | 2 | * |
ashleymills | 0:714293de3836 | 3 | * Copyright (C) 2006-2013 wolfSSL Inc. |
ashleymills | 0:714293de3836 | 4 | * |
ashleymills | 0:714293de3836 | 5 | * This file is part of CyaSSL. |
ashleymills | 0:714293de3836 | 6 | * |
ashleymills | 0:714293de3836 | 7 | * CyaSSL is free software; you can redistribute it and/or modify |
ashleymills | 0:714293de3836 | 8 | * it under the terms of the GNU General Public License as published by |
ashleymills | 0:714293de3836 | 9 | * the Free Software Foundation; either version 2 of the License, or |
ashleymills | 0:714293de3836 | 10 | * (at your option) any later version. |
ashleymills | 0:714293de3836 | 11 | * |
ashleymills | 0:714293de3836 | 12 | * CyaSSL is distributed in the hope that it will be useful, |
ashleymills | 0:714293de3836 | 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
ashleymills | 0:714293de3836 | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
ashleymills | 0:714293de3836 | 15 | * GNU General Public License for more details. |
ashleymills | 0:714293de3836 | 16 | * |
ashleymills | 0:714293de3836 | 17 | * You should have received a copy of the GNU General Public License |
ashleymills | 0:714293de3836 | 18 | * along with this program; if not, write to the Free Software |
ashleymills | 0:714293de3836 | 19 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
ashleymills | 0:714293de3836 | 20 | */ |
ashleymills | 0:714293de3836 | 21 | |
ashleymills | 0:714293de3836 | 22 | #ifndef NO_RSA |
ashleymills | 0:714293de3836 | 23 | |
ashleymills | 0:714293de3836 | 24 | #ifndef CTAO_CRYPT_RSA_H |
ashleymills | 0:714293de3836 | 25 | #define CTAO_CRYPT_RSA_H |
ashleymills | 0:714293de3836 | 26 | |
ashleymills | 0:714293de3836 | 27 | #include <cyassl/ctaocrypt/types.h> |
ashleymills | 0:714293de3836 | 28 | #include <cyassl/ctaocrypt/integer.h> |
ashleymills | 0:714293de3836 | 29 | #include <cyassl/ctaocrypt/random.h> |
ashleymills | 0:714293de3836 | 30 | |
ashleymills | 0:714293de3836 | 31 | #ifdef __cplusplus |
ashleymills | 0:714293de3836 | 32 | extern "C" { |
ashleymills | 0:714293de3836 | 33 | #endif |
ashleymills | 0:714293de3836 | 34 | |
ashleymills | 0:714293de3836 | 35 | #define CYASSL_RSA_CAVIUM_MAGIC 0xBEEF0006 |
ashleymills | 0:714293de3836 | 36 | |
ashleymills | 0:714293de3836 | 37 | enum { |
ashleymills | 0:714293de3836 | 38 | RSA_PUBLIC = 0, |
ashleymills | 0:714293de3836 | 39 | RSA_PRIVATE = 1 |
ashleymills | 0:714293de3836 | 40 | }; |
ashleymills | 0:714293de3836 | 41 | |
ashleymills | 0:714293de3836 | 42 | /* RSA */ |
ashleymills | 0:714293de3836 | 43 | typedef struct RsaKey { |
ashleymills | 0:714293de3836 | 44 | mp_int n, e, d, p, q, dP, dQ, u; |
ashleymills | 0:714293de3836 | 45 | int type; /* public or private */ |
ashleymills | 0:714293de3836 | 46 | void* heap; /* for user memory overrides */ |
ashleymills | 0:714293de3836 | 47 | #ifdef HAVE_CAVIUM |
ashleymills | 0:714293de3836 | 48 | int devId; /* nitrox device id */ |
ashleymills | 0:714293de3836 | 49 | word32 magic; /* using cavium magic */ |
ashleymills | 0:714293de3836 | 50 | word64 contextHandle; /* nitrox context memory handle */ |
ashleymills | 0:714293de3836 | 51 | byte* c_n; /* cavium byte buffers for key parts */ |
ashleymills | 0:714293de3836 | 52 | byte* c_e; |
ashleymills | 0:714293de3836 | 53 | byte* c_d; |
ashleymills | 0:714293de3836 | 54 | byte* c_p; |
ashleymills | 0:714293de3836 | 55 | byte* c_q; |
ashleymills | 0:714293de3836 | 56 | byte* c_dP; |
ashleymills | 0:714293de3836 | 57 | byte* c_dQ; |
ashleymills | 0:714293de3836 | 58 | byte* c_u; /* sizes in bytes */ |
ashleymills | 0:714293de3836 | 59 | word16 c_nSz, c_eSz, c_dSz, c_pSz, c_qSz, c_dP_Sz, c_dQ_Sz, c_uSz; |
ashleymills | 0:714293de3836 | 60 | #endif |
ashleymills | 0:714293de3836 | 61 | } RsaKey; |
ashleymills | 0:714293de3836 | 62 | |
ashleymills | 0:714293de3836 | 63 | |
ashleymills | 0:714293de3836 | 64 | CYASSL_API void InitRsaKey(RsaKey* key, void*); |
ashleymills | 0:714293de3836 | 65 | CYASSL_API void FreeRsaKey(RsaKey* key); |
ashleymills | 0:714293de3836 | 66 | |
ashleymills | 0:714293de3836 | 67 | CYASSL_API int RsaPublicEncrypt(const byte* in, word32 inLen, byte* out, |
ashleymills | 0:714293de3836 | 68 | word32 outLen, RsaKey* key, RNG* rng); |
ashleymills | 0:714293de3836 | 69 | CYASSL_API int RsaPrivateDecryptInline(byte* in, word32 inLen, byte** out, |
ashleymills | 0:714293de3836 | 70 | RsaKey* key); |
ashleymills | 0:714293de3836 | 71 | CYASSL_API int RsaPrivateDecrypt(const byte* in, word32 inLen, byte* out, |
ashleymills | 0:714293de3836 | 72 | word32 outLen, RsaKey* key); |
ashleymills | 0:714293de3836 | 73 | CYASSL_API int RsaSSL_Sign(const byte* in, word32 inLen, byte* out, |
ashleymills | 0:714293de3836 | 74 | word32 outLen, RsaKey* key, RNG* rng); |
ashleymills | 0:714293de3836 | 75 | CYASSL_API int RsaSSL_VerifyInline(byte* in, word32 inLen, byte** out, |
ashleymills | 0:714293de3836 | 76 | RsaKey* key); |
ashleymills | 0:714293de3836 | 77 | CYASSL_API int RsaSSL_Verify(const byte* in, word32 inLen, byte* out, |
ashleymills | 0:714293de3836 | 78 | word32 outLen, RsaKey* key); |
ashleymills | 0:714293de3836 | 79 | CYASSL_API int RsaEncryptSize(RsaKey* key); |
ashleymills | 0:714293de3836 | 80 | |
ashleymills | 0:714293de3836 | 81 | CYASSL_API int RsaPrivateKeyDecode(const byte* input, word32* inOutIdx, RsaKey*, |
ashleymills | 0:714293de3836 | 82 | word32); |
ashleymills | 0:714293de3836 | 83 | CYASSL_API int RsaPublicKeyDecode(const byte* input, word32* inOutIdx, RsaKey*, |
ashleymills | 0:714293de3836 | 84 | word32); |
ashleymills | 0:714293de3836 | 85 | #ifdef CYASSL_KEY_GEN |
ashleymills | 0:714293de3836 | 86 | CYASSL_API int MakeRsaKey(RsaKey* key, int size, long e, RNG* rng); |
ashleymills | 0:714293de3836 | 87 | CYASSL_API int RsaKeyToDer(RsaKey*, byte* output, word32 inLen); |
ashleymills | 0:714293de3836 | 88 | #endif |
ashleymills | 0:714293de3836 | 89 | |
ashleymills | 0:714293de3836 | 90 | #ifdef HAVE_CAVIUM |
ashleymills | 0:714293de3836 | 91 | CYASSL_API int RsaInitCavium(RsaKey*, int); |
ashleymills | 0:714293de3836 | 92 | CYASSL_API void RsaFreeCavium(RsaKey*); |
ashleymills | 0:714293de3836 | 93 | #endif |
ashleymills | 0:714293de3836 | 94 | |
ashleymills | 0:714293de3836 | 95 | |
ashleymills | 0:714293de3836 | 96 | #ifdef __cplusplus |
ashleymills | 0:714293de3836 | 97 | } /* extern "C" */ |
ashleymills | 0:714293de3836 | 98 | #endif |
ashleymills | 0:714293de3836 | 99 | |
ashleymills | 0:714293de3836 | 100 | #endif /* CTAO_CRYPT_RSA_H */ |
ashleymills | 0:714293de3836 | 101 | |
ashleymills | 0:714293de3836 | 102 | #endif /* NO_RSA */ |