mirror of
https://github.com/signalapp/libsignal.git
synced 2026-04-26 01:35:22 +02:00
swift-format is owned by the Swift project and is generally less opinionated than swiftformat (but better at formatting to a limited line length).
36 lines
963 B
Swift
36 lines
963 B
Swift
//
|
|
// Copyright 2020-2022 Signal Messenger, LLC.
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
//
|
|
|
|
import Foundation
|
|
import SignalFfi
|
|
|
|
public func hkdf(
|
|
outputLength: Int,
|
|
inputKeyMaterial: some ContiguousBytes,
|
|
salt: some ContiguousBytes,
|
|
info: some ContiguousBytes
|
|
) throws -> Data {
|
|
var output = Data(count: outputLength)
|
|
|
|
try output.withUnsafeMutableBytes { outputBuffer in
|
|
try inputKeyMaterial.withUnsafeBorrowedBuffer { inputBuffer in
|
|
try salt.withUnsafeBorrowedBuffer { saltBuffer in
|
|
try info.withUnsafeBorrowedBuffer { infoBuffer in
|
|
try checkError(
|
|
signal_hkdf_derive(
|
|
.init(outputBuffer),
|
|
inputBuffer,
|
|
infoBuffer,
|
|
saltBuffer
|
|
)
|
|
)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return output
|
|
}
|