mirror of
https://github.com/ncruces/go-sqlite3.git
synced 2026-01-12 05:59:14 +00:00
Use crypto/pbkdf2.
This commit is contained in:
@@ -45,10 +45,7 @@ func TestBlob(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var data [1280]byte
|
var data [1280]byte
|
||||||
_, err = rand.Read(data[:])
|
rand.Read(data[:])
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = blob.Write(data[:size/2])
|
_, err = blob.Write(data[:size/2])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -25,8 +25,8 @@ func (adiantumCreator) HBSH(key []byte) *hbsh.HBSH {
|
|||||||
func (adiantumCreator) KDF(text string) []byte {
|
func (adiantumCreator) KDF(text string) []byte {
|
||||||
if text == "" {
|
if text == "" {
|
||||||
key := make([]byte, 32)
|
key := make([]byte, 32)
|
||||||
n, _ := rand.Read(key)
|
rand.Read(key)
|
||||||
return key[:n]
|
return key
|
||||||
}
|
}
|
||||||
return argon2.IDKey([]byte(text), []byte(pepper), 3, 64*1024, 4, 32)
|
return argon2.IDKey([]byte(text), []byte(pepper), 3, 64*1024, 4, 32)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,8 +45,8 @@ func (hpolycCreator) KDF(secret string) []byte {
|
|||||||
if secret == "" {
|
if secret == "" {
|
||||||
// No secret is given, generate a random key.
|
// No secret is given, generate a random key.
|
||||||
key := make([]byte, 32)
|
key := make([]byte, 32)
|
||||||
n, _ := rand.Read(key)
|
rand.Read(key)
|
||||||
return key[:n]
|
return key
|
||||||
}
|
}
|
||||||
// Hash the secret with a KDF.
|
// Hash the secret with a KDF.
|
||||||
return argon2.IDKey([]byte(secret), []byte("hpolyc"), 3, 64*1024, 4, 32)
|
return argon2.IDKey([]byte(secret), []byte("hpolyc"), 3, 64*1024, 4, 32)
|
||||||
|
|||||||
@@ -9,12 +9,12 @@ In general, any XTS construction can be used to wrap any VFS.
|
|||||||
|
|
||||||
The default AES-XTS construction uses AES-128, AES-192, or AES-256
|
The default AES-XTS construction uses AES-128, AES-192, or AES-256
|
||||||
for its block cipher.
|
for its block cipher.
|
||||||
Additionally, we use [PBKDF2-HMAC-SHA512](https://pkg.go.dev/golang.org/x/crypto/pbkdf2)
|
Additionally, we use [PBKDF2-HMAC-SHA512](https://pkg.go.dev/crypto/pbkdf2)
|
||||||
to derive AES-128 keys from plain text where needed.
|
to derive AES-128 keys from plain text where needed.
|
||||||
File contents are encrypted in 512 byte sectors, matching the
|
File contents are encrypted in 512 byte sectors, matching the
|
||||||
[minimum](https://sqlite.org/fileformat.html#pages) SQLite page size.
|
[minimum](https://sqlite.org/fileformat.html#pages) SQLite page size.
|
||||||
|
|
||||||
This VFS uses _only_ NIST and FIPS 140-2 approved cryptographic primitives,
|
This VFS uses _only_ NIST and FIPS 140-3 approved cryptographic primitives,
|
||||||
which _may_ help you become FIPS compliant.
|
which _may_ help you become FIPS compliant.
|
||||||
|
|
||||||
The VFS encrypts all files _except_
|
The VFS encrypts all files _except_
|
||||||
|
|||||||
@@ -2,10 +2,10 @@ package xts
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/aes"
|
"crypto/aes"
|
||||||
|
"crypto/pbkdf2"
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"crypto/sha512"
|
"crypto/sha512"
|
||||||
|
|
||||||
"golang.org/x/crypto/pbkdf2"
|
|
||||||
"golang.org/x/crypto/xts"
|
"golang.org/x/crypto/xts"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -27,8 +27,12 @@ func (aesCreator) XTS(key []byte) *xts.Cipher {
|
|||||||
func (aesCreator) KDF(text string) []byte {
|
func (aesCreator) KDF(text string) []byte {
|
||||||
if text == "" {
|
if text == "" {
|
||||||
key := make([]byte, 32)
|
key := make([]byte, 32)
|
||||||
n, _ := rand.Read(key)
|
rand.Read(key)
|
||||||
return key[:n]
|
return key
|
||||||
}
|
}
|
||||||
return pbkdf2.Key([]byte(text), []byte(pepper), 10_000, 32, sha512.New)
|
key, err := pbkdf2.Key(sha512.New, text, []byte(pepper), 10_000, 32)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return key
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user