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 | #ifndef WOLF_CRYPT_DH_H
|
---|
24 | #define WOLF_CRYPT_DH_H
|
---|
25 |
|
---|
26 | #include <wolfssl/wolfcrypt/types.h>
|
---|
27 |
|
---|
28 | #ifndef NO_DH
|
---|
29 |
|
---|
30 | #include <wolfssl/wolfcrypt/integer.h>
|
---|
31 | #include <wolfssl/wolfcrypt/random.h>
|
---|
32 |
|
---|
33 | #ifdef __cplusplus
|
---|
34 | extern "C" {
|
---|
35 | #endif
|
---|
36 |
|
---|
37 | #ifdef WOLFSSL_ASYNC_CRYPT
|
---|
38 | #include <wolfssl/wolfcrypt/async.h>
|
---|
39 | #endif
|
---|
40 | typedef struct DhParams {
|
---|
41 | const byte* p;
|
---|
42 | word32 p_len;
|
---|
43 | const byte* g;
|
---|
44 | word32 g_len;
|
---|
45 | } DhParams;
|
---|
46 |
|
---|
47 | /* Diffie-Hellman Key */
|
---|
48 | typedef struct DhKey {
|
---|
49 | mp_int p, g; /* group parameters */
|
---|
50 | void* heap;
|
---|
51 | #ifdef WOLFSSL_ASYNC_CRYPT
|
---|
52 | WC_ASYNC_DEV asyncDev;
|
---|
53 | #endif
|
---|
54 | } DhKey;
|
---|
55 |
|
---|
56 |
|
---|
57 | #ifdef HAVE_FFDHE_2048
|
---|
58 | WOLFSSL_API const DhParams* wc_Dh_ffdhe2048_Get(void);
|
---|
59 | #endif
|
---|
60 | #ifdef HAVE_FFDHE_3072
|
---|
61 | WOLFSSL_API const DhParams* wc_Dh_ffdhe3072_Get(void);
|
---|
62 | #endif
|
---|
63 | #ifdef HAVE_FFDHE_4096
|
---|
64 | WOLFSSL_API const DhParams* wc_Dh_ffdhe4096_Get(void);
|
---|
65 | #endif
|
---|
66 | #ifdef HAVE_FFDHE_6144
|
---|
67 | WOLFSSL_API const DhParams* wc_Dh_ffdhe6144_Get(void);
|
---|
68 | #endif
|
---|
69 | #ifdef HAVE_FFDHE_8192
|
---|
70 | WOLFSSL_API const DhParams* wc_Dh_ffdhe8192_Get(void);
|
---|
71 | #endif
|
---|
72 |
|
---|
73 | WOLFSSL_API int wc_InitDhKey(DhKey* key);
|
---|
74 | WOLFSSL_API int wc_InitDhKey_ex(DhKey* key, void* heap, int devId);
|
---|
75 | WOLFSSL_API void wc_FreeDhKey(DhKey* key);
|
---|
76 |
|
---|
77 | WOLFSSL_API int wc_DhGenerateKeyPair(DhKey* key, WC_RNG* rng, byte* priv,
|
---|
78 | word32* privSz, byte* pub, word32* pubSz);
|
---|
79 | WOLFSSL_API int wc_DhAgree(DhKey* key, byte* agree, word32* agreeSz,
|
---|
80 | const byte* priv, word32 privSz, const byte* otherPub,
|
---|
81 | word32 pubSz);
|
---|
82 |
|
---|
83 | WOLFSSL_API int wc_DhKeyDecode(const byte* input, word32* inOutIdx, DhKey* key,
|
---|
84 | word32);
|
---|
85 | WOLFSSL_API int wc_DhSetKey(DhKey* key, const byte* p, word32 pSz, const byte* g,
|
---|
86 | word32 gSz);
|
---|
87 | WOLFSSL_API int wc_DhParamsLoad(const byte* input, word32 inSz, byte* p,
|
---|
88 | word32* pInOutSz, byte* g, word32* gInOutSz);
|
---|
89 | WOLFSSL_API int wc_DhCheckPubKey(DhKey* key, const byte* pub, word32 pubSz);
|
---|
90 |
|
---|
91 | #ifdef __cplusplus
|
---|
92 | } /* extern "C" */
|
---|
93 | #endif
|
---|
94 |
|
---|
95 | #endif /* NO_DH */
|
---|
96 | #endif /* WOLF_CRYPT_DH_H */
|
---|
97 |
|
---|