From 10cfce34c0fe20d2caed5750bbc5c315c0e4cc63 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Tue, 6 Feb 2018 21:46:46 -0500 Subject: Add user-callable SHA-2 functions Add the user-callable functions sha224, sha256, sha384, sha512. We already had these in the C code to support SCRAM, but there was no test coverage outside of the SCRAM tests. Adding these as user-callable functions allows writing some tests. Also, we have a user-callable md5 function but no more modern alternative, which led to wide use of md5 as a general-purpose hash function, which leads to occasional complaints about using md5. Also mark the existing md5 functions as leak-proof. Reviewed-by: Michael Paquier --- doc/src/sgml/func.sgml | 71 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 70 insertions(+), 1 deletion(-) (limited to 'doc/src') diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml index 1e535cf2153..2f59af25a6f 100644 --- a/doc/src/sgml/func.sgml +++ b/doc/src/sgml/func.sgml @@ -3640,7 +3640,7 @@ SELECT format('Testing %3$s, %2$s, %s', 'one', 'two', 'three'); returning the result in hexadecimal md5(E'Th\\000omas'::bytea) - 8ab2d3c9689aaf18 b4958c334c82d8b1 + 8ab2d3c9689aaf18​b4958c334c82d8b1 @@ -3674,6 +3674,66 @@ SELECT format('Testing %3$s, %2$s, %s', 'one', 'two', 'three'); set_byte(E'Th\\000omas'::bytea, 4, 64) Th\000o@as + + + + + sha224 + + sha224(bytea) + + bytea + + SHA-224 hash + + sha224('abc') + \x23097d223405d8228642a477bda2​55b32aadbce4bda0b3f7e36c9da7 + + + + + + sha256 + + sha256(bytea) + + bytea + + SHA-256 hash + + sha256('abc') + \xba7816bf8f01cfea414140de5dae2223​b00361a396177a9cb410ff61f20015ad + + + + + + sha384 + + sha384(bytea) + + bytea + + SHA-384 hash + + sha384('abc') + \xcb00753f45a35e8bb5a03d699ac65007​272c32ab0eded1631a8b605a43ff5bed​8086072ba1e7cc2358baeca134c825a7 + + + + + + sha512 + + sha512(bytea) + + bytea + + SHA-512 hash + + sha512('abc') + \xddaf35a193617abacc417349ae204131​12e6fa4e89a97ea20a9eeee64b55d39a​2192992a274fc1a836ba3c23a3feebbd​454d4423643ce80e2a9ac94fa54ca49f + @@ -3686,6 +3746,15 @@ SELECT format('Testing %3$s, %2$s, %s', 'one', 'two', 'three'); the first byte, and bit 15 is the most significant bit of the second byte. + + Note that for historic reasons, the function md5 + returns a hex-encoded value of type text whereas the SHA-2 + functions return type bytea. Use the functions + encode and decode to convert + between the two, for example encode(sha256('abc'), + 'hex') to get a hex-encoded text representation. + + See also the aggregate function string_agg in and the large object functions -- cgit v1.2.3