Dropping AES gcm from public api as it's not portable in libsodium and going the xchacha20poly1305 as only AEAD

This commit is contained in:
Ugljesa Jovanovic authored and Ugljesa Jovanovic committed 2020-06-14 17:05:28 +02:00
1 parent 5c10d3abf4
commit e24f0a29f2
12 files changed
+279 -38

No files matched your search

@@ -6,10 +6,10 @@ package com.ionspin.kotlin.crypto.authenticated
* on 14-Jun-2020
*/
interface Aes256GcmStateless {
/**
* Nonce autogenerated, key autogenerated
*/
fun encrypt(message: UByteArray, additionalData: UByteArray, rawData : UByteArray) : Aes256GcmEncryptionResult
fun encrypt(message: UByteArray, additionalData: UByteArray, rawData : UByteArray, key: Aes256GcmKey) : Aes256GcmEncryptionResult
fun decrypt(encryptedData: UByteArray, nonce: UByteArray, key : Aes256GcmKey) : UByteArray
}
data class Aes256GcmEncryptionResult(val cyphertext : UByteArray, val additionalData: UByteArray, val nonce: UByteArray, val tag: UByteArray) {
@@ -35,3 +35,8 @@ data class Aes256GcmEncryptionResult(val cyphertext : UByteArray, val additional
return result
}
}
interface Aes256GcmKey {
val key : UByteArray
}
@@ -0,0 +1,8 @@
package com.ionspin.kotlin.crypto.authenticated
/**
* Created by Ugljesa Jovanovic
* ugljesa.jovanovic@ionspin.com
* on 14-Jun-2020
*/
interface XChaCha20Poly1305
@@ -0,0 +1,47 @@
package com.ionspin.kotlin.crypto.symmetric
/**
* Created by Ugljesa Jovanovic
* ugljesa.jovanovic@ionspin.com
* on 14-Jun-2020
*/
interface XChaCha20 {
interface Nonce {
val content: UByteArray
}
interface Key {
val content : UByteArray
}
fun encrypt(key: Key, inputMessage: UByteArray) : XChaCha20EncryptionResult
fun decrypt(key: Key, nonce: Nonce) : UByteArray
}
data class XChaCha20EncryptionResult(val nonce: UByteArray, val encryptionData: UByteArray) {
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other == null || this::class != other::class) return false
other as XChaCha20EncryptionResult
if (nonce != other.nonce) return false
if (encryptionData != other.encryptionData) return false
return true
}
override fun hashCode(): Int {
var result = nonce.hashCode()
result = 31 * result + encryptionData.hashCode()
return result
}
}
interface XChaCha20KeyProvider {
fun generateNewKey() : XChaCha20.Key
fun createFromUByteArray(uByteArray: UByteArray) : XChaCha20.Key
}