77#include " duckdb/common/string_util.hpp"
88#include " duckdb/function/scalar_function.hpp"
99#include < duckdb/parser/parsed_data/create_scalar_function_info.hpp>
10+ #include < duckdb/parser/parsed_data/create_aggregate_function_info.hpp>
1011#include < openssl/evp.h>
1112#include < algorithm>
1213#include < cctype>
@@ -592,17 +593,50 @@ namespace duckdb
592593
593594 static void LoadInternal (ExtensionLoader &loader)
594595 {
595- // crypto_hash accepts VARCHAR for algorithm name and ANY type for the data to hash
596+ // crypto_hash: Computes cryptographic hash of data using specified algorithm
596597 auto crypto_hash_scalar_function = ScalarFunction (" crypto_hash" , {LogicalType::VARCHAR, LogicalType::ANY}, LogicalType::BLOB, CryptoScalarHashFun);
597- loader.RegisterFunction (crypto_hash_scalar_function);
598-
598+ CreateScalarFunctionInfo crypto_hash_info (crypto_hash_scalar_function);
599+ crypto_hash_info.descriptions .push_back ({
600+ {LogicalType::VARCHAR, LogicalType::ANY}, // parameter_types
601+ {" algorithm" , " value" }, // parameter_names
602+ " Computes a cryptographic hash of the input value using the specified algorithm. "
603+ " Supported algorithms: blake3, sha2-256, sha2-512, sha3-256, sha3-512, md5, sha1, and more. "
604+ " Accepts strings, integers, floats, dates, timestamps, UUIDs, and lists of fixed-length types." , // description
605+ {" crypto_hash('sha2-256', 'hello world')" ,
606+ " crypto_hash('blake3', 42)" ,
607+ " crypto_hash('sha2-256', [1, 2, 3])" }, // examples
608+ {" cryptography" , " hash" } // categories
609+ });
610+ loader.RegisterFunction (crypto_hash_info);
611+
612+ // crypto_hmac: Computes HMAC of message with key using specified algorithm
599613 auto crypto_hmac_scalar_function = ScalarFunction (" crypto_hmac" , {LogicalType::VARCHAR, LogicalType::VARCHAR, LogicalType::VARCHAR}, LogicalType::BLOB, CryptoScalarHmacFun);
600- loader.RegisterFunction (crypto_hmac_scalar_function);
601-
614+ CreateScalarFunctionInfo crypto_hmac_info (crypto_hmac_scalar_function);
615+ crypto_hmac_info.descriptions .push_back ({
616+ {LogicalType::VARCHAR, LogicalType::VARCHAR, LogicalType::VARCHAR}, // parameter_types
617+ {" algorithm" , " key" , " message" }, // parameter_names
618+ " Computes an HMAC (Hash-based Message Authentication Code) of the message using the specified "
619+ " algorithm and key. Supports all hash algorithms except blake3, which requires exactly 32 bytes for the key." , // description
620+ {" crypto_hmac('sha2-256', 'secret_key', 'message to authenticate')" }, // examples
621+ {" cryptography" , " hmac" , " authentication" } // categories
622+ });
623+ loader.RegisterFunction (crypto_hmac_info);
624+
625+ // crypto_random_bytes: Generates cryptographically secure random bytes
602626 auto crypto_random_bytes_scalar_function = ScalarFunction (
603627 " crypto_random_bytes" ,
604628 {LogicalType::BIGINT}, LogicalType::BLOB, CryptoScalarRandomBytesFun, nullptr , nullptr , nullptr , nullptr , LogicalTypeId::INVALID, FunctionStability::VOLATILE);
605- loader.RegisterFunction (crypto_random_bytes_scalar_function);
629+ CreateScalarFunctionInfo crypto_random_bytes_info (crypto_random_bytes_scalar_function);
630+ crypto_random_bytes_info.descriptions .push_back ({
631+ {LogicalType::BIGINT}, // parameter_types
632+ {" length" }, // parameter_names
633+ " Generates cryptographically secure random bytes using OpenSSL's RAND_bytes(). "
634+ " Length must be between 1 and 4,294,967,295 bytes. Each call produces different random bytes." , // description
635+ {" crypto_random_bytes(16)" ,
636+ " crypto_random_bytes(32)" }, // examples
637+ {" cryptography" , " random" } // categories
638+ });
639+ loader.RegisterFunction (crypto_random_bytes_info);
606640
607641 auto agg_set = AggregateFunctionSet (" crypto_hash_agg" );
608642
@@ -622,11 +656,23 @@ namespace duckdb
622656 RegisterHashAggType<hugeint_t >(agg_set, LogicalType::HUGEINT);
623657 RegisterHashAggType<uhugeint_t >(agg_set, LogicalType::UHUGEINT);
624658
625- // // Fixed-size floating point types
659+ // Fixed-size floating point types
626660 RegisterHashAggType<float >(agg_set, LogicalType::FLOAT);
627661 RegisterHashAggType<double >(agg_set, LogicalType::DOUBLE);
628662
629- loader.RegisterFunction (agg_set);
663+ // crypto_hash_agg: Aggregate function for hashing multiple rows
664+ CreateAggregateFunctionInfo crypto_hash_agg_info (agg_set);
665+ crypto_hash_agg_info.descriptions .push_back ({
666+ {LogicalType::VARCHAR, LogicalType::ANY}, // parameter_types
667+ {" algorithm" , " value" }, // parameter_names
668+ " Computes a cryptographic hash over multiple rows using the specified algorithm. "
669+ " ORDER BY is required to ensure deterministic results. Returns the same hash as crypto_hash() "
670+ " would for an equivalent ordered list. Returns NULL for empty result sets." , // description
671+ {" crypto_hash_agg('sha2-256', column_name ORDER BY id)" ,
672+ " crypto_hash_agg('blake3', data ORDER BY timestamp)" }, // examples
673+ {" cryptography" , " hash" , " aggregate" } // categories
674+ });
675+ loader.RegisterFunction (crypto_hash_agg_info);
630676
631677 QueryFarmSendTelemetry (loader, " crypto" , " 2025120201" );
632678 }
0 commit comments