示例#1
0
 public static bool Verify(byte[] signature, byte[] message, byte[] publicKey)
 {
     if (signature == null)
     {
         throw new ArgumentNullException(nameof(signature));
     }
     if (message == null)
     {
         throw new ArgumentNullException(nameof(message));
     }
     if (publicKey == null)
     {
         throw new ArgumentNullException(nameof(publicKey));
     }
     if (signature.Length != SignatureSizeInBytes)
     {
         throw new ArgumentException($"Signature size must be {SignatureSizeInBytes}",
                                     nameof(signature));
     }
     if (publicKey.Length != PublicKeySizeInBytes)
     {
         throw new ArgumentException($"Public key size must be {PublicKeySizeInBytes}",
                                     nameof(signature));
     }
     return(Ed25519Operations.CryptoSignVerify(signature, 0, message, 0, message.Length, publicKey, 0));
 }
示例#2
0
 public static void Sign(ArraySegment <byte> signature, ArraySegment <byte> message,
                         ArraySegment <byte> expandedPrivateKey)
 {
     if (signature.Array == null)
     {
         throw new ArgumentNullException(nameof(signature));
     }
     if (signature.Count != SignatureSizeInBytes)
     {
         throw new ArgumentException("signature.Count");
     }
     if (expandedPrivateKey.Array == null)
     {
         throw new ArgumentNullException(nameof(signature));
     }
     if (expandedPrivateKey.Count != ExpandedPrivateKeySizeInBytes)
     {
         throw new ArgumentException("expandedPrivateKey.Count");
     }
     if (message.Array == null)
     {
         throw new ArgumentNullException(nameof(signature));
     }
     Ed25519Operations.crypto_sign2(signature.Array, signature.Offset, message.Array, message.Offset,
                                    message.Count, expandedPrivateKey.Array, expandedPrivateKey.Offset);
 }
示例#3
0
 public static void KeyPairFromSeed(ArraySegment <byte> publicKey, ArraySegment <byte> expandedPrivateKey,
                                    ArraySegment <byte> privateKeySeed)
 {
     if (publicKey.Array == null)
     {
         throw new ArgumentNullException(nameof(publicKey));
     }
     if (expandedPrivateKey.Array == null)
     {
         throw new ArgumentNullException(nameof(publicKey));
     }
     if (privateKeySeed.Array == null)
     {
         throw new ArgumentNullException(nameof(publicKey));
     }
     if (publicKey.Count != PublicKeySizeInBytes)
     {
         throw new ArgumentException("publicKey.Count");
     }
     if (expandedPrivateKey.Count != ExpandedPrivateKeySizeInBytes)
     {
         throw new ArgumentException("expandedPrivateKey.Count");
     }
     if (privateKeySeed.Count != PrivateKeySeedSizeInBytes)
     {
         throw new ArgumentException("privateKeySeed.Count");
     }
     Ed25519Operations.CryptoSignKeypair(
         publicKey.Array, publicKey.Offset,
         expandedPrivateKey.Array, expandedPrivateKey.Offset,
         privateKeySeed.Array, privateKeySeed.Offset);
 }
示例#4
0
        public static void KeyPairFromSeed(out byte[] publicKey, out byte[] expandedPrivateKey, byte[] privateKeySeed)
        {
            if (privateKeySeed == null)
            {
                throw new ArgumentNullException(nameof(privateKeySeed));
            }
            if (privateKeySeed.Length != PrivateKeySeedSizeInBytes)
            {
                throw new ArgumentException("privateKeySeed");
            }
            var pk = new byte[PublicKeySizeInBytes];
            var sk = new byte[ExpandedPrivateKeySizeInBytes];

            Ed25519Operations.CryptoSignKeypair(pk, 0, sk, 0, privateKeySeed, 0);
            publicKey          = pk;
            expandedPrivateKey = sk;
        }