private BigInteger[] ParsePublicKey(DSA_Public_Key dpkKey) { BigInteger[] biReturn = new BigInteger[4]; biReturn[0] = dpkKey.p; biReturn[1] = dpkKey.q; biReturn[2] = dpkKey.g; biReturn[3] = dpkKey.y; return(biReturn); }
private DSA_Public_Key ParsePublicKey(PublicKeyPacket pkpKey) { DSA_Public_Key dpkKey = new DSA_Public_Key(); if (pkpKey.Algorithm != AsymAlgorithms.DSA) { throw(new System.ArgumentException("The given key is not supposed to be used with DSA!")); } if (pkpKey.KeyMaterial.Length != 4) { throw(new System.ArgumentException("The given key is not a valid key for DSA!")); } dpkKey.p = pkpKey.KeyMaterial[0]; dpkKey.q = pkpKey.KeyMaterial[1]; dpkKey.g = pkpKey.KeyMaterial[2]; dpkKey.y = pkpKey.KeyMaterial[3]; return(dpkKey); }
/// <summary> /// Public key operation. Verifies biSignature with the keydata /// in the given public key packet and returns true if the signature /// is valid. /// </summary> /// <param name="biSignature">The signature that is about to /// be verified</param> /// <param name="biHash">The hash value of the signed message.</param> /// <param name="pkpKey">The public key packet with the key /// material for the verification.</param> /// <returns>True if the signature is valid, otherwise /// false</returns> /// <remarks>No remarks</remarks> public override bool Verify(BigInteger[] biSignature, BigInteger biHash, PublicKeyPacket pkpKey) { if (biSignature == null) { throw new ArgumentNullException("rgbSignature"); } DSA_Public_Key dpkKey = new DSA_Public_Key(); dpkKey = ParsePublicKey(pkpKey); try { BigInteger m = biHash; BigInteger r = biSignature[0]; BigInteger s = biSignature[1]; if ((r < 0) || (dpkKey.q <= r)) { return(false); } if ((s < 0) || (dpkKey.q <= s)) { return(false); } BigInteger w = s.modInverse(dpkKey.q); BigInteger u1 = m * w % dpkKey.q; BigInteger u2 = r * w % dpkKey.q; u1 = dpkKey.g.modPow(u1, dpkKey.p); u2 = dpkKey.y.modPow(u2, dpkKey.p); BigInteger v = ((u1 * u2 % dpkKey.p) % dpkKey.q); return(v == r); } catch { throw new CryptographicException(); } }
private BigInteger[] ParsePublicKey(DSA_Public_Key dpkKey) { BigInteger[] biReturn = new BigInteger[4]; biReturn[0] = dpkKey.p; biReturn[1] = dpkKey.q; biReturn[2] = dpkKey.g; biReturn[3] = dpkKey.y; return biReturn; }
private DSA_Public_Key ParsePublicKey(PublicKeyPacket pkpKey) { DSA_Public_Key dpkKey = new DSA_Public_Key(); if (pkpKey.Algorithm != AsymAlgorithms.DSA) throw(new System.ArgumentException("The given key is not supposed to be used with DSA!")); if (pkpKey.KeyMaterial.Length != 4) throw(new System.ArgumentException("The given key is not a valid key for DSA!")); dpkKey.p = pkpKey.KeyMaterial[0]; dpkKey.q = pkpKey.KeyMaterial[1]; dpkKey.g = pkpKey.KeyMaterial[2]; dpkKey.y = pkpKey.KeyMaterial[3]; return dpkKey; }
/// <summary> /// Public key operation. Verifies biSignature with the keydata /// in the given public key packet and returns true if the signature /// is valid. /// </summary> /// <param name="biSignature">The signature that is about to /// be verified</param> /// <param name="biHash">The hash value of the signed message.</param> /// <param name="pkpKey">The public key packet with the key /// material for the verification.</param> /// <returns>True if the signature is valid, otherwise /// false</returns> /// <remarks>No remarks</remarks> public override bool Verify(BigInteger[] biSignature, BigInteger biHash, PublicKeyPacket pkpKey) { if (biSignature == null) throw new ArgumentNullException("rgbSignature"); DSA_Public_Key dpkKey = new DSA_Public_Key(); dpkKey = ParsePublicKey(pkpKey); try { BigInteger m = biHash; BigInteger r = biSignature[0]; BigInteger s = biSignature[1]; if ((r < 0) || (dpkKey.q <= r)) return false; if ((s < 0) || (dpkKey.q <= s)) return false; BigInteger w = s.modInverse(dpkKey.q); BigInteger u1 = m * w % dpkKey.q; BigInteger u2 = r * w % dpkKey.q; u1 = dpkKey.g.modPow(u1, dpkKey.p); u2 = dpkKey.y.modPow(u2, dpkKey.p); BigInteger v = ((u1 * u2 % dpkKey.p) % dpkKey.q); return (v == r); } catch { throw new CryptographicException(); } }