1. 28 9月, 2019 2 次提交
    • D
      Reorganize local header files · b5acbf91
      Dr. Matthias St. Pierre 提交于
      Apart from public and internal header files, there is a third type called
      local header files, which are located next to source files in the source
      directory. Currently, they have different suffixes like
      
        '*_lcl.h', '*_local.h', or '*_int.h'
      
      This commit changes the different suffixes to '*_local.h' uniformly.
      Reviewed-by: NRichard Levitte <levitte@openssl.org>
      (Merged from https://github.com/openssl/openssl/pull/9681)
      b5acbf91
    • D
      Reorganize private crypto header files · 0c994d54
      Dr. Matthias St. Pierre 提交于
      Currently, there are two different directories which contain internal
      header files of libcrypto which are meant to be shared internally:
      
      While header files in 'include/internal' are intended to be shared
      between libcrypto and libssl, the files in 'crypto/include/internal'
      are intended to be shared inside libcrypto only.
      
      To make things complicated, the include search path is set up in such
      a way that the directive #include "internal/file.h" could refer to
      a file in either of these two directoroes. This makes it necessary
      in some cases to add a '_int.h' suffix to some files to resolve this
      ambiguity:
      
        #include "internal/file.h"      # located in 'include/internal'
        #include "internal/file_int.h"  # located in 'crypto/include/internal'
      
      This commit moves the private crypto headers from
      
        'crypto/include/internal'  to  'include/crypto'
      
      As a result, the include directives become unambiguous
      
        #include "internal/file.h"       # located in 'include/internal'
        #include "crypto/file.h"         # located in 'include/crypto'
      
      hence the superfluous '_int.h' suffixes can be stripped.
      
      The files 'store_int.h' and 'store.h' need to be treated specially;
      they are joined into a single file.
      Reviewed-by: NRichard Levitte <levitte@openssl.org>
      (Merged from https://github.com/openssl/openssl/pull/9681)
      0c994d54
  2. 16 9月, 2019 1 次提交
  3. 13 9月, 2019 1 次提交
  4. 10 9月, 2019 1 次提交
  5. 09 9月, 2019 1 次提交
    • N
      [ec] Match built-in curves on EC_GROUP_new_from_ecparameters · 9a43a733
      Nicola Tuveri 提交于
      Description
      -----------
      
      Upon `EC_GROUP_new_from_ecparameters()` check if the parameters match any
      of the built-in curves. If that is the case, return a new
      `EC_GROUP_new_by_curve_name()` object instead of the explicit parameters
      `EC_GROUP`.
      
      This affects all users of `EC_GROUP_new_from_ecparameters()`:
      - direct calls to `EC_GROUP_new_from_ecparameters()`
      - direct calls to `EC_GROUP_new_from_ecpkparameters()` with an explicit
        parameters argument
      - ASN.1 parsing of explicit parameters keys (as it eventually
        ends up calling `EC_GROUP_new_from_ecpkparameters()`)
      
      A parsed explicit parameter key will still be marked with the
      `OPENSSL_EC_EXPLICIT_CURVE` ASN.1 flag on load, so, unless
      programmatically forced otherwise, if the key is eventually serialized
      the output will still be encoded with explicit parameters, even if
      internally it is treated as a named curve `EC_GROUP`.
      
      Before this change, creating any `EC_GROUP` object using
      `EC_GROUP_new_from_ecparameters()`, yielded an object associated with
      the default generic `EC_METHOD`, but this was never guaranteed in the
      documentation.
      After this commit, users of the library that intentionally want to
      create an `EC_GROUP` object using a specific `EC_METHOD` can still
      explicitly call `EC_GROUP_new(foo_method)` and then manually set the
      curve parameters using `EC_GROUP_set_*()`.
      
      Motivation
      ----------
      
      This has obvious performance benefits for the built-in curves with
      specialized `EC_METHOD`s and subtle but important security benefits:
      - the specialized methods have better security hardening than the
        generic implementations
      - optional fields in the parameter encoding, like the `cofactor`, cannot
        be leveraged by an attacker to force execution of the less secure
        code-paths for single point scalar multiplication
      - in general, this leads to reducing the attack surface
      
      Check the manuscript at https://arxiv.org/abs/1909.01785 for an in depth
      analysis of the issues related to this commit.
      
      It should be noted that `libssl` does not allow to negotiate explicit
      parameters (as per RFC 8422), so it is not directly affected by the
      consequences of using explicit parameters that this commit fixes.
      On the other hand, we detected external applications and users in the
      wild that use explicit parameters by default (and sometimes using 0 as
      the cofactor value, which is technically not a valid value per the
      specification, but is tolerated by parsers for wider compatibility given
      that the field is optional).
      These external users of `libcrypto` are exposed to these vulnerabilities
      and their security will benefit from this commit.
      
      Related commits
      ---------------
      
      While this commit is beneficial for users using built-in curves and
      explicit parameters encoding for serialized keys, commit
      b783beeadf6b80bc431e6f3230b5d5585c87ef87 (and its equivalents for the
      1.0.2, 1.1.0 and 1.1.1 stable branches) fixes the consequences of the
      invalid cofactor values more in general also for other curves
      (CVE-2019-1547).
      
      The following list covers commits in `master` that are related to the
      vulnerabilities presented in the manuscript motivating this commit:
      
      - d2baf88c43 [crypto/rsa] Set the constant-time flag in multi-prime RSA too
      - 311e903d84 [crypto/asn1] Fix multiple SCA vulnerabilities during RSA key validation.
      - b783beeadf [crypto/ec] for ECC parameters with NULL or zero cofactor, compute it
      - 724339ff44 Fix SCA vulnerability when using PVK and MSBLOB key formats
      
      Note that the PRs that contributed the listed commits also include other
      commits providing related testing and documentation, in addition to
      links to PRs and commits backporting the fixes to the 1.0.2, 1.1.0 and
      1.1.1 branches.
      
      This commit includes a partial backport of
      https://github.com/openssl/openssl/pull/8555
      (commit 8402cd5f75f8c2f60d8bd39775b24b03dd8b3b38)
      for which the main author is Shane Lontis.
      
      Responsible Disclosure
      ----------------------
      
      This and the other issues presented in https://arxiv.org/abs/1909.01785
      were reported by Cesar Pereida García, Sohaib ul Hassan, Nicola Tuveri,
      Iaroslav Gridin, Alejandro Cabrera Aldaya and Billy Bob Brumley from the
      NISEC group at Tampere University, FINLAND.
      
      The OpenSSL Security Team evaluated the security risk for this
      vulnerability as low, and encouraged to propose fixes using public Pull
      Requests.
      
      _______________________________________________________________________________
      Co-authored-by: NShane Lontis <shane.lontis@oracle.com>
      
      (Backport from https://github.com/openssl/openssl/pull/9808)
      Reviewed-by: NMatt Caswell <matt@openssl.org>
      (Merged from https://github.com/openssl/openssl/pull/9809)
      9a43a733
  6. 07 9月, 2019 4 次提交
    • B
      [crypto/ec] for ECC parameters with NULL or zero cofactor, compute it · 30c22fa8
      Billy Brumley 提交于
      The cofactor argument to EC_GROUP_set_generator is optional, and SCA
      mitigations for ECC currently use it. So the library currently falls
      back to very old SCA-vulnerable code if the cofactor is not present.
      
      This PR allows EC_GROUP_set_generator to compute the cofactor for all
      curves of cryptographic interest. Steering scalar multiplication to more
      SCA-robust code.
      
      This issue affects persisted private keys in explicit parameter form,
      where the (optional) cofactor field is zero or absent.
      
      It also affects curves not built-in to the library, but constructed
      programatically with explicit parameters, then calling
      EC_GROUP_set_generator with a nonsensical value (NULL, zero).
      
      The very old scalar multiplication code is known to be vulnerable to
      local uarch attacks, outside of the OpenSSL threat model. New results
      suggest the code path is also vulnerable to traditional wall clock
      timing attacks.
      
      CVE-2019-1547
      Reviewed-by: NMatt Caswell <matt@openssl.org>
      Reviewed-by: NTomas Mraz <tmraz@fedoraproject.org>
      Reviewed-by: NNicola Tuveri <nic.tuv@gmail.com>
      (Merged from https://github.com/openssl/openssl/pull/9781)
      30c22fa8
    • N
      [ec/ecp_nistp*.c] restyle: use {} around `else` too · ed0ac119
      Nicola Tuveri 提交于
      Reviewed-by: NMatt Caswell <matt@openssl.org>
      Reviewed-by: NBernd Edlinger <bernd.edlinger@hotmail.de>
      (Merged from https://github.com/openssl/openssl/pull/9511)
      
      (cherry picked from commit 4fe2ee3a449a8ca2886584e221f34ff0ef5de119)
      ed0ac119
    • N
      [ec/ecp_nistp*.c] remove flip_endian() · 61387fd3
      Nicola Tuveri 提交于
      Replace flip_endian() by using the little endian specific
      BN_bn2lebinpad() and BN_lebin2bn().
      Reviewed-by: NMatt Caswell <matt@openssl.org>
      Reviewed-by: NBernd Edlinger <bernd.edlinger@hotmail.de>
      (Merged from https://github.com/openssl/openssl/pull/9511)
      
      (cherry picked from commit e0b660c27d8d97b4ad9e2098cc957de26872c0ef)
      61387fd3
    • N
      Fix a SCA leak using BN_bn2bin() · 083f297a
      Nicola Tuveri 提交于
      BN_bn2bin() is not constant-time and leaks the number of bits in the
      processed BIGNUM.
      
      The specialized methods in ecp_nistp224.c, ecp_nistp256.c and
      ecp_nistp521.c internally used BN_bn2bin() to convert scalars into the
      internal fixed length representation.
      
      This can leak during ECDSA/ECDH key generation or handling the nonce
      while generating an ECDSA signature, when using these implementations.
      The amount and risk of leaked information useful for a SCA attack
      varies for each of the three curves, as it depends mainly on the
      ratio between the bitlength of the curve subgroup order (governing the
      size of the secret nonce/key) and the limb size for the internal BIGNUM
      representation (which depends on the compilation target architecture).
      
      To fix this, we replace BN_bn2bin() with BN_bn2binpad(), bounding the
      output length to the width of the internal representation buffer: this
      length is public.
      
      Internally the final implementation of both BN_bn2binpad() and
      BN_bn2bin() already has masking in place to avoid leaking bn->top
      through memory access patterns.
      Memory access pattern still leaks bn->dmax, the size of the lazily
      allocated buffer for representing the BIGNUM, which is inevitable with
      the current BIGNUM architecture: reading past bn->dmax would be an
      out-of-bound read.
      As such, it's the caller responsibility to ensure that bn->dmax does not
      leak secret information, by explicitly expanding the internal BIGNUM
      buffer to a public value sufficient to avoid any lazy reallocation
      while manipulating it: this is already done at the top level alongside
      setting the BN_FLG_CONSTTIME.
      
      Finally, the internal implementation of BN_bn2binpad() indirectly calls
      BN_num_bits() via BN_num_bytes(): the current implementation of
      BN_num_bits() can leak information to a SCA attacker, and is addressed
      in the next commit.
      
      Thanks to David Schrammel and Samuel Weiser for reporting this issue
      through responsible disclosure.
      Reviewed-by: NMatt Caswell <matt@openssl.org>
      Reviewed-by: NBernd Edlinger <bernd.edlinger@hotmail.de>
      (Merged from https://github.com/openssl/openssl/pull/9511)
      
      (cherry picked from commit 805315d3a20f7274195eed75b06c391dacf3b197)
      083f297a
  7. 09 8月, 2019 1 次提交
  8. 01 8月, 2019 1 次提交
  9. 31 7月, 2019 1 次提交
  10. 01 6月, 2019 1 次提交
  11. 28 5月, 2019 1 次提交
  12. 22 5月, 2019 1 次提交
  13. 14 4月, 2019 1 次提交
  14. 11 4月, 2019 1 次提交
  15. 30 3月, 2019 1 次提交
  16. 19 3月, 2019 3 次提交
  17. 11 3月, 2019 1 次提交
  18. 07 3月, 2019 1 次提交
    • M
      Avoid an underflow in ecp_nistp521.c · d49b8889
      Matt Caswell 提交于
      The function felem_diff_128_64 in ecp_nistp521.c substracts the number |in|
      from |out| mod p. In order to avoid underflow it first adds 32p mod p
      (which is equivalent to 0 mod p) to |out|. The comments and variable naming
      suggest that the original author intended to add 64p mod p. In fact it
      has been shown that with certain unusual co-ordinates it is possible to
      cause an underflow in this function when only adding 32p mod p while
      performing a point double operation. By changing this to 64p mod p the
      underflow is avoided.
      
      It turns out to be quite difficult to construct points that satisfy the
      underflow criteria although this has been done and the underflow
      demonstrated. However none of these points are actually on the curve.
      Finding points that satisfy the underflow criteria and are also *on* the
      curve is considered significantly more difficult. For this reason we do
      not believe that this issue is currently practically exploitable and
      therefore no CVE has been assigned.
      
      This only impacts builds using the enable-ec_nistp_64_gcc_128 Configure
      option.
      
      With thanks to Bo-Yin Yang, Billy Brumley and Dr Liu for their significant
      help in investigating this issue.
      Reviewed-by: NNicola Tuveri <nic.tuv@gmail.com>
      (Merged from https://github.com/openssl/openssl/pull/8405)
      
      (cherry picked from commit 13fbce17fc9f02e2401fc3868f3f8e02d6647e5f)
      d49b8889
  19. 27 2月, 2019 1 次提交
  20. 26 2月, 2019 2 次提交
  21. 21 2月, 2019 1 次提交
    • B
      SCA hardening for mod. field inversion in EC_GROUP · 48e82c8e
      Billy Brumley 提交于
      This commit adds a dedicated function in `EC_METHOD` to access a modular
      field inversion implementation suitable for the specifics of the
      implemented curve, featuring SCA countermeasures.
      
      The new pointer is defined as:
      `int (*field_inv)(const EC_GROUP*, BIGNUM *r, const BIGNUM *a, BN_CTX*)`
      and computes the multiplicative inverse of `a` in the underlying field,
      storing the result in `r`.
      
      Three implementations are included, each including specific SCA
      countermeasures:
        - `ec_GFp_simple_field_inv()`, featuring SCA hardening through
          blinding.
        - `ec_GFp_mont_field_inv()`, featuring SCA hardening through Fermat's
          Little Theorem (FLT) inversion.
        - `ec_GF2m_simple_field_inv()`, that uses `BN_GF2m_mod_inv()` which
          already features SCA hardening through blinding.
      
      From a security point of view, this also helps addressing a leakage
      previously affecting conversions from projective to affine coordinates.
      
      This commit also adds a new error reason code (i.e.,
      `EC_R_CANNOT_INVERT`) to improve consistency between the three
      implementations as all of them could fail for the same reason but
      through different code paths resulting in inconsistent error stack
      states.
      Co-authored-by: NNicola Tuveri <nic.tuv@gmail.com>
      
      (cherry picked from commit e0033efc30b0f00476bba8f0fa5512be5dc8a3f1)
      Reviewed-by: NMatt Caswell <matt@openssl.org>
      Reviewed-by: NNicola Tuveri <nic.tuv@gmail.com>
      (Merged from https://github.com/openssl/openssl/pull/8262)
      48e82c8e
  22. 18 2月, 2019 1 次提交
    • D
      Fix some CFI issues in x86_64 assembly · 2086edb7
      David Benjamin 提交于
      The add/double shortcut in ecp_nistz256-x86_64.pl left one instruction
      point that did not unwind, and the "slow" path in AES_cbc_encrypt was
      not annotated correctly. For the latter, add
      .cfi_{remember,restore}_state support to perlasm.
      
      Next, fill in a bunch of functions that are missing no-op .cfi_startproc
      and .cfi_endproc blocks. libunwind cannot unwind those stack frames
      otherwise.
      
      Finally, work around a bug in libunwind by not encoding rflags. (rflags
      isn't a callee-saved register, so there's not much need to annotate it
      anyway.)
      
      These were found as part of ABI testing work in BoringSSL.
      Reviewed-by: NRichard Levitte <levitte@openssl.org>
      GH: #8109
      (cherry picked from commit c0e8e5007ba5234d4d448e82a1567e0c4467e629)
      2086edb7
  23. 13 2月, 2019 1 次提交
  24. 05 2月, 2019 1 次提交
  25. 11 12月, 2018 1 次提交
  26. 07 12月, 2018 2 次提交
  27. 03 12月, 2018 1 次提交
  28. 24 11月, 2018 1 次提交
  29. 29 10月, 2018 1 次提交
  30. 17 10月, 2018 1 次提交
  31. 11 9月, 2018 1 次提交
  32. 05 9月, 2018 1 次提交