Speed up generation by caching signatures

We tend to generate the signature of the same message under the same keys
multiple times for different APIs (sign/verify, driver/dispatch, ...).
Caching results makes the script noticeably faster.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
This commit is contained in:
Gilles Peskine
2026-04-20 10:13:21 +02:00
parent c6610dde67
commit f8d36c84ac
@@ -4,6 +4,7 @@
# Copyright The Mbed TLS Contributors
# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
import functools
from typing import Iterator, List, Optional
# pip install dilithium-py
@@ -41,6 +42,7 @@ class Key:
self.seed = seed
self.public, self.secret = PURE[kl]._keygen_internal(seed)
@functools.lru_cache(maxsize=9999)
def sign_message(self, message: bytes, deterministic: bool) -> bytes:
PURE[self.kl].set_drbg_seed(bytes(48))
return PURE[self.kl].sign(self.secret, message,