Browse Source

The VRF should output bytes, not a hex string

Ian Goldberg 4 years ago
parent
commit
a9c2528364
1 changed files with 6 additions and 4 deletions
  1. 6 4
      relay.py

+ 6 - 4
relay.py

@@ -29,10 +29,11 @@ class VRF:
         # output value is sha256(privkey, input), and the proof is
         # sha256(pubkey, input, output) + 16 bytes of 0.
         # ***THIS IS NOT A REAL VRF!***
-        val = nacl.hash.sha256(bytes(vrf_privkey) + vrf_input)
+        val = nacl.hash.sha256(bytes(vrf_privkey) + vrf_input,
+                encoder=nacl.encoding.RawEncoder)
         vrf_pubkey = vrf_privkey.public_key
-        proof = nacl.hash.sha256(bytes(vrf_pubkey) + val + vrf_input) + \
-                bytes(16)
+        proof = nacl.hash.sha256(bytes(vrf_pubkey) + val + vrf_input,
+                encoder=nacl.encoding.RawEncoder) + bytes(16)
         perfstats.keygens += 1
         perfstats.dhs += 2
         return val, proof
@@ -44,7 +45,8 @@ class VRF:
         Returns the VRF output."""
         # Again, NOT A REAL VRF!
         val, proof = vrf_output
-        if nacl.hash.sha256(vrf_pubkey + val + vrf_input) + bytes(16) != \
+        if nacl.hash.sha256(vrf_pubkey + val + vrf_input,
+                encoder=nacl.encoding.RawEncoder) + bytes(16) != \
                 proof:
             raise ValueError("VRF proof did not verify")
         perfstats.dhs += 3