From 7d3a4a2667a2c35db0b775c02082ec03e05cfa65 Mon Sep 17 00:00:00 2001 From: Shargon Date: Wed, 28 Oct 2020 09:29:08 +0100 Subject: [PATCH] Change Scrypt from source to nuget (#2025) * Change from source to nuget * Use SCrypt.Generate directly * Fix UT Co-authored-by: Erik Zhang --- src/neo/Cryptography/SCrypt.cs | 323 ------------------ src/neo/Wallets/KeyPair.cs | 3 +- src/neo/Wallets/Wallet.cs | 3 +- src/neo/neo.csproj | 1 + tests/neo.UnitTests/Cryptography/UT_SCrypt.cs | 4 +- tests/neo.UnitTests/TestUtils.cs | 4 +- .../Wallets/NEP6/UT_NEP6Account.cs | 2 +- .../Wallets/NEP6/UT_NEP6Wallet.cs | 26 +- .../Wallets/SQLite/UT_UserWallet.cs | 2 +- tests/neo.UnitTests/Wallets/UT_Wallet.cs | 14 +- 10 files changed, 31 insertions(+), 351 deletions(-) delete mode 100644 src/neo/Cryptography/SCrypt.cs diff --git a/src/neo/Cryptography/SCrypt.cs b/src/neo/Cryptography/SCrypt.cs deleted file mode 100644 index 4e6f3bc389..0000000000 --- a/src/neo/Cryptography/SCrypt.cs +++ /dev/null @@ -1,323 +0,0 @@ -using System; -using System.Security.Cryptography; - -namespace Neo.Cryptography -{ - public static class SCrypt - { - private unsafe static void BulkCopy(void* dst, void* src, int len) - { - var d = (byte*)dst; - var s = (byte*)src; - - while (len >= 8) - { - *(ulong*)d = *(ulong*)s; - d += 8; - s += 8; - len -= 8; - } - if (len >= 4) - { - *(uint*)d = *(uint*)s; - d += 4; - - s += 4; - len -= 4; - } - if (len >= 2) - { - *(ushort*)d = *(ushort*)s; - d += 2; - s += 2; - len -= 2; - } - if (len >= 1) - { - *d = *s; - } - } - - private unsafe static void BulkXor(void* dst, void* src, int len) - { - var d = (byte*)dst; - var s = (byte*)src; - - while (len >= 8) - { - *(ulong*)d ^= *(ulong*)s; - d += 8; - s += 8; - len -= 8; - } - if (len >= 4) - { - *(uint*)d ^= *(uint*)s; - d += 4; - s += 4; - len -= 4; - } - if (len >= 2) - { - *(ushort*)d ^= *(ushort*)s; - d += 2; - s += 2; - len -= 2; - } - if (len >= 1) - { - *d ^= *s; - } - } - - private unsafe static void Encode32(byte* p, uint x) - { - p[0] = (byte)(x & 0xff); - p[1] = (byte)((x >> 8) & 0xff); - p[2] = (byte)((x >> 16) & 0xff); - p[3] = (byte)((x >> 24) & 0xff); - } - - private unsafe static uint Decode32(byte* p) - { - return - ((uint)(p[0]) + - ((uint)(p[1]) << 8) + - ((uint)(p[2]) << 16) + - ((uint)(p[3]) << 24)); - } - - private unsafe static void Salsa208(uint* B) - { - uint x0 = B[0]; - uint x1 = B[1]; - uint x2 = B[2]; - uint x3 = B[3]; - uint x4 = B[4]; - uint x5 = B[5]; - uint x6 = B[6]; - uint x7 = B[7]; - uint x8 = B[8]; - uint x9 = B[9]; - uint x10 = B[10]; - uint x11 = B[11]; - uint x12 = B[12]; - uint x13 = B[13]; - uint x14 = B[14]; - uint x15 = B[15]; - - for (var i = 0; i < 8; i += 2) - { - //((x0 + x12) << 7) | ((x0 + x12) >> (32 - 7)); - /* Operate on columns. */ - x4 ^= R(x0 + x12, 7); x8 ^= R(x4 + x0, 9); - x12 ^= R(x8 + x4, 13); x0 ^= R(x12 + x8, 18); - - x9 ^= R(x5 + x1, 7); x13 ^= R(x9 + x5, 9); - x1 ^= R(x13 + x9, 13); x5 ^= R(x1 + x13, 18); - - x14 ^= R(x10 + x6, 7); x2 ^= R(x14 + x10, 9); - x6 ^= R(x2 + x14, 13); x10 ^= R(x6 + x2, 18); - - x3 ^= R(x15 + x11, 7); x7 ^= R(x3 + x15, 9); - x11 ^= R(x7 + x3, 13); x15 ^= R(x11 + x7, 18); - - /* Operate on rows. */ - x1 ^= R(x0 + x3, 7); x2 ^= R(x1 + x0, 9); - x3 ^= R(x2 + x1, 13); x0 ^= R(x3 + x2, 18); - - x6 ^= R(x5 + x4, 7); x7 ^= R(x6 + x5, 9); - x4 ^= R(x7 + x6, 13); x5 ^= R(x4 + x7, 18); - - x11 ^= R(x10 + x9, 7); x8 ^= R(x11 + x10, 9); - x9 ^= R(x8 + x11, 13); x10 ^= R(x9 + x8, 18); - - x12 ^= R(x15 + x14, 7); x13 ^= R(x12 + x15, 9); - x14 ^= R(x13 + x12, 13); x15 ^= R(x14 + x13, 18); - } - - B[0] += x0; - B[1] += x1; - B[2] += x2; - B[3] += x3; - B[4] += x4; - B[5] += x5; - B[6] += x6; - B[7] += x7; - B[8] += x8; - B[9] += x9; - B[10] += x10; - B[11] += x11; - B[12] += x12; - B[13] += x13; - B[14] += x14; - B[15] += x15; - } - - private unsafe static uint R(uint a, int b) - { - return (a << b) | (a >> (32 - b)); - } - - private unsafe static void BlockMix(uint* Bin, uint* Bout, uint* X, int r) - { - /* 1: X <-- B_{2r - 1} */ - BulkCopy(X, &Bin[(2 * r - 1) * 16], 64); - - /* 2: for i = 0 to 2r - 1 do */ - for (var i = 0; i < 2 * r; i += 2) - { - /* 3: X <-- H(X \xor B_i) */ - BulkXor(X, &Bin[i * 16], 64); - Salsa208(X); - - /* 4: Y_i <-- X */ - /* 6: B' <-- (Y_0, Y_2 ... Y_{2r-2}, Y_1, Y_3 ... Y_{2r-1}) */ - BulkCopy(&Bout[i * 8], X, 64); - - /* 3: X <-- H(X \xor B_i) */ - BulkXor(X, &Bin[i * 16 + 16], 64); - Salsa208(X); - - /* 4: Y_i <-- X */ - /* 6: B' <-- (Y_0, Y_2 ... Y_{2r-2}, Y_1, Y_3 ... Y_{2r-1}) */ - BulkCopy(&Bout[i * 8 + r * 16], X, 64); - } - } - - private unsafe static long Integerify(uint* B, int r) - { - var X = (uint*)(((byte*)B) + (2 * r - 1) * 64); - - return (((long)(X[1]) << 32) + X[0]); - } - - private unsafe static void SMix(byte* B, int r, int N, uint* V, uint* XY) - { - var X = XY; - var Y = &XY[32 * r]; - var Z = &XY[64 * r]; - - /* 1: X <-- B */ - for (var k = 0; k < 32 * r; k++) - { - X[k] = Decode32(&B[4 * k]); - } - - /* 2: for i = 0 to N - 1 do */ - for (var i = 0L; i < N; i += 2) - { - /* 3: V_i <-- X */ - BulkCopy(&V[i * (32 * r)], X, 128 * r); - - /* 4: X <-- H(X) */ - BlockMix(X, Y, Z, r); - - /* 3: V_i <-- X */ - BulkCopy(&V[(i + 1) * (32 * r)], Y, 128 * r); - - /* 4: X <-- H(X) */ - BlockMix(Y, X, Z, r); - } - - /* 6: for i = 0 to N - 1 do */ - for (var i = 0; i < N; i += 2) - { - /* 7: j <-- Integerify(X) mod N */ - var j = Integerify(X, r) & (N - 1); - - /* 8: X <-- H(X \xor V_j) */ - BulkXor(X, &V[j * (32 * r)], 128 * r); - BlockMix(X, Y, Z, r); - - /* 7: j <-- Integerify(X) mod N */ - j = Integerify(Y, r) & (N - 1); - - /* 8: X <-- H(X \xor V_j) */ - BulkXor(Y, &V[j * (32 * r)], 128 * r); - BlockMix(Y, X, Z, r); - } - - /* 10: B' <-- X */ - for (var k = 0; k < 32 * r; k++) - { - Encode32(&B[4 * k], X[k]); - } - } - - public unsafe static byte[] DeriveKey(byte[] password, byte[] salt, int N, int r, int p, int derivedKeyLength) - { - var Ba = new byte[128 * r * p + 63]; - var XYa = new byte[256 * r + 63]; - var Va = new byte[128 * r * N + 63]; - var buf = new byte[derivedKeyLength]; - - var mac = new HMACSHA256(password); - - /* 1: (B_0 ... B_{p-1}) <-- PBKDF2(P, S, 1, p * MFLen) */ - PBKDF2_SHA256(mac, password, salt, salt.Length, 1, Ba, p * 128 * r); - - fixed (byte* B = Ba) - fixed (void* V = Va) - fixed (void* XY = XYa) - { - /* 2: for i = 0 to p - 1 do */ - for (var i = 0; i < p; i++) - { - /* 3: B_i <-- MF(B_i, N) */ - SMix(&B[i * 128 * r], r, N, (uint*)V, (uint*)XY); - } - } - - /* 5: DK <-- PBKDF2(P, B, 1, dkLen) */ - PBKDF2_SHA256(mac, password, Ba, p * 128 * r, 1, buf, buf.Length); - - return buf; - } - - private static void PBKDF2_SHA256(HMACSHA256 mac, byte[] password, byte[] salt, int saltLength, long iterationCount, byte[] derivedKey, int derivedKeyLength) - { - if (derivedKeyLength > (Math.Pow(2, 32) - 1) * 32) - { - throw new ArgumentException("Requested key length too long"); - } - - var U = new byte[32]; - var T = new byte[32]; - var saltBuffer = new byte[saltLength + 4]; - - var blockCount = (int)Math.Ceiling((double)derivedKeyLength / 32); - var r = derivedKeyLength - (blockCount - 1) * 32; - - Buffer.BlockCopy(salt, 0, saltBuffer, 0, saltLength); - - using (var incrementalHasher = IncrementalHash.CreateHMAC(HashAlgorithmName.SHA256, mac.Key)) - { - for (int i = 1; i <= blockCount; i++) - { - saltBuffer[saltLength + 0] = (byte)(i >> 24); - saltBuffer[saltLength + 1] = (byte)(i >> 16); - saltBuffer[saltLength + 2] = (byte)(i >> 8); - saltBuffer[saltLength + 3] = (byte)(i); - - mac.Initialize(); - incrementalHasher.AppendData(saltBuffer, 0, saltBuffer.Length); - Buffer.BlockCopy(incrementalHasher.GetHashAndReset(), 0, U, 0, U.Length); - Buffer.BlockCopy(U, 0, T, 0, 32); - - for (long j = 1; j < iterationCount; j++) - { - incrementalHasher.AppendData(U, 0, U.Length); - Buffer.BlockCopy(incrementalHasher.GetHashAndReset(), 0, U, 0, U.Length); - for (int k = 0; k < 32; k++) - { - T[k] ^= U[k]; - } - } - - Buffer.BlockCopy(T, 0, derivedKey, (i - 1) * 32, (i == blockCount ? r : 32)); - } - } - } - } -} diff --git a/src/neo/Wallets/KeyPair.cs b/src/neo/Wallets/KeyPair.cs index 01b5c71756..8acf280afe 100644 --- a/src/neo/Wallets/KeyPair.cs +++ b/src/neo/Wallets/KeyPair.cs @@ -1,5 +1,6 @@ using Neo.Cryptography; using Neo.SmartContract; +using Org.BouncyCastle.Crypto.Generators; using System; using System.Text; using static Neo.Wallets.Helper; @@ -56,7 +57,7 @@ public string Export(string passphrase, int N = 16384, int r = 8, int p = 8) UInt160 script_hash = Contract.CreateSignatureRedeemScript(PublicKey).ToScriptHash(); string address = script_hash.ToAddress(); byte[] addresshash = Encoding.ASCII.GetBytes(address).Sha256().Sha256()[..4]; - byte[] derivedkey = SCrypt.DeriveKey(Encoding.UTF8.GetBytes(passphrase), addresshash, N, r, p, 64); + byte[] derivedkey = SCrypt.Generate(Encoding.UTF8.GetBytes(passphrase), addresshash, N, r, p, 64); byte[] derivedhalf1 = derivedkey[..32]; byte[] derivedhalf2 = derivedkey[32..]; byte[] encryptedkey = XOR(PrivateKey, derivedhalf1).AES256Encrypt(derivedhalf2); diff --git a/src/neo/Wallets/Wallet.cs b/src/neo/Wallets/Wallet.cs index 614688f768..603c6a50a6 100644 --- a/src/neo/Wallets/Wallet.cs +++ b/src/neo/Wallets/Wallet.cs @@ -7,6 +7,7 @@ using Neo.SmartContract.Manifest; using Neo.SmartContract.Native; using Neo.VM; +using Org.BouncyCastle.Crypto.Generators; using System; using System.Collections.Generic; using System.Linq; @@ -162,7 +163,7 @@ public static byte[] GetPrivateKeyFromNEP2(string nep2, string passphrase, int N byte[] addresshash = new byte[4]; Buffer.BlockCopy(data, 3, addresshash, 0, 4); byte[] datapassphrase = Encoding.UTF8.GetBytes(passphrase); - byte[] derivedkey = SCrypt.DeriveKey(datapassphrase, addresshash, N, r, p, 64); + byte[] derivedkey = SCrypt.Generate(datapassphrase, addresshash, N, r, p, 64); Array.Clear(datapassphrase, 0, datapassphrase.Length); byte[] derivedhalf1 = derivedkey[..32]; byte[] derivedhalf2 = derivedkey[32..]; diff --git a/src/neo/neo.csproj b/src/neo/neo.csproj index bce36eada4..a848dc6e7b 100644 --- a/src/neo/neo.csproj +++ b/src/neo/neo.csproj @@ -22,6 +22,7 @@ + diff --git a/tests/neo.UnitTests/Cryptography/UT_SCrypt.cs b/tests/neo.UnitTests/Cryptography/UT_SCrypt.cs index 612a8307c6..f0934b8138 100644 --- a/tests/neo.UnitTests/Cryptography/UT_SCrypt.cs +++ b/tests/neo.UnitTests/Cryptography/UT_SCrypt.cs @@ -1,5 +1,5 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; -using Neo.Cryptography; +using Org.BouncyCastle.Crypto.Generators; namespace Neo.UnitTests.Cryptography { @@ -11,7 +11,7 @@ public void DeriveKeyTest() { int N = 32, r = 2, p = 2; - var derivedkey = SCrypt.DeriveKey(new byte[] { 0x01, 0x02, 0x03 }, new byte[] { 0x04, 0x05, 0x06 }, N, r, p, 64).ToHexString(); + var derivedkey = SCrypt.Generate(new byte[] { 0x01, 0x02, 0x03 }, new byte[] { 0x04, 0x05, 0x06 }, N, r, p, 64).ToHexString(); Assert.AreEqual("b6274d3a81892c24335ab46a08ec16d040ac00c5943b212099a44b76a9b8102631ab988fa07fb35357cee7b0e3910098c0774c0e97399997676d890b2bf2bb25", derivedkey); } } diff --git a/tests/neo.UnitTests/TestUtils.cs b/tests/neo.UnitTests/TestUtils.cs index a97869c8b5..9e12f702ae 100644 --- a/tests/neo.UnitTests/TestUtils.cs +++ b/tests/neo.UnitTests/TestUtils.cs @@ -82,10 +82,10 @@ public static NEP6Wallet GenerateTestWallet() JObject wallet = new JObject(); wallet["name"] = "noname"; wallet["version"] = new Version("3.0").ToString(); - wallet["scrypt"] = new ScryptParameters(0, 0, 0).ToJson(); + wallet["scrypt"] = new ScryptParameters(2, 1, 1).ToJson(); wallet["accounts"] = new JArray(); wallet["extra"] = null; - wallet.ToString().Should().Be("{\"name\":\"noname\",\"version\":\"3.0\",\"scrypt\":{\"n\":0,\"r\":0,\"p\":0},\"accounts\":[],\"extra\":null}"); + wallet.ToString().Should().Be("{\"name\":\"noname\",\"version\":\"3.0\",\"scrypt\":{\"n\":2,\"r\":1,\"p\":1},\"accounts\":[],\"extra\":null}"); return new NEP6Wallet(wallet); } diff --git a/tests/neo.UnitTests/Wallets/NEP6/UT_NEP6Account.cs b/tests/neo.UnitTests/Wallets/NEP6/UT_NEP6Account.cs index e2cb70b11a..a4f36fa5d5 100644 --- a/tests/neo.UnitTests/Wallets/NEP6/UT_NEP6Account.cs +++ b/tests/neo.UnitTests/Wallets/NEP6/UT_NEP6Account.cs @@ -23,7 +23,7 @@ public static void ClassSetup(TestContext context) byte[] privateKey = { 0x01,0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}; _keyPair = new KeyPair(privateKey); - _nep2 = _keyPair.Export("Satoshi", 0, 0, 0); + _nep2 = _keyPair.Export("Satoshi", 2, 1, 1); } [TestInitialize] diff --git a/tests/neo.UnitTests/Wallets/NEP6/UT_NEP6Wallet.cs b/tests/neo.UnitTests/Wallets/NEP6/UT_NEP6Wallet.cs index 0e8ac02e05..1af95ce082 100644 --- a/tests/neo.UnitTests/Wallets/NEP6/UT_NEP6Wallet.cs +++ b/tests/neo.UnitTests/Wallets/NEP6/UT_NEP6Wallet.cs @@ -39,7 +39,7 @@ public static void ClassInit(TestContext context) } keyPair = new KeyPair(privateKey); testScriptHash = Neo.SmartContract.Contract.CreateSignatureContract(keyPair.PublicKey).ScriptHash; - nep2key = keyPair.Export("123", 0, 0, 0); + nep2key = keyPair.Export("123", 2, 1, 1); } private NEP6Wallet CreateWallet() @@ -52,7 +52,7 @@ private string CreateWalletFile() rootPath = GetRandomPath(); if (!Directory.Exists(rootPath)) Directory.CreateDirectory(rootPath); string path = Path.Combine(rootPath, "wallet.json"); - File.WriteAllText(path, "{\"name\":\"name\",\"version\":\"3.0\",\"scrypt\":{\"n\":0,\"r\":0,\"p\":0},\"accounts\":[],\"extra\":{}}"); + File.WriteAllText(path, "{\"name\":\"name\",\"version\":\"3.0\",\"scrypt\":{\"n\":2,\"r\":1,\"p\":1},\"accounts\":[],\"extra\":{}}"); return path; } @@ -76,7 +76,7 @@ public void TestChangePassword() JObject wallet = new JObject(); wallet["name"] = "name"; wallet["version"] = new System.Version("3.0").ToString(); - wallet["scrypt"] = new ScryptParameters(0, 0, 0).ToJson(); + wallet["scrypt"] = new ScryptParameters(2, 1, 1).ToJson(); wallet["accounts"] = new JArray(); wallet["extra"] = new JObject(); File.WriteAllText(wPath, wallet.ToString()); @@ -95,7 +95,7 @@ public void TestConstructorWithPathAndName() { NEP6Wallet wallet = new NEP6Wallet(wPath); Assert.AreEqual("name", wallet.Name); - Assert.AreEqual(new ScryptParameters(0, 0, 0).ToJson().ToString(), wallet.Scrypt.ToJson().ToString()); + Assert.AreEqual(new ScryptParameters(2, 1, 1).ToJson().ToString(), wallet.Scrypt.ToJson().ToString()); Assert.AreEqual(new Version("3.0").ToString(), wallet.Version.ToString()); wallet = new NEP6Wallet("", "test"); Assert.AreEqual("test", wallet.Name); @@ -205,7 +205,7 @@ public void TestCreateAccountWithScriptHash() [TestMethod] public void TestDecryptKey() { - string nep2key = keyPair.Export("123", 0, 0, 0); + string nep2key = keyPair.Export("123", 2, 1, 1); uut.Unlock("123"); KeyPair key1 = uut.DecryptKey(nep2key); bool result = key1.Equals(keyPair); @@ -307,7 +307,7 @@ public void TestImportNep2() { bool result = uut.Contains(testScriptHash); Assert.AreEqual(false, result); - uut.Import(nep2key, "123", 0, 0, 0); + uut.Import(nep2key, "123", 2, 1, 1); result = uut.Contains(testScriptHash); Assert.AreEqual(true, result); uut.DeleteAccount(testScriptHash); @@ -316,13 +316,13 @@ public void TestImportNep2() JObject wallet = new JObject(); wallet["name"] = "name"; wallet["version"] = new Version("3.0").ToString(); - wallet["scrypt"] = new ScryptParameters(0, 0, 0).ToJson(); + wallet["scrypt"] = new ScryptParameters(2, 1, 1).ToJson(); wallet["accounts"] = new JArray(); wallet["extra"] = new JObject(); uut = new NEP6Wallet(wallet); result = uut.Contains(testScriptHash); Assert.AreEqual(false, result); - uut.Import(nep2key, "123", 0, 0, 0); + uut.Import(nep2key, "123", 2, 1, 1); result = uut.Contains(testScriptHash); Assert.AreEqual(true, result); } @@ -360,7 +360,7 @@ public void TestSave() JObject wallet = new JObject(); wallet["name"] = "name"; wallet["version"] = new System.Version("3.0").ToString(); - wallet["scrypt"] = new ScryptParameters(0, 0, 0).ToJson(); + wallet["scrypt"] = new ScryptParameters(2, 1, 1).ToJson(); wallet["accounts"] = new JArray(); wallet["extra"] = new JObject(); File.WriteAllText(wPath, wallet.ToString()); @@ -402,12 +402,12 @@ public void TestVerifyPassword() JObject wallet = new JObject(); wallet["name"] = "name"; wallet["version"] = new Version("3.0").ToString(); - wallet["scrypt"] = new ScryptParameters(0, 0, 0).ToJson(); + wallet["scrypt"] = new ScryptParameters(2, 1, 1).ToJson(); wallet["accounts"] = new JArray(); wallet["extra"] = new JObject(); uut = new NEP6Wallet(wallet); - nep2key = keyPair.Export("123", 0, 0, 0); - uut.Import(nep2key, "123", 0, 0, 0); + nep2key = keyPair.Export("123", 2, 1, 1); + uut.Import(nep2key, "123", 2, 1, 1); Assert.IsFalse(uut.VerifyPassword("1")); Assert.IsTrue(uut.VerifyPassword("123")); } @@ -418,7 +418,7 @@ public void Test_NEP6Wallet_Json() uut.Name.Should().Be("noname"); uut.Version.Should().Be(new Version("3.0")); uut.Scrypt.Should().NotBeNull(); - uut.Scrypt.N.Should().Be(new ScryptParameters(0, 0, 0).N); + uut.Scrypt.N.Should().Be(new ScryptParameters(2, 1, 1).N); } } } diff --git a/tests/neo.UnitTests/Wallets/SQLite/UT_UserWallet.cs b/tests/neo.UnitTests/Wallets/SQLite/UT_UserWallet.cs index 2a1cc699b0..e6cb2e821e 100644 --- a/tests/neo.UnitTests/Wallets/SQLite/UT_UserWallet.cs +++ b/tests/neo.UnitTests/Wallets/SQLite/UT_UserWallet.cs @@ -29,7 +29,7 @@ public static string GetRandomPath() public static void Setup(TestContext ctx) { path = GetRandomPath(); - wallet = UserWallet.Create(path, "123456", new ScryptParameters(0, 0, 0)); + wallet = UserWallet.Create(path, "123456", new ScryptParameters(2, 1, 1)); byte[] privateKey = new byte[32]; using (RandomNumberGenerator rng = RandomNumberGenerator.Create()) { diff --git a/tests/neo.UnitTests/Wallets/UT_Wallet.cs b/tests/neo.UnitTests/Wallets/UT_Wallet.cs index 82b1031fbc..93bc7441ce 100644 --- a/tests/neo.UnitTests/Wallets/UT_Wallet.cs +++ b/tests/neo.UnitTests/Wallets/UT_Wallet.cs @@ -101,7 +101,7 @@ public class UT_Wallet public static void ClassInit(TestContext context) { glkey = UT_Crypto.generateCertainKey(32); - nep2Key = glkey.Export("pwd", 0, 0, 0); + nep2Key = glkey.Export("pwd", 2, 1, 1); } [TestInitialize] @@ -240,19 +240,19 @@ public void TestGetBalance() [TestMethod] public void TestGetPrivateKeyFromNEP2() { - Action action = () => Wallet.GetPrivateKeyFromNEP2(null, null, 0, 0, 0); + Action action = () => Wallet.GetPrivateKeyFromNEP2(null, null, 2, 1, 1); action.Should().Throw(); - action = () => Wallet.GetPrivateKeyFromNEP2("TestGetPrivateKeyFromNEP2", null, 0, 0, 0); + action = () => Wallet.GetPrivateKeyFromNEP2("TestGetPrivateKeyFromNEP2", null, 2, 1, 1); action.Should().Throw(); - action = () => Wallet.GetPrivateKeyFromNEP2("3vQB7B6MrGQZaxCuFg4oh", "TestGetPrivateKeyFromNEP2", 0, 0, 0); + action = () => Wallet.GetPrivateKeyFromNEP2("3vQB7B6MrGQZaxCuFg4oh", "TestGetPrivateKeyFromNEP2", 2, 1, 1); action.Should().Throw(); - action = () => Wallet.GetPrivateKeyFromNEP2(nep2Key, "Test", 0, 0, 0); + action = () => Wallet.GetPrivateKeyFromNEP2(nep2Key, "Test", 2, 1, 1); action.Should().Throw(); - Wallet.GetPrivateKeyFromNEP2(nep2Key, "pwd", 0, 0, 0).Should().BeEquivalentTo(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31 }); + Wallet.GetPrivateKeyFromNEP2(nep2Key, "pwd", 2, 1, 1).Should().BeEquivalentTo(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31 }); } [TestMethod] @@ -278,7 +278,7 @@ public void TestImport1() public void TestImport2() { MyWallet wallet = new MyWallet(); - wallet.Import(nep2Key, "pwd", 0, 0, 0).Should().NotBeNull(); + wallet.Import(nep2Key, "pwd", 2, 1, 1).Should().NotBeNull(); } [TestMethod]