aboutsummaryrefslogtreecommitdiff
path: root/internal/crypt/salt.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/crypt/salt.go')
-rw-r--r--internal/crypt/salt.go25
1 files changed, 25 insertions, 0 deletions
diff --git a/internal/crypt/salt.go b/internal/crypt/salt.go
new file mode 100644
index 0000000..46874bd
--- /dev/null
+++ b/internal/crypt/salt.go
@@ -0,0 +1,25 @@
+package crypt
+
+import (
+ "crypto/rand"
+ "fmt"
+ "io"
+)
+
+func NewSalt() ([16]byte, error) {
+ salt := [16]byte{}
+ if _, err := io.ReadFull(rand.Reader, salt[:]); err != nil {
+ return [16]byte{}, fmt.Errorf("crypt: failed to read salt: %w", err)
+ }
+
+ return salt, nil
+}
+
+func NewNonce() ([12]byte, error) {
+ nonce := [12]byte{}
+ if _, err := io.ReadFull(rand.Reader, nonce[:]); err != nil {
+ return [12]byte{}, fmt.Errorf("crypt: failed to read nonce: %w", err)
+ }
+
+ return nonce, nil
+}