Further progress on delegated xchacha poly, working jvm , js in progress
This commit is contained in:
1 parent
e3fe276e4c
commit
6228263978
29 files changed
+419
-131
No files matched your search
+3
@@ -39,5 +39,8 @@ interface JsSodiumInterface {
|
||||
|
||||
fun crypto_hash_sha512_final(state: dynamic): Uint8Array
|
||||
|
||||
//XChaCha20Poly1305
|
||||
fun crypto_aead_xchacha20poly1305_ietf_encrypt(message: Uint8Array, additionalData: Uint8Array, nonce: Uint8Array, key: Uint8Array) : Uint8Array
|
||||
|
||||
|
||||
}
|
||||
+1
-1
@@ -53,4 +53,4 @@ object JsSodiumLoader {
|
||||
doneCallback.invoke()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package ext.libsodium.com.ionspin.kotlin.crypto
|
||||
|
||||
import org.khronos.webgl.Uint8Array
|
||||
import org.khronos.webgl.get
|
||||
import org.khronos.webgl.set
|
||||
|
||||
/**
|
||||
* Created by Ugljesa Jovanovic
|
||||
* ugljesa.jovanovic@ionspin.com
|
||||
* on 25-Jun-2020
|
||||
*/
|
||||
fun UByteArray.toUInt8Array() : Uint8Array {
|
||||
val uint8Result = Uint8Array(toByteArray().toTypedArray())
|
||||
console.log("Uint8: $uint8Result")
|
||||
return uint8Result
|
||||
}
|
||||
|
||||
|
||||
fun Uint8Array.toUByteArray() : UByteArray {
|
||||
val result = UByteArray(length)
|
||||
for (i in 0 until length) {
|
||||
result[i] = get(i).toUByte()
|
||||
}
|
||||
console.log("UbyteArray: ${result.joinToString()}")
|
||||
|
||||
return result
|
||||
}
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
package com.ionspin.kotlin.crypto.authenticated
|
||||
|
||||
import com.ionspin.kotlin.crypto.getSodium
|
||||
import ext.libsodium.com.ionspin.kotlin.crypto.toUByteArray
|
||||
import ext.libsodium.com.ionspin.kotlin.crypto.toUInt8Array
|
||||
|
||||
/**
|
||||
* Created by Ugljesa Jovanovic
|
||||
* ugljesa.jovanovic@ionspin.com
|
||||
* on 25-Jun-2020
|
||||
*/
|
||||
|
||||
/**
|
||||
* Created by Ugljesa Jovanovic
|
||||
* ugljesa.jovanovic@ionspin.com
|
||||
* on 14-Jun-2020
|
||||
*/
|
||||
actual class XChaCha20Poly1305Delegated actual constructor(key: UByteArray, additionalData: UByteArray) {
|
||||
actual companion object {
|
||||
actual fun encrypt(
|
||||
key: UByteArray,
|
||||
nonce: UByteArray,
|
||||
message: UByteArray,
|
||||
additionalData: UByteArray
|
||||
): UByteArray {
|
||||
val encrypted = getSodium().crypto_aead_xchacha20poly1305_ietf_encrypt(
|
||||
message.toUInt8Array(),
|
||||
additionalData.toUInt8Array(),
|
||||
key.toUInt8Array(),
|
||||
nonce.toUInt8Array()
|
||||
)
|
||||
return encrypted.toUByteArray()
|
||||
}
|
||||
|
||||
actual fun decrypt(
|
||||
key: UByteArray,
|
||||
nonce: UByteArray,
|
||||
ciphertext: UByteArray,
|
||||
additionalData: UByteArray
|
||||
): UByteArray {
|
||||
TODO("not implemented yet")
|
||||
}
|
||||
}
|
||||
|
||||
actual fun encryptPartialData(data: UByteArray): UByteArray {
|
||||
TODO("not implemented yet")
|
||||
}
|
||||
|
||||
actual fun verifyPartialData(data: UByteArray) {
|
||||
}
|
||||
|
||||
actual fun checkTag(expectedTag: UByteArray) {
|
||||
}
|
||||
|
||||
actual fun decrypt(data: UByteArray): UByteArray {
|
||||
TODO("not implemented yet")
|
||||
}
|
||||
|
||||
actual fun finishEncryption(): Pair<UByteArray, UByteArray> {
|
||||
TODO("not implemented yet")
|
||||
}
|
||||
|
||||
}
|
||||
+2
-2
@@ -12,7 +12,7 @@ import org.khronos.webgl.get
|
||||
*/
|
||||
|
||||
|
||||
actual class Sha512Delegated : Sha512 {
|
||||
actual class Sha512Delegated : Sha512Multipart {
|
||||
val state : dynamic
|
||||
|
||||
init {
|
||||
@@ -34,7 +34,7 @@ actual class Sha512Delegated : Sha512 {
|
||||
|
||||
}
|
||||
|
||||
actual object Sha512StatelessDelegated : MultipartSha512 {
|
||||
actual object Sha512StatelessDelegated : Sha512 {
|
||||
|
||||
override fun digest(inputMessage: UByteArray): UByteArray {
|
||||
val hashed = getSodium().crypto_hash_sha512(Uint8Array(inputMessage.toByteArray().toTypedArray()))
|
||||
|
||||
Reference in new issue
Block a user