@@ -709,13 +709,8 @@ void Hash::New(const FunctionCallbackInfo<Value>& args) { |
709 | 709 | } |
710 | 710 | } |
711 | 711 |
|
712 | | -bool Hash::HashInit(const EVP_MD* digest, Maybe<unsigned int> xof_md_len) { |
713 | | - mdctx_ = EVPMDCtxPointer::New(); |
714 | | - if (!mdctx_.digestInit(digest)) [[unlikely]] { |
715 | | - mdctx_.reset(); |
716 | | - return false; |
717 | | - } |
718 | | - |
| 712 | +bool Hash::FinishHashInit(const EVP_MD* digest, |
| 713 | + Maybe<unsigned int> xof_md_len) { |
719 | 714 | md_len_ = mdctx_.getDigestSize(); |
720 | 715 | if (mdctx_.hasXofFlag() && !xof_md_len.IsJust() && |
721 | 716 | ShouldRejectMissingXofLength(digest, md_len_)) { |
@@ -738,35 +733,26 @@ bool Hash::HashInit(const EVP_MD* digest, Maybe<unsigned int> xof_md_len) { |
738 | 733 | return true; |
739 | 734 | } |
740 | 735 |
|
741 | | -bool Hash::HashInit(const EVP_MD* digest, |
742 | | - const CShakeOptions& options, |
743 | | - Maybe<unsigned int> xof_md_len) { |
| 736 | +bool Hash::HashInit(const EVP_MD* digest, Maybe<unsigned int> xof_md_len) { |
744 | 737 | mdctx_ = EVPMDCtxPointer::New(); |
745 | | - if (!options.Initialize(&mdctx_, digest)) [[unlikely]] { |
| 738 | + if (!mdctx_.digestInit(digest)) [[unlikely]] { |
746 | 739 | mdctx_.reset(); |
747 | 740 | return false; |
748 | 741 | } |
749 | 742 |
|
750 | | - md_len_ = mdctx_.getDigestSize(); |
751 | | - if (mdctx_.hasXofFlag() && !xof_md_len.IsJust() && |
752 | | - ShouldRejectMissingXofLength(digest, md_len_)) { |
753 | | - MarkInvalidXofLength(); |
| 743 | + return FinishHashInit(digest, xof_md_len); |
| 744 | +} |
| 745 | + |
| 746 | +bool Hash::HashInit(const EVP_MD* digest, |
| 747 | + const CShakeOptions& options, |
| 748 | + Maybe<unsigned int> xof_md_len) { |
| 749 | + mdctx_ = EVPMDCtxPointer::New(); |
| 750 | + if (!options.Initialize(&mdctx_, digest)) [[unlikely]] { |
754 | 751 | mdctx_.reset(); |
755 | 752 | return false; |
756 | 753 | } |
757 | 754 |
|
758 | | - if (xof_md_len.IsJust() && xof_md_len.FromJust() != md_len_) { |
759 | | - // This is a little hack to cause createHash to fail when an incorrect |
760 | | - // hashSize option was passed for a non-XOF hash function. |
761 | | - if (!mdctx_.hasXofFlag()) [[unlikely]] { |
762 | | - MarkInvalidXofLength(); |
763 | | - mdctx_.reset(); |
764 | | - return false; |
765 | | - } |
766 | | - md_len_ = xof_md_len.FromJust(); |
767 | | - } |
768 | | - |
769 | | - return true; |
| 755 | + return FinishHashInit(digest, xof_md_len); |
770 | 756 | } |
771 | 757 |
|
772 | 758 | bool Hash::HashUpdate(const char* data, size_t len) { |
|