This repository has been archived by the owner on Jun 3, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 42
yubihsm/setup: Test vectors for key derivation hierarchy #299
Merged
tarcieri
merged 1 commit into
master
from
yubihsm/test-vectors-for-account-key-derivation
Jul 24, 2019
Merged
yubihsm/setup: Test vectors for key derivation hierarchy #299
tarcieri
merged 1 commit into
master
from
yubihsm/test-vectors-for-account-key-derivation
Jul 24, 2019
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I am planning to address one of the findings (low severity) of a recent security audit, as well and replace the key derivation implementation with one I've extracted into an external crate for reuse: https://crates.io/crates/hkd32 However, the key derivation performed by `tmkms yubihsm setup` does not presently have any tests (it was hastily written in order to meet the deadlines for the Cosmos Hub launch). This PR adds test vectors which capture the current state of the implementation, so as to ensure that followup PRs derive the same key hierarchy.
Note to anyone who is reading this who is curious about the security audit: there is nothing actionable. The tl;dr: is the setup process derives the master 24-word passphrase by using the outputs of both the OS RNG as well as the YubiHSM RNG. In the off chance there is a silent failure of the OS RNG, the derived key will have 128-bits entropy instead of the intended 256-bits. Note that we have no reason to suspect any silent failures of the OS RNG have occurred, and even if the did, 128-bits is still a sufficient amount of entropy. Nevertheless, in a followup PR we will collect 256-bits of entropy from both sources so as to ensure the desired 256-bits of entropy are always collected. |
tarcieri
pushed a commit
that referenced
this pull request
Jul 24, 2019
`hkd32` is an implementation of the same hierarchical key derivation algorith the KMS was previously using, which is an extracted subset of the symmetric parts of BIP32 derivation (to the point it could potentially be used to implement a full BIP32). The `hkd32` crate has the advantage of using a zeroize-on-drop type for all key material, as opposed to some of the manual zeroization this crate was previously using. In addition, it has some richer types for things like derivation paths, which may be potentially useful in the future. There is one case that deviated from the previous implementation, which is the behavior of calling derive with an empty derivation path. Before it would output the "chain code" derived after inputting the `DERIVATION_VERSION`, whereas when using `hkd32` it correctly outputs the other half of the derived key material, which is intended to be used as a secret key. Nothing presently calls the derivation function with an empty derivation path, except for a test I just added today in #299. While the output for this case differs, it has no practical impact, and if anything the function outputting the raw chain code for the first level of the hierarchy (which is the version number) is a sharp edge that could potentially leak what is the root key to the entire hierarchy if it were to be called with an empty derivation path. `hkd32` uses a fully uniform derivation algorithm which treats the `DERIVATION_VERSION` like any other part of the path, and therefore does not have this sharp edge. Test vectors for path lengths of 1, 2, and 3 all pass with the original vectors.
tarcieri
pushed a commit
that referenced
this pull request
Jul 24, 2019
`hkd32` is an implementation of the same hierarchical key derivation algorithm the KMS was previously using, which is an extracted subset of the symmetric parts of BIP32 derivation (to the point it could potentially be used to implement a full BIP32). The `hkd32` crate has the advantage of using a zeroize-on-drop type for all key material, as opposed to some of the manual zeroization this crate was previously using. In addition, it has some richer types for things like derivation paths, which may be potentially useful in the future. There is one case that deviated from the previous implementation, which is the behavior of calling derive with an empty derivation path. Before it would output the "chain code" derived after inputting the `DERIVATION_VERSION`, whereas when using `hkd32` it correctly outputs the other half of the derived key material, which is intended to be used as a secret key. Nothing presently calls the derivation function with an empty derivation path, except for a test I just added today in #299. While the output for this case differs, it has no practical impact, and if anything the function outputting the raw chain code for the first level of the hierarchy (which is the version number) is a sharp edge that could potentially leak what is the root key to the entire hierarchy if it were to be called with an empty derivation path. `hkd32` uses a fully uniform derivation algorithm which treats the `DERIVATION_VERSION` like any other part of the path, and therefore does not have this sharp edge. Test vectors for path lengths of 1, 2, and 3 all pass with the original vectors.
tarcieri
pushed a commit
that referenced
this pull request
Jul 24, 2019
`hkd32` is an implementation of the same hierarchical key derivation algorithm the KMS was previously using, which is an extracted subset of the symmetric parts of BIP32 derivation (to the point it could potentially be used to implement a full BIP32). The `hkd32` crate has the advantage of using a zeroize-on-drop type for all key material, as opposed to some of the manual zeroization this crate was previously using. In addition, it has some richer types for things like derivation paths, which may be potentially useful in the future. There is one case that deviated from the previous implementation, which is the behavior of calling derive with an empty derivation path. Before it would output the "chain code" derived after inputting the `DERIVATION_VERSION`, whereas when using `hkd32` it correctly outputs the other half of the derived key material, which is intended to be used as a secret key. Nothing presently calls the derivation function with an empty derivation path, except for a test I just added today in #299. While the output for this case differs, it has no practical impact, and if anything the function outputting the raw chain code for the first level of the hierarchy (which is the version number) is a sharp edge that could potentially leak what is the root key to the entire hierarchy if it were to be called with an empty derivation path. `hkd32` uses a fully uniform derivation algorithm which treats the `DERIVATION_VERSION` like any other part of the path, and therefore does not have this sharp edge. Test vectors for path lengths of 1, 2, and 3 all pass with the original vectors.
Closed
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I am planning to address one of the findings (low severity) of a recent security audit, as well and replace the key derivation implementation with one I've extracted into an external crate for reuse:
https://crates.io/crates/hkd32
However, the key derivation performed by
tmkms yubihsm setup
does not presently have any tests (it was hastily written in order to meet the deadlines for the Cosmos Hub launch).This PR adds test vectors which capture the current state of the implementation, so as to ensure that followup PRs derive the same key hierarchy.