diff options
Diffstat (limited to 'networking/tls_fe.c')
-rw-r--r-- | networking/tls_fe.c | 23 |
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 | ||
547 | void FAST_FUNC curve25519(byte *result, const byte *e, const byte *q) | 547 | static 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 | |||
605 | void 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 | } | ||