* @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;
/* 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;
}
/**
* @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 );
}
/**
* @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;
}
/**
* @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
*
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
/** 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 );
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 );
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,
/* 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,