aboutsummaryrefslogtreecommitdiff
path: root/internal/crypt/salt.go
blob: 09b6c72391f442ba8b4d1f49bc1f3d42c7efc163 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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("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("failed to read nonce: %w", err)
	}

	return nonce, nil
}