1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
use rand_core::{ RngCore, CryptoRng }; use ::params::{ SYMBYTES, PUBLICKEYBYTES, SECRETKEYBYTES, CIPHERTEXTBYTES, }; use ::kem; pub mod uake { use ::params::{ UAKE_SENDABYTES, UAKE_SENDBBYTES }; use super::*; pub fn init_a<R: RngCore + CryptoRng>( rng: &mut R, send: &mut [u8; UAKE_SENDABYTES], tk: &mut [u8; SYMBYTES], sk: &mut [u8; SECRETKEYBYTES], pkb: &[u8; PUBLICKEYBYTES] ) { kem::keypair(rng, array_mut_ref!(send, 0, PUBLICKEYBYTES), sk); kem::enc(rng, array_mut_ref!(send, PUBLICKEYBYTES, CIPHERTEXTBYTES), tk, pkb); } pub fn shared_b<R: RngCore + CryptoRng>( rng: &mut R, send: &mut [u8; UAKE_SENDBBYTES], k: &mut [u8; SYMBYTES], recv: &[u8; UAKE_SENDABYTES], skb: &[u8; SECRETKEYBYTES] ) { let mut buf = [0; SYMBYTES]; let mut buf2 = [0; SYMBYTES]; kem::enc(rng, send, &mut buf, array_ref!(recv, 0, PUBLICKEYBYTES)); kem::dec(&mut buf2, array_ref!(recv, PUBLICKEYBYTES, CIPHERTEXTBYTES), skb); shake256!(k; &buf, &buf2); } pub fn shared_a( k: &mut [u8; SYMBYTES], recv: &[u8; UAKE_SENDBBYTES], tk: &[u8; SYMBYTES], sk: &[u8; SECRETKEYBYTES] ) { let mut buf = [0; SYMBYTES]; kem::dec(&mut buf, recv, sk); shake256!(k; &buf, &tk[..SYMBYTES]); } } pub mod ake { use ::params::{ AKE_SENDABYTES, AKE_SENDBBYTES }; use super::*; pub fn init_a<R: RngCore + CryptoRng>( rng: &mut R, send: &mut [u8; AKE_SENDABYTES], tk: &mut [u8; SYMBYTES], sk: &mut [u8; SECRETKEYBYTES], pkb: &[u8; PUBLICKEYBYTES] ) { kem::keypair(rng, array_mut_ref!(send, 0, PUBLICKEYBYTES), sk); kem::enc(rng, array_mut_ref!(send, PUBLICKEYBYTES, CIPHERTEXTBYTES), tk, pkb); } pub fn shared_b<R: RngCore + CryptoRng>( rng: &mut R, send: &mut [u8; AKE_SENDBBYTES], k: &mut [u8; SYMBYTES], recv: &[u8; AKE_SENDABYTES], skb: &[u8; SECRETKEYBYTES], pka: &[u8; PUBLICKEYBYTES] ) { let mut buf = [0; SYMBYTES]; let mut buf2 = [0; SYMBYTES]; let mut buf3 = [0; SYMBYTES]; kem::enc(rng, array_mut_ref!(send, 0, CIPHERTEXTBYTES), &mut buf, array_ref!(recv, 0, PUBLICKEYBYTES)); kem::enc(rng, array_mut_ref!(send, CIPHERTEXTBYTES, CIPHERTEXTBYTES), &mut buf2, pka); kem::dec(&mut buf3, array_ref!(recv, PUBLICKEYBYTES, CIPHERTEXTBYTES), skb); shake256!(k; &buf, &buf2, &buf3); } pub fn shared_a( k: &mut [u8; SYMBYTES], recv: &[u8; AKE_SENDBBYTES], tk: &[u8; SYMBYTES], sk: &[u8; SECRETKEYBYTES], ska: &[u8; SECRETKEYBYTES] ) { let mut buf = [0; SYMBYTES]; let mut buf2 = [0; SYMBYTES]; kem::dec(&mut buf, array_ref!(recv, 0, CIPHERTEXTBYTES), sk); kem::dec(&mut buf2, array_ref!(recv, CIPHERTEXTBYTES, CIPHERTEXTBYTES), ska); shake256!(k; &buf, &buf2, tk); } }