PageRenderTime 444ms CodeModel.GetById 202ms app.highlight 3ms RepoModel.GetById 238ms app.codeStats 0ms

/flash-src/third-party/com/hurlant/crypto/tests/TLSPRFTest.as

http://github.com/gimite/web-socket-js
ActionScript | 51 lines | 37 code | 2 blank | 12 comment | 2 complexity | 11d46257841ad2efad072a643ebcd592 MD5 | raw file
 1/**
 2 * TLSPRFTest
 3 * 
 4 * A test class for TLFPRF
 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.crypto.prng.TLSPRF;
13	import com.hurlant.util.Hex;
14	
15	public class TLSPRFTest extends TestCase
16	{
17		public function TLSPRFTest(h:ITestHarness) {
18			super(h, "TLS-PRF Testing");
19			runTest(testVector, "TLF-PRF Test Vector");
20			h.endTestCase()
21		}
22		
23		/**
24		 * Test Vector as defined in
25		 * http://www.imc.org/ietf-tls/mail-archive/msg01589.html
26		 */
27		private function testVector():void {
28			var secret:ByteArray = new ByteArray;
29			for (var i:uint=0;i<48;i++) {
30				secret[i]= 0xab;
31			}
32			var label:String = "PRF Testvector";
33			var seed:ByteArray = new ByteArray;
34			for (i=0;i<64;i++) {
35				seed[i] = 0xcd;
36			}
37			var prf:TLSPRF = new TLSPRF(secret, label, seed);
38			var out:ByteArray = new ByteArray;
39			prf.nextBytes(out, 104);
40			var expected:String = "D3 D4 D1 E3 49 B5 D5 15 04 46 66 D5 1D E3 2B AB" + 
41					"25 8C B5 21 B6 B0 53 46 3E 35 48 32 FD 97 67 54" + 
42					"44 3B CF 9A 29 65 19 BC 28 9A BC BC 11 87 E4 EB" + 
43					"D3 1E 60 23 53 77 6C 40 8A AF B7 4C BC 85 EF F6" + 
44					"92 55 F9 78 8F AA 18 4C BB 95 7A 98 19 D8 4A 5D" + 
45					"7E B0 06 EB 45 9D 3A E8 DE 98 10 45 4B 8B 2D 8F" + 
46					"1A FB C6 55 A8 C9 A0 13";
47			var expect:String = Hex.fromArray(Hex.toArray(expected));
48			assert("out == expected", Hex.fromArray(out)==expect);
49		}
50	}
51}