LCOV - code coverage report
Current view: top level - ballet/ed25519 - fd_x25519_s2n.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 15 15 100.0 %
Date: 2026-08-28 06:53:58 Functions: 2 2 100.0 %

          Line data    Source code
       1             : #include <stdint.h>
       2             : #include "../../third_party/s2n-bignum/include/s2n-bignum.h"
       3             : #include "../../util/sanitize/fd_msan.h"
       4             : 
       5             : #ifndef __ADX__
       6       69148 : #define curve25519_x25519_byte      curve25519_x25519_byte_alt
       7       60150 : #define curve25519_x25519base_byte  curve25519_x25519base_byte_alt
       8             : #endif
       9             : 
      10             : /* s2n-bignum implementation of X25519.  curve25519_x25519_byte and
      11             :    curve25519_x25519base_byte are formally-verified hand-written
      12             :    x86-64/AArch64 assembly routines from
      13             :    https://github.com/awslabs/s2n-bignum (Apache-2.0 / ISC / MIT-0).
      14             :    They implement RFC 7748 ยง5 including scalar clamping and
      15             :    u-coordinate MSB masking internally. */
      16             : 
      17             : uchar * FD_FN_SENSITIVE
      18             : fd_x25519_public( uchar       self_public_key [ 32 ],
      19       90225 :                   uchar const self_private_key[ 32 ] ) {
      20       90225 :   curve25519_x25519base_byte( self_public_key, self_private_key );
      21       90225 :   fd_msan_unpoison( self_public_key, 32UL );
      22       90225 :   return self_public_key;
      23       90225 : }
      24             : 
      25             : uchar * FD_FN_SENSITIVE
      26             : fd_x25519_exchange( uchar       shared_secret   [ 32 ],
      27             :                     uchar const self_private_key[ 32 ],
      28      103722 :                     uchar const peer_public_key [ 32 ] ) {
      29      103722 :   curve25519_x25519_byte( shared_secret, self_private_key, peer_public_key );
      30      103722 :   fd_msan_unpoison( shared_secret, 32UL );
      31             : 
      32             :   /* Reject low order points */
      33      103722 :   if( FD_UNLIKELY( fd_x25519_is_zero_const_time( shared_secret ) ) ) {
      34          93 :     return NULL;
      35          93 :   }
      36             : 
      37      103629 :   return shared_secret;
      38      103722 : }

Generated by: LCOV version 1.14