Skip to content

Commit a93a272

Browse files
committed
Support HKDF in Apple provider
1 parent e897668 commit a93a272

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

cryptography-providers-tests/src/commonMain/kotlin/SupportedAlgorithmsTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,6 @@ abstract class SupportedAlgorithmsTest(provider: CryptographyProvider) : Provide
5353
assertSupports(RSA.RAW, !context.provider.isWebCrypto)
5454

5555
assertSupports(PBKDF2)
56-
assertSupports(HKDF, context.provider.isWebCrypto || context.provider.isOpenssl3)
56+
assertSupports(HKDF)
5757
}
5858
}

cryptography-providers/apple/src/commonMain/kotlin/AppleCryptographyProvider.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ internal object AppleCryptographyProvider : CryptographyProvider() {
3333
RSA.RAW -> SecRsaRaw
3434
ECDSA -> SecEcdsa
3535
PBKDF2 -> CCPbkdf2
36+
HKDF -> CCHkdf
3637
else -> null
3738
} as A?
3839
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright (c) 2024 Oleg Yukhnevich. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
5+
package dev.whyoleg.cryptography.providers.apple.algorithms
6+
7+
import dev.whyoleg.cryptography.*
8+
import dev.whyoleg.cryptography.algorithms.*
9+
import dev.whyoleg.cryptography.providers.apple.*
10+
import dev.whyoleg.cryptography.providers.base.algorithms.*
11+
import platform.CoreCrypto.*
12+
13+
internal object CCHkdf : BaseHkdf(AppleCryptographyProvider) {
14+
override fun digestSize(digest: CryptographyAlgorithmId<Digest>): Int {
15+
return when (digest) {
16+
SHA1 -> CC_SHA1_DIGEST_LENGTH
17+
SHA224 -> CC_SHA224_DIGEST_LENGTH
18+
SHA256 -> CC_SHA256_DIGEST_LENGTH
19+
SHA384 -> CC_SHA384_DIGEST_LENGTH
20+
SHA512 -> CC_SHA512_DIGEST_LENGTH
21+
else -> throw IllegalStateException("Unsupported hash algorithm: $digest")
22+
}
23+
}
24+
}

0 commit comments

Comments
 (0)