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 kyber
  8. var (
  9. isHardwareAccelerated = false
  10. hardwareAccelImpl = implReference
  11. implReference = &hwaccelImpl{
  12. name: "Reference",
  13. nttFn: nttRef,
  14. invnttFn: invnttRef,
  15. pointwiseAccFn: pointwiseAccRef,
  16. cbdFn: cbdRef,
  17. }
  18. )
  19. type hwaccelImpl struct {
  20. name string
  21. nttFn func(*[kyberN]uint16)
  22. invnttFn func(*[kyberN]uint16)
  23. pointwiseAccFn func(*poly, *polyVec, *polyVec)
  24. cbdFn func(*poly, []byte, int)
  25. }
  26. func forceDisableHardwareAcceleration() {
  27. // This is for the benefit of testing, so that it's possible to test
  28. // all versions that are supported by the host.
  29. isHardwareAccelerated = false
  30. hardwareAccelImpl = implReference
  31. }
  32. // IsHardwareAccelerated returns true iff the Kyber implementation will use
  33. // hardware acceleration (eg: AVX2).
  34. func IsHardwareAccelerated() bool {
  35. return isHardwareAccelerated
  36. }
  37. func init() {
  38. initHardwareAcceleration()
  39. }