From cf0a133e683953f939febcb8b848e4c6322f05a5 Mon Sep 17 00:00:00 2001 From: BTChip github Date: Sun, 9 May 2021 21:42:51 +0200 Subject: [PATCH] Interim fix for different cx_ecfp_scalar_mult behaviour in firmware v2 --- src/stark_utils.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/stark_utils.c b/src/stark_utils.c index 5e66288..45ec2a9 100644 --- a/src/stark_utils.c +++ b/src/stark_utils.c @@ -67,9 +67,12 @@ static const ECPoint PEDERSEN_POINTS[4] = { void accum_ec_mul(ECPoint *hash, uint8_t *buf, int len, int pedersen_idx) { ECPoint tmp; if (!allzeroes(buf, len)) { + uint8_t pad[32]; memcpy(tmp, PEDERSEN_POINTS[pedersen_idx], sizeof(ECPoint)); io_seproxyhal_io_heartbeat(); - cx_ecfp_scalar_mult(CX_CURVE_Stark256, tmp, sizeof(ECPoint), buf, len); + memset(pad, 0, sizeof(pad)); + memmove(pad + 32 - len, buf, len); + cx_ecfp_scalar_mult(CX_CURVE_Stark256, tmp, sizeof(ECPoint), pad, sizeof(pad)); io_seproxyhal_io_heartbeat(); cx_ecfp_add_point(CX_CURVE_Stark256, *hash, *hash, tmp, sizeof(ECPoint)); }