aboutsummaryrefslogtreecommitdiff
path: root/networking/tls_fe.c
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2021-04-26 13:46:36 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2021-04-26 13:46:36 +0200
commit6b69ab68b47d0933f8b4a1d7ed8460274a736a5f (patch)
treefd8febe91940f0c2fa8761d5ae6e65bfd4f4ec1f /networking/tls_fe.c
parentf18a1fd6f368ada05b33cf36483304a5e3c4945d (diff)
downloadbusybox-w32-6b69ab68b47d0933f8b4a1d7ed8460274a736a5f.tar.gz
busybox-w32-6b69ab68b47d0933f8b4a1d7ed8460274a736a5f.tar.bz2
busybox-w32-6b69ab68b47d0933f8b4a1d7ed8460274a736a5f.zip
tls: make x25519 key generation code more similar to P256
function old new delta curve_x25519_compute_pubkey_and_premaster - 74 +74 tls_handshake 2146 2072 -74 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 0/1 up/down: 74/-74) Total: 0 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'networking/tls_fe.c')
-rw-r--r--networking/tls_fe.c23
1 files changed, 22 insertions, 1 deletions
diff --git a/networking/tls_fe.c b/networking/tls_fe.c
index f810e112a..3b3578c0d 100644
--- a/networking/tls_fe.c
+++ b/networking/tls_fe.c
@@ -544,7 +544,7 @@ static void xc_double(byte *x3, byte *z3,
544 fe_mul_c(z3, x1sq, 4); 544 fe_mul_c(z3, x1sq, 4);
545} 545}
546 546
547void FAST_FUNC curve25519(byte *result, const byte *e, const byte *q) 547static void curve25519(byte *result, const byte *e, const byte *q)
548{ 548{
549 int i; 549 int i;
550 550
@@ -599,3 +599,24 @@ void FAST_FUNC curve25519(byte *result, const byte *e, const byte *q)
599 fe_mul__distinct(result, zm1, xm); 599 fe_mul__distinct(result, zm1, xm);
600 fe_normalize(result); 600 fe_normalize(result);
601} 601}
602
603/* interface to bbox's TLS code: */
604
605void FAST_FUNC curve_x25519_compute_pubkey_and_premaster(
606 uint8_t *pubkey, uint8_t *premaster,
607 const uint8_t *peerkey32)
608{
609 static const uint8_t basepoint9[CURVE25519_KEYSIZE] ALIGN8 = {9};
610 uint8_t privkey[CURVE25519_KEYSIZE]; //[32]
611
612 /* Generate random private key, see RFC 7748 */
613 tls_get_random(privkey, sizeof(privkey));
614 privkey[0] &= 0xf8;
615 privkey[CURVE25519_KEYSIZE-1] = ((privkey[CURVE25519_KEYSIZE-1] & 0x7f) | 0x40);
616
617 /* Compute public key */
618 curve25519(pubkey, privkey, basepoint9);
619
620 /* Compute premaster using peer's public key */
621 curve25519(premaster, privkey, peerkey32);
622}