list-accel.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/usr/bin/env python3
  2. # Simple client of the testcrypt system that reports the available
  3. # variants of each of the crypto primitives that have hardware-
  4. # accelerated implementations.
  5. #
  6. # It will report the set of primitives compiled in to testcrypt, and
  7. # also report whether each one can be instantiated at run time.
  8. from testcrypt import *
  9. def get_implementations(alg):
  10. return get_implementations_commasep(alg).decode("ASCII").split(",")
  11. def list_implementations(alg, checkfn):
  12. print(f"Implementations of {alg}:")
  13. for impl in get_implementations(alg):
  14. if impl == alg:
  15. continue
  16. if checkfn(impl):
  17. print(f" {impl:<32s} available")
  18. else:
  19. print(f" {impl:<32s} compiled in, but unavailable at run time")
  20. def list_cipher_implementations(alg):
  21. list_implementations(alg, lambda impl: ssh_cipher_new(impl) is not None)
  22. def list_mac_implementations(alg):
  23. list_implementations(alg, lambda impl: ssh2_mac_new(impl, None) is not None)
  24. def list_hash_implementations(alg):
  25. list_implementations(alg, lambda impl: ssh_hash_new(impl) is not None)
  26. list_cipher_implementations("aes256_cbc")
  27. list_mac_implementations("aesgcm")
  28. list_hash_implementations("sha1")
  29. list_hash_implementations("sha256")
  30. list_hash_implementations("sha512")