Hashing functions in the Crypto DuckDB extension
Function category
Hashing
4 functionsCompute cryptographic digests of values, lists, and entire datasets. Supports BLAKE3, BLAKE2b / BLAKE2s, the SHA-2 / SHA-3 families, SHAKE128 / SHAKE256 with any output length, Ethereum's Keccak, RIPEMD-160 and SM3, plus legacy MD5 / SHA-1 for compatibility. The aggregate variant produces an order-deterministic dataset checksum.
Signature
Returns
A table with the following columns:
| Column | Type | Description |
|---|---|---|
Column
name
|
Type
VARCHAR
|
Description Algorithm name, as passed to crypto_hash and the other functions (case-insensitive). |
Column
family
|
Type
VARCHAR
|
Description Algorithm family, e.g. sha2, sha3, shake, keccak, blake2. |
Column
implementation
|
Type
VARCHAR
|
Description openssl, or blake3 for the vendored BLAKE3 library. |
Column
digest_length
|
Type
INTEGER
|
Description Output length in bytes (the default length for XOFs); NULL when the algorithm is unavailable. |
Column
is_xof
|
Type
BOOLEAN
|
Description Whether crypto_hash_xof can produce output of any length. |
Column
supports_hmac
|
Type
BOOLEAN
|
Description Whether the algorithm can be used with crypto_hmac. |
Column
available
|
Type
BOOLEAN
|
Description Whether the linked OpenSSL library provides the algorithm. |
Description
Lists every hash algorithm the extension knows, with its family, implementation (openssl or blake3), digest length in bytes, whether it is an extendable-output function, whether it can be used with crypto_hmac, and whether the linked OpenSSL library provides it. md4 is listed as unavailable because it lives only in OpenSSL's legacy provider.
SELECT name, digest_length, is_xof, supports_hmac
FROM crypto_algorithms()
WHERE family IN ('sha3', 'shake')
ORDER BY name;
Output
| name | digest_length | is_xof | supports_hmac |
|---|---|---|---|
| sha3-224 | 28 | false | true |
| sha3-256 | 32 | false | true |
| sha3-384 | 48 | false | true |
| sha3-512 | 64 | false | true |
| shake128 | 32 | true | false |
| shake256 | 64 | true | false |
SELECT name, available FROM crypto_algorithms() WHERE NOT available;
Output
| name | available |
|---|---|
| md4 | false |
Signature
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
algorithm
|
Type
VARCHAR
|
Mode Positional | Description |
Argument
value
|
Type
ANY
|
Mode Positional | Description |
Description
Compute a cryptographic hash of a value with the given algorithm (case-insensitive). Supported algorithms: blake2b-512, blake2s-256, blake3, keccak{224,256,384,512} (original Keccak, as used by Ethereum), md5, ripemd160, sha1, sha2-{224,256,384,512}, sha2-512/224, sha2-512/256, sha3-{224,256,384,512}, shake128, shake256 and sm3 — crypto_algorithms() lists them with their digest lengths. Accepts strings, BLOB and string-backed types (JSON, BIT), every integer and floating-point type, DECIMAL, BOOLEAN, DATE, TIME, TIME_TZ, TIMESTAMP variants, INTERVAL, UUID, ENUM, and lists or fixed-size arrays of those. Different DuckDB types of the same numeric value produce different hashes; UUIDs hash as their 16 RFC 9562 bytes, DECIMALs by unscaled value regardless of width, and ENUMs by label.
SELECT lower(to_hex(crypto_hash('sha2-256', 'hello world')));
Output
| lower(to_hex(crypto_hash('sha2-256', 'hello world'))) |
|---|
| b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9 |
SELECT lower(to_hex(crypto_hash('blake3', 42::INTEGER)));
Output
| lower(to_hex(crypto_hash('blake3', CAST(42 AS INTEGER)))) |
|---|
| 95dbc3244503309f26dee9436b39568cc80b0cbe17ef409e9273c4edb58653fd |
SELECT lower(to_hex(crypto_hash('sha2-256', ['hello', 'world']::VARCHAR[])));
Output
| lower(to_hex(crypto_hash('sha2-256', CAST(list_value('hello', 'world') AS VARCHAR[])))) |
|---|
| 306a0d104017a29193be6c7464b1fd5ee65495353a7ccad7dd2928e5fb9731fd |
SELECT lower(to_hex(crypto_hash('keccak256', 'abc'))) AS keccak256;
Output
| keccak256 |
|---|
| 4e03657aea45a94fc7d47ba826c8d667c0d1e6e33a64a036ec44f58fa12d6c45 |
SELECT crypto_hash('sha2-256', UUID '550e8400-e29b-41d4-a716-446655440000')
= crypto_hash('sha2-256', unhex('550e8400e29b41d4a716446655440000')) AS same;
Output
| same |
|---|
| true |
SELECT crypto_hash('sha2-256', 1.00::DECIMAL(4,2)) = crypto_hash('sha2-256', 1.00::DECIMAL(38,2)) AS same;
Output
| same |
|---|
| true |
SELECT lower(to_hex(crypto_hash('sha2-256', [1, 2, 3]::INTEGER[3]))) AS digest;
Output
| digest |
|---|
| 4636993d3e1da4e9d6b8f87b79e8f7c6d018580d52661950eabc3845c5897a4d |
Related functions
- crypto_hash_xof() — Extendable-output hash: returns `length` bytes (1 to 4,294,967,295) of a blake3, shake128 or shake256 digest
- crypto_hash_agg() — Order-deterministic aggregate hash
- crypto_hmac() — Hash-based Message Authentication Code (HMAC)
- crypto_algorithms() — Lists every hash algorithm the extension knows, with its family, implementation (openssl or blake3), digest length in bytes, whether it is an extendable-output function, whether it can be used with `crypto_hmac`, and whether the linked OpenSSL library provides it
Signature
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
algorithm
|
Type
VARCHAR
|
Mode Positional | Description |
Argument
value
|
Type
ANY
|
Mode Positional | Description |
Description
Order-deterministic aggregate hash. Hashes column values sequentially in the ORDER BY order — yielding the same digest as crypto_hash over an equivalent ordered list. Accepts the same scalar types as crypto_hash (UUID, DECIMAL, ENUM, BOOLEAN, DATE, TIME, TIMESTAMP, INTERVAL, …) and works as a window function. ORDER BY is required and checked when the query is planned (Hash aggregation requires a distinct total ordering); NULL values are an error, so skip them with FILTER (WHERE x IS NOT NULL). Returns NULL for an empty group. Useful for dataset checksums, change detection, and Merkle-style hierarchical hashing.
SELECT department,
lower(to_hex(crypto_hash_agg('sha2-256', employee_id ORDER BY employee_id))) AS dept_hash
FROM employees
GROUP BY department;
SELECT crypto_hash_agg('sha2-256', value ORDER BY value)
= crypto_hash('sha2-256', [1, 2, 3, 4, 5]::INTEGER[])
FROM (VALUES (1),(2),(3),(4),(5)) t(value);
Output
| (crypto_hash_agg('sha2-256', "value" ORDER BY "value") = crypto_hash('sha2-256', CAST(list_value(1, 2, 3, 4, 5) AS INTEGER[]))) |
|---|
| true |
SELECT crypto_hash_agg('sha2-256', x ORDER BY x) FILTER (WHERE x IS NOT NULL)
= crypto_hash('sha2-256', [1, 3]) AS matches
FROM (VALUES (1), (NULL), (3)) t(x);
Output
| matches |
|---|
| true |
Signature
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
algorithm
|
Type
VARCHAR
|
Mode Positional | Description |
Argument
value
|
Type
ANY
|
Mode Positional | Description |
Argument
length
|
Type
BIGINT
|
Mode Positional | Description |
Description
Extendable-output hash: returns length bytes (1 to 4,294,967,295) of a blake3, shake128 or shake256 digest. A shorter output is a prefix of a longer one, and the default length (32 bytes for blake3 and shake128, 64 for shake256) matches crypto_hash. Accepts the same input types as crypto_hash. Large outputs count against memory_limit.
SELECT lower(to_hex(crypto_hash_xof('shake256', 'abc', 100))) AS digest;
Output
| digest |
|---|
| 483366601360a8771c6863080cc4114d8db44530f8f1e1ee4f94ea37e78b5739d5a15bef186a5386c75744c0527e1faa9f8726e462a12a4feb06bd8801e751e41385141204f329979fd3047a13c5657724ada64d2470157b3cdc288620944d78dbcddbd9 |
SELECT crypto_hash_xof('blake3', 'abc', 32) = crypto_hash('blake3', 'abc') AS same;
Output
| same |
|---|
| true |
Related functions
- crypto_hash() — Compute a cryptographic hash of a value with the given algorithm (case-insensitive)
- crypto_algorithms() — Lists every hash algorithm the extension knows, with its family, implementation (openssl or blake3), digest length in bytes, whether it is an extendable-output function, whether it can be used with `crypto_hmac`, and whether the linked OpenSSL library provides it