// NOTE: Think about gaming this function independent of authenticate_start
Think about gaming this function independent of authenticate_start
Think about gaming this function independent of authenticate_start
pub fn authenticate_finalize(username: &str, ke_3: &Vec<u8>, x: &[u8; 32]) {
    println!("=> Rusty Authenticate Finalize");
    println!("Key 3: {:?}:", ke_3);
    println!("X: {:?}:", x);
    let x_point = CompressedRistretto::from_slice(&x[..]);
    let x = x_point.decompress().unwrap();
    let user_record: UserRecord =
        USER_MAP.lock().unwrap().get(username).unwrap().clone();
    let ke_2: RistrettoPoint = RISTRETTO_BASEPOINT_POINT * user_record.k_u;
    let dh: RistrettoPoint = user_record.k_u * x;
    let hkdf = Hkdf::<Sha512>::new(None, dh.compress().as_bytes());
    let mut okm_dh = [0u8; 108]; // 32 byte key, 96 bit nonce, 64 bytes
    let info = hex::decode("f0f1f2f3f4f5f6f7f8f9").unwrap();
    hkdf.expand(&info, &mut okm_dh).unwrap();
    println!("-) HKDF OKM {}", hex::encode(&okm_dh[..]));
    let encryption_key_dh: GenericArray<u8, typenum::U32> =
        GenericArray::clone_from_slice(&okm_dh[0..32]);
    let aead_dh = Aes256GcmSiv::new(encryption_key_dh);
    let nonce_dh: GenericArray<u8, typenum::U12> =
        GenericArray::clone_from_slice(&okm_dh[32..44]);
    println!("Encryption Key DH: {:?}", encryption_key_dh);
    println!("Nonce DH: {:?}", nonce_dh);
    println!("KE 3 Slice: {:?}", ke_3.as_slice());
    println!("Key 3 Size: {}", ke_3.capacity());
    let key_3_decrypted = aead_dh
        .decrypt(&nonce_dh, ke_3.as_slice())
        .expect("decryption failure, authorization failed");
    let key_3_for_realz: KeyExchange =
        bincode::deserialize(key_3_decrypted.as_slice()).unwrap();
    let pub_u = PublicKey::from_bytes(&key_3_for_realz.identity).unwrap();
    let mut prehashed: Sha3_512 = Sha3_512::new();
    prehashed.input(ke_2.compress().as_bytes());
    prehashed.input(x.compress().as_bytes());
    let context: &[u8] = b"SpecificCustomerDomainName";
    let signature: Signature =
        Signature::from_bytes(&key_3_for_realz.signature).unwrap();
    let verified = pub_u.verify_prehashed::<Sha3_512>(
        prehashed,
        Some(context),
        &signature,
    );
    // check Mac on A
    println!("=) {:?}", verified.unwrap());
    println!("=) Signature Verified KE3 -- {} logged in.", username);
}
pub fn authenticate_finalize ( username : & str , ke_3 : & Vec < u8 > , x : & [ u8 ; 32 ] ) { println ! ( " " ) ; println ! ( " " ke_3 ) ; println ! ( " " x ) ; let x_point = CompressedRistretto :: from_slice ( & x [ .. ] ) ; let x = x_point . decompress ( ) . unwrap ( ) ; let user_record : UserRecord = USER_MAP . lock ( ) . unwrap ( ) . get ( username ) . unwrap ( ) . clone ( ) ; let ke_2 : RistrettoPoint = RISTRETTO_BASEPOINT_POINT * user_record . k_u ; let dh : RistrettoPoint = user_record . k_u * x ; let hkdf = Hkdf :: < Sha512 > :: new ( None , dh . compress ( ) . as_bytes ( ) ) ; let mut okm_dh = [ 0u8 ; 108 ] ; // 32 byte key, 96 bit nonce, 64 bytes let info = hex :: decode ( " " ) . unwrap ( ) ; hkdf . expand ( & info , & mut okm_dh ) . unwrap ( ) ; println ! ( " " hex encode ( okm_dh [ ] ) ) ; let encryption_key_dh : GenericArray < u8 , typenum :: U32 > = GenericArray :: clone_from_slice ( & okm_dh [ 0 .. 32 ] ) ; let aead_dh = Aes256GcmSiv :: new ( encryption_key_dh ) ; let nonce_dh : GenericArray < u8 , typenum :: U12 > = GenericArray :: clone_from_slice ( & okm_dh [ 32 .. 44 ] ) ; println ! ( " " encryption_key_dh ) ; println ! ( " " nonce_dh ) ; println ! ( " " ke_3 as_slice ( ) ) ; println ! ( " " ke_3 capacity ( ) ) ; let key_3_decrypted = aead_dh . decrypt ( & nonce_dh , ke_3 . as_slice ( ) ) . expect ( " " ) ; let key_3_for_realz : KeyExchange = bincode :: deserialize ( key_3_decrypted . as_slice ( ) ) . unwrap ( ) ; let pub_u = PublicKey :: from_bytes ( & key_3_for_realz . identity ) . unwrap ( ) ; let mut prehashed : Sha3_512 = Sha3_512 :: new ( ) ; prehashed . input ( ke_2 . compress ( ) . as_bytes ( ) ) ; prehashed . input ( x . compress ( ) . as_bytes ( ) ) ; let context : & [ u8 ] = b" " ; let signature : Signature = Signature :: from_bytes ( & key_3_for_realz . signature ) . unwrap ( ) ; let verified = pub_u . verify_prehashed :: < Sha3_512 > ( prehashed , Some ( context ) , & signature , ) ; // check Mac on A println ! ( " " verified unwrap ( ) ) ; println ! ( " " username ) ; }
NOTE: Think about gaming this function independent of authenticate_start
NOTE : Think about gaming this function independent of authenticate_start
username
&str
ke_3
&Vec<u8>
x
&[u8; 32]