~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/symmetric/CBCMode.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
 * CBCMode
 
3
 * 
 
4
 * An ActionScript 3 implementation of the CBC confidentiality mode
 
5
 * Copyright (c) 2007 Henri Torgemane
 
6
 * 
 
7
 * See LICENSE.txt for full license information.
 
8
 */
 
9
package com.hurlant.crypto.symmetric
 
10
{
 
11
        import flash.utils.ByteArray;
 
12
        
 
13
        /**
 
14
         * CBC confidentiality mode. why not.
 
15
         */
 
16
        public class CBCMode extends IVMode implements IMode
 
17
        {
 
18
                
 
19
                public function CBCMode(key:ISymmetricKey, padding:IPad = null) {
 
20
                        super(key, padding);
 
21
                }
 
22
 
 
23
                public function encrypt(src:ByteArray):void {
 
24
                        padding.pad(src);
 
25
                        var vector:ByteArray = getIV4e();
 
26
                        for (var i:uint=0;i<src.length;i+=blockSize) {
 
27
                                for (var j:uint=0;j<blockSize;j++) {
 
28
                                        src[i+j] ^= vector[j];
 
29
                                }
 
30
                                key.encrypt(src, i);
 
31
                                vector.position=0;
 
32
                                vector.writeBytes(src, i, blockSize);
 
33
                        }
 
34
                }
 
35
                public function decrypt(src:ByteArray):void {
 
36
                        var vector:ByteArray = getIV4d();
 
37
                        var tmp:ByteArray = new ByteArray;
 
38
                        for (var i:uint=0;i<src.length;i+=blockSize) {
 
39
                                tmp.position=0;
 
40
                                tmp.writeBytes(src, i, blockSize);
 
41
                                key.decrypt(src, i);
 
42
                                for (var j:uint=0;j<blockSize;j++) {
 
43
                                        src[i+j] ^= vector[j];
 
44
                                }
 
45
                                vector.position=0;
 
46
                                vector.writeBytes(tmp, 0, blockSize);
 
47
                        }
 
48
                        padding.unpad(src);
 
49
                }
 
50
                
 
51
                public function toString():String {
 
52
                        return key.toString()+"-cbc";
 
53
                }
 
54
        }
 
55
}