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