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