diff --git a/app/app.js b/app/app.js index 30881ca..3d16806 100644 --- a/app/app.js +++ b/app/app.js @@ -4,6 +4,8 @@ */ var fs = require('fs'); var path = require('path'); +var mongo = require('mongodb'); +var BSON = mongo.BSONPure; var db = require('mongoskin').db('localhost:27017/test'); var testcollection = db.collection('testcollection'); var exercisecollection = db.collection('exercisecollection'); @@ -106,6 +108,33 @@ io.sockets.on('connection', function(socket) { socket.emit('populateexercises', result); }); }); + socket.on('updateexercises', function(data) { + console.log('updateexecises' + JSON.stringify(data)) + if (data[0]._id == 'undefined') { + delete data[0]._id + console.log('edited updateexecises' + JSON.stringify(data)) + exercisecollection.insert(data, function(err, result) { + if (err) throw err; + exercisecollection.find().toArray(function(err, result) { + if (err) throw err; + socket.emit('populateexercises', result); + }); + }); + } + else { + var document_id = new BSON.ObjectID(data[0]._id); + delete data[0]._id; + exercisecollection.update({_id:document_id}, data[0],{upsert:true} , function(err, result) { + if (err) throw err; + exercisecollection.find().toArray(function(err, result) { + if (err) throw err; + console.log('populateexercises'); + socket.emit('populateexercises', result); + }); + }); + + }; + }); //////////////// socket.on('getexpresso', function(data) { console.log('emit expresso') diff --git a/app/index.html b/app/index.html index 3f35df4..d9df8f5 100644 --- a/app/index.html +++ b/app/index.html @@ -56,17 +56,23 @@ }); ////populate exercise sortable -// socket.on('populateexercises', function(json) { - // console.log('#exercises recieved'); - /// var content = ""; - // $(".workoutdata").hide(); - // $('#ActivityList').empty(); + socket.on('populateexercises', function(json) { + console.log('#exercises recieved' + JSON.stringify(json, null, ' ')); + var content = ""; + $('ul#sortableexercises li').remove(); + $( "ul#sortableexercises" ).append('
  • ') ///// for loop - //create html with cvaraible $( "#sortableexercises" ).html("
  • " + exercise+"
  • ") - //append to sortable + var array = json[0].exercise.name; + console.log('#exercises recieved' + array ); + $.each(array, function(index, value) { + console.log('beep' + value ); + console.log('index-' + index); + console.log('value-' + value); + $( "ul#sortableexercises" ).append('
  • ') + }); //end for //create sortable - // ); +}); $( "#tabs" ).tabs(); @@ -99,11 +105,10 @@ $( "#datepicker" ).datepicker(); - $('#ActivityList').delegate('a.activitydelete', 'click', function() { - console.log('delete clicked' + $(this).attr('title')); - socket.emit('delactivity', $(this).attr('title')); - return false; - }); +$('#ActivityList').delegate('a.activitydelete', 'click', function() { + socket.emit('delactivity', $(this).attr('title')); + return false; +}); @@ -125,14 +130,17 @@ $("#sortable").bind('sortupdate', function(event, ui) { $(this).attr("name",newname); }); }); +}); - - -}); + $("#sortableexercises").sortable({ + placeholder: "ui-state-highlight", + revert: true, +}); + //Removes slectable element $('ul').on('click', '.delete',function() { - $(this).parent().remove(); + $(this).closest('li').remove(); $('#sortable').trigger('sortupdate') }); @@ -144,7 +152,7 @@ $("button").button(); $("button").click(function() { var addtype = $(this).attr('value'); console.log('click'); - var newElem = $('.new-' + addtype).clone().attr('style', 'display: block'); + var newElem = $('.new-' + addtype).clone(true).attr('style', 'display: block'); $(newElem).removeClass("new-" + addtype); $(newElem).children('input').attr('disabled',false); $(newElem).appendTo('#sortable'); @@ -152,6 +160,10 @@ $("button").click(function() { $('#sortable').trigger('sortupdate'); }); +$("button.AddExercise").click(function() { +$( "ul#sortableexercises" ).append('
  • ') +}); + $('#Activity').find('input.datepicker').datepicker(); $('#Activity').find('input.datepicker').datepicker('setDate', new Date()); @@ -172,6 +184,20 @@ $("button").click(function() { $('#Activity').find('input.datepicker').datepicker('setDate', new Date()); return false; }); + + $('#saveexercises').click(function() { + var selector= "#ExerciseForm" + //var formDataFirst = $(selector).toObject({mode: 'first'}); + var formDataAll = $(selector).toObject({mode: 'all'}); + socket.emit('updateexercises', formDataAll); + + console.log('All ', JSON.stringify(formDataAll, null, ' ')); + // to prevent the page from changing + $('ul#sortableexercises li').remove(); + return false; + }); + + $('#cancelform').click(function() { @@ -185,6 +211,28 @@ $("button").click(function() { }); +$('ul').on('change', '.laptype',function() { + console.log ('value= ' + $(this).val() ); + switch($(this).val()) { + case "Run": + $(this).siblings('span').html('delete'); + break; + case "Bike": + $(this).siblings('span').html(' delete'); + break; + case "Cardio": + $(this).siblings('span').html('delete'); + break; + case "Exercise": + $(this).siblings('span').html(' delete'); + break; + case "Rest": + $(this).siblings('span').html('delete'); + break; + }; + + }); + }); @@ -196,37 +244,19 @@ $("button").click(function() {
    @@ -239,11 +269,7 @@ $("button").click(function() {
    - - - - - +
    • @@ -256,10 +282,15 @@ $("button").click(function() {
    + CODE FOR EDITING EXERCISES +
    + + +
    @@ -278,4 +309,4 @@ $("button").click(function() {
    - \ No newline at end of file + diff --git a/app/node_modules/formidable/package.json b/app/node_modules/formidable/package.json index c8f8f01..bb9830b 100644 --- a/app/node_modules/formidable/package.json +++ b/app/node_modules/formidable/package.json @@ -22,8 +22,11 @@ "optionalDependencies": {}, "_id": "formidable@1.0.11", "_engineSupported": true, - "_npmVersion": "1.1.21", - "_nodeVersion": "v0.6.18", + "_npmVersion": "1.1.19", + "_nodeVersion": "v0.6.17", "_defaultsLoaded": true, - "_from": "formidable" + "dist": { + "shasum": "92adc356117d0d9954d53a99f1b84985997beba9" + }, + "_from": "formidable@>= 0.0.1" } diff --git a/app/node_modules/formidable/test/run.js b/app/node_modules/formidable/test/run.js old mode 100644 new mode 100755 diff --git a/app/node_modules/mongoskin/node_modules/mongodb/index.js b/app/node_modules/mongoskin/node_modules/mongodb/index.js old mode 100644 new mode 100755 diff --git a/app/node_modules/mongoskin/node_modules/mongodb/node_modules/bson/package.json b/app/node_modules/mongoskin/node_modules/mongodb/node_modules/bson/package.json old mode 100644 new mode 100755 index f444287..72fa87f --- a/app/node_modules/mongoskin/node_modules/mongodb/node_modules/bson/package.json +++ b/app/node_modules/mongoskin/node_modules/mongodb/node_modules/bson/package.json @@ -48,8 +48,11 @@ "dependencies": {}, "optionalDependencies": {}, "_engineSupported": true, - "_npmVersion": "1.1.21", - "_nodeVersion": "v0.6.18", + "_npmVersion": "1.1.19", + "_nodeVersion": "v0.6.17", "_defaultsLoaded": true, + "dist": { + "shasum": "999307987eef076e4513fa5c661fe19bad897c54" + }, "_from": "bson@0.0.6" } diff --git a/app/node_modules/mongoskin/node_modules/mongodb/package.json b/app/node_modules/mongoskin/node_modules/mongodb/package.json old mode 100644 new mode 100755 index 4f44137..97c6c1e --- a/app/node_modules/mongoskin/node_modules/mongodb/package.json +++ b/app/node_modules/mongoskin/node_modules/mongodb/package.json @@ -204,8 +204,8 @@ "_id": "mongodb@1.0.2", "optionalDependencies": {}, "_engineSupported": true, - "_npmVersion": "1.1.21", - "_nodeVersion": "v0.6.18", + "_npmVersion": "1.1.19", + "_nodeVersion": "v0.6.17", "_defaultsLoaded": true, "_from": "mongodb@1.0.x" } diff --git a/app/node_modules/mongoskin/package.json b/app/node_modules/mongoskin/package.json index 7b01938..673ee78 100644 --- a/app/node_modules/mongoskin/package.json +++ b/app/node_modules/mongoskin/package.json @@ -31,8 +31,8 @@ "_id": "mongoskin@0.3.6", "optionalDependencies": {}, "_engineSupported": true, - "_npmVersion": "1.1.21", - "_nodeVersion": "v0.6.18", + "_npmVersion": "1.1.19", + "_nodeVersion": "v0.6.17", "_defaultsLoaded": true, "_from": "mongoskin@>= 0.0.1" } diff --git a/app/node_modules/socket.io/node_modules/policyfile/package.json b/app/node_modules/socket.io/node_modules/policyfile/package.json index d341100..b6e2019 100644 --- a/app/node_modules/socket.io/node_modules/policyfile/package.json +++ b/app/node_modules/socket.io/node_modules/policyfile/package.json @@ -45,8 +45,11 @@ "node": "*" }, "_engineSupported": true, - "_npmVersion": "1.1.21", - "_nodeVersion": "v0.6.18", + "_npmVersion": "1.1.19", + "_nodeVersion": "v0.6.17", "_defaultsLoaded": true, + "dist": { + "shasum": "a1b994eb7a760beadecf3b57f1d693902c92e5a8" + }, "_from": "policyfile@0.0.4" } diff --git a/app/node_modules/socket.io/node_modules/redis/package.json b/app/node_modules/socket.io/node_modules/redis/package.json index 6ee834b..63c1c9e 100644 --- a/app/node_modules/socket.io/node_modules/redis/package.json +++ b/app/node_modules/socket.io/node_modules/redis/package.json @@ -57,8 +57,11 @@ "node": "*" }, "_engineSupported": true, - "_npmVersion": "1.1.21", - "_nodeVersion": "v0.6.18", + "_npmVersion": "1.1.19", + "_nodeVersion": "v0.6.17", "_defaultsLoaded": true, + "dist": { + "shasum": "f583ce9d7991094cc7ccb1618bec1533d009841a" + }, "_from": "redis@0.6.7" } diff --git a/app/node_modules/socket.io/node_modules/redis/tests/stress/pubsub/run b/app/node_modules/socket.io/node_modules/redis/tests/stress/pubsub/run old mode 100644 new mode 100755 diff --git a/app/node_modules/socket.io/node_modules/redis/tests/stress/rpushblpop/run b/app/node_modules/socket.io/node_modules/redis/tests/stress/rpushblpop/run old mode 100644 new mode 100755 diff --git a/app/node_modules/socket.io/node_modules/redis/tests/stress/speed/plot b/app/node_modules/socket.io/node_modules/redis/tests/stress/speed/plot old mode 100644 new mode 100755 diff --git a/app/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/build.sh b/app/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/build.sh old mode 100644 new mode 100755 diff --git a/app/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/gsolo/encryption/MD5.as b/app/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/gsolo/encryption/MD5.as index 9a7824d..e5d9c4a 100644 --- a/app/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/gsolo/encryption/MD5.as +++ b/app/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/gsolo/encryption/MD5.as @@ -1,375 +1,375 @@ -package com.gsolo.encryption { - public class MD5 { - /* - * A JavaScript implementation of the RSA Data Security, Inc. MD5 Message - * Digest Algorithm, as defined in RFC 1321. - * Version 2.2-alpha Copyright (C) Paul Johnston 1999 - 2005 - * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet - * Distributed under the BSD License - * See http://pajhome.org.uk/crypt/md5 for more info. - * - * Converted to AS3 By Geoffrey Williams - */ - - /* - * Configurable variables. You may need to tweak these to be compatible with - * the server-side, but the defaults work in most cases. - */ - - public static const HEX_FORMAT_LOWERCASE:uint = 0; - public static const HEX_FORMAT_UPPERCASE:uint = 1; - - public static const BASE64_PAD_CHARACTER_DEFAULT_COMPLIANCE:String = ""; - public static const BASE64_PAD_CHARACTER_RFC_COMPLIANCE:String = "="; - - public static var hexcase:uint = 0; /* hex output format. 0 - lowercase; 1 - uppercase */ - public static var b64pad:String = ""; /* base-64 pad character. "=" for strict RFC compliance */ - - public static function encrypt (string:String):String { - return hex_md5 (string); - } - - /* - * These are the functions you'll usually want to call - * They take string arguments and return either hex or base-64 encoded strings - */ - public static function hex_md5 (string:String):String { - return rstr2hex (rstr_md5 (str2rstr_utf8 (string))); - } - - public static function b64_md5 (string:String):String { - return rstr2b64 (rstr_md5 (str2rstr_utf8 (string))); - } - - public static function any_md5 (string:String, encoding:String):String { - return rstr2any (rstr_md5 (str2rstr_utf8 (string)), encoding); - } - public static function hex_hmac_md5 (key:String, data:String):String { - return rstr2hex (rstr_hmac_md5 (str2rstr_utf8 (key), str2rstr_utf8 (data))); - } - public static function b64_hmac_md5 (key:String, data:String):String { - return rstr2b64 (rstr_hmac_md5 (str2rstr_utf8 (key), str2rstr_utf8 (data))); - } - public static function any_hmac_md5 (key:String, data:String, encoding:String):String { - return rstr2any(rstr_hmac_md5(str2rstr_utf8(key), str2rstr_utf8(data)), encoding); - } - - /* - * Perform a simple self-test to see if the VM is working - */ - public static function md5_vm_test ():Boolean { - return hex_md5 ("abc") == "900150983cd24fb0d6963f7d28e17f72"; - } - - /* - * Calculate the MD5 of a raw string - */ - public static function rstr_md5 (string:String):String { - return binl2rstr (binl_md5 (rstr2binl (string), string.length * 8)); - } - - /* - * Calculate the HMAC-MD5, of a key and some data (raw strings) - */ - public static function rstr_hmac_md5 (key:String, data:String):String { - var bkey:Array = rstr2binl (key); - if (bkey.length > 16) bkey = binl_md5 (bkey, key.length * 8); - - var ipad:Array = new Array(16), opad:Array = new Array(16); - for(var i:Number = 0; i < 16; i++) { - ipad[i] = bkey[i] ^ 0x36363636; - opad[i] = bkey[i] ^ 0x5C5C5C5C; - } - - var hash:Array = binl_md5 (ipad.concat (rstr2binl (data)), 512 + data.length * 8); - return binl2rstr (binl_md5 (opad.concat (hash), 512 + 128)); - } - - /* - * Convert a raw string to a hex string - */ - public static function rstr2hex (input:String):String { - var hex_tab:String = hexcase ? "0123456789ABCDEF" : "0123456789abcdef"; - var output:String = ""; - var x:Number; - for(var i:Number = 0; i < input.length; i++) { - x = input.charCodeAt(i); - output += hex_tab.charAt((x >>> 4) & 0x0F) - + hex_tab.charAt( x & 0x0F); - } - return output; - } - - /* - * Convert a raw string to a base-64 string - */ - public static function rstr2b64 (input:String):String { - var tab:String = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; - var output:String = ""; - var len:Number = input.length; - for(var i:Number = 0; i < len; i += 3) { - var triplet:Number = (input.charCodeAt(i) << 16) - | (i + 1 < len ? input.charCodeAt(i+1) << 8 : 0) - | (i + 2 < len ? input.charCodeAt(i+2) : 0); - for(var j:Number = 0; j < 4; j++) { - if(i * 8 + j * 6 > input.length * 8) output += b64pad; - else output += tab.charAt((triplet >>> 6*(3-j)) & 0x3F); - } - } - return output; - } - - /* - * Convert a raw string to an arbitrary string encoding - */ - public static function rstr2any(input:String, encoding:String):String { - var divisor:Number = encoding.length; - var remainders:Array = []; - var i:Number, q:Number, x:Number, quotient:Array; - - /* Convert to an array of 16-bit big-endian values, forming the dividend */ - var dividend:Array = new Array(input.length / 2); - for(i = 0; i < dividend.length; i++) { - dividend[i] = (input.charCodeAt(i * 2) << 8) | input.charCodeAt(i * 2 + 1); - } - - /* - * Repeatedly perform a long division. The binary array forms the dividend, - * the length of the encoding is the divisor. Once computed, the quotient - * forms the dividend for the next step. We stop when the dividend is zero. - * All remainders are stored for later use. - */ - while(dividend.length > 0) { - quotient = []; - x = 0; - for(i = 0; i < dividend.length; i++) { - x = (x << 16) + dividend[i]; - q = Math.floor(x / divisor); - x -= q * divisor; - if(quotient.length > 0 || q > 0) - quotient[quotient.length] = q; - } - remainders[remainders.length] = x; - dividend = quotient; - } - - /* Convert the remainders to the output string */ - var output:String = ""; - for(i = remainders.length - 1; i >= 0; i--) - output += encoding.charAt (remainders[i]); - - return output; - } - - /* - * Encode a string as utf-8. - * For efficiency, this assumes the input is valid utf-16. - */ - public static function str2rstr_utf8 (input:String):String { - var output:String = ""; - var i:Number = -1; - var x:Number, y:Number; - - while(++i < input.length) { - /* Decode utf-16 surrogate pairs */ - x = input.charCodeAt(i); - y = i + 1 < input.length ? input.charCodeAt(i + 1) : 0; - if(0xD800 <= x && x <= 0xDBFF && 0xDC00 <= y && y <= 0xDFFF) { - x = 0x10000 + ((x & 0x03FF) << 10) + (y & 0x03FF); - i++; - } - - /* Encode output as utf-8 */ - if(x <= 0x7F) - output += String.fromCharCode(x); - else if(x <= 0x7FF) - output += String.fromCharCode(0xC0 | ((x >>> 6 ) & 0x1F), - 0x80 | ( x & 0x3F)); - else if(x <= 0xFFFF) - output += String.fromCharCode(0xE0 | ((x >>> 12) & 0x0F), - 0x80 | ((x >>> 6 ) & 0x3F), - 0x80 | ( x & 0x3F)); - else if(x <= 0x1FFFFF) - output += String.fromCharCode(0xF0 | ((x >>> 18) & 0x07), - 0x80 | ((x >>> 12) & 0x3F), - 0x80 | ((x >>> 6 ) & 0x3F), - 0x80 | ( x & 0x3F)); - } - return output; - } - - /* - * Encode a string as utf-16 - */ - public static function str2rstr_utf16le (input:String):String { - var output:String = ""; - for(var i:Number = 0; i < input.length; i++) - output += String.fromCharCode( input.charCodeAt(i) & 0xFF, - (input.charCodeAt(i) >>> 8) & 0xFF); - return output; - } - - public static function str2rstr_utf16be (input:String):String { - var output:String = ""; - for(var i:Number = 0; i < input.length; i++) - output += String.fromCharCode((input.charCodeAt(i) >>> 8) & 0xFF, - input.charCodeAt(i) & 0xFF); - return output; - } - - /* - * Convert a raw string to an array of little-endian words - * Characters >255 have their high-byte silently ignored. - */ - public static function rstr2binl (input:String):Array { - var output:Array = new Array(input.length >> 2); - for(var i:Number = 0; i < output.length; i++) - output[i] = 0; - for(i = 0; i < input.length * 8; i += 8) - output[i>>5] |= (input.charCodeAt(i / 8) & 0xFF) << (i%32); - return output; - } - - /* - * Convert an array of little-endian words to a string - */ - public static function binl2rstr (input:Array):String { - var output:String = ""; - for(var i:Number = 0; i < input.length * 32; i += 8) - output += String.fromCharCode((input[i>>5] >>> (i % 32)) & 0xFF); - return output; - } - - /* - * Calculate the MD5 of an array of little-endian words, and a bit length. - */ - public static function binl_md5 (x:Array, len:Number):Array { - /* append padding */ - x[len >> 5] |= 0x80 << ((len) % 32); - x[(((len + 64) >>> 9) << 4) + 14] = len; - - var a:Number = 1732584193; - var b:Number = -271733879; - var c:Number = -1732584194; - var d:Number = 271733878; - - for(var i:Number = 0; i < x.length; i += 16) { - var olda:Number = a; - var oldb:Number = b; - var oldc:Number = c; - var oldd:Number = d; - - a = md5_ff(a, b, c, d, x[i+ 0], 7 , -680876936); - d = md5_ff(d, a, b, c, x[i+ 1], 12, -389564586); - c = md5_ff(c, d, a, b, x[i+ 2], 17, 606105819); - b = md5_ff(b, c, d, a, x[i+ 3], 22, -1044525330); - a = md5_ff(a, b, c, d, x[i+ 4], 7 , -176418897); - d = md5_ff(d, a, b, c, x[i+ 5], 12, 1200080426); - c = md5_ff(c, d, a, b, x[i+ 6], 17, -1473231341); - b = md5_ff(b, c, d, a, x[i+ 7], 22, -45705983); - a = md5_ff(a, b, c, d, x[i+ 8], 7 , 1770035416); - d = md5_ff(d, a, b, c, x[i+ 9], 12, -1958414417); - c = md5_ff(c, d, a, b, x[i+10], 17, -42063); - b = md5_ff(b, c, d, a, x[i+11], 22, -1990404162); - a = md5_ff(a, b, c, d, x[i+12], 7 , 1804603682); - d = md5_ff(d, a, b, c, x[i+13], 12, -40341101); - c = md5_ff(c, d, a, b, x[i+14], 17, -1502002290); - b = md5_ff(b, c, d, a, x[i+15], 22, 1236535329); - - a = md5_gg(a, b, c, d, x[i+ 1], 5 , -165796510); - d = md5_gg(d, a, b, c, x[i+ 6], 9 , -1069501632); - c = md5_gg(c, d, a, b, x[i+11], 14, 643717713); - b = md5_gg(b, c, d, a, x[i+ 0], 20, -373897302); - a = md5_gg(a, b, c, d, x[i+ 5], 5 , -701558691); - d = md5_gg(d, a, b, c, x[i+10], 9 , 38016083); - c = md5_gg(c, d, a, b, x[i+15], 14, -660478335); - b = md5_gg(b, c, d, a, x[i+ 4], 20, -405537848); - a = md5_gg(a, b, c, d, x[i+ 9], 5 , 568446438); - d = md5_gg(d, a, b, c, x[i+14], 9 , -1019803690); - c = md5_gg(c, d, a, b, x[i+ 3], 14, -187363961); - b = md5_gg(b, c, d, a, x[i+ 8], 20, 1163531501); - a = md5_gg(a, b, c, d, x[i+13], 5 , -1444681467); - d = md5_gg(d, a, b, c, x[i+ 2], 9 , -51403784); - c = md5_gg(c, d, a, b, x[i+ 7], 14, 1735328473); - b = md5_gg(b, c, d, a, x[i+12], 20, -1926607734); - - a = md5_hh(a, b, c, d, x[i+ 5], 4 , -378558); - d = md5_hh(d, a, b, c, x[i+ 8], 11, -2022574463); - c = md5_hh(c, d, a, b, x[i+11], 16, 1839030562); - b = md5_hh(b, c, d, a, x[i+14], 23, -35309556); - a = md5_hh(a, b, c, d, x[i+ 1], 4 , -1530992060); - d = md5_hh(d, a, b, c, x[i+ 4], 11, 1272893353); - c = md5_hh(c, d, a, b, x[i+ 7], 16, -155497632); - b = md5_hh(b, c, d, a, x[i+10], 23, -1094730640); - a = md5_hh(a, b, c, d, x[i+13], 4 , 681279174); - d = md5_hh(d, a, b, c, x[i+ 0], 11, -358537222); - c = md5_hh(c, d, a, b, x[i+ 3], 16, -722521979); - b = md5_hh(b, c, d, a, x[i+ 6], 23, 76029189); - a = md5_hh(a, b, c, d, x[i+ 9], 4 , -640364487); - d = md5_hh(d, a, b, c, x[i+12], 11, -421815835); - c = md5_hh(c, d, a, b, x[i+15], 16, 530742520); - b = md5_hh(b, c, d, a, x[i+ 2], 23, -995338651); - - a = md5_ii(a, b, c, d, x[i+ 0], 6 , -198630844); - d = md5_ii(d, a, b, c, x[i+ 7], 10, 1126891415); - c = md5_ii(c, d, a, b, x[i+14], 15, -1416354905); - b = md5_ii(b, c, d, a, x[i+ 5], 21, -57434055); - a = md5_ii(a, b, c, d, x[i+12], 6 , 1700485571); - d = md5_ii(d, a, b, c, x[i+ 3], 10, -1894986606); - c = md5_ii(c, d, a, b, x[i+10], 15, -1051523); - b = md5_ii(b, c, d, a, x[i+ 1], 21, -2054922799); - a = md5_ii(a, b, c, d, x[i+ 8], 6 , 1873313359); - d = md5_ii(d, a, b, c, x[i+15], 10, -30611744); - c = md5_ii(c, d, a, b, x[i+ 6], 15, -1560198380); - b = md5_ii(b, c, d, a, x[i+13], 21, 1309151649); - a = md5_ii(a, b, c, d, x[i+ 4], 6 , -145523070); - d = md5_ii(d, a, b, c, x[i+11], 10, -1120210379); - c = md5_ii(c, d, a, b, x[i+ 2], 15, 718787259); - b = md5_ii(b, c, d, a, x[i+ 9], 21, -343485551); - - a = safe_add(a, olda); - b = safe_add(b, oldb); - c = safe_add(c, oldc); - d = safe_add(d, oldd); - } - return [a, b, c, d]; - } - - /* - * These functions implement the four basic operations the algorithm uses. - */ - public static function md5_cmn (q:Number, a:Number, b:Number, x:Number, s:Number, t:Number):Number { - return safe_add (bit_rol (safe_add (safe_add (a, q), safe_add(x, t)), s), b); - } - public static function md5_ff (a:Number, b:Number, c:Number, d:Number, x:Number, s:Number, t:Number):Number { - return md5_cmn ((b & c) | ((~b) & d), a, b, x, s, t); - } - public static function md5_gg (a:Number, b:Number, c:Number, d:Number, x:Number, s:Number, t:Number):Number { - return md5_cmn ((b & d) | (c & (~d)), a, b, x, s, t); - } - public static function md5_hh (a:Number, b:Number, c:Number, d:Number, x:Number, s:Number, t:Number):Number { - return md5_cmn (b ^ c ^ d, a, b, x, s, t); - } - public static function md5_ii (a:Number, b:Number, c:Number, d:Number, x:Number, s:Number, t:Number):Number { - return md5_cmn (c ^ (b | (~d)), a, b, x, s, t); - } - - /* - * Add integers, wrapping at 2^32. This uses 16-bit operations internally - * to work around bugs in some JS interpreters. - */ - public static function safe_add (x:Number, y:Number):Number { - var lsw:Number = (x & 0xFFFF) + (y & 0xFFFF); - var msw:Number = (x >> 16) + (y >> 16) + (lsw >> 16); - return (msw << 16) | (lsw & 0xFFFF); - } - - /* - * Bitwise rotate a 32-bit number to the left. - */ - public static function bit_rol (num:Number, cnt:Number):Number { - return (num << cnt) | (num >>> (32 - cnt)); - } - - } -} +package com.gsolo.encryption { + public class MD5 { + /* + * A JavaScript implementation of the RSA Data Security, Inc. MD5 Message + * Digest Algorithm, as defined in RFC 1321. + * Version 2.2-alpha Copyright (C) Paul Johnston 1999 - 2005 + * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet + * Distributed under the BSD License + * See http://pajhome.org.uk/crypt/md5 for more info. + * + * Converted to AS3 By Geoffrey Williams + */ + + /* + * Configurable variables. You may need to tweak these to be compatible with + * the server-side, but the defaults work in most cases. + */ + + public static const HEX_FORMAT_LOWERCASE:uint = 0; + public static const HEX_FORMAT_UPPERCASE:uint = 1; + + public static const BASE64_PAD_CHARACTER_DEFAULT_COMPLIANCE:String = ""; + public static const BASE64_PAD_CHARACTER_RFC_COMPLIANCE:String = "="; + + public static var hexcase:uint = 0; /* hex output format. 0 - lowercase; 1 - uppercase */ + public static var b64pad:String = ""; /* base-64 pad character. "=" for strict RFC compliance */ + + public static function encrypt (string:String):String { + return hex_md5 (string); + } + + /* + * These are the functions you'll usually want to call + * They take string arguments and return either hex or base-64 encoded strings + */ + public static function hex_md5 (string:String):String { + return rstr2hex (rstr_md5 (str2rstr_utf8 (string))); + } + + public static function b64_md5 (string:String):String { + return rstr2b64 (rstr_md5 (str2rstr_utf8 (string))); + } + + public static function any_md5 (string:String, encoding:String):String { + return rstr2any (rstr_md5 (str2rstr_utf8 (string)), encoding); + } + public static function hex_hmac_md5 (key:String, data:String):String { + return rstr2hex (rstr_hmac_md5 (str2rstr_utf8 (key), str2rstr_utf8 (data))); + } + public static function b64_hmac_md5 (key:String, data:String):String { + return rstr2b64 (rstr_hmac_md5 (str2rstr_utf8 (key), str2rstr_utf8 (data))); + } + public static function any_hmac_md5 (key:String, data:String, encoding:String):String { + return rstr2any(rstr_hmac_md5(str2rstr_utf8(key), str2rstr_utf8(data)), encoding); + } + + /* + * Perform a simple self-test to see if the VM is working + */ + public static function md5_vm_test ():Boolean { + return hex_md5 ("abc") == "900150983cd24fb0d6963f7d28e17f72"; + } + + /* + * Calculate the MD5 of a raw string + */ + public static function rstr_md5 (string:String):String { + return binl2rstr (binl_md5 (rstr2binl (string), string.length * 8)); + } + + /* + * Calculate the HMAC-MD5, of a key and some data (raw strings) + */ + public static function rstr_hmac_md5 (key:String, data:String):String { + var bkey:Array = rstr2binl (key); + if (bkey.length > 16) bkey = binl_md5 (bkey, key.length * 8); + + var ipad:Array = new Array(16), opad:Array = new Array(16); + for(var i:Number = 0; i < 16; i++) { + ipad[i] = bkey[i] ^ 0x36363636; + opad[i] = bkey[i] ^ 0x5C5C5C5C; + } + + var hash:Array = binl_md5 (ipad.concat (rstr2binl (data)), 512 + data.length * 8); + return binl2rstr (binl_md5 (opad.concat (hash), 512 + 128)); + } + + /* + * Convert a raw string to a hex string + */ + public static function rstr2hex (input:String):String { + var hex_tab:String = hexcase ? "0123456789ABCDEF" : "0123456789abcdef"; + var output:String = ""; + var x:Number; + for(var i:Number = 0; i < input.length; i++) { + x = input.charCodeAt(i); + output += hex_tab.charAt((x >>> 4) & 0x0F) + + hex_tab.charAt( x & 0x0F); + } + return output; + } + + /* + * Convert a raw string to a base-64 string + */ + public static function rstr2b64 (input:String):String { + var tab:String = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; + var output:String = ""; + var len:Number = input.length; + for(var i:Number = 0; i < len; i += 3) { + var triplet:Number = (input.charCodeAt(i) << 16) + | (i + 1 < len ? input.charCodeAt(i+1) << 8 : 0) + | (i + 2 < len ? input.charCodeAt(i+2) : 0); + for(var j:Number = 0; j < 4; j++) { + if(i * 8 + j * 6 > input.length * 8) output += b64pad; + else output += tab.charAt((triplet >>> 6*(3-j)) & 0x3F); + } + } + return output; + } + + /* + * Convert a raw string to an arbitrary string encoding + */ + public static function rstr2any(input:String, encoding:String):String { + var divisor:Number = encoding.length; + var remainders:Array = []; + var i:Number, q:Number, x:Number, quotient:Array; + + /* Convert to an array of 16-bit big-endian values, forming the dividend */ + var dividend:Array = new Array(input.length / 2); + for(i = 0; i < dividend.length; i++) { + dividend[i] = (input.charCodeAt(i * 2) << 8) | input.charCodeAt(i * 2 + 1); + } + + /* + * Repeatedly perform a long division. The binary array forms the dividend, + * the length of the encoding is the divisor. Once computed, the quotient + * forms the dividend for the next step. We stop when the dividend is zero. + * All remainders are stored for later use. + */ + while(dividend.length > 0) { + quotient = []; + x = 0; + for(i = 0; i < dividend.length; i++) { + x = (x << 16) + dividend[i]; + q = Math.floor(x / divisor); + x -= q * divisor; + if(quotient.length > 0 || q > 0) + quotient[quotient.length] = q; + } + remainders[remainders.length] = x; + dividend = quotient; + } + + /* Convert the remainders to the output string */ + var output:String = ""; + for(i = remainders.length - 1; i >= 0; i--) + output += encoding.charAt (remainders[i]); + + return output; + } + + /* + * Encode a string as utf-8. + * For efficiency, this assumes the input is valid utf-16. + */ + public static function str2rstr_utf8 (input:String):String { + var output:String = ""; + var i:Number = -1; + var x:Number, y:Number; + + while(++i < input.length) { + /* Decode utf-16 surrogate pairs */ + x = input.charCodeAt(i); + y = i + 1 < input.length ? input.charCodeAt(i + 1) : 0; + if(0xD800 <= x && x <= 0xDBFF && 0xDC00 <= y && y <= 0xDFFF) { + x = 0x10000 + ((x & 0x03FF) << 10) + (y & 0x03FF); + i++; + } + + /* Encode output as utf-8 */ + if(x <= 0x7F) + output += String.fromCharCode(x); + else if(x <= 0x7FF) + output += String.fromCharCode(0xC0 | ((x >>> 6 ) & 0x1F), + 0x80 | ( x & 0x3F)); + else if(x <= 0xFFFF) + output += String.fromCharCode(0xE0 | ((x >>> 12) & 0x0F), + 0x80 | ((x >>> 6 ) & 0x3F), + 0x80 | ( x & 0x3F)); + else if(x <= 0x1FFFFF) + output += String.fromCharCode(0xF0 | ((x >>> 18) & 0x07), + 0x80 | ((x >>> 12) & 0x3F), + 0x80 | ((x >>> 6 ) & 0x3F), + 0x80 | ( x & 0x3F)); + } + return output; + } + + /* + * Encode a string as utf-16 + */ + public static function str2rstr_utf16le (input:String):String { + var output:String = ""; + for(var i:Number = 0; i < input.length; i++) + output += String.fromCharCode( input.charCodeAt(i) & 0xFF, + (input.charCodeAt(i) >>> 8) & 0xFF); + return output; + } + + public static function str2rstr_utf16be (input:String):String { + var output:String = ""; + for(var i:Number = 0; i < input.length; i++) + output += String.fromCharCode((input.charCodeAt(i) >>> 8) & 0xFF, + input.charCodeAt(i) & 0xFF); + return output; + } + + /* + * Convert a raw string to an array of little-endian words + * Characters >255 have their high-byte silently ignored. + */ + public static function rstr2binl (input:String):Array { + var output:Array = new Array(input.length >> 2); + for(var i:Number = 0; i < output.length; i++) + output[i] = 0; + for(i = 0; i < input.length * 8; i += 8) + output[i>>5] |= (input.charCodeAt(i / 8) & 0xFF) << (i%32); + return output; + } + + /* + * Convert an array of little-endian words to a string + */ + public static function binl2rstr (input:Array):String { + var output:String = ""; + for(var i:Number = 0; i < input.length * 32; i += 8) + output += String.fromCharCode((input[i>>5] >>> (i % 32)) & 0xFF); + return output; + } + + /* + * Calculate the MD5 of an array of little-endian words, and a bit length. + */ + public static function binl_md5 (x:Array, len:Number):Array { + /* append padding */ + x[len >> 5] |= 0x80 << ((len) % 32); + x[(((len + 64) >>> 9) << 4) + 14] = len; + + var a:Number = 1732584193; + var b:Number = -271733879; + var c:Number = -1732584194; + var d:Number = 271733878; + + for(var i:Number = 0; i < x.length; i += 16) { + var olda:Number = a; + var oldb:Number = b; + var oldc:Number = c; + var oldd:Number = d; + + a = md5_ff(a, b, c, d, x[i+ 0], 7 , -680876936); + d = md5_ff(d, a, b, c, x[i+ 1], 12, -389564586); + c = md5_ff(c, d, a, b, x[i+ 2], 17, 606105819); + b = md5_ff(b, c, d, a, x[i+ 3], 22, -1044525330); + a = md5_ff(a, b, c, d, x[i+ 4], 7 , -176418897); + d = md5_ff(d, a, b, c, x[i+ 5], 12, 1200080426); + c = md5_ff(c, d, a, b, x[i+ 6], 17, -1473231341); + b = md5_ff(b, c, d, a, x[i+ 7], 22, -45705983); + a = md5_ff(a, b, c, d, x[i+ 8], 7 , 1770035416); + d = md5_ff(d, a, b, c, x[i+ 9], 12, -1958414417); + c = md5_ff(c, d, a, b, x[i+10], 17, -42063); + b = md5_ff(b, c, d, a, x[i+11], 22, -1990404162); + a = md5_ff(a, b, c, d, x[i+12], 7 , 1804603682); + d = md5_ff(d, a, b, c, x[i+13], 12, -40341101); + c = md5_ff(c, d, a, b, x[i+14], 17, -1502002290); + b = md5_ff(b, c, d, a, x[i+15], 22, 1236535329); + + a = md5_gg(a, b, c, d, x[i+ 1], 5 , -165796510); + d = md5_gg(d, a, b, c, x[i+ 6], 9 , -1069501632); + c = md5_gg(c, d, a, b, x[i+11], 14, 643717713); + b = md5_gg(b, c, d, a, x[i+ 0], 20, -373897302); + a = md5_gg(a, b, c, d, x[i+ 5], 5 , -701558691); + d = md5_gg(d, a, b, c, x[i+10], 9 , 38016083); + c = md5_gg(c, d, a, b, x[i+15], 14, -660478335); + b = md5_gg(b, c, d, a, x[i+ 4], 20, -405537848); + a = md5_gg(a, b, c, d, x[i+ 9], 5 , 568446438); + d = md5_gg(d, a, b, c, x[i+14], 9 , -1019803690); + c = md5_gg(c, d, a, b, x[i+ 3], 14, -187363961); + b = md5_gg(b, c, d, a, x[i+ 8], 20, 1163531501); + a = md5_gg(a, b, c, d, x[i+13], 5 , -1444681467); + d = md5_gg(d, a, b, c, x[i+ 2], 9 , -51403784); + c = md5_gg(c, d, a, b, x[i+ 7], 14, 1735328473); + b = md5_gg(b, c, d, a, x[i+12], 20, -1926607734); + + a = md5_hh(a, b, c, d, x[i+ 5], 4 , -378558); + d = md5_hh(d, a, b, c, x[i+ 8], 11, -2022574463); + c = md5_hh(c, d, a, b, x[i+11], 16, 1839030562); + b = md5_hh(b, c, d, a, x[i+14], 23, -35309556); + a = md5_hh(a, b, c, d, x[i+ 1], 4 , -1530992060); + d = md5_hh(d, a, b, c, x[i+ 4], 11, 1272893353); + c = md5_hh(c, d, a, b, x[i+ 7], 16, -155497632); + b = md5_hh(b, c, d, a, x[i+10], 23, -1094730640); + a = md5_hh(a, b, c, d, x[i+13], 4 , 681279174); + d = md5_hh(d, a, b, c, x[i+ 0], 11, -358537222); + c = md5_hh(c, d, a, b, x[i+ 3], 16, -722521979); + b = md5_hh(b, c, d, a, x[i+ 6], 23, 76029189); + a = md5_hh(a, b, c, d, x[i+ 9], 4 , -640364487); + d = md5_hh(d, a, b, c, x[i+12], 11, -421815835); + c = md5_hh(c, d, a, b, x[i+15], 16, 530742520); + b = md5_hh(b, c, d, a, x[i+ 2], 23, -995338651); + + a = md5_ii(a, b, c, d, x[i+ 0], 6 , -198630844); + d = md5_ii(d, a, b, c, x[i+ 7], 10, 1126891415); + c = md5_ii(c, d, a, b, x[i+14], 15, -1416354905); + b = md5_ii(b, c, d, a, x[i+ 5], 21, -57434055); + a = md5_ii(a, b, c, d, x[i+12], 6 , 1700485571); + d = md5_ii(d, a, b, c, x[i+ 3], 10, -1894986606); + c = md5_ii(c, d, a, b, x[i+10], 15, -1051523); + b = md5_ii(b, c, d, a, x[i+ 1], 21, -2054922799); + a = md5_ii(a, b, c, d, x[i+ 8], 6 , 1873313359); + d = md5_ii(d, a, b, c, x[i+15], 10, -30611744); + c = md5_ii(c, d, a, b, x[i+ 6], 15, -1560198380); + b = md5_ii(b, c, d, a, x[i+13], 21, 1309151649); + a = md5_ii(a, b, c, d, x[i+ 4], 6 , -145523070); + d = md5_ii(d, a, b, c, x[i+11], 10, -1120210379); + c = md5_ii(c, d, a, b, x[i+ 2], 15, 718787259); + b = md5_ii(b, c, d, a, x[i+ 9], 21, -343485551); + + a = safe_add(a, olda); + b = safe_add(b, oldb); + c = safe_add(c, oldc); + d = safe_add(d, oldd); + } + return [a, b, c, d]; + } + + /* + * These functions implement the four basic operations the algorithm uses. + */ + public static function md5_cmn (q:Number, a:Number, b:Number, x:Number, s:Number, t:Number):Number { + return safe_add (bit_rol (safe_add (safe_add (a, q), safe_add(x, t)), s), b); + } + public static function md5_ff (a:Number, b:Number, c:Number, d:Number, x:Number, s:Number, t:Number):Number { + return md5_cmn ((b & c) | ((~b) & d), a, b, x, s, t); + } + public static function md5_gg (a:Number, b:Number, c:Number, d:Number, x:Number, s:Number, t:Number):Number { + return md5_cmn ((b & d) | (c & (~d)), a, b, x, s, t); + } + public static function md5_hh (a:Number, b:Number, c:Number, d:Number, x:Number, s:Number, t:Number):Number { + return md5_cmn (b ^ c ^ d, a, b, x, s, t); + } + public static function md5_ii (a:Number, b:Number, c:Number, d:Number, x:Number, s:Number, t:Number):Number { + return md5_cmn (c ^ (b | (~d)), a, b, x, s, t); + } + + /* + * Add integers, wrapping at 2^32. This uses 16-bit operations internally + * to work around bugs in some JS interpreters. + */ + public static function safe_add (x:Number, y:Number):Number { + var lsw:Number = (x & 0xFFFF) + (y & 0xFFFF); + var msw:Number = (x >> 16) + (y >> 16) + (lsw >> 16); + return (msw << 16) | (lsw & 0xFFFF); + } + + /* + * Bitwise rotate a 32-bit number to the left. + */ + public static function bit_rol (num:Number, cnt:Number):Number { + return (num << cnt) | (num >>> (32 - cnt)); + } + + } +} diff --git a/app/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/Crypto.as b/app/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/Crypto.as index d631797..32ec97a 100644 --- a/app/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/Crypto.as +++ b/app/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/Crypto.as @@ -1,287 +1,287 @@ -/** - * Crypto - * - * An abstraction layer to instanciate our crypto algorithms - * Copyright (c) 2007 Henri Torgemane - * - * See LICENSE.txt for full license information. - */ -package com.hurlant.crypto -{ - import com.hurlant.crypto.hash.HMAC; - import com.hurlant.crypto.hash.MAC; - import com.hurlant.crypto.hash.IHash; - import com.hurlant.crypto.hash.MD2; - import com.hurlant.crypto.hash.MD5; - import com.hurlant.crypto.hash.SHA1; - import com.hurlant.crypto.hash.SHA224; - import com.hurlant.crypto.hash.SHA256; - import com.hurlant.crypto.prng.ARC4; - import com.hurlant.crypto.rsa.RSAKey; - import com.hurlant.crypto.symmetric.AESKey; - import com.hurlant.crypto.symmetric.BlowFishKey; - import com.hurlant.crypto.symmetric.CBCMode; - import com.hurlant.crypto.symmetric.CFB8Mode; - import com.hurlant.crypto.symmetric.CFBMode; - import com.hurlant.crypto.symmetric.CTRMode; - import com.hurlant.crypto.symmetric.DESKey; - import com.hurlant.crypto.symmetric.ECBMode; - import com.hurlant.crypto.symmetric.ICipher; - import com.hurlant.crypto.symmetric.IMode; - import com.hurlant.crypto.symmetric.IPad; - import com.hurlant.crypto.symmetric.ISymmetricKey; - import com.hurlant.crypto.symmetric.IVMode; - import com.hurlant.crypto.symmetric.NullPad; - import com.hurlant.crypto.symmetric.OFBMode; - import com.hurlant.crypto.symmetric.PKCS5; - import com.hurlant.crypto.symmetric.SimpleIVMode; - import com.hurlant.crypto.symmetric.TripleDESKey; - import com.hurlant.crypto.symmetric.XTeaKey; - import com.hurlant.util.Base64; - - import flash.utils.ByteArray; - - /** - * A class to make it easy to use the rest of the framework. - * As a side-effect, using this class will cause most of the framework - * to be linked into your application, which is not always what you want. - * - * If you want to optimize your download size, don't use this class. - * (But feel free to read it to get ideas on how to get the algorithm you want.) - */ - public class Crypto - { - private var b64:Base64; // we don't use it, but we want the swc to include it, so cheap trick. - - public function Crypto(){ - } - - /** - * Things that should work, among others: - * "aes" - * "aes-128-ecb" - * "aes-128-cbc" - * "aes-128-cfb" - * "aes-128-cfb8" - * "aes-128-ofb" - * "aes-192-cfb" - * "aes-256-ofb" - * "blowfish-cbc" - * "des-ecb" - * "xtea" - * "xtea-ecb" - * "xtea-cbc" - * "xtea-cfb" - * "xtea-cfb8" - * "xtea-ofb" - * "rc4" - * "simple-aes-cbc" - */ - public static function getCipher(name:String, key:ByteArray, pad:IPad=null):ICipher { - // split name into an array. - var keys:Array = name.split("-"); - switch (keys[0]) { - /** - * "simple" is a special case. It means: - * "If using an IV mode, prepend the IV to the ciphertext" - */ - case "simple": - keys.shift(); - name = keys.join("-"); - var cipher:ICipher = getCipher(name, key, pad); - if (cipher is IVMode) { - return new SimpleIVMode(cipher as IVMode); - } else { - return cipher; - } - /** - * we support both "aes-128" and "aes128" - * Technically, you could use "aes192-128", but you'd - * only be hurting yourself. - */ - case "aes": - case "aes128": - case "aes192": - case "aes256": - keys.shift(); - if (key.length*8==keys[0]) { - // support for "aes-128-..." and such. - keys.shift(); - } - return getMode(keys[0], new AESKey(key), pad); - break; - case "bf": - case "blowfish": - keys.shift(); - return getMode(keys[0], new BlowFishKey(key), pad); - /** - * des-ede and des-ede3 are both equivalent to des3. - * the choice between 2tdes and 3tdes is made based - * on the length of the key provided. - */ - case "des": - keys.shift(); - if (keys[0]!="ede" && keys[0]!="ede3") { - return getMode(keys[0], new DESKey(key), pad); - } - if (keys.length==1) { - keys.push("ecb"); // default mode for 2tdes and 3tdes with openssl enc - } - // fall-through to triple des - case "3des": - case "des3": - keys.shift(); - return getMode(keys[0], new TripleDESKey(key), pad); - case "xtea": - keys.shift(); - return getMode(keys[0], new XTeaKey(key), pad); - break; - /** - * Technically, you could say "rc4-128" or whatever, - * but really, the length of the key is what counts here. - */ - case "rc4": - keys.shift(); - return new ARC4(key); - break; - } - return null; - } - - /** - * Returns the size of a key for a given cipher identifier. - */ - public static function getKeySize(name:String):uint { - var keys:Array = name.split("-"); - switch (keys[0]) { - case "simple": - keys.shift(); - return getKeySize(keys.join("-")); - case "aes128": - return 16; - case "aes192": - return 24; - case "aes256": - return 32; - case "aes": - keys.shift(); - return parseInt(keys[0])/8; - case "bf": - case "blowfish": - return 16; - case "des": - keys.shift(); - switch (keys[0]) { - case "ede": - return 16; - case "ede3": - return 24; - default: - return 8; - } - case "3des": - case "des3": - return 24; - case "xtea": - return 8; - case "rc4": - if (parseInt(keys[1])>0) { - return parseInt(keys[1])/8; - } - return 16; // why not. - } - return 0; // unknown; - } - - private static function getMode(name:String, alg:ISymmetricKey, padding:IPad=null):IMode { - switch (name) { - case "ecb": - return new ECBMode(alg, padding); - case "cfb": - return new CFBMode(alg, padding); - case "cfb8": - return new CFB8Mode(alg, padding); - case "ofb": - return new OFBMode(alg, padding); - case "ctr": - return new CTRMode(alg, padding); - case "cbc": - default: - return new CBCMode(alg, padding); - } - } - - /** - * Things that should work: - * "md5" - * "sha" - * "sha1" - * "sha224" - * "sha256" - */ - public static function getHash(name:String):IHash { - switch(name) { - case "md2": - return new MD2; - case "md5": - return new MD5; - case "sha": // let's hope you didn't mean sha-0 - case "sha1": - return new SHA1; - case "sha224": - return new SHA224; - case "sha256": - return new SHA256; - } - return null; - } - - /** - * Things that should work: - * "sha1" - * "md5-64" - * "hmac-md5-96" - * "hmac-sha1-128" - * "hmac-sha256-192" - * etc. - */ - public static function getHMAC(name:String):HMAC { - var keys:Array = name.split("-"); - if (keys[0]=="hmac") keys.shift(); - var bits:uint = 0; - if (keys.length>1) { - bits = parseInt(keys[1]); - } - return new HMAC(getHash(keys[0]), bits); - } - - - public static function getMAC(name:String):MAC { - - var keys:Array = name.split("-"); - if (keys[0]=="mac") keys.shift(); - var bits:uint = 0; - if (keys.length > 1) { - bits = parseInt(keys[1]); - } - return new MAC(getHash(keys[0]), bits); - } - - - public static function getPad(name:String):IPad { - switch(name) { - case "null": - return new NullPad; - case "pkcs5": - default: - return new PKCS5; - } - } - - /** mostly useless. - */ - public static function getRSA(E:String, M:String):RSAKey { - return RSAKey.parsePublicKey(M,E); - } - } +/** + * Crypto + * + * An abstraction layer to instanciate our crypto algorithms + * Copyright (c) 2007 Henri Torgemane + * + * See LICENSE.txt for full license information. + */ +package com.hurlant.crypto +{ + import com.hurlant.crypto.hash.HMAC; + import com.hurlant.crypto.hash.MAC; + import com.hurlant.crypto.hash.IHash; + import com.hurlant.crypto.hash.MD2; + import com.hurlant.crypto.hash.MD5; + import com.hurlant.crypto.hash.SHA1; + import com.hurlant.crypto.hash.SHA224; + import com.hurlant.crypto.hash.SHA256; + import com.hurlant.crypto.prng.ARC4; + import com.hurlant.crypto.rsa.RSAKey; + import com.hurlant.crypto.symmetric.AESKey; + import com.hurlant.crypto.symmetric.BlowFishKey; + import com.hurlant.crypto.symmetric.CBCMode; + import com.hurlant.crypto.symmetric.CFB8Mode; + import com.hurlant.crypto.symmetric.CFBMode; + import com.hurlant.crypto.symmetric.CTRMode; + import com.hurlant.crypto.symmetric.DESKey; + import com.hurlant.crypto.symmetric.ECBMode; + import com.hurlant.crypto.symmetric.ICipher; + import com.hurlant.crypto.symmetric.IMode; + import com.hurlant.crypto.symmetric.IPad; + import com.hurlant.crypto.symmetric.ISymmetricKey; + import com.hurlant.crypto.symmetric.IVMode; + import com.hurlant.crypto.symmetric.NullPad; + import com.hurlant.crypto.symmetric.OFBMode; + import com.hurlant.crypto.symmetric.PKCS5; + import com.hurlant.crypto.symmetric.SimpleIVMode; + import com.hurlant.crypto.symmetric.TripleDESKey; + import com.hurlant.crypto.symmetric.XTeaKey; + import com.hurlant.util.Base64; + + import flash.utils.ByteArray; + + /** + * A class to make it easy to use the rest of the framework. + * As a side-effect, using this class will cause most of the framework + * to be linked into your application, which is not always what you want. + * + * If you want to optimize your download size, don't use this class. + * (But feel free to read it to get ideas on how to get the algorithm you want.) + */ + public class Crypto + { + private var b64:Base64; // we don't use it, but we want the swc to include it, so cheap trick. + + public function Crypto(){ + } + + /** + * Things that should work, among others: + * "aes" + * "aes-128-ecb" + * "aes-128-cbc" + * "aes-128-cfb" + * "aes-128-cfb8" + * "aes-128-ofb" + * "aes-192-cfb" + * "aes-256-ofb" + * "blowfish-cbc" + * "des-ecb" + * "xtea" + * "xtea-ecb" + * "xtea-cbc" + * "xtea-cfb" + * "xtea-cfb8" + * "xtea-ofb" + * "rc4" + * "simple-aes-cbc" + */ + public static function getCipher(name:String, key:ByteArray, pad:IPad=null):ICipher { + // split name into an array. + var keys:Array = name.split("-"); + switch (keys[0]) { + /** + * "simple" is a special case. It means: + * "If using an IV mode, prepend the IV to the ciphertext" + */ + case "simple": + keys.shift(); + name = keys.join("-"); + var cipher:ICipher = getCipher(name, key, pad); + if (cipher is IVMode) { + return new SimpleIVMode(cipher as IVMode); + } else { + return cipher; + } + /** + * we support both "aes-128" and "aes128" + * Technically, you could use "aes192-128", but you'd + * only be hurting yourself. + */ + case "aes": + case "aes128": + case "aes192": + case "aes256": + keys.shift(); + if (key.length*8==keys[0]) { + // support for "aes-128-..." and such. + keys.shift(); + } + return getMode(keys[0], new AESKey(key), pad); + break; + case "bf": + case "blowfish": + keys.shift(); + return getMode(keys[0], new BlowFishKey(key), pad); + /** + * des-ede and des-ede3 are both equivalent to des3. + * the choice between 2tdes and 3tdes is made based + * on the length of the key provided. + */ + case "des": + keys.shift(); + if (keys[0]!="ede" && keys[0]!="ede3") { + return getMode(keys[0], new DESKey(key), pad); + } + if (keys.length==1) { + keys.push("ecb"); // default mode for 2tdes and 3tdes with openssl enc + } + // fall-through to triple des + case "3des": + case "des3": + keys.shift(); + return getMode(keys[0], new TripleDESKey(key), pad); + case "xtea": + keys.shift(); + return getMode(keys[0], new XTeaKey(key), pad); + break; + /** + * Technically, you could say "rc4-128" or whatever, + * but really, the length of the key is what counts here. + */ + case "rc4": + keys.shift(); + return new ARC4(key); + break; + } + return null; + } + + /** + * Returns the size of a key for a given cipher identifier. + */ + public static function getKeySize(name:String):uint { + var keys:Array = name.split("-"); + switch (keys[0]) { + case "simple": + keys.shift(); + return getKeySize(keys.join("-")); + case "aes128": + return 16; + case "aes192": + return 24; + case "aes256": + return 32; + case "aes": + keys.shift(); + return parseInt(keys[0])/8; + case "bf": + case "blowfish": + return 16; + case "des": + keys.shift(); + switch (keys[0]) { + case "ede": + return 16; + case "ede3": + return 24; + default: + return 8; + } + case "3des": + case "des3": + return 24; + case "xtea": + return 8; + case "rc4": + if (parseInt(keys[1])>0) { + return parseInt(keys[1])/8; + } + return 16; // why not. + } + return 0; // unknown; + } + + private static function getMode(name:String, alg:ISymmetricKey, padding:IPad=null):IMode { + switch (name) { + case "ecb": + return new ECBMode(alg, padding); + case "cfb": + return new CFBMode(alg, padding); + case "cfb8": + return new CFB8Mode(alg, padding); + case "ofb": + return new OFBMode(alg, padding); + case "ctr": + return new CTRMode(alg, padding); + case "cbc": + default: + return new CBCMode(alg, padding); + } + } + + /** + * Things that should work: + * "md5" + * "sha" + * "sha1" + * "sha224" + * "sha256" + */ + public static function getHash(name:String):IHash { + switch(name) { + case "md2": + return new MD2; + case "md5": + return new MD5; + case "sha": // let's hope you didn't mean sha-0 + case "sha1": + return new SHA1; + case "sha224": + return new SHA224; + case "sha256": + return new SHA256; + } + return null; + } + + /** + * Things that should work: + * "sha1" + * "md5-64" + * "hmac-md5-96" + * "hmac-sha1-128" + * "hmac-sha256-192" + * etc. + */ + public static function getHMAC(name:String):HMAC { + var keys:Array = name.split("-"); + if (keys[0]=="hmac") keys.shift(); + var bits:uint = 0; + if (keys.length>1) { + bits = parseInt(keys[1]); + } + return new HMAC(getHash(keys[0]), bits); + } + + + public static function getMAC(name:String):MAC { + + var keys:Array = name.split("-"); + if (keys[0]=="mac") keys.shift(); + var bits:uint = 0; + if (keys.length > 1) { + bits = parseInt(keys[1]); + } + return new MAC(getHash(keys[0]), bits); + } + + + public static function getPad(name:String):IPad { + switch(name) { + case "null": + return new NullPad; + case "pkcs5": + default: + return new PKCS5; + } + } + + /** mostly useless. + */ + public static function getRSA(E:String, M:String):RSAKey { + return RSAKey.parsePublicKey(M,E); + } + } } \ No newline at end of file diff --git a/app/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/cert/MozillaRootCertificates.as b/app/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/cert/MozillaRootCertificates.as old mode 100644 new mode 100755 diff --git a/app/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/cert/X509Certificate.as b/app/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/cert/X509Certificate.as old mode 100644 new mode 100755 index 418aad4..db4ea1c --- a/app/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/cert/X509Certificate.as +++ b/app/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/cert/X509Certificate.as @@ -1,218 +1,218 @@ -/** - * X509Certificate - * - * A representation for a X509 Certificate, with - * methods to parse, verify and sign it. - * Copyright (c) 2007 Henri Torgemane - * - * See LICENSE.txt for full license information. - */ -package com.hurlant.crypto.cert { - import com.hurlant.crypto.hash.IHash; - import com.hurlant.crypto.hash.MD2; - import com.hurlant.crypto.hash.MD5; - import com.hurlant.crypto.hash.SHA1; - import com.hurlant.crypto.rsa.RSAKey; - import com.hurlant.util.ArrayUtil; - import com.hurlant.util.Base64; - import com.hurlant.util.der.ByteString; - import com.hurlant.util.der.DER; - import com.hurlant.util.der.OID; - import com.hurlant.util.der.ObjectIdentifier; - import com.hurlant.util.der.PEM; - import com.hurlant.util.der.PrintableString; - import com.hurlant.util.der.Sequence; - import com.hurlant.util.der.Type; - - import flash.utils.ByteArray; - - public class X509Certificate { - private var _loaded:Boolean; - private var _param:*; - private var _obj:Object; - public function X509Certificate(p:*) { - _loaded = false; - _param = p; - // lazy initialization, to avoid unnecessary parsing of every builtin CA at start-up. - } - private function load():void { - if (_loaded) return; - var p:* = _param; - var b:ByteArray; - if (p is String) { - b = PEM.readCertIntoArray(p as String); - } else if (p is ByteArray) { - b = p; - } - if (b!=null) { - _obj = DER.parse(b, Type.TLS_CERT); - _loaded = true; - } else { - throw new Error("Invalid x509 Certificate parameter: "+p); - } - } - public function isSigned(store:X509CertificateCollection, CAs:X509CertificateCollection, time:Date=null):Boolean { - load(); - // check timestamps first. cheapest. - if (time==null) { - time = new Date; - } - var notBefore:Date = getNotBefore(); - var notAfter:Date = getNotAfter(); - if (time.getTime()notAfter.getTime()) return false; // cert died of old age. - // check signature. - var subject:String = getIssuerPrincipal(); - // try from CA first, since they're treated better. - var parent:X509Certificate = CAs.getCertificate(subject); - var parentIsAuthoritative:Boolean = false; - if (parent == null) { - parent = store.getCertificate(subject); - if (parent == null) { - return false; // issuer not found - } - } else { - parentIsAuthoritative = true; - } - if (parent == this) { // pathological case. avoid infinite loop - return false; // isSigned() returns false if we're self-signed. - } - if (!(parentIsAuthoritative&&parent.isSelfSigned(time)) && - !parent.isSigned(store, CAs, time)) { - return false; - } - var key:RSAKey = parent.getPublicKey(); - return verifyCertificate(key); - } - public function isSelfSigned(time:Date):Boolean { - load(); - - var key:RSAKey = getPublicKey(); - return verifyCertificate(key); - } - private function verifyCertificate(key:RSAKey):Boolean { - var algo:String = getAlgorithmIdentifier(); - var hash:IHash; - var oid:String; - switch (algo) { - case OID.SHA1_WITH_RSA_ENCRYPTION: - hash = new SHA1; - oid = OID.SHA1_ALGORITHM; - break; - case OID.MD2_WITH_RSA_ENCRYPTION: - hash = new MD2; - oid = OID.MD2_ALGORITHM; - break; - case OID.MD5_WITH_RSA_ENCRYPTION: - hash = new MD5; - oid = OID.MD5_ALGORITHM; - break; - default: - return false; - } - var data:ByteArray = _obj.signedCertificate_bin; - var buf:ByteArray = new ByteArray; - key.verify(_obj.encrypted, buf, _obj.encrypted.length); - buf.position=0; - data = hash.hash(data); - var obj:Object = DER.parse(buf, Type.RSA_SIGNATURE); - if (obj.algorithm.algorithmId.toString() != oid) { - return false; // wrong algorithm - } - if (!ArrayUtil.equals(obj.hash, data)) { - return false; // hashes don't match - } - return true; - } - - /** - * This isn't used anywhere so far. - * It would become useful if we started to offer facilities - * to generate and sign X509 certificates. - * - * @param key - * @param algo - * @return - * - */ - private function signCertificate(key:RSAKey, algo:String):ByteArray { - var hash:IHash; - var oid:String; - switch (algo) { - case OID.SHA1_WITH_RSA_ENCRYPTION: - hash = new SHA1; - oid = OID.SHA1_ALGORITHM; - break; - case OID.MD2_WITH_RSA_ENCRYPTION: - hash = new MD2; - oid = OID.MD2_ALGORITHM; - break; - case OID.MD5_WITH_RSA_ENCRYPTION: - hash = new MD5; - oid = OID.MD5_ALGORITHM; - break; - default: - return null - } - var data:ByteArray = _obj.signedCertificate_bin; - data = hash.hash(data); - var seq1:Sequence = new Sequence; - seq1[0] = new Sequence; - seq1[0][0] = new ObjectIdentifier(0,0, oid); - seq1[0][1] = null; - seq1[1] = new ByteString; - seq1[1].writeBytes(data); - data = seq1.toDER(); - var buf:ByteArray = new ByteArray; - key.sign(data, buf, data.length); - return buf; - } - - public function getPublicKey():RSAKey { - load(); - var pk:ByteArray = _obj.signedCertificate.subjectPublicKeyInfo.subjectPublicKey as ByteArray; - pk.position = 0; - var rsaKey:Object = DER.parse(pk, [{name:"N"},{name:"E"}]); - return new RSAKey(rsaKey.N, rsaKey.E.valueOf()); - } - - /** - * Returns a subject principal, as an opaque base64 string. - * This is only used as a hash key for known certificates. - * - * Note that this assumes X509 DER-encoded certificates are uniquely encoded, - * as we look for exact matches between Issuer and Subject fields. - * - */ - public function getSubjectPrincipal():String { - load(); - return Base64.encodeByteArray(_obj.signedCertificate.subject_bin); - } - /** - * Returns an issuer principal, as an opaque base64 string. - * This is only used to quickly find matching parent certificates. - * - * Note that this assumes X509 DER-encoded certificates are uniquely encoded, - * as we look for exact matches between Issuer and Subject fields. - * - */ - public function getIssuerPrincipal():String { - load(); - return Base64.encodeByteArray(_obj.signedCertificate.issuer_bin); - } - public function getAlgorithmIdentifier():String { - return _obj.algorithmIdentifier.algorithmId.toString(); - } - public function getNotBefore():Date { - return _obj.signedCertificate.validity.notBefore.date; - } - public function getNotAfter():Date { - return _obj.signedCertificate.validity.notAfter.date; - } - - public function getCommonName():String { - var subject:Sequence = _obj.signedCertificate.subject; - return (subject.findAttributeValue(OID.COMMON_NAME) as PrintableString).getString(); - } - } +/** + * X509Certificate + * + * A representation for a X509 Certificate, with + * methods to parse, verify and sign it. + * Copyright (c) 2007 Henri Torgemane + * + * See LICENSE.txt for full license information. + */ +package com.hurlant.crypto.cert { + import com.hurlant.crypto.hash.IHash; + import com.hurlant.crypto.hash.MD2; + import com.hurlant.crypto.hash.MD5; + import com.hurlant.crypto.hash.SHA1; + import com.hurlant.crypto.rsa.RSAKey; + import com.hurlant.util.ArrayUtil; + import com.hurlant.util.Base64; + import com.hurlant.util.der.ByteString; + import com.hurlant.util.der.DER; + import com.hurlant.util.der.OID; + import com.hurlant.util.der.ObjectIdentifier; + import com.hurlant.util.der.PEM; + import com.hurlant.util.der.PrintableString; + import com.hurlant.util.der.Sequence; + import com.hurlant.util.der.Type; + + import flash.utils.ByteArray; + + public class X509Certificate { + private var _loaded:Boolean; + private var _param:*; + private var _obj:Object; + public function X509Certificate(p:*) { + _loaded = false; + _param = p; + // lazy initialization, to avoid unnecessary parsing of every builtin CA at start-up. + } + private function load():void { + if (_loaded) return; + var p:* = _param; + var b:ByteArray; + if (p is String) { + b = PEM.readCertIntoArray(p as String); + } else if (p is ByteArray) { + b = p; + } + if (b!=null) { + _obj = DER.parse(b, Type.TLS_CERT); + _loaded = true; + } else { + throw new Error("Invalid x509 Certificate parameter: "+p); + } + } + public function isSigned(store:X509CertificateCollection, CAs:X509CertificateCollection, time:Date=null):Boolean { + load(); + // check timestamps first. cheapest. + if (time==null) { + time = new Date; + } + var notBefore:Date = getNotBefore(); + var notAfter:Date = getNotAfter(); + if (time.getTime()notAfter.getTime()) return false; // cert died of old age. + // check signature. + var subject:String = getIssuerPrincipal(); + // try from CA first, since they're treated better. + var parent:X509Certificate = CAs.getCertificate(subject); + var parentIsAuthoritative:Boolean = false; + if (parent == null) { + parent = store.getCertificate(subject); + if (parent == null) { + return false; // issuer not found + } + } else { + parentIsAuthoritative = true; + } + if (parent == this) { // pathological case. avoid infinite loop + return false; // isSigned() returns false if we're self-signed. + } + if (!(parentIsAuthoritative&&parent.isSelfSigned(time)) && + !parent.isSigned(store, CAs, time)) { + return false; + } + var key:RSAKey = parent.getPublicKey(); + return verifyCertificate(key); + } + public function isSelfSigned(time:Date):Boolean { + load(); + + var key:RSAKey = getPublicKey(); + return verifyCertificate(key); + } + private function verifyCertificate(key:RSAKey):Boolean { + var algo:String = getAlgorithmIdentifier(); + var hash:IHash; + var oid:String; + switch (algo) { + case OID.SHA1_WITH_RSA_ENCRYPTION: + hash = new SHA1; + oid = OID.SHA1_ALGORITHM; + break; + case OID.MD2_WITH_RSA_ENCRYPTION: + hash = new MD2; + oid = OID.MD2_ALGORITHM; + break; + case OID.MD5_WITH_RSA_ENCRYPTION: + hash = new MD5; + oid = OID.MD5_ALGORITHM; + break; + default: + return false; + } + var data:ByteArray = _obj.signedCertificate_bin; + var buf:ByteArray = new ByteArray; + key.verify(_obj.encrypted, buf, _obj.encrypted.length); + buf.position=0; + data = hash.hash(data); + var obj:Object = DER.parse(buf, Type.RSA_SIGNATURE); + if (obj.algorithm.algorithmId.toString() != oid) { + return false; // wrong algorithm + } + if (!ArrayUtil.equals(obj.hash, data)) { + return false; // hashes don't match + } + return true; + } + + /** + * This isn't used anywhere so far. + * It would become useful if we started to offer facilities + * to generate and sign X509 certificates. + * + * @param key + * @param algo + * @return + * + */ + private function signCertificate(key:RSAKey, algo:String):ByteArray { + var hash:IHash; + var oid:String; + switch (algo) { + case OID.SHA1_WITH_RSA_ENCRYPTION: + hash = new SHA1; + oid = OID.SHA1_ALGORITHM; + break; + case OID.MD2_WITH_RSA_ENCRYPTION: + hash = new MD2; + oid = OID.MD2_ALGORITHM; + break; + case OID.MD5_WITH_RSA_ENCRYPTION: + hash = new MD5; + oid = OID.MD5_ALGORITHM; + break; + default: + return null + } + var data:ByteArray = _obj.signedCertificate_bin; + data = hash.hash(data); + var seq1:Sequence = new Sequence; + seq1[0] = new Sequence; + seq1[0][0] = new ObjectIdentifier(0,0, oid); + seq1[0][1] = null; + seq1[1] = new ByteString; + seq1[1].writeBytes(data); + data = seq1.toDER(); + var buf:ByteArray = new ByteArray; + key.sign(data, buf, data.length); + return buf; + } + + public function getPublicKey():RSAKey { + load(); + var pk:ByteArray = _obj.signedCertificate.subjectPublicKeyInfo.subjectPublicKey as ByteArray; + pk.position = 0; + var rsaKey:Object = DER.parse(pk, [{name:"N"},{name:"E"}]); + return new RSAKey(rsaKey.N, rsaKey.E.valueOf()); + } + + /** + * Returns a subject principal, as an opaque base64 string. + * This is only used as a hash key for known certificates. + * + * Note that this assumes X509 DER-encoded certificates are uniquely encoded, + * as we look for exact matches between Issuer and Subject fields. + * + */ + public function getSubjectPrincipal():String { + load(); + return Base64.encodeByteArray(_obj.signedCertificate.subject_bin); + } + /** + * Returns an issuer principal, as an opaque base64 string. + * This is only used to quickly find matching parent certificates. + * + * Note that this assumes X509 DER-encoded certificates are uniquely encoded, + * as we look for exact matches between Issuer and Subject fields. + * + */ + public function getIssuerPrincipal():String { + load(); + return Base64.encodeByteArray(_obj.signedCertificate.issuer_bin); + } + public function getAlgorithmIdentifier():String { + return _obj.algorithmIdentifier.algorithmId.toString(); + } + public function getNotBefore():Date { + return _obj.signedCertificate.validity.notBefore.date; + } + public function getNotAfter():Date { + return _obj.signedCertificate.validity.notAfter.date; + } + + public function getCommonName():String { + var subject:Sequence = _obj.signedCertificate.subject; + return (subject.findAttributeValue(OID.COMMON_NAME) as PrintableString).getString(); + } + } } \ No newline at end of file diff --git a/app/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/cert/X509CertificateCollection.as b/app/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/cert/X509CertificateCollection.as old mode 100644 new mode 100755 index 3bcdc96..db11e40 --- a/app/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/cert/X509CertificateCollection.as +++ b/app/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/cert/X509CertificateCollection.as @@ -1,57 +1,57 @@ -/** - * X509CertificateCollection - * - * A class to store and index X509 Certificates by Subject. - * Copyright (c) 2007 Henri Torgemane - * - * See LICENSE.txt for full license information. - */ -package com.hurlant.crypto.cert { - - public class X509CertificateCollection { - - private var _map:Object; - - public function X509CertificateCollection() { - _map = {}; - } - - /** - * Mostly meant for built-in CA loading. - * This entry-point allows to index CAs without parsing them. - * - * @param name A friendly name. not currently used - * @param subject base64 DER encoded Subject principal for the Cert - * @param pem PEM encoded certificate data - * - */ - public function addPEMCertificate(name:String, subject:String, pem:String):void { - _map[subject] = new X509Certificate(pem); - } - - /** - * Adds a X509 certificate to the collection. - * This call will force the certificate to be parsed. - * - * @param cert A X509 certificate - * - */ - public function addCertificate(cert:X509Certificate):void { - var subject:String = cert.getSubjectPrincipal(); - _map[subject] = cert; - } - - /** - * Returns a X509 Certificate present in the collection, given - * a base64 DER encoded X500 Subject principal - * - * @param subject A Base64 DER-encoded Subject principal - * @return A matching certificate, or null. - * - */ - public function getCertificate(subject:String):X509Certificate { - return _map[subject]; - } - - } +/** + * X509CertificateCollection + * + * A class to store and index X509 Certificates by Subject. + * Copyright (c) 2007 Henri Torgemane + * + * See LICENSE.txt for full license information. + */ +package com.hurlant.crypto.cert { + + public class X509CertificateCollection { + + private var _map:Object; + + public function X509CertificateCollection() { + _map = {}; + } + + /** + * Mostly meant for built-in CA loading. + * This entry-point allows to index CAs without parsing them. + * + * @param name A friendly name. not currently used + * @param subject base64 DER encoded Subject principal for the Cert + * @param pem PEM encoded certificate data + * + */ + public function addPEMCertificate(name:String, subject:String, pem:String):void { + _map[subject] = new X509Certificate(pem); + } + + /** + * Adds a X509 certificate to the collection. + * This call will force the certificate to be parsed. + * + * @param cert A X509 certificate + * + */ + public function addCertificate(cert:X509Certificate):void { + var subject:String = cert.getSubjectPrincipal(); + _map[subject] = cert; + } + + /** + * Returns a X509 Certificate present in the collection, given + * a base64 DER encoded X500 Subject principal + * + * @param subject A Base64 DER-encoded Subject principal + * @return A matching certificate, or null. + * + */ + public function getCertificate(subject:String):X509Certificate { + return _map[subject]; + } + + } } \ No newline at end of file diff --git a/app/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/hash/HMAC.as b/app/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/hash/HMAC.as index 1438645..8215afc 100644 --- a/app/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/hash/HMAC.as +++ b/app/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/hash/HMAC.as @@ -1,82 +1,82 @@ -/** - * HMAC - * - * An ActionScript 3 implementation of HMAC, Keyed-Hashing for Message - * Authentication, as defined by RFC-2104 - * Copyright (c) 2007 Henri Torgemane - * - * See LICENSE.txt for full license information. - */ -package com.hurlant.crypto.hash -{ - import flash.utils.ByteArray; - import com.hurlant.util.Hex; - - public class HMAC implements IHMAC - { - private var hash:IHash; - private var bits:uint; - - /** - * Create a HMAC object, using a Hash function, and - * optionally a number of bits to return. - * The HMAC will be truncated to that size if needed. - */ - public function HMAC(hash:IHash, bits:uint=0) { - this.hash = hash; - this.bits = bits; - } - - - public function getHashSize():uint { - if (bits!=0) { - return bits/8; - } else { - return hash.getHashSize(); - } - } - - /** - * Compute a HMAC using a key and some data. - * It doesn't modify either, and returns a new ByteArray with the HMAC value. - */ - public function compute(key:ByteArray, data:ByteArray):ByteArray { - var hashKey:ByteArray; - if (key.length>hash.getInputSize()) { - hashKey = hash.hash(key); - } else { - hashKey = new ByteArray; - hashKey.writeBytes(key); - } - while (hashKey.length0 && bits<8*outerHash.length) { - outerHash.length = bits/8; - } - return outerHash; - } - public function dispose():void { - hash = null; - bits = 0; - } - public function toString():String { - return "hmac-"+(bits>0?bits+"-":"")+hash.toString(); - } - - } +/** + * HMAC + * + * An ActionScript 3 implementation of HMAC, Keyed-Hashing for Message + * Authentication, as defined by RFC-2104 + * Copyright (c) 2007 Henri Torgemane + * + * See LICENSE.txt for full license information. + */ +package com.hurlant.crypto.hash +{ + import flash.utils.ByteArray; + import com.hurlant.util.Hex; + + public class HMAC implements IHMAC + { + private var hash:IHash; + private var bits:uint; + + /** + * Create a HMAC object, using a Hash function, and + * optionally a number of bits to return. + * The HMAC will be truncated to that size if needed. + */ + public function HMAC(hash:IHash, bits:uint=0) { + this.hash = hash; + this.bits = bits; + } + + + public function getHashSize():uint { + if (bits!=0) { + return bits/8; + } else { + return hash.getHashSize(); + } + } + + /** + * Compute a HMAC using a key and some data. + * It doesn't modify either, and returns a new ByteArray with the HMAC value. + */ + public function compute(key:ByteArray, data:ByteArray):ByteArray { + var hashKey:ByteArray; + if (key.length>hash.getInputSize()) { + hashKey = hash.hash(key); + } else { + hashKey = new ByteArray; + hashKey.writeBytes(key); + } + while (hashKey.length0 && bits<8*outerHash.length) { + outerHash.length = bits/8; + } + return outerHash; + } + public function dispose():void { + hash = null; + bits = 0; + } + public function toString():String { + return "hmac-"+(bits>0?bits+"-":"")+hash.toString(); + } + + } } \ No newline at end of file diff --git a/app/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/hash/IHMAC.as b/app/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/hash/IHMAC.as old mode 100644 new mode 100755 index 047d277..f0ee063 --- a/app/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/hash/IHMAC.as +++ b/app/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/hash/IHMAC.as @@ -1,27 +1,27 @@ -/** - * HMAC - * - * An ActionScript 3 interface for HMAC & MAC - * implementations. - * - * Loosely copyrighted by Bobby Parker - * - * See LICENSE.txt for full license information. - */ -package com.hurlant.crypto.hash -{ - import flash.utils.ByteArray; - - public interface IHMAC - { - function getHashSize():uint; - /** - * Compute a HMAC using a key and some data. - * It doesn't modify either, and returns a new ByteArray with the HMAC value. - */ - function compute(key:ByteArray, data:ByteArray):ByteArray; - function dispose():void; - function toString():String; - - } +/** + * HMAC + * + * An ActionScript 3 interface for HMAC & MAC + * implementations. + * + * Loosely copyrighted by Bobby Parker + * + * See LICENSE.txt for full license information. + */ +package com.hurlant.crypto.hash +{ + import flash.utils.ByteArray; + + public interface IHMAC + { + function getHashSize():uint; + /** + * Compute a HMAC using a key and some data. + * It doesn't modify either, and returns a new ByteArray with the HMAC value. + */ + function compute(key:ByteArray, data:ByteArray):ByteArray; + function dispose():void; + function toString():String; + + } } \ No newline at end of file diff --git a/app/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/hash/IHash.as b/app/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/hash/IHash.as index 103829f..32c5321 100644 --- a/app/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/hash/IHash.as +++ b/app/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/hash/IHash.as @@ -1,21 +1,21 @@ -/** - * IHash - * - * An interface for each hash function to implement - * Copyright (c) 2007 Henri Torgemane - * - * See LICENSE.txt for full license information. - */ -package com.hurlant.crypto.hash -{ - import flash.utils.ByteArray; - - public interface IHash - { - function getInputSize():uint; - function getHashSize():uint; - function hash(src:ByteArray):ByteArray; - function toString():String; - function getPadSize():int; - } +/** + * IHash + * + * An interface for each hash function to implement + * Copyright (c) 2007 Henri Torgemane + * + * See LICENSE.txt for full license information. + */ +package com.hurlant.crypto.hash +{ + import flash.utils.ByteArray; + + public interface IHash + { + function getInputSize():uint; + function getHashSize():uint; + function hash(src:ByteArray):ByteArray; + function toString():String; + function getPadSize():int; + } } \ No newline at end of file diff --git a/app/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/hash/MAC.as b/app/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/hash/MAC.as old mode 100644 new mode 100755 index f8fbcee..0815d6c --- a/app/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/hash/MAC.as +++ b/app/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/hash/MAC.as @@ -1,137 +1,137 @@ -/** - * MAC - * - * An ActionScript 3 implementation of MAC, Message Authentication Code - * for use with SSL 3.0. - * Loosely copyrighted by Bobby Parker. - * As3crypto copyrighted by Henri Torgemane. - * - * See LICENSE.txt for full license information. - */ -package com.hurlant.crypto.hash -{ - import flash.utils.ByteArray; - import com.hurlant.util.Hex; - - public class MAC implements IHMAC - { - private var hash:IHash; - private var bits:uint; - private var pad_1:ByteArray; - private var pad_2:ByteArray; - private var innerHash:ByteArray; - private var outerHash:ByteArray; - private var outerKey:ByteArray; - private var innerKey:ByteArray; - /** - * Create a MAC object (for SSL 3.0 ) and - * optionally a number of bits to return. - * The MAC will be truncated to that size if needed. - */ - public function MAC(hash:IHash, bits:uint=0) { - this.hash = hash; - this.bits = bits; - innerHash = new ByteArray(); - outerHash = new ByteArray(); - innerKey = new ByteArray(); - outerKey = new ByteArray(); - - - if (hash != null) { - var pad_size:int = hash.getPadSize(); - pad_1 = new ByteArray(); - pad_2 = new ByteArray(); - - for (var x:int = 0; x < pad_size; x++) { - pad_1.writeByte(0x36); - pad_2.writeByte(0x5c); - } - } - } - - public function setPadSize(pad_size:int) : void { } - - public function getHashSize():uint { - if (bits!=0) { - return bits/8; - } else { - return hash.getHashSize(); - } - } - - - /** - * Compute a MAC using a key and some data. - * - */ - public function compute(key:ByteArray, data:ByteArray):ByteArray { - // take that incoming key and do hash(key + pad_2 + hash(key + pad_1 + sequence + length + record) - // note that data = (sequence + type + length + record) - - if (pad_1 == null) { - var pad_size:int = hash.getPadSize(); - pad_1 = new ByteArray(); - pad_2 = new ByteArray(); - - for (var x:int = 0; x < pad_size; x++) { - pad_1.writeByte(0x36); - pad_2.writeByte(0x5c); - } - } - - // Do some preliminary checking on stuff - /* - if (key.length > hash.getInputSize()) { - hashKey = hash.hash(key); - } else { - hashKey = new ByteArray; - hashKey.writeBytes(key); - } - - while (hashKey.length < hash.getInputSize() ) { - hashKey[hashKey.length] = 0; - } */ - // Henri's conventions work just fine here.. - - innerKey.length = 0; - outerKey.length = 0; - // trace("MAC Key: " + Hex.fromArray(key)); - // trace("Key Length: " + key.length); - // trace("Pad_1 : " + Hex.fromArray(pad_1)); - // inner hash calc - innerKey.writeBytes(key); - innerKey.writeBytes(pad_1); - innerKey.writeBytes(data); - // trace("MAC Inner Key: " + Hex.fromArray(innerKey)); - - innerHash = hash.hash(innerKey); - // trace("MAC Inner Hash: " + Hex.fromArray(innerHash)); - - // outer hash calc - outerKey.writeBytes(key); - outerKey.writeBytes(pad_2); - outerKey.writeBytes(innerHash); - - // trace("MAC Outer Key: " + Hex.fromArray(outerKey)); - outerHash = hash.hash(outerKey); - - - if (bits > 0 && bits < 8*outerHash.length) { - outerHash.length = bits/8; - } - - // trace("MAC for record: " + Hex.fromArray(outerHash)); - return outerHash; - - } - - public function dispose():void { - hash = null; - bits = 0; - } - public function toString():String { - return "mac-"+(bits>0?bits+"-":"")+hash.toString(); - } - - } +/** + * MAC + * + * An ActionScript 3 implementation of MAC, Message Authentication Code + * for use with SSL 3.0. + * Loosely copyrighted by Bobby Parker. + * As3crypto copyrighted by Henri Torgemane. + * + * See LICENSE.txt for full license information. + */ +package com.hurlant.crypto.hash +{ + import flash.utils.ByteArray; + import com.hurlant.util.Hex; + + public class MAC implements IHMAC + { + private var hash:IHash; + private var bits:uint; + private var pad_1:ByteArray; + private var pad_2:ByteArray; + private var innerHash:ByteArray; + private var outerHash:ByteArray; + private var outerKey:ByteArray; + private var innerKey:ByteArray; + /** + * Create a MAC object (for SSL 3.0 ) and + * optionally a number of bits to return. + * The MAC will be truncated to that size if needed. + */ + public function MAC(hash:IHash, bits:uint=0) { + this.hash = hash; + this.bits = bits; + innerHash = new ByteArray(); + outerHash = new ByteArray(); + innerKey = new ByteArray(); + outerKey = new ByteArray(); + + + if (hash != null) { + var pad_size:int = hash.getPadSize(); + pad_1 = new ByteArray(); + pad_2 = new ByteArray(); + + for (var x:int = 0; x < pad_size; x++) { + pad_1.writeByte(0x36); + pad_2.writeByte(0x5c); + } + } + } + + public function setPadSize(pad_size:int) : void { } + + public function getHashSize():uint { + if (bits!=0) { + return bits/8; + } else { + return hash.getHashSize(); + } + } + + + /** + * Compute a MAC using a key and some data. + * + */ + public function compute(key:ByteArray, data:ByteArray):ByteArray { + // take that incoming key and do hash(key + pad_2 + hash(key + pad_1 + sequence + length + record) + // note that data = (sequence + type + length + record) + + if (pad_1 == null) { + var pad_size:int = hash.getPadSize(); + pad_1 = new ByteArray(); + pad_2 = new ByteArray(); + + for (var x:int = 0; x < pad_size; x++) { + pad_1.writeByte(0x36); + pad_2.writeByte(0x5c); + } + } + + // Do some preliminary checking on stuff + /* + if (key.length > hash.getInputSize()) { + hashKey = hash.hash(key); + } else { + hashKey = new ByteArray; + hashKey.writeBytes(key); + } + + while (hashKey.length < hash.getInputSize() ) { + hashKey[hashKey.length] = 0; + } */ + // Henri's conventions work just fine here.. + + innerKey.length = 0; + outerKey.length = 0; + // trace("MAC Key: " + Hex.fromArray(key)); + // trace("Key Length: " + key.length); + // trace("Pad_1 : " + Hex.fromArray(pad_1)); + // inner hash calc + innerKey.writeBytes(key); + innerKey.writeBytes(pad_1); + innerKey.writeBytes(data); + // trace("MAC Inner Key: " + Hex.fromArray(innerKey)); + + innerHash = hash.hash(innerKey); + // trace("MAC Inner Hash: " + Hex.fromArray(innerHash)); + + // outer hash calc + outerKey.writeBytes(key); + outerKey.writeBytes(pad_2); + outerKey.writeBytes(innerHash); + + // trace("MAC Outer Key: " + Hex.fromArray(outerKey)); + outerHash = hash.hash(outerKey); + + + if (bits > 0 && bits < 8*outerHash.length) { + outerHash.length = bits/8; + } + + // trace("MAC for record: " + Hex.fromArray(outerHash)); + return outerHash; + + } + + public function dispose():void { + hash = null; + bits = 0; + } + public function toString():String { + return "mac-"+(bits>0?bits+"-":"")+hash.toString(); + } + + } } \ No newline at end of file diff --git a/app/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/hash/MD2.as b/app/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/hash/MD2.as index d372df2..e104f0d 100644 --- a/app/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/hash/MD2.as +++ b/app/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/hash/MD2.as @@ -1,124 +1,124 @@ -/** - * MD2 - * - * An ActionScript 3 implementation of the RSA Data Security, Inc MD2 Message - * Digest Algorithm, as defined in RFC 1319 - * Copyright (c) 2007 Henri Torgemane - * - * See LICENSE.txt for full license information. - * - * Excerpt from http://en.wikipedia.org/wiki/MD2: - * > - * > Rogier and Chauvaud (1997) described collisions of MD2's compression function, - * > although they were unable to extend the attack to the full MD2. - * > - * > In 2004, MD2 was shown to be vulnerable to a preimage attack with time - * > complexity equivalent to 2104 applications of the compression function - * > (Muller, 2004). - * > The author concludes, "MD2 can no longer be considered a secure one-way - * > hash function". - * - * also, this implementaton is quite slow. - */ - -package com.hurlant.crypto.hash -{ - import flash.utils.ByteArray; - - public class MD2 implements IHash - { - public static const HASH_SIZE:int = 16; - public var pad_size:int = 48; // probably will never get used, only here for SSL 3.0 support - - private static const S:Array = [ // PI Digits - 41, 46, 67, 201, 162, 216, 124, 1, 61, 54, 84, 161, 236, 240, 6, 19, - 98, 167, 5, 243, 192, 199, 115, 140, 152, 147, 43, 217, 188, 76, 130, 202, - 30, 155, 87, 60, 253, 212, 224, 22, 103, 66, 111, 24, 138, 23, 229, 18, -190, 78, 196, 214, 218, 158, 222, 73, 160, 251, 245, 142, 187, 47, 238, 122, -169, 104, 121, 145, 21, 178, 7, 63, 148, 194, 16, 137, 11, 34, 95, 33, -128, 127, 93, 154, 90, 144, 50, 39, 53, 62, 204, 231, 191, 247, 151, 3, -255, 25, 48, 179, 72, 165, 181, 209, 215, 94, 146, 42, 172, 86, 170, 198, - 79, 184, 56, 210, 150, 164, 125, 182, 118, 252, 107, 226, 156, 116, 4, 241, - 69, 157, 112, 89, 100, 113, 135, 32, 134, 91, 207, 101, 230, 45, 168, 2, - 27, 96, 37, 173, 174, 176, 185, 246, 28, 70, 97, 105, 52, 64, 126, 15, - 85, 71, 163, 35, 221, 81, 175, 58, 195, 92, 249, 206, 186, 197, 234, 38, - 44, 83, 13, 110, 133, 40, 132, 9, 211, 223, 205, 244, 65, 129, 77, 82, -106, 220, 55, 200, 108, 193, 171, 250, 36, 225, 123, 8, 12, 189, 177, 74, -120, 136, 149, 139, 227, 99, 232, 109, 233, 203, 213, 254, 59, 0, 29, 57, -242, 239, 183, 14, 102, 88, 208, 228, 166, 119, 114, 248, 235, 117, 75, 10, - 49, 68, 80, 180, 143, 237, 31, 26, 219, 153, 141, 51, 159, 17, 131, 20 ]; - - - public function MD2() { } - - public function getInputSize():uint - { - return 16; - } - - public function getPadSize():int { - return pad_size; - } - - public function getHashSize():uint - { - return HASH_SIZE; - } - - public function hash(src:ByteArray):ByteArray - { - var savedLength:uint = src.length; - - // 3.1 Step 1. Padding - var i:uint = (16-src.length%16) || 16; - do { - src[src.length]=i; - } while (src.length%16!=0); - - // 3.2 Step 2. Checksum - var len:uint = src.length; - var checksum:ByteArray = new ByteArray; - var L:uint = 0; - for (i = 0;i + * > Rogier and Chauvaud (1997) described collisions of MD2's compression function, + * > although they were unable to extend the attack to the full MD2. + * > + * > In 2004, MD2 was shown to be vulnerable to a preimage attack with time + * > complexity equivalent to 2104 applications of the compression function + * > (Muller, 2004). + * > The author concludes, "MD2 can no longer be considered a secure one-way + * > hash function". + * + * also, this implementaton is quite slow. + */ + +package com.hurlant.crypto.hash +{ + import flash.utils.ByteArray; + + public class MD2 implements IHash + { + public static const HASH_SIZE:int = 16; + public var pad_size:int = 48; // probably will never get used, only here for SSL 3.0 support + + private static const S:Array = [ // PI Digits + 41, 46, 67, 201, 162, 216, 124, 1, 61, 54, 84, 161, 236, 240, 6, 19, + 98, 167, 5, 243, 192, 199, 115, 140, 152, 147, 43, 217, 188, 76, 130, 202, + 30, 155, 87, 60, 253, 212, 224, 22, 103, 66, 111, 24, 138, 23, 229, 18, +190, 78, 196, 214, 218, 158, 222, 73, 160, 251, 245, 142, 187, 47, 238, 122, +169, 104, 121, 145, 21, 178, 7, 63, 148, 194, 16, 137, 11, 34, 95, 33, +128, 127, 93, 154, 90, 144, 50, 39, 53, 62, 204, 231, 191, 247, 151, 3, +255, 25, 48, 179, 72, 165, 181, 209, 215, 94, 146, 42, 172, 86, 170, 198, + 79, 184, 56, 210, 150, 164, 125, 182, 118, 252, 107, 226, 156, 116, 4, 241, + 69, 157, 112, 89, 100, 113, 135, 32, 134, 91, 207, 101, 230, 45, 168, 2, + 27, 96, 37, 173, 174, 176, 185, 246, 28, 70, 97, 105, 52, 64, 126, 15, + 85, 71, 163, 35, 221, 81, 175, 58, 195, 92, 249, 206, 186, 197, 234, 38, + 44, 83, 13, 110, 133, 40, 132, 9, 211, 223, 205, 244, 65, 129, 77, 82, +106, 220, 55, 200, 108, 193, 171, 250, 36, 225, 123, 8, 12, 189, 177, 74, +120, 136, 149, 139, 227, 99, 232, 109, 233, 203, 213, 254, 59, 0, 29, 57, +242, 239, 183, 14, 102, 88, 208, 228, 166, 119, 114, 248, 235, 117, 75, 10, + 49, 68, 80, 180, 143, 237, 31, 26, 219, 153, 141, 51, 159, 17, 131, 20 ]; + + + public function MD2() { } + + public function getInputSize():uint + { + return 16; + } + + public function getPadSize():int { + return pad_size; + } + + public function getHashSize():uint + { + return HASH_SIZE; + } + + public function hash(src:ByteArray):ByteArray + { + var savedLength:uint = src.length; + + // 3.1 Step 1. Padding + var i:uint = (16-src.length%16) || 16; + do { + src[src.length]=i; + } while (src.length%16!=0); + + // 3.2 Step 2. Checksum + var len:uint = src.length; + var checksum:ByteArray = new ByteArray; + var L:uint = 0; + for (i = 0;i> 5] |= 0x80 << ((len) % 32); - x[(((len + 64) >>> 9) << 4) + 14] = len; - - var a:uint = 0x67452301; // 1732584193; - var b:uint = 0xEFCDAB89; //-271733879; - var c:uint = 0x98BADCFE; //-1732584194; - var d:uint = 0x10325476; // 271733878; - - for(var i:uint = 0; i < x.length; i += 16) - { - x[i]||=0; x[i+1]||=0; x[i+2]||=0; x[i+3]||=0; - x[i+4]||=0; x[i+5]||=0; x[i+6]||=0; x[i+7]||=0; - x[i+8]||=0; x[i+9]||=0; x[i+10]||=0; x[i+11]||=0; - x[i+12]||=0; x[i+13]||=0; x[i+14]||=0; x[i+15]||=0; - - var olda:uint = a; - var oldb:uint = b; - var oldc:uint = c; - var oldd:uint = d; - - a = ff(a, b, c, d, x[i+ 0], 7 , 0xD76AA478); - d = ff(d, a, b, c, x[i+ 1], 12, 0xE8C7B756); - c = ff(c, d, a, b, x[i+ 2], 17, 0x242070DB); - b = ff(b, c, d, a, x[i+ 3], 22, 0xC1BDCEEE); - a = ff(a, b, c, d, x[i+ 4], 7 , 0xF57C0FAF); - d = ff(d, a, b, c, x[i+ 5], 12, 0x4787C62A); - c = ff(c, d, a, b, x[i+ 6], 17, 0xA8304613); - b = ff(b, c, d, a, x[i+ 7], 22, 0xFD469501); - a = ff(a, b, c, d, x[i+ 8], 7 , 0x698098D8); - d = ff(d, a, b, c, x[i+ 9], 12, 0x8B44F7AF); - c = ff(c, d, a, b, x[i+10], 17, 0xFFFF5BB1); - b = ff(b, c, d, a, x[i+11], 22, 0x895CD7BE); - a = ff(a, b, c, d, x[i+12], 7 , 0x6B901122); - d = ff(d, a, b, c, x[i+13], 12, 0xFD987193); - c = ff(c, d, a, b, x[i+14], 17, 0xA679438E); - b = ff(b, c, d, a, x[i+15], 22, 0x49B40821); - - a = gg(a, b, c, d, x[i+ 1], 5 , 0xf61e2562); - d = gg(d, a, b, c, x[i+ 6], 9 , 0xc040b340); - c = gg(c, d, a, b, x[i+11], 14, 0x265e5a51); - b = gg(b, c, d, a, x[i+ 0], 20, 0xe9b6c7aa); - a = gg(a, b, c, d, x[i+ 5], 5 , 0xd62f105d); - d = gg(d, a, b, c, x[i+10], 9 , 0x2441453); - c = gg(c, d, a, b, x[i+15], 14, 0xd8a1e681); - b = gg(b, c, d, a, x[i+ 4], 20, 0xe7d3fbc8); - a = gg(a, b, c, d, x[i+ 9], 5 , 0x21e1cde6); - d = gg(d, a, b, c, x[i+14], 9 , 0xc33707d6); - c = gg(c, d, a, b, x[i+ 3], 14, 0xf4d50d87); - b = gg(b, c, d, a, x[i+ 8], 20, 0x455a14ed); - a = gg(a, b, c, d, x[i+13], 5 , 0xa9e3e905); - d = gg(d, a, b, c, x[i+ 2], 9 , 0xfcefa3f8); - c = gg(c, d, a, b, x[i+ 7], 14, 0x676f02d9); - b = gg(b, c, d, a, x[i+12], 20, 0x8d2a4c8a); - - a = hh(a, b, c, d, x[i+ 5], 4 , 0xfffa3942); - d = hh(d, a, b, c, x[i+ 8], 11, 0x8771f681); - c = hh(c, d, a, b, x[i+11], 16, 0x6d9d6122); - b = hh(b, c, d, a, x[i+14], 23, 0xfde5380c); - a = hh(a, b, c, d, x[i+ 1], 4 , 0xa4beea44); - d = hh(d, a, b, c, x[i+ 4], 11, 0x4bdecfa9); - c = hh(c, d, a, b, x[i+ 7], 16, 0xf6bb4b60); - b = hh(b, c, d, a, x[i+10], 23, 0xbebfbc70); - a = hh(a, b, c, d, x[i+13], 4 , 0x289b7ec6); - d = hh(d, a, b, c, x[i+ 0], 11, 0xeaa127fa); - c = hh(c, d, a, b, x[i+ 3], 16, 0xd4ef3085); - b = hh(b, c, d, a, x[i+ 6], 23, 0x4881d05); - a = hh(a, b, c, d, x[i+ 9], 4 , 0xd9d4d039); - d = hh(d, a, b, c, x[i+12], 11, 0xe6db99e5); - c = hh(c, d, a, b, x[i+15], 16, 0x1fa27cf8); - b = hh(b, c, d, a, x[i+ 2], 23, 0xc4ac5665); - - a = ii(a, b, c, d, x[i+ 0], 6 , 0xf4292244); - d = ii(d, a, b, c, x[i+ 7], 10, 0x432aff97); - c = ii(c, d, a, b, x[i+14], 15, 0xab9423a7); - b = ii(b, c, d, a, x[i+ 5], 21, 0xfc93a039); - a = ii(a, b, c, d, x[i+12], 6 , 0x655b59c3); - d = ii(d, a, b, c, x[i+ 3], 10, 0x8f0ccc92); - c = ii(c, d, a, b, x[i+10], 15, 0xffeff47d); - b = ii(b, c, d, a, x[i+ 1], 21, 0x85845dd1); - a = ii(a, b, c, d, x[i+ 8], 6 , 0x6fa87e4f); - d = ii(d, a, b, c, x[i+15], 10, 0xfe2ce6e0); - c = ii(c, d, a, b, x[i+ 6], 15, 0xa3014314); - b = ii(b, c, d, a, x[i+13], 21, 0x4e0811a1); - a = ii(a, b, c, d, x[i+ 4], 6 , 0xf7537e82); - d = ii(d, a, b, c, x[i+11], 10, 0xbd3af235); - c = ii(c, d, a, b, x[i+ 2], 15, 0x2ad7d2bb); - b = ii(b, c, d, a, x[i+ 9], 21, 0xeb86d391); - - a += olda; - b += oldb; - c += oldc; - d += oldd; - - } - return [ a, b, c, d ]; - } - - /* - * Bitwise rotate a 32-bit number to the left. - */ - private function rol(num:uint, cnt:uint):uint - { - return (num << cnt) | (num >>> (32 - cnt)); - } - - /* - * These functions implement the four basic operations the algorithm uses. - */ - private function cmn(q:uint, a:uint, b:uint, x:uint, s:uint, t:uint):uint { - return rol(a + q + x + t, s) + b; - } - private function ff(a:uint, b:uint, c:uint, d:uint, x:uint, s:uint, t:uint):uint { - return cmn((b & c) | ((~b) & d), a, b, x, s, t); - } - private function gg(a:uint, b:uint, c:uint, d:uint, x:uint, s:uint, t:uint):uint { - return cmn((b & d) | (c & (~d)), a, b, x, s, t); - } - private function hh(a:uint, b:uint, c:uint, d:uint, x:uint, s:uint, t:uint):uint { - return cmn(b ^ c ^ d, a, b, x, s, t); - } - private function ii(a:uint, b:uint, c:uint, d:uint, x:uint, s:uint, t:uint):uint { - return cmn(c ^ (b | (~d)), a, b, x, s, t); - } - - public function toString():String { - return "md5"; - } - } -} +/** + * MD5 + * + * An ActionScript 3 implementation of the RSA Data Security, Inc. MD5 Message + * Digest Algorithm, as defined in RFC 1321. + * Copyright (c) 2007 Henri Torgemane + * + * Derived from + * A JavaScript implementation of the same. + * Version 2.1 Copyright (C) Paul Johnston 1999 - 2002. + * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet + * + * Note: + * This algorithm should not be your first choice for new developements, but is + * included to allow interoperability with existing codes and protocols. + * + * See LICENSE.txt for full license information. + */ +package com.hurlant.crypto.hash +{ + import flash.utils.ByteArray; + import flash.utils.Endian; + + public class MD5 implements IHash + { + public static const HASH_SIZE:int = 16; + public var pad_size:int = 48; + + public function MD5() { } + + public function getInputSize():uint + { + return 64; + } + + public function getHashSize():uint + { + return HASH_SIZE; + } + + public function getPadSize():int + { + return pad_size; + } + + public function hash(src:ByteArray):ByteArray + { + var len:uint = src.length *8; + var savedEndian:String = src.endian; + // pad to nearest int. + while (src.length%4!=0) { + src[src.length]=0; + } + // convert ByteArray to an array of uint + src.position=0; + var a:Array = []; + src.endian=Endian.LITTLE_ENDIAN + for (var i:uint=0;i> 5] |= 0x80 << ((len) % 32); + x[(((len + 64) >>> 9) << 4) + 14] = len; + + var a:uint = 0x67452301; // 1732584193; + var b:uint = 0xEFCDAB89; //-271733879; + var c:uint = 0x98BADCFE; //-1732584194; + var d:uint = 0x10325476; // 271733878; + + for(var i:uint = 0; i < x.length; i += 16) + { + x[i]||=0; x[i+1]||=0; x[i+2]||=0; x[i+3]||=0; + x[i+4]||=0; x[i+5]||=0; x[i+6]||=0; x[i+7]||=0; + x[i+8]||=0; x[i+9]||=0; x[i+10]||=0; x[i+11]||=0; + x[i+12]||=0; x[i+13]||=0; x[i+14]||=0; x[i+15]||=0; + + var olda:uint = a; + var oldb:uint = b; + var oldc:uint = c; + var oldd:uint = d; + + a = ff(a, b, c, d, x[i+ 0], 7 , 0xD76AA478); + d = ff(d, a, b, c, x[i+ 1], 12, 0xE8C7B756); + c = ff(c, d, a, b, x[i+ 2], 17, 0x242070DB); + b = ff(b, c, d, a, x[i+ 3], 22, 0xC1BDCEEE); + a = ff(a, b, c, d, x[i+ 4], 7 , 0xF57C0FAF); + d = ff(d, a, b, c, x[i+ 5], 12, 0x4787C62A); + c = ff(c, d, a, b, x[i+ 6], 17, 0xA8304613); + b = ff(b, c, d, a, x[i+ 7], 22, 0xFD469501); + a = ff(a, b, c, d, x[i+ 8], 7 , 0x698098D8); + d = ff(d, a, b, c, x[i+ 9], 12, 0x8B44F7AF); + c = ff(c, d, a, b, x[i+10], 17, 0xFFFF5BB1); + b = ff(b, c, d, a, x[i+11], 22, 0x895CD7BE); + a = ff(a, b, c, d, x[i+12], 7 , 0x6B901122); + d = ff(d, a, b, c, x[i+13], 12, 0xFD987193); + c = ff(c, d, a, b, x[i+14], 17, 0xA679438E); + b = ff(b, c, d, a, x[i+15], 22, 0x49B40821); + + a = gg(a, b, c, d, x[i+ 1], 5 , 0xf61e2562); + d = gg(d, a, b, c, x[i+ 6], 9 , 0xc040b340); + c = gg(c, d, a, b, x[i+11], 14, 0x265e5a51); + b = gg(b, c, d, a, x[i+ 0], 20, 0xe9b6c7aa); + a = gg(a, b, c, d, x[i+ 5], 5 , 0xd62f105d); + d = gg(d, a, b, c, x[i+10], 9 , 0x2441453); + c = gg(c, d, a, b, x[i+15], 14, 0xd8a1e681); + b = gg(b, c, d, a, x[i+ 4], 20, 0xe7d3fbc8); + a = gg(a, b, c, d, x[i+ 9], 5 , 0x21e1cde6); + d = gg(d, a, b, c, x[i+14], 9 , 0xc33707d6); + c = gg(c, d, a, b, x[i+ 3], 14, 0xf4d50d87); + b = gg(b, c, d, a, x[i+ 8], 20, 0x455a14ed); + a = gg(a, b, c, d, x[i+13], 5 , 0xa9e3e905); + d = gg(d, a, b, c, x[i+ 2], 9 , 0xfcefa3f8); + c = gg(c, d, a, b, x[i+ 7], 14, 0x676f02d9); + b = gg(b, c, d, a, x[i+12], 20, 0x8d2a4c8a); + + a = hh(a, b, c, d, x[i+ 5], 4 , 0xfffa3942); + d = hh(d, a, b, c, x[i+ 8], 11, 0x8771f681); + c = hh(c, d, a, b, x[i+11], 16, 0x6d9d6122); + b = hh(b, c, d, a, x[i+14], 23, 0xfde5380c); + a = hh(a, b, c, d, x[i+ 1], 4 , 0xa4beea44); + d = hh(d, a, b, c, x[i+ 4], 11, 0x4bdecfa9); + c = hh(c, d, a, b, x[i+ 7], 16, 0xf6bb4b60); + b = hh(b, c, d, a, x[i+10], 23, 0xbebfbc70); + a = hh(a, b, c, d, x[i+13], 4 , 0x289b7ec6); + d = hh(d, a, b, c, x[i+ 0], 11, 0xeaa127fa); + c = hh(c, d, a, b, x[i+ 3], 16, 0xd4ef3085); + b = hh(b, c, d, a, x[i+ 6], 23, 0x4881d05); + a = hh(a, b, c, d, x[i+ 9], 4 , 0xd9d4d039); + d = hh(d, a, b, c, x[i+12], 11, 0xe6db99e5); + c = hh(c, d, a, b, x[i+15], 16, 0x1fa27cf8); + b = hh(b, c, d, a, x[i+ 2], 23, 0xc4ac5665); + + a = ii(a, b, c, d, x[i+ 0], 6 , 0xf4292244); + d = ii(d, a, b, c, x[i+ 7], 10, 0x432aff97); + c = ii(c, d, a, b, x[i+14], 15, 0xab9423a7); + b = ii(b, c, d, a, x[i+ 5], 21, 0xfc93a039); + a = ii(a, b, c, d, x[i+12], 6 , 0x655b59c3); + d = ii(d, a, b, c, x[i+ 3], 10, 0x8f0ccc92); + c = ii(c, d, a, b, x[i+10], 15, 0xffeff47d); + b = ii(b, c, d, a, x[i+ 1], 21, 0x85845dd1); + a = ii(a, b, c, d, x[i+ 8], 6 , 0x6fa87e4f); + d = ii(d, a, b, c, x[i+15], 10, 0xfe2ce6e0); + c = ii(c, d, a, b, x[i+ 6], 15, 0xa3014314); + b = ii(b, c, d, a, x[i+13], 21, 0x4e0811a1); + a = ii(a, b, c, d, x[i+ 4], 6 , 0xf7537e82); + d = ii(d, a, b, c, x[i+11], 10, 0xbd3af235); + c = ii(c, d, a, b, x[i+ 2], 15, 0x2ad7d2bb); + b = ii(b, c, d, a, x[i+ 9], 21, 0xeb86d391); + + a += olda; + b += oldb; + c += oldc; + d += oldd; + + } + return [ a, b, c, d ]; + } + + /* + * Bitwise rotate a 32-bit number to the left. + */ + private function rol(num:uint, cnt:uint):uint + { + return (num << cnt) | (num >>> (32 - cnt)); + } + + /* + * These functions implement the four basic operations the algorithm uses. + */ + private function cmn(q:uint, a:uint, b:uint, x:uint, s:uint, t:uint):uint { + return rol(a + q + x + t, s) + b; + } + private function ff(a:uint, b:uint, c:uint, d:uint, x:uint, s:uint, t:uint):uint { + return cmn((b & c) | ((~b) & d), a, b, x, s, t); + } + private function gg(a:uint, b:uint, c:uint, d:uint, x:uint, s:uint, t:uint):uint { + return cmn((b & d) | (c & (~d)), a, b, x, s, t); + } + private function hh(a:uint, b:uint, c:uint, d:uint, x:uint, s:uint, t:uint):uint { + return cmn(b ^ c ^ d, a, b, x, s, t); + } + private function ii(a:uint, b:uint, c:uint, d:uint, x:uint, s:uint, t:uint):uint { + return cmn(c ^ (b | (~d)), a, b, x, s, t); + } + + public function toString():String { + return "md5"; + } + } +} diff --git a/app/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/hash/SHA1.as b/app/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/hash/SHA1.as index fc75835..5b186f3 100644 --- a/app/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/hash/SHA1.as +++ b/app/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/hash/SHA1.as @@ -1,106 +1,106 @@ -/** - * SHA1 - * - * An ActionScript 3 implementation of Secure Hash Algorithm, SHA-1, as defined - * in FIPS PUB 180-1 - * Copyright (c) 2007 Henri Torgemane - * - * Derived from: - * A JavaScript implementation of the Secure Hash Algorithm, SHA-1, as defined - * in FIPS PUB 180-1 - * Version 2.1a Copyright Paul Johnston 2000 - 2002. - * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet - * - * See LICENSE.txt for full license information. - */ -package com.hurlant.crypto.hash -{ - - - public class SHA1 extends SHABase implements IHash - { - public static const HASH_SIZE:int = 20; - - public override function getHashSize():uint { - return HASH_SIZE; - } - - protected override function core(x:Array, len:uint):Array - { - /* append padding */ - x[len >> 5] |= 0x80 << (24 - len % 32); - x[((len + 64 >> 9) << 4) + 15] = len; - - var w:Array = []; - var a:uint = 0x67452301; //1732584193; - var b:uint = 0xEFCDAB89; //-271733879; - var c:uint = 0x98BADCFE; //-1732584194; - var d:uint = 0x10325476; //271733878; - var e:uint = 0xC3D2E1F0; //-1009589776; - - for(var i:uint = 0; i < x.length; i += 16) - { - - var olda:uint = a; - var oldb:uint = b; - var oldc:uint = c; - var oldd:uint = d; - var olde:uint = e; - - for(var j:uint = 0; j < 80; j++) - { - if (j < 16) { - w[j] = x[i + j] || 0; - } else { - w[j] = rol(w[j-3] ^ w[j-8] ^ w[j-14] ^ w[j-16], 1); - } - var t:uint = rol(a,5) + ft(j,b,c,d) + e + w[j] + kt(j); - e = d; - d = c; - c = rol(b, 30); - b = a; - a = t; - } - a += olda; - b += oldb; - c += oldc; - d += oldd; - e += olde; - } - return [ a, b, c, d, e ]; - - } - - /* - * Bitwise rotate a 32-bit number to the left. - */ - private function rol(num:uint, cnt:uint):uint - { - return (num << cnt) | (num >>> (32 - cnt)); - } - - /* - * Perform the appropriate triplet combination function for the current - * iteration - */ - private function ft(t:uint, b:uint, c:uint, d:uint):uint - { - if(t < 20) return (b & c) | ((~b) & d); - if(t < 40) return b ^ c ^ d; - if(t < 60) return (b & c) | (b & d) | (c & d); - return b ^ c ^ d; - } - - /* - * Determine the appropriate additive constant for the current iteration - */ - private function kt(t:uint):uint - { - return (t < 20) ? 0x5A827999 : (t < 40) ? 0x6ED9EBA1 : - (t < 60) ? 0x8F1BBCDC : 0xCA62C1D6; - } - public override function toString():String { - return "sha1"; - } - } -} +/** + * SHA1 + * + * An ActionScript 3 implementation of Secure Hash Algorithm, SHA-1, as defined + * in FIPS PUB 180-1 + * Copyright (c) 2007 Henri Torgemane + * + * Derived from: + * A JavaScript implementation of the Secure Hash Algorithm, SHA-1, as defined + * in FIPS PUB 180-1 + * Version 2.1a Copyright Paul Johnston 2000 - 2002. + * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet + * + * See LICENSE.txt for full license information. + */ +package com.hurlant.crypto.hash +{ + + + public class SHA1 extends SHABase implements IHash + { + public static const HASH_SIZE:int = 20; + + public override function getHashSize():uint { + return HASH_SIZE; + } + + protected override function core(x:Array, len:uint):Array + { + /* append padding */ + x[len >> 5] |= 0x80 << (24 - len % 32); + x[((len + 64 >> 9) << 4) + 15] = len; + + var w:Array = []; + var a:uint = 0x67452301; //1732584193; + var b:uint = 0xEFCDAB89; //-271733879; + var c:uint = 0x98BADCFE; //-1732584194; + var d:uint = 0x10325476; //271733878; + var e:uint = 0xC3D2E1F0; //-1009589776; + + for(var i:uint = 0; i < x.length; i += 16) + { + + var olda:uint = a; + var oldb:uint = b; + var oldc:uint = c; + var oldd:uint = d; + var olde:uint = e; + + for(var j:uint = 0; j < 80; j++) + { + if (j < 16) { + w[j] = x[i + j] || 0; + } else { + w[j] = rol(w[j-3] ^ w[j-8] ^ w[j-14] ^ w[j-16], 1); + } + var t:uint = rol(a,5) + ft(j,b,c,d) + e + w[j] + kt(j); + e = d; + d = c; + c = rol(b, 30); + b = a; + a = t; + } + a += olda; + b += oldb; + c += oldc; + d += oldd; + e += olde; + } + return [ a, b, c, d, e ]; + + } + + /* + * Bitwise rotate a 32-bit number to the left. + */ + private function rol(num:uint, cnt:uint):uint + { + return (num << cnt) | (num >>> (32 - cnt)); + } + + /* + * Perform the appropriate triplet combination function for the current + * iteration + */ + private function ft(t:uint, b:uint, c:uint, d:uint):uint + { + if(t < 20) return (b & c) | ((~b) & d); + if(t < 40) return b ^ c ^ d; + if(t < 60) return (b & c) | (b & d) | (c & d); + return b ^ c ^ d; + } + + /* + * Determine the appropriate additive constant for the current iteration + */ + private function kt(t:uint):uint + { + return (t < 20) ? 0x5A827999 : (t < 40) ? 0x6ED9EBA1 : + (t < 60) ? 0x8F1BBCDC : 0xCA62C1D6; + } + public override function toString():String { + return "sha1"; + } + } +} diff --git a/app/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/hash/SHA224.as b/app/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/hash/SHA224.as index c8e542e..345aa3d 100644 --- a/app/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/hash/SHA224.as +++ b/app/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/hash/SHA224.as @@ -1,28 +1,28 @@ -/** - * SHA224 - * - * An ActionScript 3 implementation of Secure Hash Algorithm, SHA-224, as defined - * in FIPS PUB 180-2 - * Copyright (c) 2007 Henri Torgemane - * - * See LICENSE.txt for full license information. - */ -package com.hurlant.crypto.hash -{ - public class SHA224 extends SHA256 - { - function SHA224() { - h = [ - 0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939, - 0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4 - ]; - } - - public override function getHashSize():uint { - return 28; - } - public override function toString():String { - return "sha224"; - } - } +/** + * SHA224 + * + * An ActionScript 3 implementation of Secure Hash Algorithm, SHA-224, as defined + * in FIPS PUB 180-2 + * Copyright (c) 2007 Henri Torgemane + * + * See LICENSE.txt for full license information. + */ +package com.hurlant.crypto.hash +{ + public class SHA224 extends SHA256 + { + function SHA224() { + h = [ + 0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939, + 0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4 + ]; + } + + public override function getHashSize():uint { + return 28; + } + public override function toString():String { + return "sha224"; + } + } } \ No newline at end of file diff --git a/app/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/hash/SHA256.as b/app/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/hash/SHA256.as index ae8df1d..67bdbb4 100644 --- a/app/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/hash/SHA256.as +++ b/app/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/hash/SHA256.as @@ -1,115 +1,115 @@ -/** - * SHA256 - * - * An ActionScript 3 implementation of Secure Hash Algorithm, SHA-256, as defined - * in FIPS PUB 180-2 - * Copyright (c) 2007 Henri Torgemane - * - * Derived from: - * A JavaScript implementation of the Secure Hash Standard - * Version 0.3 Copyright Angel Marin 2003-2004 - http://anmar.eu.org/ - * Derived from: - * A JavaScript implementation of the Secure Hash Algorithm, SHA-1, as defined - * in FIPS PUB 180-1 - * Version 2.1a Copyright Paul Johnston 2000 - 2002. - * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet - * - * See LICENSE.txt for full license information. - */ -package com.hurlant.crypto.hash -{ - - - public class SHA256 extends SHABase implements IHash - { - - protected static const k:Array = [ - 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, - 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, - 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, - 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, - 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, - 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, - 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, - 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2]; - protected var h:Array = [ - 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19 - ]; - - public function SHA256(){ - } - - public override function getHashSize():uint - { - return 32; - } - - protected override function core(x:Array, len:uint):Array { - /* append padding */ - x[len >> 5] |= 0x80 << (24 - len % 32); - x[((len + 64 >> 9) << 4) + 15] = len; - - var w:Array = []; - var a:uint = h[0]; - var b:uint = h[1]; - var c:uint = h[2]; - var d:uint = h[3]; - var e:uint = h[4]; - var f:uint = h[5]; - var g:uint = h[6]; - var h:uint = h[7]; - - for (var i:uint=0; i>>3); - var s1:uint = rrol(w[j-2], 17)^rrol(w[j-2],19)^(w[j-2]>>>10); - w[j] = w[j-16] + s0 + w[j-7] + s1; - } - var t2:uint = (rrol(a,2) ^ rrol(a,13) ^ rrol(a,22)) + ((a&b) ^ (a&c) ^ (b&c)); - var t1:uint = h + (rrol(e,6) ^ rrol(e,11) ^ rrol(e,25)) + ((e&f)^(g&~e)) + k[j] + w[j] - h = g; - g = f; - f = e; - e = d + t1; - d = c; - c = b; - b = a; - a = t1 + t2; - - } - a += olda; - b += oldb; - c += oldc; - d += oldd; - e += olde; - f += oldf; - g += oldg; - h += oldh; - } - return [ a,b,c,d,e,f,g,h ]; - } - - /* - * Bitwise rotate a 32-bit number to the right. - */ - protected function rrol(num:uint, cnt:uint):uint { - return (num << (32-cnt)) | (num >>> cnt); - } - - public override function toString():String { - return "sha256"; - } - } +/** + * SHA256 + * + * An ActionScript 3 implementation of Secure Hash Algorithm, SHA-256, as defined + * in FIPS PUB 180-2 + * Copyright (c) 2007 Henri Torgemane + * + * Derived from: + * A JavaScript implementation of the Secure Hash Standard + * Version 0.3 Copyright Angel Marin 2003-2004 - http://anmar.eu.org/ + * Derived from: + * A JavaScript implementation of the Secure Hash Algorithm, SHA-1, as defined + * in FIPS PUB 180-1 + * Version 2.1a Copyright Paul Johnston 2000 - 2002. + * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet + * + * See LICENSE.txt for full license information. + */ +package com.hurlant.crypto.hash +{ + + + public class SHA256 extends SHABase implements IHash + { + + protected static const k:Array = [ + 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, + 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, + 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, + 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, + 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, + 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, + 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, + 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2]; + protected var h:Array = [ + 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19 + ]; + + public function SHA256(){ + } + + public override function getHashSize():uint + { + return 32; + } + + protected override function core(x:Array, len:uint):Array { + /* append padding */ + x[len >> 5] |= 0x80 << (24 - len % 32); + x[((len + 64 >> 9) << 4) + 15] = len; + + var w:Array = []; + var a:uint = h[0]; + var b:uint = h[1]; + var c:uint = h[2]; + var d:uint = h[3]; + var e:uint = h[4]; + var f:uint = h[5]; + var g:uint = h[6]; + var h:uint = h[7]; + + for (var i:uint=0; i>>3); + var s1:uint = rrol(w[j-2], 17)^rrol(w[j-2],19)^(w[j-2]>>>10); + w[j] = w[j-16] + s0 + w[j-7] + s1; + } + var t2:uint = (rrol(a,2) ^ rrol(a,13) ^ rrol(a,22)) + ((a&b) ^ (a&c) ^ (b&c)); + var t1:uint = h + (rrol(e,6) ^ rrol(e,11) ^ rrol(e,25)) + ((e&f)^(g&~e)) + k[j] + w[j] + h = g; + g = f; + f = e; + e = d + t1; + d = c; + c = b; + b = a; + a = t1 + t2; + + } + a += olda; + b += oldb; + c += oldc; + d += oldd; + e += olde; + f += oldf; + g += oldg; + h += oldh; + } + return [ a,b,c,d,e,f,g,h ]; + } + + /* + * Bitwise rotate a 32-bit number to the right. + */ + protected function rrol(num:uint, cnt:uint):uint { + return (num << (32-cnt)) | (num >>> cnt); + } + + public override function toString():String { + return "sha256"; + } + } } \ No newline at end of file diff --git a/app/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/hash/SHABase.as b/app/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/hash/SHABase.as index cd39d4e..dc9bafe 100644 --- a/app/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/hash/SHABase.as +++ b/app/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/hash/SHABase.as @@ -1,71 +1,71 @@ -/** - * SHABase - * - * An ActionScript 3 abstract class for the SHA family of hash functions - * Copyright (c) 2007 Henri Torgemane - * - * See LICENSE.txt for full license information. - */ -package com.hurlant.crypto.hash -{ - import flash.utils.ByteArray; - import flash.utils.Endian; - - public class SHABase implements IHash - { - - public function SHABase() { } - - public var pad_size:int = 40; - public function getInputSize():uint - { - return 64; - } - - public function getHashSize():uint - { - return 0; - } - - public function getPadSize():int - { - return pad_size; - } - - public function hash(src:ByteArray):ByteArray - { - var savedLength:uint = src.length; - var savedEndian:String = src.endian; - - src.endian = Endian.BIG_ENDIAN; - var len:uint = savedLength *8; - // pad to nearest int. - while (src.length%4!=0) { - src[src.length]=0; - } - // convert ByteArray to an array of uint - src.position=0; - var a:Array = []; - for (var i:uint=0;i>> 8; - pool[pptr++] = t&255; - } - pptr=0; - seed(); - } - - public function seed(x:int = 0):void { - if (x==0) { - x = new Date().getTime(); - } - pool[pptr++] ^= x & 255; - pool[pptr++] ^= (x>>8)&255; - pool[pptr++] ^= (x>>16)&255; - pool[pptr++] ^= (x>>24)&255; - pptr %= psize; - seeded = true; - } - - /** - * Gather anything we have that isn't entirely predictable: - * - memory used - * - system capabilities - * - timing stuff - * - installed fonts - */ - public function autoSeed():void { - var b:ByteArray = new ByteArray; - b.writeUnsignedInt(System.totalMemory); - b.writeUTF(Capabilities.serverString); - b.writeUnsignedInt(getTimer()); - b.writeUnsignedInt((new Date).getTime()); - var a:Array = Font.enumerateFonts(true); - for each (var f:Font in a) { - b.writeUTF(f.fontName); - b.writeUTF(f.fontStyle); - b.writeUTF(f.fontType); - } - b.position=0; - while (b.bytesAvailable>=4) { - seed(b.readUnsignedInt()); - } - } - - - public function nextBytes(buffer:ByteArray, length:int):void { - while (length--) { - buffer.writeByte(nextByte()); - } - } - public function nextByte():int { - if (!ready) { - if (!seeded) { - autoSeed(); - } - state.init(pool); - pool.length = 0; - pptr = 0; - ready = true; - } - return state.next(); - } - public function dispose():void { - for (var i:uint=0;i>> 8; + pool[pptr++] = t&255; + } + pptr=0; + seed(); + } + + public function seed(x:int = 0):void { + if (x==0) { + x = new Date().getTime(); + } + pool[pptr++] ^= x & 255; + pool[pptr++] ^= (x>>8)&255; + pool[pptr++] ^= (x>>16)&255; + pool[pptr++] ^= (x>>24)&255; + pptr %= psize; + seeded = true; + } + + /** + * Gather anything we have that isn't entirely predictable: + * - memory used + * - system capabilities + * - timing stuff + * - installed fonts + */ + public function autoSeed():void { + var b:ByteArray = new ByteArray; + b.writeUnsignedInt(System.totalMemory); + b.writeUTF(Capabilities.serverString); + b.writeUnsignedInt(getTimer()); + b.writeUnsignedInt((new Date).getTime()); + var a:Array = Font.enumerateFonts(true); + for each (var f:Font in a) { + b.writeUTF(f.fontName); + b.writeUTF(f.fontStyle); + b.writeUTF(f.fontType); + } + b.position=0; + while (b.bytesAvailable>=4) { + seed(b.readUnsignedInt()); + } + } + + + public function nextBytes(buffer:ByteArray, length:int):void { + while (length--) { + buffer.writeByte(nextByte()); + } + } + public function nextByte():int { + if (!ready) { + if (!seeded) { + autoSeed(); + } + state.init(pool); + pool.length = 0; + pptr = 0; + ready = true; + } + return state.next(); + } + public function dispose():void { + for (var i:uint=0;i 6 && idx % Nk == 4 ) { - tmp0 = Sbox[tmp0]; - tmp1 = Sbox[tmp1]; - tmp2 = Sbox[tmp2]; - tmp3 = Sbox[tmp3]; - } - - key[4*idx+0] = key[4*idx - 4*Nk + 0] ^ tmp0; - key[4*idx+1] = key[4*idx - 4*Nk + 1] ^ tmp1; - key[4*idx+2] = key[4*idx - 4*Nk + 2] ^ tmp2; - key[4*idx+3] = key[4*idx - 4*Nk + 3] ^ tmp3; - } - } - - - public function getBlockSize():uint - { - return 16; - } - - // encrypt one 128 bit block - public function encrypt(block:ByteArray, index:uint=0):void - { - var round:uint; - state.position=0; - state.writeBytes(block, index, Nb*4); - - addRoundKey(key, 0); - for ( round = 1; round < Nr + 1; round++ ) { - if (round < Nr) { - mixSubColumns(); - } else { - shiftRows(); - } - addRoundKey(key, round * Nb * 4); - } - - block.position=index; - block.writeBytes(state); - } - - public function decrypt(block:ByteArray, index:uint=0):void - { - var round:uint; - state.position=0; - state.writeBytes(block, index, Nb*4); - - addRoundKey(key, Nr*Nb*4); - invShiftRows(); - for( round = Nr; round--; ) - { - addRoundKey( key, round*Nb*4); - if (round) { - invMixSubColumns(); - } - } - - block.position=index; - block.writeBytes(state); - } - - public function dispose():void { - var i:uint; - var r:Random = new Random; - for (i=0;i 6 && idx % Nk == 4 ) { + tmp0 = Sbox[tmp0]; + tmp1 = Sbox[tmp1]; + tmp2 = Sbox[tmp2]; + tmp3 = Sbox[tmp3]; + } + + key[4*idx+0] = key[4*idx - 4*Nk + 0] ^ tmp0; + key[4*idx+1] = key[4*idx - 4*Nk + 1] ^ tmp1; + key[4*idx+2] = key[4*idx - 4*Nk + 2] ^ tmp2; + key[4*idx+3] = key[4*idx - 4*Nk + 3] ^ tmp3; + } + } + + + public function getBlockSize():uint + { + return 16; + } + + // encrypt one 128 bit block + public function encrypt(block:ByteArray, index:uint=0):void + { + var round:uint; + state.position=0; + state.writeBytes(block, index, Nb*4); + + addRoundKey(key, 0); + for ( round = 1; round < Nr + 1; round++ ) { + if (round < Nr) { + mixSubColumns(); + } else { + shiftRows(); + } + addRoundKey(key, round * Nb * 4); + } + + block.position=index; + block.writeBytes(state); + } + + public function decrypt(block:ByteArray, index:uint=0):void + { + var round:uint; + state.position=0; + state.writeBytes(block, index, Nb*4); + + addRoundKey(key, Nr*Nb*4); + invShiftRows(); + for( round = Nr; round--; ) + { + addRoundKey( key, round*Nb*4); + if (round) { + invMixSubColumns(); + } + } + + block.position=index; + block.writeBytes(state); + } + + public function dispose():void { + var i:uint; + var r:Random = new Random; + for (i=0;i>> 24)] + S1[(x >>> 16) & 0xff]) ^ S2[(x >>> 8) & 0xff]) + S3[x & 0xff]); - } - - /** - * apply the encryption cycle to each value pair in the table. - */ - private function processTable(xl:uint, xr:uint, table:Array):void - { - var size:uint = table.length; - - for (var s:uint = 0; s < size; s += 2) - { - xl ^= P[0]; - - for (var i:uint = 1; i < ROUNDS; i += 2) - { - xr ^= F(xl) ^ P[i]; - xl ^= F(xr) ^ P[i + 1]; - } - - xr ^= P[ROUNDS + 1]; - - table[s] = xr; - table[s + 1] = xl; - - xr = xl; // end of cycle swap - xl = table[s]; - } - } - - private function setKey(key:ByteArray):void - { - /* - * - comments are from _Applied Crypto_, Schneier, p338 please be - * careful comparing the two, AC numbers the arrays from 1, the enclosed - * code from 0. - * - * (1) Initialise the S-boxes and the P-array, with a fixed string This - * string contains the hexadecimal digits of pi (3.141...) - */ - S0 = KS0.concat(); - S1 = KS1.concat(); - S2 = KS2.concat(); - S3 = KS3.concat(); - P = KP.concat(); - - /* - * (2) Now, XOR P[0] with the first 32 bits of the key, XOR P[1] with - * the second 32-bits of the key, and so on for all bits of the key (up - * to P[17]). Repeatedly cycle through the key bits until the entire - * P-array has been XOR-ed with the key bits - */ - var keyLength:uint= key.length; - var keyIndex:uint = 0; - - for (var i:uint = 0; i < P_SZ; i++) - { - // get the 32 bits of the key, in 4 * 8 bit chunks - var data:uint = 0x0000000; - for (var j:uint = 0; j < 4; j++) - { - // create a 32 bit block - data = (data << 8) | (key[keyIndex++] & 0xff); - - // wrap when we get to the end of the key - if (keyIndex >= keyLength) - { - keyIndex = 0; - } - } - // XOR the newly created 32 bit chunk onto the P-array - P[i] ^= data; - } - - /* - * (3) Encrypt the all-zero string with the Blowfish algorithm, using - * the subkeys described in (1) and (2) - * - * (4) Replace P1 and P2 with the output of step (3) - * - * (5) Encrypt the output of step(3) using the Blowfish algorithm, with - * the modified subkeys. - * - * (6) Replace P3 and P4 with the output of step (5) - * - * (7) Continue the process, replacing all elements of the P-array and - * then all four S-boxes in order, with the output of the continuously - * changing Blowfish algorithm - */ - - processTable(0, 0, P); - processTable(P[P_SZ - 2], P[P_SZ - 1], S0); - processTable(S0[SBOX_SK - 2], S0[SBOX_SK - 1], S1); - processTable(S1[SBOX_SK - 2], S1[SBOX_SK - 1], S2); - processTable(S2[SBOX_SK - 2], S2[SBOX_SK - 1], S3); - } - - /** - * Encrypt the given input starting at the given offset and place the result - * in the provided buffer starting at the given offset. The input will be an - * exact multiple of our blocksize. - */ - private function encryptBlock(src:ByteArray, srcIndex:uint, dst:ByteArray, dstIndex:uint):void - { - var xl:uint = BytesTo32bits(src, srcIndex); - var xr:uint = BytesTo32bits(src, srcIndex + 4); - - xl ^= P[0]; - - for (var i:uint = 1; i < ROUNDS; i += 2) - { - xr ^= F(xl) ^ P[i]; - xl ^= F(xr) ^ P[i + 1]; - } - - xr ^= P[ROUNDS + 1]; - - Bits32ToBytes(xr, dst, dstIndex); - Bits32ToBytes(xl, dst, dstIndex + 4); - } - - /** - * Decrypt the given input starting at the given offset and place the result - * in the provided buffer starting at the given offset. The input will be an - * exact multiple of our blocksize. - */ - private function decryptBlock(src:ByteArray, srcIndex:uint, dst:ByteArray, dstIndex:uint):void - { - var xl:uint = BytesTo32bits(src, srcIndex); - var xr:uint = BytesTo32bits(src, srcIndex + 4); - - xl ^= P[ROUNDS + 1]; - - for (var i:uint = ROUNDS; i > 0; i -= 2) - { - xr ^= F(xl) ^ P[i]; - xl ^= F(xr) ^ P[i - 1]; - } - - xr ^= P[0]; - - Bits32ToBytes(xr, dst, dstIndex); - Bits32ToBytes(xl, dst, dstIndex + 4); - } - - private function BytesTo32bits(b:ByteArray, i:uint):uint - { - return ((b[i] & 0xff) << 24) | ((b[i + 1] & 0xff) << 16) | ((b[i + 2] & 0xff) << 8) | ((b[i + 3] & 0xff)); - } - - private function Bits32ToBytes(i:uint, b:ByteArray, offset:uint):void - { - b[offset + 3] = i; - b[offset + 2] = (i >> 8); - b[offset + 1] = (i >> 16); - b[offset] = (i >> 24); - } - - public function toString():String { - return "blowfish"; - } - - } - -} +/** + * BlowFishKey + * + * An Actionscript 3 implementation of the BlowFish encryption algorithm, + * as documented at http://www.schneier.com/blowfish.html + * Copyright (c) 2007 Henri Torgemane + * + * Derived from: + * The Bouncy Castle Crypto package, + * Copyright (c) 2000-2004 The Legion Of The Bouncy Castle + * (http://www.bouncycastle.org) + * + * See LICENSE.txt for full license information. + */ +package com.hurlant.crypto.symmetric +{ + import flash.utils.ByteArray; + import com.hurlant.util.Memory; + + public class BlowFishKey implements ISymmetricKey + { + + private static const KP:Array = [ 0x243F6A88, 0x85A308D3, 0x13198A2E, 0x03707344, 0xA4093822, 0x299F31D0, + 0x082EFA98, 0xEC4E6C89, 0x452821E6, 0x38D01377, 0xBE5466CF, 0x34E90C6C, 0xC0AC29B7, 0xC97C50DD, 0x3F84D5B5, + 0xB5470917, 0x9216D5D9, 0x8979FB1B ]; + + private static const KS0:Array = [ 0xD1310BA6, 0x98DFB5AC, 0x2FFD72DB, 0xD01ADFB7, 0xB8E1AFED, 0x6A267E96, 0xBA7C9045, 0xF12C7F99, 0x24A19947, + 0xB3916CF7, 0x0801F2E2, 0x858EFC16, 0x636920D8, 0x71574E69, 0xA458FEA3, 0xF4933D7E, 0x0D95748F, 0x728EB658, + 0x718BCD58, 0x82154AEE, 0x7B54A41D, 0xC25A59B5, 0x9C30D539, 0x2AF26013, 0xC5D1B023, 0x286085F0, 0xCA417918, + 0xB8DB38EF, 0x8E79DCB0, 0x603A180E, 0x6C9E0E8B, 0xB01E8A3E, 0xD71577C1, 0xBD314B27, 0x78AF2FDA, 0x55605C60, + 0xE65525F3, 0xAA55AB94, 0x57489862, 0x63E81440, 0x55CA396A, 0x2AAB10B6, 0xB4CC5C34, 0x1141E8CE, 0xA15486AF, + 0x7C72E993, 0xB3EE1411, 0x636FBC2A, 0x2BA9C55D, 0x741831F6, 0xCE5C3E16, 0x9B87931E, 0xAFD6BA33, 0x6C24CF5C, + 0x7A325381, 0x28958677, 0x3B8F4898, 0x6B4BB9AF, 0xC4BFE81B, 0x66282193, 0x61D809CC, 0xFB21A991, 0x487CAC60, + 0x5DEC8032, 0xEF845D5D, 0xE98575B1, 0xDC262302, 0xEB651B88, 0x23893E81, 0xD396ACC5, 0x0F6D6FF3, 0x83F44239, + 0x2E0B4482, 0xA4842004, 0x69C8F04A, 0x9E1F9B5E, 0x21C66842, 0xF6E96C9A, 0x670C9C61, 0xABD388F0, 0x6A51A0D2, + 0xD8542F68, 0x960FA728, 0xAB5133A3, 0x6EEF0B6C, 0x137A3BE4, 0xBA3BF050, 0x7EFB2A98, 0xA1F1651D, 0x39AF0176, + 0x66CA593E, 0x82430E88, 0x8CEE8619, 0x456F9FB4, 0x7D84A5C3, 0x3B8B5EBE, 0xE06F75D8, 0x85C12073, 0x401A449F, + 0x56C16AA6, 0x4ED3AA62, 0x363F7706, 0x1BFEDF72, 0x429B023D, 0x37D0D724, 0xD00A1248, 0xDB0FEAD3, 0x49F1C09B, + 0x075372C9, 0x80991B7B, 0x25D479D8, 0xF6E8DEF7, 0xE3FE501A, 0xB6794C3B, 0x976CE0BD, 0x04C006BA, 0xC1A94FB6, + 0x409F60C4, 0x5E5C9EC2, 0x196A2463, 0x68FB6FAF, 0x3E6C53B5, 0x1339B2EB, 0x3B52EC6F, 0x6DFC511F, 0x9B30952C, + 0xCC814544, 0xAF5EBD09, 0xBEE3D004, 0xDE334AFD, 0x660F2807, 0x192E4BB3, 0xC0CBA857, 0x45C8740F, 0xD20B5F39, + 0xB9D3FBDB, 0x5579C0BD, 0x1A60320A, 0xD6A100C6, 0x402C7279, 0x679F25FE, 0xFB1FA3CC, 0x8EA5E9F8, 0xDB3222F8, + 0x3C7516DF, 0xFD616B15, 0x2F501EC8, 0xAD0552AB, 0x323DB5FA, 0xFD238760, 0x53317B48, 0x3E00DF82, 0x9E5C57BB, + 0xCA6F8CA0, 0x1A87562E, 0xDF1769DB, 0xD542A8F6, 0x287EFFC3, 0xAC6732C6, 0x8C4F5573, 0x695B27B0, 0xBBCA58C8, + 0xE1FFA35D, 0xB8F011A0, 0x10FA3D98, 0xFD2183B8, 0x4AFCB56C, 0x2DD1D35B, 0x9A53E479, 0xB6F84565, 0xD28E49BC, + 0x4BFB9790, 0xE1DDF2DA, 0xA4CB7E33, 0x62FB1341, 0xCEE4C6E8, 0xEF20CADA, 0x36774C01, 0xD07E9EFE, 0x2BF11FB4, + 0x95DBDA4D, 0xAE909198, 0xEAAD8E71, 0x6B93D5A0, 0xD08ED1D0, 0xAFC725E0, 0x8E3C5B2F, 0x8E7594B7, 0x8FF6E2FB, + 0xF2122B64, 0x8888B812, 0x900DF01C, 0x4FAD5EA0, 0x688FC31C, 0xD1CFF191, 0xB3A8C1AD, 0x2F2F2218, 0xBE0E1777, + 0xEA752DFE, 0x8B021FA1, 0xE5A0CC0F, 0xB56F74E8, 0x18ACF3D6, 0xCE89E299, 0xB4A84FE0, 0xFD13E0B7, 0x7CC43B81, + 0xD2ADA8D9, 0x165FA266, 0x80957705, 0x93CC7314, 0x211A1477, 0xE6AD2065, 0x77B5FA86, 0xC75442F5, 0xFB9D35CF, + 0xEBCDAF0C, 0x7B3E89A0, 0xD6411BD3, 0xAE1E7E49, 0x00250E2D, 0x2071B35E, 0x226800BB, 0x57B8E0AF, 0x2464369B, + 0xF009B91E, 0x5563911D, 0x59DFA6AA, 0x78C14389, 0xD95A537F, 0x207D5BA2, 0x02E5B9C5, 0x83260376, 0x6295CFA9, + 0x11C81968, 0x4E734A41, 0xB3472DCA, 0x7B14A94A, 0x1B510052, 0x9A532915, 0xD60F573F, 0xBC9BC6E4, 0x2B60A476, + 0x81E67400, 0x08BA6FB5, 0x571BE91F, 0xF296EC6B, 0x2A0DD915, 0xB6636521, 0xE7B9F9B6, 0xFF34052E, 0xC5855664, + 0x53B02D5D, 0xA99F8FA1, 0x08BA4799, 0x6E85076A ]; + + private static const KS1:Array = [ 0x4B7A70E9, 0xB5B32944, 0xDB75092E, 0xC4192623, 0xAD6EA6B0, 0x49A7DF7D, 0x9CEE60B8, 0x8FEDB266, 0xECAA8C71, + 0x699A17FF, 0x5664526C, 0xC2B19EE1, 0x193602A5, 0x75094C29, 0xA0591340, 0xE4183A3E, 0x3F54989A, 0x5B429D65, + 0x6B8FE4D6, 0x99F73FD6, 0xA1D29C07, 0xEFE830F5, 0x4D2D38E6, 0xF0255DC1, 0x4CDD2086, 0x8470EB26, 0x6382E9C6, + 0x021ECC5E, 0x09686B3F, 0x3EBAEFC9, 0x3C971814, 0x6B6A70A1, 0x687F3584, 0x52A0E286, 0xB79C5305, 0xAA500737, + 0x3E07841C, 0x7FDEAE5C, 0x8E7D44EC, 0x5716F2B8, 0xB03ADA37, 0xF0500C0D, 0xF01C1F04, 0x0200B3FF, 0xAE0CF51A, + 0x3CB574B2, 0x25837A58, 0xDC0921BD, 0xD19113F9, 0x7CA92FF6, 0x94324773, 0x22F54701, 0x3AE5E581, 0x37C2DADC, + 0xC8B57634, 0x9AF3DDA7, 0xA9446146, 0x0FD0030E, 0xECC8C73E, 0xA4751E41, 0xE238CD99, 0x3BEA0E2F, 0x3280BBA1, + 0x183EB331, 0x4E548B38, 0x4F6DB908, 0x6F420D03, 0xF60A04BF, 0x2CB81290, 0x24977C79, 0x5679B072, 0xBCAF89AF, + 0xDE9A771F, 0xD9930810, 0xB38BAE12, 0xDCCF3F2E, 0x5512721F, 0x2E6B7124, 0x501ADDE6, 0x9F84CD87, 0x7A584718, + 0x7408DA17, 0xBC9F9ABC, 0xE94B7D8C, 0xEC7AEC3A, 0xDB851DFA, 0x63094366, 0xC464C3D2, 0xEF1C1847, 0x3215D908, + 0xDD433B37, 0x24C2BA16, 0x12A14D43, 0x2A65C451, 0x50940002, 0x133AE4DD, 0x71DFF89E, 0x10314E55, 0x81AC77D6, + 0x5F11199B, 0x043556F1, 0xD7A3C76B, 0x3C11183B, 0x5924A509, 0xF28FE6ED, 0x97F1FBFA, 0x9EBABF2C, 0x1E153C6E, + 0x86E34570, 0xEAE96FB1, 0x860E5E0A, 0x5A3E2AB3, 0x771FE71C, 0x4E3D06FA, 0x2965DCB9, 0x99E71D0F, 0x803E89D6, + 0x5266C825, 0x2E4CC978, 0x9C10B36A, 0xC6150EBA, 0x94E2EA78, 0xA5FC3C53, 0x1E0A2DF4, 0xF2F74EA7, 0x361D2B3D, + 0x1939260F, 0x19C27960, 0x5223A708, 0xF71312B6, 0xEBADFE6E, 0xEAC31F66, 0xE3BC4595, 0xA67BC883, 0xB17F37D1, + 0x018CFF28, 0xC332DDEF, 0xBE6C5AA5, 0x65582185, 0x68AB9802, 0xEECEA50F, 0xDB2F953B, 0x2AEF7DAD, 0x5B6E2F84, + 0x1521B628, 0x29076170, 0xECDD4775, 0x619F1510, 0x13CCA830, 0xEB61BD96, 0x0334FE1E, 0xAA0363CF, 0xB5735C90, + 0x4C70A239, 0xD59E9E0B, 0xCBAADE14, 0xEECC86BC, 0x60622CA7, 0x9CAB5CAB, 0xB2F3846E, 0x648B1EAF, 0x19BDF0CA, + 0xA02369B9, 0x655ABB50, 0x40685A32, 0x3C2AB4B3, 0x319EE9D5, 0xC021B8F7, 0x9B540B19, 0x875FA099, 0x95F7997E, + 0x623D7DA8, 0xF837889A, 0x97E32D77, 0x11ED935F, 0x16681281, 0x0E358829, 0xC7E61FD6, 0x96DEDFA1, 0x7858BA99, + 0x57F584A5, 0x1B227263, 0x9B83C3FF, 0x1AC24696, 0xCDB30AEB, 0x532E3054, 0x8FD948E4, 0x6DBC3128, 0x58EBF2EF, + 0x34C6FFEA, 0xFE28ED61, 0xEE7C3C73, 0x5D4A14D9, 0xE864B7E3, 0x42105D14, 0x203E13E0, 0x45EEE2B6, 0xA3AAABEA, + 0xDB6C4F15, 0xFACB4FD0, 0xC742F442, 0xEF6ABBB5, 0x654F3B1D, 0x41CD2105, 0xD81E799E, 0x86854DC7, 0xE44B476A, + 0x3D816250, 0xCF62A1F2, 0x5B8D2646, 0xFC8883A0, 0xC1C7B6A3, 0x7F1524C3, 0x69CB7492, 0x47848A0B, 0x5692B285, + 0x095BBF00, 0xAD19489D, 0x1462B174, 0x23820E00, 0x58428D2A, 0x0C55F5EA, 0x1DADF43E, 0x233F7061, 0x3372F092, + 0x8D937E41, 0xD65FECF1, 0x6C223BDB, 0x7CDE3759, 0xCBEE7460, 0x4085F2A7, 0xCE77326E, 0xA6078084, 0x19F8509E, + 0xE8EFD855, 0x61D99735, 0xA969A7AA, 0xC50C06C2, 0x5A04ABFC, 0x800BCADC, 0x9E447A2E, 0xC3453484, 0xFDD56705, + 0x0E1E9EC9, 0xDB73DBD3, 0x105588CD, 0x675FDA79, 0xE3674340, 0xC5C43465, 0x713E38D8, 0x3D28F89E, 0xF16DFF20, + 0x153E21E7, 0x8FB03D4A, 0xE6E39F2B, 0xDB83ADF7 ]; + + private static const KS2:Array = [ 0xE93D5A68, 0x948140F7, 0xF64C261C, 0x94692934, 0x411520F7, 0x7602D4F7, 0xBCF46B2E, 0xD4A20068, 0xD4082471, + 0x3320F46A, 0x43B7D4B7, 0x500061AF, 0x1E39F62E, 0x97244546, 0x14214F74, 0xBF8B8840, 0x4D95FC1D, 0x96B591AF, + 0x70F4DDD3, 0x66A02F45, 0xBFBC09EC, 0x03BD9785, 0x7FAC6DD0, 0x31CB8504, 0x96EB27B3, 0x55FD3941, 0xDA2547E6, + 0xABCA0A9A, 0x28507825, 0x530429F4, 0x0A2C86DA, 0xE9B66DFB, 0x68DC1462, 0xD7486900, 0x680EC0A4, 0x27A18DEE, + 0x4F3FFEA2, 0xE887AD8C, 0xB58CE006, 0x7AF4D6B6, 0xAACE1E7C, 0xD3375FEC, 0xCE78A399, 0x406B2A42, 0x20FE9E35, + 0xD9F385B9, 0xEE39D7AB, 0x3B124E8B, 0x1DC9FAF7, 0x4B6D1856, 0x26A36631, 0xEAE397B2, 0x3A6EFA74, 0xDD5B4332, + 0x6841E7F7, 0xCA7820FB, 0xFB0AF54E, 0xD8FEB397, 0x454056AC, 0xBA489527, 0x55533A3A, 0x20838D87, 0xFE6BA9B7, + 0xD096954B, 0x55A867BC, 0xA1159A58, 0xCCA92963, 0x99E1DB33, 0xA62A4A56, 0x3F3125F9, 0x5EF47E1C, 0x9029317C, + 0xFDF8E802, 0x04272F70, 0x80BB155C, 0x05282CE3, 0x95C11548, 0xE4C66D22, 0x48C1133F, 0xC70F86DC, 0x07F9C9EE, + 0x41041F0F, 0x404779A4, 0x5D886E17, 0x325F51EB, 0xD59BC0D1, 0xF2BCC18F, 0x41113564, 0x257B7834, 0x602A9C60, + 0xDFF8E8A3, 0x1F636C1B, 0x0E12B4C2, 0x02E1329E, 0xAF664FD1, 0xCAD18115, 0x6B2395E0, 0x333E92E1, 0x3B240B62, + 0xEEBEB922, 0x85B2A20E, 0xE6BA0D99, 0xDE720C8C, 0x2DA2F728, 0xD0127845, 0x95B794FD, 0x647D0862, 0xE7CCF5F0, + 0x5449A36F, 0x877D48FA, 0xC39DFD27, 0xF33E8D1E, 0x0A476341, 0x992EFF74, 0x3A6F6EAB, 0xF4F8FD37, 0xA812DC60, + 0xA1EBDDF8, 0x991BE14C, 0xDB6E6B0D, 0xC67B5510, 0x6D672C37, 0x2765D43B, 0xDCD0E804, 0xF1290DC7, 0xCC00FFA3, + 0xB5390F92, 0x690FED0B, 0x667B9FFB, 0xCEDB7D9C, 0xA091CF0B, 0xD9155EA3, 0xBB132F88, 0x515BAD24, 0x7B9479BF, + 0x763BD6EB, 0x37392EB3, 0xCC115979, 0x8026E297, 0xF42E312D, 0x6842ADA7, 0xC66A2B3B, 0x12754CCC, 0x782EF11C, + 0x6A124237, 0xB79251E7, 0x06A1BBE6, 0x4BFB6350, 0x1A6B1018, 0x11CAEDFA, 0x3D25BDD8, 0xE2E1C3C9, 0x44421659, + 0x0A121386, 0xD90CEC6E, 0xD5ABEA2A, 0x64AF674E, 0xDA86A85F, 0xBEBFE988, 0x64E4C3FE, 0x9DBC8057, 0xF0F7C086, + 0x60787BF8, 0x6003604D, 0xD1FD8346, 0xF6381FB0, 0x7745AE04, 0xD736FCCC, 0x83426B33, 0xF01EAB71, 0xB0804187, + 0x3C005E5F, 0x77A057BE, 0xBDE8AE24, 0x55464299, 0xBF582E61, 0x4E58F48F, 0xF2DDFDA2, 0xF474EF38, 0x8789BDC2, + 0x5366F9C3, 0xC8B38E74, 0xB475F255, 0x46FCD9B9, 0x7AEB2661, 0x8B1DDF84, 0x846A0E79, 0x915F95E2, 0x466E598E, + 0x20B45770, 0x8CD55591, 0xC902DE4C, 0xB90BACE1, 0xBB8205D0, 0x11A86248, 0x7574A99E, 0xB77F19B6, 0xE0A9DC09, + 0x662D09A1, 0xC4324633, 0xE85A1F02, 0x09F0BE8C, 0x4A99A025, 0x1D6EFE10, 0x1AB93D1D, 0x0BA5A4DF, 0xA186F20F, + 0x2868F169, 0xDCB7DA83, 0x573906FE, 0xA1E2CE9B, 0x4FCD7F52, 0x50115E01, 0xA70683FA, 0xA002B5C4, 0x0DE6D027, + 0x9AF88C27, 0x773F8641, 0xC3604C06, 0x61A806B5, 0xF0177A28, 0xC0F586E0, 0x006058AA, 0x30DC7D62, 0x11E69ED7, + 0x2338EA63, 0x53C2DD94, 0xC2C21634, 0xBBCBEE56, 0x90BCB6DE, 0xEBFC7DA1, 0xCE591D76, 0x6F05E409, 0x4B7C0188, + 0x39720A3D, 0x7C927C24, 0x86E3725F, 0x724D9DB9, 0x1AC15BB4, 0xD39EB8FC, 0xED545578, 0x08FCA5B5, 0xD83D7CD3, + 0x4DAD0FC4, 0x1E50EF5E, 0xB161E6F8, 0xA28514D9, 0x6C51133C, 0x6FD5C7E7, 0x56E14EC4, 0x362ABFCE, 0xDDC6C837, + 0xD79A3234, 0x92638212, 0x670EFA8E, 0x406000E0 ]; + + private static const KS3:Array = [ 0x3A39CE37, 0xD3FAF5CF, 0xABC27737, 0x5AC52D1B, 0x5CB0679E, 0x4FA33742, 0xD3822740, 0x99BC9BBE, 0xD5118E9D, + 0xBF0F7315, 0xD62D1C7E, 0xC700C47B, 0xB78C1B6B, 0x21A19045, 0xB26EB1BE, 0x6A366EB4, 0x5748AB2F, 0xBC946E79, + 0xC6A376D2, 0x6549C2C8, 0x530FF8EE, 0x468DDE7D, 0xD5730A1D, 0x4CD04DC6, 0x2939BBDB, 0xA9BA4650, 0xAC9526E8, + 0xBE5EE304, 0xA1FAD5F0, 0x6A2D519A, 0x63EF8CE2, 0x9A86EE22, 0xC089C2B8, 0x43242EF6, 0xA51E03AA, 0x9CF2D0A4, + 0x83C061BA, 0x9BE96A4D, 0x8FE51550, 0xBA645BD6, 0x2826A2F9, 0xA73A3AE1, 0x4BA99586, 0xEF5562E9, 0xC72FEFD3, + 0xF752F7DA, 0x3F046F69, 0x77FA0A59, 0x80E4A915, 0x87B08601, 0x9B09E6AD, 0x3B3EE593, 0xE990FD5A, 0x9E34D797, + 0x2CF0B7D9, 0x022B8B51, 0x96D5AC3A, 0x017DA67D, 0xD1CF3ED6, 0x7C7D2D28, 0x1F9F25CF, 0xADF2B89B, 0x5AD6B472, + 0x5A88F54C, 0xE029AC71, 0xE019A5E6, 0x47B0ACFD, 0xED93FA9B, 0xE8D3C48D, 0x283B57CC, 0xF8D56629, 0x79132E28, + 0x785F0191, 0xED756055, 0xF7960E44, 0xE3D35E8C, 0x15056DD4, 0x88F46DBA, 0x03A16125, 0x0564F0BD, 0xC3EB9E15, + 0x3C9057A2, 0x97271AEC, 0xA93A072A, 0x1B3F6D9B, 0x1E6321F5, 0xF59C66FB, 0x26DCF319, 0x7533D928, 0xB155FDF5, + 0x03563482, 0x8ABA3CBB, 0x28517711, 0xC20AD9F8, 0xABCC5167, 0xCCAD925F, 0x4DE81751, 0x3830DC8E, 0x379D5862, + 0x9320F991, 0xEA7A90C2, 0xFB3E7BCE, 0x5121CE64, 0x774FBE32, 0xA8B6E37E, 0xC3293D46, 0x48DE5369, 0x6413E680, + 0xA2AE0810, 0xDD6DB224, 0x69852DFD, 0x09072166, 0xB39A460A, 0x6445C0DD, 0x586CDECF, 0x1C20C8AE, 0x5BBEF7DD, + 0x1B588D40, 0xCCD2017F, 0x6BB4E3BB, 0xDDA26A7E, 0x3A59FF45, 0x3E350A44, 0xBCB4CDD5, 0x72EACEA8, 0xFA6484BB, + 0x8D6612AE, 0xBF3C6F47, 0xD29BE463, 0x542F5D9E, 0xAEC2771B, 0xF64E6370, 0x740E0D8D, 0xE75B1357, 0xF8721671, + 0xAF537D5D, 0x4040CB08, 0x4EB4E2CC, 0x34D2466A, 0x0115AF84, 0xE1B00428, 0x95983A1D, 0x06B89FB4, 0xCE6EA048, + 0x6F3F3B82, 0x3520AB82, 0x011A1D4B, 0x277227F8, 0x611560B1, 0xE7933FDC, 0xBB3A792B, 0x344525BD, 0xA08839E1, + 0x51CE794B, 0x2F32C9B7, 0xA01FBAC9, 0xE01CC87E, 0xBCC7D1F6, 0xCF0111C3, 0xA1E8AAC7, 0x1A908749, 0xD44FBD9A, + 0xD0DADECB, 0xD50ADA38, 0x0339C32A, 0xC6913667, 0x8DF9317C, 0xE0B12B4F, 0xF79E59B7, 0x43F5BB3A, 0xF2D519FF, + 0x27D9459C, 0xBF97222C, 0x15E6FC2A, 0x0F91FC71, 0x9B941525, 0xFAE59361, 0xCEB69CEB, 0xC2A86459, 0x12BAA8D1, + 0xB6C1075E, 0xE3056A0C, 0x10D25065, 0xCB03A442, 0xE0EC6E0E, 0x1698DB3B, 0x4C98A0BE, 0x3278E964, 0x9F1F9532, + 0xE0D392DF, 0xD3A0342B, 0x8971F21E, 0x1B0A7441, 0x4BA3348C, 0xC5BE7120, 0xC37632D8, 0xDF359F8D, 0x9B992F2E, + 0xE60B6F47, 0x0FE3F11D, 0xE54CDA54, 0x1EDAD891, 0xCE6279CF, 0xCD3E7E6F, 0x1618B166, 0xFD2C1D05, 0x848FD2C5, + 0xF6FB2299, 0xF523F357, 0xA6327623, 0x93A83531, 0x56CCCD02, 0xACF08162, 0x5A75EBB5, 0x6E163697, 0x88D273CC, + 0xDE966292, 0x81B949D0, 0x4C50901B, 0x71C65614, 0xE6C6C7BD, 0x327A140A, 0x45E1D006, 0xC3F27B9A, 0xC9AA53FD, + 0x62A80F00, 0xBB25BFE2, 0x35BDD2F6, 0x71126905, 0xB2040222, 0xB6CBCF7C, 0xCD769C2B, 0x53113EC0, 0x1640E3D3, + 0x38ABBD60, 0x2547ADF0, 0xBA38209C, 0xF746CE76, 0x77AFA1C5, 0x20756060, 0x85CBFE4E, 0x8AE88DD8, 0x7AAAF9B0, + 0x4CF9AA7E, 0x1948C25C, 0x02FB8A8C, 0x01C36AE4, 0xD6EBE1F9, 0x90D4F869, 0xA65CDEA0, 0x3F09252D, 0xC208E69F, + 0xB74E6132, 0xCE77E25B, 0x578FDFE3, 0x3AC372E6 ]; + + // ==================================== + // Useful constants + // ==================================== + + private static const ROUNDS:uint = 16; + private static const BLOCK_SIZE:uint = 8; // bytes = 64 bits + private static const SBOX_SK:uint = 256; + private static const P_SZ:uint = ROUNDS + 2; + + private var S0:Array; + private var S1:Array; + private var S2:Array; + private var S3:Array; // the s-boxes + private var P:Array; // the p-array + + private var key:ByteArray = null; + + public function BlowFishKey(key:ByteArray) { + this.key = key; + setKey(key); + } + + public function getBlockSize():uint + { + return BLOCK_SIZE; + } + + public function decrypt(block:ByteArray, index:uint=0):void + { + decryptBlock(block, index, block, index); + } + + public function dispose():void + { + var i:uint=0; + for (i=0;i>> 24)] + S1[(x >>> 16) & 0xff]) ^ S2[(x >>> 8) & 0xff]) + S3[x & 0xff]); + } + + /** + * apply the encryption cycle to each value pair in the table. + */ + private function processTable(xl:uint, xr:uint, table:Array):void + { + var size:uint = table.length; + + for (var s:uint = 0; s < size; s += 2) + { + xl ^= P[0]; + + for (var i:uint = 1; i < ROUNDS; i += 2) + { + xr ^= F(xl) ^ P[i]; + xl ^= F(xr) ^ P[i + 1]; + } + + xr ^= P[ROUNDS + 1]; + + table[s] = xr; + table[s + 1] = xl; + + xr = xl; // end of cycle swap + xl = table[s]; + } + } + + private function setKey(key:ByteArray):void + { + /* + * - comments are from _Applied Crypto_, Schneier, p338 please be + * careful comparing the two, AC numbers the arrays from 1, the enclosed + * code from 0. + * + * (1) Initialise the S-boxes and the P-array, with a fixed string This + * string contains the hexadecimal digits of pi (3.141...) + */ + S0 = KS0.concat(); + S1 = KS1.concat(); + S2 = KS2.concat(); + S3 = KS3.concat(); + P = KP.concat(); + + /* + * (2) Now, XOR P[0] with the first 32 bits of the key, XOR P[1] with + * the second 32-bits of the key, and so on for all bits of the key (up + * to P[17]). Repeatedly cycle through the key bits until the entire + * P-array has been XOR-ed with the key bits + */ + var keyLength:uint= key.length; + var keyIndex:uint = 0; + + for (var i:uint = 0; i < P_SZ; i++) + { + // get the 32 bits of the key, in 4 * 8 bit chunks + var data:uint = 0x0000000; + for (var j:uint = 0; j < 4; j++) + { + // create a 32 bit block + data = (data << 8) | (key[keyIndex++] & 0xff); + + // wrap when we get to the end of the key + if (keyIndex >= keyLength) + { + keyIndex = 0; + } + } + // XOR the newly created 32 bit chunk onto the P-array + P[i] ^= data; + } + + /* + * (3) Encrypt the all-zero string with the Blowfish algorithm, using + * the subkeys described in (1) and (2) + * + * (4) Replace P1 and P2 with the output of step (3) + * + * (5) Encrypt the output of step(3) using the Blowfish algorithm, with + * the modified subkeys. + * + * (6) Replace P3 and P4 with the output of step (5) + * + * (7) Continue the process, replacing all elements of the P-array and + * then all four S-boxes in order, with the output of the continuously + * changing Blowfish algorithm + */ + + processTable(0, 0, P); + processTable(P[P_SZ - 2], P[P_SZ - 1], S0); + processTable(S0[SBOX_SK - 2], S0[SBOX_SK - 1], S1); + processTable(S1[SBOX_SK - 2], S1[SBOX_SK - 1], S2); + processTable(S2[SBOX_SK - 2], S2[SBOX_SK - 1], S3); + } + + /** + * Encrypt the given input starting at the given offset and place the result + * in the provided buffer starting at the given offset. The input will be an + * exact multiple of our blocksize. + */ + private function encryptBlock(src:ByteArray, srcIndex:uint, dst:ByteArray, dstIndex:uint):void + { + var xl:uint = BytesTo32bits(src, srcIndex); + var xr:uint = BytesTo32bits(src, srcIndex + 4); + + xl ^= P[0]; + + for (var i:uint = 1; i < ROUNDS; i += 2) + { + xr ^= F(xl) ^ P[i]; + xl ^= F(xr) ^ P[i + 1]; + } + + xr ^= P[ROUNDS + 1]; + + Bits32ToBytes(xr, dst, dstIndex); + Bits32ToBytes(xl, dst, dstIndex + 4); + } + + /** + * Decrypt the given input starting at the given offset and place the result + * in the provided buffer starting at the given offset. The input will be an + * exact multiple of our blocksize. + */ + private function decryptBlock(src:ByteArray, srcIndex:uint, dst:ByteArray, dstIndex:uint):void + { + var xl:uint = BytesTo32bits(src, srcIndex); + var xr:uint = BytesTo32bits(src, srcIndex + 4); + + xl ^= P[ROUNDS + 1]; + + for (var i:uint = ROUNDS; i > 0; i -= 2) + { + xr ^= F(xl) ^ P[i]; + xl ^= F(xr) ^ P[i - 1]; + } + + xr ^= P[0]; + + Bits32ToBytes(xr, dst, dstIndex); + Bits32ToBytes(xl, dst, dstIndex + 4); + } + + private function BytesTo32bits(b:ByteArray, i:uint):uint + { + return ((b[i] & 0xff) << 24) | ((b[i + 1] & 0xff) << 16) | ((b[i + 2] & 0xff) << 8) | ((b[i + 3] & 0xff)); + } + + private function Bits32ToBytes(i:uint, b:ByteArray, offset:uint):void + { + b[offset + 3] = i; + b[offset + 2] = (i >> 8); + b[offset + 1] = (i >> 16); + b[offset] = (i >> 24); + } + + public function toString():String { + return "blowfish"; + } + + } + +} diff --git a/app/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/CBCMode.as b/app/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/CBCMode.as index c108d2d..e3781be 100644 --- a/app/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/CBCMode.as +++ b/app/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/CBCMode.as @@ -1,55 +1,55 @@ -/** - * CBCMode - * - * An ActionScript 3 implementation of the CBC confidentiality mode - * Copyright (c) 2007 Henri Torgemane - * - * See LICENSE.txt for full license information. - */ -package com.hurlant.crypto.symmetric -{ - import flash.utils.ByteArray; - - /** - * CBC confidentiality mode. why not. - */ - public class CBCMode extends IVMode implements IMode - { - - public function CBCMode(key:ISymmetricKey, padding:IPad = null) { - super(key, padding); - } - - public function encrypt(src:ByteArray):void { - padding.pad(src); - var vector:ByteArray = getIV4e(); - for (var i:uint=0;i=0;--j) { - X[j]++; - if (X[j]!=0) - break; - } - } - } - public function toString():String { - return key.toString()+"-ctr"; - } - - } +/** + * CTRMode + * + * An ActionScript 3 implementation of the counter confidentiality mode + * Copyright (c) 2007 Henri Torgemane + * + * See LICENSE.txt for full license information. + */ +package com.hurlant.crypto.symmetric +{ + import flash.utils.ByteArray; + + public class CTRMode extends IVMode implements IMode + { + + public function CTRMode(key:ISymmetricKey, padding:IPad = null) { + super(key, padding); + } + + public function encrypt(src:ByteArray):void + { + padding.pad(src); + var vector:ByteArray = getIV4e(); + core(src, vector); + } + + public function decrypt(src:ByteArray):void + { + var vector:ByteArray = getIV4d(); + core(src, vector); + padding.unpad(src); + } + + private function core(src:ByteArray, iv:ByteArray):void { + var X:ByteArray = new ByteArray; + var Xenc:ByteArray = new ByteArray; + X.writeBytes(iv); + for (var i:uint=0;i=0;--j) { + X[j]++; + if (X[j]!=0) + break; + } + } + } + public function toString():String { + return key.toString()+"-ctr"; + } + + } } \ No newline at end of file diff --git a/app/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/DESKey.as b/app/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/DESKey.as index fbefc3f..4a0b755 100644 --- a/app/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/DESKey.as +++ b/app/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/DESKey.as @@ -1,365 +1,365 @@ -/** - * DESKey - * - * An Actionscript 3 implementation of the Data Encryption Standard (DES) - * Copyright (c) 2007 Henri Torgemane - * - * Derived from: - * The Bouncy Castle Crypto package, - * Copyright (c) 2000-2004 The Legion Of The Bouncy Castle - * (http://www.bouncycastle.org) - * - * See LICENSE.txt for full license information. - */ -package com.hurlant.crypto.symmetric -{ - import flash.utils.ByteArray; - import com.hurlant.util.Hex; - import com.hurlant.util.Memory; - - public class DESKey implements ISymmetricKey - { - /** - * what follows is mainly taken from "Applied Cryptography", by Bruce - * Schneier, however it also bears great resemblance to Richard - * Outerbridge's D3DES... - */ - - private static const Df_Key:Array = [ 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, - 0x10, 0x89, 0xab, 0xcd, 0xef, 0x01, 0x23, 0x45, 0x67 ]; - - private static const bytebit:Array = [ 128, 64, 32, 16, 8, 4, 2, 1 ]; - - private static const bigbyte:Array = [ 0x800000, 0x400000, 0x200000, 0x100000, 0x80000, 0x40000, 0x20000, 0x10000, 0x8000, - 0x4000, 0x2000, 0x1000, 0x800, 0x400, 0x200, 0x100, 0x80, 0x40, 0x20, 0x10, 0x8, 0x4, 0x2, 0x1 ]; - - /* - * Use the key schedule specified in the Standard (ANSI X3.92-1981). - */ - - private static const pc1:Array = [ 56, 48, 40, 32, 24, 16, 8, 0, 57, 49, 41, 33, 25, 17, 9, 1, 58, 50, 42, 34, 26, 18, 10, 2, - 59, 51, 43, 35, 62, 54, 46, 38, 30, 22, 14, 6, 61, 53, 45, 37, 29, 21, 13, 5, 60, 52, 44, 36, 28, 20, 12, - 4, 27, 19, 11, 3 ]; - - private static const totrot:Array = [ 1, 2, 4, 6, 8, 10, 12, 14, 15, 17, 19, 21, 23, 25, 27, 28 ]; - - private static const pc2:Array = [ 13, 16, 10, 23, 0, 4, 2, 27, 14, 5, 20, 9, 22, 18, 11, 3, 25, 7, 15, 6, 26, 19, 12, 1, 40, - 51, 30, 36, 46, 54, 29, 39, 50, 44, 32, 47, 43, 48, 38, 55, 33, 52, 45, 41, 49, 35, 28, 31 ]; - - private static const SP1:Array = [ 0x01010400, 0x00000000, 0x00010000, 0x01010404, 0x01010004, 0x00010404, 0x00000004, - 0x00010000, 0x00000400, 0x01010400, 0x01010404, 0x00000400, 0x01000404, 0x01010004, 0x01000000, 0x00000004, - 0x00000404, 0x01000400, 0x01000400, 0x00010400, 0x00010400, 0x01010000, 0x01010000, 0x01000404, 0x00010004, - 0x01000004, 0x01000004, 0x00010004, 0x00000000, 0x00000404, 0x00010404, 0x01000000, 0x00010000, 0x01010404, - 0x00000004, 0x01010000, 0x01010400, 0x01000000, 0x01000000, 0x00000400, 0x01010004, 0x00010000, 0x00010400, - 0x01000004, 0x00000400, 0x00000004, 0x01000404, 0x00010404, 0x01010404, 0x00010004, 0x01010000, 0x01000404, - 0x01000004, 0x00000404, 0x00010404, 0x01010400, 0x00000404, 0x01000400, 0x01000400, 0x00000000, 0x00010004, - 0x00010400, 0x00000000, 0x01010004 ]; - - private static const SP2:Array = [ 0x80108020, 0x80008000, 0x00008000, 0x00108020, 0x00100000, 0x00000020, 0x80100020, - 0x80008020, 0x80000020, 0x80108020, 0x80108000, 0x80000000, 0x80008000, 0x00100000, 0x00000020, 0x80100020, - 0x00108000, 0x00100020, 0x80008020, 0x00000000, 0x80000000, 0x00008000, 0x00108020, 0x80100000, 0x00100020, - 0x80000020, 0x00000000, 0x00108000, 0x00008020, 0x80108000, 0x80100000, 0x00008020, 0x00000000, 0x00108020, - 0x80100020, 0x00100000, 0x80008020, 0x80100000, 0x80108000, 0x00008000, 0x80100000, 0x80008000, 0x00000020, - 0x80108020, 0x00108020, 0x00000020, 0x00008000, 0x80000000, 0x00008020, 0x80108000, 0x00100000, 0x80000020, - 0x00100020, 0x80008020, 0x80000020, 0x00100020, 0x00108000, 0x00000000, 0x80008000, 0x00008020, 0x80000000, - 0x80100020, 0x80108020, 0x00108000 ]; - - private static const SP3:Array = [ 0x00000208, 0x08020200, 0x00000000, 0x08020008, 0x08000200, 0x00000000, 0x00020208, - 0x08000200, 0x00020008, 0x08000008, 0x08000008, 0x00020000, 0x08020208, 0x00020008, 0x08020000, 0x00000208, - 0x08000000, 0x00000008, 0x08020200, 0x00000200, 0x00020200, 0x08020000, 0x08020008, 0x00020208, 0x08000208, - 0x00020200, 0x00020000, 0x08000208, 0x00000008, 0x08020208, 0x00000200, 0x08000000, 0x08020200, 0x08000000, - 0x00020008, 0x00000208, 0x00020000, 0x08020200, 0x08000200, 0x00000000, 0x00000200, 0x00020008, 0x08020208, - 0x08000200, 0x08000008, 0x00000200, 0x00000000, 0x08020008, 0x08000208, 0x00020000, 0x08000000, 0x08020208, - 0x00000008, 0x00020208, 0x00020200, 0x08000008, 0x08020000, 0x08000208, 0x00000208, 0x08020000, 0x00020208, - 0x00000008, 0x08020008, 0x00020200 ]; - - private static const SP4:Array = [ 0x00802001, 0x00002081, 0x00002081, 0x00000080, 0x00802080, 0x00800081, 0x00800001, - 0x00002001, 0x00000000, 0x00802000, 0x00802000, 0x00802081, 0x00000081, 0x00000000, 0x00800080, 0x00800001, - 0x00000001, 0x00002000, 0x00800000, 0x00802001, 0x00000080, 0x00800000, 0x00002001, 0x00002080, 0x00800081, - 0x00000001, 0x00002080, 0x00800080, 0x00002000, 0x00802080, 0x00802081, 0x00000081, 0x00800080, 0x00800001, - 0x00802000, 0x00802081, 0x00000081, 0x00000000, 0x00000000, 0x00802000, 0x00002080, 0x00800080, 0x00800081, - 0x00000001, 0x00802001, 0x00002081, 0x00002081, 0x00000080, 0x00802081, 0x00000081, 0x00000001, 0x00002000, - 0x00800001, 0x00002001, 0x00802080, 0x00800081, 0x00002001, 0x00002080, 0x00800000, 0x00802001, 0x00000080, - 0x00800000, 0x00002000, 0x00802080 ]; - - private static const SP5:Array = [ 0x00000100, 0x02080100, 0x02080000, 0x42000100, 0x00080000, 0x00000100, 0x40000000, - 0x02080000, 0x40080100, 0x00080000, 0x02000100, 0x40080100, 0x42000100, 0x42080000, 0x00080100, 0x40000000, - 0x02000000, 0x40080000, 0x40080000, 0x00000000, 0x40000100, 0x42080100, 0x42080100, 0x02000100, 0x42080000, - 0x40000100, 0x00000000, 0x42000000, 0x02080100, 0x02000000, 0x42000000, 0x00080100, 0x00080000, 0x42000100, - 0x00000100, 0x02000000, 0x40000000, 0x02080000, 0x42000100, 0x40080100, 0x02000100, 0x40000000, 0x42080000, - 0x02080100, 0x40080100, 0x00000100, 0x02000000, 0x42080000, 0x42080100, 0x00080100, 0x42000000, 0x42080100, - 0x02080000, 0x00000000, 0x40080000, 0x42000000, 0x00080100, 0x02000100, 0x40000100, 0x00080000, 0x00000000, - 0x40080000, 0x02080100, 0x40000100 ]; - - private static const SP6:Array = [ 0x20000010, 0x20400000, 0x00004000, 0x20404010, 0x20400000, 0x00000010, 0x20404010, - 0x00400000, 0x20004000, 0x00404010, 0x00400000, 0x20000010, 0x00400010, 0x20004000, 0x20000000, 0x00004010, - 0x00000000, 0x00400010, 0x20004010, 0x00004000, 0x00404000, 0x20004010, 0x00000010, 0x20400010, 0x20400010, - 0x00000000, 0x00404010, 0x20404000, 0x00004010, 0x00404000, 0x20404000, 0x20000000, 0x20004000, 0x00000010, - 0x20400010, 0x00404000, 0x20404010, 0x00400000, 0x00004010, 0x20000010, 0x00400000, 0x20004000, 0x20000000, - 0x00004010, 0x20000010, 0x20404010, 0x00404000, 0x20400000, 0x00404010, 0x20404000, 0x00000000, 0x20400010, - 0x00000010, 0x00004000, 0x20400000, 0x00404010, 0x00004000, 0x00400010, 0x20004010, 0x00000000, 0x20404000, - 0x20000000, 0x00400010, 0x20004010 ]; - - private static const SP7:Array = [ 0x00200000, 0x04200002, 0x04000802, 0x00000000, 0x00000800, 0x04000802, 0x00200802, - 0x04200800, 0x04200802, 0x00200000, 0x00000000, 0x04000002, 0x00000002, 0x04000000, 0x04200002, 0x00000802, - 0x04000800, 0x00200802, 0x00200002, 0x04000800, 0x04000002, 0x04200000, 0x04200800, 0x00200002, 0x04200000, - 0x00000800, 0x00000802, 0x04200802, 0x00200800, 0x00000002, 0x04000000, 0x00200800, 0x04000000, 0x00200800, - 0x00200000, 0x04000802, 0x04000802, 0x04200002, 0x04200002, 0x00000002, 0x00200002, 0x04000000, 0x04000800, - 0x00200000, 0x04200800, 0x00000802, 0x00200802, 0x04200800, 0x00000802, 0x04000002, 0x04200802, 0x04200000, - 0x00200800, 0x00000000, 0x00000002, 0x04200802, 0x00000000, 0x00200802, 0x04200000, 0x00000800, 0x04000002, - 0x04000800, 0x00000800, 0x00200002 ]; - - private static const SP8:Array = [ 0x10001040, 0x00001000, 0x00040000, 0x10041040, 0x10000000, 0x10001040, 0x00000040, - 0x10000000, 0x00040040, 0x10040000, 0x10041040, 0x00041000, 0x10041000, 0x00041040, 0x00001000, 0x00000040, - 0x10040000, 0x10000040, 0x10001000, 0x00001040, 0x00041000, 0x00040040, 0x10040040, 0x10041000, 0x00001040, - 0x00000000, 0x00000000, 0x10040040, 0x10000040, 0x10001000, 0x00041040, 0x00040000, 0x00041040, 0x00040000, - 0x10041000, 0x00001000, 0x00000040, 0x10040040, 0x00001000, 0x00041040, 0x10001000, 0x00000040, 0x10000040, - 0x10040000, 0x10040040, 0x10000000, 0x00040000, 0x10001040, 0x00000000, 0x10041040, 0x00040040, 0x10000040, - 0x10040000, 0x10001000, 0x10001040, 0x00000000, 0x10041040, 0x00041000, 0x00041000, 0x00001040, 0x00001040, - 0x00040040, 0x10000000, 0x10041000 ]; - - - protected var key:ByteArray; - protected var encKey:Array; - protected var decKey:Array; - - - public function DESKey(key:ByteArray) { - this.key = key; - this.encKey = generateWorkingKey(true, key, 0); - this.decKey = generateWorkingKey(false, key, 0); - } - - public function getBlockSize():uint - { - return 8; - } - - public function decrypt(block:ByteArray, index:uint=0):void - { - desFunc(decKey, block, index, block, index); - } - - public function dispose():void - { - var i:uint=0; - for (i=0;i>> 3)] & bytebit[l & 07]) != 0); - } - - for (var i:uint = 0; i < 16; i++) - { - var m:uint; - var n:uint; - - if (encrypting) - { - m = i << 1; - } - else - { - m = (15 - i) << 1; - } - - n = m + 1; - newKey[m] = newKey[n] = 0; - - for (j = 0; j < 28; j++) - { - l = j + totrot[i]; - if (l < 28) - { - pcr[j] = pc1m[l]; - } - else - { - pcr[j] = pc1m[l - 28]; - } - } - - for (j = 28; j < 56; j++) - { - l = j + totrot[i]; - if (l < 56) - { - pcr[j] = pc1m[l]; - } - else - { - pcr[j] = pc1m[l - 28]; - } - } - - for (j = 0; j < 24; j++) - { - if (pcr[pc2[j]]) - { - newKey[m] |= bigbyte[j]; - } - - if (pcr[pc2[j + 24]]) - { - newKey[n] |= bigbyte[j]; - } - } - } - - // - // store the processed key - // - for (i = 0; i != 32; i += 2) - { - var i1:uint; - var i2:uint; - - i1 = newKey[i]; - i2 = newKey[i + 1]; - - newKey[i] = ((i1 & 0x00fc0000) << 6) | ((i1 & 0x00000fc0) << 10) | ((i2 & 0x00fc0000) >>> 10) - | ((i2 & 0x00000fc0) >>> 6); - - newKey[i + 1] = ((i1 & 0x0003f000) << 12) | ((i1 & 0x0000003f) << 16) | ((i2 & 0x0003f000) >>> 4) - | (i2 & 0x0000003f); - } - return newKey; - } - - /** - * the DES engine. - */ - protected function desFunc(wKey:Array, inp:ByteArray, inOff:uint, out:ByteArray, outOff:uint):void - { - var work:uint; - var right:uint; - var left:uint; - - left = (inp[inOff + 0] & 0xff) << 24; - left |= (inp[inOff + 1] & 0xff) << 16; - left |= (inp[inOff + 2] & 0xff) << 8; - left |= (inp[inOff + 3] & 0xff); - - right = (inp[inOff + 4] & 0xff) << 24; - right |= (inp[inOff + 5] & 0xff) << 16; - right |= (inp[inOff + 6] & 0xff) << 8; - right |= (inp[inOff + 7] & 0xff); - - work = ((left >>> 4) ^ right) & 0x0f0f0f0f; - right ^= work; - left ^= (work << 4); - work = ((left >>> 16) ^ right) & 0x0000ffff; - right ^= work; - left ^= (work << 16); - work = ((right >>> 2) ^ left) & 0x33333333; - left ^= work; - right ^= (work << 2); - work = ((right >>> 8) ^ left) & 0x00ff00ff; - left ^= work; - right ^= (work << 8); - right = ((right << 1) | ((right >>> 31) & 1)) & 0xffffffff; - work = (left ^ right) & 0xaaaaaaaa; - left ^= work; - right ^= work; - left = ((left << 1) | ((left >>> 31) & 1)) & 0xffffffff; - - for (var round:uint = 0; round < 8; round++) - { - var fval:uint; - - work = (right << 28) | (right >>> 4); - work ^= wKey[round * 4 + 0]; - fval = SP7[work & 0x3f]; - fval |= SP5[(work >>> 8) & 0x3f]; - fval |= SP3[(work >>> 16) & 0x3f]; - fval |= SP1[(work >>> 24) & 0x3f]; - work = right ^ wKey[round * 4 + 1]; - fval |= SP8[work & 0x3f]; - fval |= SP6[(work >>> 8) & 0x3f]; - fval |= SP4[(work >>> 16) & 0x3f]; - fval |= SP2[(work >>> 24) & 0x3f]; - left ^= fval; - work = (left << 28) | (left >>> 4); - work ^= wKey[round * 4 + 2]; - fval = SP7[work & 0x3f]; - fval |= SP5[(work >>> 8) & 0x3f]; - fval |= SP3[(work >>> 16) & 0x3f]; - fval |= SP1[(work >>> 24) & 0x3f]; - work = left ^ wKey[round * 4 + 3]; - fval |= SP8[work & 0x3f]; - fval |= SP6[(work >>> 8) & 0x3f]; - fval |= SP4[(work >>> 16) & 0x3f]; - fval |= SP2[(work >>> 24) & 0x3f]; - right ^= fval; - } - - right = (right << 31) | (right >>> 1); - work = (left ^ right) & 0xaaaaaaaa; - left ^= work; - right ^= work; - left = (left << 31) | (left >>> 1); - work = ((left >>> 8) ^ right) & 0x00ff00ff; - right ^= work; - left ^= (work << 8); - work = ((left >>> 2) ^ right) & 0x33333333; - right ^= work; - left ^= (work << 2); - work = ((right >>> 16) ^ left) & 0x0000ffff; - left ^= work; - right ^= (work << 16); - work = ((right >>> 4) ^ left) & 0x0f0f0f0f; - left ^= work; - right ^= (work << 4); - - out[outOff + 0] = ((right >>> 24) & 0xff); - out[outOff + 1] = ((right >>> 16) & 0xff); - out[outOff + 2] = ((right >>> 8) & 0xff); - out[outOff + 3] = (right & 0xff); - out[outOff + 4] = ((left >>> 24) & 0xff); - out[outOff + 5] = ((left >>> 16) & 0xff); - out[outOff + 6] = ((left >>> 8) & 0xff); - out[outOff + 7] = (left & 0xff); - } - - - public function toString():String { - return "des"; - } - - - - } +/** + * DESKey + * + * An Actionscript 3 implementation of the Data Encryption Standard (DES) + * Copyright (c) 2007 Henri Torgemane + * + * Derived from: + * The Bouncy Castle Crypto package, + * Copyright (c) 2000-2004 The Legion Of The Bouncy Castle + * (http://www.bouncycastle.org) + * + * See LICENSE.txt for full license information. + */ +package com.hurlant.crypto.symmetric +{ + import flash.utils.ByteArray; + import com.hurlant.util.Hex; + import com.hurlant.util.Memory; + + public class DESKey implements ISymmetricKey + { + /** + * what follows is mainly taken from "Applied Cryptography", by Bruce + * Schneier, however it also bears great resemblance to Richard + * Outerbridge's D3DES... + */ + + private static const Df_Key:Array = [ 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, + 0x10, 0x89, 0xab, 0xcd, 0xef, 0x01, 0x23, 0x45, 0x67 ]; + + private static const bytebit:Array = [ 128, 64, 32, 16, 8, 4, 2, 1 ]; + + private static const bigbyte:Array = [ 0x800000, 0x400000, 0x200000, 0x100000, 0x80000, 0x40000, 0x20000, 0x10000, 0x8000, + 0x4000, 0x2000, 0x1000, 0x800, 0x400, 0x200, 0x100, 0x80, 0x40, 0x20, 0x10, 0x8, 0x4, 0x2, 0x1 ]; + + /* + * Use the key schedule specified in the Standard (ANSI X3.92-1981). + */ + + private static const pc1:Array = [ 56, 48, 40, 32, 24, 16, 8, 0, 57, 49, 41, 33, 25, 17, 9, 1, 58, 50, 42, 34, 26, 18, 10, 2, + 59, 51, 43, 35, 62, 54, 46, 38, 30, 22, 14, 6, 61, 53, 45, 37, 29, 21, 13, 5, 60, 52, 44, 36, 28, 20, 12, + 4, 27, 19, 11, 3 ]; + + private static const totrot:Array = [ 1, 2, 4, 6, 8, 10, 12, 14, 15, 17, 19, 21, 23, 25, 27, 28 ]; + + private static const pc2:Array = [ 13, 16, 10, 23, 0, 4, 2, 27, 14, 5, 20, 9, 22, 18, 11, 3, 25, 7, 15, 6, 26, 19, 12, 1, 40, + 51, 30, 36, 46, 54, 29, 39, 50, 44, 32, 47, 43, 48, 38, 55, 33, 52, 45, 41, 49, 35, 28, 31 ]; + + private static const SP1:Array = [ 0x01010400, 0x00000000, 0x00010000, 0x01010404, 0x01010004, 0x00010404, 0x00000004, + 0x00010000, 0x00000400, 0x01010400, 0x01010404, 0x00000400, 0x01000404, 0x01010004, 0x01000000, 0x00000004, + 0x00000404, 0x01000400, 0x01000400, 0x00010400, 0x00010400, 0x01010000, 0x01010000, 0x01000404, 0x00010004, + 0x01000004, 0x01000004, 0x00010004, 0x00000000, 0x00000404, 0x00010404, 0x01000000, 0x00010000, 0x01010404, + 0x00000004, 0x01010000, 0x01010400, 0x01000000, 0x01000000, 0x00000400, 0x01010004, 0x00010000, 0x00010400, + 0x01000004, 0x00000400, 0x00000004, 0x01000404, 0x00010404, 0x01010404, 0x00010004, 0x01010000, 0x01000404, + 0x01000004, 0x00000404, 0x00010404, 0x01010400, 0x00000404, 0x01000400, 0x01000400, 0x00000000, 0x00010004, + 0x00010400, 0x00000000, 0x01010004 ]; + + private static const SP2:Array = [ 0x80108020, 0x80008000, 0x00008000, 0x00108020, 0x00100000, 0x00000020, 0x80100020, + 0x80008020, 0x80000020, 0x80108020, 0x80108000, 0x80000000, 0x80008000, 0x00100000, 0x00000020, 0x80100020, + 0x00108000, 0x00100020, 0x80008020, 0x00000000, 0x80000000, 0x00008000, 0x00108020, 0x80100000, 0x00100020, + 0x80000020, 0x00000000, 0x00108000, 0x00008020, 0x80108000, 0x80100000, 0x00008020, 0x00000000, 0x00108020, + 0x80100020, 0x00100000, 0x80008020, 0x80100000, 0x80108000, 0x00008000, 0x80100000, 0x80008000, 0x00000020, + 0x80108020, 0x00108020, 0x00000020, 0x00008000, 0x80000000, 0x00008020, 0x80108000, 0x00100000, 0x80000020, + 0x00100020, 0x80008020, 0x80000020, 0x00100020, 0x00108000, 0x00000000, 0x80008000, 0x00008020, 0x80000000, + 0x80100020, 0x80108020, 0x00108000 ]; + + private static const SP3:Array = [ 0x00000208, 0x08020200, 0x00000000, 0x08020008, 0x08000200, 0x00000000, 0x00020208, + 0x08000200, 0x00020008, 0x08000008, 0x08000008, 0x00020000, 0x08020208, 0x00020008, 0x08020000, 0x00000208, + 0x08000000, 0x00000008, 0x08020200, 0x00000200, 0x00020200, 0x08020000, 0x08020008, 0x00020208, 0x08000208, + 0x00020200, 0x00020000, 0x08000208, 0x00000008, 0x08020208, 0x00000200, 0x08000000, 0x08020200, 0x08000000, + 0x00020008, 0x00000208, 0x00020000, 0x08020200, 0x08000200, 0x00000000, 0x00000200, 0x00020008, 0x08020208, + 0x08000200, 0x08000008, 0x00000200, 0x00000000, 0x08020008, 0x08000208, 0x00020000, 0x08000000, 0x08020208, + 0x00000008, 0x00020208, 0x00020200, 0x08000008, 0x08020000, 0x08000208, 0x00000208, 0x08020000, 0x00020208, + 0x00000008, 0x08020008, 0x00020200 ]; + + private static const SP4:Array = [ 0x00802001, 0x00002081, 0x00002081, 0x00000080, 0x00802080, 0x00800081, 0x00800001, + 0x00002001, 0x00000000, 0x00802000, 0x00802000, 0x00802081, 0x00000081, 0x00000000, 0x00800080, 0x00800001, + 0x00000001, 0x00002000, 0x00800000, 0x00802001, 0x00000080, 0x00800000, 0x00002001, 0x00002080, 0x00800081, + 0x00000001, 0x00002080, 0x00800080, 0x00002000, 0x00802080, 0x00802081, 0x00000081, 0x00800080, 0x00800001, + 0x00802000, 0x00802081, 0x00000081, 0x00000000, 0x00000000, 0x00802000, 0x00002080, 0x00800080, 0x00800081, + 0x00000001, 0x00802001, 0x00002081, 0x00002081, 0x00000080, 0x00802081, 0x00000081, 0x00000001, 0x00002000, + 0x00800001, 0x00002001, 0x00802080, 0x00800081, 0x00002001, 0x00002080, 0x00800000, 0x00802001, 0x00000080, + 0x00800000, 0x00002000, 0x00802080 ]; + + private static const SP5:Array = [ 0x00000100, 0x02080100, 0x02080000, 0x42000100, 0x00080000, 0x00000100, 0x40000000, + 0x02080000, 0x40080100, 0x00080000, 0x02000100, 0x40080100, 0x42000100, 0x42080000, 0x00080100, 0x40000000, + 0x02000000, 0x40080000, 0x40080000, 0x00000000, 0x40000100, 0x42080100, 0x42080100, 0x02000100, 0x42080000, + 0x40000100, 0x00000000, 0x42000000, 0x02080100, 0x02000000, 0x42000000, 0x00080100, 0x00080000, 0x42000100, + 0x00000100, 0x02000000, 0x40000000, 0x02080000, 0x42000100, 0x40080100, 0x02000100, 0x40000000, 0x42080000, + 0x02080100, 0x40080100, 0x00000100, 0x02000000, 0x42080000, 0x42080100, 0x00080100, 0x42000000, 0x42080100, + 0x02080000, 0x00000000, 0x40080000, 0x42000000, 0x00080100, 0x02000100, 0x40000100, 0x00080000, 0x00000000, + 0x40080000, 0x02080100, 0x40000100 ]; + + private static const SP6:Array = [ 0x20000010, 0x20400000, 0x00004000, 0x20404010, 0x20400000, 0x00000010, 0x20404010, + 0x00400000, 0x20004000, 0x00404010, 0x00400000, 0x20000010, 0x00400010, 0x20004000, 0x20000000, 0x00004010, + 0x00000000, 0x00400010, 0x20004010, 0x00004000, 0x00404000, 0x20004010, 0x00000010, 0x20400010, 0x20400010, + 0x00000000, 0x00404010, 0x20404000, 0x00004010, 0x00404000, 0x20404000, 0x20000000, 0x20004000, 0x00000010, + 0x20400010, 0x00404000, 0x20404010, 0x00400000, 0x00004010, 0x20000010, 0x00400000, 0x20004000, 0x20000000, + 0x00004010, 0x20000010, 0x20404010, 0x00404000, 0x20400000, 0x00404010, 0x20404000, 0x00000000, 0x20400010, + 0x00000010, 0x00004000, 0x20400000, 0x00404010, 0x00004000, 0x00400010, 0x20004010, 0x00000000, 0x20404000, + 0x20000000, 0x00400010, 0x20004010 ]; + + private static const SP7:Array = [ 0x00200000, 0x04200002, 0x04000802, 0x00000000, 0x00000800, 0x04000802, 0x00200802, + 0x04200800, 0x04200802, 0x00200000, 0x00000000, 0x04000002, 0x00000002, 0x04000000, 0x04200002, 0x00000802, + 0x04000800, 0x00200802, 0x00200002, 0x04000800, 0x04000002, 0x04200000, 0x04200800, 0x00200002, 0x04200000, + 0x00000800, 0x00000802, 0x04200802, 0x00200800, 0x00000002, 0x04000000, 0x00200800, 0x04000000, 0x00200800, + 0x00200000, 0x04000802, 0x04000802, 0x04200002, 0x04200002, 0x00000002, 0x00200002, 0x04000000, 0x04000800, + 0x00200000, 0x04200800, 0x00000802, 0x00200802, 0x04200800, 0x00000802, 0x04000002, 0x04200802, 0x04200000, + 0x00200800, 0x00000000, 0x00000002, 0x04200802, 0x00000000, 0x00200802, 0x04200000, 0x00000800, 0x04000002, + 0x04000800, 0x00000800, 0x00200002 ]; + + private static const SP8:Array = [ 0x10001040, 0x00001000, 0x00040000, 0x10041040, 0x10000000, 0x10001040, 0x00000040, + 0x10000000, 0x00040040, 0x10040000, 0x10041040, 0x00041000, 0x10041000, 0x00041040, 0x00001000, 0x00000040, + 0x10040000, 0x10000040, 0x10001000, 0x00001040, 0x00041000, 0x00040040, 0x10040040, 0x10041000, 0x00001040, + 0x00000000, 0x00000000, 0x10040040, 0x10000040, 0x10001000, 0x00041040, 0x00040000, 0x00041040, 0x00040000, + 0x10041000, 0x00001000, 0x00000040, 0x10040040, 0x00001000, 0x00041040, 0x10001000, 0x00000040, 0x10000040, + 0x10040000, 0x10040040, 0x10000000, 0x00040000, 0x10001040, 0x00000000, 0x10041040, 0x00040040, 0x10000040, + 0x10040000, 0x10001000, 0x10001040, 0x00000000, 0x10041040, 0x00041000, 0x00041000, 0x00001040, 0x00001040, + 0x00040040, 0x10000000, 0x10041000 ]; + + + protected var key:ByteArray; + protected var encKey:Array; + protected var decKey:Array; + + + public function DESKey(key:ByteArray) { + this.key = key; + this.encKey = generateWorkingKey(true, key, 0); + this.decKey = generateWorkingKey(false, key, 0); + } + + public function getBlockSize():uint + { + return 8; + } + + public function decrypt(block:ByteArray, index:uint=0):void + { + desFunc(decKey, block, index, block, index); + } + + public function dispose():void + { + var i:uint=0; + for (i=0;i>> 3)] & bytebit[l & 07]) != 0); + } + + for (var i:uint = 0; i < 16; i++) + { + var m:uint; + var n:uint; + + if (encrypting) + { + m = i << 1; + } + else + { + m = (15 - i) << 1; + } + + n = m + 1; + newKey[m] = newKey[n] = 0; + + for (j = 0; j < 28; j++) + { + l = j + totrot[i]; + if (l < 28) + { + pcr[j] = pc1m[l]; + } + else + { + pcr[j] = pc1m[l - 28]; + } + } + + for (j = 28; j < 56; j++) + { + l = j + totrot[i]; + if (l < 56) + { + pcr[j] = pc1m[l]; + } + else + { + pcr[j] = pc1m[l - 28]; + } + } + + for (j = 0; j < 24; j++) + { + if (pcr[pc2[j]]) + { + newKey[m] |= bigbyte[j]; + } + + if (pcr[pc2[j + 24]]) + { + newKey[n] |= bigbyte[j]; + } + } + } + + // + // store the processed key + // + for (i = 0; i != 32; i += 2) + { + var i1:uint; + var i2:uint; + + i1 = newKey[i]; + i2 = newKey[i + 1]; + + newKey[i] = ((i1 & 0x00fc0000) << 6) | ((i1 & 0x00000fc0) << 10) | ((i2 & 0x00fc0000) >>> 10) + | ((i2 & 0x00000fc0) >>> 6); + + newKey[i + 1] = ((i1 & 0x0003f000) << 12) | ((i1 & 0x0000003f) << 16) | ((i2 & 0x0003f000) >>> 4) + | (i2 & 0x0000003f); + } + return newKey; + } + + /** + * the DES engine. + */ + protected function desFunc(wKey:Array, inp:ByteArray, inOff:uint, out:ByteArray, outOff:uint):void + { + var work:uint; + var right:uint; + var left:uint; + + left = (inp[inOff + 0] & 0xff) << 24; + left |= (inp[inOff + 1] & 0xff) << 16; + left |= (inp[inOff + 2] & 0xff) << 8; + left |= (inp[inOff + 3] & 0xff); + + right = (inp[inOff + 4] & 0xff) << 24; + right |= (inp[inOff + 5] & 0xff) << 16; + right |= (inp[inOff + 6] & 0xff) << 8; + right |= (inp[inOff + 7] & 0xff); + + work = ((left >>> 4) ^ right) & 0x0f0f0f0f; + right ^= work; + left ^= (work << 4); + work = ((left >>> 16) ^ right) & 0x0000ffff; + right ^= work; + left ^= (work << 16); + work = ((right >>> 2) ^ left) & 0x33333333; + left ^= work; + right ^= (work << 2); + work = ((right >>> 8) ^ left) & 0x00ff00ff; + left ^= work; + right ^= (work << 8); + right = ((right << 1) | ((right >>> 31) & 1)) & 0xffffffff; + work = (left ^ right) & 0xaaaaaaaa; + left ^= work; + right ^= work; + left = ((left << 1) | ((left >>> 31) & 1)) & 0xffffffff; + + for (var round:uint = 0; round < 8; round++) + { + var fval:uint; + + work = (right << 28) | (right >>> 4); + work ^= wKey[round * 4 + 0]; + fval = SP7[work & 0x3f]; + fval |= SP5[(work >>> 8) & 0x3f]; + fval |= SP3[(work >>> 16) & 0x3f]; + fval |= SP1[(work >>> 24) & 0x3f]; + work = right ^ wKey[round * 4 + 1]; + fval |= SP8[work & 0x3f]; + fval |= SP6[(work >>> 8) & 0x3f]; + fval |= SP4[(work >>> 16) & 0x3f]; + fval |= SP2[(work >>> 24) & 0x3f]; + left ^= fval; + work = (left << 28) | (left >>> 4); + work ^= wKey[round * 4 + 2]; + fval = SP7[work & 0x3f]; + fval |= SP5[(work >>> 8) & 0x3f]; + fval |= SP3[(work >>> 16) & 0x3f]; + fval |= SP1[(work >>> 24) & 0x3f]; + work = left ^ wKey[round * 4 + 3]; + fval |= SP8[work & 0x3f]; + fval |= SP6[(work >>> 8) & 0x3f]; + fval |= SP4[(work >>> 16) & 0x3f]; + fval |= SP2[(work >>> 24) & 0x3f]; + right ^= fval; + } + + right = (right << 31) | (right >>> 1); + work = (left ^ right) & 0xaaaaaaaa; + left ^= work; + right ^= work; + left = (left << 31) | (left >>> 1); + work = ((left >>> 8) ^ right) & 0x00ff00ff; + right ^= work; + left ^= (work << 8); + work = ((left >>> 2) ^ right) & 0x33333333; + right ^= work; + left ^= (work << 2); + work = ((right >>> 16) ^ left) & 0x0000ffff; + left ^= work; + right ^= (work << 16); + work = ((right >>> 4) ^ left) & 0x0f0f0f0f; + left ^= work; + right ^= (work << 4); + + out[outOff + 0] = ((right >>> 24) & 0xff); + out[outOff + 1] = ((right >>> 16) & 0xff); + out[outOff + 2] = ((right >>> 8) & 0xff); + out[outOff + 3] = (right & 0xff); + out[outOff + 4] = ((left >>> 24) & 0xff); + out[outOff + 5] = ((left >>> 16) & 0xff); + out[outOff + 6] = ((left >>> 8) & 0xff); + out[outOff + 7] = (left & 0xff); + } + + + public function toString():String { + return "des"; + } + + + + } } \ No newline at end of file diff --git a/app/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/ECBMode.as b/app/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/ECBMode.as index 70783e8..b2a7b77 100644 --- a/app/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/ECBMode.as +++ b/app/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/ECBMode.as @@ -1,86 +1,86 @@ -/** - * ECBMode - * - * An ActionScript 3 implementation of the ECB confidentiality mode - * Copyright (c) 2007 Henri Torgemane - * - * See LICENSE.txt for full license information. - */ -package com.hurlant.crypto.symmetric -{ - import flash.utils.ByteArray; - import com.hurlant.util.Memory; - import com.hurlant.util.Hex; - - /** - * ECB mode. - * This uses a padding and a symmetric key. - * If no padding is given, PKCS#5 is used. - */ - public class ECBMode implements IMode, ICipher - { - private var key:ISymmetricKey; - private var padding:IPad; - - public function ECBMode(key:ISymmetricKey, padding:IPad = null) { - this.key = key; - if (padding == null) { - padding = new PKCS5(key.getBlockSize()); - } else { - padding.setBlockSize(key.getBlockSize()); - } - this.padding = padding; - } - - public function getBlockSize():uint { - return key.getBlockSize(); - } - - public function encrypt(src:ByteArray):void { - padding.pad(src); - src.position = 0; - var blockSize:uint = key.getBlockSize(); - var tmp:ByteArray = new ByteArray; - var dst:ByteArray = new ByteArray; - for (var i:uint=0;i0;i--) { - var v:uint = a[a.length-1]; - a.length--; - if (c!=v) throw new Error("PKCS#5:unpad: Invalid padding value. expected ["+c+"], found ["+v+"]"); - } - // that is all. - } - - public function setBlockSize(bs:uint):void { - blockSize = bs; - } - - } +/** + * PKCS5 + * + * A padding implementation of PKCS5. + * Copyright (c) 2007 Henri Torgemane + * + * See LICENSE.txt for full license information. + */ +package com.hurlant.crypto.symmetric +{ + import flash.utils.ByteArray; + + public class PKCS5 implements IPad + { + private var blockSize:uint; + + public function PKCS5(blockSize:uint=0) { + this.blockSize = blockSize; + } + + public function pad(a:ByteArray):void { + var c:uint = blockSize-a.length%blockSize; + for (var i:uint=0;i0;i--) { + var v:uint = a[a.length-1]; + a.length--; + if (c!=v) throw new Error("PKCS#5:unpad: Invalid padding value. expected ["+c+"], found ["+v+"]"); + } + // that is all. + } + + public function setBlockSize(bs:uint):void { + blockSize = bs; + } + + } } \ No newline at end of file diff --git a/app/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/SSLPad.as b/app/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/SSLPad.as old mode 100644 new mode 100755 diff --git a/app/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/SimpleIVMode.as b/app/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/SimpleIVMode.as index 16c65b2..590f0df 100644 --- a/app/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/SimpleIVMode.as +++ b/app/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/SimpleIVMode.as @@ -1,60 +1,60 @@ -/** - * SimpleIVMode - * - * A convenience class that automatically places the IV - * at the beginning of the encrypted stream, so it doesn't have to - * be handled explicitely. - * Copyright (c) 2007 Henri Torgemane - * - * See LICENSE.txt for full license information. - */ -package com.hurlant.crypto.symmetric -{ - import flash.utils.ByteArray; - import com.hurlant.util.Memory; - - public class SimpleIVMode implements IMode, ICipher - { - protected var mode:IVMode; - protected var cipher:ICipher; - - public function SimpleIVMode(mode:IVMode) { - this.mode = mode; - cipher = mode as ICipher; - } - - public function getBlockSize():uint { - return mode.getBlockSize(); - } - - public function dispose():void { - mode.dispose(); - mode = null; - cipher = null; - Memory.gc(); - } - - public function encrypt(src:ByteArray):void { - cipher.encrypt(src); - var tmp:ByteArray = new ByteArray; - tmp.writeBytes(mode.IV); - tmp.writeBytes(src); - src.position=0; - src.writeBytes(tmp); - } - - public function decrypt(src:ByteArray):void { - var tmp:ByteArray = new ByteArray; - tmp.writeBytes(src, 0, getBlockSize()); - mode.IV = tmp; - tmp = new ByteArray; - tmp.writeBytes(src, getBlockSize()); - cipher.decrypt(tmp); - src.length=0; - src.writeBytes(tmp); - } - public function toString():String { - return "simple-"+cipher.toString(); - } - } +/** + * SimpleIVMode + * + * A convenience class that automatically places the IV + * at the beginning of the encrypted stream, so it doesn't have to + * be handled explicitely. + * Copyright (c) 2007 Henri Torgemane + * + * See LICENSE.txt for full license information. + */ +package com.hurlant.crypto.symmetric +{ + import flash.utils.ByteArray; + import com.hurlant.util.Memory; + + public class SimpleIVMode implements IMode, ICipher + { + protected var mode:IVMode; + protected var cipher:ICipher; + + public function SimpleIVMode(mode:IVMode) { + this.mode = mode; + cipher = mode as ICipher; + } + + public function getBlockSize():uint { + return mode.getBlockSize(); + } + + public function dispose():void { + mode.dispose(); + mode = null; + cipher = null; + Memory.gc(); + } + + public function encrypt(src:ByteArray):void { + cipher.encrypt(src); + var tmp:ByteArray = new ByteArray; + tmp.writeBytes(mode.IV); + tmp.writeBytes(src); + src.position=0; + src.writeBytes(tmp); + } + + public function decrypt(src:ByteArray):void { + var tmp:ByteArray = new ByteArray; + tmp.writeBytes(src, 0, getBlockSize()); + mode.IV = tmp; + tmp = new ByteArray; + tmp.writeBytes(src, getBlockSize()); + cipher.decrypt(tmp); + src.length=0; + src.writeBytes(tmp); + } + public function toString():String { + return "simple-"+cipher.toString(); + } + } } \ No newline at end of file diff --git a/app/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/TLSPad.as b/app/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/TLSPad.as index 4f6a436..f3b6182 100644 --- a/app/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/TLSPad.as +++ b/app/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/TLSPad.as @@ -1,42 +1,42 @@ -/** - * TLSPad - * - * A padding implementation used by TLS - * Copyright (c) 2007 Henri Torgemane - * - * See LICENSE.txt for full license information. - */ -package com.hurlant.crypto.symmetric { - import flash.utils.ByteArray; - import com.hurlant.util.Hex; - import com.hurlant.crypto.tls.TLSError; - - public class TLSPad implements IPad { - private var blockSize:uint; - - public function TLSPad(blockSize:uint=0) { - this.blockSize = blockSize; - } - public function pad(a:ByteArray):void { - var c:uint = blockSize - (a.length+1)%blockSize; - for (var i:uint=0;i<=c;i++) { - a[a.length] = c; - } - } - public function unpad(a:ByteArray):void { - var c:uint = a.length%blockSize; - if (c!=0) throw new TLSError("TLSPad::unpad: ByteArray.length isn't a multiple of the blockSize", TLSError.bad_record_mac); - c = a[a.length-1]; - for (var i:uint=c;i>0;i--) { - var v:uint = a[a.length-1]; - a.length--; - if (c!=v) throw new TLSError("TLSPad:unpad: Invalid padding value. expected ["+c+"], found ["+v+"]", TLSError.bad_record_mac); - } - a.length--; - // mostly ripped off from PKCS5.as, but with subtle differences - } - public function setBlockSize(bs:uint):void { - blockSize = bs; - } - } +/** + * TLSPad + * + * A padding implementation used by TLS + * Copyright (c) 2007 Henri Torgemane + * + * See LICENSE.txt for full license information. + */ +package com.hurlant.crypto.symmetric { + import flash.utils.ByteArray; + import com.hurlant.util.Hex; + import com.hurlant.crypto.tls.TLSError; + + public class TLSPad implements IPad { + private var blockSize:uint; + + public function TLSPad(blockSize:uint=0) { + this.blockSize = blockSize; + } + public function pad(a:ByteArray):void { + var c:uint = blockSize - (a.length+1)%blockSize; + for (var i:uint=0;i<=c;i++) { + a[a.length] = c; + } + } + public function unpad(a:ByteArray):void { + var c:uint = a.length%blockSize; + if (c!=0) throw new TLSError("TLSPad::unpad: ByteArray.length isn't a multiple of the blockSize", TLSError.bad_record_mac); + c = a[a.length-1]; + for (var i:uint=c;i>0;i--) { + var v:uint = a[a.length-1]; + a.length--; + if (c!=v) throw new TLSError("TLSPad:unpad: Invalid padding value. expected ["+c+"], found ["+v+"]", TLSError.bad_record_mac); + } + a.length--; + // mostly ripped off from PKCS5.as, but with subtle differences + } + public function setBlockSize(bs:uint):void { + blockSize = bs; + } + } } \ No newline at end of file diff --git a/app/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/TripleDESKey.as b/app/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/TripleDESKey.as index 880e041..1e75011 100644 --- a/app/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/TripleDESKey.as +++ b/app/node_modules/socket.io/node_modules/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/TripleDESKey.as @@ -1,88 +1,88 @@ -/** - * TripleDESKey - * - * An Actionscript 3 implementation of Triple DES - * Copyright (c) 2007 Henri Torgemane - * - * Derived from: - * The Bouncy Castle Crypto package, - * Copyright (c) 2000-2004 The Legion Of The Bouncy Castle - * (http://www.bouncycastle.org) - * - * See LICENSE.txt for full license information. - */ -package com.hurlant.crypto.symmetric -{ - import flash.utils.ByteArray; - import com.hurlant.util.Memory; - import com.hurlant.util.Hex; - - public class TripleDESKey extends DESKey - { - protected var encKey2:Array; - protected var encKey3:Array; - protected var decKey2:Array; - protected var decKey3:Array; - - /** - * This supports 2TDES and 3TDES. - * If the key passed is 128 bits, 2TDES is used. - * If the key has 192 bits, 3TDES is used. - * Other key lengths give "undefined" results. - */ - public function TripleDESKey(key:ByteArray) - { - super(key); - encKey2 = generateWorkingKey(false, key, 8); - decKey2 = generateWorkingKey(true, key, 8); - if (key.length>16) { - encKey3 = generateWorkingKey(true, key, 16); - decKey3 = generateWorkingKey(false, key, 16); - } else { - encKey3 = encKey; - decKey3 = decKey; - } - } - - public override function dispose():void - { - super.dispose(); - var i:uint = 0; - if (encKey2!=null) { - for (i=0;i16) { + encKey3 = generateWorkingKey(true, key, 16); + decKey3 = generateWorkingKey(false, key, 16); + } else { + encKey3 = encKey; + decKey3 = decKey; + } + } + + public override function dispose():void + { + super.dispose(); + var i:uint = 0; + if (encKey2!=null) { + for (i=0;i> 5)) + v1) ^ (sum + k[sum & 3]); - sum += delta; - v1 += (((v0 << 4) ^ (v0 >> 5)) + v0) ^ (sum + k[(sum>>11) & 3]); - } - block.position-=8; - block.writeUnsignedInt(v0); - block.writeUnsignedInt(v1); - } - - public function decrypt(block:ByteArray, index:uint=0):void { - block.position = index; - var v0:uint = block.readUnsignedInt(); - var v1:uint = block.readUnsignedInt(); - var i:uint; - var delta:uint = 0x9E3779B9; - var sum:uint = delta*NUM_ROUNDS; - for (i=0; i> 5)) + v0) ^ (sum + k[(sum>>11) & 3]); - sum -= delta; - v0 -= (((v1 << 4) ^ (v1 >> 5)) + v1) ^ (sum + k[sum & 3]); - } - block.position-=8; - block.writeUnsignedInt(v0); - block.writeUnsignedInt(v1); - } - - public function dispose():void { - //private var k:Array; - var r:Random = new Random; - for (var i:uint=0;i> 5)) + v1) ^ (sum + k[sum & 3]); + sum += delta; + v1 += (((v0 << 4) ^ (v0 >> 5)) + v0) ^ (sum + k[(sum>>11) & 3]); + } + block.position-=8; + block.writeUnsignedInt(v0); + block.writeUnsignedInt(v1); + } + + public function decrypt(block:ByteArray, index:uint=0):void { + block.position = index; + var v0:uint = block.readUnsignedInt(); + var v1:uint = block.readUnsignedInt(); + var i:uint; + var delta:uint = 0x9E3779B9; + var sum:uint = delta*NUM_ROUNDS; + for (i=0; i> 5)) + v0) ^ (sum + k[(sum>>11) & 3]); + sum -= delta; + v0 -= (((v1 << 4) ^ (v1 >> 5)) + v1) ^ (sum + k[sum & 3]); + } + block.position-=8; + block.writeUnsignedInt(v0); + block.writeUnsignedInt(v1); + } + + public function dispose():void { + //private var k:Array; + var r:Random = new Random; + for (var i:uint=0;i