On Mon, Jul 4, 2016 at 12:54 PM, Michael Paquier <michael.paqu...@gmail.com> wrote: > As I am coming back into that, I would as well suggest do the > following, that the current set of patches is clearly missing: > - Put the HMAC infrastructure stuff of pgcrypto into src/common/. It > is a bit a shame to not reuse what is currently available, then I > would suggest to reuse that with HMAC_SCRAM_SHAXXX as label. > - Move *all* the SHA-related things of pgcrypto to src/common, > including SHA1, SHA224 and SHA256. px_memset is a simple wrapper on > top of memset, we should clean up that first. > Any other things to consider that I am forgetting?
After looking more into that, I have come up with PG-like equivalents of things in openssl/sha.h: pg_shaXX_init(pg_shaXX_ctx *ctx, data); pg_shaXX_update(pg_shaXX_ctx *ctx, uint8 *data, size_t len); pg_shaXX_final(uint8 *dest, pg_shaXX_ctx *ctx); Then think about shaXX as 1, 224, 256, 384 and 512. Hence all those functions, moved to src/common, finish with the following shape, take an init() one: #ifdef USE_SSL #define <openssl/sha.h> #endif void pg_shaXX_init(pg_shaXX_ctx *ctx) { #ifdef USE_SSL SHAXX_Init((SHAXX_CTX *) ctx); #else //Here does the OpenBSD stuff, now part of pgcrypto #endif } And that's really ugly, all the OpenBSD things that are used by pgcrypto when the code is not built with --with-openssl gather into a single place with parts wrapped around USE_SSL. A less ugly solution would be to split that into two files, and one or the other gets included in OBJS depending on if the build is done with or without OpenSSL. We do a rather similar thing with fe/be-secure-openssl.c. Another possibility is that we could say that SCRAM is designed to work with TLS, as mentioned a bit upthread via the RFC, so we would not support it in builds compiled without OpenSSL. I think that would be a shame, but it would simplify all this refactoring juggling. So, 3 possibilities here: 1) Use a single file src/common/sha.c that includes a set of functions using USE_SSL 2) Have two files in src/common, one when build is used with OpenSSL, and the second one when built-in methods are used 3) Disable the use of SCRAM when OpenSSL is not present in the build. Opinions? My heart goes for 2) because 1) is ugly, and 3) is not appealing in terms of flexibility. -- Michael -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers