From: Michael Paquier <michael@paquier.xyz>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Refactor HMAC implementations
Date: Sat, 03 Apr 2021 08:36:02 +0000
Message-ID: <E1lSblC-0000qT-7J@gemulon.postgresql.org> (raw)
Refactor HMAC implementations
Similarly to the cryptohash implementations, this refactors the existing
HMAC code into a single set of APIs that can be plugged with any crypto
libraries PostgreSQL is built with (only OpenSSL currently). If there
is no such libraries, a fallback implementation is available. Those new
APIs are designed similarly to the existing cryptohash layer, so there
is no real new design here, with the same logic around buffer bound
checks and memory handling.
HMAC has a dependency on cryptohashes, so all the cryptohash types
supported by cryptohash{_openssl}.c can be used with HMAC. This
refactoring is an advantage mainly for SCRAM, that included its own
implementation of HMAC with SHA256 without relying on the existing
crypto libraries even if PostgreSQL was built with their support.
This code has been tested on Windows and Linux, with and without
OpenSSL, across all the versions supported on HEAD from 1.1.1 down to
1.0.1. I have also checked that the implementations are working fine
using some sample results, a custom extension of my own, and doing
cross-checks across different major versions with SCRAM with the client
and the backend.
Author: Michael Paquier
Reviewed-by: Bruce Momjian
Discussion: https://postgr.es/m/X9m0nkEJEzIPXjeZ@paquier.xyz
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/e6bdfd9700ebfc7df811c97c2fc46d7e94e329a2
Modified Files
--------------
configure | 2 +-
configure.ac | 2 +-
src/backend/libpq/auth-scram.c | 61 ++++----
src/backend/utils/resowner/resowner.c | 61 ++++++++
src/common/Makefile | 4 +-
src/common/hmac.c | 263 ++++++++++++++++++++++++++++++++++
src/common/hmac_openssl.c | 256 +++++++++++++++++++++++++++++++++
src/common/scram-common.c | 158 +++++---------------
src/include/common/hmac.h | 29 ++++
src/include/common/md5.h | 2 +
src/include/common/scram-common.h | 13 --
src/include/common/sha1.h | 2 +
src/include/pg_config.h.in | 6 +
src/include/utils/resowner_private.h | 7 +
src/interfaces/libpq/fe-auth-scram.c | 75 ++++++----
src/tools/msvc/Mkvcbuild.pm | 2 +
src/tools/msvc/Solution.pm | 4 +
src/tools/pgindent/typedefs.list | 2 +-
18 files changed, 749 insertions(+), 200 deletions(-)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-committers@postgresql.org
Cc: michael@paquier.xyz
Subject: Re: pgsql: Refactor HMAC implementations
In-Reply-To: <E1lSblC-0000qT-7J@gemulon.postgresql.org>
References: <E1lSblC-0000qT-7J@gemulon.postgresql.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox