hwaccel.go 1.2 KB

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