public void Ed25519PhTestVectors(string message, string signature, string publicKey, string context, bool expectedResult)
        {
            var signatureAndMessage = signature.HexToByteArray();

            byte[] signatureBytes = new ArraySegment <byte>(signatureAndMessage, 0, _wrapper.SignatureLength).ToArray();
            byte[] publicKeyBytes = publicKey.HexToByteArray();
            byte[] messageBytes   = message.HexToByteArray();
            byte[] contextBytes   = context.HexToByteArray();

            var sig = _wrapper.GetSignatureFromBytes(signatureBytes, publicKeyBytes);

            var isVerified = _wrapper.Verify(sig, messageBytes, contextBytes);

            isVerified.Should().Be(expectedResult);
        }
        private bool ValidateTransactionSignature(PublicEntry transaction)
        {
            if (transaction.Signature.RawBytes == ByteString.Empty)
            {
                _logger.Error("Transaction signature is null");
                return(false);
            }

            var transactionSignature = _cryptoContext.GetSignatureFromBytes(transaction.Signature.RawBytes.ToByteArray(),
                                                                            transaction.SenderAddress.ToByteArray());

            var signingContext = transaction.Signature.SigningContext.ToByteArray();

            // we need to verify the signature matches the message, but transactionBroadcast contains the signature and original data,
            // passing message+sig will mean your verifying an incorrect message and always return false, so just null the sig.
            var transactionClone = transaction.Clone();

            transactionClone.Signature = null;

            if (_cryptoContext.Verify(transactionSignature, transactionClone.ToByteArray(), signingContext))
            {
                return(true);
            }

            _logger.Information(
                "Transaction Signature {signature} invalid.",
                transactionSignature);
            return(false);
        }
Exemple #3
0
        public void TestFailureSigningVerification()
        {
            var key1 = _context.GeneratePrivateKey();

            var data           = Encoding.UTF8.GetBytes("Testing testing 1 2 3");
            var signingContext = Encoding.UTF8.GetBytes("Testing testing 1 2 3 context");
            var signature      = _context.Sign(key1, data, signingContext);

            var key2       = _context.GeneratePrivateKey();
            var publicKey2 = _context.GetPublicKeyFromPrivateKey(key2);

            var invalidSignature = _context.GetSignatureFromBytes(signature.SignatureBytes, publicKey2.Bytes);

            _context.Verify(invalidSignature, data, signingContext)
            .Should().BeFalse("signature should not verify with incorrect key");
        }
        public (byte[], bool) Run(byte[] inputData)
        {
            if (inputData.Length != 160)
            {
                return(Bytes.Empty, false);
            }

            byte[] message        = inputData.AsSpan().Slice(0, 32).ToArray();
            byte[] signatureBytes = inputData.AsSpan().Slice(32, 64).ToArray();
            byte[] signingContext = inputData.AsSpan().Slice(96, 32).ToArray();
            byte[] publicKey      = inputData.AsSpan().Slice(128, 32).ToArray();

            ISignature signature = _cryptoContext.GetSignatureFromBytes(signatureBytes, publicKey);

            return(_cryptoContext.Verify(signature, message, signingContext)
                ? (new byte[] { 1 }, true)
                : (new byte[] { 0 }, true));
        }
Exemple #5
0
        private bool ValidateTransactionSignature(TransactionBroadcast transactionBroadcast, NetworkType networkType)
        {
            if (transactionBroadcast.Signature.RawBytes == ByteString.Empty)
            {
                _logger.Error("Transaction signature is null");
                return(false);
            }

            var transactionSignature = _cryptoContext.GetSignatureFromBytes(transactionBroadcast.Signature.RawBytes.ToByteArray(),
                                                                            transactionBroadcast.PublicEntries.First().Base.SenderPublicKey.ToByteArray());
            var transactionWithoutSig = transactionBroadcast.Clone();

            transactionWithoutSig.Signature = null;

            if (!_cryptoContext.Verify(transactionSignature, transactionWithoutSig.ToByteArray(), transactionBroadcast.Signature.SigningContext.ToByteArray()))
            {
                return(true);
            }

            _logger.Information(
                "Transaction Signature {signature} invalid.",
                transactionSignature);
            return(false);
        }