forked from sergeych/crypto2
Universal keys. fixed bugs with keys serialization and equality
This commit is contained in:
1 parent
9027bb0e88
commit
f64412fdc7
18 files changed
+593
-26
No files matched your search
@@ -3,6 +3,7 @@ import com.ionspin.kotlin.crypto.util.encodeToUByteArray
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import kotlinx.serialization.encodeToString
|
||||
import kotlinx.serialization.json.Json
|
||||
import net.sergeych.bipack.BipackEncoder
|
||||
import net.sergeych.crypto2.*
|
||||
import net.sergeych.utools.now
|
||||
import net.sergeych.utools.pack
|
||||
@@ -153,6 +154,11 @@ class KeysTest {
|
||||
assertContentEquals(plain, m.decrypt(sk1))
|
||||
}
|
||||
|
||||
val x1 = BipackEncoder.encode(Asymmetric.createMessage(sk0, pk1, plain))
|
||||
val x2 = BipackEncoder.encode(Asymmetric.createMessage(sk0, pk1, plain))
|
||||
|
||||
assertFalse { x1 contentEquals x2 }
|
||||
|
||||
}
|
||||
@Test
|
||||
fun asymmetricKeySerializationTest() = runTest {
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
import com.ionspin.kotlin.crypto.util.encodeToUByteArray
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import net.sergeych.bintools.toDump
|
||||
import net.sergeych.bipack.BipackDecoder
|
||||
import net.sergeych.bipack.BipackEncoder
|
||||
import net.sergeych.crypto2.*
|
||||
import kotlin.test.*
|
||||
|
||||
class RingTest {
|
||||
|
||||
@Test
|
||||
fun testCreationAndSerialization() = runTest {
|
||||
initCrypto()
|
||||
|
||||
val y1 = SymmetricKey("1234567890Hello,dolly.here-we-go".encodeToUByteArray())
|
||||
val y2 = SymmetricKey("1234567890Hello,dolly.here-we-go".encodeToUByteArray())
|
||||
assertEquals(y1, y2)
|
||||
|
||||
val e1 = Asymmetric.randomSecretKey()
|
||||
val e2: Asymmetric.SecretKey = BipackDecoder.decode(BipackEncoder.encode(e1))
|
||||
assertEquals(e1, e2)
|
||||
|
||||
val k1 = UniversalKey.from(SymmetricKey("1234567890Hello,dolly.here-we-go".encodeToUByteArray()))
|
||||
val k11 = UniversalKey.from(SymmetricKey("1234567890Hello,dolly.here-we-go".encodeToUByteArray()))
|
||||
|
||||
assertEquals(k1, k11)
|
||||
|
||||
|
||||
val k2 = UniversalKey.from(Asymmetric.randomSecretKey())
|
||||
val k3 = UniversalKey.from(Asymmetric.randomSecretKey())
|
||||
//
|
||||
val r = UniversalRing(k1, k2)
|
||||
// val r = UniversalRing(k1)
|
||||
assertContains(r, k2)
|
||||
assertContains(r, k1)
|
||||
assertFalse { k3 in r }
|
||||
|
||||
println(Asymmetric.randomSecretKey().keyBytes.size)
|
||||
println(BipackEncoder.encode(Asymmetric.randomSecretKey()).size)
|
||||
val encoded = BipackEncoder.encode(r)
|
||||
println(encoded.toDump())
|
||||
println(encoded.size)
|
||||
assertTrue { encoded.size < 80 }
|
||||
val r2: UniversalRing = BipackDecoder.decode(encoded)
|
||||
assertContains(r2, k2)
|
||||
assertContains(r2, k1)
|
||||
assertFalse { k3 in r2 }
|
||||
|
||||
println(r)
|
||||
println(r2)
|
||||
|
||||
assertEquals(r, r2)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,8 @@
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import net.sergeych.crypto2.*
|
||||
import net.sergeych.crypto2.NumericNonce
|
||||
import net.sergeych.crypto2.createContrail
|
||||
import net.sergeych.crypto2.initCrypto
|
||||
import net.sergeych.crypto2.isValidContrail
|
||||
import kotlin.test.*
|
||||
|
||||
class ToolsTest {
|
||||
@@ -20,8 +23,8 @@ class ToolsTest {
|
||||
val counter = 1031
|
||||
val x1 = nn.withInt(0)
|
||||
val x2 = nn.withInt(counter)
|
||||
println(x1.toDump())
|
||||
println(x2.toDump())
|
||||
// println(x1.toDump())
|
||||
// println(x2.toDump())
|
||||
val t = (x1[0] xor x2[0]).toInt() + ((x1[1] xor x2[1]).toInt() shl 8)
|
||||
assertEquals(counter, t)
|
||||
assertContentEquals(x1.drop(2), x2.drop(2))
|
||||
|
||||
Reference in new issue
Block a user