Skip to content

Commit

Permalink
Add support for RIPEMD160 digest (#55)
Browse files Browse the repository at this point in the history
* Use ubuntu 24.04 with OpenSSL >= 3.0.8 for native builds (#55 (comment))
  • Loading branch information
huskcasaca authored Dec 13, 2024
1 parent 69b77a8 commit 186a420
Show file tree
Hide file tree
Showing 13 changed files with 30 additions and 3 deletions.
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'
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

0 comments on commit 186a420

Please sign in to comment.