forked from I2P_Developers/i2p.i2p
Support "raw" EdDSA signatures (in reality they are double-hashed)
This commit is contained in:
@ -42,6 +42,7 @@ import java.security.interfaces.ECKey;
|
|||||||
import java.security.interfaces.RSAKey;
|
import java.security.interfaces.RSAKey;
|
||||||
|
|
||||||
import net.i2p.I2PAppContext;
|
import net.i2p.I2PAppContext;
|
||||||
|
import net.i2p.crypto.eddsa.EdDSAKey;
|
||||||
import net.i2p.data.Hash;
|
import net.i2p.data.Hash;
|
||||||
import net.i2p.data.Signature;
|
import net.i2p.data.Signature;
|
||||||
import net.i2p.data.SigningPrivateKey;
|
import net.i2p.data.SigningPrivateKey;
|
||||||
@ -549,7 +550,11 @@ public class DSAEngine {
|
|||||||
throw new IllegalArgumentException("type mismatch hash=" + hash.getClass() + " key=" + type);
|
throw new IllegalArgumentException("type mismatch hash=" + hash.getClass() + " key=" + type);
|
||||||
|
|
||||||
String algo = getRawAlgo(type);
|
String algo = getRawAlgo(type);
|
||||||
java.security.Signature jsig = java.security.Signature.getInstance(algo);
|
java.security.Signature jsig;
|
||||||
|
if (type.getBaseAlgorithm() == SigAlgo.EdDSA)
|
||||||
|
jsig = new net.i2p.crypto.eddsa.EdDSAEngine(); // Ignore algo, EdDSAKey includes a hash specification.
|
||||||
|
else
|
||||||
|
jsig = java.security.Signature.getInstance(algo);
|
||||||
jsig.initVerify(pubKey);
|
jsig.initVerify(pubKey);
|
||||||
jsig.update(hash.getData());
|
jsig.update(hash.getData());
|
||||||
boolean rv = jsig.verify(SigUtil.toJavaSig(signature));
|
boolean rv = jsig.verify(SigUtil.toJavaSig(signature));
|
||||||
@ -623,7 +628,11 @@ public class DSAEngine {
|
|||||||
if (type.getHashLen() != hashlen)
|
if (type.getHashLen() != hashlen)
|
||||||
throw new IllegalArgumentException("type mismatch hash=" + hash.getClass() + " key=" + type);
|
throw new IllegalArgumentException("type mismatch hash=" + hash.getClass() + " key=" + type);
|
||||||
|
|
||||||
java.security.Signature jsig = java.security.Signature.getInstance(algo);
|
java.security.Signature jsig;
|
||||||
|
if (type.getBaseAlgorithm() == SigAlgo.EdDSA)
|
||||||
|
jsig = new net.i2p.crypto.eddsa.EdDSAEngine(); // Ignore algo, EdDSAKey includes a hash specification.
|
||||||
|
else
|
||||||
|
jsig = java.security.Signature.getInstance(algo);
|
||||||
jsig.initSign(privKey, _context.random());
|
jsig.initSign(privKey, _context.random());
|
||||||
jsig.update(hash.getData());
|
jsig.update(hash.getData());
|
||||||
return SigUtil.fromJavaSig(jsig.sign(), type);
|
return SigUtil.fromJavaSig(jsig.sign(), type);
|
||||||
@ -650,6 +659,8 @@ public class DSAEngine {
|
|||||||
return "NONEwithDSA";
|
return "NONEwithDSA";
|
||||||
case EC:
|
case EC:
|
||||||
return "NONEwithECDSA";
|
return "NONEwithECDSA";
|
||||||
|
case EdDSA:
|
||||||
|
return "NONEwithEdDSA";
|
||||||
case RSA:
|
case RSA:
|
||||||
return "NONEwithRSA";
|
return "NONEwithRSA";
|
||||||
default:
|
default:
|
||||||
@ -663,6 +674,8 @@ public class DSAEngine {
|
|||||||
return "NONEwithDSA";
|
return "NONEwithDSA";
|
||||||
if (key instanceof ECKey)
|
if (key instanceof ECKey)
|
||||||
return "NONEwithECDSA";
|
return "NONEwithECDSA";
|
||||||
|
if (key instanceof EdDSAKey)
|
||||||
|
return "NONEwithEdDSA";
|
||||||
if (key instanceof RSAKey)
|
if (key instanceof RSAKey)
|
||||||
return "NONEwithRSA";
|
return "NONEwithRSA";
|
||||||
throw new IllegalArgumentException();
|
throw new IllegalArgumentException();
|
||||||
|
Reference in New Issue
Block a user