-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Build with only montgomery curves (+ DJB configuration) #2013
Changes from all commits
b1b2d90
ddc8032
edff4df
168209c
6bbec3b
d82a19e
32e6ad8
29efeea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
/** | ||
* \file config-montgomery.h | ||
* | ||
* \brief Minimal configuration for TLS with ChaCha/Poly and Curve25519 | ||
*/ | ||
/* | ||
* Copyright (C) 2018, ARM Limited, All Rights Reserved | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* This file is part of mbed TLS (https://tls.mbed.org) | ||
*/ | ||
/* | ||
* Minimal configuration for TLS with ChaCha/Poly and Curve25519 | ||
* | ||
* Distinguishing features: | ||
* - no RSA or classic DH, fully based on ECC | ||
* - no NIST curves | ||
* | ||
* See README.txt for usage instructions. | ||
*/ | ||
|
||
#ifndef MBEDTLS_CONFIG_H | ||
#define MBEDTLS_CONFIG_H | ||
|
||
/* System support */ | ||
#define MBEDTLS_HAVE_ASM | ||
#define MBEDTLS_HAVE_TIME | ||
|
||
/* mbed TLS feature support */ | ||
#define MBEDTLS_ECP_DP_CURVE25519_ENABLED | ||
#define MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED | ||
#define MBEDTLS_SSL_PROTO_TLS1_2 | ||
|
||
/* mbed TLS modules */ | ||
#define MBEDTLS_ASN1_PARSE_C | ||
#define MBEDTLS_ASN1_WRITE_C | ||
#define MBEDTLS_BIGNUM_C | ||
#define MBEDTLS_CHACHA20_C | ||
#define MBEDTLS_CHACHAPOLY_C | ||
#define MBEDTLS_CIPHER_C | ||
#define MBEDTLS_ECDH_C | ||
#define MBEDTLS_ECDSA_C | ||
#define MBEDTLS_ECP_C | ||
#define MBEDTLS_ENTROPY_C | ||
#define MBEDTLS_HMAC_DRBG_C | ||
#define MBEDTLS_MD_C | ||
#define MBEDTLS_NET_C | ||
#define MBEDTLS_OID_C | ||
#define MBEDTLS_PK_C | ||
#define MBEDTLS_PK_PARSE_C | ||
#define MBEDTLS_POLY1305_C | ||
#define MBEDTLS_SHA256_C | ||
#define MBEDTLS_SHA512_C | ||
#define MBEDTLS_SSL_CLI_C | ||
#define MBEDTLS_SSL_SRV_C | ||
#define MBEDTLS_SSL_TLS_C | ||
#define MBEDTLS_X509_CRT_PARSE_C | ||
#define MBEDTLS_X509_USE_C | ||
|
||
/* For test certificates */ | ||
#define MBEDTLS_BASE64_C | ||
#define MBEDTLS_CERTS_C | ||
#define MBEDTLS_PEM_PARSE_C | ||
|
||
/* Save RAM at the expense of ROM */ | ||
#define MBEDTLS_AES_ROM_TABLES | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't really make sense in an AES-less config, does it? While it technically doesn't hurt, I think it's confusing, if we assume these config files are not just for testing but also examples for users. |
||
|
||
/* Save RAM by adjusting to our exact needs */ | ||
#define MBEDTLS_ECP_MAX_BITS 256 | ||
#define MBEDTLS_MPI_MAX_SIZE 32 // 256 bits is 32 bytes | ||
|
||
/* Save RAM at the expense of speed, see ecp.h */ | ||
#define MBEDTLS_ECP_WINDOW_SIZE 2 | ||
#define MBEDTLS_ECP_FIXED_POINT_OPTIM 0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Only applicable to short-Weierstrass curves. Again, not technically relevant, but could be confusing for humans. |
||
|
||
/* | ||
* You should adjust this to the exact number of sources you're using: default | ||
* is the "mbedtls_platform_entropy_poll" source, but you may want to add other ones. | ||
* Minimum is 2 for the entropy test suite. | ||
*/ | ||
#define MBEDTLS_ENTROPY_MAX_SOURCES 2 | ||
|
||
/* Save ROM and a few bytes of RAM by specifying our own ciphersuite list */ | ||
#define MBEDTLS_SSL_CIPHERSUITES \ | ||
MBEDTLS_TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256, \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note: this one will need more complete support of RFC 8422 (EdDSA), and also support of https://tools.ietf.org/html/draft-ietf-curdle-pkix-10 for the certificate chain if I'm not mistaken (unless of course one only uses explicitly-trusted self-signed certificates, in which case one would be better off using raw public keys, but we don't support that yet). |
||
MBEDTLS_TLS_PSK_WITH_CHACHA20_POLY1305_SHA256, \ | ||
MBEDTLS_TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256 | ||
|
||
/* | ||
* Save RAM at the expense of interoperability: do this only if you control | ||
* both ends of the connection! (See coments in "mbedtls/ssl.h".) | ||
* The minimum size here depends on the certificate chain used as well as the | ||
* typical size of records. | ||
*/ | ||
// #define MBEDTLS_SSL_MAX_CONTENT_LEN 1024 | ||
|
||
#include "mbedtls/check_config.h" | ||
|
||
#endif /* MBEDTLS_CONFIG_H */ |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1769,7 +1769,6 @@ static int ecp_check_pubkey_sw( const mbedtls_ecp_group *grp, const mbedtls_ecp_ | |
|
||
return( ret ); | ||
} | ||
#endif /* ECP_SHORTWEIERSTRASS */ | ||
|
||
/* | ||
* R = m * P with shortcuts for m == 1 and m == -1 | ||
|
@@ -1800,15 +1799,19 @@ static int mbedtls_ecp_mul_shortcuts( mbedtls_ecp_group *grp, | |
cleanup: | ||
return( ret ); | ||
} | ||
#endif /* ECP_SHORTWEIERSTRASS */ | ||
|
||
/* | ||
* Linear combination | ||
* NOT constant-time | ||
* NOT constant-time. | ||
* Only implemented for Short Weierstrass, but unconditionally part of the | ||
* public API. | ||
*/ | ||
int mbedtls_ecp_muladd( mbedtls_ecp_group *grp, mbedtls_ecp_point *R, | ||
const mbedtls_mpi *m, const mbedtls_ecp_point *P, | ||
const mbedtls_mpi *n, const mbedtls_ecp_point *Q ) | ||
{ | ||
#if defined(ECP_SHORTWEIERSTRASS) | ||
int ret; | ||
mbedtls_ecp_point mP; | ||
#if defined(MBEDTLS_ECP_INTERNAL_ALT) | ||
|
@@ -1845,6 +1848,16 @@ int mbedtls_ecp_muladd( mbedtls_ecp_group *grp, mbedtls_ecp_point *R, | |
mbedtls_ecp_point_free( &mP ); | ||
|
||
return( ret ); | ||
|
||
#else /* ECP_SHORTWEIERSTRASS */ | ||
(void) grp; | ||
(void) R; | ||
(void) m; | ||
(void) P; | ||
(void) n; | ||
(void) Q; | ||
return( MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we prefer a run-time error in this case to a link-time error? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because the function existed and I don't want to remove a function in a minor version. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm don't think compatibility considerations apply here, as they would only matter for a non-default configuration that was simply not possible before (and never was). Prior to that change, with only Mongomery curves, you couldn't build ecp.c, so you didn't have that function either. After that change, with only Montgomery curves, you would start having the rest of the module but no that function, which you didn't have anyway. So I think I would prefer compile-time exclusion here. Note that removing this function at compile-time also means making ECDSA dependent on at least one ECDSA-capable curve (currently, only Short Weierstrass curves) to be defined, because ECDSA uses muladd(). |
||
#endif /* ECP_SHORTWEIERSTRASS */ | ||
} | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,12 +39,22 @@ | |
|
||
#if !defined(MBEDTLS_ENTROPY_C) || \ | ||
!defined(MBEDTLS_SSL_TLS_C) || !defined(MBEDTLS_SSL_CLI_C) || \ | ||
!defined(MBEDTLS_NET_C) || !defined(MBEDTLS_CTR_DRBG_C) | ||
!defined(MBEDTLS_NET_C) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wanted to enable the SSL test programs to at least build in the “DJB-only” configuration. DJB-only means no AES and therefore no CTR_DRBG. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK |
||
int main( void ) | ||
{ | ||
mbedtls_printf("MBEDTLS_ENTROPY_C and/or " | ||
"MBEDTLS_SSL_TLS_C and/or MBEDTLS_SSL_CLI_C and/or " | ||
"MBEDTLS_NET_C and/or MBEDTLS_CTR_DRBG_C and/or not defined.\n"); | ||
"MBEDTLS_NET_C not defined.\n"); | ||
return( 0 ); | ||
} | ||
#elif !( defined(MBEDTLS_CTR_DRBG_C) || \ | ||
( defined(MBEDTLS_HMAC_DRBG_C) && ( defined(MBEDTLS_SHA256_C) || \ | ||
defined(MBEDTLS_SHA512_C) ) ) ) | ||
int main( void ) | ||
{ | ||
mbedtls_printf("MBEDTLS_CTR_DRBG_C and MBEDTLS_HMAC_DRBG_C not defined, " | ||
"or MBEDTLS_HMAC_DRBG_C defined without " | ||
"MBEDTLS_SHA256_C or MBEDTLS_512_C.\n"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Typo: SHA512 |
||
return( 0 ); | ||
} | ||
#else | ||
|
@@ -53,6 +63,7 @@ int main( void ) | |
#include "mbedtls/ssl.h" | ||
#include "mbedtls/entropy.h" | ||
#include "mbedtls/ctr_drbg.h" | ||
#include "mbedtls/hmac_drbg.h" | ||
#include "mbedtls/certs.h" | ||
#include "mbedtls/x509.h" | ||
#include "mbedtls/error.h" | ||
|
@@ -530,7 +541,11 @@ int main( int argc, char *argv[] ) | |
mbedtls_x509_crt_profile crt_profile_for_test = mbedtls_x509_crt_profile_default; | ||
#endif | ||
mbedtls_entropy_context entropy; | ||
#if defined(MBEDTLS_CTR_DRBG_C) | ||
mbedtls_ctr_drbg_context ctr_drbg; | ||
#else | ||
mbedtls_hmac_drbg_context hmac_drbg; | ||
#endif | ||
mbedtls_ssl_context ssl; | ||
mbedtls_ssl_config conf; | ||
mbedtls_ssl_session saved_session; | ||
|
@@ -553,7 +568,11 @@ int main( int argc, char *argv[] ) | |
mbedtls_ssl_init( &ssl ); | ||
mbedtls_ssl_config_init( &conf ); | ||
memset( &saved_session, 0, sizeof( mbedtls_ssl_session ) ); | ||
#if defined(MBEDTLS_CTR_DRBG_C) | ||
mbedtls_ctr_drbg_init( &ctr_drbg ); | ||
#else | ||
mbedtls_hmac_drbg_init( &hmac_drbg ); | ||
#endif | ||
#if defined(MBEDTLS_X509_CRT_PARSE_C) | ||
mbedtls_x509_crt_init( &cacert ); | ||
mbedtls_x509_crt_init( &clicert ); | ||
|
@@ -1165,11 +1184,24 @@ int main( int argc, char *argv[] ) | |
fflush( stdout ); | ||
|
||
mbedtls_entropy_init( &entropy ); | ||
if( ( ret = mbedtls_ctr_drbg_seed( &ctr_drbg, mbedtls_entropy_func, | ||
&entropy, (const unsigned char *) pers, | ||
strlen( pers ) ) ) != 0 ) | ||
#if defined(MBEDTLS_CTR_DRBG_C) | ||
ret = mbedtls_ctr_drbg_seed( &ctr_drbg, mbedtls_entropy_func, | ||
&entropy, (const unsigned char *) pers, | ||
strlen( pers ) ); | ||
#else | ||
ret = mbedtls_hmac_drbg_seed( &hmac_drbg, | ||
#if defined(MBEDTLS_SHA256_C) | ||
mbedtls_md_info_from_type( MBEDTLS_MD_SHA256 ), | ||
#else | ||
mbedtls_md_info_from_type( MBEDTLS_MD_SHA512 ), | ||
#endif | ||
mbedtls_entropy_func, | ||
&entropy, (const unsigned char *) pers, | ||
strlen( pers ) ); | ||
#endif | ||
if( ret != 0 ) | ||
{ | ||
mbedtls_printf( " failed\n ! mbedtls_ctr_drbg_seed returned -0x%x\n", | ||
mbedtls_printf( " failed\n ! mbedtls_xxx_drbg_seed returned -0x%x\n", | ||
-ret ); | ||
goto exit; | ||
} | ||
|
@@ -1403,7 +1435,12 @@ int main( int argc, char *argv[] ) | |
} | ||
#endif | ||
|
||
#if defined(MBEDTLS_CTR_DRBG_C) | ||
mbedtls_ssl_conf_rng( &conf, mbedtls_ctr_drbg_random, &ctr_drbg ); | ||
#else | ||
mbedtls_ssl_conf_rng( &conf, mbedtls_hmac_drbg_random, &hmac_drbg ); | ||
#endif | ||
|
||
mbedtls_ssl_conf_dbg( &conf, my_debug, stdout ); | ||
|
||
mbedtls_ssl_conf_read_timeout( &conf, opt.read_timeout ); | ||
|
@@ -2054,7 +2091,11 @@ int main( int argc, char *argv[] ) | |
mbedtls_ssl_session_free( &saved_session ); | ||
mbedtls_ssl_free( &ssl ); | ||
mbedtls_ssl_config_free( &conf ); | ||
#if defined(MBEDTLS_CTR_DRBG_C) | ||
mbedtls_ctr_drbg_free( &ctr_drbg ); | ||
#else | ||
mbedtls_hmac_drbg_free( &hmac_drbg ); | ||
#endif | ||
mbedtls_entropy_free( &entropy ); | ||
|
||
#if defined(_WIN32) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also: