Skip to content

Commit

Permalink
internal/age: add a label to the scrypt salt
Browse files Browse the repository at this point in the history
This way every recipient is labeled with the version.

-----BEGIN AGE ENCRYPTED FILE-----
YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IHNjcnlwdCBSbmw2ellyQ1VFK25rVkwx
TkF0SklnIDE4CjlZL2RKb2FOcjFrM0MwSVZqS1BzMUFLeVF5Y1RaMEwvQlRLMWwv
Q0xJbEEKLS0tIEJ1STZCbFh5Vjdsam5nSEFGTVZUY1BxcVVIek04ZUVrOGR4L3ph
NkYzS28KucY25ejFefMDMtKvsAEofDQLsYF41NPrSPITpoxuVWMMZ1ldm+lDh09q
RzCIZAhLN8jaqdeVdCEutqiniJ/9qv4=
-----END AGE ENCRYPTED FILE-----

Password: lies
  • Loading branch information
FiloSottile committed Dec 27, 2019
1 parent 158b2ce commit bbab440
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions internal/age/scrypt.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import (
"golang.org/x/crypto/scrypt"
)

const scryptLabel = "age-encryption.org/v1/scrypt"

type ScryptRecipient struct {
password []byte
workFactor int
Expand Down Expand Up @@ -59,6 +61,7 @@ func (r *ScryptRecipient) Wrap(fileKey []byte) (*format.Recipient, error) {
Args: []string{format.EncodeToString(salt), strconv.Itoa(logN)},
}

salt = append([]byte(scryptLabel), salt...)
k, err := scrypt.Key(r.password, salt, 1<<logN, 8, 1, chacha20poly1305.KeySize)
if err != nil {
return nil, fmt.Errorf("failed to generate scrypt hash: %v", err)
Expand Down Expand Up @@ -127,6 +130,7 @@ func (i *ScryptIdentity) Unwrap(block *format.Recipient) ([]byte, error) {
return nil, fmt.Errorf("invalid scrypt work factor: %v", logN)
}

salt = append([]byte(scryptLabel), salt...)
k, err := scrypt.Key(i.password, salt, 1<<logN, 8, 1, chacha20poly1305.KeySize)
if err != nil {
return nil, fmt.Errorf("failed to generate scrypt hash: %v", err)
Expand Down

0 comments on commit bbab440

Please sign in to comment.