Skip to content

Instantly share code, notes, and snippets.

@ergo70
Last active November 30, 2018 11:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ergo70/9a244b92fd3d67c634cc786119e981c1 to your computer and use it in GitHub Desktop.
Save ergo70/9a244b92fd3d67c634cc786119e981c1 to your computer and use it in GitHub Desktop.
CREATE EXTENSION IF NOT EXISTS plpython3u;
CREATE OR REPLACE FUNCTION py_create_ed25519_keypair ()
RETURNS text[]
AS $$
import axolotl_curve25519 as curve
import os
import base64
randm32 = os.urandom(32)
private_key = curve.generatePrivateKey(randm32)
public_key = curve.generatePublicKey(private_key)
return [base64.b64encode(private_key).decode('ascii'), base64.b64encode(public_key).decode('ascii')]
$$ LANGUAGE plpython3u;
CREATE OR REPLACE FUNCTION py_create_ed25519_signature (message text, private_key text)
RETURNS text
AS $$
import axolotl_curve25519 as curve
import os
import base64
randm64 = os.urandom(64)
signature = curve.calculateSignature(randm64, base64.b64decode(private_key), message.encode())
return base64.b64encode(signature).decode('ascii')
$$ LANGUAGE plpython3u;
CREATE OR REPLACE FUNCTION py_verify_ed25519_signature (message text, signature text, public_key text)
RETURNS boolean
AS $$
import axolotl_curve25519 as curve
import base64
valid = (curve.verifySignature(base64.b64decode(public_key), message.encode(), base64.b64decode(signature)) == 0)
return valid
$$ LANGUAGE plpython3u;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment