api.odin 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #+build amd64
  2. package aes_hw_intel
  3. import "core:sys/info"
  4. // is_supported returns true iff hardware accelerated AES
  5. // is supported.
  6. is_supported :: proc "contextless" () -> bool {
  7. features, ok := info.cpu_features.?
  8. if !ok {
  9. return false
  10. }
  11. // Note: Everything with AES-NI and PCLMULQDQ has support for
  12. // the required SSE extxtensions.
  13. req_features :: info.CPU_Features{
  14. .sse2,
  15. .ssse3,
  16. .sse41,
  17. .aes,
  18. .pclmulqdq,
  19. }
  20. return features >= req_features
  21. }
  22. // Context is a keyed AES (ECB) instance.
  23. Context :: struct {
  24. // Note: The ideal thing to do is for the expanded round keys to be
  25. // arrays of `__m128i`, however that implies alignment (or using AVX).
  26. //
  27. // All the people using e-waste processors that don't support an
  28. // insturction set that has been around for over 10 years are why
  29. // we can't have nice things.
  30. _sk_exp_enc: [15][16]byte,
  31. _sk_exp_dec: [15][16]byte,
  32. _num_rounds: int,
  33. }
  34. // init initializes a context for AES with the provided key.
  35. init :: proc(ctx: ^Context, key: []byte) {
  36. keysched(ctx, key)
  37. }