Browse Source

Add `IsHardwareAccelerated()`.

Being able to query if this can be expected to be fast at runtime is
useful.
Yawning Angel 1 year ago
parent
commit
7f657ddbe3
2 changed files with 8 additions and 0 deletions
  1. 7 0
      aez.go
  2. 1 0
      aez_amd64.go

+ 7 - 0
aez.go

@@ -36,6 +36,7 @@ var (
 	extractBlake2Cfg             = &blake2b.Config{Size: extractedKeySize}
 	newAes           aesImplCtor = nil
 	zero                         = [blockSize]byte{}
+	isHardwareAccelerated        = false
 )
 
 func extract(k []byte, extractedKey *[extractedKeySize]byte) {
@@ -593,6 +594,12 @@ func Decrypt(key []byte, nonce []byte, additionalData [][]byte, tau int, ciphert
 	return dst, true
 }
 
+// IsHardwareAccelerated returns true iff the AEZ implementation will use
+// hardware acceleration (eg: AES-NI).
+func IsHardwareAccelerated() bool {
+	return isHardwareAccelerated
+}
+
 func memwipe(b []byte) {
 	for i := range b {
 		b[i] = 0

+ 1 - 0
aez_amd64.go

@@ -116,5 +116,6 @@ func platformInit() {
 	useAESNI = supportsAESNI()
 	if useAESNI {
 		newAes = newRoundAESNI
+		isHardwareAccelerated = true
 	}
 }