~ubuntu-branches/ubuntu/vivid/emscripten/vivid-proposed

« back to all changes in this revision

Viewing changes to third_party/websockify/include/web-socket-js/src/flash-src/third-party/com/hurlant/crypto/tests/XTeaKeyTest.as

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2014-01-19 14:12:40 UTC
  • mfrom: (4.1.2 sid)
  • Revision ID: package-import@ubuntu.com-20140119141240-nfiw0p8033oitpfz
Tags: 1.9.0~20140119~7dc8c2f-1
* New snapshot release (Closes: #733714)
* Provide sources for javascript and flash. Done in orig-tar.sh
  Available in third_party/websockify/include/web-socket-js/src/
  (Closes: #735903)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * XTeaKeyTest
 
3
 * 
 
4
 * A test class for XTeaKey
 
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.prng.Random;
 
12
        import com.hurlant.crypto.symmetric.ECBMode;
 
13
        import com.hurlant.crypto.symmetric.XTeaKey;
 
14
        import com.hurlant.util.Hex;
 
15
        
 
16
        import flash.utils.ByteArray;
 
17
        import flash.utils.getTimer;
 
18
        
 
19
        public class XTeaKeyTest extends TestCase
 
20
        {
 
21
                public function XTeaKeyTest(h:ITestHarness) {
 
22
                        super(h, "XTeaKey Test");
 
23
                        runTest(testGetBlockSize, "XTea Block Size");
 
24
                        runTest(testVectors, "XTea Test Vectors");
 
25
                        
 
26
                        h.endTestCase();
 
27
                }
 
28
                
 
29
                public function testGetBlockSize():void {
 
30
                        var tea:XTeaKey = new XTeaKey(Hex.toArray("deadbabecafebeefdeadbabecafebeef"));
 
31
                        assert("tea blocksize", tea.getBlockSize()==8);
 
32
                }
 
33
                
 
34
                public function testVectors():void {
 
35
                        // blah.
 
36
                        // can't find working test vectors.
 
37
                        // algorithms should not get published without vectors :(
 
38
                        var keys:Array=[
 
39
                        "00000000000000000000000000000000",
 
40
                        "2b02056806144976775d0e266c287843"];
 
41
                        var pts:Array=[
 
42
                        "0000000000000000",
 
43
                        "74657374206d652e"];
 
44
                        var cts:Array=[
 
45
                        "2dc7e8d3695b0538",
 
46
                        "7909582138198783"];
 
47
                        // self-fullfilling vectors.
 
48
                        // oh well, at least I can decrypt what I produce. :(
 
49
                        
 
50
                        for (var i:uint=0;i<keys.length;i++) {
 
51
                                var key:ByteArray = Hex.toArray(keys[i]);
 
52
                                var pt:ByteArray = Hex.toArray(pts[i]);
 
53
                                var tea:XTeaKey = new XTeaKey(key);
 
54
                                tea.encrypt(pt);
 
55
                                var out:String = Hex.fromArray(pt);
 
56
                                assert("comparing "+cts[i]+" to "+out, cts[i]==out);
 
57
                                // now go back to plaintext.
 
58
                                pt.position=0;
 
59
                                tea.decrypt(pt);
 
60
                                out = Hex.fromArray(pt);
 
61
                                assert("comparing "+pts[i]+" to "+out, pts[i]==out);
 
62
                        }
 
63
                }
 
64
 
 
65
        }
 
66
}
 
 
b'\\ No newline at end of file'