Browse Source

check testvectors

master
Matthias J. Kannwischer 5 years ago
parent
commit
f7fb850ecf
4 changed files with 41 additions and 0 deletions
  1. +1
    -0
      crypto_kem/kyber768/META.yml
  2. +1
    -0
      crypto_sign/dilithium-iii/META.yml
  3. +1
    -0
      requirements.txt
  4. +38
    -0
      test/check_testvectors.py

+ 1
- 0
crypto_kem/kyber768/META.yml View File

@@ -4,6 +4,7 @@ version: https://github.com/pq-crystals/kyber/commit/ab996e7460e5356b0e23aa034e7
claimed-nist-level: 3
length-public-key: 1088
length-ciphertext: 1152
testvectors-sha3-256: 0xF3D335A7C393083F11F2D9EF4D7312ADB5683139473EA9BDF0091618476BA412
principal-submitter: Peter Schwabe
auxiliary-submitters:
- Roberto Avanzi


+ 1
- 0
crypto_sign/dilithium-iii/META.yml View File

@@ -4,6 +4,7 @@ version: https://github.com/pq-crystals/dilithium/commit/ffa89bdbc12a8ee178ccec4
claimed-nist-level: 3
length-public-key: 1472
length-signature: 2701
testvectors-sha3-256: 0xCE28BBD23C2AC42C7F9A17A4FA463DC9F8ACBF767397AD4ECDE136A92D4D6C3E
principal-submitter: Vadim Lyubashevsky
auxiliary-submitters:
- Léo Ducas


+ 1
- 0
requirements.txt View File

@@ -0,0 +1 @@
PyYAML==3.13

+ 38
- 0
test/check_testvectors.py View File

@@ -0,0 +1,38 @@
import yaml
import sys
import os
import subprocess
import hashlib

"""
For a given SCHEME, this script verifies that the hash of the testvectors
produced on this platform matches the one provided in the META file.
"""

if len(sys.argv) != 2:
print("Provide a scheme name (e.g. crypto_kem/kyber768) as argv[1]")
exit(1)

SCHEME = sys.argv[1]
SCHEMEFULL = SCHEME.replace('/', '_') # e.g. crypto_kem_kyber768
SCHEMESHORT = SCHEME.split('/')[1].upper()

def get_hash(scheme):
with open(f"{scheme}/META.yml", 'r') as stream:
meta = yaml.load(stream)
return hex(meta['testvectors-sha3-256']).replace('0x', '')


expectedTestvectorsHash = get_hash(SCHEME)

subprocess.run(["make", "testvectors", f"SCHEME={SCHEME}"])
implementations = [x for x in os.listdir('bin') if 'testvectors' in x and SCHEMEFULL in x]

for impl in implementations:
testvectors = subprocess.run([f"bin/{impl}"],stdout=subprocess.PIPE)
testvectorsHash = hashlib.sha3_256(testvectors.stdout).hexdigest()
if testvectorsHash.lower() != expectedTestvectorsHash.lower():
print(f"testvectors of {SCHEME} should be {expectedTestvectorsHash}, but is {testvectorsHash}")
sys.exit(1)



Loading…
Cancel
Save