summaryrefslogtreecommitdiff
path: root/lib/gnutls_dh.c
blob: 228b7c932aaa7891e72673c4069b1d83df1a13dc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
/*
 *      Copyright (C) 2000 Nikos Mavroyanopoulos
 *
 * This file is part of GNUTLS.
 *           someday was part of gsti
 *
 * GNUTLS is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * GNUTLS is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
 */

#include <gnutls_int.h>
#include <gnutls_errors.h>
#include <gnutls_gcry.h>

#define DH_G_1024 2
#define DH_G_4096 5
#define DH_G_2048 5
#define DH_G_3072 13

static const uint8 diffie_hellman_group1_prime[130] = { 0x04, 0x00,
	0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xC9, 0x0F, 0xDA, 0xA2,
	0x21, 0x68, 0xC2, 0x34, 0xC4, 0xC6, 0x62, 0x8B, 0x80, 0xDC, 0x1C, 0xD1,
	0x29, 0x02, 0x4E, 0x08, 0x8A, 0x67, 0xCC, 0x74, 0x02, 0x0B, 0xBE, 0xA6,
	0x3B, 0x13, 0x9B, 0x22, 0x51, 0x4A, 0x08, 0x79, 0x8E, 0x34, 0x04, 0xDD,
	0xEF, 0x95, 0x19, 0xB3, 0xCD, 0x3A, 0x43, 0x1B, 0x30, 0x2B, 0x0A, 0x6D,
	0xF2, 0x5F, 0x14, 0x37, 0x4F, 0xE1, 0x35, 0x6D, 0x6D, 0x51, 0xC2, 0x45,
	0xE4, 0x85, 0xB5, 0x76, 0x62, 0x5E, 0x7E, 0xC6, 0xF4, 0x4C, 0x42, 0xE9,
	0xA6, 0x37, 0xED, 0x6B, 0x0B, 0xFF, 0x5C, 0xB6, 0xF4, 0x06, 0xB7, 0xED,
	0xEE, 0x38, 0x6B, 0xFB, 0x5A, 0x89, 0x9F, 0xA5, 0xAE, 0x9F, 0x24, 0x11,
	0x7C, 0x4B, 0x1F, 0xE6, 0x49, 0x28, 0x66, 0x51, 0xEC, 0xE6, 0x53, 0x81,
	0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
};

/* prime - 4096 bits */
const uint8 diffie_hellman_prime_4096[512] = { 
	0x98, 0xb7, 0x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, 0x3b, 0xb9, 0xfe, 
	0x08, 0x7e, 0xe9, 0x0a, 0xdc, 0xe7, 0xc2, 
	0xa6, 0xa6, 0xb3, 0x7d, 0xe0, 0xa2, 0xe7, 
	0x6d, 0x2e, 0x33, 0xed, 0x47, 0xf7
};

/* prime - 2048 bits */
const uint8 diffie_hellman_prime_2048[256] = { 
	0xf0, 0x49, 0x65, 0x6d, 0x24, 0x61, 0xe6, 
	0x86, 0x8e, 0x57, 0x2b, 0x9b, 0x1c, 0x53, 
	0x2e, 0xef, 0xd2, 0x6e, 0xe5, 0x6c, 0xc4, 
	0x0c, 0x77, 0x1d, 0xce, 0xc7, 0xe0, 0x92, 
	0x78, 0x8b, 0x2b, 0x80, 0x9f, 0xc4, 0x59, 
	0xb5, 0x2e, 0xeb, 0x81, 0x8b, 0xfa, 0x08, 
	0x9f, 0x02, 0x5e, 0x94, 0x85, 0xab, 0xab, 
	0x08, 0x8a, 0x71, 0xb5, 0x0c, 0x26, 0x63, 
	0x2f, 0x34, 0x10, 0xdf, 0x32, 0x9a, 0xa1, 
	0xd5, 0xb5, 0xd7, 0xa1, 0x46, 0x24, 0x9a, 
	0xe3, 0x2a, 0xf1, 0x3a, 0x52, 0xc4, 0xa4, 
	0xe6, 0xa2, 0x29, 0x5e, 0x49, 0x0e, 0x2a, 
	0x4d, 0xad, 0xcd, 0x92, 0xb6, 0xa5, 0x25, 
	0xe5, 0x09, 0xae, 0x76, 0xe4, 0x19, 0xec, 
	0x29, 0x9b, 0x9b, 0xdb, 0x0c, 0xc8, 0x28, 
	0x1c, 0x49, 0x11, 0x45, 0x30, 0x51, 0x73, 
	0x31, 0x18, 0x9e, 0xa5, 0x89, 0x7d, 0x17, 
	0x22, 0xd5, 0x49, 0xaf, 0xf6, 0xe5, 0x00, 
	0x55, 0x7f, 0x2b, 0x33, 0x2d, 0x2f, 0x89, 
	0x73, 0x0b, 0x4d, 0x44, 0x72, 0xb1, 0x2e, 
	0xa3, 0x68, 0xbe, 0x52, 0x4e, 0x5a, 0x66, 
	0x36, 0xf9, 0x2c, 0xe7, 0xce, 0x92, 0x4d, 
	0x0c, 0xa3, 0xc7, 0x85, 0x7e, 0xe6, 0x97, 
	0x02, 0x8b, 0x0c, 0xcb, 0xf3, 0x6f, 0x2e, 
	0x04, 0xed, 0x6e, 0x75, 0xcf, 0xd1, 0xd4, 
	0x9f, 0xd3, 0x44, 0x3e, 0x5f, 0x81, 0xaa, 
	0xc1, 0xb8, 0xe2, 0xab, 0xed, 0x3b, 0xfc, 
	0xeb, 0x47, 0x48, 0xee, 0xe5, 0xfd, 0xc2, 
	0x79, 0x7a, 0x01, 0xe9, 0xab, 0xc6, 0x34, 
	0x65, 0x6a, 0x0a, 0x6c, 0xe8, 0x89, 0xa6, 
	0x96, 0xd2, 0x1e, 0xe5, 0xbe, 0x58, 0xf2, 
	0xcf, 0x17, 0xb8, 0x75, 0x43, 0xec, 0x0b, 
	0xb2, 0x91, 0x50, 0x93, 0x4c, 0xd2, 0xa3, 
	0xa4, 0x8a, 0x67, 0x23, 0x7f, 0x86, 0xac, 
	0xe3, 0x56, 0x9b, 0x18, 0x03, 0x03, 0x70, 
	0x50, 0x7b, 0x1a, 0x02, 0x22, 0x0b, 0x93, 
	0xc8, 0x9b, 0xa8, 0x8f
};


/* 
	--Example-- 
	you: X = g ^ x mod p;
	peer:Y = g ^ y mod p;

	your_key = Y ^ x mod p;
	his_key  = X ^ y mod p;

//      generate our secret and the public value for it
	X = gnutls_calc_dh_secret(&x, g, p);
//      now we can calculate the shared secret
	key = gnutls_calc_dh_key(Y, x, g, p);
	_gnutls_mpi_release(x);
	_gnutls_mpi_release(g);
*/


/* This function should return a resonable size for X
 * (DH secret key). The input is the number of bits of 
 * the modulus.
 * FIXME: This function is not correct
 */
static int get_x_size( int bits) {
	if (bits <= 2048) return 512;
	if (bits <= 4096) return 768;
	return 1024;
}

MPI gnutls_calc_dh_secret(MPI * ret_x, MPI g, MPI prime)
{
	MPI e, x;
	int x_size = get_x_size( gcry_mpi_get_nbits(prime));
	
	x = gcry_mpi_new(x_size);	/* FIXME: allocate in secure memory */
	gcry_mpi_randomize(x, x_size, GCRY_STRONG_RANDOM);
	/* fixme: set high bit of x and select a larger one */

	e = gcry_mpi_alloc_like(prime);
	gcry_mpi_powm(e, g, x, prime);

	if (ret_x)
		*ret_x = x;
	else
		_gnutls_mpi_release(&x);
	return e;
}

/* returns g and p, depends on the requested bits.
 * We only support limited key sizes.
 */
MPI gnutls_get_dh_params(MPI * ret_p, int bits)
{
	MPI g, prime;
	size_t n;
	
	if (bits >= 4096) bits = 4096;
	else if (bits<=1024) bits=1024;
	else if (bits<=2048) bits=2048;
	else if (bits<=3072) bits=3072;
	else if (bits<=4096) bits=4096;
	
	switch (bits) {
	case 1024:
		n = sizeof diffie_hellman_group1_prime;

		if (gcry_mpi_scan(&prime, GCRYMPI_FMT_USG,
			  diffie_hellman_group1_prime, &n)) {
			gnutls_assert();
			abort();
		}

		g = gcry_mpi_set_ui(NULL, DH_G_1024);

		if (ret_p)
			*ret_p = prime;
		else
			_gnutls_mpi_release(&prime);
		return g;
	case 2048:
		n = sizeof diffie_hellman_prime_2048;

		if (gcry_mpi_scan(&prime, GCRYMPI_FMT_USG,
			  diffie_hellman_prime_2048, &n)) {
			gnutls_assert();
			abort();
		}

		g = gcry_mpi_set_ui(NULL, DH_G_2048);

		if (ret_p)
			*ret_p = prime;
		else
			_gnutls_mpi_release(&prime);
		return g;
	case 3072:
		n = sizeof diffie_hellman_prime_3072;

		if (gcry_mpi_scan(&prime, GCRYMPI_FMT_USG,
			  diffie_hellman_prime_3072, &n)) {
			gnutls_assert();
			abort();
		}

		g = gcry_mpi_set_ui(NULL, DH_G_3072);

		if (ret_p)
			*ret_p = prime;
		else
			_gnutls_mpi_release(&prime);
		return g;
	case 4096:
		n = sizeof diffie_hellman_prime_4096;

		if (gcry_mpi_scan(&prime, GCRYMPI_FMT_USG,
			  diffie_hellman_prime_4096, &n)) {
			gnutls_assert();
			abort();
		}

		g = gcry_mpi_set_ui(NULL, DH_G_4096);

		if (ret_p)
			*ret_p = prime;
		else
			_gnutls_mpi_release(&prime);
		return g;
	default:
		gnutls_assert();
		abort();
	}
}


MPI gnutls_calc_dh_key(MPI f, MPI x, MPI prime)
{
	MPI k;

	k = gcry_mpi_alloc_like(prime);
	gcry_mpi_powm(k, f, x, prime);
	return k;
}