Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add argon2 test vector for 32-bit platforms #245

Merged
merged 3 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 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,10 +635,13 @@ func TestReadV6Messages(t *testing.T) {
t.Errorf("inline message is wrong: %s", contents)
}
}

func TestSymmetricDecryptionArgon2(t *testing.T) {
if bits.UintSize == 32 {
// 32-bit platforms cannot allocate 2GiB of RAM
// required by the test vector.
t.Skip()
}
// 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)
Expand All @@ -646,6 +650,22 @@ func TestSymmetricDecryptionArgon2(t *testing.T) {
if err != nil {
t.Fatal(err)
}
testSymmetricDecryptionArgon2Run(t, armoredEncryptedMessage)
}

func TestSymmetricDecryptionArgon2LessMemory(t *testing.T) {
armoredEncryptedMessage := []byte(`-----BEGIN PGP MESSAGE-----

w0gGJgcCFATa3KMW/4/9RsPME+un+MBqAwQQljCpv3dPfmVTFJAcqn+YRcIFrbY4
iiVOkxM5uAKScyYn/T2su2j2fu+uPl/HpgLSWQIHAgx/1caHYWvwl7tyjJ/tSYwK
m8OMKQHidSWi7UM88mN17ltnLCV/Wa3bLDIyAgJr9XKubHXeUK6/FqmtPxepd4y/
SXkqZq0XEafMIbynK2gH6JHjctFX
-----END PGP MESSAGE-----`)
testSymmetricDecryptionArgon2Run(t, armoredEncryptedMessage)
}

func testSymmetricDecryptionArgon2Run(t *testing.T, armoredEncryptedMessage []byte) {
passphrase := []byte("password")
// Unarmor string
raw, err := armor.Decode(strings.NewReader(string(armoredEncryptedMessage)))
if err != nil {
Expand Down
23 changes: 22 additions & 1 deletion 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 @@ -667,8 +668,12 @@ func TestReadV6Messages(t *testing.T) {
}

func TestSymmetricDecryptionArgon2(t *testing.T) {
if bits.UintSize == 32 {
// 32-bit platforms cannot allocate 2GiB of RAM
// required by the test vector.
t.Skip()
}
// 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)
Expand All @@ -677,6 +682,22 @@ func TestSymmetricDecryptionArgon2(t *testing.T) {
if err != nil {
t.Fatal(err)
}
testSymmetricDecryptionArgon2Run(t, armoredEncryptedMessage)
}

func TestSymmetricDecryptionArgon2LessMemory(t *testing.T) {
armoredEncryptedMessage := []byte(`-----BEGIN PGP MESSAGE-----

w0gGJgcCFATa3KMW/4/9RsPME+un+MBqAwQQljCpv3dPfmVTFJAcqn+YRcIFrbY4
iiVOkxM5uAKScyYn/T2su2j2fu+uPl/HpgLSWQIHAgx/1caHYWvwl7tyjJ/tSYwK
m8OMKQHidSWi7UM88mN17ltnLCV/Wa3bLDIyAgJr9XKubHXeUK6/FqmtPxepd4y/
SXkqZq0XEafMIbynK2gH6JHjctFX
-----END PGP MESSAGE-----`)
testSymmetricDecryptionArgon2Run(t, armoredEncryptedMessage)
}

func testSymmetricDecryptionArgon2Run(t *testing.T, armoredEncryptedMessage []byte) {
passphrase := []byte("password")
// Unarmor string
raw, err := armor.Decode(strings.NewReader(string(armoredEncryptedMessage)))
if err != nil {
Expand Down
Loading