forked from sergeych/crypto2
0.5.3 incompatible but better asymmetric keys id (both encryption and signing)
This commit is contained in:
1 parent
6431d4896a
commit
134f619037
7 files changed
+38
-6
No files matched your search
@@ -23,7 +23,7 @@ import kotlinx.serialization.Serializable
|
||||
* password, see above.
|
||||
*/
|
||||
@Serializable
|
||||
data class KeyId(val id: BinaryId, val kdp: PBKD.Params?=null ) {
|
||||
data class KeyId(val id: BinaryId, val kdp: PBKD.Params? = null) {
|
||||
|
||||
/**
|
||||
* Binary array representation of the [id], not including the [kdp]. Used in [SafeKeyExchange]
|
||||
@@ -31,7 +31,7 @@ data class KeyId(val id: BinaryId, val kdp: PBKD.Params?=null ) {
|
||||
*/
|
||||
val binaryTag: UByteArray by lazy { id.id }
|
||||
|
||||
val keymagic: KeysmagicNumber by lazy { KeysmagicNumber.entries[id.magic]}
|
||||
val keymagic: KeysmagicNumber by lazy { KeysmagicNumber.entries[id.magic] }
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
@@ -45,6 +45,17 @@ data class KeyId(val id: BinaryId, val kdp: PBKD.Params?=null ) {
|
||||
|
||||
override fun toString() = id.toString()
|
||||
|
||||
constructor(magicNumber: KeysmagicNumber, keyData: UByteArray, kdp: PBKD.Params?=null)
|
||||
: this(BinaryId.createFromUBytes(magicNumber.ordinal, blake2b3l(keyData)), kdp)
|
||||
constructor(
|
||||
magicNumber: KeysmagicNumber,
|
||||
keyData: UByteArray,
|
||||
kdp: PBKD.Params? = null,
|
||||
donNotHash: Boolean = false,
|
||||
)
|
||||
: this(
|
||||
BinaryId.createFromUBytes(
|
||||
magicNumber.ordinal,
|
||||
if (donNotHash) keyData else blake2b3l(keyData)
|
||||
),
|
||||
kdp
|
||||
)
|
||||
}
|
||||
@@ -69,4 +69,6 @@ class PublicKey(override val keyBytes: UByteArray) : UniversalKey(), EncryptingK
|
||||
randomFill: IntRange? = null,
|
||||
): Asymmetric.Message =
|
||||
Asymmetric.createMessage(senderKey, this, WithFill.encode(plainData, randomFill))
|
||||
|
||||
override val id by lazy { KeyId(magic, keyBytes, null, true) }
|
||||
}
|
||||
@@ -13,7 +13,7 @@ sealed class UniversalKey: KeyInstance {
|
||||
open val magic: KeysmagicNumber = KeysmagicNumber.Unknown
|
||||
|
||||
|
||||
override val id by lazy { KeyId(magic, keyBytes) }
|
||||
override val id by lazy { KeyId(magic, keyBytes, null) }
|
||||
|
||||
// Important: id can be overridden, so we use it, not magic:
|
||||
open val label by lazy { id.keymagic.label }
|
||||
|
||||
@@ -24,4 +24,6 @@ class VerifyingPublicKey(override val keyBytes: UByteArray) : UniversalKey(), Ve
|
||||
|
||||
@Transient
|
||||
override val magic: KeysmagicNumber = KeysmagicNumber.defaultVerifying
|
||||
|
||||
override val id by lazy { KeyId(magic, keyBytes, null, true) }
|
||||
}
|
||||
Reference in new issue
Block a user