Commit f16a20d
authored
Ensure HMAC_Init_ex reinitializes data properly (#2806)
### Description of changes:
I discovered this edge case when working with an older Ruby version.
This discrepancy only exists in older versions since Ruby openssl
migrated from using the `HMAC_CTX` APIs to use the `EVP` layer in 3.1:
ruby/ruby@b91f62f.
[`test_reset_keep_key`](https://github.com/ruby/ruby/blame/cf4a034d59913fb71a7dd1b052164984be4a3d14/test/openssl/test_hmac.rb#L37-L43)
was failing since we were MACing the data twice. It turns out the call
to `h1.reset` wasn't working properly and this was due to our
implementation of `HMAC_Init_ex` not reinitializing the data input when
only `HMAC_Update` had been called. According to the original function
contract, `HMAC_Init_ex` should reinitialize the inputted data, but the
computed key should still be preserved.
This is a minor edge case due to how older versions of Ruby were
consuming `HMAC_CTX`. [Their
call](https://github.com/ruby/ruby/blob/ruby_2_7/ext/openssl/ossl_hmac.c#L167-L174)
to `HMAC_Final` was called upon a copy of the original `HMAC_CTX`. The
original `HMAC_CTX` was always within a `HMAC_Update` state and AWS-LC
was not properly reinitializing these cases.
### Call-outs:
N/A
### Testing:
New tests
By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache 2.0 license and the ISC license.1 parent a3c40ea commit f16a20d
File tree
3 files changed
+59
-5
lines changed- crypto
- fipsmodule/hmac
- hmac_extra
- include/openssl
3 files changed
+59
-5
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
371 | 371 | | |
372 | 372 | | |
373 | 373 | | |
| 374 | + | |
| 375 | + | |
374 | 376 | | |
375 | 377 | | |
376 | 378 | | |
377 | 379 | | |
378 | 380 | | |
379 | | - | |
| 381 | + | |
380 | 382 | | |
381 | 383 | | |
382 | 384 | | |
383 | 385 | | |
384 | 386 | | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
385 | 392 | | |
386 | 393 | | |
387 | 394 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
635 | 635 | | |
636 | 636 | | |
637 | 637 | | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
108 | 108 | | |
109 | 109 | | |
110 | 110 | | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
115 | 117 | | |
116 | 118 | | |
117 | 119 | | |
| |||
0 commit comments