public static bool DoVerifyEcDsaSha256P256_old(IEnumerable <BufLen> bufs, I2PSigningPublicKey key, I2PSignature signed) { if (!SupportedSignatureType(signed.Certificate.SignatureType)) { throw new NotImplementedException(); } var sha = new Sha256Digest(); foreach (var buf in bufs) { sha.BlockUpdate(buf.BaseArray, buf.BaseArrayOffset, buf.Length); } var hash = new byte[sha.GetDigestSize()]; sha.DoFinal(hash, 0); var p = Org.BouncyCastle.Asn1.Nist.NistNamedCurves.GetByName("P-256"); var param = new ECDomainParameters(p.Curve, p.G, p.N, p.H); var pk = new ECPublicKeyParameters(p.Curve.DecodePoint(key.ToByteArray()), param); var dsa = new Org.BouncyCastle.Crypto.Signers.DsaSigner(); var sigsize = signed.Certificate.SignatureLength; var r = new BigInteger(1, signed.Sig.BaseArray, signed.Sig.BaseArrayOffset + 0, sigsize / 2); var s = new BigInteger(1, signed.Sig.BaseArray, signed.Sig.BaseArrayOffset + sigsize / 2, sigsize / 2); dsa.Init(false, pk); var result = dsa.VerifySignature(hash, r, s); DebugUtils.LogDebug("DoVerifyEcDsaSha256P256: " + result.ToString()); return(result); }
public static bool DoVerifyEcDsa( IEnumerable <BufLen> bufs, I2PSigningPublicKey key, I2PSignature signed, IDigest digest, X9ECParameters ecparam) { if (!SupportedSignatureType(signed.Certificate.SignatureType)) { throw new NotImplementedException(); } foreach (var buf in bufs) { digest.BlockUpdate(buf.BaseArray, buf.BaseArrayOffset, buf.Length); } var hash = new byte[digest.GetDigestSize()]; digest.DoFinal(hash, 0); var param = new ECDomainParameters(ecparam.Curve, ecparam.G, ecparam.N, ecparam.H); var pk = new ECPublicKeyParameters(ecparam.Curve.DecodePoint(key.ToByteArray()), param); var dsa = new Org.BouncyCastle.Crypto.Signers.DsaSigner(); var sigsize = signed.Certificate.SignatureLength; var r = new BigInteger(1, signed.Sig.BaseArray, signed.Sig.BaseArrayOffset, sigsize / 2); var s = new BigInteger(1, signed.Sig.BaseArray, signed.Sig.BaseArrayOffset + sigsize / 2, sigsize / 2); dsa.Init(false, pk); var result = dsa.VerifySignature(hash, r, s); DebugUtils.LogDebug("DoVerifyEcDsa: " + result.ToString() + ": " + digest.ToString()); return(result); }
public static bool DoVerify(I2PSigningPublicKey key, I2PSignature signed, params BufLen[] bufs) { //DebugUtils.LogDebug( "DoVerify: " + key.Certificate.SignatureType.ToString() ); switch (key.Certificate.SignatureType) { case I2PSigningKey.SigningKeyTypes.DSA_SHA1: return(DoVerifyDsaSha1(bufs, key, signed)); case I2PSigningKey.SigningKeyTypes.ECDSA_SHA256_P256: return(DoVerifyEcDsa(bufs, key, signed, new Sha256Digest(), NistNamedCurves.GetByName("P-256"))); case I2PSigningKey.SigningKeyTypes.ECDSA_SHA384_P384: return(DoVerifyEcDsa(bufs, key, signed, new Sha384Digest(), NistNamedCurves.GetByName("P-384"))); case I2PSigningKey.SigningKeyTypes.ECDSA_SHA512_P521: return(DoVerifyEcDsa(bufs, key, signed, new Sha512Digest(), NistNamedCurves.GetByName("P-521"))); case I2PSigningKey.SigningKeyTypes.EdDSA_SHA512_Ed25519: return(DoVerifyEdDSASHA512Ed25519(bufs, key, signed)); default: throw new NotImplementedException(); } }
public static bool DoVerifyDsaSha1(IEnumerable <BufLen> bufs, I2PSigningPublicKey key, I2PSignature signed) { if (!SupportedSignatureType(signed.Certificate.SignatureType)) { throw new NotImplementedException(); } var sha = new Sha1Digest(); foreach (var buf in bufs) { sha.BlockUpdate(buf.BaseArray, buf.BaseArrayOffset, buf.Length); } var hash = new byte[sha.GetDigestSize()]; sha.DoFinal(hash, 0); var dsa = new Org.BouncyCastle.Crypto.Signers.DsaSigner(); var sigsize = signed.Certificate.SignatureLength; var r = new BigInteger(1, signed.Sig.BaseArray, signed.Sig.BaseArrayOffset + 0, sigsize / 2); var s = new BigInteger(1, signed.Sig.BaseArray, signed.Sig.BaseArrayOffset + sigsize / 2, sigsize / 2); var dsaparams = new DsaPublicKeyParameters( key.ToBigInteger(), new DsaParameters( I2PConstants.DsaP, I2PConstants.DsaQ, I2PConstants.DsaG)); dsa.Init(false, dsaparams); return(dsa.VerifySignature(hash, r, s)); }
public I2PLeaseInfo(I2PDestinationInfo di) { PublicKey = di.Destination.PublicKey; PrivateKey = di.PrivateKey; PrivateSigningKey = di.PrivateSigningKey; PublicSigningKey = di.Destination.SigningPublicKey; }
public I2PDestinationInfo(BufRef reader) { Certificate = new I2PCertificate(reader); PrivateKey = new I2PPrivateKey(reader, Certificate); PublicKey = new I2PPublicKey(reader, Certificate); PrivateSigningKey = new I2PSigningPrivateKey(reader, Certificate); PublicSigningKey = new I2PSigningPublicKey(reader, Certificate); }
public I2PKeysAndCert(I2PPublicKey pubkey, I2PSigningPublicKey signkey) { Data = new BufLen(new byte[RecordSize(signkey.Certificate)]); Data.Randomize(); Certificate = signkey.Certificate; PublicKey = pubkey; SigningPublicKey = signkey; }
public static bool DoVerifyEdDSASHA512Ed25519(IEnumerable <BufLen> bufs, I2PSigningPublicKey key, I2PSignature signed) { return(Chaos.NaCl.Ed25519.Verify( signed.Sig.ToByteArray(), bufs.SelectMany(b => b .ToByteArray()) .ToArray(), key.ToByteArray())); }
public I2PDestinationInfo(string base64) { var reader = new BufRefLen(FreenetBase64.Decode(base64)); Certificate = new I2PCertificate(reader); PrivateKey = new I2PPrivateKey(reader, Certificate); PublicKey = new I2PPublicKey(reader, Certificate); PrivateSigningKey = new I2PSigningPrivateKey(reader, Certificate); PublicSigningKey = new I2PSigningPublicKey(reader, Certificate); }
public I2PLeaseInfo( I2PPublicKey pubkey, I2PSigningPublicKey spubkey, I2PPrivateKey privkey, I2PSigningPrivateKey sprivkey) { PublicKey = pubkey; PrivateKey = privkey; PrivateSigningKey = sprivkey; PublicSigningKey = spubkey; }
public I2PDestinationInfo(I2PSigningKey.SigningKeyTypes signkeytype) { Certificate = new I2PCertificate(signkeytype); var keys = I2PPrivateKey.GetNewKeyPair(); PublicKey = keys.PublicKey; PrivateKey = keys.PrivateKey; PrivateSigningKey = new I2PSigningPrivateKey(Certificate); PublicSigningKey = new I2PSigningPublicKey(PrivateSigningKey); }
public I2PLeaseSet(I2PKeysAndCert dest, IEnumerable <I2PLease> leases, I2PLeaseInfo info) { Destination = dest; Leases = new List <I2PLease>(); if (leases != null) { Leases.AddRange(leases); } Info = info; PublicKey = info.PublicKey; PublicSigningKey = info.PublicSigningKey; }
public I2PDestinationInfo( I2PCertificate cert, I2PPublicKey pubkey, I2PSigningPublicKey spubkey, I2PPrivateKey privkey, I2PSigningPrivateKey sprivkey) { Certificate = cert; PublicKey = pubkey; PrivateKey = privkey; PrivateSigningKey = sprivkey; PublicSigningKey = spubkey; }
public I2PLeaseSet(BufRef reader) { Destination = new I2PDestination(reader); PublicKey = new I2PPublicKey(reader, I2PKeyType.DefaultAsymetricKeyCert); PublicSigningKey = new I2PSigningPublicKey(reader, Destination.Certificate); var leases = new List <I2PLease>(); int leasecount = reader.Read8(); for (int i = 0; i < leasecount; ++i) { leases.Add(new I2PLease(reader)); } Leases = leases; Signature = new I2PSignature(reader, Destination.Certificate); }
public I2PRouterIdentity(I2PPublicKey pubkey, I2PSigningPublicKey signkey) : base(pubkey, signkey) { }
public I2PDestination(I2PPublicKey pubkey, I2PSigningPublicKey signkey) : base(pubkey, signkey) { }