Пример #1
0
        public static byte[] SignCompact(byte[] data, byte[] seckey, out int recoveryId)
        {
            if (data == null)
            {
                throw new ArgumentNullException(nameof(data));
            }
            if (data.Length == 0)
            {
                throw new ArgumentOutOfRangeException(nameof(data));
            }
            if (seckey == null)
            {
                throw new ArgumentNullException(nameof(seckey));
            }
            if (seckey.Length != 32)
            {
                throw new ArgumentOutOfRangeException(nameof(seckey));
            }
            recoveryId = 0;
            var recoverableSignature = new EcdsaRecoverableSignature();

            if (!Secp256K1Manager.Secp256K1EcdsaSignRecoverable(Secp256K1Manager.Ctx, recoverableSignature, data, seckey, (NonceFunction)null, (byte[])null))
            {
                return((byte[])null);
            }
            var  output64 = new byte[64];
            byte recid;

            if (!Secp256K1Manager.Secp256K1EcdsaRecoverableSignatureSerializeCompact(Secp256K1Manager.Ctx, output64, out recid, recoverableSignature))
            {
                return((byte[])null);
            }
            recoveryId = (int)recid;
            return(output64);
        }
Пример #2
0
        public static byte[] SignCompressedCompact(byte[] data, byte[] seckey)
        {
            if (data == null)
            {
                throw new ArgumentNullException(nameof(data));
            }
            if (data.Length == 0)
            {
                throw new ArgumentOutOfRangeException(nameof(data));
            }
            if (seckey == null)
            {
                throw new ArgumentNullException(nameof(seckey));
            }
            if (seckey.Length != 32)
            {
                throw new ArgumentOutOfRangeException(nameof(seckey));
            }
            byte recid = 0;
            var  recoverableSignature = new EcdsaRecoverableSignature();
            byte num1     = 0;
            var  num2     = 0;
            var  numArray = (byte[])null;
            var  randomNumberGenerator = RandomNumberGenerator.Create();

            do
            {
                if ((int)num1 == (int)byte.MaxValue)
                {
                    ++num2;
                    num1 = (byte)0;
                }
                if ((int)num1 > 0)
                {
                    numArray = new byte[32];
                    randomNumberGenerator.GetBytes(numArray);
                }
                ++num1;
            }while (!Secp256K1Manager.Secp256K1EcdsaSignRecoverable(Secp256K1Manager.Ctx, recoverableSignature, data, seckey, (NonceFunction)null, numArray) || !Secp256K1Manager.IsCanonical(recoverableSignature.Data));
            var outputxx = new byte[65];

            Secp256K1Manager.Secp256K1EcdsaRecoverableSignatureSerializeCompact(Secp256K1Manager.Ctx, outputxx, 1, out recid, recoverableSignature);
            outputxx[0] = (byte)((int)recid + 4 + 27);
            return(outputxx);
        }
Пример #3
0
        private static int SignCompact(Context ctx, byte[] msg32, byte[] seckey, byte[] output64, out byte recid)
        {
            var  recoverableSignature = new EcdsaRecoverableSignature();
            byte num       = 0;
            var  index     = 0;
            var  noncedata = new byte[32];

            do
            {
                noncedata[index] = num;
                ++num;
                if ((int)noncedata[index] == (int)byte.MaxValue)
                {
                    ++index;
                }
            }while (!Secp256K1Manager.Secp256K1EcdsaSignRecoverable(ctx, recoverableSignature, msg32, seckey, (NonceFunction)null, noncedata));
            Secp256K1Manager.Secp256K1EcdsaRecoverableSignatureSerializeCompact(ctx, output64, out recid, recoverableSignature);
            return((int)num);
        }
Пример #4
0
        private static byte[] SignCompact(byte[] data, byte[] seckey, out byte recoveryId)
        {
            var  recoverableSignature = new EcdsaRecoverableSignature();
            byte num       = 0;
            var  index     = 0;
            var  noncedata = new byte[32];

            do
            {
                noncedata[index] = num++;
                if ((int)num == (int)byte.MaxValue)
                {
                    ++index;
                    num = (byte)0;
                }
            }while (!Secp256K1Manager.Secp256K1EcdsaSignRecoverable(Secp256K1Manager.Ctx, recoverableSignature, data, seckey, (NonceFunction)null, noncedata));
            var output64 = new byte[64];

            Secp256K1Manager.Secp256K1EcdsaRecoverableSignatureSerializeCompact(Secp256K1Manager.Ctx, output64, out recoveryId, recoverableSignature);
            return(output64);
        }