mbed TLS v2.2.0
dhm.h
Go to the documentation of this file.
1 
23 #ifndef MBEDTLS_DHM_H
24 #define MBEDTLS_DHM_H
25 
26 #include "bignum.h"
27 
28 /*
29  * DHM Error codes
30  */
31 #define MBEDTLS_ERR_DHM_BAD_INPUT_DATA -0x3080
32 #define MBEDTLS_ERR_DHM_READ_PARAMS_FAILED -0x3100
33 #define MBEDTLS_ERR_DHM_MAKE_PARAMS_FAILED -0x3180
34 #define MBEDTLS_ERR_DHM_READ_PUBLIC_FAILED -0x3200
35 #define MBEDTLS_ERR_DHM_MAKE_PUBLIC_FAILED -0x3280
36 #define MBEDTLS_ERR_DHM_CALC_SECRET_FAILED -0x3300
37 #define MBEDTLS_ERR_DHM_INVALID_FORMAT -0x3380
38 #define MBEDTLS_ERR_DHM_ALLOC_FAILED -0x3400
39 #define MBEDTLS_ERR_DHM_FILE_IO_ERROR -0x3480
55 #define MBEDTLS_DHM_RFC3526_MODP_2048_P \
56  "FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD1" \
57  "29024E088A67CC74020BBEA63B139B22514A08798E3404DD" \
58  "EF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245" \
59  "E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED" \
60  "EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3D" \
61  "C2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F" \
62  "83655D23DCA3AD961C62F356208552BB9ED529077096966D" \
63  "670C354E4ABC9804F1746C08CA18217C32905E462E36CE3B" \
64  "E39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9" \
65  "DE2BCBF6955817183995497CEA956AE515D2261898FA0510" \
66  "15728E5A8AACAA68FFFFFFFFFFFFFFFF"
67 
68 #define MBEDTLS_DHM_RFC3526_MODP_2048_G "02"
69 
70 #define MBEDTLS_DHM_RFC3526_MODP_3072_P \
71  "FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD1" \
72  "29024E088A67CC74020BBEA63B139B22514A08798E3404DD" \
73  "EF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245" \
74  "E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED" \
75  "EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3D" \
76  "C2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F" \
77  "83655D23DCA3AD961C62F356208552BB9ED529077096966D" \
78  "670C354E4ABC9804F1746C08CA18217C32905E462E36CE3B" \
79  "E39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9" \
80  "DE2BCBF6955817183995497CEA956AE515D2261898FA0510" \
81  "15728E5A8AAAC42DAD33170D04507A33A85521ABDF1CBA64" \
82  "ECFB850458DBEF0A8AEA71575D060C7DB3970F85A6E1E4C7" \
83  "ABF5AE8CDB0933D71E8C94E04A25619DCEE3D2261AD2EE6B" \
84  "F12FFA06D98A0864D87602733EC86A64521F2B18177B200C" \
85  "BBE117577A615D6C770988C0BAD946E208E24FA074E5AB31" \
86  "43DB5BFCE0FD108E4B82D120A93AD2CAFFFFFFFFFFFFFFFF"
87 
88 #define MBEDTLS_DHM_RFC3526_MODP_3072_G "02"
89 
90 #define MBEDTLS_DHM_RFC3526_MODP_4096_P \
91  "FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD1" \
92  "29024E088A67CC74020BBEA63B139B22514A08798E3404DD" \
93  "EF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245" \
94  "E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED" \
95  "EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3D" \
96  "C2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F" \
97  "83655D23DCA3AD961C62F356208552BB9ED529077096966D" \
98  "670C354E4ABC9804F1746C08CA18217C32905E462E36CE3B" \
99  "E39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9" \
100  "DE2BCBF6955817183995497CEA956AE515D2261898FA0510" \
101  "15728E5A8AAAC42DAD33170D04507A33A85521ABDF1CBA64" \
102  "ECFB850458DBEF0A8AEA71575D060C7DB3970F85A6E1E4C7" \
103  "ABF5AE8CDB0933D71E8C94E04A25619DCEE3D2261AD2EE6B" \
104  "F12FFA06D98A0864D87602733EC86A64521F2B18177B200C" \
105  "BBE117577A615D6C770988C0BAD946E208E24FA074E5AB31" \
106  "43DB5BFCE0FD108E4B82D120A92108011A723C12A787E6D7" \
107  "88719A10BDBA5B2699C327186AF4E23C1A946834B6150BDA" \
108  "2583E9CA2AD44CE8DBBBC2DB04DE8EF92E8EFC141FBECAA6" \
109  "287C59474E6BC05D99B2964FA090C3A2233BA186515BE7ED" \
110  "1F612970CEE2D7AFB81BDD762170481CD0069127D5B05AA9" \
111  "93B4EA988D8FDDC186FFB7DC90A6C08F4DF435C934063199" \
112  "FFFFFFFFFFFFFFFF"
113 
114 #define MBEDTLS_DHM_RFC3526_MODP_4096_G "02"
115 
116 #define MBEDTLS_DHM_RFC5114_MODP_2048_P \
117  "AD107E1E9123A9D0D660FAA79559C51FA20D64E5683B9FD1" \
118  "B54B1597B61D0A75E6FA141DF95A56DBAF9A3C407BA1DF15" \
119  "EB3D688A309C180E1DE6B85A1274A0A66D3F8152AD6AC212" \
120  "9037C9EDEFDA4DF8D91E8FEF55B7394B7AD5B7D0B6C12207" \
121  "C9F98D11ED34DBF6C6BA0B2C8BBC27BE6A00E0A0B9C49708" \
122  "B3BF8A317091883681286130BC8985DB1602E714415D9330" \
123  "278273C7DE31EFDC7310F7121FD5A07415987D9ADC0A486D" \
124  "CDF93ACC44328387315D75E198C641A480CD86A1B9E587E8" \
125  "BE60E69CC928B2B9C52172E413042E9B23F10B0E16E79763" \
126  "C9B53DCF4BA80A29E3FB73C16B8E75B97EF363E2FFA31F71" \
127  "CF9DE5384E71B81C0AC4DFFE0C10E64F"
128 
129 #define MBEDTLS_DHM_RFC5114_MODP_2048_G \
130  "AC4032EF4F2D9AE39DF30B5C8FFDAC506CDEBE7B89998CAF"\
131  "74866A08CFE4FFE3A6824A4E10B9A6F0DD921F01A70C4AFA"\
132  "AB739D7700C29F52C57DB17C620A8652BE5E9001A8D66AD7"\
133  "C17669101999024AF4D027275AC1348BB8A762D0521BC98A"\
134  "E247150422EA1ED409939D54DA7460CDB5F6C6B250717CBE"\
135  "F180EB34118E98D119529A45D6F834566E3025E316A330EF"\
136  "BB77A86F0C1AB15B051AE3D428C8F8ACB70A8137150B8EEB"\
137  "10E183EDD19963DDD9E263E4770589EF6AA21E7F5F2FF381"\
138  "B539CCE3409D13CD566AFBB48D6C019181E1BCFE94B30269"\
139  "EDFE72FE9B6AA4BD7B5A0F1C71CFFF4C19C418E1F6EC0179"\
140  "81BC087F2A7065B384B890D3191F2BFA"
141 
142 #ifdef __cplusplus
143 extern "C" {
144 #endif
145 
149 typedef struct
150 {
151  size_t len;
162 }
164 
171 
182  unsigned char **p,
183  const unsigned char *end );
184 
201 int mbedtls_dhm_make_params( mbedtls_dhm_context *ctx, int x_size,
202  unsigned char *output, size_t *olen,
203  int (*f_rng)(void *, unsigned char *, size_t),
204  void *p_rng );
205 
216  const unsigned char *input, size_t ilen );
217 
230 int mbedtls_dhm_make_public( mbedtls_dhm_context *ctx, int x_size,
231  unsigned char *output, size_t olen,
232  int (*f_rng)(void *, unsigned char *, size_t),
233  void *p_rng );
234 
254  unsigned char *output, size_t output_size, size_t *olen,
255  int (*f_rng)(void *, unsigned char *, size_t),
256  void *p_rng );
257 
264 
265 #if defined(MBEDTLS_ASN1_PARSE_C)
266 
277 int mbedtls_dhm_parse_dhm( mbedtls_dhm_context *dhm, const unsigned char *dhmin,
278  size_t dhminlen );
279 
280 #if defined(MBEDTLS_FS_IO)
281 
290 int mbedtls_dhm_parse_dhmfile( mbedtls_dhm_context *dhm, const char *path );
291 #endif /* MBEDTLS_FS_IO */
292 #endif /* MBEDTLS_ASN1_PARSE_C */
293 
299 int mbedtls_dhm_self_test( int verbose );
300 
301 #ifdef __cplusplus
302 }
303 #endif
304 
305 #endif /* dhm.h */
mbedtls_mpi X
Definition: dhm.h:154
void mbedtls_dhm_init(mbedtls_dhm_context *ctx)
Initialize DHM context.
mbedtls_mpi K
Definition: dhm.h:157
mbedtls_mpi GX
Definition: dhm.h:155
size_t len
Definition: dhm.h:151
mbedtls_mpi P
Definition: dhm.h:152
Multi-precision integer library.
int mbedtls_dhm_make_params(mbedtls_dhm_context *ctx, int x_size, unsigned char *output, size_t *olen, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng)
Setup and write the ServerKeyExchange parameters.
int mbedtls_dhm_self_test(int verbose)
Checkup routine.
mbedtls_mpi pX
Definition: dhm.h:161
mbedtls_mpi RP
Definition: dhm.h:158
mbedtls_mpi Vi
Definition: dhm.h:159
int mbedtls_dhm_calc_secret(mbedtls_dhm_context *ctx, unsigned char *output, size_t output_size, size_t *olen, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng)
Derive and export the shared secret (G^Y)^X mod P.
DHM context structure.
Definition: dhm.h:149
mbedtls_mpi GY
Definition: dhm.h:156
int mbedtls_dhm_make_public(mbedtls_dhm_context *ctx, int x_size, unsigned char *output, size_t olen, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng)
Create own private value X and export G^X.
mbedtls_mpi G
Definition: dhm.h:153
int mbedtls_dhm_read_public(mbedtls_dhm_context *ctx, const unsigned char *input, size_t ilen)
Import the peer's public value G^Y.
void mbedtls_dhm_free(mbedtls_dhm_context *ctx)
Free and clear the components of a DHM key.
MPI structure.
Definition: bignum.h:143
int mbedtls_dhm_read_params(mbedtls_dhm_context *ctx, unsigned char **p, const unsigned char *end)
Parse the ServerKeyExchange parameters.
mbedtls_mpi Vf
Definition: dhm.h:160