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

Validate KEY_DATA_BLOB_VERSION1 content in ExtractHKDF #71

Merged
merged 1 commit into from
Oct 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions cng/hkdf.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,19 @@ func ExtractHKDF(h func() hash.Hash, secret, salt []byte) ([]byte, error) {
return nil, errors.New("cng: unknown key data blob version")
}
// KEY_DATA_BLOB_VERSION1 format is:
// cbHash uint32 // Big-endian
// hashName [cbHash]byte
// cbHashName uint32 // Big-endian
// pHashName [cbHash]byte
// key []byte // Rest of the blob
Comment on lines 158 to 161
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where does this format come from? I'm not able to find it anywhere.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I don't remember where the definition came from. Maybe I just inspected the content of the data and figured it out? I'll ask the CNG team to document this payload, just as other algorithm payloads are.

if len(blob) < 4 {
return nil, errors.New("cng: exported key is corrupted")
}
hashLength := binary.BigEndian.Uint32(blob[:])
return blob[4+hashLength:], nil
cbHashName := binary.BigEndian.Uint32(blob)
blob = blob[4:]
if len(blob) < int(cbHashName) {
return nil, errors.New("cng: exported key is corrupted")
}
// Skip pHashName.
return blob[cbHashName:], nil
}

func ExpandHKDF(h func() hash.Hash, pseudorandomKey, info []byte) (io.Reader, error) {
Expand Down
Loading