Example #1
0
        internal static int GetPassword(string UserName, string Password)
        {
            string UserGUID = Encryptor.DecryptText(AppData.SECURITY.UserGUID, Keygen.ComputeSHA512(UserName + Password));

            if (UserGUID.Equals(string.Empty))
            {
                return(1);
            }
            string username = Encryptor.DecryptText(AppData.SECURITY.UserName, Keygen.ComputeSHA512(UserGUID + Password));

            if (username.Equals(string.Empty))
            {
                return(2);
            }
            string password = Encryptor.DecryptText(AppData.SECURITY.Password, Keygen.ComputeSHA512(UserGUID + UserName));

            if (password.Equals(string.Empty))
            {
                return(3);
            }
            else
            {
                return(0);
            }
        }
        public override byte[] generatePublicKey(byte[] privateKey)
        {
            byte[] publicKey = new byte[32];
            Keygen.curve25519_keygen(publicKey, privateKey);

            return(publicKey);
        }
Example #3
0
    async public static Task MainAsync(string[] args)
    {
        var keygen = new Keygen("demo");

        // Keep a reference to the current license and device
        Keygen.License license = null;
        Keygen.Machine device  = null;

        // Validate license
        var validation = await keygen.ValidateLicense("0BB042-E1A90B-A5DC67-D651E0-73E6C5-V3", "AB:CD:EF:GH:IJ:KL:MN:OP");

        if (validation.Meta.Valid)
        {
            Console.WriteLine("[INFO] [ValidateLicense] Valid={0} ValidationCode={1}", validation.Meta.Detail, validation.Meta.Code);
        }
        else
        {
            Console.WriteLine("[INFO] [ValidateLicense] Invalid={0} ValidationCode={1}", validation.Meta.Detail, validation.Meta.Code);
        }

        // Store license data
        license = validation.Data;

        // Activate the current machine if it is not already activated (based on validation code)
        switch (validation.Meta.Code)
        {
        case "FINGERPRINT_SCOPE_MISMATCH":
        case "NO_MACHINES":
        case "NO_MACHINE":
            var activation = await keygen.ActivateDevice((string)license.ID, "AB:CD:EF:GH:IJ:KL:MN:OP", "activ-37ab75d19cfbc88b6c4c4e06c3517447v3");

            // Store device data
            device = activation.Data;

            Console.WriteLine("[INFO] [ActivateDevice] DeviceId={0} LicenseId={1}", device.ID, license.ID);

            // OPTIONAL: Validate license again
            validation = await keygen.ValidateLicense("0BB042-E1A90B-A5DC67-D651E0-73E6C5-V3", "AB:CD:EF:GH:IJ:KL:MN:OP");

            if (validation.Meta.Valid)
            {
                Console.WriteLine("[INFO] [ValidateLicense] Valid={0} ValidationCode={1}", validation.Meta.Detail, validation.Meta.Code);
            }
            else
            {
                Console.WriteLine("[INFO] [ValidateLicense] Invalid={0} ValidationCode={1}", validation.Meta.Detail, validation.Meta.Code);
            }

            break;
        }

        // Print the overall results
        Console.WriteLine("[INFO] [Main] Valid={0} RecentlyActivated={1}", validation.Meta.Valid, device != null);
    }
Example #4
0
    void OnTriggerEnter(Collider col)
    {
        Hitbox3D hitbox = col.GetComponent <Hitbox3D>();

        if (hitbox != null && hitbox.owner != this.owner)
        {
            Keygen entity = owner.GetComponent <Keygen>();

            entity.OnHit(hitbox.damage, hitbox.owner);

            //Visual hit effect stuff?
            //Vector3 hitLocation = (this.transform.position + col.bounds.ClosestPoint(this.transform.position)) / 2.0f;
        }
    }
Example #5
0
        public void xeddsa_fast_test()
        {
            byte[] signature_correct = new byte[]
            {
                0x11, 0xc7, 0xf3, 0xe6, 0xc4, 0xdf, 0x9e, 0x8a,
                0x51, 0x50, 0xe1, 0xdb, 0x3b, 0x30, 0xf9, 0x2d,
                0xe3, 0xa3, 0xb3, 0xaa, 0x43, 0x86, 0x56, 0x54,
                0x5f, 0xa7, 0x39, 0x0f, 0x4b, 0xcc, 0x7b, 0xb2,
                0x6c, 0x43, 0x1d, 0x9e, 0x90, 0x64, 0x3e, 0x4f,
                0x0e, 0xaa, 0x0e, 0x9c, 0x55, 0x77, 0x66, 0xfa,
                0x69, 0xad, 0xa5, 0x76, 0xd6, 0x3d, 0xca, 0xf2,
                0xac, 0x32, 0x6c, 0x11, 0xd0, 0xb9, 0x77, 0x02,
            };
            const int MSG_LEN = 200;

            byte[] privkey   = new byte[32];
            byte[] pubkey    = new byte[32];
            byte[] signature = new byte[64];
            byte[] msg       = new byte[MSG_LEN];
            byte[] random    = new byte[64];

            privkey[8] = 189; /* just so there's some bits set */
            Sc_clamp.sc_clamp(privkey);

            /* Signature vector test */
            Keygen.curve25519_keygen(pubkey, privkey);

            ISha512 sha512provider = new BouncyCastleDotNETSha512Provider();

            xeddsa.xed25519_sign(sha512provider, signature, privkey, msg, MSG_LEN, random);

            CollectionAssert.AreEqual(signature_correct, signature, "XEdDSA sign");

            Assert.AreEqual(0, xeddsa.xed25519_verify(sha512provider, signature, pubkey, msg, MSG_LEN), "XEdDSA verify #1");

            signature[0] ^= 1;

            Assert.AreNotEqual(0, xeddsa.xed25519_verify(sha512provider, signature, pubkey, msg, MSG_LEN), "XEdDSA verify #2");
        }
Example #6
0
        public void curvesigs_fast_test()
        {
            byte[] signature_correct = new byte[]
            {
                0xcf, 0x87, 0x3d, 0x03, 0x79, 0xac, 0x20, 0xe8,
                0x89, 0x3e, 0x55, 0x67, 0xee, 0x0f, 0x89, 0x51,
                0xf8, 0xdb, 0x84, 0x0d, 0x26, 0xb2, 0x43, 0xb4,
                0x63, 0x52, 0x66, 0x89, 0xd0, 0x1c, 0xa7, 0x18,
                0xac, 0x18, 0x9f, 0xb1, 0x67, 0x85, 0x74, 0xeb,
                0xdd, 0xe5, 0x69, 0x33, 0x06, 0x59, 0x44, 0x8b,
                0x0b, 0xd6, 0xc1, 0x97, 0x3f, 0x7d, 0x78, 0x0a,
                0xb3, 0x95, 0x18, 0x62, 0x68, 0x03, 0xd7, 0x82,
            };
            const int MSG_LEN = 200;

            byte[] privkey   = new byte[32];
            byte[] pubkey    = new byte[32];
            byte[] signature = new byte[64];
            byte[] msg       = new byte[MSG_LEN];
            byte[] random    = new byte[64];

            privkey[8] = 189; /* just so there's some bits set */
            Sc_clamp.sc_clamp(privkey);

            /* Signature vector test */
            Keygen.curve25519_keygen(pubkey, privkey);

            ISha512 sha512provider = new BouncyCastleDotNETSha512Provider();

            Curve_sigs.curve25519_sign(sha512provider, signature, privkey, msg, MSG_LEN, random);

            CollectionAssert.AreEqual(signature_correct, signature, "Curvesig sign");

            Assert.AreEqual(0, Curve_sigs.curve25519_verify(sha512provider, signature, pubkey, msg, MSG_LEN), "Curvesig verify #1");

            signature[0] ^= 1;

            Assert.AreNotEqual(0, Curve_sigs.curve25519_verify(sha512provider, signature, pubkey, msg, MSG_LEN), "Curvesig verify #2");
        }
Example #7
0
 private void keyGeneration(object number)
 {
     System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = false;
     for (int i = 1; i < Convert.ToInt32(numericUpDown1.Value) + 1; i++)
     {
         if (i != Convert.ToInt32(numericUpDown1.Value))
         {
             massKeyOut.Text += Keygen.Create(Convert.ToInt32(symbols.Value), Convert.ToInt32(blocks.Value)) + "\r";
         }
         else
         {
             massKeyOut.Text += Keygen.Create(Convert.ToInt32(symbols.Value), Convert.ToInt32(blocks.Value));
         }
         massKeyOut.Update();
         generationProcess.Text = Translate.keysGenerated + i + "/" + Convert.ToInt32(numericUpDown1.Value) + ".";
         generationProcess.Update();
     }
     symbols.Enabled        = true;
     blocks.Enabled         = true;
     numericUpDown1.Enabled = true;
     saving.Enabled         = true;
     startMassGen.Enabled   = true;
     generationProcess.Text = Translate.done;
 }
Example #8
0
        public void vxeddsa_fast_test()
        {
            byte[] signature_correct = new byte[]
            {
                0x23, 0xc6, 0xe5, 0x93, 0x3f, 0xcd, 0x56, 0x47,
                0x7a, 0x86, 0xc9, 0x9b, 0x76, 0x2c, 0xb5, 0x24,
                0xc3, 0xd6, 0x05, 0x55, 0x38, 0x83, 0x4d, 0x4f,
                0x8d, 0xb8, 0xf0, 0x31, 0x07, 0xec, 0xeb, 0xa0,
                0xa0, 0x01, 0x50, 0xb8, 0x4c, 0xbb, 0x8c, 0xcd,
                0x23, 0xdc, 0x65, 0xfd, 0x0e, 0x81, 0xb2, 0x86,
                0x06, 0xa5, 0x6b, 0x0c, 0x4f, 0x53, 0x6d, 0xc8,
                0x8b, 0x8d, 0xc9, 0x04, 0x6e, 0x4a, 0xeb, 0x08,
                0xce, 0x08, 0x71, 0xfc, 0xc7, 0x00, 0x09, 0xa4,
                0xd6, 0xc0, 0xfd, 0x2d, 0x1a, 0xe5, 0xb6, 0xc0,
                0x7c, 0xc7, 0x22, 0x3b, 0x69, 0x59, 0xa8, 0x26,
                0x2b, 0x57, 0x78, 0xd5, 0x46, 0x0e, 0x0f, 0x05,
            };
            const int MSG_LEN = 200;

            byte[] privkey     = new byte[32];
            byte[] pubkey      = new byte[32];
            byte[] signature   = new byte[96];
            byte[] msg         = new byte[MSG_LEN];
            byte[] random      = new byte[64];
            byte[] vrf_out     = new byte[32];
            byte[] vrf_outprev = new byte[32];

            privkey[8] = 189; /* just so there's some bits set */
            Sc_clamp.sc_clamp(privkey);

            /* Signature vector test */
            Keygen.curve25519_keygen(pubkey, privkey);

            ISha512 sha512provider = new BouncyCastleDotNETSha512Provider();

            vxeddsa.vxed25510_sign(sha512provider, signature, privkey, msg, MSG_LEN, random);

            CollectionAssert.AreEqual(signature_correct, signature, "VXEdDSA sign");
            Assert.AreEqual(0, vxeddsa.vxed25519_verify(sha512provider, vrf_out, signature, pubkey, msg, MSG_LEN), "VXEdDSA verify #1");
            Array.Copy(vrf_out, 0, vrf_outprev, 0, 32);
            signature[0] ^= 1;
            Assert.AreNotEqual(0, vxeddsa.vxed25519_verify(sha512provider, vrf_out, signature, pubkey, msg, MSG_LEN), "VXEdDSA verify #2");

            /* Test U */
            byte[] sigprev = new byte[96];
            Array.Copy(signature, 0, sigprev, 0, 96);
            sigprev[0] ^= 1; /* undo prev disturbance */

            random[0] ^= 1;
            vxeddsa.vxed25510_sign(sha512provider, signature, privkey, msg, MSG_LEN, random);
            Assert.AreEqual(0, vxeddsa.vxed25519_verify(sha512provider, vrf_out, signature, pubkey, msg, MSG_LEN), "VXEdDSA verify #3");

            byte[] vrf0 = new byte[32];
            Array.Copy(vrf_outprev, 0, vrf0, 0, 32);
            byte[] vrfprev0 = new byte[32];
            Array.Copy(vrf_out, 0, vrfprev0, 0, 32);
            CollectionAssert.AreEqual(vrfprev0, vrf0, "VXEdDSA VRF value unchanged");

            byte[] sig32 = new byte[64];
            Array.Copy(signature, 32, sig32, 0, 64);
            byte[] sigprev32 = new byte[64];
            Array.Copy(sigprev, 32, sigprev32, 0, 64);
            CollectionAssert.AreNotEqual(sigprev32, sig32, "VXEdDSA (h, s) changed");
        }
Example #9
0
 private void oneKey(object sender)
 {
     System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = false;
     keyOneOut.Text = Keygen.Create(Convert.ToInt32(symbols.Value), Convert.ToInt32(blocks.Value));
 }
Example #10
0
        public void xeddsa_to_curvesigs_slow_test()
        {
            int iterations = 10000;

            byte[] signature_10k_correct = new byte[]
            {
                0x33, 0x50, 0xa8, 0x68, 0xcd, 0x9e, 0x74, 0x99,
                0xa3, 0x5c, 0x33, 0x75, 0x2b, 0x22, 0x03, 0xf8,
                0xb5, 0x0f, 0xea, 0x8c, 0x33, 0x1c, 0x68, 0x8b,
                0xbb, 0xf3, 0x31, 0xcf, 0x7c, 0x42, 0x37, 0x35,
                0xa0, 0x0e, 0x15, 0xb8, 0x5d, 0x2b, 0xe1, 0xa2,
                0x03, 0x77, 0x94, 0x3d, 0x13, 0x5c, 0xd4, 0x9b,
                0x6a, 0x31, 0xf4, 0xdc, 0xfe, 0x24, 0xad, 0x54,
                0xeb, 0xd2, 0x98, 0x47, 0xf1, 0xcc, 0xbf, 0x0d
            };

            int       count;
            const int MSG_LEN = 200;

            byte[] privkey   = new byte[32];
            byte[] pubkey    = new byte[32];
            byte[] signature = new byte[96];
            byte[] msg       = new byte[MSG_LEN];
            byte[] random    = new byte[64];

            for (int i = 0; i < 64; i++)
            {
                signature[i] = 2;
            }

            /* Signature random test */
            Debug.WriteLine("Pseudorandom XEdDSA/Curvesigs...");
            for (count = 1; count <= iterations; count++)
            {
                byte[]  b = new byte[64];
                ISha512 sha512provider = new BouncyCastleDotNETSha512Provider();
                sha512provider.calculateDigest(b, signature, 64);
                Array.Copy(b, 0, privkey, 0, 32);
                sha512provider.calculateDigest(b, privkey, 32);
                Array.Copy(b, 0, random, 0, 64);

                Sc_clamp.sc_clamp(privkey);
                Keygen.curve25519_keygen(pubkey, privkey);

                xeddsa.xed25519_sign(sha512provider, signature, privkey, msg, MSG_LEN, random);

                Assert.AreEqual(0, Curve_sigs.curve25519_verify(sha512provider, signature, pubkey, msg, MSG_LEN), $"XEdDSA/Curvesigs verify failure #1 {count}");

                if ((b[63] & 1) != 0)
                {
                    signature[count % 64] ^= 1;
                }
                else
                {
                    msg[count % MSG_LEN] ^= 1;
                }
                Assert.AreNotEqual(0, Curve_sigs.curve25519_verify(sha512provider, signature, pubkey, msg, MSG_LEN), $"XEdDSA/Curvesigs verify failure #2 {count}");

                if (count == 10000)
                {
                    byte[] sig0 = new byte[64];
                    Array.Copy(signature, 0, sig0, 0, 64);
                    CollectionAssert.AreEqual(signature_10k_correct, sig0, $"XEdDSA/Curvesigs signature 10K doesn't match {count}");
                }
                if (count == 100000)
                {
                    //utility.print_bytes("100K XEdDSA/C", signature, 64);
                }
                if (count == 1000000)
                {
                    //utility.print_bytes("1M XEdDSA/C", signature, 64);
                }
                if (count == 10000000)
                {
                    //utility.print_bytes("10M XEdDSA/C", signature, 64);
                }
            }
        }
Example #11
0
        public Title(string titleId, string titleKey, string name, string region)
        {
            if (!String.IsNullOrEmpty(titleId))
            {
                TitleId = SanitizeString(titleId.ToUpper());
                TitleIdHexified = FormatHexString(TitleId);
            }

            if (!String.IsNullOrEmpty(titleKey))
            {
                TitleKey = titleKey.ToUpper();
                TitleKeyHexified = FormatHexString(TitleKey);
            }
            else
            {
                TitleKey = Keygen.GenerateKey(TitleId);
                TitleKeyHexified = FormatHexString(TitleKey);
            }

            if (!String.IsNullOrEmpty(name))
            {
                Name = name;
                NameSanitized = SanitizeString(Name);
            }

            if (String.IsNullOrEmpty(region))
            {
                Region = "UKN";
            }
            else
            {
                Region = region.Trim();
            }

            if (TitleId.StartsWith("00050000", StringComparison.OrdinalIgnoreCase))
            {
                TitleType = "GAME";
            }
            else if (TitleId.StartsWith("00050002", StringComparison.OrdinalIgnoreCase))
            {
                TitleType = "DEMO";
            }
            else if (TitleId.StartsWith("0005000C", StringComparison.OrdinalIgnoreCase))
            {
                TitleType = "DLC";
            }
            else if (TitleId.StartsWith("0005000E", StringComparison.OrdinalIgnoreCase))
            {
                TitleType = "UPDATE";
            }
            else if (TitleId.StartsWith("00050010", StringComparison.OrdinalIgnoreCase))
            {
                TitleType = "SYSAPP";
            }
            else if (TitleId.StartsWith("0005001B", StringComparison.OrdinalIgnoreCase))
            {
                TitleType = "SYSDAT";
            }
            else if (TitleId.StartsWith("00050030", StringComparison.OrdinalIgnoreCase))
            {
                TitleType = "APPLET";
            }
            else
            {
                TitleType = "UNKNOWN";
            }
        }
Example #12
0
 public void KeygenConstructorTest()
 {
     var target = new Keygen();
 }
Example #13
0
        public void RenderTest()
        {
            var target = new Keygen();

            Assert.AreEqual("<keygen keytype=\"rsa\" name=\"test\" />", target.Render("test", null));
        }
Example #14
0
 static License GenerateTestLicense(User user)
 {
     return(Keygen.GenerateLicense(user));
 }
Example #15
0
        public void curvesigs_slow_test()
        {
            int iterations = 10000;

            byte[] signature_10k_correct = new byte[]
            {
                0xfc, 0xba, 0x55, 0xc4, 0x85, 0x4a, 0x42, 0x25,
                0x19, 0xab, 0x08, 0x8d, 0xfe, 0xb5, 0x13, 0xb6,
                0x0d, 0x24, 0xbb, 0x16, 0x27, 0x55, 0x71, 0x48,
                0xdd, 0x20, 0xb1, 0xcd, 0x2a, 0xd6, 0x7e, 0x35,
                0xef, 0x33, 0x4c, 0x7b, 0x6d, 0x94, 0x6f, 0x52,
                0xec, 0x43, 0xd7, 0xe6, 0x35, 0x24, 0xcd, 0x5b,
                0x5d, 0xdc, 0xb2, 0x32, 0xc6, 0x22, 0x53, 0xf3,
                0x38, 0x02, 0xf8, 0x28, 0x28, 0xc5, 0x65, 0x05,
            };

            int       count;
            const int MSG_LEN = 200;

            byte[] privkey   = new byte[32];
            byte[] pubkey    = new byte[32];
            byte[] signature = new byte[64];
            byte[] msg       = new byte[MSG_LEN];
            byte[] random    = new byte[64];
            /* Signature random test */
            Debug.WriteLine("Pseudorandom curvesigs...");
            for (count = 1; count <= iterations; count++)
            {
                byte[]  b = new byte[64];
                ISha512 sha512provider = new BouncyCastleDotNETSha512Provider();
                sha512provider.calculateDigest(b, signature, 64);
                Array.Copy(b, 0, privkey, 0, 32);
                sha512provider.calculateDigest(b, privkey, 32);
                Array.Copy(b, 0, random, 0, 64);

                Sc_clamp.sc_clamp(privkey);
                Keygen.curve25519_keygen(pubkey, privkey);

                Curve_sigs.curve25519_sign(sha512provider, signature, privkey, msg, MSG_LEN, random);

                Assert.AreEqual(0, Curve_sigs.curve25519_verify(sha512provider, signature, pubkey, msg, MSG_LEN), $"Curvesig verify failure #1 {count}");

                if ((b[63] & 1) != 0)
                {
                    signature[count % 64] ^= 1;
                }
                else
                {
                    msg[count % MSG_LEN] ^= 1;
                }
                Assert.AreNotEqual(0, Curve_sigs.curve25519_verify(sha512provider, signature, pubkey, msg, MSG_LEN), $"Curvesig verify failure #2 {count}");

                if (count == 10000)
                {
                    CollectionAssert.AreEqual(signature_10k_correct, signature, $"Curvesig signature 10K doesn't match {count}");
                }
                if (count == 100000)
                {
                    //utility.print_bytes("100K curvesigs", signature, 64);
                }
                if (count == 1000000)
                {
                    //utility.print_bytes("1M curvesigs", signature, 64);
                }
                if (count == 10000000)
                {
                    //utility.print_bytes("10M curvesigs", signature, 64);
                }
            }
        }
Example #16
0
 public Keygen(string password)
 {
     this.password = Keygen.Convert("30949i349i0fdsko30-" + password + "k20rk0kf029k20 2 2r-023kr");
 }
Example #17
0
        public void xeddsa_slow_test()
        {
            int iterations = 10000;

            byte[] signature_10k_correct = new byte[]
            {
                0x15, 0x29, 0x03, 0x38, 0x66, 0x16, 0xcd, 0x26,
                0xbb, 0x3e, 0xec, 0xe2, 0x9f, 0x72, 0xa2, 0x5c,
                0x7d, 0x05, 0xc9, 0xcb, 0x84, 0x3f, 0x92, 0x96,
                0xb3, 0xfb, 0xb9, 0xdd, 0xd6, 0xed, 0x99, 0x04,
                0xc1, 0xa8, 0x02, 0x16, 0xcf, 0x49, 0x3f, 0xf1,
                0xbe, 0x69, 0xf9, 0xf1, 0xcc, 0x16, 0xd7, 0xdc,
                0x6e, 0xd3, 0x78, 0xaa, 0x04, 0xeb, 0x71, 0x51,
                0x9d, 0xe8, 0x7a, 0x5b, 0xd8, 0x49, 0x7b, 0x05,
            };

            int       count;
            const int MSG_LEN = 200;

            byte[] privkey   = new byte[32];
            byte[] pubkey    = new byte[32];
            byte[] signature = new byte[96];
            byte[] msg       = new byte[MSG_LEN];
            byte[] random    = new byte[64];

            for (int i = 0; i < 64; i++)
            {
                signature[i] = 1;
            }

            /* Signature random test */
            Debug.WriteLine("Pseudorandom XEdDSA...");
            for (count = 1; count <= iterations; count++)
            {
                byte[]  b = new byte[64];
                ISha512 sha512provider = new BouncyCastleDotNETSha512Provider();
                sha512provider.calculateDigest(b, signature, 64);
                Array.Copy(b, 0, privkey, 0, 32);
                sha512provider.calculateDigest(b, privkey, 32);
                Array.Copy(b, 0, random, 0, 64);

                Sc_clamp.sc_clamp(privkey);
                Keygen.curve25519_keygen(pubkey, privkey);

                xeddsa.xed25519_sign(sha512provider, signature, privkey, msg, MSG_LEN, random);

                Assert.AreEqual(0, xeddsa.xed25519_verify(sha512provider, signature, pubkey, msg, MSG_LEN), $"XEdDSA verify failure #1 {count}");

                if ((b[63] & 1) != 0)
                {
                    signature[count % 64] ^= 1;
                }
                else
                {
                    msg[count % MSG_LEN] ^= 1;
                }
                Assert.AreNotEqual(0, xeddsa.xed25519_verify(sha512provider, signature, pubkey, msg, MSG_LEN), $"XEdDSA verify failure #2 {count}");

                if (count == 10000)
                {
                    byte[] sig0 = new byte[64];
                    Array.Copy(signature, 0, sig0, 0, 64);
                    CollectionAssert.AreEqual(signature_10k_correct, sig0, $"XEdDSA signature 10K doesn't match {count}");
                }
            }
        }
Example #18
0
 public ByteGenerator(string s)
 {
     kg = new Keygen(s);
 }
Example #19
0
        public void vxeddsa_slow_test()
        {
            int iterations = 10000000;

            //int iterations = 100000;
            byte[] signature_10k_correct = new byte[]
            {
                0xa1, 0x96, 0x96, 0xe5, 0x87, 0x3f, 0x6e, 0x5c,
                0x2e, 0xd3, 0x73, 0xab, 0x04, 0x0c, 0x1f, 0x26,
                0x3c, 0xca, 0x52, 0xc4, 0x7e, 0x49, 0xaa, 0xce,
                0xb5, 0xd6, 0xa2, 0x29, 0x46, 0x3f, 0x1b, 0x54,
                0x45, 0x94, 0x9b, 0x6c, 0x27, 0xf9, 0x2a, 0xed,
                0x17, 0xa4, 0x72, 0xbf, 0x35, 0x37, 0xc1, 0x90,
                0xac, 0xb3, 0xfd, 0x2d, 0xf1, 0x01, 0x05, 0xbe,
                0x56, 0x5c, 0xaf, 0x63, 0x65, 0xad, 0x38, 0x04,
                0x70, 0x53, 0xdf, 0x2b, 0xc1, 0x45, 0xc8, 0xee,
                0x02, 0x0d, 0x2b, 0x22, 0x23, 0x7a, 0xbf, 0xfa,
                0x43, 0x31, 0xb3, 0xac, 0x26, 0xd9, 0x76, 0xfc,
                0xfe, 0x30, 0xa1, 0x7c, 0xce, 0x10, 0x67, 0x0e,
            };

            byte[] signature_100k_correct = new byte[]
            {
                0xc9, 0x11, 0x2b, 0x55, 0xfa, 0xc4, 0xb2, 0xfe,
                0x00, 0x7d, 0xf6, 0x45, 0xcb, 0xd2, 0x73, 0xc9,
                0x43, 0xba, 0x20, 0xf6, 0x9c, 0x18, 0x84, 0xef,
                0x6c, 0x65, 0x7a, 0xdb, 0x49, 0xfc, 0x1e, 0xbe,
                0x31, 0xb3, 0xe6, 0xa4, 0x68, 0x2f, 0xd0, 0x30,
                0x81, 0xfc, 0x0d, 0xcd, 0x2d, 0x00, 0xab, 0xae,
                0x9f, 0x08, 0xf0, 0x99, 0xff, 0x9f, 0xdc, 0x2d,
                0x68, 0xd6, 0xe7, 0xe8, 0x44, 0x2a, 0x5b, 0x0e,
                0x48, 0x67, 0xe2, 0x41, 0x4a, 0xd9, 0x0c, 0x2a,
                0x2b, 0x4e, 0x66, 0x09, 0x87, 0xa0, 0x6b, 0x3b,
                0xd1, 0xd9, 0xa3, 0xe3, 0xa5, 0x69, 0xed, 0xc1,
                0x42, 0x03, 0x93, 0x0d, 0xbc, 0x7e, 0xe9, 0x08,
            };

            byte[] signature_1m_correct = new byte[]
            {
                0xf8, 0xb1, 0x20, 0xf2, 0x1e, 0x5c, 0xbf, 0x5f,
                0xea, 0x07, 0xcb, 0xb5, 0x77, 0xb8, 0x03, 0xbc,
                0xcb, 0x6d, 0xf1, 0xc1, 0xa5, 0x03, 0x05, 0x7b,
                0x01, 0x63, 0x9b, 0xf9, 0xed, 0x3e, 0x57, 0x47,
                0xd2, 0x5b, 0xf4, 0x7e, 0x7c, 0x45, 0xce, 0xfc,
                0x06, 0xb3, 0xf4, 0x05, 0x81, 0x9f, 0x53, 0xb0,
                0x18, 0xe3, 0xfa, 0xcb, 0xb2, 0x52, 0x3e, 0x57,
                0xcb, 0x34, 0xcc, 0x81, 0x60, 0xb9, 0x0b, 0x04,
                0x07, 0x79, 0xc0, 0x53, 0xad, 0xc4, 0x4b, 0xd0,
                0xb5, 0x7d, 0x95, 0x4e, 0xbe, 0xa5, 0x75, 0x0c,
                0xd4, 0xbf, 0xa7, 0xc0, 0xcf, 0xba, 0xe7, 0x7c,
                0xe2, 0x90, 0xef, 0x61, 0xa9, 0x29, 0x66, 0x0d,
            };

            byte[] signature_10m_correct = new byte[]
            {
                0xf5, 0xa4, 0xbc, 0xec, 0xc3, 0x3d, 0xd0, 0x43,
                0xd2, 0x81, 0x27, 0x9e, 0xf0, 0x4c, 0xbe, 0xf3,
                0x77, 0x01, 0x56, 0x41, 0x0e, 0xff, 0x0c, 0xb9,
                0x66, 0xec, 0x4d, 0xe0, 0xb7, 0x25, 0x63, 0x6b,
                0x5c, 0x08, 0x39, 0x80, 0x4e, 0x37, 0x1b, 0x2c,
                0x46, 0x6f, 0x86, 0x99, 0x1c, 0x4e, 0x31, 0x60,
                0xdb, 0x4c, 0xfe, 0xc5, 0xa2, 0x4d, 0x71, 0x2b,
                0xd6, 0xd0, 0xc3, 0x98, 0x88, 0xdb, 0x0e, 0x0c,
                0x68, 0x4a, 0xd3, 0xc7, 0x56, 0xac, 0x8d, 0x95,
                0x7b, 0xbd, 0x99, 0x50, 0xe8, 0xd3, 0xea, 0xf3,
                0x7b, 0x26, 0xf2, 0xa2, 0x2b, 0x02, 0x58, 0xca,
                0xbd, 0x2c, 0x2b, 0xf7, 0x77, 0x58, 0xfe, 0x09,
            };

            int       count;
            const int MSG_LEN = 200;

            byte[] privkey   = new byte[32];
            byte[] pubkey    = new byte[32];
            byte[] signature = new byte[96];
            byte[] msg       = new byte[MSG_LEN];
            byte[] random    = new byte[64];
            byte[] vrf_out   = new byte[32];

            for (int i = 0; i < 96; i++)
            {
                signature[i] = 3;
            }

            Debug.WriteLine("Pseudorandom VXEdDSA...");
            for (count = 1; count <= iterations; count++)
            {
                byte[]  b = new byte[64];
                ISha512 sha512provider = new BouncyCastleDotNETSha512Provider();
                sha512provider.calculateDigest(b, signature, 96);
                Array.Copy(b, 0, privkey, 0, 32);
                sha512provider.calculateDigest(b, privkey, 32);
                Array.Copy(b, 0, random, 0, 64);

                Sc_clamp.sc_clamp(privkey);
                Keygen.curve25519_keygen(pubkey, privkey);

                vxeddsa.vxed25510_sign(sha512provider, signature, privkey, msg, MSG_LEN, random);

                Assert.AreEqual(0, vxeddsa.vxed25519_verify(sha512provider, vrf_out, signature, pubkey, msg, MSG_LEN), $"VXEdDSA verify failure #1 {count}");

                if ((b[63] & 1) != 0)
                {
                    signature[count % 96] ^= 1;
                }
                else
                {
                    msg[count % MSG_LEN] ^= 1;
                }
                Assert.AreNotEqual(0, vxeddsa.vxed25519_verify(sha512provider, vrf_out, signature, pubkey, msg, MSG_LEN), $"VXEdDSA verify failure #2 {count}");

                //if (count == 10000)
                //    print_bytes("10K VXEdDSA", signature, 96);
                //if (count == 100000)
                //    print_bytes("100K VXEdDSA", signature, 96);
                //if (count == 1000000)
                //    print_bytes("1M VXEdDSA", signature, 96);
                //if (count == 10000000)
                //    print_bytes("10M VXEdDSA", signature, 96);
                //if (count == 100000000)
                //    print_bytes("100M VXEdDSA", signature, 96);

                if (count == 10000)
                {
                    CollectionAssert.AreEqual(signature_10k_correct, signature, $"VXEdDSA 10K doesn't match {count}");
                }
                if (count == 100000)
                {
                    CollectionAssert.AreEqual(signature_100k_correct, signature, $"VXEdDSA 100K doesn't match {count}");
                }
                if (count == 1000000)
                {
                    CollectionAssert.AreEqual(signature_1m_correct, signature, $"VXEdDSA 1m doesn't match {count}");
                }
                if (count == 10000000)
                {
                    CollectionAssert.AreEqual(signature_10m_correct, signature, $"VXEdDSA 10m doesn't match {count}");
                }

                /*
                 * if (count == 100000000) {
                 *  if (memcmp(signature, signature_100m_correct, 96) != 0)
                 *      ERROR("VXEDDSA 100m doesn't match %d\n", count);
                 * }
                 */
            }
        }
Example #20
0
        static void Main(string[] args)
        {
            if (args.Length < 2)
            {
                Console.WriteLine("Commandline Parameter Error");
                Console.WriteLine("Example:  SolveMe_Riddle.exe <Wordfile Filename> <Cipher Filename>");
                Console.WriteLine("Arguments = " + String.Join(';', args));
            }
            else
            {
                var      WordFilename = args[0];
                WordFile theWordfile  = GetWordfile(WordFilename);

                var    CipherFilename = args[1];
                Cipher theCipherFile  = GetCipher(CipherFilename);

                Debug.Print(theCipherFile.GetBytes.Length.ToString());

                if (theWordfile is null)
                {
                    Console.WriteLine("Error loading Wordfile.");
                }
                else if (theCipherFile is null)
                {
                    Console.WriteLine("Error loading CipherFile.");
                }
                else
                {
                    Console.WriteLine("Start Processing...");

                    byte[] nextKeys;
                    var    theKeygen      = new Keygen();
                    var    theDecrypter   = new Decrypter();
                    var    theWordtester  = new WordTester(theWordfile);
                    var    theLogger      = new Logger("Logger.txt");
                    var    DecryptedBytes = new byte[theCipherFile.GetBytes.Length];

                    while (!theKeygen.AllKeysDelivered)
                    {
                        nextKeys       = theKeygen.GetNextKeys();
                        DecryptedBytes = theDecrypter.DecryptBytes(theCipherFile.GetBytes, nextKeys);
                        bool TestText = theWordtester.TestAsciiBytes(DecryptedBytes);

                        if (TestText && theWordtester.LastMatchCollection.Count >= 8)
                        {
                            Console.WriteLine(":)");
                            Console.Write("{0} - Found Key : {1,3} {2,3} {3,3} -> ", DateTime.Now.ToString(), nextKeys[0], nextKeys[1], nextKeys[2]);
                            Console.WriteLine("");
                            Console.WriteLine("Anzahl an Wort Treffer ---> {0}", theWordtester.LastMatchCollection.Count);
                            foreach (Match m in theWordtester.LastMatchCollection)
                            {
                                Console.WriteLine("---> {0}", m.Value);
                            }

                            Console.WriteLine("{0}", theWordtester.LastMatchCollection);

                            Console.WriteLine("");
                            Console.WriteLine(System.Text.ASCIIEncoding.ASCII.GetString(theDecrypter.DecryptedBytes));
                            Console.WriteLine("");
                            Console.WriteLine("");
                        }
                    }
                    Console.WriteLine("Finish.");
                }
            }
        }