Page MenuHomePhabricator
Paste P38789

(An Untitled Masterwork)
ActivePublic

Authored by Vgutierrez on Nov 9 2022, 10:18 AM.
Referenced Files
F35729797: raw-paste-data.txt
Nov 9 2022, 10:18 AM
Subscribers
None
#!/usr/bin/python3.9
import datetime
# requires python3-nacl
import nacl.encoding
from nacl.hash import blake2b, siphash24, SIPHASH_KEYBYTES
master_key = bytes.fromhex('e7e1ce2f97d3b8c6a83096ff5a68566549fa5de00731e001b1e623865060a725ed99c68790a3a8e09e3f631bc5fc704bedb4b6604aa8d06d5609147b34d6dc4e')
subkey_id = str(datetime.date.today()).encode()
context = b'diffpriv'
# from https://libsodium.gitbook.io/doc/key_derivation
# BLAKE2B-subkeylen(key=key, message={}, salt=subkey_id || {0}, personal=ctx || {0})
derived = blake2b(b'', key=master_key, salt=subkey_id, person=context, encoder=nacl.encoding.RawEncoder)
key = derived[:SIPHASH_KEYBYTES]
print(f"[*] key to be used with SipHash24: {key.hex()}")
msg = b'message to be hashed'
h = siphash24(msg, key)
print(f"[*] siphash24({msg}, {key.hex()}) = {h.hex()}")