Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
wolfssl/wolfcrypt/dh.h@15:117db924cf7c, 2018-08-18 (annotated)
- Committer:
- wolfSSL
- Date:
- Sat Aug 18 22:20:43 2018 +0000
- Revision:
- 15:117db924cf7c
wolfSSL 3.15.3
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
wolfSSL | 15:117db924cf7c | 1 | /* dh.h |
wolfSSL | 15:117db924cf7c | 2 | * |
wolfSSL | 15:117db924cf7c | 3 | * Copyright (C) 2006-2017 wolfSSL Inc. |
wolfSSL | 15:117db924cf7c | 4 | * |
wolfSSL | 15:117db924cf7c | 5 | * This file is part of wolfSSL. |
wolfSSL | 15:117db924cf7c | 6 | * |
wolfSSL | 15:117db924cf7c | 7 | * wolfSSL is free software; you can redistribute it and/or modify |
wolfSSL | 15:117db924cf7c | 8 | * it under the terms of the GNU General Public License as published by |
wolfSSL | 15:117db924cf7c | 9 | * the Free Software Foundation; either version 2 of the License, or |
wolfSSL | 15:117db924cf7c | 10 | * (at your option) any later version. |
wolfSSL | 15:117db924cf7c | 11 | * |
wolfSSL | 15:117db924cf7c | 12 | * wolfSSL is distributed in the hope that it will be useful, |
wolfSSL | 15:117db924cf7c | 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
wolfSSL | 15:117db924cf7c | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
wolfSSL | 15:117db924cf7c | 15 | * GNU General Public License for more details. |
wolfSSL | 15:117db924cf7c | 16 | * |
wolfSSL | 15:117db924cf7c | 17 | * You should have received a copy of the GNU General Public License |
wolfSSL | 15:117db924cf7c | 18 | * along with this program; if not, write to the Free Software |
wolfSSL | 15:117db924cf7c | 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA |
wolfSSL | 15:117db924cf7c | 20 | */ |
wolfSSL | 15:117db924cf7c | 21 | |
wolfSSL | 15:117db924cf7c | 22 | /*! |
wolfSSL | 15:117db924cf7c | 23 | \file wolfssl/wolfcrypt/dh.h |
wolfSSL | 15:117db924cf7c | 24 | */ |
wolfSSL | 15:117db924cf7c | 25 | |
wolfSSL | 15:117db924cf7c | 26 | #ifndef WOLF_CRYPT_DH_H |
wolfSSL | 15:117db924cf7c | 27 | #define WOLF_CRYPT_DH_H |
wolfSSL | 15:117db924cf7c | 28 | |
wolfSSL | 15:117db924cf7c | 29 | #include <wolfssl/wolfcrypt/types.h> |
wolfSSL | 15:117db924cf7c | 30 | |
wolfSSL | 15:117db924cf7c | 31 | #ifndef NO_DH |
wolfSSL | 15:117db924cf7c | 32 | |
wolfSSL | 15:117db924cf7c | 33 | #if defined(HAVE_FIPS) && \ |
wolfSSL | 15:117db924cf7c | 34 | defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2) |
wolfSSL | 15:117db924cf7c | 35 | #include <wolfssl/wolfcrypt/fips.h> |
wolfSSL | 15:117db924cf7c | 36 | #endif /* HAVE_FIPS_VERSION >= 2 */ |
wolfSSL | 15:117db924cf7c | 37 | |
wolfSSL | 15:117db924cf7c | 38 | #include <wolfssl/wolfcrypt/integer.h> |
wolfSSL | 15:117db924cf7c | 39 | #include <wolfssl/wolfcrypt/random.h> |
wolfSSL | 15:117db924cf7c | 40 | |
wolfSSL | 15:117db924cf7c | 41 | #ifdef __cplusplus |
wolfSSL | 15:117db924cf7c | 42 | extern "C" { |
wolfSSL | 15:117db924cf7c | 43 | #endif |
wolfSSL | 15:117db924cf7c | 44 | |
wolfSSL | 15:117db924cf7c | 45 | #ifdef WOLFSSL_ASYNC_CRYPT |
wolfSSL | 15:117db924cf7c | 46 | #include <wolfssl/wolfcrypt/async.h> |
wolfSSL | 15:117db924cf7c | 47 | #endif |
wolfSSL | 15:117db924cf7c | 48 | typedef struct DhParams { |
wolfSSL | 15:117db924cf7c | 49 | #ifdef HAVE_FFDHE_Q |
wolfSSL | 15:117db924cf7c | 50 | const byte* q; |
wolfSSL | 15:117db924cf7c | 51 | word32 q_len; |
wolfSSL | 15:117db924cf7c | 52 | #endif /* HAVE_FFDHE_Q */ |
wolfSSL | 15:117db924cf7c | 53 | const byte* p; |
wolfSSL | 15:117db924cf7c | 54 | word32 p_len; |
wolfSSL | 15:117db924cf7c | 55 | const byte* g; |
wolfSSL | 15:117db924cf7c | 56 | word32 g_len; |
wolfSSL | 15:117db924cf7c | 57 | } DhParams; |
wolfSSL | 15:117db924cf7c | 58 | |
wolfSSL | 15:117db924cf7c | 59 | /* Diffie-Hellman Key */ |
wolfSSL | 15:117db924cf7c | 60 | typedef struct DhKey { |
wolfSSL | 15:117db924cf7c | 61 | mp_int p, g, q; /* group parameters */ |
wolfSSL | 15:117db924cf7c | 62 | void* heap; |
wolfSSL | 15:117db924cf7c | 63 | #ifdef WOLFSSL_ASYNC_CRYPT |
wolfSSL | 15:117db924cf7c | 64 | WC_ASYNC_DEV asyncDev; |
wolfSSL | 15:117db924cf7c | 65 | #endif |
wolfSSL | 15:117db924cf7c | 66 | } DhKey; |
wolfSSL | 15:117db924cf7c | 67 | |
wolfSSL | 15:117db924cf7c | 68 | |
wolfSSL | 15:117db924cf7c | 69 | #ifdef HAVE_FFDHE_2048 |
wolfSSL | 15:117db924cf7c | 70 | WOLFSSL_API const DhParams* wc_Dh_ffdhe2048_Get(void); |
wolfSSL | 15:117db924cf7c | 71 | #endif |
wolfSSL | 15:117db924cf7c | 72 | #ifdef HAVE_FFDHE_3072 |
wolfSSL | 15:117db924cf7c | 73 | WOLFSSL_API const DhParams* wc_Dh_ffdhe3072_Get(void); |
wolfSSL | 15:117db924cf7c | 74 | #endif |
wolfSSL | 15:117db924cf7c | 75 | #ifdef HAVE_FFDHE_4096 |
wolfSSL | 15:117db924cf7c | 76 | WOLFSSL_API const DhParams* wc_Dh_ffdhe4096_Get(void); |
wolfSSL | 15:117db924cf7c | 77 | #endif |
wolfSSL | 15:117db924cf7c | 78 | #ifdef HAVE_FFDHE_6144 |
wolfSSL | 15:117db924cf7c | 79 | WOLFSSL_API const DhParams* wc_Dh_ffdhe6144_Get(void); |
wolfSSL | 15:117db924cf7c | 80 | #endif |
wolfSSL | 15:117db924cf7c | 81 | #ifdef HAVE_FFDHE_8192 |
wolfSSL | 15:117db924cf7c | 82 | WOLFSSL_API const DhParams* wc_Dh_ffdhe8192_Get(void); |
wolfSSL | 15:117db924cf7c | 83 | #endif |
wolfSSL | 15:117db924cf7c | 84 | |
wolfSSL | 15:117db924cf7c | 85 | WOLFSSL_API int wc_InitDhKey(DhKey* key); |
wolfSSL | 15:117db924cf7c | 86 | WOLFSSL_API int wc_InitDhKey_ex(DhKey* key, void* heap, int devId); |
wolfSSL | 15:117db924cf7c | 87 | WOLFSSL_API int wc_FreeDhKey(DhKey* key); |
wolfSSL | 15:117db924cf7c | 88 | |
wolfSSL | 15:117db924cf7c | 89 | WOLFSSL_API int wc_DhGenerateKeyPair(DhKey* key, WC_RNG* rng, byte* priv, |
wolfSSL | 15:117db924cf7c | 90 | word32* privSz, byte* pub, word32* pubSz); |
wolfSSL | 15:117db924cf7c | 91 | WOLFSSL_API int wc_DhAgree(DhKey* key, byte* agree, word32* agreeSz, |
wolfSSL | 15:117db924cf7c | 92 | const byte* priv, word32 privSz, const byte* otherPub, |
wolfSSL | 15:117db924cf7c | 93 | word32 pubSz); |
wolfSSL | 15:117db924cf7c | 94 | |
wolfSSL | 15:117db924cf7c | 95 | WOLFSSL_API int wc_DhKeyDecode(const byte* input, word32* inOutIdx, DhKey* key, |
wolfSSL | 15:117db924cf7c | 96 | word32); |
wolfSSL | 15:117db924cf7c | 97 | WOLFSSL_API int wc_DhSetKey(DhKey* key, const byte* p, word32 pSz, const byte* g, |
wolfSSL | 15:117db924cf7c | 98 | word32 gSz); |
wolfSSL | 15:117db924cf7c | 99 | WOLFSSL_API int wc_DhSetKey_ex(DhKey* key, const byte* p, word32 pSz, |
wolfSSL | 15:117db924cf7c | 100 | const byte* g, word32 gSz, const byte* q, word32 qSz); |
wolfSSL | 15:117db924cf7c | 101 | WOLFSSL_API int wc_DhParamsLoad(const byte* input, word32 inSz, byte* p, |
wolfSSL | 15:117db924cf7c | 102 | word32* pInOutSz, byte* g, word32* gInOutSz); |
wolfSSL | 15:117db924cf7c | 103 | WOLFSSL_API int wc_DhCheckPubKey(DhKey* key, const byte* pub, word32 pubSz); |
wolfSSL | 15:117db924cf7c | 104 | WOLFSSL_API int wc_DhCheckPubKey_ex(DhKey* key, const byte* pub, word32 pubSz, |
wolfSSL | 15:117db924cf7c | 105 | const byte* prime, word32 primeSz); |
wolfSSL | 15:117db924cf7c | 106 | WOLFSSL_API int wc_DhCheckPrivKey(DhKey* key, const byte* priv, word32 pubSz); |
wolfSSL | 15:117db924cf7c | 107 | WOLFSSL_API int wc_DhCheckPrivKey_ex(DhKey* key, const byte* priv, word32 pubSz, |
wolfSSL | 15:117db924cf7c | 108 | const byte* prime, word32 primeSz); |
wolfSSL | 15:117db924cf7c | 109 | WOLFSSL_API int wc_DhCheckKeyPair(DhKey* key, const byte* pub, word32 pubSz, |
wolfSSL | 15:117db924cf7c | 110 | const byte* priv, word32 privSz); |
wolfSSL | 15:117db924cf7c | 111 | WOLFSSL_API int wc_DhGenerateParams(WC_RNG *rng, int modSz, DhKey *dh); |
wolfSSL | 15:117db924cf7c | 112 | WOLFSSL_API int wc_DhExportParamsRaw(DhKey* dh, byte* p, word32* pSz, |
wolfSSL | 15:117db924cf7c | 113 | byte* q, word32* qSz, byte* g, word32* gSz); |
wolfSSL | 15:117db924cf7c | 114 | |
wolfSSL | 15:117db924cf7c | 115 | |
wolfSSL | 15:117db924cf7c | 116 | #ifdef __cplusplus |
wolfSSL | 15:117db924cf7c | 117 | } /* extern "C" */ |
wolfSSL | 15:117db924cf7c | 118 | #endif |
wolfSSL | 15:117db924cf7c | 119 | |
wolfSSL | 15:117db924cf7c | 120 | #endif /* NO_DH */ |
wolfSSL | 15:117db924cf7c | 121 | #endif /* WOLF_CRYPT_DH_H */ |
wolfSSL | 15:117db924cf7c | 122 | |
wolfSSL | 15:117db924cf7c | 123 |