コード例 #1
0
        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 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();
     }
 }
コード例 #3
0
 public static void Copy(ECPointHandle to, ECPointHandle from)
 {
     Debug.Assert(!to.IsInvalid, $"Accessed an invalid ECPointHandle! <{nameof(to)}>");
     Debug.Assert(!from.IsInvalid, $"Accessed an invalid ECPointHandle! <{nameof(from)}>");
     if (EC_POINT_copy(to, from) == 0)
     {
         throw new OpenSslNativeException();
     }
 }
コード例 #4
0
        /// <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);
        }
コード例 #5
0
 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();
     }
 }
コード例 #6
0
 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();
     }
 }
コード例 #7
0
        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();
            }
        }
コード例 #8
0
 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();
     }
 }
コード例 #9
0
 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();
     }
 }
コード例 #10
0
        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);
        }
コード例 #11
0
        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);
        }
コード例 #12
0
        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);
        }
コード例 #13
0
 private extern static int EC_POINT_add(ECGroupHandle group, ECPointHandle r, ECPointHandle a, ECPointHandle b, BigNumberContextHandle ctx);
コード例 #14
0
 private extern static int EC_POINT_is_at_infinity(ECGroupHandle group, ECPointHandle p);
コード例 #15
0
 private extern static int EC_POINT_oct2point(ECGroupHandle group, ECPointHandle p, byte[] buffer, int bufferLen, BigNumberContextHandle ctx);
コード例 #16
0
 private extern static int EC_POINT_point2oct(ECGroupHandle group, ECPointHandle p, PointEncoding form, byte[]?buffer, int bufferLen, BigNumberContextHandle contextHandle);
コード例 #17
0
 private extern static int EC_POINT_invert(ECGroupHandle group, ECPointHandle a, BigNumberContextHandle ctx);
コード例 #18
0
 private extern static int EC_POINT_is_on_curve(ECGroupHandle group, ECPointHandle point, BigNumberContextHandle ctx);
コード例 #19
0
 private extern static int EC_POINT_set_to_infinity(ECGroupHandle group, ECPointHandle point);
コード例 #20
0
 private extern static int EC_POINT_mul(ECGroupHandle group, ECPointHandle r, BigNumberHandle n, ECPointHandle q, BigNumberHandle m, BigNumberContextHandle ctx);
コード例 #21
0
 private extern static int EC_POINT_get_affine_coordinates(ECGroupHandle group, ECPointHandle p, BigNumberHandle x, BigNumberHandle y, BigNumberContextHandle ctx);
コード例 #22
0
 private extern static int EC_POINT_copy(ECPointHandle dst, ECPointHandle src);