Adding _sign_ native implementation and started writing tests
This commit is contained in:
3 files changed
+315
-7
No files matched your search
+15
-7
@@ -5,12 +5,13 @@ package com.ionspin.kotlin.crypto.signature
|
||||
*/
|
||||
expect class SignatureState
|
||||
|
||||
data class SignKeyPair(val publicKey: UByteArray, val secretKey: UByteArray)
|
||||
data class SignatureKeyPair(val publicKey: UByteArray, val secretKey: UByteArray)
|
||||
|
||||
const val crypto_sign_BYTES = 64
|
||||
const val crypto_sign_SEEDBYTES = 32
|
||||
const val crypto_sign_PUBLICKEYBYTES = 32
|
||||
const val crypto_sign_SECRETKEY2BYTES = 64
|
||||
const val crypto_sign_SECRETKEYBYTES = 64
|
||||
const val crypto_scalarmult_curve25519_BYTES = 32
|
||||
|
||||
class InvalidSignatureException() : RuntimeException("Signature validation failed")
|
||||
|
||||
@@ -24,14 +25,14 @@ expect object Signature {
|
||||
* The crypto_sign_keypair() function randomly generates a secret key and a corresponding public key.
|
||||
* The public key is put into pk (crypto_sign_PUBLICKEYBYTES bytes) and the secret key into sk (crypto_sign_SECRETKEYBYTES bytes).
|
||||
*/
|
||||
fun keypair(): SignKeyPair
|
||||
fun keypair(): SignatureKeyPair
|
||||
|
||||
/**
|
||||
* The crypto_sign_keypair() function randomly generates a secret key and a corresponding public key.
|
||||
* The public key is put into pk (crypto_sign_PUBLICKEYBYTES bytes) and the secret key into sk (crypto_sign_SECRETKEYBYTES bytes).
|
||||
* Using crypto_sign_seed_keypair(), the key pair can also be deterministically derived from a single key seed (crypto_sign_SEEDBYTES bytes).
|
||||
*/
|
||||
fun seedKeypair(seed: UByteArray): SignKeyPair
|
||||
fun seedKeypair(seed: UByteArray): SignatureKeyPair
|
||||
|
||||
/**
|
||||
* The crypto_sign() function prepends a signature to a message m whose length is mlen bytes, using the secret key sk.
|
||||
@@ -56,9 +57,16 @@ expect object Signature {
|
||||
* The crypto_sign_verify_detached() function verifies that sig is a valid signature for the message m whose length
|
||||
* is mlen bytes, using the signer's public key pk.
|
||||
*/
|
||||
fun verifyDetached(signature: UByteArray, message: UByteArray, publicKey: UByteArray): Boolean
|
||||
fun ed25519PkToCurve25519()
|
||||
fun ed25519SkToCurve25519()
|
||||
fun verifyDetached(signature: UByteArray, message: UByteArray, publicKey: UByteArray)
|
||||
/**
|
||||
* The crypto_sign_ed25519_pk_to_curve25519() function converts an Ed25519 public key ed25519_pk to an X25519 public key and stores it into x25519_pk.
|
||||
*/
|
||||
fun ed25519PkToCurve25519(ed25519PublicKey: UByteArray) : UByteArray
|
||||
|
||||
/**
|
||||
* The crypto_sign_ed25519_sk_to_curve25519() function converts an Ed25519 secret key ed25519_sk to an X25519 secret key and stores it into x25519_sk.
|
||||
*/
|
||||
fun ed25519SkToCurve25519(ed25519SecretKey: UByteArray) : UByteArray
|
||||
|
||||
/**
|
||||
* The secret key actually includes the seed (either a random seed or the one given to crypto_sign_seed_keypair()) as well as the public key.
|
||||
|
||||
Reference in new issue
Block a user