hwaccel.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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 norx
  8. var (
  9. isHardwareAccelerated = false
  10. hardwareAccelImpl = implReference
  11. implReference = &hwaccelImpl{
  12. name: "Reference",
  13. initFn: initRef,
  14. absorbDataFn: absorbDataRef,
  15. encryptDataFn: encryptDataRef,
  16. decryptDataFn: decryptDataRef,
  17. finalizeFn: finalizeRef,
  18. }
  19. )
  20. type hwaccelImpl struct {
  21. name string
  22. initFn func(*state, []byte, []byte)
  23. absorbDataFn func(*state, []byte, uint64)
  24. encryptDataFn func(*state, []byte, []byte)
  25. decryptDataFn func(*state, []byte, []byte)
  26. finalizeFn func(*state, []byte, []byte)
  27. }
  28. func forceDisableHardwareAcceleration() {
  29. isHardwareAccelerated = false
  30. hardwareAccelImpl = implReference
  31. }
  32. // IsHardwareAccelerated returns true iff the NORX implementation will use
  33. // hardware acceleration (eg: AVX2).
  34. func IsHardwareAccelerated() bool {
  35. return isHardwareAccelerated
  36. }
  37. func init() {
  38. initHardwareAcceleration()
  39. }