Skip to content

Commit c0ca2b8

Browse files
authored
Add argon2 test vector for 32-bit platforms (#245)
32-bit platforms fail to allocate the 2 GiB of RAM that argon2 requires in the RFC9580 test vector. Thus, this PR skips the test for 32-bit platforms and adds a separate test vector with smaller parameters.
1 parent 2d2c789 commit c0ca2b8

File tree

2 files changed

+44
-3
lines changed

2 files changed

+44
-3
lines changed

openpgp/read_test.go

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"encoding/hex"
1212
"io"
1313
"io/ioutil"
14+
"math/bits"
1415
"os"
1516
"strings"
1617
"testing"
@@ -634,10 +635,13 @@ func TestReadV6Messages(t *testing.T) {
634635
t.Errorf("inline message is wrong: %s", contents)
635636
}
636637
}
637-
638638
func TestSymmetricDecryptionArgon2(t *testing.T) {
639+
if bits.UintSize == 32 {
640+
// 32-bit platforms cannot allocate 2GiB of RAM
641+
// required by the test vector.
642+
t.Skip()
643+
}
639644
// Appendix IETF OpenPGP crypto refresh draft v08 A.8.1
640-
passphrase := []byte("password")
641645
file, err := os.Open("test_data/argon2-sym-message.asc")
642646
if err != nil {
643647
t.Fatal(err)
@@ -646,6 +650,22 @@ func TestSymmetricDecryptionArgon2(t *testing.T) {
646650
if err != nil {
647651
t.Fatal(err)
648652
}
653+
testSymmetricDecryptionArgon2Run(t, armoredEncryptedMessage)
654+
}
655+
656+
func TestSymmetricDecryptionArgon2LessMemory(t *testing.T) {
657+
armoredEncryptedMessage := []byte(`-----BEGIN PGP MESSAGE-----
658+
659+
w0gGJgcCFATa3KMW/4/9RsPME+un+MBqAwQQljCpv3dPfmVTFJAcqn+YRcIFrbY4
660+
iiVOkxM5uAKScyYn/T2su2j2fu+uPl/HpgLSWQIHAgx/1caHYWvwl7tyjJ/tSYwK
661+
m8OMKQHidSWi7UM88mN17ltnLCV/Wa3bLDIyAgJr9XKubHXeUK6/FqmtPxepd4y/
662+
SXkqZq0XEafMIbynK2gH6JHjctFX
663+
-----END PGP MESSAGE-----`)
664+
testSymmetricDecryptionArgon2Run(t, armoredEncryptedMessage)
665+
}
666+
667+
func testSymmetricDecryptionArgon2Run(t *testing.T, armoredEncryptedMessage []byte) {
668+
passphrase := []byte("password")
649669
// Unarmor string
650670
raw, err := armor.Decode(strings.NewReader(string(armoredEncryptedMessage)))
651671
if err != nil {

openpgp/v2/read_test.go

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"encoding/hex"
1212
"io"
1313
"io/ioutil"
14+
"math/bits"
1415
"os"
1516
"strings"
1617
"testing"
@@ -667,8 +668,12 @@ func TestReadV6Messages(t *testing.T) {
667668
}
668669

669670
func TestSymmetricDecryptionArgon2(t *testing.T) {
671+
if bits.UintSize == 32 {
672+
// 32-bit platforms cannot allocate 2GiB of RAM
673+
// required by the test vector.
674+
t.Skip()
675+
}
670676
// Appendix IETF OpenPGP crypto refresh draft v08 A.8.1
671-
passphrase := []byte("password")
672677
file, err := os.Open("../test_data/argon2-sym-message.asc")
673678
if err != nil {
674679
t.Fatal(err)
@@ -677,6 +682,22 @@ func TestSymmetricDecryptionArgon2(t *testing.T) {
677682
if err != nil {
678683
t.Fatal(err)
679684
}
685+
testSymmetricDecryptionArgon2Run(t, armoredEncryptedMessage)
686+
}
687+
688+
func TestSymmetricDecryptionArgon2LessMemory(t *testing.T) {
689+
armoredEncryptedMessage := []byte(`-----BEGIN PGP MESSAGE-----
690+
691+
w0gGJgcCFATa3KMW/4/9RsPME+un+MBqAwQQljCpv3dPfmVTFJAcqn+YRcIFrbY4
692+
iiVOkxM5uAKScyYn/T2su2j2fu+uPl/HpgLSWQIHAgx/1caHYWvwl7tyjJ/tSYwK
693+
m8OMKQHidSWi7UM88mN17ltnLCV/Wa3bLDIyAgJr9XKubHXeUK6/FqmtPxepd4y/
694+
SXkqZq0XEafMIbynK2gH6JHjctFX
695+
-----END PGP MESSAGE-----`)
696+
testSymmetricDecryptionArgon2Run(t, armoredEncryptedMessage)
697+
}
698+
699+
func testSymmetricDecryptionArgon2Run(t *testing.T, armoredEncryptedMessage []byte) {
700+
passphrase := []byte("password")
680701
// Unarmor string
681702
raw, err := armor.Decode(strings.NewReader(string(armoredEncryptedMessage)))
682703
if err != nil {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy