mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-01-31 03:27:39 +00:00
ea83cc0ad0
One of the disadvantages of x25519 and ℘256 is it only provides 126 bits of security, so that seems like a weak link in the chain, if we're using ECDHE-ECDSA-AES256-GCM-SHA384. The U.S. government wants classified data to be encrypted using a curve at least as strong as ℘384, which provides 192 bits of security, but if you read the consensus of stack exchange it would give you the impression that ℘384 is three times slower. This change (as well as the previous one) makes ℘384 three times as fast by tuning its modulus and multiplication subroutines with new tests that should convincingly show: the optimized code behaves the same way as the old code. Some of the diff noise from the previous change is now removed too, so that our vendored fork can be more easily compared with upstream sources. So you can now have stronger cryptography without compromises. ℘384 modulus Justine l: 28𝑐 9𝑛𝑠 ℘384 modulus MbedTLS NIST l: 127𝑐 41𝑛𝑠 ℘384 modulus MbedTLS MPI l: 1,850𝑐 597𝑛𝑠 The benchmarks above show the improvements made by secp384r1() which is an important function since it needs to be called 13,000 times whenever someone establishes a connection to your web server. The same's true of Mul6x6Adx() which is able to multiply 384-bit numbers in 73 cycles, but only if your CPU was purchased after 2014 when Broadwell was introduced
43 lines
1.9 KiB
C
43 lines
1.9 KiB
C
#ifndef COSMOPOLITAN_THIRD_PARTY_MBEDTLS_X25519_H_
|
|
#define COSMOPOLITAN_THIRD_PARTY_MBEDTLS_X25519_H_
|
|
#include "third_party/mbedtls/config.h"
|
|
#include "third_party/mbedtls/ecp.h"
|
|
COSMOPOLITAN_C_START_
|
|
|
|
#define MBEDTLS_ECP_TLS_CURVE25519 0x1d
|
|
#define MBEDTLS_X25519_KEY_SIZE_BYTES 32
|
|
|
|
typedef enum {
|
|
MBEDTLS_EVEREST_ECDH_OURS,
|
|
MBEDTLS_EVEREST_ECDH_THEIRS,
|
|
} mbedtls_everest_ecdh_side;
|
|
|
|
typedef struct {
|
|
unsigned char our_secret[MBEDTLS_X25519_KEY_SIZE_BYTES];
|
|
unsigned char peer_point[MBEDTLS_X25519_KEY_SIZE_BYTES];
|
|
} mbedtls_ecdh_context_everest;
|
|
|
|
int mbedtls_everest_setup(mbedtls_ecdh_context_everest *, int);
|
|
void mbedtls_everest_free(mbedtls_ecdh_context_everest *);
|
|
int mbedtls_everest_make_params(mbedtls_ecdh_context_everest *, size_t *,
|
|
unsigned char *, size_t,
|
|
int (*)(void *, unsigned char *, size_t),
|
|
void *);
|
|
int mbedtls_everest_read_params(mbedtls_ecdh_context_everest *,
|
|
const unsigned char **, const unsigned char *);
|
|
int mbedtls_everest_get_params(mbedtls_ecdh_context_everest *,
|
|
const mbedtls_ecp_keypair *,
|
|
mbedtls_everest_ecdh_side);
|
|
int mbedtls_everest_make_public(mbedtls_ecdh_context_everest *, size_t *,
|
|
unsigned char *, size_t,
|
|
int (*)(void *, unsigned char *, size_t),
|
|
void *);
|
|
int mbedtls_everest_read_public(mbedtls_ecdh_context_everest *,
|
|
const unsigned char *, size_t);
|
|
int mbedtls_everest_calc_secret(mbedtls_ecdh_context_everest *, size_t *,
|
|
unsigned char *, size_t,
|
|
int (*)(void *, unsigned char *, size_t),
|
|
void *);
|
|
|
|
COSMOPOLITAN_C_END_
|
|
#endif /* COSMOPOLITAN_THIRD_PARTY_MBEDTLS_X25519_H_ */
|