mirror of
https://github.com/ibm-s390-linux/s390-tools.git
synced 2026-08-05 02:14:52 +00:00
pvimg: Fix hash comparison in SeHdrAadV2::contains_hash
Ensure both sides of the hash comparison use the same slice length
by explicitly slicing both the keyslot hash and the input hash to
UV_KEY_HASH_SIZE. Previously, only the keyslot hash was sliced while
comparing against the full input hash reference, which could lead to
incorrect comparisons if the input hash length differs.
This makes the comparison more explicit and ensures we're always
comparing equal-length hashes. This is useful if one hash is a subset of
another, e.g. a sha512 hash truncated to 32 bytes.
Fixes: 89577c2f8c ("pvimg: Use hybrid keys")
Reviewed-by: Marc Hartmayer <marc@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
This commit is contained in:
@@ -118,11 +118,26 @@ impl KeyExchangeTrait for SeHdrAadV2 {
|
||||
Self::KEY_TYPE
|
||||
}
|
||||
|
||||
/** contains_hash - test if the given hash is in this SE-header
|
||||
*
|
||||
* * `hash`: hash to compare, either 32 or 64 byte long
|
||||
*
|
||||
* Returns:
|
||||
* - false if the given hash is not 64 or 32 bytes long
|
||||
* - the comparison result otherwise
|
||||
*/
|
||||
fn contains_hash<H: AsRef<[u8]>>(&self, hash: H) -> bool {
|
||||
let hash = hash.as_ref();
|
||||
let size = hash.len();
|
||||
|
||||
match size {
|
||||
UvKeyHashV1::UV_KEY_HASH_SIZE | SHA_512_HASH_LEN => (),
|
||||
_ => return false,
|
||||
};
|
||||
|
||||
self.keyslots
|
||||
.iter()
|
||||
.any(|ks| &ks.phkh[..UvKeyHashV1::UV_KEY_HASH_SIZE] == hash)
|
||||
.any(|ks| ks.phkh[..size] == hash[..size])
|
||||
}
|
||||
|
||||
fn contains<K>(&self, key: K) -> Result<bool>
|
||||
|
||||
Reference in New Issue
Block a user