iPXE
ffdhe.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2026 Michael Brown <mbrown@fensystems.co.uk>.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 * 02110-1301, USA.
18 *
19 * You can also choose to distribute this program under the terms of
20 * the Unmodified Binary Distribution Licence (as given in the file
21 * COPYING.UBDL), provided that you have satisfied its requirements.
22 */
23
24FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
25FILE_SECBOOT ( PERMITTED );
26
27/** @file
28 *
29 * Finite Field Diffie-Hellman Ephemeral key exchange
30 *
31 * RFC 7919 defines a family of finite fields all constructed from the
32 * natural logarithm constant "e".
33 *
34 * We choose to support only up to ffdhe4096, since this is sufficient
35 * to exceed the security strength of our RNG (128 bits).
36 *
37 * Support for ffdhe6144 and ffdhe8192 could trivially be added by
38 * simply extending the "euler" constant and adding the relevant
39 * FFDHE_GROUP() declarations. Doing so would approximately double
40 * the space requirements for both read-only data (from 0.5kB to 1kB)
41 * and for uninitialised data (from 3.5kB to 7kB).
42 *
43 * RFC 3526 defines an almost identical family of finite fields all
44 * constructed from the constant "pi", which may be used by older TLS
45 * servers.
46 */
47
48#include <assert.h>
49#include <stdint.h>
50#include <stdlib.h>
51#include <string.h>
52#include <errno.h>
53#include <ipxe/ffdhe.h>
54
55/** Maximum length of FFDHE prime modulus */
56#define FFDHE_LEN 512
57
58/** Maximum length of group constant portion of FFDHE prime modulus */
59#define FFDHE_CONSTANT_LEN \
60 ( FFDHE_LEN - 8 /* high */ - 4 /* lsb32 */ - 8 /* low */ )
61
62/** An FFDHE prime modulus */
63#define ffdhe_modulus_t( len ) \
64 struct { \
65 uint64_t high; \
66 uint8_t constant[ len + FFDHE_CONSTANT_LEN - FFDHE_LEN ]; \
67 uint32_t lsb32; \
68 uint64_t low; \
69 } __attribute__ (( packed ))
70
71/** Euler's constant ("e") */
72static const uint8_t euler[] = {
73 0xad, 0xf8, 0x54, 0x58, 0xa2, 0xbb, 0x4a, 0x9a, 0xaf, 0xdc, 0x56,
74 0x20, 0x27, 0x3d, 0x3c, 0xf1, 0xd8, 0xb9, 0xc5, 0x83, 0xce, 0x2d,
75 0x36, 0x95, 0xa9, 0xe1, 0x36, 0x41, 0x14, 0x64, 0x33, 0xfb, 0xcc,
76 0x93, 0x9d, 0xce, 0x24, 0x9b, 0x3e, 0xf9, 0x7d, 0x2f, 0xe3, 0x63,
77 0x63, 0x0c, 0x75, 0xd8, 0xf6, 0x81, 0xb2, 0x02, 0xae, 0xc4, 0x61,
78 0x7a, 0xd3, 0xdf, 0x1e, 0xd5, 0xd5, 0xfd, 0x65, 0x61, 0x24, 0x33,
79 0xf5, 0x1f, 0x5f, 0x06, 0x6e, 0xd0, 0x85, 0x63, 0x65, 0x55, 0x3d,
80 0xed, 0x1a, 0xf3, 0xb5, 0x57, 0x13, 0x5e, 0x7f, 0x57, 0xc9, 0x35,
81 0x98, 0x4f, 0x0c, 0x70, 0xe0, 0xe6, 0x8b, 0x77, 0xe2, 0xa6, 0x89,
82 0xda, 0xf3, 0xef, 0xe8, 0x72, 0x1d, 0xf1, 0x58, 0xa1, 0x36, 0xad,
83 0xe7, 0x35, 0x30, 0xac, 0xca, 0x4f, 0x48, 0x3a, 0x79, 0x7a, 0xbc,
84 0x0a, 0xb1, 0x82, 0xb3, 0x24, 0xfb, 0x61, 0xd1, 0x08, 0xa9, 0x4b,
85 0xb2, 0xc8, 0xe3, 0xfb, 0xb9, 0x6a, 0xda, 0xb7, 0x60, 0xd7, 0xf4,
86 0x68, 0x1d, 0x4f, 0x42, 0xa3, 0xde, 0x39, 0x4d, 0xf4, 0xae, 0x56,
87 0xed, 0xe7, 0x63, 0x72, 0xbb, 0x19, 0x0b, 0x07, 0xa7, 0xc8, 0xee,
88 0x0a, 0x6d, 0x70, 0x9e, 0x02, 0xfc, 0xe1, 0xcd, 0xf7, 0xe2, 0xec,
89 0xc0, 0x34, 0x04, 0xcd, 0x28, 0x34, 0x2f, 0x61, 0x91, 0x72, 0xfe,
90 0x9c, 0xe9, 0x85, 0x83, 0xff, 0x8e, 0x4f, 0x12, 0x32, 0xee, 0xf2,
91 0x81, 0x83, 0xc3, 0xfe, 0x3b, 0x1b, 0x4c, 0x6f, 0xad, 0x73, 0x3b,
92 0xb5, 0xfc, 0xbc, 0x2e, 0xc2, 0x20, 0x05, 0xc5, 0x8e, 0xf1, 0x83,
93 0x7d, 0x16, 0x83, 0xb2, 0xc6, 0xf3, 0x4a, 0x26, 0xc1, 0xb2, 0xef,
94 0xfa, 0x88, 0x6b, 0x42, 0x38, 0x61, 0x1f, 0xcf, 0xdc, 0xde, 0x35,
95 0x5b, 0x3b, 0x65, 0x19, 0x03, 0x5b, 0xbc, 0x34, 0xf4, 0xde, 0xf9,
96 0x9c, 0x02, 0x38, 0x61, 0xb4, 0x6f, 0xc9, 0xd6, 0xe6, 0xc9, 0x07,
97 0x7a, 0xd9, 0x1d, 0x26, 0x91, 0xf7, 0xf7, 0xee, 0x59, 0x8c, 0xb0,
98 0xfa, 0xc1, 0x86, 0xd9, 0x1c, 0xae, 0xfe, 0x13, 0x09, 0x85, 0x13,
99 0x92, 0x70, 0xb4, 0x13, 0x0c, 0x93, 0xbc, 0x43, 0x79, 0x44, 0xf4,
100 0xfd, 0x44, 0x52, 0xe2, 0xd7, 0x4d, 0xd3, 0x64, 0xf2, 0xe2, 0x1e,
101 0x71, 0xf5, 0x4b, 0xff, 0x5c, 0xae, 0x82, 0xab, 0x9c, 0x9d, 0xf6,
102 0x9e, 0xe8, 0x6d, 0x2b, 0xc5, 0x22, 0x36, 0x3a, 0x0d, 0xab, 0xc5,
103 0x21, 0x97, 0x9b, 0x0d, 0xea, 0xda, 0x1d, 0xbf, 0x9a, 0x42, 0xd5,
104 0xc4, 0x48, 0x4e, 0x0a, 0xbc, 0xd0, 0x6b, 0xfa, 0x53, 0xdd, 0xef,
105 0x3c, 0x1b, 0x20, 0xee, 0x3f, 0xd5, 0x9d, 0x7c, 0x25, 0xe4, 0x1d,
106 0x2b, 0x66, 0x9e, 0x1e, 0xf1, 0x6e, 0x6f, 0x52, 0xc3, 0x16, 0x4d,
107 0xf4, 0xfb, 0x79, 0x30, 0xe9, 0xe4, 0xe5, 0x88, 0x57, 0xb6, 0xac,
108 0x7d, 0x5f, 0x42, 0xd6, 0x9f, 0x6d, 0x18, 0x77, 0x63, 0xcf, 0x1d,
109 0x55, 0x03, 0x40, 0x04, 0x87, 0xf5, 0x5b, 0xa5, 0x7e, 0x31, 0xcc,
110 0x7a, 0x71, 0x35, 0xc8, 0x86, 0xef, 0xb4, 0x31, 0x8a, 0xed, 0x6a,
111 0x1e, 0x01, 0x2d, 0x9e, 0x68, 0x32, 0xa9, 0x07, 0x60, 0x0a, 0x91,
112 0x81, 0x30, 0xc4, 0x6d, 0xc7, 0x78, 0xf9, 0x71, 0xad, 0x00, 0x38,
113 0x09, 0x29, 0x99, 0xa3, 0x33, 0xcb, 0x8b, 0x7a, 0x1a, 0x1d, 0xb9,
114 0x3d, 0x71, 0x40, 0x00, 0x3c, 0x2a, 0x4e, 0xce, 0xa9, 0xf9, 0x8d,
115 0x0a, 0xcc, 0x0a, 0x82, 0x91, 0xcd, 0xce, 0xc9, 0x7d, 0xcf, 0x8e,
116 0xc9, 0xb5, 0x5a, 0x7f, 0x88, 0xa4, 0x6b, 0x4d, 0xb5, 0xa8, 0x51,
117 0xf4, 0x41, 0x82, 0xe1, 0xc6, 0x8a, 0x00, 0x7e
118};
119
120/** Constant "pi" */
121static const uint8_t pi[] = {
122 0xc9, 0x0f, 0xda, 0xa2, 0x21, 0x68, 0xc2, 0x34, 0xc4, 0xc6, 0x62,
123 0x8b, 0x80, 0xdc, 0x1c, 0xd1, 0x29, 0x02, 0x4e, 0x08, 0x8a, 0x67,
124 0xcc, 0x74, 0x02, 0x0b, 0xbe, 0xa6, 0x3b, 0x13, 0x9b, 0x22, 0x51,
125 0x4a, 0x08, 0x79, 0x8e, 0x34, 0x04, 0xdd, 0xef, 0x95, 0x19, 0xb3,
126 0xcd, 0x3a, 0x43, 0x1b, 0x30, 0x2b, 0x0a, 0x6d, 0xf2, 0x5f, 0x14,
127 0x37, 0x4f, 0xe1, 0x35, 0x6d, 0x6d, 0x51, 0xc2, 0x45, 0xe4, 0x85,
128 0xb5, 0x76, 0x62, 0x5e, 0x7e, 0xc6, 0xf4, 0x4c, 0x42, 0xe9, 0xa6,
129 0x37, 0xed, 0x6b, 0x0b, 0xff, 0x5c, 0xb6, 0xf4, 0x06, 0xb7, 0xed,
130 0xee, 0x38, 0x6b, 0xfb, 0x5a, 0x89, 0x9f, 0xa5, 0xae, 0x9f, 0x24,
131 0x11, 0x7c, 0x4b, 0x1f, 0xe6, 0x49, 0x28, 0x66, 0x51, 0xec, 0xe4,
132 0x5b, 0x3d, 0xc2, 0x00, 0x7c, 0xb8, 0xa1, 0x63, 0xbf, 0x05, 0x98,
133 0xda, 0x48, 0x36, 0x1c, 0x55, 0xd3, 0x9a, 0x69, 0x16, 0x3f, 0xa8,
134 0xfd, 0x24, 0xcf, 0x5f, 0x83, 0x65, 0x5d, 0x23, 0xdc, 0xa3, 0xad,
135 0x96, 0x1c, 0x62, 0xf3, 0x56, 0x20, 0x85, 0x52, 0xbb, 0x9e, 0xd5,
136 0x29, 0x07, 0x70, 0x96, 0x96, 0x6d, 0x67, 0x0c, 0x35, 0x4e, 0x4a,
137 0xbc, 0x98, 0x04, 0xf1, 0x74, 0x6c, 0x08, 0xca, 0x18, 0x21, 0x7c,
138 0x32, 0x90, 0x5e, 0x46, 0x2e, 0x36, 0xce, 0x3b, 0xe3, 0x9e, 0x77,
139 0x2c, 0x18, 0x0e, 0x86, 0x03, 0x9b, 0x27, 0x83, 0xa2, 0xec, 0x07,
140 0xa2, 0x8f, 0xb5, 0xc5, 0x5d, 0xf0, 0x6f, 0x4c, 0x52, 0xc9, 0xde,
141 0x2b, 0xcb, 0xf6, 0x95, 0x58, 0x17, 0x18, 0x39, 0x95, 0x49, 0x7c,
142 0xea, 0x95, 0x6a, 0xe5, 0x15, 0xd2, 0x26, 0x18, 0x98, 0xfa, 0x05,
143 0x10, 0x15, 0x72, 0x8e, 0x5a, 0x8a, 0xaa, 0xc4, 0x2d, 0xad, 0x33,
144 0x17, 0x0d, 0x04, 0x50, 0x7a, 0x33, 0xa8, 0x55, 0x21, 0xab, 0xdf,
145 0x1c, 0xba, 0x64, 0xec, 0xfb, 0x85, 0x04, 0x58, 0xdb, 0xef, 0x0a,
146 0x8a, 0xea, 0x71, 0x57, 0x5d, 0x06, 0x0c, 0x7d, 0xb3, 0x97, 0x0f,
147 0x85, 0xa6, 0xe1, 0xe4, 0xc7, 0xab, 0xf5, 0xae, 0x8c, 0xdb, 0x09,
148 0x33, 0xd7, 0x1e, 0x8c, 0x94, 0xe0, 0x4a, 0x25, 0x61, 0x9d, 0xce,
149 0xe3, 0xd2, 0x26, 0x1a, 0xd2, 0xee, 0x6b, 0xf1, 0x2f, 0xfa, 0x06,
150 0xd9, 0x8a, 0x08, 0x64, 0xd8, 0x76, 0x02, 0x73, 0x3e, 0xc8, 0x6a,
151 0x64, 0x52, 0x1f, 0x2b, 0x18, 0x17, 0x7b, 0x20, 0x0c, 0xbb, 0xe1,
152 0x17, 0x57, 0x7a, 0x61, 0x5d, 0x6c, 0x77, 0x09, 0x88, 0xc0, 0xba,
153 0xd9, 0x46, 0xe2, 0x08, 0xe2, 0x4f, 0xa0, 0x74, 0xe5, 0xab, 0x31,
154 0x43, 0xdb, 0x5b, 0xfc, 0xe0, 0xfd, 0x10, 0x8e, 0x4b, 0x82, 0xd1,
155 0x20, 0xa9, 0x21, 0x08, 0x01, 0x1a, 0x72, 0x3c, 0x12, 0xa7, 0x87,
156 0xe6, 0xd7, 0x88, 0x71, 0x9a, 0x10, 0xbd, 0xba, 0x5b, 0x26, 0x99,
157 0xc3, 0x27, 0x18, 0x6a, 0xf4, 0xe2, 0x3c, 0x1a, 0x94, 0x68, 0x34,
158 0xb6, 0x15, 0x0b, 0xda, 0x25, 0x83, 0xe9, 0xca, 0x2a, 0xd4, 0x4c,
159 0xe8, 0xdb, 0xbb, 0xc2, 0xdb, 0x04, 0xde, 0x8e, 0xf9, 0x2e, 0x8e,
160 0xfc, 0x14, 0x1f, 0xbe, 0xca, 0xa6, 0x28, 0x7c, 0x59, 0x47, 0x4e,
161 0x6b, 0xc0, 0x5d, 0x99, 0xb2, 0x96, 0x4f, 0xa0, 0x90, 0xc3, 0xa2,
162 0x23, 0x3b, 0xa1, 0x86, 0x51, 0x5b, 0xe7, 0xed, 0x1f, 0x61, 0x29,
163 0x70, 0xce, 0xe2, 0xd7, 0xaf, 0xb8, 0x1b, 0xdd, 0x76, 0x21, 0x70,
164 0x48, 0x1c, 0xd0, 0x06, 0x91, 0x27, 0xd5, 0xb0, 0x5a, 0xa9, 0x93,
165 0xb4, 0xea, 0x98, 0x8d, 0x8f, 0xdd, 0xc1, 0x86, 0xff, 0xb7, 0xdc,
166 0x90, 0xa6, 0xc0, 0x8f, 0x4d, 0xf4, 0x35, 0xc9
167};
168
169/**
170 * Calculate FFDHE result
171 *
172 * @v group FFDHE group
173 * @v public Base public value, or NULL to use generator
174 * @v private Private exponent
175 * @v shared Shared result to fill in
176 * @ret rc Return status code
177 */
178static int ffdhe ( struct ffdhe_group *group, const void *public,
179 const void *private, void *shared ) {
180 unsigned int expsize = group->expsize;
181 unsigned int size = group->size;
182 size_t explen = group->explen;
183 size_t len = group->len;
184 bigint_t ( expsize ) exponent;
185 bigint_t ( size ) *modulus;
186 bigint_t ( size ) *base;
187 bigint_t ( size ) *result;
189 struct {
190 typeof ( *modulus ) modulus;
191 typeof ( *base ) base;
192 typeof ( *result ) result;
193 uint8_t mod_exp[ bigint_mod_exp_tmp_len ( modulus ) ];
194 } *tmp;
195 static const uint8_t two[1] = { 2 };
196 int rc;
197
198 /* Sanity checks */
199 static_assert ( sizeof ( euler ) == FFDHE_CONSTANT_LEN );
200 static_assert ( sizeof ( pi ) == FFDHE_CONSTANT_LEN );
201
202 /* Allocate temporary space */
203 tmp = malloc ( sizeof ( *tmp ) );
204 if ( ! tmp ) {
205 rc = -ENOMEM;
206 goto err_alloc;
207 }
208 modulus = &tmp->modulus;
209 base = &tmp->base;
210 result = &tmp->result;
211
212 /* Construct modulus (using base as temporary buffer) */
213 assert ( sizeof ( *raw ) <= sizeof ( *base ) );
214 raw = ( ( void * ) base );
215 memset ( raw, 0xff, sizeof ( *raw ) );
216 memcpy ( raw->constant, group->constant, sizeof ( raw->constant ) );
217 raw->lsb32 = group->lsb32;
218 bigint_init ( modulus, raw, len );
219 DBGC ( group, "FFDHE %s mod: %s\n",
220 group->name, bigint_ntoa ( modulus ) );
221
222 /* Construct base */
223 if ( public ) {
224 bigint_init ( base, public, len );
225 } else {
226 bigint_init ( base, two, sizeof ( two ) );
227 }
228 DBGC ( group, "FFDHE %s %s: %s\n", group->name,
229 ( public ? "pub" : "gen" ), bigint_ntoa ( base ) );
230
231 /* Construct exponent */
232 bigint_init ( &exponent, private, explen );
233 DBGC ( group, "FFDHE %s exp: %s\n",
234 group->name, bigint_ntoa ( &exponent ) );
235
236 /* Calculate result */
237 bigint_mod_exp ( base, modulus, &exponent, result, tmp->mod_exp );
238 DBGC ( group, "FFDHE %s %s: %s\n", group->name,
239 ( public ? "shr" : "pub" ), bigint_ntoa ( result ) );
240 bigint_done ( result, shared, len );
241
242 /* Validate result */
243 bigint_init ( base, two, sizeof ( two ) );
244 if ( ! bigint_is_geq ( result, base ) ) {
245 /* Result is 0 or 1 */
246 DBGC ( group, "FFDHE %s invalid result\n", group->name );
247 rc = -EPERM;
248 goto err_result;
249 }
251 if ( ! bigint_is_geq ( modulus, result ) ) {
252 /* Result is p-1 */
253 DBGC ( group, "FFDHE %s invalid result\n", group->name );
254 rc = -EPERM;
255 goto err_result;
256 }
257
258 /* Success */
259 rc = 0;
260
261 err_result:
262 zfree ( tmp );
263 err_alloc:
264 return rc;
265}
266
267/**
268 * Share public key
269 *
270 * @v exchange Key exchange algorithm
271 * @v private Private key
272 * @v public Public key to fill in
273 * @ret rc Return status code
274 */
275int ffdhe_share ( struct exchange_algorithm *exchange, const void *private,
276 void *public ) {
277 struct ffdhe_group *group = exchange->priv;
278
279 return ffdhe ( group, NULL, private, public );
280}
281
282/**
283 * Agree shared secret
284 *
285 * @v exchange Key exchange algorithm
286 * @v private Private key
287 * @v partner Partner public key
288 * @v shared Shared secret to fill in
289 * @ret rc Return status code
290 */
291int ffdhe_agree ( struct exchange_algorithm *exchange, const void *private,
292 const void *partner, void *shared ) {
293 struct ffdhe_group *group = exchange->priv;
294
295 return ffdhe ( group, partner, private, shared );
296}
297
298/**
299 * Check group parameters
300 *
301 * @v exchange Key exchange algorithm
302 * @v dh_p Prime modulus
303 * @v dh_p_len Length of prime modulus
304 * @v dh_g Generator
305 * @v dh_g_len Length of generator
306 * @ret match Field parameters are correct for this group
307 *
308 * Leading zeros in the modulus and generator will be tolerated.
309 */
311 const void *dh_p, size_t dh_p_len,
312 const void *dh_g, size_t dh_g_len ) {
313 struct ffdhe_group *group = exchange->priv;
314 const ffdhe_modulus_t ( group->len ) *modulus;
315 const uint8_t *generator;
316
317 /* Sanity check */
318 assert ( is_ffdhe ( exchange ) );
319
320 /* Strip leading zeros from modulus and check length */
321 while ( dh_p_len && ( ! *( ( uint8_t * ) dh_p ) ) ) {
322 dh_p++;
323 dh_p_len--;
324 }
325 if ( dh_p_len != sizeof ( *modulus ) )
326 return 0;
327 modulus = dh_p;
328
329 /* Strip leading zeros from generator and check length */
330 while ( dh_g_len && ( ! *( ( uint8_t * ) dh_g ) ) ) {
331 dh_g++;
332 dh_g_len--;
333 }
334 if ( dh_g_len != sizeof ( *generator ) )
335 return 0;
336 generator = dh_g;
337
338 /* Check values */
339 return ( ( modulus->high == ~( ( uint64_t ) 0 ) ) &&
340 ( memcmp ( modulus->constant, group->constant,
341 sizeof ( modulus->constant ) ) == 0 ) &&
342 ( modulus->lsb32 == group->lsb32 ) &&
343 ( modulus->low == ~( ( uint64_t ) 0 ) ) &&
344 ( *generator == 2 ) );
345}
346
347/* Supported groups */
348FFDHE_GROUP ( ffdhe2048, ffdhe2048_algorithm, euler, 2048, 225, 0x61285c97 );
349FFDHE_GROUP ( ffdhe3072, ffdhe3072_algorithm, euler, 3072, 275, 0x66c62e37 );
350FFDHE_GROUP ( ffdhe4096, ffdhe4096_algorithm, euler, 4096, 325, 0x5e655f6a );
351FFDHE_GROUP ( modp2048, modp2048_algorithm, pi, 2048, 230, 0x8aacaa68 );
352FFDHE_GROUP ( modp3072, modp3072_algorithm, pi, 3072, 279, 0xa93ad2ca );
353FFDHE_GROUP ( modp4096, modp4096_algorithm, pi, 4096, 328, 0x34063199 );
#define NULL
NULL pointer (VOID *).
Definition Base.h:321
__be32 raw[7]
Definition CIB_PRM.h:0
typeof(acpi_finder=acpi_find)
ACPI table finder.
Definition acpi.c:48
struct arbelprm_rc_send_wqe rc
Definition arbel.h:3
uint16_t result
Definition hyperv.h:33
unsigned long long uint64_t
Definition stdint.h:13
unsigned char uint8_t
Definition stdint.h:10
Assertions.
#define assert(condition)
Assert a condition at run-time.
Definition assert.h:50
ring len
Length.
Definition dwmac.h:226
uint16_t group
Type of event.
Definition ena.h:1
Error codes.
struct eth_slow_lacp_entity_tlv partner
Partner information.
Definition eth_slow.h:5
static const uint8_t euler[]
Euler's constant ("e").
Definition ffdhe.c:72
static int ffdhe(struct ffdhe_group *group, const void *public, const void *private, void *shared)
Calculate FFDHE result.
Definition ffdhe.c:178
#define ffdhe_modulus_t(len)
An FFDHE prime modulus.
Definition ffdhe.c:63
int ffdhe_share(struct exchange_algorithm *exchange, const void *private, void *public)
Share public key.
Definition ffdhe.c:275
#define FFDHE_CONSTANT_LEN
Maximum length of group constant portion of FFDHE prime modulus.
Definition ffdhe.c:59
int ffdhe_has_params(struct exchange_algorithm *exchange, const void *dh_p, size_t dh_p_len, const void *dh_g, size_t dh_g_len)
Check group parameters.
Definition ffdhe.c:310
static const uint8_t pi[]
Constant "pi".
Definition ffdhe.c:121
int ffdhe_agree(struct exchange_algorithm *exchange, const void *private, const void *partner, void *shared)
Agree shared secret.
Definition ffdhe.c:291
Finite Field Diffie-Hellman Ephemeral key exchange.
struct exchange_algorithm modp3072_algorithm
struct exchange_algorithm modp2048_algorithm
struct exchange_algorithm ffdhe4096_algorithm
struct exchange_algorithm modp4096_algorithm
struct exchange_algorithm ffdhe2048_algorithm
#define FFDHE_GROUP(_name, _exchange, _constant, _bits, _expbits, _lsb)
Define a finite field DHE group.
Definition ffdhe.h:58
static int is_ffdhe(struct exchange_algorithm *exchange)
Check if key exchange algorithm is a finite field DHE group.
Definition ffdhe.h:52
struct exchange_algorithm ffdhe3072_algorithm
#define DBGC(...)
Definition compiler.h:530
uint16_t size
Buffer size.
Definition dwmac.h:3
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
Definition compiler.h:921
#define ENOMEM
Not enough space.
Definition errno.h:535
#define EPERM
Operation not permitted.
Definition errno.h:615
#define FILE_SECBOOT(_status)
Declare a file's UEFI Secure Boot permission status.
Definition compiler.h:951
#define bigint_mod_exp(base, modulus, exponent, result, tmp)
Perform modular exponentiation of big integers.
Definition bigint.h:348
#define bigint_mod_exp_tmp_len(modulus)
Calculate temporary working space required for moduluar exponentiation.
Definition bigint.h:362
#define bigint_is_geq(value, reference)
Compare big integers.
Definition bigint.h:146
#define bigint_t(size)
Define a big-integer type.
Definition bigint.h:21
#define bigint_done(value, out, len)
Finalise big integer.
Definition bigint.h:76
#define bigint_add(addend, value)
Add big integers.
Definition bigint.h:88
#define bigint_ntoa(value)
Transcribe big integer (for debugging).
Definition bigint.h:51
#define bigint_init(value, data, len)
Initialise big integer.
Definition bigint.h:63
String functions.
void * memcpy(void *dest, const void *src, size_t len) __nonnull
void * memset(void *dest, int character, size_t len) __nonnull
uint32_t base
Base.
Definition librm.h:3
unsigned long tmp
Definition linux_pci.h:65
void * malloc(size_t size)
Allocate memory.
Definition malloc.c:621
void zfree(void *ptr)
Clear and free memory.
Definition malloc.c:682
int memcmp(const void *first, const void *second, size_t len)
Compare memory regions.
Definition string.c:115
A key exchange algorithm.
Definition crypto.h:210
void * priv
Algorithm private data.
Definition crypto.h:242
A finite field DHE group.
Definition ffdhe.h:19