PageRenderTime 83ms CodeModel.GetById 41ms app.highlight 8ms RepoModel.GetById 32ms app.codeStats 1ms

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

http://github.com/onedayitwillmake/RealtimeMultiplayerNodeJs
ActionScript | 71 lines | 57 code | 3 blank | 11 comment | 0 complexity | 7b71fba87d1eb91ff6c3d827d1dc1a43 MD5 | raw file
 1/**
 2 * CFB8ModeTest
 3 * 
 4 * A test class for CFB8Mode
 5 * Copyright (c) 2007 Henri Torgemane
 6 * 
 7 * See LICENSE.txt for full license information.
 8 */
 9package com.hurlant.crypto.tests
10{
11	import flash.utils.ByteArray;
12	import com.hurlant.util.Hex;
13	import com.hurlant.crypto.symmetric.CFB8Mode;
14	import com.hurlant.crypto.symmetric.AESKey;
15	import com.hurlant.crypto.symmetric.NullPad;
16	
17	public class CFB8ModeTest extends TestCase
18	{
19		public function CFB8ModeTest(h:ITestHarness) {
20			super(h,"CBF8Mode Test");
21			runTest(testCFB8_AES128, "CFB-8 AES-128 Test Vectors");
22			runTest(testCFB8_AES192, "CFB-8 AES-192 Test Vectors");
23			runTest(testCFB8_AES256, "CFB-8 AES-192 Test Vectors");
24			h.endTestCase();
25		}
26		
27		/**
28		 * http://csrc.nist.gov/publications/nistpubs/800-38a/sp800-38a.pdf
29		 */
30		public function testCFB8_AES128():void {
31			var key:ByteArray = Hex.toArray("2b7e151628aed2a6abf7158809cf4f3c");
32			var pt:ByteArray = Hex.toArray("6bc1bee22e409f96e93d7e117393172aae2d");
33			var ct:ByteArray = Hex.toArray("3b79424c9c0dd436bace9e0ed4586a4f32b9");
34			var cfb8:CFB8Mode = new CFB8Mode(new AESKey(key), new NullPad);
35			cfb8.IV = Hex.toArray("000102030405060708090a0b0c0d0e0f");
36			var src:ByteArray = new ByteArray;
37			src.writeBytes(pt);
38			cfb8.encrypt(src);
39			assert("CFB8_AES128 test 1", Hex.fromArray(src)==Hex.fromArray(ct));
40			cfb8.decrypt(src);
41			assert("CFB8_AES128 test 2", Hex.fromArray(src)==Hex.fromArray(pt));
42		}
43		public function testCFB8_AES192():void {
44			var key:ByteArray = Hex.toArray("8e73b0f7da0e6452c810f32b809079e562f8ead2522c6b7b");
45			var pt:ByteArray = Hex.toArray("6bc1bee22e409f96e93d7e117393172aae2d");
46			var ct:ByteArray = Hex.toArray("cda2521ef0a905ca44cd057cbf0d47a0678a");
47			var cfb8:CFB8Mode = new CFB8Mode(new AESKey(key), new NullPad);
48			cfb8.IV = Hex.toArray("000102030405060708090a0b0c0d0e0f");
49			var src:ByteArray = new ByteArray;
50			src.writeBytes(pt);
51			cfb8.encrypt(src);
52			assert("CFB8_AES128 test 1", Hex.fromArray(src)==Hex.fromArray(ct));
53			cfb8.decrypt(src);
54			assert("CFB8_AES128 test 2", Hex.fromArray(src)==Hex.fromArray(pt));
55		}
56		public function testCFB8_AES256():void {
57			var key:ByteArray = Hex.toArray("603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4");
58			var pt:ByteArray = Hex.toArray("6bc1bee22e409f96e93d7e117393172aae2d");
59			var ct:ByteArray = Hex.toArray("dc1f1a8520a64db55fcc8ac554844e889700");
60			var cfb8:CFB8Mode = new CFB8Mode(new AESKey(key), new NullPad);
61			cfb8.IV = Hex.toArray("000102030405060708090a0b0c0d0e0f");
62			var src:ByteArray = new ByteArray;
63			src.writeBytes(pt);
64			cfb8.encrypt(src);
65			assert("CFB8_AES128 test 1", Hex.fromArray(src)==Hex.fromArray(ct));
66			cfb8.decrypt(src);
67			assert("CFB8_AES128 test 2", Hex.fromArray(src)==Hex.fromArray(pt));
68		}
69		
70	}
71}