#![allow(clippy::items_after_test_module)]
use oxilean_kernel::{BinderInfo, Declaration, Environment, Expr, Level, Name};
use super::types::{
DiffieHellmanSim, HashChain, ModularArithmetic, RsaKeyGen, ShamirSecretShare, ToyDiffieHellman,
ToyRsa,
};
pub fn app(f: Expr, a: Expr) -> Expr {
Expr::App(Box::new(f), Box::new(a))
}
pub fn app2(f: Expr, a: Expr, b: Expr) -> Expr {
app(app(f, a), b)
}
pub fn app3(f: Expr, a: Expr, b: Expr, c: Expr) -> Expr {
app(app2(f, a, b), c)
}
pub fn cst(s: &str) -> Expr {
Expr::Const(Name::str(s), vec![])
}
pub fn prop() -> Expr {
Expr::Sort(Level::zero())
}
pub fn type0() -> Expr {
Expr::Sort(Level::succ(Level::zero()))
}
pub fn pi(bi: BinderInfo, name: &str, dom: Expr, body: Expr) -> Expr {
Expr::Pi(bi, Name::str(name), Box::new(dom), Box::new(body))
}
pub fn arrow(a: Expr, b: Expr) -> Expr {
pi(BinderInfo::Default, "_", a, b)
}
pub fn bvar(n: u32) -> Expr {
Expr::BVar(n)
}
pub fn nat_ty() -> Expr {
cst("Nat")
}
pub fn bool_ty() -> Expr {
cst("Bool")
}
pub fn bytes_ty() -> Expr {
app(cst("List"), nat_ty())
}
pub fn hash_function_ty() -> Expr {
arrow(bytes_ty(), bytes_ty())
}
pub fn symmetric_key_ty() -> Expr {
bytes_ty()
}
pub fn public_key_ty() -> Expr {
type0()
}
pub fn private_key_ty() -> Expr {
type0()
}
pub fn signature_ty() -> Expr {
bytes_ty()
}
pub fn ciphertext_ty() -> Expr {
bytes_ty()
}
pub fn group_ty() -> Expr {
type0()
}
pub fn rsa_params_ty() -> Expr {
type0()
}
pub fn one_way_function_ty() -> Expr {
arrow(bytes_ty(), bytes_ty())
}
pub fn collision_resistant_ty() -> Expr {
arrow(hash_function_ty(), prop())
}
pub fn ind_cpa_ty() -> Expr {
prop()
}
pub fn ind_cca_ty() -> Expr {
prop()
}
pub fn euf_cma_ty() -> Expr {
prop()
}
pub fn discrete_log_hard_ty() -> Expr {
prop()
}
pub fn rsa_hard_ty() -> Expr {
prop()
}
pub fn rsa_correctness_ty() -> Expr {
prop()
}
pub fn dh_correctness_ty() -> Expr {
prop()
}
pub fn birthday_bound_ty() -> Expr {
prop()
}
pub fn trapdoor_function_ty() -> Expr {
type0()
}
pub fn trapdoor_invertible_ty() -> Expr {
arrow(trapdoor_function_ty(), prop())
}
pub fn goldreich_levin_ty() -> Expr {
arrow(one_way_function_ty(), prop())
}
pub fn prg_ty() -> Expr {
arrow(nat_ty(), arrow(nat_ty(), type0()))
}
pub fn prg_secure_ty() -> Expr {
arrow(app2(cst("PRG"), nat_ty(), nat_ty()), prop())
}
pub fn prf_ty() -> Expr {
arrow(nat_ty(), arrow(nat_ty(), type0()))
}
pub fn prf_secure_ty() -> Expr {
arrow(app2(cst("PRF"), nat_ty(), nat_ty()), prop())
}
pub fn preimage_resistant_ty() -> Expr {
arrow(hash_function_ty(), prop())
}
pub fn second_preimage_resistant_ty() -> Expr {
arrow(hash_function_ty(), prop())
}
pub fn random_oracle_model_ty() -> Expr {
type0()
}
pub fn signature_scheme_ty() -> Expr {
type0()
}
pub fn signature_correctness_ty() -> Expr {
arrow(signature_scheme_ty(), prop())
}
pub fn ecdsa_signature_ty() -> Expr {
type0()
}
pub fn ecdsa_correctness_ty() -> Expr {
prop()
}
pub fn ecdsa_unforgeability_ty() -> Expr {
prop()
}
pub fn pke_scheme_ty() -> Expr {
type0()
}
pub fn pke_correctness_ty() -> Expr {
arrow(pke_scheme_ty(), prop())
}
pub fn ind_cca2_ty() -> Expr {
prop()
}
pub fn rsa_oaep_ty() -> Expr {
type0()
}
pub fn rsa_oaep_ind_cca2_ty() -> Expr {
prop()
}
pub fn elliptic_curve_ty() -> Expr {
arrow(nat_ty(), type0())
}
pub fn ec_point_ty() -> Expr {
arrow(app(cst("EllipticCurve"), nat_ty()), type0())
}
pub fn ec_group_law_ty() -> Expr {
arrow(app(cst("EllipticCurve"), nat_ty()), prop())
}
pub fn ecdlp_hard_ty() -> Expr {
arrow(nat_ty(), prop())
}
pub fn ecdh_correctness_ty() -> Expr {
prop()
}
pub fn ecdh_hardness_ty() -> Expr {
prop()
}
pub fn bilinear_map_ty() -> Expr {
type0()
}
pub fn pairing_bilinearity_ty() -> Expr {
arrow(bilinear_map_ty(), prop())
}
pub fn bdh_hard_ty() -> Expr {
prop()
}
pub fn bdddh_hard_ty() -> Expr {
prop()
}
pub fn bls_signature_ty() -> Expr {
arrow(bilinear_map_ty(), type0())
}
pub fn bls_unforgeability_ty() -> Expr {
arrow(bilinear_map_ty(), prop())
}
pub fn sigma_protocol_ty() -> Expr {
type0()
}
pub fn zk_completeness_ty() -> Expr {
arrow(sigma_protocol_ty(), prop())
}
pub fn zk_soundness_ty() -> Expr {
arrow(sigma_protocol_ty(), prop())
}
pub fn zk_zero_knowledge_ty() -> Expr {
arrow(sigma_protocol_ty(), prop())
}
pub fn fiat_shamir_transform_ty() -> Expr {
arrow(sigma_protocol_ty(), type0())
}
pub fn fiat_shamir_soundness_ty() -> Expr {
arrow(sigma_protocol_ty(), prop())
}
pub fn ip_eq_pspace_ty() -> Expr {
prop()
}
pub fn snark_correctness_ty() -> Expr {
prop()
}
pub fn commitment_scheme_ty() -> Expr {
type0()
}
pub fn commitment_hiding_ty() -> Expr {
arrow(commitment_scheme_ty(), prop())
}
pub fn commitment_binding_ty() -> Expr {
arrow(commitment_scheme_ty(), prop())
}
pub fn pedersen_commitment_ty() -> Expr {
type0()
}
pub fn oblivious_transfer_ty() -> Expr {
type0()
}
pub fn ot_correctness_ty() -> Expr {
arrow(oblivious_transfer_ty(), prop())
}
pub fn secure_mpc_ty() -> Expr {
arrow(nat_ty(), type0())
}
pub fn mpc_security_ty() -> Expr {
arrow(app(cst("SecureMPC"), nat_ty()), prop())
}
pub fn she_ty() -> Expr {
type0()
}
pub fn she_correctness_ty() -> Expr {
arrow(she_ty(), prop())
}
pub fn fhe_ty() -> Expr {
type0()
}
pub fn fhe_correctness_ty() -> Expr {
arrow(fhe_ty(), prop())
}
pub fn bootstrapping_theorem_ty() -> Expr {
prop()
}
pub fn shamir_secret_sharing_ty() -> Expr {
arrow(nat_ty(), arrow(nat_ty(), type0()))
}
pub fn shamir_perfect_secrecy_ty() -> Expr {
arrow(nat_ty(), arrow(nat_ty(), prop()))
}
pub fn shamir_reconstruction_ty() -> Expr {
arrow(nat_ty(), arrow(nat_ty(), prop()))
}
pub fn threshold_scheme_ty() -> Expr {
arrow(nat_ty(), arrow(nat_ty(), type0()))
}
pub fn hash_chain_ty() -> Expr {
arrow(nat_ty(), type0())
}
pub fn hash_chain_integrity_ty() -> Expr {
arrow(app(cst("HashChain"), nat_ty()), prop())
}
pub fn merkle_tree_ty() -> Expr {
arrow(nat_ty(), type0())
}
pub fn merkle_inclusion_proof_ty() -> Expr {
arrow(app(cst("MerkleTree"), nat_ty()), prop())
}
pub fn blockchain_consensus_ty() -> Expr {
type0()
}
pub fn build_cryptography_env(env: &mut Environment) -> Result<(), String> {
let axioms: &[(&str, Expr)] = &[
("Crypto.HashFunction", hash_function_ty()),
("Crypto.SymmetricKey", symmetric_key_ty()),
("Crypto.PublicKey", public_key_ty()),
("Crypto.PrivateKey", private_key_ty()),
("Crypto.Signature", signature_ty()),
("Crypto.Ciphertext", ciphertext_ty()),
("Crypto.Group", group_ty()),
("Crypto.RsaParams", rsa_params_ty()),
("Crypto.OneWayFunction", one_way_function_ty()),
("Crypto.CollisionResistant", collision_resistant_ty()),
("Crypto.IndCpa", ind_cpa_ty()),
("Crypto.IndCca", ind_cca_ty()),
("Crypto.EufCma", euf_cma_ty()),
("Crypto.DiscreteLogHard", discrete_log_hard_ty()),
("Crypto.RsaHard", rsa_hard_ty()),
("Crypto.RsaCorrectness", rsa_correctness_ty()),
("Crypto.DhCorrectness", dh_correctness_ty()),
("Crypto.BirthdayBound", birthday_bound_ty()),
("Crypto.TrapdoorFunction", trapdoor_function_ty()),
("Crypto.TrapdoorInvertible", trapdoor_invertible_ty()),
("Crypto.GoldreichLevinHardCoreBit", goldreich_levin_ty()),
("Crypto.PRG", prg_ty()),
("Crypto.PrgSecure", prg_secure_ty()),
("Crypto.PRF", prf_ty()),
("Crypto.PrfSecure", prf_secure_ty()),
("Crypto.PreimageResistant", preimage_resistant_ty()),
(
"Crypto.SecondPreimageResistant",
second_preimage_resistant_ty(),
),
("Crypto.RandomOracleModel", random_oracle_model_ty()),
("Crypto.SignatureScheme", signature_scheme_ty()),
("Crypto.SignatureCorrectness", signature_correctness_ty()),
("Crypto.EcdsaSignature", ecdsa_signature_ty()),
("Crypto.EcdsaCorrectness", ecdsa_correctness_ty()),
("Crypto.EcdsaUnforgeability", ecdsa_unforgeability_ty()),
("Crypto.PKEScheme", pke_scheme_ty()),
("Crypto.PkeCorrectness", pke_correctness_ty()),
("Crypto.IndCca2", ind_cca2_ty()),
("Crypto.RsaOaep", rsa_oaep_ty()),
("Crypto.RsaOaepIndCca2", rsa_oaep_ind_cca2_ty()),
("Crypto.EllipticCurve", elliptic_curve_ty()),
("Crypto.ECPoint", ec_point_ty()),
("Crypto.EcGroupLaw", ec_group_law_ty()),
("Crypto.EcdlpHard", ecdlp_hard_ty()),
("Crypto.EcdhCorrectness", ecdh_correctness_ty()),
("Crypto.EcdhHardness", ecdh_hardness_ty()),
("Crypto.BilinearMap", bilinear_map_ty()),
("Crypto.PairingBilinearity", pairing_bilinearity_ty()),
("Crypto.BdhHard", bdh_hard_ty()),
("Crypto.BdddhHard", bdddh_hard_ty()),
("Crypto.BlsSignature", bls_signature_ty()),
("Crypto.BlsUnforgeability", bls_unforgeability_ty()),
("Crypto.SigmaProtocol", sigma_protocol_ty()),
("Crypto.ZkCompleteness", zk_completeness_ty()),
("Crypto.ZkSoundness", zk_soundness_ty()),
("Crypto.ZkZeroKnowledge", zk_zero_knowledge_ty()),
("Crypto.FiatShamirTransform", fiat_shamir_transform_ty()),
("Crypto.FiatShamirSoundness", fiat_shamir_soundness_ty()),
("Crypto.IpEqPspace", ip_eq_pspace_ty()),
("Crypto.SnarkCorrectness", snark_correctness_ty()),
("Crypto.CommitmentScheme", commitment_scheme_ty()),
("Crypto.CommitmentHiding", commitment_hiding_ty()),
("Crypto.CommitmentBinding", commitment_binding_ty()),
("Crypto.PedersenCommitment", pedersen_commitment_ty()),
("Crypto.ObliviousTransfer", oblivious_transfer_ty()),
("Crypto.OtCorrectness", ot_correctness_ty()),
("Crypto.SecureMPC", secure_mpc_ty()),
("Crypto.MpcSecurity", mpc_security_ty()),
("Crypto.SHE", she_ty()),
("Crypto.SheCorrectness", she_correctness_ty()),
("Crypto.FHE", fhe_ty()),
("Crypto.FheCorrectness", fhe_correctness_ty()),
("Crypto.BootstrappingTheorem", bootstrapping_theorem_ty()),
("Crypto.ShamirSecretSharing", shamir_secret_sharing_ty()),
("Crypto.ShamirPerfectSecrecy", shamir_perfect_secrecy_ty()),
("Crypto.ShamirReconstruction", shamir_reconstruction_ty()),
("Crypto.ThresholdScheme", threshold_scheme_ty()),
("Crypto.HashChain", hash_chain_ty()),
("Crypto.HashChainIntegrity", hash_chain_integrity_ty()),
("Crypto.MerkleTree", merkle_tree_ty()),
("Crypto.MerkleInclusionProof", merkle_inclusion_proof_ty()),
("Crypto.BlockchainConsensus", blockchain_consensus_ty()),
];
for (name, ty) in axioms {
env.add(Declaration::Axiom {
name: Name::str(*name),
univ_params: vec![],
ty: ty.clone(),
})
.ok();
}
Ok(())
}
pub fn mod_exp(base: u64, exp: u64, modulus: u64) -> u64 {
if modulus == 1 {
return 0;
}
let mut result: u128 = 1;
let mut base = base as u128 % modulus as u128;
let mut exp = exp;
let modulus = modulus as u128;
while exp > 0 {
if exp & 1 == 1 {
result = result * base % modulus;
}
exp >>= 1;
base = base * base % modulus;
}
result as u64
}
pub fn extended_gcd(a: i64, b: i64) -> (i64, i64, i64) {
if b == 0 {
return (a, 1, 0);
}
let (g, x1, y1) = extended_gcd(b, a % b);
(g, y1, x1 - (a / b) * y1)
}
pub fn mod_inverse(a: u64, m: u64) -> Option<u64> {
let (g, x, _) = extended_gcd(a as i64, m as i64);
if g != 1 {
return None;
}
Some(((x % m as i64 + m as i64) % m as i64) as u64)
}
pub fn sha256_compress_round(state: &mut [u32; 8], w: u32, k: u32) {
let [a, b, c, d, e, f, g, h] = *state;
let s1 = e.rotate_right(6) ^ e.rotate_right(11) ^ e.rotate_right(25);
let ch = (e & f) ^ ((!e) & g);
let temp1 = h
.wrapping_add(s1)
.wrapping_add(ch)
.wrapping_add(k)
.wrapping_add(w);
let s0 = a.rotate_right(2) ^ a.rotate_right(13) ^ a.rotate_right(22);
let maj = (a & b) ^ (a & c) ^ (b & c);
let temp2 = s0.wrapping_add(maj);
state[7] = g;
state[6] = f;
state[5] = e;
state[4] = d.wrapping_add(temp1);
state[3] = c;
state[2] = b;
state[1] = a;
state[0] = temp1.wrapping_add(temp2);
}
pub fn simple_hash(data: &[u8]) -> u64 {
const BASE: u128 = 131;
const MOD: u128 = (1 << 61) - 1;
let mut hash: u128 = 0;
let mut power: u128 = 1;
for &byte in data {
hash = (hash + (byte as u128) * power) % MOD;
power = power * BASE % MOD;
}
hash as u64
}
pub fn caesar_cipher(text: &[u8], shift: u8) -> Vec<u8> {
text.iter().map(|&b| b.wrapping_add(shift)).collect()
}
pub fn caesar_decipher(text: &[u8], shift: u8) -> Vec<u8> {
text.iter().map(|&b| b.wrapping_sub(shift)).collect()
}
pub fn vigenere_cipher(text: &[u8], key: &[u8]) -> Vec<u8> {
if key.is_empty() {
return text.to_vec();
}
text.iter()
.enumerate()
.map(|(i, &b)| b ^ key[i % key.len()])
.collect()
}
pub fn miller_rabin(n: u64, witnesses: &[u64]) -> bool {
if n < 2 {
return false;
}
if n == 2 || n == 3 {
return true;
}
if n % 2 == 0 {
return false;
}
let mut d = n - 1;
let mut r = 0u32;
while d % 2 == 0 {
d /= 2;
r += 1;
}
'witness: for &a in witnesses {
if a >= n {
continue;
}
let mut x = mod_exp(a, d, n);
if x == 1 || x == n - 1 {
continue 'witness;
}
for _ in 0..r - 1 {
x = mod_exp(x, 2, n);
if x == n - 1 {
continue 'witness;
}
}
return false;
}
true
}
#[cfg(test)]
mod tests {
use super::*;
use oxilean_kernel::Environment;
#[test]
fn test_mod_exp() {
assert_eq!(mod_exp(2, 10, 1000), 24);
assert_eq!(mod_exp(5, 0, 7), 1);
assert_eq!(mod_exp(0, 5, 7), 0);
assert_eq!(mod_exp(3, 6, 7), 1);
}
#[test]
fn test_extended_gcd() {
let (g, x, y) = extended_gcd(35, 15);
assert_eq!(g, 5);
assert_eq!(35 * x + 15 * y, g);
let (g2, x2, y2) = extended_gcd(48, 18);
assert_eq!(g2, 6);
assert_eq!(48 * x2 + 18 * y2, g2);
}
#[test]
fn test_mod_inverse() {
assert_eq!(mod_inverse(3, 7), Some(5));
assert_eq!(mod_inverse(2, 9), Some(5));
assert_eq!(mod_inverse(4, 6), None);
}
#[test]
fn test_toy_rsa() {
let rsa = ToyRsa::generate(61, 53).expect("RSA generation should succeed for p=61, q=53");
let message = 42u64;
assert!(message < rsa.n, "message must be smaller than modulus");
let ciphertext = rsa.encrypt(message);
let recovered = rsa.decrypt(ciphertext);
assert_eq!(
recovered, message,
"RSA decrypt(encrypt(m)) must equal m; got {} for message {}",
recovered, message
);
let msg2 = 100u64;
assert!(msg2 < rsa.n);
assert_eq!(rsa.decrypt(rsa.encrypt(msg2)), msg2);
}
#[test]
fn test_toy_dh() {
let dh = ToyDiffieHellman { p: 23, g: 5 };
let alice_private = 6u64;
let bob_private = 15u64;
let alice_public = dh.public_key(alice_private);
let bob_public = dh.public_key(bob_private);
let alice_secret = dh.shared_secret(bob_public, alice_private);
let bob_secret = dh.shared_secret(alice_public, bob_private);
assert_eq!(
alice_secret, bob_secret,
"Diffie-Hellman shared secrets must match: Alice got {}, Bob got {}",
alice_secret, bob_secret
);
assert_eq!(alice_secret, 2);
}
#[test]
fn test_miller_rabin() {
let primes = [2u64, 3, 5, 7, 11, 13, 17, 19, 23, 97, 101, 7919];
let witnesses = [2u64, 3, 5, 7];
for &p in &primes {
assert!(
miller_rabin(p, &witnesses),
"{} is prime but Miller-Rabin returned false",
p
);
}
let composites = [1u64, 4, 6, 8, 9, 10, 15, 21, 25, 100, 561];
for &c in &composites {
assert!(
!miller_rabin(c, &witnesses),
"{} is composite but Miller-Rabin returned true",
c
);
}
}
#[test]
fn test_caesar() {
let plaintext = b"hello";
let shift = 3u8;
let ciphertext = caesar_cipher(plaintext, shift);
let decrypted = caesar_decipher(&ciphertext, shift);
assert_eq!(
decrypted, plaintext,
"Caesar decipher(cipher(text, k), k) must return original text"
);
assert_eq!(ciphertext[0], b'k');
}
#[test]
fn test_vigenere() {
let plaintext = b"attackatdawn";
let key = b"lemon";
let ciphertext = vigenere_cipher(plaintext, key);
let decrypted = vigenere_cipher(&ciphertext, key);
assert_eq!(decrypted, plaintext);
}
#[test]
fn test_simple_hash() {
assert_eq!(simple_hash(b"hello"), simple_hash(b"hello"));
assert_ne!(simple_hash(b"hello"), simple_hash(b"world"));
assert_eq!(simple_hash(b""), 0);
}
#[test]
fn test_build_env() {
let mut env = Environment::new();
let result = build_cryptography_env(&mut env);
assert!(
result.is_ok(),
"build_cryptography_env should succeed: {:?}",
result
);
}
#[test]
fn test_modular_arithmetic() {
let ma = ModularArithmetic::new(17);
assert_eq!(ma.add(10, 9), 2);
assert_eq!(ma.sub(3, 5), 15);
assert_eq!(ma.mul(4, 5), 3);
assert_eq!(ma.pow(2, 8), 1);
assert_eq!(ma.inv(3), Some(6));
assert_eq!(ma.legendre(4), 1);
let ma7 = ModularArithmetic::new(7);
assert_eq!(ma7.legendre(3), -1);
}
#[test]
fn test_rsa_keygen() {
let (rsa, p, q) =
RsaKeyGen::generate_from_seed(500).expect("RsaKeyGen should succeed for seed=500");
assert!(miller_rabin(p, &[2, 3, 5, 7]), "p should be prime");
assert!(miller_rabin(q, &[2, 3, 5, 7]), "q should be prime");
assert_eq!(rsa.n, p * q);
let msg = 7u64;
assert!(msg < rsa.n);
assert_eq!(rsa.decrypt(rsa.encrypt(msg)), msg);
}
#[test]
fn test_diffie_hellman_sim() {
let sim = DiffieHellmanSim::new(23, 5, 6, 15);
assert!(sim.secrets_match(), "DH shared secrets must match");
assert_eq!(sim.alice_shared_secret(), 2);
assert_eq!(sim.bob_shared_secret(), 2);
}
#[test]
fn test_hash_chain() {
let mut chain = HashChain::new(12345);
let data = [111u64, 222, 333];
for &d in &data {
chain.append(d);
}
assert_eq!(chain.chain.len(), 4);
assert!(chain.verify(&data), "Hash chain verification should pass");
let mut tampered_chain = chain.clone();
tampered_chain.chain[1] = tampered_chain.chain[1].wrapping_add(1);
assert!(
!tampered_chain.verify(&data),
"Tampered chain should fail verification"
);
}
#[test]
fn test_shamir_secret_share() {
let sss = ShamirSecretShare::new(97, 2, 3);
let secret = 42u64;
let shares = sss.share(secret, 12345);
assert_eq!(shares.len(), 3);
let from_01 = sss.reconstruct(&shares[..2]);
let from_12 = sss.reconstruct(&[shares[1], shares[2]]);
let from_02 = sss.reconstruct(&[shares[0], shares[2]]);
assert_eq!(
from_01,
Some(secret),
"shares[0,1] should reconstruct secret"
);
assert_eq!(
from_12,
Some(secret),
"shares[1,2] should reconstruct secret"
);
assert_eq!(
from_02,
Some(secret),
"shares[0,2] should reconstruct secret"
);
let from_all = sss.reconstruct(&shares);
assert_eq!(
from_all,
Some(secret),
"all 3 shares should reconstruct secret"
);
let from_one = sss.reconstruct(&shares[..1]);
assert_eq!(from_one, None, "fewer than k shares should return None");
}
#[test]
fn test_axioms_registered() {
let mut env = Environment::new();
build_cryptography_env(&mut env).expect("build_cryptography_env should succeed");
let expected = [
"Crypto.TrapdoorFunction",
"Crypto.GoldreichLevinHardCoreBit",
"Crypto.PRG",
"Crypto.PRF",
"Crypto.PreimageResistant",
"Crypto.EcdsaUnforgeability",
"Crypto.IndCca2",
"Crypto.RsaOaepIndCca2",
"Crypto.EllipticCurve",
"Crypto.EcdlpHard",
"Crypto.EcdhCorrectness",
"Crypto.BilinearMap",
"Crypto.BdhHard",
"Crypto.BlsUnforgeability",
"Crypto.SigmaProtocol",
"Crypto.ZkCompleteness",
"Crypto.ZkSoundness",
"Crypto.ZkZeroKnowledge",
"Crypto.FiatShamirTransform",
"Crypto.IpEqPspace",
"Crypto.SnarkCorrectness",
"Crypto.CommitmentScheme",
"Crypto.CommitmentHiding",
"Crypto.CommitmentBinding",
"Crypto.ObliviousTransfer",
"Crypto.SecureMPC",
"Crypto.FHE",
"Crypto.BootstrappingTheorem",
"Crypto.ShamirSecretSharing",
"Crypto.ShamirPerfectSecrecy",
"Crypto.HashChain",
"Crypto.MerkleTree",
"Crypto.BlockchainConsensus",
];
for name in &expected {
assert!(
env.get(&Name::str(*name)).is_some(),
"Expected axiom '{}' not found in environment",
name
);
}
}
}
pub fn cry_ext_lwe_hardness_ty() -> Expr {
arrow(nat_ty(), arrow(nat_ty(), prop()))
}
pub fn cry_ext_rlwe_hardness_ty() -> Expr {
arrow(nat_ty(), prop())
}
pub fn cry_ext_lwe_enc_ty() -> Expr {
arrow(nat_ty(), arrow(nat_ty(), type0()))
}
pub fn cry_ext_lwe_enc_correct_ty() -> Expr {
arrow(nat_ty(), arrow(nat_ty(), prop()))
}
pub fn cry_ext_kyber_kem_ty() -> Expr {
arrow(nat_ty(), type0())
}
pub fn cry_ext_kyber_ind_cca2_ty() -> Expr {
arrow(nat_ty(), prop())
}
pub fn cry_ext_ntru_hardness_ty() -> Expr {
arrow(nat_ty(), prop())
}
pub fn cry_ext_dilithium_sig_ty() -> Expr {
arrow(nat_ty(), type0())
}
pub fn cry_ext_dilithium_euf_cma_ty() -> Expr {
arrow(nat_ty(), prop())
}
pub fn cry_ext_linear_code_ty() -> Expr {
arrow(nat_ty(), arrow(nat_ty(), arrow(nat_ty(), type0())))
}
pub fn cry_ext_mceliece_ty() -> Expr {
arrow(nat_ty(), arrow(nat_ty(), arrow(nat_ty(), type0())))
}
pub fn cry_ext_mceliece_hardness_ty() -> Expr {
arrow(nat_ty(), arrow(nat_ty(), prop()))
}
pub fn cry_ext_syndrome_decode_ty() -> Expr {
arrow(nat_ty(), arrow(nat_ty(), prop()))
}
pub fn cry_ext_xmss_sig_ty() -> Expr {
arrow(nat_ty(), type0())
}
pub fn cry_ext_xmss_euf_cma_ty() -> Expr {
arrow(nat_ty(), prop())
}
pub fn cry_ext_sphincs_sig_ty() -> Expr {
type0()
}
pub fn cry_ext_sphincs_euf_cma_ty() -> Expr {
prop()
}
pub fn cry_ext_wots_plus_ty() -> Expr {
arrow(nat_ty(), type0())
}
pub fn cry_ext_isogeny_ty() -> Expr {
arrow(nat_ty(), arrow(nat_ty(), type0()))
}
pub fn cry_ext_sidh_hardness_ty() -> Expr {
arrow(nat_ty(), prop())
}
pub fn cry_ext_supersingular_curve_ty() -> Expr {
arrow(nat_ty(), type0())
}
pub fn cry_ext_zk_snark_ty() -> Expr {
type0()
}
pub fn cry_ext_zk_snark_succinctness_ty() -> Expr {
arrow(cry_ext_zk_snark_ty(), prop())
}
pub fn cry_ext_zk_snark_knowledge_ty() -> Expr {
arrow(cry_ext_zk_snark_ty(), prop())
}
pub fn cry_ext_zk_stark_ty() -> Expr {
type0()
}
pub fn cry_ext_zk_stark_soundness_ty() -> Expr {
arrow(cry_ext_zk_stark_ty(), prop())
}
pub fn cry_ext_schnorr_id_ty() -> Expr {
type0()
}
pub fn cry_ext_schnorr_soundness_ty() -> Expr {
arrow(cry_ext_schnorr_id_ty(), prop())
}
pub fn cry_ext_nizk_proof_ty() -> Expr {
type0()
}
pub fn cry_ext_nizk_sim_soundness_ty() -> Expr {
arrow(cry_ext_nizk_proof_ty(), prop())
}
pub fn cry_ext_blakley_ss_ty() -> Expr {
arrow(nat_ty(), arrow(nat_ty(), type0()))
}
pub fn cry_ext_blakley_correct_ty() -> Expr {
arrow(nat_ty(), arrow(nat_ty(), prop()))
}
pub fn cry_ext_garbled_circuit_ty() -> Expr {
type0()
}
pub fn cry_ext_garbled_circuit_sec_ty() -> Expr {
arrow(cry_ext_garbled_circuit_ty(), prop())
}
pub fn cry_ext_oram_ty() -> Expr {
arrow(nat_ty(), type0())
}
pub fn cry_ext_oram_security_ty() -> Expr {
arrow(nat_ty(), prop())
}
pub fn cry_ext_vss_ty() -> Expr {
arrow(nat_ty(), arrow(nat_ty(), type0()))
}
pub fn cry_ext_vss_correct_ty() -> Expr {
arrow(nat_ty(), arrow(nat_ty(), prop()))
}
pub fn cry_ext_pedersen_hiding_ty() -> Expr {
prop()
}
pub fn cry_ext_pedersen_binding_ty() -> Expr {
prop()
}
pub fn cry_ext_elgamal_ty() -> Expr {
type0()
}
pub fn cry_ext_elgamal_hom_ty() -> Expr {
arrow(cry_ext_elgamal_ty(), prop())
}
pub fn cry_ext_elgamal_ind_cpa_ty() -> Expr {
prop()
}
pub fn cry_ext_paillier_ty() -> Expr {
type0()
}
pub fn cry_ext_paillier_add_hom_ty() -> Expr {
arrow(cry_ext_paillier_ty(), prop())
}
pub fn cry_ext_threshold_sig_ty() -> Expr {
arrow(nat_ty(), arrow(nat_ty(), type0()))
}
pub fn cry_ext_threshold_sig_correct_ty() -> Expr {
arrow(nat_ty(), arrow(nat_ty(), prop()))
}
pub fn cry_ext_threshold_sig_sec_ty() -> Expr {
arrow(nat_ty(), arrow(nat_ty(), prop()))
}
pub fn cry_ext_frost_sig_ty() -> Expr {
arrow(nat_ty(), type0())
}
pub fn register_cryptography_extended(env: &mut Environment) -> Result<(), String> {
let axioms: &[(&str, Expr)] = &[
("Crypto.LweHardness", cry_ext_lwe_hardness_ty()),
("Crypto.RlweHardness", cry_ext_rlwe_hardness_ty()),
("Crypto.LweEncScheme", cry_ext_lwe_enc_ty()),
("Crypto.LweEncCorrectness", cry_ext_lwe_enc_correct_ty()),
("Crypto.KyberKem", cry_ext_kyber_kem_ty()),
("Crypto.KyberIndCca2", cry_ext_kyber_ind_cca2_ty()),
("Crypto.NtruHardness", cry_ext_ntru_hardness_ty()),
("Crypto.DilithiumSig", cry_ext_dilithium_sig_ty()),
("Crypto.DilithiumEufCma", cry_ext_dilithium_euf_cma_ty()),
("Crypto.LinearCode", cry_ext_linear_code_ty()),
("Crypto.McElieceEncryption", cry_ext_mceliece_ty()),
("Crypto.McElieceHardness", cry_ext_mceliece_hardness_ty()),
("Crypto.SyndromeDecode", cry_ext_syndrome_decode_ty()),
("Crypto.XmssSig", cry_ext_xmss_sig_ty()),
("Crypto.XmssEufCma", cry_ext_xmss_euf_cma_ty()),
("Crypto.SphincsSig", cry_ext_sphincs_sig_ty()),
("Crypto.SphincsEufCma", cry_ext_sphincs_euf_cma_ty()),
("Crypto.WotsPlus", cry_ext_wots_plus_ty()),
("Crypto.Isogeny", cry_ext_isogeny_ty()),
("Crypto.SidhHardness", cry_ext_sidh_hardness_ty()),
(
"Crypto.SupersingularCurve",
cry_ext_supersingular_curve_ty(),
),
("Crypto.ZkSnark", cry_ext_zk_snark_ty()),
(
"Crypto.ZkSnarkSuccinctness",
cry_ext_zk_snark_succinctness_ty(),
),
(
"Crypto.ZkSnarkKnowledgeSoundness",
cry_ext_zk_snark_knowledge_ty(),
),
("Crypto.ZkStark", cry_ext_zk_stark_ty()),
("Crypto.ZkStarkSoundness", cry_ext_zk_stark_soundness_ty()),
("Crypto.SchnorrIdentification", cry_ext_schnorr_id_ty()),
("Crypto.SchnorrSoundness", cry_ext_schnorr_soundness_ty()),
("Crypto.NizkProof", cry_ext_nizk_proof_ty()),
(
"Crypto.NizkSimulationSoundness",
cry_ext_nizk_sim_soundness_ty(),
),
("Crypto.BlakleySecretSharing", cry_ext_blakley_ss_ty()),
("Crypto.BlakleyCorrectness", cry_ext_blakley_correct_ty()),
("Crypto.GarbledCircuit", cry_ext_garbled_circuit_ty()),
(
"Crypto.GarbledCircuitSecurity",
cry_ext_garbled_circuit_sec_ty(),
),
("Crypto.ObliviousRam", cry_ext_oram_ty()),
("Crypto.OramSecurity", cry_ext_oram_security_ty()),
("Crypto.VerifiableSecretSharing", cry_ext_vss_ty()),
("Crypto.VssCorrectness", cry_ext_vss_correct_ty()),
("Crypto.PedersenHiding", cry_ext_pedersen_hiding_ty()),
("Crypto.PedersenBinding", cry_ext_pedersen_binding_ty()),
("Crypto.ElgamalEncryption", cry_ext_elgamal_ty()),
("Crypto.ElgamalHomomorphism", cry_ext_elgamal_hom_ty()),
("Crypto.ElgamalIndCpa", cry_ext_elgamal_ind_cpa_ty()),
("Crypto.PaillierEncryption", cry_ext_paillier_ty()),
("Crypto.PaillierAdditiveHom", cry_ext_paillier_add_hom_ty()),
("Crypto.ThresholdSignature", cry_ext_threshold_sig_ty()),
(
"Crypto.ThresholdSigCorrectness",
cry_ext_threshold_sig_correct_ty(),
),
(
"Crypto.ThresholdSigSecurity",
cry_ext_threshold_sig_sec_ty(),
),
("Crypto.FrostSignature", cry_ext_frost_sig_ty()),
];
for (name, ty) in axioms {
env.add(Declaration::Axiom {
name: Name::str(*name),
univ_params: vec![],
ty: ty.clone(),
})
.ok();
}
Ok(())
}