1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-22 07:28:10 +00:00

fix(core,legacy): fix curve25519 public key prefix

This commit is contained in:
Ondřej Vejpustek 2024-08-14 16:44:26 +02:00
parent 3da9c6bbb9
commit 20f75e001b
5 changed files with 4 additions and 8 deletions

View File

@ -0,0 +1 @@
Changed prefix of public key returned by `get_ecdh_session_key` for curve25519.

View File

@ -46,12 +46,10 @@ async def get_ecdh_session_key(msg: GetECDHSessionKey) -> ECDHSessionKey:
from trezor.crypto.curve import secp256k1
session_key = secp256k1.multiply(node.private_key(), peer_public_key)
public_key = node.public_key()
elif curve_name == "nist256p1":
from trezor.crypto.curve import nist256p1
session_key = nist256p1.multiply(node.private_key(), peer_public_key)
public_key = node.public_key()
elif curve_name == "curve25519":
from trezor.crypto.curve import curve25519
@ -60,9 +58,8 @@ async def get_ecdh_session_key(msg: GetECDHSessionKey) -> ECDHSessionKey:
session_key = b"\x04" + curve25519.multiply(
node.private_key(), peer_public_key[1:]
)
public_key = b"\x01" + node.public_key()[1:]
else:
raise DataError("Unsupported curve for ECDH: " + curve_name)
# END ecdh
return ECDHSessionKey(session_key=session_key, public_key=public_key)
return ECDHSessionKey(session_key=session_key, public_key=node.public_key())

View File

@ -0,0 +1 @@
Changed prefix of public key returned by `get_ecdh_session_key` for curve25519.

View File

@ -221,9 +221,6 @@ void fsm_msgGetECDHSessionKey(const GetECDHSessionKey *msg) {
return;
}
memcpy(resp->public_key.bytes, node->public_key, 33);
if (strcmp(curve, CURVE25519_NAME) == 0) {
resp->public_key.bytes[0] = 0x01;
}
resp->public_key.size = 33;
resp->has_public_key = true;
msg_write(MessageType_MessageType_ECDHSessionKey, resp);

View File

@ -84,5 +84,5 @@ def test_ecdh(client: Client):
)
assert (
result.public_key.hex()
== "019753a0738c55c7ba7c17dd4a9a975ce9b0d2b62e8a1ecef4a76767fad99d3c71"
== "009753a0738c55c7ba7c17dd4a9a975ce9b0d2b62e8a1ecef4a76767fad99d3c71"
)