tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

tests.rs (1377B)


      1 // Copyright 2023 Cryspen Sarl
      2 //
      3 // Licensed under the Apache License, Version 2.0 (the "License");
      4 // you may not use this file except in compliance with the License.
      5 // You may obtain a copy of the License at
      6 //
      7 //     http://www.apache.org/licenses/LICENSE-2.0
      8 
      9 pub fn simple<
     10    const EK_LEN: usize,
     11    const DK_LEN: usize,
     12    const CT_LEN: usize,
     13    const SS_LEN: usize,
     14    const RAND_KEYGEN_LEN: usize,
     15    const RAND_ENCAPS_LEN: usize,
     16    Kem: super::arrayref::Kem<EK_LEN, DK_LEN, CT_LEN, SS_LEN, RAND_KEYGEN_LEN, RAND_ENCAPS_LEN>,
     17 >() {
     18    let alice_keygen_rand = [1; RAND_KEYGEN_LEN];
     19    let bob_keygen_rand = [2; RAND_KEYGEN_LEN];
     20 
     21    let mut alice_dk = [0; DK_LEN];
     22    let mut alice_ek = [0; EK_LEN];
     23 
     24    let mut bob_dk = [0; DK_LEN];
     25    let mut bob_ek = [0; EK_LEN];
     26 
     27    Kem::keygen(&mut alice_ek, &mut alice_dk, &alice_keygen_rand)
     28        .expect("error generating alice's key pair");
     29    Kem::keygen(&mut bob_ek, &mut bob_dk, &bob_keygen_rand)
     30        .expect("error generating bob's key pair");
     31 
     32    let mut ct = [0; CT_LEN];
     33    let mut ss_alice = [0; SS_LEN];
     34    let rand_encaps = [3; RAND_ENCAPS_LEN];
     35 
     36    Kem::encaps(&mut ct, &mut ss_alice, &bob_ek, &rand_encaps).expect("error encapsulating");
     37 
     38    let mut ss_bob = [0; SS_LEN];
     39 
     40    Kem::decaps(&mut ss_bob, &ct, &bob_dk).expect("error decapsulating");
     41 
     42    assert_eq!(ss_alice, ss_bob)
     43 }