private byte[] EncodeBlock(byte[] inBytes, int inOff, int inLen) { byte[] array = new byte[GetInputBlockSize() + 1 + 2 * defHash.Length]; Array.Copy(inBytes, inOff, array, array.Length - inLen, inLen); array[array.Length - inLen - 1] = 1; Array.Copy(defHash, 0, array, defHash.Length, defHash.Length); byte[] nextBytes = SecureRandom.GetNextBytes(random, defHash.Length); byte[] array2 = maskGeneratorFunction1(nextBytes, 0, nextBytes.Length, array.Length - defHash.Length); for (int i = defHash.Length; i != array.Length; i++) { byte[] array3; byte[] array4 = array3 = array; int num = i; IntPtr intPtr = (IntPtr)num; array4[num] = (byte)(array3[(long)intPtr] ^ array2[i - defHash.Length]); } Array.Copy(nextBytes, 0, array, 0, defHash.Length); array2 = maskGeneratorFunction1(array, defHash.Length, array.Length - defHash.Length, defHash.Length); for (int j = 0; j != defHash.Length; j++) { byte[] array3; byte[] array5 = array3 = array; int num2 = j; IntPtr intPtr = (IntPtr)num2; array5[num2] = (byte)(array3[(long)intPtr] ^ array2[j]); } return(engine.ProcessBlock(array, 0, array.Length)); }
/// <summary> /// Gets the <see cref="SecureRandom"/> instance based on our <see cref="IDigest"/> and seed data. /// </summary> /// <param name="randomDigest"> The algorithm to use to use for random processing. </param> /// <param name="seedData"> Array of objects to use as our random seed. </param> /// <returns> The <see cref="SecureRandom"/> created from our <see cref="IDigest"/> and seed. </returns> private SecureRandom GetSecureRandom(IDigest randomDigest, object[] seedData) { IRandomGenerator randomGenerator = new DigestRandomGenerator(randomDigest); if (seedData == null || seedData.Length == 0) { randomGenerator.AddSeedMaterial(SecureRandom.GetNextBytes(new SecureRandom(), 16)); } else { foreach (var seed in seedData) { Type seedType = seed.GetType(); byte[] byteData = seedType == typeof(byte[]) ? (byte[])seed : seed is IRandomSeed ? ((IRandomSeed)seed).Seed : Encoding.UTF8.GetBytes(seed.ToString()); randomGenerator.AddSeedMaterial(byteData); } } return(new SecureRandom(randomGenerator)); }
private byte[] EncodeBlock( byte[] inBytes, int inOff, int inLen) { byte[] block = new byte[GetInputBlockSize() + 1 + 2 * defHash.Length]; // // copy in the message // Array.Copy(inBytes, inOff, block, block.Length - inLen, inLen); // // add sentinel // block[block.Length - inLen - 1] = 0x01; // // as the block is already zeroed - there's no need to add PS (the >= 0 pad of 0) // // // add the hash of the encoding params. // Array.Copy(defHash, 0, block, defHash.Length, defHash.Length); // // generate the seed. // byte[] seed = SecureRandom.GetNextBytes(random, defHash.Length); // // mask the message block. // byte[] mask = maskGeneratorFunction1(seed, 0, seed.Length, block.Length - defHash.Length); for (int i = defHash.Length; i != block.Length; i++) { block[i] ^= mask[i - defHash.Length]; } // // add in the seed // Array.Copy(seed, 0, block, 0, defHash.Length); // // mask the seed. // mask = maskGeneratorFunction1( block, defHash.Length, block.Length - defHash.Length, defHash.Length); for (int i = 0; i != defHash.Length; i++) { block[i] ^= mask[i]; } return(engine.ProcessBlock(block, 0, block.Length)); }
private static Pkcs12Store CreateTemporaryStore(X509Certificate2 signerCertificate) { Pkcs12Store store = new Pkcs12StoreBuilder().Build(); var random = new SecureRandom(); string sessionPassword = Convert.ToBase64String(SecureRandom.GetNextBytes(random, 32)); using (var stream = new MemoryStream(signerCertificate.Export(X509ContentType.Pfx, sessionPassword))) { store.Load(stream, sessionPassword.ToCharArray()); } return(store); }
private byte[] EncodeBlock(byte[] inBytes, int inOff, int inLen) { byte[] destinationArray = new byte[(this.GetInputBlockSize() + 1) + (2 * this.defHash.Length)]; Array.Copy(inBytes, inOff, destinationArray, destinationArray.Length - inLen, inLen); destinationArray[(destinationArray.Length - inLen) - 1] = 1; Array.Copy(this.defHash, 0, destinationArray, this.defHash.Length, this.defHash.Length); byte[] nextBytes = SecureRandom.GetNextBytes(this.random, this.defHash.Length); byte[] buffer3 = this.maskGeneratorFunction1(nextBytes, 0, nextBytes.Length, destinationArray.Length - this.defHash.Length); for (int i = this.defHash.Length; i != destinationArray.Length; i++) { destinationArray[i] = (byte)(destinationArray[i] ^ buffer3[i - this.defHash.Length]); } Array.Copy(nextBytes, 0, destinationArray, 0, this.defHash.Length); buffer3 = this.maskGeneratorFunction1(destinationArray, this.defHash.Length, destinationArray.Length - this.defHash.Length, this.defHash.Length); for (int j = 0; j != this.defHash.Length; j++) { destinationArray[j] = (byte)(destinationArray[j] ^ buffer3[j]); } return(this.engine.ProcessBlock(destinationArray, 0, destinationArray.Length)); }
public override byte[] GenerateSeed(int numBytes) { return(SecureRandom.GetNextBytes(this, numBytes)); }
public static void KdcToken(string[] cmds) { if (cmds.Length != 7) { Console.WriteLine("Incorrect argument Count: KdcToken <AS> <Audience> <Scope> <OscoreKeys> <Kdc> <Store>"); return; } Request request = new Request(Method.POST) { URI = new Uri(cmds[1]) }; Oauth.Request oRequest = new Oauth.Request(Oauth.Request.GrantType_ClientToken) { Audience = cmds[2], Scope = CBORObject.FromObject(cmds[3]) }; request.Payload = oRequest.EncodeToBytes(); request.ContentType = MediaType.ApplicationAceCbor; request.OscoreContext = Program._OscoreKeys[cmds[4]]; request.Send(); Response response = request.WaitForResponse(); if (response.StatusCode != StatusCode.Created) { Console.WriteLine($"Error with response from the AS - Code is {response.StatusCode}"); return; } Oauth.Response oResponse = Oauth.Response.FromCBOR(response.Payload); Confirmation cnf = oResponse.Confirmation; byte[][] oscoreSalts = new byte[2][]; request = new Request(Method.POST) { URI = new Uri(cmds[5]) }; CBORObject kdcRequest = CBORObject.NewMap(); kdcRequest.Add(Oauth_Parameter.Access_Token.Key, oResponse.Token); if (cnf.AsCBOR.ContainsKey(CBORObject.FromObject(Confirmation.ConfirmationIds.COSE_OSCORE))) { oscoreSalts[0] = SecureRandom.GetNextBytes(new SecureRandom(), 8); kdcRequest.Add(Oauth_Parameter.CNonce.Key, CBORObject.FromObject(oscoreSalts[0])); request.ContentFormat = MediaType.ApplicationAceCbor; } request.Payload = kdcRequest.EncodeToBytes(); request.Send(); response = request.WaitForResponse(); if (response.StatusCode != StatusCode.Created) { Console.WriteLine("Failure"); return; } Console.WriteLine("Successfully posted to KDC"); CBORObject cborResponse = CBORObject.DecodeFromBytes(response.Payload); GroupData groupData = new GroupData(); if (cborResponse.ContainsKey(Oauth_Parameter.CNonce.Key)) { groupData.ServerNonce = cborResponse[Oauth_Parameter.CNonce.Key].GetByteString(); } if (cborResponse.ContainsKey("sign_info")) { groupData.SignInfo = CBORObject.DecodeFromBytes(cborResponse["sign_info"].GetByteString()); } else { groupData.SignInfo = CBORObject.DecodeFromBytes(new byte[] { 0x83, 0x27, 0x06, 0x82, 0x01, 0x06 }); } if (cborResponse.ContainsKey("pub_key_enc")) { groupData.PubKeyEnc = cborResponse["pub_key_enc"].GetByteString(); } groupData.SignNonce = cborResponse["SignNonce"].GetByteString(); if (cnf.AsCBOR.ContainsKey(CBORObject.FromObject(Confirmation.ConfirmationIds.COSE_OSCORE))) { CBORObject oscoreContext = cnf.AsCBOR[CBORObject.FromObject(Confirmation.ConfirmationIds.COSE_OSCORE)]; byte[] salt = new byte[0]; if (oscoreContext.ContainsKey(CBORObject.FromObject(6))) { salt = oscoreContext[CBORObject.FromObject(CBORObject.FromObject(6))].GetByteString(); } CBORObject alg = null; if (oscoreContext.ContainsKey(CBORObject.FromObject(5))) { alg = oscoreContext[CBORObject.FromObject(5)]; } CBORObject kdf = null; if (oscoreContext.ContainsKey(CBORObject.FromObject(4))) { kdf = oscoreContext[CBORObject.FromObject(4)]; } byte[] keyContext = null; if (oscoreContext.ContainsKey(CBORObject.FromObject(7))) { keyContext = oscoreContext[CBORObject.FromObject(7)].GetByteString(); } oscoreSalts[1] = cborResponse[Oauth_Parameter.CNonce.Key].GetByteString(); byte[] newSalt = new byte[salt.Length + oscoreSalts[0].Length + oscoreSalts[1].Length]; Array.Copy(salt, newSalt, salt.Length); Array.Copy(oscoreSalts[0], 0, newSalt, salt.Length, oscoreSalts[0].Length); Array.Copy(oscoreSalts[1], 0, newSalt, salt.Length + oscoreSalts[0].Length, oscoreSalts[1].Length); SecurityContext oscoapContext = SecurityContext.DeriveContext( oscoreContext[CBORObject.FromObject(1)].GetByteString(), keyContext, oscoreContext[CBORObject.FromObject(2)].GetByteString(), oscoreContext[CBORObject.FromObject(3)].GetByteString(), newSalt, alg, kdf); oscoapContext.UserData = groupData; Program._OscoreKeys.Add(cmds[6], oscoapContext); } else if (cnf.AsCBOR.ContainsKey(CBORObject.FromObject(Confirmation.ConfirmationIds.COSE_Key))) { TlsKeyPair tlsKey = new TlsKeyPair(cnf.Key); tlsKey.PrivateKey.UserData = groupData; Program._TlsKeys.Add(cmds[5], new TlsKeyPair(cnf.Key)); } else { Console.WriteLine("Don't know how to get the key"); } }
protected virtual byte[] engineGenerateKey() { return(SecureRandom.GetNextBytes(random, strength)); }
/// <summary> /// Generates the random init vector. /// </summary> /// <returns>The random init vector.</returns> public static byte[] GenerateRandomInitVector() { return(SecureRandom.GetNextBytes(new SecureRandom(), 16)); }
byte[] IEntropySource.GetEntropy() { // TODO[FIPS] Not all SecureRandom implementations are considered valid entropy sources return(SecureRandom.GetNextBytes(mSecureRandom, (mEntropySize + 7) / 8)); }
protected virtual byte[] engineGenerateKey() => SecureRandom.GetNextBytes(this.random, this.strength);
public byte[] GeneratePrivateKey() { return(SecureRandom.GetNextBytes(SecureRandom.GetInstance("SHA256PRNG"), 32)); }
private void doTest( string algorithm, byte[] input, byte[] output) { KeyParameter key = null; CipherKeyGenerator keyGen; SecureRandom rand; IBufferedCipher inCipher = null, outCipher = null; byte[] iv = null; CipherStream cIn, cOut; MemoryStream bIn, bOut; rand = new FixedSecureRandom(); string[] parts = algorithm.ToUpper(CultureInfo.InvariantCulture).Split('/'); string baseAlgorithm = parts[0]; string mode = parts.Length > 1 ? parts[1] : null; try { keyGen = GeneratorUtilities.GetKeyGenerator(baseAlgorithm); // TODO Add Algorithm property to CipherKeyGenerator? // if (!keyGen.getAlgorithm().Equals(baseAlgorithm)) // { // Fail("wrong key generator returned!"); // } // TODO Add new Init method to CipherKeyGenerator? // keyGen.Init(rand); keyGen.Init(new KeyGenerationParameters(rand, keyGen.DefaultStrength)); byte[] keyBytes = keyGen.GenerateKey(); if (algorithm.StartsWith("RC5")) { key = new RC5Parameters(keyBytes, rc5Rounds); } else { key = ParameterUtilities.CreateKeyParameter(baseAlgorithm, keyBytes); } inCipher = CipherUtilities.GetCipher(algorithm); outCipher = CipherUtilities.GetCipher(algorithm); if (!inCipher.AlgorithmName.ToUpper(CultureInfo.InvariantCulture).StartsWith(baseAlgorithm)) { Fail("wrong cipher returned!"); } ICipherParameters parameters = key; int ivLength = GetIVLength(algorithm); if (ivLength > 0) { if (baseAlgorithm == "RC2") { iv = rc2IV; } else if (baseAlgorithm == "RC5") { iv = rc5IV; } else if (baseAlgorithm == "RC5-64") { iv = rc564IV; } else { // NB: rand always generates same values each test run iv = SecureRandom.GetNextBytes(rand, ivLength); } parameters = new ParametersWithIV(key, iv); } // NB: 'rand' still needed e.g. for some paddings parameters = new ParametersWithRandom(parameters, rand); outCipher.Init(true, parameters); } catch (Exception e) { Fail("" + algorithm + " failed initialisation - " + e.ToString(), e); } // // grab the iv if there is one // try { // The Java version set this implicitly, but we set it explicity //byte[] iv = outCipher.getIV(); if (iv != null) { // TODO Examine short IV handling for these FIPS-compliant modes in Java build if (mode.StartsWith("CCM") || mode.StartsWith("CFB") || mode.StartsWith("CTR") || mode.StartsWith("EAX") || mode.StartsWith("GCM") || mode.StartsWith("GOFB") || mode.StartsWith("OCB") || mode.StartsWith("OFB") || mode.StartsWith("OPENPGPCFB") || mode.StartsWith("SIC")) { // These modes automatically pad out the IV if it is short } else { try { byte[] nIv = new byte[iv.Length - 1]; inCipher.Init(false, new ParametersWithIV(key, nIv)); Fail("failed to pick up short IV"); } //catch (InvalidAlgorithmParameterException e) catch (ArgumentException) { // ignore - this is what we want... } } //IvParameterSpec spec = new IvParameterSpec(iv); inCipher.Init(false, new ParametersWithIV(key, iv)); } else { inCipher.Init(false, key); } } catch (Exception e) { Fail("" + algorithm + " failed initialisation - " + e.ToString()); } // // encryption pass // bOut = new MemoryStream(); cOut = new CipherStream(bOut, null, outCipher); try { for (int i = 0; i != input.Length / 2; i++) { cOut.WriteByte(input[i]); } cOut.Write(input, input.Length / 2, input.Length - input.Length / 2); cOut.Close(); } catch (IOException e) { Fail("" + algorithm + " failed encryption - " + e.ToString()); } byte[] bytes = bOut.ToArray(); if (!AreEqual(bytes, output)) { Fail("" + algorithm + " failed encryption - expected " + Hex.ToHexString(output) + " got " + Hex.ToHexString(bytes)); } // // decryption pass // bIn = new MemoryStream(bytes, false); cIn = new CipherStream(bIn, inCipher, null); try { BinaryReader dIn = new BinaryReader(cIn); bytes = new byte[input.Length]; for (int i = 0; i != input.Length / 2; i++) { bytes[i] = dIn.ReadByte(); } int remaining = bytes.Length - input.Length / 2; byte[] extra = dIn.ReadBytes(remaining); if (extra.Length < remaining) { throw new EndOfStreamException(); } extra.CopyTo(bytes, input.Length / 2); } catch (Exception e) { Fail("" + algorithm + " failed decryption - " + e.ToString()); } if (!AreEqual(bytes, input)) { Fail("" + algorithm + " failed decryption - expected " + Hex.ToHexString(input) + " got " + Hex.ToHexString(bytes)); } }
byte[] IEntropySource.GetEntropy() { return(SecureRandom.GetNextBytes(mSecureRandom, (mEntropySize + 7) / 8)); }
private static byte[] Random(int size) { return(SecureRandom.GetNextBytes(RAND, size)); }
public static byte[] GenerateRandomBytes(int length) { return(SecureRandom.GetNextBytes(random, length)); }
private ITestResult KeyWrapTests() { //KW mode (PADDING NOT SUPPORTED) //test 1 /* * Initial implementation had bugs handling offset and length correctly, so for * this first test case we embed the input inside a larger buffer. */ byte[] textA = SecureRandom.GetNextBytes(Random, Random.Next(1, 64)); byte[] textB = SecureRandom.GetNextBytes(Random, Random.Next(1, 64)); byte[] textToWrap = Arrays.ConcatenateAll(textA, Hex.Decode("101112131415161718191A1B1C1D1E1F"), textB); byte[] key = Hex.Decode("000102030405060708090A0B0C0D0E0F"); byte[] expectedWrappedText = Hex.Decode("1DC91DC6E52575F6DBED25ADDA95A1B6AD3E15056E489738972C199FB9EE2913"); byte[] output = new byte[expectedWrappedText.Length]; Dstu7624WrapEngine wrapper = new Dstu7624WrapEngine(128); wrapper.Init(true, new KeyParameter(key)); output = wrapper.Wrap(textToWrap, textA.Length, textToWrap.Length - textA.Length - textB.Length); if (!Arrays.AreEqual(output, expectedWrappedText)) { return(new SimpleTestResult(false, Name + ": Failed KW (wrapping) test 1 - expected " + Hex.ToHexString(expectedWrappedText) + " got " + Hex.ToHexString(output))); } output = Arrays.ConcatenateAll(textB, output, textA); wrapper.Init(false, new KeyParameter(key)); output = wrapper.Unwrap(output, textB.Length, output.Length - textB.Length - textA.Length); byte[] expected = Arrays.CopyOfRange(textToWrap, textA.Length, textToWrap.Length - textB.Length); if (!Arrays.AreEqual(output, expected)) { return(new SimpleTestResult(false, Name + ": Failed KW (unwrapping) test 1 - expected " + Hex.ToHexString(expected) + " got " + Hex.ToHexString(output))); } //test 2 key = Hex.Decode("000102030405060708090A0B0C0D0E0F"); textToWrap = Hex.Decode("101112131415161718191A1B1C1D1E1F20219000000000000000800000000000"); expectedWrappedText = Hex.Decode("0EA983D6CE48484D51462C32CC61672210FCC44196ABE635BAF878FDB83E1A63114128585D49DB355C5819FD38039169"); output = new byte[expectedWrappedText.Length]; wrapper.Init(true, new KeyParameter(key)); output = wrapper.Wrap(textToWrap, 0, textToWrap.Length); if (!Arrays.AreEqual(output, expectedWrappedText)) { return(new SimpleTestResult(false, Name + ": Failed KW (wrapping) test 2 - expected " + Hex.ToHexString(expectedWrappedText) + " got " + Hex.ToHexString(output))); } wrapper.Init(false, new KeyParameter(key)); output = wrapper.Unwrap(expectedWrappedText, 0, expectedWrappedText.Length); if (!Arrays.AreEqual(output, textToWrap)) { return(new SimpleTestResult(false, Name + ": Failed KW (unwrapping) test 2 - expected " + Hex.ToHexString(textToWrap) + " got " + Hex.ToHexString(output))); } //test 3 key = Hex.Decode("000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F"); textToWrap = Hex.Decode("202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F404142434445464748494A4B4C4D4E4F"); expectedWrappedText = Hex.Decode("2D09A7C18E6A5A0816331EC27CEA596903F77EC8D63F3BDB73299DE7FD9F4558E05992B0B24B39E02EA496368E0841CC1E3FA44556A3048C5A6E9E335717D17D"); output = new byte[expectedWrappedText.Length]; wrapper = new Dstu7624WrapEngine(128); wrapper.Init(true, new KeyParameter(key)); output = wrapper.Wrap(textToWrap, 0, textToWrap.Length); if (!Arrays.AreEqual(output, expectedWrappedText)) { return(new SimpleTestResult(false, Name + ": Failed KW (wrapping) test 3 - expected " + Hex.ToHexString(expectedWrappedText) + " got " + Hex.ToHexString(output))); } wrapper.Init(false, new KeyParameter(key)); output = wrapper.Unwrap(expectedWrappedText, 0, expectedWrappedText.Length); if (!Arrays.AreEqual(output, textToWrap)) { return(new SimpleTestResult(false, Name + ": Failed KW (unwrapping) test 3 - expected " + Hex.ToHexString(textToWrap) + " got " + Hex.ToHexString(output))); } //test 4 key = Hex.Decode("000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F"); textToWrap = Hex.Decode("202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F404142434445464E8040000000000020"); expectedWrappedText = Hex.Decode("37E3EECB91150C6FA04CFD19D6FC57B7168C9FA5C5ED18601C68EE4AFD7301F8C8C51D7A0A5CD34F6FAB0D8AF11845CC1E4B16E0489FDA1D76BA4EFCFD161F76"); output = new byte[expectedWrappedText.Length]; wrapper = new Dstu7624WrapEngine(128); wrapper.Init(true, new KeyParameter(key)); output = wrapper.Wrap(textToWrap, 0, textToWrap.Length); if (!Arrays.AreEqual(output, expectedWrappedText)) { return(new SimpleTestResult(false, Name + ": Failed KW (wrapping) test 4 - expected " + Hex.ToHexString(expectedWrappedText) + " got " + Hex.ToHexString(output))); } wrapper.Init(false, new KeyParameter(key)); output = wrapper.Unwrap(expectedWrappedText, 0, expectedWrappedText.Length); if (!Arrays.AreEqual(output, textToWrap)) { return(new SimpleTestResult(false, Name + ": Failed KW (unwrapping) test 4 - expected " + Hex.ToHexString(textToWrap) + " got " + Hex.ToHexString(output))); } //test 5 key = Hex.Decode("000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F"); textToWrap = Hex.Decode("202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E7F"); expectedWrappedText = Hex.Decode("BE59D3C3C31B2685A8FA57CD000727F16AF303F0D87BC2D7ABD80DC2796BBC4CDBC4E0408943AF4DAF7DE9084DC81BFEF15FDCDD0DF399983DF69BF730D7AE2A199CA4F878E4723B7171DD4D1E8DF59C0F25FA0C20946BA64F9037D724BB1D50B6C2BD9788B2AF83EF6163087CD2D4488BC19F3A858D813E3A8947A529B6D65D"); output = new byte[expectedWrappedText.Length]; wrapper = new Dstu7624WrapEngine(256); wrapper.Init(true, new KeyParameter(key)); output = wrapper.Wrap(textToWrap, 0, textToWrap.Length); if (!Arrays.AreEqual(output, expectedWrappedText)) { return(new SimpleTestResult(false, Name + ": Failed KW (wrapping) test 5 - expected " + Hex.ToHexString(expectedWrappedText) + " got " + Hex.ToHexString(output))); } wrapper.Init(false, new KeyParameter(key)); output = wrapper.Unwrap(expectedWrappedText, 0, expectedWrappedText.Length); if (!Arrays.AreEqual(output, textToWrap)) { return(new SimpleTestResult(false, Name + ": Failed KW (unwrapping) test 5 - expected " + Hex.ToHexString(textToWrap) + " got " + Hex.ToHexString(output))); } //test 6 key = Hex.Decode("000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F"); textToWrap = Hex.Decode("202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F708802000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000"); expectedWrappedText = Hex.Decode("CC41D643B08592F509432E3C6F4B73156907A53B9FFB99B157DEC708F917AEA1E41D76475EDFB138A8B0220A152B673E9713DE7A2791E3573FE257C3FF3C0DAA9AD13477E52770F54CBF94D1603AED7CA876FB7913BC359D2B89562299FA92D32A9C17DBE4CC21CCE097089B9FBC245580D6DB59F8731D864B604E654397E5F5E7A79A6A777C75856039C8C86140D0CB359CA3923D902D08269F8D48E7F0F085"); output = new byte[expectedWrappedText.Length]; wrapper = new Dstu7624WrapEngine(256); wrapper.Init(true, new KeyParameter(key)); output = wrapper.Wrap(textToWrap, 0, textToWrap.Length); if (!Arrays.AreEqual(output, expectedWrappedText)) { return(new SimpleTestResult(false, Name + ": Failed KW (wrapping) test 6 - expected " + Hex.ToHexString(expectedWrappedText) + " got " + Hex.ToHexString(output))); } wrapper.Init(false, new KeyParameter(key)); output = wrapper.Unwrap(expectedWrappedText, 0, expectedWrappedText.Length); if (!Arrays.AreEqual(output, textToWrap)) { return(new SimpleTestResult(false, Name + ": Failed KW (unwrapping) test 6 - expected " + Hex.ToHexString(textToWrap) + " got " + Hex.ToHexString(output))); } //test 7 key = Hex.Decode("000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F"); textToWrap = Hex.Decode("404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E7F808182838485868788898A8B8C8D8E8F909192939495969798999A9B9C9D9E9F"); expectedWrappedText = Hex.Decode("599217EB2B5270ECEF0BB716D70E251234A2451CE04FCFBAEEA92022C581F19B7C9386BB7476B4AD721D40778F49062C3605F1E8FAC9F3F3AC04E46E89E1844DBF4F18FA9303B288741ABD71013CF208F31B4C76FBE342F89B1ABFD97E830457555651B74D3CCDBF94CC5E5EEC22821536A96F44C8BC4346B0271303E67FD313"); output = new byte[expectedWrappedText.Length]; wrapper = new Dstu7624WrapEngine(256); wrapper.Init(true, new KeyParameter(key)); output = wrapper.Wrap(textToWrap, 0, textToWrap.Length); if (!Arrays.AreEqual(output, expectedWrappedText)) { return(new SimpleTestResult(false, Name + ": Failed KW (wrapping) test 7 - expected " + Hex.ToHexString(expectedWrappedText) + " got " + Hex.ToHexString(output))); } wrapper.Init(false, new KeyParameter(key)); output = wrapper.Unwrap(expectedWrappedText, 0, expectedWrappedText.Length); if (!Arrays.AreEqual(output, textToWrap)) { return(new SimpleTestResult(false, Name + ": Failed KW (unwrapping) test 7 - expected " + Hex.ToHexString(textToWrap) + " got " + Hex.ToHexString(output))); } //test 8 key = Hex.Decode("000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F"); textToWrap = Hex.Decode("404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E7F808182838485868788898A8B8C8D8E8F908802000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000"); expectedWrappedText = Hex.Decode("B92E58F53C38F7D23F1068FA98B921AC800AD0D1947BD620700D0B6088F87D03D6A516F54198154D0C71169C2BCF520F3DF3DF527FC23E800E9A65158D45BB253A3BD0493E4822DF0DB5A366BC2F47551C5D477DDDE724A0B869F562223CEDB9D4AA36C750FA864ADF938273FBC859F7D4930F6B70C6474304AB670BA32CB0C41023769338A29EA1555F526CDFEB75C72212CD2D29F4BA49C2A62ACBE4F3272B"); output = new byte[expectedWrappedText.Length]; wrapper = new Dstu7624WrapEngine(256); wrapper.Init(true, new KeyParameter(key)); output = wrapper.Wrap(textToWrap, 0, textToWrap.Length); if (!Arrays.AreEqual(output, expectedWrappedText)) { return(new SimpleTestResult(false, Name + ": Failed KW (wrapping) test 8 - expected " + Hex.ToHexString(expectedWrappedText) + " got " + Hex.ToHexString(output))); } wrapper.Init(false, new KeyParameter(key)); output = wrapper.Unwrap(expectedWrappedText, 0, expectedWrappedText.Length); if (!Arrays.AreEqual(output, textToWrap)) { return(new SimpleTestResult(false, Name + ": Failed KW (unwrapping) test 8 - expected " + Hex.ToHexString(textToWrap) + " got " + Hex.ToHexString(output))); } //test 9 key = Hex.Decode("000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F"); textToWrap = Hex.Decode("404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E7F808182838485868788898A8B8C8D8E8F909192939495969798999A9B9C9D9E9FA0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6B7B8B9BABBBCBDBEBF"); expectedWrappedText = Hex.Decode("9618AE6065069D5054464040F17337D58BEB51AE92391D740BDF7ABB239709C46270832039FF045BCF7878E7DA9C3B4CF89326CA8B4D29DB8680EEAE1B5A18463284713A323A69AEBF33CFC4B11283C7C8041FFC97668EDF727823411C9559816C108C11EC401643765527860D8DA0ED7254792C21DB775DEB1D6971C924CC83EB626173D894694943B1828ABDE8F9495BCEBA9AC3A4A03592C085AA29CC9A0C65786E631A702D589B819C89E79EEFF29C4EC312C8860BB68F02272EA770FB8D"); output = new byte[expectedWrappedText.Length]; wrapper = new Dstu7624WrapEngine(512); wrapper.Init(true, new KeyParameter(key)); output = wrapper.Wrap(textToWrap, 0, textToWrap.Length); if (!Arrays.AreEqual(output, expectedWrappedText)) { return(new SimpleTestResult(false, Name + ": Failed KW (wrapping) test 9 - expected " + Hex.ToHexString(expectedWrappedText) + " got " + Hex.ToHexString(output))); } wrapper.Init(false, new KeyParameter(key)); output = wrapper.Unwrap(expectedWrappedText, 0, expectedWrappedText.Length); if (!Arrays.AreEqual(output, textToWrap)) { return(new SimpleTestResult(false, Name + ": Failed KW (unwrapping) test 9 - expected " + Hex.ToHexString(textToWrap) + " got " + Hex.ToHexString(output))); } //test 10 key = Hex.Decode("000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F"); textToWrap = Hex.Decode("404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E7F808182838485868788898A8B8C8D8E8F909192939495969798999A9B9C9D9E9FA0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6B7B8B9BABBBCBDBEBFC0C1C2C3C4C5C6C7C8C9CACBCCCDCECFD0D1D2D3D4D5D6D7D8D9DADBDCDDDEDFE00805000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"); expectedWrappedText = Hex.Decode("3A05BB41513555F171E9234D4834EDAD16C0BAA6136197650138219C5DA406A703C39259E9DCCF6F2691EC691CE7414B5D3CDA006DE6D6C62142FAAA742C5F8AF64FCE95BE7ABA7FE5E06C3C33EE67BAEAB196E3A71132CAE78CD605A22E34D53CD159217E7B692CC79FAC66BF5E08DBC4FE274299474E176DDDF9F462AC63F4872E9B7F16B98AA56707EE5F2F94616CFC6A9548ADBD7DCB73664C331213964593F712ECCDFA7A94E3ABA7995176EA4B7E77096A3A3FF4E4087F430B62D5DEE64999F235FA9EAC79896A1C2258BF1DFC8A6AD0E5E7E06EAEEA0CCC2DEF62F67ECE8D12EFF432277C40A7BF1A23440B3533AF1E2F7AE1BBC076D12628BB4BC7B2E4D4B4353BCEAF9A67276B3FA23CADCA80062B95EBB2D51510AFA16F97249DF98E7B845C9A410F24B3C8B3E838E58D22BC2D14F46190FC1BFDB60C9691404F99"); output = new byte[expectedWrappedText.Length]; wrapper = new Dstu7624WrapEngine(512); wrapper.Init(true, new KeyParameter(key)); output = wrapper.Wrap(textToWrap, 0, textToWrap.Length); if (!Arrays.AreEqual(output, expectedWrappedText)) { return(new SimpleTestResult(false, Name + ": Failed KW (wrapping) test 10 - expected " + Hex.ToHexString(expectedWrappedText) + " got " + Hex.ToHexString(output))); } wrapper.Init(false, new KeyParameter(key)); output = wrapper.Unwrap(expectedWrappedText, 0, expectedWrappedText.Length); if (!Arrays.AreEqual(output, textToWrap)) { return(new SimpleTestResult(false, Name + ": Failed KW (unwrapping) test 10 - expected " + Hex.ToHexString(textToWrap) + " got " + Hex.ToHexString(output))); } return(new SimpleTestResult(true, Name + ": Okay")); }