-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
644 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,18 @@ | ||
github.com/bwesterb/go-ristretto v1.2.1/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0= | ||
github.com/cloudflare/circl v1.2.0 h1:NheeISPSUcYftKlfrLuOo4T62FkmD4t4jviLfFFYaec= | ||
github.com/cloudflare/circl v1.2.0/go.mod h1:Ch2UgYr6ti2KTtlejELlROl0YIYj7SLjAC8M+INXlMk= | ||
golang.org/x/crypto v0.0.0-20220315160706-3147a52a75dd h1:XcWmESyNjXJMLahc3mqVQJcgSTDxFxhETVlfk9uGc38= | ||
github.com/kasperdi/SPHINCSPLUS-golang v0.0.0-20221227220735-de985e5a663c h1:JCxCKz59IXghzSSUstoaWa7h7lZdmd0LFMiMfF56ECk= | ||
github.com/kasperdi/SPHINCSPLUS-golang v0.0.0-20221227220735-de985e5a663c/go.mod h1:+SeUKO8dPlXRdYr4SK+UIs8SLz0Dl3ZceKdXGaSFsFY= | ||
golang.org/x/crypto v0.0.0-20220315160706-3147a52a75dd/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= | ||
golang.org/x/crypto v0.0.0-20220518034528-6f7dac969898 h1:SLP7Q4Di66FONjDJbCYrCRrh97focO6sLogHO7/g8F0= | ||
golang.org/x/crypto v0.0.0-20220518034528-6f7dac969898/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= | ||
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= | ||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | ||
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | ||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | ||
golang.org/x/sys v0.0.0-20220315194320-039c03cc5b86 h1:A9i04dxx7Cribqbs8jf3FQLogkL/CV2YN7hj9KWJCkc= | ||
golang.org/x/sys v0.0.0-20220315194320-039c03cc5b86/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | ||
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a h1:dGzPydgVsqGcTRVwiLJ1jVbufYwmzD3LfVPLKsKg+0k= | ||
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | ||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= | ||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= | ||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ import ( | |
"github.com/ProtonMail/go-crypto/openpgp/dilithium_eddsa" | ||
"github.com/ProtonMail/go-crypto/openpgp/errors" | ||
"github.com/ProtonMail/go-crypto/openpgp/kyber_ecdh" | ||
"github.com/ProtonMail/go-crypto/openpgp/sphincs_plus" | ||
"io/ioutil" | ||
"strings" | ||
"testing" | ||
|
@@ -207,7 +208,7 @@ func checkSerializeRead(t *testing.T, e *Entity) { | |
checkV5Key(t, el[0]) | ||
} | ||
|
||
func TestGenerateDilithiumKey(t *testing.T) { | ||
func TestGeneratePqKey(t *testing.T) { | ||
randomPassword := make([]byte, 128) | ||
_, err := rand.Read(randomPassword) | ||
if err != nil { | ||
|
@@ -221,11 +222,13 @@ func TestGenerateDilithiumKey(t *testing.T) { | |
"Dilithium5_P384":packet.PubKeyAlgoDilithium5p384, | ||
"Dilithium3_Brainpool256": packet.PubKeyAlgoDilithium3Brainpool256, | ||
"Dilithium5_Brainpool384":packet.PubKeyAlgoDilithium5Brainpool384, | ||
"SphincsPlus_simple_SHA2":packet.PubKeyAlgoSphincsPlusSha2, | ||
"SphincsPlus_simple_SHAKE":packet.PubKeyAlgoSphincsPlusShake, | ||
} | ||
|
||
for name, algo := range asymmAlgos { | ||
t.Run(name, func(t *testing.T) { | ||
dilithiumConfig := &packet.Config{ | ||
config := &packet.Config{ | ||
DefaultHash: crypto.SHA512, | ||
Algorithm: algo, | ||
V5Keys: true, | ||
|
@@ -235,7 +238,7 @@ func TestGenerateDilithiumKey(t *testing.T) { | |
}, | ||
} | ||
|
||
entity, err := NewEntity("Golang Gopher", "Test Key", "[email protected]", dilithiumConfig) | ||
entity, err := NewEntity("Golang Gopher", "Test Key", "[email protected]", config) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
@@ -252,7 +255,7 @@ func TestGenerateDilithiumKey(t *testing.T) { | |
} | ||
|
||
if read.PrimaryKey.PubKeyAlgo != algo { | ||
t.Fatalf("Expected subkey algorithm: %v, got: %v", packet.PubKeyAlgoEdDSA, read.PrimaryKey.PubKeyAlgo) | ||
t.Fatalf("Expected subkey algorithm: %v, got: %v", algo, read.PrimaryKey.PubKeyAlgo) | ||
} | ||
|
||
if err = read.PrivateKey.Encrypt(randomPassword); err != nil { | ||
|
@@ -280,41 +283,48 @@ func TestGenerateDilithiumKey(t *testing.T) { | |
pk.PublicDilithium = pk.Dilithium.PublicKeyFromBytes(bin) | ||
} | ||
|
||
if pk, ok := read.PrivateKey.PublicKey.PublicKey.(*sphincs_plus.PublicKey); ok { | ||
pk.PublicData.PKseed[5] ^= 1 | ||
} | ||
|
||
err = read.PrivateKey.Decrypt(randomPassword) | ||
if _, ok := err.(errors.KeyInvalidError); !ok { | ||
t.Fatal("Failed to detect invalid Dilithium key") | ||
} | ||
|
||
// Kyber subkey | ||
subkey := read.Subkeys[0] | ||
if err = subkey.PrivateKey.Encrypt(randomPassword); err != nil { | ||
t.Fatal(err) | ||
} | ||
testKyberSubkey(t, read.Subkeys[0], randomPassword) | ||
}) | ||
} | ||
} | ||
|
||
if err := subkey.PrivateKey.Decrypt(randomPassword); err != nil { | ||
t.Fatal("Valid Kyber key was marked as invalid: ", err) | ||
} | ||
func testKyberSubkey(t *testing.T, subkey Subkey, randomPassword []byte) { | ||
var err error | ||
if err = subkey.PrivateKey.Encrypt(randomPassword); err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
if err = subkey.PrivateKey.Encrypt(randomPassword); err != nil { | ||
t.Fatal(err) | ||
} | ||
if err = subkey.PrivateKey.Decrypt(randomPassword); err != nil { | ||
t.Fatal("Valid Kyber key was marked as invalid: ", err) | ||
} | ||
|
||
// Corrupt public Kyber in primary key | ||
if pk, ok := subkey.PublicKey.PublicKey.(*kyber_ecdh.PublicKey); ok { | ||
bin, _ := pk.PublicKyber.MarshalBinary() | ||
bin[5] ^= 1 | ||
if pk.PublicKyber, err = pk.Kyber.UnmarshalBinaryPublicKey(bin); err != nil { | ||
t.Fatal("unable to corrupt key") | ||
} | ||
} else { | ||
t.Fatal("Invalid subkey") | ||
} | ||
if err = subkey.PrivateKey.Encrypt(randomPassword); err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
err = subkey.PrivateKey.Decrypt(randomPassword) | ||
if _, ok := err.(errors.KeyInvalidError); !ok { | ||
t.Fatal("Failed to detect invalid Dilithium key") | ||
} | ||
}) | ||
// Corrupt public Kyber in primary key | ||
if pk, ok := subkey.PublicKey.PublicKey.(*kyber_ecdh.PublicKey); ok { | ||
bin, _ := pk.PublicKyber.MarshalBinary() | ||
bin[5] ^= 1 | ||
if pk.PublicKyber, err = pk.Kyber.UnmarshalBinaryPublicKey(bin); err != nil { | ||
t.Fatal("unable to corrupt key") | ||
} | ||
} else { | ||
t.Fatal("Invalid subkey") | ||
} | ||
|
||
err = subkey.PrivateKey.Decrypt(randomPassword) | ||
if _, ok := err.(errors.KeyInvalidError); !ok { | ||
t.Fatal("Failed to detect invalid kyber key") | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.