Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a bug in HmacExt::verify_bigint #151

Merged
merged 1 commit into from
Aug 22, 2022
Merged

Conversation

elichai
Copy link
Contributor

@elichai elichai commented Oct 28, 2021

Every once in a while I get tests failing like this a few weeks ago:

---- cryptographic_primitives::hashing::ext::test::create_hmac_test_blake2b stdout ----
thread 'cryptographic_primitives::hashing::ext::test::create_hmac_test_blake2b' panicked at 'assertion failed: Hmac::<H>::new_bigint(&key).chain_bigint(&BigInt::from(10)).verify_bigint(&result1).is_ok()', src/cryptographic_primitives/hashing/ext.rs:306:9

---- cryptographic_primitives::hashing::ext::test::create_hmac_test_sha512 stdout ----
thread 'cryptographic_primitives::hashing::ext::test::create_hmac_test_sha512' panicked at 'assertion failed: Hmac::<H>::new_bigint(&key).chain_bigint(&BigInt::from(10)).verify_bigint(&result1).is_ok()', src/cryptographic_primitives/hashing/ext.rs:306:9


failures:
    cryptographic_primitives::hashing::ext::test::create_hmac_test_blake2b
    cryptographic_primitives::hashing::ext::test::create_hmac_test_sha512

test result: FAILED. 475 passed; 2 failed; 0 ignored; 0 measured; 0 filtered out; finished in 4.16s

and this today:

---- cryptographic_primitives::hashing::ext::test::create_hmac_test_sha3_512 stdout ----
thread 'cryptographic_primitives::hashing::ext::test::create_hmac_test_sha3_512' panicked at 'assertion failed: Hmac::<H>::new_bigint(&key).chain_bigint(&BigInt::from(10)).verify_bigint(&result1).is_ok()', src/cryptographic_primitives/hashing/ext.rs:306:9

The reason was that we converted BigInt to a vector and then compared that means that if the least significant byte was 0 it returned 32 bytes instead of 33 (or 63 bytes instead of 64).

We fix it by copying into an array of the right size.

…igInt was 0 the resulting array was 31 bytes and then the verification failed
@elichai elichai merged commit 3025dca into master Aug 22, 2022
@elichai elichai deleted the fix-mac-verify-bigint branch August 22, 2022 09:04
qalisander pushed a commit to GridlockNetwork/curv that referenced this pull request Jul 1, 2023
…igInt was 0 the resulting array was 31 bytes and then the verification failed (ZenGo-X#151)

(cherry picked from commit 3025dca)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant