Skip to content

Commit a21035c

Browse files
authored
add_hkdf_info: use patched version if fips is enabled (#30)
openssl/openssl#23448 has been fixed in the openssl upstream and backported to all 3.y branches. However, unpatched instances of openssl may still contain the bug. This can be the same for openssl fips providers, which are usually quite stable, and receive only CVE patches. Using patched version of add_hkdf_info function in FIPS environment enables this usecase. Signed-off-by: Zuzana Miklankova <zmiklank@redhat.com>
1 parent c32b266 commit a21035c

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

src/hkdf.rs

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -107,22 +107,28 @@ impl RustlsHkdfExpander for HkdfExpander {
107107
}
108108
}
109109

110-
#[cfg(bugged_add_hkdf_info)]
111110
fn add_hkdf_info<T>(ctx: &mut PkeyCtxRef<T>, info: &[&[u8]]) -> Result<(), ErrorStack> {
112-
// Concatenate the info strings to work around https://github.com/openssl/openssl/issues/23448
113-
let infos = info.iter().fold(Vec::new(), |mut acc, i| {
114-
acc.extend_from_slice(i);
115-
acc
116-
});
117-
ctx.add_hkdf_info(&infos)
118-
}
119111

120-
#[cfg(not(bugged_add_hkdf_info))]
121-
fn add_hkdf_info<T>(ctx: &mut PkeyCtxRef<T>, info: &[&[u8]]) -> Result<(), ErrorStack> {
122-
for info in info {
123-
ctx.add_hkdf_info(info)?;
112+
#[cfg(bugged_add_hkdf_info)]
113+
let bugged_version = true;
114+
115+
#[cfg(not(bugged_add_hkdf_info))]
116+
let bugged_version = false;
117+
118+
if bugged_version || crate::fips::enabled() {
119+
// Concatenate the info strings to work around
120+
// https://github.com/openssl/openssl/issues/23448
121+
let infos = info.iter().fold(Vec::new(), |mut acc, i| {
122+
acc.extend_from_slice(i);
123+
acc
124+
});
125+
ctx.add_hkdf_info(&infos)
126+
} else {
127+
for info in info {
128+
ctx.add_hkdf_info(info)?;
129+
}
130+
Ok(())
124131
}
125-
Ok(())
126132
}
127133

128134
impl Drop for HkdfExpander {

0 commit comments

Comments
 (0)