Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
ECDSA Verify: A PostgreSQL Extension for ECDSA Signature Verification
Overview
ecdsa_verify is a PostgreSQL extension for verifying ECDSA signatures,
implemented in Rust. It leverages
the pgrx framework for creating
PostgreSQL extensions in Rust, providing enhanced safety and performance
compared to traditional C implementations.
This extension aims to be a compatible drop-in replacement for the C-based pg-ecdsa, with the same function signature for ease of integration.
Features
- Compatibility: Supports multiple PostgreSQL versions (11 to 16).
- Elliptic Curves: Supports
secp256r1andsecp256k1curves. - Hash Functions: Supports SHA-256 for hashing input data.
- Performance: Written in Rust for better safety and performance.
- Testing: Comprehensive test suite to ensure reliability.
- Benchmarking: Includes benchmarks to measure performance.
Getting Started
Prerequisites
Skip these steps if you've already installed these, or if you're on a different platform than Ubuntu/Debian in which case you should visit the links and follow the instructions for your platform.
-
Install Rust:
| -
Install latest PostgreSQL:
https://www.postgresql.org/download/linux/ubuntu/
-
Install pgrx:
https://github.com/pgcentralfoundation/pgrx/
Installation
-
Clone the repository:
-
Build and test the extension:
-
Install the extension to PostgreSQL:
Usage
SQL Function
The extension provides a single SQL function ecdsa_verify to verify ECDSA signatures.
Function Signature
\df ecdsa_verify
List of functions
-[ RECORD 1 ]-------+-------------------------------------------------------------------------------------
Schema | public
Name | ecdsa_verify
Result data type | boolean
Argument data types | public_key bytea, input_data bytea, signature bytea, hash_func text, curve_name text
Type | func
Example Usage
CREATE EXTENSION ecdsa_verify;
SELECT ecdsa_verify(
public_key := '\x7fa92dd0666eee7c13ddb7b6249b0c8f9fba4360857c4e15d2fc634a2b5a1f8fdb9983b319469d35e719a3b93e1ac292854cd3ff2ad50898681b0a32ffbcbc6a'::bytea,
input_data := '\x49960de5880e8c687434170f6476605b8fe4aeb9a28632c7995cf3ba831d9763010000000117bd119a942a38b92bfc3b90a21f7eaa37fe1a7fa0abe27fd15dd20683b14d54'::bytea,
signature := '\x10fab01307f3eed59bc11601265efaab524b50d017bd9cdfeec4f61b01caa8d669c6e9f8d9bcbdba4e5478cb75b084332d51b0be2c21701b157c7c87abb98057'::bytea,
hash_func := 'sha256',
curve_name := 'secp256r1'
);
ecdsa_verify
--------------
t
(1 row)
Supported Curves
secp256r1secp256k1
Supported Hash Functions
sha256
Development
Project Structure
- Cargo.toml: Project metadata and dependencies.
- src/lib.rs: Main implementation file.
- benches/ecdsa_verify.rs: Benchmarking script.
- ecdsa_verify.control: PostgreSQL extension control file.
Running Tests
To run the tests, use the following command:
Benchmarking
To benchmark the extension, ensure you are using the Rust Nightly toolchain, then use the following command:
Benchmark Results
The benchmarks were run on an Intel Core i9-14900K. The results are as follows:
$ cargo bench
Running benches/ecdsa_verify.rs (target/release/deps/ecdsa_verify-f2c7ac91fb3e2e9c)
test bench_ecdsa_verify ... bench: 839,281 ns/iter (+/- 12,977)
License
This project is licensed under the MIT License. See the LICENSE file for details.
Acknowledgements
- Inspired by the starkbank-ecdsa library.
- Built using the pgrx framework.
Contributing
Bugfixes, optimizations and simplifications are welcome, but no more features. Please open an issue or submit a pull request.