initial commit
Some checks failed
CI / lint (push) Successful in 1m37s
CI / test-python (push) Successful in 1m49s
CI / test-zig (push) Successful in 1m39s
CI / test-wasm (push) Successful in 1m54s
CI / test (push) Successful in 14m44s
CI / miri (push) Successful in 14m18s
CI / build (push) Successful in 1m9s
CI / fuzz-regression (push) Successful in 9m9s
CI / publish (push) Failing after 1m10s
CI / publish-python (push) Failing after 1m46s
CI / publish-wasm (push) Has been cancelled

Signed-off-by: Kamal Tufekcic <kamal@lo.sh>
This commit is contained in:
Kamal Tufekcic 2026-04-02 23:48:10 +03:00
commit 1d99048c95
No known key found for this signature in database
165830 changed files with 79062 additions and 0 deletions

View file

@ -0,0 +1,55 @@
"""Tests for primitive cryptographic operations."""
import soliton
def test_sha3_256_known_vector():
"""FIPS 202 test vector: SHA3-256("abc")."""
result = soliton.sha3_256(b"abc")
expected = bytes.fromhex(
"3a985da74fe225b2045c172d6bd390bd"
"855f086e3e9d525b46bfe24511431532"
)
assert result == expected
def test_sha3_256_empty():
"""FIPS 202 test vector: SHA3-256("")."""
result = soliton.sha3_256(b"")
expected = bytes.fromhex(
"a7ffc6f8bf1ed76651c14756a061d662"
"f580ff4de43b49fa82d80a4b80f8434a"
)
assert result == expected
def test_fingerprint_hex():
result = soliton.fingerprint_hex(b"abc")
assert isinstance(result, str)
assert len(result) == 64 # 32 bytes hex-encoded
def test_hmac_sha3_256():
key = b"\x0b" * 32
data = b"Hi There"
tag = soliton.hmac_sha3_256(key, data)
assert len(tag) == 32
def test_hmac_sha3_256_verify():
key = b"\x0b" * 32
data = b"Hi There"
tag = soliton.hmac_sha3_256(key, data)
assert soliton.hmac_sha3_256_verify(tag, tag) is True
# Tampered tag should fail.
tampered = bytearray(tag)
tampered[0] ^= 0xFF
assert soliton.hmac_sha3_256_verify(tag, bytes(tampered)) is False
def test_hkdf_sha3_256():
salt = b"\x00" * 32
ikm = b"\x0b" * 32
info = b"test"
okm = soliton.hkdf_sha3_256(salt, ikm, info, length=64)
assert len(okm) == 64