24 lines
564 B
Go
24 lines
564 B
Go
|
package storage
|
||
|
|
||
|
import (
|
||
|
"crypto/rand"
|
||
|
"git.openprivacy.ca/openprivacy/libricochet-go/log"
|
||
|
"golang.org/x/crypto/pbkdf2"
|
||
|
"golang.org/x/crypto/sha3"
|
||
|
"io"
|
||
|
)
|
||
|
|
||
|
// createKey derives a key from a password
|
||
|
func createKey(password string) ([32]byte, [128]byte, error) {
|
||
|
var salt [128]byte
|
||
|
if _, err := io.ReadFull(rand.Reader, salt[:]); err != nil {
|
||
|
log.Errorf("Cannot read from random: %v\n", err)
|
||
|
return [32]byte{}, salt, err
|
||
|
}
|
||
|
dk := pbkdf2.Key([]byte(password), salt[:], 4096, 32, sha3.New512)
|
||
|
|
||
|
var dkr [32]byte
|
||
|
copy(dkr[:], dk)
|
||
|
return dkr, salt, nil
|
||
|
}
|