예제 #1
0
        ///// <summary>
        ///// Create new Ed25519 signature
        ///// </summary>
        ///// <param name="signature">Buffer for signature</param>
        ///// <param name="message">Message bytes</param>
        ///// <param name="expandedPrivateKey">Expanded form of private key</param>
        //public static void Sign(ArraySegment<byte> signature, ArraySegment<byte> message, ArraySegment<byte> expandedPrivateKey) {
        //	Contract.Requires<ArgumentNullException>(signature.Array != null && message.Array != null && expandedPrivateKey.Array != null);
        //	Contract.Requires<ArgumentException>(expandedPrivateKey.Count == ExpandedPrivateKeySize);

        //	Ed25519Operations.crypto_sign(signature.Array, signature.Offset, message.Array, message.Offset, message.Count, expandedPrivateKey.Array, expandedPrivateKey.Offset);
        //}

        ///// <summary>
        ///// Create new Ed25519 signature
        ///// </summary>
        ///// <param name="signature">Buffer for signature</param>
        ///// <param name="message">Message bytes</param>
        ///// <param name="expandedPrivateKey">Expanded form of private key</param>
        //public static byte[] Sign(byte[] message, byte[] expandedPrivateKey) {
        //	Contract.Requires<ArgumentNullException>(message != null && expandedPrivateKey != null);
        //	Contract.Requires<ArgumentException>(expandedPrivateKey.Length == ExpandedPrivateKeySize);

        //	var signature = new byte[SignatureSize];
        //	Sign(new ArraySegment<byte>(signature), new ArraySegment<byte>(message), new ArraySegment<byte>(expandedPrivateKey));
        //	return signature;
        //}

        public static byte[] SignWithPrehashed(byte[] message, byte[] privateKey, byte[] publicKey)
        {
            Contract.Requires <ArgumentNullException>(message != null && privateKey != null && publicKey != null);
            Contract.Requires <ArgumentException>(privateKey.Length == ExpandedPrivateKeySize);
            Contract.Requires <ArgumentException>(publicKey.Length == PublicKeySize);

            var signature = new byte[SignatureSize];

            Ed25519Operations.crypto_sign_prehashed(signature, message, message.Length, privateKey, publicKey);
            return(signature);
        }