Im trying to use the SecKeyCopyKeyExchangeResult function to obtain the shared secret from my local private key and received public key of server. Shared key is generated successfully and I able to decrypt incomming message with AES encryption Not so long time ago server devs decided to add KDF to key generation flow. I started investigate how I can do it on iOS side and find out that there is a special param static let sharedInfo: SecKeyKeyExchangeParameter To say that documentation is poor its to say nothing... Only what I did found is this description in header
@constant kSecKeyKeyExchangeParameterSharedInfo Contains CFDataRef with additional shared info for KDF (key derivation function).
If somebody have worked with this please help. Server use this params to generate KDF on scala
private def concatWithKdf(secretKey: SecretKey) = {
val bytes = new Array[Byte](SECRET_KEY_LENGTH)
val digest = new SHA256Digest();
val kdf1BytesGenerator = new KDF1BytesGenerator(digest)
kdf1BytesGenerator.init(new KDFParameters(secretKey.getEncoded, null))
kdf1BytesGenerator.generateBytes(bytes, 0, bytes.length)
new SecretKeySpec(bytes, secretKey.getAlgorithm)
}
Code on iOS side
var keyExchangeError: Unmanaged<CFError>?
let dict = [SecKeyKeyExchangeParameter.requestedSize.rawValue : 32,
SecKeyKeyExchangeParameter.sharedInfo.rawValue : ???]
let secret = SecKeyCopyKeyExchangeResult(privateOwn,
SecKeyAlgorithm.ecdhKeyExchangeStandard,
publicTheir,
dict as CFDictionary,
&keyExchangeError)