mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-21 09:14:34 +00:00
modify salt generation scheme
based on feedback that the current mechanism is overly complicated and doesn't add any real security, and it's better to stick with something simple e.g. just a tried-and-true hash of the basics
This commit is contained in:
parent
0965c4ccc6
commit
9910547e21
3 changed files with 24 additions and 1 deletions
|
|
@ -11,7 +11,7 @@ CertUtil -hashfile precursors/soc_csr.bin MD5
|
||||||
|
|
||||||
CertUtil -hashfile target/riscv32imac-unknown-xous-elf/release/loader.bin MD5
|
CertUtil -hashfile target/riscv32imac-unknown-xous-elf/release/loader.bin MD5
|
||||||
CertUtil -hashfile target/riscv32imac-unknown-xous-elf/release/xous.img MD5
|
CertUtil -hashfile target/riscv32imac-unknown-xous-elf/release/xous.img MD5
|
||||||
scp -i c:/users/bunnie/.ssh/id_pi target/riscv32imac-unknown-xous-elf/release/xous.img target/riscv32imac-unknown-xous-elf/release/loader.bin precursors/soc_csr.bin pi@10.0.245.90:code/precursors/
|
scp -i c:/users/bunnie/.ssh/id_pi target/riscv32imac-unknown-xous-elf/release/xous.img target/riscv32imac-unknown-xous-elf/release/loader.bin precursors/soc_csr.bin pi@10.0.245.181:code/precursors/
|
||||||
|
|
||||||
# CertUtil -hashfile target/riscv32imac-unknown-none-elf/release/loader.bin MD5
|
# CertUtil -hashfile target/riscv32imac-unknown-none-elf/release/loader.bin MD5
|
||||||
# CertUtil -hashfile target/riscv32imac-unknown-none-elf/release/xous.img MD5
|
# CertUtil -hashfile target/riscv32imac-unknown-none-elf/release/xous.img MD5
|
||||||
|
|
|
||||||
|
|
@ -59,4 +59,6 @@ mbbb = []
|
||||||
deterministic = []
|
deterministic = []
|
||||||
# this flag adds CI tests to the build
|
# this flag adds CI tests to the build
|
||||||
ci = []
|
ci = []
|
||||||
|
# selects the salt strategy; defaults to salt_v2 if salt_v1 is not present
|
||||||
|
salt_v1 = []
|
||||||
default = ["mbbb"]
|
default = ["mbbb"]
|
||||||
|
|
|
||||||
|
|
@ -1362,6 +1362,18 @@ impl PddbOs {
|
||||||
let mut hasher = Sha512::new_with_strategy(FallbackStrategy::SoftwareOnly);
|
let mut hasher = Sha512::new_with_strategy(FallbackStrategy::SoftwareOnly);
|
||||||
hasher.update(&bname_copy);
|
hasher.update(&bname_copy);
|
||||||
hasher.update(&plaintext_pw);
|
hasher.update(&plaintext_pw);
|
||||||
|
|
||||||
|
/*
|
||||||
|
v1 salt: takes Sha512 hash of {basis name, plaintext password}, and uses the bits of the hash
|
||||||
|
to sequence through a lookup table of salt values. It was noted that this process actually could
|
||||||
|
reduce entropy, and it's complicated and hard to analyze without necessarily adding any security.
|
||||||
|
|
||||||
|
v2 salt: takes Sha512 hash of {basis name, plaintext password, salt region}, and uses the first
|
||||||
|
16 bytes as the salt to the bcrypt algorithm. This is much "simpler" and hopefully easier to analyze
|
||||||
|
for problems. We use the full salt region only because we already have it, we could, of course,
|
||||||
|
go to a shorter string if for some reason that was a better idea.
|
||||||
|
*/
|
||||||
|
#[cfg(feature="salt_v1")]
|
||||||
let digest = hasher.finalize();
|
let digest = hasher.finalize();
|
||||||
// 2. now derive the actual salt by using indices from the digest to progressively
|
// 2. now derive the actual salt by using indices from the digest to progressively
|
||||||
// index into the salt table.
|
// index into the salt table.
|
||||||
|
|
@ -1369,11 +1381,20 @@ impl PddbOs {
|
||||||
let scd = self.static_crypto_data_get();
|
let scd = self.static_crypto_data_get();
|
||||||
let mut salt = [0u8; 16];
|
let mut salt = [0u8; 16];
|
||||||
log::info!("got scd");
|
log::info!("got scd");
|
||||||
|
#[cfg(feature="salt_v1")]
|
||||||
for (index_bytes, dst) in digest.chunks(2).into_iter().zip(salt.iter_mut()) {
|
for (index_bytes, dst) in digest.chunks(2).into_iter().zip(salt.iter_mut()) {
|
||||||
let index = u16::from_le_bytes(index_bytes.try_into().unwrap()) as usize % scd.salt_base.len();
|
let index = u16::from_le_bytes(index_bytes.try_into().unwrap()) as usize % scd.salt_base.len();
|
||||||
*dst = scd.salt_base[index];
|
*dst = scd.salt_base[index];
|
||||||
log::info!("index: {}, dst: {}", index as usize % scd.salt_base.len(), *dst);
|
log::info!("index: {}, dst: {}", index as usize % scd.salt_base.len(), *dst);
|
||||||
}
|
}
|
||||||
|
#[cfg(not(feature="salt_v1"))]
|
||||||
|
hasher.update(&scd.salt_base);
|
||||||
|
#[cfg(not(feature="salt_v1"))]
|
||||||
|
let digest = hasher.finalize();
|
||||||
|
#[cfg(not(feature="salt_v1"))]
|
||||||
|
for (&src, dst) in digest.iter().zip(salt.iter_mut()) {
|
||||||
|
*dst = src;
|
||||||
|
}
|
||||||
log::info!("derived salt: {:x?}", salt);
|
log::info!("derived salt: {:x?}", salt);
|
||||||
|
|
||||||
// 3. use the salt + password and run bcrypt on it to derive a key.
|
// 3. use the salt + password and run bcrypt on it to derive a key.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue