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; }
public static unsafe int BN_bn2binpad(BIGNUM a, Span <byte> buffer) { fixed(void *ptr = &buffer.DangerousGetPinnableReference()) { return(BN_bn2binpad(a, ptr, buffer.Length)); } }
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)); } }
internal static extern void DH_get0_key(DH dh, out BIGNUM pub_key, out BIGNUM priv_key);
private static extern unsafe int BN_bn2binpad(BIGNUM a, void *to, int tolen);
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); }
private static extern int Internal_DH_set0_key(DH dh, BIGNUM pub_key, BIGNUM priv_key);
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); }
private static extern int Internal_DH_set0_pqg(DH dh, BIGNUM p, BIGNUM q, BIGNUM g);
internal static extern int DH_set0_pqg(DH dh, BIGNUM p, BIGNUM q, BIGNUM g);
internal static extern unsafe int DH_compute_key(byte *key, BIGNUM pub_key, DH dh);
internal static extern int DH_set0_key(DH dh, BIGNUM pub_key, BIGNUM priv_key);
private static extern unsafe int Internal_DH_compute_key(void *key, BIGNUM pub_key, DH dh);
public unsafe KeyshareProvider() { byte val = 2; _numberTwo = BN_bin2bn(&val, 1, IntPtr.Zero); }