Add Ristretto255 Support
This commit is contained in:
1 parent
4ff2dddf14
commit
6a66654436
7 files changed
+813
No files matched your search
+49
@@ -363,5 +363,54 @@ external object JsSodiumInterface {
|
||||
// ---- 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 ----
|
||||
}
|
||||
+94
@@ -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 abstract class Ristretto255LowLevel actual constructor() {
|
||||
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
|
||||
}
|
||||
|
||||
actual fun encodedPointFromHash(hash: UByteArray): UByteArray {
|
||||
val result = getSodium().crypto_core_ristretto255_from_hash(hash.toUint8Array())
|
||||
|
||||
return result.toUByteArray()
|
||||
}
|
||||
|
||||
actual fun randomEncodedPoint(): UByteArray {
|
||||
val result = getSodium().crypto_core_ristretto255_random()
|
||||
|
||||
return result.toUByteArray()
|
||||
}
|
||||
|
||||
actual fun randomEncodedScalar(): UByteArray {
|
||||
val result = getSodium().crypto_core_ristretto255_scalar_random()
|
||||
|
||||
return result.toUByteArray()
|
||||
}
|
||||
|
||||
actual fun invert(scalar: UByteArray): UByteArray {
|
||||
val result = getSodium().crypto_core_ristretto255_scalar_invert(scalar.toUint8Array())
|
||||
|
||||
return result.toUByteArray()
|
||||
}
|
||||
|
||||
actual fun negate(scalar: UByteArray): UByteArray {
|
||||
val result = getSodium().crypto_core_ristretto255_scalar_negate(scalar.toUint8Array())
|
||||
|
||||
return result.toUByteArray()
|
||||
}
|
||||
|
||||
actual fun complement(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 reduce(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()
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user