Skip to content

fix: reuse the SM3 security provider across hash calls - #994

Open
mvanhorn wants to merge 1 commit into
aliyun:masterfrom
mvanhorn:fix/965-reuse-sm3-security-provider
Open

mvanhorn wants to merge 1 commit into
aliyun:masterfrom
mvanhorn:fix/965-reuse-sm3-security-provider

Conversation

@mvanhorn

Copy link
Copy Markdown

Why

Repeated SM3 hash calls incur unnecessary overhead, slowing callers that hash many inputs.

HmacSM3Signer.hash constructs a new BouncyCastleProvider for every non-null input. This repeats expensive provider initialization on every call.

What changed

A static final BouncyCastleProvider is reused across hash calls and signer instances. Each call still creates its own MessageDigest, and null inputs still return null. Tests now cover known digests, empty input, repeated calls across signer instances, and concurrent calls.

Testing

Mvn -B -ntp test -Dtest=HmacSM3SignerTest -Dsurefire.failIfNoSpecifiedTests=false failed during test compilation because the JDK does not support source and target level 6; no tests ran.

Fixes #965

A static final BouncyCastleProvider is reused across hash calls and
signer instances. Each call still creates its own MessageDigest, and
null inputs still return null. Tests now cover known digests, empty
input, repeated calls across signer instances, and concurrent calls.

Fixes aliyun#965
@CLAassistant

CLAassistant commented Oct 20, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

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.

Bad performance HmacSM3Signer#hash

2 participants