forked from sergeych/crypto2
added more tests, foxed several bugs ;)
This commit is contained in:
1 parent
ede55650f4
commit
c4accfcd91
5 files changed
+20
-11
No files matched your search
@@ -1,6 +1,7 @@
|
||||
package net.sergeych.crypto2
|
||||
|
||||
import com.ionspin.kotlin.crypto.generichash.GenericHash
|
||||
import com.ionspin.kotlin.crypto.util.encodeToUByteArray
|
||||
import org.komputing.khash.keccak.Keccak
|
||||
import org.komputing.khash.keccak.KeccakParameter
|
||||
|
||||
@@ -12,6 +13,10 @@ enum class Hash(val perform: (UByteArray)->UByteArray) {
|
||||
Sha3_256({ Keccak.digest(it.toByteArray(), KeccakParameter.SHA3_256).toUByteArray()}),
|
||||
}
|
||||
|
||||
private val defaultSuffix1 = "All lay loads on a willing horse".encodeToUByteArray()
|
||||
private val defaultSuffix2 = "A stitch in time saves nine".encodeToUByteArray()
|
||||
|
||||
fun blake2b(src: UByteArray): UByteArray = Hash.Blake2b.perform(src)
|
||||
fun blake2b2l(src: UByteArray): UByteArray = blake2b(blake2b(src) + src)
|
||||
fun blake2b3l(src: UByteArray): UByteArray = blake2b(blake2b2l(src) + src)
|
||||
fun blake2b2l(src: UByteArray): UByteArray =
|
||||
blake2b(blake2b(src) + defaultSuffix1 + src)
|
||||
fun blake2b3l(src: UByteArray): UByteArray = blake2b(blake2b2l(src) + defaultSuffix2 + src)
|
||||
@@ -23,6 +23,6 @@ data class KeyId(val id: BinaryId, val kdp: KeyDerivationParams?=null ) {
|
||||
|
||||
override fun toString() = id.toString()
|
||||
|
||||
constructor(magickNumber: KeysMagickNumber, data: UByteArray, kdp: KeyDerivationParams?=null)
|
||||
: this(BinaryId.createFromUBytes(magickNumber.number, data), kdp)
|
||||
constructor(magickNumber: KeysMagickNumber, keyData: UByteArray, kdp: KeyDerivationParams?=null)
|
||||
: this(BinaryId.createFromUBytes(magickNumber.number, blake2b3l(keyData)), kdp)
|
||||
}
|
||||
@@ -28,6 +28,8 @@ class SigningSecretKey(
|
||||
|
||||
override fun toString(): String = "Sct:${super.toString()}"
|
||||
|
||||
override val id: KeyId = verifyingKey.id
|
||||
|
||||
@Transient
|
||||
override val magick = KeysMagickNumber.defaultSigning
|
||||
|
||||
|
||||
@@ -28,6 +28,8 @@ sealed class UniversalKey {
|
||||
override val id: KeyId = key.id
|
||||
@Transient
|
||||
override val nonceBytesLength: Int = key.nonceBytesLength
|
||||
|
||||
override fun toString() = "U.Ssn:$id"
|
||||
}
|
||||
|
||||
@Serializable
|
||||
@@ -56,7 +58,7 @@ sealed class UniversalKey {
|
||||
override val nonceBytesLength: Int
|
||||
get() = Asymmetric.nonceBytesLength
|
||||
|
||||
override fun toString() = "U.Sec:$id"
|
||||
override fun toString() = "U.Pub:$id"
|
||||
}
|
||||
|
||||
@Serializable
|
||||
@@ -76,7 +78,7 @@ sealed class UniversalKey {
|
||||
@SerialName("ver")
|
||||
data class Verifying(val key: SigningPublicKey) : UniversalKey(), VerifyingKey by key {
|
||||
override val id: KeyId by lazy { key.id }
|
||||
override fun toString() = "U.Sig:$id"
|
||||
override fun toString() = "U.Ver:$id"
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user