iPXE
ffdhe.h
Go to the documentation of this file.
1#ifndef _IPXE_FFDHE_H
2#define _IPXE_FFDHE_H
3
4/** @file
5 *
6 * Finite Field Diffie-Hellman Ephemeral key exchange
7 *
8 */
9
10FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11FILE_SECBOOT ( PERMITTED );
12
13#include <stddef.h>
14#include <byteswap.h>
15#include <ipxe/bigint.h>
16#include <ipxe/crypto.h>
17
18/** A finite field DHE group */
20 /** Group name */
21 const char *name;
22 /** Group constant */
24 /** Length of raw scalar values */
25 size_t len;
26 /** Number of elements in scalar values */
27 unsigned int size;
28 /** Length of (short) exponents */
29 size_t explen;
30 /** Number of elements in exponent values */
31 unsigned int expsize;
32 /** Least significant interesting bits of modulus (big-endian) */
34};
35
36extern int ffdhe_share ( struct exchange_algorithm *exchange,
37 const void *private, void *public );
38extern int ffdhe_agree ( struct exchange_algorithm *exchange,
39 const void *private, const void *partner,
40 void *shared );
41extern int ffdhe_has_params ( struct exchange_algorithm *exchange,
42 const void *modulus, size_t len,
43 const void *generator, size_t generator_len );
44
45/**
46 * Check if key exchange algorithm is a finite field DHE group
47 *
48 * @v exchange Key exchange algorithm
49 * @ret is_ffdhe Key exchange algorithm is a finite field DHE group
50 */
51static inline __attribute__ (( always_inline )) int
52is_ffdhe ( struct exchange_algorithm *exchange ) {
53
54 return ( exchange->share == ffdhe_share );
55}
56
57/** Define a finite field DHE group */
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 }
77
84
85#endif /* _IPXE_FFDHE_H */
unsigned int uint32_t
Definition stdint.h:12
unsigned char uint8_t
Definition stdint.h:10
ring len
Length.
Definition dwmac.h:226
struct eth_slow_lacp_entity_tlv partner
Partner information.
Definition eth_slow.h:5
int ffdhe_share(struct exchange_algorithm *exchange, const void *private, void *public)
Share public key.
Definition ffdhe.c:275
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
int ffdhe_has_params(struct exchange_algorithm *exchange, const void *modulus, size_t len, const void *generator, size_t generator_len)
Check group parameters.
Definition ffdhe.c:310
int ffdhe_share(struct exchange_algorithm *exchange, const void *private, void *public)
Share public key.
Definition ffdhe.c:275
static int is_ffdhe(struct exchange_algorithm *exchange)
Check if key exchange algorithm is a finite field DHE group.
Definition ffdhe.h:52
int ffdhe_agree(struct exchange_algorithm *exchange, const void *private, const void *partner, void *shared)
Agree shared secret.
Definition ffdhe.c:291
struct exchange_algorithm ffdhe3072_algorithm
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
Definition compiler.h:921
#define FILE_SECBOOT(_status)
Declare a file's UEFI Secure Boot permission status.
Definition compiler.h:951
#define __attribute__(x)
Definition compiler.h:10
Big integer support.
Cryptographic API.
A key exchange algorithm.
Definition crypto.h:210
int(* share)(struct exchange_algorithm *exchange, const void *private, void *public)
Share public key.
Definition crypto.h:227
A finite field DHE group.
Definition ffdhe.h:19
const uint8_t * constant
Group constant.
Definition ffdhe.h:23
size_t explen
Length of (short) exponents.
Definition ffdhe.h:29
uint32_t lsb32
Least significant interesting bits of modulus (big-endian).
Definition ffdhe.h:33
unsigned int expsize
Number of elements in exponent values.
Definition ffdhe.h:31
const char * name
Group name.
Definition ffdhe.h:21
unsigned int size
Number of elements in scalar values.
Definition ffdhe.h:27
size_t len
Length of raw scalar values.
Definition ffdhe.h:25