oqs: cross-check McEliece against the rustcrypto provider
Keys and ciphertexts from either implementation must work in the other, including implicit rejection. Refs: R3-9
This commit is contained in:
parent
99c0324195
commit
64082b98a8
|
|
@ -326,6 +326,7 @@ name = "ccc-crypto-oqs"
|
|||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"ccc-crypto-core",
|
||||
"ccc-crypto-rustcrypto",
|
||||
"getrandom",
|
||||
"log",
|
||||
"oqs",
|
||||
|
|
|
|||
|
|
@ -23,3 +23,6 @@ getrandom = { version = "0.4", optional = true }
|
|||
default = []
|
||||
liboqs = ["dep:oqs", "dep:sha3", "dep:getrandom"]
|
||||
|
||||
[dev-dependencies]
|
||||
# Classic McEliece interop: liboqs is the oracle for the RustCrypto code.
|
||||
ccc-crypto-rustcrypto.workspace = true
|
||||
|
|
|
|||
|
|
@ -0,0 +1,42 @@
|
|||
//! liboqs as the oracle for the RustCrypto Classic McEliece code: keys and
|
||||
//! ciphertexts from either side work on the other.
|
||||
|
||||
#![cfg(feature = "liboqs")]
|
||||
|
||||
use ccc_crypto_core::{algorithms::KemAlgorithm, provider::KemProvider};
|
||||
use ccc_crypto_oqs::OqsProvider;
|
||||
use ccc_crypto_rustcrypto::RustCryptoProvider;
|
||||
|
||||
const ALGO: KemAlgorithm = KemAlgorithm::ClassicMcEliece460896f;
|
||||
|
||||
#[test]
|
||||
fn rustcrypto_ciphertext_opens_in_oqs() {
|
||||
let (oqs, rc) = (OqsProvider::new(), RustCryptoProvider::new());
|
||||
let kp = oqs.generate_keypair(ALGO).unwrap();
|
||||
let enc = rc.encapsulate(ALGO, &kp.public_key).unwrap();
|
||||
let ss = oqs.decapsulate(ALGO, &kp.private_key, &enc.ciphertext).unwrap();
|
||||
assert_eq!(*ss, enc.shared_secret);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn oqs_ciphertext_opens_in_rustcrypto() {
|
||||
let (oqs, rc) = (OqsProvider::new(), RustCryptoProvider::new());
|
||||
let kp = rc.generate_keypair(ALGO).unwrap();
|
||||
let enc = oqs.encapsulate(ALGO, &kp.public_key).unwrap();
|
||||
let ss = rc.decapsulate(ALGO, &kp.private_key, &enc.ciphertext).unwrap();
|
||||
assert_eq!(*ss, enc.shared_secret);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn both_reject_a_tampered_ciphertext_alike() {
|
||||
let (oqs, rc) = (OqsProvider::new(), RustCryptoProvider::new());
|
||||
let kp = rc.generate_keypair(ALGO).unwrap();
|
||||
let enc = rc.encapsulate(ALGO, &kp.public_key).unwrap();
|
||||
let mut ct = enc.ciphertext.clone();
|
||||
ct[7] ^= 0x10;
|
||||
let a = oqs.decapsulate(ALGO, &kp.private_key, &ct).unwrap();
|
||||
let b = rc.decapsulate(ALGO, &kp.private_key, &ct).unwrap();
|
||||
// Implicit rejection is deterministic, so both derive the same secret.
|
||||
assert_ne!(*a, enc.shared_secret);
|
||||
assert_eq!(*a, *b);
|
||||
}
|
||||
Loading…
Reference in New Issue