Reference implementations of PQC
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 

61 rader
1.7 KiB

  1. """
  2. Checks that the all exported symbols are properly namespaced, i.e., all
  3. start with "PQCLEAN_SCHEMENAME_".
  4. """
  5. import sys
  6. import unittest
  7. import pytest
  8. import helpers
  9. import pqclean
  10. @pytest.mark.parametrize(
  11. 'implementation,test_dir,impl_path,init,destr',
  12. [(impl,
  13. *helpers.isolate_test_files(impl.path(), 'test_symbol_ns_'))
  14. for impl in pqclean.Scheme.all_implementations()],
  15. ids=[str(impl) for impl in pqclean.Scheme.all_implementations()],
  16. )
  17. @helpers.filtered_test
  18. def test_symbol_namespaces(implementation, impl_path, test_dir, init, destr):
  19. if sys.platform not in ['linux', 'darwin']:
  20. raise unittest.SkipTest("Unsupported platform")
  21. init()
  22. helpers.make(working_dir=impl_path)
  23. out = helpers.run_subprocess(
  24. ['nm', '-g', implementation.libname()],
  25. impl_path,
  26. )
  27. lines = out.strip().split("\n")
  28. symbols = []
  29. for line in lines:
  30. if ' T ' in line or ' D ' in line or ' S ' in line:
  31. symbols.append(line)
  32. namespace = implementation.namespace_prefix()
  33. non_namespaced = []
  34. for symbolstr in symbols:
  35. *_, symtype, symbol = symbolstr.split()
  36. if symtype in 'TR':
  37. if (not symbol.startswith(namespace) and
  38. # weird things on i386
  39. not symbol.startswith('__x86.get_pc_thunk.') and
  40. not symbol.startswith('_' + namespace)):
  41. non_namespaced.append(symbol)
  42. if non_namespaced:
  43. print("Missing namespace literal {}".format(namespace))
  44. for symbol in non_namespaced:
  45. print("\ttype: {}, symbol: {}".format(symtype, symbol))
  46. assert not non_namespaced, "Literals with missing namespaces"
  47. destr()
  48. if __name__ == '__main__':
  49. pytest.main(sys.argv)