2019-01-18 12:41:07 +00:00
|
|
|
import subprocess
|
|
|
|
import sys
|
|
|
|
|
|
|
|
"""
|
|
|
|
For a given SCHEME, this script verifies that all exported symbols are properly
|
|
|
|
namespaced, i.e., all start with "PQCLEAN_SCHEMENAME_"
|
|
|
|
"""
|
|
|
|
|
|
|
|
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()
|
2019-01-23 10:27:43 +00:00
|
|
|
namespace = "PQCLEAN_{}_".format(SCHEMESHORT).replace('-', '')
|
2019-01-18 12:41:07 +00:00
|
|
|
|
|
|
|
# TODO can we do this using object files instead, to preserve file origin?
|
2019-01-22 14:21:49 +00:00
|
|
|
sharedlib = "bin/shared_{}_clean.so".format(SCHEMEFULL)
|
|
|
|
subprocess.run(["make", sharedlib, "SCHEME={}".format(SCHEME)])
|
2019-01-23 10:27:43 +00:00
|
|
|
p = subprocess.run(["nm", "-D", sharedlib], stdout=subprocess.PIPE)
|
2019-01-18 12:41:07 +00:00
|
|
|
|
|
|
|
symbols = p.stdout.decode('utf-8').strip().split("\n")
|
|
|
|
non_namespaced = []
|
|
|
|
|
|
|
|
for symbolstr in symbols:
|
|
|
|
*_, symtype, symbol = symbolstr.split()
|
|
|
|
if symtype in 'TR':
|
|
|
|
if not symbol.startswith(namespace):
|
|
|
|
non_namespaced.append(symbol)
|
|
|
|
|
|
|
|
if non_namespaced:
|
|
|
|
print("! Not all symbols were properly namespaced.", file=sys.stderr)
|
2019-01-22 14:21:49 +00:00
|
|
|
print("! Missing namespace literal {}".format(namespace), file=sys.stderr)
|
2019-01-18 12:41:07 +00:00
|
|
|
for symbol in non_namespaced:
|
2019-01-22 14:21:49 +00:00
|
|
|
print("\t{}".format(symbol), file=sys.stderr)
|
2019-01-18 12:41:07 +00:00
|
|
|
sys.exit(1)
|