Exemplo n.º 1
0
 public static extern int blsVerify(blsSignature sig, blsPublicKey pub, byte[] m, int size);
Exemplo n.º 2
0
        static void bls_use_stackTest()
        {
            var msg      = "this is a pen";
            var msgBytes = Encoding.UTF8.GetBytes(msg);
            var msgSize  = msgBytes.Length;

            //blsSetETHserialization(1);
            //Console.WriteLine("Eth serialization set");

            var privateKeyBytes = new byte[] {
                0x47, 0xb8, 0x19, 0x2d, 0x77, 0xbf, 0x87, 0x1b,
                0x62, 0xe8, 0x78, 0x59, 0xd6, 0x53, 0x92, 0x27,
                0x25, 0x72, 0x4a, 0x5c, 0x03, 0x1a, 0xfe, 0xab,
                0xc6, 0x0b, 0xce, 0xf5, 0xff, 0x66, 0x51, 0x38
            };

            Console.WriteLine("Serialized private key: {0}", BitConverter.ToString(privateKeyBytes));

            var sec = new blsSecretKey();

            unsafe
            {
                fixed(byte *privateKeyPtr = privateKeyBytes)
                {
                    blsSecretKeyDeserialize(ref sec, privateKeyPtr, privateKeyBytes.Length);
                }
            }
            //blsSecretKeySetByCSPRNG(out sec);
            Console.WriteLine("Secret key: {0}", sec);
            Console.WriteLine();

            var pub = new blsPublicKey();

            blsGetPublicKey(ref pub, ref sec);
//            unsafe
//            {
//                fixed (blsPublicKey* pubPtr = pub)
//                fixed (blsSecretKey* secPtr = sec)
//                {
//                    blsGetPublicKey(pubPtr, secPtr);
//                }
//            }
            Console.WriteLine("Public key: {0}", pub);
            Console.WriteLine();

            var buffer = new Span <byte>(new byte[48]);

            unsafe
            {
                fixed(byte *ptr = buffer)
                {
                    blsPublicKeySerialize(ptr, buffer.Length, ref pub);
                }
            }
            Console.WriteLine("Expecting public key b301803f...");
            Console.WriteLine("Serialized public key: {0}", BitConverter.ToString(buffer.ToArray()));

            var sig0 = new blsSignature();
            var ret0 = blsVerify(ref sig0, ref pub, msgBytes, msgSize);

            Console.WriteLine("Verify Fail {0}", ret0);

            var sig = new blsSignature();

            blsSign(ref sig, ref sec, msgBytes, msgSize);
            Console.WriteLine("Signature : {0}", sig);
            Console.WriteLine();

            int ret = blsVerify(ref sig, ref pub, msgBytes, msgSize);

            Console.WriteLine("Verify Result {0}", ret);

            msgBytes[0]++;
            int ret2 = blsVerify(ref sig, ref pub, msgBytes, msgSize);

            Console.WriteLine("Verify Result after tamper {0}", ret2);
        }
Exemplo n.º 3
0
 public static extern int blsSign(out blsSignature sig, blsSecretKey sec, byte[] m, int size);
Exemplo n.º 4
0
 public static extern int blsSign([In, Out] ref blsSignature sig, ref blsSecretKey sec, byte[] m, int size);