pguecc

pg_ecdsa : uECC bindings for Postgres

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
4460
pguecc
pg_ecdsa
1.0
UTIL
BSD 2-Clause
C
AttributeHas BinaryHas LibraryNeed LoadHas DDLRelocatableTrusted
--s-d-r
No
Yes
No
Yes
yes
no
Relationships
See Also
hashlib
shacrypt
cryptint
pgcrypto
gzip
bzip
zstd
http

Packages

TypeRepoVersionPG Major CompatibilityPackage PatternDependencies
EXT
PIGSTY
1.0
18
17
16
15
14
pg_ecdsa-
RPM
PIGSTY
1.0
18
17
16
15
14
pg_ecdsa_$v-
DEB
PIGSTY
1.0
18
17
16
15
14
postgresql-$v-pg-ecdsa-
Linux / PGPG18PG17PG16PG15PG14
el8.x86_64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
el8.aarch64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
el9.x86_64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
el9.aarch64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
el10.x86_64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
el10.aarch64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
d12.x86_64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
d12.aarch64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
d13.x86_64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
d13.aarch64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
u22.x86_64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
u22.aarch64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
u24.x86_64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
u24.aarch64
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0
PIGSTY 1.0

Source

pig build pkg pg_ecdsa;		# build rpm/deb

Install

Make sure PGDG and PIGSTY repo available:

pig repo add pgsql -u   # add both repo and update cache

Install this extension with pig:

pig install pg_ecdsa;		# install via package name, for the active PG version
pig install pguecc;		# install by extension name, for the current active PG version

pig install pguecc -v 18;   # install for PG 18
pig install pguecc -v 17;   # install for PG 17
pig install pguecc -v 16;   # install for PG 16
pig install pguecc -v 15;   # install for PG 15
pig install pguecc -v 14;   # install for PG 14

Create this extension with:

CREATE EXTENSION pguecc;

Usage

pguecc: Elliptic curve cryptography (micro-ecc bindings) for PostgreSQL

Requires the pgcrypto extension.

Generate Key Pair

SELECT ecdsa_make_key('secp256k1');
-- (public_key_hex, private_key_hex)

Sign Data

SELECT ecdsa_sign(
    '000000000000000000000000000000000000000000',  -- private key (hex)
    '1234',                                          -- data to sign
    'sha256',                                        -- hash function
    'secp160r1'                                      -- curve name
);

Verify Signature

SELECT ecdsa_verify(
    '<public_key_hex>',
    'hello, world',
    '<signature_hex>',
    'sha256',
    'secp256k1'
);
-- t

Key Validation

SELECT ecdsa_is_valid_public_key('<public_key_hex>', 'secp256k1');
SELECT ecdsa_is_valid_private_key('<private_key_hex>', 'secp256k1');
SELECT ecdsa_is_valid_curve('secp256k1');  -- true

Supported Curves

secp160r1, secp192r1, secp224r1, secp256r1, secp256k1

Raw API

For direct signing without hashing (use with caution):

SELECT ecdsa_sign_raw(private_key_bytea, hash_bytea, 'secp256k1');
SELECT ecdsa_verify_raw(public_key_bytea, hash_bytea, signature_bytea, 'secp256k1');
Last updated on