2
0

CastCipherTest.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. using Microsoft.VisualStudio.TestTools.UnitTesting;
  2. using Renci.SshNet.Security.Cryptography.Ciphers;
  3. using Renci.SshNet.Security.Cryptography.Ciphers.Modes;
  4. using Renci.SshNet.Tests.Common;
  5. using Renci.SshNet.Tests.Properties;
  6. using System.Linq;
  7. namespace Renci.SshNet.Tests.Classes.Security.Cryptography.Ciphers
  8. {
  9. /// <summary>
  10. /// Implements CAST cipher algorithm
  11. /// </summary>
  12. [TestClass]
  13. public class CastCipherTest : TestBase
  14. {
  15. [TestMethod]
  16. public void Test_Cipher_CastCipher_128_CBC()
  17. {
  18. var input = new byte[] { 0x00, 0x00, 0x00, 0x2c, 0x1a, 0x05, 0x00, 0x00, 0x00, 0x0c, 0x73, 0x73, 0x68, 0x2d, 0x75, 0x73, 0x65, 0x72, 0x61, 0x75, 0x74, 0x68, 0x30, 0x9e, 0xe0, 0x9c, 0x12, 0xee, 0x3a, 0x30, 0x03, 0x52, 0x1c, 0x1a, 0xe7, 0x3e, 0x0b, 0x9a, 0xcf, 0x9a, 0x57, 0x42, 0x0b, 0x4f, 0x4a, 0x15, 0xa0, 0xf5 };
  19. var key = new byte[] { 0xe4, 0x94, 0xf9, 0xb1, 0x00, 0x4f, 0x16, 0x2a, 0x80, 0x11, 0xea, 0x73, 0x0d, 0xb9, 0xbf, 0x64 };
  20. var iv = new byte[] { 0x74, 0x8b, 0x4f, 0xe6, 0xc1, 0x29, 0xb3, 0x54, 0xec, 0x77, 0x92, 0xf3, 0x15, 0xa0, 0x41, 0xa8 };
  21. var output = new byte[] { 0x32, 0xef, 0xbd, 0xac, 0xb6, 0xfd, 0x1f, 0xae, 0x1b, 0x13, 0x5f, 0x31, 0x6d, 0x38, 0xcd, 0xb0, 0xe3, 0xca, 0xe1, 0xbc, 0xf8, 0xa7, 0xc2, 0x31, 0x62, 0x14, 0x3a, 0x9a, 0xda, 0xe3, 0xf8, 0xc8, 0x70, 0x87, 0x53, 0x21, 0x5d, 0xb7, 0x94, 0xb7, 0xe8, 0xc6, 0x9d, 0x46, 0x0c, 0x6d, 0x64, 0x6d };
  22. var testCipher = new Renci.SshNet.Security.Cryptography.Ciphers.CastCipher(key, new Renci.SshNet.Security.Cryptography.Ciphers.Modes.CbcCipherMode(iv), null);
  23. var r = testCipher.Encrypt(input);
  24. if (!r.SequenceEqual(output))
  25. Assert.Fail("Invalid encryption");
  26. }
  27. [TestMethod]
  28. [Owner("olegkap")]
  29. [TestCategory("Cipher")]
  30. [TestCategory("integration")]
  31. public void Test_Cipher_Cast128CBC_Connection()
  32. {
  33. var connectionInfo = new PasswordConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD);
  34. connectionInfo.Encryptions.Clear();
  35. connectionInfo.Encryptions.Add("cast128-cbc", new CipherInfo(128, (key, iv) => { return new CastCipher(key, new CbcCipherMode(iv), null); }));
  36. using (var client = new SshClient(connectionInfo))
  37. {
  38. client.Connect();
  39. client.Disconnect();
  40. }
  41. }
  42. /// <summary>
  43. ///A test for CastCipher Constructor
  44. ///</summary>
  45. [TestMethod]
  46. [Ignore] // placeholder for actual test
  47. public void CastCipherConstructorTest()
  48. {
  49. byte[] key = null; // TODO: Initialize to an appropriate value
  50. CipherMode mode = null; // TODO: Initialize to an appropriate value
  51. CipherPadding padding = null; // TODO: Initialize to an appropriate value
  52. CastCipher target = new CastCipher(key, mode, padding);
  53. Assert.Inconclusive("TODO: Implement code to verify target");
  54. }
  55. /// <summary>
  56. ///A test for DecryptBlock
  57. ///</summary>
  58. [TestMethod]
  59. [Ignore] // placeholder for actual test
  60. public void DecryptBlockTest()
  61. {
  62. byte[] key = null; // TODO: Initialize to an appropriate value
  63. CipherMode mode = null; // TODO: Initialize to an appropriate value
  64. CipherPadding padding = null; // TODO: Initialize to an appropriate value
  65. CastCipher target = new CastCipher(key, mode, padding); // TODO: Initialize to an appropriate value
  66. byte[] inputBuffer = null; // TODO: Initialize to an appropriate value
  67. int inputOffset = 0; // TODO: Initialize to an appropriate value
  68. int inputCount = 0; // TODO: Initialize to an appropriate value
  69. byte[] outputBuffer = null; // TODO: Initialize to an appropriate value
  70. int outputOffset = 0; // TODO: Initialize to an appropriate value
  71. int expected = 0; // TODO: Initialize to an appropriate value
  72. int actual;
  73. actual = target.DecryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset);
  74. Assert.AreEqual(expected, actual);
  75. Assert.Inconclusive("Verify the correctness of this test method.");
  76. }
  77. /// <summary>
  78. ///A test for EncryptBlock
  79. ///</summary>
  80. [TestMethod]
  81. [Ignore] // placeholder for actual test
  82. public void EncryptBlockTest()
  83. {
  84. byte[] key = null; // TODO: Initialize to an appropriate value
  85. CipherMode mode = null; // TODO: Initialize to an appropriate value
  86. CipherPadding padding = null; // TODO: Initialize to an appropriate value
  87. CastCipher target = new CastCipher(key, mode, padding); // TODO: Initialize to an appropriate value
  88. byte[] inputBuffer = null; // TODO: Initialize to an appropriate value
  89. int inputOffset = 0; // TODO: Initialize to an appropriate value
  90. int inputCount = 0; // TODO: Initialize to an appropriate value
  91. byte[] outputBuffer = null; // TODO: Initialize to an appropriate value
  92. int outputOffset = 0; // TODO: Initialize to an appropriate value
  93. int expected = 0; // TODO: Initialize to an appropriate value
  94. int actual;
  95. actual = target.EncryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset);
  96. Assert.AreEqual(expected, actual);
  97. Assert.Inconclusive("Verify the correctness of this test method.");
  98. }
  99. }
  100. }