Rebase and adapting new functions to wasmJs
This commit is contained in:
parent
bd64211bab
commit
90feb762db
@ -366,5 +366,112 @@ external object JsSodiumInterface: JsAny {
|
||||
// ---- Scalar multiplication end ----
|
||||
|
||||
|
||||
//
|
||||
// ---- Ristretto255 ----
|
||||
|
||||
@JsName("crypto_core_ristretto255_is_valid_point")
|
||||
fun crypto_core_ristretto255_is_valid_point(p: Uint8Array): Boolean
|
||||
|
||||
@JsName("crypto_core_ristretto255_random")
|
||||
fun crypto_core_ristretto255_random(): Uint8Array
|
||||
|
||||
@JsName("crypto_core_ristretto255_from_hash")
|
||||
fun crypto_core_ristretto255_from_hash(r: Uint8Array): Uint8Array
|
||||
|
||||
@JsName("crypto_core_ristretto255_add")
|
||||
fun crypto_core_ristretto255_add(p: Uint8Array, q: Uint8Array): Uint8Array
|
||||
|
||||
@JsName("crypto_core_ristretto255_sub")
|
||||
fun crypto_core_ristretto255_sub(p: Uint8Array, q: Uint8Array): Uint8Array
|
||||
|
||||
@JsName("crypto_core_ristretto255_scalar_random")
|
||||
fun crypto_core_ristretto255_scalar_random(): Uint8Array
|
||||
|
||||
@JsName("crypto_core_ristretto255_scalar_reduce")
|
||||
fun crypto_core_ristretto255_scalar_reduce(s: Uint8Array): Uint8Array
|
||||
|
||||
@JsName("crypto_core_ristretto255_scalar_invert")
|
||||
fun crypto_core_ristretto255_scalar_invert(s: Uint8Array): Uint8Array
|
||||
|
||||
@JsName("crypto_core_ristretto255_scalar_negate")
|
||||
fun crypto_core_ristretto255_scalar_negate(s: Uint8Array): Uint8Array
|
||||
|
||||
@JsName("crypto_core_ristretto255_scalar_complement")
|
||||
fun crypto_core_ristretto255_scalar_complement(s: Uint8Array): Uint8Array
|
||||
|
||||
@JsName("crypto_core_ristretto255_scalar_add")
|
||||
fun crypto_core_ristretto255_scalar_add(x: Uint8Array, y: Uint8Array): Uint8Array
|
||||
|
||||
@JsName("crypto_core_ristretto255_scalar_sub")
|
||||
fun crypto_core_ristretto255_scalar_sub(x: Uint8Array, y: Uint8Array): Uint8Array
|
||||
|
||||
@JsName("crypto_core_ristretto255_scalar_mul")
|
||||
fun crypto_core_ristretto255_scalar_mul(x: Uint8Array, y: Uint8Array): Uint8Array
|
||||
|
||||
@JsName("crypto_scalarmult_ristretto255")
|
||||
fun crypto_scalarmult_ristretto255(n: Uint8Array, p: Uint8Array): Uint8Array
|
||||
|
||||
@JsName("crypto_scalarmult_ristretto255_base")
|
||||
fun crypto_scalarmult_ristretto255_base(n: Uint8Array): Uint8Array
|
||||
|
||||
//
|
||||
// ---- Ristretto255 end ----
|
||||
|
||||
|
||||
//
|
||||
// ---- Ed25519 ----
|
||||
|
||||
@JsName("crypto_core_ed25519_is_valid_point")
|
||||
fun crypto_core_ed25519_is_valid_point(p: Uint8Array): Boolean
|
||||
|
||||
@JsName("crypto_core_ed25519_random")
|
||||
fun crypto_core_ed25519_random(): Uint8Array
|
||||
|
||||
@JsName("crypto_core_ed25519_from_uniform")
|
||||
fun crypto_core_ed25519_from_uniform(r: Uint8Array): Uint8Array
|
||||
|
||||
@JsName("crypto_core_ed25519_add")
|
||||
fun crypto_core_ed25519_add(p: Uint8Array, q: Uint8Array): Uint8Array
|
||||
|
||||
@JsName("crypto_core_ed25519_sub")
|
||||
fun crypto_core_ed25519_sub(p: Uint8Array, q: Uint8Array): Uint8Array
|
||||
|
||||
@JsName("crypto_core_ed25519_scalar_random")
|
||||
fun crypto_core_ed25519_scalar_random(): Uint8Array
|
||||
|
||||
@JsName("crypto_core_ed25519_scalar_reduce")
|
||||
fun crypto_core_ed25519_scalar_reduce(s: Uint8Array): Uint8Array
|
||||
|
||||
@JsName("crypto_core_ed25519_scalar_invert")
|
||||
fun crypto_core_ed25519_scalar_invert(s: Uint8Array): Uint8Array
|
||||
|
||||
@JsName("crypto_core_ed25519_scalar_negate")
|
||||
fun crypto_core_ed25519_scalar_negate(s: Uint8Array): Uint8Array
|
||||
|
||||
@JsName("crypto_core_ed25519_scalar_complement")
|
||||
fun crypto_core_ed25519_scalar_complement(s: Uint8Array): Uint8Array
|
||||
|
||||
@JsName("crypto_core_ed25519_scalar_add")
|
||||
fun crypto_core_ed25519_scalar_add(x: Uint8Array, y: Uint8Array): Uint8Array
|
||||
|
||||
@JsName("crypto_core_ed25519_scalar_sub")
|
||||
fun crypto_core_ed25519_scalar_sub(x: Uint8Array, y: Uint8Array): Uint8Array
|
||||
|
||||
@JsName("crypto_core_ed25519_scalar_mul")
|
||||
fun crypto_core_ed25519_scalar_mul(x: Uint8Array, y: Uint8Array): Uint8Array
|
||||
|
||||
@JsName("crypto_scalarmult_ed25519")
|
||||
fun crypto_scalarmult_ed25519(n: Uint8Array, p: Uint8Array): Uint8Array
|
||||
|
||||
@JsName("crypto_scalarmult_ed25519_noclamp")
|
||||
fun crypto_scalarmult_ed25519_noclamp(n: Uint8Array, p: Uint8Array): Uint8Array
|
||||
|
||||
@JsName("crypto_scalarmult_ed25519_base")
|
||||
fun crypto_scalarmult_ed25519_base(n: Uint8Array): Uint8Array
|
||||
|
||||
@JsName("crypto_scalarmult_ed25519_base_noclamp")
|
||||
fun crypto_scalarmult_ed25519_base_noclamp(n: Uint8Array): Uint8Array
|
||||
|
||||
//
|
||||
// ---- Ed25519 end ----
|
||||
}
|
||||
|
@ -0,0 +1,106 @@
|
||||
package com.ionspin.kotlin.crypto.ed25519
|
||||
|
||||
import com.ionspin.kotlin.crypto.getSodium
|
||||
import ext.libsodium.com.ionspin.kotlin.crypto.toUByteArray
|
||||
import ext.libsodium.com.ionspin.kotlin.crypto.toUInt8Array
|
||||
|
||||
actual object Ed25519LowLevel {
|
||||
actual fun isValidPoint(encoded: UByteArray): Boolean =
|
||||
getSodium().crypto_core_ed25519_is_valid_point(encoded.toUInt8Array())
|
||||
|
||||
actual fun addPoints(p: UByteArray, q: UByteArray): UByteArray {
|
||||
val result = getSodium().crypto_core_ed25519_add(p.toUInt8Array(), q.toUInt8Array())
|
||||
|
||||
return result.toUByteArray()
|
||||
}
|
||||
|
||||
actual fun subtractPoints(p: UByteArray, q: UByteArray): UByteArray {
|
||||
val result = getSodium().crypto_core_ed25519_sub(p.toUInt8Array(), q.toUInt8Array())
|
||||
|
||||
return result.toUByteArray()
|
||||
}
|
||||
|
||||
actual fun pointFromUniform(uniform: UByteArray): UByteArray {
|
||||
val result = getSodium().crypto_core_ed25519_from_uniform(uniform.toUInt8Array())
|
||||
|
||||
return result.toUByteArray()
|
||||
}
|
||||
|
||||
actual fun randomPoint(): UByteArray {
|
||||
val result = getSodium().crypto_core_ed25519_random()
|
||||
|
||||
return result.toUByteArray()
|
||||
}
|
||||
|
||||
actual fun randomScalar(): UByteArray {
|
||||
val result = getSodium().crypto_core_ed25519_scalar_random()
|
||||
|
||||
return result.toUByteArray()
|
||||
}
|
||||
|
||||
actual fun invertScalar(scalar: UByteArray): UByteArray {
|
||||
val result = getSodium().crypto_core_ed25519_scalar_invert(scalar.toUInt8Array())
|
||||
|
||||
return result.toUByteArray()
|
||||
}
|
||||
|
||||
actual fun negateScalar(scalar: UByteArray): UByteArray {
|
||||
val result = getSodium().crypto_core_ed25519_scalar_negate(scalar.toUInt8Array())
|
||||
|
||||
return result.toUByteArray()
|
||||
}
|
||||
|
||||
actual fun complementScalar(scalar: UByteArray): UByteArray {
|
||||
val result = getSodium().crypto_core_ed25519_scalar_complement(scalar.toUInt8Array())
|
||||
|
||||
return result.toUByteArray()
|
||||
}
|
||||
|
||||
actual fun addScalars(x: UByteArray, y: UByteArray): UByteArray {
|
||||
val result = getSodium().crypto_core_ed25519_scalar_add(x.toUInt8Array(), y.toUInt8Array())
|
||||
|
||||
return result.toUByteArray()
|
||||
}
|
||||
|
||||
actual fun subtractScalars(x: UByteArray, y: UByteArray): UByteArray {
|
||||
val result = getSodium().crypto_core_ed25519_scalar_sub(x.toUInt8Array(), y.toUInt8Array())
|
||||
|
||||
return result.toUByteArray()
|
||||
}
|
||||
|
||||
actual fun multiplyScalars(x: UByteArray, y: UByteArray): UByteArray {
|
||||
val result = getSodium().crypto_core_ed25519_scalar_mul(x.toUInt8Array(), y.toUInt8Array())
|
||||
|
||||
return result.toUByteArray()
|
||||
}
|
||||
|
||||
actual fun reduceScalar(scalar: UByteArray): UByteArray {
|
||||
val result = getSodium().crypto_core_ed25519_scalar_reduce(scalar.toUInt8Array())
|
||||
|
||||
return result.toUByteArray()
|
||||
}
|
||||
|
||||
actual fun scalarMultiplication(n: UByteArray, p: UByteArray): UByteArray {
|
||||
val result = getSodium().crypto_scalarmult_ed25519(n.toUInt8Array(), p.toUInt8Array())
|
||||
|
||||
return result.toUByteArray()
|
||||
}
|
||||
|
||||
actual fun scalarMultiplicationNoClamp(n: UByteArray, p: UByteArray): UByteArray {
|
||||
val result = getSodium().crypto_scalarmult_ed25519_noclamp(n.toUInt8Array(), p.toUInt8Array())
|
||||
|
||||
return result.toUByteArray()
|
||||
}
|
||||
|
||||
actual fun scalarMultiplicationBase(n: UByteArray): UByteArray {
|
||||
val result = getSodium().crypto_scalarmult_ed25519_base(n.toUInt8Array())
|
||||
|
||||
return result.toUByteArray()
|
||||
}
|
||||
|
||||
actual fun scalarMultiplicationBaseNoClamp(n: UByteArray): UByteArray {
|
||||
val result = getSodium().crypto_scalarmult_ed25519_base_noclamp(n.toUInt8Array())
|
||||
|
||||
return result.toUByteArray()
|
||||
}
|
||||
}
|
@ -0,0 +1,94 @@
|
||||
package com.ionspin.kotlin.crypto.ristretto255
|
||||
|
||||
import com.ionspin.kotlin.crypto.getSodium
|
||||
import ext.libsodium.com.ionspin.kotlin.crypto.toUByteArray
|
||||
import ext.libsodium.com.ionspin.kotlin.crypto.toUInt8Array
|
||||
|
||||
actual object Ristretto255LowLevel {
|
||||
actual fun isValidPoint(encoded: UByteArray): Boolean =
|
||||
getSodium().crypto_core_ristretto255_is_valid_point(encoded.toUInt8Array())
|
||||
|
||||
actual fun addPoints(p: UByteArray, q: UByteArray): UByteArray {
|
||||
val result = getSodium().crypto_core_ristretto255_add(p.toUInt8Array(), q.toUInt8Array())
|
||||
|
||||
return result.toUByteArray()
|
||||
}
|
||||
|
||||
actual fun subtractPoints(p: UByteArray, q: UByteArray): UByteArray {
|
||||
val result = getSodium().crypto_core_ristretto255_sub(p.toUInt8Array(), q.toUInt8Array())
|
||||
|
||||
return result.toUByteArray()
|
||||
}
|
||||
|
||||
actual fun pointFromHash(hash: UByteArray): UByteArray {
|
||||
val result = getSodium().crypto_core_ristretto255_from_hash(hash.toUInt8Array())
|
||||
|
||||
return result.toUByteArray()
|
||||
}
|
||||
|
||||
actual fun randomPoint(): UByteArray {
|
||||
val result = getSodium().crypto_core_ristretto255_random()
|
||||
|
||||
return result.toUByteArray()
|
||||
}
|
||||
|
||||
actual fun randomScalar(): UByteArray {
|
||||
val result = getSodium().crypto_core_ristretto255_scalar_random()
|
||||
|
||||
return result.toUByteArray()
|
||||
}
|
||||
|
||||
actual fun invertScalar(scalar: UByteArray): UByteArray {
|
||||
val result = getSodium().crypto_core_ristretto255_scalar_invert(scalar.toUInt8Array())
|
||||
|
||||
return result.toUByteArray()
|
||||
}
|
||||
|
||||
actual fun negateScalar(scalar: UByteArray): UByteArray {
|
||||
val result = getSodium().crypto_core_ristretto255_scalar_negate(scalar.toUInt8Array())
|
||||
|
||||
return result.toUByteArray()
|
||||
}
|
||||
|
||||
actual fun complementScalar(scalar: UByteArray): UByteArray {
|
||||
val result = getSodium().crypto_core_ristretto255_scalar_complement(scalar.toUInt8Array())
|
||||
|
||||
return result.toUByteArray()
|
||||
}
|
||||
|
||||
actual fun addScalars(x: UByteArray, y: UByteArray): UByteArray {
|
||||
val result = getSodium().crypto_core_ristretto255_scalar_add(x.toUInt8Array(), y.toUInt8Array())
|
||||
|
||||
return result.toUByteArray()
|
||||
}
|
||||
|
||||
actual fun subtractScalars(x: UByteArray, y: UByteArray): UByteArray {
|
||||
val result = getSodium().crypto_core_ristretto255_scalar_sub(x.toUInt8Array(), y.toUInt8Array())
|
||||
|
||||
return result.toUByteArray()
|
||||
}
|
||||
|
||||
actual fun multiplyScalars(x: UByteArray, y: UByteArray): UByteArray {
|
||||
val result = getSodium().crypto_core_ristretto255_scalar_mul(x.toUInt8Array(), y.toUInt8Array())
|
||||
|
||||
return result.toUByteArray()
|
||||
}
|
||||
|
||||
actual fun reduceScalar(scalar: UByteArray): UByteArray {
|
||||
val result = getSodium().crypto_core_ristretto255_scalar_reduce(scalar.toUInt8Array())
|
||||
|
||||
return result.toUByteArray()
|
||||
}
|
||||
|
||||
actual fun scalarMultiplication(n: UByteArray, p: UByteArray): UByteArray {
|
||||
val result = getSodium().crypto_scalarmult_ristretto255(n.toUInt8Array(), p.toUInt8Array())
|
||||
|
||||
return result.toUByteArray()
|
||||
}
|
||||
|
||||
actual fun scalarMultiplicationBase(n: UByteArray): UByteArray {
|
||||
val result = getSodium().crypto_scalarmult_ristretto255_base(n.toUInt8Array())
|
||||
|
||||
return result.toUByteArray()
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user