|
iPXE
|
Finite Field Diffie-Hellman Ephemeral key exchange. More...
#include <assert.h>#include <stdint.h>#include <stdlib.h>#include <string.h>#include <errno.h>#include <ipxe/ffdhe.h>Go to the source code of this file.
Macros | |
| #define | FFDHE_LEN 512 |
| Maximum length of FFDHE prime modulus. | |
| #define | FFDHE_CONSTANT_LEN ( FFDHE_LEN - 8 /* high */ - 4 /* lsb32 */ - 8 /* low */ ) |
| Maximum length of group constant portion of FFDHE prime modulus. | |
| #define | ffdhe_modulus_t(len) |
| An FFDHE prime modulus. | |
Functions | |
| FILE_LICENCE (GPL2_OR_LATER_OR_UBDL) | |
| FILE_SECBOOT (PERMITTED) | |
| static int | ffdhe (struct ffdhe_group *group, const void *public, const void *private, void *shared) |
| Calculate FFDHE result. | |
| int | ffdhe_share (struct exchange_algorithm *exchange, const void *private, void *public) |
| Share public key. | |
| int | ffdhe_agree (struct exchange_algorithm *exchange, const void *private, const void *partner, void *shared) |
| Agree shared secret. | |
| 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. | |
| FFDHE_GROUP (ffdhe2048, ffdhe2048_algorithm, euler, 2048, 225, 0x61285c97) | |
| FFDHE_GROUP (ffdhe3072, ffdhe3072_algorithm, euler, 3072, 275, 0x66c62e37) | |
| FFDHE_GROUP (ffdhe4096, ffdhe4096_algorithm, euler, 4096, 325, 0x5e655f6a) | |
| FFDHE_GROUP (modp2048, modp2048_algorithm, pi, 2048, 230, 0x8aacaa68) | |
| FFDHE_GROUP (modp3072, modp3072_algorithm, pi, 3072, 279, 0xa93ad2ca) | |
| FFDHE_GROUP (modp4096, modp4096_algorithm, pi, 4096, 328, 0x34063199) | |
Variables | |
| static const uint8_t | euler [] |
| Euler's constant ("e"). | |
| static const uint8_t | pi [] |
| Constant "pi". | |
Finite Field Diffie-Hellman Ephemeral key exchange.
RFC 7919 defines a family of finite fields all constructed from the natural logarithm constant "e".
We choose to support only up to ffdhe4096, since this is sufficient to exceed the security strength of our RNG (128 bits).
Support for ffdhe6144 and ffdhe8192 could trivially be added by simply extending the "euler" constant and adding the relevant FFDHE_GROUP() declarations. Doing so would approximately double the space requirements for both read-only data (from 0.5kB to 1kB) and for uninitialised data (from 3.5kB to 7kB).
RFC 3526 defines an almost identical family of finite fields all constructed from the constant "pi", which may be used by older TLS servers.
Definition in file ffdhe.c.
| #define ffdhe_modulus_t | ( | len | ) |
An FFDHE prime modulus.
Definition at line 63 of file ffdhe.c.
Referenced by ffdhe(), and ffdhe_has_params().
| FILE_LICENCE | ( | GPL2_OR_LATER_OR_UBDL | ) |
| FILE_SECBOOT | ( | PERMITTED | ) |
|
static |
Calculate FFDHE result.
| group | FFDHE group |
| public | Base public value, or NULL to use generator |
| private | Private exponent |
| shared | Shared result to fill in |
| rc | Return status code |
Definition at line 178 of file ffdhe.c.
References assert, base, bigint_add, bigint_done, bigint_init, bigint_is_geq, bigint_mod_exp, bigint_mod_exp_tmp_len, bigint_ntoa, bigint_t, DBGC, ENOMEM, EPERM, euler, FFDHE_CONSTANT_LEN, ffdhe_modulus_t, group, len, malloc(), memcpy(), memset(), pi, raw, rc, result, size, tmp, typeof(), and zfree().
Referenced by ffdhe_agree(), and ffdhe_share().
| int ffdhe_share | ( | struct exchange_algorithm * | exchange, |
| const void * | private, | ||
| void * | public ) |
Share public key.
| exchange | Key exchange algorithm |
| private | Private key |
| public | Public key to fill in |
| rc | Return status code |
Definition at line 275 of file ffdhe.c.
References ffdhe(), group, NULL, and exchange_algorithm::priv.
Referenced by is_ffdhe().
| int ffdhe_agree | ( | struct exchange_algorithm * | exchange, |
| const void * | private, | ||
| const void * | partner, | ||
| void * | shared ) |
| 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.
| exchange | Key exchange algorithm |
| dh_p | Prime modulus |
| dh_p_len | Length of prime modulus |
| dh_g | Generator |
| dh_g_len | Length of generator |
| match | Field parameters are correct for this group |
Leading zeros in the modulus and generator will be tolerated.
Definition at line 310 of file ffdhe.c.
References assert, ffdhe_modulus_t, group, is_ffdhe(), memcmp(), and exchange_algorithm::priv.
Referenced by tls_find_param_group().
| FFDHE_GROUP | ( | ffdhe2048 | , |
| ffdhe2048_algorithm | , | ||
| euler | , | ||
| 2048 | , | ||
| 225 | , | ||
| 0x61285c97 | ) |
References euler, and ffdhe2048_algorithm.
| FFDHE_GROUP | ( | ffdhe3072 | , |
| ffdhe3072_algorithm | , | ||
| euler | , | ||
| 3072 | , | ||
| 275 | , | ||
| 0x66c62e37 | ) |
References euler, and ffdhe3072_algorithm.
| FFDHE_GROUP | ( | ffdhe4096 | , |
| ffdhe4096_algorithm | , | ||
| euler | , | ||
| 4096 | , | ||
| 325 | , | ||
| 0x5e655f6a | ) |
References euler, and ffdhe4096_algorithm.
| FFDHE_GROUP | ( | modp2048 | , |
| modp2048_algorithm | , | ||
| pi | , | ||
| 2048 | , | ||
| 230 | , | ||
| 0x8aacaa68 | ) |
References modp2048_algorithm, and pi.
| FFDHE_GROUP | ( | modp3072 | , |
| modp3072_algorithm | , | ||
| pi | , | ||
| 3072 | , | ||
| 279 | , | ||
| 0xa93ad2ca | ) |
References modp3072_algorithm, and pi.
| FFDHE_GROUP | ( | modp4096 | , |
| modp4096_algorithm | , | ||
| pi | , | ||
| 4096 | , | ||
| 328 | , | ||
| 0x34063199 | ) |
References modp4096_algorithm, and pi.
|
static |
Euler's constant ("e").
Definition at line 72 of file ffdhe.c.
Referenced by ffdhe(), FFDHE_GROUP(), FFDHE_GROUP(), and FFDHE_GROUP().
|
static |
Constant "pi".
Definition at line 121 of file ffdhe.c.
Referenced by ffdhe(), FFDHE_GROUP(), FFDHE_GROUP(), and FFDHE_GROUP().