1. 04 1月, 2018 1 次提交
    • D
      crypto/rand: rename drbg_rand.c to drbg_ctr.c · 4e585e72
      Dr. Matthias St. Pierre 提交于
      The generic part of the FIPS DRBG was implemented in fips_drbg_lib.c and the
      algorithm specific parts in fips_drbg_<alg>.c for <alg> in {ctr, hash, hmac}.
      Additionally, there was the module fips_drbg_rand.c which contained 'gluing'
      code between the RAND_METHOD api and the FIPS DRBG.
      
      When the FIPS code was ported to master in #4019, for some reason the ctr-drbg
      implementation from fips_drbg_ctr.c ended up in drbg_rand.c instead of drbg_ctr.c.
      
      This commit renames the module drbg_rand.c back to drbg_ctr.c, thereby restoring
      a simple relationship between the original fips modules and the drbg modules
      in master:
      
       fips_drbg_lib.c    =>  drbg_lib.c    /* generic part of implementation */
       fips_drbg_<alg>.c  =>  drbg_<alg>.c  /* algorithm specific implementations */
      Reviewed-by: NPaul Dale <paul.dale@oracle.com>
      Reviewed-by: NTim Hudson <tjh@openssl.org>
      (Merged from https://github.com/openssl/openssl/pull/4998)
      4e585e72
  2. 18 12月, 2017 2 次提交
  3. 18 10月, 2017 1 次提交
    • 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
  4. 28 8月, 2017 1 次提交
    • D
      DRBG: clarify difference between entropy counts and buffer lengths · aa048aef
      Dr. Matthias St. Pierre 提交于
      Unlike the NIST DRBG standard, entropy counts are in bits and
      buffer lengths are in bytes. This has lead to some confusion and
      errors in the past, see my comment on PR 3789.
      
      To clarify the destinction between entropy counts and buffer lengths,
      a 'len' suffix has been added to all member names of RAND_DRBG which
      represent buffer lengths:
      
      -   {min,max}_{entropy,adin,nonce,pers}
      +   {min,max}_{entropy,adin,nonce,pers}len
      
      This change makes naming also more consistent, as can be seen in the
      diffs, for example:
      
      -    else if (adinlen > drbg->max_adin) {
      +    else if (adinlen > drbg->max_adinlen) {
      
      Also replaced all 'ent's by 'entropy's, following a suggestion of Paul Dale.
      Reviewed-by: NPaul Dale <paul.dale@oracle.com>
      Reviewed-by: NRich Salz <rsalz@openssl.org>
      (Merged from https://github.com/openssl/openssl/pull/4266)
      aa048aef
  5. 05 8月, 2017 1 次提交
  6. 03 8月, 2017 1 次提交
    • 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
  7. 23 7月, 2017 1 次提交
    • R
      Add --with-rand-seed · 8389ec4b
      Rich Salz 提交于
      Add a new config param to specify how the CSPRNG should be seeded.
      Illegal values or nonsensical combinations (e.g., anything other
      than "os" on VMS or HP VOS etc) result in build failures.
      Add RDSEED support.
      Add RDTSC but leave it disabled for now pending more investigation.
      
      Refactor and reorganization all seeding files (rand_unix/win/vms) so
      that they are simpler.
      
      Only require 128 bits of seeding material.
      
      Many document improvements, including why to not use RAND_add() and the
      limitations around using load_file/write_file.
      Document RAND_poll().
      
      Cleanup Windows RAND_poll and return correct status
      
      More completely initialize the default DRBG.
      Reviewed-by: NPaul Dale <paul.dale@oracle.com>
      (Merged from https://github.com/openssl/openssl/pull/3965)
      8389ec4b
  8. 21 7月, 2017 1 次提交
    • B
      Fix out-of-bounds read in ctr_XOR · b8a437ff
      Benjamin Kaduk 提交于
      Looking at
      http://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-90Ar1.pdf
      we see that in the CTR_DRBG_Update() algorithm (internal page number 51),
      the provided input data is (after truncation to seedlen) xor-d with the
      key and V vector (of length keylen and blocklen respectively).  The comment
      in ctr_XOR notes that xor-ing with 0 is the identity function, so we can
      just ignore the case when the provided input is shorter than seedlen.
      
      The code in ctr_XOR() then proceeds to xor the key with the input, up
      to the amount of input present, and computes the remaining input that
      could be used to xor with the V vector, before accessing a full 16-byte
      stretch of the input vector and ignoring the calculated length.  The correct
      behavior is to respect the supplied input length and only xor the
      indicated number of bytes.
      Reviewed-by: NRich Salz <rsalz@openssl.org>
      (Merged from https://github.com/openssl/openssl/pull/3971)
      b8a437ff
  9. 20 7月, 2017 1 次提交
  10. 19 7月, 2017 1 次提交