iPXE
ffdhe.h File Reference

Finite Field Diffie-Hellman Ephemeral key exchange. More...

#include <stddef.h>
#include <byteswap.h>
#include <ipxe/bigint.h>
#include <ipxe/crypto.h>

Go to the source code of this file.

Data Structures

struct  ffdhe_group
 A finite field DHE group. More...

Macros

#define FFDHE_GROUP(_name, _exchange, _constant, _bits, _expbits, _lsb)
 Define a finite field DHE group.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 FILE_SECBOOT (PERMITTED)
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 *modulus, size_t len, const void *generator, size_t generator_len)
 Check group parameters.
static int is_ffdhe (struct exchange_algorithm *exchange)
 Check if key exchange algorithm is a finite field DHE group.

Variables

struct exchange_algorithm ffdhe2048_algorithm
struct exchange_algorithm ffdhe3072_algorithm
struct exchange_algorithm ffdhe4096_algorithm
struct exchange_algorithm modp2048_algorithm
struct exchange_algorithm modp3072_algorithm
struct exchange_algorithm modp4096_algorithm

Detailed Description

Finite Field Diffie-Hellman Ephemeral key exchange.

Definition in file ffdhe.h.

Macro Definition Documentation

◆ FFDHE_GROUP

#define FFDHE_GROUP ( _name,
_exchange,
_constant,
_bits,
_expbits,
_lsb )
Value:
static struct ffdhe_group _name ## _group = { \
.name = #_name, \
.constant = (_constant), \
.len = ( _bits / 8 ), \
.size = bigint_required_size ( _bits / 8 ), \
.explen = ( ( _expbits + 7 ) / 8 ), \
.expsize = bigint_required_size ( ( _expbits + 7 ) / 8 ), \
.lsb32 = cpu_to_be32 ( _lsb ), \
}; \
struct exchange_algorithm _exchange = { \
.name = #_name, \
.privsize = ( ( _expbits + 7 ) / 8 ), \
.pubsize = ( _bits / 8 ), \
.sharedsize = ( _bits / 8 ), \
.share = ffdhe_share, \
.agree = ffdhe_agree, \
.priv = &_name ## _group, \
}
ring len
Length.
Definition dwmac.h:226
int ffdhe_share(struct exchange_algorithm *exchange, const void *private, void *public)
Share public key.
Definition ffdhe.c:275
int ffdhe_agree(struct exchange_algorithm *exchange, const void *private, const void *partner, void *shared)
Agree shared secret.
Definition ffdhe.c:291
#define cpu_to_be32(value)
Definition byteswap.h:111
#define bigint_required_size(len)
Determine number of elements required for a big-integer type.
Definition bigint.h:32
A key exchange algorithm.
Definition crypto.h:210
A finite field DHE group.
Definition ffdhe.h:19
static struct tlan_private * priv
Definition tlan.c:225

Define a finite field DHE group.

Definition at line 58 of file ffdhe.h.

58#define FFDHE_GROUP( _name, _exchange, _constant, _bits, _expbits, _lsb ) \
59 static struct ffdhe_group _name ## _group = { \
60 .name = #_name, \
61 .constant = (_constant), \
62 .len = ( _bits / 8 ), \
63 .size = bigint_required_size ( _bits / 8 ), \
64 .explen = ( ( _expbits + 7 ) / 8 ), \
65 .expsize = bigint_required_size ( ( _expbits + 7 ) / 8 ), \
66 .lsb32 = cpu_to_be32 ( _lsb ), \
67 }; \
68 struct exchange_algorithm _exchange = { \
69 .name = #_name, \
70 .privsize = ( ( _expbits + 7 ) / 8 ), \
71 .pubsize = ( _bits / 8 ), \
72 .sharedsize = ( _bits / 8 ), \
73 .share = ffdhe_share, \
74 .agree = ffdhe_agree, \
75 .priv = &_name ## _group, \
76 }

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED )

◆ ffdhe_share()

int ffdhe_share ( struct exchange_algorithm * exchange,
const void * private,
void * public )
extern

Share public key.

Parameters
exchangeKey exchange algorithm
privatePrivate key
publicPublic key to fill in
Return values
rcReturn status code

Definition at line 275 of file ffdhe.c.

276 {
277 struct ffdhe_group *group = exchange->priv;
278
279 return ffdhe ( group, NULL, private, public );
280}
#define NULL
NULL pointer (VOID *).
Definition Base.h:321
uint16_t group
Type of event.
Definition ena.h:1
static int ffdhe(struct ffdhe_group *group, const void *public, const void *private, void *shared)
Calculate FFDHE result.
Definition ffdhe.c:178
void * priv
Algorithm private data.
Definition crypto.h:242

References ffdhe(), group, NULL, and exchange_algorithm::priv.

Referenced by is_ffdhe().

◆ ffdhe_agree()

int ffdhe_agree ( struct exchange_algorithm * exchange,
const void * private,
const void * partner,
void * shared )
extern

Agree shared secret.

Parameters
exchangeKey exchange algorithm
privatePrivate key
partnerPartner public key
sharedShared secret to fill in
Return values
rcReturn status code

Definition at line 291 of file ffdhe.c.

292 {
293 struct ffdhe_group *group = exchange->priv;
294
295 return ffdhe ( group, partner, private, shared );
296}
struct eth_slow_lacp_entity_tlv partner
Partner information.
Definition eth_slow.h:5

References ffdhe(), group, partner, and exchange_algorithm::priv.

◆ ffdhe_has_params()

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 )
extern

Check group parameters.

Parameters
exchangeKey exchange algorithm
dh_pPrime modulus
dh_p_lenLength of prime modulus
dh_gGenerator
dh_g_lenLength of generator
Return values
matchField parameters are correct for this group

Leading zeros in the modulus and generator will be tolerated.

Definition at line 310 of file ffdhe.c.

312 {
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}
unsigned long long uint64_t
Definition stdint.h:13
unsigned char uint8_t
Definition stdint.h:10
#define assert(condition)
Assert a condition at run-time.
Definition assert.h:50
#define ffdhe_modulus_t(len)
An FFDHE prime modulus.
Definition ffdhe.c:63
static int is_ffdhe(struct exchange_algorithm *exchange)
Check if key exchange algorithm is a finite field DHE group.
Definition ffdhe.h:52
int memcmp(const void *first, const void *second, size_t len)
Compare memory regions.
Definition string.c:115

References assert, ffdhe_modulus_t, group, is_ffdhe(), memcmp(), and exchange_algorithm::priv.

Referenced by tls_find_param_group().

◆ is_ffdhe()

int is_ffdhe ( struct exchange_algorithm * exchange)
inlinestatic

Check if key exchange algorithm is a finite field DHE group.

Parameters
exchangeKey exchange algorithm
Return values
is_ffdheKey exchange algorithm is a finite field DHE group

Definition at line 52 of file ffdhe.h.

52 {
53
54 return ( exchange->share == ffdhe_share );
55}
int(* share)(struct exchange_algorithm *exchange, const void *private, void *public)
Share public key.
Definition crypto.h:227

References ffdhe_share(), and exchange_algorithm::share.

Referenced by ffdhe_has_params(), and tls_find_param_group().

Variable Documentation

◆ ffdhe2048_algorithm

◆ ffdhe3072_algorithm

struct exchange_algorithm ffdhe3072_algorithm
extern

◆ ffdhe4096_algorithm

struct exchange_algorithm ffdhe4096_algorithm
extern

◆ modp2048_algorithm

struct exchange_algorithm modp2048_algorithm
extern

Referenced by EXCHANGE_TEST(), and FFDHE_GROUP().

◆ modp3072_algorithm

struct exchange_algorithm modp3072_algorithm
extern

Referenced by EXCHANGE_TEST(), and FFDHE_GROUP().

◆ modp4096_algorithm

struct exchange_algorithm modp4096_algorithm
extern

Referenced by EXCHANGE_TEST(), and FFDHE_GROUP().