iPXE
elliptic.h File Reference

Elliptic curves. More...

#include <stdint.h>
#include <ipxe/crypto.h>

Go to the source code of this file.

Macros

#define elliptic_uncompressed_t(len)
 An uncompressed elliptic curve point.
#define ELLIPTIC_FORMAT_UNCOMPRESSED   0x04
 Format byte for uncompressed curve point representation.
#define ELLIPTIC_EXCHANGE(_name, _exchange, _len, _curve)
 Define an uncompressed elliptic curve point key exchange algorithm.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 FILE_SECBOOT (PERMITTED)
int elliptic_share (struct exchange_algorithm *exchange, const void *private, void *public)
 Share public key.
int elliptic_agree (struct exchange_algorithm *exchange, const void *private, const void *partner, void *shared)
 Agree shared secret.

Detailed Description

Elliptic curves.

Definition in file elliptic.h.

Macro Definition Documentation

◆ elliptic_uncompressed_t

#define elliptic_uncompressed_t ( len)
Value:
struct { \
union { \
struct { \
uint8_t x[ (len) ]; \
uint8_t y[ (len) ]; \
} __attribute__ (( packed )); \
uint8_t xy[ (len) * 2 ]; \
}; \
} __attribute__ (( packed ))
unsigned char uint8_t
Definition stdint.h:10
ring len
Length.
Definition dwmac.h:226
#define __attribute__(x)
Definition compiler.h:10
static unsigned int unsigned int y
Definition pixbuf.h:63
static unsigned int x
Definition pixbuf.h:63
int const char * format
Definition xfer.h:105

An uncompressed elliptic curve point.

Definition at line 17 of file elliptic.h.

17#define elliptic_uncompressed_t( len ) \
18 struct { \
19 uint8_t format; \
20 union { \
21 struct { \
22 uint8_t x[ (len) ]; \
23 uint8_t y[ (len) ]; \
24 } __attribute__ (( packed )); \
25 uint8_t xy[ (len) * 2 ]; \
26 }; \
27 } __attribute__ (( packed ))

Referenced by elliptic_agree(), and elliptic_share().

◆ ELLIPTIC_FORMAT_UNCOMPRESSED

#define ELLIPTIC_FORMAT_UNCOMPRESSED   0x04

Format byte for uncompressed curve point representation.

Definition at line 30 of file elliptic.h.

Referenced by elliptic_agree(), and elliptic_share().

◆ ELLIPTIC_EXCHANGE

#define ELLIPTIC_EXCHANGE ( _name,
_exchange,
_len,
_curve )
Value:
struct exchange_algorithm _exchange = { \
.name = #_name, \
.privsize = (_len), \
.pubsize = sizeof ( elliptic_uncompressed_t (_len) ), \
.sharedsize = (_len), \
.share = elliptic_share, \
.agree = elliptic_agree, \
.priv = _curve, \
}
int elliptic_agree(struct exchange_algorithm *exchange, const void *private, const void *partner, void *shared)
Agree shared secret.
Definition elliptic.c:80
int elliptic_share(struct exchange_algorithm *exchange, const void *private, void *public)
Share public key.
Definition elliptic.c:47
#define elliptic_uncompressed_t(len)
An uncompressed elliptic curve point.
Definition elliptic.h:17
A key exchange algorithm.
Definition crypto.h:210
static struct tlan_private * priv
Definition tlan.c:225

Define an uncompressed elliptic curve point key exchange algorithm.

Definition at line 39 of file elliptic.h.

39#define ELLIPTIC_EXCHANGE( _name, _exchange, _len, _curve ) \
40 struct exchange_algorithm _exchange = { \
41 .name = #_name, \
42 .privsize = (_len), \
43 .pubsize = sizeof ( elliptic_uncompressed_t (_len) ), \
44 .sharedsize = (_len), \
45 .share = elliptic_share, \
46 .agree = elliptic_agree, \
47 .priv = _curve, \
48 }

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED )

◆ elliptic_share()

int elliptic_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 47 of file elliptic.c.

48 {
49 struct elliptic_curve *curve = exchange->priv;
50 size_t len = exchange->sharedsize;
52 int rc;
53
54 /* Sanity checks */
55 assert ( curve->keysize == exchange->privsize );
56 assert ( curve->pointsize == sizeof ( result->xy ) );
57 assert ( sizeof ( *result ) == exchange->pubsize );
58
59 /* Calculate public key */
61 if ( ( rc = elliptic_multiply ( curve, curve->base, private,
62 &result->xy ) ) != 0 ) {
63 /* Can never fail when using the curve's own base point */
64 assert ( 0 );
65 return rc;
66 }
67
68 return rc;
69}
struct arbelprm_rc_send_wqe rc
Definition arbel.h:3
uint16_t result
Definition hyperv.h:33
#define assert(condition)
Assert a condition at run-time.
Definition assert.h:50
#define ELLIPTIC_FORMAT_UNCOMPRESSED
Format byte for uncompressed curve point representation.
Definition elliptic.h:30
static int elliptic_multiply(struct elliptic_curve *curve, const void *base, const void *scalar, void *result)
Definition crypto.h:414
An elliptic curve.
Definition crypto.h:246
size_t keysize
Scalar (and private key) size.
Definition crypto.h:252
size_t pointsize
Point (and public key) size.
Definition crypto.h:250
const void * base
Generator base point.
Definition crypto.h:254
size_t sharedsize
Shared secret size.
Definition crypto.h:218
size_t privsize
Private key size.
Definition crypto.h:214
size_t pubsize
Public key size.
Definition crypto.h:216
void * priv
Algorithm private data.
Definition crypto.h:242

References assert, elliptic_curve::base, ELLIPTIC_FORMAT_UNCOMPRESSED, elliptic_multiply(), elliptic_uncompressed_t, elliptic_curve::keysize, len, elliptic_curve::pointsize, exchange_algorithm::priv, exchange_algorithm::privsize, exchange_algorithm::pubsize, rc, result, and exchange_algorithm::sharedsize.

◆ elliptic_agree()

int elliptic_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 80 of file elliptic.c.

81 {
82 struct elliptic_curve *curve = exchange->priv;
83 size_t len = exchange->sharedsize;
86 int rc;
87
88 /* Sanity checks */
89 assert ( curve->keysize == exchange->privsize );
90 assert ( curve->pointsize == sizeof ( base->xy ) );
91 assert ( curve->pointsize == sizeof ( result.xy ) );
92 assert ( sizeof ( *base ) == exchange->pubsize );
93 assert ( sizeof ( result.x ) == exchange->sharedsize );
94
95 /* Calculate shared secret */
96 if ( ( rc = elliptic_multiply ( curve, &base->xy, private,
97 result.xy ) ) != 0 )
98 return rc;
99 memcpy ( shared, &result.x, sizeof ( result.x ) );
100
101 /* Check for point at infinity */
102 if ( elliptic_is_infinity ( curve, &result.xy ) )
103 return -EPERM;
104
105 /* Check format byte */
106 if ( base->format != ELLIPTIC_FORMAT_UNCOMPRESSED )
107 return -EPERM;
108
109 return 0;
110}
struct eth_slow_lacp_entity_tlv partner
Partner information.
Definition eth_slow.h:5
#define EPERM
Operation not permitted.
Definition errno.h:615
static int elliptic_is_infinity(struct elliptic_curve *curve, const void *point)
Definition crypto.h:409
void * memcpy(void *dest, const void *src, size_t len) __nonnull
uint32_t base
Base.
Definition librm.h:3

References assert, base, ELLIPTIC_FORMAT_UNCOMPRESSED, elliptic_is_infinity(), elliptic_multiply(), elliptic_uncompressed_t, EPERM, elliptic_curve::keysize, len, memcpy(), partner, elliptic_curve::pointsize, exchange_algorithm::priv, exchange_algorithm::privsize, exchange_algorithm::pubsize, rc, result, and exchange_algorithm::sharedsize.