-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add ec pub key validation checks
- Loading branch information
1 parent
1788dd1
commit 8eb52b5
Showing
8 changed files
with
63 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
cryptography/src/commonMain/kotlin/io/iohk/atala/prism/apollo/secp256k1/Secp256k1Helper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package io.iohk.atala.prism.apollo.secp256k1 | ||
|
||
import com.ionspin.kotlin.bignum.integer.BigInteger | ||
import com.ionspin.kotlin.bignum.integer.Sign | ||
|
||
class Secp256k1Helper { | ||
companion object { | ||
fun validatePublicKey(pubKey: ByteArray): Boolean { | ||
val x = BigInteger.fromByteArray(pubKey.sliceArray(1..32), Sign.POSITIVE) | ||
val y = BigInteger.fromByteArray(pubKey.sliceArray(33..64), Sign.POSITIVE) | ||
val b = BigInteger(7) | ||
val p = BigInteger.parseString("115792089237316195423570985008687907853269984665640564039457584007908834671663", 10) | ||
return ((y * y - x * x * x - b) mod p) == BigInteger.ZERO | ||
} | ||
} | ||
} | ||
|
||
public class Secp256k1Exception : RuntimeException { | ||
public constructor() : super() | ||
public constructor(message: String?) : super(message) | ||
} |
13 changes: 9 additions & 4 deletions
13
cryptography/src/iosMain/kotlin/io/iohk/atala/prism/apollo/secp256k1/Secp256k1Lib.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters