Skip to content

Clean up HKDF code. #5

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

Merged
merged 1 commit into from
Jan 20, 2020
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
8 changes: 4 additions & 4 deletions Sources/Crypto/Key Derivation/HKDF.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ struct HKDF<H: HashFunction> {
}

static func expand<Info: DataProtocol>(PRK: HashedAuthenticationCode<H>, info: Info?, L: Int) -> SymmetricKey {
let iterations: Int = Int(ceil((Float(L) / Float(H.Digest.byteCount))))
let iterations = UInt8(ceil((Float(L) / Float(H.Digest.byteCount))))
var output = SecureBytes()
let key = SymmetricKey(data: Data(PRK.digest))
var TMinusOne = Data()
Expand All @@ -53,9 +53,9 @@ struct HKDF<H: HashFunction> {
if let infoData = info {
hmac.update(data: infoData)
}
var counter_int = i
let counter = UnsafeRawBufferPointer(start: &counter_int, count: 1)
hmac.update(bufferPointer: counter)
withUnsafeBytes(of: i) { counter in
hmac.update(bufferPointer: counter)
}
TMinusOne = Data(hmac.finalize())
output.append(TMinusOne)
}
Expand Down