mirror of
https://github.com/ipxe/ipxe
synced 2026-07-06 15:51:30 +03:00
[crypto] Allow construction of shared public key to return an error
Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
@@ -42,8 +42,9 @@ FILE_SECBOOT ( PERMITTED );
|
||||
* @v exchange Key exchange algorithm
|
||||
* @v private Private key
|
||||
* @v public Public key to fill in
|
||||
* @ret rc Return status code
|
||||
*/
|
||||
void elliptic_share ( struct exchange_algorithm *exchange, const void *private,
|
||||
int elliptic_share ( struct exchange_algorithm *exchange, const void *private,
|
||||
void *public ) {
|
||||
struct elliptic_curve *curve = exchange->priv;
|
||||
size_t len = exchange->sharedsize;
|
||||
@@ -57,10 +58,14 @@ void elliptic_share ( struct exchange_algorithm *exchange, const void *private,
|
||||
|
||||
/* Calculate public key */
|
||||
result->format = ELLIPTIC_FORMAT_UNCOMPRESSED;
|
||||
rc = elliptic_multiply ( curve, curve->base, private, &result->xy );
|
||||
if ( ( rc = elliptic_multiply ( curve, curve->base, private,
|
||||
&result->xy ) ) != 0 ) {
|
||||
/* Can never fail when using the curve's own base point */
|
||||
assert ( 0 );
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* Can never fail when using the curve's own base point */
|
||||
assert ( rc == 0 );
|
||||
return rc;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+4
-3
@@ -264,12 +264,13 @@ static int ffdhe ( struct ffdhe_group *group, const void *public,
|
||||
* @v exchange Key exchange algorithm
|
||||
* @v private Private key
|
||||
* @v public Public key to fill in
|
||||
* @ret rc Return status code
|
||||
*/
|
||||
void ffdhe_share ( struct exchange_algorithm *exchange, const void *private,
|
||||
void *public ) {
|
||||
int ffdhe_share ( struct exchange_algorithm *exchange, const void *private,
|
||||
void *public ) {
|
||||
struct ffdhe_group *group = exchange->priv;
|
||||
|
||||
ffdhe ( group, NULL, private, public );
|
||||
return ffdhe ( group, NULL, private, public );
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+5
-2
@@ -836,12 +836,15 @@ void x25519_key ( const struct x25519_value *base,
|
||||
* @v exchange Key exchange algorithm
|
||||
* @v private Private key
|
||||
* @v public Public key to fill in
|
||||
* @ret rc Return status code
|
||||
*/
|
||||
static void x25519_share ( struct exchange_algorithm *exchange __unused,
|
||||
const void *private, void *public ) {
|
||||
static int x25519_share ( struct exchange_algorithm *exchange __unused,
|
||||
const void *private, void *public ) {
|
||||
|
||||
/* Calculate public key */
|
||||
x25519_key ( &x25519_generator, private, public );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -220,9 +220,10 @@ struct exchange_algorithm {
|
||||
* @v exchange Key exchange algorithm
|
||||
* @v private Private key
|
||||
* @v public Public key to fill in
|
||||
* @ret rc Return status code
|
||||
*/
|
||||
void ( * share ) ( struct exchange_algorithm *exchange,
|
||||
const void *private, void *public );
|
||||
int ( * share ) ( struct exchange_algorithm *exchange,
|
||||
const void *private, void *public );
|
||||
/**
|
||||
* Agree shared secret
|
||||
*
|
||||
@@ -390,10 +391,10 @@ pubkey_match ( struct pubkey_algorithm *pubkey,
|
||||
return pubkey->match ( pubkey, private_key, public_key );
|
||||
}
|
||||
|
||||
static inline __attribute__ (( always_inline )) void
|
||||
static inline __attribute__ (( always_inline )) int
|
||||
exchange_share ( struct exchange_algorithm *exchange, const void *private,
|
||||
void *public ) {
|
||||
exchange->share ( exchange, private, public );
|
||||
return exchange->share ( exchange, private, public );
|
||||
}
|
||||
|
||||
static inline __attribute__ (( always_inline )) int
|
||||
|
||||
@@ -29,8 +29,8 @@ FILE_SECBOOT ( PERMITTED );
|
||||
/** Format byte for uncompressed curve point representation */
|
||||
#define ELLIPTIC_FORMAT_UNCOMPRESSED 0x04
|
||||
|
||||
extern void elliptic_share ( struct exchange_algorithm *exchange,
|
||||
const void *private, void *public );
|
||||
extern int elliptic_share ( struct exchange_algorithm *exchange,
|
||||
const void *private, void *public );
|
||||
extern int elliptic_agree ( struct exchange_algorithm *exchange,
|
||||
const void *private, const void *partner,
|
||||
void *shared );
|
||||
|
||||
@@ -33,8 +33,8 @@ struct ffdhe_group {
|
||||
uint32_t lsb32;
|
||||
};
|
||||
|
||||
extern void ffdhe_share ( struct exchange_algorithm *exchange,
|
||||
const void *private, void *public );
|
||||
extern int ffdhe_share ( struct exchange_algorithm *exchange,
|
||||
const void *private, void *public );
|
||||
extern int ffdhe_agree ( struct exchange_algorithm *exchange,
|
||||
const void *private, const void *partner,
|
||||
void *shared );
|
||||
|
||||
+4
-1
@@ -1820,7 +1820,10 @@ static int tls_send_client_key_exchange_ecdhe ( struct tls_connection *tls ) {
|
||||
htonl ( sizeof ( key_xchg ) -
|
||||
sizeof ( key_xchg.type_length ) ) );
|
||||
key_xchg.public_len = sizeof ( key_xchg.public );
|
||||
exchange_share ( exchange, private, key_xchg.public );
|
||||
if ( ( rc = exchange_share ( exchange, private,
|
||||
key_xchg.public ) ) != 0 ) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* Transmit Client Key Exchange record */
|
||||
if ( ( rc = tls_send_handshake ( tls, &key_xchg,
|
||||
|
||||
@@ -67,7 +67,8 @@ void exchange_okx ( struct exchange_test *test, const char *file,
|
||||
/* Verify calculation of public key */
|
||||
DBGC ( test, "KEX %s private key:\n", exchange->name );
|
||||
DBGC_HDA ( test, 0, test->private, exchange->privsize );
|
||||
exchange_share ( exchange, test->private, actual->public );
|
||||
okx ( exchange_share ( exchange, test->private, actual->public ) == 0,
|
||||
file, line );
|
||||
DBGC ( test, "KEX %s public key:\n", exchange->name );
|
||||
DBGC_HDA ( test, 0, actual->public, exchange->pubsize );
|
||||
okx ( memcmp ( actual->public, test->public, exchange->pubsize ) == 0,
|
||||
|
||||
Reference in New Issue
Block a user