Remove all annotations
This commit is contained in:
parent
d901a45b87
commit
3ad86e284a
@ -26,7 +26,7 @@ interface Hash {
|
||||
val MAX_HASH_BYTES : Int
|
||||
}
|
||||
|
||||
@ExperimentalUnsignedTypes
|
||||
|
||||
interface UpdatableHash : Hash {
|
||||
fun update(data : UByteArray)
|
||||
|
||||
@ -37,7 +37,7 @@ interface UpdatableHash : Hash {
|
||||
fun digestString() : String
|
||||
}
|
||||
|
||||
@ExperimentalUnsignedTypes
|
||||
|
||||
interface StatelessHash : Hash {
|
||||
fun digest(inputString: String, key: String? = null, hashLength: Int = MAX_HASH_BYTES): UByteArray
|
||||
|
||||
|
@ -8,11 +8,11 @@ import com.ionspin.kotlin.crypto.hash.UpdatableHash
|
||||
* ugljesa.jovanovic@ionspin.com
|
||||
* on 24-May-2020
|
||||
*/
|
||||
@ExperimentalUnsignedTypes
|
||||
|
||||
interface Blake2b : UpdatableHash
|
||||
@ExperimentalUnsignedTypes
|
||||
|
||||
interface Blake2bStatelessInterface : StatelessHash {
|
||||
@ExperimentalUnsignedTypes
|
||||
|
||||
override val MAX_HASH_BYTES: Int
|
||||
get() = 64
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
package com.ionspin.kotlin.crypto
|
||||
|
||||
import com.ionspin.kotlin.crypto.hash.blake2b.Blake2b
|
||||
import com.ionspin.kotlin.crypto.hash.blake2b.Blake2bDelegated
|
||||
import com.ionspin.kotlin.crypto.hash.blake2b.Blake2bStateless
|
||||
import com.ionspin.kotlin.crypto.hash.sha.Sha256Pure
|
||||
@ -13,18 +12,17 @@ import com.ionspin.kotlin.crypto.hash.sha.Sha512Pure
|
||||
*/
|
||||
|
||||
|
||||
@ExperimentalUnsignedTypes
|
||||
typealias Sha256Stateless = Sha256Pure.Companion
|
||||
@ExperimentalUnsignedTypes
|
||||
|
||||
typealias Sha512Stateless = Sha512Pure.Companion
|
||||
|
||||
@ExperimentalUnsignedTypes
|
||||
|
||||
object Crypto : CryptoProvider {
|
||||
override suspend fun initialize() {
|
||||
Initializer.initialize()
|
||||
}
|
||||
@ExperimentalUnsignedTypes
|
||||
@ExperimentalStdlibApi
|
||||
|
||||
|
||||
object Blake2b {
|
||||
fun updateable(): com.ionspin.kotlin.crypto.hash.blake2b.Blake2b {
|
||||
return Blake2bDelegated()
|
||||
@ -38,9 +36,11 @@ object Crypto : CryptoProvider {
|
||||
|
||||
}
|
||||
|
||||
@ExperimentalUnsignedTypes
|
||||
|
||||
object SimpleCrypto {
|
||||
fun hash(message : String) : UByteArray { return ubyteArrayOf(0U) }
|
||||
fun hash(message: String): UByteArray {
|
||||
return ubyteArrayOf(0U)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -27,10 +27,10 @@ import com.ionspin.kotlin.crypto.util.rotateRight
|
||||
* on 14-Jul-2019
|
||||
*/
|
||||
|
||||
@ExperimentalUnsignedTypes
|
||||
|
||||
expect class Blake2bDelegated(key: UByteArray? = null, hashLength: Int = 64) : Blake2b
|
||||
|
||||
@ExperimentalUnsignedTypes
|
||||
|
||||
expect object Blake2bStateless : Blake2bStatelessInterface
|
||||
|
||||
|
||||
|
@ -28,7 +28,7 @@ import com.ionspin.kotlin.crypto.util.rotateRight
|
||||
*/
|
||||
|
||||
|
||||
@ExperimentalUnsignedTypes
|
||||
|
||||
class Sha256Pure : Sha256 {
|
||||
|
||||
override val MAX_HASH_BYTES: Int = 32
|
||||
@ -65,7 +65,7 @@ class Sha256Pure : Sha256 {
|
||||
0x748f82eeU, 0x78a5636fU, 0x84c87814U, 0x8cc70208U, 0x90befffaU, 0xa4506cebU, 0xbef9a3f7U, 0xc67178f2U
|
||||
)
|
||||
|
||||
@ExperimentalStdlibApi
|
||||
|
||||
override fun digest(inputString: String, key: String?, hashLength: Int): UByteArray {
|
||||
return digest(
|
||||
inputString.encodeToByteArray().toUByteArray(),
|
||||
@ -243,7 +243,7 @@ class Sha256Pure : Sha256 {
|
||||
var bufferCounter = 0
|
||||
var buffer = UByteArray(BLOCK_SIZE_IN_BYTES) { 0U }
|
||||
|
||||
@ExperimentalStdlibApi
|
||||
|
||||
override fun update(data: String) {
|
||||
return update(data.encodeToByteArray().toUByteArray())
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ import com.ionspin.kotlin.crypto.util.rotateRight
|
||||
* on 18-Jul-2019
|
||||
*/
|
||||
|
||||
@ExperimentalUnsignedTypes
|
||||
|
||||
class Sha512Pure : Sha512 {
|
||||
|
||||
override val MAX_HASH_BYTES: Int = 32
|
||||
@ -133,7 +133,7 @@ class Sha512Pure : Sha512 {
|
||||
0x5be0cd19137e2179UL
|
||||
)
|
||||
|
||||
@ExperimentalStdlibApi
|
||||
|
||||
override fun digest(inputString: String, key: String?, hashLength: Int): UByteArray {
|
||||
return digest(
|
||||
inputString.encodeToByteArray().toUByteArray(),
|
||||
@ -318,7 +318,7 @@ class Sha512Pure : Sha512 {
|
||||
var bufferCounter = 0
|
||||
var buffer = UByteArray(BLOCK_SIZE_IN_BYTES) { 0U }
|
||||
|
||||
@ExperimentalStdlibApi
|
||||
|
||||
override fun update(data: String) {
|
||||
return update(data.encodeToByteArray().toUByteArray())
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ import com.ionspin.kotlin.crypto.util.xor
|
||||
* ugljesa.jovanovic@ionspin.com
|
||||
* on 21-Sep-2019
|
||||
*/
|
||||
@ExperimentalUnsignedTypes
|
||||
|
||||
class AesCbcPure internal constructor(val aesKey: AesKey, val mode: Mode, initializationVector: UByteArray? = null) {
|
||||
|
||||
companion object {
|
||||
@ -219,7 +219,7 @@ class AesCbcPure internal constructor(val aesKey: AesKey, val mode: Mode, initia
|
||||
|
||||
}
|
||||
|
||||
@ExperimentalUnsignedTypes
|
||||
|
||||
data class EncryptedDataAndInitializationVector(val encryptedData : UByteArray, val initilizationVector : UByteArray) {
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
|
@ -35,7 +35,7 @@ import com.ionspin.kotlin.crypto.util.xor
|
||||
* ugljesa.jovanovic@ionspin.com
|
||||
* on 22-Sep-2019
|
||||
*/
|
||||
@ExperimentalUnsignedTypes
|
||||
|
||||
class AesCtrPure internal constructor(val aesKey: AesKey, val mode: Mode, initialCounter: UByteArray? = null) {
|
||||
|
||||
companion object {
|
||||
@ -186,7 +186,7 @@ class AesCtrPure internal constructor(val aesKey: AesKey, val mode: Mode, initia
|
||||
|
||||
}
|
||||
|
||||
@ExperimentalUnsignedTypes
|
||||
|
||||
data class EncryptedDataAndInitialCounter(val encryptedData : UByteArray, val initialCounter : UByteArray) {
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
|
@ -5,7 +5,7 @@ import com.ionspin.kotlin.crypto.util.flattenToUByteArray
|
||||
/**
|
||||
* Created by Ugljesa Jovanovic (jovanovic.ugljesa@gmail.com) on 07/Sep/2019
|
||||
*/
|
||||
@ExperimentalUnsignedTypes
|
||||
|
||||
internal class AesPure internal constructor(val aesKey: AesKey, val input: UByteArray) {
|
||||
companion object {
|
||||
private val debug = false
|
||||
|
@ -62,17 +62,17 @@ inline fun <reified T> Array<T>.chunked(sliceSize: Int): Array<Array<T>> {
|
||||
|
||||
}
|
||||
|
||||
@ExperimentalUnsignedTypes
|
||||
|
||||
infix fun UInt.rotateRight(places: Int): UInt {
|
||||
return (this shr places) xor (this shl (32 - places))
|
||||
}
|
||||
|
||||
@ExperimentalUnsignedTypes
|
||||
|
||||
infix fun ULong.rotateRight(places: Int): ULong {
|
||||
return (this shr places) xor (this shl (64 - places))
|
||||
}
|
||||
|
||||
@ExperimentalUnsignedTypes
|
||||
|
||||
infix fun Array<UByte>.xor(other : Array<UByte>) : Array<UByte> {
|
||||
if (this.size != other.size) {
|
||||
throw RuntimeException("Operands of different sizes are not supported yet")
|
||||
@ -80,7 +80,7 @@ infix fun Array<UByte>.xor(other : Array<UByte>) : Array<UByte> {
|
||||
return Array(this.size) { this[it] xor other[it] }
|
||||
}
|
||||
|
||||
@ExperimentalUnsignedTypes
|
||||
|
||||
infix fun UByteArray.xor(other : UByteArray) : UByteArray {
|
||||
if (this.size != other.size) {
|
||||
throw RuntimeException("Operands of different sizes are not supported yet")
|
||||
@ -88,17 +88,17 @@ infix fun UByteArray.xor(other : UByteArray) : UByteArray {
|
||||
return UByteArray(this.size) { this[it] xor other[it] }
|
||||
}
|
||||
|
||||
@ExperimentalUnsignedTypes
|
||||
|
||||
fun String.hexStringToTypedUByteArray() : Array<UByte> {
|
||||
return this.chunked(2).map { it.toUByte(16) }.toTypedArray()
|
||||
}
|
||||
|
||||
@ExperimentalUnsignedTypes
|
||||
|
||||
fun String.hexStringToUByteArray() : UByteArray {
|
||||
return this.chunked(2).map { it.toUByte(16) }.toUByteArray()
|
||||
}
|
||||
|
||||
@ExperimentalUnsignedTypes
|
||||
|
||||
fun Array<UByte>.toHexString() : String {
|
||||
return this.joinToString(separator = "") {
|
||||
if (it <= 0x0FU) {
|
||||
@ -109,7 +109,7 @@ fun Array<UByte>.toHexString() : String {
|
||||
}
|
||||
}
|
||||
|
||||
@ExperimentalUnsignedTypes
|
||||
|
||||
fun UByteArray.toHexString() : String {
|
||||
return this.joinToString(separator = "") {
|
||||
if (it <= 0x0FU) {
|
||||
@ -121,20 +121,20 @@ fun UByteArray.toHexString() : String {
|
||||
}
|
||||
|
||||
// UInt / Array utils
|
||||
@ExperimentalUnsignedTypes
|
||||
|
||||
fun UInt.toBigEndianUByteArray() : Array<UByte> {
|
||||
return Array<UByte> (4) {
|
||||
((this shr (24 - (it * 8))) and 0xFFU).toUByte()
|
||||
}
|
||||
}
|
||||
@ExperimentalUnsignedTypes
|
||||
|
||||
fun UInt.toLittleEndianTypedUByteArray() : Array<UByte> {
|
||||
return Array<UByte> (4) {
|
||||
((this shr (it * 8)) and 0xFFU).toUByte()
|
||||
}
|
||||
}
|
||||
|
||||
@ExperimentalUnsignedTypes
|
||||
|
||||
fun UInt.toLittleEndianUByteArray() : UByteArray {
|
||||
return UByteArray (4) {
|
||||
((this shr (it * 8)) and 0xFFU).toUByte()
|
||||
@ -142,27 +142,27 @@ fun UInt.toLittleEndianUByteArray() : UByteArray {
|
||||
}
|
||||
|
||||
// UInt / Array utils
|
||||
@ExperimentalUnsignedTypes
|
||||
|
||||
fun ULong.toBigEndianUByteArray() : Array<UByte> {
|
||||
return Array<UByte> (8) {
|
||||
((this shr (56 - (it * 8))) and 0xFFU).toUByte()
|
||||
}
|
||||
}
|
||||
@ExperimentalUnsignedTypes
|
||||
|
||||
fun ULong.toLittleEndianTypedUByteArray() : Array<UByte> {
|
||||
return Array<UByte> (8) {
|
||||
((this shr (it * 8)) and 0xFFU).toUByte()
|
||||
}
|
||||
}
|
||||
|
||||
@ExperimentalUnsignedTypes
|
||||
|
||||
fun ULong.toLittleEndianUByteArray() :UByteArray {
|
||||
return UByteArray (8) {
|
||||
((this shr (it * 8)) and 0xFFU).toUByte()
|
||||
}
|
||||
}
|
||||
|
||||
@ExperimentalUnsignedTypes
|
||||
|
||||
fun Array<UByte>.fromLittleEndianArrayToULong() : ULong {
|
||||
if (this.size > 8) {
|
||||
throw RuntimeException("ore than 8 bytes in input, potential overflow")
|
||||
@ -171,7 +171,7 @@ fun Array<UByte>.fromLittleEndianArrayToULong() : ULong {
|
||||
return ulong
|
||||
}
|
||||
|
||||
@ExperimentalUnsignedTypes
|
||||
|
||||
fun UByteArray.fromLittleEndianArrayToULong() : ULong {
|
||||
if (this.size > 8) {
|
||||
throw RuntimeException("ore than 8 bytes in input, potential overflow")
|
||||
@ -199,7 +199,7 @@ fun UByteArray.arrayChunked(sliceSize: Int): List<UByteArray> {
|
||||
}
|
||||
|
||||
|
||||
@ExperimentalUnsignedTypes
|
||||
|
||||
fun Array<UByte>.fromBigEndianArrayToULong() : ULong {
|
||||
if (this.size > 8) {
|
||||
throw RuntimeException("ore than 8 bytes in input, potential overflow")
|
||||
@ -213,7 +213,7 @@ fun Array<UByte>.fromBigEndianArrayToULong() : ULong {
|
||||
return ulong
|
||||
}
|
||||
|
||||
@ExperimentalUnsignedTypes
|
||||
|
||||
fun Array<UByte>.fromLittleEndianArrayToUInt() : UInt {
|
||||
if (this.size > 4) {
|
||||
throw RuntimeException("ore than 8 bytes in input, potential overflow")
|
||||
@ -222,7 +222,7 @@ fun Array<UByte>.fromLittleEndianArrayToUInt() : UInt {
|
||||
return uint
|
||||
}
|
||||
|
||||
@ExperimentalUnsignedTypes
|
||||
|
||||
fun UByteArray.fromLittleEndianArrayToUInt() : UInt {
|
||||
if (this.size > 4) {
|
||||
throw RuntimeException("ore than 8 bytes in input, potential overflow")
|
||||
@ -234,7 +234,7 @@ fun UByteArray.fromLittleEndianArrayToUInt() : UInt {
|
||||
|
||||
|
||||
|
||||
@ExperimentalUnsignedTypes
|
||||
|
||||
fun Array<UByte>.fromBigEndianArrayToUInt() : UInt {
|
||||
if (this.size > 4) {
|
||||
throw RuntimeException("ore than 8 bytes in input, potential overflow")
|
||||
@ -243,7 +243,7 @@ fun Array<UByte>.fromBigEndianArrayToUInt() : UInt {
|
||||
return uint
|
||||
}
|
||||
|
||||
@ExperimentalUnsignedTypes
|
||||
|
||||
operator fun UInt.plus(other : UByteArray) : UByteArray {
|
||||
return this.toLittleEndianUByteArray() + other
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ import org.khronos.webgl.get
|
||||
*/
|
||||
actual object SRNG {
|
||||
var counter = 0
|
||||
@ExperimentalUnsignedTypes
|
||||
|
||||
actual fun getRandomBytes(amount: Int): UByteArray {
|
||||
val randomBytes = getSodium().randombytes_buf(amount)
|
||||
println("Random bytes: $randomBytes")
|
||||
|
@ -9,7 +9,7 @@ import com.ionspin.kotlin.crypto.util.toHexString
|
||||
* on 14-Jul-2019
|
||||
*/
|
||||
|
||||
@ExperimentalUnsignedTypes
|
||||
|
||||
actual class Blake2bDelegated actual constructor(key: UByteArray?, hashLength: Int) : Blake2b {
|
||||
override val MAX_HASH_BYTES: Int = 64
|
||||
|
||||
@ -31,8 +31,8 @@ actual class Blake2bDelegated actual constructor(key: UByteArray?, hashLength: I
|
||||
}
|
||||
}
|
||||
|
||||
@ExperimentalStdlibApi
|
||||
@ExperimentalUnsignedTypes
|
||||
|
||||
|
||||
actual object Blake2bStateless : Blake2bStatelessInterface {
|
||||
override val MAX_HASH_BYTES: Int = 64
|
||||
|
||||
|
@ -26,7 +26,7 @@ import kotlin.test.assertTrue
|
||||
* ugljesa.jovanovic@ionspin.com
|
||||
* on 05-Jan-2020
|
||||
*/
|
||||
@ExperimentalUnsignedTypes
|
||||
|
||||
class SRNGJsTest {
|
||||
|
||||
@Test
|
||||
|
@ -12,8 +12,8 @@ import kotlin.test.assertEquals
|
||||
* ugljesa.jovanovic@ionspin.com
|
||||
* on 25-May-2020
|
||||
*/
|
||||
@ExperimentalUnsignedTypes
|
||||
@ExperimentalStdlibApi
|
||||
|
||||
|
||||
class Blake2bJsTest {
|
||||
|
||||
@Test
|
||||
|
@ -23,7 +23,7 @@ import java.security.SecureRandom
|
||||
* ugljesa.jovanovic@ionspin.com
|
||||
* on 21-Sep-2019
|
||||
*/
|
||||
@ExperimentalUnsignedTypes
|
||||
|
||||
actual object SRNG {
|
||||
val secureRandom = SecureRandom()
|
||||
actual fun getRandomBytes(amount: Int): UByteArray {
|
||||
|
@ -6,7 +6,7 @@ package com.ionspin.kotlin.crypto.hash.blake2b
|
||||
* on 14-Jul-2019
|
||||
*/
|
||||
|
||||
@ExperimentalUnsignedTypes
|
||||
|
||||
actual class Blake2bDelegated actual constructor(key: UByteArray?, hashLength: Int) : Blake2b {
|
||||
override val MAX_HASH_BYTES: Int
|
||||
get() = TODO("not implemented yet")
|
||||
@ -27,7 +27,7 @@ actual class Blake2bDelegated actual constructor(key: UByteArray?, hashLength: I
|
||||
TODO("not implemented yet")
|
||||
}
|
||||
}
|
||||
@ExperimentalUnsignedTypes
|
||||
|
||||
actual object Blake2bStateless : Blake2bStatelessInterface {
|
||||
|
||||
|
||||
|
@ -8,7 +8,7 @@ import libsodium.*
|
||||
* on 14-Jul-2019
|
||||
*/
|
||||
|
||||
@ExperimentalUnsignedTypes
|
||||
|
||||
actual class Blake2bDelegated actual constructor(key: UByteArray?, hashLength: Int) : Blake2b {
|
||||
override val MAX_HASH_BYTES: Int = 64
|
||||
|
||||
|
@ -8,7 +8,7 @@ import libsodium.*
|
||||
* on 14-Jul-2019
|
||||
*/
|
||||
|
||||
@ExperimentalUnsignedTypes
|
||||
|
||||
actual class Blake2bDelegated actual constructor(key: UByteArray?, hashLength: Int) : Blake2b {
|
||||
override val MAX_HASH_BYTES: Int = 64
|
||||
|
||||
|
@ -27,7 +27,7 @@ import com.ionspin.kotlin.crypto.util.rotateRight
|
||||
* on 14-Jul-2019
|
||||
*/
|
||||
|
||||
@ExperimentalUnsignedTypes
|
||||
|
||||
class Blake2bPure(val key: UByteArray? = null, val hashLength: Int = 64) : Blake2b {
|
||||
|
||||
companion object : Blake2bStatelessInterface {
|
||||
@ -144,7 +144,7 @@ class Blake2bPure(val key: UByteArray? = null, val hashLength: Int = 64) : Blake
|
||||
return h
|
||||
}
|
||||
|
||||
@ExperimentalStdlibApi
|
||||
|
||||
override fun digest(inputString: String, key: String?, hashLength: Int): UByteArray {
|
||||
val array = inputString.encodeToByteArray().toUByteArray()
|
||||
val keyBytes = key?.run {
|
||||
@ -243,7 +243,7 @@ class Blake2bPure(val key: UByteArray? = null, val hashLength: Int = 64) : Blake
|
||||
|
||||
}
|
||||
}
|
||||
@ExperimentalStdlibApi
|
||||
|
||||
constructor(
|
||||
key: String?,
|
||||
requestedHashLenght: Int = 64
|
||||
@ -308,7 +308,7 @@ class Blake2bPure(val key: UByteArray? = null, val hashLength: Int = 64) : Blake
|
||||
}
|
||||
|
||||
}
|
||||
@ExperimentalStdlibApi
|
||||
|
||||
override fun update(data: String) {
|
||||
update(data.encodeToByteArray().toUByteArray())
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ import com.ionspin.kotlin.crypto.util.rotateRight
|
||||
*/
|
||||
|
||||
|
||||
@ExperimentalUnsignedTypes
|
||||
|
||||
class Sha256Pure : Sha256 {
|
||||
|
||||
override val MAX_HASH_BYTES: Int = 32
|
||||
@ -65,7 +65,7 @@ class Sha256Pure : Sha256 {
|
||||
0x748f82eeU, 0x78a5636fU, 0x84c87814U, 0x8cc70208U, 0x90befffaU, 0xa4506cebU, 0xbef9a3f7U, 0xc67178f2U
|
||||
)
|
||||
|
||||
@ExperimentalStdlibApi
|
||||
|
||||
override fun digest(inputString: String, key: String?, hashLength: Int): UByteArray {
|
||||
return digest(
|
||||
inputString.encodeToByteArray().toUByteArray(),
|
||||
@ -243,7 +243,7 @@ class Sha256Pure : Sha256 {
|
||||
var bufferCounter = 0
|
||||
var buffer = UByteArray(BLOCK_SIZE_IN_BYTES) { 0U }
|
||||
|
||||
@ExperimentalStdlibApi
|
||||
|
||||
override fun update(data: String) {
|
||||
return update(data.encodeToByteArray().toUByteArray())
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ import com.ionspin.kotlin.crypto.util.rotateRight
|
||||
* on 18-Jul-2019
|
||||
*/
|
||||
|
||||
@ExperimentalUnsignedTypes
|
||||
|
||||
class Sha512Pure : Sha512 {
|
||||
|
||||
override val MAX_HASH_BYTES: Int = 32
|
||||
@ -133,7 +133,7 @@ class Sha512Pure : Sha512 {
|
||||
0x5be0cd19137e2179UL
|
||||
)
|
||||
|
||||
@ExperimentalStdlibApi
|
||||
|
||||
override fun digest(inputString: String, key: String?, hashLength: Int): UByteArray {
|
||||
return digest(
|
||||
inputString.encodeToByteArray().toUByteArray(),
|
||||
@ -318,7 +318,7 @@ class Sha512Pure : Sha512 {
|
||||
var bufferCounter = 0
|
||||
var buffer = UByteArray(BLOCK_SIZE_IN_BYTES) { 0U }
|
||||
|
||||
@ExperimentalStdlibApi
|
||||
|
||||
override fun update(data: String) {
|
||||
return update(data.encodeToByteArray().toUByteArray())
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ data class ArgonResult(
|
||||
|
||||
|
||||
|
||||
@ExperimentalStdlibApi
|
||||
|
||||
class Argon2Pure(
|
||||
private val password: UByteArray,
|
||||
private val salt: UByteArray = ubyteArrayOf(),
|
||||
|
@ -161,7 +161,7 @@ object Argon2Utils {
|
||||
|
||||
// ------------ Arithmetic and other utils
|
||||
|
||||
@ExperimentalUnsignedTypes
|
||||
|
||||
fun UByteArray.xorWithBlock(other : ArgonMatrix, rowPosition: Int, columnPosition: Int) : UByteArray {
|
||||
return UByteArray(BLOCK_SIZE) { this[it] xor other[rowPosition, columnPosition, it] }
|
||||
}
|
@ -30,7 +30,7 @@ import com.ionspin.kotlin.crypto.util.xor
|
||||
* ugljesa.jovanovic@ionspin.com
|
||||
* on 21-Sep-2019
|
||||
*/
|
||||
@ExperimentalUnsignedTypes
|
||||
|
||||
class AesCbcPure internal constructor(val aesKey: AesKey, val mode: Mode, initializationVector: UByteArray? = null) {
|
||||
|
||||
companion object {
|
||||
@ -219,7 +219,7 @@ class AesCbcPure internal constructor(val aesKey: AesKey, val mode: Mode, initia
|
||||
|
||||
}
|
||||
|
||||
@ExperimentalUnsignedTypes
|
||||
|
||||
data class EncryptedDataAndInitializationVector(val encryptedData : UByteArray, val initilizationVector : UByteArray) {
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
|
@ -35,7 +35,7 @@ import com.ionspin.kotlin.crypto.util.xor
|
||||
* ugljesa.jovanovic@ionspin.com
|
||||
* on 22-Sep-2019
|
||||
*/
|
||||
@ExperimentalUnsignedTypes
|
||||
|
||||
class AesCtrPure internal constructor(val aesKey: AesKey, val mode: Mode, initialCounter: UByteArray? = null) {
|
||||
|
||||
companion object {
|
||||
@ -186,7 +186,7 @@ class AesCtrPure internal constructor(val aesKey: AesKey, val mode: Mode, initia
|
||||
|
||||
}
|
||||
|
||||
@ExperimentalUnsignedTypes
|
||||
|
||||
data class EncryptedDataAndInitialCounter(val encryptedData : UByteArray, val initialCounter : UByteArray) {
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
|
@ -5,7 +5,7 @@ import com.ionspin.kotlin.crypto.util.flattenToUByteArray
|
||||
/**
|
||||
* Created by Ugljesa Jovanovic (jovanovic.ugljesa@gmail.com) on 07/Sep/2019
|
||||
*/
|
||||
@ExperimentalUnsignedTypes
|
||||
|
||||
internal class AesPure internal constructor(val aesKey: AesKey, val input: UByteArray) {
|
||||
companion object {
|
||||
private val debug = false
|
||||
|
@ -62,17 +62,17 @@ inline fun <reified T> Array<T>.chunked(sliceSize: Int): Array<Array<T>> {
|
||||
|
||||
}
|
||||
|
||||
@ExperimentalUnsignedTypes
|
||||
|
||||
infix fun UInt.rotateRight(places: Int): UInt {
|
||||
return (this shr places) xor (this shl (32 - places))
|
||||
}
|
||||
|
||||
@ExperimentalUnsignedTypes
|
||||
|
||||
infix fun ULong.rotateRight(places: Int): ULong {
|
||||
return (this shr places) xor (this shl (64 - places))
|
||||
}
|
||||
|
||||
@ExperimentalUnsignedTypes
|
||||
|
||||
infix fun Array<UByte>.xor(other : Array<UByte>) : Array<UByte> {
|
||||
if (this.size != other.size) {
|
||||
throw RuntimeException("Operands of different sizes are not supported yet")
|
||||
@ -80,7 +80,7 @@ infix fun Array<UByte>.xor(other : Array<UByte>) : Array<UByte> {
|
||||
return Array(this.size) { this[it] xor other[it] }
|
||||
}
|
||||
|
||||
@ExperimentalUnsignedTypes
|
||||
|
||||
infix fun UByteArray.xor(other : UByteArray) : UByteArray {
|
||||
if (this.size != other.size) {
|
||||
throw RuntimeException("Operands of different sizes are not supported yet")
|
||||
@ -88,17 +88,17 @@ infix fun UByteArray.xor(other : UByteArray) : UByteArray {
|
||||
return UByteArray(this.size) { this[it] xor other[it] }
|
||||
}
|
||||
|
||||
@ExperimentalUnsignedTypes
|
||||
|
||||
fun String.hexStringToTypedUByteArray() : Array<UByte> {
|
||||
return this.chunked(2).map { it.toUByte(16) }.toTypedArray()
|
||||
}
|
||||
|
||||
@ExperimentalUnsignedTypes
|
||||
|
||||
fun String.hexStringToUByteArray() : UByteArray {
|
||||
return this.chunked(2).map { it.toUByte(16) }.toUByteArray()
|
||||
}
|
||||
|
||||
@ExperimentalUnsignedTypes
|
||||
|
||||
fun Array<UByte>.toHexString() : String {
|
||||
return this.joinToString(separator = "") {
|
||||
if (it <= 0x0FU) {
|
||||
@ -109,7 +109,7 @@ fun Array<UByte>.toHexString() : String {
|
||||
}
|
||||
}
|
||||
|
||||
@ExperimentalUnsignedTypes
|
||||
|
||||
fun UByteArray.toHexString() : String {
|
||||
return this.joinToString(separator = "") {
|
||||
if (it <= 0x0FU) {
|
||||
@ -121,20 +121,20 @@ fun UByteArray.toHexString() : String {
|
||||
}
|
||||
|
||||
// UInt / Array utils
|
||||
@ExperimentalUnsignedTypes
|
||||
|
||||
fun UInt.toBigEndianUByteArray() : Array<UByte> {
|
||||
return Array<UByte> (4) {
|
||||
((this shr (24 - (it * 8))) and 0xFFU).toUByte()
|
||||
}
|
||||
}
|
||||
@ExperimentalUnsignedTypes
|
||||
|
||||
fun UInt.toLittleEndianTypedUByteArray() : Array<UByte> {
|
||||
return Array<UByte> (4) {
|
||||
((this shr (it * 8)) and 0xFFU).toUByte()
|
||||
}
|
||||
}
|
||||
|
||||
@ExperimentalUnsignedTypes
|
||||
|
||||
fun UInt.toLittleEndianUByteArray() : UByteArray {
|
||||
return UByteArray (4) {
|
||||
((this shr (it * 8)) and 0xFFU).toUByte()
|
||||
@ -142,27 +142,27 @@ fun UInt.toLittleEndianUByteArray() : UByteArray {
|
||||
}
|
||||
|
||||
// UInt / Array utils
|
||||
@ExperimentalUnsignedTypes
|
||||
|
||||
fun ULong.toBigEndianUByteArray() : Array<UByte> {
|
||||
return Array<UByte> (8) {
|
||||
((this shr (56 - (it * 8))) and 0xFFU).toUByte()
|
||||
}
|
||||
}
|
||||
@ExperimentalUnsignedTypes
|
||||
|
||||
fun ULong.toLittleEndianTypedUByteArray() : Array<UByte> {
|
||||
return Array<UByte> (8) {
|
||||
((this shr (it * 8)) and 0xFFU).toUByte()
|
||||
}
|
||||
}
|
||||
|
||||
@ExperimentalUnsignedTypes
|
||||
|
||||
fun ULong.toLittleEndianUByteArray() :UByteArray {
|
||||
return UByteArray (8) {
|
||||
((this shr (it * 8)) and 0xFFU).toUByte()
|
||||
}
|
||||
}
|
||||
|
||||
@ExperimentalUnsignedTypes
|
||||
|
||||
fun Array<UByte>.fromLittleEndianArrayToULong() : ULong {
|
||||
if (this.size > 8) {
|
||||
throw RuntimeException("ore than 8 bytes in input, potential overflow")
|
||||
@ -171,7 +171,7 @@ fun Array<UByte>.fromLittleEndianArrayToULong() : ULong {
|
||||
return ulong
|
||||
}
|
||||
|
||||
@ExperimentalUnsignedTypes
|
||||
|
||||
fun UByteArray.fromLittleEndianArrayToULong() : ULong {
|
||||
if (this.size > 8) {
|
||||
throw RuntimeException("ore than 8 bytes in input, potential overflow")
|
||||
@ -199,7 +199,7 @@ fun UByteArray.arrayChunked(sliceSize: Int): List<UByteArray> {
|
||||
}
|
||||
|
||||
|
||||
@ExperimentalUnsignedTypes
|
||||
|
||||
fun Array<UByte>.fromBigEndianArrayToULong() : ULong {
|
||||
if (this.size > 8) {
|
||||
throw RuntimeException("ore than 8 bytes in input, potential overflow")
|
||||
@ -213,7 +213,7 @@ fun Array<UByte>.fromBigEndianArrayToULong() : ULong {
|
||||
return ulong
|
||||
}
|
||||
|
||||
@ExperimentalUnsignedTypes
|
||||
|
||||
fun Array<UByte>.fromLittleEndianArrayToUInt() : UInt {
|
||||
if (this.size > 4) {
|
||||
throw RuntimeException("ore than 8 bytes in input, potential overflow")
|
||||
@ -222,7 +222,7 @@ fun Array<UByte>.fromLittleEndianArrayToUInt() : UInt {
|
||||
return uint
|
||||
}
|
||||
|
||||
@ExperimentalUnsignedTypes
|
||||
|
||||
fun UByteArray.fromLittleEndianArrayToUInt() : UInt {
|
||||
if (this.size > 4) {
|
||||
throw RuntimeException("ore than 8 bytes in input, potential overflow")
|
||||
@ -234,7 +234,7 @@ fun UByteArray.fromLittleEndianArrayToUInt() : UInt {
|
||||
|
||||
|
||||
|
||||
@ExperimentalUnsignedTypes
|
||||
|
||||
fun Array<UByte>.fromBigEndianArrayToUInt() : UInt {
|
||||
if (this.size > 4) {
|
||||
throw RuntimeException("ore than 8 bytes in input, potential overflow")
|
||||
@ -243,7 +243,7 @@ fun Array<UByte>.fromBigEndianArrayToUInt() : UInt {
|
||||
return uint
|
||||
}
|
||||
|
||||
@ExperimentalUnsignedTypes
|
||||
|
||||
operator fun UInt.plus(other : UByteArray) : UByteArray {
|
||||
return this.toLittleEndianUByteArray() + other
|
||||
}
|
||||
|
@ -34,8 +34,8 @@ import kotlin.time.measureTime
|
||||
* ugljesa.jovanovic@ionspin.com
|
||||
* on 20-Jul-2019
|
||||
*/
|
||||
@ExperimentalUnsignedTypes
|
||||
@ExperimentalStdlibApi
|
||||
|
||||
|
||||
class ReadmeTest {
|
||||
|
||||
@Test
|
||||
@ -76,7 +76,7 @@ class ReadmeTest {
|
||||
}
|
||||
}
|
||||
|
||||
@ExperimentalStdlibApi
|
||||
|
||||
@Test
|
||||
fun sha256Example() {
|
||||
val input = "abc"
|
||||
@ -89,7 +89,7 @@ class ReadmeTest {
|
||||
|
||||
}
|
||||
|
||||
@ExperimentalStdlibApi
|
||||
|
||||
@Test
|
||||
fun sha512Example() {
|
||||
val input = "abc"
|
||||
@ -104,7 +104,7 @@ class ReadmeTest {
|
||||
|
||||
}
|
||||
|
||||
@ExperimentalStdlibApi
|
||||
|
||||
@Test
|
||||
fun sha256UpdatableExample() {
|
||||
val sha256 = Sha256Pure()
|
||||
@ -116,7 +116,7 @@ class ReadmeTest {
|
||||
}
|
||||
}
|
||||
|
||||
@ExperimentalStdlibApi
|
||||
|
||||
@Test
|
||||
fun sha512UpdatableExample() {
|
||||
val sha512 = Sha512Pure()
|
||||
|
@ -30,7 +30,7 @@ import kotlin.test.assertTrue
|
||||
* ugljesa.jovanovic@ionspin.com
|
||||
* on 10-May-2020
|
||||
*/
|
||||
@ExperimentalStdlibApi
|
||||
|
||||
class Argon2KATTest {
|
||||
|
||||
@Test
|
||||
|
@ -25,8 +25,8 @@ import kotlin.test.assertTrue
|
||||
* ugljesa.jovanovic@ionspin.com
|
||||
* on 14-Jul-2019
|
||||
*/
|
||||
@ExperimentalUnsignedTypes
|
||||
@ExperimentalStdlibApi
|
||||
|
||||
|
||||
class Blake2BTest {
|
||||
|
||||
@Test
|
||||
|
@ -24,8 +24,8 @@ import kotlin.test.assertTrue
|
||||
* ugljesa.jovanovic@ionspin.com
|
||||
* on 20-Jul-2019
|
||||
*/
|
||||
@ExperimentalUnsignedTypes
|
||||
@ExperimentalStdlibApi
|
||||
|
||||
|
||||
class Blake2bInstanceTest {
|
||||
|
||||
@Test
|
||||
|
@ -30,8 +30,8 @@ data class KnownAnswerTest(
|
||||
val hash: String
|
||||
)
|
||||
|
||||
@ExperimentalUnsignedTypes
|
||||
@ExperimentalStdlibApi
|
||||
|
||||
|
||||
class Blake2bKnowAnswerTests {
|
||||
@Test
|
||||
fun knownAnswerTest() {
|
||||
|
@ -24,10 +24,10 @@ import kotlin.test.assertTrue
|
||||
* ugljesa.jovanovic@ionspin.com
|
||||
* on 17-Jul-2019
|
||||
*/
|
||||
@ExperimentalUnsignedTypes
|
||||
|
||||
class Sha256Test {
|
||||
|
||||
@ExperimentalStdlibApi
|
||||
|
||||
@Test
|
||||
fun testWellKnownValue() {
|
||||
|
||||
@ -40,7 +40,7 @@ class Sha256Test {
|
||||
|
||||
}
|
||||
|
||||
@ExperimentalStdlibApi
|
||||
|
||||
@Test
|
||||
fun testWellKnownDoubleBlock() {
|
||||
|
||||
@ -51,7 +51,7 @@ class Sha256Test {
|
||||
}
|
||||
}
|
||||
|
||||
@ExperimentalStdlibApi
|
||||
|
||||
@Test
|
||||
fun testWellKnown3() { //It's good that I'm consistent with names.
|
||||
|
||||
@ -64,7 +64,7 @@ class Sha256Test {
|
||||
}
|
||||
}
|
||||
|
||||
@ExperimentalStdlibApi
|
||||
|
||||
@Test
|
||||
fun testWellKnownLong() {
|
||||
val inputBuilder = StringBuilder()
|
||||
|
@ -25,10 +25,10 @@ import kotlin.test.assertTrue
|
||||
* ugljesa.jovanovic@ionspin.com
|
||||
* on 17-Jul-2019
|
||||
*/
|
||||
@ExperimentalUnsignedTypes
|
||||
|
||||
class Sha256UpdatableTest {
|
||||
|
||||
@ExperimentalStdlibApi
|
||||
|
||||
@Test
|
||||
fun testWellKnownValue() {
|
||||
val sha256 = Sha256Pure()
|
||||
@ -40,7 +40,7 @@ class Sha256UpdatableTest {
|
||||
}
|
||||
}
|
||||
|
||||
@ExperimentalStdlibApi
|
||||
|
||||
@Test
|
||||
fun testWellKnownDoubleBlock() {
|
||||
val sha256 = Sha256Pure()
|
||||
@ -53,7 +53,7 @@ class Sha256UpdatableTest {
|
||||
}
|
||||
}
|
||||
|
||||
@ExperimentalStdlibApi
|
||||
|
||||
@Test
|
||||
fun testWellKnown3() { //It's good that I'm consistent with names.
|
||||
val sha256 = Sha256Pure()
|
||||
@ -66,7 +66,7 @@ class Sha256UpdatableTest {
|
||||
}
|
||||
}
|
||||
|
||||
@ExperimentalStdlibApi
|
||||
|
||||
@Test
|
||||
fun testWellKnownLong() {
|
||||
val sha256 = Sha256Pure()
|
||||
@ -81,7 +81,7 @@ class Sha256UpdatableTest {
|
||||
}
|
||||
|
||||
@Ignore()
|
||||
@ExperimentalStdlibApi
|
||||
|
||||
@Test
|
||||
fun testWellKnownLonger() {
|
||||
val sha256 = Sha256Pure()
|
||||
|
@ -26,7 +26,7 @@ import kotlin.test.assertTrue
|
||||
*/
|
||||
class Sha512Test {
|
||||
|
||||
@ExperimentalStdlibApi
|
||||
|
||||
@Test
|
||||
fun testWellKnownValue() {
|
||||
|
||||
@ -41,8 +41,8 @@ class Sha512Test {
|
||||
|
||||
}
|
||||
|
||||
@ExperimentalUnsignedTypes
|
||||
@ExperimentalStdlibApi
|
||||
|
||||
|
||||
@Test
|
||||
fun testWellKnown3() {
|
||||
val sha512 = Sha512Pure()
|
||||
@ -55,7 +55,7 @@ class Sha512Test {
|
||||
}
|
||||
}
|
||||
|
||||
@ExperimentalStdlibApi
|
||||
|
||||
@Test
|
||||
fun testWellKnownLong() {
|
||||
val inputBuilder = StringBuilder()
|
||||
|
@ -26,7 +26,7 @@ import kotlin.test.assertTrue
|
||||
* on 21-Jul-2019
|
||||
*/
|
||||
class Sha512UpdatableTest {
|
||||
@ExperimentalStdlibApi
|
||||
|
||||
@Test
|
||||
fun testWellKnownValue() {
|
||||
val sha512 = Sha512Pure()
|
||||
@ -41,7 +41,7 @@ class Sha512UpdatableTest {
|
||||
|
||||
}
|
||||
|
||||
@ExperimentalStdlibApi
|
||||
|
||||
@Test
|
||||
fun testWellKnownDoubleBlock() {
|
||||
val sha512 = Sha512Pure()
|
||||
@ -55,7 +55,7 @@ class Sha512UpdatableTest {
|
||||
}
|
||||
}
|
||||
|
||||
@ExperimentalStdlibApi
|
||||
|
||||
@Test
|
||||
fun testWellKnownLong() {
|
||||
val sha512 = Sha512Pure()
|
||||
@ -70,7 +70,7 @@ class Sha512UpdatableTest {
|
||||
}
|
||||
|
||||
@Ignore() //Interestingly enough I'm not the only one having trouble with this test.
|
||||
@ExperimentalStdlibApi
|
||||
|
||||
@Test
|
||||
fun testWellKnownLonger() {
|
||||
val sha512 = Sha512Pure()
|
||||
|
@ -26,7 +26,7 @@ import kotlin.test.assertTrue
|
||||
* ugljesa.jovanovic@ionspin.com
|
||||
* on 21-Sep-2019
|
||||
*/
|
||||
@ExperimentalUnsignedTypes
|
||||
|
||||
class AesCbcTest {
|
||||
|
||||
@Test
|
||||
|
@ -26,7 +26,7 @@ import kotlin.test.assertTrue
|
||||
* ugljesa.jovanovic@ionspin.com
|
||||
* on 21-Sep-2019
|
||||
*/
|
||||
@ExperimentalUnsignedTypes
|
||||
|
||||
class AesCtrTest {
|
||||
|
||||
@Test
|
||||
|
@ -6,7 +6,7 @@ import kotlin.test.assertTrue
|
||||
/**
|
||||
* Created by Ugljesa Jovanovic (jovanovic.ugljesa@gmail.com) on 10/Sep/2019
|
||||
*/
|
||||
@ExperimentalUnsignedTypes
|
||||
|
||||
class AesTest {
|
||||
|
||||
val irrelevantKey = "01234567890123345678901234567890"
|
||||
|
@ -24,7 +24,7 @@ import kotlin.test.assertTrue
|
||||
* ugljesa.jovanovic@ionspin.com
|
||||
* on 17-Jul-2019
|
||||
*/
|
||||
@ExperimentalUnsignedTypes
|
||||
|
||||
class UtilTest {
|
||||
|
||||
@Test
|
||||
|
@ -25,7 +25,7 @@ import kotlin.browser.window
|
||||
*/
|
||||
actual object SRNG {
|
||||
var counter = 0
|
||||
@ExperimentalUnsignedTypes
|
||||
|
||||
actual fun getRandomBytes(amount: Int): UByteArray {
|
||||
val runningOnNode = jsTypeOf(window) == "undefined"
|
||||
val randomBytes = if (runningOnNode) {
|
||||
|
@ -24,7 +24,7 @@ import kotlin.test.assertTrue
|
||||
* ugljesa.jovanovic@ionspin.com
|
||||
* on 05-Jan-2020
|
||||
*/
|
||||
@ExperimentalUnsignedTypes
|
||||
|
||||
class SRNGJsTest {
|
||||
|
||||
@Test
|
||||
|
@ -23,7 +23,7 @@ import java.security.SecureRandom
|
||||
* ugljesa.jovanovic@ionspin.com
|
||||
* on 21-Sep-2019
|
||||
*/
|
||||
@ExperimentalUnsignedTypes
|
||||
|
||||
actual object SRNG {
|
||||
val secureRandom = SecureRandom()
|
||||
actual fun getRandomBytes(amount: Int): UByteArray {
|
||||
|
@ -3,7 +3,7 @@ import kotlin.time.ExperimentalTime
|
||||
import kotlin.time.measureTime
|
||||
|
||||
@ExperimentalTime
|
||||
@ExperimentalStdlibApi
|
||||
|
||||
fun main() {
|
||||
println("Test")
|
||||
// Blake
|
||||
|
@ -6,7 +6,7 @@ import kotlin.time.ExperimentalTime
|
||||
import kotlin.time.measureTime
|
||||
|
||||
@ExperimentalTime
|
||||
@ExperimentalStdlibApi
|
||||
|
||||
fun main() = runBlocking {
|
||||
Sample.runSample()
|
||||
// println("Test")
|
||||
|
@ -4,7 +4,7 @@ import kotlin.time.ExperimentalTime
|
||||
import kotlin.time.measureTime
|
||||
|
||||
@ExperimentalTime
|
||||
@ExperimentalStdlibApi
|
||||
|
||||
fun main() {
|
||||
println("Test")
|
||||
// Blake
|
||||
|
Loading…
x
Reference in New Issue
Block a user