Reference implementations of PQC
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

58 lines
1.6 KiB

  1. """
  2. Checks that the all exported symbols are properly namespaced, i.e., all
  3. start with "PQCLEAN_SCHEMENAME_".
  4. """
  5. import pqclean
  6. import helpers
  7. import sys
  8. import unittest
  9. def test_symbol_namespace():
  10. for scheme in pqclean.Scheme.all_schemes():
  11. for implementation in scheme.implementations:
  12. yield check_symbol_namespace, implementation
  13. def check_symbol_namespace(implementation):
  14. if sys.platform not in ['linux', 'darwin']:
  15. raise unittest.SkipTest("Unsupported platform")
  16. helpers.make(working_dir=implementation.path())
  17. out = helpers.run_subprocess(
  18. ['nm', '-g', implementation.libname()],
  19. implementation.path()
  20. )
  21. lines = out.strip().split("\n")
  22. symbols = []
  23. for line in lines:
  24. if ' T ' in line or ' D ' in line or ' S ' in line:
  25. symbols.append(line)
  26. namespace = implementation.namespace_prefix()
  27. non_namespaced = []
  28. for symbolstr in symbols:
  29. *_, symtype, symbol = symbolstr.split()
  30. if symtype in 'TR':
  31. if (not symbol.startswith(namespace) and
  32. # weird things on i386
  33. not symbol.startswith('__x86.get_pc_thunk.') and
  34. not symbol.startswith('_' + namespace)):
  35. non_namespaced.append(symbol)
  36. if non_namespaced:
  37. print("Missing namespace literal {}".format(namespace))
  38. for symbol in non_namespaced:
  39. print("\ttype: {}, symbol: {}".format(symtype, symbol))
  40. assert(False)
  41. if __name__ == '__main__':
  42. try:
  43. import nose2
  44. nose2.main()
  45. except ImportError:
  46. import nose
  47. nose.runmodule()