Skip to content

Commit 0acf655

Browse files
committed
estimate_tile_size: Add a flag to swap out different algorithms
1 parent e8fde3f commit 0acf655

1 file changed

Lines changed: 29 additions & 9 deletions

File tree

estimate_tile_size.go

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,6 @@ const (
3131
fullTileSize = 256
3232

3333
tbsCertEntry = 1
34-
35-
// Sizes for ML-DSA-44
36-
mldsaPublicKey = 1312
37-
mldsaSignature = 2420
3834
)
3935

4036
var (
@@ -43,11 +39,29 @@ var (
4339
flagFilterKeyIDs = flag.Bool("filter-key-id", false, "filter out SKID and AKID extensions")
4440
flagFilterAIA = flag.Bool("filter-aia", false, "filter out AIA extension")
4541
flagPQEmbeddedSCTs = flag.Bool("pq-embedded-scts", false, "simulate embedded SCTs getting upgraded to post-quantum")
42+
flagPQAlg = flag.String("pq-alg", "ML-DSA-44", "the PQ algorithm to simulate")
4643

4744
// Put together some placeholder value based on https://www.ietf.org/archive/id/draft-davidben-tls-merkle-tree-certs-06.html#name-log-ids
4845
placeholderIssuer = []byte{0x30, 0x14, 0x31, 0x12, 0x30, 0x10, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, 0x00, 0x00, 0x0d, 0x04, 0xd6, 0x79, 0x09, 0x01}
4946
)
5047

48+
type pqAlgorithm struct {
49+
publicKeySize int
50+
signatureSize int
51+
}
52+
53+
func getPQAlgorithm(alg string) (pqAlgorithm, bool) {
54+
switch alg {
55+
case "ML-DSA-44":
56+
return pqAlgorithm{publicKeySize: 1312, signatureSize: 2420}, true
57+
case "ML-DSA-65":
58+
return pqAlgorithm{publicKeySize: 1952, signatureSize: 3309}, true
59+
case "ML-DSA-87":
60+
return pqAlgorithm{publicKeySize: 2592, signatureSize: 4627}, true
61+
}
62+
return pqAlgorithm{}, false
63+
}
64+
5165
// Extracts leaf certificates from a data tile, as defined in https://c2sp.org/static-ct-api
5266
func parseDataTile(tile []byte, n int) ([]*x509.Certificate, error) {
5367
certs := make([]*x509.Certificate, n)
@@ -282,11 +296,17 @@ func do() error {
282296
if !baseURL.IsAbs() {
283297
return errors.New("not a valid URL")
284298
}
299+
pqAlg, ok := getPQAlgorithm(*flagPQAlg)
300+
if !ok {
301+
return fmt.Errorf("unknown post-quantum algorithm: %s", *flagPQAlg)
302+
}
285303

286304
fmt.Printf("Sampling from log %s\n", *flagURL)
287305
fmt.Printf("Filtering AIA in simulated MTC tiles: %t\n", *flagFilterAIA)
288306
fmt.Printf("Filtering SKID/AKID in simulated MTC tiles: %t\n", *flagFilterKeyIDs)
307+
fmt.Printf("Simulating PQ with %s\n", *flagPQAlg)
289308
fmt.Printf("Including embedded SCTs in PQ simulation: %t\n", *flagPQEmbeddedSCTs)
309+
fmt.Printf("\n")
290310

291311
treeSize, err := fetchTreeSize(baseURL)
292312
if err != nil {
@@ -328,11 +348,11 @@ func do() error {
328348

329349
// As a very, very rough estimate of the status quo with PQ,
330350
// simulate replacing the leaf SPKI, leaf signature, and embedded
331-
// SCT signatures with ML-DSA-44.
332-
pqIncrease += mldsaPublicKey - len(cert.RawSubjectPublicKeyInfo)
333-
pqIncrease += mldsaSignature - len(cert.Signature)
351+
// SCT signatures with the chosen PQ algorithm.
352+
pqIncrease += pqAlg.publicKeySize - len(cert.RawSubjectPublicKeyInfo)
353+
pqIncrease += pqAlg.signatureSize - len(cert.Signature)
334354
if *flagPQEmbeddedSCTs {
335-
pqIncrease += scts.numSCTs*mldsaSignature - scts.totSig
355+
pqIncrease += scts.numSCTs*pqAlg.signatureSize - scts.totSig
336356
}
337357

338358
// Construct the new tiles.
@@ -363,7 +383,7 @@ func do() error {
363383
compareStats(newStats, oldStats)
364384
compareStats(newStats, oldPQStats)
365385
fmt.Printf("\n")
366-
fmt.Printf("old + PQ estimated with ML-DSA-44. new + PQ would be the same as new.\n")
386+
fmt.Printf("new + PQ would be the same as new.\n")
367387
return nil
368388
}
369389

0 commit comments

Comments
 (0)