mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-16 19:38:09 +00:00
ed25519-donna/modm: sub more effective
- using trick: https://www.imperialviolet.org/2010/12/04/ecc.html
This commit is contained in:
parent
6a20ba5586
commit
60805d0001
@ -169,11 +169,24 @@ void neg256_modm(bignum256modm r, const bignum256modm x) {
|
||||
reduce256_modm(r);
|
||||
}
|
||||
|
||||
/* consts for subtraction, > p */
|
||||
/* Emilia Kasper trick, https://www.imperialviolet.org/2010/12/04/ecc.html */
|
||||
static const uint32_t twoP[] = {
|
||||
0x5cf5d3ed, 0x60498c68, 0x6f79cd64, 0x77be77a7, 0x40000013, 0x3fffffff, 0x3fffffff, 0x3fffffff, 0xfff};
|
||||
|
||||
/* subtraction x-y % m */
|
||||
void sub256_modm(bignum256modm r, const bignum256modm x, const bignum256modm y) {
|
||||
bignum256modm negy;
|
||||
neg256_modm(negy, y);
|
||||
add256_modm(r, x, negy);
|
||||
bignum256modm_element_t c = 0;
|
||||
c = twoP[0] + x[0] - y[0]; r[0] = c & 0x3fffffff; c >>= 30;
|
||||
c += twoP[1] + x[1] - y[1]; r[1] = c & 0x3fffffff; c >>= 30;
|
||||
c += twoP[2] + x[2] - y[2]; r[2] = c & 0x3fffffff; c >>= 30;
|
||||
c += twoP[3] + x[3] - y[3]; r[3] = c & 0x3fffffff; c >>= 30;
|
||||
c += twoP[4] + x[4] - y[4]; r[4] = c & 0x3fffffff; c >>= 30;
|
||||
c += twoP[5] + x[5] - y[5]; r[5] = c & 0x3fffffff; c >>= 30;
|
||||
c += twoP[6] + x[6] - y[6]; r[6] = c & 0x3fffffff; c >>= 30;
|
||||
c += twoP[7] + x[7] - y[7]; r[7] = c & 0x3fffffff; c >>= 30;
|
||||
c += twoP[8] + x[8] - y[8]; r[8] = c;
|
||||
reduce256_modm(r);
|
||||
}
|
||||
|
||||
/* multiplication modulo m */
|
||||
|
@ -3472,6 +3472,11 @@ START_TEST(test_ed25519_modl_sub)
|
||||
"8859d1d1deee0767a4ff1b72a3e0d0327573c69bbff5fc07cfa61414e6ef3b0e"
|
||||
},
|
||||
|
||||
{"9d91e26dbe7a14fdca9f5b20d13e828dc8c1ffe03fe90136a6bba507436ce500",
|
||||
"9ca406705ccce65eb8cbf63706d3df09fcc67216c0dc3990270731aacbb2e607",
|
||||
"eec0d15a7c1140f6e8705c8ba9658198ccfa8cca7f0cc8a57eb4745d77b9fe08"
|
||||
},
|
||||
|
||||
{"eef80ad5a9aad8b35b84f6a4eb3a7e2b222f403d455d8cdf40ad27e4cd5ae90a",
|
||||
"0000000000000000000000000000000000000000000000000000000000000000",
|
||||
"eef80ad5a9aad8b35b84f6a4eb3a7e2b222f403d455d8cdf40ad27e4cd5ae90a"
|
||||
@ -3491,6 +3496,61 @@ START_TEST(test_ed25519_modl_sub)
|
||||
"0800000000000000000000000000000000000000000000000000000000000000",
|
||||
"dbd3f55c1a631258d69cf7a2def9de1400000000000000000000000000000010"
|
||||
},
|
||||
|
||||
{"ecd3f55c1a631258d69cf7a2def9de1400000000000000000000000000000010",
|
||||
"0000000000000000000000000000000000000000000000000000000000000000",
|
||||
"ecd3f55c1a631258d69cf7a2def9de1400000000000000000000000000000010"
|
||||
},
|
||||
|
||||
{"0000000000000000000000000000000000000000000000000000000000000000",
|
||||
"ecd3f55c1a631258d69cf7a2def9de1400000000000000000000000000000010",
|
||||
"0100000000000000000000000000000000000000000000000000000000000000"
|
||||
},
|
||||
|
||||
{"0000000000000000000000000000000000000000000000000000000000000000",
|
||||
"0000000000000000000000000000000000000000000000000000000000000010",
|
||||
"edd3f55c1a631258d69cf7a2def9de1400000000000000000000000000000000"
|
||||
},
|
||||
|
||||
{"0000000000000000000000000000000000000000000000000000000000000000",
|
||||
"ffffff3f00000000000000000000000000000000000000000000000000000010",
|
||||
"eed3f51c1a631258d69cf7a2def9de1400000000000000000000000000000000"
|
||||
},
|
||||
|
||||
{"0000000000000000000000000000000000000000000000000000000000000000",
|
||||
"edd3f55c1a631258d69cf7a2def9de1400000000000000000000000000000000",
|
||||
"0000000000000000000000000000000000000000000000000000000000000010"
|
||||
},
|
||||
|
||||
{"0000000000000000000000000000000000000000000000000000000000000000",
|
||||
"e75f947f11d49d25a137fac8757538a980dec23811235cf63c48ee6bc6e4ed03",
|
||||
"067461dd088f74323565fdd96884a66b7f213dc7eedca309c3b71194391b120c"
|
||||
},
|
||||
|
||||
{"0000000000000000000000000000000000000000000000000000000000000000",
|
||||
"ecd3f55c1a631258d69cf7a2def9de140000000000000000000000000000ff0f",
|
||||
"0100000000000000000000000000000000000000000000000000000000000100"
|
||||
},
|
||||
|
||||
{"0000000000000000000000000000000000000000000000000000000000000000",
|
||||
"edd3f55c1a631258d69cf7a2def9de140000000000000000000004000000ff0f",
|
||||
"0000000000000000000000000000000000000000000000000000fcffffff0000"
|
||||
},
|
||||
|
||||
{"0000000000000000000000000000000000000000000000000000000000000000",
|
||||
"edd3f55c1a631258d69cf7a2def9de150000c0ffffffffffffffffffffffff0f",
|
||||
"000000000000000000000000000000ffffff3f00000000000000000000000000"
|
||||
},
|
||||
|
||||
{"0000000000000000000000000000000000000000000000000000000000000000",
|
||||
"edd3f55c1a631258d69cf7a2def9de1200000000000000000000000000000110",
|
||||
"edd3f55c1a631258d69cf7a2def9de160000000000000000000000000000ff0f"
|
||||
},
|
||||
|
||||
{"0000000000000000000000000000000000000000000000000000000000000000",
|
||||
"edd3f55c1a631258d69cf7a2def9de1300000000000000000000000000000010",
|
||||
"0000000000000000000000000000000100000000000000000000000000000000"
|
||||
},
|
||||
};
|
||||
|
||||
unsigned char buff[32];
|
||||
|
Loading…
Reference in New Issue
Block a user