Skip to content

Commit 90a3818

Browse files
committed
fix: change to openssl rather than rust
fix: support hashing of lists of fixed types and strings feat: add blake3 support fix: update readme feat: add crypto_hash_agg function
1 parent 81f20f4 commit 90a3818

File tree

16 files changed

+2190
-901
lines changed

16 files changed

+2190
-901
lines changed

.github/workflows/MainDistributionPipeline.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,4 @@ jobs:
2121
duckdb_version: v1.4-andium
2222
ci_tools_version: main
2323
extension_name: crypto
24-
enable_rust: true
25-
exclude_archs: "windows_amd64_rtools;windows_amd64_mingw"
24+
exclude_archs: "wasm_mvp;wasm_eh;wasm_threads;"

CLAUDE.md

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Overview
6+
7+
This is a DuckDB extension that adds cryptographic hash functions and HMAC calculation capabilities using OpenSSL.
8+
9+
## Architecture
10+
11+
The extension is implemented in C++ and uses OpenSSL's EVP API for cryptographic operations:
12+
13+
1. **C++ implementation** (`src/`):
14+
- `src/crypto_extension.cpp`: Main extension entry point, registers functions with DuckDB
15+
- `src/crypto_hash.cpp`: Core hash and HMAC implementations using OpenSSL
16+
- `src/query_farm_telemetry.cpp`: Telemetry integration
17+
- Implements DuckDB scalar functions: `crypto_hash()` and `crypto_hmac()`
18+
19+
### Build Integration
20+
21+
- Uses standard CMake `find_package(OpenSSL)` to locate and link OpenSSL
22+
- Links against OpenSSL::SSL and OpenSSL::Crypto for both static and loadable extension variants
23+
- No external code generation tools required
24+
25+
## Common Commands
26+
27+
### Building
28+
29+
For debug
30+
31+
```sh
32+
VCPKG_TOOLCHAIN_PATH=`pwd`/vcpkg/scripts/buildsystems/vcpkg.cmake GEN=ninja make debug
33+
```
34+
35+
Builds:
36+
- `./build/debug/duckdb` - DuckDB shell with extension pre-loaded
37+
- `./build/debug/test/unittest` - Test runner with extension linked
38+
- `./build/debug/extension/crypto/crypto.duckdb_extension` - Loadable extension binary
39+
40+
For release builds:
41+
42+
```sh
43+
VCPKG_TOOLCHAIN_PATH=`pwd`/vcpkg/scripts/buildsystems/vcpkg.cmake GEN=ninja make release
44+
```
45+
46+
Builds:
47+
- `./build/release/duckdb` - DuckDB shell with extension pre-loaded
48+
- `./build/release/test/unittest` - Test runner with extension linked
49+
- `./build/release/extension/crypto/crypto.duckdb_extension` - Loadable extension binary
50+
51+
**Note**: Requires OpenSSL to be installed on your system.
52+
53+
### Testing
54+
55+
```sh
56+
make test
57+
```
58+
59+
Runs SQL tests located in `test/sql/crypto.test`. but using the release build.
60+
61+
### Running the Extension
62+
63+
```sh
64+
./build/release/duckdb
65+
```
66+
67+
Launches DuckDB with the extension already loaded.
68+
69+
## Supported Hash Algorithms
70+
71+
The extension supports these algorithms (defined in `src/crypto_hash.cpp:getDigestByName()`):
72+
- blake2b-512
73+
- keccak224, keccak256, keccak384, keccak512 (mapped to SHA3 variants)
74+
- md4, md5
75+
- sha1
76+
- sha2-224, sha2-256, sha2-384, sha2-512
77+
- sha3-224, sha3-256, sha3-384, sha3-512
78+
79+
Both `crypto_hash()` and `crypto_hmac()` support all these algorithms.
80+
81+
**Note**: Keccak is mapped to SHA3 in OpenSSL. True Keccak (pre-standardization) differs slightly from SHA3.
82+
83+
## Development Workflow
84+
85+
### Adding a New Hash Algorithm
86+
87+
1. Add the new algorithm case to `getDigestByName()` in `src/crypto_hash.cpp`
88+
2. Return the appropriate OpenSSL EVP_MD function (e.g., `EVP_sha512_256()`)
89+
3. Update error messages to include the new algorithm name
90+
4. Add tests to `test/sql/crypto.test`
91+
5. Update README.md with the new algorithm
92+
93+
### Error Handling
94+
95+
The C++ implementation throws DuckDB exceptions:
96+
- `InvalidInputException`: For invalid algorithm names or input validation failures
97+
- `InternalException`: For OpenSSL operation failures
98+
99+
Exceptions are caught by DuckDB's executor and presented to the user.
100+
101+
## CI/CD
102+
103+
The repository uses the DuckDB extension template's CI system:
104+
- Build configuration is in `extension_config.cmake`
105+
- CI tools are in `extension-ci-tools/` (git submodule)
106+
- The Makefile includes `extension-ci-tools/makefiles/duckdb_extension.Makefile`

CMakeLists.txt

Lines changed: 13 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,8 @@
11
cmake_minimum_required(VERSION 3.5)
22

3-
set(CORROSION_VERBOSE_OUTPUT ON)
4-
set(CMAKE_CXX_STANDARD 11)
3+
set(CMAKE_CXX_STANDARD 14)
54
set(CMAKE_CXX_STANDARD_REQUIRED 1)
65

7-
execute_process(
8-
COMMAND rustup target list --installed
9-
OUTPUT_VARIABLE RUST_TARGETS
10-
)
11-
# Propagate arch to rust build for CI
12-
set(Rust_CARGO_TARGET "")
13-
if("${OS_NAME}" STREQUAL "linux")
14-
if ("${OS_ARCH}" STREQUAL "arm64")
15-
set(Rust_CARGO_TARGET "aarch64-unknown-linux-gnu")
16-
elseif("${CMAKE_CXX_COMPILER}" MATCHES "aarch64")
17-
set(Rust_CARGO_TARGET ${RUST_ENV_VARS} CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc)
18-
set(Rust_CARGO_TARGET "aarch64-unknown-linux-gnu")
19-
else()
20-
string(FIND "${RUST_TARGETS}" "musl" MUSL_TARGET_FOUND)
21-
if(NOT MUSL_TARGET_FOUND EQUAL -1)
22-
set(Rust_CARGO_TARGET "x86_64-unknown-linux-musl")
23-
else()
24-
set(Rust_CARGO_TARGET "x86_64-unknown-linux-gnu")
25-
endif()
26-
endif()
27-
elseif("${OS_NAME}" STREQUAL "osx")
28-
if ("${OSX_BUILD_ARCH}" STREQUAL "arm64")
29-
set(Rust_CARGO_TARGET "aarch64-apple-darwin")
30-
elseif ("${OSX_BUILD_ARCH}" STREQUAL "x86_64")
31-
set(Rust_CARGO_TARGET "x86_64-apple-darwin")
32-
elseif ("${OS_ARCH}" STREQUAL "arm64")
33-
set(Rust_CARGO_TARGET "aarch64-apple-darwin")
34-
endif()
35-
elseif(WIN32)
36-
if (MINGW AND "${OS_ARCH}" STREQUAL "arm64")
37-
set(Rust_CARGO_TARGET "aarch64-pc-windows-gnu")
38-
elseif (MINGW AND "${OS_ARCH}" STREQUAL "amd64")
39-
set(Rust_CARGO_TARGET "x86_64-pc-windows-gnu")
40-
elseif (MSVC AND "${OS_ARCH}" STREQUAL "arm64")
41-
set(Rust_CARGO_TARGET "aarch64-pc-windows-msvc")
42-
elseif (MSVC AND "${OS_ARCH}" STREQUAL "amd64")
43-
set(Rust_CARGO_TARGET "x86_64-pc-windows-msvc")
44-
endif()
45-
endif()
46-
47-
execute_process(
48-
COMMAND rustup target list --installed
49-
OUTPUT_VARIABLE RUST_TARGETS
50-
)
51-
string(FIND "${RUST_TARGETS}" "wasm32-unknown-emscripten" WASM_TARGET_FOUND)
52-
53-
if (NOT WASM_TARGET_FOUND EQUAL -1)
54-
set(Rust_CARGO_TARGET "wasm32-unknown-emscripten")
55-
endif()
56-
57-
58-
include(FetchContent)
59-
60-
FetchContent_Declare(
61-
Corrosion
62-
GIT_REPOSITORY https://github.com/corrosion-rs/corrosion.git
63-
GIT_TAG v0.5.2
64-
)
65-
# Set any global configuration variables such as `Rust_TOOLCHAIN` before this line!
66-
FetchContent_MakeAvailable(Corrosion)
67-
68-
# Import targets defined in a package or workspace manifest `Cargo.toml` file
69-
corrosion_import_crate(MANIFEST_PATH "${CMAKE_SOURCE_DIR}/../duckdb_crypto_rust/Cargo.toml"
70-
CRATES "duckdb_crypto_rust"
71-
)
72-
736
# Set extension name here
747
set(TARGET_NAME crypto)
758

@@ -80,20 +13,25 @@ project(${TARGET_NAME})
8013

8114
include_directories(src/include)
8215

83-
set(EXTENSION_SOURCES src/crypto_extension.cpp
84-
src/query_farm_telemetry.cpp)
16+
# Find OpenSSL
17+
find_package(OpenSSL REQUIRED)
18+
find_package(blake3 CONFIG REQUIRED)
19+
20+
set(EXTENSION_SOURCES
21+
src/crypto_extension.cpp
22+
src/crypto_hash.cpp
23+
src/query_farm_telemetry.cpp
24+
)
8525

8626
build_static_extension(${TARGET_NAME} ${EXTENSION_SOURCES})
8727
build_loadable_extension(${TARGET_NAME} " " ${EXTENSION_SOURCES})
8828

89-
get_target_property(fake_includes duckdb_crypto_rust INCLUDE_DIRECTORIES)
90-
91-
target_link_libraries(${EXTENSION_NAME} duckdb_crypto_rust-static)
92-
target_link_libraries(${LOADABLE_EXTENSION_NAME} duckdb_crypto_rust)
29+
# Link OpenSSL to both static and loadable extensions
30+
target_link_libraries(${EXTENSION_NAME} OpenSSL::SSL OpenSSL::Crypto BLAKE3::blake3)
31+
target_link_libraries(${LOADABLE_EXTENSION_NAME} OpenSSL::SSL OpenSSL::Crypto BLAKE3::blake3)
9332

9433
install(
9534
TARGETS ${EXTENSION_NAME}
9635
EXPORT "${DUCKDB_EXPORT_SET}"
9736
LIBRARY DESTINATION "${INSTALL_LIB_DIR}"
9837
ARCHIVE DESTINATION "${INSTALL_LIB_DIR}")
99-

Makefile

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,4 @@ EXT_NAME=crypto
55
EXT_CONFIG=${PROJ_DIR}extension_config.cmake
66

77
# Include the Makefile from extension-ci-tools
8-
include extension-ci-tools/makefiles/duckdb_extension.Makefile
9-
10-
rust_binding_headers:
11-
cd duckdb_crypto_rust && cbindgen --config ./cbindgen.toml --crate duckdb_crypto_rust --output ../src/include/rust.h
8+
include extension-ci-tools/makefiles/duckdb_extension.Makefile

0 commit comments

Comments
 (0)