Go to file
Nicola Tuveri a377871db1 [PROV][KEYMGMT][EC] Import/export of priv_key as padded const time BN
For EC keys it is particularly important to avoid leaking the bit length
of the secret scalar.

Key import/export should never leak the bit length of the secret
scalar in the key.

For this reason, on export we use padded BIGNUMs with fixed length,
using the new `ossl_param_bld_push_BN_pad()`.

When importing we also should make sure that, even if short lived,
the newly created BIGNUM is marked with the BN_FLG_CONSTTIME flag as
soon as possible, so that any processing of this BIGNUM might opt for
constant time implementations in the backend.

Setting the BN_FLG_CONSTTIME flag alone is never enough, we also have
to preallocate the BIGNUM internal buffer to a fixed size big enough
that operations performed during the processing never trigger a
realloc which would leak the size of the scalar through memory
accesses.

Fixed length
------------

The order of the large prime subgroup of the curve is our choice for
a fixed public size, as that is generally the upper bound for
generating a private key in EC cryptosystems and should fit all valid
secret scalars.

For padding on export we just use the bit length of the order
converted to bytes (rounding up).

For preallocating the BIGNUM storage we look at the number of "words"
required for the internal representation of the order, and we
preallocate 2 extra "words" in case any of the subsequent processing
might temporarily overflow the order length.

Future work
-----------

To ensure the flag and fixed size preallocation persists upon
`EC_KEY_set_private_key()`, we need to further harden
`EC_KEY_set_private_key()` and `BN_copy()`.
This is done in separate commits.

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/10631)
2020-02-18 19:11:10 +02:00
.github
apps Deprecate EC command line apps. 2020-02-18 19:53:52 +10:00
boringssl@2070f8ad91
Configurations TEST: Create test specific output directories 2020-02-18 09:45:51 +01:00
crypto [PROV][KEYMGMT][EC] Import/export of priv_key as padded const time BN 2020-02-18 19:11:10 +02:00
demos
doc DOC:Fix typos in x509v3_config.pod 2020-02-18 13:40:11 +01:00
engines Fix misspelling errors and typos reported by codespell 2020-02-06 17:01:00 +01:00
external/perl
fuzz Deprecate the low level DSA functions. 2020-02-12 08:52:41 +10:00
include [PROV][KMGMT][KEXCH][EC] Implement EC keymgtm and ECDH 2020-02-18 19:11:10 +02:00
krb5@890ca2f401 Update the krb5 submodule 2019-12-25 12:45:32 -08:00
ms
os-dep
providers [PROV][KEYMGMT][EC] Import/export of priv_key as padded const time BN 2020-02-18 19:11:10 +02:00
pyca-cryptography@09403100de
ssl Fix coverity issues 2020-02-14 07:28:46 +10:00
test [CMS] Test decryption of a ciphertext encrypted from 1.1.1 2020-02-18 19:11:10 +02:00
tools
util [PROV][KMGMT][KEXCH][EC] Implement EC keymgtm and ECDH 2020-02-18 19:11:10 +02:00
VMS
.gitattributes
.gitignore TEST: Create test specific output directories 2020-02-18 09:45:51 +01:00
.gitmodules
.travis-apt-pin.preferences
.travis-create-release.sh
.travis.yml Add a minimal build target for Travis and Appveyor 2020-02-11 13:22:39 +01:00
ACKNOWLEDGEMENTS
appveyor.yml Add a minimal build target for Travis and Appveyor 2020-02-11 13:22:39 +01:00
AUTHORS
build.info Add better support for using deprecated symbols internally 2019-12-13 10:09:49 +01:00
CHANGES Deprecate EC command line apps. 2020-02-18 19:53:52 +10:00
config config: ensure the perl Configure run is the last statement 2020-02-02 11:54:46 +01:00
config.com
configdata.pm.in configdata.pm.in: Don't try to quotify undefined values 2019-12-04 00:19:40 +01:00
Configure Make secure-memory be a config option 2020-02-14 15:18:27 +01:00
CONTRIBUTING Fix misspelling errors and typos reported by codespell 2020-02-06 17:01:00 +01:00
e_os.h Make secure-memory be a config option 2020-02-14 15:18:27 +01:00
FAQ
HACKING
INSTALL Deprecate most of debug-memory 2019-12-14 20:57:35 +01:00
LICENSE
NEWS Add NEWS entry about deprecation of command line public tools 2020-02-12 08:52:42 +10:00
NOTES.ANDROID Remove spurious space from file. 2019-12-05 07:25:52 +10:00
NOTES.DJGPP
NOTES.PERL
NOTES.UNIX
NOTES.VALGRIND
NOTES.VMS
NOTES.WIN
README
README.ENGINE
README.FIPS
VERSION

 Copyright (c) 1998-2018 The OpenSSL Project
 Copyright (c) 1995-1998 Eric A. Young, Tim J. Hudson
 All rights reserved.

 DESCRIPTION
 -----------

 The OpenSSL Project is a collaborative effort to develop a robust,
 commercial-grade, fully featured, and Open Source toolkit implementing the
 Transport Layer Security (TLS) protocols (including SSLv3) as well as a
 full-strength general purpose cryptographic library.

 OpenSSL is descended from the SSLeay library developed by Eric A. Young
 and Tim J. Hudson.

 The OpenSSL toolkit is licensed under the Apache License 2.0, which means
 that you are free to get and use it for commercial and non-commercial
 purposes as long as you fulfill its conditions.

 OVERVIEW
 --------

 The OpenSSL toolkit includes:

 libssl (with platform specific naming):
     Provides the client and server-side implementations for SSLv3 and TLS.

 libcrypto (with platform specific naming):
     Provides general cryptographic and X.509 support needed by SSL/TLS but
     not logically part of it.

 openssl:
     A command line tool that can be used for:
        Creation of key parameters
        Creation of X.509 certificates, CSRs and CRLs
        Calculation of message digests
        Encryption and decryption
        SSL/TLS client and server tests
        Handling of S/MIME signed or encrypted mail
        And more...

 INSTALLATION
 ------------

 See the appropriate file:
        INSTALL         Linux, Unix, Windows, OpenVMS, ...
        NOTES.*         INSTALL addendums for different platforms

 SUPPORT
 -------

 See the OpenSSL website www.openssl.org for details on how to obtain
 commercial technical support. Free community support is available through the
 openssl-users email list (see
 https://www.openssl.org/community/mailinglists.html for further details).

 If you have any problems with OpenSSL then please take the following steps
 first:

    - Download the latest version from the repository
      to see if the problem has already been addressed
    - Configure with no-asm
    - Remove compiler optimization flags

 If you wish to report a bug then please include the following information
 and create an issue on GitHub:

    - OpenSSL version: output of 'openssl version -a'
    - Configuration data: output of 'perl configdata.pm --dump'
    - OS Name, Version, Hardware platform
    - Compiler Details (name, version)
    - Application Details (name, version)
    - Problem Description (steps that will reproduce the problem, if known)
    - Stack Traceback (if the application dumps core)

 Just because something doesn't work the way you expect does not mean it
 is necessarily a bug in OpenSSL. Use the openssl-users email list for this type
 of query.

 HOW TO CONTRIBUTE TO OpenSSL
 ----------------------------

 See CONTRIBUTING

 LEGALITIES
 ----------

 A number of nations restrict the use or export of cryptography. If you
 are potentially subject to such restrictions you should seek competent
 professional legal advice before attempting to develop or distribute
 cryptographic code.