wolfSSL 3.11.1 for TLS1.3 beta
Fork of wolfSSL by
wolfssl/wolfcrypt/dh.h@13:80fb167dafdf, 2017-05-30 (annotated)
- Committer:
- wolfSSL
- Date:
- Tue May 30 06:16:19 2017 +0000
- Revision:
- 13:80fb167dafdf
wolfSSL 3.11.1: TLS1.3 Beta
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
wolfSSL | 13:80fb167dafdf | 1 | /* dh.h |
wolfSSL | 13:80fb167dafdf | 2 | * |
wolfSSL | 13:80fb167dafdf | 3 | * Copyright (C) 2006-2016 wolfSSL Inc. |
wolfSSL | 13:80fb167dafdf | 4 | * |
wolfSSL | 13:80fb167dafdf | 5 | * This file is part of wolfSSL. |
wolfSSL | 13:80fb167dafdf | 6 | * |
wolfSSL | 13:80fb167dafdf | 7 | * wolfSSL is free software; you can redistribute it and/or modify |
wolfSSL | 13:80fb167dafdf | 8 | * it under the terms of the GNU General Public License as published by |
wolfSSL | 13:80fb167dafdf | 9 | * the Free Software Foundation; either version 2 of the License, or |
wolfSSL | 13:80fb167dafdf | 10 | * (at your option) any later version. |
wolfSSL | 13:80fb167dafdf | 11 | * |
wolfSSL | 13:80fb167dafdf | 12 | * wolfSSL is distributed in the hope that it will be useful, |
wolfSSL | 13:80fb167dafdf | 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
wolfSSL | 13:80fb167dafdf | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
wolfSSL | 13:80fb167dafdf | 15 | * GNU General Public License for more details. |
wolfSSL | 13:80fb167dafdf | 16 | * |
wolfSSL | 13:80fb167dafdf | 17 | * You should have received a copy of the GNU General Public License |
wolfSSL | 13:80fb167dafdf | 18 | * along with this program; if not, write to the Free Software |
wolfSSL | 13:80fb167dafdf | 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA |
wolfSSL | 13:80fb167dafdf | 20 | */ |
wolfSSL | 13:80fb167dafdf | 21 | |
wolfSSL | 13:80fb167dafdf | 22 | |
wolfSSL | 13:80fb167dafdf | 23 | #ifndef WOLF_CRYPT_DH_H |
wolfSSL | 13:80fb167dafdf | 24 | #define WOLF_CRYPT_DH_H |
wolfSSL | 13:80fb167dafdf | 25 | |
wolfSSL | 13:80fb167dafdf | 26 | #include <wolfssl/wolfcrypt/types.h> |
wolfSSL | 13:80fb167dafdf | 27 | |
wolfSSL | 13:80fb167dafdf | 28 | #ifndef NO_DH |
wolfSSL | 13:80fb167dafdf | 29 | |
wolfSSL | 13:80fb167dafdf | 30 | #include <wolfssl/wolfcrypt/integer.h> |
wolfSSL | 13:80fb167dafdf | 31 | #include <wolfssl/wolfcrypt/random.h> |
wolfSSL | 13:80fb167dafdf | 32 | |
wolfSSL | 13:80fb167dafdf | 33 | #ifdef __cplusplus |
wolfSSL | 13:80fb167dafdf | 34 | extern "C" { |
wolfSSL | 13:80fb167dafdf | 35 | #endif |
wolfSSL | 13:80fb167dafdf | 36 | |
wolfSSL | 13:80fb167dafdf | 37 | #ifdef WOLFSSL_ASYNC_CRYPT |
wolfSSL | 13:80fb167dafdf | 38 | #include <wolfssl/wolfcrypt/async.h> |
wolfSSL | 13:80fb167dafdf | 39 | #endif |
wolfSSL | 13:80fb167dafdf | 40 | typedef struct DhParams { |
wolfSSL | 13:80fb167dafdf | 41 | const byte* p; |
wolfSSL | 13:80fb167dafdf | 42 | word32 p_len; |
wolfSSL | 13:80fb167dafdf | 43 | const byte* g; |
wolfSSL | 13:80fb167dafdf | 44 | word32 g_len; |
wolfSSL | 13:80fb167dafdf | 45 | } DhParams; |
wolfSSL | 13:80fb167dafdf | 46 | |
wolfSSL | 13:80fb167dafdf | 47 | /* Diffie-Hellman Key */ |
wolfSSL | 13:80fb167dafdf | 48 | typedef struct DhKey { |
wolfSSL | 13:80fb167dafdf | 49 | mp_int p, g; /* group parameters */ |
wolfSSL | 13:80fb167dafdf | 50 | void* heap; |
wolfSSL | 13:80fb167dafdf | 51 | #ifdef WOLFSSL_ASYNC_CRYPT |
wolfSSL | 13:80fb167dafdf | 52 | WC_ASYNC_DEV asyncDev; |
wolfSSL | 13:80fb167dafdf | 53 | #endif |
wolfSSL | 13:80fb167dafdf | 54 | } DhKey; |
wolfSSL | 13:80fb167dafdf | 55 | |
wolfSSL | 13:80fb167dafdf | 56 | |
wolfSSL | 13:80fb167dafdf | 57 | #ifdef HAVE_FFDHE_2048 |
wolfSSL | 13:80fb167dafdf | 58 | WOLFSSL_API const DhParams* wc_Dh_ffdhe2048_Get(void); |
wolfSSL | 13:80fb167dafdf | 59 | #endif |
wolfSSL | 13:80fb167dafdf | 60 | #ifdef HAVE_FFDHE_3072 |
wolfSSL | 13:80fb167dafdf | 61 | WOLFSSL_API const DhParams* wc_Dh_ffdhe3072_Get(void); |
wolfSSL | 13:80fb167dafdf | 62 | #endif |
wolfSSL | 13:80fb167dafdf | 63 | #ifdef HAVE_FFDHE_4096 |
wolfSSL | 13:80fb167dafdf | 64 | WOLFSSL_API const DhParams* wc_Dh_ffdhe4096_Get(void); |
wolfSSL | 13:80fb167dafdf | 65 | #endif |
wolfSSL | 13:80fb167dafdf | 66 | #ifdef HAVE_FFDHE_6144 |
wolfSSL | 13:80fb167dafdf | 67 | WOLFSSL_API const DhParams* wc_Dh_ffdhe6144_Get(void); |
wolfSSL | 13:80fb167dafdf | 68 | #endif |
wolfSSL | 13:80fb167dafdf | 69 | #ifdef HAVE_FFDHE_8192 |
wolfSSL | 13:80fb167dafdf | 70 | WOLFSSL_API const DhParams* wc_Dh_ffdhe8192_Get(void); |
wolfSSL | 13:80fb167dafdf | 71 | #endif |
wolfSSL | 13:80fb167dafdf | 72 | |
wolfSSL | 13:80fb167dafdf | 73 | WOLFSSL_API int wc_InitDhKey(DhKey* key); |
wolfSSL | 13:80fb167dafdf | 74 | WOLFSSL_API int wc_InitDhKey_ex(DhKey* key, void* heap, int devId); |
wolfSSL | 13:80fb167dafdf | 75 | WOLFSSL_API void wc_FreeDhKey(DhKey* key); |
wolfSSL | 13:80fb167dafdf | 76 | |
wolfSSL | 13:80fb167dafdf | 77 | WOLFSSL_API int wc_DhGenerateKeyPair(DhKey* key, WC_RNG* rng, byte* priv, |
wolfSSL | 13:80fb167dafdf | 78 | word32* privSz, byte* pub, word32* pubSz); |
wolfSSL | 13:80fb167dafdf | 79 | WOLFSSL_API int wc_DhAgree(DhKey* key, byte* agree, word32* agreeSz, |
wolfSSL | 13:80fb167dafdf | 80 | const byte* priv, word32 privSz, const byte* otherPub, |
wolfSSL | 13:80fb167dafdf | 81 | word32 pubSz); |
wolfSSL | 13:80fb167dafdf | 82 | |
wolfSSL | 13:80fb167dafdf | 83 | WOLFSSL_API int wc_DhKeyDecode(const byte* input, word32* inOutIdx, DhKey* key, |
wolfSSL | 13:80fb167dafdf | 84 | word32); |
wolfSSL | 13:80fb167dafdf | 85 | WOLFSSL_API int wc_DhSetKey(DhKey* key, const byte* p, word32 pSz, const byte* g, |
wolfSSL | 13:80fb167dafdf | 86 | word32 gSz); |
wolfSSL | 13:80fb167dafdf | 87 | WOLFSSL_API int wc_DhParamsLoad(const byte* input, word32 inSz, byte* p, |
wolfSSL | 13:80fb167dafdf | 88 | word32* pInOutSz, byte* g, word32* gInOutSz); |
wolfSSL | 13:80fb167dafdf | 89 | WOLFSSL_API int wc_DhCheckPubKey(DhKey* key, const byte* pub, word32 pubSz); |
wolfSSL | 13:80fb167dafdf | 90 | |
wolfSSL | 13:80fb167dafdf | 91 | #ifdef __cplusplus |
wolfSSL | 13:80fb167dafdf | 92 | } /* extern "C" */ |
wolfSSL | 13:80fb167dafdf | 93 | #endif |
wolfSSL | 13:80fb167dafdf | 94 | |
wolfSSL | 13:80fb167dafdf | 95 | #endif /* NO_DH */ |
wolfSSL | 13:80fb167dafdf | 96 | #endif /* WOLF_CRYPT_DH_H */ |
wolfSSL | 13:80fb167dafdf | 97 | |
wolfSSL | 13:80fb167dafdf | 98 |