mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-08-22 11:33:23 +02:00
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
67 lines
2.0 KiB
Makefile
67 lines
2.0 KiB
Makefile
# contrib/pgcrypto/Makefile
|
|
|
|
INT_SRCS = md5.c sha1.c sha2.c internal.c internal-sha2.c blf.c rijndael.c \
|
|
pgp-mpi-internal.c imath.c
|
|
INT_TESTS = sha2
|
|
|
|
OSSL_SRCS = openssl.c pgp-mpi-openssl.c
|
|
OSSL_TESTS = sha2 des 3des cast5
|
|
|
|
ZLIB_TST = pgp-compression
|
|
ZLIB_OFF_TST = pgp-zlib-DISABLED
|
|
|
|
CF_SRCS = $(if $(subst no,,$(with_openssl)), $(OSSL_SRCS), $(INT_SRCS))
|
|
CF_TESTS = $(if $(subst no,,$(with_openssl)), $(OSSL_TESTS), $(INT_TESTS))
|
|
CF_PGP_TESTS = $(if $(subst no,,$(with_zlib)), $(ZLIB_TST), $(ZLIB_OFF_TST))
|
|
|
|
SRCS = pgcrypto.c px.c px-hmac.c px-crypt.c \
|
|
crypt-gensalt.c crypt-blowfish.c crypt-des.c \
|
|
crypt-md5.c $(CF_SRCS) \
|
|
mbuf.c pgp.c pgp-armor.c pgp-cfb.c pgp-compress.c \
|
|
pgp-decrypt.c pgp-encrypt.c pgp-info.c pgp-mpi.c \
|
|
pgp-pubdec.c pgp-pubenc.c pgp-pubkey.c pgp-s2k.c \
|
|
pgp-pgsql.c
|
|
|
|
MODULE_big = pgcrypto
|
|
OBJS = $(SRCS:.c=.o) $(WIN32RES)
|
|
|
|
EXTENSION = pgcrypto
|
|
DATA = pgcrypto--1.3.sql pgcrypto--1.2--1.3.sql pgcrypto--1.1--1.2.sql \
|
|
pgcrypto--1.0--1.1.sql pgcrypto--unpackaged--1.0.sql
|
|
PGFILEDESC = "pgcrypto - cryptographic functions"
|
|
|
|
REGRESS = init md5 sha1 hmac-md5 hmac-sha1 blowfish rijndael \
|
|
$(CF_TESTS) \
|
|
crypt-des crypt-md5 crypt-blowfish crypt-xdes \
|
|
pgp-armor pgp-decrypt pgp-encrypt $(CF_PGP_TESTS) \
|
|
pgp-pubkey-decrypt pgp-pubkey-encrypt pgp-info
|
|
|
|
EXTRA_CLEAN = gen-rtab
|
|
|
|
ifdef USE_PGXS
|
|
PG_CONFIG = pg_config
|
|
PGXS := $(shell $(PG_CONFIG) --pgxs)
|
|
include $(PGXS)
|
|
else
|
|
subdir = contrib/pgcrypto
|
|
top_builddir = ../..
|
|
include $(top_builddir)/src/Makefile.global
|
|
include $(top_srcdir)/contrib/contrib-global.mk
|
|
endif
|
|
|
|
# Add libraries that pgcrypto depends (or might depend) on into the
|
|
# shared library link. (The order in which you list them here doesn't
|
|
# matter.)
|
|
SHLIB_LINK += $(filter -lcrypto -lz, $(LIBS))
|
|
ifeq ($(PORTNAME), win32)
|
|
SHLIB_LINK += $(filter -leay32, $(LIBS))
|
|
# those must be at the end
|
|
SHLIB_LINK += -lws2_32
|
|
endif
|
|
|
|
rijndael.o: rijndael.tbl
|
|
|
|
rijndael.tbl:
|
|
$(CC) $(CPPFLAGS) $(CFLAGS) -DPRINT_TABS rijndael.c -o gen-rtab
|
|
./gen-rtab > rijndael.tbl
|