Skip to content

Commit

Permalink
fix: Add argon2 test vector for 32-bit platforms
Browse files Browse the repository at this point in the history
32-bit platforms fail to allocate 2 GiB of RAM for argon2, thus, we
need a seperate test vector.
  • Loading branch information
lubux committed Nov 11, 2024
1 parent 2d2c789 commit ec7ab77
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 15 deletions.
29 changes: 21 additions & 8 deletions openpgp/read_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"encoding/hex"
"io"
"io/ioutil"
"math/bits"
"os"
"strings"
"testing"
Expand Down Expand Up @@ -634,18 +635,30 @@ func TestReadV6Messages(t *testing.T) {
t.Errorf("inline message is wrong: %s", contents)
}
}

func TestSymmetricDecryptionArgon2(t *testing.T) {
// Appendix IETF OpenPGP crypto refresh draft v08 A.8.1
passphrase := []byte("password")
file, err := os.Open("test_data/argon2-sym-message.asc")
if err != nil {
t.Fatal(err)
}
armoredEncryptedMessage, err := io.ReadAll(file)
if err != nil {
t.Fatal(err)
var armoredEncryptedMessage []byte
if bits.UintSize == 32 {
// Alternative for 32-bit platforms (cannot allocate 2GiB of RAM)
armoredEncryptedMessage = []byte(`-----BEGIN PGP MESSAGE-----
w0gGJgcCFATa3KMW/4/9RsPME+un+MBqAwQQljCpv3dPfmVTFJAcqn+YRcIFrbY4
iiVOkxM5uAKScyYn/T2su2j2fu+uPl/HpgLSWQIHAgx/1caHYWvwl7tyjJ/tSYwK
m8OMKQHidSWi7UM88mN17ltnLCV/Wa3bLDIyAgJr9XKubHXeUK6/FqmtPxepd4y/
SXkqZq0XEafMIbynK2gH6JHjctFX
-----END PGP MESSAGE-----`)
} else {
file, err := os.Open("test_data/argon2-sym-message.asc")
if err != nil {
t.Fatal(err)
}
armoredEncryptedMessage, err = io.ReadAll(file)
if err != nil {
t.Fatal(err)
}
}

// Unarmor string
raw, err := armor.Decode(strings.NewReader(string(armoredEncryptedMessage)))
if err != nil {
Expand Down
28 changes: 21 additions & 7 deletions openpgp/v2/read_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"encoding/hex"
"io"
"io/ioutil"
"math/bits"
"os"
"strings"
"testing"
Expand Down Expand Up @@ -669,14 +670,27 @@ func TestReadV6Messages(t *testing.T) {
func TestSymmetricDecryptionArgon2(t *testing.T) {
// Appendix IETF OpenPGP crypto refresh draft v08 A.8.1
passphrase := []byte("password")
file, err := os.Open("../test_data/argon2-sym-message.asc")
if err != nil {
t.Fatal(err)
}
armoredEncryptedMessage, err := io.ReadAll(file)
if err != nil {
t.Fatal(err)
var armoredEncryptedMessage []byte
if bits.UintSize == 32 {
// Alternative for 32-bit platforms (cannot allocate 2GiB of RAM)
armoredEncryptedMessage = []byte(`-----BEGIN PGP MESSAGE-----
w0gGJgcCFATa3KMW/4/9RsPME+un+MBqAwQQljCpv3dPfmVTFJAcqn+YRcIFrbY4
iiVOkxM5uAKScyYn/T2su2j2fu+uPl/HpgLSWQIHAgx/1caHYWvwl7tyjJ/tSYwK
m8OMKQHidSWi7UM88mN17ltnLCV/Wa3bLDIyAgJr9XKubHXeUK6/FqmtPxepd4y/
SXkqZq0XEafMIbynK2gH6JHjctFX
-----END PGP MESSAGE-----`)
} else {
file, err := os.Open("../test_data/argon2-sym-message.asc")
if err != nil {
t.Fatal(err)
}
armoredEncryptedMessage, err = io.ReadAll(file)
if err != nil {
t.Fatal(err)
}
}

// Unarmor string
raw, err := armor.Decode(strings.NewReader(string(armoredEncryptedMessage)))
if err != nil {
Expand Down

0 comments on commit ec7ab77

Please sign in to comment.