Abstract class for elliptic curve parameters.
Example #1
0
        /// <summary>
        /// Parses an elliptic curve point.
        /// </summary>
        /// <param name="data">octet data</param>
        /// <param name="ec">elliptic curve domain parameters</param>
        /// <param name="p">an elliptic curve point object</param>
        /// <returns>true if parsing and validation succeeded</returns>
        public static bool Parse(byte[] data, EllipticCurve ec, out ECPoint p) {
            if (IsZero(data)) {
                // point at infinity
                p = null;
                return false;
            }

            if (data.Length < 2) {
                // invalid length
                p = null;
                return false;
            }

            if (data[0] == 0x04) {
                ECPoint tmp = ParseUncompressed(data);
                if (tmp == null) {
                    p = null;
                    return false;
                }
                if (!ec.ValidatePoint(tmp)) {
                    p = null;
                    return false;
                }
                p = tmp;
                p.Validated = true;
                return true;
            }

            // Compressed form of EC point is not supported.
            // OpenSSL, which is used by OpenSSH for cryptography, disables
            // EC point compression by default due to the patent reason.

            p = null;
            return false;
        }
Example #2
0
        /// <summary>
        /// Chooses a hashing algorithm.
        /// </summary>
        /// <remarks>
        /// Hashing algorithm is determined according to the curve size as described in RFC5656.
        /// </remarks>
        /// <param name="curve">elliptic curve</param>
        /// <returns>new instance of the hashing algorithm</returns>
        public static HashAlgorithm Choose(EllipticCurve curve) {
            int orderBits = curve.Order.BitCount();

            if (orderBits <= 256) {
                return new SHA256CryptoServiceProvider();
            }
            else if (orderBits <= 384) {
                return new SHA384CryptoServiceProvider();
            }
            else {
                return new SHA512CryptoServiceProvider();
            }
        }
Example #3
0
        /// <summary>
        /// Hash data for signing
        /// </summary>
        /// <param name="data">data to be hashed</param>
        /// <param name="curve">elliptic curve for determining hashing algorithm</param>
        /// <returns></returns>
        internal byte[] HashForSigning(byte[] data, EllipticCurve curve) {

            byte[] hash;
            using (var hashAlgorithm = ECDSAHashAlgorithmChooser.Choose(curve)) {
                hash = hashAlgorithm.ComputeHash(data);
            }

            return ExtractLeftBits(hash, curve.Order.BitCount());
        }
Example #4
0
 /// <summary>
 ///  Constructor
 /// </summary>
 /// <param name="curve">elliptic curve</param>
 /// <param name="publicKey">public key</param>
 /// <param name="privateKey">private key</param>
 public ECDSAKeyPair(EllipticCurve curve, ECDSAPublicKey publicKey, BigInteger privateKey) {
     _curve = curve;
     _publicKey = publicKey;
     _privateKey = privateKey;
 }
Example #5
0
 public ECDSAPublicKey(EllipticCurve curve, ECPoint point) {
     _curve = curve;
     _point = point;
 }