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

Hmac should blank preparedKey after deriving iKey and oKey #30

Closed
05nelsonm opened this issue Jun 7, 2023 · 0 comments · Fixed by #32
Closed

Hmac should blank preparedKey after deriving iKey and oKey #30

05nelsonm opened this issue Jun 7, 2023 · 0 comments · Fixed by #32

Comments

@05nelsonm
Copy link
Member

Current implementation of Hmac.Engine is that the provided key ByteArray is sized to the digest.blockSize() by either hashing it once (if larger than), padding it with 0's (if smaller), or using the provided key. It then uses the prepared key to derive iKey and oKey.

After those are derived, the preparedKey should be blanked. As such, the provided key should always be copied so we are not modifying the provided ByteArray, so that the copy can be blanked before dereferencing.

val preparedKey = if (key.size > digest.blockSize()) {
    digest.digest(key).copyOf(digest.blockSize())
} else {
    key.copyOf(digest.blockSize())
}

// ... derive iKey and oKey

preparedKey.fill(0)
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 a pull request may close this issue.

1 participant