PageRenderTime 32ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/js/lib/Socket.IO-node/support/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/CFBModeTest.as

http://github.com/onedayitwillmake/RealtimeMultiplayerNodeJs
ActionScript | 98 lines | 84 code | 3 blank | 11 comment | 0 complexity | 11159297669d126cbf08c58fc31c451a MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, MPL-2.0-no-copyleft-exception, BSD-3-Clause
  1. /**
  2. * CFBModeTest
  3. *
  4. * A test class for CFBMode
  5. * Copyright (c) 2007 Henri Torgemane
  6. *
  7. * See LICENSE.txt for full license information.
  8. */
  9. package com.hurlant.crypto.tests
  10. {
  11. import com.hurlant.crypto.symmetric.AESKey;
  12. import com.hurlant.crypto.symmetric.CFBMode;
  13. import com.hurlant.crypto.symmetric.NullPad;
  14. import com.hurlant.util.Hex;
  15. import flash.utils.ByteArray;
  16. public class CFBModeTest extends TestCase
  17. {
  18. public function CFBModeTest(h:ITestHarness)
  19. {
  20. super(h, "CFBMode Test");
  21. runTest(testCFB_AES128, "CFB AES-128 Test Vectors");
  22. runTest(testCFB_AES192, "CFB AES-192 Test Vectors");
  23. runTest(testCFB_AES256, "CFB AES-256 Test Vectors");
  24. h.endTestCase();
  25. }
  26. /**
  27. * http://csrc.nist.gov/publications/nistpubs/800-38a/sp800-38a.pdf
  28. */
  29. public function testCFB_AES128():void {
  30. var key:ByteArray = Hex.toArray("2b7e151628aed2a6abf7158809cf4f3c");
  31. var pt:ByteArray = Hex.toArray(
  32. "6bc1bee22e409f96e93d7e117393172a" +
  33. "ae2d8a571e03ac9c9eb76fac45af8e51" +
  34. "30c81c46a35ce411e5fbc1191a0a52ef" +
  35. "f69f2445df4f9b17ad2b417be66c3710");
  36. var ct:ByteArray = Hex.toArray(
  37. "3b3fd92eb72dad20333449f8e83cfb4a" +
  38. "c8a64537a0b3a93fcde3cdad9f1ce58b" +
  39. "26751f67a3cbb140b1808cf187a4f4df" +
  40. "c04b05357c5d1c0eeac4c66f9ff7f2e6");
  41. var cfb:CFBMode = new CFBMode(new AESKey(key), new NullPad);
  42. cfb.IV = Hex.toArray("000102030405060708090a0b0c0d0e0f");
  43. var src:ByteArray = new ByteArray;
  44. src.writeBytes(pt);
  45. cfb.encrypt(src);
  46. assert("CFB_AES128 test 1", Hex.fromArray(src)==Hex.fromArray(ct));
  47. cfb.decrypt(src);
  48. assert("CFB_AES128 test 2", Hex.fromArray(src)==Hex.fromArray(pt));
  49. }
  50. public function testCFB_AES192():void {
  51. var key:ByteArray = Hex.toArray("8e73b0f7da0e6452c810f32b809079e562f8ead2522c6b7b");
  52. var pt:ByteArray = Hex.toArray(
  53. "6bc1bee22e409f96e93d7e117393172a" +
  54. "ae2d8a571e03ac9c9eb76fac45af8e51" +
  55. "30c81c46a35ce411e5fbc1191a0a52ef" +
  56. "f69f2445df4f9b17ad2b417be66c3710");
  57. var ct:ByteArray = Hex.toArray(
  58. "cdc80d6fddf18cab34c25909c99a4174" +
  59. "67ce7f7f81173621961a2b70171d3d7a" +
  60. "2e1e8a1dd59b88b1c8e60fed1efac4c9" +
  61. "c05f9f9ca9834fa042ae8fba584b09ff");
  62. var cfb:CFBMode = new CFBMode(new AESKey(key), new NullPad);
  63. cfb.IV = Hex.toArray("000102030405060708090a0b0c0d0e0f");
  64. var src:ByteArray = new ByteArray;
  65. src.writeBytes(pt);
  66. cfb.encrypt(src);
  67. assert("CFB_AES192 test 1", Hex.fromArray(src)==Hex.fromArray(ct));
  68. cfb.decrypt(src);
  69. assert("CFB_AES192 test 2", Hex.fromArray(src)==Hex.fromArray(pt));
  70. }
  71. public function testCFB_AES256():void {
  72. var key:ByteArray = Hex.toArray(
  73. "603deb1015ca71be2b73aef0857d7781" +
  74. "1f352c073b6108d72d9810a30914dff4");
  75. var pt:ByteArray = Hex.toArray(
  76. "6bc1bee22e409f96e93d7e117393172a" +
  77. "ae2d8a571e03ac9c9eb76fac45af8e51" +
  78. "30c81c46a35ce411e5fbc1191a0a52ef" +
  79. "f69f2445df4f9b17ad2b417be66c3710");
  80. var ct:ByteArray = Hex.toArray(
  81. "dc7e84bfda79164b7ecd8486985d3860" +
  82. "39ffed143b28b1c832113c6331e5407b" +
  83. "df10132415e54b92a13ed0a8267ae2f9" +
  84. "75a385741ab9cef82031623d55b1e471");
  85. var cfb:CFBMode = new CFBMode(new AESKey(key), new NullPad);
  86. cfb.IV = Hex.toArray("000102030405060708090a0b0c0d0e0f");
  87. var src:ByteArray = new ByteArray;
  88. src.writeBytes(pt);
  89. cfb.encrypt(src);
  90. assert("CFB_AES256 test 1", Hex.fromArray(src)==Hex.fromArray(ct));
  91. cfb.decrypt(src);
  92. assert("CFB_AES256 test 2", Hex.fromArray(src)==Hex.fromArray(pt));
  93. }
  94. }
  95. }