Esempio n. 1
0
        public unsafe void SetPeerKey(ReadableBuffer peerKey)
        {
            GenerateKeys(null, null);
            if (peerKey.Length != _keyExchangeSize)
            {
                Alerts.AlertException.ThrowAlert(Alerts.AlertLevel.Fatal, Alerts.AlertDescription.illegal_parameter, "The client key didn't match the expected size");
            }
            GCHandle handle = default(GCHandle);

            try
            {
                void *ptr;
                if (peerKey.IsSingleSpan)
                {
                    ptr = peerKey.First.GetPointer(out handle);
                }
                else
                {
                    var sBuffer = stackalloc byte[peerKey.Length];
                    peerKey.CopyTo(new Span <byte>(sBuffer, peerKey.Length));
                    ptr = sBuffer;
                }
                _clientBN = BN_bin2bn(ptr, peerKey.Length, IntPtr.Zero);
            }
            finally
            {
                if (handle.IsAllocated)
                {
                    handle.Free();
                }
            }
            _hasPeerKey = true;
        }
Esempio n. 2
0
 public static unsafe int BN_bn2binpad(BIGNUM a, Span <byte> buffer)
 {
     fixed(void *ptr = &buffer.DangerousGetPinnableReference())
     {
         return(BN_bn2binpad(a, ptr, buffer.Length));
     }
 }
Esempio n. 3
0
 public static unsafe int DH_compute_key(Span <byte> key, BIGNUM pub_key, DH dh)
 {
     fixed(void *ptr = &key.DangerousGetPinnableReference())
     {
         return(Internal_DH_compute_key(ptr, pub_key, dh));
     }
 }
Esempio n. 4
0
 internal static extern void DH_get0_key(DH dh, out BIGNUM pub_key, out BIGNUM priv_key);
Esempio n. 5
0
 private static extern unsafe int BN_bn2binpad(BIGNUM a, void *to, int tolen);
Esempio n. 6
0
        public static void DH_set0_key(DH dh, BIGNUM pub_key, BIGNUM priv_key)
        {
            var result = Internal_DH_set0_key(dh, pub_key, priv_key);

            ThrowOnErrorReturnCode(result);
        }
Esempio n. 7
0
 private static extern int Internal_DH_set0_key(DH dh, BIGNUM pub_key, BIGNUM priv_key);
Esempio n. 8
0
        public static void DH_set0_pqg(DH dh, BIGNUM p, BIGNUM q, BIGNUM g)
        {
            var result = Internal_DH_set0_pqg(dh, p, q, g);

            ThrowOnErrorReturnCode(result);
        }
Esempio n. 9
0
 private static extern int Internal_DH_set0_pqg(DH dh, BIGNUM p, BIGNUM q, BIGNUM g);
Esempio n. 10
0
 internal static extern int DH_set0_pqg(DH dh, BIGNUM p, BIGNUM q, BIGNUM g);
Esempio n. 11
0
 internal static extern unsafe int DH_compute_key(byte *key, BIGNUM pub_key, DH dh);
Esempio n. 12
0
 internal static extern int DH_set0_key(DH dh, BIGNUM pub_key, BIGNUM priv_key);
Esempio n. 13
0
 private static extern unsafe int Internal_DH_compute_key(void *key, BIGNUM pub_key, DH dh);
Esempio n. 14
0
        public unsafe KeyshareProvider()
        {
            byte val = 2;

            _numberTwo = BN_bin2bn(&val, 1, IntPtr.Zero);
        }