summaryrefslogtreecommitdiff
path: root/frontend/beta/js/Clipperz/Crypto/Base.js
Side-by-side diff
Diffstat (limited to 'frontend/beta/js/Clipperz/Crypto/Base.js') (more/less context) (ignore whitespace changes)
-rw-r--r--frontend/beta/js/Clipperz/Crypto/Base.js22
1 files changed, 10 insertions, 12 deletions
diff --git a/frontend/beta/js/Clipperz/Crypto/Base.js b/frontend/beta/js/Clipperz/Crypto/Base.js
index d3a8e36..9acfc49 100644
--- a/frontend/beta/js/Clipperz/Crypto/Base.js
+++ b/frontend/beta/js/Clipperz/Crypto/Base.js
@@ -1,790 +1,788 @@
/*
-Copyright 2008-2011 Clipperz Srl
+Copyright 2008-2013 Clipperz Srl
-This file is part of Clipperz Community Edition.
-Clipperz Community Edition is an online password manager.
+This file is part of Clipperz, the online password manager.
For further information about its features and functionalities please
refer to http://www.clipperz.com.
-* Clipperz Community Edition is free software: you can redistribute
- it and/or modify it under the terms of the GNU Affero General Public
- License as published by the Free Software Foundation, either version
- 3 of the License, or (at your option) any later version.
+* Clipperz is free software: you can redistribute it and/or modify it
+ under the terms of the GNU Affero General Public License as published
+ by the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
-* Clipperz Community Edition is distributed in the hope that it will
- be useful, but WITHOUT ANY WARRANTY; without even the implied
- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+* Clipperz is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public
- License along with Clipperz Community Edition. If not, see
- <http://www.gnu.org/licenses/>.
+ License along with Clipperz. If not, see http://www.gnu.org/licenses/.
*/
try { if (typeof(Clipperz.Base) == 'undefined') { throw ""; }} catch (e) {
throw "Clipperz.Crypto.Base depends on Clipperz.Base!";
}
if (typeof(Clipperz.Crypto) == 'undefined') { Clipperz.Crypto = {}; }
if (typeof(Clipperz.Crypto.Base) == 'undefined') { Clipperz.Crypto.Base = {}; }
Clipperz.Crypto.Base.VERSION = "0.1";
Clipperz.Crypto.Base.NAME = "Clipperz.Crypto.Base";
//#############################################################################
// Downloaded on March 30, 2006 from http://anmar.eu.org/projects/jssha2/files/jssha2-0.3.zip (jsSha2/sha256.js)
//#############################################################################
/* A JavaScript implementation of the Secure Hash Algorithm, SHA-256
* Version 0.3 Copyright Angel Marin 2003-2004 - http://anmar.eu.org/
* Distributed under the BSD License
* Some bits taken from Paul Johnston's SHA-1 implementation
*/
var chrsz = 8; /* bits per input character. 8 - ASCII; 16 - Unicode */
function safe_add (x, y) {
var lsw = (x & 0xFFFF) + (y & 0xFFFF);
var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
return (msw << 16) | (lsw & 0xFFFF);
}
function S (X, n) {return ( X >>> n ) | (X << (32 - n));}
function R (X, n) {return ( X >>> n );}
function Ch(x, y, z) {return ((x & y) ^ ((~x) & z));}
function Maj(x, y, z) {return ((x & y) ^ (x & z) ^ (y & z));}
function Sigma0256(x) {return (S(x, 2) ^ S(x, 13) ^ S(x, 22));}
function Sigma1256(x) {return (S(x, 6) ^ S(x, 11) ^ S(x, 25));}
function Gamma0256(x) {return (S(x, 7) ^ S(x, 18) ^ R(x, 3));}
function Gamma1256(x) {return (S(x, 17) ^ S(x, 19) ^ R(x, 10));}
function core_sha256 (m, l) {
var K = new Array(0x428A2F98,0x71374491,0xB5C0FBCF,0xE9B5DBA5,0x3956C25B,0x59F111F1,0x923F82A4,0xAB1C5ED5,0xD807AA98,0x12835B01,0x243185BE,0x550C7DC3,0x72BE5D74,0x80DEB1FE,0x9BDC06A7,0xC19BF174,0xE49B69C1,0xEFBE4786,0xFC19DC6,0x240CA1CC,0x2DE92C6F,0x4A7484AA,0x5CB0A9DC,0x76F988DA,0x983E5152,0xA831C66D,0xB00327C8,0xBF597FC7,0xC6E00BF3,0xD5A79147,0x6CA6351,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);
var HASH = new Array(0x6A09E667, 0xBB67AE85, 0x3C6EF372, 0xA54FF53A, 0x510E527F, 0x9B05688C, 0x1F83D9AB, 0x5BE0CD19);
var W = new Array(64);
var a, b, c, d, e, f, g, h, i, j;
var T1, T2;
/* append padding */
m[l >> 5] |= 0x80 << (24 - l % 32);
m[((l + 64 >> 9) << 4) + 15] = l;
for ( var i = 0; i<m.length; i+=16 ) {
a = HASH[0]; b = HASH[1]; c = HASH[2]; d = HASH[3]; e = HASH[4]; f = HASH[5]; g = HASH[6]; h = HASH[7];
for ( var j = 0; j<64; j++) {
if (j < 16) W[j] = m[j + i];
else W[j] = safe_add(safe_add(safe_add(Gamma1256(W[j - 2]), W[j - 7]), Gamma0256(W[j - 15])), W[j - 16]);
T1 = safe_add(safe_add(safe_add(safe_add(h, Sigma1256(e)), Ch(e, f, g)), K[j]), W[j]);
T2 = safe_add(Sigma0256(a), Maj(a, b, c));
h = g; g = f; f = e; e = safe_add(d, T1); d = c; c = b; b = a; a = safe_add(T1, T2);
}
HASH[0] = safe_add(a, HASH[0]); HASH[1] = safe_add(b, HASH[1]); HASH[2] = safe_add(c, HASH[2]); HASH[3] = safe_add(d, HASH[3]); HASH[4] = safe_add(e, HASH[4]); HASH[5] = safe_add(f, HASH[5]); HASH[6] = safe_add(g, HASH[6]); HASH[7] = safe_add(h, HASH[7]);
}
return HASH;
}
function str2binb (str) {
var bin = Array();
var mask = (1 << chrsz) - 1;
for(var i = 0; i < str.length * chrsz; i += chrsz)
bin[i>>5] |= (str.charCodeAt(i / chrsz) & mask) << (24 - i%32);
return bin;
}
function binb2hex (binarray) {
var hexcase = 0; /* hex output format. 0 - lowercase; 1 - uppercase */
var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef";
var str = "";
for (var i = 0; i < binarray.length * 4; i++) {
str += hex_tab.charAt((binarray[i>>2] >> ((3 - i%4)*8+4)) & 0xF) + hex_tab.charAt((binarray[i>>2] >> ((3 - i%4)*8 )) & 0xF);
}
return str;
}
function hex_sha256(s){return binb2hex(core_sha256(str2binb(s),s.length * chrsz));}
//#############################################################################
// Downloaded on March 30, 2006 from http://www.fourmilab.ch/javascrypt/javascrypt.zip (entropy.js)
//#############################################################################
// Entropy collection utilities
/* Start by declaring static storage and initialise
the entropy vector from the time we come through
here. */
var entropyData = new Array(); // Collected entropy data
var edlen = 0; // Keyboard array data length
addEntropyTime(); // Start entropy collection with page load time
ce(); // Roll milliseconds into initial entropy
// Add a byte to the entropy vector
function addEntropyByte(b) {
entropyData[edlen++] = b;
}
/* Capture entropy. When the user presses a key or performs
various other events for which we can request
notification, add the time in 255ths of a second to the
entropyData array. The name of the function is short
so it doesn't bloat the form object declarations in
which it appears in various "onXXX" events. */
function ce() {
addEntropyByte(Math.floor((((new Date).getMilliseconds()) * 255) / 999));
}
// Add a 32 bit quantity to the entropy vector
function addEntropy32(w) {
var i;
for (i = 0; i < 4; i++) {
addEntropyByte(w & 0xFF);
w >>= 8;
}
}
/* Add the current time and date (milliseconds since the epoch,
truncated to 32 bits) to the entropy vector. */
function addEntropyTime() {
addEntropy32((new Date()).getTime());
}
/* Start collection of entropy from mouse movements. The
argument specifies the number of entropy items to be
obtained from mouse motion, after which mouse motion
will be ignored. Note that you can re-enable mouse
motion collection at any time if not already underway. */
var mouseMotionCollect = 0;
var oldMoveHandler; // For saving and restoring mouse move handler in IE4
function mouseMotionEntropy(maxsamp) {
if (mouseMotionCollect <= 0) {
mouseMotionCollect = maxsamp;
if ((document.implementation.hasFeature("Events", "2.0")) &&
document.addEventListener) {
// Browser supports Document Object Model (DOM) 2 events
document.addEventListener("mousemove", mouseMoveEntropy, false);
} else {
if (document.attachEvent) {
// Internet Explorer 5 and above event model
document.attachEvent("onmousemove", mouseMoveEntropy);
} else {
// Internet Explorer 4 event model
oldMoveHandler = document.onmousemove;
document.onmousemove = mouseMoveEntropy;
}
}
//dump("Mouse enable", mouseMotionCollect);
}
}
/* Collect entropy from mouse motion events. Note that
this is craftily coded to work with either DOM2 or Internet
Explorer style events. Note that we don't use every successive
mouse movement event. Instead, we XOR the three bytes collected
from the mouse and use that to determine how many subsequent
mouse movements we ignore before capturing the next one. */
var mouseEntropyTime = 0; // Delay counter for mouse entropy collection
function mouseMoveEntropy(e) {
if (!e) {
e = window.event; // Internet Explorer event model
}
if (mouseMotionCollect > 0) {
if (mouseEntropyTime-- <= 0) {
addEntropyByte(e.screenX & 0xFF);
addEntropyByte(e.screenY & 0xFF);
ce();
mouseMotionCollect--;
mouseEntropyTime = (entropyData[edlen - 3] ^ entropyData[edlen - 2] ^
entropyData[edlen - 1]) % 19;
//dump("Mouse Move", byteArrayToHex(entropyData.slice(-3)));
}
if (mouseMotionCollect <= 0) {
if (document.removeEventListener) {
document.removeEventListener("mousemove", mouseMoveEntropy, false);
} else if (document.detachEvent) {
document.detachEvent("onmousemove", mouseMoveEntropy);
} else {
document.onmousemove = oldMoveHandler;
}
//dump("Spung!", 0);
}
}
}
/* Compute a 32 byte key value from the entropy vector.
We compute the value by taking the MD5 sum of the even
and odd bytes respectively of the entropy vector, then
concatenating the two MD5 sums. */
function keyFromEntropy() {
var i, k = new Array(32);
if (edlen == 0) {
alert("Blooie! Entropy vector void at call to keyFromEntropy.");
}
//dump("Entropy bytes", edlen);
md5_init();
for (i = 0; i < edlen; i += 2) {
md5_update(entropyData[i]);
}
md5_finish();
for (i = 0; i < 16; i++) {
k[i] = digestBits[i];
}
md5_init();
for (i = 1; i < edlen; i += 2) {
md5_update(entropyData[i]);
}
md5_finish();
for (i = 0; i < 16; i++) {
k[i + 16] = digestBits[i];
}
//dump("keyFromEntropy", byteArrayToHex(k));
return k;
}
//#############################################################################
// Downloaded on March 30, 2006 from http://www.fourmilab.ch/javascrypt/javascrypt.zip (aesprng.js)
//#############################################################################
// AES based pseudorandom number generator
/* Constructor. Called with an array of 32 byte (0-255) values
containing the initial seed. */
function AESprng(seed) {
this.key = new Array();
this.key = seed;
this.itext = hexToByteArray("9F489613248148F9C27945C6AE62EECA3E3367BB14064E4E6DC67A9F28AB3BD1");
this.nbytes = 0; // Bytes left in buffer
this.next = AESprng_next;
this.nextbits = AESprng_nextbits;
this.nextInt = AESprng_nextInt;
this.round = AESprng_round;
/* Encrypt the initial text with the seed key
three times, feeding the output of the encryption
back into the key for the next round. */
bsb = blockSizeInBits;
blockSizeInBits = 256;
var i, ct;
for (i = 0; i < 3; i++) {
this.key = rijndaelEncrypt(this.itext, this.key, "ECB");
}
/* Now make between one and four additional
key-feedback rounds, with the number determined
by bits from the result of the first three
rounds. */
var n = 1 + (this.key[3] & 2) + (this.key[9] & 1);
for (i = 0; i < n; i++) {
this.key = rijndaelEncrypt(this.itext, this.key, "ECB");
}
blockSizeInBits = bsb;
}
function AESprng_round() {
bsb = blockSizeInBits;
blockSizeInBits = 256;
this.key = rijndaelEncrypt(this.itext, this.key, "ECB");
this.nbytes = 32;
blockSizeInBits = bsb;
}
// Return next byte from the generator
function AESprng_next() {
if (this.nbytes <= 0) {
this.round();
}
return(this.key[--this.nbytes]);
}
// Return n bit integer value (up to maximum integer size)
function AESprng_nextbits(n) {
var i, w = 0, nbytes = Math.floor((n + 7) / 8);
for (i = 0; i < nbytes; i++) {
w = (w << 8) | this.next();
}
return w & ((1 << n) - 1);
}
// Return integer between 0 and n inclusive
function AESprng_nextInt(n) {
var p = 1, nb = 0;
// Determine smallest p, 2^p > n
// nb = log_2 p
while (n >= p) {
p <<= 1;
nb++;
}
p--;
/* Generate values from 0 through n by first generating
values v from 0 to (2^p)-1, then discarding any results v > n.
For the rationale behind this (and why taking
values mod (n + 1) is biased toward smaller values, see
Ferguson and Schneier, "Practical Cryptography",
ISBN 0-471-22357-3, section 10.8). */
while (true) {
var v = this.nextbits(nb) & p;
if (v <= n) {
return v;
}
}
}
//#############################################################################
// Downloaded on March 30, 2006 from http://www.fourmilab.ch/javascrypt/javascrypt.zip (md5.js)
//#############################################################################
/*
* md5.jvs 1.0b 27/06/96
*
* Javascript implementation of the RSA Data Security, Inc. MD5
* Message-Digest Algorithm.
*
* Copyright (c) 1996 Henri Torgemane. All Rights Reserved.
*
* Permission to use, copy, modify, and distribute this software
* and its documentation for any purposes and without
* fee is hereby granted provided that this copyright notice
* appears in all copies.
*
* Of course, this soft is provided "as is" without express or implied
* warranty of any kind.
This version contains some trivial reformatting modifications
by John Walker.
*/
function array(n) {
for (i = 0; i < n; i++) {
this[i] = 0;
}
this.length = n;
}
/* Some basic logical functions had to be rewritten because of a bug in
* Javascript.. Just try to compute 0xffffffff >> 4 with it..
* Of course, these functions are slower than the original would be, but
* at least, they work!
*/
function integer(n) {
return n % (0xffffffff + 1);
}
function shr(a, b) {
a = integer(a);
b = integer(b);
if (a - 0x80000000 >= 0) {
a = a % 0x80000000;
a >>= b;
a += 0x40000000 >> (b - 1);
} else {
a >>= b;
}
return a;
}
function shl1(a) {
a = a % 0x80000000;
if (a & 0x40000000 == 0x40000000) {
a -= 0x40000000;
a *= 2;
a += 0x80000000;
} else {
a *= 2;
}
return a;
}
function shl(a, b) {
a = integer(a);
b = integer(b);
for (var i = 0; i < b; i++) {
a = shl1(a);
}
return a;
}
function and(a, b) {
a = integer(a);
b = integer(b);
var t1 = a - 0x80000000;
var t2 = b - 0x80000000;
if (t1 >= 0) {
if (t2 >= 0) {
return ((t1 & t2) + 0x80000000);
} else {
return (t1 & b);
}
} else {
if (t2 >= 0) {
return (a & t2);
} else {
return (a & b);
}
}
}
function or(a, b) {
a = integer(a);
b = integer(b);
var t1 = a - 0x80000000;
var t2 = b - 0x80000000;
if (t1 >= 0) {
if (t2 >= 0) {
return ((t1 | t2) + 0x80000000);
} else {
return ((t1 | b) + 0x80000000);
}
} else {
if (t2 >= 0) {
return ((a | t2) + 0x80000000);
} else {
return (a | b);
}
}
}
function xor(a, b) {
a = integer(a);
b = integer(b);
var t1 = a - 0x80000000;
var t2 = b - 0x80000000;
if (t1 >= 0) {
if (t2 >= 0) {
return (t1 ^ t2);
} else {
return ((t1 ^ b) + 0x80000000);
}
} else {
if (t2 >= 0) {
return ((a ^ t2) + 0x80000000);
} else {
return (a ^ b);
}
}
}
function not(a) {
a = integer(a);
return 0xffffffff - a;
}
/* Here begin the real algorithm */
var state = new array(4);
var count = new array(2);
count[0] = 0;
count[1] = 0;
var buffer = new array(64);
var transformBuffer = new array(16);
var digestBits = new array(16);
var S11 = 7;
var S12 = 12;
var S13 = 17;
var S14 = 22;
var S21 = 5;
var S22 = 9;
var S23 = 14;
var S24 = 20;
var S31 = 4;
var S32 = 11;
var S33 = 16;
var S34 = 23;
var S41 = 6;
var S42 = 10;
var S43 = 15;
var S44 = 21;
function F(x, y, z) {
return or(and(x, y), and(not(x), z));
}
function G(x, y, z) {
return or(and(x, z), and(y, not(z)));
}
function H(x, y, z) {
return xor(xor(x, y), z);
}
function I(x, y, z) {
return xor(y ,or(x , not(z)));
}
function rotateLeft(a, n) {
return or(shl(a, n), (shr(a, (32 - n))));
}
function FF(a, b, c, d, x, s, ac) {
a = a + F(b, c, d) + x + ac;
a = rotateLeft(a, s);
a = a + b;
return a;
}
function GG(a, b, c, d, x, s, ac) {
a = a + G(b, c, d) + x + ac;
a = rotateLeft(a, s);
a = a + b;
return a;
}
function HH(a, b, c, d, x, s, ac) {
a = a + H(b, c, d) + x + ac;
a = rotateLeft(a, s);
a = a + b;
return a;
}
function II(a, b, c, d, x, s, ac) {
a = a + I(b, c, d) + x + ac;
a = rotateLeft(a, s);
a = a + b;
return a;
}
function transform(buf, offset) {
var a = 0, b = 0, c = 0, d = 0;
var x = transformBuffer;
a = state[0];
b = state[1];
c = state[2];
d = state[3];
for (i = 0; i < 16; i++) {
x[i] = and(buf[i * 4 + offset], 0xFF);
for (j = 1; j < 4; j++) {
x[i] += shl(and(buf[i * 4 + j + offset] ,0xFF), j * 8);
}
}
/* Round 1 */
a = FF( a, b, c, d, x[ 0], S11, 0xd76aa478); /* 1 */
d = FF( d, a, b, c, x[ 1], S12, 0xe8c7b756); /* 2 */
c = FF( c, d, a, b, x[ 2], S13, 0x242070db); /* 3 */
b = FF( b, c, d, a, x[ 3], S14, 0xc1bdceee); /* 4 */
a = FF( a, b, c, d, x[ 4], S11, 0xf57c0faf); /* 5 */
d = FF( d, a, b, c, x[ 5], S12, 0x4787c62a); /* 6 */
c = FF( c, d, a, b, x[ 6], S13, 0xa8304613); /* 7 */
b = FF( b, c, d, a, x[ 7], S14, 0xfd469501); /* 8 */
a = FF( a, b, c, d, x[ 8], S11, 0x698098d8); /* 9 */
d = FF( d, a, b, c, x[ 9], S12, 0x8b44f7af); /* 10 */
c = FF( c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */
b = FF( b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */
a = FF( a, b, c, d, x[12], S11, 0x6b901122); /* 13 */
d = FF( d, a, b, c, x[13], S12, 0xfd987193); /* 14 */
c = FF( c, d, a, b, x[14], S13, 0xa679438e); /* 15 */
b = FF( b, c, d, a, x[15], S14, 0x49b40821); /* 16 */
/* Round 2 */
a = GG( a, b, c, d, x[ 1], S21, 0xf61e2562); /* 17 */
d = GG( d, a, b, c, x[ 6], S22, 0xc040b340); /* 18 */
c = GG( c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */
b = GG( b, c, d, a, x[ 0], S24, 0xe9b6c7aa); /* 20 */
a = GG( a, b, c, d, x[ 5], S21, 0xd62f105d); /* 21 */
d = GG( d, a, b, c, x[10], S22, 0x2441453); /* 22 */
c = GG( c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */
b = GG( b, c, d, a, x[ 4], S24, 0xe7d3fbc8); /* 24 */
a = GG( a, b, c, d, x[ 9], S21, 0x21e1cde6); /* 25 */
d = GG( d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */
c = GG( c, d, a, b, x[ 3], S23, 0xf4d50d87); /* 27 */
b = GG( b, c, d, a, x[ 8], S24, 0x455a14ed); /* 28 */
a = GG( a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */
d = GG( d, a, b, c, x[ 2], S22, 0xfcefa3f8); /* 30 */
c = GG( c, d, a, b, x[ 7], S23, 0x676f02d9); /* 31 */
b = GG( b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */
/* Round 3 */
a = HH( a, b, c, d, x[ 5], S31, 0xfffa3942); /* 33 */
d = HH( d, a, b, c, x[ 8], S32, 0x8771f681); /* 34 */
c = HH( c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */
b = HH( b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */
a = HH( a, b, c, d, x[ 1], S31, 0xa4beea44); /* 37 */
d = HH( d, a, b, c, x[ 4], S32, 0x4bdecfa9); /* 38 */
c = HH( c, d, a, b, x[ 7], S33, 0xf6bb4b60); /* 39 */
b = HH( b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */
a = HH( a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */
d = HH( d, a, b, c, x[ 0], S32, 0xeaa127fa); /* 42 */
c = HH( c, d, a, b, x[ 3], S33, 0xd4ef3085); /* 43 */
b = HH( b, c, d, a, x[ 6], S34, 0x4881d05); /* 44 */
a = HH( a, b, c, d, x[ 9], S31, 0xd9d4d039); /* 45 */
d = HH( d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */
c = HH( c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */
b = HH( b, c, d, a, x[ 2], S34, 0xc4ac5665); /* 48 */
/* Round 4 */
a = II( a, b, c, d, x[ 0], S41, 0xf4292244); /* 49 */
d = II( d, a, b, c, x[ 7], S42, 0x432aff97); /* 50 */
c = II( c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */
b = II( b, c, d, a, x[ 5], S44, 0xfc93a039); /* 52 */
a = II( a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */
d = II( d, a, b, c, x[ 3], S42, 0x8f0ccc92); /* 54 */
c = II( c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */
b = II( b, c, d, a, x[ 1], S44, 0x85845dd1); /* 56 */
a = II( a, b, c, d, x[ 8], S41, 0x6fa87e4f); /* 57 */
d = II( d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */
c = II( c, d, a, b, x[ 6], S43, 0xa3014314); /* 59 */
b = II( b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */
a = II( a, b, c, d, x[ 4], S41, 0xf7537e82); /* 61 */
d = II( d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */
c = II( c, d, a, b, x[ 2], S43, 0x2ad7d2bb); /* 63 */
b = II( b, c, d, a, x[ 9], S44, 0xeb86d391); /* 64 */
state[0] += a;
state[1] += b;
state[2] += c;
state[3] += d;
}
function md5_init() {
count[0] = count[1] = 0;
state[0] = 0x67452301;
state[1] = 0xefcdab89;
state[2] = 0x98badcfe;
state[3] = 0x10325476;
for (i = 0; i < digestBits.length; i++) {
digestBits[i] = 0;
}
}
function md5_update(b) {
var index, i;
index = and(shr(count[0],3) , 0x3F);
if (count[0] < 0xFFFFFFFF - 7) {
count[0] += 8;
} else {
count[1]++;
count[0] -= 0xFFFFFFFF + 1;
count[0] += 8;
}
buffer[index] = and(b, 0xff);
if (index >= 63) {
transform(buffer, 0);
}
}
function md5_finish() {
var bits = new array(8);
var padding;
var i = 0, index = 0, padLen = 0;
for (i = 0; i < 4; i++) {
bits[i] = and(shr(count[0], (i * 8)), 0xFF);
}
for (i = 0; i < 4; i++) {
bits[i + 4] = and(shr(count[1], (i * 8)), 0xFF);
}
index = and(shr(count[0], 3), 0x3F);
padLen = (index < 56) ? (56 - index) : (120 - index);
padding = new array(64);
padding[0] = 0x80;
for (i = 0; i < padLen; i++) {
md5_update(padding[i]);
}
for (i = 0; i < 8; i++) {
md5_update(bits[i]);
}
for (i = 0; i < 4; i++) {
for (j = 0; j < 4; j++) {
digestBits[i * 4 + j] = and(shr(state[i], (j * 8)) , 0xFF);
}
}
}
/* End of the MD5 algorithm */
//#############################################################################
// Downloaded on March 30, 2006 from http://www.fourmilab.ch/javascrypt/javascrypt.zip (aes.js)
//#############################################################################
/* rijndael.js Rijndael Reference Implementation
This is a modified version of the software described below,
produced in September 2003 by John Walker for use in the
JavsScrypt browser-based encryption package. The principal
changes are replacing the original getRandomBytes function with
one which calls our pseudorandom generator (which must
be instantiated and seeded before the first call on getRandomBytes),
and changing keySizeInBits to 256. Some code not required by the
JavsScrypt application has been commented out. Please see
http://www.fourmilab.ch/javascrypt/ for further information on
JavaScrypt.
The following is the original copyright and application
information.
Copyright (c) 2001 Fritz Schneider
This software is provided as-is, without express or implied warranty.
Permission to use, copy, modify, distribute or sell this software, with or
without fee, for any purpose and by any individual or organization, is hereby
granted, provided that the above copyright notice and this paragraph appear
in all copies. Distribution as a part of an application or binary must
include the above copyright notice in the documentation and/or other materials
provided with the application or distribution.
As the above disclaimer notes, you are free to use this code however you
want. However, I would request that you send me an email
(fritz /at/ cs /dot/ ucsd /dot/ edu) to say hi if you find this code useful
or instructional. Seeing that people are using the code acts as
encouragement for me to continue development. If you *really* want to thank
me you can buy the book I wrote with Thomas Powell, _JavaScript:
_The_Complete_Reference_ :)
This code is an UNOPTIMIZED REFERENCE implementation of Rijndael.
If there is sufficient interest I can write an optimized (word-based,
table-driven) version, although you might want to consider using a
compiled language if speed is critical to your application. As it stands,
one run of the monte carlo test (10,000 encryptions) can take up to
several minutes, depending upon your processor. You shouldn't expect more
than a few kilobytes per second in throughput.
Also note that there is very little error checking in these functions.
Doing proper error checking is always a good idea, but the ideal
implementation (using the instanceof operator and exceptions) requires
IE5+/NS6+, and I've chosen to implement this code so that it is compatible
with IE4/NS4.
And finally, because JavaScript doesn't have an explicit byte/char data
type (although JavaScript 2.0 most likely will), when I refer to "byte"
in this code I generally mean "32 bit integer with value in the interval
[0,255]" which I treat as a byte.
See http://www-cse.ucsd.edu/~fritz/rijndael.html for more documentation
of the (very simple) API provided by this code.
Fritz Schneider
fritz at cs.ucsd.edu
*/