Set static thread count; add sanity check before encryption on example program

This commit is contained in:
2025-05-11 10:58:47 -04:00
parent d7ed4def86
commit 7ceea99f35
4 changed files with 18 additions and 19 deletions
+4 -7
View File
@@ -1,24 +1,21 @@
package wrappers
import (
"runtime"
"golang.org/x/crypto/argon2"
)
const (
// parameters for Argon2
argonTime = 8 // set to pass 1-second test in dev environment
argonMemory = 384 * 1024 // 384 MB (target running comfortably on a Pi Zero/512 MB RAM)
argonTime = 8 // set to pass 1-second test in dev environment
argonMemory = 384 * 1024 // 384 MB (target running comfortably on a Pi Zero/512 MB RAM)
argonThreads = 32 // must use a static thread count for support across multiple devices
// general constants
keyLen = 32 // 256 bits, key length for both algorithms
saltSize = 16 // 128 bits, recommended salt size for both algorithms
)
var argonThreads = uint8(runtime.NumCPU())
// DeriveKey derives an encryption key from a passphrase using Argon2.
// deriveKey derives an encryption key from a passphrase using Argon2.
func deriveKey(passphrase []byte, salt []byte) []byte {
return argon2.IDKey(passphrase, salt, argonTime, argonMemory, argonThreads, keyLen)
}