]> git.openstreetmap.org Git - rails.git/blob - vendor/assets/ohauth/ohauth.js
Patch Leaflet bug
[rails.git] / vendor / assets / ohauth / ohauth.js
1 (function(e){if("function"==typeof bootstrap)bootstrap("ohauth",e);else if("object"==typeof exports)module.exports=e();else if("function"==typeof define&&define.amd)define(e);else if("undefined"!=typeof ses){if(!ses.ok())return;ses.makeOhauth=e}else"undefined"!=typeof window?window.ohauth=e():global.ohauth=e()})(function(){var define,ses,bootstrap,module,exports;
2 return (function(e,t,n){function i(n,s){if(!t[n]){if(!e[n]){var o=typeof require=="function"&&require;if(!s&&o)return o(n,!0);if(r)return r(n,!0);throw new Error("Cannot find module '"+n+"'")}var u=t[n]={exports:{}};e[n][0].call(u.exports,function(t){var r=e[n][1][t];return i(r?r:t)},u,u.exports)}return t[n].exports}var r=typeof require=="function"&&require;for(var s=0;s<n.length;s++)i(n[s]);return i})({1:[function(require,module,exports){
3 'use strict';
4
5 var hashes = require('jshashes'),
6     xtend = require('xtend'),
7     sha1 = new hashes.SHA1();
8
9 var ohauth = {};
10
11 ohauth.qsString = function(obj) {
12     return Object.keys(obj).sort().map(function(key) {
13         return ohauth.percentEncode(key) + '=' +
14             ohauth.percentEncode(obj[key]);
15     }).join('&');
16 };
17
18 ohauth.stringQs = function(str) {
19     return str.split('&').filter(function (pair) {
20         return pair !== '';
21     }).reduce(function(obj, pair){
22         var parts = pair.split('=');
23         obj[decodeURIComponent(parts[0])] = (null === parts[1]) ?
24             '' : decodeURIComponent(parts[1]);
25         return obj;
26     }, {});
27 };
28
29 ohauth.rawxhr = function(method, url, data, headers, callback) {
30     var xhr = new XMLHttpRequest(),
31         twoHundred = /^20\d$/;
32     xhr.onreadystatechange = function() {
33         if (4 == xhr.readyState && 0 !== xhr.status) {
34             if (twoHundred.test(xhr.status)) callback(null, xhr);
35             else return callback(xhr, null);
36         }
37     };
38     xhr.onerror = function(e) { return callback(e, null); };
39     xhr.open(method, url, true);
40     for (var h in headers) xhr.setRequestHeader(h, headers[h]);
41     xhr.send(data);
42 };
43
44 ohauth.xhr = function(method, url, auth, data, options, callback) {
45     var headers = (options && options.header) || {
46         'Content-Type': 'application/x-www-form-urlencoded'
47     };
48     headers.Authorization = 'OAuth ' + ohauth.authHeader(auth);
49     ohauth.rawxhr(method, url, data, headers, callback);
50 };
51
52 ohauth.nonce = function() {
53     for (var o = ''; o.length < 6;) {
54         o += '0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz'[Math.floor(Math.random() * 61)];
55     }
56     return o;
57 };
58
59 ohauth.authHeader = function(obj) {
60     return Object.keys(obj).sort().map(function(key) {
61         return encodeURIComponent(key) + '="' + encodeURIComponent(obj[key]) + '"';
62     }).join(', ');
63 };
64
65 ohauth.timestamp = function() { return ~~((+new Date()) / 1000); };
66
67 ohauth.percentEncode = function(s) {
68     return encodeURIComponent(s)
69         .replace(/\!/g, '%21').replace(/\'/g, '%27')
70         .replace(/\*/g, '%2A').replace(/\(/g, '%28').replace(/\)/g, '%29');
71 };
72
73 ohauth.baseString = function(method, url, params) {
74     if (params.oauth_signature) delete params.oauth_signature;
75     return [
76         method,
77         ohauth.percentEncode(url),
78         ohauth.percentEncode(ohauth.qsString(params))].join('&');
79 };
80
81 ohauth.signature = function(oauth_secret, token_secret, baseString) {
82     return sha1.b64_hmac(
83         ohauth.percentEncode(oauth_secret) + '&' +
84         ohauth.percentEncode(token_secret),
85         baseString);
86 };
87
88 /**
89  * Takes an options object for configuration (consumer_key,
90  * consumer_secret, version, signature_method, token) and returns a
91  * function that generates the Authorization header for given data.
92  *
93  * The returned function takes these parameters:
94  * - method: GET/POST/...
95  * - uri: full URI with protocol, port, path and query string
96  * - extra_params: any extra parameters (that are passed in the POST data),
97  *   can be an object or a from-urlencoded string.
98  *
99  * Returned function returns full OAuth header with "OAuth" string in it.
100  */
101
102 ohauth.headerGenerator = function(options) {
103     options = options || {};
104     var consumer_key = options.consumer_key || '',
105         consumer_secret = options.consumer_secret || '',
106         signature_method = options.signature_method || 'HMAC-SHA1',
107         version = options.version || '1.0',
108         token = options.token || '',
109         token_secret = options.token_secret || '';
110
111     return function(method, uri, extra_params) {
112         method = method.toUpperCase();
113         if (typeof extra_params === 'string' && extra_params.length > 0) {
114             extra_params = ohauth.stringQs(extra_params);
115         }
116
117         var uri_parts = uri.split('?', 2),
118         base_uri = uri_parts[0];
119
120         var query_params = uri_parts.length === 2 ?
121             ohauth.stringQs(uri_parts[1]) : {};
122
123         var oauth_params = {
124             oauth_consumer_key: consumer_key,
125             oauth_signature_method: signature_method,
126             oauth_version: version,
127             oauth_timestamp: ohauth.timestamp(),
128             oauth_nonce: ohauth.nonce()
129         };
130
131         if (token) oauth_params.oauth_token = token;
132
133         var all_params = xtend({}, oauth_params, query_params, extra_params),
134             base_str = ohauth.baseString(method, base_uri, all_params);
135
136         oauth_params.oauth_signature = ohauth.signature(consumer_secret, token_secret, base_str);
137
138         return 'OAuth ' + ohauth.authHeader(oauth_params);
139     };
140 };
141
142 module.exports = ohauth;
143
144 },{"xtend":2,"jshashes":3}],2:[function(require,module,exports){
145 var Keys = Object.keys || objectKeys
146
147 module.exports = extend
148
149 function extend() {
150     var target = {}
151
152     for (var i = 0; i < arguments.length; i++) {
153         var source = arguments[i]
154
155         if (!isObject(source)) {
156             continue
157         }
158
159         var keys = Keys(source)
160
161         for (var j = 0; j < keys.length; j++) {
162             var name = keys[j]
163             target[name] = source[name]
164         }
165     }
166
167     return target
168 }
169
170 function objectKeys(obj) {
171     var keys = []
172     for (var k in obj) {
173         keys.push(k)
174     }
175     return keys
176 }
177
178 function isObject(obj) {
179     return obj !== null && typeof obj === "object"
180 }
181
182 },{}],3:[function(require,module,exports){
183 (function(global){/**
184  * jsHashes - A fast and independent hashing library pure JavaScript implemented (ES5 compliant) for both server and client side
185  * 
186  * @class Hashes
187  * @author Tomas Aparicio <tomas@rijndael-project.com>
188  * @license New BSD (see LICENSE file)
189  * @version 1.0.3
190  *
191  * Algorithms specification:
192  *
193  * MD5 <http://www.ietf.org/rfc/rfc1321.txt>
194  * RIPEMD-160 <http://homes.esat.kuleuven.be/~bosselae/ripemd160.html>
195  * SHA1   <http://csrc.nist.gov/publications/fips/fips180-4/fips-180-4.pdf>
196  * SHA256 <http://csrc.nist.gov/publications/fips/fips180-4/fips-180-4.pdf>
197  * SHA512 <http://csrc.nist.gov/publications/fips/fips180-4/fips-180-4.pdf>
198  * HMAC <http://www.ietf.org/rfc/rfc2104.txt>
199  *
200  */
201 (function(){
202   var Hashes;
203   
204   // private helper methods
205   function utf8Encode(input) {
206     var  x, y, output = '', i = -1, l = input.length;
207     while ((i+=1) < l) {
208       /* Decode utf-16 surrogate pairs */
209       x = input.charCodeAt(i);
210       y = i + 1 < l ? input.charCodeAt(i + 1) : 0;
211       if (0xD800 <= x && x <= 0xDBFF && 0xDC00 <= y && y <= 0xDFFF) {
212           x = 0x10000 + ((x & 0x03FF) << 10) + (y & 0x03FF);
213           i += 1;
214       }
215       /* Encode output as utf-8 */
216       if (x <= 0x7F) {
217           output += String.fromCharCode(x);
218       } else if (x <= 0x7FF) {
219           output += String.fromCharCode(0xC0 | ((x >>> 6 ) & 0x1F),
220                       0x80 | ( x & 0x3F));
221       } else if (x <= 0xFFFF) {
222           output += String.fromCharCode(0xE0 | ((x >>> 12) & 0x0F),
223                       0x80 | ((x >>> 6 ) & 0x3F),
224                       0x80 | ( x & 0x3F));
225       } else if (x <= 0x1FFFFF) {
226           output += String.fromCharCode(0xF0 | ((x >>> 18) & 0x07),
227                       0x80 | ((x >>> 12) & 0x3F),
228                       0x80 | ((x >>> 6 ) & 0x3F),
229                       0x80 | ( x & 0x3F));
230       }
231     }
232     return output;
233   }
234   
235   function utf8Decode(str_data) {
236     var i, ac, c1, c2, c3, arr = [], l = str_data.length;
237     i = ac = c1 = c2 = c3 = 0;
238     str_data += '';
239
240     while (i < l) {
241         c1 = str_data.charCodeAt(i);
242         ac += 1;
243         if (c1 < 128) {
244             arr[ac] = String.fromCharCode(c1);
245             i+=1;
246         } else if (c1 > 191 && c1 < 224) {
247             c2 = str_data.charCodeAt(i + 1);
248             arr[ac] = String.fromCharCode(((c1 & 31) << 6) | (c2 & 63));
249             i += 2;
250         } else {
251             c2 = str_data.charCodeAt(i + 1);
252             c3 = str_data.charCodeAt(i + 2);
253             arr[ac] = String.fromCharCode(((c1 & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
254             i += 3;
255         }
256     }
257     return arr.join('');
258   }
259
260   /**
261    * Add integers, wrapping at 2^32. This uses 16-bit operations internally
262    * to work around bugs in some JS interpreters.
263    */
264   function safe_add(x, y) {
265     var lsw = (x & 0xFFFF) + (y & 0xFFFF),
266         msw = (x >> 16) + (y >> 16) + (lsw >> 16);
267     return (msw << 16) | (lsw & 0xFFFF);
268   }
269
270   /**
271    * Bitwise rotate a 32-bit number to the left.
272    */
273   function bit_rol(num, cnt) {
274     return (num << cnt) | (num >>> (32 - cnt));
275   }
276
277   /**
278    * Convert a raw string to a hex string
279    */
280   function rstr2hex(input, hexcase) {
281     var hex_tab = hexcase ? '0123456789ABCDEF' : '0123456789abcdef',
282         output = '', x, i = 0, l = input.length;
283     for (; i < l; i+=1) {
284       x = input.charCodeAt(i);
285       output += hex_tab.charAt((x >>> 4) & 0x0F) + hex_tab.charAt(x & 0x0F);
286     }
287     return output;
288   }
289
290   /**
291    * Encode a string as utf-16
292    */
293   function str2rstr_utf16le(input) {
294     var i, l = input.length, output = '';
295     for (i = 0; i < l; i+=1) {
296       output += String.fromCharCode( input.charCodeAt(i) & 0xFF, (input.charCodeAt(i) >>> 8) & 0xFF);
297     }
298     return output;
299   }
300
301   function str2rstr_utf16be(input) {
302     var i, l = input.length, output = '';
303     for (i = 0; i < l; i+=1) {
304       output += String.fromCharCode((input.charCodeAt(i) >>> 8) & 0xFF, input.charCodeAt(i) & 0xFF);
305     }
306     return output;
307   }
308
309   /**
310    * Convert an array of big-endian words to a string
311    */
312   function binb2rstr(input) {
313     var i, l = input.length * 32, output = '';
314     for (i = 0; i < l; i += 8) {
315         output += String.fromCharCode((input[i>>5] >>> (24 - i % 32)) & 0xFF);
316     }
317     return output;
318   }
319
320   /**
321    * Convert an array of little-endian words to a string
322    */
323   function binl2rstr(input) {
324     var i, l = input.length * 32, output = '';
325     for (i = 0;i < l; i += 8) {
326       output += String.fromCharCode((input[i>>5] >>> (i % 32)) & 0xFF);
327     }
328     return output;
329   }
330
331   /**
332    * Convert a raw string to an array of little-endian words
333    * Characters >255 have their high-byte silently ignored.
334    */
335   function rstr2binl(input) {
336     var i, l = input.length * 8, output = Array(input.length >> 2), lo = output.length;
337     for (i = 0; i < lo; i+=1) {
338       output[i] = 0;
339     }
340     for (i = 0; i < l; i += 8) {
341       output[i>>5] |= (input.charCodeAt(i / 8) & 0xFF) << (i%32);
342     }
343     return output;
344   }
345   
346   /**
347    * Convert a raw string to an array of big-endian words 
348    * Characters >255 have their high-byte silently ignored.
349    */
350    function rstr2binb(input) {
351       var i, l = input.length * 8, output = Array(input.length >> 2), lo = output.length;
352       for (i = 0; i < lo; i+=1) {
353             output[i] = 0;
354         }
355       for (i = 0; i < l; i += 8) {
356             output[i>>5] |= (input.charCodeAt(i / 8) & 0xFF) << (24 - i % 32);
357         }
358       return output;
359    }
360
361   /**
362    * Convert a raw string to an arbitrary string encoding
363    */
364   function rstr2any(input, encoding) {
365     var divisor = encoding.length,
366         remainders = Array(),
367         i, q, x, ld, quotient, dividend, output, full_length;
368   
369     /* Convert to an array of 16-bit big-endian values, forming the dividend */
370     dividend = Array(Math.ceil(input.length / 2));
371     ld = dividend.length;
372     for (i = 0; i < ld; i+=1) {
373       dividend[i] = (input.charCodeAt(i * 2) << 8) | input.charCodeAt(i * 2 + 1);
374     }
375   
376     /**
377      * Repeatedly perform a long division. The binary array forms the dividend,
378      * the length of the encoding is the divisor. Once computed, the quotient
379      * forms the dividend for the next step. We stop when the dividend is zerHashes.
380      * All remainders are stored for later use.
381      */
382     while(dividend.length > 0) {
383       quotient = Array();
384       x = 0;
385       for (i = 0; i < dividend.length; i+=1) {
386         x = (x << 16) + dividend[i];
387         q = Math.floor(x / divisor);
388         x -= q * divisor;
389         if (quotient.length > 0 || q > 0) {
390           quotient[quotient.length] = q;
391         }
392       }
393       remainders[remainders.length] = x;
394       dividend = quotient;
395     }
396   
397     /* Convert the remainders to the output string */
398     output = '';
399     for (i = remainders.length - 1; i >= 0; i--) {
400       output += encoding.charAt(remainders[i]);
401     }
402   
403     /* Append leading zero equivalents */
404     full_length = Math.ceil(input.length * 8 / (Math.log(encoding.length) / Math.log(2)));
405     for (i = output.length; i < full_length; i+=1) {
406       output = encoding[0] + output;
407     }
408     return output;
409   }
410
411   /**
412    * Convert a raw string to a base-64 string
413    */
414   function rstr2b64(input, b64pad) {
415     var tab = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/',
416         output = '',
417         len = input.length, i, j, triplet;
418     b64pad= b64pad || '=';
419     for (i = 0; i < len; i += 3) {
420       triplet = (input.charCodeAt(i) << 16)
421             | (i + 1 < len ? input.charCodeAt(i+1) << 8 : 0)
422             | (i + 2 < len ? input.charCodeAt(i+2)      : 0);
423       for (j = 0; j < 4; j+=1) {
424         if (i * 8 + j * 6 > input.length * 8) { 
425           output += b64pad; 
426         } else { 
427           output += tab.charAt((triplet >>> 6*(3-j)) & 0x3F); 
428         }
429        }
430     }
431     return output;
432   }
433
434   Hashes = {
435   /**  
436    * @property {String} version
437    * @readonly
438    */
439   VERSION : '1.0.3',
440   /**
441    * @member Hashes
442    * @class Base64
443    * @constructor
444    */
445   Base64 : function () {
446     // private properties
447     var tab = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/',
448         pad = '=', // default pad according with the RFC standard
449         url = false, // URL encoding support @todo
450         utf8 = true; // by default enable UTF-8 support encoding
451
452     // public method for encoding
453     this.encode = function (input) {
454       var i, j, triplet,
455           output = '', 
456           len = input.length;
457
458       pad = pad || '=';
459       input = (utf8) ? utf8Encode(input) : input;
460
461       for (i = 0; i < len; i += 3) {
462         triplet = (input.charCodeAt(i) << 16)
463               | (i + 1 < len ? input.charCodeAt(i+1) << 8 : 0)
464               | (i + 2 < len ? input.charCodeAt(i+2) : 0);
465         for (j = 0; j < 4; j+=1) {
466           if (i * 8 + j * 6 > len * 8) {
467               output += pad;
468           } else {
469               output += tab.charAt((triplet >>> 6*(3-j)) & 0x3F);
470           }
471         }
472       }
473       return output;    
474     };
475
476     // public method for decoding
477     this.decode = function (input) {
478       // var b64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
479       var i, o1, o2, o3, h1, h2, h3, h4, bits, ac,
480         dec = '',
481         arr = [];
482       if (!input) { return input; }
483
484       i = ac = 0;
485       input = input.replace(new RegExp('\\'+pad,'gi'),''); // use '='
486       //input += '';
487
488       do { // unpack four hexets into three octets using index points in b64
489         h1 = tab.indexOf(input.charAt(i+=1));
490         h2 = tab.indexOf(input.charAt(i+=1));
491         h3 = tab.indexOf(input.charAt(i+=1));
492         h4 = tab.indexOf(input.charAt(i+=1));
493
494         bits = h1 << 18 | h2 << 12 | h3 << 6 | h4;
495
496         o1 = bits >> 16 & 0xff;
497         o2 = bits >> 8 & 0xff;
498         o3 = bits & 0xff;
499         ac += 1;
500
501         if (h3 === 64) {
502           arr[ac] = String.fromCharCode(o1);
503         } else if (h4 === 64) {
504           arr[ac] = String.fromCharCode(o1, o2);
505         } else {
506           arr[ac] = String.fromCharCode(o1, o2, o3);
507         }
508       } while (i < input.length);
509
510       dec = arr.join('');
511       dec = (utf8) ? utf8Decode(dec) : dec;
512
513       return dec;
514     };
515
516     // set custom pad string
517     this.setPad = function (str) {
518         pad = str || pad;
519         return this;
520     };
521     // set custom tab string characters
522     this.setTab = function (str) {
523         tab = str || tab;
524         return this;
525     };
526     this.setUTF8 = function (bool) {
527         if (typeof bool === 'boolean') {
528           utf8 = bool;
529         }
530         return this;
531     };
532   },
533
534   /**
535    * CRC-32 calculation
536    * @member Hashes
537    * @method CRC32
538    * @static
539    * @param {String} str Input String
540    * @return {String}
541    */
542   CRC32 : function (str) {
543     var crc = 0, x = 0, y = 0, table, i, iTop;
544     str = utf8Encode(str);
545         
546     table = [ 
547         '00000000 77073096 EE0E612C 990951BA 076DC419 706AF48F E963A535 9E6495A3 0EDB8832 ',
548         '79DCB8A4 E0D5E91E 97D2D988 09B64C2B 7EB17CBD E7B82D07 90BF1D91 1DB71064 6AB020F2 F3B97148 ',
549         '84BE41DE 1ADAD47D 6DDDE4EB F4D4B551 83D385C7 136C9856 646BA8C0 FD62F97A 8A65C9EC 14015C4F ',
550         '63066CD9 FA0F3D63 8D080DF5 3B6E20C8 4C69105E D56041E4 A2677172 3C03E4D1 4B04D447 D20D85FD ',
551         'A50AB56B 35B5A8FA 42B2986C DBBBC9D6 ACBCF940 32D86CE3 45DF5C75 DCD60DCF ABD13D59 26D930AC ',
552         '51DE003A C8D75180 BFD06116 21B4F4B5 56B3C423 CFBA9599 B8BDA50F 2802B89E 5F058808 C60CD9B2 ',
553         'B10BE924 2F6F7C87 58684C11 C1611DAB B6662D3D 76DC4190 01DB7106 98D220BC EFD5102A 71B18589 ',
554         '06B6B51F 9FBFE4A5 E8B8D433 7807C9A2 0F00F934 9609A88E E10E9818 7F6A0DBB 086D3D2D 91646C97 ',
555         'E6635C01 6B6B51F4 1C6C6162 856530D8 F262004E 6C0695ED 1B01A57B 8208F4C1 F50FC457 65B0D9C6 ',
556         '12B7E950 8BBEB8EA FCB9887C 62DD1DDF 15DA2D49 8CD37CF3 FBD44C65 4DB26158 3AB551CE A3BC0074 ',
557         'D4BB30E2 4ADFA541 3DD895D7 A4D1C46D D3D6F4FB 4369E96A 346ED9FC AD678846 DA60B8D0 44042D73 ',
558         '33031DE5 AA0A4C5F DD0D7CC9 5005713C 270241AA BE0B1010 C90C2086 5768B525 206F85B3 B966D409 ',
559         'CE61E49F 5EDEF90E 29D9C998 B0D09822 C7D7A8B4 59B33D17 2EB40D81 B7BD5C3B C0BA6CAD EDB88320 ',
560         '9ABFB3B6 03B6E20C 74B1D29A EAD54739 9DD277AF 04DB2615 73DC1683 E3630B12 94643B84 0D6D6A3E ',
561         '7A6A5AA8 E40ECF0B 9309FF9D 0A00AE27 7D079EB1 F00F9344 8708A3D2 1E01F268 6906C2FE F762575D ',
562         '806567CB 196C3671 6E6B06E7 FED41B76 89D32BE0 10DA7A5A 67DD4ACC F9B9DF6F 8EBEEFF9 17B7BE43 ',
563         '60B08ED5 D6D6A3E8 A1D1937E 38D8C2C4 4FDFF252 D1BB67F1 A6BC5767 3FB506DD 48B2364B D80D2BDA ',
564         'AF0A1B4C 36034AF6 41047A60 DF60EFC3 A867DF55 316E8EEF 4669BE79 CB61B38C BC66831A 256FD2A0 ', 
565         '5268E236 CC0C7795 BB0B4703 220216B9 5505262F C5BA3BBE B2BD0B28 2BB45A92 5CB36A04 C2D7FFA7 ',
566         'B5D0CF31 2CD99E8B 5BDEAE1D 9B64C2B0 EC63F226 756AA39C 026D930A 9C0906A9 EB0E363F 72076785 ',
567         '05005713 95BF4A82 E2B87A14 7BB12BAE 0CB61B38 92D28E9B E5D5BE0D 7CDCEFB7 0BDBDF21 86D3D2D4 ',
568         'F1D4E242 68DDB3F8 1FDA836E 81BE16CD F6B9265B 6FB077E1 18B74777 88085AE6 FF0F6A70 66063BCA ',
569         '11010B5C 8F659EFF F862AE69 616BFFD3 166CCF45 A00AE278 D70DD2EE 4E048354 3903B3C2 A7672661 ',
570         'D06016F7 4969474D 3E6E77DB AED16A4A D9D65ADC 40DF0B66 37D83BF0 A9BCAE53 DEBB9EC5 47B2CF7F ',
571         '30B5FFE9 BDBDF21C CABAC28A 53B39330 24B4A3A6 BAD03605 CDD70693 54DE5729 23D967BF B3667A2E ',
572         'C4614AB8 5D681B02 2A6F2B94 B40BBE37 C30C8EA1 5A05DF1B 2D02EF8D'
573     ].join('');
574
575     crc = crc ^ (-1);
576     for (i = 0, iTop = str.length; i < iTop; i+=1 ) {
577         y = ( crc ^ str.charCodeAt( i ) ) & 0xFF;
578         x = '0x' + table.substr( y * 9, 8 );
579         crc = ( crc >>> 8 ) ^ x;
580     }
581     // always return a positive number (that's what >>> 0 does)
582     return (crc ^ (-1)) >>> 0;
583   },
584   /**
585    * @member Hashes
586    * @class MD5
587    * @constructor
588    * @param {Object} [config]
589    * 
590    * A JavaScript implementation of the RSA Data Security, Inc. MD5 Message
591    * Digest Algorithm, as defined in RFC 1321.
592    * Version 2.2 Copyright (C) Paul Johnston 1999 - 2009
593    * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
594    * See <http://pajhome.org.uk/crypt/md5> for more infHashes.
595    */
596   MD5 : function (options) {  
597     /**
598      * Private config properties. You may need to tweak these to be compatible with
599      * the server-side, but the defaults work in most cases.
600      * See {@link Hashes.MD5#method-setUpperCase} and {@link Hashes.SHA1#method-setUpperCase}
601      */
602     var hexcase = (options && typeof options.uppercase === 'boolean') ? options.uppercase : false, // hexadecimal output case format. false - lowercase; true - uppercase
603         b64pad = (options && typeof options.pad === 'string') ? options.pda : '=', // base-64 pad character. Defaults to '=' for strict RFC compliance
604         utf8 = (options && typeof options.utf8 === 'boolean') ? options.utf8 : true; // enable/disable utf8 encoding
605
606     // privileged (public) methods 
607     this.hex = function (s) { 
608       return rstr2hex(rstr(s, utf8), hexcase);
609     };
610     this.b64 = function (s) { 
611       return rstr2b64(rstr(s), b64pad);
612     };
613     this.any = function(s, e) { 
614       return rstr2any(rstr(s, utf8), e); 
615     };
616     this.hex_hmac = function (k, d) { 
617       return rstr2hex(rstr_hmac(k, d), hexcase); 
618     };
619     this.b64_hmac = function (k, d) { 
620       return rstr2b64(rstr_hmac(k,d), b64pad); 
621     };
622     this.any_hmac = function (k, d, e) { 
623       return rstr2any(rstr_hmac(k, d), e); 
624     };
625     /**
626      * Perform a simple self-test to see if the VM is working
627      * @return {String} Hexadecimal hash sample
628      */
629     this.vm_test = function () {
630       return hex('abc').toLowerCase() === '900150983cd24fb0d6963f7d28e17f72';
631     };
632     /** 
633      * Enable/disable uppercase hexadecimal returned string 
634      * @param {Boolean} 
635      * @return {Object} this
636      */ 
637     this.setUpperCase = function (a) {
638       if (typeof a === 'boolean' ) {
639         hexcase = a;
640       }
641       return this;
642     };
643     /** 
644      * Defines a base64 pad string 
645      * @param {String} Pad
646      * @return {Object} this
647      */ 
648     this.setPad = function (a) {
649       b64pad = a || b64pad;
650       return this;
651     };
652     /** 
653      * Defines a base64 pad string 
654      * @param {Boolean} 
655      * @return {Object} [this]
656      */ 
657     this.setUTF8 = function (a) {
658       if (typeof a === 'boolean') { 
659         utf8 = a;
660       }
661       return this;
662     };
663
664     // private methods
665
666     /**
667      * Calculate the MD5 of a raw string
668      */
669     function rstr(s) {
670       s = (utf8) ? utf8Encode(s): s;
671       return binl2rstr(binl(rstr2binl(s), s.length * 8));
672     }
673     
674     /**
675      * Calculate the HMAC-MD5, of a key and some data (raw strings)
676      */
677     function rstr_hmac(key, data) {
678       var bkey, ipad, opad, hash, i;
679
680       key = (utf8) ? utf8Encode(key) : key;
681       data = (utf8) ? utf8Encode(data) : data;
682       bkey = rstr2binl(key);
683       if (bkey.length > 16) { 
684         bkey = binl(bkey, key.length * 8); 
685       }
686
687       ipad = Array(16), opad = Array(16); 
688       for (i = 0; i < 16; i+=1) {
689           ipad[i] = bkey[i] ^ 0x36363636;
690           opad[i] = bkey[i] ^ 0x5C5C5C5C;
691       }
692       hash = binl(ipad.concat(rstr2binl(data)), 512 + data.length * 8);
693       return binl2rstr(binl(opad.concat(hash), 512 + 128));
694     }
695
696     /**
697      * Calculate the MD5 of an array of little-endian words, and a bit length.
698      */
699     function binl(x, len) {
700       var i, olda, oldb, oldc, oldd,
701           a =  1732584193,
702           b = -271733879,
703           c = -1732584194,
704           d =  271733878;
705         
706       /* append padding */
707       x[len >> 5] |= 0x80 << ((len) % 32);
708       x[(((len + 64) >>> 9) << 4) + 14] = len;
709
710       for (i = 0; i < x.length; i += 16) {
711         olda = a;
712         oldb = b;
713         oldc = c;
714         oldd = d;
715
716         a = md5_ff(a, b, c, d, x[i+ 0], 7 , -680876936);
717         d = md5_ff(d, a, b, c, x[i+ 1], 12, -389564586);
718         c = md5_ff(c, d, a, b, x[i+ 2], 17,  606105819);
719         b = md5_ff(b, c, d, a, x[i+ 3], 22, -1044525330);
720         a = md5_ff(a, b, c, d, x[i+ 4], 7 , -176418897);
721         d = md5_ff(d, a, b, c, x[i+ 5], 12,  1200080426);
722         c = md5_ff(c, d, a, b, x[i+ 6], 17, -1473231341);
723         b = md5_ff(b, c, d, a, x[i+ 7], 22, -45705983);
724         a = md5_ff(a, b, c, d, x[i+ 8], 7 ,  1770035416);
725         d = md5_ff(d, a, b, c, x[i+ 9], 12, -1958414417);
726         c = md5_ff(c, d, a, b, x[i+10], 17, -42063);
727         b = md5_ff(b, c, d, a, x[i+11], 22, -1990404162);
728         a = md5_ff(a, b, c, d, x[i+12], 7 ,  1804603682);
729         d = md5_ff(d, a, b, c, x[i+13], 12, -40341101);
730         c = md5_ff(c, d, a, b, x[i+14], 17, -1502002290);
731         b = md5_ff(b, c, d, a, x[i+15], 22,  1236535329);
732
733         a = md5_gg(a, b, c, d, x[i+ 1], 5 , -165796510);
734         d = md5_gg(d, a, b, c, x[i+ 6], 9 , -1069501632);
735         c = md5_gg(c, d, a, b, x[i+11], 14,  643717713);
736         b = md5_gg(b, c, d, a, x[i+ 0], 20, -373897302);
737         a = md5_gg(a, b, c, d, x[i+ 5], 5 , -701558691);
738         d = md5_gg(d, a, b, c, x[i+10], 9 ,  38016083);
739         c = md5_gg(c, d, a, b, x[i+15], 14, -660478335);
740         b = md5_gg(b, c, d, a, x[i+ 4], 20, -405537848);
741         a = md5_gg(a, b, c, d, x[i+ 9], 5 ,  568446438);
742         d = md5_gg(d, a, b, c, x[i+14], 9 , -1019803690);
743         c = md5_gg(c, d, a, b, x[i+ 3], 14, -187363961);
744         b = md5_gg(b, c, d, a, x[i+ 8], 20,  1163531501);
745         a = md5_gg(a, b, c, d, x[i+13], 5 , -1444681467);
746         d = md5_gg(d, a, b, c, x[i+ 2], 9 , -51403784);
747         c = md5_gg(c, d, a, b, x[i+ 7], 14,  1735328473);
748         b = md5_gg(b, c, d, a, x[i+12], 20, -1926607734);
749
750         a = md5_hh(a, b, c, d, x[i+ 5], 4 , -378558);
751         d = md5_hh(d, a, b, c, x[i+ 8], 11, -2022574463);
752         c = md5_hh(c, d, a, b, x[i+11], 16,  1839030562);
753         b = md5_hh(b, c, d, a, x[i+14], 23, -35309556);
754         a = md5_hh(a, b, c, d, x[i+ 1], 4 , -1530992060);
755         d = md5_hh(d, a, b, c, x[i+ 4], 11,  1272893353);
756         c = md5_hh(c, d, a, b, x[i+ 7], 16, -155497632);
757         b = md5_hh(b, c, d, a, x[i+10], 23, -1094730640);
758         a = md5_hh(a, b, c, d, x[i+13], 4 ,  681279174);
759         d = md5_hh(d, a, b, c, x[i+ 0], 11, -358537222);
760         c = md5_hh(c, d, a, b, x[i+ 3], 16, -722521979);
761         b = md5_hh(b, c, d, a, x[i+ 6], 23,  76029189);
762         a = md5_hh(a, b, c, d, x[i+ 9], 4 , -640364487);
763         d = md5_hh(d, a, b, c, x[i+12], 11, -421815835);
764         c = md5_hh(c, d, a, b, x[i+15], 16,  530742520);
765         b = md5_hh(b, c, d, a, x[i+ 2], 23, -995338651);
766
767         a = md5_ii(a, b, c, d, x[i+ 0], 6 , -198630844);
768         d = md5_ii(d, a, b, c, x[i+ 7], 10,  1126891415);
769         c = md5_ii(c, d, a, b, x[i+14], 15, -1416354905);
770         b = md5_ii(b, c, d, a, x[i+ 5], 21, -57434055);
771         a = md5_ii(a, b, c, d, x[i+12], 6 ,  1700485571);
772         d = md5_ii(d, a, b, c, x[i+ 3], 10, -1894986606);
773         c = md5_ii(c, d, a, b, x[i+10], 15, -1051523);
774         b = md5_ii(b, c, d, a, x[i+ 1], 21, -2054922799);
775         a = md5_ii(a, b, c, d, x[i+ 8], 6 ,  1873313359);
776         d = md5_ii(d, a, b, c, x[i+15], 10, -30611744);
777         c = md5_ii(c, d, a, b, x[i+ 6], 15, -1560198380);
778         b = md5_ii(b, c, d, a, x[i+13], 21,  1309151649);
779         a = md5_ii(a, b, c, d, x[i+ 4], 6 , -145523070);
780         d = md5_ii(d, a, b, c, x[i+11], 10, -1120210379);
781         c = md5_ii(c, d, a, b, x[i+ 2], 15,  718787259);
782         b = md5_ii(b, c, d, a, x[i+ 9], 21, -343485551);
783
784         a = safe_add(a, olda);
785         b = safe_add(b, oldb);
786         c = safe_add(c, oldc);
787         d = safe_add(d, oldd);
788       }
789       return Array(a, b, c, d);
790     }
791
792     /**
793      * These functions implement the four basic operations the algorithm uses.
794      */
795     function md5_cmn(q, a, b, x, s, t) {
796       return safe_add(bit_rol(safe_add(safe_add(a, q), safe_add(x, t)), s),b);
797     }
798     function md5_ff(a, b, c, d, x, s, t) {
799       return md5_cmn((b & c) | ((~b) & d), a, b, x, s, t);
800     }
801     function md5_gg(a, b, c, d, x, s, t) {
802       return md5_cmn((b & d) | (c & (~d)), a, b, x, s, t);
803     }
804     function md5_hh(a, b, c, d, x, s, t) {
805       return md5_cmn(b ^ c ^ d, a, b, x, s, t);
806     }
807     function md5_ii(a, b, c, d, x, s, t) {
808       return md5_cmn(c ^ (b | (~d)), a, b, x, s, t);
809     }
810   },
811   /**
812    * @member Hashes
813    * @class Hashes.SHA1
814    * @param {Object} [config]
815    * @constructor
816    * 
817    * A JavaScript implementation of the Secure Hash Algorithm, SHA-1, as defined in FIPS 180-1
818    * Version 2.2 Copyright Paul Johnston 2000 - 2009.
819    * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
820    * See http://pajhome.org.uk/crypt/md5 for details.
821    */
822   SHA1 : function (options) {
823    /**
824      * Private config properties. You may need to tweak these to be compatible with
825      * the server-side, but the defaults work in most cases.
826      * See {@link Hashes.MD5#method-setUpperCase} and {@link Hashes.SHA1#method-setUpperCase}
827      */
828     var hexcase = (options && typeof options.uppercase === 'boolean') ? options.uppercase : false, // hexadecimal output case format. false - lowercase; true - uppercase
829         b64pad = (options && typeof options.pad === 'string') ? options.pda : '=', // base-64 pad character. Defaults to '=' for strict RFC compliance
830         utf8 = (options && typeof options.utf8 === 'boolean') ? options.utf8 : true; // enable/disable utf8 encoding
831
832     // public methods
833     this.hex = function (s) { 
834         return rstr2hex(rstr(s, utf8), hexcase); 
835     };
836     this.b64 = function (s) { 
837         return rstr2b64(rstr(s, utf8), b64pad);
838     };
839     this.any = function (s, e) { 
840         return rstr2any(rstr(s, utf8), e);
841     };
842     this.hex_hmac = function (k, d) {
843         return rstr2hex(rstr_hmac(k, d));
844     };
845     this.b64_hmac = function (k, d) { 
846         return rstr2b64(rstr_hmac(k, d), b64pad); 
847     };
848     this.any_hmac = function (k, d, e) { 
849         return rstr2any(rstr_hmac(k, d), e);
850     };
851     /**
852      * Perform a simple self-test to see if the VM is working
853      * @return {String} Hexadecimal hash sample
854      * @public
855      */
856     this.vm_test = function () {
857       return hex('abc').toLowerCase() === '900150983cd24fb0d6963f7d28e17f72';
858     };
859     /** 
860      * @description Enable/disable uppercase hexadecimal returned string 
861      * @param {boolean} 
862      * @return {Object} this
863      * @public
864      */ 
865     this.setUpperCase = function (a) {
866         if (typeof a === 'boolean') {
867         hexcase = a;
868       }
869         return this;
870     };
871     /** 
872      * @description Defines a base64 pad string 
873      * @param {string} Pad
874      * @return {Object} this
875      * @public
876      */ 
877     this.setPad = function (a) {
878       b64pad = a || b64pad;
879         return this;
880     };
881     /** 
882      * @description Defines a base64 pad string 
883      * @param {boolean} 
884      * @return {Object} this
885      * @public
886      */ 
887     this.setUTF8 = function (a) {
888         if (typeof a === 'boolean') {
889         utf8 = a;
890       }
891         return this;
892     };
893
894     // private methods
895
896     /**
897          * Calculate the SHA-512 of a raw string
898          */
899         function rstr(s) {
900       s = (utf8) ? utf8Encode(s) : s;
901       return binb2rstr(binb(rstr2binb(s), s.length * 8));
902         }
903
904     /**
905      * Calculate the HMAC-SHA1 of a key and some data (raw strings)
906      */
907     function rstr_hmac(key, data) {
908         var bkey, ipad, opad, i, hash;
909         key = (utf8) ? utf8Encode(key) : key;
910         data = (utf8) ? utf8Encode(data) : data;
911         bkey = rstr2binb(key);
912
913         if (bkey.length > 16) {
914         bkey = binb(bkey, key.length * 8);
915       }
916         ipad = Array(16), opad = Array(16);
917         for (i = 0; i < 16; i+=1) {
918                 ipad[i] = bkey[i] ^ 0x36363636;
919                 opad[i] = bkey[i] ^ 0x5C5C5C5C;
920         }
921         hash = binb(ipad.concat(rstr2binb(data)), 512 + data.length * 8);
922         return binb2rstr(binb(opad.concat(hash), 512 + 160));
923     }
924
925     /**
926      * Calculate the SHA-1 of an array of big-endian words, and a bit length
927      */
928     function binb(x, len) {
929       var i, j, t, olda, oldb, oldc, oldd, olde,
930           w = Array(80),
931           a =  1732584193,
932           b = -271733879,
933           c = -1732584194,
934           d =  271733878,
935           e = -1009589776;
936
937       /* append padding */
938       x[len >> 5] |= 0x80 << (24 - len % 32);
939       x[((len + 64 >> 9) << 4) + 15] = len;
940
941       for (i = 0; i < x.length; i += 16) {
942         olda = a,
943         oldb = b;
944         oldc = c;
945         oldd = d;
946         olde = e;
947       
948         for (j = 0; j < 80; j+=1)       {
949           if (j < 16) { 
950             w[j] = x[i + j]; 
951           } else { 
952             w[j] = bit_rol(w[j-3] ^ w[j-8] ^ w[j-14] ^ w[j-16], 1); 
953           }
954           t = safe_add(safe_add(bit_rol(a, 5), sha1_ft(j, b, c, d)),
955                                            safe_add(safe_add(e, w[j]), sha1_kt(j)));
956           e = d;
957           d = c;
958           c = bit_rol(b, 30);
959           b = a;
960           a = t;
961         }
962
963         a = safe_add(a, olda);
964         b = safe_add(b, oldb);
965         c = safe_add(c, oldc);
966         d = safe_add(d, oldd);
967         e = safe_add(e, olde);
968       }
969       return Array(a, b, c, d, e);
970     }
971
972     /**
973      * Perform the appropriate triplet combination function for the current
974      * iteration
975      */
976     function sha1_ft(t, b, c, d) {
977       if (t < 20) { return (b & c) | ((~b) & d); }
978       if (t < 40) { return b ^ c ^ d; }
979       if (t < 60) { return (b & c) | (b & d) | (c & d); }
980       return b ^ c ^ d;
981     }
982
983     /**
984      * Determine the appropriate additive constant for the current iteration
985      */
986     function sha1_kt(t) {
987       return (t < 20) ?  1518500249 : (t < 40) ?  1859775393 :
988                  (t < 60) ? -1894007588 : -899497514;
989     }
990   },
991   /**
992    * @class Hashes.SHA256
993    * @param {config}
994    * 
995    * A JavaScript implementation of the Secure Hash Algorithm, SHA-256, as defined in FIPS 180-2
996    * Version 2.2 Copyright Angel Marin, Paul Johnston 2000 - 2009.
997    * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
998    * See http://pajhome.org.uk/crypt/md5 for details.
999    * Also http://anmar.eu.org/projects/jssha2/
1000    */
1001   SHA256 : function (options) {
1002     /**
1003      * Private properties configuration variables. You may need to tweak these to be compatible with
1004      * the server-side, but the defaults work in most cases.
1005      * @see this.setUpperCase() method
1006      * @see this.setPad() method
1007      */
1008     var hexcase = (options && typeof options.uppercase === 'boolean') ? options.uppercase : false, // hexadecimal output case format. false - lowercase; true - uppercase  */
1009               b64pad = (options && typeof options.pad === 'string') ? options.pda : '=', /* base-64 pad character. Default '=' for strict RFC compliance   */
1010               utf8 = (options && typeof options.utf8 === 'boolean') ? options.utf8 : true, /* enable/disable utf8 encoding */
1011               sha256_K;
1012
1013     /* privileged (public) methods */
1014     this.hex = function (s) { 
1015       return rstr2hex(rstr(s, utf8)); 
1016     };
1017     this.b64 = function (s) { 
1018       return rstr2b64(rstr(s, utf8), b64pad);
1019     };
1020     this.any = function (s, e) { 
1021       return rstr2any(rstr(s, utf8), e); 
1022     };
1023     this.hex_hmac = function (k, d) { 
1024       return rstr2hex(rstr_hmac(k, d)); 
1025     };
1026     this.b64_hmac = function (k, d) { 
1027       return rstr2b64(rstr_hmac(k, d), b64pad);
1028     };
1029     this.any_hmac = function (k, d, e) { 
1030       return rstr2any(rstr_hmac(k, d), e); 
1031     };
1032     /**
1033      * Perform a simple self-test to see if the VM is working
1034      * @return {String} Hexadecimal hash sample
1035      * @public
1036      */
1037     this.vm_test = function () {
1038       return hex('abc').toLowerCase() === '900150983cd24fb0d6963f7d28e17f72';
1039     };
1040     /** 
1041      * Enable/disable uppercase hexadecimal returned string 
1042      * @param {boolean} 
1043      * @return {Object} this
1044      * @public
1045      */ 
1046     this.setUpperCase = function (a) {
1047       if (typeof a === 'boolean') { 
1048         hexcase = a;
1049       }
1050       return this;
1051     };
1052     /** 
1053      * @description Defines a base64 pad string 
1054      * @param {string} Pad
1055      * @return {Object} this
1056      * @public
1057      */ 
1058     this.setPad = function (a) {
1059       b64pad = a || b64pad;
1060       return this;
1061     };
1062     /** 
1063      * Defines a base64 pad string 
1064      * @param {boolean} 
1065      * @return {Object} this
1066      * @public
1067      */ 
1068     this.setUTF8 = function (a) {
1069       if (typeof a === 'boolean') {
1070         utf8 = a;
1071       }
1072       return this;
1073     };
1074     
1075     // private methods
1076
1077     /**
1078      * Calculate the SHA-512 of a raw string
1079      */
1080     function rstr(s, utf8) {
1081       s = (utf8) ? utf8Encode(s) : s;
1082       return binb2rstr(binb(rstr2binb(s), s.length * 8));
1083     }
1084
1085     /**
1086      * Calculate the HMAC-sha256 of a key and some data (raw strings)
1087      */
1088     function rstr_hmac(key, data) {
1089       key = (utf8) ? utf8Encode(key) : key;
1090       data = (utf8) ? utf8Encode(data) : data;
1091       var hash, i = 0,
1092           bkey = rstr2binb(key), 
1093           ipad = Array(16), 
1094           opad = Array(16);
1095
1096       if (bkey.length > 16) { bkey = binb(bkey, key.length * 8); }
1097       
1098       for (; i < 16; i+=1) {
1099         ipad[i] = bkey[i] ^ 0x36363636;
1100         opad[i] = bkey[i] ^ 0x5C5C5C5C;
1101       }
1102       
1103       hash = binb(ipad.concat(rstr2binb(data)), 512 + data.length * 8);
1104       return binb2rstr(binb(opad.concat(hash), 512 + 256));
1105     }
1106     
1107     /*
1108      * Main sha256 function, with its support functions
1109      */
1110     function sha256_S (X, n) {return ( X >>> n ) | (X << (32 - n));}
1111     function sha256_R (X, n) {return ( X >>> n );}
1112     function sha256_Ch(x, y, z) {return ((x & y) ^ ((~x) & z));}
1113     function sha256_Maj(x, y, z) {return ((x & y) ^ (x & z) ^ (y & z));}
1114     function sha256_Sigma0256(x) {return (sha256_S(x, 2) ^ sha256_S(x, 13) ^ sha256_S(x, 22));}
1115     function sha256_Sigma1256(x) {return (sha256_S(x, 6) ^ sha256_S(x, 11) ^ sha256_S(x, 25));}
1116     function sha256_Gamma0256(x) {return (sha256_S(x, 7) ^ sha256_S(x, 18) ^ sha256_R(x, 3));}
1117     function sha256_Gamma1256(x) {return (sha256_S(x, 17) ^ sha256_S(x, 19) ^ sha256_R(x, 10));}
1118     function sha256_Sigma0512(x) {return (sha256_S(x, 28) ^ sha256_S(x, 34) ^ sha256_S(x, 39));}
1119     function sha256_Sigma1512(x) {return (sha256_S(x, 14) ^ sha256_S(x, 18) ^ sha256_S(x, 41));}
1120     function sha256_Gamma0512(x) {return (sha256_S(x, 1)  ^ sha256_S(x, 8) ^ sha256_R(x, 7));}
1121     function sha256_Gamma1512(x) {return (sha256_S(x, 19) ^ sha256_S(x, 61) ^ sha256_R(x, 6));}
1122     
1123     sha256_K = [
1124       1116352408, 1899447441, -1245643825, -373957723, 961987163, 1508970993,
1125       -1841331548, -1424204075, -670586216, 310598401, 607225278, 1426881987,
1126       1925078388, -2132889090, -1680079193, -1046744716, -459576895, -272742522,
1127       264347078, 604807628, 770255983, 1249150122, 1555081692, 1996064986,
1128       -1740746414, -1473132947, -1341970488, -1084653625, -958395405, -710438585,
1129       113926993, 338241895, 666307205, 773529912, 1294757372, 1396182291,
1130       1695183700, 1986661051, -2117940946, -1838011259, -1564481375, -1474664885,
1131       -1035236496, -949202525, -778901479, -694614492, -200395387, 275423344,
1132       430227734, 506948616, 659060556, 883997877, 958139571, 1322822218,
1133       1537002063, 1747873779, 1955562222, 2024104815, -2067236844, -1933114872,
1134       -1866530822, -1538233109, -1090935817, -965641998
1135     ];
1136     
1137     function binb(m, l) {
1138       var HASH = [1779033703, -1150833019, 1013904242, -1521486534,
1139                  1359893119, -1694144372, 528734635, 1541459225];
1140       var W = new Array(64);
1141       var a, b, c, d, e, f, g, h;
1142       var i, j, T1, T2;
1143     
1144       /* append padding */
1145       m[l >> 5] |= 0x80 << (24 - l % 32);
1146       m[((l + 64 >> 9) << 4) + 15] = l;
1147     
1148       for (i = 0; i < m.length; i += 16)
1149       {
1150       a = HASH[0];
1151       b = HASH[1];
1152       c = HASH[2];
1153       d = HASH[3];
1154       e = HASH[4];
1155       f = HASH[5];
1156       g = HASH[6];
1157       h = HASH[7];
1158     
1159       for (j = 0; j < 64; j+=1)
1160       {
1161         if (j < 16) { 
1162           W[j] = m[j + i];
1163         } else { 
1164           W[j] = safe_add(safe_add(safe_add(sha256_Gamma1256(W[j - 2]), W[j - 7]),
1165                           sha256_Gamma0256(W[j - 15])), W[j - 16]);
1166         }
1167     
1168         T1 = safe_add(safe_add(safe_add(safe_add(h, sha256_Sigma1256(e)), sha256_Ch(e, f, g)),
1169                                   sha256_K[j]), W[j]);
1170         T2 = safe_add(sha256_Sigma0256(a), sha256_Maj(a, b, c));
1171         h = g;
1172         g = f;
1173         f = e;
1174         e = safe_add(d, T1);
1175         d = c;
1176         c = b;
1177         b = a;
1178         a = safe_add(T1, T2);
1179       }
1180     
1181       HASH[0] = safe_add(a, HASH[0]);
1182       HASH[1] = safe_add(b, HASH[1]);
1183       HASH[2] = safe_add(c, HASH[2]);
1184       HASH[3] = safe_add(d, HASH[3]);
1185       HASH[4] = safe_add(e, HASH[4]);
1186       HASH[5] = safe_add(f, HASH[5]);
1187       HASH[6] = safe_add(g, HASH[6]);
1188       HASH[7] = safe_add(h, HASH[7]);
1189       }
1190       return HASH;
1191     }
1192
1193   },
1194
1195   /**
1196    * @class Hashes.SHA512
1197    * @param {config}
1198    * 
1199    * A JavaScript implementation of the Secure Hash Algorithm, SHA-512, as defined in FIPS 180-2
1200    * Version 2.2 Copyright Anonymous Contributor, Paul Johnston 2000 - 2009.
1201    * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
1202    * See http://pajhome.org.uk/crypt/md5 for details. 
1203    */
1204   SHA512 : function (options) {
1205     /**
1206      * Private properties configuration variables. You may need to tweak these to be compatible with
1207      * the server-side, but the defaults work in most cases.
1208      * @see this.setUpperCase() method
1209      * @see this.setPad() method
1210      */
1211     var hexcase = (options && typeof options.uppercase === 'boolean') ? options.uppercase : false , /* hexadecimal output case format. false - lowercase; true - uppercase  */
1212         b64pad = (options && typeof options.pad === 'string') ? options.pda : '=',  /* base-64 pad character. Default '=' for strict RFC compliance   */
1213         utf8 = (options && typeof options.utf8 === 'boolean') ? options.utf8 : true, /* enable/disable utf8 encoding */
1214         sha512_k;
1215
1216     /* privileged (public) methods */
1217     this.hex = function (s) { 
1218       return rstr2hex(rstr(s)); 
1219     };
1220     this.b64 = function (s) { 
1221       return rstr2b64(rstr(s), b64pad);  
1222     };
1223     this.any = function (s, e) { 
1224       return rstr2any(rstr(s), e);
1225     };
1226     this.hex_hmac = function (k, d) {
1227       return rstr2hex(rstr_hmac(k, d));
1228     };
1229     this.b64_hmac = function (k, d) { 
1230       return rstr2b64(rstr_hmac(k, d), b64pad);
1231     };
1232     this.any_hmac = function (k, d, e) { 
1233       return rstr2any(rstr_hmac(k, d), e);
1234     };
1235     /**
1236      * Perform a simple self-test to see if the VM is working
1237      * @return {String} Hexadecimal hash sample
1238      * @public
1239      */
1240     this.vm_test = function () {
1241       return hex('abc').toLowerCase() === '900150983cd24fb0d6963f7d28e17f72';
1242     };
1243     /** 
1244      * @description Enable/disable uppercase hexadecimal returned string 
1245      * @param {boolean} 
1246      * @return {Object} this
1247      * @public
1248      */ 
1249     this.setUpperCase = function (a) {
1250       if (typeof a === 'boolean') {
1251         hexcase = a;
1252       }
1253       return this;
1254     };
1255     /** 
1256      * @description Defines a base64 pad string 
1257      * @param {string} Pad
1258      * @return {Object} this
1259      * @public
1260      */ 
1261     this.setPad = function (a) {
1262       b64pad = a || b64pad;
1263       return this;
1264     };
1265     /** 
1266      * @description Defines a base64 pad string 
1267      * @param {boolean} 
1268      * @return {Object} this
1269      * @public
1270      */ 
1271     this.setUTF8 = function (a) {
1272       if (typeof a === 'boolean') {
1273         utf8 = a;
1274       }
1275       return this;
1276     };
1277
1278     /* private methods */
1279     
1280     /**
1281      * Calculate the SHA-512 of a raw string
1282      */
1283     function rstr(s) {
1284       s = (utf8) ? utf8Encode(s) : s;
1285       return binb2rstr(binb(rstr2binb(s), s.length * 8));
1286     }
1287     /*
1288      * Calculate the HMAC-SHA-512 of a key and some data (raw strings)
1289      */
1290     function rstr_hmac(key, data) {
1291       key = (utf8) ? utf8Encode(key) : key;
1292       data = (utf8) ? utf8Encode(data) : data;
1293       
1294       var hash, i = 0, 
1295           bkey = rstr2binb(key),
1296           ipad = Array(32), opad = Array(32);
1297
1298       if (bkey.length > 32) { bkey = binb(bkey, key.length * 8); }
1299       
1300       for (; i < 32; i+=1) {
1301         ipad[i] = bkey[i] ^ 0x36363636;
1302         opad[i] = bkey[i] ^ 0x5C5C5C5C;
1303       }
1304       
1305       hash = binb(ipad.concat(rstr2binb(data)), 1024 + data.length * 8);
1306       return binb2rstr(binb(opad.concat(hash), 1024 + 512));
1307     }
1308             
1309     /**
1310      * Calculate the SHA-512 of an array of big-endian dwords, and a bit length
1311      */
1312     function binb(x, len) {
1313       var j, i, l,
1314           W = new Array(80),
1315           hash = new Array(16),
1316           //Initial hash values
1317           H = [
1318             new int64(0x6a09e667, -205731576),
1319             new int64(-1150833019, -2067093701),
1320             new int64(0x3c6ef372, -23791573),
1321             new int64(-1521486534, 0x5f1d36f1),
1322             new int64(0x510e527f, -1377402159),
1323             new int64(-1694144372, 0x2b3e6c1f),
1324             new int64(0x1f83d9ab, -79577749),
1325             new int64(0x5be0cd19, 0x137e2179)
1326           ],
1327           T1 = new int64(0, 0),
1328           T2 = new int64(0, 0),
1329           a = new int64(0,0),
1330           b = new int64(0,0),
1331           c = new int64(0,0),
1332           d = new int64(0,0),
1333           e = new int64(0,0),
1334           f = new int64(0,0),
1335           g = new int64(0,0),
1336           h = new int64(0,0),
1337           //Temporary variables not specified by the document
1338           s0 = new int64(0, 0),
1339           s1 = new int64(0, 0),
1340           Ch = new int64(0, 0),
1341           Maj = new int64(0, 0),
1342           r1 = new int64(0, 0),
1343           r2 = new int64(0, 0),
1344           r3 = new int64(0, 0);
1345
1346       if (sha512_k === undefined) {
1347           //SHA512 constants
1348           sha512_k = [
1349             new int64(0x428a2f98, -685199838), new int64(0x71374491, 0x23ef65cd),
1350             new int64(-1245643825, -330482897), new int64(-373957723, -2121671748),
1351             new int64(0x3956c25b, -213338824), new int64(0x59f111f1, -1241133031),
1352             new int64(-1841331548, -1357295717), new int64(-1424204075, -630357736),
1353             new int64(-670586216, -1560083902), new int64(0x12835b01, 0x45706fbe),
1354             new int64(0x243185be, 0x4ee4b28c), new int64(0x550c7dc3, -704662302),
1355             new int64(0x72be5d74, -226784913), new int64(-2132889090, 0x3b1696b1),
1356             new int64(-1680079193, 0x25c71235), new int64(-1046744716, -815192428),
1357             new int64(-459576895, -1628353838), new int64(-272742522, 0x384f25e3),
1358             new int64(0xfc19dc6, -1953704523), new int64(0x240ca1cc, 0x77ac9c65),
1359             new int64(0x2de92c6f, 0x592b0275), new int64(0x4a7484aa, 0x6ea6e483),
1360             new int64(0x5cb0a9dc, -1119749164), new int64(0x76f988da, -2096016459),
1361             new int64(-1740746414, -295247957), new int64(-1473132947, 0x2db43210),
1362             new int64(-1341970488, -1728372417), new int64(-1084653625, -1091629340),
1363             new int64(-958395405, 0x3da88fc2), new int64(-710438585, -1828018395),
1364             new int64(0x6ca6351, -536640913), new int64(0x14292967, 0xa0e6e70),
1365             new int64(0x27b70a85, 0x46d22ffc), new int64(0x2e1b2138, 0x5c26c926),
1366             new int64(0x4d2c6dfc, 0x5ac42aed), new int64(0x53380d13, -1651133473),
1367             new int64(0x650a7354, -1951439906), new int64(0x766a0abb, 0x3c77b2a8),
1368             new int64(-2117940946, 0x47edaee6), new int64(-1838011259, 0x1482353b),
1369             new int64(-1564481375, 0x4cf10364), new int64(-1474664885, -1136513023),
1370             new int64(-1035236496, -789014639), new int64(-949202525, 0x654be30),
1371             new int64(-778901479, -688958952), new int64(-694614492, 0x5565a910),
1372             new int64(-200395387, 0x5771202a), new int64(0x106aa070, 0x32bbd1b8),
1373             new int64(0x19a4c116, -1194143544), new int64(0x1e376c08, 0x5141ab53),
1374             new int64(0x2748774c, -544281703), new int64(0x34b0bcb5, -509917016),
1375             new int64(0x391c0cb3, -976659869), new int64(0x4ed8aa4a, -482243893),
1376             new int64(0x5b9cca4f, 0x7763e373), new int64(0x682e6ff3, -692930397),
1377             new int64(0x748f82ee, 0x5defb2fc), new int64(0x78a5636f, 0x43172f60),
1378             new int64(-2067236844, -1578062990), new int64(-1933114872, 0x1a6439ec),
1379             new int64(-1866530822, 0x23631e28), new int64(-1538233109, -561857047),
1380             new int64(-1090935817, -1295615723), new int64(-965641998, -479046869),
1381             new int64(-903397682, -366583396), new int64(-779700025, 0x21c0c207),
1382             new int64(-354779690, -840897762), new int64(-176337025, -294727304),
1383             new int64(0x6f067aa, 0x72176fba), new int64(0xa637dc5, -1563912026),
1384             new int64(0x113f9804, -1090974290), new int64(0x1b710b35, 0x131c471b),
1385             new int64(0x28db77f5, 0x23047d84), new int64(0x32caab7b, 0x40c72493),
1386             new int64(0x3c9ebe0a, 0x15c9bebc), new int64(0x431d67c4, -1676669620),
1387             new int64(0x4cc5d4be, -885112138), new int64(0x597f299c, -60457430),
1388             new int64(0x5fcb6fab, 0x3ad6faec), new int64(0x6c44198c, 0x4a475817)
1389           ];
1390       }
1391   
1392       for (i=0; i<80; i+=1) {
1393         W[i] = new int64(0, 0);
1394       }
1395     
1396       // append padding to the source string. The format is described in the FIPS.
1397       x[len >> 5] |= 0x80 << (24 - (len & 0x1f));
1398       x[((len + 128 >> 10)<< 5) + 31] = len;
1399       l = x.length;
1400       for (i = 0; i<l; i+=32) { //32 dwords is the block size
1401         int64copy(a, H[0]);
1402         int64copy(b, H[1]);
1403         int64copy(c, H[2]);
1404         int64copy(d, H[3]);
1405         int64copy(e, H[4]);
1406         int64copy(f, H[5]);
1407         int64copy(g, H[6]);
1408         int64copy(h, H[7]);
1409       
1410         for (j=0; j<16; j+=1) {
1411           W[j].h = x[i + 2*j];
1412           W[j].l = x[i + 2*j + 1];
1413         }
1414       
1415         for (j=16; j<80; j+=1) {
1416           //sigma1
1417           int64rrot(r1, W[j-2], 19);
1418           int64revrrot(r2, W[j-2], 29);
1419           int64shr(r3, W[j-2], 6);
1420           s1.l = r1.l ^ r2.l ^ r3.l;
1421           s1.h = r1.h ^ r2.h ^ r3.h;
1422           //sigma0
1423           int64rrot(r1, W[j-15], 1);
1424           int64rrot(r2, W[j-15], 8);
1425           int64shr(r3, W[j-15], 7);
1426           s0.l = r1.l ^ r2.l ^ r3.l;
1427           s0.h = r1.h ^ r2.h ^ r3.h;
1428       
1429           int64add4(W[j], s1, W[j-7], s0, W[j-16]);
1430         }
1431       
1432         for (j = 0; j < 80; j+=1) {
1433           //Ch
1434           Ch.l = (e.l & f.l) ^ (~e.l & g.l);
1435           Ch.h = (e.h & f.h) ^ (~e.h & g.h);
1436       
1437           //Sigma1
1438           int64rrot(r1, e, 14);
1439           int64rrot(r2, e, 18);
1440           int64revrrot(r3, e, 9);
1441           s1.l = r1.l ^ r2.l ^ r3.l;
1442           s1.h = r1.h ^ r2.h ^ r3.h;
1443       
1444           //Sigma0
1445           int64rrot(r1, a, 28);
1446           int64revrrot(r2, a, 2);
1447           int64revrrot(r3, a, 7);
1448           s0.l = r1.l ^ r2.l ^ r3.l;
1449           s0.h = r1.h ^ r2.h ^ r3.h;
1450       
1451           //Maj
1452           Maj.l = (a.l & b.l) ^ (a.l & c.l) ^ (b.l & c.l);
1453           Maj.h = (a.h & b.h) ^ (a.h & c.h) ^ (b.h & c.h);
1454       
1455           int64add5(T1, h, s1, Ch, sha512_k[j], W[j]);
1456           int64add(T2, s0, Maj);
1457       
1458           int64copy(h, g);
1459           int64copy(g, f);
1460           int64copy(f, e);
1461           int64add(e, d, T1);
1462           int64copy(d, c);
1463           int64copy(c, b);
1464           int64copy(b, a);
1465           int64add(a, T1, T2);
1466         }
1467         int64add(H[0], H[0], a);
1468         int64add(H[1], H[1], b);
1469         int64add(H[2], H[2], c);
1470         int64add(H[3], H[3], d);
1471         int64add(H[4], H[4], e);
1472         int64add(H[5], H[5], f);
1473         int64add(H[6], H[6], g);
1474         int64add(H[7], H[7], h);
1475       }
1476     
1477       //represent the hash as an array of 32-bit dwords
1478       for (i=0; i<8; i+=1) {
1479         hash[2*i] = H[i].h;
1480         hash[2*i + 1] = H[i].l;
1481       }
1482       return hash;
1483     }
1484     
1485     //A constructor for 64-bit numbers
1486     function int64(h, l) {
1487       this.h = h;
1488       this.l = l;
1489       //this.toString = int64toString;
1490     }
1491     
1492     //Copies src into dst, assuming both are 64-bit numbers
1493     function int64copy(dst, src) {
1494       dst.h = src.h;
1495       dst.l = src.l;
1496     }
1497     
1498     //Right-rotates a 64-bit number by shift
1499     //Won't handle cases of shift>=32
1500     //The function revrrot() is for that
1501     function int64rrot(dst, x, shift) {
1502       dst.l = (x.l >>> shift) | (x.h << (32-shift));
1503       dst.h = (x.h >>> shift) | (x.l << (32-shift));
1504     }
1505     
1506     //Reverses the dwords of the source and then rotates right by shift.
1507     //This is equivalent to rotation by 32+shift
1508     function int64revrrot(dst, x, shift) {
1509       dst.l = (x.h >>> shift) | (x.l << (32-shift));
1510       dst.h = (x.l >>> shift) | (x.h << (32-shift));
1511     }
1512     
1513     //Bitwise-shifts right a 64-bit number by shift
1514     //Won't handle shift>=32, but it's never needed in SHA512
1515     function int64shr(dst, x, shift) {
1516       dst.l = (x.l >>> shift) | (x.h << (32-shift));
1517       dst.h = (x.h >>> shift);
1518     }
1519     
1520     //Adds two 64-bit numbers
1521     //Like the original implementation, does not rely on 32-bit operations
1522     function int64add(dst, x, y) {
1523        var w0 = (x.l & 0xffff) + (y.l & 0xffff);
1524        var w1 = (x.l >>> 16) + (y.l >>> 16) + (w0 >>> 16);
1525        var w2 = (x.h & 0xffff) + (y.h & 0xffff) + (w1 >>> 16);
1526        var w3 = (x.h >>> 16) + (y.h >>> 16) + (w2 >>> 16);
1527        dst.l = (w0 & 0xffff) | (w1 << 16);
1528        dst.h = (w2 & 0xffff) | (w3 << 16);
1529     }
1530     
1531     //Same, except with 4 addends. Works faster than adding them one by one.
1532     function int64add4(dst, a, b, c, d) {
1533        var w0 = (a.l & 0xffff) + (b.l & 0xffff) + (c.l & 0xffff) + (d.l & 0xffff);
1534        var w1 = (a.l >>> 16) + (b.l >>> 16) + (c.l >>> 16) + (d.l >>> 16) + (w0 >>> 16);
1535        var w2 = (a.h & 0xffff) + (b.h & 0xffff) + (c.h & 0xffff) + (d.h & 0xffff) + (w1 >>> 16);
1536        var w3 = (a.h >>> 16) + (b.h >>> 16) + (c.h >>> 16) + (d.h >>> 16) + (w2 >>> 16);
1537        dst.l = (w0 & 0xffff) | (w1 << 16);
1538        dst.h = (w2 & 0xffff) | (w3 << 16);
1539     }
1540     
1541     //Same, except with 5 addends
1542     function int64add5(dst, a, b, c, d, e) {
1543       var w0 = (a.l & 0xffff) + (b.l & 0xffff) + (c.l & 0xffff) + (d.l & 0xffff) + (e.l & 0xffff),
1544           w1 = (a.l >>> 16) + (b.l >>> 16) + (c.l >>> 16) + (d.l >>> 16) + (e.l >>> 16) + (w0 >>> 16),
1545           w2 = (a.h & 0xffff) + (b.h & 0xffff) + (c.h & 0xffff) + (d.h & 0xffff) + (e.h & 0xffff) + (w1 >>> 16),
1546           w3 = (a.h >>> 16) + (b.h >>> 16) + (c.h >>> 16) + (d.h >>> 16) + (e.h >>> 16) + (w2 >>> 16);
1547        dst.l = (w0 & 0xffff) | (w1 << 16);
1548        dst.h = (w2 & 0xffff) | (w3 << 16);
1549     }
1550   },
1551   /**
1552    * @class Hashes.RMD160
1553    * @constructor
1554    * @param {Object} [config]
1555    * 
1556    * A JavaScript implementation of the RIPEMD-160 Algorithm
1557    * Version 2.2 Copyright Jeremy Lin, Paul Johnston 2000 - 2009.
1558    * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
1559    * See http://pajhome.org.uk/crypt/md5 for details.
1560    * Also http://www.ocf.berkeley.edu/~jjlin/jsotp/
1561    */
1562   RMD160 : function (options) {
1563     /**
1564      * Private properties configuration variables. You may need to tweak these to be compatible with
1565      * the server-side, but the defaults work in most cases.
1566      * @see this.setUpperCase() method
1567      * @see this.setPad() method
1568      */
1569     var hexcase = (options && typeof options.uppercase === 'boolean') ? options.uppercase : false,   /* hexadecimal output case format. false - lowercase; true - uppercase  */
1570         b64pad = (options && typeof options.pad === 'string') ? options.pda : '=',  /* base-64 pad character. Default '=' for strict RFC compliance   */
1571         utf8 = (options && typeof options.utf8 === 'boolean') ? options.utf8 : true, /* enable/disable utf8 encoding */
1572         rmd160_r1 = [
1573            0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15,
1574            7,  4, 13,  1, 10,  6, 15,  3, 12,  0,  9,  5,  2, 14, 11,  8,
1575            3, 10, 14,  4,  9, 15,  8,  1,  2,  7,  0,  6, 13, 11,  5, 12,
1576            1,  9, 11, 10,  0,  8, 12,  4, 13,  3,  7, 15, 14,  5,  6,  2,
1577            4,  0,  5,  9,  7, 12,  2, 10, 14,  1,  3,  8, 11,  6, 15, 13
1578         ],
1579         rmd160_r2 = [
1580            5, 14,  7,  0,  9,  2, 11,  4, 13,  6, 15,  8,  1, 10,  3, 12,
1581            6, 11,  3,  7,  0, 13,  5, 10, 14, 15,  8, 12,  4,  9,  1,  2,
1582           15,  5,  1,  3,  7, 14,  6,  9, 11,  8, 12,  2, 10,  0,  4, 13,
1583            8,  6,  4,  1,  3, 11, 15,  0,  5, 12,  2, 13,  9,  7, 10, 14,
1584           12, 15, 10,  4,  1,  5,  8,  7,  6,  2, 13, 14,  0,  3,  9, 11
1585         ],
1586         rmd160_s1 = [
1587           11, 14, 15, 12,  5,  8,  7,  9, 11, 13, 14, 15,  6,  7,  9,  8,
1588            7,  6,  8, 13, 11,  9,  7, 15,  7, 12, 15,  9, 11,  7, 13, 12,
1589           11, 13,  6,  7, 14,  9, 13, 15, 14,  8, 13,  6,  5, 12,  7,  5,
1590           11, 12, 14, 15, 14, 15,  9,  8,  9, 14,  5,  6,  8,  6,  5, 12,
1591            9, 15,  5, 11,  6,  8, 13, 12,  5, 12, 13, 14, 11,  8,  5,  6
1592         ],
1593         rmd160_s2 = [
1594            8,  9,  9, 11, 13, 15, 15,  5,  7,  7,  8, 11, 14, 14, 12,  6,
1595            9, 13, 15,  7, 12,  8,  9, 11,  7,  7, 12,  7,  6, 15, 13, 11,
1596            9,  7, 15, 11,  8,  6,  6, 14, 12, 13,  5, 14, 13, 13,  7,  5,
1597           15,  5,  8, 11, 14, 14,  6, 14,  6,  9, 12,  9, 12,  5, 15,  8,
1598            8,  5, 12,  9, 12,  5, 14,  6,  8, 13,  6,  5, 15, 13, 11, 11
1599         ];
1600
1601     /* privileged (public) methods */
1602     this.hex = function (s) {
1603       return rstr2hex(rstr(s, utf8)); 
1604     };
1605     this.b64 = function (s) {
1606       return rstr2b64(rstr(s, utf8), b64pad);
1607     };
1608     this.any = function (s, e) { 
1609       return rstr2any(rstr(s, utf8), e);
1610     };
1611     this.hex_hmac = function (k, d) { 
1612       return rstr2hex(rstr_hmac(k, d));
1613     };
1614     this.b64_hmac = function (k, d) { 
1615       return rstr2b64(rstr_hmac(k, d), b64pad);
1616     };
1617     this.any_hmac = function (k, d, e) { 
1618       return rstr2any(rstr_hmac(k, d), e); 
1619     };
1620     /**
1621      * Perform a simple self-test to see if the VM is working
1622      * @return {String} Hexadecimal hash sample
1623      * @public
1624      */
1625     this.vm_test = function () {
1626       return hex('abc').toLowerCase() === '900150983cd24fb0d6963f7d28e17f72';
1627     };
1628     /** 
1629      * @description Enable/disable uppercase hexadecimal returned string 
1630      * @param {boolean} 
1631      * @return {Object} this
1632      * @public
1633      */ 
1634     this.setUpperCase = function (a) {
1635       if (typeof a === 'boolean' ) { hexcase = a; }
1636       return this;
1637     };
1638     /** 
1639      * @description Defines a base64 pad string 
1640      * @param {string} Pad
1641      * @return {Object} this
1642      * @public
1643      */ 
1644     this.setPad = function (a) {
1645       if (typeof a !== 'undefined' ) { b64pad = a; }
1646       return this;
1647     };
1648     /** 
1649      * @description Defines a base64 pad string 
1650      * @param {boolean} 
1651      * @return {Object} this
1652      * @public
1653      */ 
1654     this.setUTF8 = function (a) {
1655       if (typeof a === 'boolean') { utf8 = a; }
1656       return this;
1657     };
1658
1659     /* private methods */
1660
1661     /**
1662      * Calculate the rmd160 of a raw string
1663      */
1664     function rstr(s) {
1665       s = (utf8) ? utf8Encode(s) : s;
1666       return binl2rstr(binl(rstr2binl(s), s.length * 8));
1667     }
1668
1669     /**
1670      * Calculate the HMAC-rmd160 of a key and some data (raw strings)
1671      */
1672     function rstr_hmac(key, data) {
1673       key = (utf8) ? utf8Encode(key) : key;
1674       data = (utf8) ? utf8Encode(data) : data;
1675       var i, hash,
1676           bkey = rstr2binl(key),
1677           ipad = Array(16), opad = Array(16);
1678
1679       if (bkey.length > 16) { 
1680         bkey = binl(bkey, key.length * 8); 
1681       }
1682       
1683       for (i = 0; i < 16; i+=1) {
1684         ipad[i] = bkey[i] ^ 0x36363636;
1685         opad[i] = bkey[i] ^ 0x5C5C5C5C;
1686       }
1687       hash = binl(ipad.concat(rstr2binl(data)), 512 + data.length * 8);
1688       return binl2rstr(binl(opad.concat(hash), 512 + 160));
1689     }
1690
1691     /**
1692      * Convert an array of little-endian words to a string
1693      */
1694     function binl2rstr(input) {
1695       var i, output = '', l = input.length * 32;
1696       for (i = 0; i < l; i += 8) {
1697         output += String.fromCharCode((input[i>>5] >>> (i % 32)) & 0xFF);
1698       }
1699       return output;
1700     }
1701
1702     /**
1703      * Calculate the RIPE-MD160 of an array of little-endian words, and a bit length.
1704      */
1705     function binl(x, len) {
1706       var T, j, i, l,
1707           h0 = 0x67452301,
1708           h1 = 0xefcdab89,
1709           h2 = 0x98badcfe,
1710           h3 = 0x10325476,
1711           h4 = 0xc3d2e1f0,
1712           A1, B1, C1, D1, E1,
1713           A2, B2, C2, D2, E2;
1714
1715       /* append padding */
1716       x[len >> 5] |= 0x80 << (len % 32);
1717       x[(((len + 64) >>> 9) << 4) + 14] = len;
1718       l = x.length;
1719       
1720       for (i = 0; i < l; i+=16) {
1721         A1 = A2 = h0; B1 = B2 = h1; C1 = C2 = h2; D1 = D2 = h3; E1 = E2 = h4;
1722         for (j = 0; j <= 79; j+=1) {
1723           T = safe_add(A1, rmd160_f(j, B1, C1, D1));
1724           T = safe_add(T, x[i + rmd160_r1[j]]);
1725           T = safe_add(T, rmd160_K1(j));
1726           T = safe_add(bit_rol(T, rmd160_s1[j]), E1);
1727           A1 = E1; E1 = D1; D1 = bit_rol(C1, 10); C1 = B1; B1 = T;
1728           T = safe_add(A2, rmd160_f(79-j, B2, C2, D2));
1729           T = safe_add(T, x[i + rmd160_r2[j]]);
1730           T = safe_add(T, rmd160_K2(j));
1731           T = safe_add(bit_rol(T, rmd160_s2[j]), E2);
1732           A2 = E2; E2 = D2; D2 = bit_rol(C2, 10); C2 = B2; B2 = T;
1733         }
1734
1735         T = safe_add(h1, safe_add(C1, D2));
1736         h1 = safe_add(h2, safe_add(D1, E2));
1737         h2 = safe_add(h3, safe_add(E1, A2));
1738         h3 = safe_add(h4, safe_add(A1, B2));
1739         h4 = safe_add(h0, safe_add(B1, C2));
1740         h0 = T;
1741       }
1742       return [h0, h1, h2, h3, h4];
1743     }
1744
1745     // specific algorithm methods 
1746     function rmd160_f(j, x, y, z) {
1747       return ( 0 <= j && j <= 15) ? (x ^ y ^ z) :
1748          (16 <= j && j <= 31) ? (x & y) | (~x & z) :
1749          (32 <= j && j <= 47) ? (x | ~y) ^ z :
1750          (48 <= j && j <= 63) ? (x & z) | (y & ~z) :
1751          (64 <= j && j <= 79) ? x ^ (y | ~z) :
1752          'rmd160_f: j out of range';
1753     }
1754
1755     function rmd160_K1(j) {
1756       return ( 0 <= j && j <= 15) ? 0x00000000 :
1757          (16 <= j && j <= 31) ? 0x5a827999 :
1758          (32 <= j && j <= 47) ? 0x6ed9eba1 :
1759          (48 <= j && j <= 63) ? 0x8f1bbcdc :
1760          (64 <= j && j <= 79) ? 0xa953fd4e :
1761          'rmd160_K1: j out of range';
1762     }
1763
1764     function rmd160_K2(j){
1765       return ( 0 <= j && j <= 15) ? 0x50a28be6 :
1766          (16 <= j && j <= 31) ? 0x5c4dd124 :
1767          (32 <= j && j <= 47) ? 0x6d703ef3 :
1768          (48 <= j && j <= 63) ? 0x7a6d76e9 :
1769          (64 <= j && j <= 79) ? 0x00000000 :
1770          'rmd160_K2: j out of range';
1771     }
1772   }
1773 };
1774
1775   // exposes Hashes
1776   (function( window, undefined ) {
1777     var freeExports = false;
1778     if (typeof exports === 'object' ) {
1779       freeExports = exports;
1780       if (exports && typeof global === 'object' && global && global === global.global ) { window = global; }
1781     }
1782
1783     if (typeof define === 'function' && typeof define.amd === 'object' && define.amd) {
1784       // define as an anonymous module, so, through path mapping, it can be aliased
1785       define(function () { return Hashes; });
1786     }
1787     else if ( freeExports ) {
1788       // in Node.js or RingoJS v0.8.0+
1789       if ( typeof module === 'object' && module && module.exports === freeExports ) {
1790         module.exports = Hashes;
1791       }
1792       // in Narwhal or RingoJS v0.7.0-
1793       else {
1794         freeExports.Hashes = Hashes;
1795       }
1796     }
1797     else {
1798       // in a browser or Rhino
1799       window.Hashes = Hashes;
1800     }
1801   }( this ));
1802 }()); // IIFE
1803 })(window)
1804 },{}]},{},[1])(1)
1805 });
1806 ;