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

Add support for RIPEMD160 digest #55

Merged
merged 4 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
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: 6 additions & 2 deletions .github/workflows/run-tests-compatibility.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ jobs:
fail-fast: false
matrix:
os: [ 'ubuntu-latest' ]
target: [ 'jvm', 'js', 'wasm', 'native' ]
target: [ 'jvm', 'js', 'wasm' ]
include:
- os: 'macos-latest'
target: 'macos'
- os: 'windows-latest'
target: 'native'
- os: 'ubuntu-24.04'
Copy link
Owner

Choose a reason for hiding this comment

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

is there some problem with ubuntu-latest?
There were no problems before, so I don't think that it's needed for this PR
Could you please revert those changes and I will re-run CI?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried not to change but ubuntu-latest is 22.04 which is using OpenSSL 3.0.2. It dropped RIPEMD160 to legacy providers which requires an extra config file to reenable it otherwise the CI will fail.
But OpenSSL 3.0.6 reverts the drop so I have to update to ubuntu-24.04 with OpenSSL 3.0.8+.

openssl/openssl#16994
https://openssl-library.org/news/openssl-3.0-notes/

Copy link
Owner

Choose a reason for hiding this comment

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

Okay, I see, thanks for the explanation!

target: 'native'
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup-environment
Expand Down Expand Up @@ -66,12 +68,14 @@ jobs:
fail-fast: false
matrix:
os: [ 'ubuntu-latest' ]
target: [ 'jvm', 'js', 'wasm', 'native' ]
target: [ 'jvm', 'js', 'wasm' ]
include:
- os: 'macos-latest'
target: 'macos'
- os: 'windows-latest'
target: 'native'
- os: 'ubuntu-24.04'
target: 'native'
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup-environment
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/run-tests-default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
fail-fast: false
matrix:
os: [ 'ubuntu-latest' ]
target: [ 'jvmAll', 'js', 'wasm', 'native' ]
target: [ 'jvmAll', 'js', 'wasm' ]
include:
- os: 'macos-latest'
target: 'macos'
Expand All @@ -35,6 +35,8 @@ jobs:
- os: 'ubuntu-22.04'
target: 'connectedAndroid'
android-api-level: 33
- os: 'ubuntu-24.04'
target: 'native'
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup-environment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ abstract class GenerateProviderTestsTask : DefaultTask() {
"Sha3B256CompatibilityTest",
"Sha3B384CompatibilityTest",
"Sha3B512CompatibilityTest",
"Ripemd160CompatibilityTest",

"AesCbcTest",
"AesCbcCompatibilityTest",
Expand Down
4 changes: 4 additions & 0 deletions cryptography-core/api/cryptography-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,10 @@ public abstract interface class dev/whyoleg/cryptography/algorithms/PBKDF2 : dev
public final class dev/whyoleg/cryptography/algorithms/PBKDF2$Companion : dev/whyoleg/cryptography/CryptographyAlgorithmId {
}

public final class dev/whyoleg/cryptography/algorithms/RIPEMD160 : dev/whyoleg/cryptography/CryptographyAlgorithmId {
public static final field INSTANCE Ldev/whyoleg/cryptography/algorithms/RIPEMD160;
}

public abstract interface class dev/whyoleg/cryptography/algorithms/RSA : dev/whyoleg/cryptography/CryptographyAlgorithm {
public abstract fun keyPairGenerator-imL9hLU (ILdev/whyoleg/cryptography/CryptographyAlgorithmId;Ldev/whyoleg/cryptography/bigint/BigInt;)Ldev/whyoleg/cryptography/materials/key/KeyGenerator;
public static synthetic fun keyPairGenerator-imL9hLU$default (Ldev/whyoleg/cryptography/algorithms/RSA;ILdev/whyoleg/cryptography/CryptographyAlgorithmId;Ldev/whyoleg/cryptography/bigint/BigInt;ILjava/lang/Object;)Ldev/whyoleg/cryptography/materials/key/KeyGenerator;
Expand Down
2 changes: 2 additions & 0 deletions cryptography-core/api/cryptography-core.klib.api
Original file line number Diff line number Diff line change
Expand Up @@ -801,6 +801,8 @@ open class dev.whyoleg.cryptography/CryptographyException : kotlin/RuntimeExcept

final object dev.whyoleg.cryptography.algorithms/MD5 : dev.whyoleg.cryptography/CryptographyAlgorithmId<dev.whyoleg.cryptography.algorithms/Digest> // dev.whyoleg.cryptography.algorithms/MD5|null[0]

final object dev.whyoleg.cryptography.algorithms/RIPEMD160 : dev.whyoleg.cryptography/CryptographyAlgorithmId<dev.whyoleg.cryptography.algorithms/Digest> // dev.whyoleg.cryptography.algorithms/RIPEMD160|null[0]

final object dev.whyoleg.cryptography.algorithms/SHA1 : dev.whyoleg.cryptography/CryptographyAlgorithmId<dev.whyoleg.cryptography.algorithms/Digest> // dev.whyoleg.cryptography.algorithms/SHA1|null[0]

final object dev.whyoleg.cryptography.algorithms/SHA224 : dev.whyoleg.cryptography/CryptographyAlgorithmId<dev.whyoleg.cryptography.algorithms/Digest> // dev.whyoleg.cryptography.algorithms/SHA224|null[0]
Expand Down
3 changes: 3 additions & 0 deletions cryptography-core/src/commonMain/kotlin/algorithms/Digest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,6 @@ public object SHA3_384 : CryptographyAlgorithmId<Digest>("SHA3-384")

@Suppress("ClassName")
public object SHA3_512 : CryptographyAlgorithmId<Digest>("SHA3-512")

@DelicateCryptographyApi
public object RIPEMD160 : CryptographyAlgorithmId<Digest>("RIPEMD-160")
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ fun AlgorithmTestScope<*>.supportsDigest(digest: CryptographyAlgorithmId<Digest>
digest in sha3Algorithms &&
provider.isJdkDefault &&
(platform.isJdk { major < 17 } || platform.isAndroid) -> "${digest.name} signatures on old JDK"
digest == RIPEMD160 && (provider.isJdkDefault || provider.isApple || provider.isWebCrypto)
-> digest.name
else -> null
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ abstract class SupportedAlgorithmsTest(provider: CryptographyProvider) : Provide
assertSupports(SHA3_384, supportsSha3)
assertSupports(SHA3_512, supportsSha3)

assertSupports(RIPEMD160, !context.provider.isApple && !context.provider.isWebCrypto)

assertSupports(ECDSA)
assertSupports(ECDH, !context.provider.isApple)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ abstract class Sha3B224CompatibilityTest(provider: CryptographyProvider) : Diges
abstract class Sha3B256CompatibilityTest(provider: CryptographyProvider) : DigestCompatibilityTest(SHA3_256, provider)
abstract class Sha3B384CompatibilityTest(provider: CryptographyProvider) : DigestCompatibilityTest(SHA3_384, provider)
abstract class Sha3B512CompatibilityTest(provider: CryptographyProvider) : DigestCompatibilityTest(SHA3_512, provider)
abstract class Ripemd160CompatibilityTest(provider: CryptographyProvider) : DigestCompatibilityTest(RIPEMD160, provider)

abstract class DigestCompatibilityTest(algorithmId: CryptographyAlgorithmId<Digest>, provider: CryptographyProvider) :
CompatibilityTest<Digest>(algorithmId, provider) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ abstract class DigestTest(provider: CryptographyProvider) : ProviderTest(provide
@Test
fun testSHA3_512() = test(SHA3_512, 64)

@Test
fun testRIPEMD160() = test(RIPEMD160, 20)

@Test
fun testFunctionIndexes() = testWithAlgorithm(SHA256) {
if (!supportsFunctions()) return@testWithAlgorithm
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ internal class JdkCryptographyProvider(
SHA3_256 -> JdkDigest(state, "SHA3-256", SHA3_256)
SHA3_384 -> JdkDigest(state, "SHA3-384", SHA3_384)
SHA3_512 -> JdkDigest(state, "SHA3-512", SHA3_512)
RIPEMD160 -> JdkDigest(state, "RIPEMD160", RIPEMD160)
HMAC -> JdkHmac(state)
AES.CBC -> JdkAesCbc(state)
AES.CTR -> JdkAesCtr(state)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ internal object Openssl3CryptographyProvider : CryptographyProvider() {
SHA3_256 -> Openssl3Digest("SHA3-256", SHA3_256)
SHA3_384 -> Openssl3Digest("SHA3-384", SHA3_384)
SHA3_512 -> Openssl3Digest("SHA3-512", SHA3_512)
RIPEMD160 -> Openssl3Digest("RIPEMD160", RIPEMD160)
HMAC -> Openssl3Hmac
AES.CBC -> Openssl3AesCbc
AES.CTR -> Openssl3AesCtr
Expand Down
1 change: 1 addition & 0 deletions docs/providers/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ For additional limitation please consult provider specific documentation.
| | SHA384 | ✅ | ✅ | ✅ | ✅ |
| | SHA512 | ✅ | ✅ | ✅ | ✅ |
| | SHA3 family | ✅ | ❌ | ❌ | ✅ |
| | ⚠️ RIPEMD160 | ✅ | ❌ | ❌ | ✅ |
| **MAC** | HMAC | ✅ | ✅ | ✅ | ✅ |
| **Symmetric-key<br/>encryption/decryption** | AES-CBC | ✅ | ✅ | ✅ | ✅ |
| | AES-CTR | ✅ | ✅ | ✅ | ✅ |
Expand Down
Loading