whyoleg / cryptography-kotlin

Kotlin Multiplatform cryptography / crypto library
https://whyoleg.github.io/cryptography-kotlin/
Apache License 2.0
337 stars 19 forks source link

Add more algorithms to support cryptocurrency #4

Closed huskcasaca closed 1 year ago

huskcasaca commented 1 year ago

Add support for ECDSA secp256k1 (current is secp256r1) Add more cryptography providers like bouncycastle and spongycastle

whyoleg commented 1 year ago

Hey, thx for the interest! I believe it's possible already now (though not tested yet) to use custom JDK JCE provider (like bouncy castle) you just need to use not default provider but create it. So f.e. you can create BC provider and use to get ECDSA with custom curve similar to this example:

val BC = CryptographyProvider.JDK(JdkProvider.Instance(BouncyCastleProvider()))
//now use BC as provider, f.e:
val endsa = BC.get(ECDSA)
val keyPairGenerator = ecdsa.keyPairGenerator(EC.Curve("secp256k1"))

Feel free to ping me on results, if you will be able to try it

Neustradamus commented 1 year ago

Important to know, there are a lot of CVE in Spongy Castle.

It is needed to use Bouncy Castle:

whyoleg commented 1 year ago

Hey, current dev branch now contains both testing that every supported algorithm works with Bouncy Castle (specifically org.bouncycastle:bcprov-jdk18on dependency) and that it works on Android API 21+ via integration tests using emulator. From under the hood implementation side, there were little changes, so I could confirm, that overall almost everything should work here on Android and JVM with Bouncy Castle (PEM certificates could not work on all Android versions, as for now they require java.util.Base64) I will also add an additional test for secp256k1 curve, but I believe there will be no issues.

whyoleg commented 1 year ago

0.2.0 is released. Added a small note on custom providers and Android support in documentation: https://whyoleg.github.io/cryptography-kotlin/modules/cryptography-provider-jdk/#custom-java-providers secp256k1 curve is supported by OpenSSL3 and JDK with BouncyCastle providers out of the box