github.com/ncruces/go-sqlite3@v0.15.1-0.20240520133447-53eef1510ff0/vfs/adiantum/adiantum.go (about) 1 package adiantum 2 3 import ( 4 "crypto/rand" 5 6 "golang.org/x/crypto/argon2" 7 "lukechampine.com/adiantum" 8 "lukechampine.com/adiantum/hbsh" 9 ) 10 11 // This variable can be replaced with -ldflags: 12 // 13 // go build -ldflags="-X github.com/ncruces/go-sqlite3/vfs/adiantum.pepper=adiantum" 14 var pepper = "github.com/ncruces/go-sqlite3/vfs/adiantum" 15 16 type adiantumCreator struct{} 17 18 func (adiantumCreator) HBSH(key []byte) *hbsh.HBSH { 19 if len(key) != 32 { 20 return nil 21 } 22 return adiantum.New(key) 23 } 24 25 func (adiantumCreator) KDF(text string) []byte { 26 if text == "" { 27 key := make([]byte, 32) 28 n, _ := rand.Read(key) 29 return key[:n] 30 } 31 return argon2.IDKey([]byte(text), []byte(pepper), 3, 64*1024, 4, 32) 32 }