Skip to content

Commit

Permalink
LibWeb: Remove superfluous step in HKDF deriveBits operation
Browse files Browse the repository at this point in the history
This corresponds to a recent change in the spec:
w3c/webcrypto#372
Inspired by the following review comment:
LadybirdBrowser/ladybird#1877 (comment)

(cherry picked from commit ee3b86c3f87d8a44ba92c8aaff75925948ceacfd)
  • Loading branch information
BenWiederhake authored and nico committed Nov 12, 2024
1 parent 95dabae commit 81174e6
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions Userland/Libraries/LibWeb/Crypto/CryptoAlgorithms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1450,13 +1450,10 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<JS::ArrayBuffer>> HKDF::derive_bits(Algorit
if (length == 0 || length % 8 != 0)
return WebIDL::OperationError::create(realm, "Length must be greater than 0 and divisible by 8"_string);

// 2. Let extractKey be a key equal to n zero bits where n is the size of the output of the hash function described by the hash member of normalizedAlgorithm.
// (However, this variable is never directly used, and therefore pointless.)

// 3. Let keyDerivationKey be the secret represented by [[handle]] internal slot of key as the message.
// 2. Let keyDerivationKey be the secret represented by [[handle]] internal slot of key as the message.
auto key_derivation_key = key->handle().get<ByteBuffer>();

// 4. Let result be the result of performing the HKDF extract and then the HKDF expand step described in Section 2 of [RFC5869] using:
// 3. Let result be the result of performing the HKDF extract and then the HKDF expand step described in Section 2 of [RFC5869] using:
// * the hash member of normalizedAlgorithm as Hash,
// * keyDerivationKey as the input keying material, IKM,
// * the contents of the salt member of normalizedAlgorithm as salt,
Expand Down Expand Up @@ -1484,11 +1481,11 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<JS::ArrayBuffer>> HKDF::derive_bits(Algorit
return WebIDL::NotSupportedError::create(m_realm, MUST(String::formatted("Invalid hash function '{}'", hash_algorithm)));
}

// 5. If the key derivation operation fails, then throw an OperationError.
// 4. If the key derivation operation fails, then throw an OperationError.
if (result.is_error())
return WebIDL::OperationError::create(realm, "Failed to derive key"_string);

// 6. Return result
// 5. Return result
return JS::ArrayBuffer::create(realm, result.release_value());
}

Expand Down

0 comments on commit 81174e6

Please sign in to comment.