hwaccel.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // hwaccel.go - Hardware acceleration hooks
  2. //
  3. // To the extent possible under law, Yawning Angel has waived all copyright
  4. // and related or neighboring rights to the software, using the Creative
  5. // Commons "CC0" public domain dedication. See LICENSE or
  6. // <http://creativecommons.org/publicdomain/zero/1.0/> for full details.
  7. package morus
  8. var (
  9. isHardwareAccelerated = false
  10. hardwareAccelImpl = implReference
  11. implReference = &hwaccelImpl{
  12. name: "Reference",
  13. aeadEncryptFn: aeadEncryptRef,
  14. aeadDecryptFn: aeadDecryptRef,
  15. }
  16. )
  17. type hwaccelImpl struct {
  18. name string
  19. aeadEncryptFn func([]byte, []byte, []byte, []byte, []byte) []byte
  20. aeadDecryptFn func([]byte, []byte, []byte, []byte, []byte) ([]byte, bool)
  21. }
  22. func forceDisableHardwareAcceleration() {
  23. isHardwareAccelerated = false
  24. hardwareAccelImpl = implReference
  25. }
  26. // IsHardwareAccelerated returns true iff the MORUS implementation will use
  27. // hardware acceleration (eg: AVX2).
  28. func IsHardwareAccelerated() bool {
  29. return isHardwareAccelerated
  30. }
  31. func init() {
  32. initHardwareAcceleration()
  33. }