From 48a18d15dfbfa41d137802e811a3abdfef012ac8 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 27 Apr 2021 12:24:21 +0200 Subject: tls: shrink p256_base more function old new delta static.p256_base_bin - 64 +64 sp_256_point_from_bin2x32 - 62 +62 static.base_y 40 - -40 static.base_x 40 - -40 curve_P256_compute_pubkey_and_premaster 291 194 -97 ------------------------------------------------------------------------------ (add/remove: 2/2 grow/shrink: 0/1 up/down: 126/-177) Total: -51 bytes Signed-off-by: Denys Vlasenko --- networking/tls_sp_c32.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/networking/tls_sp_c32.c b/networking/tls_sp_c32.c index 64c53b006..f9c66b186 100644 --- a/networking/tls_sp_c32.c +++ b/networking/tls_sp_c32.c @@ -790,19 +790,16 @@ static void sp_256_ecc_mulmod_base_10(sp_point* r, sp_digit* k /*, int map*/) * don't have "static const sp_point p256_base = {...}", * it would have more zeros than data. */ - static const sp_digit base_x[] = { - 0x098c296,0x04e5176,0x33a0f4a,0x204b7ac,0x277037d,0x0e9103c,0x3ce6e56,0x1091fe2,0x1f2e12c,0x01ac5f4 - }; - static const sp_digit base_y[] = { - 0x3bf51f5,0x1901a0d,0x1ececbb,0x15dacc5,0x22bce33,0x303e785,0x27eb4a7,0x1fe6e3b,0x2e2fe1a,0x013f8d0 + static const uint8_t p256_base_bin[] = { + /* x (big-endian) */ + 0x6b,0x17,0xd1,0xf2,0xe1,0x2c,0x42,0x47,0xf8,0xbc,0xe6,0xe5,0x63,0xa4,0x40,0xf2,0x77,0x03,0x7d,0x81,0x2d,0xeb,0x33,0xa0,0xf4,0xa1,0x39,0x45,0xd8,0x98,0xc2,0x96, + /* y */ + 0x4f,0xe3,0x42,0xe2,0xfe,0x1a,0x7f,0x9b,0x8e,0xe7,0xeb,0x4a,0x7c,0x0f,0x9e,0x16,0x2b,0xce,0x33,0x57,0x6b,0x31,0x5e,0xce,0xcb,0xb6,0x40,0x68,0x37,0xbf,0x51,0xf5, + /* z will be set to 0, infinity flag to "false" */ }; sp_point p256_base; - memset(&p256_base, 0, sizeof(p256_base)); - memcpy(p256_base.x, base_x, sizeof(base_x)); - memcpy(p256_base.y, base_y, sizeof(base_y)); - p256_base.z[0] = 1; - /*p256_base.infinity = 0;*/ + sp_256_point_from_bin2x32(&p256_base, p256_base_bin); sp_256_ecc_mulmod_10(r, &p256_base, k /*, map*/); } -- cgit v1.2.3