iPXE
elliptic.c File Reference

Elliptic curves. More...

#include <assert.h>
#include <errno.h>
#include <string.h>
#include <ipxe/crypto.h>
#include <ipxe/elliptic.h>

Go to the source code of this file.

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.c.

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 )

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
ring len
Length.
Definition dwmac.h:226
#define elliptic_uncompressed_t(len)
An uncompressed elliptic curve point.
Definition elliptic.h:17
#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 )

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.