Add support for BCRYPT_RNG_ALG_HANDLE

This commit is contained in:
Ben Kimock 2022-09-03 12:13:47 -04:00
parent 90731796c5
commit ee1c1e6d78
2 changed files with 24 additions and 11 deletions

View File

@ -1 +1 @@
8c6ce6b91b172f77c795a74bfeaf74b865146b3f 47d1cdb0bcac8e417071ce1929d261efe2399ae2

View File

@ -288,19 +288,32 @@ fn emulate_foreign_item_by_name(
let [algorithm, ptr, len, flags] = let [algorithm, ptr, len, flags] =
this.check_shim(abi, Abi::System { unwind: false }, link_name, args)?; this.check_shim(abi, Abi::System { unwind: false }, link_name, args)?;
let algorithm = this.read_scalar(algorithm)?; let algorithm = this.read_scalar(algorithm)?;
let algorithm = algorithm.to_machine_usize(this)?;
let ptr = this.read_pointer(ptr)?; let ptr = this.read_pointer(ptr)?;
let len = this.read_scalar(len)?.to_u32()?; let len = this.read_scalar(len)?.to_u32()?;
let flags = this.read_scalar(flags)?.to_u32()?; let flags = this.read_scalar(flags)?.to_u32()?;
if flags != 2 { match flags {
// ^ BCRYPT_USE_SYSTEM_PREFERRED_RNG 0 => {
throw_unsup_format!( // BCRYPT_RNG_ALG_HANDLE
"BCryptGenRandom is supported only with the BCRYPT_USE_SYSTEM_PREFERRED_RNG flag" if algorithm != 0x81 {
); throw_unsup_format!(
} "BCryptGenRandom algorithm must be BCRYPT_RNG_ALG_HANDLE when the flag is 0"
if algorithm.to_machine_usize(this)? != 0 { );
throw_unsup_format!( }
"BCryptGenRandom algorithm must be NULL when the flag is BCRYPT_USE_SYSTEM_PREFERRED_RNG" }
); 2 => {
// BCRYPT_USE_SYSTEM_PREFERRED_RNG
if algorithm != 0 {
throw_unsup_format!(
"BCryptGenRandom algorithm must be NULL when the flag is BCRYPT_USE_SYSTEM_PREFERRED_RNG"
);
}
}
_ => {
throw_unsup_format!(
"BCryptGenRandom is only supported with BCRYPT_USE_SYSTEM_PREFERRED_RNG or BCRYPT_RNG_ALG_HANDLE"
);
}
} }
this.gen_random(ptr, len.into())?; this.gen_random(ptr, len.into())?;
this.write_null(dest)?; // STATUS_SUCCESS this.write_null(dest)?; // STATUS_SUCCESS