-
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
Aron Wussler
committed
Nov 5, 2023
1 parent
d3f636b
commit 419fab5
Showing
5 changed files
with
120 additions
and
89 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 |
---|---|---|
|
@@ -1848,3 +1848,90 @@ mQ00BF00000BCAD0000000000000000000000000000000000000000000000000 | |
000000000000000000000000000000000000ABE000G0Dn000000000000000000iQ00BB0BAgAGBCG00000` | ||
ReadArmoredKeyRing(strings.NewReader(data)) | ||
} | ||
|
||
func TestAddV4KyberSubkey(t *testing.T) { | ||
eddsaConfig := &packet.Config{ | ||
DefaultHash: crypto.SHA512, | ||
Algorithm: packet.PubKeyAlgoEdDSA, | ||
V6Keys: false, | ||
Time: func() time.Time { | ||
parsed, _ := time.Parse("2006-01-02", "2013-07-01") | ||
return parsed | ||
}, | ||
} | ||
|
||
entity, err := NewEntity("Golang Gopher", "Test Key", "[email protected]", eddsaConfig) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
testAddKyberSubkey(t, entity, false) | ||
} | ||
|
||
|
||
func testAddKyberSubkey(t *testing.T, entity *Entity, v6Keys bool) { | ||
var err error | ||
|
||
asymmAlgos := map[string] packet.PublicKeyAlgorithm{ | ||
"Kyber768_X25519": packet.PubKeyAlgoKyber768X25519, | ||
"Kyber1024_X448": packet.PubKeyAlgoKyber1024X448, | ||
"Kyber768_P256": packet.PubKeyAlgoKyber768P256, | ||
"Kyber1024_P384":packet.PubKeyAlgoKyber1024P384, | ||
"Kyber768_Brainpool256": packet.PubKeyAlgoKyber768Brainpool256, | ||
"Kyber1024_Brainpool384":packet.PubKeyAlgoKyber1024Brainpool384, | ||
} | ||
|
||
for name, algo := range asymmAlgos { | ||
// Remove existing subkeys | ||
entity.Subkeys = []Subkey{} | ||
|
||
t.Run(name, func(t *testing.T) { | ||
kyberConfig := &packet.Config{ | ||
DefaultHash: crypto.SHA512, | ||
Algorithm: algo, | ||
V6Keys: v6Keys, | ||
AEADConfig: &packet.AEADConfig{ | ||
DefaultMode: packet.AEADModeOCB, | ||
}, | ||
Time: func() time.Time { | ||
parsed, _ := time.Parse("2006-01-02", "2013-07-01") | ||
return parsed | ||
}, | ||
} | ||
|
||
err = entity.AddEncryptionSubkey(kyberConfig) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
if len(entity.Subkeys) != 1 { | ||
t.Fatalf("Expected 1 subkey, got %d", len(entity.Subkeys)) | ||
} | ||
|
||
if entity.Subkeys[0].PublicKey.PubKeyAlgo != algo { | ||
t.Fatalf("Expected subkey algorithm: %v, got: %v", packet.PubKeyAlgoEdDSA, | ||
entity.Subkeys[0].PublicKey.PubKeyAlgo) | ||
} | ||
|
||
serializedEntity := bytes.NewBuffer(nil) | ||
err = entity.SerializePrivate(serializedEntity, nil) | ||
if err != nil { | ||
t.Fatalf("Failed to serialize entity: %s", err) | ||
} | ||
|
||
read, err := ReadEntity(packet.NewReader(bytes.NewBuffer(serializedEntity.Bytes()))) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
if len(read.Subkeys) != 1 { | ||
t.Fatalf("Expected 1 subkey, got %d", len(entity.Subkeys)) | ||
} | ||
|
||
if read.Subkeys[0].PublicKey.PubKeyAlgo != algo { | ||
t.Fatalf("Expected subkey algorithm: %v, got: %v", packet.PubKeyAlgoEdDSA, | ||
entity.Subkeys[0].PublicKey.PubKeyAlgo) | ||
} | ||
}) | ||
} | ||
} |
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