public static bool IsAtInfinity(ECGroupHandle group, ECPointHandle p)
        {
            Debug.Assert(!group.IsInvalid, $"Accessed an invalid ECGroupHandle! <{nameof(group)}>");
            Debug.Assert(!p.IsInvalid, $"Accessed an invalid ECPointHandle! <{nameof(p)}>");
            var result = EC_POINT_is_at_infinity(group, p);

            return(result == 1);
        }
示例#2
0
 public static void SetGroup(ECKeyHandle key, ECGroupHandle group)
 {
     Debug.Assert(!key.IsInvalid, $"Accessed an invalid ECKeyHandle! <{nameof(key)}>");
     Debug.Assert(!key.IsInvalid, $"Accessed an invalid ECGroupHandle! <{nameof(group)}>");
     if (EC_KEY_set_group(key, group) == 0)
     {
         throw new OpenSslNativeException();
     }
 }
示例#3
0
 public static void PrecomputeGeneratorMultiples(ECGroupHandle group, BigNumberContextHandle ctx)
 {
     Debug.Assert(!group.IsInvalid, $"Accessed an invalid ECGroupHandle! <{nameof(group)}>");
     Debug.Assert(!ctx.IsInvalid, $"Accessed an invalid BigNumberContextHandle! <{nameof(ctx)}>");
     if (EC_GROUP_precompute_mult(group, ctx) == 0)
     {
         throw new OpenSslNativeException();
     }
 }
 public static void SetToInfinity(ECGroupHandle group, ECPointHandle p)
 {
     Debug.Assert(!group.IsInvalid, $"Accessed an invalid ECGroupHandle! <{nameof(group)}>");
     Debug.Assert(!p.IsInvalid, $"Accessed an invalid ECPointHandle! <{nameof(p)}>");
     if (EC_POINT_set_to_infinity(group, p) == 0)
     {
         throw new OpenSslNativeException();
     }
 }
        /// <summary>
        /// Allocates a new OpenSSL <c>EC_POINT</c> structure and
        /// returns a handle to it.
        ///
        /// The returned handle is guaranteed to point to be valid,
        /// i.e., point to a valid <c>EC_POINT</c> structure.
        /// </summary>
        /// <param name="group">Valid handle to a OpenSSL <c>EC_GROUP</c> structure.</param>
        /// <returns>
        /// A valid <see cref="ECPointHandle" /> pointing to a freshly allocated
        /// <c>EC_POINT</c> structure associated with the <c>EC_GROUP</c> given by <paramref name="group"/>.
        /// </returns>
        public static ECPointHandle Create(ECGroupHandle group)
        {
            var point = new ECPointHandle(EC_POINT_new(group), ownsHandle: true);

            if (point.IsInvalid)
            {
                throw new OpenSslNativeException();
            }
            return(point);
        }
示例#6
0
        /// <summary>
        /// Allocates a new OpenSSL <c>EC_GROUP</c> structure for
        /// the curve indicated by <paramref name="nid"/> and
        /// returns a handle to it.
        ///
        /// The returned handle is guaranteed to point to be valid,
        /// i.e., point to a valid <c>EC_GROUP</c> structure.
        /// </summary>
        /// <returns>
        /// A valid <see cref="ECGroupHandle" /> pointing to a freshly allocated
        /// <c>EC_GROUP</c> structure.
        /// </returns>
        public static ECGroupHandle CreateByCurveNID(int nid)
        {
            var group = new ECGroupHandle(EC_GROUP_new_by_curve_name(nid), ownsHandle: true);

            if (group.IsInvalid)
            {
                throw new OpenSslNativeException();
            }
            return(group);
        }
示例#7
0
 public static void GetCofactor(ECGroupHandle group, BigNumberHandle cofactor, BigNumberContextHandle ctx)
 {
     Debug.Assert(!group.IsInvalid, $"Accessed an invalid ECGroupHandle! <{nameof(group)}>");
     Debug.Assert(!cofactor.IsInvalid, $"Accessed an invalid BigNumberHandle! <{nameof(cofactor)}>");
     Debug.Assert(!ctx.IsInvalid, $"Accessed an invalid BigNumberContextHandle! <{nameof(ctx)}>");
     if (EC_GROUP_get_cofactor(group, cofactor, ctx) == 0)
     {
         throw new OpenSslNativeException();
     }
 }
 public static void Multiply(ECGroupHandle group, ECPointHandle result, BigNumberHandle n, ECPointHandle q, BigNumberHandle m, BigNumberContextHandle ctx)
 {
     Debug.Assert(!group.IsInvalid, $"Accessed an invalid ECGroupHandle! <{nameof(group)}>");
     Debug.Assert(!result.IsInvalid, $"Accessed an invalid ECPointHandle! <{nameof(result)}>");
     Debug.Assert(!ctx.IsInvalid, $"Accessed an invalid BigNumberContextHandle! <{nameof(ctx)}>");
     if (EC_POINT_mul(group, result, n, q, m, ctx) == 0)
     {
         throw new OpenSslNativeException();
     }
 }
 public static void InvertInPlace(ECGroupHandle group, ECPointHandle p, BigNumberContextHandle ctx)
 {
     Debug.Assert(!group.IsInvalid, $"Accessed an invalid ECGroupHandle! <{nameof(group)}>");
     Debug.Assert(!p.IsInvalid, $"Accessed an invalid ECPointHandle! <{nameof(p)}>");
     Debug.Assert(!ctx.IsInvalid, $"Accessed an invalid BigNumberContextHandle! <{nameof(ctx)}>");
     if (EC_POINT_invert(group, p, ctx) == 0)
     {
         throw new OpenSslNativeException();
     }
 }
        public static void FromByteBuffer(ECGroupHandle group, ECPointHandle p, byte[] buffer, BigNumberContextHandle ctx)
        {
            Debug.Assert(!group.IsInvalid, $"Accessed an invalid ECGroupHandle! <{nameof(group)}>");
            Debug.Assert(!ctx.IsInvalid, $"Accessed an invalid BigNumberContextHandle! <{nameof(ctx)}>");
            var result = EC_POINT_oct2point(group, p, buffer, buffer.Length, ctx);

            if (result == 0)
            {
                throw new OpenSslNativeException();
            }
        }
示例#11
0
        public static int GetDegree(ECGroupHandle group)
        {
            Debug.Assert(!group.IsInvalid, $"Accessed an invalid ECGroupHandle! <{nameof(group)}>");
            var result = EC_GROUP_get_degree(group);

            if (result == 0)
            {
                throw new OpenSslNativeException();
            }
            return(result);
        }
示例#12
0
        public static ECPointHandle GetGenerator(ECGroupHandle group)
        {
            Debug.Assert(!group.IsInvalid, $"Accessed an invalid ECGroupHandle! <{nameof(group)}>");
            var generator = EC_GROUP_get0_generator(group);

            if (generator.IsInvalid)
            {
                throw new OpenSslNativeException();
            }
            return(generator);
        }
 public static void Add(ECGroupHandle group, ECPointHandle result, ECPointHandle a, ECPointHandle b, BigNumberContextHandle ctx)
 {
     Debug.Assert(!group.IsInvalid, $"Accessed an invalid ECGroupHandle! <{nameof(group)}>");
     Debug.Assert(!result.IsInvalid, $"Accessed an invalid ECPointHandle! <{nameof(result)}>");
     Debug.Assert(!a.IsInvalid, $"Accessed an invalid ECPointHandle! <{nameof(a)}>");
     Debug.Assert(!b.IsInvalid, $"Accessed an invalid ECPointHandle! <{nameof(b)}>");
     Debug.Assert(!ctx.IsInvalid, $"Accessed an invalid BigNumberContextHandle! <{nameof(ctx)}>");
     if (EC_POINT_add(group, result, a, b, ctx) == 0)
     {
         throw new OpenSslNativeException();
     }
 }
 public static void GetAffineCoordinates(ECGroupHandle group, ECPointHandle p, BigNumberHandle x, BigNumberHandle y, BigNumberContextHandle ctx)
 {
     Debug.Assert(!group.IsInvalid, $"Accessed an invalid ECGroupHandle! <{nameof(group)}>");
     Debug.Assert(!p.IsInvalid, $"Accessed an invalid ECPointHandle! <{nameof(p)}>");
     Debug.Assert(!x.IsInvalid, $"Accessed an invalid BigNumberHandle! <{nameof(x)}>");
     Debug.Assert(!y.IsInvalid, $"Accessed an invalid BigNumberHandle! <{nameof(y)}>");
     Debug.Assert(!ctx.IsInvalid, $"Accessed an invalid BigNumberContextHandle! <{nameof(ctx)}>");
     if (EC_POINT_get_affine_coordinates(group, p, x, y, ctx) == 0)
     {
         throw new OpenSslNativeException();
     }
 }
        public static bool IsOnCurve(ECGroupHandle group, ECPointHandle p, BigNumberContextHandle ctx)
        {
            Debug.Assert(!group.IsInvalid, $"Accessed an invalid ECGroupHandle! <{nameof(group)}>");
            Debug.Assert(!p.IsInvalid, $"Accessed an invalid ECPointHandle! <{nameof(p)}>");
            Debug.Assert(!ctx.IsInvalid, $"Accessed an invalid BigNumberContextHandle! <{nameof(ctx)}>");
            var result = EC_POINT_is_on_curve(group, p, ctx);

            if (result < 0)
            {
                throw new OpenSslNativeException();
            }
            return(result == 1);
        }
        public static bool Compare(ECGroupHandle group, ECPointHandle a, ECPointHandle b, BigNumberContextHandle ctx)
        {
            Debug.Assert(!group.IsInvalid, $"Accessed an invalid ECGroupHandle! <{nameof(group)}>");
            Debug.Assert(!a.IsInvalid, $"Accessed an invalid ECPointHandle! <{nameof(a)}>");
            Debug.Assert(!b.IsInvalid, $"Accessed an invalid ECPointHandle! <{nameof(b)}>");
            Debug.Assert(!ctx.IsInvalid, $"Accessed an invalid BigNumberContextHandle! <{nameof(ctx)}>");
            var result = EC_POINT_cmp(group, a, b, ctx);

            if (result < 0)
            {
                throw new OpenSslNativeException();
            }
            return(result == 0);
        }
示例#17
0
        public static bool Compare(ECGroupHandle a, ECGroupHandle b, BigNumberContextHandle ctx)
        {
            Debug.Assert(!a.IsInvalid, $"Accessed an invalid ECGroupHandle! <{nameof(a)}>");
            Debug.Assert(!b.IsInvalid, $"Accessed an invalid ECGroupHandle! <{nameof(b)}>");
            Debug.Assert(!ctx.IsInvalid, $"Accessed an invalid BigNumberContextHandle! <{nameof(ctx)}>");
            var result = EC_GROUP_cmp(a, b, ctx);

            if (result == -1)
            {
                throw new OpenSslNativeException();
            }
            else if (result == 0)
            {
                return(true);
            }
            return(false);
        }
        public static int ToByteBuffer(ECGroupHandle group, ECPointHandle p, PointEncoding form, byte[]?buffer, BigNumberContextHandle ctx)
        {
            Debug.Assert(!group.IsInvalid, $"Accessed an invalid ECGroupHandle! <{nameof(group)}>");
            Debug.Assert(!p.IsInvalid, $"Accessed an invalid ECPointHandle! <{nameof(p)}>");
            Debug.Assert(!ctx.IsInvalid, $"Accessed an invalid BigNumberContextHandle! <{nameof(ctx)}>");
            int bufferLen = 0;

            if (buffer != null)
            {
                bufferLen = buffer.Length;
            }
            bufferLen = EC_POINT_point2oct(group, p, form, buffer, bufferLen, ctx);
            if (bufferLen == 0)
            {
                throw new OpenSslNativeException();
            }
            return(bufferLen);
        }
 private extern static int EC_POINT_get_affine_coordinates(ECGroupHandle group, ECPointHandle p, BigNumberHandle x, BigNumberHandle y, BigNumberContextHandle ctx);
 private extern static int EC_POINT_is_at_infinity(ECGroupHandle group, ECPointHandle p);
 private extern static int EC_POINT_oct2point(ECGroupHandle group, ECPointHandle p, byte[] buffer, int bufferLen, BigNumberContextHandle ctx);
 private extern static int EC_POINT_point2oct(ECGroupHandle group, ECPointHandle p, PointEncoding form, byte[]?buffer, int bufferLen, BigNumberContextHandle contextHandle);
 private extern static int EC_POINT_invert(ECGroupHandle group, ECPointHandle a, BigNumberContextHandle ctx);
 private extern static int EC_POINT_is_on_curve(ECGroupHandle group, ECPointHandle point, BigNumberContextHandle ctx);
 private extern static int EC_POINT_set_to_infinity(ECGroupHandle group, ECPointHandle point);
 private extern static int EC_POINT_mul(ECGroupHandle group, ECPointHandle r, BigNumberHandle n, ECPointHandle q, BigNumberHandle m, BigNumberContextHandle ctx);
示例#27
0
 private extern static int EC_KEY_set_group(ECKeyHandle key, ECGroupHandle group);
示例#28
0
 public static int GetOrderNumberOfBits(ECGroupHandle group)
 {
     Debug.Assert(!group.IsInvalid, $"Accessed an invalid ECGroupHandle! <{nameof(group)}>");
     return(EC_GROUP_order_bits(group));
 }
 private extern static IntPtr EC_POINT_new(ECGroupHandle group);
 private extern static int EC_POINT_add(ECGroupHandle group, ECPointHandle r, ECPointHandle a, ECPointHandle b, BigNumberContextHandle ctx);