Slow progress.

This commit is contained in:
Ugljesa Jovanovic authored and Ugljesa Jovanovic committed 2020-08-21 18:55:17 +02:00
1 parent cd90f964ab
commit be4468785d
9 files changed
+122 -54

No files matched your search

@@ -20,6 +20,13 @@ data class SecretStreamStateAndHeader(
val header: UByteArray
)
data class DecryptedDataAndTag(
@JsName("decrypted")
val decrypted: UByteArray,
@JsName("tag")
val tag: UByte
)
expect class Crypto internal constructor() {
/**
* Initialize the SHA256 hash
@@ -68,5 +75,5 @@ expect class Crypto internal constructor() {
state: SecretStreamState,
c: UByteArray,
ad: UByteArray
): UByteArray
): DecryptedDataAndTag
}
@@ -65,7 +65,7 @@ class SecretStreamTest {
encrypted.hexColumsPrint()
val decryptState = crypto.crypto_secretstream_xchacha20poly1305_init_pull(stateAndHeader.header, key)
val decrypted =
crypto.crypto_secretstream_xchacha20poly1305_pull(decryptState, encrypted, ubyteArrayOf()) //TODO JS pull returns a tag and a message!!!
crypto.crypto_secretstream_xchacha20poly1305_pull(decryptState, encrypted, ubyteArrayOf())
decrypted.hexColumsPrint()
decrypted.contentEquals(message)
@@ -70,17 +70,17 @@ actual class Crypto internal actual constructor() {
getSodium().crypto_secretstream_xchacha20poly1305_init_push(key.toUInt8Array())
val state = stateAndHeader.state
val header = (stateAndHeader.header as Uint8Array).toUByteArray()
return SecretStreamStateAndHeader(state, header)
return SecretStreamStateAndHeader(state, header)
}
/**
* Initialize state from header and key. The state can then be used for decryption.
*/
actual fun crypto_secretstream_xchacha20poly1305_init_pull(header: UByteArray, key: UByteArray):
SecretStreamState {
dynamic {
println("Debug crypto_secretstream_xchacha20poly1305_init_pull")
return getSodium().crypto_secretstream_xchacha20poly1305_init_pull(header.toUInt8Array(),
key.toUInt8Array()) as SecretStreamState
key.toUInt8Array())
}
/**
@@ -104,9 +104,9 @@ actual class Crypto internal actual constructor() {
state: SecretStreamState,
c: UByteArray,
ad: UByteArray
): UByteArray {
): UByte {
println("Debug crypto_secretstream_xchacha20poly1305_pull")
return getSodium().crypto_secretstream_xchacha20poly1305_pull(state, c.toUInt8Array(),
ad.toUInt8Array()).toUByteArray()
ad.toUInt8Array())
}
}
@@ -117,11 +117,12 @@ actual class Crypto internal actual constructor() {
state: SecretStreamState,
c: UByteArray,
ad: UByteArray
): UByteArray {
): DecryptedDataAndTag {
val m = UByteArray(c.size - 17)
var tag_p : UByte = 0U
println("Debug crypto_secretstream_xchacha20poly1305_pull")
sodium.crypto_secretstream_xchacha20poly1305_pull(state, m.asByteArray(), null, null,
sodium.crypto_secretstream_xchacha20poly1305_pull(state, m.asByteArray(), null, tag_p.toByte(),
c.asByteArray(), c.size.toLong(), ad.asByteArray(), ad.size.toLong())
return m
return debug.test.DecryptedDataAndTag(m, tag_p)
}
}
@@ -162,17 +162,18 @@ actual class Crypto internal actual constructor() {
state: SecretStreamState,
c: UByteArray,
ad: UByteArray
): UByteArray {
): DecryptedDataAndTag {
val m = UByteArray(c.size - 17)
var tag_p : UByte = 0U
println("Debug crypto_secretstream_xchacha20poly1305_pull")
val pinnedM = m.pin()
val pinnedC = c.pin()
val pinnedAd = ad.pin()
libsodium.crypto_secretstream_xchacha20poly1305_pull(state.ptr, pinnedM.addressOf(0), null,
null, pinnedC.addressOf(0), c.size.convert(), pinnedAd.addressOf(0), ad.size.convert())
tag_p, pinnedC.addressOf(0), c.size.convert(), pinnedAd.addressOf(0), ad.size.convert())
pinnedM.unpin()
pinnedC.unpin()
pinnedAd.unpin()
return m
return debug.test.DecryptedDataAndTag(m, tag_p)
}
}