0.7.1 started. fixed secret key serialization excessive size for signing/verifying keys

This commit is contained in:
Sergey Chernov 2024-11-26 18:50:07 +07:00
parent 10ec58ec08
commit e8fa634640
4 changed files with 31 additions and 2 deletions

View File

@ -8,6 +8,8 @@ All primitives meant to send over the network or store are `kotlinx.serializatio
# Important notes on upgrade # Important notes on upgrade
___Please upgrade to 0.7.1+___ as it has much more compact but not backward-compatible serialization format!
Since version __0.5.*__ key identity calculation for asymmetric keys is updated Since version __0.5.*__ key identity calculation for asymmetric keys is updated
to make it safer for theoretic future attack on blake2b hashing. Key.id values to make it safer for theoretic future attack on blake2b hashing. Key.id values
are incompatible with older. Sorry for inconvenience. are incompatible with older. Sorry for inconvenience.
@ -19,7 +21,7 @@ repositories {
maven("https://gitea.sergeych.net/api/packages/SergeychWorks/maven") maven("https://gitea.sergeych.net/api/packages/SergeychWorks/maven")
} }
dependencies { dependencies {
import("net.sergeych:crypto2:0.5.8") import("net.sergeych:crypto2:0.7.1-SNAPSHOT")
} }
``` ```

View File

@ -9,7 +9,7 @@ plugins {
} }
group = "net.sergeych" group = "net.sergeych"
version = "0.6.3-SNAPSHOT" version = "0.7.1-SNAPSHOT"
repositories { repositories {
mavenCentral() mavenCentral()

View File

@ -30,6 +30,7 @@ class SigningSecretKey(
override fun seal(message: UByteArray, expiresAt: Instant?): Seal = override fun seal(message: UByteArray, expiresAt: Instant?): Seal =
Seal.create(this, message, now(), expiresAt) Seal.create(this, message, now(), expiresAt)
@Transient
override val id: KeyId = verifyingKey.id override val id: KeyId = verifyingKey.id
override val label: String override val label: String

View File

@ -3,6 +3,8 @@ import com.ionspin.kotlin.crypto.util.encodeToUByteArray
import kotlinx.coroutines.test.runTest import kotlinx.coroutines.test.runTest
import kotlinx.serialization.encodeToString import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json import kotlinx.serialization.json.Json
import net.sergeych.bipack.BipackDecoder
import net.sergeych.bipack.BipackEncoder
import net.sergeych.crypto2.* import net.sergeych.crypto2.*
import net.sergeych.tools.bipack import net.sergeych.tools.bipack
import net.sergeych.tools.biunpack import net.sergeych.tools.biunpack
@ -390,4 +392,28 @@ class KeysTest {
assertNull(Container.decrypt<String>(bytes, kr1)) assertNull(Container.decrypt<String>(bytes, kr1))
assertEquals(data, Container.decrypt<String>(bytes, kr2)) assertEquals(data, Container.decrypt<String>(bytes, kr2))
} }
@Test
fun testEncodedSizes() = runTest {
initCrypto()
val x = SigningSecretKey.new()
// println("key bytes: ${x.keyBytes.size}:\n${x.keyBytes.toDump()}")
val y = BipackEncoder.encode(x)
// println("packed: ${y.size}: ${y.toDump()}")
assertTrue { x.keyBytes.size + 5 > y.size }
assertEquals(x, BipackDecoder.decode<SigningSecretKey>(y))
assertContentEquals(x.keyBytes, BipackDecoder.decode<SigningSecretKey>(y).keyBytes)
}
@Test
fun testEncodedSizes2() = runTest {
initCrypto()
val x = SecretKey.new()
// println("key bytes: ${x.keyBytes.size}:\n${x.keyBytes.toDump()}")
val y = BipackEncoder.encode(x)
// println("packed: ${y.size}: ${y.toDump()}")
assertTrue { x.keyBytes.size + 5 > y.size }
assertEquals(x, BipackDecoder.decode<SecretKey>(y))
assertContentEquals(x.keyBytes, BipackDecoder.decode<SecretKey>(y).keyBytes)
}
} }