Signatures - someburner/pyhy GitHub Wiki
Preparation
- Generate a keypair suitable for signing
- Define a context (must be string of 8 characters)
kp = hydro_sign_keygen()
SECKEY = kp.sk # required for generating
PUBKEY = kp.pk # used for verification
YOUR_CTX = 'context1' # used for both, must be the same for verification to succeed
print( PUBKEY.hex() )
Signature generation
# Create a signing object with context=YOUR_CTX
s1 = hydro_sign(YOUR_CTX)
s1.update('first chunk')
s1.update('second chunk')
SIG = s1.final_create(SECKEY)
print('Signature: ', SIG.hex())
NOTE: final_create
will wipe the memory location of the passed in
secret_key just after verification. According to cffi
, the memory will be
freed when it goes out of scope (which could be never), so it's on by default.
But if you are signing tons of messages you can prevent that by doing:
sig = s1.final_create(kp.sk, wipe=False)
Verification
- Assumes
SIG
from above andPUBKEY
from above are known/defined here
# Create another signing object with context=YOUR_CTX
s2 = hydro_sign(YOUR_CTX)
s2.update('first chunk')
s2.update('second chunk')
result = s2.final_verify(SIG, PUBKEY)
assert result == True