diff options
author | Peter Eisentraut <peter_e@gmx.net> | 2018-02-06 21:46:46 -0500 |
---|---|---|
committer | Peter Eisentraut <peter_e@gmx.net> | 2018-02-22 11:34:53 -0500 |
commit | 10cfce34c0fe20d2caed5750bbc5c315c0e4cc63 (patch) | |
tree | bad5c503278b81c77080c534a882a93c2bcb952b /doc/src | |
parent | edd44738bc88148784899a8949519364d81d9ea8 (diff) |
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 <michael@paquier.xyz>
Diffstat (limited to 'doc/src')
-rw-r--r-- | doc/src/sgml/func.sgml | 71 |
1 files changed, 70 insertions, 1 deletions
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 </entry> <entry><literal>md5(E'Th\\000omas'::bytea)</literal></entry> - <entry><literal>8ab2d3c9689aaf18 b4958c334c82d8b1</literal></entry> + <entry><literal>8ab2d3c9689aaf18​b4958c334c82d8b1</literal></entry> </row> <row> @@ -3674,6 +3674,66 @@ SELECT format('Testing %3$s, %2$s, %s', 'one', 'two', 'three'); <entry><literal>set_byte(E'Th\\000omas'::bytea, 4, 64)</literal></entry> <entry><literal>Th\000o@as</literal></entry> </row> + + <row> + <entry> + <indexterm> + <primary>sha224</primary> + </indexterm> + <literal><function>sha224(<type>bytea</type>)</function></literal> + </entry> + <entry><type>bytea</type></entry> + <entry> + SHA-224 hash + </entry> + <entry><literal>sha224('abc')</literal></entry> + <entry><literal>\x23097d223405d8228642a477bda2​55b32aadbce4bda0b3f7e36c9da7</literal></entry> + </row> + + <row> + <entry> + <indexterm> + <primary>sha256</primary> + </indexterm> + <literal><function>sha256(<type>bytea</type>)</function></literal> + </entry> + <entry><type>bytea</type></entry> + <entry> + SHA-256 hash + </entry> + <entry><literal>sha256('abc')</literal></entry> + <entry><literal>\xba7816bf8f01cfea414140de5dae2223​b00361a396177a9cb410ff61f20015ad</literal></entry> + </row> + + <row> + <entry> + <indexterm> + <primary>sha384</primary> + </indexterm> + <literal><function>sha384(<type>bytea</type>)</function></literal> + </entry> + <entry><type>bytea</type></entry> + <entry> + SHA-384 hash + </entry> + <entry><literal>sha384('abc')</literal></entry> + <entry><literal>\xcb00753f45a35e8bb5a03d699ac65007​272c32ab0eded1631a8b605a43ff5bed​8086072ba1e7cc2358baeca134c825a7</literal></entry> + </row> + + <row> + <entry> + <indexterm> + <primary>sha512</primary> + </indexterm> + <literal><function>sha512(<type>bytea</type>)</function></literal> + </entry> + <entry><type>bytea</type></entry> + <entry> + SHA-512 hash + </entry> + <entry><literal>sha512('abc')</literal></entry> + <entry><literal>\xddaf35a193617abacc417349ae204131​12e6fa4e89a97ea20a9eeee64b55d39a​2192992a274fc1a836ba3c23a3feebbd​454d4423643ce80e2a9ac94fa54ca49f</literal></entry> + </row> </tbody> </tgroup> </table> @@ -3687,6 +3747,15 @@ SELECT format('Testing %3$s, %2$s, %s', 'one', 'two', 'three'); </para> <para> + Note that for historic reasons, the function <function>md5</function> + returns a hex-encoded value of type <type>text</type> whereas the SHA-2 + functions return type <type>bytea</type>. Use the functions + <function>encode</function> and <function>decode</function> to convert + between the two, for example <literal>encode(sha256('abc'), + 'hex')</literal> to get a hex-encoded text representation. + </para> + + <para> See also the aggregate function <function>string_agg</function> in <xref linkend="functions-aggregate"/> and the large object functions in <xref linkend="lo-funcs"/>. |