diff --git a/src/slowkey.rs b/src/slowkey.rs index afe3c26..b63bd2f 100755 --- a/src/slowkey.rs +++ b/src/slowkey.rs @@ -77,7 +77,7 @@ lazy_static! { scrypt: ScryptOptions::default(), argon2id: Argon2idOptions::default() }, - salt: "SlowKeySalt".as_bytes().to_vec(), + salt: b"SlowKeySalt".to_vec(), secret: Vec::new(), offset_data: Vec::new(), offset: 0, @@ -89,8 +89,8 @@ lazy_static! { scrypt: ScryptOptions::default(), argon2id: Argon2idOptions::default() }, - salt: "SlowKeySalt".as_bytes().to_vec(), - secret: "Hello World".as_bytes().to_vec(), + salt: b"SlowKeySalt".to_vec(), + secret: b"Hello World".to_vec(), offset_data: Vec::new(), offset: 0, }, @@ -198,70 +198,70 @@ mod tests { length: 64, scrypt: ScryptOptions::default(), argon2id: Argon2idOptions::default() - }, &"saltsalt".as_bytes(), &"test".as_bytes(), &Vec::new(), 0, + }, b"saltsalt", b"test", &Vec::new(), 0, "96140c82d8fdc8f845b0765ff5b80026872278f220f9261e5ab46a6146a02ad2feb9fea8be0f44551c0d4e731460ffebee3879da9140f090f137a9fab18308e0")] #[case(&SlowKeyOptions { iterations: 10, length: 32, scrypt: ScryptOptions { log_n: 12, r: 8, p: 1 }, argon2id: Argon2idOptions::default() - }, &"saltsalt".as_bytes(), &"test".as_bytes(), &Vec::new(), 0, + }, b"saltsalt", b"test", &Vec::new(), 0, "a0a2b2b3cdb9002208a32b598025dfe7789bf2b3cceed8928fd873554d461128")] #[case(&SlowKeyOptions { iterations: 10, length: 32, scrypt: ScryptOptions::default(), argon2id: Argon2idOptions { m_cost: 16, t_cost: 2, p_cost: 2 } - }, &"saltsalt".as_bytes(), &"test".as_bytes(), &Vec::new(), 0, + }, b"saltsalt", b"test", &Vec::new(), 0, "bb599595d1f5cf42fc39b414fa81798085c00fce25dfece2b84bbc038c3737a9")] #[case(&SlowKeyOptions { iterations: 4, length: 64, scrypt: ScryptOptions { log_n: 20, r: 8, p: 1 }, argon2id: Argon2idOptions::default() - }, &"saltsalt".as_bytes(), &"test".as_bytes(), &Vec::new(), 0, + }, b"saltsalt", b"test", &Vec::new(), 0, "d256abf03bea97bdde3b14e5248c74055f289a7d954572de9280a451cf4961c967d94076979dc77ddffc3ed21fcd11724ac22d927d7f47861f4c93e6afc5743d")] #[case(&SlowKeyOptions { iterations: 4, length: 64, scrypt: ScryptOptions { log_n: 15, r: 8, p: 1 }, argon2id: Argon2idOptions::default() - }, &"saltsalt".as_bytes(), &"".as_bytes(), &Vec::new(), 0, + }, b"saltsalt", b"", &Vec::new(), 0, "d7b3c1eb6ac6c933e9de68803832d67588f255cab90a4c2abdbdbaf28db5fac172fcf037b3e8d0ba23567414391418ae225cbde9feda8c1305df5773a7d2aa12")] #[case(&SlowKeyOptions { iterations: 10, length: 64, scrypt: ScryptOptions { log_n: 15, r: 8, p: 1 }, argon2id: Argon2idOptions::default() - }, &"saltsalt".as_bytes(), &"test".as_bytes(), &Vec::new(), 0, + }, b"saltsalt", b"test", &Vec::new(), 0, "dd8a764e87063965dc28627e4114fb239ff87d442d87754fa9cff0f254cb740e1e992907ff8746f1d824585b6135952aa130560d82b3f0799f919d85c6900a61")] #[case(&SlowKeyOptions { iterations: 10, length: 64, scrypt: ScryptOptions { log_n: 15, r: 8, p: 1 }, argon2id: Argon2idOptions::default() - }, &"saltsalt2".as_bytes(), &"test".as_bytes(), &Vec::new(), 0, + }, b"saltsalt2", b"test", &Vec::new(), 0, "3989531a09fa72b8184d18c267e6380260484bc3892e45e520bd7056667add4d7e436fb24daa168f6bdd3ff8d436d0b74af449d174cf1119244317e5c750eb41")] #[case(&SlowKeyOptions { iterations: 10, length: 64, scrypt: ScryptOptions { log_n: 15, r: 8, p: 1 }, argon2id: Argon2idOptions::default() - }, &"saltsalt".as_bytes(), &"test2".as_bytes(), &Vec::new(), 0, + }, b"saltsalt", b"test2", &Vec::new(), 0, "7114ee8eecab95fefb06a4369d30462ae743a70367d23c73a83501cc2d398bf930e62b6332caf283a97ef2269e5fce5cd597a5ff12deb5f9af6ed418dd89b01a")] #[case(&SlowKeyOptions { iterations: 10, length: 32, scrypt: ScryptOptions { log_n: 12, r: 8, p: 1 }, argon2id: Argon2idOptions::default() - }, &"saltsalt".as_bytes(), &"test".as_bytes(), &Vec::new(), 1, + }, b"saltsalt", b"test", &Vec::new(), 1, "260dbbff8a342c3915aaa2e54823f7da2d006227305572129fbae9706158fdab")] #[case(&SlowKeyOptions { iterations: 10, length: 64, scrypt: ScryptOptions { log_n: 15, r: 8, p: 1 }, argon2id: Argon2idOptions::default() - }, &"saltsalt".as_bytes(), &"test".as_bytes(), &Vec::new(), 5, + }, b"saltsalt", b"test", &Vec::new(), 5, "2686ceace042c42bc15519be2450edcaacce45fe9e26db10d6b3f74708ebb1279d48c225fbeacff7d84da6723fe71a5b5cc87b05677d23ff5b9bd30a1fc0e0d8")] fn derive_test( diff --git a/src/utils/argon2id.rs b/src/utils/argon2id.rs index 80e86aa..bc0b9c5 100644 --- a/src/utils/argon2id.rs +++ b/src/utils/argon2id.rs @@ -112,16 +112,16 @@ mod tests { use rstest::rstest; #[rstest] - #[case(&"saltsalt".as_bytes(), &"".as_bytes(), 64, &Argon2idOptions::default(), "110a3202612f4af228ff817a5d0545c4bccfc68ec876a6330602ed8fdd3eb04367e748a38eba826dfb6bd41f54c06bfbcf3404014b6194767ca7cf4e6828fc87")] - #[case(&"saltsalt".as_bytes(), &"test".as_bytes(), 64, &Argon2idOptions::default(), "9e8dc8d00570edb4e7474a3e7c59cffa828f4145081e24c87612fcd2dad526e2d942a55225c94af995fc87d554e2845f7b3449f5d86db069a94c3670a3288675")] - #[case(&"saltsalt".as_bytes(), &"test".as_bytes(), 32, &Argon2idOptions::default(), "e209f7dcd8b44a509c680fa61f9204b286f221b932afc0fbf54f7d53f0f34da8")] - #[case(&"saltsalt".as_bytes(), &"test".as_bytes(), 16, &Argon2idOptions::default(), "c8506852d2d0ea5d9bd43a3997304a91")] - #[case(&"saltsalt".as_bytes(), &"test".as_bytes(), 64, &Argon2idOptions { m_cost: Params::DEFAULT_M_COST / 2, t_cost: Params::DEFAULT_T_COST, p_cost: Params::DEFAULT_P_COST * 2 }, "2ea32d06a83bbcf48e62e64570e852fe06689bffd9826f7f17ef2e6bdd30fcde4c2895d3ed56936e93fafbf980deeaa825524a6277cc597f4b13b246d907823b")] - #[case(&"saltsalt".as_bytes(), &"test".as_bytes(), 32, &Argon2idOptions { m_cost: Params::DEFAULT_M_COST / 2, t_cost: Params::DEFAULT_T_COST, p_cost: Params::DEFAULT_P_COST * 2 }, "b5ff8b38f1871d121b97f90e1c56fbb982dd960fe6e09456720dba3e3f5302bd")] - #[case(&"saltsalt".as_bytes(), &"test".as_bytes(), 16, &Argon2idOptions { m_cost: Params::DEFAULT_M_COST / 2, t_cost: Params::DEFAULT_T_COST, p_cost: Params::DEFAULT_P_COST * 2 }, "8ce847ad689abdbcfebf3b7a38f75fcf")] - #[case(&"saltsalt".as_bytes(), &"test".as_bytes(), 64, &Argon2idOptions { m_cost: Params::DEFAULT_M_COST / 2, t_cost: Params::DEFAULT_T_COST * 2, p_cost: Params::DEFAULT_P_COST}, "8d8a16f98d2083e949adcfa2b66b78ad86a284a6f3bbf85a428f2f41f102a2761bb5ba3232085ae337b347174ca2057580730646b97109ebcfae18bafb9f9dce")] - #[case(&"saltsalt".as_bytes(), &"test".as_bytes(), 32, &Argon2idOptions { m_cost: Params::DEFAULT_M_COST / 2, t_cost: Params::DEFAULT_T_COST * 2, p_cost: Params::DEFAULT_P_COST}, "0090960e76b193fb67e96ddeb68e3d9771b66e4ed16bb4d843edd2788a039d8c")] - #[case(&"saltsalt".as_bytes(), &"test".as_bytes(), 16, &Argon2idOptions { m_cost: Params::DEFAULT_M_COST / 2, t_cost: Params::DEFAULT_T_COST * 2, p_cost: Params::DEFAULT_P_COST}, "5c4a7816c50c8480ae45e2a4df9c3251")] + #[case(b"saltsalt", b"", 64, &Argon2idOptions::default(), "110a3202612f4af228ff817a5d0545c4bccfc68ec876a6330602ed8fdd3eb04367e748a38eba826dfb6bd41f54c06bfbcf3404014b6194767ca7cf4e6828fc87")] + #[case(b"saltsalt", b"test", 64, &Argon2idOptions::default(), "9e8dc8d00570edb4e7474a3e7c59cffa828f4145081e24c87612fcd2dad526e2d942a55225c94af995fc87d554e2845f7b3449f5d86db069a94c3670a3288675")] + #[case(b"saltsalt", b"test", 32, &Argon2idOptions::default(), "e209f7dcd8b44a509c680fa61f9204b286f221b932afc0fbf54f7d53f0f34da8")] + #[case(b"saltsalt", b"test", 16, &Argon2idOptions::default(), "c8506852d2d0ea5d9bd43a3997304a91")] + #[case(b"saltsalt", b"test", 64, &Argon2idOptions { m_cost: Params::DEFAULT_M_COST / 2, t_cost: Params::DEFAULT_T_COST, p_cost: Params::DEFAULT_P_COST * 2 }, "2ea32d06a83bbcf48e62e64570e852fe06689bffd9826f7f17ef2e6bdd30fcde4c2895d3ed56936e93fafbf980deeaa825524a6277cc597f4b13b246d907823b")] + #[case(b"saltsalt", b"test", 32, &Argon2idOptions { m_cost: Params::DEFAULT_M_COST / 2, t_cost: Params::DEFAULT_T_COST, p_cost: Params::DEFAULT_P_COST * 2 }, "b5ff8b38f1871d121b97f90e1c56fbb982dd960fe6e09456720dba3e3f5302bd")] + #[case(b"saltsalt", b"test", 16, &Argon2idOptions { m_cost: Params::DEFAULT_M_COST / 2, t_cost: Params::DEFAULT_T_COST, p_cost: Params::DEFAULT_P_COST * 2 }, "8ce847ad689abdbcfebf3b7a38f75fcf")] + #[case(b"saltsalt", b"test", 64, &Argon2idOptions { m_cost: Params::DEFAULT_M_COST / 2, t_cost: Params::DEFAULT_T_COST * 2, p_cost: Params::DEFAULT_P_COST}, "8d8a16f98d2083e949adcfa2b66b78ad86a284a6f3bbf85a428f2f41f102a2761bb5ba3232085ae337b347174ca2057580730646b97109ebcfae18bafb9f9dce")] + #[case(b"saltsalt", b"test", 32, &Argon2idOptions { m_cost: Params::DEFAULT_M_COST / 2, t_cost: Params::DEFAULT_T_COST * 2, p_cost: Params::DEFAULT_P_COST}, "0090960e76b193fb67e96ddeb68e3d9771b66e4ed16bb4d843edd2788a039d8c")] + #[case(b"saltsalt", b"test", 16, &Argon2idOptions { m_cost: Params::DEFAULT_M_COST / 2, t_cost: Params::DEFAULT_T_COST * 2, p_cost: Params::DEFAULT_P_COST}, "5c4a7816c50c8480ae45e2a4df9c3251")] fn argon2_test( #[case] salt: &[u8], #[case] secret: &[u8], #[case] length: usize, #[case] opts: &Argon2idOptions, diff --git a/src/utils/scrypt.rs b/src/utils/scrypt.rs index 8a27dba..019c002 100644 --- a/src/utils/scrypt.rs +++ b/src/utils/scrypt.rs @@ -74,16 +74,16 @@ mod tests { #[rstest] #[case(&Vec::new(), &Vec::new(), 64, &ScryptOptions::default(), "d436cba148427322d47a09a84b9bbb64d5ff086545170518711f3ec6936124e0383b3f47409e0329776231b295df5038ab07b096b8717718fd6f092195bfb03a")] - #[case(&"salt".as_bytes(), &"".as_bytes(), 64, &ScryptOptions { log_n: 15, r: 8, p: 1 }, "6e6d0720a5766a2f99679af8dbf78794d8cfe4c2b658ec82a1d005c0d54582846583ccf105fa66271ad7907868b4e3f5bb61f12b427fe0dd2c75df55afce74c1")] - #[case(&"salt".as_bytes(), &"test".as_bytes(), 64, &ScryptOptions::default(), "c91328bf58e9904c6c3aa15b26178b7ff03caf4eab382e3b9e1a335fb487c775b64ff03b82391a33b655047a632391b6216b98b2595cd82e89eaa1d9c8c2ccf5")] - #[case(&"salt".as_bytes(), &"test".as_bytes(), 32, &ScryptOptions::default(), "c91328bf58e9904c6c3aa15b26178b7ff03caf4eab382e3b9e1a335fb487c775")] - #[case(&"salt".as_bytes(), &"test".as_bytes(), 16, &ScryptOptions::default(), "c91328bf58e9904c6c3aa15b26178b7f")] - #[case(&"salt".as_bytes(), &"test".as_bytes(), 64, &ScryptOptions { log_n: 12, r: 8, p: 2 }, "3ed57e6edeae5e46f2932b6d22e0a73e47ff22c66d3acab5f0488cda26297425693b2d5cbd463c3521c8132056fb801997b915a9f8d051948a430142c7aa5855")] - #[case(&"salt".as_bytes(), &"test".as_bytes(), 32, &ScryptOptions { log_n: 12, r: 8, p: 2 }, "3ed57e6edeae5e46f2932b6d22e0a73e47ff22c66d3acab5f0488cda26297425")] - #[case(&"salt".as_bytes(), &"test".as_bytes(), 16, &ScryptOptions { log_n: 12, r: 8, p: 2 }, "3ed57e6edeae5e46f2932b6d22e0a73e")] - #[case(&"salt".as_bytes(), &"test".as_bytes(), 64, &ScryptOptions { log_n: 12, r: 16, p: 1 }, "107a4e74f205207f82c8fd0f8a4a5fbe3a485fb9509e1b839d9cb98d63649354a0d56eaad6340f2c1e92dd25a6883b51f9806b6c7980c60c1b290b96dbceec45")] - #[case(&"salt".as_bytes(), &"test".as_bytes(), 32, &ScryptOptions { log_n: 12, r: 16, p: 1 }, "107a4e74f205207f82c8fd0f8a4a5fbe3a485fb9509e1b839d9cb98d63649354")] - #[case(&"salt".as_bytes(), &"test".as_bytes(), 16, &ScryptOptions { log_n: 12, r: 16, p: 1 }, "107a4e74f205207f82c8fd0f8a4a5fbe")] + #[case(b"salt", b"", 64, &ScryptOptions { log_n: 15, r: 8, p: 1 }, "6e6d0720a5766a2f99679af8dbf78794d8cfe4c2b658ec82a1d005c0d54582846583ccf105fa66271ad7907868b4e3f5bb61f12b427fe0dd2c75df55afce74c1")] + #[case(b"salt", b"test", 64, &ScryptOptions::default(), "c91328bf58e9904c6c3aa15b26178b7ff03caf4eab382e3b9e1a335fb487c775b64ff03b82391a33b655047a632391b6216b98b2595cd82e89eaa1d9c8c2ccf5")] + #[case(b"salt", b"test", 32, &ScryptOptions::default(), "c91328bf58e9904c6c3aa15b26178b7ff03caf4eab382e3b9e1a335fb487c775")] + #[case(b"salt", b"test", 16, &ScryptOptions::default(), "c91328bf58e9904c6c3aa15b26178b7f")] + #[case(b"salt", b"test", 64, &ScryptOptions { log_n: 12, r: 8, p: 2 }, "3ed57e6edeae5e46f2932b6d22e0a73e47ff22c66d3acab5f0488cda26297425693b2d5cbd463c3521c8132056fb801997b915a9f8d051948a430142c7aa5855")] + #[case(b"salt", b"test", 32, &ScryptOptions { log_n: 12, r: 8, p: 2 }, "3ed57e6edeae5e46f2932b6d22e0a73e47ff22c66d3acab5f0488cda26297425")] + #[case(b"salt", b"test", 16, &ScryptOptions { log_n: 12, r: 8, p: 2 }, "3ed57e6edeae5e46f2932b6d22e0a73e")] + #[case(b"salt", b"test", 64, &ScryptOptions { log_n: 12, r: 16, p: 1 }, "107a4e74f205207f82c8fd0f8a4a5fbe3a485fb9509e1b839d9cb98d63649354a0d56eaad6340f2c1e92dd25a6883b51f9806b6c7980c60c1b290b96dbceec45")] + #[case(b"salt", b"test", 32, &ScryptOptions { log_n: 12, r: 16, p: 1 }, "107a4e74f205207f82c8fd0f8a4a5fbe3a485fb9509e1b839d9cb98d63649354")] + #[case(b"salt", b"test", 16, &ScryptOptions { log_n: 12, r: 16, p: 1 }, "107a4e74f205207f82c8fd0f8a4a5fbe")] fn scrypt_test( #[case] salt: &[u8], #[case] secret: &[u8], #[case] length: usize, #[case] opts: &ScryptOptions,