Adding pull secretstream definition
This commit is contained in:
parent
28995c065f
commit
df87dae376
@ -126,7 +126,9 @@ enum class TypeDefinition(override val typeName: TypeName) : GeneralTypeDefiniti
|
|||||||
INT(Int::class.asTypeName()),
|
INT(Int::class.asTypeName()),
|
||||||
STRING(String::class.asTypeName()),
|
STRING(String::class.asTypeName()),
|
||||||
UNIT(Unit::class.asTypeName()),
|
UNIT(Unit::class.asTypeName()),
|
||||||
UBYTE(UByte::class.asTypeName())
|
UBYTE(UByte::class.asTypeName()),
|
||||||
|
IRRELEVANT(Unit::class.asTypeName()),
|
||||||
|
NULL(Unit::class.asTypeName())
|
||||||
}
|
}
|
||||||
|
|
||||||
enum class TargetPlatform {
|
enum class TargetPlatform {
|
||||||
|
@ -68,7 +68,7 @@ fun ClassDefinition.defineSecretStreamFunctions() {
|
|||||||
+funcDef(
|
+funcDef(
|
||||||
"crypto_secretstream_xchacha20poly1305_init_push",
|
"crypto_secretstream_xchacha20poly1305_init_push",
|
||||||
codeDocumentation = """
|
codeDocumentation = """
|
||||||
Initialize a state and generate a random header. Both are returned inside `SecretStreamStateAndHeader` object
|
Initialize a state and generate a random header. Both are returned inside `SecretStreamStateAndHeader` object.
|
||||||
""".trimIndent(),
|
""".trimIndent(),
|
||||||
returnType = CustomTypeDefinition(withPackageName("SecretStreamStateAndHeader")),
|
returnType = CustomTypeDefinition(withPackageName("SecretStreamStateAndHeader")),
|
||||||
dynamicJsReturn = true,
|
dynamicJsReturn = true,
|
||||||
@ -81,6 +81,32 @@ fun ClassDefinition.defineSecretStreamFunctions() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
+funcDef(
|
||||||
|
"crypto_secretstream_xchacha20poly1305_init_pull",
|
||||||
|
codeDocumentation = """
|
||||||
|
Initialize state from header and key. The state can then be used for decryption.
|
||||||
|
""".trimIndent(),
|
||||||
|
returnType = CustomTypeDefinition(withPackageName("SecretStreamState")),
|
||||||
|
dynamicJsReturn = true,
|
||||||
|
isStateCreationFunction = true,
|
||||||
|
) {
|
||||||
|
+ParameterDefinition(
|
||||||
|
"state",
|
||||||
|
parameterType = CustomTypeDefinition(withPackageName("SecretStreamState")),
|
||||||
|
dropParameterFromDefinition = true,
|
||||||
|
isStateType = true
|
||||||
|
)
|
||||||
|
+ParameterDefinition(
|
||||||
|
"header",
|
||||||
|
parameterType = TypeDefinition.ARRAY_OF_UBYTES_NO_SIZE
|
||||||
|
)
|
||||||
|
+ParameterDefinition(
|
||||||
|
"key",
|
||||||
|
parameterType = TypeDefinition.ARRAY_OF_UBYTES_NO_SIZE
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
+funcDef(
|
+funcDef(
|
||||||
name = "crypto_secretstream_xchacha20poly1305_push",
|
name = "crypto_secretstream_xchacha20poly1305_push",
|
||||||
codeDocumentation = """
|
codeDocumentation = """
|
||||||
@ -94,10 +120,15 @@ fun ClassDefinition.defineSecretStreamFunctions() {
|
|||||||
)
|
)
|
||||||
+ParameterDefinition(
|
+ParameterDefinition(
|
||||||
"c",
|
"c",
|
||||||
TypeDefinition.ARRAY_OF_UBYTES_LONG_SIZE,
|
TypeDefinition.ARRAY_OF_UBYTES_NO_SIZE,
|
||||||
isActuallyAnOutputParam = true,
|
isActuallyAnOutputParam = true,
|
||||||
dropParameterFromDefinition = true
|
dropParameterFromDefinition = true
|
||||||
)
|
)
|
||||||
|
+ParameterDefinition(
|
||||||
|
"clen",
|
||||||
|
TypeDefinition.NULL,
|
||||||
|
dropParameterFromDefinition = true
|
||||||
|
)
|
||||||
+ParameterDefinition(
|
+ParameterDefinition(
|
||||||
"m",
|
"m",
|
||||||
TypeDefinition.ARRAY_OF_UBYTES_LONG_SIZE,
|
TypeDefinition.ARRAY_OF_UBYTES_LONG_SIZE,
|
||||||
@ -113,5 +144,43 @@ fun ClassDefinition.defineSecretStreamFunctions() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
+funcDef(
|
||||||
|
name = "crypto_secretstream_xchacha20poly1305_pull",
|
||||||
|
codeDocumentation = """
|
||||||
|
Decrypt next block of data using the previously initialized state. Returns decrypted block.
|
||||||
|
""".trimIndent(),
|
||||||
|
returnType = TypeDefinition.ARRAY_OF_UBYTES
|
||||||
|
) {
|
||||||
|
+ParameterDefinition(
|
||||||
|
"state",
|
||||||
|
CustomTypeDefinition(withPackageName("SecretStreamState"))
|
||||||
|
)
|
||||||
|
+ParameterDefinition(
|
||||||
|
"m",
|
||||||
|
TypeDefinition.ARRAY_OF_UBYTES_NO_SIZE,
|
||||||
|
isActuallyAnOutputParam = true,
|
||||||
|
dropParameterFromDefinition = true
|
||||||
|
)
|
||||||
|
+ParameterDefinition(
|
||||||
|
"mlen",
|
||||||
|
TypeDefinition.NULL,
|
||||||
|
dropParameterFromDefinition = true
|
||||||
|
)
|
||||||
|
+ParameterDefinition(
|
||||||
|
"tag_p",
|
||||||
|
TypeDefinition.NULL
|
||||||
|
)
|
||||||
|
+ParameterDefinition(
|
||||||
|
"c",
|
||||||
|
TypeDefinition.ARRAY_OF_UBYTES_LONG_SIZE,
|
||||||
|
modifiesReturn = true
|
||||||
|
)
|
||||||
|
+ParameterDefinition(
|
||||||
|
"ad",
|
||||||
|
TypeDefinition.ARRAY_OF_UBYTES_LONG_SIZE
|
||||||
|
)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package com.ionspin.kotlin.crypto.generator.libsodium.generator
|
|||||||
import com.ionspin.kotlin.crypto.generator.libsodium.definitions.FunctionDefinition
|
import com.ionspin.kotlin.crypto.generator.libsodium.definitions.FunctionDefinition
|
||||||
import com.ionspin.kotlin.crypto.generator.libsodium.definitions.InnerClassDefinition
|
import com.ionspin.kotlin.crypto.generator.libsodium.definitions.InnerClassDefinition
|
||||||
import com.ionspin.kotlin.crypto.generator.libsodium.definitions.KotlinFileDefinition
|
import com.ionspin.kotlin.crypto.generator.libsodium.definitions.KotlinFileDefinition
|
||||||
|
import com.ionspin.kotlin.crypto.generator.libsodium.definitions.TypeDefinition
|
||||||
import com.squareup.kotlinpoet.*
|
import com.squareup.kotlinpoet.*
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -56,9 +57,11 @@ object CommonLibsodiumGenerator {
|
|||||||
var actualReturnTypeFound : Boolean = false
|
var actualReturnTypeFound : Boolean = false
|
||||||
for (paramDefinition in methodDefinition.parameterList) {
|
for (paramDefinition in methodDefinition.parameterList) {
|
||||||
if ((paramDefinition.isStateType.not() || methodDefinition.isStateCreationFunction.not()) && paramDefinition.dropParameterFromDefinition.not()) {
|
if ((paramDefinition.isStateType.not() || methodDefinition.isStateCreationFunction.not()) && paramDefinition.dropParameterFromDefinition.not()) {
|
||||||
val parameterSpec =
|
if (paramDefinition.parameterType != TypeDefinition.NULL) {
|
||||||
ParameterSpec.builder(paramDefinition.parameterName, paramDefinition.parameterType.typeName)
|
val parameterSpec =
|
||||||
methodBuilder.addParameter(parameterSpec.build())
|
ParameterSpec.builder(paramDefinition.parameterName, paramDefinition.parameterType.typeName)
|
||||||
|
methodBuilder.addParameter(parameterSpec.build())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (paramDefinition.isActuallyAnOutputParam) {
|
if (paramDefinition.isActuallyAnOutputParam) {
|
||||||
actualReturnTypeFound = true
|
actualReturnTypeFound = true
|
||||||
|
@ -68,9 +68,11 @@ object JsLibsodiumGenerator {
|
|||||||
var actualReturnTypeFound: Boolean = false
|
var actualReturnTypeFound: Boolean = false
|
||||||
for (paramDefinition in methodDefinition.parameterList) {
|
for (paramDefinition in methodDefinition.parameterList) {
|
||||||
if ((paramDefinition.isStateType.not() || methodDefinition.isStateCreationFunction.not()) && paramDefinition.isActuallyAnOutputParam.not()) {
|
if ((paramDefinition.isStateType.not() || methodDefinition.isStateCreationFunction.not()) && paramDefinition.isActuallyAnOutputParam.not()) {
|
||||||
val parameterSpec =
|
if (paramDefinition.parameterType != TypeDefinition.NULL) {
|
||||||
ParameterSpec.builder(paramDefinition.parameterName, paramDefinition.parameterType.typeName)
|
val parameterSpec =
|
||||||
methodBuilder.addParameter(parameterSpec.build())
|
ParameterSpec.builder(paramDefinition.parameterName, paramDefinition.parameterType.typeName)
|
||||||
|
methodBuilder.addParameter(parameterSpec.build())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (paramDefinition.modifiesReturn) {
|
if (paramDefinition.modifiesReturn) {
|
||||||
if (returnModifierFound == true) {
|
if (returnModifierFound == true) {
|
||||||
@ -158,7 +160,7 @@ object JsLibsodiumGenerator {
|
|||||||
paramsBuilder.append(paramDefinition.parameterName + ".toUInt8Array()" + separator)
|
paramsBuilder.append(paramDefinition.parameterName + ".toUInt8Array()" + separator)
|
||||||
}
|
}
|
||||||
TypeDefinition.ARRAY_OF_UBYTES_LONG_SIZE -> {
|
TypeDefinition.ARRAY_OF_UBYTES_LONG_SIZE -> {
|
||||||
paramsBuilder.append(paramDefinition.parameterName + ".toUInt8Array(), " + separator)
|
paramsBuilder.append(paramDefinition.parameterName + ".toUInt8Array()" + separator)
|
||||||
}
|
}
|
||||||
TypeDefinition.ARRAY_OF_UBYTES_NO_SIZE -> {
|
TypeDefinition.ARRAY_OF_UBYTES_NO_SIZE -> {
|
||||||
paramsBuilder.append(paramDefinition.parameterName + ".toUInt8Array()" + separator)
|
paramsBuilder.append(paramDefinition.parameterName + ".toUInt8Array()" + separator)
|
||||||
@ -175,6 +177,10 @@ object JsLibsodiumGenerator {
|
|||||||
TypeDefinition.UBYTE -> {
|
TypeDefinition.UBYTE -> {
|
||||||
paramsBuilder.append(paramDefinition.parameterName + separator)
|
paramsBuilder.append(paramDefinition.parameterName + separator)
|
||||||
}
|
}
|
||||||
|
TypeDefinition.NULL -> {
|
||||||
|
println("Got null parameter in js")
|
||||||
|
// paramsBuilder.append("null" + separator)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,9 +63,11 @@ object JvmLibsodiumGenerator {
|
|||||||
createStateParam(paramDefinition, methodBuilder)
|
createStateParam(paramDefinition, methodBuilder)
|
||||||
}
|
}
|
||||||
if ((paramDefinition.isStateType.not() || methodDefinition.isStateCreationFunction.not()) && paramDefinition.isActuallyAnOutputParam.not()) {
|
if ((paramDefinition.isStateType.not() || methodDefinition.isStateCreationFunction.not()) && paramDefinition.isActuallyAnOutputParam.not()) {
|
||||||
val parameterSpec =
|
if (paramDefinition.parameterType != TypeDefinition.NULL) {
|
||||||
ParameterSpec.builder(paramDefinition.parameterName, paramDefinition.parameterType.typeName)
|
val parameterSpec =
|
||||||
methodBuilder.addParameter(parameterSpec.build())
|
ParameterSpec.builder(paramDefinition.parameterName, paramDefinition.parameterType.typeName)
|
||||||
|
methodBuilder.addParameter(parameterSpec.build())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (paramDefinition.modifiesReturn) {
|
if (paramDefinition.modifiesReturn) {
|
||||||
if (returnModifierFound == true) {
|
if (returnModifierFound == true) {
|
||||||
@ -213,7 +215,10 @@ object JvmLibsodiumGenerator {
|
|||||||
paramsBuilder.append(paramDefinition.parameterName + separator)
|
paramsBuilder.append(paramDefinition.parameterName + separator)
|
||||||
}
|
}
|
||||||
TypeDefinition.UBYTE -> {
|
TypeDefinition.UBYTE -> {
|
||||||
paramsBuilder.append(paramDefinition.parameterName + separator)
|
paramsBuilder.append(paramDefinition.parameterName + ".toByte()" + separator)
|
||||||
|
}
|
||||||
|
TypeDefinition.NULL -> {
|
||||||
|
paramsBuilder.append("null" + separator)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -78,9 +78,11 @@ object NativeLibsodiumGenerator {
|
|||||||
createStateParam(paramDefinition, methodBuilder)
|
createStateParam(paramDefinition, methodBuilder)
|
||||||
}
|
}
|
||||||
if ((paramDefinition.isStateType.not() || methodDefinition.isStateCreationFunction.not()) && paramDefinition.isActuallyAnOutputParam.not()) {
|
if ((paramDefinition.isStateType.not() || methodDefinition.isStateCreationFunction.not()) && paramDefinition.isActuallyAnOutputParam.not()) {
|
||||||
val parameterSpec =
|
if (paramDefinition.parameterType != TypeDefinition.NULL) {
|
||||||
ParameterSpec.builder(paramDefinition.parameterName, paramDefinition.parameterType.typeName)
|
val parameterSpec =
|
||||||
methodBuilder.addParameter(parameterSpec.build())
|
ParameterSpec.builder(paramDefinition.parameterName, paramDefinition.parameterType.typeName)
|
||||||
|
methodBuilder.addParameter(parameterSpec.build())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (paramDefinition.modifiesReturn) {
|
if (paramDefinition.modifiesReturn) {
|
||||||
if (returnModifierFound == true) {
|
if (returnModifierFound == true) {
|
||||||
@ -293,6 +295,9 @@ object NativeLibsodiumGenerator {
|
|||||||
TypeDefinition.UBYTE -> {
|
TypeDefinition.UBYTE -> {
|
||||||
paramsBuilder.append(paramDefinition.parameterName + separator)
|
paramsBuilder.append(paramDefinition.parameterName + separator)
|
||||||
}
|
}
|
||||||
|
TypeDefinition.NULL -> {
|
||||||
|
paramsBuilder.append("null" + separator)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,3 +12,4 @@ import org.junit.Test
|
|||||||
class DebugTest {
|
class DebugTest {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,10 +38,16 @@ expect class Crypto internal constructor() {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize a state and generate a random header. Both are returned inside
|
* Initialize a state and generate a random header. Both are returned inside
|
||||||
* `SecretStreamStateAndHeader` object
|
* `SecretStreamStateAndHeader` object.
|
||||||
*/
|
*/
|
||||||
fun crypto_secretstream_xchacha20poly1305_init_push(key: UByteArray): SecretStreamStateAndHeader
|
fun crypto_secretstream_xchacha20poly1305_init_push(key: UByteArray): SecretStreamStateAndHeader
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize state from header and key. The state can then be used for decryption.
|
||||||
|
*/
|
||||||
|
fun crypto_secretstream_xchacha20poly1305_init_pull(header: UByteArray, key: UByteArray):
|
||||||
|
SecretStreamState
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Encrypt next block of data using the previously initialized state. Returns encrypted block.
|
* Encrypt next block of data using the previously initialized state. Returns encrypted block.
|
||||||
*/
|
*/
|
||||||
@ -51,4 +57,13 @@ expect class Crypto internal constructor() {
|
|||||||
ad: UByteArray,
|
ad: UByteArray,
|
||||||
tag: UByte
|
tag: UByte
|
||||||
): UByteArray
|
): UByteArray
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decrypt next block of data using the previously initialized state. Returns decrypted block.
|
||||||
|
*/
|
||||||
|
fun crypto_secretstream_xchacha20poly1305_pull(
|
||||||
|
state: SecretStreamState,
|
||||||
|
c: UByteArray,
|
||||||
|
ad: UByteArray
|
||||||
|
): UByteArray
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ actual class Crypto internal actual constructor() {
|
|||||||
|
|
||||||
actual fun crypto_hash_sha256_update(state: Sha256State, input: UByteArray) {
|
actual fun crypto_hash_sha256_update(state: Sha256State, input: UByteArray) {
|
||||||
println("Debug crypto_hash_sha256_update")
|
println("Debug crypto_hash_sha256_update")
|
||||||
getSodium().crypto_hash_sha256_update(state, input.toUInt8Array(), )
|
getSodium().crypto_hash_sha256_update(state, input.toUInt8Array())
|
||||||
}
|
}
|
||||||
|
|
||||||
actual fun crypto_hash_sha256_final(state: Sha256State): UByteArray {
|
actual fun crypto_hash_sha256_final(state: Sha256State): UByteArray {
|
||||||
@ -46,7 +46,7 @@ actual class Crypto internal actual constructor() {
|
|||||||
|
|
||||||
actual fun crypto_hash_sha512_update(state: Sha512State, input: UByteArray) {
|
actual fun crypto_hash_sha512_update(state: Sha512State, input: UByteArray) {
|
||||||
println("Debug crypto_hash_sha512_update")
|
println("Debug crypto_hash_sha512_update")
|
||||||
getSodium().crypto_hash_sha512_update(state, input.toUInt8Array(), )
|
getSodium().crypto_hash_sha512_update(state, input.toUInt8Array())
|
||||||
}
|
}
|
||||||
|
|
||||||
actual fun crypto_hash_sha512_final(state: Sha512State): UByteArray {
|
actual fun crypto_hash_sha512_final(state: Sha512State): UByteArray {
|
||||||
@ -61,7 +61,7 @@ actual class Crypto internal actual constructor() {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize a state and generate a random header. Both are returned inside
|
* Initialize a state and generate a random header. Both are returned inside
|
||||||
* `SecretStreamStateAndHeader` object
|
* `SecretStreamStateAndHeader` object.
|
||||||
*/
|
*/
|
||||||
actual fun crypto_secretstream_xchacha20poly1305_init_push(key: UByteArray): dynamic {
|
actual fun crypto_secretstream_xchacha20poly1305_init_push(key: UByteArray): dynamic {
|
||||||
println("Debug crypto_secretstream_xchacha20poly1305_init_push")
|
println("Debug crypto_secretstream_xchacha20poly1305_init_push")
|
||||||
@ -72,6 +72,16 @@ actual class Crypto internal actual constructor() {
|
|||||||
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):
|
||||||
|
dynamic {
|
||||||
|
println("Debug crypto_secretstream_xchacha20poly1305_init_pull")
|
||||||
|
return getSodium().crypto_secretstream_xchacha20poly1305_init_pull(header.toUInt8Array(),
|
||||||
|
key.toUInt8Array())
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Encrypt next block of data using the previously initialized state. Returns encrypted block.
|
* Encrypt next block of data using the previously initialized state. Returns encrypted block.
|
||||||
*/
|
*/
|
||||||
@ -82,7 +92,20 @@ actual class Crypto internal actual constructor() {
|
|||||||
tag: UByte
|
tag: UByte
|
||||||
): UByteArray {
|
): UByteArray {
|
||||||
println("Debug crypto_secretstream_xchacha20poly1305_push")
|
println("Debug crypto_secretstream_xchacha20poly1305_push")
|
||||||
return getSodium().crypto_secretstream_xchacha20poly1305_push(state, m.toUInt8Array(), ,
|
return getSodium().crypto_secretstream_xchacha20poly1305_push(state, m.toUInt8Array(),
|
||||||
ad.toUInt8Array(), , tag).toUByteArray()
|
ad.toUInt8Array(), tag).toUByteArray()
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decrypt next block of data using the previously initialized state. Returns decrypted block.
|
||||||
|
*/
|
||||||
|
actual fun crypto_secretstream_xchacha20poly1305_pull(
|
||||||
|
state: SecretStreamState,
|
||||||
|
c: UByteArray,
|
||||||
|
ad: UByteArray
|
||||||
|
): UByteArray {
|
||||||
|
println("Debug crypto_secretstream_xchacha20poly1305_pull")
|
||||||
|
return getSodium().crypto_secretstream_xchacha20poly1305_pull(state, c.toUInt8Array(),
|
||||||
|
ad.toUInt8Array()).toUByteArray()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -70,7 +70,7 @@ actual class Crypto internal actual constructor() {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize a state and generate a random header. Both are returned inside
|
* Initialize a state and generate a random header. Both are returned inside
|
||||||
* `SecretStreamStateAndHeader` object
|
* `SecretStreamStateAndHeader` object.
|
||||||
*/
|
*/
|
||||||
actual fun crypto_secretstream_xchacha20poly1305_init_push(key: UByteArray):
|
actual fun crypto_secretstream_xchacha20poly1305_init_push(key: UByteArray):
|
||||||
SecretStreamStateAndHeader {
|
SecretStreamStateAndHeader {
|
||||||
@ -82,6 +82,18 @@ actual class Crypto internal actual constructor() {
|
|||||||
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 {
|
||||||
|
val state = debug.test.SecretStreamState()
|
||||||
|
println("Debug crypto_secretstream_xchacha20poly1305_init_pull")
|
||||||
|
sodium.crypto_secretstream_xchacha20poly1305_init_pull(state, header.asByteArray(),
|
||||||
|
key.asByteArray())
|
||||||
|
return state
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Encrypt next block of data using the previously initialized state. Returns encrypted block.
|
* Encrypt next block of data using the previously initialized state. Returns encrypted block.
|
||||||
*/
|
*/
|
||||||
@ -93,8 +105,23 @@ actual class Crypto internal actual constructor() {
|
|||||||
): UByteArray {
|
): UByteArray {
|
||||||
val c = UByteArray(m.size)
|
val c = UByteArray(m.size)
|
||||||
println("Debug crypto_secretstream_xchacha20poly1305_push")
|
println("Debug crypto_secretstream_xchacha20poly1305_push")
|
||||||
sodium.crypto_secretstream_xchacha20poly1305_push(state, c.asByteArray(), c.size.toLong(),
|
sodium.crypto_secretstream_xchacha20poly1305_push(state, c.asByteArray(), null, m.asByteArray(),
|
||||||
m.asByteArray(), m.size.toLong(), ad.asByteArray(), ad.size.toLong(), tag)
|
m.size.toLong(), ad.asByteArray(), ad.size.toLong(), tag.toByte())
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decrypt next block of data using the previously initialized state. Returns decrypted block.
|
||||||
|
*/
|
||||||
|
actual fun crypto_secretstream_xchacha20poly1305_pull(
|
||||||
|
state: SecretStreamState,
|
||||||
|
c: UByteArray,
|
||||||
|
ad: UByteArray
|
||||||
|
): UByteArray {
|
||||||
|
val m = UByteArray(c.size)
|
||||||
|
println("Debug crypto_secretstream_xchacha20poly1305_pull")
|
||||||
|
sodium.crypto_secretstream_xchacha20poly1305_pull(state, m.asByteArray(), null, null,
|
||||||
|
c.asByteArray(), c.size.toLong(), ad.asByteArray(), ad.size.toLong())
|
||||||
|
return m
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -96,7 +96,7 @@ actual class Crypto internal actual constructor() {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize a state and generate a random header. Both are returned inside
|
* Initialize a state and generate a random header. Both are returned inside
|
||||||
* `SecretStreamStateAndHeader` object
|
* `SecretStreamStateAndHeader` object.
|
||||||
*/
|
*/
|
||||||
actual fun crypto_secretstream_xchacha20poly1305_init_push(key: UByteArray):
|
actual fun crypto_secretstream_xchacha20poly1305_init_push(key: UByteArray):
|
||||||
SecretStreamStateAndHeader {
|
SecretStreamStateAndHeader {
|
||||||
@ -116,6 +116,23 @@ actual class Crypto internal actual constructor() {
|
|||||||
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 {
|
||||||
|
val allocated = sodium_malloc(debug.test.SecretStreamState.size.convert())!!
|
||||||
|
val state = allocated.reinterpret<debug.test.SecretStreamState>().pointed
|
||||||
|
println("Debug crypto_secretstream_xchacha20poly1305_init_pull")
|
||||||
|
val pinnedHeader = header.pin()
|
||||||
|
val pinnedKey = key.pin()
|
||||||
|
libsodium.crypto_secretstream_xchacha20poly1305_init_pull(state.ptr, pinnedHeader.addressOf(0),
|
||||||
|
pinnedKey.addressOf(0))
|
||||||
|
pinnedHeader.unpin()
|
||||||
|
pinnedKey.unpin()
|
||||||
|
return state
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Encrypt next block of data using the previously initialized state. Returns encrypted block.
|
* Encrypt next block of data using the previously initialized state. Returns encrypted block.
|
||||||
*/
|
*/
|
||||||
@ -130,12 +147,32 @@ actual class Crypto internal actual constructor() {
|
|||||||
val pinnedC = c.pin()
|
val pinnedC = c.pin()
|
||||||
val pinnedM = m.pin()
|
val pinnedM = m.pin()
|
||||||
val pinnedAd = ad.pin()
|
val pinnedAd = ad.pin()
|
||||||
libsodium.crypto_secretstream_xchacha20poly1305_push(state.ptr, pinnedC.addressOf(0),
|
libsodium.crypto_secretstream_xchacha20poly1305_push(state.ptr, pinnedC.addressOf(0), null,
|
||||||
c.size.convert(), pinnedM.addressOf(0), m.size.convert(), pinnedAd.addressOf(0),
|
pinnedM.addressOf(0), m.size.convert(), pinnedAd.addressOf(0), ad.size.convert(), tag)
|
||||||
ad.size.convert(), tag)
|
|
||||||
pinnedC.unpin()
|
pinnedC.unpin()
|
||||||
pinnedM.unpin()
|
pinnedM.unpin()
|
||||||
pinnedAd.unpin()
|
pinnedAd.unpin()
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decrypt next block of data using the previously initialized state. Returns decrypted block.
|
||||||
|
*/
|
||||||
|
actual fun crypto_secretstream_xchacha20poly1305_pull(
|
||||||
|
state: SecretStreamState,
|
||||||
|
c: UByteArray,
|
||||||
|
ad: UByteArray
|
||||||
|
): UByteArray {
|
||||||
|
val m = UByteArray(c.size)
|
||||||
|
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())
|
||||||
|
pinnedM.unpin()
|
||||||
|
pinnedC.unpin()
|
||||||
|
pinnedAd.unpin()
|
||||||
|
return m
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user