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:
bunnie 2022-01-02 17:53:00 +08:00
parent 0965c4ccc6
commit 9910547e21
3 changed files with 24 additions and 1 deletions

View file

@ -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/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/xous.img MD5

View file

@ -59,4 +59,6 @@ mbbb = []
deterministic = []
# this flag adds CI tests to the build
ci = []
# selects the salt strategy; defaults to salt_v2 if salt_v1 is not present
salt_v1 = []
default = ["mbbb"]

View file

@ -1362,6 +1362,18 @@ impl PddbOs {
let mut hasher = Sha512::new_with_strategy(FallbackStrategy::SoftwareOnly);
hasher.update(&bname_copy);
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();
// 2. now derive the actual salt by using indices from the digest to progressively
// index into the salt table.
@ -1369,11 +1381,20 @@ impl PddbOs {
let scd = self.static_crypto_data_get();
let mut salt = [0u8; 16];
log::info!("got scd");
#[cfg(feature="salt_v1")]
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();
*dst = scd.salt_base[index];
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);
// 3. use the salt + password and run bcrypt on it to derive a key.