コード例 #1
0
ファイル: ScalarMult.cs プロジェクト: archerland/UCS-3
        /// <summary>
        ///     Diffie-Hellman (function computes the public key)
        /// </summary>
        /// <param name="secretKey">A secret key.</param>
        /// <returns>A computed public key.</returns>
        /// <exception cref="KeyOutOfRangeException"></exception>
        public static byte[] Base(byte[] secretKey)
        {
            //validate the length of the scalar
            if (secretKey == null || secretKey.Length != SCALAR_BYTES)
            {
                throw new KeyOutOfRangeException("secretKey", secretKey == null ? 0 : secretKey.Length,
                                                 string.Format("secretKey must be {0} bytes in length.", SCALAR_BYTES));
            }

            var publicKey = new byte[SCALAR_BYTES];

            SodiumLibrary.crypto_scalarmult_base(publicKey, secretKey);

            return(publicKey);
        }