Repository: novifinancial/opaque-ke
Pull request #128 (2021-02-01 01:42:44)

Applying envelope simplified construction and km3 mac changes
Incorporates two changes:
1) The suggested change here: https://github.com/cfrg/draft-irtf-cfrg-opaque/pull/126
2) Ensures that the mac generated by Km3 in 3DH covers the Km2 mac.

This requires a change to the test vectors.


Patch:
diff --git a/src/envelope.rs b/src/envelope.rs
index b0f9c8c..addeea1 100644
--- a/src/envelope.rs
+++ b/src/envelope.rs
@@ -16,7 +16,6 @@ use rand_core::{CryptoRng, RngCore};
 use std::convert::TryFrom;
 
 // Constant string used as salt for HKDF computation
-const STR_RWDU: &[u8] = b"rwdU";
 const STR_PAD: &[u8] = b"Pad";
 const STR_AUTH_KEY: &[u8] = b"AuthKey";
 const STR_EXPORT_KEY: &[u8] = b"ExportKey";
@@ -191,23 +190,17 @@ impl<D: Hash> Envelope<D> {
         let mut nonce = vec![0u8; NONCE_LEN];
         rng.fill_bytes(&mut nonce);
 
-        let h = Hkdf::<D>::new(Some(STR_RWDU), &key);
+        let h = Hkdf::<D>::new(Some(&nonce), &key);
         let mut xor_key = vec![0u8; plaintext.len()];
         let mut hmac_key = vec![0u8; Self::hmac_key_size()];
         let mut export_key = vec![0u8; Self::export_key_size()];
 
-        h.expand(&[nonce.clone(), STR_PAD.to_vec()].concat(), &mut xor_key)
+        h.expand(STR_PAD, &mut xor_key)
+            .map_err(|_| InternalPakeError::HkdfError)?;
+        h.expand(STR_AUTH_KEY, &mut hmac_key)
+            .map_err(|_| InternalPakeError::HkdfError)?;
+        h.expand(STR_EXPORT_KEY, &mut export_key)
             .map_err(|_| InternalPakeError::HkdfError)?;
-        h.expand(
-            &[nonce.clone(), STR_AUTH_KEY.to_vec()].concat(),
-            &mut hmac_key,
-        )
-        .map_err(|_| InternalPakeError::HkdfError)?;
-        h.expand(
-            &[nonce.clone(), STR_EXPORT_KEY.to_vec()].concat(),
-            &mut export_key,
-        )
-        .map_err(|_| InternalPakeError::HkdfError)?;
 
         let ciphertext: Vec<u8> = xor_key
             .iter()
@@ -271,26 +264,17 @@ impl<D: Hash> Envelope<D> {
         key: &[u8],
         aad: &[u8],
     ) -> Result<OpenedInnerEnvelope<D>, InternalPakeError> {
-        let h = Hkdf::<D>::new(Some(STR_RWDU), &key);
+        let h = Hkdf::<D>::new(Some(&self.inner_envelope.nonce), &key);
         let mut xor_key = vec![0u8; self.inner_envelope.ciphertext.len()];
         let mut hmac_key = vec![0u8; Self::hmac_key_size()];
         let mut export_key = vec![0u8; Self::export_key_size()];
 
-        h.expand(
-            &[self.inner_envelope.nonce.clone(), STR_PAD.to_vec()].concat(),
-            &mut xor_key,
-        )
-        .map_err(|_| InternalPakeError::HkdfError)?;
-        h.expand(
-            &[self.inner_envelope.nonce.clone(), STR_AUTH_KEY.to_vec()].concat(),
-            &mut hmac_key,
-        )
-        .map_err(|_| InternalPakeError::HkdfError)?;
-        h.expand(
-            &[self.inner_envelope.nonce.clone(), STR_EXPORT_KEY.to_vec()].concat(),
-            &mut export_key,
-        )
-        .map_err(|_| InternalPakeError::HkdfError)?;
+        h.expand(STR_PAD, &mut xor_key)
+            .map_err(|_| InternalPakeError::HkdfError)?;
+        h.expand(STR_AUTH_KEY, &mut hmac_key)
+            .map_err(|_| InternalPakeError::HkdfError)?;
+        h.expand(STR_EXPORT_KEY, &mut export_key)
+            .map_err(|_| InternalPakeError::HkdfError)?;
 
         let mut hmac =
             Hmac::<D>::new_varkey(&hmac_key).map_err(|_| InternalPakeError::HmacError)?;
diff --git a/src/key_exchange/tripledh.rs b/src/key_exchange/tripledh.rs
index 8900a63..61606b2 100644
--- a/src/key_exchange/tripledh.rs
+++ b/src/key_exchange/tripledh.rs
@@ -34,7 +34,7 @@ static STR_3DH: &[u8] = b"3DH keys";
 static STR_CLIENT_MAC: &[u8] = b"client mac";
 static STR_HANDSHAKE_SECRET: &[u8] = b"handshake secret";
 static STR_SERVER_MAC: &[u8] = b"server mac";
-static STR_SERVER_ENC: &[u8] = b"server enc";
+static STR_SERVER_ENC: &[u8] = b"handshake enc";
 static STR_ENCRYPTION_PAD: &[u8] = b"encryption pad";
 static STR_SESSION_SECRET: &[u8] = b"session secret";
 static STR_OPAQUE: &[u8] = b"OPAQUE ";
@@ -140,6 +140,7 @@ impl<D: Hash, G: Group> KeyExchange<D, G> for TripleDH {
 
         let mut hasher3 = D::new();
         hasher3.update(&transcript2);
+        hasher3.update(&mac);
         let hashed_transcript = hasher3.finalize();
 
         Ok((
@@ -207,7 +208,7 @@ impl<D: Hash, G: Group> KeyExchange<D, G> for TripleDH {
 
         let mut hasher2 = D::new();
         hasher2.update(transcript);
-        // hasher2.update(ke2_message.mac.to_vec()); // FIXME, sync with @caw on including this
+        hasher2.update(ke2_message.mac.to_vec());
         let hashed_transcript = hasher2.finalize();
 
         let mut client_mac =
diff --git a/src/opaque.rs b/src/opaque.rs
index b21e4ea..885fa16 100644
--- a/src/opaque.rs
+++ b/src/opaque.rs
@@ -27,7 +27,7 @@ use rand_core::{CryptoRng, RngCore};
 use std::{convert::TryFrom, marker::PhantomData};
 use zeroize::Zeroize;
 
-static STR_OPAQUE_VERSION: &[u8] = b"OPAQUE01";
+static STR_OPAQUE_VERSION: &[u8] = b"OPAQUE";
 
 // Registration
 // ============


Test patch:
diff --git a/src/tests/full_test.rs b/src/tests/full_test.rs
index 533ed97..261cb20 100644
--- a/src/tests/full_test.rs
+++ b/src/tests/full_test.rs
@@ -68,37 +68,37 @@ pub struct TestVectorParameters {
 
 static TEST_VECTOR: &str = r#"
 {
-    "client_s_pk": "ba8c7e239ed64ea1e6068b52cbd5a34ba6f55d635d20a4593884dc271865ea63",
-    "client_s_sk": "edb5e886441ddcd4fdd80593d9ea7b7f82f284fcc1d565b802e99997457b960a",
-    "client_e_pk": "08973113b27d6f2291aaaeb92f34a8438d279a48b1b412bddbf2785be660e479",
-    "client_e_sk": "28fb3aadbc2716844d8de562d35e61914da734dcea0fa6ebd79603ef9eff4e01",
-    "server_s_pk": "b67d948b98eecfb516a626fab94170e490ccd90da05fce94a016c4d5d6b7136a",
-    "server_s_sk": "52350a684c353e39bbaadeb042b2de94226a493f6ae172b7fc45408bbfda6401",
-    "server_e_pk": "42103d44b03f3886fe3e419b1b96521fa5a706bb1a4e003907daa381960d664a",
-    "server_e_sk": "564e113d5b2784fcf3a55d5ca48512a2fd5c3c393753f6cfd157cb712b317c04",
+    "client_s_pk": "3a776afc0ba554a731cc8e2c8fef1ba3e9110195a7902d9b15ecc1352867833e",
+    "client_s_sk": "bd42afe22725696df96e193ff4d0580e565ad8b769ea718f343245ea83625505",
+    "client_e_pk": "c22c46082bae3fcb2e5690c0c9a27fa59f752ff9a78ad5c41a18f7f665a3da05",
+    "client_e_sk": "21616ff86563a235ab01eb7e13f057b1cae8533dc7a4e99076e56d29f948c40b",
+    "server_s_pk": "d685d935664b0f8175456c9594cb3205329352970a560a4efedb5bfb39335811",
+    "server_s_sk": "5e37d39ed0c5880c748818b834d97fd8235f4b77a7e06287664c02e5bafd6407",
+    "server_e_pk": "0202a269a71da47901e071eab4702d92288e9e3ac12b77cc9eae1a6a3be5bf25",
+    "server_e_sk": "055453a054b87b50c8e9f2ae4eac6e56348ec82b3e3271d843a958b0f634ed0b",
     "id_u": "696455",
     "id_s": "696453",
     "password": "70617373776f7264",
-    "blinding_factor": "a70b37951d84ed312a0a8e025b71eafdd362b4e7db872881762d506a271b6e07",
-    "oprf_key": "1eaf3cdd64da67e17e3364182f00ed0c323bfb44b20a1b7e0025a0334ab6d40d",
-    "envelope_nonce": "5dba53e994e82b6d76353341102791cdfb1c2b460e1f913c5741a9c8cf2017c9",
-    "client_nonce": "488244dbf75f86ebaa30307773d3e0eabccb91be349abef8a69c458dbf236e4c",
-    "server_nonce": "13cc5ceb7687d80293005e7f9452ce104d1bac6598dd2265f184cacd558d6b31",
+    "blinding_factor": "67c5f74c953923c950c978b332f306454a8dc7ae7888449281b9d550ab05e204",
+    "oprf_key": "94ddb3f439fb4d69ac31b3220604066316b370b4402403d04f9efece28d6a00f",
+    "envelope_nonce": "c2956142808696bc993b1b1424166afcf0e7de8ba45d8348cd5ff0fbbf528485",
+    "client_nonce": "b61c639342a00e60652c0567423bc332fc7af6558da4651bd53b89f688fc1274",
+    "server_nonce": "ebb9dcbbfe8776aa3831763a4172f6e95cec5714d08a0e0a03151f561135c416",
     "info1": "696e666f31",
     "einfo2": "65696e666f32",
-    "registration_request": "ecf819ef83351e4c75e016ef845b62a12c14f397328960574935a42e04e0fa42",
-    "registration_response": "2e9bf80e5c101ee2d391ff2aec06af97af17f443fc93a5cc98189681cb943d700020b67d948b98eecfb516a626fab94170e490ccd90da05fce94a016c4d5d6b7136a",
-    "registration_upload": "0020ba8c7e239ed64ea1e6068b52cbd5a34ba6f55d635d20a4593884dc271865ea63015dba53e994e82b6d76353341102791cdfb1c2b460e1f913c5741a9c8cf2017c90022f11b89b207eb0735f2bdb2a9968bc9d7c1c962fd0274b4fc1fff2466c769d3710586a3a21ac8ecf13aafe2dc5460eb2f52d8f760396a17beeaf1ef3d1e4e50dd906555832fc51fc474554cb9ff063f6685f9043efc08fd6816666833d68d3b0eb6d9",
-    "credential_request": "ecf819ef83351e4c75e016ef845b62a12c14f397328960574935a42e04e0fa42488244dbf75f86ebaa30307773d3e0eabccb91be349abef8a69c458dbf236e4c0005696e666f3108973113b27d6f2291aaaeb92f34a8438d279a48b1b412bddbf2785be660e479",
-    "credential_response": "2e9bf80e5c101ee2d391ff2aec06af97af17f443fc93a5cc98189681cb943d700020b67d948b98eecfb516a626fab94170e490ccd90da05fce94a016c4d5d6b7136a015dba53e994e82b6d76353341102791cdfb1c2b460e1f913c5741a9c8cf2017c90022f11b89b207eb0735f2bdb2a9968bc9d7c1c962fd0274b4fc1fff2466c769d3710586a3a21ac8ecf13aafe2dc5460eb2f52d8f760396a17beeaf1ef3d1e4e50dd906555832fc51fc474554cb9ff063f6685f9043efc08fd6816666833d68d3b0eb6d913cc5ceb7687d80293005e7f9452ce104d1bac6598dd2265f184cacd558d6b3142103d44b03f3886fe3e419b1b96521fa5a706bb1a4e003907daa381960d664a0006a0f4de671e13c37b24e29138ff9d3df3d55c3b822fedee8dcefd643a1deab7cda5aa1c20f31a0c2a1823c8de3e793f50b257833788b75609fb6c5c4a9cad225f3a981c4ff7b2",
-    "credential_finalization": "0640114ec21fbad6da11c61dfa77a48026646a2a1bd091ef5c9dc46b45f9e53c72f5d714e026d808b6de8911947eef437e9f6a6e969e1ea13f2f4880adc7c879",
-    "client_registration_state": "a70b37951d84ed312a0a8e025b71eafdd362b4e7db872881762d506a271b6e0770617373776f7264",
-    "client_login_state": "a70b37951d84ed312a0a8e025b71eafdd362b4e7db872881762d506a271b6e070067ecf819ef83351e4c75e016ef845b62a12c14f397328960574935a42e04e0fa42488244dbf75f86ebaa30307773d3e0eabccb91be349abef8a69c458dbf236e4c0005696e666f3108973113b27d6f2291aaaeb92f34a8438d279a48b1b412bddbf2785be660e479004028fb3aadbc2716844d8de562d35e61914da734dcea0fa6ebd79603ef9eff4e01488244dbf75f86ebaa30307773d3e0eabccb91be349abef8a69c458dbf236e4c70617373776f7264",
-    "server_registration_state": "1eaf3cdd64da67e17e3364182f00ed0c323bfb44b20a1b7e0025a0334ab6d40d",
-    "server_login_state": "4952acf61167e6d0e799572827724fdf8c80bda8c62ac28deb68d125661dade2cc1136e634d5fb93f1de4d170ae3e2f5885e333ac3b72d630ab56618c2247fa4d5968eefd69cd270ed14fbcb39627fea9a93cd18175e1b5cfceb06f705bbcb5ecddcd0602aacd7cb358f3273b1099895210bf8baa37d2fab5ed8c092fe9e5739bc6c50cf08ca7d4f4107d48057507480e0c9534b4f04d77cd5156cbd112565d8a2d5beaa473003dcf8dd82d4046648a701c72afeed0f627fcb782627dfaed3ca",
-    "password_file": "1eaf3cdd64da67e17e3364182f00ed0c323bfb44b20a1b7e0025a0334ab6d40dba8c7e239ed64ea1e6068b52cbd5a34ba6f55d635d20a4593884dc271865ea63015dba53e994e82b6d76353341102791cdfb1c2b460e1f913c5741a9c8cf2017c90022f11b89b207eb0735f2bdb2a9968bc9d7c1c962fd0274b4fc1fff2466c769d3710586a3a21ac8ecf13aafe2dc5460eb2f52d8f760396a17beeaf1ef3d1e4e50dd906555832fc51fc474554cb9ff063f6685f9043efc08fd6816666833d68d3b0eb6d9",
-    "export_key": "2b86667de895e4d2c15b93bc70f0aa2df67b83987fa53deac9473697e2fade045e0fd0e4af478ccff52165c1467272993da34dcb3baa45aa59cf9d817e6c6bcb",
-    "shared_secret": "bc6c50cf08ca7d4f4107d48057507480e0c9534b4f04d77cd5156cbd112565d8a2d5beaa473003dcf8dd82d4046648a701c72afeed0f627fcb782627dfaed3ca"
+    "registration_request": "5ea0a0a57a2882691c3fc8e0dfe09bf05b130723b24371f8ac03b9c75d0d5b79",
+    "registration_response": "c0ebf6cc43f92c2da075f93da39cb37d7571e61c26bfab69bbcdb35a0a313e260020d685d935664b0f8175456c9594cb3205329352970a560a4efedb5bfb39335811",
+    "registration_upload": "00203a776afc0ba554a731cc8e2c8fef1ba3e9110195a7902d9b15ecc1352867833e01c2956142808696bc993b1b1424166afcf0e7de8ba45d8348cd5ff0fbbf52848500223b28798f911bb2f0c6cc626f27daf055271234dc1c1e32df59e864cffe946dfb02795cc53d6bcadf5e9535341c473f72b7ea88f4ff87fe941c0dace9f9975fa8887ac0bb7c84a5028fcdd10b41f9216523ba3513c95eb127437155feb0c022469334",
+    "credential_request": "5ea0a0a57a2882691c3fc8e0dfe09bf05b130723b24371f8ac03b9c75d0d5b79b61c639342a00e60652c0567423bc332fc7af6558da4651bd53b89f688fc12740005696e666f31c22c46082bae3fcb2e5690c0c9a27fa59f752ff9a78ad5c41a18f7f665a3da05",
+    "credential_response": "c0ebf6cc43f92c2da075f93da39cb37d7571e61c26bfab69bbcdb35a0a313e260020d685d935664b0f8175456c9594cb3205329352970a560a4efedb5bfb3933581101c2956142808696bc993b1b1424166afcf0e7de8ba45d8348cd5ff0fbbf52848500223b28798f911bb2f0c6cc626f27daf055271234dc1c1e32df59e864cffe946dfb02795cc53d6bcadf5e9535341c473f72b7ea88f4ff87fe941c0dace9f9975fa8887ac0bb7c84a5028fcdd10b41f9216523ba3513c95eb127437155feb0c022469334ebb9dcbbfe8776aa3831763a4172f6e95cec5714d08a0e0a03151f561135c4160202a269a71da47901e071eab4702d92288e9e3ac12b77cc9eae1a6a3be5bf250006148cc6985fd9c04245efa02487d25a5e4ffa64fdb7f7fd627839ca70f29da495e59489891e14b7122656edcf2bfc788f92bf458fac31d4b0ddd6b6aa764e08c56d16e803e919",
+    "credential_finalization": "c6c0ccf4e5155b2cecabc61efc289824e00eb2e5d3c15d508100d35d8f0d3ba317797270af96cd4610b954ec21898f2e9df02411c21352a3220259034c711487",
+    "client_registration_state": "67c5f74c953923c950c978b332f306454a8dc7ae7888449281b9d550ab05e20470617373776f7264",
+    "client_login_state": "67c5f74c953923c950c978b332f306454a8dc7ae7888449281b9d550ab05e20400675ea0a0a57a2882691c3fc8e0dfe09bf05b130723b24371f8ac03b9c75d0d5b79b61c639342a00e60652c0567423bc332fc7af6558da4651bd53b89f688fc12740005696e666f31c22c46082bae3fcb2e5690c0c9a27fa59f752ff9a78ad5c41a18f7f665a3da05004021616ff86563a235ab01eb7e13f057b1cae8533dc7a4e99076e56d29f948c40bb61c639342a00e60652c0567423bc332fc7af6558da4651bd53b89f688fc127470617373776f7264",
+    "server_registration_state": "94ddb3f439fb4d69ac31b3220604066316b370b4402403d04f9efece28d6a00f",
+    "server_login_state": "fa7795f9a3a3f93e950d4d902689157f98cdf839fe64847b9b24dc2c7d07e9d674cdcb3db4c7653dcf133c49eadbf2b3a0665e19c37461352a8bdce781cefd5d8c8153b0b60a3abbb9cc2a34fe3c53541b1e7df3216d3bac1e8280fa697db9ee6b2468e585f9912bd227c51b702671691b6d6a3542db4597c18013fbae903b5c9d5ff920b8a7231d717155af4475b3591973245b9dd26cf956383e8145fa3e8c1e508b72f3e3c42e3d116611b676780628591acf37757c74ad297f71a0b54b39",
+    "password_file": "94ddb3f439fb4d69ac31b3220604066316b370b4402403d04f9efece28d6a00f3a776afc0ba554a731cc8e2c8fef1ba3e9110195a7902d9b15ecc1352867833e01c2956142808696bc993b1b1424166afcf0e7de8ba45d8348cd5ff0fbbf52848500223b28798f911bb2f0c6cc626f27daf055271234dc1c1e32df59e864cffe946dfb02795cc53d6bcadf5e9535341c473f72b7ea88f4ff87fe941c0dace9f9975fa8887ac0bb7c84a5028fcdd10b41f9216523ba3513c95eb127437155feb0c022469334",
+    "export_key": "c250b23ac69b71bcc246db97398487198c94c73c84e1256b57c3ceb32a76fdc7547a8953bfc94b530e5b660f559faa53572f98ec0168e378087017b9a7393f57",
+    "shared_secret": "9d5ff920b8a7231d717155af4475b3591973245b9dd26cf956383e8145fa3e8c1e508b72f3e3c42e3d116611b676780628591acf37757c74ad297f71a0b54b39"
 }
 "#;
 
diff --git a/src/tests/opaque_test_vectors.rs b/src/tests/opaque_test_vectors.rs
index c5454f0..56a97d4 100644
--- a/src/tests/opaque_test_vectors.rs
+++ b/src/tests/opaque_test_vectors.rs
@@ -8,7 +8,6 @@ use crate::{
     slow_hash::NoOpHash, tests::mock_rng::CycleRng, *,
 };
 use curve25519_dalek::ristretto::RistrettoPoint;
-use rand_core::OsRng;
 use serde_json::Value;
 use std::convert::TryFrom;
 
@@ -23,83 +22,238 @@ impl CipherSuite for Ristretto255Sha512NoSlowHash {
     type SlowHash = NoOpHash;
 }
 
+#[derive(PartialEq)]
+pub enum EnvelopeMode {
+    Base,
+    CustomIdentifier,
+}
+
+#[allow(non_snake_case)]
 pub struct TestVectorParameters {
-    pub client_s_pk: Vec<u8>,
-    pub client_s_sk: Vec<u8>,
-    pub client_e_pk: Vec<u8>,
-    pub client_e_sk: Vec<u8>,
-    pub server_s_pk: Vec<u8>,
-    pub server_s_sk: Vec<u8>,
-    pub server_e_pk: Vec<u8>,
-    pub server_e_sk: Vec<u8>,
-    pub client_identifier: Vec<u8>,
-    pub server_identifier: Vec<u8>,
+    pub envelope_mode: EnvelopeMode,
+    pub client_public_key: Vec<u8>,
+    pub client_private_key: Vec<u8>,
+    pub client_keyshare: Vec<u8>,
+    pub client_private_keyshare: Vec<u8>,
+    pub server_public_key: Vec<u8>,
+    pub server_private_key: Vec<u8>,
+    pub server_keyshare: Vec<u8>,
+    pub server_private_keyshare: Vec<u8>,
+    pub client_identity: Vec<u8>,
+    pub server_identity: Vec<u8>,
     pub password: Vec<u8>,
-    pub blinding_factor_registration: Vec<u8>,
+    pub blind_registration: Vec<u8>,
     pub oprf_key: Vec<u8>,
     pub envelope_nonce: Vec<u8>,
     pub client_nonce: Vec<u8>,
     pub server_nonce: Vec<u8>,
-    pub info1: Vec<u8>,
-    pub info2: Vec<u8>,
+    pub client_info: Vec<u8>,
+    pub server_info: Vec<u8>,
     pub registration_request: Vec<u8>,
     pub registration_response: Vec<u8>,
     pub registration_upload: Vec<u8>,
-    pub credential_request: Vec<u8>,
-    pub blinding_factor_login: Vec<u8>,
-    pub credential_response: Vec<u8>,
-    pub credential_finalization: Vec<u8>,
-    pub password_file: Vec<u8>,
+    pub KE1: Vec<u8>,
+    pub blind_login: Vec<u8>,
+    pub KE2: Vec<u8>,
+    pub KE3: Vec<u8>,
     pub export_key: Vec<u8>,
-    pub shared_secret: Vec<u8>,
+    pub session_key: Vec<u8>,
 }
 
-static TEST_VECTOR: &str = r#"
-{
-    "auth_key": "5da3dcc6721e638fa4eef769f7af5bd30f7132308d41fff00f0cf9745e9090235f75697a0dc58fe8692204c4702a20db4a6ee59119fe6ab4173322f06b896309",
-    "blinding_factor_login": "ed8366feb6b1d05d1f46acb727061e43aadfafe9c10e5a64e7518d63e3263503",
-    "blinding_factor_registration": "c604c785ada70d77a5256ae21767de8c3304115237d262134f5e46e512cf8e03",
-    "client_e_pk": "645a5d8c715454a2ba77918d44234d9cbbd723d03113b68c9ea076ab4e776067",
-    "client_e_sk": "9be30157b01e572d9ee296defd7bd2f98fed15fbbf3cbed847547d6759c73c08",
-    "client_identifier": "0aa0f9643e2ecaf3075201e9e762371d1b5cdfac674494b2d5ed0b0908c46e5b",
-    "client_nonce": "a9f275415d9bee6b86c2c390b7577c7684d70479c7e23bfbc01652a7464fb1cc",
-    "client_s_pk": "0aa0f9643e2ecaf3075201e9e762371d1b5cdfac674494b2d5ed0b0908c46e5b",
-    "client_s_sk": "8772da7da9af3fcdae2a23cf8a34a49954a56b48ae2f866b71113132664f0e09",
-    "credential_finalization": "b8de4c989e5caefb57f5a506fd469c4e329aa3076d17a8c8648266c2c2db6f4c33be2161c11c63b7039459de0f9f7f9c5b6a429e6002ac03516ba3979fc970f7",
-    "credential_request": "b68e0e356f8490fa9c3bed952e16cc02db21eda686b3c484f3d9d912caa41f76a9f275415d9bee6b86c2c390b7577c7684d70479c7e23bfbc01652a7464fb1cc000968656c6c6f20626f62645a5d8c715454a2ba77918d44234d9cbbd723d03113b68c9ea076ab4e776067",
-    "credential_response": "e83812f06568d57b8cdfdcc90fe91454e21bd25dd2a1c32dd1599a2e4a4b6c35002008a499182bb67b86190e2d8315ca1ae4a6cdd503db50bed3d90cc7670dcb9f2b0090f17bbbfeaf88def8713679002f4825d936a5347afdf4d020a99167843056d60022147e90c0c40a3652bdef905ab2f61386a4119a121f3411c1da6463ac5d0c633c6e6eaf0eb0d45ab8afb746ccd00a1e96cbb2eca09cdc61520772b32978470dcdb0f8aaec7016681d431f194a447bea2c0be84c7191837e362f0f69b7f29676e15d0351c529e997a215d410ef6f387a2f1e708729d2316bf27b75138fb440020c1fcdbcae720a4acd4a44602024a9d6f2d536baf230f8301c9f9ff5113e229549fd05000f3b629da91fc6405e82b16c18ae4be1ff00020b37dfa8dbd7eeea4bef1c678693b2f1e2da0370e6792f5ab860fad7a098f0d5d00d4d4205aae4d70887fb28edc16f5f1268aa021dba8810909cb2f9e6",
-    "envU": "0090f17bbbfeaf88def8713679002f4825d936a5347afdf4d020a99167843056d60022147e90c0c40a3652bdef905ab2f61386a4119a121f3411c1da6463ac5d0c633c6e6eaf0eb0d45ab8afb746ccd00a1e96cbb2eca09cdc61520772b32978470dcdb0f8aaec7016681d431f194a447bea2c0be84c7191837e362f0f69b7f29676e15d03",
-    "envelope_nonce": "90f17bbbfeaf88def8713679002f4825d936a5347afdf4d020a99167843056d6",
-    "export_key": "453f61eae9b840519eb025d2297eb31ad13c960deba40c2799d2cd4b5034161e1c13695877b460643386ed5e41d5ec9bf2bc845592469fab50abf77d4812fcf0",
-    "handshake_secret": "67b75ff7291d68e20bdbc6a15209aba0c61b7b690d69f293db3761ad62f6014476daeb8ce1235e2d29404bdba3b843dbd544250751e51af747010bb25c310fd5",
-    "info1": "68656c6c6f20626f62",
-    "info2": "6772656574696e677320616c696365",
-    "ke2": "44feeac8078ca91e22ac0133fe33890207c3d927ace293fffa66296c74e82e09ffb1ac00f76198e0ebe74eab722ac49173bdee616f32b3a7416ddee1d8075d54",
-    "km2": "0d5b3bd8e1f6b937570b501d5647cb061276bba36cfc3213205c36d2240e8fe55f2338108f52947fd589ce344ce0a677ddb178c881deb4d075874ade133b99c7",
-    "km3": "8ed3a633ad925fedcf19f9f4acca15f8bfbd147ba11e0950a2ae6c3efb6e41aef75faa20ae0f9104801bdb8a4edbd23a5cc19fe626a00c50e4718d8dedb180fd",
-    "oprf_key": "5ed895206bfc53316d307b23e46ecc6623afb3086da74189a416012be037e50b",
-    "password": "436f7272656374486f72736542617474657279537461706c65",
-    "pseudorandom_pad": "145e17b21e779ffd82223e70913999b20088ceb7747cbfee5c0f12bd6c3e05736067",
-    "registration_request": "241b621c417c0705b5ea7a8b7cdd5039fd61e6b63effe2a44418164c4d49003e",
-    "registration_response": "1867301bcc67bdf8e640b7d6edcbe2a65488446417b50d30cdba66ccb379e572002008a499182bb67b86190e2d8315ca1ae4a6cdd503db50bed3d90cc7670dcb9f2b",
-    "registration_upload": "00200aa0f9643e2ecaf3075201e9e762371d1b5cdfac674494b2d5ed0b0908c46e5b0090f17bbbfeaf88def8713679002f4825d936a5347afdf4d020a99167843056d60022147e90c0c40a3652bdef905ab2f61386a4119a121f3411c1da6463ac5d0c633c6e6eaf0eb0d45ab8afb746ccd00a1e96cbb2eca09cdc61520772b32978470dcdb0f8aaec7016681d431f194a447bea2c0be84c7191837e362f0f69b7f29676e15d03",
-    "rwdU": "17eacc90e168aafd6cf5cbf4aba71e6c08d16800e4880a3fcc5252a1b5072ab7253942f3b4da8a2132863730970ca7a737b5bec96e038a8fa2915b4eeb678180",
-    "server_e_pk": "bcae720a4acd4a44602024a9d6f2d536baf230f8301c9f9ff5113e229549fd05",
-    "server_e_sk": "c02a638f90e8a9fd25b69252ec7465b7dd33aa905ba947c013b6e6be6edf3909",
-    "server_identifier": "08a499182bb67b86190e2d8315ca1ae4a6cdd503db50bed3d90cc7670dcb9f2b",
-    "server_nonce": "51c529e997a215d410ef6f387a2f1e708729d2316bf27b75138fb440020c1fcd",
-    "server_s_pk": "08a499182bb67b86190e2d8315ca1ae4a6cdd503db50bed3d90cc7670dcb9f2b",
-    "server_s_sk": "852b5300434b5f39f7885ee812255747793e04846b910cf9ae80a5a904bd3a03",
-    "shared_secret": "d0336451e8de1df9a648772c86f97a1b9ed860297f0fafa13faa4e23bb44b9355ec196a25ba39e7db5b9102a06fa09ca778b10aee5acb11f4eb5826b1370e98c",
-    "password_file": "5ed895206bfc53316d307b23e46ecc6623afb3086da74189a416012be037e50b0aa0f9643e2ecaf3075201e9e762371d1b5cdfac674494b2d5ed0b0908c46e5b0090f17bbbfeaf88def8713679002f4825d936a5347afdf4d020a99167843056d60022147e90c0c40a3652bdef905ab2f61386a4119a121f3411c1da6463ac5d0c633c6e6eaf0eb0d45ab8afb746ccd00a1e96cbb2eca09cdc61520772b32978470dcdb0f8aaec7016681d431f194a447bea2c0be84c7191837e362f0f69b7f29676e15d03"
-}
-"#;
-
-fn decode(values: &Value, key: &str) -> Option<Vec<u8>> {
-    values[key]
-        .as_str()
-        .and_then(|s| hex::decode(&s.to_string()).ok())
-}
+static TEST_VECTORS: &[&str] = &[
+    r#"
+Group: ristretto255
+EnvelopeMode: 00
+OPRF: 0001
+SlowHash: Identity
+Hash: SHA512
+server_nonce: 534a8d6ca099313c73f909ecadd9973644203036913b162134def00
+fdf8b8a18
+oprf_key: 5ed895206bfc53316d307b23e46ecc6623afb3086da74189a416012be03
+7e50b
+password: 436f7272656374486f72736542617474657279537461706c65
+blind_login: ed8366feb6b1d05d1f46acb727061e43aadfafe9c10e5a64e7518d63
+e3263503
+server_private_keyshare: bfd25bddcd9190db01fdc127247eb2461d78281233d8
+77b4564a00404cb79700
+client_nonce: 1a7c15f8ca50bb7a8d654035ad59488a33758b80fc1cc1fa7cc4d92
+50c00f567
+server_info: 6772656574696e677320616c696365
+client_info: 68656c6c6f20626f62
+client_private_keyshare: 1d6078acf052615f1e3206b9aa9aed95cb0f04daa534
+0ccb52534871f1158f09
+envelope_nonce: ff05735be871d25c4fa25f2a65e26386fad3eda2ba1e093562844
+1ed18bbe818
+server_keyshare: dcc991d13fa137302cc1adce95e6f9087f503d88e12d90200682
+2e6da438ec22
+blind_registration: c604c785ada70d77a5256ae21767de8c3304115237d262134
+f5e46e512cf8e03
+client_public_key: fcca4fd8732b9887f566bbdcdb738c884f5390b360f43b5b3a
+4b81b3bb7e060d
+client_private_key: 31aca12a23a2a03db43c91fafe6d32589e2d8f09d8004d605
+0ec275317cc7f08
+client_keyshare: 408c2a2025080d6507b6250f3dc1ac420c37134bf14d7b1be542
+c4d8cfd64a52
+server_public_key: 76ba3df8660de4e37dd3ac120bb3f8c9a4d95931b54cf14856
+974424a8561115
+server_private_key: ccde5849510d7175da028ccccba666e446b9418cf7ba9383b
+9530c75474bcb04
+auth_key: c0ee18ecc5ae7012bcf641a28c2d21ebc198492f1d75ed7ee7cc60b6c5f
+c2a6e5f0ad974fc8f0f48dacfcac765d2b626fce0728f3abbee16d522fe2fa108270c
+server_mac_key: 18685231e1442f5547af5f9c965fc6a951428a963f26ef99cea69
+53873296df81b71e89c05d9bd4abf6863a1e3215f3fe4a202e33f7164c90d250d00a8
+dd4a91
+envelope: 00ff05735be871d25c4fa25f2a65e26386fad3eda2ba1e0935628441ed1
+8bbe81800228f595ba5f6cf5b9c590bc270cbdc1b46b570b76db941ff14035630294f
+b8c42ae21c6d965b5ee07b9a86687941dc9594b3f0c92317b367fd19d168b810d7b08
+787319d837367607662e9d545c5e5abecc469e544903a570e2efdb168bbb8603d11c8
+prk: ec754de047f914e9adf78a82925d70f90478c0e74ea4124de5ba92e8bd935691
+641b6a6ad00ad7d101d232c11fdbe1a578d4795bc62e73fb7e42d6ef234bf2e1
+client_mac_key: 1b73e32b32aad3e94a8bfd664532c9cf8c3385d8ec62badd59873
+270e02f854436b68ade26d0efa0c6b4b41e4970d950d6e7a5ca292427952730105bba
+f89896
+pseudorandom_pad: 8f796a0957e5783ef936764c5a26e52b87282940364827144e3
+660c568ebd3e69d14
+handshake_encrypt_key: 26eea148eeaad14bba63d6d30cac46ddb1d37971f6fe1d
+dfc80955271f4d242c0db5824d5df69b3a6f619753733a26640d20e35b8589c6b7448
+df7d902155ed4
+handshake_secret: 46c0c3d90c38b9cf3a0c3f19248adef96365e059a4a0034b4b2
+d36efda24174620e0894bcb0916dcaa79cdb1a7f475e9b809c0f4a072c8bf4b6b4735
+87838641
+registration_response: 1867301bcc67bdf8e640b7d6edcbe2a65488446417b50d
+30cdba66ccb379e572002076ba3df8660de4e37dd3ac120bb3f8c9a4d95931b54cf14
+856974424a8561115
+export_key: 39a81bd85c701bcb4396d7d6fad5a67712aff40a4a7d806094f84dbbb
+56bf371d8b9b522abba314dc5203cf387c4be187128e3270b151023221c9fc86fff11
+4a
+registration_upload: 0020fcca4fd8732b9887f566bbdcdb738c884f5390b360f4
+3b5b3a4b81b3bb7e060d00ff05735be871d25c4fa25f2a65e26386fad3eda2ba1e093
+5628441ed18bbe81800228f595ba5f6cf5b9c590bc270cbdc1b46b570b76db941ff14
+035630294fb8c42ae21c6d965b5ee07b9a86687941dc9594b3f0c92317b367fd19d16
+8b810d7b08787319d837367607662e9d545c5e5abecc469e544903a570e2efdb168bb
+b8603d11c8
+registration_request: 241b621c417c0705b5ea7a8b7cdd5039fd61e6b63effe2a
+44418164c4d49003e
+session_key: f27806d4c588eac72b3da00dba21a2852cf3a91d5164d9ac4dcfa896
+a3cbbb2836785a33ba9d5fb193068347b0ed20bcde94a4482e4456d9c5666eb6191de
+a47
+KE3: bf680d0471ffd1885f050b51c3e57b59e4b3ec31c49dd893644028f30e4bca44
+6cf2f047abd75f739bffccac0af3fe24b8255d3391c4899608df9539f97b5c91
+KE2: e83812f06568d57b8cdfdcc90fe91454e21bd25dd2a1c32dd1599a2e4a4b6c35
+002076ba3df8660de4e37dd3ac120bb3f8c9a4d95931b54cf14856974424a85611150
+0ff05735be871d25c4fa25f2a65e26386fad3eda2ba1e0935628441ed18bbe8180022
+8f595ba5f6cf5b9c590bc270cbdc1b46b570b76db941ff14035630294fb8c42ae21c6
+d965b5ee07b9a86687941dc9594b3f0c92317b367fd19d168b810d7b08787319d8373
+67607662e9d545c5e5abecc469e544903a570e2efdb168bbb8603d11c8534a8d6ca09
+9313c73f909ecadd9973644203036913b162134def00fdf8b8a18dcc991d13fa13730
+2cc1adce95e6f9087f503d88e12d902006822e6da438ec22000f1e4413f30f38967bd
+8c1f3a65da5f825ec34bf0c56f7c50117388593922db7bf53b1f451f6623df88c355a
+a7fb7f9464e00c14683bbab1386ee43e59952a44b73af76d7659a81b219270f2543de
+fc1
+KE1: b68e0e356f8490fa9c3bed952e16cc02db21eda686b3c484f3d9d912caa41f76
+1a7c15f8ca50bb7a8d654035ad59488a33758b80fc1cc1fa7cc4d9250c00f56700096
+8656c6c6f20626f62408c2a2025080d6507b6250f3dc1ac420c37134bf14d7b1be542
+c4d8cfd64a52
+"#,
+    r#"
+Group: ristretto255
+EnvelopeMode: 01
+OPRF: 0001
+SlowHash: Identity
+Hash: SHA512
+server_nonce: be1b6a9ee06b76c648efd2e57300cae3418a2137ee3abcfa018431e
+e50876be4
+oprf_key: 89c61a42c8191a5ca41f2fe959843d333bcf43173b7de4c5c119e0e0d8b
+0e707
+password: 436f7272656374486f72736542617474657279537461706c65
+blind_login: e6d0f1d89ad552e383d6c6f4e8598cc3037d6e274d22da3089e7afbd
+4171ea02
+server_private_keyshare: 79450906dc147d9b73edf5c98f7d1970ebcc825c474c
+ecddc671f3290038c205
+client_nonce: 79a442d9fbebbd244e27fd10ea255dcec9f43e9b2c6a33575eb3377
+5b081d77e
+server_info: 6772656574696e677320616c696365
+server_identity: 76ba3df8660de4e37dd3ac120bb3f8c9a4d95931b54cf1485697
+4424a8561115
+client_info: 68656c6c6f20626f62
+client_private_keyshare: 46124f54f47fec6b66c53e4154475d27a0e046c5d1c8
+54b2f3680defdff14a0e
+envelope_nonce: f627cf8e027b5fca94ba970dc06866b79d5914abb16526835bbbd
+6c46d705cf2
+server_public_key: 76ba3df8660de4e37dd3ac120bb3f8c9a4d95931b54cf14856
+974424a8561115
+client_identity: fcca4fd8732b9887f566bbdcdb738c884f5390b360f43b5b3a4b
+81b3bb7e060d
+blind_registration: 019cbd1d7420292528f8cdd62f339fdabb602f04a95dac9db
+cec831b8c681a09
+client_public_key: fcca4fd8732b9887f566bbdcdb738c884f5390b360f43b5b3a
+4b81b3bb7e060d
+client_private_key: 31aca12a23a2a03db43c91fafe6d32589e2d8f09d8004d605
+0ec275317cc7f08
+client_keyshare: 5a7396b6e6e0dbb1690ba3b69061ba864fda0c2c078520f01804
+ef15c0b25d56
+server_keyshare: ea25f0b5ed03ec29b5eaacf21dde7d4c1fcb4e34ddb2d7c6e4a7
+1b6d10e3d870
+server_private_key: ccde5849510d7175da028ccccba666e446b9418cf7ba9383b
+9530c75474bcb04
+auth_key: 3f5312f1c60350f5c46ab368434035f5740eef83a6d5cbc7ed3720fb78a
+c32a5ea9fc734296efc9167350492903c449d85ac774b05f37efcc3ea0bcd9c600f55
+server_mac_key: 341d064d83d7415f28f9528771f10d768891ac552409d44ee7324
+8eed0ed4b58f48ac7406fe8c7fce9cb13029bc30d4e2bc48711fe5932b499a55cb7c1
+85ce1b
+envelope: 01f627cf8e027b5fca94ba970dc06866b79d5914abb16526835bbbd6c46
+d705cf20022ceffb2fded3ff3dfd323ef4411cc213014316463bdd6692907cd4caffd
+885530d0d9ceb917641b2550623727461b647b81b1e81ae67fcb0f57ad93175306ff3
+26b1ec66433a67ed4da46f1cb54c80c24cf805f3df77a2b81c7f5fda0bcb06f093fa9
+prk: 8923bf6277c4593732d3cdfaa559f531acd20e5cbec5bc180ddf6795d7a4d7ab
+a39404eed4f94adcf25c84d6e8764fb9bb943db894ac9655fed08b68097de0f9
+client_mac_key: 37ffae79ea8bd0b83884ca45e65ce63d4a4210a39d8c158e8772b
+31fa96a9e174b6badeb15454a14ac46ce4f758a1c9fe1748b7b598c7cb6c7431dbac4
+448b45
+pseudorandom_pad: cedf83514c15d07d731e5b788036df5d2669fa4e32dfb1294aa
+d1c43dadb42fcafd1
+handshake_encrypt_key: 7eec22c81178c6f91176961bc78ccb8a9459f9a54c565b
+f44ab8d2445074bd994672f02e8d7a9974722acfca87a56ffbed3d4092d4ef5e8941c
+5b117227e07d9
+handshake_secret: cc5ce99088b2459ed11e6664e479c19d285878dc0961c47e741
+221029f9ca3df00b2cd35b643a263a872e49de7f6bb95d68cb5793d36087b1d6a0b3c
+7565f3c8
+registration_response: 088ac01ebf5700f0c96bc2988509343cb7e2dd6f0df820
+d0fb807faa11a26f56002076ba3df8660de4e37dd3ac120bb3f8c9a4d95931b54cf14
+856974424a8561115
+export_key: 38b7c0fc66819d9cd51e0e0051d87e159c2be9829f3e2c2ad42560b12
+b7b7950588be9bf8db36bfd9fe26ff55a57e42a5345ee1fa9734f78c8e4e427ede4ee
+9e
+registration_upload: 0020fcca4fd8732b9887f566bbdcdb738c884f5390b360f4
+3b5b3a4b81b3bb7e060d01f627cf8e027b5fca94ba970dc06866b79d5914abb165268
+35bbbd6c46d705cf20022ceffb2fded3ff3dfd323ef4411cc213014316463bdd66929
+07cd4caffd885530d0d9ceb917641b2550623727461b647b81b1e81ae67fcb0f57ad9
+3175306ff326b1ec66433a67ed4da46f1cb54c80c24cf805f3df77a2b81c7f5fda0bc
+b06f093fa9
+registration_request: c8d2e9ba503bf3f8821226653314427edb1ec8a3ecc94a5
+dfbbe33d59d07b645
+session_key: db9fa3c0bec6ce623b1b124b843c5b8a8d79f93247396eed72e8c06a
+dba2d5389692f988d65e3adb0d59ed477e37fab31633daa514780522ada541eb354d7
+d49
+KE3: 3e2538f0a28344ba9db33e55270e1db37fedde130e13b088bad31239e3bbf358
+7922f8039e205e842f2a012f8db39cb66994b9970363d24f128b882b2b696724
+KE2: 5079b16709b195b3b63257b419efb752bd0603170160fa72b828ce9ff9209c0c
+002076ba3df8660de4e37dd3ac120bb3f8c9a4d95931b54cf14856974424a85611150
+1f627cf8e027b5fca94ba970dc06866b79d5914abb16526835bbbd6c46d705cf20022
+ceffb2fded3ff3dfd323ef4411cc213014316463bdd6692907cd4caffd885530d0d9c
+eb917641b2550623727461b647b81b1e81ae67fcb0f57ad93175306ff326b1ec66433
+a67ed4da46f1cb54c80c24cf805f3df77a2b81c7f5fda0bcb06f093fa9be1b6a9ee06
+b76c648efd2e57300cae3418a2137ee3abcfa018431ee50876be4ea25f0b5ed03ec29
+b5eaacf21dde7d4c1fcb4e34ddb2d7c6e4a71b6d10e3d870000f853360d8962c60208
+1c1a7f11e0ab10b045d752511f9254a95e390e72b9c60f073c85bf789649883a1c712
+6b1150e6db4607ac5491833b25f91211ab4e7fc292912562f1397c15e6e91a4972b00
+052
+KE1: 7024ca0d5423176294fbb9ca968d8ce3fc879a231f1ceef69e672c89e02ded59
+79a442d9fbebbd244e27fd10ea255dcec9f43e9b2c6a33575eb33775b081d77e00096
+8656c6c6f20626f625a7396b6e6e0dbb1690ba3b69061ba864fda0c2c078520f01804
+ef15c0b25d56
+"#,
+];
 
 macro_rules! parse {
     ( $v:ident, $s:expr ) => {
@@ -110,321 +264,311 @@ macro_rules! parse {
     };
 }
 
+macro_rules! rfc_to_params {
+    ( $v:ident ) => {
+        $v.iter()
+            .map(|x| populate_test_vectors(&serde_json::from_str(rfc_to_json(x).as_str()).unwrap()))
+            .collect::<Vec<TestVectorParameters>>()
+    };
+}
+
+fn rfc_to_json(input: &str) -> String {
+    let mut json = vec![];
+    for line in input.lines() {
+        // If line contains colon, then
+        if line.contains(":") {
+            if json.len() > 0 {
+                // Adding closing quote for previous line, comma, and newline
+                json.push("\",\n".to_string());
+            }
+
+            let mut iter = line.split(":");
+            let key = iter.next().unwrap().split_whitespace().next().unwrap();
+            let val = iter.next().unwrap().split_whitespace().next().unwrap();
+
+            json.push(format!("    \"{}\": \"{}", key, val));
+        } else {
+            let s = line.trim().to_string();
+            if s.len() > 0 {
+                json.push(s);
+            }
+        }
+    }
+
+    format!("{{\n{}\"\n}}", json.join(""))
+}
+
+fn decode(values: &Value, key: &str) -> Option<Vec<u8>> {
+    values[key]
+        .as_str()
+        .and_then(|s| hex::decode(&s.to_string()).ok())
+}
+
 fn populate_test_vectors(values: &Value) -> TestVectorParameters {
     TestVectorParameters {
-        client_s_pk: parse!(values, "client_s_pk"),
-        client_s_sk: parse!(values, "client_s_sk"),
-        client_e_pk: parse!(values, "client_e_pk"),
-        client_e_sk: parse!(values, "client_e_sk"),
-        server_s_pk: parse!(values, "server_s_pk"),
-        server_s_sk: parse!(values, "server_s_sk"),
-        server_e_pk: parse!(values, "server_e_pk"),
-        server_e_sk: parse!(values, "server_e_sk"),
-        client_identifier: parse!(values, "client_identifier"),
-        server_identifier: parse!(values, "server_identifier"),
+        envelope_mode: match values["EnvelopeMode"].as_str() {
+            Some("00") => EnvelopeMode::Base,
+            Some("01") => EnvelopeMode::CustomIdentifier,
+            _ => panic!("Could not match envelope mode"),
+        },
+        client_public_key: parse!(values, "client_public_key"),
+        client_private_key: parse!(values, "client_private_key"),
+        client_keyshare: parse!(values, "client_keyshare"),
+        client_private_keyshare: parse!(values, "client_private_keyshare"),
+        server_public_key: parse!(values, "server_public_key"),
+        server_private_key: parse!(values, "server_private_key"),
+        server_keyshare: parse!(values, "server_keyshare"),
+        server_private_keyshare: parse!(values, "server_private_keyshare"),
+        client_identity: parse!(values, "client_identity"),
+        server_identity: parse!(values, "server_identity"),
         password: parse!(values, "password"),
-        blinding_factor_registration: parse!(values, "blinding_factor_registration"),
+        blind_registration: parse!(values, "blind_registration"),
         oprf_key: parse!(values, "oprf_key"),
         envelope_nonce: parse!(values, "envelope_nonce"),
         client_nonce: parse!(values, "client_nonce"),
         server_nonce: parse!(values, "server_nonce"),
-        info1: parse!(values, "info1"),
-        info2: parse!(values, "info2"),
+        client_info: parse!(values, "client_info"),
+        server_info: parse!(values, "server_info"),
         registration_request: parse!(values, "registration_request"),
         registration_response: parse!(values, "registration_response"),
         registration_upload: parse!(values, "registration_upload"),
-        credential_request: parse!(values, "credential_request"),
-        credential_response: parse!(values, "credential_response"),
-        credential_finalization: parse!(values, "credential_finalization"),
-        blinding_factor_login: parse!(values, "blinding_factor_login"),
-        password_file: parse!(values, "password_file"),
+        KE1: parse!(values, "KE1"),
+        KE2: parse!(values, "KE2"),
+        KE3: parse!(values, "KE3"),
+        blind_login: parse!(values, "blind_login"),
         export_key: parse!(values, "export_key"),
-        shared_secret: parse!(values, "shared_secret"),
+        session_key: parse!(values, "session_key"),
     }
 }
 
-#[test]
-fn test_registration_request() -> Result<(), ProtocolError> {
-    let parameters = populate_test_vectors(&serde_json::from_str(TEST_VECTOR).unwrap());
-    let mut rng = CycleRng::new(parameters.blinding_factor_registration.to_vec());
-    let client_registration_start_result =
-        ClientRegistration::<Ristretto255Sha512NoSlowHash>::start(&mut rng, &parameters.password)?;
-    assert_eq!(
-        hex::encode(&parameters.registration_request),
-        hex::encode(client_registration_start_result.message.serialize())
-    );
-    Ok(())
-}
-
-#[test]
-fn test_registration_response() -> Result<(), ProtocolError> {
-    let parameters = populate_test_vectors(&serde_json::from_str(TEST_VECTOR).unwrap());
-    let mut oprf_key_rng = CycleRng::new(parameters.oprf_key);
+fn get_password_file_bytes(parameters: &TestVectorParameters) -> Result<Vec<u8>, ProtocolError> {
+    let mut oprf_key_rng = CycleRng::new(parameters.oprf_key.clone());
     let server_registration_start_result =
         ServerRegistration::<Ristretto255Sha512NoSlowHash>::start(
             &mut oprf_key_rng,
             RegistrationRequest::deserialize(&parameters.registration_request[..]).unwrap(),
-            &Key::try_from(&parameters.server_s_pk[..]).unwrap(),
+            &Key::try_from(&parameters.server_public_key[..]).unwrap(),
         )?;
-    assert_eq!(
-        hex::encode(parameters.registration_response),
-        hex::encode(server_registration_start_result.message.serialize())
-    );
-    Ok(())
-}
 
-#[test]
-fn test_registration_upload() -> Result<(), ProtocolError> {
-    let parameters = populate_test_vectors(&serde_json::from_str(TEST_VECTOR).unwrap());
-
-    let mut rng = CycleRng::new(parameters.blinding_factor_registration.to_vec());
-    let client_registration_start_result =
-        ClientRegistration::<Ristretto255Sha512NoSlowHash>::start(&mut rng, &parameters.password)?;
-
-    let sk_u_and_nonce: Vec<u8> = [parameters.client_s_sk, parameters.envelope_nonce].concat();
-    let mut finish_registration_rng = CycleRng::new(sk_u_and_nonce);
-    let result = client_registration_start_result.state.finish(
-        &mut finish_registration_rng,
-        RegistrationResponse::deserialize(&parameters.registration_response[..]).unwrap(),
-        ClientRegistrationFinishParameters::default(),
-    )?;
-
-    assert_eq!(
-        hex::encode(parameters.registration_upload),
-        hex::encode(result.message.serialize())
-    );
-    assert_eq!(
-        hex::encode(parameters.export_key),
-        hex::encode(result.export_key.to_vec())
-    );
+    let password_file = server_registration_start_result
+        .state
+        .finish(RegistrationUpload::deserialize(&parameters.registration_upload[..]).unwrap())?;
 
-    Ok(())
+    Ok(password_file.to_bytes())
 }
 
 #[test]
-fn test_password_file() -> Result<(), ProtocolError> {
-    let parameters = populate_test_vectors(&serde_json::from_str(TEST_VECTOR).unwrap());
-
-    let mut oprf_key_rng = CycleRng::new(parameters.oprf_key);
-    let server_registration_start_result =
-        ServerRegistration::<Ristretto255Sha512NoSlowHash>::start(
-            &mut oprf_key_rng,
-            RegistrationRequest::deserialize(&parameters.registration_request[..]).unwrap(),
-            &Key::try_from(&parameters.server_s_pk[..]).unwrap(),
-        )?;
-
-    let password_file = server_registration_start_result
-        .state
-        .finish(RegistrationUpload::deserialize(&parameters.registration_upload[..]).unwrap())?;
-    assert_eq!(
-        hex::encode(parameters.password_file),
-        hex::encode(password_file.to_bytes())
-    );
+fn test_registration_request() -> Result<(), ProtocolError> {
+    for parameters in rfc_to_params!(TEST_VECTORS) {
+        let mut rng = CycleRng::new(parameters.blind_registration.to_vec());
+        let client_registration_start_result =
+            ClientRegistration::<Ristretto255Sha512NoSlowHash>::start(
+                &mut rng,
+                &parameters.password,
+            )?;
+        assert_eq!(
+            hex::encode(&parameters.registration_request),
+            hex::encode(client_registration_start_result.message.serialize())
+        );
+    }
     Ok(())
 }
 
 #[test]
-fn test_credential_request() -> Result<(), ProtocolError> {
-    let parameters = populate_test_vectors(&serde_json::from_str(TEST_VECTOR).unwrap());
-
-    let client_login_start = [
-        parameters.blinding_factor_login,
-        parameters.client_e_sk,
-        parameters.client_nonce,
-    ]
-    .concat();
-    let mut client_login_start_rng = CycleRng::new(client_login_start);
-    let client_login_start_result = ClientLogin::<Ristretto255Sha512NoSlowHash>::start(
-        &mut client_login_start_rng,
-        &parameters.password,
-        ClientLoginStartParameters::WithInfo(parameters.info1),
-    )?;
-    assert_eq!(
-        hex::encode(&parameters.credential_request),
-        hex::encode(client_login_start_result.message.serialize())
-    );
+fn test_registration_response() -> Result<(), ProtocolError> {
+    for parameters in rfc_to_params!(TEST_VECTORS) {
+        let mut oprf_key_rng = CycleRng::new(parameters.oprf_key);
+        let server_registration_start_result =
+            ServerRegistration::<Ristretto255Sha512NoSlowHash>::start(
+                &mut oprf_key_rng,
+                RegistrationRequest::deserialize(&parameters.registration_request[..]).unwrap(),
+                &Key::try_from(&parameters.server_public_key[..]).unwrap(),
+            )?;
+        assert_eq!(
+            hex::encode(parameters.registration_response),
+            hex::encode(server_registration_start_result.message.serialize())
+        );
+    }
     Ok(())
 }
 
 #[test]
-fn test_credential_response() -> Result<(), ProtocolError> {
-    let parameters = populate_test_vectors(&serde_json::from_str(TEST_VECTOR).unwrap());
-
-    let mut server_e_sk_and_nonce_rng =
-        CycleRng::new([parameters.server_e_sk, parameters.server_nonce].concat());
-    let server_login_start_result = ServerLogin::<Ristretto255Sha512NoSlowHash>::start(
-        &mut server_e_sk_and_nonce_rng,
-        ServerRegistration::try_from(&parameters.password_file[..]).unwrap(),
-        &Key::try_from(&parameters.server_s_sk[..]).unwrap(),
-        CredentialRequest::<Ristretto255Sha512NoSlowHash>::deserialize(
-            &parameters.credential_request[..],
-        )
-        .unwrap(),
-        ServerLoginStartParameters::WithInfo(parameters.info2.to_vec()),
-    )?;
-    assert_eq!(
-        hex::encode(&parameters.info1),
-        hex::encode(server_login_start_result.plain_info),
-    );
-    assert_eq!(
-        hex::encode(&parameters.credential_response),
-        hex::encode(server_login_start_result.message.serialize())
-    );
+fn test_registration_upload() -> Result<(), ProtocolError> {
+    for parameters in rfc_to_params!(TEST_VECTORS) {
+        let mut rng = CycleRng::new(parameters.blind_registration.to_vec());
+        let client_registration_start_result =
+            ClientRegistration::<Ristretto255Sha512NoSlowHash>::start(
+                &mut rng,
+                &parameters.password,
+            )?;
+
+        let sk_u_and_nonce: Vec<u8> =
+            [parameters.client_private_key, parameters.envelope_nonce].concat();
+        let mut finish_registration_rng = CycleRng::new(sk_u_and_nonce);
+        let result = client_registration_start_result.state.finish(
+            &mut finish_registration_rng,
+            RegistrationResponse::deserialize(&parameters.registration_response[..]).unwrap(),
+            if parameters.envelope_mode == EnvelopeMode::CustomIdentifier {
+                ClientRegistrationFinishParameters::WithIdentifiers(
+                    parameters.client_identity,
+                    parameters.server_identity,
+                )
+            } else {
+                ClientRegistrationFinishParameters::default()
+            },
+        )?;
+
+        assert_eq!(
+            hex::encode(parameters.registration_upload),
+            hex::encode(result.message.serialize())
+        );
+        assert_eq!(
+            hex::encode(parameters.export_key),
+            hex::encode(result.export_key.to_vec())
+        );
+    }
+
     Ok(())
 }
 
 #[test]
-fn test_credential_finalization() -> Result<(), ProtocolError> {
-    let parameters = populate_test_vectors(&serde_json::from_str(TEST_VECTOR).unwrap());
-
-    let client_login_start = [
-        parameters.blinding_factor_login,
-        parameters.client_e_sk,
-        parameters.client_nonce,
-    ]
-    .concat();
-    let mut client_login_start_rng = CycleRng::new(client_login_start);
-    let client_login_start_result = ClientLogin::<Ristretto255Sha512NoSlowHash>::start(
-        &mut client_login_start_rng,
-        &parameters.password,
-        ClientLoginStartParameters::WithInfo(parameters.info1),
-    )?;
-
-    let client_login_finish_result = client_login_start_result.state.finish(
-        CredentialResponse::<Ristretto255Sha512NoSlowHash>::deserialize(
-            &parameters.credential_response[..],
-        )?,
-        ClientLoginFinishParameters::default(),
-    )?;
-
-    assert_eq!(
-        hex::encode(&parameters.info2),
-        hex::encode(&client_login_finish_result.confidential_info)
-    );
-    assert_eq!(
-        hex::encode(&parameters.shared_secret),
-        hex::encode(&client_login_finish_result.shared_secret)
-    );
-    assert_eq!(
-        hex::encode(&parameters.credential_finalization),
-        hex::encode(client_login_finish_result.message.to_bytes())
-    );
-    assert_eq!(
-        hex::encode(&parameters.export_key),
-        hex::encode(client_login_finish_result.export_key)
-    );
+fn test_ke1() -> Result<(), ProtocolError> {
+    for parameters in rfc_to_params!(TEST_VECTORS) {
+        let client_login_start = [
+            parameters.blind_login,
+            parameters.client_private_keyshare,
+            parameters.client_nonce,
+        ]
+        .concat();
+        let mut client_login_start_rng = CycleRng::new(client_login_start);
+        let client_login_start_result = ClientLogin::<Ristretto255Sha512NoSlowHash>::start(
+            &mut client_login_start_rng,
+            &parameters.password,
+            ClientLoginStartParameters::WithInfo(parameters.client_info),
+        )?;
+        assert_eq!(
+            hex::encode(&parameters.KE1),
+            hex::encode(client_login_start_result.message.serialize())
+        );
+    }
     Ok(())
 }
 
 #[test]
-fn test_server_login_finish() -> Result<(), ProtocolError> {
-    let parameters = populate_test_vectors(&serde_json::from_str(TEST_VECTOR).unwrap());
-
-    let mut server_e_sk_and_nonce_rng =
-        CycleRng::new([parameters.server_e_sk, parameters.server_nonce].concat());
-    let server_login_start_result = ServerLogin::<Ristretto255Sha512NoSlowHash>::start(
-        &mut server_e_sk_and_nonce_rng,
-        ServerRegistration::try_from(&parameters.password_file[..]).unwrap(),
-        &Key::try_from(&parameters.server_s_sk[..]).unwrap(),
-        CredentialRequest::<Ristretto255Sha512NoSlowHash>::deserialize(
-            &parameters.credential_request[..],
-        )
-        .unwrap(),
-        ServerLoginStartParameters::WithInfo(parameters.info2.to_vec()),
-    )?;
-
-    let server_login_result =
-        server_login_start_result
-            .state
-            .finish(CredentialFinalization::try_from(
-                &parameters.credential_finalization[..],
-            )?)?;
-
-    assert_eq!(
-        hex::encode(parameters.shared_secret),
-        hex::encode(server_login_result.shared_secret)
-    );
-
+fn test_ke2() -> Result<(), ProtocolError> {
+    for parameters in rfc_to_params!(TEST_VECTORS) {
+        let password_file_bytes = get_password_file_bytes(&parameters)?;
+
+        let mut server_private_keyshare_and_nonce_rng =
+            CycleRng::new([parameters.server_private_keyshare, parameters.server_nonce].concat());
+        let server_login_start_result = ServerLogin::<Ristretto255Sha512NoSlowHash>::start(
+            &mut server_private_keyshare_and_nonce_rng,
+            ServerRegistration::try_from(&password_file_bytes[..]).unwrap(),
+            &Key::try_from(&parameters.server_private_key[..]).unwrap(),
+            CredentialRequest::<Ristretto255Sha512NoSlowHash>::deserialize(&parameters.KE1[..])
+                .unwrap(),
+            if parameters.envelope_mode == EnvelopeMode::CustomIdentifier {
+                ServerLoginStartParameters::WithInfoAndIdentifiers(
+                    parameters.server_info.to_vec(),
+                    parameters.client_identity,
+                    parameters.server_identity,
+                )
+            } else {
+                ServerLoginStartParameters::WithInfo(parameters.server_info.to_vec())
+            },
+        )?;
+        assert_eq!(
+            hex::encode(&parameters.client_info),
+            hex::encode(server_login_start_result.plain_info),
+        );
+        assert_eq!(
+            hex::encode(&parameters.KE2),
+            hex::encode(server_login_start_result.message.serialize())
+        );
+    }
     Ok(())
 }
 
-fn test_complete_flow(
-    registration_password: &[u8],
-    login_password: &[u8],
-) -> Result<(), ProtocolError> {
-    let mut client_rng = OsRng;
-    let mut server_rng = OsRng;
-    let server_kp = Ristretto255Sha512NoSlowHash::generate_random_keypair(&mut server_rng);
-    let client_registration_start_result =
-        ClientRegistration::<Ristretto255Sha512NoSlowHash>::start(
-            &mut client_rng,
-            registration_password,
+#[test]
+fn test_ke3() -> Result<(), ProtocolError> {
+    for parameters in rfc_to_params!(TEST_VECTORS) {
+        let client_login_start = [
+            parameters.blind_login,
+            parameters.client_private_keyshare,
+            parameters.client_nonce,
+        ]
+        .concat();
+        let mut client_login_start_rng = CycleRng::new(client_login_start);
+        let client_login_start_result = ClientLogin::<Ristretto255Sha512NoSlowHash>::start(
+            &mut client_login_start_rng,
+            &parameters.password,
+            ClientLoginStartParameters::WithInfo(parameters.client_info),
         )?;
-    let server_registration_start_result =
-        ServerRegistration::<Ristretto255Sha512NoSlowHash>::start(
-            &mut server_rng,
-            client_registration_start_result.message,
-            server_kp.public(),
+
+        let client_login_finish_result = client_login_start_result.state.finish(
+            CredentialResponse::<Ristretto255Sha512NoSlowHash>::deserialize(&parameters.KE2[..])?,
+            if parameters.envelope_mode == EnvelopeMode::CustomIdentifier {
+                ClientLoginFinishParameters::WithIdentifiers(
+                    parameters.client_identity,
+                    parameters.server_identity,
+                )
+            } else {
+                ClientLoginFinishParameters::default()
+            },
         )?;
-    let client_registration_finish_result = client_registration_start_result.state.finish(
-        &mut client_rng,
-        server_registration_start_result.message,
-        ClientRegistrationFinishParameters::default(),
-    )?;
-    let p_file = server_registration_start_result
-        .state
-        .finish(client_registration_finish_result.message)?;
-    let client_login_start_result = ClientLogin::<Ristretto255Sha512NoSlowHash>::start(
-        &mut client_rng,
-        login_password,
-        ClientLoginStartParameters::default(),
-    )?;
-    let server_login_start_result = ServerLogin::<Ristretto255Sha512NoSlowHash>::start(
-        &mut server_rng,
-        p_file,
-        &server_kp.private(),
-        client_login_start_result.message,
-        ServerLoginStartParameters::default(),
-    )?;
-
-    let client_login_result = client_login_start_result.state.finish(
-        server_login_start_result.message,
-        ClientLoginFinishParameters::default(),
-    );
-
-    if hex::encode(registration_password) == hex::encode(login_password) {
-        let client_login_finish_result = client_login_result?;
-        let server_login_finish_result = server_login_start_result
-            .state
-            .finish(client_login_finish_result.message)?;
 
         assert_eq!(
-            hex::encode(server_login_finish_result.shared_secret),
-            hex::encode(client_login_finish_result.shared_secret)
+            hex::encode(&parameters.server_info),
+            hex::encode(&client_login_finish_result.confidential_info)
         );
         assert_eq!(
-            hex::encode(client_registration_finish_result.export_key),
-            hex::encode(client_login_finish_result.export_key)
+            hex::encode(&parameters.session_key),
+            hex::encode(&client_login_finish_result.shared_secret)
         );
-    } else {
-        let res = matches!(
-            client_login_result,
-            Err(ProtocolError::VerificationError(
-                PakeError::InvalidLoginError
-            ))
+        assert_eq!(
+            hex::encode(&parameters.KE3),
+            hex::encode(client_login_finish_result.message.to_bytes())
+        );
+        assert_eq!(
+            hex::encode(&parameters.export_key),
+            hex::encode(client_login_finish_result.export_key)
         );
-        assert!(res);
     }
-
     Ok(())
 }
 
 #[test]
-fn test_complete_flow_success() -> Result<(), ProtocolError> {
-    test_complete_flow(b"good password", b"good password")
-}
+fn test_server_login_finish() -> Result<(), ProtocolError> {
+    for parameters in rfc_to_params!(TEST_VECTORS) {
+        let password_file_bytes = get_password_file_bytes(&parameters)?;
+
+        let mut server_private_keyshare_and_nonce_rng =
+            CycleRng::new([parameters.server_private_keyshare, parameters.server_nonce].concat());
+        let server_login_start_result = ServerLogin::<Ristretto255Sha512NoSlowHash>::start(
+            &mut server_private_keyshare_and_nonce_rng,
+            ServerRegistration::try_from(&password_file_bytes[..]).unwrap(),
+            &Key::try_from(&parameters.server_private_key[..]).unwrap(),
+            CredentialRequest::<Ristretto255Sha512NoSlowHash>::deserialize(&parameters.KE1[..])
+                .unwrap(),
+            if parameters.envelope_mode == EnvelopeMode::CustomIdentifier {
+                ServerLoginStartParameters::WithInfoAndIdentifiers(
+                    parameters.server_info.to_vec(),
+                    parameters.client_identity,
+                    parameters.server_identity,
+                )
+            } else {
+                ServerLoginStartParameters::WithInfo(parameters.server_info.to_vec())
+            },
+        )?;
 
-#[test]
-fn test_complete_flow_fail() -> Result<(), ProtocolError> {
-    test_complete_flow(b"good password", b"bad password")
+        let server_login_result = server_login_start_result
+            .state
+            .finish(CredentialFinalization::try_from(&parameters.KE3[..])?)?;
+
+        assert_eq!(
+            hex::encode(parameters.session_key),
+            hex::encode(server_login_result.shared_secret)
+        );
+    }
+    Ok(())
 }