This release is a pre-release and may not be stable for production use.
Swarmauri Evaluator Constanttime
Evaluator that detects timing side channels using a fixed-vs-random strategy.
It times a callable with repeated fixed inputs and compares those timings against
randomly generated inputs. Welch's t-test and Cliff's delta are used to decide
whether the observed runtime differences are statistically significant. The
evaluator reports a score of 1.0 for constant-time behaviour and 0.0
otherwise, together with rich metadata about the underlying measurements.
Installation
pip
pip install swarmauri_evaluator_constanttime
Poetry
poetry add swarmauri_evaluator_constanttime
uv
uv venv
source .venv/bin/activate
uv pip install swarmauri_evaluator_constanttime
Usage
The example below evaluates a deliberately leaky string comparison that sleeps for every matching byte. Fixed inputs run all the way through the comparison and take measurably longer than random guesses that fail fast, so the evaluator flags the function as not constant time.
import secrets
import time
from swarmauri_core.programs.IProgram import IProgram
from swarmauri_evaluator_constanttime import ConstantTimeEvaluator
class DummyProgram(IProgram):
def diff(self, other: "IProgram"):
return ()
def apply_diff(self, diff):
return self
def validate(self) -> bool:
return True
def clone(self) -> "IProgram":
return DummyProgram()
def insecure_compare(secret: bytes, guess: bytes) -> bool:
for secret_byte, guess_byte in zip(secret, guess):
if secret_byte != guess_byte:
return False
time.sleep(0.0001)
return len(secret) == len(guess)
def make_input_pair() -> tuple[bytes, bytes]:
return secrets.token_bytes(16), secrets.token_bytes(16)
def main() -> None:
evaluator = ConstantTimeEvaluator()
score, metadata = evaluator._compute_score(
program=DummyProgram(),
fn=insecure_compare,
make_input_pair=make_input_pair,
fixed_pair=(b"A" * 16, b"A" * 16),
n_samples=20,
iters_per=5,
)
print(f"Score: {score:.1f}")
print(f"Constant time? {metadata['constant_time']}")
print(f"t-statistic: {metadata['t_stat']:.2f}")
print(f"Cliff's delta: {metadata['cliff_delta']:.3f}")
assert metadata["constant_time"] is False
if __name__ == "__main__":
main()
Want to help?
If you want to contribute to swarmauri-sdk, read up on our guidelines for contributing that will help you get started.
Metadata
Release files for swarmauri_evaluator_constanttime 0.11.0.dev1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| swarmauri_evaluator_constanttime-0.11.0.dev1.tar.gz | 8.6 kB | Without provenance | Details for swarmauri_evaluator_constanttime-0.11.0.dev1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| swarmauri_evaluator_constanttime-0.11.0.dev1-py3-none-any.whl | Python 3 | none | any | Details for swarmauri_evaluator_constanttime-0.11.0.dev1-py3-none-any.whl |
Total release size: 18.2 kB
Release files / swarmauri_evaluator_constanttime-0.11.0.dev1.tar.gz
| Download URL | swarmauri_evaluator_constanttime-0.11.0.dev1.tar.gz |
|---|---|
| Size | 8.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
22d58e452bb1995fa197db96a8c8b070b7bf0f20aa9429ef1eb09c7eca1c4251
|
|
BLAKE2b-256 checksum How to use checksums |
df0725fbfe39eff78416dbd070cc9e8c8367985f56258a2f3e67d5cc35dddfda
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / swarmauri_evaluator_constanttime-0.11.0.dev1-py3-none-any.whl
| Download URL | swarmauri_evaluator_constanttime-0.11.0.dev1-py3-none-any.whl |
|---|---|
| Size | 9.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0252e8f58e8dfc62e4926abbd7a4d64ce9971ffd3e8691d0a0248628967d276c
|
|
BLAKE2b-256 checksum How to use checksums |
61b075d179cabcc84b4d3a9452db73148904c753019dd1dd13eb3e779ec97521
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for swarmauri_evaluator_constanttime 0.11.0.dev1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.