mirror of
https://github.com/rwinkhart/rcw.git
synced 2026-09-06 09:07:16 -04:00
Set static thread count; add sanity check before encryption on example program
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user