-
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.
Signed-off-by: Ahmed Moussa <[email protected]>
- Loading branch information
Showing
8 changed files
with
31 additions
and
282 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
19 changes: 3 additions & 16 deletions
19
apollo/src/appleMain/kotlin/io/iohk/atala/prism/apollo/secp256k1/ECDH.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 |
---|---|---|
@@ -1,27 +1,14 @@ | ||
package io.iohk.atala.prism.apollo.secp256k1 | ||
|
||
import kotlinx.cinterop.ExperimentalForeignApi | ||
import kotlinx.cinterop.UByteVar | ||
import kotlinx.cinterop.allocArray | ||
import kotlinx.cinterop.memScoped | ||
import kotlinx.cinterop.ptr | ||
import kotlinx.cinterop.readBytes | ||
import secp256k1.secp256k1_ecdh | ||
import fr.acinq.secp256k1.Secp256k1Native | ||
|
||
class ECDH : Secp256k1() { | ||
class ECDH { | ||
/** | ||
* Compute an elliptic curve Diffie-Hellman secret. | ||
*/ | ||
@OptIn(ExperimentalForeignApi::class) | ||
fun ecdh(privateKey: ByteArray, publicKey: ByteArray): ByteArray { | ||
require(privateKey.size == 32) | ||
require(publicKey.size == 33 || publicKey.size == 65) | ||
memScoped { | ||
val nPubkey = allocPublicKey(publicKey) | ||
val nPrivkey = toNat(privateKey) | ||
val output = allocArray<UByteVar>(32) | ||
secp256k1_ecdh(ctx, output, nPubkey.ptr, nPrivkey, null, null).requireSuccess("secp256k1_ecdh() failed") | ||
return output.readBytes(32) | ||
} | ||
return Secp256k1Native.ecdh(privateKey, publicKey) | ||
} | ||
} |
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
243 changes: 0 additions & 243 deletions
243
apollo/src/appleMain/kotlin/io/iohk/atala/prism/apollo/secp256k1/Secp256k1.kt
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.