Exemplo n.º 1
0
        /// <inheritdoc />
        public (SecureBigNumber, ECPoint) GenerateRandomElement(RandomNumberGenerator randomNumberGenerator)
        {
            using (var keyHandle = ECKeyHandle.Create())
            {
                ECKeyHandle.SetGroup(keyHandle, Handle);

                // note(lumip): OpenSSL up to version 1.1.1 does not generate private keys for EC
                //  as secure BIGNUM. Workaround by setting an empty secure private key BIGNUM before
                //  generation. (cf. https://github.com/openssl/openssl/issues/13892)
                using (var privKeyTemplateHandle = BigNumberHandle.CreateSecure())
                {
                    ECKeyHandle.SetPrivateKey(keyHandle, privKeyTemplateHandle);
                }
                ECKeyHandle.GenerateKey(keyHandle);

                // note(lumip): ensure the workaround worked
                var privKeyHandle = ECKeyHandle.GetPrivateKey(keyHandle);
                Debug.Assert(!privKeyHandle.IsInvalid);
                Debug.Assert(BigNumberHandle.GetFlags(privKeyHandle).HasFlag(BigNumberFlags.Secure));

                var pubKeyHandle = ECKeyHandle.GetPublicKey(keyHandle);
                Debug.Assert(!pubKeyHandle.IsInvalid);
                var point = new ECPoint(Handle, pubKeyHandle);

                var index = SecureBigNumber.FromRawHandle(privKeyHandle);
                return(index, point);
            }
        }
 /// <summary>
 /// Creates a new uninitialized <see cref="SecureBigNumber" /> instance.
 /// </summary>
 public SecureBigNumber()
 {
     Handle = BigNumberHandle.CreateSecure();
 }
Exemplo n.º 3
0
        public void TestFromRawHandleFailsWithSecure()
        {
            var secureHandle = BigNumberHandle.CreateSecure();

            Assert.Throws <ArgumentException>(() => BigNumber.FromRawHandle(secureHandle));
        }