mirror of
https://github.com/corda/corda.git
synced 2025-01-31 08:25:50 +00:00
core: switch to ed25519
This commit is contained in:
parent
9930e8d5c7
commit
1fe283c113
@ -1,13 +1,14 @@
|
|||||||
package com.r3corda.core.crypto
|
package com.r3corda.core.crypto
|
||||||
|
|
||||||
import com.google.common.io.BaseEncoding
|
import com.google.common.io.BaseEncoding
|
||||||
import com.r3corda.core.crypto.Party
|
|
||||||
import com.r3corda.core.serialization.OpaqueBytes
|
import com.r3corda.core.serialization.OpaqueBytes
|
||||||
import com.r3corda.core.serialization.SerializedBytes
|
import com.r3corda.core.serialization.SerializedBytes
|
||||||
import com.r3corda.core.serialization.deserialize
|
import com.r3corda.core.serialization.deserialize
|
||||||
|
import net.i2p.crypto.eddsa.EdDSAEngine
|
||||||
import java.math.BigInteger
|
import java.math.BigInteger
|
||||||
import java.security.*
|
import java.security.*
|
||||||
import java.security.interfaces.ECPublicKey
|
import java.security.interfaces.ECPublicKey
|
||||||
|
import net.i2p.crypto.eddsa.KeyPairGenerator as EddsaKeyPairGenerator
|
||||||
|
|
||||||
// "sealed" here means there can't be any subclasses other than the ones defined here.
|
// "sealed" here means there can't be any subclasses other than the ones defined here.
|
||||||
sealed class SecureHash private constructor(bits: ByteArray) : OpaqueBytes(bits) {
|
sealed class SecureHash private constructor(bits: ByteArray) : OpaqueBytes(bits) {
|
||||||
@ -118,7 +119,7 @@ class DummyPublicKey(val s: String) : PublicKey, Comparable<PublicKey> {
|
|||||||
|
|
||||||
/** Utility to simplify the act of signing a byte array */
|
/** Utility to simplify the act of signing a byte array */
|
||||||
fun PrivateKey.signWithECDSA(bits: ByteArray): DigitalSignature {
|
fun PrivateKey.signWithECDSA(bits: ByteArray): DigitalSignature {
|
||||||
val signer = Signature.getInstance("SHA256withECDSA")
|
val signer = EdDSAEngine()
|
||||||
signer.initSign(this)
|
signer.initSign(this)
|
||||||
signer.update(bits)
|
signer.update(bits)
|
||||||
val sig = signer.sign()
|
val sig = signer.sign()
|
||||||
@ -140,7 +141,7 @@ fun KeyPair.signWithECDSA(bitsToSign: ByteArray, party: Party): DigitalSignature
|
|||||||
|
|
||||||
/** Utility to simplify the act of verifying a signature */
|
/** Utility to simplify the act of verifying a signature */
|
||||||
fun PublicKey.verifyWithECDSA(content: ByteArray, signature: DigitalSignature) {
|
fun PublicKey.verifyWithECDSA(content: ByteArray, signature: DigitalSignature) {
|
||||||
val verifier = Signature.getInstance("SHA256withECDSA")
|
val verifier = EdDSAEngine()
|
||||||
verifier.initVerify(this)
|
verifier.initVerify(this)
|
||||||
verifier.update(content)
|
verifier.update(content)
|
||||||
if (verifier.verify(signature.bits) == false)
|
if (verifier.verify(signature.bits) == false)
|
||||||
@ -160,4 +161,4 @@ operator fun KeyPair.component1() = this.private
|
|||||||
operator fun KeyPair.component2() = this.public
|
operator fun KeyPair.component2() = this.public
|
||||||
|
|
||||||
/** A simple wrapper that will make it easier to swap out the EC algorithm we use in future */
|
/** A simple wrapper that will make it easier to swap out the EC algorithm we use in future */
|
||||||
fun generateKeyPair() = KeyPairGenerator.getInstance("EC").genKeyPair()
|
fun generateKeyPair() = EddsaKeyPairGenerator().generateKeyPair()
|
Loading…
x
Reference in New Issue
Block a user