Change all occurences of additionalData to associatedData
This commit is contained in:
1 parent
54489ef6cb
commit
3de04749ba
21 files changed
+142
-142
No files matched your search
+2
-2
@@ -27,9 +27,9 @@ class SecretStreamCorrupedOrTamperedDataException() : RuntimeException("MAC vali
|
||||
expect object SecretStream {
|
||||
|
||||
fun xChaCha20Poly1305InitPush(key: UByteArray) : SecretStreamStateAndHeader
|
||||
fun xChaCha20Poly1305Push(state : SecretStreamState, message: UByteArray, additionalData : UByteArray = ubyteArrayOf(), tag: UByte) : UByteArray
|
||||
fun xChaCha20Poly1305Push(state : SecretStreamState, message: UByteArray, associatedData : UByteArray = ubyteArrayOf(), tag: UByte) : UByteArray
|
||||
fun xChaCha20Poly1305InitPull(key: UByteArray, header: UByteArray) : SecretStreamStateAndHeader
|
||||
fun xChaCha20Poly1305Pull(state : SecretStreamState, ciphertext: UByteArray, additionalData : UByteArray = ubyteArrayOf()) : DecryptedDataAndTag
|
||||
fun xChaCha20Poly1305Pull(state : SecretStreamState, ciphertext: UByteArray, associatedData : UByteArray = ubyteArrayOf()) : DecryptedDataAndTag
|
||||
fun xChaCha20Poly1305Keygen() : UByteArray
|
||||
fun xChaCha20Poly1305Rekey(state: SecretStreamState)
|
||||
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@ class SecretStreamTest {
|
||||
val message = ("Ladies and Gentlemen of the class of '99: If I could offer you " +
|
||||
"only one tip for the future, sunscreen would be it.").encodeToUByteArray()
|
||||
|
||||
val additionalData = ubyteArrayOf(
|
||||
val associatedData = ubyteArrayOf(
|
||||
0x50U, 0x51U, 0x52U, 0x53U, 0xc0U, 0xc1U, 0xc2U, 0xc3U, 0xc4U, 0xc5U, 0xc6U, 0xc7U
|
||||
)
|
||||
val key = ubyteArrayOf(
|
||||
|
||||
+4
-4
@@ -45,17 +45,17 @@ interface JsSodiumInterface {
|
||||
fun crypto_hash_sha512_final(state: dynamic): Uint8Array
|
||||
|
||||
//XChaCha20Poly1305
|
||||
fun crypto_aead_xchacha20poly1305_ietf_encrypt(message: Uint8Array, additionalData: Uint8Array, secretNonce: Uint8Array, nonce: Uint8Array, key: Uint8Array) : Uint8Array
|
||||
fun crypto_aead_xchacha20poly1305_ietf_decrypt(secretNonce: Uint8Array, ciphertext: Uint8Array, additionalData: Uint8Array, nonce: Uint8Array, key: Uint8Array) : Uint8Array
|
||||
fun crypto_aead_xchacha20poly1305_ietf_encrypt(message: Uint8Array, associatedData: Uint8Array, secretNonce: Uint8Array, nonce: Uint8Array, key: Uint8Array) : Uint8Array
|
||||
fun crypto_aead_xchacha20poly1305_ietf_decrypt(secretNonce: Uint8Array, ciphertext: Uint8Array, associatedData: Uint8Array, nonce: Uint8Array, key: Uint8Array) : Uint8Array
|
||||
|
||||
//XChaCha20Poly1305
|
||||
//encrypt
|
||||
fun crypto_secretstream_xchacha20poly1305_init_push(key: Uint8Array) : dynamic
|
||||
fun crypto_secretstream_xchacha20poly1305_push(state: dynamic, message: Uint8Array, additionalData: Uint8Array, tag: UByte) : Uint8Array
|
||||
fun crypto_secretstream_xchacha20poly1305_push(state: dynamic, message: Uint8Array, associatedData: Uint8Array, tag: UByte) : Uint8Array
|
||||
|
||||
//decrypt
|
||||
fun crypto_secretstream_xchacha20poly1305_init_pull(header: Uint8Array, key: Uint8Array) : dynamic
|
||||
fun crypto_secretstream_xchacha20poly1305_pull(state: dynamic, ciphertext: Uint8Array, additionalData: Uint8Array) : dynamic
|
||||
fun crypto_secretstream_xchacha20poly1305_pull(state: dynamic, ciphertext: Uint8Array, associatedData: Uint8Array) : dynamic
|
||||
|
||||
//keygen and rekey
|
||||
fun crypto_secretstream_xchacha20poly1305_keygen() : Uint8Array
|
||||
|
||||
+4
-4
@@ -16,11 +16,11 @@ actual object SecretStream {
|
||||
actual fun xChaCha20Poly1305Push(
|
||||
state: SecretStreamState,
|
||||
message: UByteArray,
|
||||
additionalData: UByteArray,
|
||||
associatedData: UByteArray,
|
||||
tag: UByte
|
||||
): UByteArray {
|
||||
return getSodium().crypto_secretstream_xchacha20poly1305_push(
|
||||
state, message.toUInt8Array(), additionalData.toUInt8Array(), tag
|
||||
state, message.toUInt8Array(), associatedData.toUInt8Array(), tag
|
||||
).toUByteArray()
|
||||
}
|
||||
|
||||
@@ -35,10 +35,10 @@ actual object SecretStream {
|
||||
actual fun xChaCha20Poly1305Pull(
|
||||
state: SecretStreamState,
|
||||
ciphertext: UByteArray,
|
||||
additionalData: UByteArray
|
||||
associatedData: UByteArray
|
||||
): DecryptedDataAndTag {
|
||||
val dataAndTag = getSodium().crypto_secretstream_xchacha20poly1305_pull(
|
||||
state, ciphertext.toUInt8Array(), additionalData.toUInt8Array()
|
||||
state, ciphertext.toUInt8Array(), associatedData.toUInt8Array()
|
||||
)
|
||||
if (dataAndTag == false) {
|
||||
throw SecretStreamCorrupedOrTamperedDataException()
|
||||
|
||||
+6
-6
@@ -16,7 +16,7 @@ actual object SecretStream {
|
||||
actual fun xChaCha20Poly1305Push(
|
||||
state: SecretStreamState,
|
||||
message: UByteArray,
|
||||
additionalData: UByteArray,
|
||||
associatedData: UByteArray,
|
||||
tag: UByte
|
||||
): UByteArray {
|
||||
val ciphertext = UByteArray(message.size + crypto_secretstream_xchacha20poly1305_ABYTES)
|
||||
@@ -26,8 +26,8 @@ actual object SecretStream {
|
||||
null,
|
||||
message.asByteArray(),
|
||||
message.size.toLong(),
|
||||
additionalData.asByteArray(),
|
||||
additionalData.size.toLong(),
|
||||
associatedData.asByteArray(),
|
||||
associatedData.size.toLong(),
|
||||
tag.toByte()
|
||||
)
|
||||
return ciphertext
|
||||
@@ -45,7 +45,7 @@ actual object SecretStream {
|
||||
actual fun xChaCha20Poly1305Pull(
|
||||
state: SecretStreamState,
|
||||
ciphertext: UByteArray,
|
||||
additionalData: UByteArray
|
||||
associatedData: UByteArray
|
||||
): DecryptedDataAndTag {
|
||||
val result = UByteArray(ciphertext.size - crypto_secretstream_xchacha20poly1305_ABYTES)
|
||||
val tagArray = UByteArray(1) { 0U }
|
||||
@@ -56,8 +56,8 @@ actual object SecretStream {
|
||||
tagArray.asByteArray(),
|
||||
ciphertext.asByteArray(),
|
||||
ciphertext.size.toLong(),
|
||||
additionalData.asByteArray(),
|
||||
additionalData.size.toLong()
|
||||
associatedData.asByteArray(),
|
||||
associatedData.size.toLong()
|
||||
)
|
||||
if (validationResult != 0) {
|
||||
throw SecretStreamCorrupedOrTamperedDataException()
|
||||
|
||||
+12
-12
@@ -40,14 +40,14 @@ actual object SecretStream {
|
||||
actual fun xChaCha20Poly1305Push(
|
||||
state: SecretStreamState,
|
||||
message: UByteArray,
|
||||
additionalData: UByteArray,
|
||||
associatedData: UByteArray,
|
||||
tag: UByte
|
||||
): UByteArray {
|
||||
val ciphertext = UByteArray(message.size + crypto_secretstream_xchacha20poly1305_ABYTES.toInt()) { 0U }
|
||||
val ciphertextPinned = ciphertext.pin()
|
||||
val messagePinned = message.pin()
|
||||
val additionalDataPinned = if (additionalData.isNotEmpty()) {
|
||||
additionalData.pin()
|
||||
val associatedDataPinned = if (associatedData.isNotEmpty()) {
|
||||
associatedData.pin()
|
||||
} else {
|
||||
null
|
||||
}
|
||||
@@ -57,14 +57,14 @@ actual object SecretStream {
|
||||
null,
|
||||
messagePinned.toPtr(),
|
||||
message.size.convert(),
|
||||
additionalDataPinned?.toPtr(),
|
||||
additionalData.size.convert(),
|
||||
associatedDataPinned?.toPtr(),
|
||||
associatedData.size.convert(),
|
||||
tag
|
||||
)
|
||||
|
||||
ciphertextPinned.unpin()
|
||||
messagePinned.unpin()
|
||||
additionalDataPinned?.unpin()
|
||||
associatedDataPinned?.unpin()
|
||||
return ciphertext
|
||||
}
|
||||
|
||||
@@ -89,13 +89,13 @@ actual object SecretStream {
|
||||
actual fun xChaCha20Poly1305Pull(
|
||||
state: SecretStreamState,
|
||||
ciphertext: UByteArray,
|
||||
additionalData: UByteArray
|
||||
associatedData: UByteArray
|
||||
): DecryptedDataAndTag {
|
||||
val message = UByteArray(ciphertext.size - crypto_secretstream_xchacha20poly1305_ABYTES.toInt())
|
||||
val messagePinned = message.pin()
|
||||
val ciphertextPinned = ciphertext.pin()
|
||||
val additionalDataPinned = if (additionalData.isNotEmpty()) {
|
||||
additionalData.pin()
|
||||
val associatedDataPinned = if (associatedData.isNotEmpty()) {
|
||||
associatedData.pin()
|
||||
} else {
|
||||
null
|
||||
}
|
||||
@@ -108,12 +108,12 @@ actual object SecretStream {
|
||||
tagPinned.toPtr(),
|
||||
ciphertextPinned.toPtr(),
|
||||
ciphertext.size.convert(),
|
||||
additionalDataPinned?.toPtr(),
|
||||
additionalData.size.convert()
|
||||
associatedDataPinned?.toPtr(),
|
||||
associatedData.size.convert()
|
||||
)
|
||||
ciphertextPinned.unpin()
|
||||
messagePinned.unpin()
|
||||
additionalDataPinned?.unpin()
|
||||
associatedDataPinned?.unpin()
|
||||
tagPinned.unpin()
|
||||
if (validationResult != 0) {
|
||||
throw SecretStreamCorrupedOrTamperedDataException()
|
||||
|
||||
Reference in new issue
Block a user