Skip to content
Snippets Groups Projects
  1. Jul 03, 2017
  2. Dec 05, 2016
    • Heikki Linnakangas's avatar
      Replace PostmasterRandom() with a stronger source, second attempt. · fe0a0b59
      Heikki Linnakangas authored
      This adds a new routine, pg_strong_random() for generating random bytes,
      for use in both frontend and backend. At the moment, it's only used in
      the backend, but the upcoming SCRAM authentication patches need strong
      random numbers in libpq as well.
      
      pg_strong_random() is based on, and replaces, the existing implementation
      in pgcrypto. It can acquire strong random numbers from a number of sources,
      depending on what's available:
      
      - OpenSSL RAND_bytes(), if built with OpenSSL
      - On Windows, the native cryptographic functions are used
      - /dev/urandom
      
      Unlike the current pgcrypto function, the source is chosen by configure.
      That makes it easier to test different implementations, and ensures that
      we don't accidentally fall back to a less secure implementation, if the
      primary source fails. All of those methods are quite reliable, it would be
      pretty surprising for them to fail, so we'd rather find out by failing
      hard.
      
      If no strong random source is available, we fall back to using erand48(),
      seeded from current timestamp, like PostmasterRandom() was. That isn't
      cryptographically secure, but allows us to still work on platforms that
      don't have any of the above stronger sources. Because it's not very secure,
      the built-in implementation is only used if explicitly requested with
      --disable-strong-random.
      
      This replaces the more complicated Fortuna algorithm we used to have in
      pgcrypto, which is unfortunate, but all modern platforms have /dev/urandom,
      so it doesn't seem worth the maintenance effort to keep that. pgcrypto
      functions that require strong random numbers will be disabled with
      --disable-strong-random.
      
      Original patch by Magnus Hagander, tons of further work by Michael Paquier
      and me.
      
      Discussion: https://www.postgresql.org/message-id/CAB7nPqRy3krN8quR9XujMVVHYtXJ0_60nqgVc6oUk8ygyVkZsA@mail.gmail.com
      Discussion: https://www.postgresql.org/message-id/CAB7nPqRWkNYRRPJA7-cF+LfroYV10pvjdz6GNvxk-Eee9FypKA@mail.gmail.com
      fe0a0b59
  3. Aug 04, 2009
  4. Aug 13, 2005
    • Bruce Momjian's avatar
      The large one adds support for RSA keys and reorganizes · 87688ddf
      Bruce Momjian authored
      the pubkey functions a bit.  The actual RSA-specific code
      there is tiny, most of the patch consists of reorg of the
      pubkey code, as lots of it was written as elgamal-only.
      
      ---------------------------------------------------------------------------
      
      The SHLIB section was copy-pasted from somewhere and contains
      several unnecessary libs.  This cleans it up a bit.
      
       -lcrypt
         we don't use system crypt()
      
       -lssl, -lssleay32
         no SSL here
      
       -lz in win32 section
         already added on previous line
      
       -ldes
         The chance anybody has it is pretty low.
         And the chance pgcrypto works with it is even lower.
      
      Also trim the win32 section.
      
      ---------------------------------------------------------------------------
      
      It is already disabled in Makefile, remove code too.
      
      ---------------------------------------------------------------------------
      
      I was bit hasty making the random exponent 'k' a prime.  Further researh
      shows that Elgamal encryption has no specific needs in respect to k,
      any random number is fine.
      
      It is bit different for signing, there it needs to be 'relatively prime'
      to p - 1,  that means GCD(k, p-1) == 1, which is also a lot lighter than
      full primality.  As we don't do signing, this can be ignored.
      
      This brings major speedup to Elgamal encryption.
      
      ---------------------------------------------------------------------------
      
      o  pgp_mpi_free: Accept NULLs
      o  pgp_mpi_cksum: result should be 16bit
      o  Remove function name from error messages - to be similar to other
         SQL functions, and it does not match anyway the called function
      o  remove couple junk lines
      
      ---------------------------------------------------------------------------
      
      o  Support for RSA encryption
      o  Big reorg to better separate generic and algorithm-specific code.
      o  Regression tests for RSA.
      
      ---------------------------------------------------------------------------
      
      o  Tom stuck a CVS id into file.  I doubt the usefulness of it,
         but if it needs to be in the file then rather at the end.
         Also tag it as comment for asciidoc.
      o  Mention bytea vs. text difference
      o  Couple clarifications
      
      ---------------------------------------------------------------------------
      
      There is a choice whether to update it with pgp functions or
      remove it.  I decided to remove it, updating is pointless.
      
      I've tried to keep the core of pgcrypto relatively independent
      from main PostgreSQL, to make it easy to use externally if needed,
      and that is good.  Eg. that made development of PGP functions much
      nicer.
      
      But I have no plans to release it as generic library, so keeping such
      doc
      up-to-date is waste of time.  If anyone is interested in using it in
      other products, he can probably bother to read the source too.
      
      Commented source is another thing - I'll try to make another pass
      over code to see if there is anything non-obvious that would need
      more comments.
      
      ---------------------------------------------------------------------------
      
      Marko Kreen
      87688ddf
  5. Jul 10, 2005
Loading