mirror of
https://git.sr.ht/~thestr4ng3r/chiaki
synced 2025-08-20 13:33:13 -07:00
Read remote ECDH Key
This commit is contained in:
parent
587fc0ea69
commit
6eba5af333
3 changed files with 47 additions and 0 deletions
|
@ -36,6 +36,7 @@ typedef struct chiaki_ecdh_t
|
||||||
CHIAKI_EXPORT ChiakiErrorCode chiaki_ecdh_init(ChiakiECDH *ecdh);
|
CHIAKI_EXPORT ChiakiErrorCode chiaki_ecdh_init(ChiakiECDH *ecdh);
|
||||||
CHIAKI_EXPORT void chiaki_ecdh_fini(ChiakiECDH *ecdh);
|
CHIAKI_EXPORT void chiaki_ecdh_fini(ChiakiECDH *ecdh);
|
||||||
CHIAKI_EXPORT ChiakiErrorCode chiaki_ecdh_get_local_pub_key(ChiakiECDH *ecdh, uint8_t *key_out, size_t *key_out_size, uint8_t *handshake_key, uint8_t *sig_out, size_t *sig_out_size);
|
CHIAKI_EXPORT ChiakiErrorCode chiaki_ecdh_get_local_pub_key(ChiakiECDH *ecdh, uint8_t *key_out, size_t *key_out_size, uint8_t *handshake_key, uint8_t *sig_out, size_t *sig_out_size);
|
||||||
|
CHIAKI_EXPORT ChiakiErrorCode chiaki_ecdh_derive_secret(ChiakiECDH *ecdh, uint8_t *remote_key, size_t remote_key_size, uint8_t *handshake_key, uint8_t *remote_sig, size_t remote_sig_size);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,5 +65,46 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_ecdh_get_local_pub_key(ChiakiECDH *ecdh, ui
|
||||||
if(!HMAC(EVP_sha256(), handshake_key, CHIAKI_HANDSHAKE_KEY_SIZE, key_out, *key_out_size, sig_out, (unsigned int *)sig_out_size))
|
if(!HMAC(EVP_sha256(), handshake_key, CHIAKI_HANDSHAKE_KEY_SIZE, key_out, *key_out_size, sig_out, (unsigned int *)sig_out_size))
|
||||||
return CHIAKI_ERR_UNKNOWN;
|
return CHIAKI_ERR_UNKNOWN;
|
||||||
|
|
||||||
|
return CHIAKI_ERR_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
CHIAKI_EXPORT ChiakiErrorCode chiaki_ecdh_derive_secret(ChiakiECDH *ecdh, uint8_t *remote_key, size_t remote_key_size, uint8_t *handshake_key, uint8_t *remote_sig, size_t remote_sig_size)
|
||||||
|
{
|
||||||
|
EC_POINT *point = EC_POINT_new(ecdh->group);
|
||||||
|
if(!point)
|
||||||
|
return CHIAKI_ERR_UNKNOWN;
|
||||||
|
|
||||||
|
if(!EC_POINT_oct2point(ecdh->group, point, remote_key, remote_key_size, NULL))
|
||||||
|
{
|
||||||
|
EC_POINT_free(point);
|
||||||
|
return CHIAKI_ERR_UNKNOWN;
|
||||||
|
}
|
||||||
|
|
||||||
|
EC_KEY *remote_ec_key = EC_KEY_new();
|
||||||
|
if(!remote_ec_key)
|
||||||
|
{
|
||||||
|
EC_POINT_free(point);
|
||||||
|
return CHIAKI_ERR_UNKNOWN;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!EC_KEY_set_group(remote_ec_key, ecdh->group))
|
||||||
|
{
|
||||||
|
EC_KEY_free(remote_ec_key);
|
||||||
|
EC_POINT_free(point);
|
||||||
|
return CHIAKI_ERR_UNKNOWN;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!EC_KEY_set_public_key(remote_ec_key, point))
|
||||||
|
{
|
||||||
|
EC_KEY_free(remote_ec_key);
|
||||||
|
EC_POINT_free(point);
|
||||||
|
return CHIAKI_ERR_UNKNOWN;
|
||||||
|
}
|
||||||
|
EC_POINT_free(point);
|
||||||
|
|
||||||
|
// TODO: do derivation
|
||||||
|
|
||||||
|
EC_KEY_free(remote_ec_key);
|
||||||
|
|
||||||
return CHIAKI_ERR_SUCCESS;
|
return CHIAKI_ERR_SUCCESS;
|
||||||
}
|
}
|
|
@ -200,6 +200,11 @@ static void nagare_takion_data_expect_bang(ChiakiNagare *nagare, uint8_t *buf, s
|
||||||
|
|
||||||
CHIAKI_LOGI(nagare->log, "Nagare bang looks good so far\n");
|
CHIAKI_LOGI(nagare->log, "Nagare bang looks good so far\n");
|
||||||
|
|
||||||
|
chiaki_ecdh_derive_secret(&nagare->session->ecdh,
|
||||||
|
ecdh_pub_key_buf.buf, ecdh_pub_key_buf.size,
|
||||||
|
nagare->session->handshake_key,
|
||||||
|
ecdh_sig_buf.buf, ecdh_sig_buf.size);
|
||||||
|
|
||||||
error:
|
error:
|
||||||
chiaki_mirai_signal(&nagare->bang_mirai, true);
|
chiaki_mirai_signal(&nagare->bang_mirai, true);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue