1. 30 3月, 2018 1 次提交
  2. 19 3月, 2018 1 次提交
  3. 17 3月, 2018 3 次提交
  4. 16 3月, 2018 1 次提交
  5. 10 3月, 2018 1 次提交
    • D
      RAND_DRBG: add a function for setting the reseeding defaults · 4917e911
      Dr. Matthias St. Pierre 提交于
      The introduction of thread local public and private DRBG instances (#5547)
      makes it very cumbersome to change the reseeding (time) intervals for
      those instances. This commit provides a function to set the default
      values for all subsequently created DRBG instances.
      
       int RAND_DRBG_set_reseed_defaults(
                                         unsigned int master_reseed_interval,
                                         unsigned int slave_reseed_interval,
                                         time_t master_reseed_time_interval,
                                         time_t slave_reseed_time_interval
                                         );
      
      The function is intended only to be used during application initialization,
      before any threads are created and before any random bytes are generated.
      Reviewed-by: NRich Salz <rsalz@openssl.org>
      (Merged from https://github.com/openssl/openssl/pull/5576)
      4917e911
  6. 07 3月, 2018 1 次提交
  7. 15 2月, 2018 1 次提交
    • D
      DRBG: make locking api truly private · 812b1537
      Dr. Matthias St. Pierre 提交于
      In PR #5295 it was decided that the locking api should remain private
      and used only inside libcrypto. However, the locking functions were added
      back to `libcrypto.num` by `mkdef.pl`, because the function prototypes
      were still listed in `internal/rand.h`. (This header contains functions
      which are internal, but shared between libcrypto and libssl.)
      
      This commit moves the prototypes to `rand_lcl.h` and changes the names
      to lowercase, following the convention therein. It also corrects an
      outdated documenting comment.
      Reviewed-by: NRichard Levitte <levitte@openssl.org>
      (Merged from https://github.com/openssl/openssl/pull/5375)
      812b1537
  8. 14 2月, 2018 3 次提交
    • D
      DRBG: make the derivation function the default for ctr_drbg · 8164d91d
      Dr. Matthias St. Pierre 提交于
      The NIST standard presents two alternative ways for seeding the
      CTR DRBG, depending on whether a derivation function is used or not.
      In Section 10.2.1 of NIST SP800-90Ar1 the following is assessed:
      
        The use of the derivation function is optional if either an
        approved RBG or an entropy source provides full entropy output
        when entropy input is requested by the DRBG mechanism.
        Otherwise, the derivation function shall be used.
      
      Since the OpenSSL DRBG supports being reseeded from low entropy random
      sources (using RAND_POOL), the use of a derivation function is mandatory.
      For that reason we change the default and replace the opt-in flag
      RAND_DRBG_FLAG_CTR_USE_DF with an opt-out flag RAND_DRBG_FLAG_CTR_NO_DF.
      This change simplifies the RAND_DRBG_new() calls.
      Reviewed-by: NRich Salz <rsalz@openssl.org>
      (Merged from https://github.com/openssl/openssl/pull/5294)
      8164d91d
    • D
      DRBG: unify initialization and cleanup code · 4f9dabbf
      Dr. Matthias St. Pierre 提交于
      The functions drbg_setup() and drbg_cleanup() used to duplicate a lot of
      code from RAND_DRBG_new() and RAND_DRBG_free(). This duplication has been
      removed, which simplifies drbg_setup() and makes drbg_cleanup() obsolete.
      Reviewed-by: NRich Salz <rsalz@openssl.org>
      (Merged from https://github.com/openssl/openssl/pull/5294)
      4f9dabbf
    • D
      DRBG: add locking api · 3ce1c27b
      Dr. Matthias St. Pierre 提交于
      This commit adds three new accessors to the internal DRBG lock
      
         int RAND_DRBG_lock(RAND_DRBG *drbg)
         int RAND_DRBG_unlock(RAND_DRBG *drbg)
         int RAND_DRBG_enable_locking(RAND_DRBG *drbg)
      
      The three shared DRBGs are intended to be used concurrently, so they
      have locking enabled by default. It is the callers responsibility to
      guard access to the shared DRBGs by calls to RAND_DRBG_lock() and
      RAND_DRBG_unlock().
      
      All other DRBG instances don't have locking enabled by default, because
      they are intendended to be used by a single thread. If it is desired,
      locking can be enabled by using RAND_DRBG_enable_locking().
      Reviewed-by: NRich Salz <rsalz@openssl.org>
      (Merged from https://github.com/openssl/openssl/pull/5294)
      3ce1c27b
  9. 06 2月, 2018 3 次提交
  10. 01 2月, 2018 1 次提交
    • B
      Revert the crypto "global lock" implementation · 63ab5ea1
      Benjamin Kaduk 提交于
      Conceptually, this is a squashed version of:
      
          Revert "Address feedback"
      
          This reverts commit 75551e07.
      
      and
      
          Revert "Add CRYPTO_thread_glock_new"
      
          This reverts commit ed6b2c79.
      
      But there were some intervening commits that made neither revert apply
      cleanly, so instead do it all as one shot.
      
      The crypto global locks were an attempt to cope with the awkward
      POSIX semantics for pthread_atfork(); its documentation (the "RATIONALE"
      section) indicates that the expected usage is to have the prefork handler
      lock all "global" locks, and the parent and child handlers release those
      locks, to ensure that forking happens with a consistent (lock) state.
      However, the set of functions available in the child process is limited
      to async-signal-safe functions, and pthread_mutex_unlock() is not on
      the list of async-signal-safe functions!  The only synchronization
      primitives that are async-signal-safe are the semaphore primitives,
      which are not really appropriate for general-purpose usage.
      
      However, the state consistency problem that the global locks were
      attempting to solve is not actually a serious problem, particularly for
      OpenSSL.  That is, we can consider four cases of forking application
      that might use OpenSSL:
      
      (1) Single-threaded, does not call into OpenSSL in the child (e.g.,
      the child calls exec() immediately)
      
      For this class of process, no locking is needed at all, since there is
      only ever a single thread of execution and the only reentrancy is due to
      signal handlers (which are themselves limited to async-signal-safe
      operation and should not be doing much work at all).
      
      (2) Single-threaded, calls into OpenSSL after fork()
      
      The application must ensure that it does not fork() with an unexpected
      lock held (that is, one that would get unlocked in the parent but
      accidentally remain locked in the child and cause deadlock).  Since
      OpenSSL does not expose any of its internal locks to the application
      and the application is single-threaded, the OpenSSL internal locks
      will be unlocked for the fork(), and the state will be consistent.
      (OpenSSL will need to reseed its PRNG in the child, but that is
      an orthogonal issue.)  If the application makes use of locks from
      libcrypto, proper handling for those locks is the responsibility of
      the application, as for any other locking primitive that is available
      for application programming.
      
      (3) Multi-threaded, does not call into OpenSSL after fork()
      
      As for (1), the OpenSSL state is only relevant in the parent, so
      no particular fork()-related handling is needed.  The internal locks
      are relevant, but there is no interaction with the child to consider.
      
      (4) Multi-threaded, calls into OpenSSL after fork()
      
      This is the case where the pthread_atfork() hooks to ensure that all
      global locks are in a known state across fork() would come into play,
      per the above discussion.  However, these "calls into OpenSSL after
      fork()" are still subject to the restriction to async-signal-safe
      functions.  Since OpenSSL uses all sorts of locking and libc functions
      that are not on the list of safe functions (e.g., malloc()), this
      case is not currently usable and is unlikely to ever be usable,
      independently of the locking situation.  So, there is no need to
      go through contortions to attempt to support this case in the one small
      area of locking interaction with fork().
      
      In light of the above analysis (thanks @davidben and @achernya), go
      back to the simpler implementation that does not need to distinguish
      "library-global" locks or to have complicated atfork handling for locks.
      Reviewed-by: NKurt Roeckx <kurt@roeckx.be>
      Reviewed-by: NMatthias St. Pierre <Matthias.St.Pierre@ncp-e.com>
      (Merged from https://github.com/openssl/openssl/pull/5089)
      63ab5ea1
  11. 29 1月, 2018 1 次提交
  12. 16 1月, 2018 1 次提交
  13. 09 1月, 2018 1 次提交
  14. 04 1月, 2018 1 次提交
    • D
      crypto/rand: restore the generic DRBG implementation · 8212d505
      Dr. Matthias St. Pierre 提交于
      The DRGB concept described in NIST SP 800-90A provides for having different
      algorithms to generate random output. In fact, the FIPS object module used to
      implement three of them, CTR DRBG, HASH DRBG and HMAC DRBG.
      
      When the FIPS code was ported to master in #4019, two of the three algorithms
      were dropped, and together with those the entire code that made RAND_DRBG
      generic was removed, since only one concrete implementation was left.
      
      This commit restores the original generic implementation of the DRBG, making it
      possible again to add additional implementations using different algorithms
      (like RAND_DRBG_CHACHA20) in the future.
      Reviewed-by: NPaul Dale <paul.dale@oracle.com>
      Reviewed-by: NTim Hudson <tjh@openssl.org>
      (Merged from https://github.com/openssl/openssl/pull/4998)
      8212d505
  15. 18 12月, 2017 4 次提交
  16. 18 10月, 2017 3 次提交
    • B
      Add missing RAND_DRBG locking · 2139145b
      Benjamin Kaduk 提交于
      The drbg's lock must be held across calls to RAND_DRBG_generate()
      to prevent simultaneous modification of internal state.
      
      This was observed in practice with simultaneous SSL_new() calls attempting
      to seed the (separate) per-SSL RAND_DRBG instances from the global
      rand_drbg instance; this eventually led to simultaneous calls to
      ctr_BCC_update() attempting to increment drbg->bltmp_pos for their
      respective partial final block, violating the invariant that bltmp_pos < 16.
      The AES operations performed in ctr_BCC_blocks() makes the race window
      quite easy to trigger.  A value of bltmp_pos greater than 16 induces
      catastrophic failure in ctr_BCC_final(), with subtraction overflowing
      and leading to an attempt to memset() to zero a very large range,
      which eventually reaches an unmapped page and segfaults.
      
      Provide the needed locking in get_entropy_from_parent(), as well as
      fixing a similar issue in RAND_priv_bytes().  There is also an
      unlocked call to RAND_DRBG_generate() in ssl_randbytes(), but the
      requisite serialization is already guaranteed by the requirements on
      the application's usage of SSL objects, and no further locking is
      needed for correct behavior.  In that case, leave a comment noting
      the apparent discrepancy and the reason for its safety (at present).
      Reviewed-by: NPaul Dale <paul.dale@oracle.com>
      Reviewed-by: NKurt Roeckx <kurt@roeckx.be>
      Reviewed-by: NRich Salz <rsalz@openssl.org>
      (Merged from https://github.com/openssl/openssl/pull/4328)
      2139145b
    • D
      Remove unnecessary DRBG_RESEED state · e0b625f9
      Dr. Matthias St. Pierre 提交于
      The DRBG_RESEED state plays an analogue role to the |reseed_required_flag| in
      Appendix B.3.4 of [NIST SP 800-90A Rev. 1]. The latter is a local variable,
      the scope of which is limited to the RAND_DRBG_generate() function. Hence there
      is no need for a DRBG_RESEED state outside of the generate function. This state
      was removed and replaced by a local variable |reseed_required|.
      Reviewed-by: NPaul Dale <paul.dale@oracle.com>
      Reviewed-by: NKurt Roeckx <kurt@roeckx.be>
      Reviewed-by: NRich Salz <rsalz@openssl.org>
      Reviewed-by: NBen Kaduk <kaduk@mit.edu>
      (Merged from https://github.com/openssl/openssl/pull/4328)
      e0b625f9
    • D
      Fix reseeding issues of the public RAND_DRBG · c16de9d8
      Dr. Matthias St. Pierre 提交于
      Reseeding is handled very differently by the classic RAND_METHOD API
      and the new RAND_DRBG api. These differences led to some problems when
      the new RAND_DRBG was made the default OpenSSL RNG. In particular,
      RAND_add() did not work as expected anymore. These issues are discussed
      on the thread '[openssl-dev] Plea for a new public OpenSSL RNG API'
      and in Pull Request #4328. This commit fixes the mentioned issues,
      introducing the following changes:
      
      - Replace the fixed size RAND_BYTES_BUFFER by a new RAND_POOL API which
        facilitates collecting entropy by the get_entropy() callback.
      - Don't use RAND_poll()/RAND_add() for collecting entropy from the
        get_entropy() callback anymore. Instead, replace RAND_poll() by
        RAND_POOL_acquire_entropy().
      - Add a new function rand_drbg_restart() which tries to get the DRBG
        in an instantiated state by all means, regardless of the current
        state (uninstantiated, error, ...) the DRBG is in. If the caller
        provides entropy or additional input, it will be used for reseeding.
      - Restore the original documented behaviour of RAND_add() and RAND_poll()
        (namely to reseed the DRBG immediately) by a new implementation based
        on rand_drbg_restart().
      - Add automatic error recovery from temporary failures of the entropy
        source to RAND_DRBG_generate() using the rand_drbg_restart() function.
      Reviewed-by: NPaul Dale <paul.dale@oracle.com>
      Reviewed-by: NKurt Roeckx <kurt@roeckx.be>
      Reviewed-by: NRich Salz <rsalz@openssl.org>
      Reviewed-by: NBen Kaduk <kaduk@mit.edu>
      (Merged from https://github.com/openssl/openssl/pull/4328)
      c16de9d8
  17. 01 9月, 2017 1 次提交
  18. 29 8月, 2017 2 次提交
  19. 28 8月, 2017 2 次提交
  20. 23 8月, 2017 1 次提交
  21. 14 8月, 2017 1 次提交
  22. 07 8月, 2017 1 次提交
  23. 03 8月, 2017 3 次提交
    • R
      Add RAND_priv_bytes() for private keys · ddc6a5c8
      Rich Salz 提交于
      Add a new global DRBG for private keys used by RAND_priv_bytes.
      
      Add BN_priv_rand() and BN_priv_rand_range() which use RAND_priv_bytes().
      Change callers to use the appropriate BN_priv... function.
      Reviewed-by: NPaul Dale <paul.dale@oracle.com>
      (Merged from https://github.com/openssl/openssl/pull/4076)
      ddc6a5c8
    • R
      Add a DRBG to each SSL object · ae3947de
      Rich Salz 提交于
      Give each SSL object it's own DRBG, chained to the parent global
      DRBG which is used only as a source of randomness into the per-SSL
      DRBG.  This is used for all session, ticket, and pre-master secret keys.
      It is NOT used for ECDH key generation which use only the global
      DRBG. (Doing that without changing the API is tricky, if not impossible.)
      Reviewed-by: NPaul Dale <paul.dale@oracle.com>
      (Merged from https://github.com/openssl/openssl/pull/4050)
      ae3947de
    • R
      Switch from ossl_rand to DRBG rand · 75e2c877
      Rich Salz 提交于
      If RAND_add wraps around, XOR with existing. Add test to drbgtest that
      does the wrap-around.
      
      Re-order seeding and stop after first success.
      
      Add RAND_poll_ex()
      
      Use the DF and therefore lower RANDOMNESS_NEEDED.  Also, for child DRBG's,
      mix in the address as the personalization bits.
      
      Centralize the entropy callbacks, from drbg_lib to rand_lib.
      (Conceptually, entropy is part of the enclosing application.)
      Thanks to Dr. Matthias St Pierre for the suggestion.
      
      Various code cleanups:
          -Make state an enum; inline RANDerr calls.
          -Add RAND_POLL_RETRIES (thanks Pauli for the idea)
          -Remove most RAND_seed calls from rest of library
          -Rename DRBG_CTX to RAND_DRBG, etc.
          -Move some code from drbg_lib to drbg_rand; drbg_lib is now only the
           implementation of NIST DRBG.
          -Remove blocklength
      Reviewed-by: NPaul Dale <paul.dale@oracle.com>
      (Merged from https://github.com/openssl/openssl/pull/4019)
      75e2c877
  24. 20 7月, 2017 1 次提交
  25. 19 7月, 2017 1 次提交