Package qrc verifies Quantum Recovery Commits.
The gno.land LAWS ("Quantum Proof Cryptography Roadmap", user accounts) ask for a protocol that registers each account with
Example
1two Merkle tree hash commits of at least 64 distinct Lamport signature
2public keys with one commit using only the sha256 hash function and the
3other commit using a different hash function family such as sha3
4(Quantum Recovery Commit) that can be used to securely register/sign-for
5at least 64 new arbitrary (e.g. quantum-proof) public key bytes of any
6length determined in the future (e.g. after "D-day") for each commit.
This package is the stateless half of such a protocol. It knows how to check that a message was signed by one of the one-time keys a commit stands for, and how the signed messages are laid out. It holds no state and no secret: keeping the commits and enforcing that every key signs at most once is the job of a realm.
Construction
Everything below exists twice, once per hash function H. The two copies never share a hash call, so a break of one function leaves the other commit intact.
A Lamport key has one pair of 32-byte secrets per bit of a 256-bit digest. Its public key is the 512 hashes H(secret), pair after pair:
Example
1PK = H(s[0][0]) || H(s[0][1]) || H(s[1][0]) || ... || H(s[255][1])
To sign a message, the signer hashes it with H. Bit number i of the digest, counting from the most significant bit of byte 0, selects one secret of pair i: s[i][0] if the bit is 0, s[i][1] if it is 1. The signature is the public key in which the hash of every selected secret is replaced by the secret itself:
Example
1signature = PK, with H(s[i][bit i]) replaced by s[i][bit i] for all i
It is as long as the public key. A verifier hashes the 256 selected values where they stand and gets the public key back, without ever having seen it: a signature made with another key, or for another digest, gives back other bytes.
The commit is the root of an RFC 6962 Merkle tree whose leaves are the public keys. It is the tree gno.land builds over its own blocks, the simple Merkle tree of Tendermint, for a number of leaves that is a power of two:
Example
1leaf = H(0x00 || PK)
2inner = H(0x01 || left || right)
A proof is a signature followed by the sibling hashes on the way from the leaf to the root, bottom first. See Verify.
Cost
Checking a proof takes one hash of the message, whose cost grows with its length, then 257 hash calls for the signature, one of them over the 16385 bytes of a leaf, and one per tree level. A proof is 16384 bytes plus 32 per level: 16576 bytes for 64 keys, 16896 for 65536.
One-time keys
A Lamport key may sign a single message. Every further message signed with it reveals both secrets of more of its pairs and makes a forgery cheaper: a few such signatures make it easy. Verify cannot detect that. Whoever stores a commit must remember which leaves were used and refuse them forever, and a signer must treat a leaf as used as soon as a signature made with it leaves its hands, even if the transaction that carried it failed.