Remove all annotations
This commit is contained in:
1 parent
d901a45b87
commit
3ad86e284a
46 files changed
+142
-142
No files matched your search
+11
-11
@@ -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,24 +12,23 @@ 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 {
|
||||
fun updateable(): com.ionspin.kotlin.crypto.hash.blake2b.Blake2b {
|
||||
return Blake2bDelegated()
|
||||
}
|
||||
|
||||
fun stateless(message : String) : UByteArray {
|
||||
fun stateless(message: String): UByteArray {
|
||||
println("?")
|
||||
return Blake2bStateless.digest(message)
|
||||
}
|
||||
@@ -38,15 +36,17 @@ object Crypto : CryptoProvider {
|
||||
|
||||
}
|
||||
|
||||
@ExperimentalUnsignedTypes
|
||||
|
||||
object SimpleCrypto {
|
||||
fun hash(message : String) : UByteArray { return ubyteArrayOf(0U) }
|
||||
fun hash(message: String): UByteArray {
|
||||
return ubyteArrayOf(0U)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
expect object Initializer {
|
||||
suspend fun initialize()
|
||||
|
||||
fun initializeWithCallback(done : () -> (Unit))
|
||||
fun initializeWithCallback(done: () -> (Unit))
|
||||
}
|
||||
|
||||
+2
-2
@@ -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
|
||||
|
||||
|
||||
+3
-3
@@ -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())
|
||||
}
|
||||
|
||||
+3
-3
@@ -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())
|
||||
}
|
||||
|
||||
+2
-2
@@ -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
|
||||
|
||||
+2
-2
@@ -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
|
||||
|
||||
+1
-1
@@ -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
|
||||
|
||||
+21
-21
@@ -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")
|
||||
|
||||
+3
-3
@@ -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
|
||||
|
||||
|
||||
+1
-1
@@ -26,7 +26,7 @@ import kotlin.test.assertTrue
|
||||
* ugljesa.jovanovic@ionspin.com
|
||||
* on 05-Jan-2020
|
||||
*/
|
||||
@ExperimentalUnsignedTypes
|
||||
|
||||
class SRNGJsTest {
|
||||
|
||||
@Test
|
||||
|
||||
+2
-2
@@ -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 {
|
||||
|
||||
+2
-2
@@ -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 {
|
||||
|
||||
|
||||
|
||||
+1
-1
@@ -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
|
||||
|
||||
|
||||
+1
-1
@@ -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
|
||||
|
||||
|
||||
Reference in new issue
Block a user