Removed unused standalone libraries and fixed a few outstanding imports.
This commit is contained in:
parent
a21e0e546b
commit
99f306dc18
@ -61,7 +61,6 @@
|
||||
"moment": "^2.17.1",
|
||||
"moment-timezone": "^0.5.11",
|
||||
"sladex-blowfish": "^0.8.1",
|
||||
"uas-parser": "^0.2.2",
|
||||
"vkbeautify": "^0.99.1",
|
||||
"zlibjs": "^0.2.0"
|
||||
}
|
||||
|
@ -29,7 +29,11 @@
|
||||
// modify rules from base configurations
|
||||
"no-unused-vars": ["error", {
|
||||
"args": "none",
|
||||
"vars": "local"
|
||||
"vars": "local",
|
||||
// Allow vars that start with a capital letter to be unused.
|
||||
// This is mainly for exported module names which are useful to indicate
|
||||
// the name of the module and may be used to refer to itself in future.
|
||||
"varsIgnorePattern": "^[A-Z]"
|
||||
}],
|
||||
"no-empty": ["error", {
|
||||
"allowEmptyCatch": true
|
||||
@ -112,7 +116,7 @@
|
||||
"SeasonalWaiter": false,
|
||||
"WindowWaiter": false,
|
||||
|
||||
/* tests */
|
||||
/* test/* */
|
||||
"TestRegister": false,
|
||||
"TestRunner": false
|
||||
}
|
||||
|
@ -1,649 +0,0 @@
|
||||
/** @license
|
||||
========================================================================
|
||||
Blowfish.js from Dojo Toolkit 1.8.1
|
||||
Cut of by Sladex (xslade@gmail.com)
|
||||
|
||||
Created based on the C# implementation by Marcus Hahn (http://www.hotpixel.net/)
|
||||
Unsigned math based on Paul Johnstone and Peter Wood patches.
|
||||
2005-12-08
|
||||
|
||||
The Dojo Toolkit (including this package) is dual licensed under BSD 3-Clause and AFL.
|
||||
The Dojo Toolkit is Copyright (c) 2005-2016, The Dojo Foundation. All rights reserved.
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* Blowfish.js from Dojo Toolkit 1.8.1
|
||||
* Cut of by Sladex (xslade@gmail.com)
|
||||
*
|
||||
* Usage:
|
||||
* blowfish.encrypt(String 'subj to encrypt', String 'key', Object {outputType: 1, cipherMode: 0});
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
(function(global){
|
||||
|
||||
var crypto = {};
|
||||
|
||||
|
||||
|
||||
/* dojo-release-1.8.1/dojox/encoding/crypto/_base.js.uncompressed.js */
|
||||
|
||||
crypto.cipherModes = {
|
||||
// summary:
|
||||
// Enumeration for various cipher modes.
|
||||
ECB:0, CBC:1, PCBC:2, CFB:3, OFB:4, CTR:5
|
||||
};
|
||||
crypto.outputTypes = {
|
||||
// summary:
|
||||
// Enumeration for input and output encodings.
|
||||
Base64:0, Hex:1, String:2, Raw:3
|
||||
};
|
||||
|
||||
|
||||
|
||||
/* dojo-release-1.8.1/dojox/encoding/base64.js.uncompressed.js */
|
||||
|
||||
var base64 = {};
|
||||
var p="=";
|
||||
var tab="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
|
||||
base64.encode=function(/* byte[] */ba){
|
||||
// summary:
|
||||
// Encode an array of bytes as a base64-encoded string
|
||||
var s=[], l=ba.length;
|
||||
var rm=l%3;
|
||||
var x=l-rm;
|
||||
for (var i=0; i<x;){
|
||||
var t=ba[i++]<<16|ba[i++]<<8|ba[i++];
|
||||
s.push(tab.charAt((t>>>18)&0x3f));
|
||||
s.push(tab.charAt((t>>>12)&0x3f));
|
||||
s.push(tab.charAt((t>>>6)&0x3f));
|
||||
s.push(tab.charAt(t&0x3f));
|
||||
}
|
||||
// deal with trailers, based on patch from Peter Wood.
|
||||
switch(rm){
|
||||
case 2:{
|
||||
var t=ba[i++]<<16|ba[i++]<<8;
|
||||
s.push(tab.charAt((t>>>18)&0x3f));
|
||||
s.push(tab.charAt((t>>>12)&0x3f));
|
||||
s.push(tab.charAt((t>>>6)&0x3f));
|
||||
s.push(p);
|
||||
break;
|
||||
}
|
||||
case 1:{
|
||||
var t=ba[i++]<<16;
|
||||
s.push(tab.charAt((t>>>18)&0x3f));
|
||||
s.push(tab.charAt((t>>>12)&0x3f));
|
||||
s.push(p);
|
||||
s.push(p);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return s.join(""); // string
|
||||
};
|
||||
|
||||
base64.decode=function(/* string */str){
|
||||
// summary:
|
||||
// Convert a base64-encoded string to an array of bytes
|
||||
var s=str.split(""), out=[];
|
||||
var l=s.length;
|
||||
while(s[--l]==p){ } // strip off trailing padding
|
||||
for (var i=0; i<l;){
|
||||
var t=tab.indexOf(s[i++])<<18;
|
||||
if(i<=l){ t|=tab.indexOf(s[i++])<<12 };
|
||||
if(i<=l){ t|=tab.indexOf(s[i++])<<6 };
|
||||
if(i<=l){ t|=tab.indexOf(s[i++]) };
|
||||
out.push((t>>>16)&0xff);
|
||||
out.push((t>>>8)&0xff);
|
||||
out.push(t&0xff);
|
||||
}
|
||||
// strip off any null bytes
|
||||
while(out[out.length-1]==0){ out.pop(); }
|
||||
return out; // byte[]
|
||||
};
|
||||
|
||||
|
||||
|
||||
/* dojo-release-1.8.1/dojo/_base/lang.js.uncompressed.js */
|
||||
|
||||
var lang = {};
|
||||
lang.isString = function(it){
|
||||
// summary:
|
||||
// Return true if it is a String
|
||||
// it: anything
|
||||
// Item to test.
|
||||
return (typeof it == "string" || it instanceof String); // Boolean
|
||||
};
|
||||
|
||||
|
||||
|
||||
/* dojo-release-1.8.1/dojo/_base/array.js.uncompressed.js */
|
||||
|
||||
var arrayUtil = {};
|
||||
arrayUtil.map = function(arr, callback, thisObject, Ctr){
|
||||
// summary:
|
||||
// applies callback to each element of arr and returns
|
||||
// an Array with the results
|
||||
// arr: Array|String
|
||||
// the array to iterate on. If a string, operates on
|
||||
// individual characters.
|
||||
// callback: Function|String
|
||||
// a function is invoked with three arguments, (item, index,
|
||||
// array), and returns a value
|
||||
// thisObject: Object?
|
||||
// may be used to scope the call to callback
|
||||
// returns: Array
|
||||
// description:
|
||||
// This function corresponds to the JavaScript 1.6 Array.map() method, with one difference: when
|
||||
// run over sparse arrays, this implementation passes the "holes" in the sparse array to
|
||||
// the callback function with a value of undefined. JavaScript 1.6's map skips the holes in the sparse array.
|
||||
// For more details, see:
|
||||
// https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/map
|
||||
// example:
|
||||
// | // returns [2, 3, 4, 5]
|
||||
// | array.map([1, 2, 3, 4], function(item){ return item+1 });
|
||||
|
||||
// TODO: why do we have a non-standard signature here? do we need "Ctr"?
|
||||
var i = 0, l = arr && arr.length || 0, out = new (Ctr || Array)(l);
|
||||
if(l && typeof arr == "string") arr = arr.split("");
|
||||
if(typeof callback == "string") callback = cache[callback] || buildFn(callback);
|
||||
if(thisObject){
|
||||
for(; i < l; ++i){
|
||||
out[i] = callback.call(thisObject, arr[i], i, arr);
|
||||
}
|
||||
}else{
|
||||
for(; i < l; ++i){
|
||||
out[i] = callback(arr[i], i, arr);
|
||||
}
|
||||
}
|
||||
return out; // Array
|
||||
};
|
||||
|
||||
|
||||
|
||||
/* dojo-release-1.8.1/dojox/encoding/crypto/Blowfish.js.uncompressed.js */
|
||||
|
||||
/* Blowfish
|
||||
* Created based on the C# implementation by Marcus Hahn (http://www.hotpixel.net/)
|
||||
* Unsigned math based on Paul Johnstone and Peter Wood patches.
|
||||
* 2005-12-08
|
||||
*/
|
||||
crypto.Blowfish = new function(){
|
||||
// summary:
|
||||
// Object for doing Blowfish encryption/decryption.
|
||||
var POW2=Math.pow(2,2);
|
||||
var POW3=Math.pow(2,3);
|
||||
var POW4=Math.pow(2,4);
|
||||
var POW8=Math.pow(2,8);
|
||||
var POW16=Math.pow(2,16);
|
||||
var POW24=Math.pow(2,24);
|
||||
var iv=null; // CBC mode initialization vector
|
||||
var boxes={
|
||||
p:[
|
||||
0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344, 0xa4093822, 0x299f31d0, 0x082efa98, 0xec4e6c89,
|
||||
0x452821e6, 0x38d01377, 0xbe5466cf, 0x34e90c6c, 0xc0ac29b7, 0xc97c50dd, 0x3f84d5b5, 0xb5470917,
|
||||
0x9216d5d9, 0x8979fb1b
|
||||
],
|
||||
s0:[
|
||||
0xd1310ba6, 0x98dfb5ac, 0x2ffd72db, 0xd01adfb7, 0xb8e1afed, 0x6a267e96, 0xba7c9045, 0xf12c7f99,
|
||||
0x24a19947, 0xb3916cf7, 0x0801f2e2, 0x858efc16, 0x636920d8, 0x71574e69, 0xa458fea3, 0xf4933d7e,
|
||||
0x0d95748f, 0x728eb658, 0x718bcd58, 0x82154aee, 0x7b54a41d, 0xc25a59b5, 0x9c30d539, 0x2af26013,
|
||||
0xc5d1b023, 0x286085f0, 0xca417918, 0xb8db38ef, 0x8e79dcb0, 0x603a180e, 0x6c9e0e8b, 0xb01e8a3e,
|
||||
0xd71577c1, 0xbd314b27, 0x78af2fda, 0x55605c60, 0xe65525f3, 0xaa55ab94, 0x57489862, 0x63e81440,
|
||||
0x55ca396a, 0x2aab10b6, 0xb4cc5c34, 0x1141e8ce, 0xa15486af, 0x7c72e993, 0xb3ee1411, 0x636fbc2a,
|
||||
0x2ba9c55d, 0x741831f6, 0xce5c3e16, 0x9b87931e, 0xafd6ba33, 0x6c24cf5c, 0x7a325381, 0x28958677,
|
||||
0x3b8f4898, 0x6b4bb9af, 0xc4bfe81b, 0x66282193, 0x61d809cc, 0xfb21a991, 0x487cac60, 0x5dec8032,
|
||||
0xef845d5d, 0xe98575b1, 0xdc262302, 0xeb651b88, 0x23893e81, 0xd396acc5, 0x0f6d6ff3, 0x83f44239,
|
||||
0x2e0b4482, 0xa4842004, 0x69c8f04a, 0x9e1f9b5e, 0x21c66842, 0xf6e96c9a, 0x670c9c61, 0xabd388f0,
|
||||
0x6a51a0d2, 0xd8542f68, 0x960fa728, 0xab5133a3, 0x6eef0b6c, 0x137a3be4, 0xba3bf050, 0x7efb2a98,
|
||||
0xa1f1651d, 0x39af0176, 0x66ca593e, 0x82430e88, 0x8cee8619, 0x456f9fb4, 0x7d84a5c3, 0x3b8b5ebe,
|
||||
0xe06f75d8, 0x85c12073, 0x401a449f, 0x56c16aa6, 0x4ed3aa62, 0x363f7706, 0x1bfedf72, 0x429b023d,
|
||||
0x37d0d724, 0xd00a1248, 0xdb0fead3, 0x49f1c09b, 0x075372c9, 0x80991b7b, 0x25d479d8, 0xf6e8def7,
|
||||
0xe3fe501a, 0xb6794c3b, 0x976ce0bd, 0x04c006ba, 0xc1a94fb6, 0x409f60c4, 0x5e5c9ec2, 0x196a2463,
|
||||
0x68fb6faf, 0x3e6c53b5, 0x1339b2eb, 0x3b52ec6f, 0x6dfc511f, 0x9b30952c, 0xcc814544, 0xaf5ebd09,
|
||||
0xbee3d004, 0xde334afd, 0x660f2807, 0x192e4bb3, 0xc0cba857, 0x45c8740f, 0xd20b5f39, 0xb9d3fbdb,
|
||||
0x5579c0bd, 0x1a60320a, 0xd6a100c6, 0x402c7279, 0x679f25fe, 0xfb1fa3cc, 0x8ea5e9f8, 0xdb3222f8,
|
||||
0x3c7516df, 0xfd616b15, 0x2f501ec8, 0xad0552ab, 0x323db5fa, 0xfd238760, 0x53317b48, 0x3e00df82,
|
||||
0x9e5c57bb, 0xca6f8ca0, 0x1a87562e, 0xdf1769db, 0xd542a8f6, 0x287effc3, 0xac6732c6, 0x8c4f5573,
|
||||
0x695b27b0, 0xbbca58c8, 0xe1ffa35d, 0xb8f011a0, 0x10fa3d98, 0xfd2183b8, 0x4afcb56c, 0x2dd1d35b,
|
||||
0x9a53e479, 0xb6f84565, 0xd28e49bc, 0x4bfb9790, 0xe1ddf2da, 0xa4cb7e33, 0x62fb1341, 0xcee4c6e8,
|
||||
0xef20cada, 0x36774c01, 0xd07e9efe, 0x2bf11fb4, 0x95dbda4d, 0xae909198, 0xeaad8e71, 0x6b93d5a0,
|
||||
0xd08ed1d0, 0xafc725e0, 0x8e3c5b2f, 0x8e7594b7, 0x8ff6e2fb, 0xf2122b64, 0x8888b812, 0x900df01c,
|
||||
0x4fad5ea0, 0x688fc31c, 0xd1cff191, 0xb3a8c1ad, 0x2f2f2218, 0xbe0e1777, 0xea752dfe, 0x8b021fa1,
|
||||
0xe5a0cc0f, 0xb56f74e8, 0x18acf3d6, 0xce89e299, 0xb4a84fe0, 0xfd13e0b7, 0x7cc43b81, 0xd2ada8d9,
|
||||
0x165fa266, 0x80957705, 0x93cc7314, 0x211a1477, 0xe6ad2065, 0x77b5fa86, 0xc75442f5, 0xfb9d35cf,
|
||||
0xebcdaf0c, 0x7b3e89a0, 0xd6411bd3, 0xae1e7e49, 0x00250e2d, 0x2071b35e, 0x226800bb, 0x57b8e0af,
|
||||
0x2464369b, 0xf009b91e, 0x5563911d, 0x59dfa6aa, 0x78c14389, 0xd95a537f, 0x207d5ba2, 0x02e5b9c5,
|
||||
0x83260376, 0x6295cfa9, 0x11c81968, 0x4e734a41, 0xb3472dca, 0x7b14a94a, 0x1b510052, 0x9a532915,
|
||||
0xd60f573f, 0xbc9bc6e4, 0x2b60a476, 0x81e67400, 0x08ba6fb5, 0x571be91f, 0xf296ec6b, 0x2a0dd915,
|
||||
0xb6636521, 0xe7b9f9b6, 0xff34052e, 0xc5855664, 0x53b02d5d, 0xa99f8fa1, 0x08ba4799, 0x6e85076a
|
||||
],
|
||||
s1:[
|
||||
0x4b7a70e9, 0xb5b32944, 0xdb75092e, 0xc4192623, 0xad6ea6b0, 0x49a7df7d, 0x9cee60b8, 0x8fedb266,
|
||||
0xecaa8c71, 0x699a17ff, 0x5664526c, 0xc2b19ee1, 0x193602a5, 0x75094c29, 0xa0591340, 0xe4183a3e,
|
||||
0x3f54989a, 0x5b429d65, 0x6b8fe4d6, 0x99f73fd6, 0xa1d29c07, 0xefe830f5, 0x4d2d38e6, 0xf0255dc1,
|
||||
0x4cdd2086, 0x8470eb26, 0x6382e9c6, 0x021ecc5e, 0x09686b3f, 0x3ebaefc9, 0x3c971814, 0x6b6a70a1,
|
||||
0x687f3584, 0x52a0e286, 0xb79c5305, 0xaa500737, 0x3e07841c, 0x7fdeae5c, 0x8e7d44ec, 0x5716f2b8,
|
||||
0xb03ada37, 0xf0500c0d, 0xf01c1f04, 0x0200b3ff, 0xae0cf51a, 0x3cb574b2, 0x25837a58, 0xdc0921bd,
|
||||
0xd19113f9, 0x7ca92ff6, 0x94324773, 0x22f54701, 0x3ae5e581, 0x37c2dadc, 0xc8b57634, 0x9af3dda7,
|
||||
0xa9446146, 0x0fd0030e, 0xecc8c73e, 0xa4751e41, 0xe238cd99, 0x3bea0e2f, 0x3280bba1, 0x183eb331,
|
||||
0x4e548b38, 0x4f6db908, 0x6f420d03, 0xf60a04bf, 0x2cb81290, 0x24977c79, 0x5679b072, 0xbcaf89af,
|
||||
0xde9a771f, 0xd9930810, 0xb38bae12, 0xdccf3f2e, 0x5512721f, 0x2e6b7124, 0x501adde6, 0x9f84cd87,
|
||||
0x7a584718, 0x7408da17, 0xbc9f9abc, 0xe94b7d8c, 0xec7aec3a, 0xdb851dfa, 0x63094366, 0xc464c3d2,
|
||||
0xef1c1847, 0x3215d908, 0xdd433b37, 0x24c2ba16, 0x12a14d43, 0x2a65c451, 0x50940002, 0x133ae4dd,
|
||||
0x71dff89e, 0x10314e55, 0x81ac77d6, 0x5f11199b, 0x043556f1, 0xd7a3c76b, 0x3c11183b, 0x5924a509,
|
||||
0xf28fe6ed, 0x97f1fbfa, 0x9ebabf2c, 0x1e153c6e, 0x86e34570, 0xeae96fb1, 0x860e5e0a, 0x5a3e2ab3,
|
||||
0x771fe71c, 0x4e3d06fa, 0x2965dcb9, 0x99e71d0f, 0x803e89d6, 0x5266c825, 0x2e4cc978, 0x9c10b36a,
|
||||
0xc6150eba, 0x94e2ea78, 0xa5fc3c53, 0x1e0a2df4, 0xf2f74ea7, 0x361d2b3d, 0x1939260f, 0x19c27960,
|
||||
0x5223a708, 0xf71312b6, 0xebadfe6e, 0xeac31f66, 0xe3bc4595, 0xa67bc883, 0xb17f37d1, 0x018cff28,
|
||||
0xc332ddef, 0xbe6c5aa5, 0x65582185, 0x68ab9802, 0xeecea50f, 0xdb2f953b, 0x2aef7dad, 0x5b6e2f84,
|
||||
0x1521b628, 0x29076170, 0xecdd4775, 0x619f1510, 0x13cca830, 0xeb61bd96, 0x0334fe1e, 0xaa0363cf,
|
||||
0xb5735c90, 0x4c70a239, 0xd59e9e0b, 0xcbaade14, 0xeecc86bc, 0x60622ca7, 0x9cab5cab, 0xb2f3846e,
|
||||
0x648b1eaf, 0x19bdf0ca, 0xa02369b9, 0x655abb50, 0x40685a32, 0x3c2ab4b3, 0x319ee9d5, 0xc021b8f7,
|
||||
0x9b540b19, 0x875fa099, 0x95f7997e, 0x623d7da8, 0xf837889a, 0x97e32d77, 0x11ed935f, 0x16681281,
|
||||
0x0e358829, 0xc7e61fd6, 0x96dedfa1, 0x7858ba99, 0x57f584a5, 0x1b227263, 0x9b83c3ff, 0x1ac24696,
|
||||
0xcdb30aeb, 0x532e3054, 0x8fd948e4, 0x6dbc3128, 0x58ebf2ef, 0x34c6ffea, 0xfe28ed61, 0xee7c3c73,
|
||||
0x5d4a14d9, 0xe864b7e3, 0x42105d14, 0x203e13e0, 0x45eee2b6, 0xa3aaabea, 0xdb6c4f15, 0xfacb4fd0,
|
||||
0xc742f442, 0xef6abbb5, 0x654f3b1d, 0x41cd2105, 0xd81e799e, 0x86854dc7, 0xe44b476a, 0x3d816250,
|
||||
0xcf62a1f2, 0x5b8d2646, 0xfc8883a0, 0xc1c7b6a3, 0x7f1524c3, 0x69cb7492, 0x47848a0b, 0x5692b285,
|
||||
0x095bbf00, 0xad19489d, 0x1462b174, 0x23820e00, 0x58428d2a, 0x0c55f5ea, 0x1dadf43e, 0x233f7061,
|
||||
0x3372f092, 0x8d937e41, 0xd65fecf1, 0x6c223bdb, 0x7cde3759, 0xcbee7460, 0x4085f2a7, 0xce77326e,
|
||||
0xa6078084, 0x19f8509e, 0xe8efd855, 0x61d99735, 0xa969a7aa, 0xc50c06c2, 0x5a04abfc, 0x800bcadc,
|
||||
0x9e447a2e, 0xc3453484, 0xfdd56705, 0x0e1e9ec9, 0xdb73dbd3, 0x105588cd, 0x675fda79, 0xe3674340,
|
||||
0xc5c43465, 0x713e38d8, 0x3d28f89e, 0xf16dff20, 0x153e21e7, 0x8fb03d4a, 0xe6e39f2b, 0xdb83adf7
|
||||
],
|
||||
s2:[
|
||||
0xe93d5a68, 0x948140f7, 0xf64c261c, 0x94692934, 0x411520f7, 0x7602d4f7, 0xbcf46b2e, 0xd4a20068,
|
||||
0xd4082471, 0x3320f46a, 0x43b7d4b7, 0x500061af, 0x1e39f62e, 0x97244546, 0x14214f74, 0xbf8b8840,
|
||||
0x4d95fc1d, 0x96b591af, 0x70f4ddd3, 0x66a02f45, 0xbfbc09ec, 0x03bd9785, 0x7fac6dd0, 0x31cb8504,
|
||||
0x96eb27b3, 0x55fd3941, 0xda2547e6, 0xabca0a9a, 0x28507825, 0x530429f4, 0x0a2c86da, 0xe9b66dfb,
|
||||
0x68dc1462, 0xd7486900, 0x680ec0a4, 0x27a18dee, 0x4f3ffea2, 0xe887ad8c, 0xb58ce006, 0x7af4d6b6,
|
||||
0xaace1e7c, 0xd3375fec, 0xce78a399, 0x406b2a42, 0x20fe9e35, 0xd9f385b9, 0xee39d7ab, 0x3b124e8b,
|
||||
0x1dc9faf7, 0x4b6d1856, 0x26a36631, 0xeae397b2, 0x3a6efa74, 0xdd5b4332, 0x6841e7f7, 0xca7820fb,
|
||||
0xfb0af54e, 0xd8feb397, 0x454056ac, 0xba489527, 0x55533a3a, 0x20838d87, 0xfe6ba9b7, 0xd096954b,
|
||||
0x55a867bc, 0xa1159a58, 0xcca92963, 0x99e1db33, 0xa62a4a56, 0x3f3125f9, 0x5ef47e1c, 0x9029317c,
|
||||
0xfdf8e802, 0x04272f70, 0x80bb155c, 0x05282ce3, 0x95c11548, 0xe4c66d22, 0x48c1133f, 0xc70f86dc,
|
||||
0x07f9c9ee, 0x41041f0f, 0x404779a4, 0x5d886e17, 0x325f51eb, 0xd59bc0d1, 0xf2bcc18f, 0x41113564,
|
||||
0x257b7834, 0x602a9c60, 0xdff8e8a3, 0x1f636c1b, 0x0e12b4c2, 0x02e1329e, 0xaf664fd1, 0xcad18115,
|
||||
0x6b2395e0, 0x333e92e1, 0x3b240b62, 0xeebeb922, 0x85b2a20e, 0xe6ba0d99, 0xde720c8c, 0x2da2f728,
|
||||
0xd0127845, 0x95b794fd, 0x647d0862, 0xe7ccf5f0, 0x5449a36f, 0x877d48fa, 0xc39dfd27, 0xf33e8d1e,
|
||||
0x0a476341, 0x992eff74, 0x3a6f6eab, 0xf4f8fd37, 0xa812dc60, 0xa1ebddf8, 0x991be14c, 0xdb6e6b0d,
|
||||
0xc67b5510, 0x6d672c37, 0x2765d43b, 0xdcd0e804, 0xf1290dc7, 0xcc00ffa3, 0xb5390f92, 0x690fed0b,
|
||||
0x667b9ffb, 0xcedb7d9c, 0xa091cf0b, 0xd9155ea3, 0xbb132f88, 0x515bad24, 0x7b9479bf, 0x763bd6eb,
|
||||
0x37392eb3, 0xcc115979, 0x8026e297, 0xf42e312d, 0x6842ada7, 0xc66a2b3b, 0x12754ccc, 0x782ef11c,
|
||||
0x6a124237, 0xb79251e7, 0x06a1bbe6, 0x4bfb6350, 0x1a6b1018, 0x11caedfa, 0x3d25bdd8, 0xe2e1c3c9,
|
||||
0x44421659, 0x0a121386, 0xd90cec6e, 0xd5abea2a, 0x64af674e, 0xda86a85f, 0xbebfe988, 0x64e4c3fe,
|
||||
0x9dbc8057, 0xf0f7c086, 0x60787bf8, 0x6003604d, 0xd1fd8346, 0xf6381fb0, 0x7745ae04, 0xd736fccc,
|
||||
0x83426b33, 0xf01eab71, 0xb0804187, 0x3c005e5f, 0x77a057be, 0xbde8ae24, 0x55464299, 0xbf582e61,
|
||||
0x4e58f48f, 0xf2ddfda2, 0xf474ef38, 0x8789bdc2, 0x5366f9c3, 0xc8b38e74, 0xb475f255, 0x46fcd9b9,
|
||||
0x7aeb2661, 0x8b1ddf84, 0x846a0e79, 0x915f95e2, 0x466e598e, 0x20b45770, 0x8cd55591, 0xc902de4c,
|
||||
0xb90bace1, 0xbb8205d0, 0x11a86248, 0x7574a99e, 0xb77f19b6, 0xe0a9dc09, 0x662d09a1, 0xc4324633,
|
||||
0xe85a1f02, 0x09f0be8c, 0x4a99a025, 0x1d6efe10, 0x1ab93d1d, 0x0ba5a4df, 0xa186f20f, 0x2868f169,
|
||||
0xdcb7da83, 0x573906fe, 0xa1e2ce9b, 0x4fcd7f52, 0x50115e01, 0xa70683fa, 0xa002b5c4, 0x0de6d027,
|
||||
0x9af88c27, 0x773f8641, 0xc3604c06, 0x61a806b5, 0xf0177a28, 0xc0f586e0, 0x006058aa, 0x30dc7d62,
|
||||
0x11e69ed7, 0x2338ea63, 0x53c2dd94, 0xc2c21634, 0xbbcbee56, 0x90bcb6de, 0xebfc7da1, 0xce591d76,
|
||||
0x6f05e409, 0x4b7c0188, 0x39720a3d, 0x7c927c24, 0x86e3725f, 0x724d9db9, 0x1ac15bb4, 0xd39eb8fc,
|
||||
0xed545578, 0x08fca5b5, 0xd83d7cd3, 0x4dad0fc4, 0x1e50ef5e, 0xb161e6f8, 0xa28514d9, 0x6c51133c,
|
||||
0x6fd5c7e7, 0x56e14ec4, 0x362abfce, 0xddc6c837, 0xd79a3234, 0x92638212, 0x670efa8e, 0x406000e0
|
||||
],
|
||||
s3:[
|
||||
0x3a39ce37, 0xd3faf5cf, 0xabc27737, 0x5ac52d1b, 0x5cb0679e, 0x4fa33742, 0xd3822740, 0x99bc9bbe,
|
||||
0xd5118e9d, 0xbf0f7315, 0xd62d1c7e, 0xc700c47b, 0xb78c1b6b, 0x21a19045, 0xb26eb1be, 0x6a366eb4,
|
||||
0x5748ab2f, 0xbc946e79, 0xc6a376d2, 0x6549c2c8, 0x530ff8ee, 0x468dde7d, 0xd5730a1d, 0x4cd04dc6,
|
||||
0x2939bbdb, 0xa9ba4650, 0xac9526e8, 0xbe5ee304, 0xa1fad5f0, 0x6a2d519a, 0x63ef8ce2, 0x9a86ee22,
|
||||
0xc089c2b8, 0x43242ef6, 0xa51e03aa, 0x9cf2d0a4, 0x83c061ba, 0x9be96a4d, 0x8fe51550, 0xba645bd6,
|
||||
0x2826a2f9, 0xa73a3ae1, 0x4ba99586, 0xef5562e9, 0xc72fefd3, 0xf752f7da, 0x3f046f69, 0x77fa0a59,
|
||||
0x80e4a915, 0x87b08601, 0x9b09e6ad, 0x3b3ee593, 0xe990fd5a, 0x9e34d797, 0x2cf0b7d9, 0x022b8b51,
|
||||
0x96d5ac3a, 0x017da67d, 0xd1cf3ed6, 0x7c7d2d28, 0x1f9f25cf, 0xadf2b89b, 0x5ad6b472, 0x5a88f54c,
|
||||
0xe029ac71, 0xe019a5e6, 0x47b0acfd, 0xed93fa9b, 0xe8d3c48d, 0x283b57cc, 0xf8d56629, 0x79132e28,
|
||||
0x785f0191, 0xed756055, 0xf7960e44, 0xe3d35e8c, 0x15056dd4, 0x88f46dba, 0x03a16125, 0x0564f0bd,
|
||||
0xc3eb9e15, 0x3c9057a2, 0x97271aec, 0xa93a072a, 0x1b3f6d9b, 0x1e6321f5, 0xf59c66fb, 0x26dcf319,
|
||||
0x7533d928, 0xb155fdf5, 0x03563482, 0x8aba3cbb, 0x28517711, 0xc20ad9f8, 0xabcc5167, 0xccad925f,
|
||||
0x4de81751, 0x3830dc8e, 0x379d5862, 0x9320f991, 0xea7a90c2, 0xfb3e7bce, 0x5121ce64, 0x774fbe32,
|
||||
0xa8b6e37e, 0xc3293d46, 0x48de5369, 0x6413e680, 0xa2ae0810, 0xdd6db224, 0x69852dfd, 0x09072166,
|
||||
0xb39a460a, 0x6445c0dd, 0x586cdecf, 0x1c20c8ae, 0x5bbef7dd, 0x1b588d40, 0xccd2017f, 0x6bb4e3bb,
|
||||
0xdda26a7e, 0x3a59ff45, 0x3e350a44, 0xbcb4cdd5, 0x72eacea8, 0xfa6484bb, 0x8d6612ae, 0xbf3c6f47,
|
||||
0xd29be463, 0x542f5d9e, 0xaec2771b, 0xf64e6370, 0x740e0d8d, 0xe75b1357, 0xf8721671, 0xaf537d5d,
|
||||
0x4040cb08, 0x4eb4e2cc, 0x34d2466a, 0x0115af84, 0xe1b00428, 0x95983a1d, 0x06b89fb4, 0xce6ea048,
|
||||
0x6f3f3b82, 0x3520ab82, 0x011a1d4b, 0x277227f8, 0x611560b1, 0xe7933fdc, 0xbb3a792b, 0x344525bd,
|
||||
0xa08839e1, 0x51ce794b, 0x2f32c9b7, 0xa01fbac9, 0xe01cc87e, 0xbcc7d1f6, 0xcf0111c3, 0xa1e8aac7,
|
||||
0x1a908749, 0xd44fbd9a, 0xd0dadecb, 0xd50ada38, 0x0339c32a, 0xc6913667, 0x8df9317c, 0xe0b12b4f,
|
||||
0xf79e59b7, 0x43f5bb3a, 0xf2d519ff, 0x27d9459c, 0xbf97222c, 0x15e6fc2a, 0x0f91fc71, 0x9b941525,
|
||||
0xfae59361, 0xceb69ceb, 0xc2a86459, 0x12baa8d1, 0xb6c1075e, 0xe3056a0c, 0x10d25065, 0xcb03a442,
|
||||
0xe0ec6e0e, 0x1698db3b, 0x4c98a0be, 0x3278e964, 0x9f1f9532, 0xe0d392df, 0xd3a0342b, 0x8971f21e,
|
||||
0x1b0a7441, 0x4ba3348c, 0xc5be7120, 0xc37632d8, 0xdf359f8d, 0x9b992f2e, 0xe60b6f47, 0x0fe3f11d,
|
||||
0xe54cda54, 0x1edad891, 0xce6279cf, 0xcd3e7e6f, 0x1618b166, 0xfd2c1d05, 0x848fd2c5, 0xf6fb2299,
|
||||
0xf523f357, 0xa6327623, 0x93a83531, 0x56cccd02, 0xacf08162, 0x5a75ebb5, 0x6e163697, 0x88d273cc,
|
||||
0xde966292, 0x81b949d0, 0x4c50901b, 0x71c65614, 0xe6c6c7bd, 0x327a140a, 0x45e1d006, 0xc3f27b9a,
|
||||
0xc9aa53fd, 0x62a80f00, 0xbb25bfe2, 0x35bdd2f6, 0x71126905, 0xb2040222, 0xb6cbcf7c, 0xcd769c2b,
|
||||
0x53113ec0, 0x1640e3d3, 0x38abbd60, 0x2547adf0, 0xba38209c, 0xf746ce76, 0x77afa1c5, 0x20756060,
|
||||
0x85cbfe4e, 0x8ae88dd8, 0x7aaaf9b0, 0x4cf9aa7e, 0x1948c25c, 0x02fb8a8c, 0x01c36ae4, 0xd6ebe1f9,
|
||||
0x90d4f869, 0xa65cdea0, 0x3f09252d, 0xc208e69f, 0xb74e6132, 0xce77e25b, 0x578fdfe3, 0x3ac372e6
|
||||
]
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// fixes based on patch submitted by Peter Wood (#5791)
|
||||
function add(x,y){
|
||||
return (((x>>0x10)+(y>>0x10)+(((x&0xffff)+(y&0xffff))>>0x10))<<0x10)|(((x&0xffff)+(y&0xffff))&0xffff);
|
||||
}
|
||||
function xor(x,y){
|
||||
return (((x>>0x10)^(y>>0x10))<<0x10)|(((x&0xffff)^(y&0xffff))&0xffff);
|
||||
}
|
||||
|
||||
function $(v, box){
|
||||
var d=box.s3[v&0xff]; v>>=8;
|
||||
var c=box.s2[v&0xff]; v>>=8;
|
||||
var b=box.s1[v&0xff]; v>>=8;
|
||||
var a=box.s0[v&0xff];
|
||||
|
||||
var r = (((a>>0x10)+(b>>0x10)+(((a&0xffff)+(b&0xffff))>>0x10))<<0x10)|(((a&0xffff)+(b&0xffff))&0xffff);
|
||||
r = (((r>>0x10)^(c>>0x10))<<0x10)|(((r&0xffff)^(c&0xffff))&0xffff);
|
||||
return (((r>>0x10)+(d>>0x10)+(((r&0xffff)+(d&0xffff))>>0x10))<<0x10)|(((r&0xffff)+(d&0xffff))&0xffff);
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
function eb(o, box){
|
||||
// TODO: see if this can't be made more efficient
|
||||
var l=o.left;
|
||||
var r=o.right;
|
||||
l=xor(l,box.p[0]);
|
||||
r=xor(r,xor($(l,box),box.p[1]));
|
||||
l=xor(l,xor($(r,box),box.p[2]));
|
||||
r=xor(r,xor($(l,box),box.p[3]));
|
||||
l=xor(l,xor($(r,box),box.p[4]));
|
||||
r=xor(r,xor($(l,box),box.p[5]));
|
||||
l=xor(l,xor($(r,box),box.p[6]));
|
||||
r=xor(r,xor($(l,box),box.p[7]));
|
||||
l=xor(l,xor($(r,box),box.p[8]));
|
||||
r=xor(r,xor($(l,box),box.p[9]));
|
||||
l=xor(l,xor($(r,box),box.p[10]));
|
||||
r=xor(r,xor($(l,box),box.p[11]));
|
||||
l=xor(l,xor($(r,box),box.p[12]));
|
||||
r=xor(r,xor($(l,box),box.p[13]));
|
||||
l=xor(l,xor($(r,box),box.p[14]));
|
||||
r=xor(r,xor($(l,box),box.p[15]));
|
||||
l=xor(l,xor($(r,box),box.p[16]));
|
||||
o.right=l;
|
||||
o.left=xor(r,box.p[17]);
|
||||
}
|
||||
|
||||
function db(o, box){
|
||||
var l=o.left;
|
||||
var r=o.right;
|
||||
l=xor(l,box.p[17]);
|
||||
r=xor(r,xor($(l,box),box.p[16]));
|
||||
l=xor(l,xor($(r,box),box.p[15]));
|
||||
r=xor(r,xor($(l,box),box.p[14]));
|
||||
l=xor(l,xor($(r,box),box.p[13]));
|
||||
r=xor(r,xor($(l,box),box.p[12]));
|
||||
l=xor(l,xor($(r,box),box.p[11]));
|
||||
r=xor(r,xor($(l,box),box.p[10]));
|
||||
l=xor(l,xor($(r,box),box.p[9]));
|
||||
r=xor(r,xor($(l,box),box.p[8]));
|
||||
l=xor(l,xor($(r,box),box.p[7]));
|
||||
r=xor(r,xor($(l,box),box.p[6]));
|
||||
l=xor(l,xor($(r,box),box.p[5]));
|
||||
r=xor(r,xor($(l,box),box.p[4]));
|
||||
l=xor(l,xor($(r,box),box.p[3]));
|
||||
r=xor(r,xor($(l,box),box.p[2]));
|
||||
l=xor(l,xor($(r,box),box.p[1]));
|
||||
o.right=l;
|
||||
o.left=xor(r,box.p[0]);
|
||||
}
|
||||
|
||||
// Note that we aren't caching contexts here; it might take a little longer
|
||||
// but we should be more secure this way.
|
||||
function init(key){
|
||||
var k=key;
|
||||
if(lang.isString(k)){
|
||||
k = arrayUtil.map(k.split(""), function(item){
|
||||
return item.charCodeAt(0) & 0xff;
|
||||
});
|
||||
}
|
||||
|
||||
// init the boxes
|
||||
var pos=0, data=0, res={ left:0, right:0 }, i, j, l;
|
||||
var box = {
|
||||
p: arrayUtil.map(boxes.p.slice(0), function(item){
|
||||
var l=k.length, j;
|
||||
for(j=0; j<4; j++){ data=(data*POW8)|k[pos++ % l]; }
|
||||
return (((item>>0x10)^(data>>0x10))<<0x10)|(((item&0xffff)^(data&0xffff))&0xffff);
|
||||
}),
|
||||
s0:boxes.s0.slice(0),
|
||||
s1:boxes.s1.slice(0),
|
||||
s2:boxes.s2.slice(0),
|
||||
s3:boxes.s3.slice(0)
|
||||
};
|
||||
|
||||
// encrypt p and the s boxes
|
||||
for(i=0, l=box.p.length; i<l;){
|
||||
eb(res, box);
|
||||
box.p[i++]=res.left, box.p[i++]=res.right;
|
||||
}
|
||||
for(i=0; i<4; i++){
|
||||
for(j=0, l=box["s"+i].length; j<l;){
|
||||
eb(res, box);
|
||||
box["s"+i][j++]=res.left, box["s"+i][j++]=res.right;
|
||||
}
|
||||
}
|
||||
return box;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// PUBLIC FUNCTIONS
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
this.getIV=function(/* dojox.encoding.crypto.outputTypes? */ outputType){
|
||||
// summary:
|
||||
// returns the initialization vector in the output format specified by outputType
|
||||
var out=outputType||crypto.outputTypes.Base64;
|
||||
switch(out){
|
||||
case crypto.outputTypes.Hex:{
|
||||
return arrayUtil.map(iv, function(item){
|
||||
return (item<=0xf?'0':'')+item.toString(16);
|
||||
}).join(""); // string
|
||||
}
|
||||
case crypto.outputTypes.String:{
|
||||
return iv.join(""); // string
|
||||
}
|
||||
case crypto.outputTypes.Raw:{
|
||||
return iv; // array
|
||||
}
|
||||
default:{
|
||||
return base64.encode(iv); // string
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
this.setIV=function(/* string */data, /* dojox.encoding.crypto.outputTypes? */inputType){
|
||||
// summary:
|
||||
// sets the initialization vector to data (as interpreted as inputType)
|
||||
var ip=inputType||crypto.outputTypes.Base64;
|
||||
var ba=null;
|
||||
switch(ip){
|
||||
case crypto.outputTypes.String:{
|
||||
ba = arrayUtil.map(data.split(""), function(item){
|
||||
return item.charCodeAt(0);
|
||||
});
|
||||
break;
|
||||
}
|
||||
case crypto.outputTypes.Hex:{
|
||||
ba=[];
|
||||
for(var i=0, l=data.length-1; i<l; i+=2){
|
||||
ba.push(parseInt(data.substr(i,2), 16));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case crypto.outputTypes.Raw:{
|
||||
ba=data;
|
||||
break;
|
||||
}
|
||||
default:{
|
||||
ba=base64.decode(data);
|
||||
break;
|
||||
}
|
||||
}
|
||||
// make it a pair of words now
|
||||
iv={};
|
||||
iv.left=ba[0]*POW24|ba[1]*POW16|ba[2]*POW8|ba[3];
|
||||
iv.right=ba[4]*POW24|ba[5]*POW16|ba[6]*POW8|ba[7];
|
||||
};
|
||||
|
||||
this.encrypt = function(/* string */plaintext, /* string */key, /* object? */ao){
|
||||
// summary:
|
||||
// encrypts plaintext using key; allows user to specify output type and cipher mode via keyword object "ao"
|
||||
var out=crypto.outputTypes.Base64;
|
||||
var mode=crypto.cipherModes.ECB;
|
||||
if (ao){
|
||||
if (ao.outputType) out=ao.outputType;
|
||||
if (ao.cipherMode) mode=ao.cipherMode;
|
||||
}
|
||||
|
||||
var bx = init(key), padding = 8-(plaintext.length&7);
|
||||
for (var i=0; i<padding; i++){ plaintext+=String.fromCharCode(padding); }
|
||||
|
||||
var cipher=[], count=plaintext.length >> 3, pos=0, o={}, isCBC=(mode==crypto.cipherModes.CBC);
|
||||
var vector={left:iv.left||null, right:iv.right||null};
|
||||
for(var i=0; i<count; i++){
|
||||
o.left=plaintext.charCodeAt(pos)*POW24
|
||||
|plaintext.charCodeAt(pos+1)*POW16
|
||||
|plaintext.charCodeAt(pos+2)*POW8
|
||||
|plaintext.charCodeAt(pos+3);
|
||||
o.right=plaintext.charCodeAt(pos+4)*POW24
|
||||
|plaintext.charCodeAt(pos+5)*POW16
|
||||
|plaintext.charCodeAt(pos+6)*POW8
|
||||
|plaintext.charCodeAt(pos+7);
|
||||
|
||||
if(isCBC){
|
||||
o.left=(((o.left>>0x10)^(vector.left>>0x10))<<0x10)|(((o.left&0xffff)^(vector.left&0xffff))&0xffff);
|
||||
o.right=(((o.right>>0x10)^(vector.right>>0x10))<<0x10)|(((o.right&0xffff)^(vector.right&0xffff))&0xffff);
|
||||
}
|
||||
|
||||
eb(o, bx); // encrypt the block
|
||||
|
||||
if(isCBC){
|
||||
vector.left=o.left;
|
||||
vector.right=o.right;
|
||||
}
|
||||
|
||||
cipher.push((o.left>>24)&0xff);
|
||||
cipher.push((o.left>>16)&0xff);
|
||||
cipher.push((o.left>>8)&0xff);
|
||||
cipher.push(o.left&0xff);
|
||||
cipher.push((o.right>>24)&0xff);
|
||||
cipher.push((o.right>>16)&0xff);
|
||||
cipher.push((o.right>>8)&0xff);
|
||||
cipher.push(o.right&0xff);
|
||||
pos+=8;
|
||||
}
|
||||
|
||||
switch(out){
|
||||
case crypto.outputTypes.Hex:{
|
||||
return arrayUtil.map(cipher, function(item){
|
||||
return (item<=0xf?'0':'')+item.toString(16);
|
||||
}).join(""); // string
|
||||
}
|
||||
case crypto.outputTypes.String:{
|
||||
return cipher.join(""); // string
|
||||
}
|
||||
case crypto.outputTypes.Raw:{
|
||||
return cipher; // array
|
||||
}
|
||||
default:{
|
||||
return base64.encode(cipher); // string
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
this.decrypt = function(/* string */ciphertext, /* string */key, /* object? */ao){
|
||||
// summary:
|
||||
// decrypts ciphertext using key; allows specification of how ciphertext is encoded via ao.
|
||||
var ip=crypto.outputTypes.Base64;
|
||||
var mode=crypto.cipherModes.ECB;
|
||||
if (ao){
|
||||
if (ao.outputType) ip=ao.outputType;
|
||||
if (ao.cipherMode) mode=ao.cipherMode;
|
||||
}
|
||||
var bx = init(key);
|
||||
var pt=[];
|
||||
|
||||
var c=null;
|
||||
switch(ip){
|
||||
case crypto.outputTypes.Hex:{
|
||||
c = [];
|
||||
for(var i=0, l=ciphertext.length-1; i<l; i+=2){
|
||||
c.push(parseInt(ciphertext.substr(i,2), 16));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case crypto.outputTypes.String:{
|
||||
c = arrayUtil.map(ciphertext.split(""), function(item){
|
||||
return item.charCodeAt(0);
|
||||
});
|
||||
break;
|
||||
}
|
||||
case crypto.outputTypes.Raw:{
|
||||
c=ciphertext; // should be a byte array
|
||||
break;
|
||||
}
|
||||
default:{
|
||||
c=base64.decode(ciphertext);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
var count=c.length >> 3, pos=0, o={}, isCBC=(mode==crypto.cipherModes.CBC);
|
||||
var vector={left:iv.left||null, right:iv.right||null};
|
||||
for(var i=0; i<count; i++){
|
||||
o.left=c[pos]*POW24|c[pos+1]*POW16|c[pos+2]*POW8|c[pos+3];
|
||||
o.right=c[pos+4]*POW24|c[pos+5]*POW16|c[pos+6]*POW8|c[pos+7];
|
||||
|
||||
if(isCBC){
|
||||
var left=o.left;
|
||||
var right=o.right;
|
||||
}
|
||||
|
||||
db(o, bx); // decrypt the block
|
||||
|
||||
if(isCBC){
|
||||
o.left=(((o.left>>0x10)^(vector.left>>0x10))<<0x10)|(((o.left&0xffff)^(vector.left&0xffff))&0xffff);
|
||||
o.right=(((o.right>>0x10)^(vector.right>>0x10))<<0x10)|(((o.right&0xffff)^(vector.right&0xffff))&0xffff);
|
||||
vector.left=left;
|
||||
vector.right=right;
|
||||
}
|
||||
|
||||
pt.push((o.left>>24)&0xff);
|
||||
pt.push((o.left>>16)&0xff);
|
||||
pt.push((o.left>>8)&0xff);
|
||||
pt.push(o.left&0xff);
|
||||
pt.push((o.right>>24)&0xff);
|
||||
pt.push((o.right>>16)&0xff);
|
||||
pt.push((o.right>>8)&0xff);
|
||||
pt.push(o.right&0xff);
|
||||
pos+=8;
|
||||
}
|
||||
|
||||
// check for padding, and remove.
|
||||
if(pt[pt.length-1]==pt[pt.length-2]||pt[pt.length-1]==0x01){
|
||||
var n=pt[pt.length-1];
|
||||
pt.splice(pt.length-n, n);
|
||||
}
|
||||
|
||||
// convert to string
|
||||
return arrayUtil.map(pt, function(item){
|
||||
return String.fromCharCode(item);
|
||||
}).join(""); // string
|
||||
};
|
||||
|
||||
this.setIV("0000000000000000", crypto.outputTypes.Hex);
|
||||
}();
|
||||
|
||||
|
||||
|
||||
if (typeof exports != 'undefined') {
|
||||
exports.blowfish = crypto.Blowfish;
|
||||
} else {
|
||||
global.blowfish = crypto.Blowfish;
|
||||
}
|
||||
|
||||
}(this));
|
@ -28,7 +28,7 @@
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
var bzip2 = {};
|
||||
var bzip2 = module.exports = {};
|
||||
|
||||
bzip2.array = function(bytes){
|
||||
var bit = 0, byte = 0;
|
||||
|
@ -1,768 +0,0 @@
|
||||
/** @license
|
||||
========================================================================
|
||||
Crypto API for JavaScript - https://github.com/nf404/crypto-api
|
||||
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015 nf404
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
/*global module, require */
|
||||
(/**
|
||||
* @param {Object} root
|
||||
* @returns {CryptoApi}
|
||||
*/
|
||||
function (root) {
|
||||
'use strict';
|
||||
/**
|
||||
* @class CryptoApi
|
||||
* @classdesc Main class
|
||||
* @public
|
||||
*/
|
||||
var CryptoApi = function cryptoApi () {
|
||||
/**
|
||||
* @property Hashers
|
||||
* @type {Hashers}
|
||||
*/
|
||||
this.Hashers = new Hashers();
|
||||
/**
|
||||
* @property Encodes
|
||||
* @type {Encodes}
|
||||
*/
|
||||
this.Encodes = new Encodes();
|
||||
/**
|
||||
* @property Macs
|
||||
* @type {Macs}
|
||||
*/
|
||||
this.Macs = new Macs();
|
||||
/**
|
||||
* @property Tools
|
||||
* @type {Tools}
|
||||
*/
|
||||
this.Tools = new Tools();
|
||||
};
|
||||
|
||||
/**
|
||||
* @interface HasherInterface
|
||||
* @classdesc All hashers MUST implement this interface
|
||||
* @public
|
||||
*/
|
||||
var HasherInterface = function () {};
|
||||
/**
|
||||
* @memberOf HasherInterface
|
||||
* @constructor
|
||||
*/
|
||||
HasherInterface.prototype.constructor = function constructor() {};
|
||||
/**
|
||||
* @desc Process ready block
|
||||
* @memberOf HasherInterface
|
||||
* @method processBlock
|
||||
* @param {number[]} block
|
||||
*/
|
||||
HasherInterface.prototype.processBlock = function processBlock(block) {};
|
||||
/**
|
||||
* Update message
|
||||
* @memberOf HasherInterface
|
||||
* @method update
|
||||
* @param {string} message
|
||||
*/
|
||||
HasherInterface.prototype.update = function update(message) {};
|
||||
/**
|
||||
* @desc Process last block and return hash
|
||||
* @memberOf HasherInterface
|
||||
* @method finalize
|
||||
* @return {HashArray} hash
|
||||
*/
|
||||
HasherInterface.prototype.finalize = function finalize() {};
|
||||
|
||||
/**
|
||||
* @class BaseHasher
|
||||
* @param {string} name
|
||||
* @param {Object} options
|
||||
* @public
|
||||
*/
|
||||
var BaseHasher = function(name, options) {};
|
||||
BaseHasher.prototype.constructor = function (name, options) {
|
||||
/**
|
||||
* @desc Hasher name
|
||||
* @property name
|
||||
* @type {string}
|
||||
*/
|
||||
this.name = name;
|
||||
/**
|
||||
* @desc All algorithm variables that changed during process
|
||||
* @property state
|
||||
* @type {Object}
|
||||
*/
|
||||
this.state = {};
|
||||
/**
|
||||
* @desc Unprocessed Message
|
||||
* @memberof! BaseHasher#
|
||||
* @alias state.message
|
||||
* @type {number[]}
|
||||
*/
|
||||
this.state.message = [];
|
||||
/**
|
||||
* @desc Length of message
|
||||
* @memberof! BaseHasher#
|
||||
* @alias state.length
|
||||
* @type {number}
|
||||
*/
|
||||
this.state.length = 0;
|
||||
/**
|
||||
* @memberof! BaseHasher#
|
||||
* @alias state.options
|
||||
* @type {Object}
|
||||
*/
|
||||
this.state.options = options;
|
||||
this.blockUnits = [];
|
||||
};
|
||||
|
||||
/**
|
||||
* Size of unit in bytes (4 = 32 bits)
|
||||
* @memberOf BaseHasher
|
||||
* @member {number} unitSize
|
||||
* @static
|
||||
*/
|
||||
BaseHasher.prototype.unitSize = 4;
|
||||
/**
|
||||
* Bytes order in unit
|
||||
* 0 - normal
|
||||
* 1 - reverse
|
||||
* @memberOf BaseHasher
|
||||
* @member {number} unitOrder
|
||||
* @static
|
||||
*/
|
||||
BaseHasher.prototype.unitOrder = 0;
|
||||
/**
|
||||
* Size of block in units
|
||||
* @memberOf BaseHasher
|
||||
* @member {number} blockSize
|
||||
* @static
|
||||
*/
|
||||
BaseHasher.prototype.blockSize = 16;
|
||||
/**
|
||||
* Return current state
|
||||
* @memberOf BaseHasher
|
||||
* @method getState
|
||||
* @returns {Object}
|
||||
*/
|
||||
BaseHasher.prototype.getState = function getState() {
|
||||
return JSON.parse(JSON.stringify(this.state));
|
||||
};
|
||||
/**
|
||||
* Set state
|
||||
* @memberOf BaseHasher
|
||||
* @method setState
|
||||
* @param {Object} state
|
||||
* @return {HasherInterface}
|
||||
*/
|
||||
BaseHasher.prototype.setState = function setState(state) {
|
||||
this.state = state;
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Update message
|
||||
* @memberOf BaseHasher
|
||||
* @method update
|
||||
* @param {string} message
|
||||
*/
|
||||
BaseHasher.prototype.update = function update(message) {
|
||||
var l = 0;
|
||||
for (var i = 0, msgLen = message.length; i < msgLen; i++) {
|
||||
var charcode = message.charCodeAt(i);
|
||||
if (charcode < 0x80) {
|
||||
this.state.message.push(charcode);
|
||||
l += 1;
|
||||
}
|
||||
else if (charcode < 0x800) {
|
||||
this.state.message.push(0xc0 | (charcode >> 6),
|
||||
0x80 | (charcode & 0x3f));
|
||||
l += 2;
|
||||
}
|
||||
else if (charcode < 0xd800 || charcode >= 0xe000) {
|
||||
this.state.message.push(0xe0 | (charcode >> 12),
|
||||
0x80 | ((charcode >> 6) & 0x3f),
|
||||
0x80 | (charcode & 0x3f));
|
||||
l += 3;
|
||||
}
|
||||
// surrogate pair
|
||||
else {
|
||||
i++;
|
||||
// UTF-16 encodes 0x10000-0x10FFFF by
|
||||
// subtracting 0x10000 and splitting the
|
||||
// 20 bits of 0x0-0xFFFFF into two halves
|
||||
charcode = 0x10000 + (((charcode & 0x3ff) << 10)
|
||||
| (message.charCodeAt(i) & 0x3ff));
|
||||
this.state.message.push(0xf0 | (charcode >> 18),
|
||||
0x80 | ((charcode >> 12) & 0x3f),
|
||||
0x80 | ((charcode >> 6) & 0x3f),
|
||||
0x80 | (charcode & 0x3f));
|
||||
l += 4;
|
||||
}
|
||||
}
|
||||
this.state.length += l;
|
||||
|
||||
this.process();
|
||||
};
|
||||
|
||||
/**
|
||||
* Update message from array
|
||||
* @memberOf BaseHasher
|
||||
* @method updateFromArray
|
||||
* @param {number[]} message
|
||||
* @return {BaseHasher}
|
||||
*/
|
||||
BaseHasher.prototype.updateFromArray = function updateFromArray(message) {
|
||||
this.state.length += message.length;
|
||||
this.state.message = this.state.message.concat(message);
|
||||
this.process();
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Process ready blocks
|
||||
* @memberOf BaseHasher
|
||||
* @method process
|
||||
*/
|
||||
BaseHasher.prototype.process = function process() {
|
||||
while (this.state.message.length >= this.blockSize * this.unitSize) {
|
||||
var j = 0, b = 0, block = this.state.message.splice(0, this.blockSize * this.unitSize);
|
||||
if (this.unitSize > 1) {
|
||||
this.blockUnits = [];
|
||||
for (var i = 0, u = 0; i < block.length; i += this.unitSize, u++) {
|
||||
if (this.unitOrder === 1) {
|
||||
for (j = this.unitSize - 1, b = 0; j >= 0; j--, b += 8) {
|
||||
this.blockUnits[u] |= (block[i + j] << b);
|
||||
}
|
||||
} else {
|
||||
for (j = 0, b = 0; j < this.unitSize; j++, b += 8) {
|
||||
this.blockUnits[u] |= (block[i + j] << b);
|
||||
}
|
||||
}
|
||||
}
|
||||
this.processBlock(this.blockUnits);
|
||||
} else {
|
||||
this.processBlock(block);
|
||||
}
|
||||
}
|
||||
};
|
||||
/**
|
||||
* @memberOf CryptoApi
|
||||
* @member {BaseHasher} BaseHasher
|
||||
*/
|
||||
CryptoApi.prototype.BaseHasher = BaseHasher;
|
||||
|
||||
/**
|
||||
* @class Hasher8
|
||||
* @desc Hasher for 32 bit little endian blocks
|
||||
* @extends BaseHasher
|
||||
* @param {string} name
|
||||
* @param {Object} options
|
||||
* @public
|
||||
*/
|
||||
var Hasher8 = function (name, options) {
|
||||
this.constructor(name, options);
|
||||
};
|
||||
Hasher8.prototype = Object.create(BaseHasher.prototype);
|
||||
|
||||
/**
|
||||
* @desc Normal order of bytes
|
||||
* @memberOf Hasher8#
|
||||
* @member {number} unitOrder
|
||||
*/
|
||||
Hasher8.prototype.unitOrder = 0;
|
||||
/**
|
||||
* @desc Size of unit = 1 byte
|
||||
* @memberOf Hasher8#
|
||||
* @member {number} unitSize
|
||||
*/
|
||||
Hasher8.prototype.unitSize = 1;
|
||||
|
||||
/**
|
||||
* @memberOf Hasher8
|
||||
* @constructor
|
||||
* @param {string} name
|
||||
* @param {Object} options
|
||||
*/
|
||||
Hasher8.prototype.constructor = function (name, options) {
|
||||
BaseHasher.prototype.constructor.call(this, name, options);
|
||||
};
|
||||
/**
|
||||
* Process ready blocks
|
||||
* @memberOf Hasher8
|
||||
* @method process
|
||||
*/
|
||||
Hasher8.prototype.process = function process() {
|
||||
while (this.state.message.length >= this.blockSize * this.unitSize) {
|
||||
var block = this.state.message.splice(0, this.blockSize * this.unitSize);
|
||||
this.blockUnits = [];
|
||||
for (var i = 0; i < this.blockSize; i++) {
|
||||
this.blockUnits[i] = (block[i]);
|
||||
}
|
||||
this.processBlock(this.blockUnits);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @memberOf CryptoApi
|
||||
* @member {Hasher8} Hasher8
|
||||
*/
|
||||
CryptoApi.prototype.Hasher8 = Hasher8;
|
||||
|
||||
/**
|
||||
* @class Hasher32le
|
||||
* @desc Hasher for 32 bit little endian blocks
|
||||
* @extends BaseHasher
|
||||
* @param {string} name
|
||||
* @param {Object} options
|
||||
* @public
|
||||
*/
|
||||
var Hasher32le = function (name, options) {
|
||||
this.constructor(name, options);
|
||||
};
|
||||
Hasher32le.prototype = Object.create(BaseHasher.prototype);
|
||||
|
||||
Hasher32le.prototype.unitOrder = 0; // Normal order of bytes
|
||||
|
||||
/**
|
||||
* @memberOf Hasher32le
|
||||
* @constructor
|
||||
* @param {string} name
|
||||
* @param {Object} options
|
||||
*/
|
||||
Hasher32le.prototype.constructor = function (name, options) {
|
||||
BaseHasher.prototype.constructor.call(this, name, options);
|
||||
};
|
||||
/**
|
||||
* Process ready blocks
|
||||
* @memberOf Hasher32le
|
||||
* @method process
|
||||
*/
|
||||
Hasher32le.prototype.process = function process() {
|
||||
while (this.state.message.length >= this.blockSize * this.unitSize) {
|
||||
var block = this.state.message.splice(0, this.blockSize * this.unitSize);
|
||||
this.blockUnits = [];
|
||||
for (var i = 0, b = 0; i < this.blockSize; i++, b+=4) {
|
||||
this.blockUnits[i] = (block[b]);
|
||||
this.blockUnits[i] |= (block[b + 1] << 8);
|
||||
this.blockUnits[i] |= (block[b + 2] << 16);
|
||||
this.blockUnits[i] |= (block[b + 3] << 24);
|
||||
}
|
||||
this.processBlock(this.blockUnits);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @memberOf CryptoApi
|
||||
* @member {Hasher32le} Hasher32
|
||||
*/
|
||||
CryptoApi.prototype.Hasher32le = Hasher32le;
|
||||
|
||||
/**
|
||||
* @class Hasher32be
|
||||
* @desc Hasher for 32 bit big endian blocks
|
||||
* @extends BaseHasher
|
||||
* @param {string} name
|
||||
* @param {Object} options
|
||||
* @public
|
||||
*/
|
||||
var Hasher32be = function (name, options) {
|
||||
this.constructor(name, options);
|
||||
};
|
||||
Hasher32be.prototype = Object.create(BaseHasher.prototype);
|
||||
|
||||
Hasher32be.prototype.unitOrder = 1; // Reverse order of bytes
|
||||
|
||||
/**
|
||||
* @memberOf Hasher32be
|
||||
* @constructor
|
||||
* @param {string} name
|
||||
* @param {Object} options
|
||||
*/
|
||||
Hasher32be.prototype.constructor = function (name, options) {
|
||||
BaseHasher.prototype.constructor.call(this, name, options);
|
||||
};
|
||||
/**
|
||||
* Process ready blocks
|
||||
* @memberOf Hasher32be
|
||||
* @method process
|
||||
*/
|
||||
Hasher32be.prototype.process = function process() {
|
||||
while (this.state.message.length >= this.blockSize * this.unitSize) {
|
||||
var block = this.state.message.splice(0, this.blockSize * this.unitSize);
|
||||
this.blockUnits = [];
|
||||
for (var i = 0, b = 0; i < this.blockSize; i++, b+=4) {
|
||||
this.blockUnits[i] = (block[b] << 24);
|
||||
this.blockUnits[i] |= (block[b + 1] << 16);
|
||||
this.blockUnits[i] |= (block[b + 2] << 8);
|
||||
this.blockUnits[i] |= (block[b + 3]);
|
||||
}
|
||||
this.processBlock(this.blockUnits);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @memberOf CryptoApi
|
||||
* @member {Hasher32be} Hasher32be
|
||||
*/
|
||||
CryptoApi.prototype.Hasher32be = Hasher32be;
|
||||
|
||||
/**
|
||||
* @interface MacInterface
|
||||
* @classdesc All coders MUST implement this interface
|
||||
* @public
|
||||
*/
|
||||
var MacInterface = function () {};
|
||||
/**
|
||||
* @memberOf MacInterface
|
||||
* @param {string|number[]} key
|
||||
* @param {string} hasher
|
||||
* @param {Object} options
|
||||
* @constructor
|
||||
*/
|
||||
MacInterface.prototype.constructor = function constructor(key, hasher, options) {};
|
||||
/**
|
||||
* @desc Process ready block
|
||||
* @memberOf MacInterface
|
||||
* @method processBlock
|
||||
* @param {number[]} block
|
||||
*/
|
||||
MacInterface.prototype.processBlock = function processBlock(block) {};
|
||||
/**
|
||||
* Update message
|
||||
* @memberOf MacInterface
|
||||
* @method update
|
||||
* @param {string|number[]} message
|
||||
* @return {MacInterface}
|
||||
*/
|
||||
MacInterface.prototype.update = function update(message) {};
|
||||
/**
|
||||
* @desc Process last block and return hash
|
||||
* @memberOf MacInterface
|
||||
* @method finalize
|
||||
* @return {HashArray} hash
|
||||
*/
|
||||
MacInterface.prototype.finalize = function finalize() {};
|
||||
|
||||
/**
|
||||
* @class BaseMac
|
||||
* @extends BaseHasher
|
||||
* @param {string|number[]} key
|
||||
* @param {string} hasher
|
||||
* @param {Object} options
|
||||
* @public
|
||||
*/
|
||||
var BaseMac = function(key, hasher, options) {};
|
||||
BaseMac.prototype = Object.create(BaseHasher.prototype);
|
||||
BaseMac.prototype.constructor = function (key, hasher, options) {
|
||||
BaseHasher.prototype.constructor.call(this, hasher, options);
|
||||
};
|
||||
/**
|
||||
* @memberOf CryptoApi
|
||||
* @member {BaseMac} BaseMac
|
||||
*/
|
||||
CryptoApi.prototype.BaseMac = BaseMac;
|
||||
/**
|
||||
* @interface EncodeInterface
|
||||
* @classdesc All encodes MUST implement this interface
|
||||
* @public
|
||||
*/
|
||||
var EncodeInterface = function () {};
|
||||
/**
|
||||
* @memberOf EncodeInterface
|
||||
* @constructor
|
||||
* @param {HashArray} hash
|
||||
*/
|
||||
EncodeInterface.prototype.constructor = function constructor(hash) {};
|
||||
/**
|
||||
* @desc Stringify hash
|
||||
* @memberOf EncodeInterface
|
||||
* @method stringify
|
||||
* @returns {string}
|
||||
*/
|
||||
EncodeInterface.prototype.stringify = function encode() {};
|
||||
|
||||
|
||||
/**
|
||||
* @class BaseEncode
|
||||
* @desc Encode HashArray
|
||||
* @param {HashArray} hash
|
||||
* @public
|
||||
*/
|
||||
var BaseEncode = function (hash) {};
|
||||
/**
|
||||
* @memberOf BaseEncode
|
||||
* @constructor
|
||||
* @param {HashArray} hash
|
||||
*/
|
||||
BaseEncode.prototype.constructor = function constructor(hash) {
|
||||
/**
|
||||
* @property hash
|
||||
* @type {HashArray}
|
||||
*/
|
||||
this.hash = hash;
|
||||
};
|
||||
/**
|
||||
* @memberOf CryptoApi
|
||||
* @member {BaseEncode} BaseEncode
|
||||
*/
|
||||
CryptoApi.prototype.BaseEncode = BaseEncode;
|
||||
|
||||
/**
|
||||
* @class Hashers
|
||||
* @classdesc Collection of hashers
|
||||
*/
|
||||
var Hashers = function hashers() {
|
||||
/**
|
||||
* @property hashers
|
||||
* @type {Object}
|
||||
*/
|
||||
this.hashers = {};
|
||||
};
|
||||
/**
|
||||
* @memberOf Hashers
|
||||
* @method add
|
||||
* @param {string} name
|
||||
* @param {HasherInterface} hasher
|
||||
*/
|
||||
Hashers.prototype.add = function add(name, hasher) {
|
||||
if (hasher === undefined) {
|
||||
throw Error('Error adding hasher: ' + name);
|
||||
}
|
||||
this.hashers[name] = hasher;
|
||||
};
|
||||
/**
|
||||
* @memberOf Hashers
|
||||
* @method add
|
||||
* @param {string} name
|
||||
* @param {Object} options
|
||||
* @returns {HasherInterface}
|
||||
*/
|
||||
Hashers.prototype.get = function get(name, options) {
|
||||
var Hasher = this.hashers[name];
|
||||
if ((Hasher === undefined) && (typeof require !== 'undefined')) {
|
||||
var filename = name;
|
||||
if (filename === 'sha224') {
|
||||
filename = 'sha256';
|
||||
}
|
||||
require('./hasher.' + filename);
|
||||
Hasher = this.hashers[name];
|
||||
}
|
||||
if (Hasher === undefined) {
|
||||
throw Error('No hash algorithm: ' + name);
|
||||
}
|
||||
return new Hasher(name, options);
|
||||
};
|
||||
|
||||
/**
|
||||
* @class Encodes
|
||||
* @classdesc Collection of encodes
|
||||
*/
|
||||
var Encodes = function encodes() {
|
||||
/**
|
||||
* @property encodes
|
||||
* @type {Object}
|
||||
*/
|
||||
this.encodes = {};
|
||||
};
|
||||
/**
|
||||
* @memberOf Encodes
|
||||
* @method add
|
||||
* @param {string} name
|
||||
* @param {BaseEncode} encode
|
||||
*/
|
||||
Encodes.prototype.add = function add(name, encode) {
|
||||
if (encode === undefined) {
|
||||
throw Error('Error adding encode: ' + name);
|
||||
}
|
||||
this.encodes[name] = encode;
|
||||
};
|
||||
/**
|
||||
* @memberOf Encodes
|
||||
* @method get
|
||||
* @param {string} name
|
||||
* @param {HashArray} hash
|
||||
* @returns {BaseEncode}
|
||||
*/
|
||||
Encodes.prototype.get = function get(name, hash) {
|
||||
var Encode = this.encodes[name];
|
||||
if ((Encode === undefined) && (typeof require !== 'undefined')) {
|
||||
require('./enc.' + name);
|
||||
Encode = this.encodes[name];
|
||||
}
|
||||
if (Encode === undefined) {
|
||||
throw Error('No encode type: ' + name);
|
||||
}
|
||||
return new Encode(hash);
|
||||
};
|
||||
|
||||
/**
|
||||
* @class Macs
|
||||
* @classdesc Collection of macs
|
||||
*/
|
||||
var Macs = function macs() {
|
||||
/**
|
||||
* @property macs
|
||||
* @type {Object}
|
||||
*/
|
||||
this.macs = {};
|
||||
};
|
||||
/**
|
||||
* @memberOf Macs
|
||||
* @method add
|
||||
* @param {string} name
|
||||
* @param {BaseMac} mac
|
||||
*/
|
||||
Macs.prototype.add = function add(name, mac) {
|
||||
if (mac === undefined) {
|
||||
throw Error('Error adding mac: ' + name);
|
||||
}
|
||||
this.macs[name] = mac;
|
||||
};
|
||||
/**
|
||||
* @memberOf Macs
|
||||
* @method get
|
||||
* @param {string} name
|
||||
* @param {string|number[]} key
|
||||
* @param {string} hasher
|
||||
* @param {Object} options
|
||||
* @returns {MacInterface}
|
||||
*/
|
||||
Macs.prototype.get = function get(name, key, hasher, options) {
|
||||
var Mac = this.macs[name];
|
||||
if ((Mac === undefined) && (typeof require !== 'undefined')) {
|
||||
require('./mac.' + name);
|
||||
Mac = this.macs[name];
|
||||
}
|
||||
if (Mac === undefined) {
|
||||
throw Error('No mac type: ' + name);
|
||||
}
|
||||
return new Mac(key, hasher, options);
|
||||
};
|
||||
|
||||
/**
|
||||
* @class Tools
|
||||
* @classdesc Helper with some methods
|
||||
*/
|
||||
var Tools = function tools() {};
|
||||
/**
|
||||
* Rotate x to n bits left
|
||||
* @memberOf Tools
|
||||
* @method rotateLeft
|
||||
* @param {number} x
|
||||
* @param {number} n
|
||||
* @returns {number}
|
||||
*/
|
||||
Tools.prototype.rotateLeft = function rotateLeft(x, n) {
|
||||
return ((x << n) | (x >>> (32 - n))) | 0;
|
||||
};
|
||||
/**
|
||||
* Rotate x to n bits right
|
||||
* @memberOf Tools
|
||||
* @method rotateLeft
|
||||
* @param {number} x
|
||||
* @param {number} n
|
||||
* @returns {number}
|
||||
*/
|
||||
Tools.prototype.rotateRight = function rotateLeft(x, n) {
|
||||
return ((x >>> n) | (x << (32 - n))) | 0;
|
||||
};
|
||||
/**
|
||||
* @class HashArray
|
||||
* @classdesc Array of hash bytes
|
||||
* @instanceof {Array}
|
||||
* @param {number[]} hash
|
||||
* @param {Encodes} Encodes
|
||||
* @public
|
||||
*/
|
||||
var HashArray = function (hash, Encodes) {
|
||||
Array.prototype.push.apply(this, hash);
|
||||
/**
|
||||
* @property Encodes
|
||||
* @type {Encodes}
|
||||
*/
|
||||
this.Encodes = Encodes;
|
||||
};
|
||||
HashArray.prototype = Object.create(Array.prototype);
|
||||
HashArray.prototype.constructor = HashArray;
|
||||
|
||||
/**
|
||||
* Get hash as string
|
||||
* @param {string} method
|
||||
* @returns {string|*}
|
||||
*/
|
||||
HashArray.prototype.stringify = function stringify(method) {
|
||||
return this.Encodes.get(method, this).stringify();
|
||||
};
|
||||
|
||||
/**
|
||||
* Hash message with algo
|
||||
*
|
||||
* @memberof CryptoApi
|
||||
* @method hash
|
||||
* @public
|
||||
* @param {string} algo
|
||||
* @param {string} message
|
||||
* @param {Object} options
|
||||
* @return {HashArray} hash
|
||||
*/
|
||||
CryptoApi.prototype.hash = function hash(algo, message, options) {
|
||||
var hash = this.hasher(algo, options);
|
||||
hash.update(message);
|
||||
return hash.finalize();
|
||||
};
|
||||
/**
|
||||
* Get new Hasher object
|
||||
*
|
||||
* @memberof CryptoApi
|
||||
* @method hasher
|
||||
* @public
|
||||
* @param {string} algo
|
||||
* @param {Object} options
|
||||
* @returns {HasherInterface}
|
||||
*/
|
||||
CryptoApi.prototype.hasher = function hasher(algo, options) {
|
||||
return this.Hashers.get(algo, options);
|
||||
};
|
||||
/**
|
||||
* Get new MAC object
|
||||
*
|
||||
* @memberof CryptoApi
|
||||
* @method mac
|
||||
* @public
|
||||
* @param {string} algo
|
||||
* @param {string|number[]} key
|
||||
* @param {string} hasher
|
||||
* @param {Object} options
|
||||
* @returns {MacInterface}
|
||||
*/
|
||||
CryptoApi.prototype.mac = function mac(algo, key, hasher, options) {
|
||||
return this.Macs.get(algo, key, hasher, options);
|
||||
};
|
||||
/**
|
||||
* Get new HashArray
|
||||
*
|
||||
* @memberof CryptoApi
|
||||
* @method hashArray
|
||||
* @public
|
||||
* @param {number[]} hash
|
||||
* @returns {HashArray}
|
||||
*/
|
||||
CryptoApi.prototype.hashArray = function hashArray(hash) {
|
||||
return new HashArray(hash, this.Encodes);
|
||||
};
|
||||
root.CryptoApi = new CryptoApi();
|
||||
if (typeof module !== 'undefined' && module.exports) {
|
||||
module.exports = root.CryptoApi;
|
||||
} else {
|
||||
return root.CryptoApi;
|
||||
}
|
||||
})(this);
|
@ -1,113 +0,0 @@
|
||||
/*global require */
|
||||
(/**
|
||||
* @param {CryptoApi} CryptoApi
|
||||
* @returns {Md2}
|
||||
*/
|
||||
function (CryptoApi) {
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* @class Md2
|
||||
* @extends Hasher8
|
||||
* @implements HasherInterface
|
||||
* @desc Md2 hasher
|
||||
*/
|
||||
var Md2 = function (name, options) {
|
||||
this.constructor(name, options);
|
||||
};
|
||||
Md2.prototype = Object.create(CryptoApi.Hasher8.prototype);
|
||||
/**
|
||||
* @memberOf Md2
|
||||
* @constructor
|
||||
*/
|
||||
Md2.prototype.constructor = function (name, options) {
|
||||
CryptoApi.Hasher8.prototype.constructor.call(this, name, options);
|
||||
/**
|
||||
* @desc Hash state
|
||||
* @memberOf! Md2#
|
||||
* @alias state.hash
|
||||
* @type {number[]}
|
||||
*/
|
||||
this.state.hash = new Array(48);
|
||||
/**
|
||||
* @desc Checksum
|
||||
* @memberOf! Md2#
|
||||
* @alias state.checksum
|
||||
* @type {number[]}
|
||||
*/
|
||||
this.state.checksum = new Array(16);
|
||||
};
|
||||
|
||||
/**
|
||||
* @desc Constants from Pi
|
||||
* @link https://github.com/e-sushi/MD2-S-box-creator
|
||||
* @memberOf Md2#
|
||||
* @member {number[]} piSubst
|
||||
*/
|
||||
Md2.prototype.piSubst = [
|
||||
0x29, 0x2E, 0x43, 0xC9, 0xA2, 0xD8, 0x7C, 0x01, 0x3D, 0x36, 0x54, 0xA1, 0xEC, 0xF0, 0x06, 0x13,
|
||||
0x62, 0xA7, 0x05, 0xF3, 0xC0, 0xC7, 0x73, 0x8C, 0x98, 0x93, 0x2B, 0xD9, 0xBC, 0x4C, 0x82, 0xCA,
|
||||
0x1E, 0x9B, 0x57, 0x3C, 0xFD, 0xD4, 0xE0, 0x16, 0x67, 0x42, 0x6F, 0x18, 0x8A, 0x17, 0xE5, 0x12,
|
||||
0xBE, 0x4E, 0xC4, 0xD6, 0xDA, 0x9E, 0xDE, 0x49, 0xA0, 0xFB, 0xF5, 0x8E, 0xBB, 0x2F, 0xEE, 0x7A,
|
||||
0xA9, 0x68, 0x79, 0x91, 0x15, 0xB2, 0x07, 0x3F, 0x94, 0xC2, 0x10, 0x89, 0x0B, 0x22, 0x5F, 0x21,
|
||||
0x80, 0x7F, 0x5D, 0x9A, 0x5A, 0x90, 0x32, 0x27, 0x35, 0x3E, 0xCC, 0xE7, 0xBF, 0xF7, 0x97, 0x03,
|
||||
0xFF, 0x19, 0x30, 0xB3, 0x48, 0xA5, 0xB5, 0xD1, 0xD7, 0x5E, 0x92, 0x2A, 0xAC, 0x56, 0xAA, 0xC6,
|
||||
0x4F, 0xB8, 0x38, 0xD2, 0x96, 0xA4, 0x7D, 0xB6, 0x76, 0xFC, 0x6B, 0xE2, 0x9C, 0x74, 0x04, 0xF1,
|
||||
0x45, 0x9D, 0x70, 0x59, 0x64, 0x71, 0x87, 0x20, 0x86, 0x5B, 0xCF, 0x65, 0xE6, 0x2D, 0xA8, 0x02,
|
||||
0x1B, 0x60, 0x25, 0xAD, 0xAE, 0xB0, 0xB9, 0xF6, 0x1C, 0x46, 0x61, 0x69, 0x34, 0x40, 0x7E, 0x0F,
|
||||
0x55, 0x47, 0xA3, 0x23, 0xDD, 0x51, 0xAF, 0x3A, 0xC3, 0x5C, 0xF9, 0xCE, 0xBA, 0xC5, 0xEA, 0x26,
|
||||
0x2C, 0x53, 0x0D, 0x6E, 0x85, 0x28, 0x84, 0x09, 0xD3, 0xDF, 0xCD, 0xF4, 0x41, 0x81, 0x4D, 0x52,
|
||||
0x6A, 0xDC, 0x37, 0xC8, 0x6C, 0xC1, 0xAB, 0xFA, 0x24, 0xE1, 0x7B, 0x08, 0x0C, 0xBD, 0xB1, 0x4A,
|
||||
0x78, 0x88, 0x95, 0x8B, 0xE3, 0x63, 0xE8, 0x6D, 0xE9, 0xCB, 0xD5, 0xFE, 0x3B, 0x00, 0x1D, 0x39,
|
||||
0xF2, 0xEF, 0xB7, 0x0E, 0x66, 0x58, 0xD0, 0xE4, 0xA6, 0x77, 0x72, 0xF8, 0xEB, 0x75, 0x4B, 0x0A,
|
||||
0x31, 0x44, 0x50, 0xB4, 0x8F, 0xED, 0x1F, 0x1A, 0xDB, 0x99, 0x8D, 0x33, 0x9F, 0x11, 0x83, 0x14];
|
||||
|
||||
/**
|
||||
* @memberOf Md2
|
||||
* @method processBlock
|
||||
* @param {number[]} block
|
||||
*/
|
||||
Md2.prototype.processBlock = function processBlock(block) {
|
||||
// Append hash
|
||||
for (var i = 0; i < 16; i++) {
|
||||
this.state.hash[16 + i] = block[i];
|
||||
this.state.hash[32 + i] = this.state.hash[16 + i] ^ this.state.hash[i];
|
||||
}
|
||||
|
||||
// 18 Rounds
|
||||
var t = 0;
|
||||
for (i = 0; i < 18; i++) {
|
||||
for (var j = 0; j < 48; j++) {
|
||||
t = this.state.hash[j] ^= this.piSubst[t];
|
||||
}
|
||||
t = (t + i) & 0xff;
|
||||
}
|
||||
|
||||
// Append checksum
|
||||
t = this.state.checksum[15];
|
||||
for (i = 0; i < 16; i++) {
|
||||
t = this.state.checksum[i] ^= this.piSubst[block[i] ^ t];
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @memberOf Md2
|
||||
* @method finalize
|
||||
* @return {HashArray}
|
||||
*/
|
||||
Md2.prototype.finalize = function finalize() {
|
||||
var padLen = this.state.message.length & 0xf;
|
||||
this.update(new Array(17 - padLen).join(String.fromCharCode(16 - padLen)));
|
||||
|
||||
// Process checksum
|
||||
this.updateFromArray(this.state.checksum);
|
||||
|
||||
// Return hash
|
||||
return CryptoApi.hashArray(this.state.hash.slice(0, 16));
|
||||
};
|
||||
|
||||
CryptoApi.Hashers.add('md2', Md2);
|
||||
return Md2;
|
||||
})(
|
||||
this.CryptoApi || require('./crypto-api')
|
||||
);
|
@ -1,204 +0,0 @@
|
||||
/*global require */
|
||||
(/**
|
||||
* @param {CryptoApi} CryptoApi
|
||||
* @returns {Md4}
|
||||
*/
|
||||
function (CryptoApi) {
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* @class Md4
|
||||
* @desc Md4 hasher
|
||||
* @implements HasherInterface
|
||||
* @extends Hasher32le
|
||||
*/
|
||||
var Md4 = function md4(name, options) {
|
||||
this.constructor(name, options);
|
||||
};
|
||||
Md4.prototype = Object.create(CryptoApi.Hasher32le.prototype);
|
||||
/**
|
||||
* @memberOf Md4
|
||||
* @constructor
|
||||
*/
|
||||
Md4.prototype.constructor = function (name, options) {
|
||||
CryptoApi.Hasher32le.prototype.constructor.call(this, name, options);
|
||||
/**
|
||||
* @desc Hash state
|
||||
* @memberOf! Md4#
|
||||
* @alias state.hash
|
||||
* @type {number[]}
|
||||
*/
|
||||
this.state.hash = [0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476];
|
||||
};
|
||||
|
||||
/**
|
||||
* @desc Transform constants
|
||||
* @memberOf Md4
|
||||
* @member {number[]} S
|
||||
* @const
|
||||
*/
|
||||
Md4.prototype.S = [
|
||||
[3, 7, 11, 19],
|
||||
[3, 5, 9, 13],
|
||||
[3, 9, 11, 15]
|
||||
];
|
||||
Md4.prototype.F = 0x00000000;
|
||||
Md4.prototype.G = 0x5a827999;
|
||||
Md4.prototype.H = 0x6ed9eba1;
|
||||
|
||||
// Transform functions
|
||||
/**
|
||||
* @param {number} x
|
||||
* @param {number} y
|
||||
* @param {number} z
|
||||
* @returns {number}
|
||||
*/
|
||||
Md4.prototype.FF = function FF(x, y, z) {
|
||||
return (x & y) | ((~x) & z);
|
||||
};
|
||||
/**
|
||||
* @param {number} x
|
||||
* @param {number} y
|
||||
* @param {number} z
|
||||
* @returns {number}
|
||||
*/
|
||||
Md4.prototype.GG = function GG(x, y, z) {
|
||||
return (x & y) | (x & z) | (y & z);
|
||||
};
|
||||
/**
|
||||
* @param {number} x
|
||||
* @param {number} y
|
||||
* @param {number} z
|
||||
* @returns {number}
|
||||
*/
|
||||
Md4.prototype.HH = function HH(x, y, z) {
|
||||
return x ^ y ^ z;
|
||||
};
|
||||
/**
|
||||
*
|
||||
* @param {function} f
|
||||
* @param {number} k
|
||||
* @param {number} a
|
||||
* @param {number} x
|
||||
* @param {number} y
|
||||
* @param {number} z
|
||||
* @param {number} m
|
||||
* @param {number} s
|
||||
* @returns {number}
|
||||
* @constructor
|
||||
*/
|
||||
Md4.prototype.CC = function CC(f, k, a, x, y, z, m, s) {
|
||||
return CryptoApi.Tools.rotateLeft((a + f(x, y, z) + m + k), s) | 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* @memberOf Md4
|
||||
* @method processBlock
|
||||
* @param {number[]} block
|
||||
*/
|
||||
Md4.prototype.processBlock = function processBlock(block) {
|
||||
// Working variables
|
||||
var a = this.state.hash[0] | 0;
|
||||
var b = this.state.hash[1] | 0;
|
||||
var c = this.state.hash[2] | 0;
|
||||
var d = this.state.hash[3] | 0;
|
||||
|
||||
// Round 1
|
||||
a = this.CC(this.FF, this.F, a, b, c, d, block[0], this.S[0][0]);
|
||||
d = this.CC(this.FF, this.F, d, a, b, c, block[1], this.S[0][1]);
|
||||
c = this.CC(this.FF, this.F, c, d, a, b, block[2], this.S[0][2]);
|
||||
b = this.CC(this.FF, this.F, b, c, d, a, block[3], this.S[0][3]);
|
||||
a = this.CC(this.FF, this.F, a, b, c, d, block[4], this.S[0][0]);
|
||||
d = this.CC(this.FF, this.F, d, a, b, c, block[5], this.S[0][1]);
|
||||
c = this.CC(this.FF, this.F, c, d, a, b, block[6], this.S[0][2]);
|
||||
b = this.CC(this.FF, this.F, b, c, d, a, block[7], this.S[0][3]);
|
||||
a = this.CC(this.FF, this.F, a, b, c, d, block[8], this.S[0][0]);
|
||||
d = this.CC(this.FF, this.F, d, a, b, c, block[9], this.S[0][1]);
|
||||
c = this.CC(this.FF, this.F, c, d, a, b, block[10], this.S[0][2]);
|
||||
b = this.CC(this.FF, this.F, b, c, d, a, block[11], this.S[0][3]);
|
||||
a = this.CC(this.FF, this.F, a, b, c, d, block[12], this.S[0][0]);
|
||||
d = this.CC(this.FF, this.F, d, a, b, c, block[13], this.S[0][1]);
|
||||
c = this.CC(this.FF, this.F, c, d, a, b, block[14], this.S[0][2]);
|
||||
b = this.CC(this.FF, this.F, b, c, d, a, block[15], this.S[0][3]);
|
||||
|
||||
// Round 2
|
||||
a = this.CC(this.GG, this.G, a, b, c, d, block[0], this.S[1][0]);
|
||||
d = this.CC(this.GG, this.G, d, a, b, c, block[4], this.S[1][1]);
|
||||
c = this.CC(this.GG, this.G, c, d, a, b, block[8], this.S[1][2]);
|
||||
b = this.CC(this.GG, this.G, b, c, d, a, block[12], this.S[1][3]);
|
||||
a = this.CC(this.GG, this.G, a, b, c, d, block[1], this.S[1][0]);
|
||||
d = this.CC(this.GG, this.G, d, a, b, c, block[5], this.S[1][1]);
|
||||
c = this.CC(this.GG, this.G, c, d, a, b, block[9], this.S[1][2]);
|
||||
b = this.CC(this.GG, this.G, b, c, d, a, block[13], this.S[1][3]);
|
||||
a = this.CC(this.GG, this.G, a, b, c, d, block[2], this.S[1][0]);
|
||||
d = this.CC(this.GG, this.G, d, a, b, c, block[6], this.S[1][1]);
|
||||
c = this.CC(this.GG, this.G, c, d, a, b, block[10], this.S[1][2]);
|
||||
b = this.CC(this.GG, this.G, b, c, d, a, block[14], this.S[1][3]);
|
||||
a = this.CC(this.GG, this.G, a, b, c, d, block[3], this.S[1][0]);
|
||||
d = this.CC(this.GG, this.G, d, a, b, c, block[7], this.S[1][1]);
|
||||
c = this.CC(this.GG, this.G, c, d, a, b, block[11], this.S[1][2]);
|
||||
b = this.CC(this.GG, this.G, b, c, d, a, block[15], this.S[1][3]);
|
||||
|
||||
// Round 3
|
||||
a = this.CC(this.HH, this.H, a, b, c, d, block[0], this.S[2][0]);
|
||||
d = this.CC(this.HH, this.H, d, a, b, c, block[8], this.S[2][1]);
|
||||
c = this.CC(this.HH, this.H, c, d, a, b, block[4], this.S[2][2]);
|
||||
b = this.CC(this.HH, this.H, b, c, d, a, block[12], this.S[2][3]);
|
||||
a = this.CC(this.HH, this.H, a, b, c, d, block[2], this.S[2][0]);
|
||||
d = this.CC(this.HH, this.H, d, a, b, c, block[10], this.S[2][1]);
|
||||
c = this.CC(this.HH, this.H, c, d, a, b, block[6], this.S[2][2]);
|
||||
b = this.CC(this.HH, this.H, b, c, d, a, block[14], this.S[2][3]);
|
||||
a = this.CC(this.HH, this.H, a, b, c, d, block[1], this.S[2][0]);
|
||||
d = this.CC(this.HH, this.H, d, a, b, c, block[9], this.S[2][1]);
|
||||
c = this.CC(this.HH, this.H, c, d, a, b, block[5], this.S[2][2]);
|
||||
b = this.CC(this.HH, this.H, b, c, d, a, block[13], this.S[2][3]);
|
||||
a = this.CC(this.HH, this.H, a, b, c, d, block[3], this.S[2][0]);
|
||||
d = this.CC(this.HH, this.H, d, a, b, c, block[11], this.S[2][1]);
|
||||
c = this.CC(this.HH, this.H, c, d, a, b, block[7], this.S[2][2]);
|
||||
b = this.CC(this.HH, this.H, b, c, d, a, block[15], this.S[2][3]);
|
||||
|
||||
this.state.hash = [
|
||||
(this.state.hash[0] + a) | 0,
|
||||
(this.state.hash[1] + b) | 0,
|
||||
(this.state.hash[2] + c) | 0,
|
||||
(this.state.hash[3] + d) | 0
|
||||
];
|
||||
};
|
||||
/**
|
||||
* @memberOf Md4
|
||||
* @method finalize
|
||||
* @return {HashArray} hash
|
||||
*/
|
||||
Md4.prototype.finalize = function finalize() {
|
||||
// Add padding
|
||||
var padLen = this.state.message.length < 56 ? 56 - this.state.message.length : 120 - this.state.message.length;
|
||||
var padding = new Array(padLen);
|
||||
padding[0] = 0x80;
|
||||
|
||||
// Add length
|
||||
var lengthBits = this.state.length * 8;
|
||||
for (var i = 0; i < 4; i++) {
|
||||
padding.push((lengthBits >> (8 * i)) & 0xff);
|
||||
}
|
||||
// @todo fix length to 64 bit
|
||||
for (i = 0; i < 4; i++) {
|
||||
padding.push(0);
|
||||
}
|
||||
this.updateFromArray(padding);
|
||||
|
||||
var hash = [];
|
||||
for (i = 0; i < this.state.hash.length; i++) {
|
||||
for (var j = 0; j < 4; j++) {
|
||||
hash.push((this.state.hash[i] >> 8 * j) & 0xff);
|
||||
}
|
||||
}
|
||||
|
||||
// Return hash
|
||||
return CryptoApi.hashArray(hash);
|
||||
};
|
||||
|
||||
CryptoApi.Hashers.add('md4', Md4);
|
||||
return Md4;
|
||||
})(
|
||||
this.CryptoApi || require('./crypto-api')
|
||||
);
|
@ -1,125 +0,0 @@
|
||||
/*global require */
|
||||
(/**
|
||||
*
|
||||
* @param {CryptoApi} CryptoApi
|
||||
* @returns {Sha0}
|
||||
*/
|
||||
function (CryptoApi) {
|
||||
'use strict';
|
||||
|
||||
// Transform constants
|
||||
var K = [0x5a827999, 0x6ed9eba1, 0x8f1bbcdc, 0xca62c1d6];
|
||||
|
||||
/**
|
||||
* @class Sha0
|
||||
* @desc Sha0 hasher
|
||||
* @implements HasherInterface
|
||||
* @extends Hasher32be
|
||||
*/
|
||||
var Sha0 = function sha0(name, options) {
|
||||
this.constructor(name, options);
|
||||
};
|
||||
Sha0.prototype = Object.create(CryptoApi.Hasher32be.prototype);
|
||||
/**
|
||||
* @memberOf Sha0
|
||||
* @constructor
|
||||
*/
|
||||
Sha0.prototype.constructor = function (name, options) {
|
||||
CryptoApi.Hasher32be.prototype.constructor.call(this, name, options);
|
||||
/**
|
||||
* @desc Hash state
|
||||
* @memberOf! Sha0#
|
||||
* @alias state.hash
|
||||
* @type {number[]}
|
||||
*/
|
||||
this.state.hash = [
|
||||
0x67452301,
|
||||
0xefcdab89,
|
||||
0x98badcfe,
|
||||
0x10325476,
|
||||
0xc3d2e1f0
|
||||
];
|
||||
this.W = [];
|
||||
};
|
||||
|
||||
/**
|
||||
* @memberOf Sha0
|
||||
* @method processBlock
|
||||
* @param {number[]} M
|
||||
*/
|
||||
Sha0.prototype.processBlock = function processBlock(M) {
|
||||
// Working variables
|
||||
var a = this.state.hash[0] | 0;
|
||||
var b = this.state.hash[1] | 0;
|
||||
var c = this.state.hash[2] | 0;
|
||||
var d = this.state.hash[3] | 0;
|
||||
var e = this.state.hash[4] | 0;
|
||||
|
||||
// Calculate hash
|
||||
for (var i = 0; i < 80; i++) {
|
||||
if (i < 16) {
|
||||
this.W[i] = M[i] | 0;
|
||||
} else {
|
||||
this.W[i] = (this.W[i - 3] ^ this.W[i - 8] ^ this.W[i - 14] ^ this.W[i - 16]) | 0;
|
||||
}
|
||||
|
||||
var t = (CryptoApi.Tools.rotateLeft(a, 5) + e + this.W[i] + K[(i / 20) >> 0]) | 0;
|
||||
if (i < 20) {
|
||||
t = (t + ((b & c) | (~b & d))) | 0;
|
||||
} else if (i < 40) {
|
||||
t = (t + (b ^ c ^ d)) | 0;
|
||||
} else if (i < 60) {
|
||||
t = (t + ((b & c) | (b & d) | (c & d))) | 0;
|
||||
} else {
|
||||
t = (t + (b ^ c ^ d)) | 0;
|
||||
}
|
||||
e = d;
|
||||
d = c;
|
||||
c = CryptoApi.Tools.rotateLeft(b, 30) | 0;
|
||||
b = a;
|
||||
a = t;
|
||||
}
|
||||
|
||||
this.state.hash[0] = (this.state.hash[0] + a) | 0;
|
||||
this.state.hash[1] = (this.state.hash[1] + b) | 0;
|
||||
this.state.hash[2] = (this.state.hash[2] + c) | 0;
|
||||
this.state.hash[3] = (this.state.hash[3] + d) | 0;
|
||||
this.state.hash[4] = (this.state.hash[4] + e) | 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* @memberOf Sha0
|
||||
* @method finalize
|
||||
* @return {HashArray} hash
|
||||
*/
|
||||
Sha0.prototype.finalize = function finalize() {
|
||||
// Add padding
|
||||
var padLen = this.state.message.length < 56 ? 56 - this.state.message.length : 120 - this.state.message.length;
|
||||
padLen += 4; // @todo fix length to 64 bit
|
||||
var padding = new Array(padLen);
|
||||
padding[0] = 0x80;
|
||||
|
||||
// Add length
|
||||
var lengthBits = this.state.length * 8;
|
||||
for (var i = 3; i >= 0; i--) {
|
||||
padding.push((lengthBits >> (8 * i)) & 0xff);
|
||||
}
|
||||
|
||||
this.updateFromArray(padding);
|
||||
|
||||
var hash = [];
|
||||
for (var k = 0, l = this.state.hash.length; k < l; k++) {
|
||||
for (var j = 3; j >= 0; j--) {
|
||||
hash.push((this.state.hash[k] >> 8 * j) & 0xFF);
|
||||
}
|
||||
}
|
||||
|
||||
// Return hash
|
||||
return CryptoApi.hashArray(hash);
|
||||
};
|
||||
|
||||
CryptoApi.Hashers.add('sha0', Sha0);
|
||||
return Sha0;
|
||||
})(
|
||||
this.CryptoApi || require('./crypto-api')
|
||||
);
|
@ -1,213 +0,0 @@
|
||||
/*
|
||||
CryptoJS v3.1.2
|
||||
code.google.com/p/crypto-js
|
||||
(c) 2009-2013 by Jeff Mott. All rights reserved.
|
||||
code.google.com/p/crypto-js/wiki/License
|
||||
*/
|
||||
(function () {
|
||||
// Shortcuts
|
||||
var C = CryptoJS;
|
||||
var C_lib = C.lib;
|
||||
var BlockCipher = C_lib.BlockCipher;
|
||||
var C_algo = C.algo;
|
||||
|
||||
// Lookup tables
|
||||
var SBOX = [];
|
||||
var INV_SBOX = [];
|
||||
var SUB_MIX_0 = [];
|
||||
var SUB_MIX_1 = [];
|
||||
var SUB_MIX_2 = [];
|
||||
var SUB_MIX_3 = [];
|
||||
var INV_SUB_MIX_0 = [];
|
||||
var INV_SUB_MIX_1 = [];
|
||||
var INV_SUB_MIX_2 = [];
|
||||
var INV_SUB_MIX_3 = [];
|
||||
|
||||
// Compute lookup tables
|
||||
(function () {
|
||||
// Compute double table
|
||||
var d = [];
|
||||
for (var i = 0; i < 256; i++) {
|
||||
if (i < 128) {
|
||||
d[i] = i << 1;
|
||||
} else {
|
||||
d[i] = (i << 1) ^ 0x11b;
|
||||
}
|
||||
}
|
||||
|
||||
// Walk GF(2^8)
|
||||
var x = 0;
|
||||
var xi = 0;
|
||||
for (var i = 0; i < 256; i++) {
|
||||
// Compute sbox
|
||||
var sx = xi ^ (xi << 1) ^ (xi << 2) ^ (xi << 3) ^ (xi << 4);
|
||||
sx = (sx >>> 8) ^ (sx & 0xff) ^ 0x63;
|
||||
SBOX[x] = sx;
|
||||
INV_SBOX[sx] = x;
|
||||
|
||||
// Compute multiplication
|
||||
var x2 = d[x];
|
||||
var x4 = d[x2];
|
||||
var x8 = d[x4];
|
||||
|
||||
// Compute sub bytes, mix columns tables
|
||||
var t = (d[sx] * 0x101) ^ (sx * 0x1010100);
|
||||
SUB_MIX_0[x] = (t << 24) | (t >>> 8);
|
||||
SUB_MIX_1[x] = (t << 16) | (t >>> 16);
|
||||
SUB_MIX_2[x] = (t << 8) | (t >>> 24);
|
||||
SUB_MIX_3[x] = t;
|
||||
|
||||
// Compute inv sub bytes, inv mix columns tables
|
||||
var t = (x8 * 0x1010101) ^ (x4 * 0x10001) ^ (x2 * 0x101) ^ (x * 0x1010100);
|
||||
INV_SUB_MIX_0[sx] = (t << 24) | (t >>> 8);
|
||||
INV_SUB_MIX_1[sx] = (t << 16) | (t >>> 16);
|
||||
INV_SUB_MIX_2[sx] = (t << 8) | (t >>> 24);
|
||||
INV_SUB_MIX_3[sx] = t;
|
||||
|
||||
// Compute next counter
|
||||
if (!x) {
|
||||
x = xi = 1;
|
||||
} else {
|
||||
x = x2 ^ d[d[d[x8 ^ x2]]];
|
||||
xi ^= d[d[xi]];
|
||||
}
|
||||
}
|
||||
}());
|
||||
|
||||
// Precomputed Rcon lookup
|
||||
var RCON = [0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36];
|
||||
|
||||
/**
|
||||
* AES block cipher algorithm.
|
||||
*/
|
||||
var AES = C_algo.AES = BlockCipher.extend({
|
||||
_doReset: function () {
|
||||
// Shortcuts
|
||||
var key = this._key;
|
||||
var keyWords = key.words;
|
||||
var keySize = key.sigBytes / 4;
|
||||
|
||||
// Compute number of rounds
|
||||
var nRounds = this._nRounds = keySize + 6
|
||||
|
||||
// Compute number of key schedule rows
|
||||
var ksRows = (nRounds + 1) * 4;
|
||||
|
||||
// Compute key schedule
|
||||
var keySchedule = this._keySchedule = [];
|
||||
for (var ksRow = 0; ksRow < ksRows; ksRow++) {
|
||||
if (ksRow < keySize) {
|
||||
keySchedule[ksRow] = keyWords[ksRow];
|
||||
} else {
|
||||
var t = keySchedule[ksRow - 1];
|
||||
|
||||
if (!(ksRow % keySize)) {
|
||||
// Rot word
|
||||
t = (t << 8) | (t >>> 24);
|
||||
|
||||
// Sub word
|
||||
t = (SBOX[t >>> 24] << 24) | (SBOX[(t >>> 16) & 0xff] << 16) | (SBOX[(t >>> 8) & 0xff] << 8) | SBOX[t & 0xff];
|
||||
|
||||
// Mix Rcon
|
||||
t ^= RCON[(ksRow / keySize) | 0] << 24;
|
||||
} else if (keySize > 6 && ksRow % keySize == 4) {
|
||||
// Sub word
|
||||
t = (SBOX[t >>> 24] << 24) | (SBOX[(t >>> 16) & 0xff] << 16) | (SBOX[(t >>> 8) & 0xff] << 8) | SBOX[t & 0xff];
|
||||
}
|
||||
|
||||
keySchedule[ksRow] = keySchedule[ksRow - keySize] ^ t;
|
||||
}
|
||||
}
|
||||
|
||||
// Compute inv key schedule
|
||||
var invKeySchedule = this._invKeySchedule = [];
|
||||
for (var invKsRow = 0; invKsRow < ksRows; invKsRow++) {
|
||||
var ksRow = ksRows - invKsRow;
|
||||
|
||||
if (invKsRow % 4) {
|
||||
var t = keySchedule[ksRow];
|
||||
} else {
|
||||
var t = keySchedule[ksRow - 4];
|
||||
}
|
||||
|
||||
if (invKsRow < 4 || ksRow <= 4) {
|
||||
invKeySchedule[invKsRow] = t;
|
||||
} else {
|
||||
invKeySchedule[invKsRow] = INV_SUB_MIX_0[SBOX[t >>> 24]] ^ INV_SUB_MIX_1[SBOX[(t >>> 16) & 0xff]] ^
|
||||
INV_SUB_MIX_2[SBOX[(t >>> 8) & 0xff]] ^ INV_SUB_MIX_3[SBOX[t & 0xff]];
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
encryptBlock: function (M, offset) {
|
||||
this._doCryptBlock(M, offset, this._keySchedule, SUB_MIX_0, SUB_MIX_1, SUB_MIX_2, SUB_MIX_3, SBOX);
|
||||
},
|
||||
|
||||
decryptBlock: function (M, offset) {
|
||||
// Swap 2nd and 4th rows
|
||||
var t = M[offset + 1];
|
||||
M[offset + 1] = M[offset + 3];
|
||||
M[offset + 3] = t;
|
||||
|
||||
this._doCryptBlock(M, offset, this._invKeySchedule, INV_SUB_MIX_0, INV_SUB_MIX_1, INV_SUB_MIX_2, INV_SUB_MIX_3, INV_SBOX);
|
||||
|
||||
// Inv swap 2nd and 4th rows
|
||||
var t = M[offset + 1];
|
||||
M[offset + 1] = M[offset + 3];
|
||||
M[offset + 3] = t;
|
||||
},
|
||||
|
||||
_doCryptBlock: function (M, offset, keySchedule, SUB_MIX_0, SUB_MIX_1, SUB_MIX_2, SUB_MIX_3, SBOX) {
|
||||
// Shortcut
|
||||
var nRounds = this._nRounds;
|
||||
|
||||
// Get input, add round key
|
||||
var s0 = M[offset] ^ keySchedule[0];
|
||||
var s1 = M[offset + 1] ^ keySchedule[1];
|
||||
var s2 = M[offset + 2] ^ keySchedule[2];
|
||||
var s3 = M[offset + 3] ^ keySchedule[3];
|
||||
|
||||
// Key schedule row counter
|
||||
var ksRow = 4;
|
||||
|
||||
// Rounds
|
||||
for (var round = 1; round < nRounds; round++) {
|
||||
// Shift rows, sub bytes, mix columns, add round key
|
||||
var t0 = SUB_MIX_0[s0 >>> 24] ^ SUB_MIX_1[(s1 >>> 16) & 0xff] ^ SUB_MIX_2[(s2 >>> 8) & 0xff] ^ SUB_MIX_3[s3 & 0xff] ^ keySchedule[ksRow++];
|
||||
var t1 = SUB_MIX_0[s1 >>> 24] ^ SUB_MIX_1[(s2 >>> 16) & 0xff] ^ SUB_MIX_2[(s3 >>> 8) & 0xff] ^ SUB_MIX_3[s0 & 0xff] ^ keySchedule[ksRow++];
|
||||
var t2 = SUB_MIX_0[s2 >>> 24] ^ SUB_MIX_1[(s3 >>> 16) & 0xff] ^ SUB_MIX_2[(s0 >>> 8) & 0xff] ^ SUB_MIX_3[s1 & 0xff] ^ keySchedule[ksRow++];
|
||||
var t3 = SUB_MIX_0[s3 >>> 24] ^ SUB_MIX_1[(s0 >>> 16) & 0xff] ^ SUB_MIX_2[(s1 >>> 8) & 0xff] ^ SUB_MIX_3[s2 & 0xff] ^ keySchedule[ksRow++];
|
||||
|
||||
// Update state
|
||||
s0 = t0;
|
||||
s1 = t1;
|
||||
s2 = t2;
|
||||
s3 = t3;
|
||||
}
|
||||
|
||||
// Shift rows, sub bytes, add round key
|
||||
var t0 = ((SBOX[s0 >>> 24] << 24) | (SBOX[(s1 >>> 16) & 0xff] << 16) | (SBOX[(s2 >>> 8) & 0xff] << 8) | SBOX[s3 & 0xff]) ^ keySchedule[ksRow++];
|
||||
var t1 = ((SBOX[s1 >>> 24] << 24) | (SBOX[(s2 >>> 16) & 0xff] << 16) | (SBOX[(s3 >>> 8) & 0xff] << 8) | SBOX[s0 & 0xff]) ^ keySchedule[ksRow++];
|
||||
var t2 = ((SBOX[s2 >>> 24] << 24) | (SBOX[(s3 >>> 16) & 0xff] << 16) | (SBOX[(s0 >>> 8) & 0xff] << 8) | SBOX[s1 & 0xff]) ^ keySchedule[ksRow++];
|
||||
var t3 = ((SBOX[s3 >>> 24] << 24) | (SBOX[(s0 >>> 16) & 0xff] << 16) | (SBOX[(s1 >>> 8) & 0xff] << 8) | SBOX[s2 & 0xff]) ^ keySchedule[ksRow++];
|
||||
|
||||
// Set output
|
||||
M[offset] = t0;
|
||||
M[offset + 1] = t1;
|
||||
M[offset + 2] = t2;
|
||||
M[offset + 3] = t3;
|
||||
},
|
||||
|
||||
keySize: 256/32
|
||||
});
|
||||
|
||||
/**
|
||||
* Shortcut functions to the cipher's object interface.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* var ciphertext = CryptoJS.AES.encrypt(message, key, cfg);
|
||||
* var plaintext = CryptoJS.AES.decrypt(ciphertext, key, cfg);
|
||||
*/
|
||||
C.AES = BlockCipher._createHelper(AES);
|
||||
}());
|
@ -1,864 +0,0 @@
|
||||
/*
|
||||
CryptoJS v3.1.2
|
||||
code.google.com/p/crypto-js
|
||||
(c) 2009-2013 by Jeff Mott. All rights reserved.
|
||||
code.google.com/p/crypto-js/wiki/License
|
||||
*/
|
||||
/**
|
||||
* Cipher core components.
|
||||
*/
|
||||
CryptoJS.lib.Cipher || (function (undefined) {
|
||||
// Shortcuts
|
||||
var C = CryptoJS;
|
||||
var C_lib = C.lib;
|
||||
var Base = C_lib.Base;
|
||||
var WordArray = C_lib.WordArray;
|
||||
var BufferedBlockAlgorithm = C_lib.BufferedBlockAlgorithm;
|
||||
var C_enc = C.enc;
|
||||
var Utf8 = C_enc.Utf8;
|
||||
var Base64 = C_enc.Base64;
|
||||
var C_algo = C.algo;
|
||||
var EvpKDF = C_algo.EvpKDF;
|
||||
|
||||
/**
|
||||
* Abstract base cipher template.
|
||||
*
|
||||
* @property {number} keySize This cipher's key size. Default: 4 (128 bits)
|
||||
* @property {number} ivSize This cipher's IV size. Default: 4 (128 bits)
|
||||
* @property {number} _ENC_XFORM_MODE A constant representing encryption mode.
|
||||
* @property {number} _DEC_XFORM_MODE A constant representing decryption mode.
|
||||
*/
|
||||
var Cipher = C_lib.Cipher = BufferedBlockAlgorithm.extend({
|
||||
/**
|
||||
* Configuration options.
|
||||
*
|
||||
* @property {WordArray} iv The IV to use for this operation.
|
||||
*/
|
||||
cfg: Base.extend(),
|
||||
|
||||
/**
|
||||
* Creates this cipher in encryption mode.
|
||||
*
|
||||
* @param {WordArray} key The key.
|
||||
* @param {Object} cfg (Optional) The configuration options to use for this operation.
|
||||
*
|
||||
* @return {Cipher} A cipher instance.
|
||||
*
|
||||
* @static
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* var cipher = CryptoJS.algo.AES.createEncryptor(keyWordArray, { iv: ivWordArray });
|
||||
*/
|
||||
createEncryptor: function (key, cfg) {
|
||||
return this.create(this._ENC_XFORM_MODE, key, cfg);
|
||||
},
|
||||
|
||||
/**
|
||||
* Creates this cipher in decryption mode.
|
||||
*
|
||||
* @param {WordArray} key The key.
|
||||
* @param {Object} cfg (Optional) The configuration options to use for this operation.
|
||||
*
|
||||
* @return {Cipher} A cipher instance.
|
||||
*
|
||||
* @static
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* var cipher = CryptoJS.algo.AES.createDecryptor(keyWordArray, { iv: ivWordArray });
|
||||
*/
|
||||
createDecryptor: function (key, cfg) {
|
||||
return this.create(this._DEC_XFORM_MODE, key, cfg);
|
||||
},
|
||||
|
||||
/**
|
||||
* Initializes a newly created cipher.
|
||||
*
|
||||
* @param {number} xformMode Either the encryption or decryption transormation mode constant.
|
||||
* @param {WordArray} key The key.
|
||||
* @param {Object} cfg (Optional) The configuration options to use for this operation.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* var cipher = CryptoJS.algo.AES.create(CryptoJS.algo.AES._ENC_XFORM_MODE, keyWordArray, { iv: ivWordArray });
|
||||
*/
|
||||
init: function (xformMode, key, cfg) {
|
||||
// Apply config defaults
|
||||
this.cfg = this.cfg.extend(cfg);
|
||||
|
||||
// Store transform mode and key
|
||||
this._xformMode = xformMode;
|
||||
this._key = key;
|
||||
|
||||
// Set initial values
|
||||
this.reset();
|
||||
},
|
||||
|
||||
/**
|
||||
* Resets this cipher to its initial state.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* cipher.reset();
|
||||
*/
|
||||
reset: function () {
|
||||
// Reset data buffer
|
||||
BufferedBlockAlgorithm.reset.call(this);
|
||||
|
||||
// Perform concrete-cipher logic
|
||||
this._doReset();
|
||||
},
|
||||
|
||||
/**
|
||||
* Adds data to be encrypted or decrypted.
|
||||
*
|
||||
* @param {WordArray|string} dataUpdate The data to encrypt or decrypt.
|
||||
*
|
||||
* @return {WordArray} The data after processing.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* var encrypted = cipher.process('data');
|
||||
* var encrypted = cipher.process(wordArray);
|
||||
*/
|
||||
process: function (dataUpdate) {
|
||||
// Append
|
||||
this._append(dataUpdate);
|
||||
|
||||
// Process available blocks
|
||||
return this._process();
|
||||
},
|
||||
|
||||
/**
|
||||
* Finalizes the encryption or decryption process.
|
||||
* Note that the finalize operation is effectively a destructive, read-once operation.
|
||||
*
|
||||
* @param {WordArray|string} dataUpdate The final data to encrypt or decrypt.
|
||||
*
|
||||
* @return {WordArray} The data after final processing.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* var encrypted = cipher.finalize();
|
||||
* var encrypted = cipher.finalize('data');
|
||||
* var encrypted = cipher.finalize(wordArray);
|
||||
*/
|
||||
finalize: function (dataUpdate) {
|
||||
// Final data update
|
||||
if (dataUpdate) {
|
||||
this._append(dataUpdate);
|
||||
}
|
||||
|
||||
// Perform concrete-cipher logic
|
||||
var finalProcessedData = this._doFinalize();
|
||||
|
||||
return finalProcessedData;
|
||||
},
|
||||
|
||||
keySize: 128/32,
|
||||
|
||||
ivSize: 128/32,
|
||||
|
||||
_ENC_XFORM_MODE: 1,
|
||||
|
||||
_DEC_XFORM_MODE: 2,
|
||||
|
||||
/**
|
||||
* Creates shortcut functions to a cipher's object interface.
|
||||
*
|
||||
* @param {Cipher} cipher The cipher to create a helper for.
|
||||
*
|
||||
* @return {Object} An object with encrypt and decrypt shortcut functions.
|
||||
*
|
||||
* @static
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* var AES = CryptoJS.lib.Cipher._createHelper(CryptoJS.algo.AES);
|
||||
*/
|
||||
_createHelper: (function () {
|
||||
function selectCipherStrategy(key) {
|
||||
if (typeof key == 'string') {
|
||||
return PasswordBasedCipher;
|
||||
} else {
|
||||
return SerializableCipher;
|
||||
}
|
||||
}
|
||||
|
||||
return function (cipher) {
|
||||
return {
|
||||
encrypt: function (message, key, cfg) {
|
||||
return selectCipherStrategy(key).encrypt(cipher, message, key, cfg);
|
||||
},
|
||||
|
||||
decrypt: function (ciphertext, key, cfg) {
|
||||
return selectCipherStrategy(key).decrypt(cipher, ciphertext, key, cfg);
|
||||
}
|
||||
};
|
||||
};
|
||||
}())
|
||||
});
|
||||
|
||||
/**
|
||||
* Abstract base stream cipher template.
|
||||
*
|
||||
* @property {number} blockSize The number of 32-bit words this cipher operates on. Default: 1 (32 bits)
|
||||
*/
|
||||
var StreamCipher = C_lib.StreamCipher = Cipher.extend({
|
||||
_doFinalize: function () {
|
||||
// Process partial blocks
|
||||
var finalProcessedBlocks = this._process(!!'flush');
|
||||
|
||||
return finalProcessedBlocks;
|
||||
},
|
||||
|
||||
blockSize: 1
|
||||
});
|
||||
|
||||
/**
|
||||
* Mode namespace.
|
||||
*/
|
||||
var C_mode = C.mode = {};
|
||||
|
||||
/**
|
||||
* Abstract base block cipher mode template.
|
||||
*/
|
||||
var BlockCipherMode = C_lib.BlockCipherMode = Base.extend({
|
||||
/**
|
||||
* Creates this mode for encryption.
|
||||
*
|
||||
* @param {Cipher} cipher A block cipher instance.
|
||||
* @param {Array} iv The IV words.
|
||||
*
|
||||
* @static
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* var mode = CryptoJS.mode.CBC.createEncryptor(cipher, iv.words);
|
||||
*/
|
||||
createEncryptor: function (cipher, iv) {
|
||||
return this.Encryptor.create(cipher, iv);
|
||||
},
|
||||
|
||||
/**
|
||||
* Creates this mode for decryption.
|
||||
*
|
||||
* @param {Cipher} cipher A block cipher instance.
|
||||
* @param {Array} iv The IV words.
|
||||
*
|
||||
* @static
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* var mode = CryptoJS.mode.CBC.createDecryptor(cipher, iv.words);
|
||||
*/
|
||||
createDecryptor: function (cipher, iv) {
|
||||
return this.Decryptor.create(cipher, iv);
|
||||
},
|
||||
|
||||
/**
|
||||
* Initializes a newly created mode.
|
||||
*
|
||||
* @param {Cipher} cipher A block cipher instance.
|
||||
* @param {Array} iv The IV words.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* var mode = CryptoJS.mode.CBC.Encryptor.create(cipher, iv.words);
|
||||
*/
|
||||
init: function (cipher, iv) {
|
||||
this._cipher = cipher;
|
||||
this._iv = iv;
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Cipher Block Chaining mode.
|
||||
*/
|
||||
var CBC = C_mode.CBC = (function () {
|
||||
/**
|
||||
* Abstract base CBC mode.
|
||||
*/
|
||||
var CBC = BlockCipherMode.extend();
|
||||
|
||||
/**
|
||||
* CBC encryptor.
|
||||
*/
|
||||
CBC.Encryptor = CBC.extend({
|
||||
/**
|
||||
* Processes the data block at offset.
|
||||
*
|
||||
* @param {Array} words The data words to operate on.
|
||||
* @param {number} offset The offset where the block starts.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* mode.processBlock(data.words, offset);
|
||||
*/
|
||||
processBlock: function (words, offset) {
|
||||
// Shortcuts
|
||||
var cipher = this._cipher;
|
||||
var blockSize = cipher.blockSize;
|
||||
|
||||
// XOR and encrypt
|
||||
xorBlock.call(this, words, offset, blockSize);
|
||||
cipher.encryptBlock(words, offset);
|
||||
|
||||
// Remember this block to use with next block
|
||||
this._prevBlock = words.slice(offset, offset + blockSize);
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* CBC decryptor.
|
||||
*/
|
||||
CBC.Decryptor = CBC.extend({
|
||||
/**
|
||||
* Processes the data block at offset.
|
||||
*
|
||||
* @param {Array} words The data words to operate on.
|
||||
* @param {number} offset The offset where the block starts.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* mode.processBlock(data.words, offset);
|
||||
*/
|
||||
processBlock: function (words, offset) {
|
||||
// Shortcuts
|
||||
var cipher = this._cipher;
|
||||
var blockSize = cipher.blockSize;
|
||||
|
||||
// Remember this block to use with next block
|
||||
var thisBlock = words.slice(offset, offset + blockSize);
|
||||
|
||||
// Decrypt and XOR
|
||||
cipher.decryptBlock(words, offset);
|
||||
xorBlock.call(this, words, offset, blockSize);
|
||||
|
||||
// This block becomes the previous block
|
||||
this._prevBlock = thisBlock;
|
||||
}
|
||||
});
|
||||
|
||||
function xorBlock(words, offset, blockSize) {
|
||||
// Shortcut
|
||||
var iv = this._iv;
|
||||
|
||||
// Choose mixing block
|
||||
if (iv) {
|
||||
var block = iv;
|
||||
|
||||
// Remove IV for subsequent blocks
|
||||
this._iv = undefined;
|
||||
} else {
|
||||
var block = this._prevBlock;
|
||||
}
|
||||
|
||||
// XOR blocks
|
||||
for (var i = 0; i < blockSize; i++) {
|
||||
words[offset + i] ^= block[i];
|
||||
}
|
||||
}
|
||||
|
||||
return CBC;
|
||||
}());
|
||||
|
||||
/**
|
||||
* Padding namespace.
|
||||
*/
|
||||
var C_pad = C.pad = {};
|
||||
|
||||
/**
|
||||
* PKCS #5/7 padding strategy.
|
||||
*/
|
||||
var Pkcs7 = C_pad.Pkcs7 = {
|
||||
/**
|
||||
* Pads data using the algorithm defined in PKCS #5/7.
|
||||
*
|
||||
* @param {WordArray} data The data to pad.
|
||||
* @param {number} blockSize The multiple that the data should be padded to.
|
||||
*
|
||||
* @static
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* CryptoJS.pad.Pkcs7.pad(wordArray, 4);
|
||||
*/
|
||||
pad: function (data, blockSize) {
|
||||
// Shortcut
|
||||
var blockSizeBytes = blockSize * 4;
|
||||
|
||||
// Count padding bytes
|
||||
var nPaddingBytes = blockSizeBytes - data.sigBytes % blockSizeBytes;
|
||||
|
||||
// Create padding word
|
||||
var paddingWord = (nPaddingBytes << 24) | (nPaddingBytes << 16) | (nPaddingBytes << 8) | nPaddingBytes;
|
||||
|
||||
// Create padding
|
||||
var paddingWords = [];
|
||||
for (var i = 0; i < nPaddingBytes; i += 4) {
|
||||
paddingWords.push(paddingWord);
|
||||
}
|
||||
var padding = WordArray.create(paddingWords, nPaddingBytes);
|
||||
|
||||
// Add padding
|
||||
data.concat(padding);
|
||||
},
|
||||
|
||||
/**
|
||||
* Unpads data that had been padded using the algorithm defined in PKCS #5/7.
|
||||
*
|
||||
* @param {WordArray} data The data to unpad.
|
||||
*
|
||||
* @static
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* CryptoJS.pad.Pkcs7.unpad(wordArray);
|
||||
*/
|
||||
unpad: function (data) {
|
||||
// Get number of padding bytes from last byte
|
||||
var nPaddingBytes = data.words[(data.sigBytes - 1) >>> 2] & 0xff;
|
||||
|
||||
// Remove padding
|
||||
data.sigBytes -= nPaddingBytes;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Abstract base block cipher template.
|
||||
*
|
||||
* @property {number} blockSize The number of 32-bit words this cipher operates on. Default: 4 (128 bits)
|
||||
*/
|
||||
var BlockCipher = C_lib.BlockCipher = Cipher.extend({
|
||||
/**
|
||||
* Configuration options.
|
||||
*
|
||||
* @property {Mode} mode The block mode to use. Default: CBC
|
||||
* @property {Padding} padding The padding strategy to use. Default: Pkcs7
|
||||
*/
|
||||
cfg: Cipher.cfg.extend({
|
||||
mode: CBC,
|
||||
padding: Pkcs7
|
||||
}),
|
||||
|
||||
reset: function () {
|
||||
// Reset cipher
|
||||
Cipher.reset.call(this);
|
||||
|
||||
// Shortcuts
|
||||
var cfg = this.cfg;
|
||||
var iv = cfg.iv;
|
||||
var mode = cfg.mode;
|
||||
|
||||
// Reset block mode
|
||||
if (this._xformMode == this._ENC_XFORM_MODE) {
|
||||
var modeCreator = mode.createEncryptor;
|
||||
} else /* if (this._xformMode == this._DEC_XFORM_MODE) */ {
|
||||
var modeCreator = mode.createDecryptor;
|
||||
|
||||
// Keep at least one block in the buffer for unpadding
|
||||
this._minBufferSize = 1;
|
||||
}
|
||||
this._mode = modeCreator.call(mode, this, iv && iv.words);
|
||||
},
|
||||
|
||||
_doProcessBlock: function (words, offset) {
|
||||
this._mode.processBlock(words, offset);
|
||||
},
|
||||
|
||||
_doFinalize: function () {
|
||||
// Shortcut
|
||||
var padding = this.cfg.padding;
|
||||
|
||||
// Finalize
|
||||
if (this._xformMode == this._ENC_XFORM_MODE) {
|
||||
// Pad data
|
||||
padding.pad(this._data, this.blockSize);
|
||||
|
||||
// Process final blocks
|
||||
var finalProcessedBlocks = this._process(!!'flush');
|
||||
} else /* if (this._xformMode == this._DEC_XFORM_MODE) */ {
|
||||
// Process final blocks
|
||||
var finalProcessedBlocks = this._process(!!'flush');
|
||||
|
||||
// Unpad data
|
||||
padding.unpad(finalProcessedBlocks);
|
||||
}
|
||||
|
||||
return finalProcessedBlocks;
|
||||
},
|
||||
|
||||
blockSize: 128/32
|
||||
});
|
||||
|
||||
/**
|
||||
* A collection of cipher parameters.
|
||||
*
|
||||
* @property {WordArray} ciphertext The raw ciphertext.
|
||||
* @property {WordArray} key The key to this ciphertext.
|
||||
* @property {WordArray} iv The IV used in the ciphering operation.
|
||||
* @property {WordArray} salt The salt used with a key derivation function.
|
||||
* @property {Cipher} algorithm The cipher algorithm.
|
||||
* @property {Mode} mode The block mode used in the ciphering operation.
|
||||
* @property {Padding} padding The padding scheme used in the ciphering operation.
|
||||
* @property {number} blockSize The block size of the cipher.
|
||||
* @property {Format} formatter The default formatting strategy to convert this cipher params object to a string.
|
||||
*/
|
||||
var CipherParams = C_lib.CipherParams = Base.extend({
|
||||
/**
|
||||
* Initializes a newly created cipher params object.
|
||||
*
|
||||
* @param {Object} cipherParams An object with any of the possible cipher parameters.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* var cipherParams = CryptoJS.lib.CipherParams.create({
|
||||
* ciphertext: ciphertextWordArray,
|
||||
* key: keyWordArray,
|
||||
* iv: ivWordArray,
|
||||
* salt: saltWordArray,
|
||||
* algorithm: CryptoJS.algo.AES,
|
||||
* mode: CryptoJS.mode.CBC,
|
||||
* padding: CryptoJS.pad.PKCS7,
|
||||
* blockSize: 4,
|
||||
* formatter: CryptoJS.format.OpenSSL
|
||||
* });
|
||||
*/
|
||||
init: function (cipherParams) {
|
||||
this.mixIn(cipherParams);
|
||||
},
|
||||
|
||||
/**
|
||||
* Converts this cipher params object to a string.
|
||||
*
|
||||
* @param {Format} formatter (Optional) The formatting strategy to use.
|
||||
*
|
||||
* @return {string} The stringified cipher params.
|
||||
*
|
||||
* @throws Error If neither the formatter nor the default formatter is set.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* var string = cipherParams + '';
|
||||
* var string = cipherParams.toString();
|
||||
* var string = cipherParams.toString(CryptoJS.format.OpenSSL);
|
||||
*/
|
||||
toString: function (formatter) {
|
||||
return (formatter || this.formatter).stringify(this);
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Format namespace.
|
||||
*/
|
||||
var C_format = C.format = {};
|
||||
|
||||
/**
|
||||
* OpenSSL formatting strategy.
|
||||
*/
|
||||
var OpenSSLFormatter = C_format.OpenSSL = {
|
||||
/**
|
||||
* Converts a cipher params object to an OpenSSL-compatible string.
|
||||
*
|
||||
* @param {CipherParams} cipherParams The cipher params object.
|
||||
*
|
||||
* @return {string} The OpenSSL-compatible string.
|
||||
*
|
||||
* @static
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* var openSSLString = CryptoJS.format.OpenSSL.stringify(cipherParams);
|
||||
*/
|
||||
stringify: function (cipherParams) {
|
||||
// Shortcuts
|
||||
var ciphertext = cipherParams.ciphertext;
|
||||
var salt = cipherParams.salt;
|
||||
|
||||
// Format
|
||||
if (salt) {
|
||||
var wordArray = WordArray.create([0x53616c74, 0x65645f5f]).concat(salt).concat(ciphertext);
|
||||
} else {
|
||||
var wordArray = ciphertext;
|
||||
}
|
||||
|
||||
return wordArray.toString(Base64);
|
||||
},
|
||||
|
||||
/**
|
||||
* Converts an OpenSSL-compatible string to a cipher params object.
|
||||
*
|
||||
* @param {string} openSSLStr The OpenSSL-compatible string.
|
||||
*
|
||||
* @return {CipherParams} The cipher params object.
|
||||
*
|
||||
* @static
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* var cipherParams = CryptoJS.format.OpenSSL.parse(openSSLString);
|
||||
*/
|
||||
parse: function (openSSLStr) {
|
||||
// Parse base64
|
||||
var ciphertext = Base64.parse(openSSLStr);
|
||||
|
||||
// Shortcut
|
||||
var ciphertextWords = ciphertext.words;
|
||||
|
||||
// Test for salt
|
||||
if (ciphertextWords[0] == 0x53616c74 && ciphertextWords[1] == 0x65645f5f) {
|
||||
// Extract salt
|
||||
var salt = WordArray.create(ciphertextWords.slice(2, 4));
|
||||
|
||||
// Remove salt from ciphertext
|
||||
ciphertextWords.splice(0, 4);
|
||||
ciphertext.sigBytes -= 16;
|
||||
}
|
||||
|
||||
return CipherParams.create({ ciphertext: ciphertext, salt: salt });
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* A cipher wrapper that returns ciphertext as a serializable cipher params object.
|
||||
*/
|
||||
var SerializableCipher = C_lib.SerializableCipher = Base.extend({
|
||||
/**
|
||||
* Configuration options.
|
||||
*
|
||||
* @property {Formatter} format The formatting strategy to convert cipher param objects to and from a string. Default: OpenSSL
|
||||
*/
|
||||
cfg: Base.extend({
|
||||
format: OpenSSLFormatter
|
||||
}),
|
||||
|
||||
/**
|
||||
* Encrypts a message.
|
||||
*
|
||||
* @param {Cipher} cipher The cipher algorithm to use.
|
||||
* @param {WordArray|string} message The message to encrypt.
|
||||
* @param {WordArray} key The key.
|
||||
* @param {Object} cfg (Optional) The configuration options to use for this operation.
|
||||
*
|
||||
* @return {CipherParams} A cipher params object.
|
||||
*
|
||||
* @static
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key);
|
||||
* var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key, { iv: iv });
|
||||
* var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key, { iv: iv, format: CryptoJS.format.OpenSSL });
|
||||
*/
|
||||
encrypt: function (cipher, message, key, cfg) {
|
||||
// Apply config defaults
|
||||
cfg = this.cfg.extend(cfg);
|
||||
|
||||
// Encrypt
|
||||
var encryptor = cipher.createEncryptor(key, cfg);
|
||||
var ciphertext = encryptor.finalize(message);
|
||||
|
||||
// Shortcut
|
||||
var cipherCfg = encryptor.cfg;
|
||||
|
||||
// Create and return serializable cipher params
|
||||
return CipherParams.create({
|
||||
ciphertext: ciphertext,
|
||||
key: key,
|
||||
iv: cipherCfg.iv,
|
||||
algorithm: cipher,
|
||||
mode: cipherCfg.mode,
|
||||
padding: cipherCfg.padding,
|
||||
blockSize: cipher.blockSize,
|
||||
formatter: cfg.format
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Decrypts serialized ciphertext.
|
||||
*
|
||||
* @param {Cipher} cipher The cipher algorithm to use.
|
||||
* @param {CipherParams|string} ciphertext The ciphertext to decrypt.
|
||||
* @param {WordArray} key The key.
|
||||
* @param {Object} cfg (Optional) The configuration options to use for this operation.
|
||||
*
|
||||
* @return {WordArray} The plaintext.
|
||||
*
|
||||
* @static
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* var plaintext = CryptoJS.lib.SerializableCipher.decrypt(CryptoJS.algo.AES, formattedCiphertext, key, { iv: iv, format: CryptoJS.format.OpenSSL });
|
||||
* var plaintext = CryptoJS.lib.SerializableCipher.decrypt(CryptoJS.algo.AES, ciphertextParams, key, { iv: iv, format: CryptoJS.format.OpenSSL });
|
||||
*/
|
||||
decrypt: function (cipher, ciphertext, key, cfg) {
|
||||
// Apply config defaults
|
||||
cfg = this.cfg.extend(cfg);
|
||||
|
||||
// Convert string to CipherParams
|
||||
ciphertext = this._parse(ciphertext, cfg.format);
|
||||
|
||||
// Decrypt
|
||||
var plaintext = cipher.createDecryptor(key, cfg).finalize(ciphertext.ciphertext);
|
||||
|
||||
return plaintext;
|
||||
},
|
||||
|
||||
/**
|
||||
* Converts serialized ciphertext to CipherParams,
|
||||
* else assumed CipherParams already and returns ciphertext unchanged.
|
||||
*
|
||||
* @param {CipherParams|string} ciphertext The ciphertext.
|
||||
* @param {Formatter} format The formatting strategy to use to parse serialized ciphertext.
|
||||
*
|
||||
* @return {CipherParams} The unserialized ciphertext.
|
||||
*
|
||||
* @static
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* var ciphertextParams = CryptoJS.lib.SerializableCipher._parse(ciphertextStringOrParams, format);
|
||||
*/
|
||||
_parse: function (ciphertext, format) {
|
||||
if (typeof ciphertext == 'string') {
|
||||
return format.parse(ciphertext, this);
|
||||
} else {
|
||||
return ciphertext;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Key derivation function namespace.
|
||||
*/
|
||||
var C_kdf = C.kdf = {};
|
||||
|
||||
/**
|
||||
* OpenSSL key derivation function.
|
||||
*/
|
||||
var OpenSSLKdf = C_kdf.OpenSSL = {
|
||||
/**
|
||||
* Derives a key and IV from a password.
|
||||
*
|
||||
* @param {string} password The password to derive from.
|
||||
* @param {number} keySize The size in words of the key to generate.
|
||||
* @param {number} ivSize The size in words of the IV to generate.
|
||||
* @param {WordArray|string} salt (Optional) A 64-bit salt to use. If omitted, a salt will be generated randomly.
|
||||
*
|
||||
* @return {CipherParams} A cipher params object with the key, IV, and salt.
|
||||
*
|
||||
* @static
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* var derivedParams = CryptoJS.kdf.OpenSSL.execute('Password', 256/32, 128/32);
|
||||
* var derivedParams = CryptoJS.kdf.OpenSSL.execute('Password', 256/32, 128/32, 'saltsalt');
|
||||
*/
|
||||
execute: function (password, keySize, ivSize, salt) {
|
||||
// Generate random salt
|
||||
if (!salt) {
|
||||
salt = WordArray.random(64/8);
|
||||
}
|
||||
|
||||
// Derive key and IV
|
||||
var key = EvpKDF.create({ keySize: keySize + ivSize }).compute(password, salt);
|
||||
|
||||
// Separate key and IV
|
||||
var iv = WordArray.create(key.words.slice(keySize), ivSize * 4);
|
||||
key.sigBytes = keySize * 4;
|
||||
|
||||
// Return params
|
||||
return CipherParams.create({ key: key, iv: iv, salt: salt });
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* A serializable cipher wrapper that derives the key from a password,
|
||||
* and returns ciphertext as a serializable cipher params object.
|
||||
*/
|
||||
var PasswordBasedCipher = C_lib.PasswordBasedCipher = SerializableCipher.extend({
|
||||
/**
|
||||
* Configuration options.
|
||||
*
|
||||
* @property {KDF} kdf The key derivation function to use to generate a key and IV from a password. Default: OpenSSL
|
||||
*/
|
||||
cfg: SerializableCipher.cfg.extend({
|
||||
kdf: OpenSSLKdf
|
||||
}),
|
||||
|
||||
/**
|
||||
* Encrypts a message using a password.
|
||||
*
|
||||
* @param {Cipher} cipher The cipher algorithm to use.
|
||||
* @param {WordArray|string} message The message to encrypt.
|
||||
* @param {string} password The password.
|
||||
* @param {Object} cfg (Optional) The configuration options to use for this operation.
|
||||
*
|
||||
* @return {CipherParams} A cipher params object.
|
||||
*
|
||||
* @static
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* var ciphertextParams = CryptoJS.lib.PasswordBasedCipher.encrypt(CryptoJS.algo.AES, message, 'password');
|
||||
* var ciphertextParams = CryptoJS.lib.PasswordBasedCipher.encrypt(CryptoJS.algo.AES, message, 'password', { format: CryptoJS.format.OpenSSL });
|
||||
*/
|
||||
encrypt: function (cipher, message, password, cfg) {
|
||||
// Apply config defaults
|
||||
cfg = this.cfg.extend(cfg);
|
||||
|
||||
// Derive key and other params
|
||||
// MODIFIED: added cfg.salt param
|
||||
var derivedParams = cfg.kdf.execute(password, cipher.keySize, cipher.ivSize, cfg.salt);
|
||||
|
||||
// Add IV to config
|
||||
cfg.iv = derivedParams.iv;
|
||||
|
||||
// Encrypt
|
||||
var ciphertext = SerializableCipher.encrypt.call(this, cipher, message, derivedParams.key, cfg);
|
||||
|
||||
// Mix in derived params
|
||||
ciphertext.mixIn(derivedParams);
|
||||
|
||||
return ciphertext;
|
||||
},
|
||||
|
||||
/**
|
||||
* Decrypts serialized ciphertext using a password.
|
||||
*
|
||||
* @param {Cipher} cipher The cipher algorithm to use.
|
||||
* @param {CipherParams|string} ciphertext The ciphertext to decrypt.
|
||||
* @param {string} password The password.
|
||||
* @param {Object} cfg (Optional) The configuration options to use for this operation.
|
||||
*
|
||||
* @return {WordArray} The plaintext.
|
||||
*
|
||||
* @static
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* var plaintext = CryptoJS.lib.PasswordBasedCipher.decrypt(CryptoJS.algo.AES, formattedCiphertext, 'password', { format: CryptoJS.format.OpenSSL });
|
||||
* var plaintext = CryptoJS.lib.PasswordBasedCipher.decrypt(CryptoJS.algo.AES, ciphertextParams, 'password', { format: CryptoJS.format.OpenSSL });
|
||||
*/
|
||||
decrypt: function (cipher, ciphertext, password, cfg) {
|
||||
// Apply config defaults
|
||||
cfg = this.cfg.extend(cfg);
|
||||
|
||||
// Convert string to CipherParams
|
||||
ciphertext = this._parse(ciphertext, cfg.format);
|
||||
|
||||
// Derive key and other params
|
||||
var derivedParams = cfg.kdf.execute(password, cipher.keySize, cipher.ivSize, ciphertext.salt);
|
||||
|
||||
// Add IV to config
|
||||
cfg.iv = derivedParams.iv;
|
||||
|
||||
// Decrypt
|
||||
var plaintext = SerializableCipher.decrypt.call(this, cipher, ciphertext, derivedParams.key, cfg);
|
||||
|
||||
return plaintext;
|
||||
}
|
||||
});
|
||||
}());
|
@ -1,713 +0,0 @@
|
||||
/** @license
|
||||
========================================================================
|
||||
CryptoJS v3.1.2
|
||||
code.google.com/p/crypto-js
|
||||
(c) 2009-2013 by Jeff Mott. All rights reserved.
|
||||
code.google.com/p/crypto-js/wiki/License
|
||||
*/
|
||||
/**
|
||||
* CryptoJS core components.
|
||||
*/
|
||||
var CryptoJS = CryptoJS || (function (Math, undefined) {
|
||||
/**
|
||||
* CryptoJS namespace.
|
||||
*/
|
||||
var C = {};
|
||||
|
||||
/**
|
||||
* Library namespace.
|
||||
*/
|
||||
var C_lib = C.lib = {};
|
||||
|
||||
/**
|
||||
* Base object for prototypal inheritance.
|
||||
*/
|
||||
var Base = C_lib.Base = (function () {
|
||||
function F() {}
|
||||
|
||||
return {
|
||||
/**
|
||||
* Creates a new object that inherits from this object.
|
||||
*
|
||||
* @param {Object} overrides Properties to copy into the new object.
|
||||
*
|
||||
* @return {Object} The new object.
|
||||
*
|
||||
* @static
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* var MyType = CryptoJS.lib.Base.extend({
|
||||
* field: 'value',
|
||||
*
|
||||
* method: function () {
|
||||
* }
|
||||
* });
|
||||
*/
|
||||
extend: function (overrides) {
|
||||
// Spawn
|
||||
F.prototype = this;
|
||||
var subtype = new F();
|
||||
|
||||
// Augment
|
||||
if (overrides) {
|
||||
subtype.mixIn(overrides);
|
||||
}
|
||||
|
||||
// Create default initializer
|
||||
if (!subtype.hasOwnProperty('init')) {
|
||||
subtype.init = function () {
|
||||
subtype.$super.init.apply(this, arguments);
|
||||
};
|
||||
}
|
||||
|
||||
// Initializer's prototype is the subtype object
|
||||
subtype.init.prototype = subtype;
|
||||
|
||||
// Reference supertype
|
||||
subtype.$super = this;
|
||||
|
||||
return subtype;
|
||||
},
|
||||
|
||||
/**
|
||||
* Extends this object and runs the init method.
|
||||
* Arguments to create() will be passed to init().
|
||||
*
|
||||
* @return {Object} The new object.
|
||||
*
|
||||
* @static
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* var instance = MyType.create();
|
||||
*/
|
||||
create: function () {
|
||||
var instance = this.extend();
|
||||
instance.init.apply(instance, arguments);
|
||||
|
||||
return instance;
|
||||
},
|
||||
|
||||
/**
|
||||
* Initializes a newly created object.
|
||||
* Override this method to add some logic when your objects are created.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* var MyType = CryptoJS.lib.Base.extend({
|
||||
* init: function () {
|
||||
* // ...
|
||||
* }
|
||||
* });
|
||||
*/
|
||||
init: function () {
|
||||
},
|
||||
|
||||
/**
|
||||
* Copies properties into this object.
|
||||
*
|
||||
* @param {Object} properties The properties to mix in.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* MyType.mixIn({
|
||||
* field: 'value'
|
||||
* });
|
||||
*/
|
||||
mixIn: function (properties) {
|
||||
for (var propertyName in properties) {
|
||||
if (properties.hasOwnProperty(propertyName)) {
|
||||
this[propertyName] = properties[propertyName];
|
||||
}
|
||||
}
|
||||
|
||||
// IE won't copy toString using the loop above
|
||||
if (properties.hasOwnProperty('toString')) {
|
||||
this.toString = properties.toString;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Creates a copy of this object.
|
||||
*
|
||||
* @return {Object} The clone.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* var clone = instance.clone();
|
||||
*/
|
||||
clone: function () {
|
||||
return this.init.prototype.extend(this);
|
||||
}
|
||||
};
|
||||
}());
|
||||
|
||||
/**
|
||||
* An array of 32-bit words.
|
||||
*
|
||||
* @property {Array} words The array of 32-bit words.
|
||||
* @property {number} sigBytes The number of significant bytes in this word array.
|
||||
*/
|
||||
var WordArray = C_lib.WordArray = Base.extend({
|
||||
/**
|
||||
* Initializes a newly created word array.
|
||||
*
|
||||
* @param {Array} words (Optional) An array of 32-bit words.
|
||||
* @param {number} sigBytes (Optional) The number of significant bytes in the words.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* var wordArray = CryptoJS.lib.WordArray.create();
|
||||
* var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607]);
|
||||
* var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607], 6);
|
||||
*/
|
||||
init: function (words, sigBytes) {
|
||||
words = this.words = words || [];
|
||||
|
||||
if (sigBytes != undefined) {
|
||||
this.sigBytes = sigBytes;
|
||||
} else {
|
||||
this.sigBytes = words.length * 4;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Converts this word array to a string.
|
||||
*
|
||||
* @param {Encoder} encoder (Optional) The encoding strategy to use. Default: CryptoJS.enc.Hex
|
||||
*
|
||||
* @return {string} The stringified word array.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* var string = wordArray + '';
|
||||
* var string = wordArray.toString();
|
||||
* var string = wordArray.toString(CryptoJS.enc.Utf8);
|
||||
*/
|
||||
toString: function (encoder) {
|
||||
return (encoder || Hex).stringify(this);
|
||||
},
|
||||
|
||||
/**
|
||||
* Concatenates a word array to this word array.
|
||||
*
|
||||
* @param {WordArray} wordArray The word array to append.
|
||||
*
|
||||
* @return {WordArray} This word array.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* wordArray1.concat(wordArray2);
|
||||
*/
|
||||
concat: function (wordArray) {
|
||||
// Shortcuts
|
||||
var thisWords = this.words;
|
||||
var thatWords = wordArray.words;
|
||||
var thisSigBytes = this.sigBytes;
|
||||
var thatSigBytes = wordArray.sigBytes;
|
||||
|
||||
// Clamp excess bits
|
||||
this.clamp();
|
||||
|
||||
// Concat
|
||||
if (thisSigBytes % 4) {
|
||||
// Copy one byte at a time
|
||||
for (var i = 0; i < thatSigBytes; i++) {
|
||||
var thatByte = (thatWords[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff;
|
||||
thisWords[(thisSigBytes + i) >>> 2] |= thatByte << (24 - ((thisSigBytes + i) % 4) * 8);
|
||||
}
|
||||
} else if (thatWords.length > 0xffff) {
|
||||
// Copy one word at a time
|
||||
for (var i = 0; i < thatSigBytes; i += 4) {
|
||||
thisWords[(thisSigBytes + i) >>> 2] = thatWords[i >>> 2];
|
||||
}
|
||||
} else {
|
||||
// Copy all words at once
|
||||
thisWords.push.apply(thisWords, thatWords);
|
||||
}
|
||||
this.sigBytes += thatSigBytes;
|
||||
|
||||
// Chainable
|
||||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* Removes insignificant bits.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* wordArray.clamp();
|
||||
*/
|
||||
clamp: function () {
|
||||
// Shortcuts
|
||||
var words = this.words;
|
||||
var sigBytes = this.sigBytes;
|
||||
|
||||
// Clamp
|
||||
words[sigBytes >>> 2] &= 0xffffffff << (32 - (sigBytes % 4) * 8);
|
||||
words.length = Math.ceil(sigBytes / 4);
|
||||
},
|
||||
|
||||
/**
|
||||
* Creates a copy of this word array.
|
||||
*
|
||||
* @return {WordArray} The clone.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* var clone = wordArray.clone();
|
||||
*/
|
||||
clone: function () {
|
||||
var clone = Base.clone.call(this);
|
||||
clone.words = this.words.slice(0);
|
||||
|
||||
return clone;
|
||||
},
|
||||
|
||||
/**
|
||||
* Creates a word array filled with random bytes.
|
||||
*
|
||||
* @param {number} nBytes The number of random bytes to generate.
|
||||
*
|
||||
* @return {WordArray} The random word array.
|
||||
*
|
||||
* @static
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* var wordArray = CryptoJS.lib.WordArray.random(16);
|
||||
*/
|
||||
random: function (nBytes) {
|
||||
var words = [];
|
||||
for (var i = 0; i < nBytes; i += 4) {
|
||||
words.push((Math.random() * 0x100000000) | 0);
|
||||
}
|
||||
|
||||
return new WordArray.init(words, nBytes);
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Encoder namespace.
|
||||
*/
|
||||
var C_enc = C.enc = {};
|
||||
|
||||
/**
|
||||
* Hex encoding strategy.
|
||||
*/
|
||||
var Hex = C_enc.Hex = {
|
||||
/**
|
||||
* Converts a word array to a hex string.
|
||||
*
|
||||
* @param {WordArray} wordArray The word array.
|
||||
*
|
||||
* @return {string} The hex string.
|
||||
*
|
||||
* @static
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* var hexString = CryptoJS.enc.Hex.stringify(wordArray);
|
||||
*/
|
||||
stringify: function (wordArray) {
|
||||
// Shortcuts
|
||||
var words = wordArray.words;
|
||||
var sigBytes = wordArray.sigBytes;
|
||||
|
||||
// Convert
|
||||
var hexChars = [];
|
||||
for (var i = 0; i < sigBytes; i++) {
|
||||
var bite = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff;
|
||||
hexChars.push((bite >>> 4).toString(16));
|
||||
hexChars.push((bite & 0x0f).toString(16));
|
||||
}
|
||||
|
||||
return hexChars.join('');
|
||||
},
|
||||
|
||||
/**
|
||||
* Converts a hex string to a word array.
|
||||
*
|
||||
* @param {string} hexStr The hex string.
|
||||
*
|
||||
* @return {WordArray} The word array.
|
||||
*
|
||||
* @static
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* var wordArray = CryptoJS.enc.Hex.parse(hexString);
|
||||
*/
|
||||
parse: function (hexStr) {
|
||||
// Shortcut
|
||||
var hexStrLength = hexStr.length;
|
||||
|
||||
// Convert
|
||||
var words = [];
|
||||
for (var i = 0; i < hexStrLength; i += 2) {
|
||||
words[i >>> 3] |= parseInt(hexStr.substr(i, 2), 16) << (24 - (i % 8) * 4);
|
||||
}
|
||||
|
||||
return new WordArray.init(words, hexStrLength / 2);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Latin1 encoding strategy.
|
||||
*/
|
||||
var Latin1 = C_enc.Latin1 = {
|
||||
/**
|
||||
* Converts a word array to a Latin1 string.
|
||||
*
|
||||
* @param {WordArray} wordArray The word array.
|
||||
*
|
||||
* @return {string} The Latin1 string.
|
||||
*
|
||||
* @static
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* var latin1String = CryptoJS.enc.Latin1.stringify(wordArray);
|
||||
*/
|
||||
stringify: function (wordArray) {
|
||||
// Shortcuts
|
||||
var words = wordArray.words;
|
||||
var sigBytes = wordArray.sigBytes;
|
||||
|
||||
// Convert
|
||||
var latin1Chars = [];
|
||||
for (var i = 0; i < sigBytes; i++) {
|
||||
var bite = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff;
|
||||
latin1Chars.push(String.fromCharCode(bite));
|
||||
}
|
||||
|
||||
return latin1Chars.join('');
|
||||
},
|
||||
|
||||
/**
|
||||
* Converts a Latin1 string to a word array.
|
||||
*
|
||||
* @param {string} latin1Str The Latin1 string.
|
||||
*
|
||||
* @return {WordArray} The word array.
|
||||
*
|
||||
* @static
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* var wordArray = CryptoJS.enc.Latin1.parse(latin1String);
|
||||
*/
|
||||
parse: function (latin1Str) {
|
||||
// Shortcut
|
||||
var latin1StrLength = latin1Str.length;
|
||||
|
||||
// Convert
|
||||
var words = [];
|
||||
for (var i = 0; i < latin1StrLength; i++) {
|
||||
words[i >>> 2] |= (latin1Str.charCodeAt(i) & 0xff) << (24 - (i % 4) * 8);
|
||||
}
|
||||
|
||||
return new WordArray.init(words, latin1StrLength);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* UTF-8 encoding strategy.
|
||||
*/
|
||||
var Utf8 = C_enc.Utf8 = {
|
||||
/**
|
||||
* Converts a word array to a UTF-8 string.
|
||||
*
|
||||
* @param {WordArray} wordArray The word array.
|
||||
*
|
||||
* @return {string} The UTF-8 string.
|
||||
*
|
||||
* @static
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* var utf8String = CryptoJS.enc.Utf8.stringify(wordArray);
|
||||
*/
|
||||
stringify: function (wordArray) {
|
||||
try {
|
||||
return decodeURIComponent(escape(Latin1.stringify(wordArray)));
|
||||
} catch (e) {
|
||||
throw new Error('Malformed UTF-8 data');
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Converts a UTF-8 string to a word array.
|
||||
*
|
||||
* @param {string} utf8Str The UTF-8 string.
|
||||
*
|
||||
* @return {WordArray} The word array.
|
||||
*
|
||||
* @static
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* var wordArray = CryptoJS.enc.Utf8.parse(utf8String);
|
||||
*/
|
||||
parse: function (utf8Str) {
|
||||
return Latin1.parse(unescape(encodeURIComponent(utf8Str)));
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Abstract buffered block algorithm template.
|
||||
*
|
||||
* The property blockSize must be implemented in a concrete subtype.
|
||||
*
|
||||
* @property {number} _minBufferSize The number of blocks that should be kept unprocessed in the buffer. Default: 0
|
||||
*/
|
||||
var BufferedBlockAlgorithm = C_lib.BufferedBlockAlgorithm = Base.extend({
|
||||
/**
|
||||
* Resets this block algorithm's data buffer to its initial state.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* bufferedBlockAlgorithm.reset();
|
||||
*/
|
||||
reset: function () {
|
||||
// Initial values
|
||||
this._data = new WordArray.init();
|
||||
this._nDataBytes = 0;
|
||||
},
|
||||
|
||||
/**
|
||||
* Adds new data to this block algorithm's buffer.
|
||||
*
|
||||
* @param {WordArray|string} data The data to append. Strings are converted to a WordArray using UTF-8.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* bufferedBlockAlgorithm._append('data');
|
||||
* bufferedBlockAlgorithm._append(wordArray);
|
||||
*/
|
||||
_append: function (data) {
|
||||
// Convert string to WordArray, else assume WordArray already
|
||||
if (typeof data == 'string') {
|
||||
data = Utf8.parse(data);
|
||||
}
|
||||
|
||||
// Append
|
||||
this._data.concat(data);
|
||||
this._nDataBytes += data.sigBytes;
|
||||
},
|
||||
|
||||
/**
|
||||
* Processes available data blocks.
|
||||
*
|
||||
* This method invokes _doProcessBlock(offset), which must be implemented by a concrete subtype.
|
||||
*
|
||||
* @param {boolean} doFlush Whether all blocks and partial blocks should be processed.
|
||||
*
|
||||
* @return {WordArray} The processed data.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* var processedData = bufferedBlockAlgorithm._process();
|
||||
* var processedData = bufferedBlockAlgorithm._process(!!'flush');
|
||||
*/
|
||||
_process: function (doFlush) {
|
||||
// Shortcuts
|
||||
var data = this._data;
|
||||
var dataWords = data.words;
|
||||
var dataSigBytes = data.sigBytes;
|
||||
var blockSize = this.blockSize;
|
||||
var blockSizeBytes = blockSize * 4;
|
||||
|
||||
// Count blocks ready
|
||||
var nBlocksReady = dataSigBytes / blockSizeBytes;
|
||||
if (doFlush) {
|
||||
// Round up to include partial blocks
|
||||
nBlocksReady = Math.ceil(nBlocksReady);
|
||||
} else {
|
||||
// Round down to include only full blocks,
|
||||
// less the number of blocks that must remain in the buffer
|
||||
nBlocksReady = Math.max((nBlocksReady | 0) - this._minBufferSize, 0);
|
||||
}
|
||||
|
||||
// Count words ready
|
||||
var nWordsReady = nBlocksReady * blockSize;
|
||||
|
||||
// Count bytes ready
|
||||
var nBytesReady = Math.min(nWordsReady * 4, dataSigBytes);
|
||||
|
||||
// Process blocks
|
||||
if (nWordsReady) {
|
||||
for (var offset = 0; offset < nWordsReady; offset += blockSize) {
|
||||
// Perform concrete-algorithm logic
|
||||
this._doProcessBlock(dataWords, offset);
|
||||
}
|
||||
|
||||
// Remove processed words
|
||||
var processedWords = dataWords.splice(0, nWordsReady);
|
||||
data.sigBytes -= nBytesReady;
|
||||
}
|
||||
|
||||
// Return processed words
|
||||
return new WordArray.init(processedWords, nBytesReady);
|
||||
},
|
||||
|
||||
/**
|
||||
* Creates a copy of this object.
|
||||
*
|
||||
* @return {Object} The clone.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* var clone = bufferedBlockAlgorithm.clone();
|
||||
*/
|
||||
clone: function () {
|
||||
var clone = Base.clone.call(this);
|
||||
clone._data = this._data.clone();
|
||||
|
||||
return clone;
|
||||
},
|
||||
|
||||
_minBufferSize: 0
|
||||
});
|
||||
|
||||
/**
|
||||
* Abstract hasher template.
|
||||
*
|
||||
* @property {number} blockSize The number of 32-bit words this hasher operates on. Default: 16 (512 bits)
|
||||
*/
|
||||
var Hasher = C_lib.Hasher = BufferedBlockAlgorithm.extend({
|
||||
/**
|
||||
* Configuration options.
|
||||
*/
|
||||
cfg: Base.extend(),
|
||||
|
||||
/**
|
||||
* Initializes a newly created hasher.
|
||||
*
|
||||
* @param {Object} cfg (Optional) The configuration options to use for this hash computation.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* var hasher = CryptoJS.algo.SHA256.create();
|
||||
*/
|
||||
init: function (cfg) {
|
||||
// Apply config defaults
|
||||
this.cfg = this.cfg.extend(cfg);
|
||||
|
||||
// Set initial values
|
||||
this.reset();
|
||||
},
|
||||
|
||||
/**
|
||||
* Resets this hasher to its initial state.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* hasher.reset();
|
||||
*/
|
||||
reset: function () {
|
||||
// Reset data buffer
|
||||
BufferedBlockAlgorithm.reset.call(this);
|
||||
|
||||
// Perform concrete-hasher logic
|
||||
this._doReset();
|
||||
},
|
||||
|
||||
/**
|
||||
* Updates this hasher with a message.
|
||||
*
|
||||
* @param {WordArray|string} messageUpdate The message to append.
|
||||
*
|
||||
* @return {Hasher} This hasher.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* hasher.update('message');
|
||||
* hasher.update(wordArray);
|
||||
*/
|
||||
update: function (messageUpdate) {
|
||||
// Append
|
||||
this._append(messageUpdate);
|
||||
|
||||
// Update the hash
|
||||
this._process();
|
||||
|
||||
// Chainable
|
||||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* Finalizes the hash computation.
|
||||
* Note that the finalize operation is effectively a destructive, read-once operation.
|
||||
*
|
||||
* @param {WordArray|string} messageUpdate (Optional) A final message update.
|
||||
*
|
||||
* @return {WordArray} The hash.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* var hash = hasher.finalize();
|
||||
* var hash = hasher.finalize('message');
|
||||
* var hash = hasher.finalize(wordArray);
|
||||
*/
|
||||
finalize: function (messageUpdate) {
|
||||
// Final message update
|
||||
if (messageUpdate) {
|
||||
this._append(messageUpdate);
|
||||
}
|
||||
|
||||
// Perform concrete-hasher logic
|
||||
var hash = this._doFinalize();
|
||||
|
||||
return hash;
|
||||
},
|
||||
|
||||
blockSize: 512/32,
|
||||
|
||||
/**
|
||||
* Creates a shortcut function to a hasher's object interface.
|
||||
*
|
||||
* @param {Hasher} hasher The hasher to create a helper for.
|
||||
*
|
||||
* @return {Function} The shortcut function.
|
||||
*
|
||||
* @static
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* var SHA256 = CryptoJS.lib.Hasher._createHelper(CryptoJS.algo.SHA256);
|
||||
*/
|
||||
_createHelper: function (hasher) {
|
||||
return function (message, cfg) {
|
||||
return new hasher.init(cfg).finalize(message);
|
||||
};
|
||||
},
|
||||
|
||||
/**
|
||||
* Creates a shortcut function to the HMAC's object interface.
|
||||
*
|
||||
* @param {Hasher} hasher The hasher to use in this HMAC helper.
|
||||
*
|
||||
* @return {Function} The shortcut function.
|
||||
*
|
||||
* @static
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* var HmacSHA256 = CryptoJS.lib.Hasher._createHmacHelper(CryptoJS.algo.SHA256);
|
||||
*/
|
||||
_createHmacHelper: function (hasher) {
|
||||
return function (message, key) {
|
||||
return new C_algo.HMAC.init(hasher, key).finalize(message);
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Algorithm namespace.
|
||||
*/
|
||||
var C_algo = C.algo = {};
|
||||
|
||||
return C;
|
||||
}(Math));
|
@ -1,109 +0,0 @@
|
||||
/*
|
||||
CryptoJS v3.1.2
|
||||
code.google.com/p/crypto-js
|
||||
(c) 2009-2013 by Jeff Mott. All rights reserved.
|
||||
code.google.com/p/crypto-js/wiki/License
|
||||
*/
|
||||
(function () {
|
||||
// Shortcuts
|
||||
var C = CryptoJS;
|
||||
var C_lib = C.lib;
|
||||
var WordArray = C_lib.WordArray;
|
||||
var C_enc = C.enc;
|
||||
|
||||
/**
|
||||
* Base64 encoding strategy.
|
||||
*/
|
||||
var Base64 = C_enc.Base64 = {
|
||||
/**
|
||||
* Converts a word array to a Base64 string.
|
||||
*
|
||||
* @param {WordArray} wordArray The word array.
|
||||
*
|
||||
* @return {string} The Base64 string.
|
||||
*
|
||||
* @static
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* var base64String = CryptoJS.enc.Base64.stringify(wordArray);
|
||||
*/
|
||||
stringify: function (wordArray) {
|
||||
// Shortcuts
|
||||
var words = wordArray.words;
|
||||
var sigBytes = wordArray.sigBytes;
|
||||
var map = this._map;
|
||||
|
||||
// Clamp excess bits
|
||||
wordArray.clamp();
|
||||
|
||||
// Convert
|
||||
var base64Chars = [];
|
||||
for (var i = 0; i < sigBytes; i += 3) {
|
||||
var byte1 = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff;
|
||||
var byte2 = (words[(i + 1) >>> 2] >>> (24 - ((i + 1) % 4) * 8)) & 0xff;
|
||||
var byte3 = (words[(i + 2) >>> 2] >>> (24 - ((i + 2) % 4) * 8)) & 0xff;
|
||||
|
||||
var triplet = (byte1 << 16) | (byte2 << 8) | byte3;
|
||||
|
||||
for (var j = 0; (j < 4) && (i + j * 0.75 < sigBytes); j++) {
|
||||
base64Chars.push(map.charAt((triplet >>> (6 * (3 - j))) & 0x3f));
|
||||
}
|
||||
}
|
||||
|
||||
// Add padding
|
||||
var paddingChar = map.charAt(64);
|
||||
if (paddingChar) {
|
||||
while (base64Chars.length % 4) {
|
||||
base64Chars.push(paddingChar);
|
||||
}
|
||||
}
|
||||
|
||||
return base64Chars.join('');
|
||||
},
|
||||
|
||||
/**
|
||||
* Converts a Base64 string to a word array.
|
||||
*
|
||||
* @param {string} base64Str The Base64 string.
|
||||
*
|
||||
* @return {WordArray} The word array.
|
||||
*
|
||||
* @static
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* var wordArray = CryptoJS.enc.Base64.parse(base64String);
|
||||
*/
|
||||
parse: function (base64Str) {
|
||||
// Shortcuts
|
||||
var base64StrLength = base64Str.length;
|
||||
var map = this._map;
|
||||
|
||||
// Ignore padding
|
||||
var paddingChar = map.charAt(64);
|
||||
if (paddingChar) {
|
||||
var paddingIndex = base64Str.indexOf(paddingChar);
|
||||
if (paddingIndex != -1) {
|
||||
base64StrLength = paddingIndex;
|
||||
}
|
||||
}
|
||||
|
||||
// Convert
|
||||
var words = [];
|
||||
var nBytes = 0;
|
||||
for (var i = 0; i < base64StrLength; i++) {
|
||||
if (i % 4) {
|
||||
var bits1 = map.indexOf(base64Str.charAt(i - 1)) << ((i % 4) * 2);
|
||||
var bits2 = map.indexOf(base64Str.charAt(i)) >>> (6 - (i % 4) * 2);
|
||||
words[nBytes >>> 2] |= (bits1 | bits2) << (24 - (nBytes % 4) * 8);
|
||||
nBytes++;
|
||||
}
|
||||
}
|
||||
|
||||
return WordArray.create(words, nBytes);
|
||||
},
|
||||
|
||||
_map: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='
|
||||
};
|
||||
}());
|
@ -1,135 +0,0 @@
|
||||
/*
|
||||
CryptoJS v3.1.2
|
||||
code.google.com/p/crypto-js
|
||||
(c) 2009-2013 by Jeff Mott. All rights reserved.
|
||||
code.google.com/p/crypto-js/wiki/License
|
||||
*/
|
||||
(function () {
|
||||
// Shortcuts
|
||||
var C = CryptoJS;
|
||||
var C_lib = C.lib;
|
||||
var WordArray = C_lib.WordArray;
|
||||
var C_enc = C.enc;
|
||||
|
||||
/**
|
||||
* UTF-16 BE encoding strategy.
|
||||
*/
|
||||
var Utf16BE = C_enc.Utf16 = C_enc.Utf16BE = {
|
||||
/**
|
||||
* Converts a word array to a UTF-16 BE string.
|
||||
*
|
||||
* @param {WordArray} wordArray The word array.
|
||||
*
|
||||
* @return {string} The UTF-16 BE string.
|
||||
*
|
||||
* @static
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* var utf16String = CryptoJS.enc.Utf16.stringify(wordArray);
|
||||
*/
|
||||
stringify: function (wordArray) {
|
||||
// Shortcuts
|
||||
var words = wordArray.words;
|
||||
var sigBytes = wordArray.sigBytes;
|
||||
|
||||
// Convert
|
||||
var utf16Chars = [];
|
||||
for (var i = 0; i < sigBytes; i += 2) {
|
||||
var codePoint = (words[i >>> 2] >>> (16 - (i % 4) * 8)) & 0xffff;
|
||||
utf16Chars.push(String.fromCharCode(codePoint));
|
||||
}
|
||||
|
||||
return utf16Chars.join('');
|
||||
},
|
||||
|
||||
/**
|
||||
* Converts a UTF-16 BE string to a word array.
|
||||
*
|
||||
* @param {string} utf16Str The UTF-16 BE string.
|
||||
*
|
||||
* @return {WordArray} The word array.
|
||||
*
|
||||
* @static
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* var wordArray = CryptoJS.enc.Utf16.parse(utf16String);
|
||||
*/
|
||||
parse: function (utf16Str) {
|
||||
// Shortcut
|
||||
var utf16StrLength = utf16Str.length;
|
||||
|
||||
// Convert
|
||||
var words = [];
|
||||
for (var i = 0; i < utf16StrLength; i++) {
|
||||
words[i >>> 1] |= utf16Str.charCodeAt(i) << (16 - (i % 2) * 16);
|
||||
}
|
||||
|
||||
return WordArray.create(words, utf16StrLength * 2);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* UTF-16 LE encoding strategy.
|
||||
*/
|
||||
C_enc.Utf16LE = {
|
||||
/**
|
||||
* Converts a word array to a UTF-16 LE string.
|
||||
*
|
||||
* @param {WordArray} wordArray The word array.
|
||||
*
|
||||
* @return {string} The UTF-16 LE string.
|
||||
*
|
||||
* @static
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* var utf16Str = CryptoJS.enc.Utf16LE.stringify(wordArray);
|
||||
*/
|
||||
stringify: function (wordArray) {
|
||||
// Shortcuts
|
||||
var words = wordArray.words;
|
||||
var sigBytes = wordArray.sigBytes;
|
||||
|
||||
// Convert
|
||||
var utf16Chars = [];
|
||||
for (var i = 0; i < sigBytes; i += 2) {
|
||||
var codePoint = swapEndian((words[i >>> 2] >>> (16 - (i % 4) * 8)) & 0xffff);
|
||||
utf16Chars.push(String.fromCharCode(codePoint));
|
||||
}
|
||||
|
||||
return utf16Chars.join('');
|
||||
},
|
||||
|
||||
/**
|
||||
* Converts a UTF-16 LE string to a word array.
|
||||
*
|
||||
* @param {string} utf16Str The UTF-16 LE string.
|
||||
*
|
||||
* @return {WordArray} The word array.
|
||||
*
|
||||
* @static
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* var wordArray = CryptoJS.enc.Utf16LE.parse(utf16Str);
|
||||
*/
|
||||
parse: function (utf16Str) {
|
||||
// Shortcut
|
||||
var utf16StrLength = utf16Str.length;
|
||||
|
||||
// Convert
|
||||
var words = [];
|
||||
for (var i = 0; i < utf16StrLength; i++) {
|
||||
words[i >>> 1] |= swapEndian(utf16Str.charCodeAt(i) << (16 - (i % 2) * 16));
|
||||
}
|
||||
|
||||
return WordArray.create(words, utf16StrLength * 2);
|
||||
}
|
||||
};
|
||||
|
||||
function swapEndian(word) {
|
||||
return ((word << 8) & 0xff00ff00) | ((word >>> 8) & 0x00ff00ff);
|
||||
}
|
||||
}());
|
@ -1,118 +0,0 @@
|
||||
/*
|
||||
CryptoJS v3.1.2
|
||||
code.google.com/p/crypto-js
|
||||
(c) 2009-2013 by Jeff Mott. All rights reserved.
|
||||
code.google.com/p/crypto-js/wiki/License
|
||||
*/
|
||||
(function () {
|
||||
// Shortcuts
|
||||
var C = CryptoJS;
|
||||
var C_lib = C.lib;
|
||||
var Base = C_lib.Base;
|
||||
var WordArray = C_lib.WordArray;
|
||||
var C_algo = C.algo;
|
||||
var MD5 = C_algo.MD5;
|
||||
|
||||
/**
|
||||
* This key derivation function is meant to conform with EVP_BytesToKey.
|
||||
* www.openssl.org/docs/crypto/EVP_BytesToKey.html
|
||||
*/
|
||||
var EvpKDF = C_algo.EvpKDF = Base.extend({
|
||||
/**
|
||||
* Configuration options.
|
||||
*
|
||||
* @property {number} keySize The key size in words to generate. Default: 4 (128 bits)
|
||||
* @property {Hasher} hasher The hash algorithm to use. Default: MD5
|
||||
* @property {number} iterations The number of iterations to perform. Default: 1
|
||||
*/
|
||||
cfg: Base.extend({
|
||||
keySize: 128/32,
|
||||
hasher: MD5,
|
||||
iterations: 1
|
||||
}),
|
||||
|
||||
/**
|
||||
* Initializes a newly created key derivation function.
|
||||
*
|
||||
* @param {Object} cfg (Optional) The configuration options to use for the derivation.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* var kdf = CryptoJS.algo.EvpKDF.create();
|
||||
* var kdf = CryptoJS.algo.EvpKDF.create({ keySize: 8 });
|
||||
* var kdf = CryptoJS.algo.EvpKDF.create({ keySize: 8, iterations: 1000 });
|
||||
*/
|
||||
init: function (cfg) {
|
||||
this.cfg = this.cfg.extend(cfg);
|
||||
},
|
||||
|
||||
/**
|
||||
* Derives a key from a password.
|
||||
*
|
||||
* @param {WordArray|string} password The password.
|
||||
* @param {WordArray|string} salt A salt.
|
||||
*
|
||||
* @return {WordArray} The derived key.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* var key = kdf.compute(password, salt);
|
||||
*/
|
||||
compute: function (password, salt) {
|
||||
// Shortcut
|
||||
var cfg = this.cfg;
|
||||
|
||||
// Init hasher
|
||||
var hasher = cfg.hasher.create();
|
||||
|
||||
// Initial values
|
||||
var derivedKey = WordArray.create();
|
||||
|
||||
// Shortcuts
|
||||
var derivedKeyWords = derivedKey.words;
|
||||
var keySize = cfg.keySize;
|
||||
var iterations = cfg.iterations;
|
||||
|
||||
// Generate key
|
||||
while (derivedKeyWords.length < keySize) {
|
||||
if (block) {
|
||||
hasher.update(block);
|
||||
}
|
||||
var block = hasher.update(password).finalize(salt);
|
||||
hasher.reset();
|
||||
|
||||
// Iterations
|
||||
for (var i = 1; i < iterations; i++) {
|
||||
block = hasher.finalize(block);
|
||||
hasher.reset();
|
||||
}
|
||||
|
||||
derivedKey.concat(block);
|
||||
}
|
||||
derivedKey.sigBytes = keySize * 4;
|
||||
|
||||
return derivedKey;
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Derives a key from a password.
|
||||
*
|
||||
* @param {WordArray|string} password The password.
|
||||
* @param {WordArray|string} salt A salt.
|
||||
* @param {Object} cfg (Optional) The configuration options to use for this computation.
|
||||
*
|
||||
* @return {WordArray} The derived key.
|
||||
*
|
||||
* @static
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* var key = CryptoJS.EvpKDF(password, salt);
|
||||
* var key = CryptoJS.EvpKDF(password, salt, { keySize: 8 });
|
||||
* var key = CryptoJS.EvpKDF(password, salt, { keySize: 8, iterations: 1000 });
|
||||
*/
|
||||
C.EvpKDF = function (password, salt, cfg) {
|
||||
return EvpKDF.create(cfg).compute(password, salt);
|
||||
};
|
||||
}());
|
@ -1,52 +0,0 @@
|
||||
/*
|
||||
CryptoJS v3.1.2
|
||||
code.google.com/p/crypto-js
|
||||
(c) 2009-2013 by Jeff Mott. All rights reserved.
|
||||
code.google.com/p/crypto-js/wiki/License
|
||||
*/
|
||||
(function (undefined) {
|
||||
// Shortcuts
|
||||
var C = CryptoJS;
|
||||
var C_lib = C.lib;
|
||||
var CipherParams = C_lib.CipherParams;
|
||||
var C_enc = C.enc;
|
||||
var Hex = C_enc.Hex;
|
||||
var C_format = C.format;
|
||||
|
||||
var HexFormatter = C_format.Hex = {
|
||||
/**
|
||||
* Converts the ciphertext of a cipher params object to a hexadecimally encoded string.
|
||||
*
|
||||
* @param {CipherParams} cipherParams The cipher params object.
|
||||
*
|
||||
* @return {string} The hexadecimally encoded string.
|
||||
*
|
||||
* @static
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* var hexString = CryptoJS.format.Hex.stringify(cipherParams);
|
||||
*/
|
||||
stringify: function (cipherParams) {
|
||||
return cipherParams.ciphertext.toString(Hex);
|
||||
},
|
||||
|
||||
/**
|
||||
* Converts a hexadecimally encoded ciphertext string to a cipher params object.
|
||||
*
|
||||
* @param {string} input The hexadecimally encoded string.
|
||||
*
|
||||
* @return {CipherParams} The cipher params object.
|
||||
*
|
||||
* @static
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* var cipherParams = CryptoJS.format.Hex.parse(hexString);
|
||||
*/
|
||||
parse: function (input) {
|
||||
var ciphertext = Hex.parse(input);
|
||||
return CipherParams.create({ ciphertext: ciphertext });
|
||||
}
|
||||
};
|
||||
}());
|
@ -1,131 +0,0 @@
|
||||
/*
|
||||
CryptoJS v3.1.2
|
||||
code.google.com/p/crypto-js
|
||||
(c) 2009-2013 by Jeff Mott. All rights reserved.
|
||||
code.google.com/p/crypto-js/wiki/License
|
||||
*/
|
||||
(function () {
|
||||
// Shortcuts
|
||||
var C = CryptoJS;
|
||||
var C_lib = C.lib;
|
||||
var Base = C_lib.Base;
|
||||
var C_enc = C.enc;
|
||||
var Utf8 = C_enc.Utf8;
|
||||
var C_algo = C.algo;
|
||||
|
||||
/**
|
||||
* HMAC algorithm.
|
||||
*/
|
||||
var HMAC = C_algo.HMAC = Base.extend({
|
||||
/**
|
||||
* Initializes a newly created HMAC.
|
||||
*
|
||||
* @param {Hasher} hasher The hash algorithm to use.
|
||||
* @param {WordArray|string} key The secret key.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* var hmacHasher = CryptoJS.algo.HMAC.create(CryptoJS.algo.SHA256, key);
|
||||
*/
|
||||
init: function (hasher, key) {
|
||||
// Init hasher
|
||||
hasher = this._hasher = new hasher.init();
|
||||
|
||||
// Convert string to WordArray, else assume WordArray already
|
||||
if (typeof key == 'string') {
|
||||
key = Utf8.parse(key);
|
||||
}
|
||||
|
||||
// Shortcuts
|
||||
var hasherBlockSize = hasher.blockSize;
|
||||
var hasherBlockSizeBytes = hasherBlockSize * 4;
|
||||
|
||||
// Allow arbitrary length keys
|
||||
if (key.sigBytes > hasherBlockSizeBytes) {
|
||||
key = hasher.finalize(key);
|
||||
}
|
||||
|
||||
// Clamp excess bits
|
||||
key.clamp();
|
||||
|
||||
// Clone key for inner and outer pads
|
||||
var oKey = this._oKey = key.clone();
|
||||
var iKey = this._iKey = key.clone();
|
||||
|
||||
// Shortcuts
|
||||
var oKeyWords = oKey.words;
|
||||
var iKeyWords = iKey.words;
|
||||
|
||||
// XOR keys with pad constants
|
||||
for (var i = 0; i < hasherBlockSize; i++) {
|
||||
oKeyWords[i] ^= 0x5c5c5c5c;
|
||||
iKeyWords[i] ^= 0x36363636;
|
||||
}
|
||||
oKey.sigBytes = iKey.sigBytes = hasherBlockSizeBytes;
|
||||
|
||||
// Set initial values
|
||||
this.reset();
|
||||
},
|
||||
|
||||
/**
|
||||
* Resets this HMAC to its initial state.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* hmacHasher.reset();
|
||||
*/
|
||||
reset: function () {
|
||||
// Shortcut
|
||||
var hasher = this._hasher;
|
||||
|
||||
// Reset
|
||||
hasher.reset();
|
||||
hasher.update(this._iKey);
|
||||
},
|
||||
|
||||
/**
|
||||
* Updates this HMAC with a message.
|
||||
*
|
||||
* @param {WordArray|string} messageUpdate The message to append.
|
||||
*
|
||||
* @return {HMAC} This HMAC instance.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* hmacHasher.update('message');
|
||||
* hmacHasher.update(wordArray);
|
||||
*/
|
||||
update: function (messageUpdate) {
|
||||
this._hasher.update(messageUpdate);
|
||||
|
||||
// Chainable
|
||||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* Finalizes the HMAC computation.
|
||||
* Note that the finalize operation is effectively a destructive, read-once operation.
|
||||
*
|
||||
* @param {WordArray|string} messageUpdate (Optional) A final message update.
|
||||
*
|
||||
* @return {WordArray} The HMAC.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* var hmac = hmacHasher.finalize();
|
||||
* var hmac = hmacHasher.finalize('message');
|
||||
* var hmac = hmacHasher.finalize(wordArray);
|
||||
*/
|
||||
finalize: function (messageUpdate) {
|
||||
// Shortcut
|
||||
var hasher = this._hasher;
|
||||
|
||||
// Compute HMAC
|
||||
var innerHash = hasher.finalize(messageUpdate);
|
||||
hasher.reset();
|
||||
var hmac = hasher.finalize(this._oKey.clone().concat(innerHash));
|
||||
|
||||
return hmac;
|
||||
}
|
||||
});
|
||||
}());
|
@ -1,62 +0,0 @@
|
||||
/*
|
||||
CryptoJS v3.1.2
|
||||
code.google.com/p/crypto-js
|
||||
(c) 2009-2013 by Jeff Mott. All rights reserved.
|
||||
code.google.com/p/crypto-js/wiki/License
|
||||
*/
|
||||
(function () {
|
||||
// Check if typed arrays are supported
|
||||
if (typeof ArrayBuffer != 'function') {
|
||||
return;
|
||||
}
|
||||
|
||||
// Shortcuts
|
||||
var C = CryptoJS;
|
||||
var C_lib = C.lib;
|
||||
var WordArray = C_lib.WordArray;
|
||||
|
||||
// Reference original init
|
||||
var superInit = WordArray.init;
|
||||
|
||||
// Augment WordArray.init to handle typed arrays
|
||||
var subInit = WordArray.init = function (typedArray) {
|
||||
// Convert buffers to uint8
|
||||
if (typedArray instanceof ArrayBuffer) {
|
||||
typedArray = new Uint8Array(typedArray);
|
||||
}
|
||||
|
||||
// Convert other array views to uint8
|
||||
if (
|
||||
typedArray instanceof Int8Array ||
|
||||
typedArray instanceof Uint8ClampedArray ||
|
||||
typedArray instanceof Int16Array ||
|
||||
typedArray instanceof Uint16Array ||
|
||||
typedArray instanceof Int32Array ||
|
||||
typedArray instanceof Uint32Array ||
|
||||
typedArray instanceof Float32Array ||
|
||||
typedArray instanceof Float64Array
|
||||
) {
|
||||
typedArray = new Uint8Array(typedArray.buffer, typedArray.byteOffset, typedArray.byteLength);
|
||||
}
|
||||
|
||||
// Handle Uint8Array
|
||||
if (typedArray instanceof Uint8Array) {
|
||||
// Shortcut
|
||||
var typedArrayByteLength = typedArray.byteLength;
|
||||
|
||||
// Extract bytes
|
||||
var words = [];
|
||||
for (var i = 0; i < typedArrayByteLength; i++) {
|
||||
words[i >>> 2] |= typedArray[i] << (24 - (i % 4) * 8);
|
||||
}
|
||||
|
||||
// Initialize this word array
|
||||
superInit.call(this, words, typedArrayByteLength);
|
||||
} else {
|
||||
// Else call normal init
|
||||
superInit.apply(this, arguments);
|
||||
}
|
||||
};
|
||||
|
||||
subInit.prototype = WordArray;
|
||||
}());
|
@ -1,254 +0,0 @@
|
||||
/*
|
||||
CryptoJS v3.1.2
|
||||
code.google.com/p/crypto-js
|
||||
(c) 2009-2013 by Jeff Mott. All rights reserved.
|
||||
code.google.com/p/crypto-js/wiki/License
|
||||
*/
|
||||
(function (Math) {
|
||||
// Shortcuts
|
||||
var C = CryptoJS;
|
||||
var C_lib = C.lib;
|
||||
var WordArray = C_lib.WordArray;
|
||||
var Hasher = C_lib.Hasher;
|
||||
var C_algo = C.algo;
|
||||
|
||||
// Constants table
|
||||
var T = [];
|
||||
|
||||
// Compute constants
|
||||
(function () {
|
||||
for (var i = 0; i < 64; i++) {
|
||||
T[i] = (Math.abs(Math.sin(i + 1)) * 0x100000000) | 0;
|
||||
}
|
||||
}());
|
||||
|
||||
/**
|
||||
* MD5 hash algorithm.
|
||||
*/
|
||||
var MD5 = C_algo.MD5 = Hasher.extend({
|
||||
_doReset: function () {
|
||||
this._hash = new WordArray.init([
|
||||
0x67452301, 0xefcdab89,
|
||||
0x98badcfe, 0x10325476
|
||||
]);
|
||||
},
|
||||
|
||||
_doProcessBlock: function (M, offset) {
|
||||
// Swap endian
|
||||
for (var i = 0; i < 16; i++) {
|
||||
// Shortcuts
|
||||
var offset_i = offset + i;
|
||||
var M_offset_i = M[offset_i];
|
||||
|
||||
M[offset_i] = (
|
||||
(((M_offset_i << 8) | (M_offset_i >>> 24)) & 0x00ff00ff) |
|
||||
(((M_offset_i << 24) | (M_offset_i >>> 8)) & 0xff00ff00)
|
||||
);
|
||||
}
|
||||
|
||||
// Shortcuts
|
||||
var H = this._hash.words;
|
||||
|
||||
var M_offset_0 = M[offset + 0];
|
||||
var M_offset_1 = M[offset + 1];
|
||||
var M_offset_2 = M[offset + 2];
|
||||
var M_offset_3 = M[offset + 3];
|
||||
var M_offset_4 = M[offset + 4];
|
||||
var M_offset_5 = M[offset + 5];
|
||||
var M_offset_6 = M[offset + 6];
|
||||
var M_offset_7 = M[offset + 7];
|
||||
var M_offset_8 = M[offset + 8];
|
||||
var M_offset_9 = M[offset + 9];
|
||||
var M_offset_10 = M[offset + 10];
|
||||
var M_offset_11 = M[offset + 11];
|
||||
var M_offset_12 = M[offset + 12];
|
||||
var M_offset_13 = M[offset + 13];
|
||||
var M_offset_14 = M[offset + 14];
|
||||
var M_offset_15 = M[offset + 15];
|
||||
|
||||
// Working variables
|
||||
var a = H[0];
|
||||
var b = H[1];
|
||||
var c = H[2];
|
||||
var d = H[3];
|
||||
|
||||
// Computation
|
||||
a = FF(a, b, c, d, M_offset_0, 7, T[0]);
|
||||
d = FF(d, a, b, c, M_offset_1, 12, T[1]);
|
||||
c = FF(c, d, a, b, M_offset_2, 17, T[2]);
|
||||
b = FF(b, c, d, a, M_offset_3, 22, T[3]);
|
||||
a = FF(a, b, c, d, M_offset_4, 7, T[4]);
|
||||
d = FF(d, a, b, c, M_offset_5, 12, T[5]);
|
||||
c = FF(c, d, a, b, M_offset_6, 17, T[6]);
|
||||
b = FF(b, c, d, a, M_offset_7, 22, T[7]);
|
||||
a = FF(a, b, c, d, M_offset_8, 7, T[8]);
|
||||
d = FF(d, a, b, c, M_offset_9, 12, T[9]);
|
||||
c = FF(c, d, a, b, M_offset_10, 17, T[10]);
|
||||
b = FF(b, c, d, a, M_offset_11, 22, T[11]);
|
||||
a = FF(a, b, c, d, M_offset_12, 7, T[12]);
|
||||
d = FF(d, a, b, c, M_offset_13, 12, T[13]);
|
||||
c = FF(c, d, a, b, M_offset_14, 17, T[14]);
|
||||
b = FF(b, c, d, a, M_offset_15, 22, T[15]);
|
||||
|
||||
a = GG(a, b, c, d, M_offset_1, 5, T[16]);
|
||||
d = GG(d, a, b, c, M_offset_6, 9, T[17]);
|
||||
c = GG(c, d, a, b, M_offset_11, 14, T[18]);
|
||||
b = GG(b, c, d, a, M_offset_0, 20, T[19]);
|
||||
a = GG(a, b, c, d, M_offset_5, 5, T[20]);
|
||||
d = GG(d, a, b, c, M_offset_10, 9, T[21]);
|
||||
c = GG(c, d, a, b, M_offset_15, 14, T[22]);
|
||||
b = GG(b, c, d, a, M_offset_4, 20, T[23]);
|
||||
a = GG(a, b, c, d, M_offset_9, 5, T[24]);
|
||||
d = GG(d, a, b, c, M_offset_14, 9, T[25]);
|
||||
c = GG(c, d, a, b, M_offset_3, 14, T[26]);
|
||||
b = GG(b, c, d, a, M_offset_8, 20, T[27]);
|
||||
a = GG(a, b, c, d, M_offset_13, 5, T[28]);
|
||||
d = GG(d, a, b, c, M_offset_2, 9, T[29]);
|
||||
c = GG(c, d, a, b, M_offset_7, 14, T[30]);
|
||||
b = GG(b, c, d, a, M_offset_12, 20, T[31]);
|
||||
|
||||
a = HH(a, b, c, d, M_offset_5, 4, T[32]);
|
||||
d = HH(d, a, b, c, M_offset_8, 11, T[33]);
|
||||
c = HH(c, d, a, b, M_offset_11, 16, T[34]);
|
||||
b = HH(b, c, d, a, M_offset_14, 23, T[35]);
|
||||
a = HH(a, b, c, d, M_offset_1, 4, T[36]);
|
||||
d = HH(d, a, b, c, M_offset_4, 11, T[37]);
|
||||
c = HH(c, d, a, b, M_offset_7, 16, T[38]);
|
||||
b = HH(b, c, d, a, M_offset_10, 23, T[39]);
|
||||
a = HH(a, b, c, d, M_offset_13, 4, T[40]);
|
||||
d = HH(d, a, b, c, M_offset_0, 11, T[41]);
|
||||
c = HH(c, d, a, b, M_offset_3, 16, T[42]);
|
||||
b = HH(b, c, d, a, M_offset_6, 23, T[43]);
|
||||
a = HH(a, b, c, d, M_offset_9, 4, T[44]);
|
||||
d = HH(d, a, b, c, M_offset_12, 11, T[45]);
|
||||
c = HH(c, d, a, b, M_offset_15, 16, T[46]);
|
||||
b = HH(b, c, d, a, M_offset_2, 23, T[47]);
|
||||
|
||||
a = II(a, b, c, d, M_offset_0, 6, T[48]);
|
||||
d = II(d, a, b, c, M_offset_7, 10, T[49]);
|
||||
c = II(c, d, a, b, M_offset_14, 15, T[50]);
|
||||
b = II(b, c, d, a, M_offset_5, 21, T[51]);
|
||||
a = II(a, b, c, d, M_offset_12, 6, T[52]);
|
||||
d = II(d, a, b, c, M_offset_3, 10, T[53]);
|
||||
c = II(c, d, a, b, M_offset_10, 15, T[54]);
|
||||
b = II(b, c, d, a, M_offset_1, 21, T[55]);
|
||||
a = II(a, b, c, d, M_offset_8, 6, T[56]);
|
||||
d = II(d, a, b, c, M_offset_15, 10, T[57]);
|
||||
c = II(c, d, a, b, M_offset_6, 15, T[58]);
|
||||
b = II(b, c, d, a, M_offset_13, 21, T[59]);
|
||||
a = II(a, b, c, d, M_offset_4, 6, T[60]);
|
||||
d = II(d, a, b, c, M_offset_11, 10, T[61]);
|
||||
c = II(c, d, a, b, M_offset_2, 15, T[62]);
|
||||
b = II(b, c, d, a, M_offset_9, 21, T[63]);
|
||||
|
||||
// Intermediate hash value
|
||||
H[0] = (H[0] + a) | 0;
|
||||
H[1] = (H[1] + b) | 0;
|
||||
H[2] = (H[2] + c) | 0;
|
||||
H[3] = (H[3] + d) | 0;
|
||||
},
|
||||
|
||||
_doFinalize: function () {
|
||||
// Shortcuts
|
||||
var data = this._data;
|
||||
var dataWords = data.words;
|
||||
|
||||
var nBitsTotal = this._nDataBytes * 8;
|
||||
var nBitsLeft = data.sigBytes * 8;
|
||||
|
||||
// Add padding
|
||||
dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32);
|
||||
|
||||
var nBitsTotalH = Math.floor(nBitsTotal / 0x100000000);
|
||||
var nBitsTotalL = nBitsTotal;
|
||||
dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = (
|
||||
(((nBitsTotalH << 8) | (nBitsTotalH >>> 24)) & 0x00ff00ff) |
|
||||
(((nBitsTotalH << 24) | (nBitsTotalH >>> 8)) & 0xff00ff00)
|
||||
);
|
||||
dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = (
|
||||
(((nBitsTotalL << 8) | (nBitsTotalL >>> 24)) & 0x00ff00ff) |
|
||||
(((nBitsTotalL << 24) | (nBitsTotalL >>> 8)) & 0xff00ff00)
|
||||
);
|
||||
|
||||
data.sigBytes = (dataWords.length + 1) * 4;
|
||||
|
||||
// Hash final blocks
|
||||
this._process();
|
||||
|
||||
// Shortcuts
|
||||
var hash = this._hash;
|
||||
var H = hash.words;
|
||||
|
||||
// Swap endian
|
||||
for (var i = 0; i < 4; i++) {
|
||||
// Shortcut
|
||||
var H_i = H[i];
|
||||
|
||||
H[i] = (((H_i << 8) | (H_i >>> 24)) & 0x00ff00ff) |
|
||||
(((H_i << 24) | (H_i >>> 8)) & 0xff00ff00);
|
||||
}
|
||||
|
||||
// Return final computed hash
|
||||
return hash;
|
||||
},
|
||||
|
||||
clone: function () {
|
||||
var clone = Hasher.clone.call(this);
|
||||
clone._hash = this._hash.clone();
|
||||
|
||||
return clone;
|
||||
}
|
||||
});
|
||||
|
||||
function FF(a, b, c, d, x, s, t) {
|
||||
var n = a + ((b & c) | (~b & d)) + x + t;
|
||||
return ((n << s) | (n >>> (32 - s))) + b;
|
||||
}
|
||||
|
||||
function GG(a, b, c, d, x, s, t) {
|
||||
var n = a + ((b & d) | (c & ~d)) + x + t;
|
||||
return ((n << s) | (n >>> (32 - s))) + b;
|
||||
}
|
||||
|
||||
function HH(a, b, c, d, x, s, t) {
|
||||
var n = a + (b ^ c ^ d) + x + t;
|
||||
return ((n << s) | (n >>> (32 - s))) + b;
|
||||
}
|
||||
|
||||
function II(a, b, c, d, x, s, t) {
|
||||
var n = a + (c ^ (b | ~d)) + x + t;
|
||||
return ((n << s) | (n >>> (32 - s))) + b;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shortcut function to the hasher's object interface.
|
||||
*
|
||||
* @param {WordArray|string} message The message to hash.
|
||||
*
|
||||
* @return {WordArray} The hash.
|
||||
*
|
||||
* @static
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* var hash = CryptoJS.MD5('message');
|
||||
* var hash = CryptoJS.MD5(wordArray);
|
||||
*/
|
||||
C.MD5 = Hasher._createHelper(MD5);
|
||||
|
||||
/**
|
||||
* Shortcut function to the HMAC's object interface.
|
||||
*
|
||||
* @param {WordArray|string} message The message to hash.
|
||||
* @param {WordArray|string} key The secret key.
|
||||
*
|
||||
* @return {WordArray} The HMAC.
|
||||
*
|
||||
* @static
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* var hmac = CryptoJS.HmacMD5(message, key);
|
||||
*/
|
||||
C.HmacMD5 = Hasher._createHmacHelper(MD5);
|
||||
}(Math));
|
@ -1,64 +0,0 @@
|
||||
/*
|
||||
CryptoJS v3.1.2
|
||||
code.google.com/p/crypto-js
|
||||
(c) 2009-2013 by Jeff Mott. All rights reserved.
|
||||
code.google.com/p/crypto-js/wiki/License
|
||||
*/
|
||||
/**
|
||||
* Cipher Feedback block mode.
|
||||
*/
|
||||
CryptoJS.mode.CFB = (function () {
|
||||
var CFB = CryptoJS.lib.BlockCipherMode.extend();
|
||||
|
||||
CFB.Encryptor = CFB.extend({
|
||||
processBlock: function (words, offset) {
|
||||
// Shortcuts
|
||||
var cipher = this._cipher;
|
||||
var blockSize = cipher.blockSize;
|
||||
|
||||
generateKeystreamAndEncrypt.call(this, words, offset, blockSize, cipher);
|
||||
|
||||
// Remember this block to use with next block
|
||||
this._prevBlock = words.slice(offset, offset + blockSize);
|
||||
}
|
||||
});
|
||||
|
||||
CFB.Decryptor = CFB.extend({
|
||||
processBlock: function (words, offset) {
|
||||
// Shortcuts
|
||||
var cipher = this._cipher;
|
||||
var blockSize = cipher.blockSize;
|
||||
|
||||
// Remember this block to use with next block
|
||||
var thisBlock = words.slice(offset, offset + blockSize);
|
||||
|
||||
generateKeystreamAndEncrypt.call(this, words, offset, blockSize, cipher);
|
||||
|
||||
// This block becomes the previous block
|
||||
this._prevBlock = thisBlock;
|
||||
}
|
||||
});
|
||||
|
||||
function generateKeystreamAndEncrypt(words, offset, blockSize, cipher) {
|
||||
// Shortcut
|
||||
var iv = this._iv;
|
||||
|
||||
// Generate keystream
|
||||
if (iv) {
|
||||
var keystream = iv.slice(0);
|
||||
|
||||
// Remove IV for subsequent blocks
|
||||
this._iv = undefined;
|
||||
} else {
|
||||
var keystream = this._prevBlock;
|
||||
}
|
||||
cipher.encryptBlock(keystream, 0);
|
||||
|
||||
// Encrypt
|
||||
for (var i = 0; i < blockSize; i++) {
|
||||
words[offset + i] ^= keystream[i];
|
||||
}
|
||||
}
|
||||
|
||||
return CFB;
|
||||
}());
|
@ -1,104 +0,0 @@
|
||||
/*
|
||||
CryptoJS v3.1.2
|
||||
code.google.com/p/crypto-js
|
||||
(c) 2009-2013 by Jeff Mott. All rights reserved.
|
||||
code.google.com/p/crypto-js/wiki/License
|
||||
*/
|
||||
/** @license
|
||||
========================================================================
|
||||
CryptoJS.mode.CTRGladman
|
||||
Counter block mode compatible with Dr Brian Gladman fileenc.c
|
||||
derived from CryptoJS.mode.CTR
|
||||
Jan Hruby jhruby.web@gmail.com
|
||||
*/
|
||||
CryptoJS.mode.CTRGladman = (function () {
|
||||
var CTRGladman = CryptoJS.lib.BlockCipherMode.extend();
|
||||
|
||||
function incWord(word)
|
||||
{
|
||||
if (((word >> 24) & 0xff) === 0xff) { //overflow
|
||||
var b1 = (word >> 16)&0xff;
|
||||
var b2 = (word >> 8)&0xff;
|
||||
var b3 = word & 0xff;
|
||||
|
||||
if (b1 === 0xff) // overflow b1
|
||||
{
|
||||
b1 = 0;
|
||||
if (b2 === 0xff)
|
||||
{
|
||||
b2 = 0;
|
||||
if (b3 === 0xff)
|
||||
{
|
||||
b3 = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
++b3;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
++b2;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
++b1;
|
||||
}
|
||||
|
||||
word = 0;
|
||||
word += (b1 << 16);
|
||||
word += (b2 << 8);
|
||||
word += b3;
|
||||
}
|
||||
else
|
||||
{
|
||||
word += (0x01 << 24);
|
||||
}
|
||||
return word;
|
||||
}
|
||||
|
||||
function incCounter(counter)
|
||||
{
|
||||
if ((counter[0] = incWord(counter[0])) === 0)
|
||||
{
|
||||
// encr_data in fileenc.c from Dr Brian Gladman's counts only with DWORD j < 8
|
||||
counter[1] = incWord(counter[1]);
|
||||
}
|
||||
return counter;
|
||||
}
|
||||
|
||||
var Encryptor = CTRGladman.Encryptor = CTRGladman.extend({
|
||||
processBlock: function (words, offset) {
|
||||
// Shortcuts
|
||||
var cipher = this._cipher
|
||||
var blockSize = cipher.blockSize;
|
||||
var iv = this._iv;
|
||||
var counter = this._counter;
|
||||
|
||||
// Generate keystream
|
||||
if (iv) {
|
||||
counter = this._counter = iv.slice(0);
|
||||
|
||||
// Remove IV for subsequent blocks
|
||||
this._iv = undefined;
|
||||
}
|
||||
|
||||
incCounter(counter);
|
||||
|
||||
var keystream = counter.slice(0);
|
||||
cipher.encryptBlock(keystream, 0);
|
||||
|
||||
// Encrypt
|
||||
for (var i = 0; i < blockSize; i++) {
|
||||
words[offset + i] ^= keystream[i];
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
CTRGladman.Decryptor = Encryptor;
|
||||
|
||||
return CTRGladman;
|
||||
}());
|
||||
|
||||
|
@ -1,44 +0,0 @@
|
||||
/*
|
||||
CryptoJS v3.1.2
|
||||
code.google.com/p/crypto-js
|
||||
(c) 2009-2013 by Jeff Mott. All rights reserved.
|
||||
code.google.com/p/crypto-js/wiki/License
|
||||
*/
|
||||
/**
|
||||
* Counter block mode.
|
||||
*/
|
||||
CryptoJS.mode.CTR = (function () {
|
||||
var CTR = CryptoJS.lib.BlockCipherMode.extend();
|
||||
|
||||
var Encryptor = CTR.Encryptor = CTR.extend({
|
||||
processBlock: function (words, offset) {
|
||||
// Shortcuts
|
||||
var cipher = this._cipher
|
||||
var blockSize = cipher.blockSize;
|
||||
var iv = this._iv;
|
||||
var counter = this._counter;
|
||||
|
||||
// Generate keystream
|
||||
if (iv) {
|
||||
counter = this._counter = iv.slice(0);
|
||||
|
||||
// Remove IV for subsequent blocks
|
||||
this._iv = undefined;
|
||||
}
|
||||
var keystream = counter.slice(0);
|
||||
cipher.encryptBlock(keystream, 0);
|
||||
|
||||
// Increment counter
|
||||
counter[blockSize - 1] = (counter[blockSize - 1] + 1) | 0
|
||||
|
||||
// Encrypt
|
||||
for (var i = 0; i < blockSize; i++) {
|
||||
words[offset + i] ^= keystream[i];
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
CTR.Decryptor = Encryptor;
|
||||
|
||||
return CTR;
|
||||
}());
|
@ -1,26 +0,0 @@
|
||||
/*
|
||||
CryptoJS v3.1.2
|
||||
code.google.com/p/crypto-js
|
||||
(c) 2009-2013 by Jeff Mott. All rights reserved.
|
||||
code.google.com/p/crypto-js/wiki/License
|
||||
*/
|
||||
/**
|
||||
* Electronic Codebook block mode.
|
||||
*/
|
||||
CryptoJS.mode.ECB = (function () {
|
||||
var ECB = CryptoJS.lib.BlockCipherMode.extend();
|
||||
|
||||
ECB.Encryptor = ECB.extend({
|
||||
processBlock: function (words, offset) {
|
||||
this._cipher.encryptBlock(words, offset);
|
||||
}
|
||||
});
|
||||
|
||||
ECB.Decryptor = ECB.extend({
|
||||
processBlock: function (words, offset) {
|
||||
this._cipher.decryptBlock(words, offset);
|
||||
}
|
||||
});
|
||||
|
||||
return ECB;
|
||||
}());
|
@ -1,40 +0,0 @@
|
||||
/*
|
||||
CryptoJS v3.1.2
|
||||
code.google.com/p/crypto-js
|
||||
(c) 2009-2013 by Jeff Mott. All rights reserved.
|
||||
code.google.com/p/crypto-js/wiki/License
|
||||
*/
|
||||
/**
|
||||
* Output Feedback block mode.
|
||||
*/
|
||||
CryptoJS.mode.OFB = (function () {
|
||||
var OFB = CryptoJS.lib.BlockCipherMode.extend();
|
||||
|
||||
var Encryptor = OFB.Encryptor = OFB.extend({
|
||||
processBlock: function (words, offset) {
|
||||
// Shortcuts
|
||||
var cipher = this._cipher
|
||||
var blockSize = cipher.blockSize;
|
||||
var iv = this._iv;
|
||||
var keystream = this._keystream;
|
||||
|
||||
// Generate keystream
|
||||
if (iv) {
|
||||
keystream = this._keystream = iv.slice(0);
|
||||
|
||||
// Remove IV for subsequent blocks
|
||||
this._iv = undefined;
|
||||
}
|
||||
cipher.encryptBlock(keystream, 0);
|
||||
|
||||
// Encrypt
|
||||
for (var i = 0; i < blockSize; i++) {
|
||||
words[offset + i] ^= keystream[i];
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
OFB.Decryptor = Encryptor;
|
||||
|
||||
return OFB;
|
||||
}());
|
@ -1,35 +0,0 @@
|
||||
/*
|
||||
CryptoJS v3.1.2
|
||||
code.google.com/p/crypto-js
|
||||
(c) 2009-2013 by Jeff Mott. All rights reserved.
|
||||
code.google.com/p/crypto-js/wiki/License
|
||||
*/
|
||||
/**
|
||||
* ANSI X.923 padding strategy.
|
||||
*/
|
||||
CryptoJS.pad.AnsiX923 = {
|
||||
pad: function (data, blockSize) {
|
||||
// Shortcuts
|
||||
var dataSigBytes = data.sigBytes;
|
||||
var blockSizeBytes = blockSize * 4;
|
||||
|
||||
// Count padding bytes
|
||||
var nPaddingBytes = blockSizeBytes - dataSigBytes % blockSizeBytes;
|
||||
|
||||
// Compute last byte position
|
||||
var lastBytePos = dataSigBytes + nPaddingBytes - 1;
|
||||
|
||||
// Pad
|
||||
data.clamp();
|
||||
data.words[lastBytePos >>> 2] |= nPaddingBytes << (24 - (lastBytePos % 4) * 8);
|
||||
data.sigBytes += nPaddingBytes;
|
||||
},
|
||||
|
||||
unpad: function (data) {
|
||||
// Get number of padding bytes from last byte
|
||||
var nPaddingBytes = data.words[(data.sigBytes - 1) >>> 2] & 0xff;
|
||||
|
||||
// Remove padding
|
||||
data.sigBytes -= nPaddingBytes;
|
||||
}
|
||||
};
|
@ -1,30 +0,0 @@
|
||||
/*
|
||||
CryptoJS v3.1.2
|
||||
code.google.com/p/crypto-js
|
||||
(c) 2009-2013 by Jeff Mott. All rights reserved.
|
||||
code.google.com/p/crypto-js/wiki/License
|
||||
*/
|
||||
/**
|
||||
* ISO 10126 padding strategy.
|
||||
*/
|
||||
CryptoJS.pad.Iso10126 = {
|
||||
pad: function (data, blockSize) {
|
||||
// Shortcut
|
||||
var blockSizeBytes = blockSize * 4;
|
||||
|
||||
// Count padding bytes
|
||||
var nPaddingBytes = blockSizeBytes - data.sigBytes % blockSizeBytes;
|
||||
|
||||
// Pad
|
||||
data.concat(CryptoJS.lib.WordArray.random(nPaddingBytes - 1)).
|
||||
concat(CryptoJS.lib.WordArray.create([nPaddingBytes << 24], 1));
|
||||
},
|
||||
|
||||
unpad: function (data) {
|
||||
// Get number of padding bytes from last byte
|
||||
var nPaddingBytes = data.words[(data.sigBytes - 1) >>> 2] & 0xff;
|
||||
|
||||
// Remove padding
|
||||
data.sigBytes -= nPaddingBytes;
|
||||
}
|
||||
};
|
@ -1,26 +0,0 @@
|
||||
/*
|
||||
CryptoJS v3.1.2
|
||||
code.google.com/p/crypto-js
|
||||
(c) 2009-2013 by Jeff Mott. All rights reserved.
|
||||
code.google.com/p/crypto-js/wiki/License
|
||||
*/
|
||||
/**
|
||||
* ISO/IEC 9797-1 Padding Method 2.
|
||||
*/
|
||||
CryptoJS.pad.Iso97971 = {
|
||||
pad: function (data, blockSize) {
|
||||
// Add 0x80 byte
|
||||
data.concat(CryptoJS.lib.WordArray.create([0x80000000], 1));
|
||||
|
||||
// Zero pad the rest
|
||||
CryptoJS.pad.ZeroPadding.pad(data, blockSize);
|
||||
},
|
||||
|
||||
unpad: function (data) {
|
||||
// Remove zero padding
|
||||
CryptoJS.pad.ZeroPadding.unpad(data);
|
||||
|
||||
// Remove one more byte -- the 0x80 byte
|
||||
data.sigBytes--;
|
||||
}
|
||||
};
|
@ -1,16 +0,0 @@
|
||||
/*
|
||||
CryptoJS v3.1.2
|
||||
code.google.com/p/crypto-js
|
||||
(c) 2009-2013 by Jeff Mott. All rights reserved.
|
||||
code.google.com/p/crypto-js/wiki/License
|
||||
*/
|
||||
/**
|
||||
* A noop padding strategy.
|
||||
*/
|
||||
CryptoJS.pad.NoPadding = {
|
||||
pad: function () {
|
||||
},
|
||||
|
||||
unpad: function () {
|
||||
}
|
||||
};
|
@ -1,31 +0,0 @@
|
||||
/*
|
||||
CryptoJS v3.1.2
|
||||
code.google.com/p/crypto-js
|
||||
(c) 2009-2013 by Jeff Mott. All rights reserved.
|
||||
code.google.com/p/crypto-js/wiki/License
|
||||
*/
|
||||
/**
|
||||
* Zero padding strategy.
|
||||
*/
|
||||
CryptoJS.pad.ZeroPadding = {
|
||||
pad: function (data, blockSize) {
|
||||
// Shortcut
|
||||
var blockSizeBytes = blockSize * 4;
|
||||
|
||||
// Pad
|
||||
data.clamp();
|
||||
data.sigBytes += blockSizeBytes - ((data.sigBytes % blockSizeBytes) || blockSizeBytes);
|
||||
},
|
||||
|
||||
unpad: function (data) {
|
||||
// Shortcut
|
||||
var dataWords = data.words;
|
||||
|
||||
// Unpad
|
||||
var i = data.sigBytes - 1;
|
||||
while (!((dataWords[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff)) {
|
||||
i--;
|
||||
}
|
||||
data.sigBytes = i + 1;
|
||||
}
|
||||
};
|
@ -1,131 +0,0 @@
|
||||
/*
|
||||
CryptoJS v3.1.2
|
||||
code.google.com/p/crypto-js
|
||||
(c) 2009-2013 by Jeff Mott. All rights reserved.
|
||||
code.google.com/p/crypto-js/wiki/License
|
||||
*/
|
||||
(function () {
|
||||
// Shortcuts
|
||||
var C = CryptoJS;
|
||||
var C_lib = C.lib;
|
||||
var Base = C_lib.Base;
|
||||
var WordArray = C_lib.WordArray;
|
||||
var C_algo = C.algo;
|
||||
var SHA1 = C_algo.SHA1;
|
||||
var HMAC = C_algo.HMAC;
|
||||
|
||||
/**
|
||||
* Password-Based Key Derivation Function 2 algorithm.
|
||||
*/
|
||||
var PBKDF2 = C_algo.PBKDF2 = Base.extend({
|
||||
/**
|
||||
* Configuration options.
|
||||
*
|
||||
* @property {number} keySize The key size in words to generate. Default: 4 (128 bits)
|
||||
* @property {Hasher} hasher The hasher to use. Default: SHA1
|
||||
* @property {number} iterations The number of iterations to perform. Default: 1
|
||||
*/
|
||||
cfg: Base.extend({
|
||||
keySize: 128/32,
|
||||
hasher: SHA1,
|
||||
iterations: 1
|
||||
}),
|
||||
|
||||
/**
|
||||
* Initializes a newly created key derivation function.
|
||||
*
|
||||
* @param {Object} cfg (Optional) The configuration options to use for the derivation.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* var kdf = CryptoJS.algo.PBKDF2.create();
|
||||
* var kdf = CryptoJS.algo.PBKDF2.create({ keySize: 8 });
|
||||
* var kdf = CryptoJS.algo.PBKDF2.create({ keySize: 8, iterations: 1000 });
|
||||
*/
|
||||
init: function (cfg) {
|
||||
this.cfg = this.cfg.extend(cfg);
|
||||
},
|
||||
|
||||
/**
|
||||
* Computes the Password-Based Key Derivation Function 2.
|
||||
*
|
||||
* @param {WordArray|string} password The password.
|
||||
* @param {WordArray|string} salt A salt.
|
||||
*
|
||||
* @return {WordArray} The derived key.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* var key = kdf.compute(password, salt);
|
||||
*/
|
||||
compute: function (password, salt) {
|
||||
// Shortcut
|
||||
var cfg = this.cfg;
|
||||
|
||||
// Init HMAC
|
||||
var hmac = HMAC.create(cfg.hasher, password);
|
||||
|
||||
// Initial values
|
||||
var derivedKey = WordArray.create();
|
||||
var blockIndex = WordArray.create([0x00000001]);
|
||||
|
||||
// Shortcuts
|
||||
var derivedKeyWords = derivedKey.words;
|
||||
var blockIndexWords = blockIndex.words;
|
||||
var keySize = cfg.keySize;
|
||||
var iterations = cfg.iterations;
|
||||
|
||||
// Generate key
|
||||
while (derivedKeyWords.length < keySize) {
|
||||
var block = hmac.update(salt).finalize(blockIndex);
|
||||
hmac.reset();
|
||||
|
||||
// Shortcuts
|
||||
var blockWords = block.words;
|
||||
var blockWordsLength = blockWords.length;
|
||||
|
||||
// Iterations
|
||||
var intermediate = block;
|
||||
for (var i = 1; i < iterations; i++) {
|
||||
intermediate = hmac.finalize(intermediate);
|
||||
hmac.reset();
|
||||
|
||||
// Shortcut
|
||||
var intermediateWords = intermediate.words;
|
||||
|
||||
// XOR intermediate with block
|
||||
for (var j = 0; j < blockWordsLength; j++) {
|
||||
blockWords[j] ^= intermediateWords[j];
|
||||
}
|
||||
}
|
||||
|
||||
derivedKey.concat(block);
|
||||
blockIndexWords[0]++;
|
||||
}
|
||||
derivedKey.sigBytes = keySize * 4;
|
||||
|
||||
return derivedKey;
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Computes the Password-Based Key Derivation Function 2.
|
||||
*
|
||||
* @param {WordArray|string} password The password.
|
||||
* @param {WordArray|string} salt A salt.
|
||||
* @param {Object} cfg (Optional) The configuration options to use for this computation.
|
||||
*
|
||||
* @return {WordArray} The derived key.
|
||||
*
|
||||
* @static
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* var key = CryptoJS.PBKDF2(password, salt);
|
||||
* var key = CryptoJS.PBKDF2(password, salt, { keySize: 8 });
|
||||
* var key = CryptoJS.PBKDF2(password, salt, { keySize: 8, iterations: 1000 });
|
||||
*/
|
||||
C.PBKDF2 = function (password, salt, cfg) {
|
||||
return PBKDF2.create(cfg).compute(password, salt);
|
||||
};
|
||||
}());
|
@ -1,176 +0,0 @@
|
||||
/*
|
||||
CryptoJS v3.1.2
|
||||
code.google.com/p/crypto-js
|
||||
(c) 2009-2013 by Jeff Mott. All rights reserved.
|
||||
code.google.com/p/crypto-js/wiki/License
|
||||
*/
|
||||
(function () {
|
||||
// Shortcuts
|
||||
var C = CryptoJS;
|
||||
var C_lib = C.lib;
|
||||
var StreamCipher = C_lib.StreamCipher;
|
||||
var C_algo = C.algo;
|
||||
|
||||
// Reusable objects
|
||||
var S = [];
|
||||
var C_ = [];
|
||||
var G = [];
|
||||
|
||||
/**
|
||||
* Rabbit stream cipher algorithm.
|
||||
*
|
||||
* This is a legacy version that neglected to convert the key to little-endian.
|
||||
* This error doesn't affect the cipher's security,
|
||||
* but it does affect its compatibility with other implementations.
|
||||
*/
|
||||
var RabbitLegacy = C_algo.RabbitLegacy = StreamCipher.extend({
|
||||
_doReset: function () {
|
||||
// Shortcuts
|
||||
var K = this._key.words;
|
||||
var iv = this.cfg.iv;
|
||||
|
||||
// Generate initial state values
|
||||
var X = this._X = [
|
||||
K[0], (K[3] << 16) | (K[2] >>> 16),
|
||||
K[1], (K[0] << 16) | (K[3] >>> 16),
|
||||
K[2], (K[1] << 16) | (K[0] >>> 16),
|
||||
K[3], (K[2] << 16) | (K[1] >>> 16)
|
||||
];
|
||||
|
||||
// Generate initial counter values
|
||||
var C = this._C = [
|
||||
(K[2] << 16) | (K[2] >>> 16), (K[0] & 0xffff0000) | (K[1] & 0x0000ffff),
|
||||
(K[3] << 16) | (K[3] >>> 16), (K[1] & 0xffff0000) | (K[2] & 0x0000ffff),
|
||||
(K[0] << 16) | (K[0] >>> 16), (K[2] & 0xffff0000) | (K[3] & 0x0000ffff),
|
||||
(K[1] << 16) | (K[1] >>> 16), (K[3] & 0xffff0000) | (K[0] & 0x0000ffff)
|
||||
];
|
||||
|
||||
// Carry bit
|
||||
this._b = 0;
|
||||
|
||||
// Iterate the system four times
|
||||
for (var i = 0; i < 4; i++) {
|
||||
nextState.call(this);
|
||||
}
|
||||
|
||||
// Modify the counters
|
||||
for (var i = 0; i < 8; i++) {
|
||||
C[i] ^= X[(i + 4) & 7];
|
||||
}
|
||||
|
||||
// IV setup
|
||||
if (iv) {
|
||||
// Shortcuts
|
||||
var IV = iv.words;
|
||||
var IV_0 = IV[0];
|
||||
var IV_1 = IV[1];
|
||||
|
||||
// Generate four subvectors
|
||||
var i0 = (((IV_0 << 8) | (IV_0 >>> 24)) & 0x00ff00ff) | (((IV_0 << 24) | (IV_0 >>> 8)) & 0xff00ff00);
|
||||
var i2 = (((IV_1 << 8) | (IV_1 >>> 24)) & 0x00ff00ff) | (((IV_1 << 24) | (IV_1 >>> 8)) & 0xff00ff00);
|
||||
var i1 = (i0 >>> 16) | (i2 & 0xffff0000);
|
||||
var i3 = (i2 << 16) | (i0 & 0x0000ffff);
|
||||
|
||||
// Modify counter values
|
||||
C[0] ^= i0;
|
||||
C[1] ^= i1;
|
||||
C[2] ^= i2;
|
||||
C[3] ^= i3;
|
||||
C[4] ^= i0;
|
||||
C[5] ^= i1;
|
||||
C[6] ^= i2;
|
||||
C[7] ^= i3;
|
||||
|
||||
// Iterate the system four times
|
||||
for (var i = 0; i < 4; i++) {
|
||||
nextState.call(this);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
_doProcessBlock: function (M, offset) {
|
||||
// Shortcut
|
||||
var X = this._X;
|
||||
|
||||
// Iterate the system
|
||||
nextState.call(this);
|
||||
|
||||
// Generate four keystream words
|
||||
S[0] = X[0] ^ (X[5] >>> 16) ^ (X[3] << 16);
|
||||
S[1] = X[2] ^ (X[7] >>> 16) ^ (X[5] << 16);
|
||||
S[2] = X[4] ^ (X[1] >>> 16) ^ (X[7] << 16);
|
||||
S[3] = X[6] ^ (X[3] >>> 16) ^ (X[1] << 16);
|
||||
|
||||
for (var i = 0; i < 4; i++) {
|
||||
// Swap endian
|
||||
S[i] = (((S[i] << 8) | (S[i] >>> 24)) & 0x00ff00ff) |
|
||||
(((S[i] << 24) | (S[i] >>> 8)) & 0xff00ff00);
|
||||
|
||||
// Encrypt
|
||||
M[offset + i] ^= S[i];
|
||||
}
|
||||
},
|
||||
|
||||
blockSize: 128/32,
|
||||
|
||||
ivSize: 64/32
|
||||
});
|
||||
|
||||
function nextState() {
|
||||
// Shortcuts
|
||||
var X = this._X;
|
||||
var C = this._C;
|
||||
|
||||
// Save old counter values
|
||||
for (var i = 0; i < 8; i++) {
|
||||
C_[i] = C[i];
|
||||
}
|
||||
|
||||
// Calculate new counter values
|
||||
C[0] = (C[0] + 0x4d34d34d + this._b) | 0;
|
||||
C[1] = (C[1] + 0xd34d34d3 + ((C[0] >>> 0) < (C_[0] >>> 0) ? 1 : 0)) | 0;
|
||||
C[2] = (C[2] + 0x34d34d34 + ((C[1] >>> 0) < (C_[1] >>> 0) ? 1 : 0)) | 0;
|
||||
C[3] = (C[3] + 0x4d34d34d + ((C[2] >>> 0) < (C_[2] >>> 0) ? 1 : 0)) | 0;
|
||||
C[4] = (C[4] + 0xd34d34d3 + ((C[3] >>> 0) < (C_[3] >>> 0) ? 1 : 0)) | 0;
|
||||
C[5] = (C[5] + 0x34d34d34 + ((C[4] >>> 0) < (C_[4] >>> 0) ? 1 : 0)) | 0;
|
||||
C[6] = (C[6] + 0x4d34d34d + ((C[5] >>> 0) < (C_[5] >>> 0) ? 1 : 0)) | 0;
|
||||
C[7] = (C[7] + 0xd34d34d3 + ((C[6] >>> 0) < (C_[6] >>> 0) ? 1 : 0)) | 0;
|
||||
this._b = (C[7] >>> 0) < (C_[7] >>> 0) ? 1 : 0;
|
||||
|
||||
// Calculate the g-values
|
||||
for (var i = 0; i < 8; i++) {
|
||||
var gx = X[i] + C[i];
|
||||
|
||||
// Construct high and low argument for squaring
|
||||
var ga = gx & 0xffff;
|
||||
var gb = gx >>> 16;
|
||||
|
||||
// Calculate high and low result of squaring
|
||||
var gh = ((((ga * ga) >>> 17) + ga * gb) >>> 15) + gb * gb;
|
||||
var gl = (((gx & 0xffff0000) * gx) | 0) + (((gx & 0x0000ffff) * gx) | 0);
|
||||
|
||||
// High XOR low
|
||||
G[i] = gh ^ gl;
|
||||
}
|
||||
|
||||
// Calculate new state values
|
||||
X[0] = (G[0] + ((G[7] << 16) | (G[7] >>> 16)) + ((G[6] << 16) | (G[6] >>> 16))) | 0;
|
||||
X[1] = (G[1] + ((G[0] << 8) | (G[0] >>> 24)) + G[7]) | 0;
|
||||
X[2] = (G[2] + ((G[1] << 16) | (G[1] >>> 16)) + ((G[0] << 16) | (G[0] >>> 16))) | 0;
|
||||
X[3] = (G[3] + ((G[2] << 8) | (G[2] >>> 24)) + G[1]) | 0;
|
||||
X[4] = (G[4] + ((G[3] << 16) | (G[3] >>> 16)) + ((G[2] << 16) | (G[2] >>> 16))) | 0;
|
||||
X[5] = (G[5] + ((G[4] << 8) | (G[4] >>> 24)) + G[3]) | 0;
|
||||
X[6] = (G[6] + ((G[5] << 16) | (G[5] >>> 16)) + ((G[4] << 16) | (G[4] >>> 16))) | 0;
|
||||
X[7] = (G[7] + ((G[6] << 8) | (G[6] >>> 24)) + G[5]) | 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shortcut functions to the cipher's object interface.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* var ciphertext = CryptoJS.RabbitLegacy.encrypt(message, key, cfg);
|
||||
* var plaintext = CryptoJS.RabbitLegacy.decrypt(ciphertext, key, cfg);
|
||||
*/
|
||||
C.RabbitLegacy = StreamCipher._createHelper(RabbitLegacy);
|
||||
}());
|
@ -1,178 +0,0 @@
|
||||
/*
|
||||
CryptoJS v3.1.2
|
||||
code.google.com/p/crypto-js
|
||||
(c) 2009-2013 by Jeff Mott. All rights reserved.
|
||||
code.google.com/p/crypto-js/wiki/License
|
||||
*/
|
||||
(function () {
|
||||
// Shortcuts
|
||||
var C = CryptoJS;
|
||||
var C_lib = C.lib;
|
||||
var StreamCipher = C_lib.StreamCipher;
|
||||
var C_algo = C.algo;
|
||||
|
||||
// Reusable objects
|
||||
var S = [];
|
||||
var C_ = [];
|
||||
var G = [];
|
||||
|
||||
/**
|
||||
* Rabbit stream cipher algorithm
|
||||
*/
|
||||
var Rabbit = C_algo.Rabbit = StreamCipher.extend({
|
||||
_doReset: function () {
|
||||
// Shortcuts
|
||||
var K = this._key.words;
|
||||
var iv = this.cfg.iv;
|
||||
|
||||
// Swap endian
|
||||
for (var i = 0; i < 4; i++) {
|
||||
K[i] = (((K[i] << 8) | (K[i] >>> 24)) & 0x00ff00ff) |
|
||||
(((K[i] << 24) | (K[i] >>> 8)) & 0xff00ff00);
|
||||
}
|
||||
|
||||
// Generate initial state values
|
||||
var X = this._X = [
|
||||
K[0], (K[3] << 16) | (K[2] >>> 16),
|
||||
K[1], (K[0] << 16) | (K[3] >>> 16),
|
||||
K[2], (K[1] << 16) | (K[0] >>> 16),
|
||||
K[3], (K[2] << 16) | (K[1] >>> 16)
|
||||
];
|
||||
|
||||
// Generate initial counter values
|
||||
var C = this._C = [
|
||||
(K[2] << 16) | (K[2] >>> 16), (K[0] & 0xffff0000) | (K[1] & 0x0000ffff),
|
||||
(K[3] << 16) | (K[3] >>> 16), (K[1] & 0xffff0000) | (K[2] & 0x0000ffff),
|
||||
(K[0] << 16) | (K[0] >>> 16), (K[2] & 0xffff0000) | (K[3] & 0x0000ffff),
|
||||
(K[1] << 16) | (K[1] >>> 16), (K[3] & 0xffff0000) | (K[0] & 0x0000ffff)
|
||||
];
|
||||
|
||||
// Carry bit
|
||||
this._b = 0;
|
||||
|
||||
// Iterate the system four times
|
||||
for (var i = 0; i < 4; i++) {
|
||||
nextState.call(this);
|
||||
}
|
||||
|
||||
// Modify the counters
|
||||
for (var i = 0; i < 8; i++) {
|
||||
C[i] ^= X[(i + 4) & 7];
|
||||
}
|
||||
|
||||
// IV setup
|
||||
if (iv) {
|
||||
// Shortcuts
|
||||
var IV = iv.words;
|
||||
var IV_0 = IV[0];
|
||||
var IV_1 = IV[1];
|
||||
|
||||
// Generate four subvectors
|
||||
var i0 = (((IV_0 << 8) | (IV_0 >>> 24)) & 0x00ff00ff) | (((IV_0 << 24) | (IV_0 >>> 8)) & 0xff00ff00);
|
||||
var i2 = (((IV_1 << 8) | (IV_1 >>> 24)) & 0x00ff00ff) | (((IV_1 << 24) | (IV_1 >>> 8)) & 0xff00ff00);
|
||||
var i1 = (i0 >>> 16) | (i2 & 0xffff0000);
|
||||
var i3 = (i2 << 16) | (i0 & 0x0000ffff);
|
||||
|
||||
// Modify counter values
|
||||
C[0] ^= i0;
|
||||
C[1] ^= i1;
|
||||
C[2] ^= i2;
|
||||
C[3] ^= i3;
|
||||
C[4] ^= i0;
|
||||
C[5] ^= i1;
|
||||
C[6] ^= i2;
|
||||
C[7] ^= i3;
|
||||
|
||||
// Iterate the system four times
|
||||
for (var i = 0; i < 4; i++) {
|
||||
nextState.call(this);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
_doProcessBlock: function (M, offset) {
|
||||
// Shortcut
|
||||
var X = this._X;
|
||||
|
||||
// Iterate the system
|
||||
nextState.call(this);
|
||||
|
||||
// Generate four keystream words
|
||||
S[0] = X[0] ^ (X[5] >>> 16) ^ (X[3] << 16);
|
||||
S[1] = X[2] ^ (X[7] >>> 16) ^ (X[5] << 16);
|
||||
S[2] = X[4] ^ (X[1] >>> 16) ^ (X[7] << 16);
|
||||
S[3] = X[6] ^ (X[3] >>> 16) ^ (X[1] << 16);
|
||||
|
||||
for (var i = 0; i < 4; i++) {
|
||||
// Swap endian
|
||||
S[i] = (((S[i] << 8) | (S[i] >>> 24)) & 0x00ff00ff) |
|
||||
(((S[i] << 24) | (S[i] >>> 8)) & 0xff00ff00);
|
||||
|
||||
// Encrypt
|
||||
M[offset + i] ^= S[i];
|
||||
}
|
||||
},
|
||||
|
||||
blockSize: 128/32,
|
||||
|
||||
ivSize: 64/32
|
||||
});
|
||||
|
||||
function nextState() {
|
||||
// Shortcuts
|
||||
var X = this._X;
|
||||
var C = this._C;
|
||||
|
||||
// Save old counter values
|
||||
for (var i = 0; i < 8; i++) {
|
||||
C_[i] = C[i];
|
||||
}
|
||||
|
||||
// Calculate new counter values
|
||||
C[0] = (C[0] + 0x4d34d34d + this._b) | 0;
|
||||
C[1] = (C[1] + 0xd34d34d3 + ((C[0] >>> 0) < (C_[0] >>> 0) ? 1 : 0)) | 0;
|
||||
C[2] = (C[2] + 0x34d34d34 + ((C[1] >>> 0) < (C_[1] >>> 0) ? 1 : 0)) | 0;
|
||||
C[3] = (C[3] + 0x4d34d34d + ((C[2] >>> 0) < (C_[2] >>> 0) ? 1 : 0)) | 0;
|
||||
C[4] = (C[4] + 0xd34d34d3 + ((C[3] >>> 0) < (C_[3] >>> 0) ? 1 : 0)) | 0;
|
||||
C[5] = (C[5] + 0x34d34d34 + ((C[4] >>> 0) < (C_[4] >>> 0) ? 1 : 0)) | 0;
|
||||
C[6] = (C[6] + 0x4d34d34d + ((C[5] >>> 0) < (C_[5] >>> 0) ? 1 : 0)) | 0;
|
||||
C[7] = (C[7] + 0xd34d34d3 + ((C[6] >>> 0) < (C_[6] >>> 0) ? 1 : 0)) | 0;
|
||||
this._b = (C[7] >>> 0) < (C_[7] >>> 0) ? 1 : 0;
|
||||
|
||||
// Calculate the g-values
|
||||
for (var i = 0; i < 8; i++) {
|
||||
var gx = X[i] + C[i];
|
||||
|
||||
// Construct high and low argument for squaring
|
||||
var ga = gx & 0xffff;
|
||||
var gb = gx >>> 16;
|
||||
|
||||
// Calculate high and low result of squaring
|
||||
var gh = ((((ga * ga) >>> 17) + ga * gb) >>> 15) + gb * gb;
|
||||
var gl = (((gx & 0xffff0000) * gx) | 0) + (((gx & 0x0000ffff) * gx) | 0);
|
||||
|
||||
// High XOR low
|
||||
G[i] = gh ^ gl;
|
||||
}
|
||||
|
||||
// Calculate new state values
|
||||
X[0] = (G[0] + ((G[7] << 16) | (G[7] >>> 16)) + ((G[6] << 16) | (G[6] >>> 16))) | 0;
|
||||
X[1] = (G[1] + ((G[0] << 8) | (G[0] >>> 24)) + G[7]) | 0;
|
||||
X[2] = (G[2] + ((G[1] << 16) | (G[1] >>> 16)) + ((G[0] << 16) | (G[0] >>> 16))) | 0;
|
||||
X[3] = (G[3] + ((G[2] << 8) | (G[2] >>> 24)) + G[1]) | 0;
|
||||
X[4] = (G[4] + ((G[3] << 16) | (G[3] >>> 16)) + ((G[2] << 16) | (G[2] >>> 16))) | 0;
|
||||
X[5] = (G[5] + ((G[4] << 8) | (G[4] >>> 24)) + G[3]) | 0;
|
||||
X[6] = (G[6] + ((G[5] << 16) | (G[5] >>> 16)) + ((G[4] << 16) | (G[4] >>> 16))) | 0;
|
||||
X[7] = (G[7] + ((G[6] << 8) | (G[6] >>> 24)) + G[5]) | 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shortcut functions to the cipher's object interface.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* var ciphertext = CryptoJS.Rabbit.encrypt(message, key, cfg);
|
||||
* var plaintext = CryptoJS.Rabbit.decrypt(ciphertext, key, cfg);
|
||||
*/
|
||||
C.Rabbit = StreamCipher._createHelper(Rabbit);
|
||||
}());
|
@ -1,125 +0,0 @@
|
||||
/*
|
||||
CryptoJS v3.1.2
|
||||
code.google.com/p/crypto-js
|
||||
(c) 2009-2013 by Jeff Mott. All rights reserved.
|
||||
code.google.com/p/crypto-js/wiki/License
|
||||
*/
|
||||
(function () {
|
||||
// Shortcuts
|
||||
var C = CryptoJS;
|
||||
var C_lib = C.lib;
|
||||
var StreamCipher = C_lib.StreamCipher;
|
||||
var C_algo = C.algo;
|
||||
|
||||
/**
|
||||
* RC4 stream cipher algorithm.
|
||||
*/
|
||||
var RC4 = C_algo.RC4 = StreamCipher.extend({
|
||||
_doReset: function () {
|
||||
// Shortcuts
|
||||
var key = this._key;
|
||||
var keyWords = key.words;
|
||||
var keySigBytes = key.sigBytes;
|
||||
|
||||
// Init sbox
|
||||
var S = this._S = [];
|
||||
for (var i = 0; i < 256; i++) {
|
||||
S[i] = i;
|
||||
}
|
||||
|
||||
// Key setup
|
||||
for (var i = 0, j = 0; i < 256; i++) {
|
||||
var keyByteIndex = i % keySigBytes;
|
||||
var keyByte = (keyWords[keyByteIndex >>> 2] >>> (24 - (keyByteIndex % 4) * 8)) & 0xff;
|
||||
|
||||
j = (j + S[i] + keyByte) % 256;
|
||||
|
||||
// Swap
|
||||
var t = S[i];
|
||||
S[i] = S[j];
|
||||
S[j] = t;
|
||||
}
|
||||
|
||||
// Counters
|
||||
this._i = this._j = 0;
|
||||
},
|
||||
|
||||
_doProcessBlock: function (M, offset) {
|
||||
M[offset] ^= generateKeystreamWord.call(this);
|
||||
},
|
||||
|
||||
keySize: 256/32,
|
||||
|
||||
ivSize: 0
|
||||
});
|
||||
|
||||
function generateKeystreamWord() {
|
||||
// Shortcuts
|
||||
var S = this._S;
|
||||
var i = this._i;
|
||||
var j = this._j;
|
||||
|
||||
// Generate keystream word
|
||||
var keystreamWord = 0;
|
||||
for (var n = 0; n < 4; n++) {
|
||||
i = (i + 1) % 256;
|
||||
j = (j + S[i]) % 256;
|
||||
|
||||
// Swap
|
||||
var t = S[i];
|
||||
S[i] = S[j];
|
||||
S[j] = t;
|
||||
|
||||
keystreamWord |= S[(S[i] + S[j]) % 256] << (24 - n * 8);
|
||||
}
|
||||
|
||||
// Update counters
|
||||
this._i = i;
|
||||
this._j = j;
|
||||
|
||||
return keystreamWord;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shortcut functions to the cipher's object interface.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* var ciphertext = CryptoJS.RC4.encrypt(message, key, cfg);
|
||||
* var plaintext = CryptoJS.RC4.decrypt(ciphertext, key, cfg);
|
||||
*/
|
||||
C.RC4 = StreamCipher._createHelper(RC4);
|
||||
|
||||
/**
|
||||
* Modified RC4 stream cipher algorithm.
|
||||
*/
|
||||
var RC4Drop = C_algo.RC4Drop = RC4.extend({
|
||||
/**
|
||||
* Configuration options.
|
||||
*
|
||||
* @property {number} drop The number of keystream words to drop. Default 192
|
||||
*/
|
||||
cfg: RC4.cfg.extend({
|
||||
drop: 192
|
||||
}),
|
||||
|
||||
_doReset: function () {
|
||||
RC4._doReset.call(this);
|
||||
|
||||
// Drop
|
||||
for (var i = this.cfg.drop; i > 0; i--) {
|
||||
generateKeystreamWord.call(this);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Shortcut functions to the cipher's object interface.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* var ciphertext = CryptoJS.RC4Drop.encrypt(message, key, cfg);
|
||||
* var plaintext = CryptoJS.RC4Drop.decrypt(ciphertext, key, cfg);
|
||||
*/
|
||||
C.RC4Drop = StreamCipher._createHelper(RC4Drop);
|
||||
}());
|
@ -1,255 +0,0 @@
|
||||
/*
|
||||
CryptoJS v3.1.2
|
||||
code.google.com/p/crypto-js
|
||||
(c) 2009-2013 by Jeff Mott. All rights reserved.
|
||||
code.google.com/p/crypto-js/wiki/License
|
||||
*/
|
||||
/** @license
|
||||
========================================================================
|
||||
RIPEMD160
|
||||
(c) 2012 by Cédric Mesnil. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
- Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
- Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
(function (Math) {
|
||||
// Shortcuts
|
||||
var C = CryptoJS;
|
||||
var C_lib = C.lib;
|
||||
var WordArray = C_lib.WordArray;
|
||||
var Hasher = C_lib.Hasher;
|
||||
var C_algo = C.algo;
|
||||
|
||||
// Constants table
|
||||
var _zl = WordArray.create([
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
|
||||
7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8,
|
||||
3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12,
|
||||
1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2,
|
||||
4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13]);
|
||||
var _zr = WordArray.create([
|
||||
5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12,
|
||||
6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2,
|
||||
15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13,
|
||||
8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14,
|
||||
12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11]);
|
||||
var _sl = WordArray.create([
|
||||
11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8,
|
||||
7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12,
|
||||
11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5,
|
||||
11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12,
|
||||
9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6 ]);
|
||||
var _sr = WordArray.create([
|
||||
8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6,
|
||||
9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11,
|
||||
9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5,
|
||||
15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8,
|
||||
8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11 ]);
|
||||
|
||||
var _hl = WordArray.create([ 0x00000000, 0x5A827999, 0x6ED9EBA1, 0x8F1BBCDC, 0xA953FD4E]);
|
||||
var _hr = WordArray.create([ 0x50A28BE6, 0x5C4DD124, 0x6D703EF3, 0x7A6D76E9, 0x00000000]);
|
||||
|
||||
/**
|
||||
* RIPEMD160 hash algorithm.
|
||||
*/
|
||||
var RIPEMD160 = C_algo.RIPEMD160 = Hasher.extend({
|
||||
_doReset: function () {
|
||||
this._hash = WordArray.create([0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0]);
|
||||
},
|
||||
|
||||
_doProcessBlock: function (M, offset) {
|
||||
|
||||
// Swap endian
|
||||
for (var i = 0; i < 16; i++) {
|
||||
// Shortcuts
|
||||
var offset_i = offset + i;
|
||||
var M_offset_i = M[offset_i];
|
||||
|
||||
// Swap
|
||||
M[offset_i] = (
|
||||
(((M_offset_i << 8) | (M_offset_i >>> 24)) & 0x00ff00ff) |
|
||||
(((M_offset_i << 24) | (M_offset_i >>> 8)) & 0xff00ff00)
|
||||
);
|
||||
}
|
||||
// Shortcut
|
||||
var H = this._hash.words;
|
||||
var hl = _hl.words;
|
||||
var hr = _hr.words;
|
||||
var zl = _zl.words;
|
||||
var zr = _zr.words;
|
||||
var sl = _sl.words;
|
||||
var sr = _sr.words;
|
||||
|
||||
// Working variables
|
||||
var al, bl, cl, dl, el;
|
||||
var ar, br, cr, dr, er;
|
||||
|
||||
ar = al = H[0];
|
||||
br = bl = H[1];
|
||||
cr = cl = H[2];
|
||||
dr = dl = H[3];
|
||||
er = el = H[4];
|
||||
// Computation
|
||||
var t;
|
||||
for (var i = 0; i < 80; i += 1) {
|
||||
t = (al + M[offset+zl[i]])|0;
|
||||
if (i<16){
|
||||
t += f1(bl,cl,dl) + hl[0];
|
||||
} else if (i<32) {
|
||||
t += f2(bl,cl,dl) + hl[1];
|
||||
} else if (i<48) {
|
||||
t += f3(bl,cl,dl) + hl[2];
|
||||
} else if (i<64) {
|
||||
t += f4(bl,cl,dl) + hl[3];
|
||||
} else {// if (i<80) {
|
||||
t += f5(bl,cl,dl) + hl[4];
|
||||
}
|
||||
t = t|0;
|
||||
t = rotl(t,sl[i]);
|
||||
t = (t+el)|0;
|
||||
al = el;
|
||||
el = dl;
|
||||
dl = rotl(cl, 10);
|
||||
cl = bl;
|
||||
bl = t;
|
||||
|
||||
t = (ar + M[offset+zr[i]])|0;
|
||||
if (i<16){
|
||||
t += f5(br,cr,dr) + hr[0];
|
||||
} else if (i<32) {
|
||||
t += f4(br,cr,dr) + hr[1];
|
||||
} else if (i<48) {
|
||||
t += f3(br,cr,dr) + hr[2];
|
||||
} else if (i<64) {
|
||||
t += f2(br,cr,dr) + hr[3];
|
||||
} else {// if (i<80) {
|
||||
t += f1(br,cr,dr) + hr[4];
|
||||
}
|
||||
t = t|0;
|
||||
t = rotl(t,sr[i]) ;
|
||||
t = (t+er)|0;
|
||||
ar = er;
|
||||
er = dr;
|
||||
dr = rotl(cr, 10);
|
||||
cr = br;
|
||||
br = t;
|
||||
}
|
||||
// Intermediate hash value
|
||||
t = (H[1] + cl + dr)|0;
|
||||
H[1] = (H[2] + dl + er)|0;
|
||||
H[2] = (H[3] + el + ar)|0;
|
||||
H[3] = (H[4] + al + br)|0;
|
||||
H[4] = (H[0] + bl + cr)|0;
|
||||
H[0] = t;
|
||||
},
|
||||
|
||||
_doFinalize: function () {
|
||||
// Shortcuts
|
||||
var data = this._data;
|
||||
var dataWords = data.words;
|
||||
|
||||
var nBitsTotal = this._nDataBytes * 8;
|
||||
var nBitsLeft = data.sigBytes * 8;
|
||||
|
||||
// Add padding
|
||||
dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32);
|
||||
dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = (
|
||||
(((nBitsTotal << 8) | (nBitsTotal >>> 24)) & 0x00ff00ff) |
|
||||
(((nBitsTotal << 24) | (nBitsTotal >>> 8)) & 0xff00ff00)
|
||||
);
|
||||
data.sigBytes = (dataWords.length + 1) * 4;
|
||||
|
||||
// Hash final blocks
|
||||
this._process();
|
||||
|
||||
// Shortcuts
|
||||
var hash = this._hash;
|
||||
var H = hash.words;
|
||||
|
||||
// Swap endian
|
||||
for (var i = 0; i < 5; i++) {
|
||||
// Shortcut
|
||||
var H_i = H[i];
|
||||
|
||||
// Swap
|
||||
H[i] = (((H_i << 8) | (H_i >>> 24)) & 0x00ff00ff) |
|
||||
(((H_i << 24) | (H_i >>> 8)) & 0xff00ff00);
|
||||
}
|
||||
|
||||
// Return final computed hash
|
||||
return hash;
|
||||
},
|
||||
|
||||
clone: function () {
|
||||
var clone = Hasher.clone.call(this);
|
||||
clone._hash = this._hash.clone();
|
||||
|
||||
return clone;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
function f1(x, y, z) {
|
||||
return ((x) ^ (y) ^ (z));
|
||||
|
||||
}
|
||||
|
||||
function f2(x, y, z) {
|
||||
return (((x)&(y)) | ((~x)&(z)));
|
||||
}
|
||||
|
||||
function f3(x, y, z) {
|
||||
return (((x) | (~(y))) ^ (z));
|
||||
}
|
||||
|
||||
function f4(x, y, z) {
|
||||
return (((x) & (z)) | ((y)&(~(z))));
|
||||
}
|
||||
|
||||
function f5(x, y, z) {
|
||||
return ((x) ^ ((y) |(~(z))));
|
||||
|
||||
}
|
||||
|
||||
function rotl(x,n) {
|
||||
return (x<<n) | (x>>>(32-n));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Shortcut function to the hasher's object interface.
|
||||
*
|
||||
* @param {WordArray|string} message The message to hash.
|
||||
*
|
||||
* @return {WordArray} The hash.
|
||||
*
|
||||
* @static
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* var hash = CryptoJS.RIPEMD160('message');
|
||||
* var hash = CryptoJS.RIPEMD160(wordArray);
|
||||
*/
|
||||
C.RIPEMD160 = Hasher._createHelper(RIPEMD160);
|
||||
|
||||
/**
|
||||
* Shortcut function to the HMAC's object interface.
|
||||
*
|
||||
* @param {WordArray|string} message The message to hash.
|
||||
* @param {WordArray|string} key The secret key.
|
||||
*
|
||||
* @return {WordArray} The HMAC.
|
||||
*
|
||||
* @static
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* var hmac = CryptoJS.HmacRIPEMD160(message, key);
|
||||
*/
|
||||
C.HmacRIPEMD160 = Hasher._createHmacHelper(RIPEMD160);
|
||||
}(Math));
|
@ -1,136 +0,0 @@
|
||||
/*
|
||||
CryptoJS v3.1.2
|
||||
code.google.com/p/crypto-js
|
||||
(c) 2009-2013 by Jeff Mott. All rights reserved.
|
||||
code.google.com/p/crypto-js/wiki/License
|
||||
*/
|
||||
(function () {
|
||||
// Shortcuts
|
||||
var C = CryptoJS;
|
||||
var C_lib = C.lib;
|
||||
var WordArray = C_lib.WordArray;
|
||||
var Hasher = C_lib.Hasher;
|
||||
var C_algo = C.algo;
|
||||
|
||||
// Reusable object
|
||||
var W = [];
|
||||
|
||||
/**
|
||||
* SHA-1 hash algorithm.
|
||||
*/
|
||||
var SHA1 = C_algo.SHA1 = Hasher.extend({
|
||||
_doReset: function () {
|
||||
this._hash = new WordArray.init([
|
||||
0x67452301, 0xefcdab89,
|
||||
0x98badcfe, 0x10325476,
|
||||
0xc3d2e1f0
|
||||
]);
|
||||
},
|
||||
|
||||
_doProcessBlock: function (M, offset) {
|
||||
// Shortcut
|
||||
var H = this._hash.words;
|
||||
|
||||
// Working variables
|
||||
var a = H[0];
|
||||
var b = H[1];
|
||||
var c = H[2];
|
||||
var d = H[3];
|
||||
var e = H[4];
|
||||
|
||||
// Computation
|
||||
for (var i = 0; i < 80; i++) {
|
||||
if (i < 16) {
|
||||
W[i] = M[offset + i] | 0;
|
||||
} else {
|
||||
var n = W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16];
|
||||
W[i] = (n << 1) | (n >>> 31);
|
||||
}
|
||||
|
||||
var t = ((a << 5) | (a >>> 27)) + e + W[i];
|
||||
if (i < 20) {
|
||||
t += ((b & c) | (~b & d)) + 0x5a827999;
|
||||
} else if (i < 40) {
|
||||
t += (b ^ c ^ d) + 0x6ed9eba1;
|
||||
} else if (i < 60) {
|
||||
t += ((b & c) | (b & d) | (c & d)) - 0x70e44324;
|
||||
} else /* if (i < 80) */ {
|
||||
t += (b ^ c ^ d) - 0x359d3e2a;
|
||||
}
|
||||
|
||||
e = d;
|
||||
d = c;
|
||||
c = (b << 30) | (b >>> 2);
|
||||
b = a;
|
||||
a = t;
|
||||
}
|
||||
|
||||
// Intermediate hash value
|
||||
H[0] = (H[0] + a) | 0;
|
||||
H[1] = (H[1] + b) | 0;
|
||||
H[2] = (H[2] + c) | 0;
|
||||
H[3] = (H[3] + d) | 0;
|
||||
H[4] = (H[4] + e) | 0;
|
||||
},
|
||||
|
||||
_doFinalize: function () {
|
||||
// Shortcuts
|
||||
var data = this._data;
|
||||
var dataWords = data.words;
|
||||
|
||||
var nBitsTotal = this._nDataBytes * 8;
|
||||
var nBitsLeft = data.sigBytes * 8;
|
||||
|
||||
// Add padding
|
||||
dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32);
|
||||
dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = Math.floor(nBitsTotal / 0x100000000);
|
||||
dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = nBitsTotal;
|
||||
data.sigBytes = dataWords.length * 4;
|
||||
|
||||
// Hash final blocks
|
||||
this._process();
|
||||
|
||||
// Return final computed hash
|
||||
return this._hash;
|
||||
},
|
||||
|
||||
clone: function () {
|
||||
var clone = Hasher.clone.call(this);
|
||||
clone._hash = this._hash.clone();
|
||||
|
||||
return clone;
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Shortcut function to the hasher's object interface.
|
||||
*
|
||||
* @param {WordArray|string} message The message to hash.
|
||||
*
|
||||
* @return {WordArray} The hash.
|
||||
*
|
||||
* @static
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* var hash = CryptoJS.SHA1('message');
|
||||
* var hash = CryptoJS.SHA1(wordArray);
|
||||
*/
|
||||
C.SHA1 = Hasher._createHelper(SHA1);
|
||||
|
||||
/**
|
||||
* Shortcut function to the HMAC's object interface.
|
||||
*
|
||||
* @param {WordArray|string} message The message to hash.
|
||||
* @param {WordArray|string} key The secret key.
|
||||
*
|
||||
* @return {WordArray} The HMAC.
|
||||
*
|
||||
* @static
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* var hmac = CryptoJS.HmacSHA1(message, key);
|
||||
*/
|
||||
C.HmacSHA1 = Hasher._createHmacHelper(SHA1);
|
||||
}());
|
@ -1,66 +0,0 @@
|
||||
/*
|
||||
CryptoJS v3.1.2
|
||||
code.google.com/p/crypto-js
|
||||
(c) 2009-2013 by Jeff Mott. All rights reserved.
|
||||
code.google.com/p/crypto-js/wiki/License
|
||||
*/
|
||||
(function () {
|
||||
// Shortcuts
|
||||
var C = CryptoJS;
|
||||
var C_lib = C.lib;
|
||||
var WordArray = C_lib.WordArray;
|
||||
var C_algo = C.algo;
|
||||
var SHA256 = C_algo.SHA256;
|
||||
|
||||
/**
|
||||
* SHA-224 hash algorithm.
|
||||
*/
|
||||
var SHA224 = C_algo.SHA224 = SHA256.extend({
|
||||
_doReset: function () {
|
||||
this._hash = new WordArray.init([
|
||||
0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939,
|
||||
0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4
|
||||
]);
|
||||
},
|
||||
|
||||
_doFinalize: function () {
|
||||
var hash = SHA256._doFinalize.call(this);
|
||||
|
||||
hash.sigBytes -= 4;
|
||||
|
||||
return hash;
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Shortcut function to the hasher's object interface.
|
||||
*
|
||||
* @param {WordArray|string} message The message to hash.
|
||||
*
|
||||
* @return {WordArray} The hash.
|
||||
*
|
||||
* @static
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* var hash = CryptoJS.SHA224('message');
|
||||
* var hash = CryptoJS.SHA224(wordArray);
|
||||
*/
|
||||
C.SHA224 = SHA256._createHelper(SHA224);
|
||||
|
||||
/**
|
||||
* Shortcut function to the HMAC's object interface.
|
||||
*
|
||||
* @param {WordArray|string} message The message to hash.
|
||||
* @param {WordArray|string} key The secret key.
|
||||
*
|
||||
* @return {WordArray} The HMAC.
|
||||
*
|
||||
* @static
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* var hmac = CryptoJS.HmacSHA224(message, key);
|
||||
*/
|
||||
C.HmacSHA224 = SHA256._createHmacHelper(SHA224);
|
||||
}());
|
@ -1,185 +0,0 @@
|
||||
/*
|
||||
CryptoJS v3.1.2
|
||||
code.google.com/p/crypto-js
|
||||
(c) 2009-2013 by Jeff Mott. All rights reserved.
|
||||
code.google.com/p/crypto-js/wiki/License
|
||||
*/
|
||||
(function (Math) {
|
||||
// Shortcuts
|
||||
var C = CryptoJS;
|
||||
var C_lib = C.lib;
|
||||
var WordArray = C_lib.WordArray;
|
||||
var Hasher = C_lib.Hasher;
|
||||
var C_algo = C.algo;
|
||||
|
||||
// Initialization and round constants tables
|
||||
var H = [];
|
||||
var K = [];
|
||||
|
||||
// Compute constants
|
||||
(function () {
|
||||
function isPrime(n) {
|
||||
var sqrtN = Math.sqrt(n);
|
||||
for (var factor = 2; factor <= sqrtN; factor++) {
|
||||
if (!(n % factor)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function getFractionalBits(n) {
|
||||
return ((n - (n | 0)) * 0x100000000) | 0;
|
||||
}
|
||||
|
||||
var n = 2;
|
||||
var nPrime = 0;
|
||||
while (nPrime < 64) {
|
||||
if (isPrime(n)) {
|
||||
if (nPrime < 8) {
|
||||
H[nPrime] = getFractionalBits(Math.pow(n, 1 / 2));
|
||||
}
|
||||
K[nPrime] = getFractionalBits(Math.pow(n, 1 / 3));
|
||||
|
||||
nPrime++;
|
||||
}
|
||||
|
||||
n++;
|
||||
}
|
||||
}());
|
||||
|
||||
// Reusable object
|
||||
var W = [];
|
||||
|
||||
/**
|
||||
* SHA-256 hash algorithm.
|
||||
*/
|
||||
var SHA256 = C_algo.SHA256 = Hasher.extend({
|
||||
_doReset: function () {
|
||||
this._hash = new WordArray.init(H.slice(0));
|
||||
},
|
||||
|
||||
_doProcessBlock: function (M, offset) {
|
||||
// Shortcut
|
||||
var H = this._hash.words;
|
||||
|
||||
// Working variables
|
||||
var a = H[0];
|
||||
var b = H[1];
|
||||
var c = H[2];
|
||||
var d = H[3];
|
||||
var e = H[4];
|
||||
var f = H[5];
|
||||
var g = H[6];
|
||||
var h = H[7];
|
||||
|
||||
// Computation
|
||||
for (var i = 0; i < 64; i++) {
|
||||
if (i < 16) {
|
||||
W[i] = M[offset + i] | 0;
|
||||
} else {
|
||||
var gamma0x = W[i - 15];
|
||||
var gamma0 = ((gamma0x << 25) | (gamma0x >>> 7)) ^
|
||||
((gamma0x << 14) | (gamma0x >>> 18)) ^
|
||||
(gamma0x >>> 3);
|
||||
|
||||
var gamma1x = W[i - 2];
|
||||
var gamma1 = ((gamma1x << 15) | (gamma1x >>> 17)) ^
|
||||
((gamma1x << 13) | (gamma1x >>> 19)) ^
|
||||
(gamma1x >>> 10);
|
||||
|
||||
W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16];
|
||||
}
|
||||
|
||||
var ch = (e & f) ^ (~e & g);
|
||||
var maj = (a & b) ^ (a & c) ^ (b & c);
|
||||
|
||||
var sigma0 = ((a << 30) | (a >>> 2)) ^ ((a << 19) | (a >>> 13)) ^ ((a << 10) | (a >>> 22));
|
||||
var sigma1 = ((e << 26) | (e >>> 6)) ^ ((e << 21) | (e >>> 11)) ^ ((e << 7) | (e >>> 25));
|
||||
|
||||
var t1 = h + sigma1 + ch + K[i] + W[i];
|
||||
var t2 = sigma0 + maj;
|
||||
|
||||
h = g;
|
||||
g = f;
|
||||
f = e;
|
||||
e = (d + t1) | 0;
|
||||
d = c;
|
||||
c = b;
|
||||
b = a;
|
||||
a = (t1 + t2) | 0;
|
||||
}
|
||||
|
||||
// Intermediate hash value
|
||||
H[0] = (H[0] + a) | 0;
|
||||
H[1] = (H[1] + b) | 0;
|
||||
H[2] = (H[2] + c) | 0;
|
||||
H[3] = (H[3] + d) | 0;
|
||||
H[4] = (H[4] + e) | 0;
|
||||
H[5] = (H[5] + f) | 0;
|
||||
H[6] = (H[6] + g) | 0;
|
||||
H[7] = (H[7] + h) | 0;
|
||||
},
|
||||
|
||||
_doFinalize: function () {
|
||||
// Shortcuts
|
||||
var data = this._data;
|
||||
var dataWords = data.words;
|
||||
|
||||
var nBitsTotal = this._nDataBytes * 8;
|
||||
var nBitsLeft = data.sigBytes * 8;
|
||||
|
||||
// Add padding
|
||||
dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32);
|
||||
dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = Math.floor(nBitsTotal / 0x100000000);
|
||||
dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = nBitsTotal;
|
||||
data.sigBytes = dataWords.length * 4;
|
||||
|
||||
// Hash final blocks
|
||||
this._process();
|
||||
|
||||
// Return final computed hash
|
||||
return this._hash;
|
||||
},
|
||||
|
||||
clone: function () {
|
||||
var clone = Hasher.clone.call(this);
|
||||
clone._hash = this._hash.clone();
|
||||
|
||||
return clone;
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Shortcut function to the hasher's object interface.
|
||||
*
|
||||
* @param {WordArray|string} message The message to hash.
|
||||
*
|
||||
* @return {WordArray} The hash.
|
||||
*
|
||||
* @static
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* var hash = CryptoJS.SHA256('message');
|
||||
* var hash = CryptoJS.SHA256(wordArray);
|
||||
*/
|
||||
C.SHA256 = Hasher._createHelper(SHA256);
|
||||
|
||||
/**
|
||||
* Shortcut function to the HMAC's object interface.
|
||||
*
|
||||
* @param {WordArray|string} message The message to hash.
|
||||
* @param {WordArray|string} key The secret key.
|
||||
*
|
||||
* @return {WordArray} The HMAC.
|
||||
*
|
||||
* @static
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* var hmac = CryptoJS.HmacSHA256(message, key);
|
||||
*/
|
||||
C.HmacSHA256 = Hasher._createHmacHelper(SHA256);
|
||||
}(Math));
|
@ -1,309 +0,0 @@
|
||||
/*
|
||||
CryptoJS v3.1.2
|
||||
code.google.com/p/crypto-js
|
||||
(c) 2009-2013 by Jeff Mott. All rights reserved.
|
||||
code.google.com/p/crypto-js/wiki/License
|
||||
*/
|
||||
(function (Math) {
|
||||
// Shortcuts
|
||||
var C = CryptoJS;
|
||||
var C_lib = C.lib;
|
||||
var WordArray = C_lib.WordArray;
|
||||
var Hasher = C_lib.Hasher;
|
||||
var C_x64 = C.x64;
|
||||
var X64Word = C_x64.Word;
|
||||
var C_algo = C.algo;
|
||||
|
||||
// Constants tables
|
||||
var RHO_OFFSETS = [];
|
||||
var PI_INDEXES = [];
|
||||
var ROUND_CONSTANTS = [];
|
||||
|
||||
// Compute Constants
|
||||
(function () {
|
||||
// Compute rho offset constants
|
||||
var x = 1, y = 0;
|
||||
for (var t = 0; t < 24; t++) {
|
||||
RHO_OFFSETS[x + 5 * y] = ((t + 1) * (t + 2) / 2) % 64;
|
||||
|
||||
var newX = y % 5;
|
||||
var newY = (2 * x + 3 * y) % 5;
|
||||
x = newX;
|
||||
y = newY;
|
||||
}
|
||||
|
||||
// Compute pi index constants
|
||||
for (var x = 0; x < 5; x++) {
|
||||
for (var y = 0; y < 5; y++) {
|
||||
PI_INDEXES[x + 5 * y] = y + ((2 * x + 3 * y) % 5) * 5;
|
||||
}
|
||||
}
|
||||
|
||||
// Compute round constants
|
||||
var LFSR = 0x01;
|
||||
for (var i = 0; i < 24; i++) {
|
||||
var roundConstantMsw = 0;
|
||||
var roundConstantLsw = 0;
|
||||
|
||||
for (var j = 0; j < 7; j++) {
|
||||
if (LFSR & 0x01) {
|
||||
var bitPosition = (1 << j) - 1;
|
||||
if (bitPosition < 32) {
|
||||
roundConstantLsw ^= 1 << bitPosition;
|
||||
} else /* if (bitPosition >= 32) */ {
|
||||
roundConstantMsw ^= 1 << (bitPosition - 32);
|
||||
}
|
||||
}
|
||||
|
||||
// Compute next LFSR
|
||||
if (LFSR & 0x80) {
|
||||
// Primitive polynomial over GF(2): x^8 + x^6 + x^5 + x^4 + 1
|
||||
LFSR = (LFSR << 1) ^ 0x71;
|
||||
} else {
|
||||
LFSR <<= 1;
|
||||
}
|
||||
}
|
||||
|
||||
ROUND_CONSTANTS[i] = X64Word.create(roundConstantMsw, roundConstantLsw);
|
||||
}
|
||||
}());
|
||||
|
||||
// Reusable objects for temporary values
|
||||
var T = [];
|
||||
(function () {
|
||||
for (var i = 0; i < 25; i++) {
|
||||
T[i] = X64Word.create();
|
||||
}
|
||||
}());
|
||||
|
||||
/**
|
||||
* SHA-3 hash algorithm.
|
||||
*/
|
||||
var SHA3 = C_algo.SHA3 = Hasher.extend({
|
||||
/**
|
||||
* Configuration options.
|
||||
*
|
||||
* @property {number} outputLength
|
||||
* The desired number of bits in the output hash.
|
||||
* Only values permitted are: 224, 256, 384, 512.
|
||||
* Default: 512
|
||||
*/
|
||||
cfg: Hasher.cfg.extend({
|
||||
outputLength: 512
|
||||
}),
|
||||
|
||||
_doReset: function () {
|
||||
var state = this._state = []
|
||||
for (var i = 0; i < 25; i++) {
|
||||
state[i] = new X64Word.init();
|
||||
}
|
||||
|
||||
this.blockSize = (1600 - 2 * this.cfg.outputLength) / 32;
|
||||
},
|
||||
|
||||
_doProcessBlock: function (M, offset) {
|
||||
// Shortcuts
|
||||
var state = this._state;
|
||||
var nBlockSizeLanes = this.blockSize / 2;
|
||||
|
||||
// Absorb
|
||||
for (var i = 0; i < nBlockSizeLanes; i++) {
|
||||
// Shortcuts
|
||||
var M2i = M[offset + 2 * i];
|
||||
var M2i1 = M[offset + 2 * i + 1];
|
||||
|
||||
// Swap endian
|
||||
M2i = (
|
||||
(((M2i << 8) | (M2i >>> 24)) & 0x00ff00ff) |
|
||||
(((M2i << 24) | (M2i >>> 8)) & 0xff00ff00)
|
||||
);
|
||||
M2i1 = (
|
||||
(((M2i1 << 8) | (M2i1 >>> 24)) & 0x00ff00ff) |
|
||||
(((M2i1 << 24) | (M2i1 >>> 8)) & 0xff00ff00)
|
||||
);
|
||||
|
||||
// Absorb message into state
|
||||
var lane = state[i];
|
||||
lane.high ^= M2i1;
|
||||
lane.low ^= M2i;
|
||||
}
|
||||
|
||||
// Rounds
|
||||
for (var round = 0; round < 24; round++) {
|
||||
// Theta
|
||||
for (var x = 0; x < 5; x++) {
|
||||
// Mix column lanes
|
||||
var tMsw = 0, tLsw = 0;
|
||||
for (var y = 0; y < 5; y++) {
|
||||
var lane = state[x + 5 * y];
|
||||
tMsw ^= lane.high;
|
||||
tLsw ^= lane.low;
|
||||
}
|
||||
|
||||
// Temporary values
|
||||
var Tx = T[x];
|
||||
Tx.high = tMsw;
|
||||
Tx.low = tLsw;
|
||||
}
|
||||
for (var x = 0; x < 5; x++) {
|
||||
// Shortcuts
|
||||
var Tx4 = T[(x + 4) % 5];
|
||||
var Tx1 = T[(x + 1) % 5];
|
||||
var Tx1Msw = Tx1.high;
|
||||
var Tx1Lsw = Tx1.low;
|
||||
|
||||
// Mix surrounding columns
|
||||
var tMsw = Tx4.high ^ ((Tx1Msw << 1) | (Tx1Lsw >>> 31));
|
||||
var tLsw = Tx4.low ^ ((Tx1Lsw << 1) | (Tx1Msw >>> 31));
|
||||
for (var y = 0; y < 5; y++) {
|
||||
var lane = state[x + 5 * y];
|
||||
lane.high ^= tMsw;
|
||||
lane.low ^= tLsw;
|
||||
}
|
||||
}
|
||||
|
||||
// Rho Pi
|
||||
for (var laneIndex = 1; laneIndex < 25; laneIndex++) {
|
||||
// Shortcuts
|
||||
var lane = state[laneIndex];
|
||||
var laneMsw = lane.high;
|
||||
var laneLsw = lane.low;
|
||||
var rhoOffset = RHO_OFFSETS[laneIndex];
|
||||
|
||||
// Rotate lanes
|
||||
if (rhoOffset < 32) {
|
||||
var tMsw = (laneMsw << rhoOffset) | (laneLsw >>> (32 - rhoOffset));
|
||||
var tLsw = (laneLsw << rhoOffset) | (laneMsw >>> (32 - rhoOffset));
|
||||
} else /* if (rhoOffset >= 32) */ {
|
||||
var tMsw = (laneLsw << (rhoOffset - 32)) | (laneMsw >>> (64 - rhoOffset));
|
||||
var tLsw = (laneMsw << (rhoOffset - 32)) | (laneLsw >>> (64 - rhoOffset));
|
||||
}
|
||||
|
||||
// Transpose lanes
|
||||
var TPiLane = T[PI_INDEXES[laneIndex]];
|
||||
TPiLane.high = tMsw;
|
||||
TPiLane.low = tLsw;
|
||||
}
|
||||
|
||||
// Rho pi at x = y = 0
|
||||
var T0 = T[0];
|
||||
var state0 = state[0];
|
||||
T0.high = state0.high;
|
||||
T0.low = state0.low;
|
||||
|
||||
// Chi
|
||||
for (var x = 0; x < 5; x++) {
|
||||
for (var y = 0; y < 5; y++) {
|
||||
// Shortcuts
|
||||
var laneIndex = x + 5 * y;
|
||||
var lane = state[laneIndex];
|
||||
var TLane = T[laneIndex];
|
||||
var Tx1Lane = T[((x + 1) % 5) + 5 * y];
|
||||
var Tx2Lane = T[((x + 2) % 5) + 5 * y];
|
||||
|
||||
// Mix rows
|
||||
lane.high = TLane.high ^ (~Tx1Lane.high & Tx2Lane.high);
|
||||
lane.low = TLane.low ^ (~Tx1Lane.low & Tx2Lane.low);
|
||||
}
|
||||
}
|
||||
|
||||
// Iota
|
||||
var lane = state[0];
|
||||
var roundConstant = ROUND_CONSTANTS[round];
|
||||
lane.high ^= roundConstant.high;
|
||||
lane.low ^= roundConstant.low;;
|
||||
}
|
||||
},
|
||||
|
||||
_doFinalize: function () {
|
||||
// Shortcuts
|
||||
var data = this._data;
|
||||
var dataWords = data.words;
|
||||
var nBitsTotal = this._nDataBytes * 8;
|
||||
var nBitsLeft = data.sigBytes * 8;
|
||||
var blockSizeBits = this.blockSize * 32;
|
||||
|
||||
// Add padding
|
||||
dataWords[nBitsLeft >>> 5] |= 0x1 << (24 - nBitsLeft % 32);
|
||||
dataWords[((Math.ceil((nBitsLeft + 1) / blockSizeBits) * blockSizeBits) >>> 5) - 1] |= 0x80;
|
||||
data.sigBytes = dataWords.length * 4;
|
||||
|
||||
// Hash final blocks
|
||||
this._process();
|
||||
|
||||
// Shortcuts
|
||||
var state = this._state;
|
||||
var outputLengthBytes = this.cfg.outputLength / 8;
|
||||
var outputLengthLanes = outputLengthBytes / 8;
|
||||
|
||||
// Squeeze
|
||||
var hashWords = [];
|
||||
for (var i = 0; i < outputLengthLanes; i++) {
|
||||
// Shortcuts
|
||||
var lane = state[i];
|
||||
var laneMsw = lane.high;
|
||||
var laneLsw = lane.low;
|
||||
|
||||
// Swap endian
|
||||
laneMsw = (
|
||||
(((laneMsw << 8) | (laneMsw >>> 24)) & 0x00ff00ff) |
|
||||
(((laneMsw << 24) | (laneMsw >>> 8)) & 0xff00ff00)
|
||||
);
|
||||
laneLsw = (
|
||||
(((laneLsw << 8) | (laneLsw >>> 24)) & 0x00ff00ff) |
|
||||
(((laneLsw << 24) | (laneLsw >>> 8)) & 0xff00ff00)
|
||||
);
|
||||
|
||||
// Squeeze state to retrieve hash
|
||||
hashWords.push(laneLsw);
|
||||
hashWords.push(laneMsw);
|
||||
}
|
||||
|
||||
// Return final computed hash
|
||||
return new WordArray.init(hashWords, outputLengthBytes);
|
||||
},
|
||||
|
||||
clone: function () {
|
||||
var clone = Hasher.clone.call(this);
|
||||
|
||||
var state = clone._state = this._state.slice(0);
|
||||
for (var i = 0; i < 25; i++) {
|
||||
state[i] = state[i].clone();
|
||||
}
|
||||
|
||||
return clone;
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Shortcut function to the hasher's object interface.
|
||||
*
|
||||
* @param {WordArray|string} message The message to hash.
|
||||
*
|
||||
* @return {WordArray} The hash.
|
||||
*
|
||||
* @static
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* var hash = CryptoJS.SHA3('message');
|
||||
* var hash = CryptoJS.SHA3(wordArray);
|
||||
*/
|
||||
C.SHA3 = Hasher._createHelper(SHA3);
|
||||
|
||||
/**
|
||||
* Shortcut function to the HMAC's object interface.
|
||||
*
|
||||
* @param {WordArray|string} message The message to hash.
|
||||
* @param {WordArray|string} key The secret key.
|
||||
*
|
||||
* @return {WordArray} The HMAC.
|
||||
*
|
||||
* @static
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* var hmac = CryptoJS.HmacSHA3(message, key);
|
||||
*/
|
||||
C.HmacSHA3 = Hasher._createHmacHelper(SHA3);
|
||||
}(Math));
|
@ -1,69 +0,0 @@
|
||||
/*
|
||||
CryptoJS v3.1.2
|
||||
code.google.com/p/crypto-js
|
||||
(c) 2009-2013 by Jeff Mott. All rights reserved.
|
||||
code.google.com/p/crypto-js/wiki/License
|
||||
*/
|
||||
(function () {
|
||||
// Shortcuts
|
||||
var C = CryptoJS;
|
||||
var C_x64 = C.x64;
|
||||
var X64Word = C_x64.Word;
|
||||
var X64WordArray = C_x64.WordArray;
|
||||
var C_algo = C.algo;
|
||||
var SHA512 = C_algo.SHA512;
|
||||
|
||||
/**
|
||||
* SHA-384 hash algorithm.
|
||||
*/
|
||||
var SHA384 = C_algo.SHA384 = SHA512.extend({
|
||||
_doReset: function () {
|
||||
this._hash = new X64WordArray.init([
|
||||
new X64Word.init(0xcbbb9d5d, 0xc1059ed8), new X64Word.init(0x629a292a, 0x367cd507),
|
||||
new X64Word.init(0x9159015a, 0x3070dd17), new X64Word.init(0x152fecd8, 0xf70e5939),
|
||||
new X64Word.init(0x67332667, 0xffc00b31), new X64Word.init(0x8eb44a87, 0x68581511),
|
||||
new X64Word.init(0xdb0c2e0d, 0x64f98fa7), new X64Word.init(0x47b5481d, 0xbefa4fa4)
|
||||
]);
|
||||
},
|
||||
|
||||
_doFinalize: function () {
|
||||
var hash = SHA512._doFinalize.call(this);
|
||||
|
||||
hash.sigBytes -= 16;
|
||||
|
||||
return hash;
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Shortcut function to the hasher's object interface.
|
||||
*
|
||||
* @param {WordArray|string} message The message to hash.
|
||||
*
|
||||
* @return {WordArray} The hash.
|
||||
*
|
||||
* @static
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* var hash = CryptoJS.SHA384('message');
|
||||
* var hash = CryptoJS.SHA384(wordArray);
|
||||
*/
|
||||
C.SHA384 = SHA512._createHelper(SHA384);
|
||||
|
||||
/**
|
||||
* Shortcut function to the HMAC's object interface.
|
||||
*
|
||||
* @param {WordArray|string} message The message to hash.
|
||||
* @param {WordArray|string} key The secret key.
|
||||
*
|
||||
* @return {WordArray} The HMAC.
|
||||
*
|
||||
* @static
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* var hmac = CryptoJS.HmacSHA384(message, key);
|
||||
*/
|
||||
C.HmacSHA384 = SHA512._createHmacHelper(SHA384);
|
||||
}());
|
@ -1,309 +0,0 @@
|
||||
/*
|
||||
CryptoJS v3.1.2
|
||||
code.google.com/p/crypto-js
|
||||
(c) 2009-2013 by Jeff Mott. All rights reserved.
|
||||
code.google.com/p/crypto-js/wiki/License
|
||||
*/
|
||||
(function () {
|
||||
// Shortcuts
|
||||
var C = CryptoJS;
|
||||
var C_lib = C.lib;
|
||||
var Hasher = C_lib.Hasher;
|
||||
var C_x64 = C.x64;
|
||||
var X64Word = C_x64.Word;
|
||||
var X64WordArray = C_x64.WordArray;
|
||||
var C_algo = C.algo;
|
||||
|
||||
function X64Word_create() {
|
||||
return X64Word.create.apply(X64Word, arguments);
|
||||
}
|
||||
|
||||
// Constants
|
||||
var K = [
|
||||
X64Word_create(0x428a2f98, 0xd728ae22), X64Word_create(0x71374491, 0x23ef65cd),
|
||||
X64Word_create(0xb5c0fbcf, 0xec4d3b2f), X64Word_create(0xe9b5dba5, 0x8189dbbc),
|
||||
X64Word_create(0x3956c25b, 0xf348b538), X64Word_create(0x59f111f1, 0xb605d019),
|
||||
X64Word_create(0x923f82a4, 0xaf194f9b), X64Word_create(0xab1c5ed5, 0xda6d8118),
|
||||
X64Word_create(0xd807aa98, 0xa3030242), X64Word_create(0x12835b01, 0x45706fbe),
|
||||
X64Word_create(0x243185be, 0x4ee4b28c), X64Word_create(0x550c7dc3, 0xd5ffb4e2),
|
||||
X64Word_create(0x72be5d74, 0xf27b896f), X64Word_create(0x80deb1fe, 0x3b1696b1),
|
||||
X64Word_create(0x9bdc06a7, 0x25c71235), X64Word_create(0xc19bf174, 0xcf692694),
|
||||
X64Word_create(0xe49b69c1, 0x9ef14ad2), X64Word_create(0xefbe4786, 0x384f25e3),
|
||||
X64Word_create(0x0fc19dc6, 0x8b8cd5b5), X64Word_create(0x240ca1cc, 0x77ac9c65),
|
||||
X64Word_create(0x2de92c6f, 0x592b0275), X64Word_create(0x4a7484aa, 0x6ea6e483),
|
||||
X64Word_create(0x5cb0a9dc, 0xbd41fbd4), X64Word_create(0x76f988da, 0x831153b5),
|
||||
X64Word_create(0x983e5152, 0xee66dfab), X64Word_create(0xa831c66d, 0x2db43210),
|
||||
X64Word_create(0xb00327c8, 0x98fb213f), X64Word_create(0xbf597fc7, 0xbeef0ee4),
|
||||
X64Word_create(0xc6e00bf3, 0x3da88fc2), X64Word_create(0xd5a79147, 0x930aa725),
|
||||
X64Word_create(0x06ca6351, 0xe003826f), X64Word_create(0x14292967, 0x0a0e6e70),
|
||||
X64Word_create(0x27b70a85, 0x46d22ffc), X64Word_create(0x2e1b2138, 0x5c26c926),
|
||||
X64Word_create(0x4d2c6dfc, 0x5ac42aed), X64Word_create(0x53380d13, 0x9d95b3df),
|
||||
X64Word_create(0x650a7354, 0x8baf63de), X64Word_create(0x766a0abb, 0x3c77b2a8),
|
||||
X64Word_create(0x81c2c92e, 0x47edaee6), X64Word_create(0x92722c85, 0x1482353b),
|
||||
X64Word_create(0xa2bfe8a1, 0x4cf10364), X64Word_create(0xa81a664b, 0xbc423001),
|
||||
X64Word_create(0xc24b8b70, 0xd0f89791), X64Word_create(0xc76c51a3, 0x0654be30),
|
||||
X64Word_create(0xd192e819, 0xd6ef5218), X64Word_create(0xd6990624, 0x5565a910),
|
||||
X64Word_create(0xf40e3585, 0x5771202a), X64Word_create(0x106aa070, 0x32bbd1b8),
|
||||
X64Word_create(0x19a4c116, 0xb8d2d0c8), X64Word_create(0x1e376c08, 0x5141ab53),
|
||||
X64Word_create(0x2748774c, 0xdf8eeb99), X64Word_create(0x34b0bcb5, 0xe19b48a8),
|
||||
X64Word_create(0x391c0cb3, 0xc5c95a63), X64Word_create(0x4ed8aa4a, 0xe3418acb),
|
||||
X64Word_create(0x5b9cca4f, 0x7763e373), X64Word_create(0x682e6ff3, 0xd6b2b8a3),
|
||||
X64Word_create(0x748f82ee, 0x5defb2fc), X64Word_create(0x78a5636f, 0x43172f60),
|
||||
X64Word_create(0x84c87814, 0xa1f0ab72), X64Word_create(0x8cc70208, 0x1a6439ec),
|
||||
X64Word_create(0x90befffa, 0x23631e28), X64Word_create(0xa4506ceb, 0xde82bde9),
|
||||
X64Word_create(0xbef9a3f7, 0xb2c67915), X64Word_create(0xc67178f2, 0xe372532b),
|
||||
X64Word_create(0xca273ece, 0xea26619c), X64Word_create(0xd186b8c7, 0x21c0c207),
|
||||
X64Word_create(0xeada7dd6, 0xcde0eb1e), X64Word_create(0xf57d4f7f, 0xee6ed178),
|
||||
X64Word_create(0x06f067aa, 0x72176fba), X64Word_create(0x0a637dc5, 0xa2c898a6),
|
||||
X64Word_create(0x113f9804, 0xbef90dae), X64Word_create(0x1b710b35, 0x131c471b),
|
||||
X64Word_create(0x28db77f5, 0x23047d84), X64Word_create(0x32caab7b, 0x40c72493),
|
||||
X64Word_create(0x3c9ebe0a, 0x15c9bebc), X64Word_create(0x431d67c4, 0x9c100d4c),
|
||||
X64Word_create(0x4cc5d4be, 0xcb3e42b6), X64Word_create(0x597f299c, 0xfc657e2a),
|
||||
X64Word_create(0x5fcb6fab, 0x3ad6faec), X64Word_create(0x6c44198c, 0x4a475817)
|
||||
];
|
||||
|
||||
// Reusable objects
|
||||
var W = [];
|
||||
(function () {
|
||||
for (var i = 0; i < 80; i++) {
|
||||
W[i] = X64Word_create();
|
||||
}
|
||||
}());
|
||||
|
||||
/**
|
||||
* SHA-512 hash algorithm.
|
||||
*/
|
||||
var SHA512 = C_algo.SHA512 = Hasher.extend({
|
||||
_doReset: function () {
|
||||
this._hash = new X64WordArray.init([
|
||||
new X64Word.init(0x6a09e667, 0xf3bcc908), new X64Word.init(0xbb67ae85, 0x84caa73b),
|
||||
new X64Word.init(0x3c6ef372, 0xfe94f82b), new X64Word.init(0xa54ff53a, 0x5f1d36f1),
|
||||
new X64Word.init(0x510e527f, 0xade682d1), new X64Word.init(0x9b05688c, 0x2b3e6c1f),
|
||||
new X64Word.init(0x1f83d9ab, 0xfb41bd6b), new X64Word.init(0x5be0cd19, 0x137e2179)
|
||||
]);
|
||||
},
|
||||
|
||||
_doProcessBlock: function (M, offset) {
|
||||
// Shortcuts
|
||||
var H = this._hash.words;
|
||||
|
||||
var H0 = H[0];
|
||||
var H1 = H[1];
|
||||
var H2 = H[2];
|
||||
var H3 = H[3];
|
||||
var H4 = H[4];
|
||||
var H5 = H[5];
|
||||
var H6 = H[6];
|
||||
var H7 = H[7];
|
||||
|
||||
var H0h = H0.high;
|
||||
var H0l = H0.low;
|
||||
var H1h = H1.high;
|
||||
var H1l = H1.low;
|
||||
var H2h = H2.high;
|
||||
var H2l = H2.low;
|
||||
var H3h = H3.high;
|
||||
var H3l = H3.low;
|
||||
var H4h = H4.high;
|
||||
var H4l = H4.low;
|
||||
var H5h = H5.high;
|
||||
var H5l = H5.low;
|
||||
var H6h = H6.high;
|
||||
var H6l = H6.low;
|
||||
var H7h = H7.high;
|
||||
var H7l = H7.low;
|
||||
|
||||
// Working variables
|
||||
var ah = H0h;
|
||||
var al = H0l;
|
||||
var bh = H1h;
|
||||
var bl = H1l;
|
||||
var ch = H2h;
|
||||
var cl = H2l;
|
||||
var dh = H3h;
|
||||
var dl = H3l;
|
||||
var eh = H4h;
|
||||
var el = H4l;
|
||||
var fh = H5h;
|
||||
var fl = H5l;
|
||||
var gh = H6h;
|
||||
var gl = H6l;
|
||||
var hh = H7h;
|
||||
var hl = H7l;
|
||||
|
||||
// Rounds
|
||||
for (var i = 0; i < 80; i++) {
|
||||
// Shortcut
|
||||
var Wi = W[i];
|
||||
|
||||
// Extend message
|
||||
if (i < 16) {
|
||||
var Wih = Wi.high = M[offset + i * 2] | 0;
|
||||
var Wil = Wi.low = M[offset + i * 2 + 1] | 0;
|
||||
} else {
|
||||
// Gamma0
|
||||
var gamma0x = W[i - 15];
|
||||
var gamma0xh = gamma0x.high;
|
||||
var gamma0xl = gamma0x.low;
|
||||
var gamma0h = ((gamma0xh >>> 1) | (gamma0xl << 31)) ^ ((gamma0xh >>> 8) | (gamma0xl << 24)) ^ (gamma0xh >>> 7);
|
||||
var gamma0l = ((gamma0xl >>> 1) | (gamma0xh << 31)) ^ ((gamma0xl >>> 8) | (gamma0xh << 24)) ^ ((gamma0xl >>> 7) | (gamma0xh << 25));
|
||||
|
||||
// Gamma1
|
||||
var gamma1x = W[i - 2];
|
||||
var gamma1xh = gamma1x.high;
|
||||
var gamma1xl = gamma1x.low;
|
||||
var gamma1h = ((gamma1xh >>> 19) | (gamma1xl << 13)) ^ ((gamma1xh << 3) | (gamma1xl >>> 29)) ^ (gamma1xh >>> 6);
|
||||
var gamma1l = ((gamma1xl >>> 19) | (gamma1xh << 13)) ^ ((gamma1xl << 3) | (gamma1xh >>> 29)) ^ ((gamma1xl >>> 6) | (gamma1xh << 26));
|
||||
|
||||
// W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16]
|
||||
var Wi7 = W[i - 7];
|
||||
var Wi7h = Wi7.high;
|
||||
var Wi7l = Wi7.low;
|
||||
|
||||
var Wi16 = W[i - 16];
|
||||
var Wi16h = Wi16.high;
|
||||
var Wi16l = Wi16.low;
|
||||
|
||||
var Wil = gamma0l + Wi7l;
|
||||
var Wih = gamma0h + Wi7h + ((Wil >>> 0) < (gamma0l >>> 0) ? 1 : 0);
|
||||
var Wil = Wil + gamma1l;
|
||||
var Wih = Wih + gamma1h + ((Wil >>> 0) < (gamma1l >>> 0) ? 1 : 0);
|
||||
var Wil = Wil + Wi16l;
|
||||
var Wih = Wih + Wi16h + ((Wil >>> 0) < (Wi16l >>> 0) ? 1 : 0);
|
||||
|
||||
Wi.high = Wih;
|
||||
Wi.low = Wil;
|
||||
}
|
||||
|
||||
var chh = (eh & fh) ^ (~eh & gh);
|
||||
var chl = (el & fl) ^ (~el & gl);
|
||||
var majh = (ah & bh) ^ (ah & ch) ^ (bh & ch);
|
||||
var majl = (al & bl) ^ (al & cl) ^ (bl & cl);
|
||||
|
||||
var sigma0h = ((ah >>> 28) | (al << 4)) ^ ((ah << 30) | (al >>> 2)) ^ ((ah << 25) | (al >>> 7));
|
||||
var sigma0l = ((al >>> 28) | (ah << 4)) ^ ((al << 30) | (ah >>> 2)) ^ ((al << 25) | (ah >>> 7));
|
||||
var sigma1h = ((eh >>> 14) | (el << 18)) ^ ((eh >>> 18) | (el << 14)) ^ ((eh << 23) | (el >>> 9));
|
||||
var sigma1l = ((el >>> 14) | (eh << 18)) ^ ((el >>> 18) | (eh << 14)) ^ ((el << 23) | (eh >>> 9));
|
||||
|
||||
// t1 = h + sigma1 + ch + K[i] + W[i]
|
||||
var Ki = K[i];
|
||||
var Kih = Ki.high;
|
||||
var Kil = Ki.low;
|
||||
|
||||
var t1l = hl + sigma1l;
|
||||
var t1h = hh + sigma1h + ((t1l >>> 0) < (hl >>> 0) ? 1 : 0);
|
||||
var t1l = t1l + chl;
|
||||
var t1h = t1h + chh + ((t1l >>> 0) < (chl >>> 0) ? 1 : 0);
|
||||
var t1l = t1l + Kil;
|
||||
var t1h = t1h + Kih + ((t1l >>> 0) < (Kil >>> 0) ? 1 : 0);
|
||||
var t1l = t1l + Wil;
|
||||
var t1h = t1h + Wih + ((t1l >>> 0) < (Wil >>> 0) ? 1 : 0);
|
||||
|
||||
// t2 = sigma0 + maj
|
||||
var t2l = sigma0l + majl;
|
||||
var t2h = sigma0h + majh + ((t2l >>> 0) < (sigma0l >>> 0) ? 1 : 0);
|
||||
|
||||
// Update working variables
|
||||
hh = gh;
|
||||
hl = gl;
|
||||
gh = fh;
|
||||
gl = fl;
|
||||
fh = eh;
|
||||
fl = el;
|
||||
el = (dl + t1l) | 0;
|
||||
eh = (dh + t1h + ((el >>> 0) < (dl >>> 0) ? 1 : 0)) | 0;
|
||||
dh = ch;
|
||||
dl = cl;
|
||||
ch = bh;
|
||||
cl = bl;
|
||||
bh = ah;
|
||||
bl = al;
|
||||
al = (t1l + t2l) | 0;
|
||||
ah = (t1h + t2h + ((al >>> 0) < (t1l >>> 0) ? 1 : 0)) | 0;
|
||||
}
|
||||
|
||||
// Intermediate hash value
|
||||
H0l = H0.low = (H0l + al);
|
||||
H0.high = (H0h + ah + ((H0l >>> 0) < (al >>> 0) ? 1 : 0));
|
||||
H1l = H1.low = (H1l + bl);
|
||||
H1.high = (H1h + bh + ((H1l >>> 0) < (bl >>> 0) ? 1 : 0));
|
||||
H2l = H2.low = (H2l + cl);
|
||||
H2.high = (H2h + ch + ((H2l >>> 0) < (cl >>> 0) ? 1 : 0));
|
||||
H3l = H3.low = (H3l + dl);
|
||||
H3.high = (H3h + dh + ((H3l >>> 0) < (dl >>> 0) ? 1 : 0));
|
||||
H4l = H4.low = (H4l + el);
|
||||
H4.high = (H4h + eh + ((H4l >>> 0) < (el >>> 0) ? 1 : 0));
|
||||
H5l = H5.low = (H5l + fl);
|
||||
H5.high = (H5h + fh + ((H5l >>> 0) < (fl >>> 0) ? 1 : 0));
|
||||
H6l = H6.low = (H6l + gl);
|
||||
H6.high = (H6h + gh + ((H6l >>> 0) < (gl >>> 0) ? 1 : 0));
|
||||
H7l = H7.low = (H7l + hl);
|
||||
H7.high = (H7h + hh + ((H7l >>> 0) < (hl >>> 0) ? 1 : 0));
|
||||
},
|
||||
|
||||
_doFinalize: function () {
|
||||
// Shortcuts
|
||||
var data = this._data;
|
||||
var dataWords = data.words;
|
||||
|
||||
var nBitsTotal = this._nDataBytes * 8;
|
||||
var nBitsLeft = data.sigBytes * 8;
|
||||
|
||||
// Add padding
|
||||
dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32);
|
||||
dataWords[(((nBitsLeft + 128) >>> 10) << 5) + 30] = Math.floor(nBitsTotal / 0x100000000);
|
||||
dataWords[(((nBitsLeft + 128) >>> 10) << 5) + 31] = nBitsTotal;
|
||||
data.sigBytes = dataWords.length * 4;
|
||||
|
||||
// Hash final blocks
|
||||
this._process();
|
||||
|
||||
// Convert hash to 32-bit word array before returning
|
||||
var hash = this._hash.toX32();
|
||||
|
||||
// Return final computed hash
|
||||
return hash;
|
||||
},
|
||||
|
||||
clone: function () {
|
||||
var clone = Hasher.clone.call(this);
|
||||
clone._hash = this._hash.clone();
|
||||
|
||||
return clone;
|
||||
},
|
||||
|
||||
blockSize: 1024/32
|
||||
});
|
||||
|
||||
/**
|
||||
* Shortcut function to the hasher's object interface.
|
||||
*
|
||||
* @param {WordArray|string} message The message to hash.
|
||||
*
|
||||
* @return {WordArray} The hash.
|
||||
*
|
||||
* @static
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* var hash = CryptoJS.SHA512('message');
|
||||
* var hash = CryptoJS.SHA512(wordArray);
|
||||
*/
|
||||
C.SHA512 = Hasher._createHelper(SHA512);
|
||||
|
||||
/**
|
||||
* Shortcut function to the HMAC's object interface.
|
||||
*
|
||||
* @param {WordArray|string} message The message to hash.
|
||||
* @param {WordArray|string} key The secret key.
|
||||
*
|
||||
* @return {WordArray} The HMAC.
|
||||
*
|
||||
* @static
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* var hmac = CryptoJS.HmacSHA512(message, key);
|
||||
*/
|
||||
C.HmacSHA512 = Hasher._createHmacHelper(SHA512);
|
||||
}());
|
@ -1,756 +0,0 @@
|
||||
/*
|
||||
CryptoJS v3.1.2
|
||||
code.google.com/p/crypto-js
|
||||
(c) 2009-2013 by Jeff Mott. All rights reserved.
|
||||
code.google.com/p/crypto-js/wiki/License
|
||||
*/
|
||||
(function () {
|
||||
// Shortcuts
|
||||
var C = CryptoJS;
|
||||
var C_lib = C.lib;
|
||||
var WordArray = C_lib.WordArray;
|
||||
var BlockCipher = C_lib.BlockCipher;
|
||||
var C_algo = C.algo;
|
||||
|
||||
// Permuted Choice 1 constants
|
||||
var PC1 = [
|
||||
57, 49, 41, 33, 25, 17, 9, 1,
|
||||
58, 50, 42, 34, 26, 18, 10, 2,
|
||||
59, 51, 43, 35, 27, 19, 11, 3,
|
||||
60, 52, 44, 36, 63, 55, 47, 39,
|
||||
31, 23, 15, 7, 62, 54, 46, 38,
|
||||
30, 22, 14, 6, 61, 53, 45, 37,
|
||||
29, 21, 13, 5, 28, 20, 12, 4
|
||||
];
|
||||
|
||||
// Permuted Choice 2 constants
|
||||
var PC2 = [
|
||||
14, 17, 11, 24, 1, 5,
|
||||
3, 28, 15, 6, 21, 10,
|
||||
23, 19, 12, 4, 26, 8,
|
||||
16, 7, 27, 20, 13, 2,
|
||||
41, 52, 31, 37, 47, 55,
|
||||
30, 40, 51, 45, 33, 48,
|
||||
44, 49, 39, 56, 34, 53,
|
||||
46, 42, 50, 36, 29, 32
|
||||
];
|
||||
|
||||
// Cumulative bit shift constants
|
||||
var BIT_SHIFTS = [1, 2, 4, 6, 8, 10, 12, 14, 15, 17, 19, 21, 23, 25, 27, 28];
|
||||
|
||||
// SBOXes and round permutation constants
|
||||
var SBOX_P = [
|
||||
{
|
||||
0x0: 0x808200,
|
||||
0x10000000: 0x8000,
|
||||
0x20000000: 0x808002,
|
||||
0x30000000: 0x2,
|
||||
0x40000000: 0x200,
|
||||
0x50000000: 0x808202,
|
||||
0x60000000: 0x800202,
|
||||
0x70000000: 0x800000,
|
||||
0x80000000: 0x202,
|
||||
0x90000000: 0x800200,
|
||||
0xa0000000: 0x8200,
|
||||
0xb0000000: 0x808000,
|
||||
0xc0000000: 0x8002,
|
||||
0xd0000000: 0x800002,
|
||||
0xe0000000: 0x0,
|
||||
0xf0000000: 0x8202,
|
||||
0x8000000: 0x0,
|
||||
0x18000000: 0x808202,
|
||||
0x28000000: 0x8202,
|
||||
0x38000000: 0x8000,
|
||||
0x48000000: 0x808200,
|
||||
0x58000000: 0x200,
|
||||
0x68000000: 0x808002,
|
||||
0x78000000: 0x2,
|
||||
0x88000000: 0x800200,
|
||||
0x98000000: 0x8200,
|
||||
0xa8000000: 0x808000,
|
||||
0xb8000000: 0x800202,
|
||||
0xc8000000: 0x800002,
|
||||
0xd8000000: 0x8002,
|
||||
0xe8000000: 0x202,
|
||||
0xf8000000: 0x800000,
|
||||
0x1: 0x8000,
|
||||
0x10000001: 0x2,
|
||||
0x20000001: 0x808200,
|
||||
0x30000001: 0x800000,
|
||||
0x40000001: 0x808002,
|
||||
0x50000001: 0x8200,
|
||||
0x60000001: 0x200,
|
||||
0x70000001: 0x800202,
|
||||
0x80000001: 0x808202,
|
||||
0x90000001: 0x808000,
|
||||
0xa0000001: 0x800002,
|
||||
0xb0000001: 0x8202,
|
||||
0xc0000001: 0x202,
|
||||
0xd0000001: 0x800200,
|
||||
0xe0000001: 0x8002,
|
||||
0xf0000001: 0x0,
|
||||
0x8000001: 0x808202,
|
||||
0x18000001: 0x808000,
|
||||
0x28000001: 0x800000,
|
||||
0x38000001: 0x200,
|
||||
0x48000001: 0x8000,
|
||||
0x58000001: 0x800002,
|
||||
0x68000001: 0x2,
|
||||
0x78000001: 0x8202,
|
||||
0x88000001: 0x8002,
|
||||
0x98000001: 0x800202,
|
||||
0xa8000001: 0x202,
|
||||
0xb8000001: 0x808200,
|
||||
0xc8000001: 0x800200,
|
||||
0xd8000001: 0x0,
|
||||
0xe8000001: 0x8200,
|
||||
0xf8000001: 0x808002
|
||||
},
|
||||
{
|
||||
0x0: 0x40084010,
|
||||
0x1000000: 0x4000,
|
||||
0x2000000: 0x80000,
|
||||
0x3000000: 0x40080010,
|
||||
0x4000000: 0x40000010,
|
||||
0x5000000: 0x40084000,
|
||||
0x6000000: 0x40004000,
|
||||
0x7000000: 0x10,
|
||||
0x8000000: 0x84000,
|
||||
0x9000000: 0x40004010,
|
||||
0xa000000: 0x40000000,
|
||||
0xb000000: 0x84010,
|
||||
0xc000000: 0x80010,
|
||||
0xd000000: 0x0,
|
||||
0xe000000: 0x4010,
|
||||
0xf000000: 0x40080000,
|
||||
0x800000: 0x40004000,
|
||||
0x1800000: 0x84010,
|
||||
0x2800000: 0x10,
|
||||
0x3800000: 0x40004010,
|
||||
0x4800000: 0x40084010,
|
||||
0x5800000: 0x40000000,
|
||||
0x6800000: 0x80000,
|
||||
0x7800000: 0x40080010,
|
||||
0x8800000: 0x80010,
|
||||
0x9800000: 0x0,
|
||||
0xa800000: 0x4000,
|
||||
0xb800000: 0x40080000,
|
||||
0xc800000: 0x40000010,
|
||||
0xd800000: 0x84000,
|
||||
0xe800000: 0x40084000,
|
||||
0xf800000: 0x4010,
|
||||
0x10000000: 0x0,
|
||||
0x11000000: 0x40080010,
|
||||
0x12000000: 0x40004010,
|
||||
0x13000000: 0x40084000,
|
||||
0x14000000: 0x40080000,
|
||||
0x15000000: 0x10,
|
||||
0x16000000: 0x84010,
|
||||
0x17000000: 0x4000,
|
||||
0x18000000: 0x4010,
|
||||
0x19000000: 0x80000,
|
||||
0x1a000000: 0x80010,
|
||||
0x1b000000: 0x40000010,
|
||||
0x1c000000: 0x84000,
|
||||
0x1d000000: 0x40004000,
|
||||
0x1e000000: 0x40000000,
|
||||
0x1f000000: 0x40084010,
|
||||
0x10800000: 0x84010,
|
||||
0x11800000: 0x80000,
|
||||
0x12800000: 0x40080000,
|
||||
0x13800000: 0x4000,
|
||||
0x14800000: 0x40004000,
|
||||
0x15800000: 0x40084010,
|
||||
0x16800000: 0x10,
|
||||
0x17800000: 0x40000000,
|
||||
0x18800000: 0x40084000,
|
||||
0x19800000: 0x40000010,
|
||||
0x1a800000: 0x40004010,
|
||||
0x1b800000: 0x80010,
|
||||
0x1c800000: 0x0,
|
||||
0x1d800000: 0x4010,
|
||||
0x1e800000: 0x40080010,
|
||||
0x1f800000: 0x84000
|
||||
},
|
||||
{
|
||||
0x0: 0x104,
|
||||
0x100000: 0x0,
|
||||
0x200000: 0x4000100,
|
||||
0x300000: 0x10104,
|
||||
0x400000: 0x10004,
|
||||
0x500000: 0x4000004,
|
||||
0x600000: 0x4010104,
|
||||
0x700000: 0x4010000,
|
||||
0x800000: 0x4000000,
|
||||
0x900000: 0x4010100,
|
||||
0xa00000: 0x10100,
|
||||
0xb00000: 0x4010004,
|
||||
0xc00000: 0x4000104,
|
||||
0xd00000: 0x10000,
|
||||
0xe00000: 0x4,
|
||||
0xf00000: 0x100,
|
||||
0x80000: 0x4010100,
|
||||
0x180000: 0x4010004,
|
||||
0x280000: 0x0,
|
||||
0x380000: 0x4000100,
|
||||
0x480000: 0x4000004,
|
||||
0x580000: 0x10000,
|
||||
0x680000: 0x10004,
|
||||
0x780000: 0x104,
|
||||
0x880000: 0x4,
|
||||
0x980000: 0x100,
|
||||
0xa80000: 0x4010000,
|
||||
0xb80000: 0x10104,
|
||||
0xc80000: 0x10100,
|
||||
0xd80000: 0x4000104,
|
||||
0xe80000: 0x4010104,
|
||||
0xf80000: 0x4000000,
|
||||
0x1000000: 0x4010100,
|
||||
0x1100000: 0x10004,
|
||||
0x1200000: 0x10000,
|
||||
0x1300000: 0x4000100,
|
||||
0x1400000: 0x100,
|
||||
0x1500000: 0x4010104,
|
||||
0x1600000: 0x4000004,
|
||||
0x1700000: 0x0,
|
||||
0x1800000: 0x4000104,
|
||||
0x1900000: 0x4000000,
|
||||
0x1a00000: 0x4,
|
||||
0x1b00000: 0x10100,
|
||||
0x1c00000: 0x4010000,
|
||||
0x1d00000: 0x104,
|
||||
0x1e00000: 0x10104,
|
||||
0x1f00000: 0x4010004,
|
||||
0x1080000: 0x4000000,
|
||||
0x1180000: 0x104,
|
||||
0x1280000: 0x4010100,
|
||||
0x1380000: 0x0,
|
||||
0x1480000: 0x10004,
|
||||
0x1580000: 0x4000100,
|
||||
0x1680000: 0x100,
|
||||
0x1780000: 0x4010004,
|
||||
0x1880000: 0x10000,
|
||||
0x1980000: 0x4010104,
|
||||
0x1a80000: 0x10104,
|
||||
0x1b80000: 0x4000004,
|
||||
0x1c80000: 0x4000104,
|
||||
0x1d80000: 0x4010000,
|
||||
0x1e80000: 0x4,
|
||||
0x1f80000: 0x10100
|
||||
},
|
||||
{
|
||||
0x0: 0x80401000,
|
||||
0x10000: 0x80001040,
|
||||
0x20000: 0x401040,
|
||||
0x30000: 0x80400000,
|
||||
0x40000: 0x0,
|
||||
0x50000: 0x401000,
|
||||
0x60000: 0x80000040,
|
||||
0x70000: 0x400040,
|
||||
0x80000: 0x80000000,
|
||||
0x90000: 0x400000,
|
||||
0xa0000: 0x40,
|
||||
0xb0000: 0x80001000,
|
||||
0xc0000: 0x80400040,
|
||||
0xd0000: 0x1040,
|
||||
0xe0000: 0x1000,
|
||||
0xf0000: 0x80401040,
|
||||
0x8000: 0x80001040,
|
||||
0x18000: 0x40,
|
||||
0x28000: 0x80400040,
|
||||
0x38000: 0x80001000,
|
||||
0x48000: 0x401000,
|
||||
0x58000: 0x80401040,
|
||||
0x68000: 0x0,
|
||||
0x78000: 0x80400000,
|
||||
0x88000: 0x1000,
|
||||
0x98000: 0x80401000,
|
||||
0xa8000: 0x400000,
|
||||
0xb8000: 0x1040,
|
||||
0xc8000: 0x80000000,
|
||||
0xd8000: 0x400040,
|
||||
0xe8000: 0x401040,
|
||||
0xf8000: 0x80000040,
|
||||
0x100000: 0x400040,
|
||||
0x110000: 0x401000,
|
||||
0x120000: 0x80000040,
|
||||
0x130000: 0x0,
|
||||
0x140000: 0x1040,
|
||||
0x150000: 0x80400040,
|
||||
0x160000: 0x80401000,
|
||||
0x170000: 0x80001040,
|
||||
0x180000: 0x80401040,
|
||||
0x190000: 0x80000000,
|
||||
0x1a0000: 0x80400000,
|
||||
0x1b0000: 0x401040,
|
||||
0x1c0000: 0x80001000,
|
||||
0x1d0000: 0x400000,
|
||||
0x1e0000: 0x40,
|
||||
0x1f0000: 0x1000,
|
||||
0x108000: 0x80400000,
|
||||
0x118000: 0x80401040,
|
||||
0x128000: 0x0,
|
||||
0x138000: 0x401000,
|
||||
0x148000: 0x400040,
|
||||
0x158000: 0x80000000,
|
||||
0x168000: 0x80001040,
|
||||
0x178000: 0x40,
|
||||
0x188000: 0x80000040,
|
||||
0x198000: 0x1000,
|
||||
0x1a8000: 0x80001000,
|
||||
0x1b8000: 0x80400040,
|
||||
0x1c8000: 0x1040,
|
||||
0x1d8000: 0x80401000,
|
||||
0x1e8000: 0x400000,
|
||||
0x1f8000: 0x401040
|
||||
},
|
||||
{
|
||||
0x0: 0x80,
|
||||
0x1000: 0x1040000,
|
||||
0x2000: 0x40000,
|
||||
0x3000: 0x20000000,
|
||||
0x4000: 0x20040080,
|
||||
0x5000: 0x1000080,
|
||||
0x6000: 0x21000080,
|
||||
0x7000: 0x40080,
|
||||
0x8000: 0x1000000,
|
||||
0x9000: 0x20040000,
|
||||
0xa000: 0x20000080,
|
||||
0xb000: 0x21040080,
|
||||
0xc000: 0x21040000,
|
||||
0xd000: 0x0,
|
||||
0xe000: 0x1040080,
|
||||
0xf000: 0x21000000,
|
||||
0x800: 0x1040080,
|
||||
0x1800: 0x21000080,
|
||||
0x2800: 0x80,
|
||||
0x3800: 0x1040000,
|
||||
0x4800: 0x40000,
|
||||
0x5800: 0x20040080,
|
||||
0x6800: 0x21040000,
|
||||
0x7800: 0x20000000,
|
||||
0x8800: 0x20040000,
|
||||
0x9800: 0x0,
|
||||
0xa800: 0x21040080,
|
||||
0xb800: 0x1000080,
|
||||
0xc800: 0x20000080,
|
||||
0xd800: 0x21000000,
|
||||
0xe800: 0x1000000,
|
||||
0xf800: 0x40080,
|
||||
0x10000: 0x40000,
|
||||
0x11000: 0x80,
|
||||
0x12000: 0x20000000,
|
||||
0x13000: 0x21000080,
|
||||
0x14000: 0x1000080,
|
||||
0x15000: 0x21040000,
|
||||
0x16000: 0x20040080,
|
||||
0x17000: 0x1000000,
|
||||
0x18000: 0x21040080,
|
||||
0x19000: 0x21000000,
|
||||
0x1a000: 0x1040000,
|
||||
0x1b000: 0x20040000,
|
||||
0x1c000: 0x40080,
|
||||
0x1d000: 0x20000080,
|
||||
0x1e000: 0x0,
|
||||
0x1f000: 0x1040080,
|
||||
0x10800: 0x21000080,
|
||||
0x11800: 0x1000000,
|
||||
0x12800: 0x1040000,
|
||||
0x13800: 0x20040080,
|
||||
0x14800: 0x20000000,
|
||||
0x15800: 0x1040080,
|
||||
0x16800: 0x80,
|
||||
0x17800: 0x21040000,
|
||||
0x18800: 0x40080,
|
||||
0x19800: 0x21040080,
|
||||
0x1a800: 0x0,
|
||||
0x1b800: 0x21000000,
|
||||
0x1c800: 0x1000080,
|
||||
0x1d800: 0x40000,
|
||||
0x1e800: 0x20040000,
|
||||
0x1f800: 0x20000080
|
||||
},
|
||||
{
|
||||
0x0: 0x10000008,
|
||||
0x100: 0x2000,
|
||||
0x200: 0x10200000,
|
||||
0x300: 0x10202008,
|
||||
0x400: 0x10002000,
|
||||
0x500: 0x200000,
|
||||
0x600: 0x200008,
|
||||
0x700: 0x10000000,
|
||||
0x800: 0x0,
|
||||
0x900: 0x10002008,
|
||||
0xa00: 0x202000,
|
||||
0xb00: 0x8,
|
||||
0xc00: 0x10200008,
|
||||
0xd00: 0x202008,
|
||||
0xe00: 0x2008,
|
||||
0xf00: 0x10202000,
|
||||
0x80: 0x10200000,
|
||||
0x180: 0x10202008,
|
||||
0x280: 0x8,
|
||||
0x380: 0x200000,
|
||||
0x480: 0x202008,
|
||||
0x580: 0x10000008,
|
||||
0x680: 0x10002000,
|
||||
0x780: 0x2008,
|
||||
0x880: 0x200008,
|
||||
0x980: 0x2000,
|
||||
0xa80: 0x10002008,
|
||||
0xb80: 0x10200008,
|
||||
0xc80: 0x0,
|
||||
0xd80: 0x10202000,
|
||||
0xe80: 0x202000,
|
||||
0xf80: 0x10000000,
|
||||
0x1000: 0x10002000,
|
||||
0x1100: 0x10200008,
|
||||
0x1200: 0x10202008,
|
||||
0x1300: 0x2008,
|
||||
0x1400: 0x200000,
|
||||
0x1500: 0x10000000,
|
||||
0x1600: 0x10000008,
|
||||
0x1700: 0x202000,
|
||||
0x1800: 0x202008,
|
||||
0x1900: 0x0,
|
||||
0x1a00: 0x8,
|
||||
0x1b00: 0x10200000,
|
||||
0x1c00: 0x2000,
|
||||
0x1d00: 0x10002008,
|
||||
0x1e00: 0x10202000,
|
||||
0x1f00: 0x200008,
|
||||
0x1080: 0x8,
|
||||
0x1180: 0x202000,
|
||||
0x1280: 0x200000,
|
||||
0x1380: 0x10000008,
|
||||
0x1480: 0x10002000,
|
||||
0x1580: 0x2008,
|
||||
0x1680: 0x10202008,
|
||||
0x1780: 0x10200000,
|
||||
0x1880: 0x10202000,
|
||||
0x1980: 0x10200008,
|
||||
0x1a80: 0x2000,
|
||||
0x1b80: 0x202008,
|
||||
0x1c80: 0x200008,
|
||||
0x1d80: 0x0,
|
||||
0x1e80: 0x10000000,
|
||||
0x1f80: 0x10002008
|
||||
},
|
||||
{
|
||||
0x0: 0x100000,
|
||||
0x10: 0x2000401,
|
||||
0x20: 0x400,
|
||||
0x30: 0x100401,
|
||||
0x40: 0x2100401,
|
||||
0x50: 0x0,
|
||||
0x60: 0x1,
|
||||
0x70: 0x2100001,
|
||||
0x80: 0x2000400,
|
||||
0x90: 0x100001,
|
||||
0xa0: 0x2000001,
|
||||
0xb0: 0x2100400,
|
||||
0xc0: 0x2100000,
|
||||
0xd0: 0x401,
|
||||
0xe0: 0x100400,
|
||||
0xf0: 0x2000000,
|
||||
0x8: 0x2100001,
|
||||
0x18: 0x0,
|
||||
0x28: 0x2000401,
|
||||
0x38: 0x2100400,
|
||||
0x48: 0x100000,
|
||||
0x58: 0x2000001,
|
||||
0x68: 0x2000000,
|
||||
0x78: 0x401,
|
||||
0x88: 0x100401,
|
||||
0x98: 0x2000400,
|
||||
0xa8: 0x2100000,
|
||||
0xb8: 0x100001,
|
||||
0xc8: 0x400,
|
||||
0xd8: 0x2100401,
|
||||
0xe8: 0x1,
|
||||
0xf8: 0x100400,
|
||||
0x100: 0x2000000,
|
||||
0x110: 0x100000,
|
||||
0x120: 0x2000401,
|
||||
0x130: 0x2100001,
|
||||
0x140: 0x100001,
|
||||
0x150: 0x2000400,
|
||||
0x160: 0x2100400,
|
||||
0x170: 0x100401,
|
||||
0x180: 0x401,
|
||||
0x190: 0x2100401,
|
||||
0x1a0: 0x100400,
|
||||
0x1b0: 0x1,
|
||||
0x1c0: 0x0,
|
||||
0x1d0: 0x2100000,
|
||||
0x1e0: 0x2000001,
|
||||
0x1f0: 0x400,
|
||||
0x108: 0x100400,
|
||||
0x118: 0x2000401,
|
||||
0x128: 0x2100001,
|
||||
0x138: 0x1,
|
||||
0x148: 0x2000000,
|
||||
0x158: 0x100000,
|
||||
0x168: 0x401,
|
||||
0x178: 0x2100400,
|
||||
0x188: 0x2000001,
|
||||
0x198: 0x2100000,
|
||||
0x1a8: 0x0,
|
||||
0x1b8: 0x2100401,
|
||||
0x1c8: 0x100401,
|
||||
0x1d8: 0x400,
|
||||
0x1e8: 0x2000400,
|
||||
0x1f8: 0x100001
|
||||
},
|
||||
{
|
||||
0x0: 0x8000820,
|
||||
0x1: 0x20000,
|
||||
0x2: 0x8000000,
|
||||
0x3: 0x20,
|
||||
0x4: 0x20020,
|
||||
0x5: 0x8020820,
|
||||
0x6: 0x8020800,
|
||||
0x7: 0x800,
|
||||
0x8: 0x8020000,
|
||||
0x9: 0x8000800,
|
||||
0xa: 0x20800,
|
||||
0xb: 0x8020020,
|
||||
0xc: 0x820,
|
||||
0xd: 0x0,
|
||||
0xe: 0x8000020,
|
||||
0xf: 0x20820,
|
||||
0x80000000: 0x800,
|
||||
0x80000001: 0x8020820,
|
||||
0x80000002: 0x8000820,
|
||||
0x80000003: 0x8000000,
|
||||
0x80000004: 0x8020000,
|
||||
0x80000005: 0x20800,
|
||||
0x80000006: 0x20820,
|
||||
0x80000007: 0x20,
|
||||
0x80000008: 0x8000020,
|
||||
0x80000009: 0x820,
|
||||
0x8000000a: 0x20020,
|
||||
0x8000000b: 0x8020800,
|
||||
0x8000000c: 0x0,
|
||||
0x8000000d: 0x8020020,
|
||||
0x8000000e: 0x8000800,
|
||||
0x8000000f: 0x20000,
|
||||
0x10: 0x20820,
|
||||
0x11: 0x8020800,
|
||||
0x12: 0x20,
|
||||
0x13: 0x800,
|
||||
0x14: 0x8000800,
|
||||
0x15: 0x8000020,
|
||||
0x16: 0x8020020,
|
||||
0x17: 0x20000,
|
||||
0x18: 0x0,
|
||||
0x19: 0x20020,
|
||||
0x1a: 0x8020000,
|
||||
0x1b: 0x8000820,
|
||||
0x1c: 0x8020820,
|
||||
0x1d: 0x20800,
|
||||
0x1e: 0x820,
|
||||
0x1f: 0x8000000,
|
||||
0x80000010: 0x20000,
|
||||
0x80000011: 0x800,
|
||||
0x80000012: 0x8020020,
|
||||
0x80000013: 0x20820,
|
||||
0x80000014: 0x20,
|
||||
0x80000015: 0x8020000,
|
||||
0x80000016: 0x8000000,
|
||||
0x80000017: 0x8000820,
|
||||
0x80000018: 0x8020820,
|
||||
0x80000019: 0x8000020,
|
||||
0x8000001a: 0x8000800,
|
||||
0x8000001b: 0x0,
|
||||
0x8000001c: 0x20800,
|
||||
0x8000001d: 0x820,
|
||||
0x8000001e: 0x20020,
|
||||
0x8000001f: 0x8020800
|
||||
}
|
||||
];
|
||||
|
||||
// Masks that select the SBOX input
|
||||
var SBOX_MASK = [
|
||||
0xf8000001, 0x1f800000, 0x01f80000, 0x001f8000,
|
||||
0x0001f800, 0x00001f80, 0x000001f8, 0x8000001f
|
||||
];
|
||||
|
||||
/**
|
||||
* DES block cipher algorithm.
|
||||
*/
|
||||
var DES = C_algo.DES = BlockCipher.extend({
|
||||
_doReset: function () {
|
||||
// Shortcuts
|
||||
var key = this._key;
|
||||
var keyWords = key.words;
|
||||
|
||||
// Select 56 bits according to PC1
|
||||
var keyBits = [];
|
||||
for (var i = 0; i < 56; i++) {
|
||||
var keyBitPos = PC1[i] - 1;
|
||||
keyBits[i] = (keyWords[keyBitPos >>> 5] >>> (31 - keyBitPos % 32)) & 1;
|
||||
}
|
||||
|
||||
// Assemble 16 subkeys
|
||||
var subKeys = this._subKeys = [];
|
||||
for (var nSubKey = 0; nSubKey < 16; nSubKey++) {
|
||||
// Create subkey
|
||||
var subKey = subKeys[nSubKey] = [];
|
||||
|
||||
// Shortcut
|
||||
var bitShift = BIT_SHIFTS[nSubKey];
|
||||
|
||||
// Select 48 bits according to PC2
|
||||
for (var i = 0; i < 24; i++) {
|
||||
// Select from the left 28 key bits
|
||||
subKey[(i / 6) | 0] |= keyBits[((PC2[i] - 1) + bitShift) % 28] << (31 - i % 6);
|
||||
|
||||
// Select from the right 28 key bits
|
||||
subKey[4 + ((i / 6) | 0)] |= keyBits[28 + (((PC2[i + 24] - 1) + bitShift) % 28)] << (31 - i % 6);
|
||||
}
|
||||
|
||||
// Since each subkey is applied to an expanded 32-bit input,
|
||||
// the subkey can be broken into 8 values scaled to 32-bits,
|
||||
// which allows the key to be used without expansion
|
||||
subKey[0] = (subKey[0] << 1) | (subKey[0] >>> 31);
|
||||
for (var i = 1; i < 7; i++) {
|
||||
subKey[i] = subKey[i] >>> ((i - 1) * 4 + 3);
|
||||
}
|
||||
subKey[7] = (subKey[7] << 5) | (subKey[7] >>> 27);
|
||||
}
|
||||
|
||||
// Compute inverse subkeys
|
||||
var invSubKeys = this._invSubKeys = [];
|
||||
for (var i = 0; i < 16; i++) {
|
||||
invSubKeys[i] = subKeys[15 - i];
|
||||
}
|
||||
},
|
||||
|
||||
encryptBlock: function (M, offset) {
|
||||
this._doCryptBlock(M, offset, this._subKeys);
|
||||
},
|
||||
|
||||
decryptBlock: function (M, offset) {
|
||||
this._doCryptBlock(M, offset, this._invSubKeys);
|
||||
},
|
||||
|
||||
_doCryptBlock: function (M, offset, subKeys) {
|
||||
// Get input
|
||||
this._lBlock = M[offset];
|
||||
this._rBlock = M[offset + 1];
|
||||
|
||||
// Initial permutation
|
||||
exchangeLR.call(this, 4, 0x0f0f0f0f);
|
||||
exchangeLR.call(this, 16, 0x0000ffff);
|
||||
exchangeRL.call(this, 2, 0x33333333);
|
||||
exchangeRL.call(this, 8, 0x00ff00ff);
|
||||
exchangeLR.call(this, 1, 0x55555555);
|
||||
|
||||
// Rounds
|
||||
for (var round = 0; round < 16; round++) {
|
||||
// Shortcuts
|
||||
var subKey = subKeys[round];
|
||||
var lBlock = this._lBlock;
|
||||
var rBlock = this._rBlock;
|
||||
|
||||
// Feistel function
|
||||
var f = 0;
|
||||
for (var i = 0; i < 8; i++) {
|
||||
f |= SBOX_P[i][((rBlock ^ subKey[i]) & SBOX_MASK[i]) >>> 0];
|
||||
}
|
||||
this._lBlock = rBlock;
|
||||
this._rBlock = lBlock ^ f;
|
||||
}
|
||||
|
||||
// Undo swap from last round
|
||||
var t = this._lBlock;
|
||||
this._lBlock = this._rBlock;
|
||||
this._rBlock = t;
|
||||
|
||||
// Final permutation
|
||||
exchangeLR.call(this, 1, 0x55555555);
|
||||
exchangeRL.call(this, 8, 0x00ff00ff);
|
||||
exchangeRL.call(this, 2, 0x33333333);
|
||||
exchangeLR.call(this, 16, 0x0000ffff);
|
||||
exchangeLR.call(this, 4, 0x0f0f0f0f);
|
||||
|
||||
// Set output
|
||||
M[offset] = this._lBlock;
|
||||
M[offset + 1] = this._rBlock;
|
||||
},
|
||||
|
||||
keySize: 64/32,
|
||||
|
||||
ivSize: 64/32,
|
||||
|
||||
blockSize: 64/32
|
||||
});
|
||||
|
||||
// Swap bits across the left and right words
|
||||
function exchangeLR(offset, mask) {
|
||||
var t = ((this._lBlock >>> offset) ^ this._rBlock) & mask;
|
||||
this._rBlock ^= t;
|
||||
this._lBlock ^= t << offset;
|
||||
}
|
||||
|
||||
function exchangeRL(offset, mask) {
|
||||
var t = ((this._rBlock >>> offset) ^ this._lBlock) & mask;
|
||||
this._lBlock ^= t;
|
||||
this._rBlock ^= t << offset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shortcut functions to the cipher's object interface.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* var ciphertext = CryptoJS.DES.encrypt(message, key, cfg);
|
||||
* var plaintext = CryptoJS.DES.decrypt(ciphertext, key, cfg);
|
||||
*/
|
||||
C.DES = BlockCipher._createHelper(DES);
|
||||
|
||||
/**
|
||||
* Triple-DES block cipher algorithm.
|
||||
*/
|
||||
var TripleDES = C_algo.TripleDES = BlockCipher.extend({
|
||||
_doReset: function () {
|
||||
// Shortcuts
|
||||
var key = this._key;
|
||||
var keyWords = key.words;
|
||||
|
||||
// Create DES instances
|
||||
this._des1 = DES.createEncryptor(WordArray.create(keyWords.slice(0, 2)));
|
||||
this._des2 = DES.createEncryptor(WordArray.create(keyWords.slice(2, 4)));
|
||||
this._des3 = DES.createEncryptor(WordArray.create(keyWords.slice(4, 6)));
|
||||
},
|
||||
|
||||
encryptBlock: function (M, offset) {
|
||||
this._des1.encryptBlock(M, offset);
|
||||
this._des2.decryptBlock(M, offset);
|
||||
this._des3.encryptBlock(M, offset);
|
||||
},
|
||||
|
||||
decryptBlock: function (M, offset) {
|
||||
this._des3.decryptBlock(M, offset);
|
||||
this._des2.encryptBlock(M, offset);
|
||||
this._des1.decryptBlock(M, offset);
|
||||
},
|
||||
|
||||
keySize: 192/32,
|
||||
|
||||
ivSize: 64/32,
|
||||
|
||||
blockSize: 64/32
|
||||
});
|
||||
|
||||
/**
|
||||
* Shortcut functions to the cipher's object interface.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* var ciphertext = CryptoJS.TripleDES.encrypt(message, key, cfg);
|
||||
* var plaintext = CryptoJS.TripleDES.decrypt(ciphertext, key, cfg);
|
||||
*/
|
||||
C.TripleDES = BlockCipher._createHelper(TripleDES);
|
||||
}());
|
@ -1,290 +0,0 @@
|
||||
/*
|
||||
CryptoJS v3.1.2
|
||||
code.google.com/p/crypto-js
|
||||
(c) 2009-2013 by Jeff Mott. All rights reserved.
|
||||
code.google.com/p/crypto-js/wiki/License
|
||||
*/
|
||||
(function (undefined) {
|
||||
// Shortcuts
|
||||
var C = CryptoJS;
|
||||
var C_lib = C.lib;
|
||||
var Base = C_lib.Base;
|
||||
var X32WordArray = C_lib.WordArray;
|
||||
|
||||
/**
|
||||
* x64 namespace.
|
||||
*/
|
||||
var C_x64 = C.x64 = {};
|
||||
|
||||
/**
|
||||
* A 64-bit word.
|
||||
*/
|
||||
var X64Word = C_x64.Word = Base.extend({
|
||||
/**
|
||||
* Initializes a newly created 64-bit word.
|
||||
*
|
||||
* @param {number} high The high 32 bits.
|
||||
* @param {number} low The low 32 bits.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* var x64Word = CryptoJS.x64.Word.create(0x00010203, 0x04050607);
|
||||
*/
|
||||
init: function (high, low) {
|
||||
this.high = high;
|
||||
this.low = low;
|
||||
}
|
||||
|
||||
/**
|
||||
* Bitwise NOTs this word.
|
||||
*
|
||||
* @return {X64Word} A new x64-Word object after negating.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* var negated = x64Word.not();
|
||||
*/
|
||||
// not: function () {
|
||||
// var high = ~this.high;
|
||||
// var low = ~this.low;
|
||||
|
||||
// return X64Word.create(high, low);
|
||||
// },
|
||||
|
||||
/**
|
||||
* Bitwise ANDs this word with the passed word.
|
||||
*
|
||||
* @param {X64Word} word The x64-Word to AND with this word.
|
||||
*
|
||||
* @return {X64Word} A new x64-Word object after ANDing.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* var anded = x64Word.and(anotherX64Word);
|
||||
*/
|
||||
// and: function (word) {
|
||||
// var high = this.high & word.high;
|
||||
// var low = this.low & word.low;
|
||||
|
||||
// return X64Word.create(high, low);
|
||||
// },
|
||||
|
||||
/**
|
||||
* Bitwise ORs this word with the passed word.
|
||||
*
|
||||
* @param {X64Word} word The x64-Word to OR with this word.
|
||||
*
|
||||
* @return {X64Word} A new x64-Word object after ORing.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* var ored = x64Word.or(anotherX64Word);
|
||||
*/
|
||||
// or: function (word) {
|
||||
// var high = this.high | word.high;
|
||||
// var low = this.low | word.low;
|
||||
|
||||
// return X64Word.create(high, low);
|
||||
// },
|
||||
|
||||
/**
|
||||
* Bitwise XORs this word with the passed word.
|
||||
*
|
||||
* @param {X64Word} word The x64-Word to XOR with this word.
|
||||
*
|
||||
* @return {X64Word} A new x64-Word object after XORing.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* var xored = x64Word.xor(anotherX64Word);
|
||||
*/
|
||||
// xor: function (word) {
|
||||
// var high = this.high ^ word.high;
|
||||
// var low = this.low ^ word.low;
|
||||
|
||||
// return X64Word.create(high, low);
|
||||
// },
|
||||
|
||||
/**
|
||||
* Shifts this word n bits to the left.
|
||||
*
|
||||
* @param {number} n The number of bits to shift.
|
||||
*
|
||||
* @return {X64Word} A new x64-Word object after shifting.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* var shifted = x64Word.shiftL(25);
|
||||
*/
|
||||
// shiftL: function (n) {
|
||||
// if (n < 32) {
|
||||
// var high = (this.high << n) | (this.low >>> (32 - n));
|
||||
// var low = this.low << n;
|
||||
// } else {
|
||||
// var high = this.low << (n - 32);
|
||||
// var low = 0;
|
||||
// }
|
||||
|
||||
// return X64Word.create(high, low);
|
||||
// },
|
||||
|
||||
/**
|
||||
* Shifts this word n bits to the right.
|
||||
*
|
||||
* @param {number} n The number of bits to shift.
|
||||
*
|
||||
* @return {X64Word} A new x64-Word object after shifting.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* var shifted = x64Word.shiftR(7);
|
||||
*/
|
||||
// shiftR: function (n) {
|
||||
// if (n < 32) {
|
||||
// var low = (this.low >>> n) | (this.high << (32 - n));
|
||||
// var high = this.high >>> n;
|
||||
// } else {
|
||||
// var low = this.high >>> (n - 32);
|
||||
// var high = 0;
|
||||
// }
|
||||
|
||||
// return X64Word.create(high, low);
|
||||
// },
|
||||
|
||||
/**
|
||||
* Rotates this word n bits to the left.
|
||||
*
|
||||
* @param {number} n The number of bits to rotate.
|
||||
*
|
||||
* @return {X64Word} A new x64-Word object after rotating.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* var rotated = x64Word.rotL(25);
|
||||
*/
|
||||
// rotL: function (n) {
|
||||
// return this.shiftL(n).or(this.shiftR(64 - n));
|
||||
// },
|
||||
|
||||
/**
|
||||
* Rotates this word n bits to the right.
|
||||
*
|
||||
* @param {number} n The number of bits to rotate.
|
||||
*
|
||||
* @return {X64Word} A new x64-Word object after rotating.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* var rotated = x64Word.rotR(7);
|
||||
*/
|
||||
// rotR: function (n) {
|
||||
// return this.shiftR(n).or(this.shiftL(64 - n));
|
||||
// },
|
||||
|
||||
/**
|
||||
* Adds this word with the passed word.
|
||||
*
|
||||
* @param {X64Word} word The x64-Word to add with this word.
|
||||
*
|
||||
* @return {X64Word} A new x64-Word object after adding.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* var added = x64Word.add(anotherX64Word);
|
||||
*/
|
||||
// add: function (word) {
|
||||
// var low = (this.low + word.low) | 0;
|
||||
// var carry = (low >>> 0) < (this.low >>> 0) ? 1 : 0;
|
||||
// var high = (this.high + word.high + carry) | 0;
|
||||
|
||||
// return X64Word.create(high, low);
|
||||
// }
|
||||
});
|
||||
|
||||
/**
|
||||
* An array of 64-bit words.
|
||||
*
|
||||
* @property {Array} words The array of CryptoJS.x64.Word objects.
|
||||
* @property {number} sigBytes The number of significant bytes in this word array.
|
||||
*/
|
||||
var X64WordArray = C_x64.WordArray = Base.extend({
|
||||
/**
|
||||
* Initializes a newly created word array.
|
||||
*
|
||||
* @param {Array} words (Optional) An array of CryptoJS.x64.Word objects.
|
||||
* @param {number} sigBytes (Optional) The number of significant bytes in the words.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* var wordArray = CryptoJS.x64.WordArray.create();
|
||||
*
|
||||
* var wordArray = CryptoJS.x64.WordArray.create([
|
||||
* CryptoJS.x64.Word.create(0x00010203, 0x04050607),
|
||||
* CryptoJS.x64.Word.create(0x18191a1b, 0x1c1d1e1f)
|
||||
* ]);
|
||||
*
|
||||
* var wordArray = CryptoJS.x64.WordArray.create([
|
||||
* CryptoJS.x64.Word.create(0x00010203, 0x04050607),
|
||||
* CryptoJS.x64.Word.create(0x18191a1b, 0x1c1d1e1f)
|
||||
* ], 10);
|
||||
*/
|
||||
init: function (words, sigBytes) {
|
||||
words = this.words = words || [];
|
||||
|
||||
if (sigBytes != undefined) {
|
||||
this.sigBytes = sigBytes;
|
||||
} else {
|
||||
this.sigBytes = words.length * 8;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Converts this 64-bit word array to a 32-bit word array.
|
||||
*
|
||||
* @return {CryptoJS.lib.WordArray} This word array's data as a 32-bit word array.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* var x32WordArray = x64WordArray.toX32();
|
||||
*/
|
||||
toX32: function () {
|
||||
// Shortcuts
|
||||
var x64Words = this.words;
|
||||
var x64WordsLength = x64Words.length;
|
||||
|
||||
// Convert
|
||||
var x32Words = [];
|
||||
for (var i = 0; i < x64WordsLength; i++) {
|
||||
var x64Word = x64Words[i];
|
||||
x32Words.push(x64Word.high);
|
||||
x32Words.push(x64Word.low);
|
||||
}
|
||||
|
||||
return X32WordArray.create(x32Words, this.sigBytes);
|
||||
},
|
||||
|
||||
/**
|
||||
* Creates a copy of this word array.
|
||||
*
|
||||
* @return {X64WordArray} The clone.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* var clone = x64WordArray.clone();
|
||||
*/
|
||||
clone: function () {
|
||||
var clone = Base.clone.call(this);
|
||||
|
||||
// Clone "words" array
|
||||
var words = clone.words = this.words.slice(0);
|
||||
|
||||
// Clone each X64Word object
|
||||
var wordsLength = words.length;
|
||||
for (var i = 0; i < wordsLength; i++) {
|
||||
words[i] = words[i].clone();
|
||||
}
|
||||
|
||||
return clone;
|
||||
}
|
||||
});
|
||||
}());
|
File diff suppressed because one or more lines are too long
BIN
src/js/lib/esmangle.min.js
vendored
BIN
src/js/lib/esmangle.min.js
vendored
Binary file not shown.
File diff suppressed because one or more lines are too long
@ -1,70 +0,0 @@
|
||||
var b64map="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
var b64padchar="=";
|
||||
function hex2b64(h) {
|
||||
var i;
|
||||
var c;
|
||||
var ret = "";
|
||||
for(i = 0; i+3 <= h.length; i+=3) {
|
||||
c = parseInt(h.substring(i,i+3),16);
|
||||
ret += b64map.charAt(c >> 6) + b64map.charAt(c & 63);
|
||||
}
|
||||
if(i+1 == h.length) {
|
||||
c = parseInt(h.substring(i,i+1),16);
|
||||
ret += b64map.charAt(c << 2);
|
||||
}
|
||||
else if(i+2 == h.length) {
|
||||
c = parseInt(h.substring(i,i+2),16);
|
||||
ret += b64map.charAt(c >> 2) + b64map.charAt((c & 3) << 4);
|
||||
}
|
||||
while((ret.length & 3) > 0) ret += b64padchar;
|
||||
return ret;
|
||||
}
|
||||
|
||||
// convert a base64 string to hex
|
||||
function b64tohex(s) {
|
||||
var ret = ""
|
||||
var i;
|
||||
var k = 0; // b64 state, 0-3
|
||||
var slop;
|
||||
for(i = 0; i < s.length; ++i) {
|
||||
if(s.charAt(i) == b64padchar) break;
|
||||
var v = b64map.indexOf(s.charAt(i));
|
||||
if(v < 0) continue;
|
||||
if(k == 0) {
|
||||
ret += int2char(v >> 2);
|
||||
slop = v & 3;
|
||||
k = 1;
|
||||
}
|
||||
else if(k == 1) {
|
||||
ret += int2char((slop << 2) | (v >> 4));
|
||||
slop = v & 0xf;
|
||||
k = 2;
|
||||
}
|
||||
else if(k == 2) {
|
||||
ret += int2char(slop);
|
||||
ret += int2char(v >> 2);
|
||||
slop = v & 3;
|
||||
k = 3;
|
||||
}
|
||||
else {
|
||||
ret += int2char((slop << 2) | (v >> 4));
|
||||
ret += int2char(v & 0xf);
|
||||
k = 0;
|
||||
}
|
||||
}
|
||||
if(k == 1)
|
||||
ret += int2char(slop << 2);
|
||||
return ret;
|
||||
}
|
||||
|
||||
// convert a base64 string to a byte/number array
|
||||
function b64toBA(s) {
|
||||
//piggyback on b64tohex for now, optimize later
|
||||
var h = b64tohex(s);
|
||||
var i;
|
||||
var a = new Array();
|
||||
for(i = 0; 2*i < h.length; ++i) {
|
||||
a[i] = parseInt(h.substring(2*i,2*i+2),16);
|
||||
}
|
||||
return a;
|
||||
}
|
@ -1,288 +0,0 @@
|
||||
// Basic Javascript Elliptic Curve implementation
|
||||
// Ported loosely from BouncyCastle's Java EC code
|
||||
// Only Fp curves implemented for now
|
||||
// Requires jsbn.js and jsbn2.js
|
||||
// ----------------
|
||||
// ECFieldElementFp
|
||||
// constructor
|
||||
function ECFieldElementFp(q,x) {
|
||||
this.x = x;
|
||||
// TODO if(x.compareTo(q) >= 0) error
|
||||
this.q = q;
|
||||
}
|
||||
function feFpEquals(other) {
|
||||
if(other == this) return true;
|
||||
return (this.q.equals(other.q) && this.x.equals(other.x));
|
||||
}
|
||||
function feFpToBigInteger() {
|
||||
return this.x;
|
||||
}
|
||||
function feFpNegate() {
|
||||
return new ECFieldElementFp(this.q, this.x.negate().mod(this.q));
|
||||
}
|
||||
function feFpAdd(b) {
|
||||
return new ECFieldElementFp(this.q, this.x.add(b.toBigInteger()).mod(this.q));
|
||||
}
|
||||
function feFpSubtract(b) {
|
||||
return new ECFieldElementFp(this.q, this.x.subtract(b.toBigInteger()).mod(this.q));
|
||||
}
|
||||
function feFpMultiply(b) {
|
||||
return new ECFieldElementFp(this.q, this.x.multiply(b.toBigInteger()).mod(this.q));
|
||||
}
|
||||
function feFpSquare() {
|
||||
return new ECFieldElementFp(this.q, this.x.square().mod(this.q));
|
||||
}
|
||||
function feFpDivide(b) {
|
||||
return new ECFieldElementFp(this.q, this.x.multiply(b.toBigInteger().modInverse(this.q)).mod(this.q));
|
||||
}
|
||||
ECFieldElementFp.prototype.equals = feFpEquals;
|
||||
ECFieldElementFp.prototype.toBigInteger = feFpToBigInteger;
|
||||
ECFieldElementFp.prototype.negate = feFpNegate;
|
||||
ECFieldElementFp.prototype.add = feFpAdd;
|
||||
ECFieldElementFp.prototype.subtract = feFpSubtract;
|
||||
ECFieldElementFp.prototype.multiply = feFpMultiply;
|
||||
ECFieldElementFp.prototype.square = feFpSquare;
|
||||
ECFieldElementFp.prototype.divide = feFpDivide;
|
||||
// ----------------
|
||||
// ECPointFp
|
||||
// constructor
|
||||
function ECPointFp(curve,x,y,z) {
|
||||
this.curve = curve;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
// Projective coordinates: either zinv == null or z * zinv == 1
|
||||
// z and zinv are just BigIntegers, not fieldElements
|
||||
if(z == null) {
|
||||
this.z = BigInteger.ONE;
|
||||
}
|
||||
else {
|
||||
this.z = z;
|
||||
}
|
||||
this.zinv = null;
|
||||
//TODO: compression flag
|
||||
}
|
||||
function pointFpGetX() {
|
||||
if(this.zinv == null) {
|
||||
this.zinv = this.z.modInverse(this.curve.q);
|
||||
}
|
||||
var r = this.x.toBigInteger().multiply(this.zinv);
|
||||
this.curve.reduce(r);
|
||||
return this.curve.fromBigInteger(r);
|
||||
}
|
||||
function pointFpGetY() {
|
||||
if(this.zinv == null) {
|
||||
this.zinv = this.z.modInverse(this.curve.q);
|
||||
}
|
||||
var r = this.y.toBigInteger().multiply(this.zinv);
|
||||
this.curve.reduce(r);
|
||||
return this.curve.fromBigInteger(r);
|
||||
}
|
||||
function pointFpEquals(other) {
|
||||
if(other == this) return true;
|
||||
if(this.isInfinity()) return other.isInfinity();
|
||||
if(other.isInfinity()) return this.isInfinity();
|
||||
var u, v;
|
||||
// u = Y2 * Z1 - Y1 * Z2
|
||||
u = other.y.toBigInteger().multiply(this.z).subtract(this.y.toBigInteger().multiply(other.z)).mod(this.curve.q);
|
||||
if(!u.equals(BigInteger.ZERO)) return false;
|
||||
// v = X2 * Z1 - X1 * Z2
|
||||
v = other.x.toBigInteger().multiply(this.z).subtract(this.x.toBigInteger().multiply(other.z)).mod(this.curve.q);
|
||||
return v.equals(BigInteger.ZERO);
|
||||
}
|
||||
function pointFpIsInfinity() {
|
||||
if((this.x == null) && (this.y == null)) return true;
|
||||
return this.z.equals(BigInteger.ZERO) && !this.y.toBigInteger().equals(BigInteger.ZERO);
|
||||
}
|
||||
function pointFpNegate() {
|
||||
return new ECPointFp(this.curve, this.x, this.y.negate(), this.z);
|
||||
}
|
||||
function pointFpAdd(b) {
|
||||
if(this.isInfinity()) return b;
|
||||
if(b.isInfinity()) return this;
|
||||
// u = Y2 * Z1 - Y1 * Z2
|
||||
var u = b.y.toBigInteger().multiply(this.z).subtract(this.y.toBigInteger().multiply(b.z)).mod(this.curve.q);
|
||||
// v = X2 * Z1 - X1 * Z2
|
||||
var v = b.x.toBigInteger().multiply(this.z).subtract(this.x.toBigInteger().multiply(b.z)).mod(this.curve.q);
|
||||
if(BigInteger.ZERO.equals(v)) {
|
||||
if(BigInteger.ZERO.equals(u)) {
|
||||
return this.twice(); // this == b, so double
|
||||
}
|
||||
return this.curve.getInfinity(); // this = -b, so infinity
|
||||
}
|
||||
var THREE = new BigInteger("3");
|
||||
var x1 = this.x.toBigInteger();
|
||||
var y1 = this.y.toBigInteger();
|
||||
var x2 = b.x.toBigInteger();
|
||||
var y2 = b.y.toBigInteger();
|
||||
var v2 = v.square();
|
||||
var v3 = v2.multiply(v);
|
||||
var x1v2 = x1.multiply(v2);
|
||||
var zu2 = u.square().multiply(this.z);
|
||||
// x3 = v * (z2 * (z1 * u^2 - 2 * x1 * v^2) - v^3)
|
||||
var x3 = zu2.subtract(x1v2.shiftLeft(1)).multiply(b.z).subtract(v3).multiply(v).mod(this.curve.q);
|
||||
// y3 = z2 * (3 * x1 * u * v^2 - y1 * v^3 - z1 * u^3) + u * v^3
|
||||
var y3 = x1v2.multiply(THREE).multiply(u).subtract(y1.multiply(v3)).subtract(zu2.multiply(u)).multiply(b.z).add(u.multiply(v3)).mod(this.curve.q);
|
||||
// z3 = v^3 * z1 * z2
|
||||
var z3 = v3.multiply(this.z).multiply(b.z).mod(this.curve.q);
|
||||
return new ECPointFp(this.curve, this.curve.fromBigInteger(x3), this.curve.fromBigInteger(y3), z3);
|
||||
}
|
||||
function pointFpTwice() {
|
||||
if(this.isInfinity()) return this;
|
||||
if(this.y.toBigInteger().signum() == 0) return this.curve.getInfinity();
|
||||
// TODO: optimized handling of constants
|
||||
var THREE = new BigInteger("3");
|
||||
var x1 = this.x.toBigInteger();
|
||||
var y1 = this.y.toBigInteger();
|
||||
var y1z1 = y1.multiply(this.z);
|
||||
var y1sqz1 = y1z1.multiply(y1).mod(this.curve.q);
|
||||
var a = this.curve.a.toBigInteger();
|
||||
// w = 3 * x1^2 + a * z1^2
|
||||
var w = x1.square().multiply(THREE);
|
||||
if(!BigInteger.ZERO.equals(a)) {
|
||||
w = w.add(this.z.square().multiply(a));
|
||||
}
|
||||
w = w.mod(this.curve.q);
|
||||
//this.curve.reduce(w);
|
||||
// x3 = 2 * y1 * z1 * (w^2 - 8 * x1 * y1^2 * z1)
|
||||
var x3 = w.square().subtract(x1.shiftLeft(3).multiply(y1sqz1)).shiftLeft(1).multiply(y1z1).mod(this.curve.q);
|
||||
// y3 = 4 * y1^2 * z1 * (3 * w * x1 - 2 * y1^2 * z1) - w^3
|
||||
var y3 = w.multiply(THREE).multiply(x1).subtract(y1sqz1.shiftLeft(1)).shiftLeft(2).multiply(y1sqz1).subtract(w.square().multiply(w)).mod(this.curve.q);
|
||||
// z3 = 8 * (y1 * z1)^3
|
||||
var z3 = y1z1.square().multiply(y1z1).shiftLeft(3).mod(this.curve.q);
|
||||
return new ECPointFp(this.curve, this.curve.fromBigInteger(x3), this.curve.fromBigInteger(y3), z3);
|
||||
}
|
||||
// Simple NAF (Non-Adjacent Form) multiplication algorithm
|
||||
// TODO: modularize the multiplication algorithm
|
||||
function pointFpMultiply(k) {
|
||||
if(this.isInfinity()) return this;
|
||||
if(k.signum() == 0) return this.curve.getInfinity();
|
||||
var e = k;
|
||||
var h = e.multiply(new BigInteger("3"));
|
||||
var neg = this.negate();
|
||||
var R = this;
|
||||
var i;
|
||||
for(i = h.bitLength() - 2; i > 0; --i) {
|
||||
R = R.twice();
|
||||
var hBit = h.testBit(i);
|
||||
var eBit = e.testBit(i);
|
||||
if (hBit != eBit) {
|
||||
R = R.add(hBit ? this : neg);
|
||||
}
|
||||
}
|
||||
return R;
|
||||
}
|
||||
// Compute this*j + x*k (simultaneous multiplication)
|
||||
function pointFpMultiplyTwo(j,x,k) {
|
||||
var i;
|
||||
if(j.bitLength() > k.bitLength())
|
||||
i = j.bitLength() - 1;
|
||||
else
|
||||
i = k.bitLength() - 1;
|
||||
var R = this.curve.getInfinity();
|
||||
var both = this.add(x);
|
||||
while(i >= 0) {
|
||||
R = R.twice();
|
||||
if(j.testBit(i)) {
|
||||
if(k.testBit(i)) {
|
||||
R = R.add(both);
|
||||
}
|
||||
else {
|
||||
R = R.add(this);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(k.testBit(i)) {
|
||||
R = R.add(x);
|
||||
}
|
||||
}
|
||||
--i;
|
||||
}
|
||||
return R;
|
||||
}
|
||||
ECPointFp.prototype.getX = pointFpGetX;
|
||||
ECPointFp.prototype.getY = pointFpGetY;
|
||||
ECPointFp.prototype.equals = pointFpEquals;
|
||||
ECPointFp.prototype.isInfinity = pointFpIsInfinity;
|
||||
ECPointFp.prototype.negate = pointFpNegate;
|
||||
ECPointFp.prototype.add = pointFpAdd;
|
||||
ECPointFp.prototype.twice = pointFpTwice;
|
||||
ECPointFp.prototype.multiply = pointFpMultiply;
|
||||
ECPointFp.prototype.multiplyTwo = pointFpMultiplyTwo;
|
||||
// ----------------
|
||||
// ECCurveFp
|
||||
// constructor
|
||||
function ECCurveFp(q,a,b) {
|
||||
this.q = q;
|
||||
this.a = this.fromBigInteger(a);
|
||||
this.b = this.fromBigInteger(b);
|
||||
this.infinity = new ECPointFp(this, null, null);
|
||||
this.reducer = new Barrett(this.q);
|
||||
}
|
||||
function curveFpGetQ() {
|
||||
return this.q;
|
||||
}
|
||||
function curveFpGetA() {
|
||||
return this.a;
|
||||
}
|
||||
function curveFpGetB() {
|
||||
return this.b;
|
||||
}
|
||||
function curveFpEquals(other) {
|
||||
if(other == this) return true;
|
||||
return(this.q.equals(other.q) && this.a.equals(other.a) && this.b.equals(other.b));
|
||||
}
|
||||
function curveFpGetInfinity() {
|
||||
return this.infinity;
|
||||
}
|
||||
function curveFpFromBigInteger(x) {
|
||||
return new ECFieldElementFp(this.q, x);
|
||||
}
|
||||
function curveReduce(x) {
|
||||
this.reducer.reduce(x);
|
||||
}
|
||||
// for now, work with hex strings because they're easier in JS
|
||||
function curveFpDecodePointHex(s) {
|
||||
switch(parseInt(s.substr(0,2), 16)) { // first byte
|
||||
case 0:
|
||||
return this.infinity;
|
||||
case 2:
|
||||
case 3:
|
||||
// point compression not supported yet
|
||||
return null;
|
||||
case 4:
|
||||
case 6:
|
||||
case 7:
|
||||
var len = (s.length - 2) / 2;
|
||||
var xHex = s.substr(2, len);
|
||||
var yHex = s.substr(len+2, len);
|
||||
return new ECPointFp(this,
|
||||
this.fromBigInteger(new BigInteger(xHex, 16)),
|
||||
this.fromBigInteger(new BigInteger(yHex, 16)));
|
||||
default: // unsupported
|
||||
return null;
|
||||
}
|
||||
}
|
||||
function curveFpEncodePointHex(p) {
|
||||
if (p.isInfinity()) return "00";
|
||||
var xHex = p.getX().toBigInteger().toString(16);
|
||||
var yHex = p.getY().toBigInteger().toString(16);
|
||||
var oLen = this.getQ().toString(16).length;
|
||||
if ((oLen % 2) != 0) oLen++;
|
||||
while (xHex.length < oLen) {
|
||||
xHex = "0" + xHex;
|
||||
}
|
||||
while (yHex.length < oLen) {
|
||||
yHex = "0" + yHex;
|
||||
}
|
||||
return "04" + xHex + yHex;
|
||||
}
|
||||
|
||||
ECCurveFp.prototype.getQ = curveFpGetQ;
|
||||
ECCurveFp.prototype.getA = curveFpGetA;
|
||||
ECCurveFp.prototype.getB = curveFpGetB;
|
||||
ECCurveFp.prototype.equals = curveFpEquals;
|
||||
ECCurveFp.prototype.getInfinity = curveFpGetInfinity;
|
||||
ECCurveFp.prototype.fromBigInteger = curveFpFromBigInteger;
|
||||
ECCurveFp.prototype.reduce = curveReduce;
|
||||
ECCurveFp.prototype.decodePointHex = curveFpDecodePointHex;
|
||||
ECCurveFp.prototype.encodePointHex = curveFpEncodePointHex;
|
@ -1,591 +0,0 @@
|
||||
/** @license
|
||||
========================================================================
|
||||
Copyright (c) 2005 Tom Wu
|
||||
All Rights Reserved.
|
||||
Basic JavaScript BN library - subset useful for RSA encryption.
|
||||
|
||||
This software is covered under the following copyright:
|
||||
|
||||
Copyright (c) 2003-2005 Tom Wu
|
||||
All Rights Reserved.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
|
||||
WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
|
||||
|
||||
IN NO EVENT SHALL TOM WU BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
|
||||
INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES WHATSOEVER
|
||||
RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT ADVISED OF
|
||||
THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF LIABILITY, ARISING OUT
|
||||
OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
In addition, the following condition applies:
|
||||
|
||||
All redistributions must retain an intact copy of this copyright notice
|
||||
and disclaimer.
|
||||
|
||||
Address all questions regarding this license to:
|
||||
Tom Wu
|
||||
tjw@cs.Stanford.EDU
|
||||
*/
|
||||
|
||||
// Bits per digit
|
||||
var dbits;
|
||||
// JavaScript engine analysis
|
||||
var canary = 0xdeadbeefcafe;
|
||||
var j_lm = ((canary&0xffffff)==0xefcafe);
|
||||
// (public) Constructor
|
||||
function BigInteger(a,b,c) {
|
||||
if(a != null)
|
||||
if("number" == typeof a) this.fromNumber(a,b,c);
|
||||
else if(b == null && "string" != typeof a) this.fromString(a,256);
|
||||
else this.fromString(a,b);
|
||||
}
|
||||
// return new, unset BigInteger
|
||||
function nbi() { return new BigInteger(null); }
|
||||
// am: Compute w_j += (x*this_i), propagate carries,
|
||||
// c is initial carry, returns final carry.
|
||||
// c < 3*dvalue, x < 2*dvalue, this_i < dvalue
|
||||
// We need to select the fastest one that works in this environment.
|
||||
|
||||
// am1: use a single mult and divide to get the high bits,
|
||||
// max digit bits should be 26 because
|
||||
// max internal value = 2*dvalue^2-2*dvalue (< 2^53)
|
||||
function am1(i,x,w,j,c,n) {
|
||||
while(--n >= 0) {
|
||||
var v = x*this[i++]+w[j]+c;
|
||||
c = Math.floor(v/0x4000000);
|
||||
w[j++] = v&0x3ffffff;
|
||||
}
|
||||
return c;
|
||||
}
|
||||
// am2 avoids a big mult-and-extract completely.
|
||||
// Max digit bits should be <= 30 because we do bitwise ops
|
||||
// on values up to 2*hdvalue^2-hdvalue-1 (< 2^31)
|
||||
function am2(i,x,w,j,c,n) {
|
||||
var xl = x&0x7fff, xh = x>>15;
|
||||
while(--n >= 0) {
|
||||
var l = this[i]&0x7fff;
|
||||
var h = this[i++]>>15;
|
||||
var m = xh*l+h*xl;
|
||||
l = xl*l+((m&0x7fff)<<15)+w[j]+(c&0x3fffffff);
|
||||
c = (l>>>30)+(m>>>15)+xh*h+(c>>>30);
|
||||
w[j++] = l&0x3fffffff;
|
||||
}
|
||||
return c;
|
||||
}
|
||||
// Alternately, set max digit bits to 28 since some
|
||||
// browsers slow down when dealing with 32-bit numbers.
|
||||
function am3(i,x,w,j,c,n) {
|
||||
var xl = x&0x3fff, xh = x>>14;
|
||||
while(--n >= 0) {
|
||||
var l = this[i]&0x3fff;
|
||||
var h = this[i++]>>14;
|
||||
var m = xh*l+h*xl;
|
||||
l = xl*l+((m&0x3fff)<<14)+w[j]+c;
|
||||
c = (l>>28)+(m>>14)+xh*h;
|
||||
w[j++] = l&0xfffffff;
|
||||
}
|
||||
return c;
|
||||
}
|
||||
if(j_lm && (navigator.appName == "Microsoft Internet Explorer")) {
|
||||
BigInteger.prototype.am = am2;
|
||||
dbits = 30;
|
||||
}
|
||||
else if(j_lm && (navigator.appName != "Netscape")) {
|
||||
BigInteger.prototype.am = am1;
|
||||
dbits = 26;
|
||||
}
|
||||
else { // Mozilla/Netscape seems to prefer am3
|
||||
BigInteger.prototype.am = am3;
|
||||
dbits = 28;
|
||||
}
|
||||
|
||||
BigInteger.prototype.DB = dbits;
|
||||
BigInteger.prototype.DM = ((1<<dbits)-1);
|
||||
BigInteger.prototype.DV = (1<<dbits);
|
||||
|
||||
var BI_FP = 52;
|
||||
BigInteger.prototype.FV = Math.pow(2,BI_FP);
|
||||
BigInteger.prototype.F1 = BI_FP-dbits;
|
||||
BigInteger.prototype.F2 = 2*dbits-BI_FP;
|
||||
|
||||
// Digit conversions
|
||||
var BI_RM = "0123456789abcdefghijklmnopqrstuvwxyz";
|
||||
var BI_RC = new Array();
|
||||
var rr,vv;
|
||||
rr = "0".charCodeAt(0);
|
||||
for(vv = 0; vv <= 9; ++vv) BI_RC[rr++] = vv;
|
||||
rr = "a".charCodeAt(0);
|
||||
for(vv = 10; vv < 36; ++vv) BI_RC[rr++] = vv;
|
||||
rr = "A".charCodeAt(0);
|
||||
for(vv = 10; vv < 36; ++vv) BI_RC[rr++] = vv;
|
||||
|
||||
function int2char(n) { return BI_RM.charAt(n); }
|
||||
function intAt(s,i) {
|
||||
var c = BI_RC[s.charCodeAt(i)];
|
||||
return (c==null)?-1:c;
|
||||
}
|
||||
|
||||
// (protected) copy this to r
|
||||
function bnpCopyTo(r) {
|
||||
for(var i = this.t-1; i >= 0; --i) r[i] = this[i];
|
||||
r.t = this.t;
|
||||
r.s = this.s;
|
||||
}
|
||||
|
||||
// (protected) set from integer value x, -DV <= x < DV
|
||||
function bnpFromInt(x) {
|
||||
this.t = 1;
|
||||
this.s = (x<0)?-1:0;
|
||||
if(x > 0) this[0] = x;
|
||||
else if(x < -1) this[0] = x+this.DV;
|
||||
else this.t = 0;
|
||||
}
|
||||
|
||||
// return bigint initialized to value
|
||||
function nbv(i) { var r = nbi(); r.fromInt(i); return r; }
|
||||
|
||||
// (protected) set from string and radix
|
||||
function bnpFromString(s,b) {
|
||||
var k;
|
||||
if(b == 16) k = 4;
|
||||
else if(b == 8) k = 3;
|
||||
else if(b == 256) k = 8; // byte array
|
||||
else if(b == 2) k = 1;
|
||||
else if(b == 32) k = 5;
|
||||
else if(b == 4) k = 2;
|
||||
else { this.fromRadix(s,b); return; }
|
||||
this.t = 0;
|
||||
this.s = 0;
|
||||
var i = s.length, mi = false, sh = 0;
|
||||
while(--i >= 0) {
|
||||
var x = (k==8)?s[i]&0xff:intAt(s,i);
|
||||
if(x < 0) {
|
||||
if(s.charAt(i) == "-") mi = true;
|
||||
continue;
|
||||
}
|
||||
mi = false;
|
||||
if(sh == 0)
|
||||
this[this.t++] = x;
|
||||
else if(sh+k > this.DB) {
|
||||
this[this.t-1] |= (x&((1<<(this.DB-sh))-1))<<sh;
|
||||
this[this.t++] = (x>>(this.DB-sh));
|
||||
}
|
||||
else
|
||||
this[this.t-1] |= x<<sh;
|
||||
sh += k;
|
||||
if(sh >= this.DB) sh -= this.DB;
|
||||
}
|
||||
if(k == 8 && (s[0]&0x80) != 0) {
|
||||
this.s = -1;
|
||||
if(sh > 0) this[this.t-1] |= ((1<<(this.DB-sh))-1)<<sh;
|
||||
}
|
||||
this.clamp();
|
||||
if(mi) BigInteger.ZERO.subTo(this,this);
|
||||
}
|
||||
|
||||
// (protected) clamp off excess high words
|
||||
function bnpClamp() {
|
||||
var c = this.s&this.DM;
|
||||
while(this.t > 0 && this[this.t-1] == c) --this.t;
|
||||
}
|
||||
|
||||
// (public) return string representation in given radix
|
||||
function bnToString(b) {
|
||||
if(this.s < 0) return "-"+this.negate().toString(b);
|
||||
var k;
|
||||
if(b == 16) k = 4;
|
||||
else if(b == 8) k = 3;
|
||||
else if(b == 2) k = 1;
|
||||
else if(b == 32) k = 5;
|
||||
else if(b == 4) k = 2;
|
||||
else return this.toRadix(b);
|
||||
var km = (1<<k)-1, d, m = false, r = "", i = this.t;
|
||||
var p = this.DB-(i*this.DB)%k;
|
||||
if(i-- > 0) {
|
||||
if(p < this.DB && (d = this[i]>>p) > 0) { m = true; r = int2char(d); }
|
||||
while(i >= 0) {
|
||||
if(p < k) {
|
||||
d = (this[i]&((1<<p)-1))<<(k-p);
|
||||
d |= this[--i]>>(p+=this.DB-k);
|
||||
}
|
||||
else {
|
||||
d = (this[i]>>(p-=k))&km;
|
||||
if(p <= 0) { p += this.DB; --i; }
|
||||
}
|
||||
if(d > 0) m = true;
|
||||
if(m) r += int2char(d);
|
||||
}
|
||||
}
|
||||
return m?r:"0";
|
||||
}
|
||||
|
||||
// (public) -this
|
||||
function bnNegate() { var r = nbi(); BigInteger.ZERO.subTo(this,r); return r; }
|
||||
|
||||
// (public) |this|
|
||||
function bnAbs() { return (this.s<0)?this.negate():this; }
|
||||
|
||||
// (public) return + if this > a, - if this < a, 0 if equal
|
||||
function bnCompareTo(a) {
|
||||
var r = this.s-a.s;
|
||||
if(r != 0) return r;
|
||||
var i = this.t;
|
||||
r = i-a.t;
|
||||
if(r != 0) return (this.s<0)?-r:r;
|
||||
while(--i >= 0) if((r=this[i]-a[i]) != 0) return r;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// returns bit length of the integer x
|
||||
function nbits(x) {
|
||||
var r = 1, t;
|
||||
if((t=x>>>16) != 0) { x = t; r += 16; }
|
||||
if((t=x>>8) != 0) { x = t; r += 8; }
|
||||
if((t=x>>4) != 0) { x = t; r += 4; }
|
||||
if((t=x>>2) != 0) { x = t; r += 2; }
|
||||
if((t=x>>1) != 0) { x = t; r += 1; }
|
||||
return r;
|
||||
}
|
||||
|
||||
// (public) return the number of bits in "this"
|
||||
function bnBitLength() {
|
||||
if(this.t <= 0) return 0;
|
||||
return this.DB*(this.t-1)+nbits(this[this.t-1]^(this.s&this.DM));
|
||||
}
|
||||
|
||||
// (protected) r = this << n*DB
|
||||
function bnpDLShiftTo(n,r) {
|
||||
var i;
|
||||
for(i = this.t-1; i >= 0; --i) r[i+n] = this[i];
|
||||
for(i = n-1; i >= 0; --i) r[i] = 0;
|
||||
r.t = this.t+n;
|
||||
r.s = this.s;
|
||||
}
|
||||
|
||||
// (protected) r = this >> n*DB
|
||||
function bnpDRShiftTo(n,r) {
|
||||
for(var i = n; i < this.t; ++i) r[i-n] = this[i];
|
||||
r.t = Math.max(this.t-n,0);
|
||||
r.s = this.s;
|
||||
}
|
||||
|
||||
// (protected) r = this << n
|
||||
function bnpLShiftTo(n,r) {
|
||||
var bs = n%this.DB;
|
||||
var cbs = this.DB-bs;
|
||||
var bm = (1<<cbs)-1;
|
||||
var ds = Math.floor(n/this.DB), c = (this.s<<bs)&this.DM, i;
|
||||
for(i = this.t-1; i >= 0; --i) {
|
||||
r[i+ds+1] = (this[i]>>cbs)|c;
|
||||
c = (this[i]&bm)<<bs;
|
||||
}
|
||||
for(i = ds-1; i >= 0; --i) r[i] = 0;
|
||||
r[ds] = c;
|
||||
r.t = this.t+ds+1;
|
||||
r.s = this.s;
|
||||
r.clamp();
|
||||
}
|
||||
|
||||
// (protected) r = this >> n
|
||||
function bnpRShiftTo(n,r) {
|
||||
r.s = this.s;
|
||||
var ds = Math.floor(n/this.DB);
|
||||
if(ds >= this.t) { r.t = 0; return; }
|
||||
var bs = n%this.DB;
|
||||
var cbs = this.DB-bs;
|
||||
var bm = (1<<bs)-1;
|
||||
r[0] = this[ds]>>bs;
|
||||
for(var i = ds+1; i < this.t; ++i) {
|
||||
r[i-ds-1] |= (this[i]&bm)<<cbs;
|
||||
r[i-ds] = this[i]>>bs;
|
||||
}
|
||||
if(bs > 0) r[this.t-ds-1] |= (this.s&bm)<<cbs;
|
||||
r.t = this.t-ds;
|
||||
r.clamp();
|
||||
}
|
||||
|
||||
// (protected) r = this - a
|
||||
function bnpSubTo(a,r) {
|
||||
var i = 0, c = 0, m = Math.min(a.t,this.t);
|
||||
while(i < m) {
|
||||
c += this[i]-a[i];
|
||||
r[i++] = c&this.DM;
|
||||
c >>= this.DB;
|
||||
}
|
||||
if(a.t < this.t) {
|
||||
c -= a.s;
|
||||
while(i < this.t) {
|
||||
c += this[i];
|
||||
r[i++] = c&this.DM;
|
||||
c >>= this.DB;
|
||||
}
|
||||
c += this.s;
|
||||
}
|
||||
else {
|
||||
c += this.s;
|
||||
while(i < a.t) {
|
||||
c -= a[i];
|
||||
r[i++] = c&this.DM;
|
||||
c >>= this.DB;
|
||||
}
|
||||
c -= a.s;
|
||||
}
|
||||
r.s = (c<0)?-1:0;
|
||||
if(c < -1) r[i++] = this.DV+c;
|
||||
else if(c > 0) r[i++] = c;
|
||||
r.t = i;
|
||||
r.clamp();
|
||||
}
|
||||
|
||||
// (protected) r = this * a, r != this,a (HAC 14.12)
|
||||
// "this" should be the larger one if appropriate.
|
||||
function bnpMultiplyTo(a,r) {
|
||||
var x = this.abs(), y = a.abs();
|
||||
var i = x.t;
|
||||
r.t = i+y.t;
|
||||
while(--i >= 0) r[i] = 0;
|
||||
for(i = 0; i < y.t; ++i) r[i+x.t] = x.am(0,y[i],r,i,0,x.t);
|
||||
r.s = 0;
|
||||
r.clamp();
|
||||
if(this.s != a.s) BigInteger.ZERO.subTo(r,r);
|
||||
}
|
||||
|
||||
// (protected) r = this^2, r != this (HAC 14.16)
|
||||
function bnpSquareTo(r) {
|
||||
var x = this.abs();
|
||||
var i = r.t = 2*x.t;
|
||||
while(--i >= 0) r[i] = 0;
|
||||
for(i = 0; i < x.t-1; ++i) {
|
||||
var c = x.am(i,x[i],r,2*i,0,1);
|
||||
if((r[i+x.t]+=x.am(i+1,2*x[i],r,2*i+1,c,x.t-i-1)) >= x.DV) {
|
||||
r[i+x.t] -= x.DV;
|
||||
r[i+x.t+1] = 1;
|
||||
}
|
||||
}
|
||||
if(r.t > 0) r[r.t-1] += x.am(i,x[i],r,2*i,0,1);
|
||||
r.s = 0;
|
||||
r.clamp();
|
||||
}
|
||||
|
||||
// (protected) divide this by m, quotient and remainder to q, r (HAC 14.20)
|
||||
// r != q, this != m. q or r may be null.
|
||||
function bnpDivRemTo(m,q,r) {
|
||||
var pm = m.abs();
|
||||
if(pm.t <= 0) return;
|
||||
var pt = this.abs();
|
||||
if(pt.t < pm.t) {
|
||||
if(q != null) q.fromInt(0);
|
||||
if(r != null) this.copyTo(r);
|
||||
return;
|
||||
}
|
||||
if(r == null) r = nbi();
|
||||
var y = nbi(), ts = this.s, ms = m.s;
|
||||
var nsh = this.DB-nbits(pm[pm.t-1]); // normalize modulus
|
||||
if(nsh > 0) { pm.lShiftTo(nsh,y); pt.lShiftTo(nsh,r); }
|
||||
else { pm.copyTo(y); pt.copyTo(r); }
|
||||
var ys = y.t;
|
||||
var y0 = y[ys-1];
|
||||
if(y0 == 0) return;
|
||||
var yt = y0*(1<<this.F1)+((ys>1)?y[ys-2]>>this.F2:0);
|
||||
var d1 = this.FV/yt, d2 = (1<<this.F1)/yt, e = 1<<this.F2;
|
||||
var i = r.t, j = i-ys, t = (q==null)?nbi():q;
|
||||
y.dlShiftTo(j,t);
|
||||
if(r.compareTo(t) >= 0) {
|
||||
r[r.t++] = 1;
|
||||
r.subTo(t,r);
|
||||
}
|
||||
BigInteger.ONE.dlShiftTo(ys,t);
|
||||
t.subTo(y,y); // "negative" y so we can replace sub with am later
|
||||
while(y.t < ys) y[y.t++] = 0;
|
||||
while(--j >= 0) {
|
||||
// Estimate quotient digit
|
||||
var qd = (r[--i]==y0)?this.DM:Math.floor(r[i]*d1+(r[i-1]+e)*d2);
|
||||
if((r[i]+=y.am(0,qd,r,j,0,ys)) < qd) { // Try it out
|
||||
y.dlShiftTo(j,t);
|
||||
r.subTo(t,r);
|
||||
while(r[i] < --qd) r.subTo(t,r);
|
||||
}
|
||||
}
|
||||
if(q != null) {
|
||||
r.drShiftTo(ys,q);
|
||||
if(ts != ms) BigInteger.ZERO.subTo(q,q);
|
||||
}
|
||||
r.t = ys;
|
||||
r.clamp();
|
||||
if(nsh > 0) r.rShiftTo(nsh,r); // Denormalize remainder
|
||||
if(ts < 0) BigInteger.ZERO.subTo(r,r);
|
||||
}
|
||||
|
||||
// (public) this mod a
|
||||
function bnMod(a) {
|
||||
var r = nbi();
|
||||
this.abs().divRemTo(a,null,r);
|
||||
if(this.s < 0 && r.compareTo(BigInteger.ZERO) > 0) a.subTo(r,r);
|
||||
return r;
|
||||
}
|
||||
|
||||
// Modular reduction using "classic" algorithm
|
||||
function Classic(m) { this.m = m; }
|
||||
function cConvert(x) {
|
||||
if(x.s < 0 || x.compareTo(this.m) >= 0) return x.mod(this.m);
|
||||
else return x;
|
||||
}
|
||||
function cRevert(x) { return x; }
|
||||
function cReduce(x) { x.divRemTo(this.m,null,x); }
|
||||
function cMulTo(x,y,r) { x.multiplyTo(y,r); this.reduce(r); }
|
||||
function cSqrTo(x,r) { x.squareTo(r); this.reduce(r); }
|
||||
|
||||
Classic.prototype.convert = cConvert;
|
||||
Classic.prototype.revert = cRevert;
|
||||
Classic.prototype.reduce = cReduce;
|
||||
Classic.prototype.mulTo = cMulTo;
|
||||
Classic.prototype.sqrTo = cSqrTo;
|
||||
|
||||
// (protected) return "-1/this % 2^DB"; useful for Mont. reduction
|
||||
// justification:
|
||||
// xy == 1 (mod m)
|
||||
// xy = 1+km
|
||||
// xy(2-xy) = (1+km)(1-km)
|
||||
// x[y(2-xy)] = 1-k^2m^2
|
||||
// x[y(2-xy)] == 1 (mod m^2)
|
||||
// if y is 1/x mod m, then y(2-xy) is 1/x mod m^2
|
||||
// should reduce x and y(2-xy) by m^2 at each step to keep size bounded.
|
||||
// JS multiply "overflows" differently from C/C++, so care is needed here.
|
||||
function bnpInvDigit() {
|
||||
if(this.t < 1) return 0;
|
||||
var x = this[0];
|
||||
if((x&1) == 0) return 0;
|
||||
var y = x&3; // y == 1/x mod 2^2
|
||||
y = (y*(2-(x&0xf)*y))&0xf; // y == 1/x mod 2^4
|
||||
y = (y*(2-(x&0xff)*y))&0xff; // y == 1/x mod 2^8
|
||||
y = (y*(2-(((x&0xffff)*y)&0xffff)))&0xffff; // y == 1/x mod 2^16
|
||||
// last step - calculate inverse mod DV directly;
|
||||
// assumes 16 < DB <= 32 and assumes ability to handle 48-bit ints
|
||||
y = (y*(2-x*y%this.DV))%this.DV; // y == 1/x mod 2^dbits
|
||||
// we really want the negative inverse, and -DV < y < DV
|
||||
return (y>0)?this.DV-y:-y;
|
||||
}
|
||||
|
||||
// Montgomery reduction
|
||||
function Montgomery(m) {
|
||||
this.m = m;
|
||||
this.mp = m.invDigit();
|
||||
this.mpl = this.mp&0x7fff;
|
||||
this.mph = this.mp>>15;
|
||||
this.um = (1<<(m.DB-15))-1;
|
||||
this.mt2 = 2*m.t;
|
||||
}
|
||||
|
||||
// xR mod m
|
||||
function montConvert(x) {
|
||||
var r = nbi();
|
||||
x.abs().dlShiftTo(this.m.t,r);
|
||||
r.divRemTo(this.m,null,r);
|
||||
if(x.s < 0 && r.compareTo(BigInteger.ZERO) > 0) this.m.subTo(r,r);
|
||||
return r;
|
||||
}
|
||||
|
||||
// x/R mod m
|
||||
function montRevert(x) {
|
||||
var r = nbi();
|
||||
x.copyTo(r);
|
||||
this.reduce(r);
|
||||
return r;
|
||||
}
|
||||
|
||||
// x = x/R mod m (HAC 14.32)
|
||||
function montReduce(x) {
|
||||
while(x.t <= this.mt2) // pad x so am has enough room later
|
||||
x[x.t++] = 0;
|
||||
for(var i = 0; i < this.m.t; ++i) {
|
||||
// faster way of calculating u0 = x[i]*mp mod DV
|
||||
var j = x[i]&0x7fff;
|
||||
var u0 = (j*this.mpl+(((j*this.mph+(x[i]>>15)*this.mpl)&this.um)<<15))&x.DM;
|
||||
// use am to combine the multiply-shift-add into one call
|
||||
j = i+this.m.t;
|
||||
x[j] += this.m.am(0,u0,x,i,0,this.m.t);
|
||||
// propagate carry
|
||||
while(x[j] >= x.DV) { x[j] -= x.DV; x[++j]++; }
|
||||
}
|
||||
x.clamp();
|
||||
x.drShiftTo(this.m.t,x);
|
||||
if(x.compareTo(this.m) >= 0) x.subTo(this.m,x);
|
||||
}
|
||||
|
||||
// r = "x^2/R mod m"; x != r
|
||||
function montSqrTo(x,r) { x.squareTo(r); this.reduce(r); }
|
||||
|
||||
// r = "xy/R mod m"; x,y != r
|
||||
function montMulTo(x,y,r) { x.multiplyTo(y,r); this.reduce(r); }
|
||||
|
||||
Montgomery.prototype.convert = montConvert;
|
||||
Montgomery.prototype.revert = montRevert;
|
||||
Montgomery.prototype.reduce = montReduce;
|
||||
Montgomery.prototype.mulTo = montMulTo;
|
||||
Montgomery.prototype.sqrTo = montSqrTo;
|
||||
|
||||
// (protected) true iff this is even
|
||||
function bnpIsEven() { return ((this.t>0)?(this[0]&1):this.s) == 0; }
|
||||
|
||||
// (protected) this^e, e < 2^32, doing sqr and mul with "r" (HAC 14.79)
|
||||
function bnpExp(e,z) {
|
||||
if(e > 0xffffffff || e < 1) return BigInteger.ONE;
|
||||
var r = nbi(), r2 = nbi(), g = z.convert(this), i = nbits(e)-1;
|
||||
g.copyTo(r);
|
||||
while(--i >= 0) {
|
||||
z.sqrTo(r,r2);
|
||||
if((e&(1<<i)) > 0) z.mulTo(r2,g,r);
|
||||
else { var t = r; r = r2; r2 = t; }
|
||||
}
|
||||
return z.revert(r);
|
||||
}
|
||||
|
||||
// (public) this^e % m, 0 <= e < 2^32
|
||||
function bnModPowInt(e,m) {
|
||||
var z;
|
||||
if(e < 256 || m.isEven()) z = new Classic(m); else z = new Montgomery(m);
|
||||
return this.exp(e,z);
|
||||
}
|
||||
|
||||
// protected
|
||||
BigInteger.prototype.copyTo = bnpCopyTo;
|
||||
BigInteger.prototype.fromInt = bnpFromInt;
|
||||
BigInteger.prototype.fromString = bnpFromString;
|
||||
BigInteger.prototype.clamp = bnpClamp;
|
||||
BigInteger.prototype.dlShiftTo = bnpDLShiftTo;
|
||||
BigInteger.prototype.drShiftTo = bnpDRShiftTo;
|
||||
BigInteger.prototype.lShiftTo = bnpLShiftTo;
|
||||
BigInteger.prototype.rShiftTo = bnpRShiftTo;
|
||||
BigInteger.prototype.subTo = bnpSubTo;
|
||||
BigInteger.prototype.multiplyTo = bnpMultiplyTo;
|
||||
BigInteger.prototype.squareTo = bnpSquareTo;
|
||||
BigInteger.prototype.divRemTo = bnpDivRemTo;
|
||||
BigInteger.prototype.invDigit = bnpInvDigit;
|
||||
BigInteger.prototype.isEven = bnpIsEven;
|
||||
BigInteger.prototype.exp = bnpExp;
|
||||
|
||||
// public
|
||||
BigInteger.prototype.toString = bnToString;
|
||||
BigInteger.prototype.negate = bnNegate;
|
||||
BigInteger.prototype.abs = bnAbs;
|
||||
BigInteger.prototype.compareTo = bnCompareTo;
|
||||
BigInteger.prototype.bitLength = bnBitLength;
|
||||
BigInteger.prototype.mod = bnMod;
|
||||
BigInteger.prototype.modPowInt = bnModPowInt;
|
||||
|
||||
// "constants"
|
||||
BigInteger.ZERO = nbv(0);
|
||||
BigInteger.ONE = nbv(1);
|
@ -1,653 +0,0 @@
|
||||
// Copyright (c) 2005-2009 Tom Wu
|
||||
// All Rights Reserved.
|
||||
// See "LICENSE" for details.
|
||||
// Extended JavaScript BN functions, required for RSA private ops.
|
||||
// Version 1.1: new BigInteger("0", 10) returns "proper" zero
|
||||
// Version 1.2: square() API, isProbablePrime fix
|
||||
|
||||
// (public)
|
||||
function bnClone() { var r = nbi(); this.copyTo(r); return r; }
|
||||
// (public) return value as integer
|
||||
function bnIntValue() {
|
||||
if(this.s < 0) {
|
||||
if(this.t == 1) return this[0]-this.DV;
|
||||
else if(this.t == 0) return -1;
|
||||
}
|
||||
else if(this.t == 1) return this[0];
|
||||
else if(this.t == 0) return 0;
|
||||
// assumes 16 < DB < 32
|
||||
return ((this[1]&((1<<(32-this.DB))-1))<<this.DB)|this[0];
|
||||
}
|
||||
|
||||
// (public) return value as byte
|
||||
function bnByteValue() { return (this.t==0)?this.s:(this[0]<<24)>>24; }
|
||||
|
||||
// (public) return value as short (assumes DB>=16)
|
||||
function bnShortValue() { return (this.t==0)?this.s:(this[0]<<16)>>16; }
|
||||
|
||||
// (protected) return x s.t. r^x < DV
|
||||
function bnpChunkSize(r) { return Math.floor(Math.LN2*this.DB/Math.log(r)); }
|
||||
|
||||
// (public) 0 if this == 0, 1 if this > 0
|
||||
function bnSigNum() {
|
||||
if(this.s < 0) return -1;
|
||||
else if(this.t <= 0 || (this.t == 1 && this[0] <= 0)) return 0;
|
||||
else return 1;
|
||||
}
|
||||
|
||||
// (protected) convert to radix string
|
||||
function bnpToRadix(b) {
|
||||
if(b == null) b = 10;
|
||||
if(this.signum() == 0 || b < 2 || b > 36) return "0";
|
||||
var cs = this.chunkSize(b);
|
||||
var a = Math.pow(b,cs);
|
||||
var d = nbv(a), y = nbi(), z = nbi(), r = "";
|
||||
this.divRemTo(d,y,z);
|
||||
while(y.signum() > 0) {
|
||||
r = (a+z.intValue()).toString(b).substr(1) + r;
|
||||
y.divRemTo(d,y,z);
|
||||
}
|
||||
return z.intValue().toString(b) + r;
|
||||
}
|
||||
|
||||
// (protected) convert from radix string
|
||||
function bnpFromRadix(s,b) {
|
||||
this.fromInt(0);
|
||||
if(b == null) b = 10;
|
||||
var cs = this.chunkSize(b);
|
||||
var d = Math.pow(b,cs), mi = false, j = 0, w = 0;
|
||||
for(var i = 0; i < s.length; ++i) {
|
||||
var x = intAt(s,i);
|
||||
if(x < 0) {
|
||||
if(s.charAt(i) == "-" && this.signum() == 0) mi = true;
|
||||
continue;
|
||||
}
|
||||
w = b*w+x;
|
||||
if(++j >= cs) {
|
||||
this.dMultiply(d);
|
||||
this.dAddOffset(w,0);
|
||||
j = 0;
|
||||
w = 0;
|
||||
}
|
||||
}
|
||||
if(j > 0) {
|
||||
this.dMultiply(Math.pow(b,j));
|
||||
this.dAddOffset(w,0);
|
||||
}
|
||||
if(mi) BigInteger.ZERO.subTo(this,this);
|
||||
}
|
||||
|
||||
// (protected) alternate constructor
|
||||
function bnpFromNumber(a,b,c) {
|
||||
if("number" == typeof b) {
|
||||
// new BigInteger(int,int,RNG)
|
||||
if(a < 2) this.fromInt(1);
|
||||
else {
|
||||
this.fromNumber(a,c);
|
||||
if(!this.testBit(a-1)) // force MSB set
|
||||
this.bitwiseTo(BigInteger.ONE.shiftLeft(a-1),op_or,this);
|
||||
if(this.isEven()) this.dAddOffset(1,0); // force odd
|
||||
while(!this.isProbablePrime(b)) {
|
||||
this.dAddOffset(2,0);
|
||||
if(this.bitLength() > a) this.subTo(BigInteger.ONE.shiftLeft(a-1),this);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
// new BigInteger(int,RNG)
|
||||
var x = new Array(), t = a&7;
|
||||
x.length = (a>>3)+1;
|
||||
b.nextBytes(x);
|
||||
if(t > 0) x[0] &= ((1<<t)-1); else x[0] = 0;
|
||||
this.fromString(x,256);
|
||||
}
|
||||
}
|
||||
|
||||
// (public) convert to bigendian byte array
|
||||
function bnToByteArray() {
|
||||
var i = this.t, r = new Array();
|
||||
r[0] = this.s;
|
||||
var p = this.DB-(i*this.DB)%8, d, k = 0;
|
||||
if(i-- > 0) {
|
||||
if(p < this.DB && (d = this[i]>>p) != (this.s&this.DM)>>p)
|
||||
r[k++] = d|(this.s<<(this.DB-p));
|
||||
while(i >= 0) {
|
||||
if(p < 8) {
|
||||
d = (this[i]&((1<<p)-1))<<(8-p);
|
||||
d |= this[--i]>>(p+=this.DB-8);
|
||||
}
|
||||
else {
|
||||
d = (this[i]>>(p-=8))&0xff;
|
||||
if(p <= 0) { p += this.DB; --i; }
|
||||
}
|
||||
if((d&0x80) != 0) d |= -256;
|
||||
if(k == 0 && (this.s&0x80) != (d&0x80)) ++k;
|
||||
if(k > 0 || d != this.s) r[k++] = d;
|
||||
}
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
function bnEquals(a) { return(this.compareTo(a)==0); }
|
||||
function bnMin(a) { return(this.compareTo(a)<0)?this:a; }
|
||||
function bnMax(a) { return(this.compareTo(a)>0)?this:a; }
|
||||
|
||||
// (protected) r = this op a (bitwise)
|
||||
function bnpBitwiseTo(a,op,r) {
|
||||
var i, f, m = Math.min(a.t,this.t);
|
||||
for(i = 0; i < m; ++i) r[i] = op(this[i],a[i]);
|
||||
if(a.t < this.t) {
|
||||
f = a.s&this.DM;
|
||||
for(i = m; i < this.t; ++i) r[i] = op(this[i],f);
|
||||
r.t = this.t;
|
||||
}
|
||||
else {
|
||||
f = this.s&this.DM;
|
||||
for(i = m; i < a.t; ++i) r[i] = op(f,a[i]);
|
||||
r.t = a.t;
|
||||
}
|
||||
r.s = op(this.s,a.s);
|
||||
r.clamp();
|
||||
}
|
||||
|
||||
// (public) this & a
|
||||
function op_and(x,y) { return x&y; }
|
||||
function bnAnd(a) { var r = nbi(); this.bitwiseTo(a,op_and,r); return r; }
|
||||
|
||||
// (public) this | a
|
||||
function op_or(x,y) { return x|y; }
|
||||
function bnOr(a) { var r = nbi(); this.bitwiseTo(a,op_or,r); return r; }
|
||||
|
||||
// (public) this ^ a
|
||||
function op_xor(x,y) { return x^y; }
|
||||
function bnXor(a) { var r = nbi(); this.bitwiseTo(a,op_xor,r); return r; }
|
||||
|
||||
// (public) this & ~a
|
||||
function op_andnot(x,y) { return x&~y; }
|
||||
function bnAndNot(a) { var r = nbi(); this.bitwiseTo(a,op_andnot,r); return r; }
|
||||
|
||||
// (public) ~this
|
||||
function bnNot() {
|
||||
var r = nbi();
|
||||
for(var i = 0; i < this.t; ++i) r[i] = this.DM&~this[i];
|
||||
r.t = this.t;
|
||||
r.s = ~this.s;
|
||||
return r;
|
||||
}
|
||||
|
||||
// (public) this << n
|
||||
function bnShiftLeft(n) {
|
||||
var r = nbi();
|
||||
if(n < 0) this.rShiftTo(-n,r); else this.lShiftTo(n,r);
|
||||
return r;
|
||||
}
|
||||
|
||||
// (public) this >> n
|
||||
function bnShiftRight(n) {
|
||||
var r = nbi();
|
||||
if(n < 0) this.lShiftTo(-n,r); else this.rShiftTo(n,r);
|
||||
return r;
|
||||
}
|
||||
|
||||
// return index of lowest 1-bit in x, x < 2^31
|
||||
function lbit(x) {
|
||||
if(x == 0) return -1;
|
||||
var r = 0;
|
||||
if((x&0xffff) == 0) { x >>= 16; r += 16; }
|
||||
if((x&0xff) == 0) { x >>= 8; r += 8; }
|
||||
if((x&0xf) == 0) { x >>= 4; r += 4; }
|
||||
if((x&3) == 0) { x >>= 2; r += 2; }
|
||||
if((x&1) == 0) ++r;
|
||||
return r;
|
||||
}
|
||||
|
||||
// (public) returns index of lowest 1-bit (or -1 if none)
|
||||
function bnGetLowestSetBit() {
|
||||
for(var i = 0; i < this.t; ++i)
|
||||
if(this[i] != 0) return i*this.DB+lbit(this[i]);
|
||||
if(this.s < 0) return this.t*this.DB;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// return number of 1 bits in x
|
||||
function cbit(x) {
|
||||
var r = 0;
|
||||
while(x != 0) { x &= x-1; ++r; }
|
||||
return r;
|
||||
}
|
||||
|
||||
// (public) return number of set bits
|
||||
function bnBitCount() {
|
||||
var r = 0, x = this.s&this.DM;
|
||||
for(var i = 0; i < this.t; ++i) r += cbit(this[i]^x);
|
||||
return r;
|
||||
}
|
||||
|
||||
// (public) true iff nth bit is set
|
||||
function bnTestBit(n) {
|
||||
var j = Math.floor(n/this.DB);
|
||||
if(j >= this.t) return(this.s!=0);
|
||||
return((this[j]&(1<<(n%this.DB)))!=0);
|
||||
}
|
||||
|
||||
// (protected) this op (1<<n)
|
||||
function bnpChangeBit(n,op) {
|
||||
var r = BigInteger.ONE.shiftLeft(n);
|
||||
this.bitwiseTo(r,op,r);
|
||||
return r;
|
||||
}
|
||||
|
||||
// (public) this | (1<<n)
|
||||
function bnSetBit(n) { return this.changeBit(n,op_or); }
|
||||
|
||||
// (public) this & ~(1<<n)
|
||||
function bnClearBit(n) { return this.changeBit(n,op_andnot); }
|
||||
|
||||
// (public) this ^ (1<<n)
|
||||
function bnFlipBit(n) { return this.changeBit(n,op_xor); }
|
||||
|
||||
// (protected) r = this + a
|
||||
function bnpAddTo(a,r) {
|
||||
var i = 0, c = 0, m = Math.min(a.t,this.t);
|
||||
while(i < m) {
|
||||
c += this[i]+a[i];
|
||||
r[i++] = c&this.DM;
|
||||
c >>= this.DB;
|
||||
}
|
||||
if(a.t < this.t) {
|
||||
c += a.s;
|
||||
while(i < this.t) {
|
||||
c += this[i];
|
||||
r[i++] = c&this.DM;
|
||||
c >>= this.DB;
|
||||
}
|
||||
c += this.s;
|
||||
}
|
||||
else {
|
||||
c += this.s;
|
||||
while(i < a.t) {
|
||||
c += a[i];
|
||||
r[i++] = c&this.DM;
|
||||
c >>= this.DB;
|
||||
}
|
||||
c += a.s;
|
||||
}
|
||||
r.s = (c<0)?-1:0;
|
||||
if(c > 0) r[i++] = c;
|
||||
else if(c < -1) r[i++] = this.DV+c;
|
||||
r.t = i;
|
||||
r.clamp();
|
||||
}
|
||||
|
||||
// (public) this + a
|
||||
function bnAdd(a) { var r = nbi(); this.addTo(a,r); return r; }
|
||||
|
||||
// (public) this - a
|
||||
function bnSubtract(a) { var r = nbi(); this.subTo(a,r); return r; }
|
||||
|
||||
// (public) this * a
|
||||
function bnMultiply(a) { var r = nbi(); this.multiplyTo(a,r); return r; }
|
||||
|
||||
// (public) this^2
|
||||
function bnSquare() { var r = nbi(); this.squareTo(r); return r; }
|
||||
|
||||
// (public) this / a
|
||||
function bnDivide(a) { var r = nbi(); this.divRemTo(a,r,null); return r; }
|
||||
|
||||
// (public) this % a
|
||||
function bnRemainder(a) { var r = nbi(); this.divRemTo(a,null,r); return r; }
|
||||
|
||||
// (public) [this/a,this%a]
|
||||
function bnDivideAndRemainder(a) {
|
||||
var q = nbi(), r = nbi();
|
||||
this.divRemTo(a,q,r);
|
||||
return new Array(q,r);
|
||||
}
|
||||
|
||||
// (protected) this *= n, this >= 0, 1 < n < DV
|
||||
function bnpDMultiply(n) {
|
||||
this[this.t] = this.am(0,n-1,this,0,0,this.t);
|
||||
++this.t;
|
||||
this.clamp();
|
||||
}
|
||||
|
||||
// (protected) this += n << w words, this >= 0
|
||||
function bnpDAddOffset(n,w) {
|
||||
if(n == 0) return;
|
||||
while(this.t <= w) this[this.t++] = 0;
|
||||
this[w] += n;
|
||||
while(this[w] >= this.DV) {
|
||||
this[w] -= this.DV;
|
||||
if(++w >= this.t) this[this.t++] = 0;
|
||||
++this[w];
|
||||
}
|
||||
}
|
||||
|
||||
// A "null" reducer
|
||||
function NullExp() {}
|
||||
function nNop(x) { return x; }
|
||||
function nMulTo(x,y,r) { x.multiplyTo(y,r); }
|
||||
function nSqrTo(x,r) { x.squareTo(r); }
|
||||
|
||||
NullExp.prototype.convert = nNop;
|
||||
NullExp.prototype.revert = nNop;
|
||||
NullExp.prototype.mulTo = nMulTo;
|
||||
NullExp.prototype.sqrTo = nSqrTo;
|
||||
|
||||
// (public) this^e
|
||||
function bnPow(e) { return this.exp(e,new NullExp()); }
|
||||
|
||||
// (protected) r = lower n words of "this * a", a.t <= n
|
||||
// "this" should be the larger one if appropriate.
|
||||
function bnpMultiplyLowerTo(a,n,r) {
|
||||
var i = Math.min(this.t+a.t,n);
|
||||
r.s = 0; // assumes a,this >= 0
|
||||
r.t = i;
|
||||
while(i > 0) r[--i] = 0;
|
||||
var j;
|
||||
for(j = r.t-this.t; i < j; ++i) r[i+this.t] = this.am(0,a[i],r,i,0,this.t);
|
||||
for(j = Math.min(a.t,n); i < j; ++i) this.am(0,a[i],r,i,0,n-i);
|
||||
r.clamp();
|
||||
}
|
||||
|
||||
// (protected) r = "this * a" without lower n words, n > 0
|
||||
// "this" should be the larger one if appropriate.
|
||||
function bnpMultiplyUpperTo(a,n,r) {
|
||||
--n;
|
||||
var i = r.t = this.t+a.t-n;
|
||||
r.s = 0; // assumes a,this >= 0
|
||||
while(--i >= 0) r[i] = 0;
|
||||
for(i = Math.max(n-this.t,0); i < a.t; ++i)
|
||||
r[this.t+i-n] = this.am(n-i,a[i],r,0,0,this.t+i-n);
|
||||
r.clamp();
|
||||
r.drShiftTo(1,r);
|
||||
}
|
||||
|
||||
// Barrett modular reduction
|
||||
function Barrett(m) {
|
||||
// setup Barrett
|
||||
this.r2 = nbi();
|
||||
this.q3 = nbi();
|
||||
BigInteger.ONE.dlShiftTo(2*m.t,this.r2);
|
||||
this.mu = this.r2.divide(m);
|
||||
this.m = m;
|
||||
}
|
||||
|
||||
function barrettConvert(x) {
|
||||
if(x.s < 0 || x.t > 2*this.m.t) return x.mod(this.m);
|
||||
else if(x.compareTo(this.m) < 0) return x;
|
||||
else { var r = nbi(); x.copyTo(r); this.reduce(r); return r; }
|
||||
}
|
||||
|
||||
function barrettRevert(x) { return x; }
|
||||
|
||||
// x = x mod m (HAC 14.42)
|
||||
function barrettReduce(x) {
|
||||
x.drShiftTo(this.m.t-1,this.r2);
|
||||
if(x.t > this.m.t+1) { x.t = this.m.t+1; x.clamp(); }
|
||||
this.mu.multiplyUpperTo(this.r2,this.m.t+1,this.q3);
|
||||
this.m.multiplyLowerTo(this.q3,this.m.t+1,this.r2);
|
||||
while(x.compareTo(this.r2) < 0) x.dAddOffset(1,this.m.t+1);
|
||||
x.subTo(this.r2,x);
|
||||
while(x.compareTo(this.m) >= 0) x.subTo(this.m,x);
|
||||
}
|
||||
|
||||
// r = x^2 mod m; x != r
|
||||
function barrettSqrTo(x,r) { x.squareTo(r); this.reduce(r); }
|
||||
|
||||
// r = x*y mod m; x,y != r
|
||||
function barrettMulTo(x,y,r) { x.multiplyTo(y,r); this.reduce(r); }
|
||||
|
||||
Barrett.prototype.convert = barrettConvert;
|
||||
Barrett.prototype.revert = barrettRevert;
|
||||
Barrett.prototype.reduce = barrettReduce;
|
||||
Barrett.prototype.mulTo = barrettMulTo;
|
||||
Barrett.prototype.sqrTo = barrettSqrTo;
|
||||
|
||||
// (public) this^e % m (HAC 14.85)
|
||||
function bnModPow(e,m) {
|
||||
var i = e.bitLength(), k, r = nbv(1), z;
|
||||
if(i <= 0) return r;
|
||||
else if(i < 18) k = 1;
|
||||
else if(i < 48) k = 3;
|
||||
else if(i < 144) k = 4;
|
||||
else if(i < 768) k = 5;
|
||||
else k = 6;
|
||||
if(i < 8)
|
||||
z = new Classic(m);
|
||||
else if(m.isEven())
|
||||
z = new Barrett(m);
|
||||
else
|
||||
z = new Montgomery(m);
|
||||
|
||||
// precomputation
|
||||
var g = new Array(), n = 3, k1 = k-1, km = (1<<k)-1;
|
||||
g[1] = z.convert(this);
|
||||
if(k > 1) {
|
||||
var g2 = nbi();
|
||||
z.sqrTo(g[1],g2);
|
||||
while(n <= km) {
|
||||
g[n] = nbi();
|
||||
z.mulTo(g2,g[n-2],g[n]);
|
||||
n += 2;
|
||||
}
|
||||
}
|
||||
|
||||
var j = e.t-1, w, is1 = true, r2 = nbi(), t;
|
||||
i = nbits(e[j])-1;
|
||||
while(j >= 0) {
|
||||
if(i >= k1) w = (e[j]>>(i-k1))&km;
|
||||
else {
|
||||
w = (e[j]&((1<<(i+1))-1))<<(k1-i);
|
||||
if(j > 0) w |= e[j-1]>>(this.DB+i-k1);
|
||||
}
|
||||
|
||||
n = k;
|
||||
while((w&1) == 0) { w >>= 1; --n; }
|
||||
if((i -= n) < 0) { i += this.DB; --j; }
|
||||
if(is1) { // ret == 1, don't bother squaring or multiplying it
|
||||
g[w].copyTo(r);
|
||||
is1 = false;
|
||||
}
|
||||
else {
|
||||
while(n > 1) { z.sqrTo(r,r2); z.sqrTo(r2,r); n -= 2; }
|
||||
if(n > 0) z.sqrTo(r,r2); else { t = r; r = r2; r2 = t; }
|
||||
z.mulTo(r2,g[w],r);
|
||||
}
|
||||
|
||||
while(j >= 0 && (e[j]&(1<<i)) == 0) {
|
||||
z.sqrTo(r,r2); t = r; r = r2; r2 = t;
|
||||
if(--i < 0) { i = this.DB-1; --j; }
|
||||
}
|
||||
}
|
||||
return z.revert(r);
|
||||
}
|
||||
|
||||
// (public) gcd(this,a) (HAC 14.54)
|
||||
function bnGCD(a) {
|
||||
var x = (this.s<0)?this.negate():this.clone();
|
||||
var y = (a.s<0)?a.negate():a.clone();
|
||||
if(x.compareTo(y) < 0) { var t = x; x = y; y = t; }
|
||||
var i = x.getLowestSetBit(), g = y.getLowestSetBit();
|
||||
if(g < 0) return x;
|
||||
if(i < g) g = i;
|
||||
if(g > 0) {
|
||||
x.rShiftTo(g,x);
|
||||
y.rShiftTo(g,y);
|
||||
}
|
||||
while(x.signum() > 0) {
|
||||
if((i = x.getLowestSetBit()) > 0) x.rShiftTo(i,x);
|
||||
if((i = y.getLowestSetBit()) > 0) y.rShiftTo(i,y);
|
||||
if(x.compareTo(y) >= 0) {
|
||||
x.subTo(y,x);
|
||||
x.rShiftTo(1,x);
|
||||
}
|
||||
else {
|
||||
y.subTo(x,y);
|
||||
y.rShiftTo(1,y);
|
||||
}
|
||||
}
|
||||
if(g > 0) y.lShiftTo(g,y);
|
||||
return y;
|
||||
}
|
||||
|
||||
// (protected) this % n, n < 2^26
|
||||
function bnpModInt(n) {
|
||||
if(n <= 0) return 0;
|
||||
var d = this.DV%n, r = (this.s<0)?n-1:0;
|
||||
if(this.t > 0)
|
||||
if(d == 0) r = this[0]%n;
|
||||
else for(var i = this.t-1; i >= 0; --i) r = (d*r+this[i])%n;
|
||||
return r;
|
||||
}
|
||||
|
||||
// (public) 1/this % m (HAC 14.61)
|
||||
function bnModInverse(m) {
|
||||
var ac = m.isEven();
|
||||
if((this.isEven() && ac) || m.signum() == 0) return BigInteger.ZERO;
|
||||
var u = m.clone(), v = this.clone();
|
||||
var a = nbv(1), b = nbv(0), c = nbv(0), d = nbv(1);
|
||||
while(u.signum() != 0) {
|
||||
while(u.isEven()) {
|
||||
u.rShiftTo(1,u);
|
||||
if(ac) {
|
||||
if(!a.isEven() || !b.isEven()) { a.addTo(this,a); b.subTo(m,b); }
|
||||
a.rShiftTo(1,a);
|
||||
}
|
||||
else if(!b.isEven()) b.subTo(m,b);
|
||||
b.rShiftTo(1,b);
|
||||
}
|
||||
while(v.isEven()) {
|
||||
v.rShiftTo(1,v);
|
||||
if(ac) {
|
||||
if(!c.isEven() || !d.isEven()) { c.addTo(this,c); d.subTo(m,d); }
|
||||
c.rShiftTo(1,c);
|
||||
}
|
||||
else if(!d.isEven()) d.subTo(m,d);
|
||||
d.rShiftTo(1,d);
|
||||
}
|
||||
if(u.compareTo(v) >= 0) {
|
||||
u.subTo(v,u);
|
||||
if(ac) a.subTo(c,a);
|
||||
b.subTo(d,b);
|
||||
}
|
||||
else {
|
||||
v.subTo(u,v);
|
||||
if(ac) c.subTo(a,c);
|
||||
d.subTo(b,d);
|
||||
}
|
||||
}
|
||||
if(v.compareTo(BigInteger.ONE) != 0) return BigInteger.ZERO;
|
||||
if(d.compareTo(m) >= 0) return d.subtract(m);
|
||||
if(d.signum() < 0) d.addTo(m,d); else return d;
|
||||
if(d.signum() < 0) return d.add(m); else return d;
|
||||
}
|
||||
|
||||
var lowprimes = [2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509,521,523,541,547,557,563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659,661,673,677,683,691,701,709,719,727,733,739,743,751,757,761,769,773,787,797,809,811,821,823,827,829,839,853,857,859,863,877,881,883,887,907,911,919,929,937,941,947,953,967,971,977,983,991,997];
|
||||
var lplim = (1<<26)/lowprimes[lowprimes.length-1];
|
||||
|
||||
// (public) test primality with certainty >= 1-.5^t
|
||||
function bnIsProbablePrime(t) {
|
||||
var i, x = this.abs();
|
||||
if(x.t == 1 && x[0] <= lowprimes[lowprimes.length-1]) {
|
||||
for(i = 0; i < lowprimes.length; ++i)
|
||||
if(x[0] == lowprimes[i]) return true;
|
||||
return false;
|
||||
}
|
||||
if(x.isEven()) return false;
|
||||
i = 1;
|
||||
while(i < lowprimes.length) {
|
||||
var m = lowprimes[i], j = i+1;
|
||||
while(j < lowprimes.length && m < lplim) m *= lowprimes[j++];
|
||||
m = x.modInt(m);
|
||||
while(i < j) if(m%lowprimes[i++] == 0) return false;
|
||||
}
|
||||
return x.millerRabin(t);
|
||||
}
|
||||
|
||||
// (protected) true if probably prime (HAC 4.24, Miller-Rabin)
|
||||
function bnpMillerRabin(t) {
|
||||
var n1 = this.subtract(BigInteger.ONE);
|
||||
var k = n1.getLowestSetBit();
|
||||
if(k <= 0) return false;
|
||||
var r = n1.shiftRight(k);
|
||||
t = (t+1)>>1;
|
||||
if(t > lowprimes.length) t = lowprimes.length;
|
||||
var a = nbi();
|
||||
for(var i = 0; i < t; ++i) {
|
||||
//Pick bases at random, instead of starting at 2
|
||||
a.fromInt(lowprimes[Math.floor(Math.random()*lowprimes.length)]);
|
||||
var y = a.modPow(r,this);
|
||||
if(y.compareTo(BigInteger.ONE) != 0 && y.compareTo(n1) != 0) {
|
||||
var j = 1;
|
||||
while(j++ < k && y.compareTo(n1) != 0) {
|
||||
y = y.modPowInt(2,this);
|
||||
if(y.compareTo(BigInteger.ONE) == 0) return false;
|
||||
}
|
||||
if(y.compareTo(n1) != 0) return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// protected
|
||||
BigInteger.prototype.chunkSize = bnpChunkSize;
|
||||
BigInteger.prototype.toRadix = bnpToRadix;
|
||||
BigInteger.prototype.fromRadix = bnpFromRadix;
|
||||
BigInteger.prototype.fromNumber = bnpFromNumber;
|
||||
BigInteger.prototype.bitwiseTo = bnpBitwiseTo;
|
||||
BigInteger.prototype.changeBit = bnpChangeBit;
|
||||
BigInteger.prototype.addTo = bnpAddTo;
|
||||
BigInteger.prototype.dMultiply = bnpDMultiply;
|
||||
BigInteger.prototype.dAddOffset = bnpDAddOffset;
|
||||
BigInteger.prototype.multiplyLowerTo = bnpMultiplyLowerTo;
|
||||
BigInteger.prototype.multiplyUpperTo = bnpMultiplyUpperTo;
|
||||
BigInteger.prototype.modInt = bnpModInt;
|
||||
BigInteger.prototype.millerRabin = bnpMillerRabin;
|
||||
|
||||
// public
|
||||
BigInteger.prototype.clone = bnClone;
|
||||
BigInteger.prototype.intValue = bnIntValue;
|
||||
BigInteger.prototype.byteValue = bnByteValue;
|
||||
BigInteger.prototype.shortValue = bnShortValue;
|
||||
BigInteger.prototype.signum = bnSigNum;
|
||||
BigInteger.prototype.toByteArray = bnToByteArray;
|
||||
BigInteger.prototype.equals = bnEquals;
|
||||
BigInteger.prototype.min = bnMin;
|
||||
BigInteger.prototype.max = bnMax;
|
||||
BigInteger.prototype.and = bnAnd;
|
||||
BigInteger.prototype.or = bnOr;
|
||||
BigInteger.prototype.xor = bnXor;
|
||||
BigInteger.prototype.andNot = bnAndNot;
|
||||
BigInteger.prototype.not = bnNot;
|
||||
BigInteger.prototype.shiftLeft = bnShiftLeft;
|
||||
BigInteger.prototype.shiftRight = bnShiftRight;
|
||||
BigInteger.prototype.getLowestSetBit = bnGetLowestSetBit;
|
||||
BigInteger.prototype.bitCount = bnBitCount;
|
||||
BigInteger.prototype.testBit = bnTestBit;
|
||||
BigInteger.prototype.setBit = bnSetBit;
|
||||
BigInteger.prototype.clearBit = bnClearBit;
|
||||
BigInteger.prototype.flipBit = bnFlipBit;
|
||||
BigInteger.prototype.add = bnAdd;
|
||||
BigInteger.prototype.subtract = bnSubtract;
|
||||
BigInteger.prototype.multiply = bnMultiply;
|
||||
BigInteger.prototype.divide = bnDivide;
|
||||
BigInteger.prototype.remainder = bnRemainder;
|
||||
BigInteger.prototype.divideAndRemainder = bnDivideAndRemainder;
|
||||
BigInteger.prototype.modPow = bnModPow;
|
||||
BigInteger.prototype.modInverse = bnModInverse;
|
||||
BigInteger.prototype.pow = bnPow;
|
||||
BigInteger.prototype.gcd = bnGCD;
|
||||
BigInteger.prototype.isProbablePrime = bnIsProbablePrime;
|
||||
|
||||
// JSBN-specific extension
|
||||
BigInteger.prototype.square = bnSquare;
|
||||
|
||||
// BigInteger interfaces not implemented in jsbn:
|
||||
|
||||
// BigInteger(int signum, byte[] magnitude)
|
||||
// double doubleValue()
|
||||
// float floatValue()
|
||||
// int hashCode()
|
||||
// long longValue()
|
||||
// static BigInteger valueOf(long val)
|
@ -1,43 +0,0 @@
|
||||
// prng4.js - uses Arcfour as a PRNG
|
||||
function Arcfour() {
|
||||
this.i = 0;
|
||||
this.j = 0;
|
||||
this.S = new Array();
|
||||
}
|
||||
// Initialize arcfour context from key, an array of ints, each from [0..255]
|
||||
function ARC4init(key) {
|
||||
var i, j, t;
|
||||
for(i = 0; i < 256; ++i)
|
||||
this.S[i] = i;
|
||||
j = 0;
|
||||
for(i = 0; i < 256; ++i) {
|
||||
j = (j + this.S[i] + key[i % key.length]) & 255;
|
||||
t = this.S[i];
|
||||
this.S[i] = this.S[j];
|
||||
this.S[j] = t;
|
||||
}
|
||||
this.i = 0;
|
||||
this.j = 0;
|
||||
}
|
||||
|
||||
function ARC4next() {
|
||||
var t;
|
||||
this.i = (this.i + 1) & 255;
|
||||
this.j = (this.j + this.S[this.i]) & 255;
|
||||
t = this.S[this.i];
|
||||
this.S[this.i] = this.S[this.j];
|
||||
this.S[this.j] = t;
|
||||
return this.S[(t + this.S[this.i]) & 255];
|
||||
}
|
||||
|
||||
Arcfour.prototype.init = ARC4init;
|
||||
Arcfour.prototype.next = ARC4next;
|
||||
|
||||
// Plug in your RNG constructor here
|
||||
function prng_newstate() {
|
||||
return new Arcfour();
|
||||
}
|
||||
|
||||
// Pool size must be a multiple of 4 and greater than 32.
|
||||
// An array of bytes the size of the pool will be passed to init()
|
||||
var rng_psize = 256;
|
@ -1,76 +0,0 @@
|
||||
// Random number generator - requires a PRNG backend, e.g. prng4.js
|
||||
// For best results, put code like
|
||||
// <body onClick='rng_seed_time();' onKeyPress='rng_seed_time();'>
|
||||
// in your main HTML document.
|
||||
|
||||
var rng_state;
|
||||
var rng_pool;
|
||||
var rng_pptr;
|
||||
|
||||
// Mix in a 32-bit integer into the pool
|
||||
function rng_seed_int(x) {
|
||||
rng_pool[rng_pptr++] ^= x & 255;
|
||||
rng_pool[rng_pptr++] ^= x >> 8 & 255;
|
||||
// rng_pool[rng_pptr++] ^= x >> 16 & 255;
|
||||
// rng_pool[rng_pptr++] ^= x >> 24 & 255;
|
||||
if (rng_pptr >= rng_psize)
|
||||
rng_pptr -= rng_psize;
|
||||
}
|
||||
|
||||
// Mix in the current time (w/milliseconds) into the pool
|
||||
function rng_seed_time() {
|
||||
rng_seed_int(new Date().getTime());
|
||||
}
|
||||
|
||||
// Initialize the pool with junk if needed.
|
||||
if (rng_pool == null) {
|
||||
rng_pool = new Array();
|
||||
rng_pptr = 0;
|
||||
var t;
|
||||
if (window.crypto && window.crypto.getRandomValues) {
|
||||
// Use webcrypto if available
|
||||
var ua = new Uint8Array(32);
|
||||
window.crypto.getRandomValues(ua);
|
||||
for (t = 0; t < 32; ++t)
|
||||
rng_pool[rng_pptr++] = ua[t];
|
||||
}
|
||||
if (navigator.appName == 'Netscape' && navigator.appVersion < '5' && window.crypto) {
|
||||
// Extract entropy (256 bits) from NS4 RNG if available
|
||||
var z = window.crypto.random(32);
|
||||
for (t = 0; t < z.length; ++t)
|
||||
rng_pool[rng_pptr++] = z.charCodeAt(t) & 255;
|
||||
}
|
||||
while (rng_pptr < rng_psize) {
|
||||
// extract some randomness from Math.random()
|
||||
t = Math.floor(65536 * Math.random());
|
||||
rng_pool[rng_pptr++] = t >>> 8;
|
||||
rng_pool[rng_pptr++] = t & 255;
|
||||
}
|
||||
rng_pptr = 0;
|
||||
rng_seed_time();
|
||||
//rng_seed_int(window.screenX);
|
||||
//rng_seed_int(window.screenY);
|
||||
}
|
||||
|
||||
function rng_get_byte() {
|
||||
if (rng_state == null) {
|
||||
rng_seed_time();
|
||||
rng_state = prng_newstate();
|
||||
rng_state.init(rng_pool);
|
||||
for (rng_pptr = 0; rng_pptr < rng_pool.length; ++rng_pptr)
|
||||
rng_pool[rng_pptr] = 0;
|
||||
rng_pptr = 0;
|
||||
//rng_pool = null;
|
||||
}
|
||||
// TODO: allow reseeding after first request
|
||||
return rng_state.next();
|
||||
}
|
||||
|
||||
function rng_get_bytes(ba) {
|
||||
var i;
|
||||
for (i = 0; i < ba.length; ++i)
|
||||
ba[i] = rng_get_byte();
|
||||
}
|
||||
|
||||
function SecureRandom() {}
|
||||
SecureRandom.prototype.nextBytes = rng_get_bytes;
|
@ -1,109 +0,0 @@
|
||||
// Depends on jsbn.js and rng.js
|
||||
// Version 1.1: support utf-8 encoding in pkcs1pad2
|
||||
// convert a (hex) string to a bignum object
|
||||
function parseBigInt(str,r) {
|
||||
return new BigInteger(str,r);
|
||||
}
|
||||
function linebrk(s,n) {
|
||||
var ret = "";
|
||||
var i = 0;
|
||||
while(i + n < s.length) {
|
||||
ret += s.substring(i,i+n) + "\n";
|
||||
i += n;
|
||||
}
|
||||
return ret + s.substring(i,s.length);
|
||||
}
|
||||
|
||||
function byte2Hex(b) {
|
||||
if(b < 0x10)
|
||||
return "0" + b.toString(16);
|
||||
else
|
||||
return b.toString(16);
|
||||
}
|
||||
|
||||
// PKCS#1 (type 2, random) pad input string s to n bytes, and return a bigint
|
||||
function pkcs1pad2(s,n) {
|
||||
if(n < s.length + 11) { // TODO: fix for utf-8
|
||||
alert("Message too long for RSA");
|
||||
return null;
|
||||
}
|
||||
var ba = new Array();
|
||||
var i = s.length - 1;
|
||||
while(i >= 0 && n > 0) {
|
||||
var c = s.charCodeAt(i--);
|
||||
if(c < 128) { // encode using utf-8
|
||||
ba[--n] = c;
|
||||
}
|
||||
else if((c > 127) && (c < 2048)) {
|
||||
ba[--n] = (c & 63) | 128;
|
||||
ba[--n] = (c >> 6) | 192;
|
||||
}
|
||||
else {
|
||||
ba[--n] = (c & 63) | 128;
|
||||
ba[--n] = ((c >> 6) & 63) | 128;
|
||||
ba[--n] = (c >> 12) | 224;
|
||||
}
|
||||
}
|
||||
ba[--n] = 0;
|
||||
var rng = new SecureRandom();
|
||||
var x = new Array();
|
||||
while(n > 2) { // random non-zero pad
|
||||
x[0] = 0;
|
||||
while(x[0] == 0) rng.nextBytes(x);
|
||||
ba[--n] = x[0];
|
||||
}
|
||||
ba[--n] = 2;
|
||||
ba[--n] = 0;
|
||||
return new BigInteger(ba);
|
||||
}
|
||||
|
||||
// "empty" RSA key constructor
|
||||
function RSAKey() {
|
||||
this.n = null;
|
||||
this.e = 0;
|
||||
this.d = null;
|
||||
this.p = null;
|
||||
this.q = null;
|
||||
this.dmp1 = null;
|
||||
this.dmq1 = null;
|
||||
this.coeff = null;
|
||||
}
|
||||
|
||||
// Set the public key fields N and e from hex strings
|
||||
function RSASetPublic(N,E) {
|
||||
if(N != null && E != null && N.length > 0 && E.length > 0) {
|
||||
this.n = parseBigInt(N,16);
|
||||
this.e = parseInt(E,16);
|
||||
}
|
||||
// else
|
||||
// alert("Invalid RSA public key");
|
||||
}
|
||||
|
||||
// Perform raw public operation on "x": return x^e (mod n)
|
||||
function RSADoPublic(x) {
|
||||
return x.modPowInt(this.e, this.n);
|
||||
}
|
||||
|
||||
// Return the PKCS#1 RSA encryption of "text" as an even-length hex string
|
||||
function RSAEncrypt(text) {
|
||||
var m = pkcs1pad2(text,(this.n.bitLength()+7)>>3);
|
||||
if(m == null) return null;
|
||||
var c = this.doPublic(m);
|
||||
if(c == null) return null;
|
||||
var h = c.toString(16);
|
||||
if((h.length & 1) == 0) return h; else return "0" + h;
|
||||
}
|
||||
|
||||
// Return the PKCS#1 RSA encryption of "text" as a Base64-encoded string
|
||||
//function RSAEncryptB64(text) {
|
||||
// var h = this.encrypt(text);
|
||||
// if(h) return hex2b64(h); else return null;
|
||||
//}
|
||||
|
||||
// protected
|
||||
RSAKey.prototype.doPublic = RSADoPublic;
|
||||
|
||||
// public
|
||||
RSAKey.prototype.setPublic = RSASetPublic;
|
||||
RSAKey.prototype.encrypt = RSAEncrypt;
|
||||
//RSAKey.prototype.encrypt_b64 = RSAEncryptB64;
|
@ -1,139 +0,0 @@
|
||||
// Named EC curves
|
||||
// Requires ec.js, jsbn.js, and jsbn2.js
|
||||
// ----------------
|
||||
// X9ECParameters
|
||||
// constructor
|
||||
function X9ECParameters(curve,g,n,h) {
|
||||
this.curve = curve;
|
||||
this.g = g;
|
||||
this.n = n;
|
||||
this.h = h;
|
||||
}
|
||||
function x9getCurve() {
|
||||
return this.curve;
|
||||
}
|
||||
function x9getG() {
|
||||
return this.g;
|
||||
}
|
||||
function x9getN() {
|
||||
return this.n;
|
||||
}
|
||||
function x9getH() {
|
||||
return this.h;
|
||||
}
|
||||
X9ECParameters.prototype.getCurve = x9getCurve;
|
||||
X9ECParameters.prototype.getG = x9getG;
|
||||
X9ECParameters.prototype.getN = x9getN;
|
||||
X9ECParameters.prototype.getH = x9getH;
|
||||
// ----------------
|
||||
// SECNamedCurves
|
||||
function fromHex(s) { return new BigInteger(s, 16); }
|
||||
function secp128r1() {
|
||||
// p = 2^128 - 2^97 - 1
|
||||
var p = fromHex("FFFFFFFDFFFFFFFFFFFFFFFFFFFFFFFF");
|
||||
var a = fromHex("FFFFFFFDFFFFFFFFFFFFFFFFFFFFFFFC");
|
||||
var b = fromHex("E87579C11079F43DD824993C2CEE5ED3");
|
||||
//byte[] S = Hex.decode("000E0D4D696E6768756151750CC03A4473D03679");
|
||||
var n = fromHex("FFFFFFFE0000000075A30D1B9038A115");
|
||||
var h = BigInteger.ONE;
|
||||
var curve = new ECCurveFp(p, a, b);
|
||||
var G = curve.decodePointHex("04"
|
||||
+ "161FF7528B899B2D0C28607CA52C5B86"
|
||||
+ "CF5AC8395BAFEB13C02DA292DDED7A83");
|
||||
return new X9ECParameters(curve, G, n, h);
|
||||
}
|
||||
function secp160k1() {
|
||||
// p = 2^160 - 2^32 - 2^14 - 2^12 - 2^9 - 2^8 - 2^7 - 2^3 - 2^2 - 1
|
||||
var p = fromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFAC73");
|
||||
var a = BigInteger.ZERO;
|
||||
var b = fromHex("7");
|
||||
//byte[] S = null;
|
||||
var n = fromHex("0100000000000000000001B8FA16DFAB9ACA16B6B3");
|
||||
var h = BigInteger.ONE;
|
||||
var curve = new ECCurveFp(p, a, b);
|
||||
var G = curve.decodePointHex("04"
|
||||
+ "3B4C382CE37AA192A4019E763036F4F5DD4D7EBB"
|
||||
+ "938CF935318FDCED6BC28286531733C3F03C4FEE");
|
||||
return new X9ECParameters(curve, G, n, h);
|
||||
}
|
||||
function secp160r1() {
|
||||
// p = 2^160 - 2^31 - 1
|
||||
var p = fromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF7FFFFFFF");
|
||||
var a = fromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF7FFFFFFC");
|
||||
var b = fromHex("1C97BEFC54BD7A8B65ACF89F81D4D4ADC565FA45");
|
||||
//byte[] S = Hex.decode("1053CDE42C14D696E67687561517533BF3F83345");
|
||||
var n = fromHex("0100000000000000000001F4C8F927AED3CA752257");
|
||||
var h = BigInteger.ONE;
|
||||
var curve = new ECCurveFp(p, a, b);
|
||||
var G = curve.decodePointHex("04"
|
||||
+ "4A96B5688EF573284664698968C38BB913CBFC82"
|
||||
+ "23A628553168947D59DCC912042351377AC5FB32");
|
||||
return new X9ECParameters(curve, G, n, h);
|
||||
}
|
||||
function secp192k1() {
|
||||
// p = 2^192 - 2^32 - 2^12 - 2^8 - 2^7 - 2^6 - 2^3 - 1
|
||||
var p = fromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFEE37");
|
||||
var a = BigInteger.ZERO;
|
||||
var b = fromHex("3");
|
||||
//byte[] S = null;
|
||||
var n = fromHex("FFFFFFFFFFFFFFFFFFFFFFFE26F2FC170F69466A74DEFD8D");
|
||||
var h = BigInteger.ONE;
|
||||
var curve = new ECCurveFp(p, a, b);
|
||||
var G = curve.decodePointHex("04"
|
||||
+ "DB4FF10EC057E9AE26B07D0280B7F4341DA5D1B1EAE06C7D"
|
||||
+ "9B2F2F6D9C5628A7844163D015BE86344082AA88D95E2F9D");
|
||||
return new X9ECParameters(curve, G, n, h);
|
||||
}
|
||||
function secp192r1() {
|
||||
// p = 2^192 - 2^64 - 1
|
||||
var p = fromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFF");
|
||||
var a = fromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFC");
|
||||
var b = fromHex("64210519E59C80E70FA7E9AB72243049FEB8DEECC146B9B1");
|
||||
//byte[] S = Hex.decode("3045AE6FC8422F64ED579528D38120EAE12196D5");
|
||||
var n = fromHex("FFFFFFFFFFFFFFFFFFFFFFFF99DEF836146BC9B1B4D22831");
|
||||
var h = BigInteger.ONE;
|
||||
var curve = new ECCurveFp(p, a, b);
|
||||
var G = curve.decodePointHex("04"
|
||||
+ "188DA80EB03090F67CBF20EB43A18800F4FF0AFD82FF1012"
|
||||
+ "07192B95FFC8DA78631011ED6B24CDD573F977A11E794811");
|
||||
return new X9ECParameters(curve, G, n, h);
|
||||
}
|
||||
function secp224r1() {
|
||||
// p = 2^224 - 2^96 + 1
|
||||
var p = fromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF000000000000000000000001");
|
||||
var a = fromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFE");
|
||||
var b = fromHex("B4050A850C04B3ABF54132565044B0B7D7BFD8BA270B39432355FFB4");
|
||||
//byte[] S = Hex.decode("BD71344799D5C7FCDC45B59FA3B9AB8F6A948BC5");
|
||||
var n = fromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFF16A2E0B8F03E13DD29455C5C2A3D");
|
||||
var h = BigInteger.ONE;
|
||||
var curve = new ECCurveFp(p, a, b);
|
||||
var G = curve.decodePointHex("04"
|
||||
+ "B70E0CBD6BB4BF7F321390B94A03C1D356C21122343280D6115C1D21"
|
||||
+ "BD376388B5F723FB4C22DFE6CD4375A05A07476444D5819985007E34");
|
||||
return new X9ECParameters(curve, G, n, h);
|
||||
}
|
||||
function secp256r1() {
|
||||
// p = 2^224 (2^32 - 1) + 2^192 + 2^96 - 1
|
||||
var p = fromHex("FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFF");
|
||||
var a = fromHex("FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFC");
|
||||
var b = fromHex("5AC635D8AA3A93E7B3EBBD55769886BC651D06B0CC53B0F63BCE3C3E27D2604B");
|
||||
//byte[] S = Hex.decode("C49D360886E704936A6678E1139D26B7819F7E90");
|
||||
var n = fromHex("FFFFFFFF00000000FFFFFFFFFFFFFFFFBCE6FAADA7179E84F3B9CAC2FC632551");
|
||||
var h = BigInteger.ONE;
|
||||
var curve = new ECCurveFp(p, a, b);
|
||||
var G = curve.decodePointHex("04"
|
||||
+ "6B17D1F2E12C4247F8BCE6E563A440F277037D812DEB33A0F4A13945D898C296"
|
||||
+ "4FE342E2FE1A7F9B8EE7EB4A7C0F9E162BCE33576B315ECECBB6406837BF51F5");
|
||||
return new X9ECParameters(curve, G, n, h);
|
||||
}
|
||||
// TODO: make this into a proper hashtable
|
||||
function getSECCurveByName(name) {
|
||||
if(name == "secp128r1") return secp128r1();
|
||||
if(name == "secp160k1") return secp160k1();
|
||||
if(name == "secp160r1") return secp160r1();
|
||||
if(name == "secp192k1") return secp192k1();
|
||||
if(name == "secp192r1") return secp192r1();
|
||||
if(name == "secp224r1") return secp224r1();
|
||||
if(name == "secp256r1") return secp256r1();
|
||||
return null;
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -1,566 +0,0 @@
|
||||
/*! asn1hex-1.1.6.js (c) 2012-2015 Kenji Urushima | kjur.github.com/jsrsasign/license
|
||||
*/
|
||||
/*
|
||||
* asn1hex.js - Hexadecimal represented ASN.1 string library
|
||||
*
|
||||
* Copyright (c) 2010-2015 Kenji Urushima (kenji.urushima@gmail.com)
|
||||
*
|
||||
* This software is licensed under the terms of the MIT License.
|
||||
* http://kjur.github.com/jsrsasign/license/
|
||||
*
|
||||
* The above copyright and license notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @fileOverview
|
||||
* @name asn1hex-1.1.js
|
||||
* @author Kenji Urushima kenji.urushima@gmail.com
|
||||
* @version asn1hex 1.1.6 (2015-Jun-11)
|
||||
* @license <a href="http://kjur.github.io/jsrsasign/license/">MIT License</a>
|
||||
*/
|
||||
|
||||
/*
|
||||
* MEMO:
|
||||
* f('3082025b02...', 2) ... 82025b ... 3bytes
|
||||
* f('020100', 2) ... 01 ... 1byte
|
||||
* f('0203001...', 2) ... 03 ... 1byte
|
||||
* f('02818003...', 2) ... 8180 ... 2bytes
|
||||
* f('3080....0000', 2) ... 80 ... -1
|
||||
*
|
||||
* Requirements:
|
||||
* - ASN.1 type octet length MUST be 1.
|
||||
* (i.e. ASN.1 primitives like SET, SEQUENCE, INTEGER, OCTETSTRING ...)
|
||||
*/
|
||||
|
||||
/**
|
||||
* ASN.1 DER encoded hexadecimal string utility class
|
||||
* @name ASN1HEX
|
||||
* @class ASN.1 DER encoded hexadecimal string utility class
|
||||
* @since jsrsasign 1.1
|
||||
*/
|
||||
var ASN1HEX = new function() {
|
||||
/**
|
||||
* get byte length for ASN.1 L(length) bytes
|
||||
* @name getByteLengthOfL_AtObj
|
||||
* @memberOf ASN1HEX
|
||||
* @function
|
||||
* @param {String} s hexadecimal string of ASN.1 DER encoded data
|
||||
* @param {Number} pos string index
|
||||
* @return byte length for ASN.1 L(length) bytes
|
||||
*/
|
||||
this.getByteLengthOfL_AtObj = function(s, pos) {
|
||||
if (s.substring(pos + 2, pos + 3) != '8') return 1;
|
||||
var i = parseInt(s.substring(pos + 3, pos + 4));
|
||||
if (i == 0) return -1; // length octet '80' indefinite length
|
||||
if (0 < i && i < 10) return i + 1; // including '8?' octet;
|
||||
return -2; // malformed format
|
||||
};
|
||||
|
||||
/**
|
||||
* get hexadecimal string for ASN.1 L(length) bytes
|
||||
* @name getHexOfL_AtObj
|
||||
* @memberOf ASN1HEX
|
||||
* @function
|
||||
* @param {String} s hexadecimal string of ASN.1 DER encoded data
|
||||
* @param {Number} pos string index
|
||||
* @return {String} hexadecimal string for ASN.1 L(length) bytes
|
||||
*/
|
||||
this.getHexOfL_AtObj = function(s, pos) {
|
||||
var len = this.getByteLengthOfL_AtObj(s, pos);
|
||||
if (len < 1) return '';
|
||||
return s.substring(pos + 2, pos + 2 + len * 2);
|
||||
};
|
||||
|
||||
// getting ASN.1 length value at the position 'idx' of
|
||||
// hexa decimal string 's'.
|
||||
//
|
||||
// f('3082025b02...', 0) ... 82025b ... ???
|
||||
// f('020100', 0) ... 01 ... 1
|
||||
// f('0203001...', 0) ... 03 ... 3
|
||||
// f('02818003...', 0) ... 8180 ... 128
|
||||
/**
|
||||
* get integer value of ASN.1 length for ASN.1 data
|
||||
* @name getIntOfL_AtObj
|
||||
* @memberOf ASN1HEX
|
||||
* @function
|
||||
* @param {String} s hexadecimal string of ASN.1 DER encoded data
|
||||
* @param {Number} pos string index
|
||||
* @return ASN.1 L(length) integer value
|
||||
*/
|
||||
this.getIntOfL_AtObj = function(s, pos) {
|
||||
var hLength = this.getHexOfL_AtObj(s, pos);
|
||||
if (hLength == '') return -1;
|
||||
var bi;
|
||||
if (parseInt(hLength.substring(0, 1)) < 8) {
|
||||
bi = new BigInteger(hLength, 16);
|
||||
} else {
|
||||
bi = new BigInteger(hLength.substring(2), 16);
|
||||
}
|
||||
return bi.intValue();
|
||||
};
|
||||
|
||||
/**
|
||||
* get ASN.1 value starting string position for ASN.1 object refered by index 'idx'.
|
||||
* @name getStartPosOfV_AtObj
|
||||
* @memberOf ASN1HEX
|
||||
* @function
|
||||
* @param {String} s hexadecimal string of ASN.1 DER encoded data
|
||||
* @param {Number} pos string index
|
||||
*/
|
||||
this.getStartPosOfV_AtObj = function(s, pos) {
|
||||
var l_len = this.getByteLengthOfL_AtObj(s, pos);
|
||||
if (l_len < 0) return l_len;
|
||||
return pos + (l_len + 1) * 2;
|
||||
};
|
||||
|
||||
/**
|
||||
* get hexadecimal string of ASN.1 V(value)
|
||||
* @name getHexOfV_AtObj
|
||||
* @memberOf ASN1HEX
|
||||
* @function
|
||||
* @param {String} s hexadecimal string of ASN.1 DER encoded data
|
||||
* @param {Number} pos string index
|
||||
* @return {String} hexadecimal string of ASN.1 value.
|
||||
*/
|
||||
this.getHexOfV_AtObj = function(s, pos) {
|
||||
var pos1 = this.getStartPosOfV_AtObj(s, pos);
|
||||
var len = this.getIntOfL_AtObj(s, pos);
|
||||
return s.substring(pos1, pos1 + len * 2);
|
||||
};
|
||||
|
||||
/**
|
||||
* get hexadecimal string of ASN.1 TLV at
|
||||
* @name getHexOfTLV_AtObj
|
||||
* @memberOf ASN1HEX
|
||||
* @function
|
||||
* @param {String} s hexadecimal string of ASN.1 DER encoded data
|
||||
* @param {Number} pos string index
|
||||
* @return {String} hexadecimal string of ASN.1 TLV.
|
||||
* @since 1.1
|
||||
*/
|
||||
this.getHexOfTLV_AtObj = function(s, pos) {
|
||||
var hT = s.substr(pos, 2);
|
||||
var hL = this.getHexOfL_AtObj(s, pos);
|
||||
var hV = this.getHexOfV_AtObj(s, pos);
|
||||
return hT + hL + hV;
|
||||
};
|
||||
|
||||
/**
|
||||
* get next sibling starting index for ASN.1 object string
|
||||
* @name getPosOfNextSibling_AtObj
|
||||
* @memberOf ASN1HEX
|
||||
* @function
|
||||
* @param {String} s hexadecimal string of ASN.1 DER encoded data
|
||||
* @param {Number} pos string index
|
||||
* @return next sibling starting index for ASN.1 object string
|
||||
*/
|
||||
this.getPosOfNextSibling_AtObj = function(s, pos) {
|
||||
var pos1 = this.getStartPosOfV_AtObj(s, pos);
|
||||
var len = this.getIntOfL_AtObj(s, pos);
|
||||
return pos1 + len * 2;
|
||||
};
|
||||
|
||||
/**
|
||||
* get array of indexes of child ASN.1 objects
|
||||
* @name getPosArrayOfChildren_AtObj
|
||||
* @memberOf ASN1HEX
|
||||
* @function
|
||||
* @param {String} s hexadecimal string of ASN.1 DER encoded data
|
||||
* @param {Number} start string index of ASN.1 object
|
||||
* @return {Array of Number} array of indexes for childen of ASN.1 objects
|
||||
*/
|
||||
this.getPosArrayOfChildren_AtObj = function(h, pos) {
|
||||
var a = new Array();
|
||||
var p0 = this.getStartPosOfV_AtObj(h, pos);
|
||||
a.push(p0);
|
||||
|
||||
var len = this.getIntOfL_AtObj(h, pos);
|
||||
var p = p0;
|
||||
var k = 0;
|
||||
while (1) {
|
||||
var pNext = this.getPosOfNextSibling_AtObj(h, p);
|
||||
if (pNext == null || (pNext - p0 >= (len * 2))) break;
|
||||
if (k >= 200) break;
|
||||
|
||||
a.push(pNext);
|
||||
p = pNext;
|
||||
|
||||
k++;
|
||||
}
|
||||
|
||||
return a;
|
||||
};
|
||||
|
||||
/**
|
||||
* get string index of nth child object of ASN.1 object refered by h, idx
|
||||
* @name getNthChildIndex_AtObj
|
||||
* @memberOf ASN1HEX
|
||||
* @function
|
||||
* @param {String} h hexadecimal string of ASN.1 DER encoded data
|
||||
* @param {Number} idx start string index of ASN.1 object
|
||||
* @param {Number} nth for child
|
||||
* @return {Number} string index of nth child.
|
||||
* @since 1.1
|
||||
*/
|
||||
this.getNthChildIndex_AtObj = function(h, idx, nth) {
|
||||
var a = this.getPosArrayOfChildren_AtObj(h, idx);
|
||||
return a[nth];
|
||||
};
|
||||
|
||||
// ========== decendant methods ==============================
|
||||
/**
|
||||
* get string index of nth child object of ASN.1 object refered by h, idx
|
||||
* @name getDecendantIndexByNthList
|
||||
* @memberOf ASN1HEX
|
||||
* @function
|
||||
* @param {String} h hexadecimal string of ASN.1 DER encoded data
|
||||
* @param {Number} currentIndex start string index of ASN.1 object
|
||||
* @param {Array of Number} nthList array list of nth
|
||||
* @return {Number} string index refered by nthList
|
||||
* @since 1.1
|
||||
* @example
|
||||
* The "nthList" is a index list of structured ASN.1 object
|
||||
* reference. Here is a sample structure and "nthList"s which
|
||||
* refers each objects.
|
||||
*
|
||||
* SQUENCE -
|
||||
* SEQUENCE - [0]
|
||||
* IA5STRING 000 - [0, 0]
|
||||
* UTF8STRING 001 - [0, 1]
|
||||
* SET - [1]
|
||||
* IA5STRING 010 - [1, 0]
|
||||
* UTF8STRING 011 - [1, 1]
|
||||
*/
|
||||
this.getDecendantIndexByNthList = function(h, currentIndex, nthList) {
|
||||
if (nthList.length == 0) {
|
||||
return currentIndex;
|
||||
}
|
||||
var firstNth = nthList.shift();
|
||||
var a = this.getPosArrayOfChildren_AtObj(h, currentIndex);
|
||||
return this.getDecendantIndexByNthList(h, a[firstNth], nthList);
|
||||
};
|
||||
|
||||
/**
|
||||
* get hexadecimal string of ASN.1 TLV refered by current index and nth index list.
|
||||
* @name getDecendantHexTLVByNthList
|
||||
* @memberOf ASN1HEX
|
||||
* @function
|
||||
* @param {String} h hexadecimal string of ASN.1 DER encoded data
|
||||
* @param {Number} currentIndex start string index of ASN.1 object
|
||||
* @param {Array of Number} nthList array list of nth
|
||||
* @return {Number} hexadecimal string of ASN.1 TLV refered by nthList
|
||||
* @since 1.1
|
||||
*/
|
||||
this.getDecendantHexTLVByNthList = function(h, currentIndex, nthList) {
|
||||
var idx = this.getDecendantIndexByNthList(h, currentIndex, nthList);
|
||||
return this.getHexOfTLV_AtObj(h, idx);
|
||||
};
|
||||
|
||||
/**
|
||||
* get hexadecimal string of ASN.1 V refered by current index and nth index list.
|
||||
* @name getDecendantHexVByNthList
|
||||
* @memberOf ASN1HEX
|
||||
* @function
|
||||
* @param {String} h hexadecimal string of ASN.1 DER encoded data
|
||||
* @param {Number} currentIndex start string index of ASN.1 object
|
||||
* @param {Array of Number} nthList array list of nth
|
||||
* @return {Number} hexadecimal string of ASN.1 V refered by nthList
|
||||
* @since 1.1
|
||||
*/
|
||||
this.getDecendantHexVByNthList = function(h, currentIndex, nthList) {
|
||||
var idx = this.getDecendantIndexByNthList(h, currentIndex, nthList);
|
||||
return this.getHexOfV_AtObj(h, idx);
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* @since asn1hex 1.1.4
|
||||
*/
|
||||
ASN1HEX.getVbyList = function(h, currentIndex, nthList, checkingTag) {
|
||||
var idx = this.getDecendantIndexByNthList(h, currentIndex, nthList);
|
||||
if (idx === undefined) {
|
||||
throw "can't find nthList object";
|
||||
}
|
||||
if (checkingTag !== undefined) {
|
||||
if (h.substr(idx, 2) != checkingTag) {
|
||||
throw "checking tag doesn't match: " +
|
||||
h.substr(idx,2) + "!=" + checkingTag;
|
||||
}
|
||||
}
|
||||
return this.getHexOfV_AtObj(h, idx);
|
||||
};
|
||||
|
||||
/**
|
||||
* get OID string from hexadecimal encoded value
|
||||
* @name hextooidstr
|
||||
* @memberOf ASN1HEX
|
||||
* @function
|
||||
* @param {String} hex hexadecmal string of ASN.1 DER encoded OID value
|
||||
* @return {String} OID string (ex. '1.2.3.4.567')
|
||||
* @since asn1hex 1.1.5
|
||||
*/
|
||||
ASN1HEX.hextooidstr = function(hex) {
|
||||
var zeroPadding = function(s, len) {
|
||||
if (s.length >= len) return s;
|
||||
return new Array(len - s.length + 1).join('0') + s;
|
||||
};
|
||||
|
||||
var a = [];
|
||||
|
||||
// a[0], a[1]
|
||||
var hex0 = hex.substr(0, 2);
|
||||
var i0 = parseInt(hex0, 16);
|
||||
a[0] = new String(Math.floor(i0 / 40));
|
||||
a[1] = new String(i0 % 40);
|
||||
|
||||
// a[2]..a[n]
|
||||
var hex1 = hex.substr(2);
|
||||
var b = [];
|
||||
for (var i = 0; i < hex1.length / 2; i++) {
|
||||
b.push(parseInt(hex1.substr(i * 2, 2), 16));
|
||||
}
|
||||
var c = [];
|
||||
var cbin = "";
|
||||
for (var i = 0; i < b.length; i++) {
|
||||
if (b[i] & 0x80) {
|
||||
cbin = cbin + zeroPadding((b[i] & 0x7f).toString(2), 7);
|
||||
} else {
|
||||
cbin = cbin + zeroPadding((b[i] & 0x7f).toString(2), 7);
|
||||
c.push(new String(parseInt(cbin, 2)));
|
||||
cbin = "";
|
||||
}
|
||||
}
|
||||
|
||||
var s = a.join(".");
|
||||
if (c.length > 0) s = s + "." + c.join(".");
|
||||
return s;
|
||||
};
|
||||
|
||||
/**
|
||||
* get string of simple ASN.1 dump from hexadecimal ASN.1 data
|
||||
* @name dump
|
||||
* @memberOf ASN1HEX
|
||||
* @function
|
||||
* @param {String} hex hexadecmal string of ASN.1 data
|
||||
* @param {Array} associative array of flags for dump (OPTION)
|
||||
* @param {Number} idx string index for starting dump (OPTION)
|
||||
* @param {String} indent string (OPTION)
|
||||
* @return {String} string of simple ASN.1 dump
|
||||
* @since jsrsasign 4.8.3 asn1hex 1.1.6
|
||||
* @description
|
||||
* This method will get an ASN.1 dump from
|
||||
* hexadecmal string of ASN.1 DER encoded data.
|
||||
* Here are features:
|
||||
* <ul>
|
||||
* <li>ommit long hexadecimal string</li>
|
||||
* <li>dump encapsulated OCTET STRING (good for X.509v3 extensions)</li>
|
||||
* <li>structured/primitive context specific tag support (i.e. [0], [3] ...)</li>
|
||||
* <li>automatic decode for implicit primitive context specific tag
|
||||
* (good for X.509v3 extension value)
|
||||
* <ul>
|
||||
* <li>if hex starts '68747470'(i.e. http) it is decoded as utf8 encoded string.</li>
|
||||
* <li>if it is in 'subjectAltName' extension value and is '[2]'(dNSName) tag
|
||||
* value will be encoded as utf8 string</li>
|
||||
* <li>otherwise it shows as hexadecimal string</li>
|
||||
* </ul>
|
||||
* </li>
|
||||
* </ul>
|
||||
* @example
|
||||
* // ASN.1 INTEGER
|
||||
* ASN1HEX.dump('0203012345')
|
||||
* ↓
|
||||
* INTEGER 012345
|
||||
* // ASN.1 Object Identifier
|
||||
* ASN1HEX.dump('06052b0e03021a')
|
||||
* ↓
|
||||
* ObjectIdentifier sha1 (1 3 14 3 2 26)
|
||||
* // ASN.1 SEQUENCE
|
||||
* ASN1HEX.dump('3006020101020102')
|
||||
* ↓
|
||||
* SEQUENCE
|
||||
* INTEGER 01
|
||||
* INTEGER 02
|
||||
* // ASN.1 DUMP FOR X.509 CERTIFICATE
|
||||
* ASN1HEX.dump(X509.pemToHex(certPEM))
|
||||
* ↓
|
||||
* SEQUENCE
|
||||
* SEQUENCE
|
||||
* [0]
|
||||
* INTEGER 02
|
||||
* INTEGER 0c009310d206dbe337553580118ddc87
|
||||
* SEQUENCE
|
||||
* ObjectIdentifier SHA256withRSA (1 2 840 113549 1 1 11)
|
||||
* NULL
|
||||
* SEQUENCE
|
||||
* SET
|
||||
* SEQUENCE
|
||||
* ObjectIdentifier countryName (2 5 4 6)
|
||||
* PrintableString 'US'
|
||||
* :
|
||||
*/
|
||||
ASN1HEX.dump = function(hex, flags, idx, indent) {
|
||||
var _skipLongHex = function(hex, limitNumOctet) {
|
||||
if (hex.length <= limitNumOctet * 2) {
|
||||
return hex;
|
||||
} else {
|
||||
var s = hex.substr(0, limitNumOctet) +
|
||||
"..(total " + hex.length / 2 + "bytes).." +
|
||||
hex.substr(hex.length - limitNumOctet, limitNumOctet);
|
||||
return s;
|
||||
};
|
||||
};
|
||||
|
||||
if (flags === undefined) flags = { "ommit_long_octet": 32 };
|
||||
if (idx === undefined) idx = 0;
|
||||
if (indent === undefined) indent = "";
|
||||
var skipLongHex = flags.ommit_long_octet;
|
||||
|
||||
if (hex.substr(idx, 2) == "01") {
|
||||
var v = ASN1HEX.getHexOfV_AtObj(hex, idx);
|
||||
if (v == "00") {
|
||||
return indent + "BOOLEAN FALSE\n";
|
||||
} else {
|
||||
return indent + "BOOLEAN TRUE\n";
|
||||
}
|
||||
}
|
||||
if (hex.substr(idx, 2) == "02") {
|
||||
var v = ASN1HEX.getHexOfV_AtObj(hex, idx);
|
||||
return indent + "INTEGER " + _skipLongHex(v, skipLongHex) + "\n";
|
||||
}
|
||||
if (hex.substr(idx, 2) == "03") {
|
||||
var v = ASN1HEX.getHexOfV_AtObj(hex, idx);
|
||||
return indent + "BITSTRING " + _skipLongHex(v, skipLongHex) + "\n";
|
||||
}
|
||||
if (hex.substr(idx, 2) == "04") {
|
||||
var v = ASN1HEX.getHexOfV_AtObj(hex, idx);
|
||||
if (ASN1HEX.isASN1HEX(v)) {
|
||||
var s = indent + "OCTETSTRING, encapsulates\n";
|
||||
s = s + ASN1HEX.dump(v, flags, 0, indent + " ");
|
||||
return s;
|
||||
} else {
|
||||
return indent + "OCTETSTRING " + _skipLongHex(v, skipLongHex) + "\n";
|
||||
}
|
||||
}
|
||||
if (hex.substr(idx, 2) == "05") {
|
||||
return indent + "NULL\n";
|
||||
}
|
||||
if (hex.substr(idx, 2) == "06") {
|
||||
var hV = ASN1HEX.getHexOfV_AtObj(hex, idx);
|
||||
var oidDot = KJUR.asn1.ASN1Util.oidHexToInt(hV);
|
||||
var oidName = KJUR.asn1.x509.OID.oid2name(oidDot);
|
||||
var oidSpc = oidDot.replace(/\./g, ' ');
|
||||
if (oidName != '') {
|
||||
return indent + "ObjectIdentifier " + oidName + " (" + oidSpc + ")\n";
|
||||
} else {
|
||||
return indent + "ObjectIdentifier (" + oidSpc + ")\n";
|
||||
}
|
||||
}
|
||||
if (hex.substr(idx, 2) == "0c") {
|
||||
return indent + "UTF8String '" + hextoutf8(ASN1HEX.getHexOfV_AtObj(hex, idx)) + "'\n";
|
||||
}
|
||||
if (hex.substr(idx, 2) == "13") {
|
||||
return indent + "PrintableString '" + hextoutf8(ASN1HEX.getHexOfV_AtObj(hex, idx)) + "'\n";
|
||||
}
|
||||
if (hex.substr(idx, 2) == "14") {
|
||||
return indent + "TeletexString '" + hextoutf8(ASN1HEX.getHexOfV_AtObj(hex, idx)) + "'\n";
|
||||
}
|
||||
if (hex.substr(idx, 2) == "16") {
|
||||
return indent + "IA5String '" + hextoutf8(ASN1HEX.getHexOfV_AtObj(hex, idx)) + "'\n";
|
||||
}
|
||||
if (hex.substr(idx, 2) == "17") {
|
||||
return indent + "UTCTime " + hextoutf8(ASN1HEX.getHexOfV_AtObj(hex, idx)) + "\n";
|
||||
}
|
||||
if (hex.substr(idx, 2) == "18") {
|
||||
return indent + "GeneralizedTime " + hextoutf8(ASN1HEX.getHexOfV_AtObj(hex, idx)) + "\n";
|
||||
}
|
||||
if (hex.substr(idx, 2) == "30") {
|
||||
if (hex.substr(idx, 4) == "3000") {
|
||||
return indent + "SEQUENCE {}\n";
|
||||
}
|
||||
|
||||
var s = indent + "SEQUENCE\n";
|
||||
var aIdx = ASN1HEX.getPosArrayOfChildren_AtObj(hex, idx);
|
||||
|
||||
var flagsTemp = flags;
|
||||
|
||||
if ((aIdx.length == 2 || aIdx.length == 3) &&
|
||||
hex.substr(aIdx[0], 2) == "06" &&
|
||||
hex.substr(aIdx[aIdx.length - 1], 2) == "04") { // supposed X.509v3 extension
|
||||
var oidHex = ASN1HEX.getHexOfV_AtObj(hex, aIdx[0]);
|
||||
var oidDot = KJUR.asn1.ASN1Util.oidHexToInt(oidHex);
|
||||
var oidName = KJUR.asn1.x509.OID.oid2name(oidDot);
|
||||
|
||||
var flagsClone = JSON.parse(JSON.stringify(flags));
|
||||
flagsClone.x509ExtName = oidName;
|
||||
flagsTemp = flagsClone;
|
||||
}
|
||||
|
||||
for (var i = 0; i < aIdx.length; i++) {
|
||||
s = s + ASN1HEX.dump(hex, flagsTemp, aIdx[i], indent + " ");
|
||||
}
|
||||
return s;
|
||||
}
|
||||
if (hex.substr(idx, 2) == "31") {
|
||||
var s = indent + "SET\n";
|
||||
var aIdx = ASN1HEX.getPosArrayOfChildren_AtObj(hex, idx);
|
||||
for (var i = 0; i < aIdx.length; i++) {
|
||||
s = s + ASN1HEX.dump(hex, flags, aIdx[i], indent + " ");
|
||||
}
|
||||
return s;
|
||||
}
|
||||
var tag = parseInt(hex.substr(idx, 2), 16);
|
||||
if ((tag & 128) != 0) { // context specific
|
||||
var tagNumber = tag & 31;
|
||||
if ((tag & 32) != 0) { // structured tag
|
||||
var s = indent + "[" + tagNumber + "]\n";
|
||||
var aIdx = ASN1HEX.getPosArrayOfChildren_AtObj(hex, idx);
|
||||
for (var i = 0; i < aIdx.length; i++) {
|
||||
s = s + ASN1HEX.dump(hex, flags, aIdx[i], indent + " ");
|
||||
}
|
||||
return s;
|
||||
} else { // primitive tag
|
||||
var v = ASN1HEX.getHexOfV_AtObj(hex, idx);
|
||||
if (v.substr(0, 8) == "68747470") { // http
|
||||
v = hextoutf8(v);
|
||||
}
|
||||
if (flags.x509ExtName === "subjectAltName" &&
|
||||
tagNumber == 2) {
|
||||
v = hextoutf8(v);
|
||||
}
|
||||
|
||||
var s = indent + "[" + tagNumber + "] " + v + "\n";
|
||||
return s;
|
||||
}
|
||||
}
|
||||
return indent + "UNKNOWN(" + hex.substr(idx, 2) + ") " + ASN1HEX.getHexOfV_AtObj(hex, idx) + "\n";
|
||||
};
|
||||
|
||||
/**
|
||||
* check wheather the string is ASN.1 hexadecimal string or not
|
||||
* @name isASN1HEX
|
||||
* @memberOf ASN1HEX
|
||||
* @function
|
||||
* @param {String} hex string to check whether it is hexadecmal string for ASN.1 DER or not
|
||||
* @return {Boolean} true if it is hexadecimal string of ASN.1 data otherwise false
|
||||
* @since jsrsasign 4.8.3 asn1hex 1.1.6
|
||||
* @description
|
||||
* This method checks wheather the argument 'hex' is a hexadecimal string of
|
||||
* ASN.1 data or not.
|
||||
* @example
|
||||
* ASN1HEX.isASN1HEX('0203012345') → true // PROPER ASN.1 INTEGER
|
||||
* ASN1HEX.isASN1HEX('0203012345ff') → false // TOO LONG VALUE
|
||||
* ASN1HEX.isASN1HEX('02030123') → false // TOO SHORT VALUE
|
||||
* ASN1HEX.isASN1HEX('fa3bcd') → false // WRONG FOR ASN.1
|
||||
*/
|
||||
ASN1HEX.isASN1HEX = function(hex) {
|
||||
if (hex.length % 2 == 1) return false;
|
||||
|
||||
var intL = ASN1HEX.getIntOfL_AtObj(hex, 0);
|
||||
var tV = hex.substr(0, 2);
|
||||
var lV = ASN1HEX.getHexOfL_AtObj(hex, 0);
|
||||
var hVLength = hex.length - tV.length - lV.length;
|
||||
if (hVLength == intL * 2) return true;
|
||||
|
||||
return false;
|
||||
};
|
File diff suppressed because it is too large
Load Diff
@ -1,430 +0,0 @@
|
||||
/*! base64x-1.1.5 (c) 2012-2015 Kenji Urushima | kjur.github.com/jsjws/license
|
||||
*/
|
||||
/*
|
||||
* base64x.js - Base64url and supplementary functions for Tom Wu's base64.js library
|
||||
*
|
||||
* version: 1.1.5 (2015-Sep-13)
|
||||
*
|
||||
* Copyright (c) 2012-2015 Kenji Urushima (kenji.urushima@gmail.com)
|
||||
*
|
||||
* This software is licensed under the terms of the MIT License.
|
||||
* http://kjur.github.com/jsjws/license/
|
||||
*
|
||||
* The above copyright and license notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* DEPENDS ON:
|
||||
* - base64.js - Tom Wu's Base64 library
|
||||
*/
|
||||
|
||||
/**
|
||||
* @fileOverview
|
||||
* @name base64x-1.1.js
|
||||
* @author Kenji Urushima kenji.urushima@gmail.com
|
||||
* @version asn1 1.1.5 (2015-Sep-13)
|
||||
* @since jsrsasign 2.1
|
||||
* @license <a href="http://kjur.github.io/jsrsasign/license/">MIT License</a>
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base64URL and supplementary functions for Tom Wu's base64.js library.<br/>
|
||||
* This class is just provide information about global functions
|
||||
* defined in 'base64x.js'. The 'base64x.js' script file provides
|
||||
* global functions for converting following data each other.
|
||||
* <ul>
|
||||
* <li>(ASCII) String</li>
|
||||
* <li>UTF8 String including CJK, Latin and other characters</li>
|
||||
* <li>byte array</li>
|
||||
* <li>hexadecimal encoded String</li>
|
||||
* <li>Full URIComponent encoded String (such like "%69%94")</li>
|
||||
* <li>Base64 encoded String</li>
|
||||
* <li>Base64URL encoded String</li>
|
||||
* </ul>
|
||||
* All functions in 'base64x.js' are defined in {@link _global_} and not
|
||||
* in this class.
|
||||
*
|
||||
* @class Base64URL and supplementary functions for Tom Wu's base64.js library
|
||||
* @author Kenji Urushima
|
||||
* @version 1.1 (07 May 2012)
|
||||
* @requires base64.js
|
||||
* @see <a href="http://kjur.github.com/jsjws/">'jwjws'(JWS JavaScript Library) home page http://kjur.github.com/jsjws/</a>
|
||||
* @see <a href="http://kjur.github.com/jsrsasigns/">'jwrsasign'(RSA Sign JavaScript Library) home page http://kjur.github.com/jsrsasign/</a>
|
||||
*/
|
||||
function Base64x() {
|
||||
}
|
||||
|
||||
// ==== string / byte array ================================
|
||||
/**
|
||||
* convert a string to an array of character codes
|
||||
* @param {String} s
|
||||
* @return {Array of Numbers}
|
||||
*/
|
||||
function stoBA(s) {
|
||||
var a = new Array();
|
||||
for (var i = 0; i < s.length; i++) {
|
||||
a[i] = s.charCodeAt(i);
|
||||
}
|
||||
return a;
|
||||
}
|
||||
|
||||
/**
|
||||
* convert an array of character codes to a string
|
||||
* @param {Array of Numbers} a array of character codes
|
||||
* @return {String} s
|
||||
*/
|
||||
function BAtos(a) {
|
||||
var s = "";
|
||||
for (var i = 0; i < a.length; i++) {
|
||||
s = s + String.fromCharCode(a[i]);
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
// ==== byte array / hex ================================
|
||||
/**
|
||||
* convert an array of bytes(Number) to hexadecimal string.<br/>
|
||||
* @param {Array of Numbers} a array of bytes
|
||||
* @return {String} hexadecimal string
|
||||
*/
|
||||
function BAtohex(a) {
|
||||
var s = "";
|
||||
for (var i = 0; i < a.length; i++) {
|
||||
var hex1 = a[i].toString(16);
|
||||
if (hex1.length == 1) hex1 = "0" + hex1;
|
||||
s = s + hex1;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
// ==== string / hex ================================
|
||||
/**
|
||||
* convert a ASCII string to a hexadecimal string of ASCII codes.<br/>
|
||||
* NOTE: This can't be used for non ASCII characters.
|
||||
* @param {s} s ASCII string
|
||||
* @return {String} hexadecimal string
|
||||
*/
|
||||
function stohex(s) {
|
||||
return BAtohex(stoBA(s));
|
||||
}
|
||||
|
||||
// ==== string / base64 ================================
|
||||
/**
|
||||
* convert a ASCII string to a Base64 encoded string.<br/>
|
||||
* NOTE: This can't be used for non ASCII characters.
|
||||
* @param {s} s ASCII string
|
||||
* @return {String} Base64 encoded string
|
||||
*/
|
||||
function stob64(s) {
|
||||
return hex2b64(stohex(s));
|
||||
}
|
||||
|
||||
// ==== string / base64url ================================
|
||||
/**
|
||||
* convert a ASCII string to a Base64URL encoded string.<br/>
|
||||
* NOTE: This can't be used for non ASCII characters.
|
||||
* @param {s} s ASCII string
|
||||
* @return {String} Base64URL encoded string
|
||||
*/
|
||||
function stob64u(s) {
|
||||
return b64tob64u(hex2b64(stohex(s)));
|
||||
}
|
||||
|
||||
/**
|
||||
* convert a Base64URL encoded string to a ASCII string.<br/>
|
||||
* NOTE: This can't be used for Base64URL encoded non ASCII characters.
|
||||
* @param {s} s Base64URL encoded string
|
||||
* @return {String} ASCII string
|
||||
*/
|
||||
function b64utos(s) {
|
||||
return BAtos(b64toBA(b64utob64(s)));
|
||||
}
|
||||
|
||||
// ==== base64 / base64url ================================
|
||||
/**
|
||||
* convert a Base64 encoded string to a Base64URL encoded string.<br/>
|
||||
* Example: "ab+c3f/==" → "ab-c3f_"
|
||||
* @param {String} s Base64 encoded string
|
||||
* @return {String} Base64URL encoded string
|
||||
*/
|
||||
function b64tob64u(s) {
|
||||
s = s.replace(/\=/g, "");
|
||||
s = s.replace(/\+/g, "-");
|
||||
s = s.replace(/\//g, "_");
|
||||
return s;
|
||||
}
|
||||
|
||||
/**
|
||||
* convert a Base64URL encoded string to a Base64 encoded string.<br/>
|
||||
* Example: "ab-c3f_" → "ab+c3f/=="
|
||||
* @param {String} s Base64URL encoded string
|
||||
* @return {String} Base64 encoded string
|
||||
*/
|
||||
function b64utob64(s) {
|
||||
if (s.length % 4 == 2) s = s + "==";
|
||||
else if (s.length % 4 == 3) s = s + "=";
|
||||
s = s.replace(/-/g, "+");
|
||||
s = s.replace(/_/g, "/");
|
||||
return s;
|
||||
}
|
||||
|
||||
// ==== hex / base64url ================================
|
||||
/**
|
||||
* convert a hexadecimal string to a Base64URL encoded string.<br/>
|
||||
* @param {String} s hexadecimal string
|
||||
* @return {String} Base64URL encoded string
|
||||
* @description
|
||||
* convert a hexadecimal string to a Base64URL encoded string.
|
||||
* NOTE: If leading "0" is omitted and odd number length for
|
||||
* hexadecimal leading "0" is automatically added.
|
||||
*/
|
||||
function hextob64u(s) {
|
||||
if (s.length % 2 == 1) s = "0" + s;
|
||||
return b64tob64u(hex2b64(s));
|
||||
}
|
||||
|
||||
/**
|
||||
* convert a Base64URL encoded string to a hexadecimal string.<br/>
|
||||
* @param {String} s Base64URL encoded string
|
||||
* @return {String} hexadecimal string
|
||||
*/
|
||||
function b64utohex(s) {
|
||||
return b64tohex(b64utob64(s));
|
||||
}
|
||||
|
||||
var utf8tob64u, b64utoutf8;
|
||||
|
||||
if (typeof Buffer === 'function')
|
||||
{
|
||||
utf8tob64u = function (s)
|
||||
{
|
||||
return b64tob64u(new Buffer(s, 'utf8').toString('base64'));
|
||||
};
|
||||
|
||||
b64utoutf8 = function (s)
|
||||
{
|
||||
return new Buffer(b64utob64(s), 'base64').toString('utf8');
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
// ==== utf8 / base64url ================================
|
||||
/**
|
||||
* convert a UTF-8 encoded string including CJK or Latin to a Base64URL encoded string.<br/>
|
||||
* @param {String} s UTF-8 encoded string
|
||||
* @return {String} Base64URL encoded string
|
||||
* @since 1.1
|
||||
*/
|
||||
utf8tob64u = function (s)
|
||||
{
|
||||
return hextob64u(uricmptohex(encodeURIComponentAll(s)));
|
||||
};
|
||||
|
||||
/**
|
||||
* convert a Base64URL encoded string to a UTF-8 encoded string including CJK or Latin.<br/>
|
||||
* @param {String} s Base64URL encoded string
|
||||
* @return {String} UTF-8 encoded string
|
||||
* @since 1.1
|
||||
*/
|
||||
b64utoutf8 = function (s)
|
||||
{
|
||||
return decodeURIComponent(hextouricmp(b64utohex(s)));
|
||||
};
|
||||
}
|
||||
|
||||
// ==== utf8 / base64url ================================
|
||||
/**
|
||||
* convert a UTF-8 encoded string including CJK or Latin to a Base64 encoded string.<br/>
|
||||
* @param {String} s UTF-8 encoded string
|
||||
* @return {String} Base64 encoded string
|
||||
* @since 1.1.1
|
||||
*/
|
||||
function utf8tob64(s) {
|
||||
return hex2b64(uricmptohex(encodeURIComponentAll(s)));
|
||||
}
|
||||
|
||||
/**
|
||||
* convert a Base64 encoded string to a UTF-8 encoded string including CJK or Latin.<br/>
|
||||
* @param {String} s Base64 encoded string
|
||||
* @return {String} UTF-8 encoded string
|
||||
* @since 1.1.1
|
||||
*/
|
||||
function b64toutf8(s) {
|
||||
return decodeURIComponent(hextouricmp(b64tohex(s)));
|
||||
}
|
||||
|
||||
// ==== utf8 / hex ================================
|
||||
/**
|
||||
* convert a UTF-8 encoded string including CJK or Latin to a hexadecimal encoded string.<br/>
|
||||
* @param {String} s UTF-8 encoded string
|
||||
* @return {String} hexadecimal encoded string
|
||||
* @since 1.1.1
|
||||
*/
|
||||
function utf8tohex(s) {
|
||||
return uricmptohex(encodeURIComponentAll(s));
|
||||
}
|
||||
|
||||
/**
|
||||
* convert a hexadecimal encoded string to a UTF-8 encoded string including CJK or Latin.<br/>
|
||||
* Note that when input is improper hexadecimal string as UTF-8 string, this function returns
|
||||
* 'null'.
|
||||
* @param {String} s hexadecimal encoded string
|
||||
* @return {String} UTF-8 encoded string or null
|
||||
* @since 1.1.1
|
||||
*/
|
||||
function hextoutf8(s) {
|
||||
return decodeURIComponent(hextouricmp(s));
|
||||
}
|
||||
|
||||
/**
|
||||
* convert a hexadecimal encoded string to raw string including non printable characters.<br/>
|
||||
* @param {String} s hexadecimal encoded string
|
||||
* @return {String} raw string
|
||||
* @since 1.1.2
|
||||
* @example
|
||||
* hextorstr("610061") → "a\x00a"
|
||||
*/
|
||||
function hextorstr(sHex) {
|
||||
var s = "";
|
||||
for (var i = 0; i < sHex.length - 1; i += 2) {
|
||||
s += String.fromCharCode(parseInt(sHex.substr(i, 2), 16));
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
/**
|
||||
* convert a raw string including non printable characters to hexadecimal encoded string.<br/>
|
||||
* @param {String} s raw string
|
||||
* @return {String} hexadecimal encoded string
|
||||
* @since 1.1.2
|
||||
* @example
|
||||
* rstrtohex("a\x00a") → "610061"
|
||||
*/
|
||||
function rstrtohex(s) {
|
||||
var result = "";
|
||||
for (var i = 0; i < s.length; i++) {
|
||||
result += ("0" + s.charCodeAt(i).toString(16)).slice(-2);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// ==== hex / b64nl =======================================
|
||||
|
||||
/*
|
||||
* since base64x 1.1.3
|
||||
*/
|
||||
function hextob64(s) {
|
||||
return hex2b64(s);
|
||||
}
|
||||
|
||||
/*
|
||||
* since base64x 1.1.3
|
||||
*/
|
||||
function hextob64nl(s) {
|
||||
var b64 = hextob64(s);
|
||||
var b64nl = b64.replace(/(.{64})/g, "$1\r\n");
|
||||
b64nl = b64nl.replace(/\r\n$/, '');
|
||||
return b64nl;
|
||||
}
|
||||
|
||||
/*
|
||||
* since base64x 1.1.3
|
||||
*/
|
||||
function b64nltohex(s) {
|
||||
var b64 = s.replace(/[^0-9A-Za-z\/+=]*/g, '');
|
||||
var hex = b64tohex(b64);
|
||||
return hex;
|
||||
}
|
||||
|
||||
// ==== URIComponent / hex ================================
|
||||
/**
|
||||
* convert a URLComponent string such like "%67%68" to a hexadecimal string.<br/>
|
||||
* @param {String} s URIComponent string such like "%67%68"
|
||||
* @return {String} hexadecimal string
|
||||
* @since 1.1
|
||||
*/
|
||||
function uricmptohex(s) {
|
||||
return s.replace(/%/g, "");
|
||||
}
|
||||
|
||||
/**
|
||||
* convert a hexadecimal string to a URLComponent string such like "%67%68".<br/>
|
||||
* @param {String} s hexadecimal string
|
||||
* @return {String} URIComponent string such like "%67%68"
|
||||
* @since 1.1
|
||||
*/
|
||||
function hextouricmp(s) {
|
||||
return s.replace(/(..)/g, "%$1");
|
||||
}
|
||||
|
||||
// ==== URIComponent ================================
|
||||
/**
|
||||
* convert UTFa hexadecimal string to a URLComponent string such like "%67%68".<br/>
|
||||
* Note that these "<code>0-9A-Za-z!'()*-._~</code>" characters will not
|
||||
* converted to "%xx" format by builtin 'encodeURIComponent()' function.
|
||||
* However this 'encodeURIComponentAll()' function will convert
|
||||
* all of characters into "%xx" format.
|
||||
* @param {String} s hexadecimal string
|
||||
* @return {String} URIComponent string such like "%67%68"
|
||||
* @since 1.1
|
||||
*/
|
||||
function encodeURIComponentAll(u8) {
|
||||
var s = encodeURIComponent(u8);
|
||||
var s2 = "";
|
||||
for (var i = 0; i < s.length; i++) {
|
||||
if (s[i] == "%") {
|
||||
s2 = s2 + s.substr(i, 3);
|
||||
i = i + 2;
|
||||
} else {
|
||||
s2 = s2 + "%" + stohex(s[i]);
|
||||
}
|
||||
}
|
||||
return s2;
|
||||
}
|
||||
|
||||
// ==== new lines ================================
|
||||
/**
|
||||
* convert all DOS new line("\r\n") to UNIX new line("\n") in
|
||||
* a String "s".
|
||||
* @param {String} s string
|
||||
* @return {String} converted string
|
||||
*/
|
||||
function newline_toUnix(s) {
|
||||
s = s.replace(/\r\n/mg, "\n");
|
||||
return s;
|
||||
}
|
||||
|
||||
/**
|
||||
* convert all UNIX new line("\r\n") to DOS new line("\n") in
|
||||
* a String "s".
|
||||
* @param {String} s string
|
||||
* @return {String} converted string
|
||||
*/
|
||||
function newline_toDos(s) {
|
||||
s = s.replace(/\r\n/mg, "\n");
|
||||
s = s.replace(/\n/mg, "\r\n");
|
||||
return s;
|
||||
}
|
||||
|
||||
// ==== others ================================
|
||||
|
||||
/**
|
||||
* find index of string where two string differs
|
||||
* @param {String} s1 string to compare
|
||||
* @param {String} s2 string to compare
|
||||
* @return {Number} string index of where character differs. Return -1 if same.
|
||||
* @since jsrsasign 4.9.0 base64x 1.1.5
|
||||
* @example
|
||||
* strdiffidx("abcdefg", "abcd4fg") -> 4
|
||||
* strdiffidx("abcdefg", "abcdefg") -> -1
|
||||
* strdiffidx("abcdefg", "abcdef") -> 6
|
||||
* strdiffidx("abcdefgh", "abcdef") -> 6
|
||||
*/
|
||||
var strdiffidx = function(s1, s2) {
|
||||
var n = s1.length;
|
||||
if (s1.length > s2.length) n = s2.length;
|
||||
for (var i = 0; i < n; i++) {
|
||||
if (s1.charCodeAt(i) != s2.charCodeAt(i)) return i;
|
||||
}
|
||||
if (s1.length != s2.length) return n;
|
||||
return -1; // same
|
||||
};
|
File diff suppressed because it is too large
Load Diff
@ -1,381 +0,0 @@
|
||||
/*! dsa-modified-1.0.1.js (c) Recurity Labs GmbH, Kenji Urushimma | github.com/openpgpjs/openpgpjs/blob/master/LICENSE
|
||||
*/
|
||||
/*
|
||||
* dsa-modified.js - modified DSA class of OpenPGP-JS
|
||||
*
|
||||
* Copyright (c) 2011-2013 Recurity Labs GmbH (github.com/openpgpjs)
|
||||
* Kenji Urushima (kenji.urushima@gmail.com)
|
||||
* LICENSE
|
||||
* https://github.com/openpgpjs/openpgpjs/blob/master/LICENSE
|
||||
*/
|
||||
|
||||
/**
|
||||
* @fileOverview
|
||||
* @name dsa-modified-1.0.js
|
||||
* @author Recurity Labs GmbH (github.com/openpgpjs) and Kenji Urushima (kenji.urushima@gmail.com)
|
||||
* @version 1.0.1 (2013-Oct-06)
|
||||
* @since jsrsasign 4.1.6
|
||||
* @license <a href="https://github.com/openpgpjs/openpgpjs/blob/master/LICENSE">LGPL License</a>
|
||||
*/
|
||||
|
||||
if (typeof KJUR == "undefined" || !KJUR) KJUR = {};
|
||||
if (typeof KJUR.crypto == "undefined" || !KJUR.crypto) KJUR.crypto = {};
|
||||
|
||||
/**
|
||||
* class for DSA signing and verification
|
||||
* @name KJUR.crypto.DSA
|
||||
* @class class for DSA signing and verifcation
|
||||
* @description
|
||||
* <p>
|
||||
* CAUTION: Most of the case, you don't need to use this class.
|
||||
* Please use {@link KJUR.crypto.Signature} class instead.
|
||||
* </p>
|
||||
* <p>
|
||||
* This class was originally developped by Recurity Labs GmbH for OpenPGP JavaScript library.
|
||||
* (See {@link https://github.com/openpgpjs/openpgpjs/blob/master/src/ciphers/asymmetric/dsa.js})
|
||||
* </p>
|
||||
*/
|
||||
/* https://github.com/openpgpjs/openpgpjs/blob/master/src/ciphers/asymmetric/dsa.js */
|
||||
KJUR.crypto.DSA = function() {
|
||||
this.p = null;
|
||||
this.q = null;
|
||||
this.g = null;
|
||||
this.y = null;
|
||||
this.x = null;
|
||||
this.type = "DSA";
|
||||
|
||||
//===========================
|
||||
// PUBLIC METHODS
|
||||
//===========================
|
||||
|
||||
/**
|
||||
* set DSA private key by key specs
|
||||
* @name setPrivate
|
||||
* @memberOf KJUR.crypto.DSA
|
||||
* @function
|
||||
* @param {BigInteger} p prime P
|
||||
* @param {BigInteger} q sub prime Q
|
||||
* @param {BigInteger} g base G
|
||||
* @param {BigInteger} y public key Y
|
||||
* @param {BigInteger} x private key X
|
||||
* @since dsa-modified 1.0.0
|
||||
*/
|
||||
this.setPrivate = function(p, q, g, y, x) {
|
||||
this.isPrivate = true;
|
||||
this.p = p;
|
||||
this.q = q;
|
||||
this.g = g;
|
||||
this.y = y;
|
||||
this.x = x;
|
||||
};
|
||||
|
||||
/**
|
||||
* set DSA public key by key specs
|
||||
* @name setPublic
|
||||
* @memberOf KJUR.crypto.DSA
|
||||
* @function
|
||||
* @param {BigInteger} p prime P
|
||||
* @param {BigInteger} q sub prime Q
|
||||
* @param {BigInteger} g base G
|
||||
* @param {BigInteger} y public key Y
|
||||
* @since dsa-modified 1.0.0
|
||||
*/
|
||||
this.setPublic = function(p, q, g, y) {
|
||||
this.isPublic = true;
|
||||
this.p = p;
|
||||
this.q = q;
|
||||
this.g = g;
|
||||
this.y = y;
|
||||
this.x = null;
|
||||
};
|
||||
|
||||
/**
|
||||
* sign to hashed message by this DSA private key object
|
||||
* @name signWithMessageHash
|
||||
* @memberOf KJUR.crypto.DSA
|
||||
* @function
|
||||
* @param {String} sHashHex hexadecimal string of hashed message
|
||||
* @return {String} hexadecimal string of ASN.1 encoded DSA signature value
|
||||
* @since dsa-modified 1.0.0
|
||||
*/
|
||||
this.signWithMessageHash = function(sHashHex) {
|
||||
var p = this.p;
|
||||
var q = this.q;
|
||||
var g = this.g;
|
||||
var y = this.y;
|
||||
var x = this.x;
|
||||
|
||||
// 1. trim message hash
|
||||
var hashHex = sHashHex.substr(0, q.bitLength() / 4);
|
||||
var hash = new BigInteger(sHashHex, 16);
|
||||
|
||||
var k = getRandomBigIntegerInRange(BigInteger.ONE.add(BigInteger.ONE),
|
||||
q.subtract(BigInteger.ONE));
|
||||
var s1 = (g.modPow(k,p)).mod(q);
|
||||
var s2 = (k.modInverse(q).multiply(hash.add(x.multiply(s1)))).mod(q);
|
||||
|
||||
var result = KJUR.asn1.ASN1Util.jsonToASN1HEX({
|
||||
'seq': [{'int': {'bigint': s1}}, {'int': {'bigint': s2}}]
|
||||
});
|
||||
return result;
|
||||
};
|
||||
|
||||
/**
|
||||
* verify signature by this DSA public key object
|
||||
* @name verifyWithMessageHash
|
||||
* @memberOf KJUR.crypto.DSA
|
||||
* @function
|
||||
* @param {String} sHashHex hexadecimal string of hashed message
|
||||
* @param {String} hSigVal hexadecimal string of ASN.1 encoded DSA signature value
|
||||
* @return {Boolean} true if the signature is valid otherwise false.
|
||||
* @since dsa-modified 1.0.0
|
||||
*/
|
||||
this.verifyWithMessageHash = function(sHashHex, hSigVal) {
|
||||
var p = this.p;
|
||||
var q = this.q;
|
||||
var g = this.g;
|
||||
var y = this.y;
|
||||
|
||||
// 1. parse ASN.1 signature
|
||||
var s1s2 = this.parseASN1Signature(hSigVal);
|
||||
var s1 = s1s2[0];
|
||||
var s2 = s1s2[1];
|
||||
|
||||
// 2. trim message hash
|
||||
var sHashHex = sHashHex.substr(0, q.bitLength() / 4);
|
||||
var hash = new BigInteger(sHashHex, 16);
|
||||
|
||||
if (BigInteger.ZERO.compareTo(s1) > 0 ||
|
||||
s1.compareTo(q) > 0 ||
|
||||
BigInteger.ZERO.compareTo(s2) > 0 ||
|
||||
s2.compareTo(q) > 0) {
|
||||
throw "invalid DSA signature";
|
||||
}
|
||||
var w = s2.modInverse(q);
|
||||
var u1 = hash.multiply(w).mod(q);
|
||||
var u2 = s1.multiply(w).mod(q);
|
||||
var dopublic = g.modPow(u1,p).multiply(y.modPow(u2,p)).mod(p).mod(q);
|
||||
return dopublic.compareTo(s1) == 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* parse hexadecimal ASN.1 DSA signature value
|
||||
* @name parseASN1Signature
|
||||
* @memberOf KJUR.crypto.DSA
|
||||
* @function
|
||||
* @param {String} hSigVal hexadecimal string of ASN.1 encoded DSA signature value
|
||||
* @return {Array} array [s1, s2] of DSA signature value. Both s1 and s2 are BigInteger.
|
||||
* @since dsa-modified 1.0.0
|
||||
*/
|
||||
this.parseASN1Signature = function(hSigVal) {
|
||||
try {
|
||||
var s1 = new BigInteger(ASN1HEX.getVbyList(hSigVal, 0, [0], "02"), 16);
|
||||
var s2 = new BigInteger(ASN1HEX.getVbyList(hSigVal, 0, [1], "02"), 16);
|
||||
return [s1, s2];
|
||||
} catch (ex) {
|
||||
throw "malformed DSA signature";
|
||||
}
|
||||
}
|
||||
|
||||
// s1 = ((g**s) mod p) mod q
|
||||
// s1 = ((s**-1)*(sha-1(m)+(s1*x) mod q)
|
||||
function sign(hashalgo, m, g, p, q, x) {
|
||||
// If the output size of the chosen hash is larger than the number of
|
||||
// bits of q, the hash result is truncated to fit by taking the number
|
||||
// of leftmost bits equal to the number of bits of q. This (possibly
|
||||
// truncated) hash function result is treated as a number and used
|
||||
// directly in the DSA signature algorithm.
|
||||
|
||||
var hashHex = KJUR.crypto.Util.hashString(m, hashalgo.toLowerCase());
|
||||
var hashHex = hashHex.substr(0, q.bitLength() / 4);
|
||||
var hash = new BigInteger(hashHex, 16);
|
||||
|
||||
var k = getRandomBigIntegerInRange(BigInteger.ONE.add(BigInteger.ONE),
|
||||
q.subtract(BigInteger.ONE));
|
||||
var s1 = (g.modPow(k,p)).mod(q);
|
||||
var s2 = (k.modInverse(q).multiply(hash.add(x.multiply(s1)))).mod(q);
|
||||
var result = new Array();
|
||||
result[0] = s1;
|
||||
result[1] = s2;
|
||||
return result;
|
||||
}
|
||||
|
||||
function select_hash_algorithm(q) {
|
||||
var usersetting = openpgp.config.config.prefer_hash_algorithm;
|
||||
/*
|
||||
* 1024-bit key, 160-bit q, SHA-1, SHA-224, SHA-256, SHA-384, or SHA-512 hash
|
||||
* 2048-bit key, 224-bit q, SHA-224, SHA-256, SHA-384, or SHA-512 hash
|
||||
* 2048-bit key, 256-bit q, SHA-256, SHA-384, or SHA-512 hash
|
||||
* 3072-bit key, 256-bit q, SHA-256, SHA-384, or SHA-512 hash
|
||||
*/
|
||||
switch (Math.round(q.bitLength() / 8)) {
|
||||
case 20: // 1024 bit
|
||||
if (usersetting != 2 &&
|
||||
usersetting > 11 &&
|
||||
usersetting != 10 &&
|
||||
usersetting < 8)
|
||||
return 2; // prefer sha1
|
||||
return usersetting;
|
||||
case 28: // 2048 bit
|
||||
if (usersetting > 11 &&
|
||||
usersetting < 8)
|
||||
return 11;
|
||||
return usersetting;
|
||||
case 32: // 4096 bit // prefer sha224
|
||||
if (usersetting > 10 &&
|
||||
usersetting < 8)
|
||||
return 8; // prefer sha256
|
||||
return usersetting;
|
||||
default:
|
||||
util.print_debug("DSA select hash algorithm: returning null for an unknown length of q");
|
||||
return null;
|
||||
|
||||
}
|
||||
}
|
||||
this.select_hash_algorithm = select_hash_algorithm;
|
||||
|
||||
function verify(hashalgo, s1,s2,m,p,q,g,y) {
|
||||
var hashHex = KJUR.crypto.Util.hashString(m, hashalgo.toLowerCase());
|
||||
var hashHex = hashHex.substr(0, q.bitLength() / 4);
|
||||
var hash = new BigInteger(hashHex, 16);
|
||||
|
||||
if (BigInteger.ZERO.compareTo(s1) > 0 ||
|
||||
s1.compareTo(q) > 0 ||
|
||||
BigInteger.ZERO.compareTo(s2) > 0 ||
|
||||
s2.compareTo(q) > 0) {
|
||||
util.print_error("invalid DSA Signature");
|
||||
return null;
|
||||
}
|
||||
var w = s2.modInverse(q);
|
||||
var u1 = hash.multiply(w).mod(q);
|
||||
var u2 = s1.multiply(w).mod(q);
|
||||
var dopublic = g.modPow(u1,p).multiply(y.modPow(u2,p)).mod(p).mod(q);
|
||||
return dopublic.compareTo(s1) == 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* unused code. This can be used as a start to write a key generator
|
||||
* function.
|
||||
*/
|
||||
function generateKey(bitcount) {
|
||||
var qi = new BigInteger(bitcount, primeCenterie);
|
||||
var pi = generateP(q, 512);
|
||||
var gi = generateG(p, q, bitcount);
|
||||
var xi;
|
||||
do {
|
||||
xi = new BigInteger(q.bitCount(), rand);
|
||||
} while (x.compareTo(BigInteger.ZERO) != 1 && x.compareTo(q) != -1);
|
||||
var yi = g.modPow(x, p);
|
||||
return {x: xi, q: qi, p: pi, g: gi, y: yi};
|
||||
}
|
||||
|
||||
function generateP(q, bitlength, randomfn) {
|
||||
if (bitlength % 64 != 0) {
|
||||
return false;
|
||||
}
|
||||
var pTemp;
|
||||
var pTemp2;
|
||||
do {
|
||||
pTemp = randomfn(bitcount, true);
|
||||
pTemp2 = pTemp.subtract(BigInteger.ONE);
|
||||
pTemp = pTemp.subtract(pTemp2.remainder(q));
|
||||
} while (!pTemp.isProbablePrime(primeCenterie) || pTemp.bitLength() != l);
|
||||
return pTemp;
|
||||
}
|
||||
|
||||
function generateG(p, q, bitlength, randomfn) {
|
||||
var aux = p.subtract(BigInteger.ONE);
|
||||
var pow = aux.divide(q);
|
||||
var gTemp;
|
||||
do {
|
||||
gTemp = randomfn(bitlength);
|
||||
} while (gTemp.compareTo(aux) != -1 && gTemp.compareTo(BigInteger.ONE) != 1);
|
||||
return gTemp.modPow(pow, p);
|
||||
}
|
||||
|
||||
function generateK(q, bitlength, randomfn) {
|
||||
var tempK;
|
||||
do {
|
||||
tempK = randomfn(bitlength, false);
|
||||
} while (tempK.compareTo(q) != -1 && tempK.compareTo(BigInteger.ZERO) != 1);
|
||||
return tempK;
|
||||
}
|
||||
|
||||
function generateR(q,p) {
|
||||
k = generateK(q);
|
||||
var r = g.modPow(k, p).mod(q);
|
||||
return r;
|
||||
}
|
||||
|
||||
function generateS(hashfn,k,r,m,q,x) {
|
||||
var hash = hashfn(m);
|
||||
s = (k.modInverse(q).multiply(hash.add(x.multiply(r)))).mod(q);
|
||||
return s;
|
||||
}
|
||||
this.sign = sign;
|
||||
this.verify = verify;
|
||||
// this.generate = generateKey;
|
||||
|
||||
//
|
||||
// METHODS FROM
|
||||
// https://github.com/openpgpjs/openpgpjs/blob/master/src/ciphers/openpgp.crypto.js
|
||||
//
|
||||
function getRandomBigIntegerInRange(min, max) {
|
||||
if (max.compareTo(min) <= 0)
|
||||
return;
|
||||
var range = max.subtract(min);
|
||||
var r = getRandomBigInteger(range.bitLength());
|
||||
while (r > range) {
|
||||
r = getRandomBigInteger(range.bitLength());
|
||||
}
|
||||
return min.add(r);
|
||||
}
|
||||
|
||||
function getRandomBigInteger(bits) {
|
||||
if (bits < 0)
|
||||
return null;
|
||||
var numBytes = Math.floor((bits+7)/8);
|
||||
|
||||
var randomBits = getRandomBytes(numBytes);
|
||||
if (bits % 8 > 0) {
|
||||
randomBits = String.fromCharCode((Math.pow(2,bits % 8)-1) &
|
||||
randomBits.charCodeAt(0)) +
|
||||
randomBits.substring(1);
|
||||
}
|
||||
return new BigInteger(hexstrdump(randomBits), 16);
|
||||
}
|
||||
|
||||
function getRandomBytes(length) {
|
||||
var result = '';
|
||||
for (var i = 0; i < length; i++) {
|
||||
result += String.fromCharCode(getSecureRandomOctet());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
function getSecureRandomOctet() {
|
||||
var buf = new Uint32Array(1);
|
||||
window.crypto.getRandomValues(buf);
|
||||
return buf[0] & 0xFF;
|
||||
}
|
||||
|
||||
// https://github.com/openpgpjs/openpgpjs/blob/master/src/util/util.js
|
||||
function hexstrdump(str) {
|
||||
if (str == null)
|
||||
return "";
|
||||
var r=[];
|
||||
var e=str.length;
|
||||
var c=0;
|
||||
var h;
|
||||
while(c<e){
|
||||
h=str[c++].charCodeAt().toString(16);
|
||||
while(h.length<2) h="0"+h;
|
||||
r.push(""+h);
|
||||
}
|
||||
return r.join('');
|
||||
}
|
||||
|
||||
this.getRandomBigIntegerInRange = getRandomBigIntegerInRange;
|
||||
this.getRandomBigInteger = getRandomBigInteger;
|
||||
this.getRandomBytes = getRandomBytes;
|
||||
}
|
@ -1,608 +0,0 @@
|
||||
/*! ecdsa-modified-1.0.4.js (c) Stephan Thomas, Kenji Urushima | github.com/bitcoinjs/bitcoinjs-lib/blob/master/LICENSE
|
||||
*/
|
||||
/*
|
||||
* ecdsa-modified.js - modified Bitcoin.ECDSA class
|
||||
*
|
||||
* Copyright (c) 2013 Stefan Thomas (github.com/justmoon)
|
||||
* Kenji Urushima (kenji.urushima@gmail.com)
|
||||
* LICENSE
|
||||
* https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/LICENSE
|
||||
*/
|
||||
|
||||
/**
|
||||
* @fileOverview
|
||||
* @name ecdsa-modified-1.0.js
|
||||
* @author Stefan Thomas (github.com/justmoon) and Kenji Urushima (kenji.urushima@gmail.com)
|
||||
* @version 1.0.4 (2013-Oct-06)
|
||||
* @since jsrsasign 4.0
|
||||
* @license <a href="https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/LICENSE">MIT License</a>
|
||||
*/
|
||||
|
||||
if (typeof KJUR == "undefined" || !KJUR) KJUR = {};
|
||||
if (typeof KJUR.crypto == "undefined" || !KJUR.crypto) KJUR.crypto = {};
|
||||
|
||||
/**
|
||||
* class for EC key generation, ECDSA signing and verifcation
|
||||
* @name KJUR.crypto.ECDSA
|
||||
* @class class for EC key generation, ECDSA signing and verifcation
|
||||
* @description
|
||||
* <p>
|
||||
* CAUTION: Most of the case, you don't need to use this class except
|
||||
* for generating an EC key pair. Please use {@link KJUR.crypto.Signature} class instead.
|
||||
* </p>
|
||||
* <p>
|
||||
* This class was originally developped by Stefan Thomas for Bitcoin JavaScript library.
|
||||
* (See {@link https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/src/ecdsa.js})
|
||||
* Currently this class supports following named curves and their aliases.
|
||||
* <ul>
|
||||
* <li>secp256r1, NIST P-256, P-256, prime256v1 (*)</li>
|
||||
* <li>secp256k1 (*)</li>
|
||||
* <li>secp384r1, NIST P-384, P-384 (*)</li>
|
||||
* </ul>
|
||||
* </p>
|
||||
*/
|
||||
KJUR.crypto.ECDSA = function(params) {
|
||||
var curveName = "secp256r1"; // curve name default
|
||||
var ecparams = null;
|
||||
var prvKeyHex = null;
|
||||
var pubKeyHex = null;
|
||||
|
||||
var rng = new SecureRandom();
|
||||
|
||||
var P_OVER_FOUR = null;
|
||||
|
||||
this.type = "EC";
|
||||
|
||||
function implShamirsTrick(P, k, Q, l) {
|
||||
var m = Math.max(k.bitLength(), l.bitLength());
|
||||
var Z = P.add2D(Q);
|
||||
var R = P.curve.getInfinity();
|
||||
|
||||
for (var i = m - 1; i >= 0; --i) {
|
||||
R = R.twice2D();
|
||||
|
||||
R.z = BigInteger.ONE;
|
||||
|
||||
if (k.testBit(i)) {
|
||||
if (l.testBit(i)) {
|
||||
R = R.add2D(Z);
|
||||
} else {
|
||||
R = R.add2D(P);
|
||||
}
|
||||
} else {
|
||||
if (l.testBit(i)) {
|
||||
R = R.add2D(Q);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return R;
|
||||
};
|
||||
|
||||
//===========================
|
||||
// PUBLIC METHODS
|
||||
//===========================
|
||||
this.getBigRandom = function (limit) {
|
||||
return new BigInteger(limit.bitLength(), rng)
|
||||
.mod(limit.subtract(BigInteger.ONE))
|
||||
.add(BigInteger.ONE)
|
||||
;
|
||||
};
|
||||
|
||||
this.setNamedCurve = function(curveName) {
|
||||
this.ecparams = KJUR.crypto.ECParameterDB.getByName(curveName);
|
||||
this.prvKeyHex = null;
|
||||
this.pubKeyHex = null;
|
||||
this.curveName = curveName;
|
||||
}
|
||||
|
||||
this.setPrivateKeyHex = function(prvKeyHex) {
|
||||
this.isPrivate = true;
|
||||
this.prvKeyHex = prvKeyHex;
|
||||
}
|
||||
|
||||
this.setPublicKeyHex = function(pubKeyHex) {
|
||||
this.isPublic = true;
|
||||
this.pubKeyHex = pubKeyHex;
|
||||
}
|
||||
|
||||
/**
|
||||
* generate a EC key pair
|
||||
* @name generateKeyPairHex
|
||||
* @memberOf KJUR.crypto.ECDSA
|
||||
* @function
|
||||
* @return {Array} associative array of hexadecimal string of private and public key
|
||||
* @since ecdsa-modified 1.0.1
|
||||
* @example
|
||||
* var ec = new KJUR.crypto.ECDSA({'curve': 'secp256r1'});
|
||||
* var keypair = ec.generateKeyPairHex();
|
||||
* var pubhex = keypair.ecpubhex; // hexadecimal string of EC private key (=d)
|
||||
* var prvhex = keypair.ecprvhex; // hexadecimal string of EC public key
|
||||
*/
|
||||
this.generateKeyPairHex = function() {
|
||||
var biN = this.ecparams['n'];
|
||||
var biPrv = this.getBigRandom(biN);
|
||||
var epPub = this.ecparams['G'].multiply(biPrv);
|
||||
var biX = epPub.getX().toBigInteger();
|
||||
var biY = epPub.getY().toBigInteger();
|
||||
|
||||
var charlen = this.ecparams['keylen'] / 4;
|
||||
var hPrv = ("0000000000" + biPrv.toString(16)).slice(- charlen);
|
||||
var hX = ("0000000000" + biX.toString(16)).slice(- charlen);
|
||||
var hY = ("0000000000" + biY.toString(16)).slice(- charlen);
|
||||
var hPub = "04" + hX + hY;
|
||||
|
||||
this.setPrivateKeyHex(hPrv);
|
||||
this.setPublicKeyHex(hPub);
|
||||
return {'ecprvhex': hPrv, 'ecpubhex': hPub};
|
||||
};
|
||||
|
||||
this.signWithMessageHash = function(hashHex) {
|
||||
return this.signHex(hashHex, this.prvKeyHex);
|
||||
};
|
||||
|
||||
/**
|
||||
* signing to message hash
|
||||
* @name signHex
|
||||
* @memberOf KJUR.crypto.ECDSA
|
||||
* @function
|
||||
* @param {String} hashHex hexadecimal string of hash value of signing message
|
||||
* @param {String} privHex hexadecimal string of EC private key
|
||||
* @return {String} hexadecimal string of ECDSA signature
|
||||
* @since ecdsa-modified 1.0.1
|
||||
* @example
|
||||
* var ec = new KJUR.crypto.ECDSA({'curve': 'secp256r1'});
|
||||
* var sigValue = ec.signHex(hash, prvKey);
|
||||
*/
|
||||
this.signHex = function (hashHex, privHex) {
|
||||
var d = new BigInteger(privHex, 16);
|
||||
var n = this.ecparams['n'];
|
||||
var e = new BigInteger(hashHex, 16);
|
||||
|
||||
do {
|
||||
var k = this.getBigRandom(n);
|
||||
var G = this.ecparams['G'];
|
||||
var Q = G.multiply(k);
|
||||
var r = Q.getX().toBigInteger().mod(n);
|
||||
} while (r.compareTo(BigInteger.ZERO) <= 0);
|
||||
|
||||
var s = k.modInverse(n).multiply(e.add(d.multiply(r))).mod(n);
|
||||
|
||||
return KJUR.crypto.ECDSA.biRSSigToASN1Sig(r, s);
|
||||
};
|
||||
|
||||
this.sign = function (hash, priv) {
|
||||
var d = priv;
|
||||
var n = this.ecparams['n'];
|
||||
var e = BigInteger.fromByteArrayUnsigned(hash);
|
||||
|
||||
do {
|
||||
var k = this.getBigRandom(n);
|
||||
var G = this.ecparams['G'];
|
||||
var Q = G.multiply(k);
|
||||
var r = Q.getX().toBigInteger().mod(n);
|
||||
} while (r.compareTo(BigInteger.ZERO) <= 0);
|
||||
|
||||
var s = k.modInverse(n).multiply(e.add(d.multiply(r))).mod(n);
|
||||
return this.serializeSig(r, s);
|
||||
};
|
||||
|
||||
this.verifyWithMessageHash = function(hashHex, sigHex) {
|
||||
return this.verifyHex(hashHex, sigHex, this.pubKeyHex);
|
||||
};
|
||||
|
||||
/**
|
||||
* verifying signature with message hash and public key
|
||||
* @name verifyHex
|
||||
* @memberOf KJUR.crypto.ECDSA
|
||||
* @function
|
||||
* @param {String} hashHex hexadecimal string of hash value of signing message
|
||||
* @param {String} sigHex hexadecimal string of signature value
|
||||
* @param {String} pubkeyHex hexadecimal string of public key
|
||||
* @return {Boolean} true if the signature is valid, otherwise false
|
||||
* @since ecdsa-modified 1.0.1
|
||||
* @example
|
||||
* var ec = new KJUR.crypto.ECDSA({'curve': 'secp256r1'});
|
||||
* var result = ec.verifyHex(msgHashHex, sigHex, pubkeyHex);
|
||||
*/
|
||||
this.verifyHex = function(hashHex, sigHex, pubkeyHex) {
|
||||
var r,s;
|
||||
|
||||
var obj = KJUR.crypto.ECDSA.parseSigHex(sigHex);
|
||||
r = obj.r;
|
||||
s = obj.s;
|
||||
|
||||
var Q;
|
||||
Q = ECPointFp.decodeFromHex(this.ecparams['curve'], pubkeyHex);
|
||||
var e = new BigInteger(hashHex, 16);
|
||||
|
||||
return this.verifyRaw(e, r, s, Q);
|
||||
};
|
||||
|
||||
this.verify = function (hash, sig, pubkey) {
|
||||
var r,s;
|
||||
if (Bitcoin.Util.isArray(sig)) {
|
||||
var obj = this.parseSig(sig);
|
||||
r = obj.r;
|
||||
s = obj.s;
|
||||
} else if ("object" === typeof sig && sig.r && sig.s) {
|
||||
r = sig.r;
|
||||
s = sig.s;
|
||||
} else {
|
||||
throw "Invalid value for signature";
|
||||
}
|
||||
|
||||
var Q;
|
||||
if (pubkey instanceof ECPointFp) {
|
||||
Q = pubkey;
|
||||
} else if (Bitcoin.Util.isArray(pubkey)) {
|
||||
Q = ECPointFp.decodeFrom(this.ecparams['curve'], pubkey);
|
||||
} else {
|
||||
throw "Invalid format for pubkey value, must be byte array or ECPointFp";
|
||||
}
|
||||
var e = BigInteger.fromByteArrayUnsigned(hash);
|
||||
|
||||
return this.verifyRaw(e, r, s, Q);
|
||||
};
|
||||
|
||||
this.verifyRaw = function (e, r, s, Q) {
|
||||
var n = this.ecparams['n'];
|
||||
var G = this.ecparams['G'];
|
||||
|
||||
if (r.compareTo(BigInteger.ONE) < 0 ||
|
||||
r.compareTo(n) >= 0)
|
||||
return false;
|
||||
|
||||
if (s.compareTo(BigInteger.ONE) < 0 ||
|
||||
s.compareTo(n) >= 0)
|
||||
return false;
|
||||
|
||||
var c = s.modInverse(n);
|
||||
|
||||
var u1 = e.multiply(c).mod(n);
|
||||
var u2 = r.multiply(c).mod(n);
|
||||
|
||||
// TODO(!!!): For some reason Shamir's trick isn't working with
|
||||
// signed message verification!? Probably an implementation
|
||||
// error!
|
||||
//var point = implShamirsTrick(G, u1, Q, u2);
|
||||
var point = G.multiply(u1).add(Q.multiply(u2));
|
||||
|
||||
var v = point.getX().toBigInteger().mod(n);
|
||||
|
||||
return v.equals(r);
|
||||
};
|
||||
|
||||
/**
|
||||
* Serialize a signature into DER format.
|
||||
*
|
||||
* Takes two BigIntegers representing r and s and returns a byte array.
|
||||
*/
|
||||
this.serializeSig = function (r, s) {
|
||||
var rBa = r.toByteArraySigned();
|
||||
var sBa = s.toByteArraySigned();
|
||||
|
||||
var sequence = [];
|
||||
sequence.push(0x02); // INTEGER
|
||||
sequence.push(rBa.length);
|
||||
sequence = sequence.concat(rBa);
|
||||
|
||||
sequence.push(0x02); // INTEGER
|
||||
sequence.push(sBa.length);
|
||||
sequence = sequence.concat(sBa);
|
||||
|
||||
sequence.unshift(sequence.length);
|
||||
sequence.unshift(0x30); // SEQUENCE
|
||||
return sequence;
|
||||
};
|
||||
|
||||
/**
|
||||
* Parses a byte array containing a DER-encoded signature.
|
||||
*
|
||||
* This function will return an object of the form:
|
||||
*
|
||||
* {
|
||||
* r: BigInteger,
|
||||
* s: BigInteger
|
||||
* }
|
||||
*/
|
||||
this.parseSig = function (sig) {
|
||||
var cursor;
|
||||
if (sig[0] != 0x30)
|
||||
throw new Error("Signature not a valid DERSequence");
|
||||
|
||||
cursor = 2;
|
||||
if (sig[cursor] != 0x02)
|
||||
throw new Error("First element in signature must be a DERInteger");;
|
||||
var rBa = sig.slice(cursor+2, cursor+2+sig[cursor+1]);
|
||||
|
||||
cursor += 2+sig[cursor+1];
|
||||
if (sig[cursor] != 0x02)
|
||||
throw new Error("Second element in signature must be a DERInteger");
|
||||
var sBa = sig.slice(cursor+2, cursor+2+sig[cursor+1]);
|
||||
|
||||
cursor += 2+sig[cursor+1];
|
||||
|
||||
//if (cursor != sig.length)
|
||||
// throw new Error("Extra bytes in signature");
|
||||
|
||||
var r = BigInteger.fromByteArrayUnsigned(rBa);
|
||||
var s = BigInteger.fromByteArrayUnsigned(sBa);
|
||||
|
||||
return {r: r, s: s};
|
||||
};
|
||||
|
||||
this.parseSigCompact = function (sig) {
|
||||
if (sig.length !== 65) {
|
||||
throw "Signature has the wrong length";
|
||||
}
|
||||
|
||||
// Signature is prefixed with a type byte storing three bits of
|
||||
// information.
|
||||
var i = sig[0] - 27;
|
||||
if (i < 0 || i > 7) {
|
||||
throw "Invalid signature type";
|
||||
}
|
||||
|
||||
var n = this.ecparams['n'];
|
||||
var r = BigInteger.fromByteArrayUnsigned(sig.slice(1, 33)).mod(n);
|
||||
var s = BigInteger.fromByteArrayUnsigned(sig.slice(33, 65)).mod(n);
|
||||
|
||||
return {r: r, s: s, i: i};
|
||||
};
|
||||
|
||||
/*
|
||||
* Recover a public key from a signature.
|
||||
*
|
||||
* See SEC 1: Elliptic Curve Cryptography, section 4.1.6, "Public
|
||||
* Key Recovery Operation".
|
||||
*
|
||||
* http://www.secg.org/download/aid-780/sec1-v2.pdf
|
||||
*/
|
||||
/*
|
||||
recoverPubKey: function (r, s, hash, i) {
|
||||
// The recovery parameter i has two bits.
|
||||
i = i & 3;
|
||||
|
||||
// The less significant bit specifies whether the y coordinate
|
||||
// of the compressed point is even or not.
|
||||
var isYEven = i & 1;
|
||||
|
||||
// The more significant bit specifies whether we should use the
|
||||
// first or second candidate key.
|
||||
var isSecondKey = i >> 1;
|
||||
|
||||
var n = this.ecparams['n'];
|
||||
var G = this.ecparams['G'];
|
||||
var curve = this.ecparams['curve'];
|
||||
var p = curve.getQ();
|
||||
var a = curve.getA().toBigInteger();
|
||||
var b = curve.getB().toBigInteger();
|
||||
|
||||
// We precalculate (p + 1) / 4 where p is if the field order
|
||||
if (!P_OVER_FOUR) {
|
||||
P_OVER_FOUR = p.add(BigInteger.ONE).divide(BigInteger.valueOf(4));
|
||||
}
|
||||
|
||||
// 1.1 Compute x
|
||||
var x = isSecondKey ? r.add(n) : r;
|
||||
|
||||
// 1.3 Convert x to point
|
||||
var alpha = x.multiply(x).multiply(x).add(a.multiply(x)).add(b).mod(p);
|
||||
var beta = alpha.modPow(P_OVER_FOUR, p);
|
||||
|
||||
var xorOdd = beta.isEven() ? (i % 2) : ((i+1) % 2);
|
||||
// If beta is even, but y isn't or vice versa, then convert it,
|
||||
// otherwise we're done and y == beta.
|
||||
var y = (beta.isEven() ? !isYEven : isYEven) ? beta : p.subtract(beta);
|
||||
|
||||
// 1.4 Check that nR is at infinity
|
||||
var R = new ECPointFp(curve,
|
||||
curve.fromBigInteger(x),
|
||||
curve.fromBigInteger(y));
|
||||
R.validate();
|
||||
|
||||
// 1.5 Compute e from M
|
||||
var e = BigInteger.fromByteArrayUnsigned(hash);
|
||||
var eNeg = BigInteger.ZERO.subtract(e).mod(n);
|
||||
|
||||
// 1.6 Compute Q = r^-1 (sR - eG)
|
||||
var rInv = r.modInverse(n);
|
||||
var Q = implShamirsTrick(R, s, G, eNeg).multiply(rInv);
|
||||
|
||||
Q.validate();
|
||||
if (!this.verifyRaw(e, r, s, Q)) {
|
||||
throw "Pubkey recovery unsuccessful";
|
||||
}
|
||||
|
||||
var pubKey = new Bitcoin.ECKey();
|
||||
pubKey.pub = Q;
|
||||
return pubKey;
|
||||
},
|
||||
*/
|
||||
|
||||
/*
|
||||
* Calculate pubkey extraction parameter.
|
||||
*
|
||||
* When extracting a pubkey from a signature, we have to
|
||||
* distinguish four different cases. Rather than putting this
|
||||
* burden on the verifier, Bitcoin includes a 2-bit value with the
|
||||
* signature.
|
||||
*
|
||||
* This function simply tries all four cases and returns the value
|
||||
* that resulted in a successful pubkey recovery.
|
||||
*/
|
||||
/*
|
||||
calcPubkeyRecoveryParam: function (address, r, s, hash) {
|
||||
for (var i = 0; i < 4; i++) {
|
||||
try {
|
||||
var pubkey = Bitcoin.ECDSA.recoverPubKey(r, s, hash, i);
|
||||
if (pubkey.getBitcoinAddress().toString() == address) {
|
||||
return i;
|
||||
}
|
||||
} catch (e) {}
|
||||
}
|
||||
throw "Unable to find valid recovery factor";
|
||||
}
|
||||
*/
|
||||
|
||||
if (params !== undefined) {
|
||||
if (params['curve'] !== undefined) {
|
||||
this.curveName = params['curve'];
|
||||
}
|
||||
}
|
||||
if (this.curveName === undefined) this.curveName = curveName;
|
||||
this.setNamedCurve(this.curveName);
|
||||
if (params !== undefined) {
|
||||
if (params['prv'] !== undefined) this.setPrivateKeyHex(params['prv']);
|
||||
if (params['pub'] !== undefined) this.setPublicKeyHex(params['pub']);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* parse ASN.1 DER encoded ECDSA signature
|
||||
* @name parseSigHex
|
||||
* @memberOf KJUR.crypto.ECDSA
|
||||
* @function
|
||||
* @static
|
||||
* @param {String} sigHex hexadecimal string of ECDSA signature value
|
||||
* @return {Array} associative array of signature field r and s of BigInteger
|
||||
* @since ecdsa-modified 1.0.1
|
||||
* @example
|
||||
* var ec = new KJUR.crypto.ECDSA({'curve': 'secp256r1'});
|
||||
* var sig = ec.parseSigHex('30...');
|
||||
* var biR = sig.r; // BigInteger object for 'r' field of signature.
|
||||
* var biS = sig.s; // BigInteger object for 's' field of signature.
|
||||
*/
|
||||
KJUR.crypto.ECDSA.parseSigHex = function(sigHex) {
|
||||
var p = KJUR.crypto.ECDSA.parseSigHexInHexRS(sigHex);
|
||||
var biR = new BigInteger(p.r, 16);
|
||||
var biS = new BigInteger(p.s, 16);
|
||||
|
||||
return {'r': biR, 's': biS};
|
||||
};
|
||||
|
||||
/**
|
||||
* parse ASN.1 DER encoded ECDSA signature
|
||||
* @name parseSigHexInHexRS
|
||||
* @memberOf KJUR.crypto.ECDSA
|
||||
* @function
|
||||
* @static
|
||||
* @param {String} sigHex hexadecimal string of ECDSA signature value
|
||||
* @return {Array} associative array of signature field r and s in hexadecimal
|
||||
* @since ecdsa-modified 1.0.3
|
||||
* @example
|
||||
* var ec = new KJUR.crypto.ECDSA({'curve': 'secp256r1'});
|
||||
* var sig = ec.parseSigHexInHexRS('30...');
|
||||
* var hR = sig.r; // hexadecimal string for 'r' field of signature.
|
||||
* var hS = sig.s; // hexadecimal string for 's' field of signature.
|
||||
*/
|
||||
KJUR.crypto.ECDSA.parseSigHexInHexRS = function(sigHex) {
|
||||
// 1. ASN.1 Sequence Check
|
||||
if (sigHex.substr(0, 2) != "30")
|
||||
throw "signature is not a ASN.1 sequence";
|
||||
|
||||
// 2. Items of ASN.1 Sequence Check
|
||||
var a = ASN1HEX.getPosArrayOfChildren_AtObj(sigHex, 0);
|
||||
if (a.length != 2)
|
||||
throw "number of signature ASN.1 sequence elements seem wrong";
|
||||
|
||||
// 3. Integer check
|
||||
var iTLV1 = a[0];
|
||||
var iTLV2 = a[1];
|
||||
if (sigHex.substr(iTLV1, 2) != "02")
|
||||
throw "1st item of sequene of signature is not ASN.1 integer";
|
||||
if (sigHex.substr(iTLV2, 2) != "02")
|
||||
throw "2nd item of sequene of signature is not ASN.1 integer";
|
||||
|
||||
// 4. getting value
|
||||
var hR = ASN1HEX.getHexOfV_AtObj(sigHex, iTLV1);
|
||||
var hS = ASN1HEX.getHexOfV_AtObj(sigHex, iTLV2);
|
||||
|
||||
return {'r': hR, 's': hS};
|
||||
};
|
||||
|
||||
/**
|
||||
* convert hexadecimal ASN.1 encoded signature to concatinated signature
|
||||
* @name asn1SigToConcatSig
|
||||
* @memberOf KJUR.crypto.ECDSA
|
||||
* @function
|
||||
* @static
|
||||
* @param {String} asn1Hex hexadecimal string of ASN.1 encoded ECDSA signature value
|
||||
* @return {String} r-s concatinated format of ECDSA signature value
|
||||
* @since ecdsa-modified 1.0.3
|
||||
*/
|
||||
KJUR.crypto.ECDSA.asn1SigToConcatSig = function(asn1Sig) {
|
||||
var pSig = KJUR.crypto.ECDSA.parseSigHexInHexRS(asn1Sig);
|
||||
var hR = pSig.r;
|
||||
var hS = pSig.s;
|
||||
|
||||
if (hR.substr(0, 2) == "00" && (((hR.length / 2) * 8) % (16 * 8)) == 8)
|
||||
hR = hR.substr(2);
|
||||
|
||||
if (hS.substr(0, 2) == "00" && (((hS.length / 2) * 8) % (16 * 8)) == 8)
|
||||
hS = hS.substr(2);
|
||||
|
||||
if ((((hR.length / 2) * 8) % (16 * 8)) != 0)
|
||||
throw "unknown ECDSA sig r length error";
|
||||
|
||||
if ((((hS.length / 2) * 8) % (16 * 8)) != 0)
|
||||
throw "unknown ECDSA sig s length error";
|
||||
|
||||
return hR + hS;
|
||||
};
|
||||
|
||||
/**
|
||||
* convert hexadecimal concatinated signature to ASN.1 encoded signature
|
||||
* @name concatSigToASN1Sig
|
||||
* @memberOf KJUR.crypto.ECDSA
|
||||
* @function
|
||||
* @static
|
||||
* @param {String} concatSig r-s concatinated format of ECDSA signature value
|
||||
* @return {String} hexadecimal string of ASN.1 encoded ECDSA signature value
|
||||
* @since ecdsa-modified 1.0.3
|
||||
*/
|
||||
KJUR.crypto.ECDSA.concatSigToASN1Sig = function(concatSig) {
|
||||
if ((((concatSig.length / 2) * 8) % (16 * 8)) != 0)
|
||||
throw "unknown ECDSA concatinated r-s sig length error";
|
||||
|
||||
var hR = concatSig.substr(0, concatSig.length / 2);
|
||||
var hS = concatSig.substr(concatSig.length / 2);
|
||||
return KJUR.crypto.ECDSA.hexRSSigToASN1Sig(hR, hS);
|
||||
};
|
||||
|
||||
/**
|
||||
* convert hexadecimal R and S value of signature to ASN.1 encoded signature
|
||||
* @name hexRSSigToASN1Sig
|
||||
* @memberOf KJUR.crypto.ECDSA
|
||||
* @function
|
||||
* @static
|
||||
* @param {String} hR hexadecimal string of R field of ECDSA signature value
|
||||
* @param {String} hS hexadecimal string of S field of ECDSA signature value
|
||||
* @return {String} hexadecimal string of ASN.1 encoded ECDSA signature value
|
||||
* @since ecdsa-modified 1.0.3
|
||||
*/
|
||||
KJUR.crypto.ECDSA.hexRSSigToASN1Sig = function(hR, hS) {
|
||||
var biR = new BigInteger(hR, 16);
|
||||
var biS = new BigInteger(hS, 16);
|
||||
return KJUR.crypto.ECDSA.biRSSigToASN1Sig(biR, biS);
|
||||
};
|
||||
|
||||
/**
|
||||
* convert R and S BigInteger object of signature to ASN.1 encoded signature
|
||||
* @name biRSSigToASN1Sig
|
||||
* @memberOf KJUR.crypto.ECDSA
|
||||
* @function
|
||||
* @static
|
||||
* @param {BigInteger} biR BigInteger object of R field of ECDSA signature value
|
||||
* @param {BigInteger} biS BIgInteger object of S field of ECDSA signature value
|
||||
* @return {String} hexadecimal string of ASN.1 encoded ECDSA signature value
|
||||
* @since ecdsa-modified 1.0.3
|
||||
*/
|
||||
KJUR.crypto.ECDSA.biRSSigToASN1Sig = function(biR, biS) {
|
||||
var derR = new KJUR.asn1.DERInteger({'bigint': biR});
|
||||
var derS = new KJUR.asn1.DERInteger({'bigint': biS});
|
||||
var derSeq = new KJUR.asn1.DERSequence({'array': [derR, derS]});
|
||||
return derSeq.getEncodedHex();
|
||||
};
|
||||
|
@ -1,248 +0,0 @@
|
||||
/*! ecparam-1.0.0.js (c) 2013 Kenji Urushima | kjur.github.com/jsrsasign/license
|
||||
*/
|
||||
/*
|
||||
* ecparam.js - Elliptic Curve Cryptography Curve Parameter Definition class
|
||||
*
|
||||
* Copyright (c) 2013 Kenji Urushima (kenji.urushima@gmail.com)
|
||||
*
|
||||
* This software is licensed under the terms of the MIT License.
|
||||
* http://kjur.github.com/jsrsasign/license
|
||||
*
|
||||
* The above copyright and license notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @fileOverview
|
||||
* @name ecparam-1.1.js
|
||||
* @author Kenji Urushima kenji.urushima@gmail.com
|
||||
* @version 1.0.0 (2013-Jul-17)
|
||||
* @since jsrsasign 4.0
|
||||
* @license <a href="http://kjur.github.io/jsrsasign/license/">MIT License</a>
|
||||
*/
|
||||
|
||||
if (typeof KJUR == "undefined" || !KJUR) KJUR = {};
|
||||
if (typeof KJUR.crypto == "undefined" || !KJUR.crypto) KJUR.crypto = {};
|
||||
|
||||
/**
|
||||
* static object for elliptic curve names and parameters
|
||||
* @name KJUR.crypto.ECParameterDB
|
||||
* @class static object for elliptic curve names and parameters
|
||||
* @description
|
||||
* This class provides parameters for named elliptic curves.
|
||||
* Currently it supoprts following curve names and aliases however
|
||||
* the name marked (*) are available for {@link KJUR.crypto.ECDSA} and
|
||||
* {@link KJUR.crypto.Signature} classes.
|
||||
* <ul>
|
||||
* <li>secp128r1</li>
|
||||
* <li>secp160r1</li>
|
||||
* <li>secp160k1</li>
|
||||
* <li>secp192r1</li>
|
||||
* <li>secp192k1</li>
|
||||
* <li>secp224r1</li>
|
||||
* <li>secp256r1, NIST P-256, P-256, prime256v1 (*)</li>
|
||||
* <li>secp256k1 (*)</li>
|
||||
* <li>secp384r1, NIST P-384, P-384 (*)</li>
|
||||
* <li>secp521r1, NIST P-521, P-521</li>
|
||||
* </ul>
|
||||
* You can register new curves by using 'register' method.
|
||||
*/
|
||||
KJUR.crypto.ECParameterDB = new function() {
|
||||
var db = {};
|
||||
var aliasDB = {};
|
||||
|
||||
function hex2bi(hex) {
|
||||
return new BigInteger(hex, 16);
|
||||
}
|
||||
|
||||
/**
|
||||
* get curve inforamtion associative array for curve name or alias
|
||||
* @name getByName
|
||||
* @memberOf KJUR.crypto.ECParameterDB
|
||||
* @function
|
||||
* @param {String} nameOrAlias curve name or alias name
|
||||
* @return {Array} associative array of curve parameters
|
||||
* @example
|
||||
* var param = KJUR.crypto.ECParameterDB.getByName('prime256v1');
|
||||
* var keylen = param['keylen'];
|
||||
* var n = param['n'];
|
||||
*/
|
||||
this.getByName = function(nameOrAlias) {
|
||||
var name = nameOrAlias;
|
||||
if (typeof aliasDB[name] != "undefined") {
|
||||
name = aliasDB[nameOrAlias];
|
||||
}
|
||||
if (typeof db[name] != "undefined") {
|
||||
return db[name];
|
||||
}
|
||||
throw "unregistered EC curve name: " + name;
|
||||
};
|
||||
|
||||
/**
|
||||
* register new curve
|
||||
* @name regist
|
||||
* @memberOf KJUR.crypto.ECParameterDB
|
||||
* @function
|
||||
* @param {String} name name of curve
|
||||
* @param {Integer} keylen key length
|
||||
* @param {String} pHex hexadecimal value of p
|
||||
* @param {String} aHex hexadecimal value of a
|
||||
* @param {String} bHex hexadecimal value of b
|
||||
* @param {String} nHex hexadecimal value of n
|
||||
* @param {String} hHex hexadecimal value of h
|
||||
* @param {String} gxHex hexadecimal value of Gx
|
||||
* @param {String} gyHex hexadecimal value of Gy
|
||||
* @param {Array} aliasList array of string for curve names aliases
|
||||
* @param {String} oid Object Identifier for the curve
|
||||
* @param {String} info information string for the curve
|
||||
*/
|
||||
this.regist = function(name, keylen, pHex, aHex, bHex, nHex, hHex, gxHex, gyHex, aliasList, oid, info) {
|
||||
db[name] = {};
|
||||
var p = hex2bi(pHex);
|
||||
var a = hex2bi(aHex);
|
||||
var b = hex2bi(bHex);
|
||||
var n = hex2bi(nHex);
|
||||
var h = hex2bi(hHex);
|
||||
var curve = new ECCurveFp(p, a, b);
|
||||
var G = curve.decodePointHex("04" + gxHex + gyHex);
|
||||
db[name]['name'] = name;
|
||||
db[name]['keylen'] = keylen;
|
||||
db[name]['curve'] = curve;
|
||||
db[name]['G'] = G;
|
||||
db[name]['n'] = n;
|
||||
db[name]['h'] = h;
|
||||
db[name]['oid'] = oid;
|
||||
db[name]['info'] = info;
|
||||
|
||||
for (var i = 0; i < aliasList.length; i++) {
|
||||
aliasDB[aliasList[i]] = name;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
KJUR.crypto.ECParameterDB.regist(
|
||||
"secp128r1", // name / p = 2^128 - 2^97 - 1
|
||||
128,
|
||||
"FFFFFFFDFFFFFFFFFFFFFFFFFFFFFFFF", // p
|
||||
"FFFFFFFDFFFFFFFFFFFFFFFFFFFFFFFC", // a
|
||||
"E87579C11079F43DD824993C2CEE5ED3", // b
|
||||
"FFFFFFFE0000000075A30D1B9038A115", // n
|
||||
"1", // h
|
||||
"161FF7528B899B2D0C28607CA52C5B86", // gx
|
||||
"CF5AC8395BAFEB13C02DA292DDED7A83", // gy
|
||||
[], // alias
|
||||
"", // oid (underconstruction)
|
||||
"secp128r1 : SECG curve over a 128 bit prime field"); // info
|
||||
|
||||
KJUR.crypto.ECParameterDB.regist(
|
||||
"secp160k1", // name / p = 2^160 - 2^32 - 2^14 - 2^12 - 2^9 - 2^8 - 2^7 - 2^3 - 2^2 - 1
|
||||
160,
|
||||
"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFAC73", // p
|
||||
"0", // a
|
||||
"7", // b
|
||||
"0100000000000000000001B8FA16DFAB9ACA16B6B3", // n
|
||||
"1", // h
|
||||
"3B4C382CE37AA192A4019E763036F4F5DD4D7EBB", // gx
|
||||
"938CF935318FDCED6BC28286531733C3F03C4FEE", // gy
|
||||
[], // alias
|
||||
"", // oid
|
||||
"secp160k1 : SECG curve over a 160 bit prime field"); // info
|
||||
|
||||
KJUR.crypto.ECParameterDB.regist(
|
||||
"secp160r1", // name / p = 2^160 - 2^31 - 1
|
||||
160,
|
||||
"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF7FFFFFFF", // p
|
||||
"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF7FFFFFFC", // a
|
||||
"1C97BEFC54BD7A8B65ACF89F81D4D4ADC565FA45", // b
|
||||
"0100000000000000000001F4C8F927AED3CA752257", // n
|
||||
"1", // h
|
||||
"4A96B5688EF573284664698968C38BB913CBFC82", // gx
|
||||
"23A628553168947D59DCC912042351377AC5FB32", // gy
|
||||
[], // alias
|
||||
"", // oid
|
||||
"secp160r1 : SECG curve over a 160 bit prime field"); // info
|
||||
|
||||
KJUR.crypto.ECParameterDB.regist(
|
||||
"secp192k1", // name / p = 2^192 - 2^32 - 2^12 - 2^8 - 2^7 - 2^6 - 2^3 - 1
|
||||
192,
|
||||
"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFEE37", // p
|
||||
"0", // a
|
||||
"3", // b
|
||||
"FFFFFFFFFFFFFFFFFFFFFFFE26F2FC170F69466A74DEFD8D", // n
|
||||
"1", // h
|
||||
"DB4FF10EC057E9AE26B07D0280B7F4341DA5D1B1EAE06C7D", // gx
|
||||
"9B2F2F6D9C5628A7844163D015BE86344082AA88D95E2F9D", // gy
|
||||
[]); // alias
|
||||
|
||||
KJUR.crypto.ECParameterDB.regist(
|
||||
"secp192r1", // name / p = 2^192 - 2^64 - 1
|
||||
192,
|
||||
"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFF", // p
|
||||
"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFC", // a
|
||||
"64210519E59C80E70FA7E9AB72243049FEB8DEECC146B9B1", // b
|
||||
"FFFFFFFFFFFFFFFFFFFFFFFF99DEF836146BC9B1B4D22831", // n
|
||||
"1", // h
|
||||
"188DA80EB03090F67CBF20EB43A18800F4FF0AFD82FF1012", // gx
|
||||
"07192B95FFC8DA78631011ED6B24CDD573F977A11E794811", // gy
|
||||
[]); // alias
|
||||
|
||||
KJUR.crypto.ECParameterDB.regist(
|
||||
"secp224r1", // name / p = 2^224 - 2^96 + 1
|
||||
224,
|
||||
"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF000000000000000000000001", // p
|
||||
"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFE", // a
|
||||
"B4050A850C04B3ABF54132565044B0B7D7BFD8BA270B39432355FFB4", // b
|
||||
"FFFFFFFFFFFFFFFFFFFFFFFFFFFF16A2E0B8F03E13DD29455C5C2A3D", // n
|
||||
"1", // h
|
||||
"B70E0CBD6BB4BF7F321390B94A03C1D356C21122343280D6115C1D21", // gx
|
||||
"BD376388B5F723FB4C22DFE6CD4375A05A07476444D5819985007E34", // gy
|
||||
[]); // alias
|
||||
|
||||
KJUR.crypto.ECParameterDB.regist(
|
||||
"secp256k1", // name / p = 2^256 - 2^32 - 2^9 - 2^8 - 2^7 - 2^6 - 2^4 - 1
|
||||
256,
|
||||
"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F", // p
|
||||
"0", // a
|
||||
"7", // b
|
||||
"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141", // n
|
||||
"1", // h
|
||||
"79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798", // gx
|
||||
"483ADA7726A3C4655DA4FBFC0E1108A8FD17B448A68554199C47D08FFB10D4B8", // gy
|
||||
[]); // alias
|
||||
|
||||
KJUR.crypto.ECParameterDB.regist(
|
||||
"secp256r1", // name / p = 2^224 (2^32 - 1) + 2^192 + 2^96 - 1
|
||||
256,
|
||||
"FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFF", // p
|
||||
"FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFC", // a
|
||||
"5AC635D8AA3A93E7B3EBBD55769886BC651D06B0CC53B0F63BCE3C3E27D2604B", // b
|
||||
"FFFFFFFF00000000FFFFFFFFFFFFFFFFBCE6FAADA7179E84F3B9CAC2FC632551", // n
|
||||
"1", // h
|
||||
"6B17D1F2E12C4247F8BCE6E563A440F277037D812DEB33A0F4A13945D898C296", // gx
|
||||
"4FE342E2FE1A7F9B8EE7EB4A7C0F9E162BCE33576B315ECECBB6406837BF51F5", // gy
|
||||
["NIST P-256", "P-256", "prime256v1"]); // alias
|
||||
|
||||
KJUR.crypto.ECParameterDB.regist(
|
||||
"secp384r1", // name
|
||||
384,
|
||||
"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFF0000000000000000FFFFFFFF", // p
|
||||
"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFF0000000000000000FFFFFFFC", // a
|
||||
"B3312FA7E23EE7E4988E056BE3F82D19181D9C6EFE8141120314088F5013875AC656398D8A2ED19D2A85C8EDD3EC2AEF", // b
|
||||
"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC7634D81F4372DDF581A0DB248B0A77AECEC196ACCC52973", // n
|
||||
"1", // h
|
||||
"AA87CA22BE8B05378EB1C71EF320AD746E1D3B628BA79B9859F741E082542A385502F25DBF55296C3A545E3872760AB7", // gx
|
||||
"3617de4a96262c6f5d9e98bf9292dc29f8f41dbd289a147ce9da3113b5f0b8c00a60b1ce1d7e819d7a431d7c90ea0e5f", // gy
|
||||
["NIST P-384", "P-384"]); // alias
|
||||
|
||||
KJUR.crypto.ECParameterDB.regist(
|
||||
"secp521r1", // name
|
||||
521,
|
||||
"1FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", // p
|
||||
"1FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC", // a
|
||||
"051953EB9618E1C9A1F929A21A0B68540EEA2DA725B99B315F3B8B489918EF109E156193951EC7E937B1652C0BD3BB1BF073573DF883D2C34F1EF451FD46B503F00", // b
|
||||
"1FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFA51868783BF2F966B7FCC0148F709A5D03BB5C9B8899C47AEBB6FB71E91386409", // n
|
||||
"1", // h
|
||||
"C6858E06B70404E9CD9E3ECB662395B4429C648139053FB521F828AF606B4D3DBAA14B5E77EFE75928FE1DC127A2FFA8DE3348B3C1856A429BF97E7E31C2E5BD66", // gx
|
||||
"011839296a789a3bc0045c8a5fb42c7d1bd998f54449579b446817afbd17273e662c97ee72995ef42640c550b9013fad0761353c7086a272c24088be94769fd16650", // gy
|
||||
["NIST P-521", "P-521"]); // alias
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,749 +0,0 @@
|
||||
/** @license
|
||||
========================================================================
|
||||
The 'jsrsasign'(RSA-Sign JavaScript Library) License
|
||||
|
||||
Copyright (c) 2010-2013 Kenji Urushima
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
||||
*/
|
||||
|
||||
/*! x509-1.1.6.js (c) 2012-2015 Kenji Urushima | kjur.github.com/jsrsasign/license
|
||||
*/
|
||||
/*
|
||||
* x509.js - X509 class to read subject public key from certificate.
|
||||
*
|
||||
* Copyright (c) 2010-2015 Kenji Urushima (kenji.urushima@gmail.com)
|
||||
*
|
||||
* This software is licensed under the terms of the MIT License.
|
||||
* http://kjur.github.com/jsrsasign/license
|
||||
*
|
||||
* The above copyright and license notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @fileOverview
|
||||
* @name x509-1.1.js
|
||||
* @author Kenji Urushima kenji.urushima@gmail.com
|
||||
* @version x509 1.1.6 (2015-May-20)
|
||||
* @since jsrsasign 1.x.x
|
||||
* @license <a href="http://kjur.github.io/jsrsasign/license/">MIT License</a>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Depends:
|
||||
* base64.js
|
||||
* rsa.js
|
||||
* asn1hex.js
|
||||
*/
|
||||
|
||||
/**
|
||||
* X.509 certificate class.<br/>
|
||||
* @class X.509 certificate class
|
||||
* @property {RSAKey} subjectPublicKeyRSA Tom Wu's RSAKey object
|
||||
* @property {String} subjectPublicKeyRSA_hN hexadecimal string for modulus of RSA public key
|
||||
* @property {String} subjectPublicKeyRSA_hE hexadecimal string for public exponent of RSA public key
|
||||
* @property {String} hex hexacedimal string for X.509 certificate.
|
||||
* @author Kenji Urushima
|
||||
* @version 1.0.1 (08 May 2012)
|
||||
* @see <a href="http://kjur.github.com/jsrsasigns/">'jwrsasign'(RSA Sign JavaScript Library) home page http://kjur.github.com/jsrsasign/</a>
|
||||
*/
|
||||
function X509() {
|
||||
this.subjectPublicKeyRSA = null;
|
||||
this.subjectPublicKeyRSA_hN = null;
|
||||
this.subjectPublicKeyRSA_hE = null;
|
||||
this.hex = null;
|
||||
|
||||
// ===== get basic fields from hex =====================================
|
||||
|
||||
/**
|
||||
* get hexadecimal string of serialNumber field of certificate.<br/>
|
||||
* @name getSerialNumberHex
|
||||
* @memberOf X509#
|
||||
* @function
|
||||
*/
|
||||
this.getSerialNumberHex = function() {
|
||||
return ASN1HEX.getDecendantHexVByNthList(this.hex, 0, [0, 1]);
|
||||
};
|
||||
|
||||
/**
|
||||
* get hexadecimal string of issuer field TLV of certificate.<br/>
|
||||
* @name getIssuerHex
|
||||
* @memberOf X509#
|
||||
* @function
|
||||
*/
|
||||
this.getIssuerHex = function() {
|
||||
return ASN1HEX.getDecendantHexTLVByNthList(this.hex, 0, [0, 3]);
|
||||
};
|
||||
|
||||
/**
|
||||
* get string of issuer field of certificate.<br/>
|
||||
* @name getIssuerString
|
||||
* @memberOf X509#
|
||||
* @function
|
||||
*/
|
||||
this.getIssuerString = function() {
|
||||
return X509.hex2dn(ASN1HEX.getDecendantHexTLVByNthList(this.hex, 0, [0, 3]));
|
||||
};
|
||||
|
||||
/**
|
||||
* get hexadecimal string of subject field of certificate.<br/>
|
||||
* @name getSubjectHex
|
||||
* @memberOf X509#
|
||||
* @function
|
||||
*/
|
||||
this.getSubjectHex = function() {
|
||||
return ASN1HEX.getDecendantHexTLVByNthList(this.hex, 0, [0, 5]);
|
||||
};
|
||||
|
||||
/**
|
||||
* get string of subject field of certificate.<br/>
|
||||
* @name getSubjectString
|
||||
* @memberOf X509#
|
||||
* @function
|
||||
*/
|
||||
this.getSubjectString = function() {
|
||||
return X509.hex2dn(ASN1HEX.getDecendantHexTLVByNthList(this.hex, 0, [0, 5]));
|
||||
};
|
||||
|
||||
/**
|
||||
* get notBefore field string of certificate.<br/>
|
||||
* @name getNotBefore
|
||||
* @memberOf X509#
|
||||
* @function
|
||||
*/
|
||||
this.getNotBefore = function() {
|
||||
var s = ASN1HEX.getDecendantHexVByNthList(this.hex, 0, [0, 4, 0]);
|
||||
s = s.replace(/(..)/g, "%$1");
|
||||
s = decodeURIComponent(s);
|
||||
return s;
|
||||
};
|
||||
|
||||
/**
|
||||
* get notAfter field string of certificate.<br/>
|
||||
* @name getNotAfter
|
||||
* @memberOf X509#
|
||||
* @function
|
||||
*/
|
||||
this.getNotAfter = function() {
|
||||
var s = ASN1HEX.getDecendantHexVByNthList(this.hex, 0, [0, 4, 1]);
|
||||
s = s.replace(/(..)/g, "%$1");
|
||||
s = decodeURIComponent(s);
|
||||
return s;
|
||||
};
|
||||
|
||||
// ===== read certificate public key ==========================
|
||||
|
||||
// ===== read certificate =====================================
|
||||
/**
|
||||
* read PEM formatted X.509 certificate from string.<br/>
|
||||
* @name readCertPEM
|
||||
* @memberOf X509#
|
||||
* @function
|
||||
* @param {String} sCertPEM string for PEM formatted X.509 certificate
|
||||
*/
|
||||
this.readCertPEM = function(sCertPEM) {
|
||||
var hCert = X509.pemToHex(sCertPEM);
|
||||
var a = X509.getPublicKeyHexArrayFromCertHex(hCert);
|
||||
var rsa = new RSAKey();
|
||||
rsa.setPublic(a[0], a[1]);
|
||||
this.subjectPublicKeyRSA = rsa;
|
||||
this.subjectPublicKeyRSA_hN = a[0];
|
||||
this.subjectPublicKeyRSA_hE = a[1];
|
||||
this.hex = hCert;
|
||||
};
|
||||
|
||||
this.readCertPEMWithoutRSAInit = function(sCertPEM) {
|
||||
var hCert = X509.pemToHex(sCertPEM);
|
||||
var a = X509.getPublicKeyHexArrayFromCertHex(hCert);
|
||||
this.subjectPublicKeyRSA.setPublic(a[0], a[1]);
|
||||
this.subjectPublicKeyRSA_hN = a[0];
|
||||
this.subjectPublicKeyRSA_hE = a[1];
|
||||
this.hex = hCert;
|
||||
};
|
||||
};
|
||||
|
||||
X509.pemToBase64 = function(sCertPEM) {
|
||||
var s = sCertPEM;
|
||||
s = s.replace("-----BEGIN CERTIFICATE-----", "");
|
||||
s = s.replace("-----END CERTIFICATE-----", "");
|
||||
s = s.replace(/[ \n]+/g, "");
|
||||
return s;
|
||||
};
|
||||
|
||||
X509.pemToHex = function(sCertPEM) {
|
||||
var b64Cert = X509.pemToBase64(sCertPEM);
|
||||
var hCert = b64tohex(b64Cert);
|
||||
return hCert;
|
||||
};
|
||||
|
||||
// NOTE: Without BITSTRING encapsulation.
|
||||
X509.getSubjectPublicKeyPosFromCertHex = function(hCert) {
|
||||
var pInfo = X509.getSubjectPublicKeyInfoPosFromCertHex(hCert);
|
||||
if (pInfo == -1) return -1;
|
||||
var a = ASN1HEX.getPosArrayOfChildren_AtObj(hCert, pInfo);
|
||||
if (a.length != 2) return -1;
|
||||
var pBitString = a[1];
|
||||
if (hCert.substring(pBitString, pBitString + 2) != '03') return -1;
|
||||
var pBitStringV = ASN1HEX.getStartPosOfV_AtObj(hCert, pBitString);
|
||||
|
||||
if (hCert.substring(pBitStringV, pBitStringV + 2) != '00') return -1;
|
||||
return pBitStringV + 2;
|
||||
};
|
||||
|
||||
// NOTE: privateKeyUsagePeriod field of X509v2 not supported.
|
||||
// NOTE: v1 and v3 supported
|
||||
X509.getSubjectPublicKeyInfoPosFromCertHex = function(hCert) {
|
||||
var pTbsCert = ASN1HEX.getStartPosOfV_AtObj(hCert, 0);
|
||||
var a = ASN1HEX.getPosArrayOfChildren_AtObj(hCert, pTbsCert);
|
||||
if (a.length < 1) return -1;
|
||||
if (hCert.substring(a[0], a[0] + 10) == "a003020102") { // v3
|
||||
if (a.length < 6) return -1;
|
||||
return a[6];
|
||||
} else {
|
||||
if (a.length < 5) return -1;
|
||||
return a[5];
|
||||
}
|
||||
};
|
||||
|
||||
X509.getPublicKeyHexArrayFromCertHex = function(hCert) {
|
||||
var p = X509.getSubjectPublicKeyPosFromCertHex(hCert);
|
||||
var a = ASN1HEX.getPosArrayOfChildren_AtObj(hCert, p);
|
||||
if (a.length != 2) return [];
|
||||
var hN = ASN1HEX.getHexOfV_AtObj(hCert, a[0]);
|
||||
var hE = ASN1HEX.getHexOfV_AtObj(hCert, a[1]);
|
||||
if (hN != null && hE != null) {
|
||||
return [hN, hE];
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
};
|
||||
|
||||
X509.getHexTbsCertificateFromCert = function(hCert) {
|
||||
var pTbsCert = ASN1HEX.getStartPosOfV_AtObj(hCert, 0);
|
||||
return pTbsCert;
|
||||
};
|
||||
|
||||
X509.getPublicKeyHexArrayFromCertPEM = function(sCertPEM) {
|
||||
var hCert = X509.pemToHex(sCertPEM);
|
||||
var a = X509.getPublicKeyHexArrayFromCertHex(hCert);
|
||||
return a;
|
||||
};
|
||||
|
||||
X509.hex2dn = function(hDN) {
|
||||
var s = "";
|
||||
var a = ASN1HEX.getPosArrayOfChildren_AtObj(hDN, 0);
|
||||
for (var i = 0; i < a.length; i++) {
|
||||
var hRDN = ASN1HEX.getHexOfTLV_AtObj(hDN, a[i]);
|
||||
s = s + "/" + X509.hex2rdn(hRDN);
|
||||
}
|
||||
return s;
|
||||
};
|
||||
|
||||
X509.hex2rdn = function(hRDN) {
|
||||
var hType = ASN1HEX.getDecendantHexTLVByNthList(hRDN, 0, [0, 0]);
|
||||
var hValue = ASN1HEX.getDecendantHexVByNthList(hRDN, 0, [0, 1]);
|
||||
var type = "";
|
||||
try { type = X509.DN_ATTRHEX[hType]; } catch (ex) { type = hType; }
|
||||
hValue = hValue.replace(/(..)/g, "%$1");
|
||||
var value = decodeURIComponent(hValue);
|
||||
return type + "=" + value;
|
||||
};
|
||||
|
||||
X509.DN_ATTRHEX = {
|
||||
"0603550406": "C",
|
||||
"060355040a": "O",
|
||||
"060355040b": "OU",
|
||||
"0603550403": "CN",
|
||||
"0603550405": "SN",
|
||||
"0603550408": "ST",
|
||||
"0603550407": "L",
|
||||
};
|
||||
|
||||
/**
|
||||
* get RSAKey/ECDSA public key object from PEM certificate string
|
||||
* @name getPublicKeyFromCertPEM
|
||||
* @memberOf X509
|
||||
* @function
|
||||
* @param {String} sCertPEM PEM formatted RSA/ECDSA/DSA X.509 certificate
|
||||
* @return returns RSAKey/KJUR.crypto.{ECDSA,DSA} object of public key
|
||||
* @since x509 1.1.1
|
||||
* @description
|
||||
* NOTE: DSA is also supported since x509 1.1.2.
|
||||
*/
|
||||
X509.getPublicKeyFromCertPEM = function(sCertPEM) {
|
||||
var info = X509.getPublicKeyInfoPropOfCertPEM(sCertPEM);
|
||||
|
||||
if (info.algoid == "2a864886f70d010101") { // RSA
|
||||
var aRSA = KEYUTIL.parsePublicRawRSAKeyHex(info.keyhex);
|
||||
var key = new RSAKey();
|
||||
key.setPublic(aRSA.n, aRSA.e);
|
||||
return key;
|
||||
} else if (info.algoid == "2a8648ce3d0201") { // ECC
|
||||
var curveName = KJUR.crypto.OID.oidhex2name[info.algparam];
|
||||
var key = new KJUR.crypto.ECDSA({'curve': curveName, 'info': info.keyhex});
|
||||
key.setPublicKeyHex(info.keyhex);
|
||||
return key;
|
||||
} else if (info.algoid == "2a8648ce380401") { // DSA 1.2.840.10040.4.1
|
||||
var p = ASN1HEX.getVbyList(info.algparam, 0, [0], "02");
|
||||
var q = ASN1HEX.getVbyList(info.algparam, 0, [1], "02");
|
||||
var g = ASN1HEX.getVbyList(info.algparam, 0, [2], "02");
|
||||
var y = ASN1HEX.getHexOfV_AtObj(info.keyhex, 0);
|
||||
y = y.substr(2);
|
||||
var key = new KJUR.crypto.DSA();
|
||||
key.setPublic(new BigInteger(p, 16),
|
||||
new BigInteger(q, 16),
|
||||
new BigInteger(g, 16),
|
||||
new BigInteger(y, 16));
|
||||
return key;
|
||||
} else {
|
||||
throw "unsupported key";
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* get public key information from PEM certificate
|
||||
* @name getPublicKeyInfoPropOfCertPEM
|
||||
* @memberOf X509
|
||||
* @function
|
||||
* @param {String} sCertPEM string of PEM formatted certificate
|
||||
* @return {Hash} hash of information for public key
|
||||
* @since x509 1.1.1
|
||||
* @description
|
||||
* Resulted associative array has following properties:
|
||||
* <ul>
|
||||
* <li>algoid - hexadecimal string of OID of asymmetric key algorithm</li>
|
||||
* <li>algparam - hexadecimal string of OID of ECC curve name or null</li>
|
||||
* <li>keyhex - hexadecimal string of key in the certificate</li>
|
||||
* </ul>
|
||||
* @since x509 1.1.1
|
||||
*/
|
||||
X509.getPublicKeyInfoPropOfCertPEM = function(sCertPEM) {
|
||||
var result = {};
|
||||
result.algparam = null;
|
||||
var hCert = X509.pemToHex(sCertPEM);
|
||||
|
||||
// 1. Certificate ASN.1
|
||||
var a1 = ASN1HEX.getPosArrayOfChildren_AtObj(hCert, 0);
|
||||
if (a1.length != 3)
|
||||
throw "malformed X.509 certificate PEM (code:001)"; // not 3 item of seq Cert
|
||||
|
||||
// 2. tbsCertificate
|
||||
if (hCert.substr(a1[0], 2) != "30")
|
||||
throw "malformed X.509 certificate PEM (code:002)"; // tbsCert not seq
|
||||
|
||||
var a2 = ASN1HEX.getPosArrayOfChildren_AtObj(hCert, a1[0]);
|
||||
|
||||
// 3. subjectPublicKeyInfo
|
||||
if (a2.length < 7)
|
||||
throw "malformed X.509 certificate PEM (code:003)"; // no subjPubKeyInfo
|
||||
|
||||
var a3 = ASN1HEX.getPosArrayOfChildren_AtObj(hCert, a2[6]);
|
||||
|
||||
if (a3.length != 2)
|
||||
throw "malformed X.509 certificate PEM (code:004)"; // not AlgId and PubKey
|
||||
|
||||
// 4. AlgId
|
||||
var a4 = ASN1HEX.getPosArrayOfChildren_AtObj(hCert, a3[0]);
|
||||
|
||||
if (a4.length != 2)
|
||||
throw "malformed X.509 certificate PEM (code:005)"; // not 2 item in AlgId
|
||||
|
||||
result.algoid = ASN1HEX.getHexOfV_AtObj(hCert, a4[0]);
|
||||
|
||||
if (hCert.substr(a4[1], 2) == "06") { // EC
|
||||
result.algparam = ASN1HEX.getHexOfV_AtObj(hCert, a4[1]);
|
||||
} else if (hCert.substr(a4[1], 2) == "30") { // DSA
|
||||
result.algparam = ASN1HEX.getHexOfTLV_AtObj(hCert, a4[1]);
|
||||
}
|
||||
|
||||
// 5. Public Key Hex
|
||||
if (hCert.substr(a3[1], 2) != "03")
|
||||
throw "malformed X.509 certificate PEM (code:006)"; // not bitstring
|
||||
|
||||
var unusedBitAndKeyHex = ASN1HEX.getHexOfV_AtObj(hCert, a3[1]);
|
||||
result.keyhex = unusedBitAndKeyHex.substr(2);
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
/**
|
||||
* get position of subjectPublicKeyInfo field from HEX certificate
|
||||
* @name getPublicKeyInfoPosOfCertHEX
|
||||
* @memberOf X509
|
||||
* @function
|
||||
* @param {String} hCert hexadecimal string of certificate
|
||||
* @return {Integer} position in hexadecimal string
|
||||
* @since x509 1.1.4
|
||||
* @description
|
||||
* get position for SubjectPublicKeyInfo field in the hexadecimal string of
|
||||
* certificate.
|
||||
*/
|
||||
X509.getPublicKeyInfoPosOfCertHEX = function(hCert) {
|
||||
// 1. Certificate ASN.1
|
||||
var a1 = ASN1HEX.getPosArrayOfChildren_AtObj(hCert, 0);
|
||||
if (a1.length != 3)
|
||||
throw "malformed X.509 certificate PEM (code:001)"; // not 3 item of seq Cert
|
||||
|
||||
// 2. tbsCertificate
|
||||
if (hCert.substr(a1[0], 2) != "30")
|
||||
throw "malformed X.509 certificate PEM (code:002)"; // tbsCert not seq
|
||||
|
||||
var a2 = ASN1HEX.getPosArrayOfChildren_AtObj(hCert, a1[0]);
|
||||
|
||||
// 3. subjectPublicKeyInfo
|
||||
if (a2.length < 7)
|
||||
throw "malformed X.509 certificate PEM (code:003)"; // no subjPubKeyInfo
|
||||
|
||||
return a2[6];
|
||||
};
|
||||
|
||||
/**
|
||||
* get array of X.509 V3 extension value information in hex string of certificate
|
||||
* @name getV3ExtInfoListOfCertHex
|
||||
* @memberOf X509
|
||||
* @function
|
||||
* @param {String} hCert hexadecimal string of X.509 certificate binary
|
||||
* @return {Array} array of result object by {@link X509.getV3ExtInfoListOfCertHex}
|
||||
* @since x509 1.1.5
|
||||
* @description
|
||||
* This method will get all extension information of a X.509 certificate.
|
||||
* Items of resulting array has following properties:
|
||||
* <ul>
|
||||
* <li>posTLV - index of ASN.1 TLV for the extension. same as 'pos' argument.</li>
|
||||
* <li>oid - dot noted string of extension oid (ex. 2.5.29.14)</li>
|
||||
* <li>critical - critical flag value for this extension</li>
|
||||
* <li>posV - index of ASN.1 TLV for the extension value.
|
||||
* This is a position of a content of ENCAPSULATED OCTET STRING.</li>
|
||||
* </ul>
|
||||
* @example
|
||||
* hCert = X509.pemToHex(certGithubPEM);
|
||||
* a = X509.getV3ExtInfoListOfCertHex(hCert);
|
||||
* // Then a will be an array of like following:
|
||||
* [{posTLV: 1952, oid: "2.5.29.35", critical: false, posV: 1968},
|
||||
* {posTLV: 1974, oid: "2.5.29.19", critical: true, posV: 1986}, ...]
|
||||
*/
|
||||
X509.getV3ExtInfoListOfCertHex = function(hCert) {
|
||||
// 1. Certificate ASN.1
|
||||
var a1 = ASN1HEX.getPosArrayOfChildren_AtObj(hCert, 0);
|
||||
if (a1.length != 3)
|
||||
throw "malformed X.509 certificate PEM (code:001)"; // not 3 item of seq Cert
|
||||
|
||||
// 2. tbsCertificate
|
||||
if (hCert.substr(a1[0], 2) != "30")
|
||||
throw "malformed X.509 certificate PEM (code:002)"; // tbsCert not seq
|
||||
|
||||
var a2 = ASN1HEX.getPosArrayOfChildren_AtObj(hCert, a1[0]);
|
||||
|
||||
// 3. v3Extension EXPLICIT Tag [3]
|
||||
// ver, seri, alg, iss, validity, subj, spki, (iui,) (sui,) ext
|
||||
if (a2.length < 8)
|
||||
throw "malformed X.509 certificate PEM (code:003)"; // tbsCert num field too short
|
||||
|
||||
if (hCert.substr(a2[7], 2) != "a3")
|
||||
throw "malformed X.509 certificate PEM (code:004)"; // not [3] tag
|
||||
|
||||
var a3 = ASN1HEX.getPosArrayOfChildren_AtObj(hCert, a2[7]);
|
||||
if (a3.length != 1)
|
||||
throw "malformed X.509 certificate PEM (code:005)"; // [3]tag numChild!=1
|
||||
|
||||
// 4. v3Extension SEQUENCE
|
||||
if (hCert.substr(a3[0], 2) != "30")
|
||||
throw "malformed X.509 certificate PEM (code:006)"; // not SEQ
|
||||
|
||||
var a4 = ASN1HEX.getPosArrayOfChildren_AtObj(hCert, a3[0]);
|
||||
|
||||
// 5. v3Extension item position
|
||||
var numExt = a4.length;
|
||||
var aInfo = new Array(numExt);
|
||||
for (var i = 0; i < numExt; i++) {
|
||||
aInfo[i] = X509.getV3ExtItemInfo_AtObj(hCert, a4[i]);
|
||||
}
|
||||
return aInfo;
|
||||
};
|
||||
|
||||
/**
|
||||
* get X.509 V3 extension value information at the specified position
|
||||
* @name getV3ExtItemInfo_AtObj
|
||||
* @memberOf X509
|
||||
* @function
|
||||
* @param {String} hCert hexadecimal string of X.509 certificate binary
|
||||
* @param {Integer} pos index of hexadecimal string for the extension
|
||||
* @return {Object} properties for the extension
|
||||
* @since x509 1.1.5
|
||||
* @description
|
||||
* This method will get some information of a X.509 V extension
|
||||
* which is referred by an index of hexadecimal string of X.509
|
||||
* certificate.
|
||||
* Resulting object has following properties:
|
||||
* <ul>
|
||||
* <li>posTLV - index of ASN.1 TLV for the extension. same as 'pos' argument.</li>
|
||||
* <li>oid - dot noted string of extension oid (ex. 2.5.29.14)</li>
|
||||
* <li>critical - critical flag value for this extension</li>
|
||||
* <li>posV - index of ASN.1 TLV for the extension value.
|
||||
* This is a position of a content of ENCAPSULATED OCTET STRING.</li>
|
||||
* </ul>
|
||||
* This method is used by {@link X509.getV3ExtInfoListOfCertHex} internally.
|
||||
*/
|
||||
X509.getV3ExtItemInfo_AtObj = function(hCert, pos) {
|
||||
var info = {};
|
||||
|
||||
// posTLV - extension TLV
|
||||
info.posTLV = pos;
|
||||
|
||||
var a = ASN1HEX.getPosArrayOfChildren_AtObj(hCert, pos);
|
||||
if (a.length != 2 && a.length != 3)
|
||||
throw "malformed X.509v3 Ext (code:001)"; // oid,(critical,)val
|
||||
|
||||
// oid - extension OID
|
||||
if (hCert.substr(a[0], 2) != "06")
|
||||
throw "malformed X.509v3 Ext (code:002)"; // not OID "06"
|
||||
var valueHex = ASN1HEX.getHexOfV_AtObj(hCert, a[0]);
|
||||
info.oid = ASN1HEX.hextooidstr(valueHex);
|
||||
|
||||
// critical - extension critical flag
|
||||
info.critical = false; // critical false by default
|
||||
if (a.length == 3) info.critical = true;
|
||||
|
||||
// posV - content TLV position of encapsulated
|
||||
// octet string of V3 extension value.
|
||||
var posExtV = a[a.length - 1];
|
||||
if (hCert.substr(posExtV, 2) != "04")
|
||||
throw "malformed X.509v3 Ext (code:003)"; // not EncapOctet "04"
|
||||
info.posV = ASN1HEX.getStartPosOfV_AtObj(hCert, posExtV);
|
||||
|
||||
return info;
|
||||
};
|
||||
|
||||
/**
|
||||
* get X.509 V3 extension value ASN.1 TLV for specified oid or name
|
||||
* @name getHexOfTLV_V3ExtValue
|
||||
* @memberOf X509
|
||||
* @function
|
||||
* @param {String} hCert hexadecimal string of X.509 certificate binary
|
||||
* @param {String} oidOrName oid or name for extension (ex. 'keyUsage' or '2.5.29.15')
|
||||
* @return {String} hexadecimal string of extension ASN.1 TLV
|
||||
* @since x509 1.1.6
|
||||
* @description
|
||||
* This method will get X.509v3 extension value of ASN.1 TLV
|
||||
* which is specifyed by extension name or oid.
|
||||
* @example
|
||||
* hExtValue = X509.getHexOfTLV_V3ExtValue(hCert, "keyUsage");
|
||||
* // hExtValue will be such like '030205a0'.
|
||||
*/
|
||||
X509.getHexOfTLV_V3ExtValue = function(hCert, oidOrName) {
|
||||
var pos = X509.getPosOfTLV_V3ExtValue(hCert, oidOrName);
|
||||
if (pos == -1) return '';
|
||||
return ASN1HEX.getHexOfTLV_AtObj(hCert, pos);
|
||||
};
|
||||
|
||||
/**
|
||||
* get X.509 V3 extension value ASN.1 V for specified oid or name
|
||||
* @name getHexOfV_V3ExtValue
|
||||
* @memberOf X509
|
||||
* @function
|
||||
* @param {String} hCert hexadecimal string of X.509 certificate binary
|
||||
* @param {String} oidOrName oid or name for extension (ex. 'keyUsage' or '2.5.29.15')
|
||||
* @return {String} hexadecimal string of extension ASN.1 TLV
|
||||
* @since x509 1.1.6
|
||||
* @description
|
||||
* This method will get X.509v3 extension value of ASN.1 value
|
||||
* which is specifyed by extension name or oid.
|
||||
* If there is no such extension in the certificate,
|
||||
* it returns empty string (i.e. '').
|
||||
* Available extension names and oids are defined
|
||||
* in the {@link KJUR.asn1.x509.OID} class.
|
||||
* @example
|
||||
* hExtValue = X509.getHexOfV_V3ExtValue(hCert, "keyUsage");
|
||||
* // hExtValue will be such like '05a0'.
|
||||
*/
|
||||
X509.getHexOfV_V3ExtValue = function(hCert, oidOrName) {
|
||||
var pos = X509.getPosOfTLV_V3ExtValue(hCert, oidOrName);
|
||||
if (pos == -1) return '';
|
||||
return ASN1HEX.getHexOfV_AtObj(hCert, pos);
|
||||
};
|
||||
|
||||
/**
|
||||
* get index in the certificate hexa string for specified oid or name specified extension
|
||||
* @name getPosOfTLV_V3ExtValue
|
||||
* @memberOf X509
|
||||
* @function
|
||||
* @param {String} hCert hexadecimal string of X.509 certificate binary
|
||||
* @param {String} oidOrName oid or name for extension (ex. 'keyUsage' or '2.5.29.15')
|
||||
* @return {Integer} index in the hexadecimal string of certficate for specified extension
|
||||
* @since x509 1.1.6
|
||||
* @description
|
||||
* This method will get X.509v3 extension value of ASN.1 V(value)
|
||||
* which is specifyed by extension name or oid.
|
||||
* If there is no such extension in the certificate,
|
||||
* it returns empty string (i.e. '').
|
||||
* Available extension names and oids are defined
|
||||
* in the {@link KJUR.asn1.x509.OID} class.
|
||||
* @example
|
||||
* idx = X509.getPosOfV_V3ExtValue(hCert, "keyUsage");
|
||||
* // The 'idx' will be index in the string for keyUsage value ASN.1 TLV.
|
||||
*/
|
||||
X509.getPosOfTLV_V3ExtValue = function(hCert, oidOrName) {
|
||||
var oid = oidOrName;
|
||||
if (! oidOrName.match(/^[0-9.]+$/)) oid = KJUR.asn1.x509.OID.name2oid(oidOrName);
|
||||
if (oid == '') return -1;
|
||||
|
||||
var infoList = X509.getV3ExtInfoListOfCertHex(hCert);
|
||||
for (var i = 0; i < infoList.length; i++) {
|
||||
var info = infoList[i];
|
||||
if (info.oid == oid) return info.posV;
|
||||
}
|
||||
return -1;
|
||||
};
|
||||
|
||||
X509.KEYUSAGE_NAME = [
|
||||
"digitalSignature",
|
||||
"nonRepudiation",
|
||||
"keyEncipherment",
|
||||
"dataEncipherment",
|
||||
"keyAgreement",
|
||||
"keyCertSign",
|
||||
"cRLSign",
|
||||
"encipherOnly",
|
||||
"decipherOnly"
|
||||
];
|
||||
|
||||
/**
|
||||
* get KeyUsage extension value as binary string in the certificate
|
||||
* @name getExtKeyUsageBin
|
||||
* @memberOf X509
|
||||
* @function
|
||||
* @param {String} hCert hexadecimal string of X.509 certificate binary
|
||||
* @return {String} binary string of key usage bits (ex. '101')
|
||||
* @since x509 1.1.6
|
||||
* @description
|
||||
* This method will get key usage extension value
|
||||
* as binary string such like '101'.
|
||||
* Key usage bits definition is in the RFC 5280.
|
||||
* If there is no key usage extension in the certificate,
|
||||
* it returns empty string (i.e. '').
|
||||
* @example
|
||||
* bKeyUsage = X509.getExtKeyUsageBin(hCert);
|
||||
* // bKeyUsage will be such like '101'.
|
||||
* // 1 - digitalSignature
|
||||
* // 0 - nonRepudiation
|
||||
* // 1 - keyEncipherment
|
||||
*/
|
||||
X509.getExtKeyUsageBin = function(hCert) {
|
||||
var hKeyUsage = X509.getHexOfV_V3ExtValue(hCert, "keyUsage");
|
||||
if (hKeyUsage == '') return '';
|
||||
if (hKeyUsage.length % 2 != 0 || hKeyUsage.length <= 2)
|
||||
throw "malformed key usage value";
|
||||
var unusedBits = parseInt(hKeyUsage.substr(0, 2));
|
||||
var bKeyUsage = parseInt(hKeyUsage.substr(2), 16).toString(2);
|
||||
return bKeyUsage.substr(0, bKeyUsage.length - unusedBits);
|
||||
};
|
||||
|
||||
/**
|
||||
* get KeyUsage extension value as names in the certificate
|
||||
* @name getExtKeyUsageString
|
||||
* @memberOf X509
|
||||
* @function
|
||||
* @param {String} hCert hexadecimal string of X.509 certificate binary
|
||||
* @return {String} comma separated string of key usage
|
||||
* @since x509 1.1.6
|
||||
* @description
|
||||
* This method will get key usage extension value
|
||||
* as comma separated string of usage names.
|
||||
* If there is no key usage extension in the certificate,
|
||||
* it returns empty string (i.e. '').
|
||||
* @example
|
||||
* sKeyUsage = X509.getExtKeyUsageString(hCert);
|
||||
* // sKeyUsage will be such like 'digitalSignature,keyEncipherment'.
|
||||
*/
|
||||
X509.getExtKeyUsageString = function(hCert) {
|
||||
var bKeyUsage = X509.getExtKeyUsageBin(hCert);
|
||||
var a = new Array();
|
||||
for (var i = 0; i < bKeyUsage.length; i++) {
|
||||
if (bKeyUsage.substr(i, 1) == "1") a.push(X509.KEYUSAGE_NAME[i]);
|
||||
}
|
||||
return a.join(",");
|
||||
};
|
||||
|
||||
/**
|
||||
* get AuthorityInfoAccess extension value in the certificate as associative array
|
||||
* @name getExtAIAInfo
|
||||
* @memberOf X509
|
||||
* @function
|
||||
* @param {String} hCert hexadecimal string of X.509 certificate binary
|
||||
* @return {Object} associative array of AIA extension properties
|
||||
* @since x509 1.1.6
|
||||
* @description
|
||||
* This method will get authority info access value
|
||||
* as associate array which has following properties:
|
||||
* <ul>
|
||||
* <li>ocsp - array of string for OCSP responder URL</li>
|
||||
* <li>caissuer - array of string for caIssuer value (i.e. CA certificates URL)</li>
|
||||
* </ul>
|
||||
* If there is no key usage extension in the certificate,
|
||||
* it returns null;
|
||||
* @example
|
||||
* oAIA = X509.getExtAIAInfo(hCert);
|
||||
* // result will be such like:
|
||||
* // oAIA.ocsp = ["http://ocsp.foo.com"];
|
||||
* // oAIA.caissuer = ["http://rep.foo.com/aaa.p8m"];
|
||||
*/
|
||||
X509.getExtAIAInfo = function(hCert) {
|
||||
var result = {};
|
||||
result.ocsp = [];
|
||||
result.caissuer = [];
|
||||
var pos1 = X509.getPosOfTLV_V3ExtValue(hCert, "authorityInfoAccess");
|
||||
if (pos1 == -1) return null;
|
||||
if (hCert.substr(pos1, 2) != "30") // extnValue SEQUENCE
|
||||
throw "malformed AIA Extn Value";
|
||||
|
||||
var posAccDescList = ASN1HEX.getPosArrayOfChildren_AtObj(hCert, pos1);
|
||||
for (var i = 0; i < posAccDescList.length; i++) {
|
||||
var p = posAccDescList[i];
|
||||
var posAccDescChild = ASN1HEX.getPosArrayOfChildren_AtObj(hCert, p);
|
||||
if (posAccDescChild.length != 2)
|
||||
throw "malformed AccessDescription of AIA Extn";
|
||||
var pOID = posAccDescChild[0];
|
||||
var pName = posAccDescChild[1];
|
||||
if (ASN1HEX.getHexOfV_AtObj(hCert, pOID) == "2b06010505073001") {
|
||||
if (hCert.substr(pName, 2) == "86") {
|
||||
result.ocsp.push(hextoutf8(ASN1HEX.getHexOfV_AtObj(hCert, pName)));
|
||||
}
|
||||
}
|
||||
if (ASN1HEX.getHexOfV_AtObj(hCert, pOID) == "2b06010505073002") {
|
||||
if (hCert.substr(pName, 2) == "86") {
|
||||
result.caissuer.push(hextoutf8(ASN1HEX.getHexOfV_AtObj(hCert, pName)));
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
/*
|
||||
X509.prototype.readCertPEM = _x509_readCertPEM;
|
||||
X509.prototype.readCertPEMWithoutRSAInit = _x509_readCertPEMWithoutRSAInit;
|
||||
X509.prototype.getSerialNumberHex = _x509_getSerialNumberHex;
|
||||
X509.prototype.getIssuerHex = _x509_getIssuerHex;
|
||||
X509.prototype.getSubjectHex = _x509_getSubjectHex;
|
||||
X509.prototype.getIssuerString = _x509_getIssuerString;
|
||||
X509.prototype.getSubjectString = _x509_getSubjectString;
|
||||
X509.prototype.getNotBefore = _x509_getNotBefore;
|
||||
X509.prototype.getNotAfter = _x509_getNotAfter;
|
||||
*/
|
File diff suppressed because it is too large
Load Diff
3609
src/js/lib/moment.js
3609
src/js/lib/moment.js
File diff suppressed because it is too large
Load Diff
@ -1,336 +0,0 @@
|
||||
/** @license
|
||||
========================================================================
|
||||
Javascript Punycode converter derived from example in RFC3492.
|
||||
This implementation is created by some@domain.name and released into public domain
|
||||
|
||||
From RFC3492:
|
||||
Disclaimer and license
|
||||
Regarding this entire document or any portion of it (including the
|
||||
pseudocode and C code), the author makes no guarantees and is not
|
||||
responsible for any damage resulting from its use. The author grants
|
||||
irrevocable permission to anyone to use, modify, and distribute it in
|
||||
any way that does not diminish the rights of anyone else to use,
|
||||
modify, and distribute it, provided that redistributed derivative works do not contain misleading author or version information. Derivative works need not be licensed under similar terms.
|
||||
|
||||
I put my work in this punycode and utf16 in the public domain.
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
var punycode = new function Punycode() {
|
||||
// This object converts to and from puny-code used in IDN
|
||||
//
|
||||
// punycode.ToASCII(domain)
|
||||
//
|
||||
// Returns a puny coded representation of "domain".
|
||||
// It only converts the part of the domain name that
|
||||
// has non ASCII characters. I.e. it dosent matter if
|
||||
// you call it with a domain that already is in ASCII.
|
||||
//
|
||||
// punycode.ToUnicode(domain)
|
||||
//
|
||||
// Converts a puny-coded domain name to unicode.
|
||||
// It only converts the puny-coded parts of the domain name.
|
||||
// I.e. it dosent matter if you call it on a string
|
||||
// that already has been converted to unicode.
|
||||
//
|
||||
//
|
||||
this.utf16 = {
|
||||
// The utf16-class is necessary to convert from javascripts internal character representation to unicode and back.
|
||||
decode:function(input){
|
||||
var output = [], i=0, len=input.length,value,extra;
|
||||
while (i < len) {
|
||||
value = input.charCodeAt(i++);
|
||||
if ((value & 0xF800) === 0xD800) {
|
||||
extra = input.charCodeAt(i++);
|
||||
if ( ((value & 0xFC00) !== 0xD800) || ((extra & 0xFC00) !== 0xDC00) ) {
|
||||
throw new RangeError("UTF-16(decode): Illegal UTF-16 sequence");
|
||||
}
|
||||
value = ((value & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000;
|
||||
}
|
||||
output.push(value);
|
||||
}
|
||||
return output;
|
||||
},
|
||||
encode:function(input){
|
||||
var output = [], i=0, len=input.length,value;
|
||||
while (i < len) {
|
||||
value = input[i++];
|
||||
if ( (value & 0xF800) === 0xD800 ) {
|
||||
throw new RangeError("UTF-16(encode): Illegal UTF-16 value");
|
||||
}
|
||||
if (value > 0xFFFF) {
|
||||
value -= 0x10000;
|
||||
output.push(String.fromCharCode(((value >>>10) & 0x3FF) | 0xD800));
|
||||
value = 0xDC00 | (value & 0x3FF);
|
||||
}
|
||||
output.push(String.fromCharCode(value));
|
||||
}
|
||||
return output.join("");
|
||||
}
|
||||
}
|
||||
|
||||
//Default parameters
|
||||
var initial_n = 0x80;
|
||||
var initial_bias = 72;
|
||||
var delimiter = "\x2D";
|
||||
var base = 36;
|
||||
var damp = 700;
|
||||
var tmin=1;
|
||||
var tmax=26;
|
||||
var skew=38;
|
||||
var maxint = 0x7FFFFFFF;
|
||||
|
||||
// decode_digit(cp) returns the numeric value of a basic code
|
||||
// point (for use in representing integers) in the range 0 to
|
||||
// base-1, or base if cp is does not represent a value.
|
||||
|
||||
function decode_digit(cp) {
|
||||
return cp - 48 < 10 ? cp - 22 : cp - 65 < 26 ? cp - 65 : cp - 97 < 26 ? cp - 97 : base;
|
||||
}
|
||||
|
||||
// encode_digit(d,flag) returns the basic code point whose value
|
||||
// (when used for representing integers) is d, which needs to be in
|
||||
// the range 0 to base-1. The lowercase form is used unless flag is
|
||||
// nonzero, in which case the uppercase form is used. The behavior
|
||||
// is undefined if flag is nonzero and digit d has no uppercase form.
|
||||
|
||||
function encode_digit(d, flag) {
|
||||
return d + 22 + 75 * (d < 26) - ((flag != 0) << 5);
|
||||
// 0..25 map to ASCII a..z or A..Z
|
||||
// 26..35 map to ASCII 0..9
|
||||
}
|
||||
//** Bias adaptation function **
|
||||
function adapt(delta, numpoints, firsttime ) {
|
||||
var k;
|
||||
delta = firsttime ? Math.floor(delta / damp) : (delta >> 1);
|
||||
delta += Math.floor(delta / numpoints);
|
||||
|
||||
for (k = 0; delta > (((base - tmin) * tmax) >> 1); k += base) {
|
||||
delta = Math.floor(delta / ( base - tmin ));
|
||||
}
|
||||
return Math.floor(k + (base - tmin + 1) * delta / (delta + skew));
|
||||
}
|
||||
|
||||
// encode_basic(bcp,flag) forces a basic code point to lowercase if flag is zero,
|
||||
// uppercase if flag is nonzero, and returns the resulting code point.
|
||||
// The code point is unchanged if it is caseless.
|
||||
// The behavior is undefined if bcp is not a basic code point.
|
||||
|
||||
function encode_basic(bcp, flag) {
|
||||
bcp -= (bcp - 97 < 26) << 5;
|
||||
return bcp + ((!flag && (bcp - 65 < 26)) << 5);
|
||||
}
|
||||
|
||||
// Main decode
|
||||
this.decode=function(input,preserveCase) {
|
||||
// Dont use utf16
|
||||
var output=[];
|
||||
var case_flags=[];
|
||||
var input_length = input.length;
|
||||
|
||||
var n, out, i, bias, basic, j, ic, oldi, w, k, digit, t, len;
|
||||
|
||||
// Initialize the state:
|
||||
|
||||
n = initial_n;
|
||||
i = 0;
|
||||
bias = initial_bias;
|
||||
|
||||
// Handle the basic code points: Let basic be the number of input code
|
||||
// points before the last delimiter, or 0 if there is none, then
|
||||
// copy the first basic code points to the output.
|
||||
|
||||
basic = input.lastIndexOf(delimiter);
|
||||
if (basic < 0) basic = 0;
|
||||
|
||||
for (j = 0; j < basic; ++j) {
|
||||
if(preserveCase) case_flags[output.length] = ( input.charCodeAt(j) -65 < 26);
|
||||
if ( input.charCodeAt(j) >= 0x80) {
|
||||
throw new RangeError("Illegal input >= 0x80");
|
||||
}
|
||||
output.push( input.charCodeAt(j) );
|
||||
}
|
||||
|
||||
// Main decoding loop: Start just after the last delimiter if any
|
||||
// basic code points were copied; start at the beginning otherwise.
|
||||
|
||||
for (ic = basic > 0 ? basic + 1 : 0; ic < input_length; ) {
|
||||
|
||||
// ic is the index of the next character to be consumed,
|
||||
|
||||
// Decode a generalized variable-length integer into delta,
|
||||
// which gets added to i. The overflow checking is easier
|
||||
// if we increase i as we go, then subtract off its starting
|
||||
// value at the end to obtain delta.
|
||||
for (oldi = i, w = 1, k = base; ; k += base) {
|
||||
if (ic >= input_length) {
|
||||
throw RangeError ("punycode_bad_input(1)");
|
||||
}
|
||||
digit = decode_digit(input.charCodeAt(ic++));
|
||||
|
||||
if (digit >= base) {
|
||||
throw RangeError("punycode_bad_input(2)");
|
||||
}
|
||||
if (digit > Math.floor((maxint - i) / w)) {
|
||||
throw RangeError ("punycode_overflow(1)");
|
||||
}
|
||||
i += digit * w;
|
||||
t = k <= bias ? tmin : k >= bias + tmax ? tmax : k - bias;
|
||||
if (digit < t) { break; }
|
||||
if (w > Math.floor(maxint / (base - t))) {
|
||||
throw RangeError("punycode_overflow(2)");
|
||||
}
|
||||
w *= (base - t);
|
||||
}
|
||||
|
||||
out = output.length + 1;
|
||||
bias = adapt(i - oldi, out, oldi === 0);
|
||||
|
||||
// i was supposed to wrap around from out to 0,
|
||||
// incrementing n each time, so we'll fix that now:
|
||||
if ( Math.floor(i / out) > maxint - n) {
|
||||
throw RangeError("punycode_overflow(3)");
|
||||
}
|
||||
n += Math.floor( i / out ) ;
|
||||
i %= out;
|
||||
|
||||
// Insert n at position i of the output:
|
||||
// Case of last character determines uppercase flag:
|
||||
if (preserveCase) { case_flags.splice(i, 0, input.charCodeAt(ic -1) -65 < 26);}
|
||||
|
||||
output.splice(i, 0, n);
|
||||
i++;
|
||||
}
|
||||
if (preserveCase) {
|
||||
for (i = 0, len = output.length; i < len; i++) {
|
||||
if (case_flags[i]) {
|
||||
output[i] = (String.fromCharCode(output[i]).toUpperCase()).charCodeAt(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
return this.utf16.encode(output);
|
||||
};
|
||||
|
||||
//** Main encode function **
|
||||
|
||||
this.encode = function (input,preserveCase) {
|
||||
//** Bias adaptation function **
|
||||
|
||||
var n, delta, h, b, bias, j, m, q, k, t, ijv, case_flags;
|
||||
|
||||
if (preserveCase) {
|
||||
// Preserve case, step1 of 2: Get a list of the unaltered string
|
||||
case_flags = this.utf16.decode(input);
|
||||
}
|
||||
// Converts the input in UTF-16 to Unicode
|
||||
input = this.utf16.decode(input.toLowerCase());
|
||||
|
||||
var input_length = input.length; // Cache the length
|
||||
|
||||
if (preserveCase) {
|
||||
// Preserve case, step2 of 2: Modify the list to true/false
|
||||
for (j=0; j < input_length; j++) {
|
||||
case_flags[j] = input[j] != case_flags[j];
|
||||
}
|
||||
}
|
||||
|
||||
var output=[];
|
||||
|
||||
|
||||
// Initialize the state:
|
||||
n = initial_n;
|
||||
delta = 0;
|
||||
bias = initial_bias;
|
||||
|
||||
// Handle the basic code points:
|
||||
for (j = 0; j < input_length; ++j) {
|
||||
if ( input[j] < 0x80) {
|
||||
output.push(
|
||||
String.fromCharCode(
|
||||
case_flags ? encode_basic(input[j], case_flags[j]) : input[j]
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
h = b = output.length;
|
||||
|
||||
// h is the number of code points that have been handled, b is the
|
||||
// number of basic code points
|
||||
|
||||
if (b > 0) output.push(delimiter);
|
||||
|
||||
// Main encoding loop:
|
||||
//
|
||||
while (h < input_length) {
|
||||
// All non-basic code points < n have been
|
||||
// handled already. Find the next larger one:
|
||||
|
||||
for (m = maxint, j = 0; j < input_length; ++j) {
|
||||
ijv = input[j];
|
||||
if (ijv >= n && ijv < m) m = ijv;
|
||||
}
|
||||
|
||||
// Increase delta enough to advance the decoder's
|
||||
// <n,i> state to <m,0>, but guard against overflow:
|
||||
|
||||
if (m - n > Math.floor((maxint - delta) / (h + 1))) {
|
||||
throw RangeError("punycode_overflow (1)");
|
||||
}
|
||||
delta += (m - n) * (h + 1);
|
||||
n = m;
|
||||
|
||||
for (j = 0; j < input_length; ++j) {
|
||||
ijv = input[j];
|
||||
|
||||
if (ijv < n ) {
|
||||
if (++delta > maxint) return Error("punycode_overflow(2)");
|
||||
}
|
||||
|
||||
if (ijv == n) {
|
||||
// Represent delta as a generalized variable-length integer:
|
||||
for (q = delta, k = base; ; k += base) {
|
||||
t = k <= bias ? tmin : k >= bias + tmax ? tmax : k - bias;
|
||||
if (q < t) break;
|
||||
output.push( String.fromCharCode(encode_digit(t + (q - t) % (base - t), 0)) );
|
||||
q = Math.floor( (q - t) / (base - t) );
|
||||
}
|
||||
output.push( String.fromCharCode(encode_digit(q, preserveCase && case_flags[j] ? 1:0 )));
|
||||
bias = adapt(delta, h + 1, h == b);
|
||||
delta = 0;
|
||||
++h;
|
||||
}
|
||||
}
|
||||
|
||||
++delta, ++n;
|
||||
}
|
||||
return output.join("");
|
||||
}
|
||||
|
||||
this.ToASCII = function ( domain ) {
|
||||
var domain_array = domain.split(".");
|
||||
var out = [];
|
||||
for (var i=0; i < domain_array.length; ++i) {
|
||||
var s = domain_array[i];
|
||||
out.push(
|
||||
s.match(/[^A-Za-z0-9-]/) ?
|
||||
"xn--" + punycode.encode(s) :
|
||||
s
|
||||
);
|
||||
}
|
||||
return out.join(".");
|
||||
}
|
||||
this.ToUnicode = function ( domain ) {
|
||||
var domain_array = domain.split(".");
|
||||
var out = [];
|
||||
for (var i=0; i < domain_array.length; ++i) {
|
||||
var s = domain_array[i];
|
||||
out.push(
|
||||
s.match(/^xn--/) ?
|
||||
punycode.decode(s.slice(4)) :
|
||||
s
|
||||
);
|
||||
}
|
||||
return out.join(".");
|
||||
}
|
||||
}();
|
@ -1,23 +0,0 @@
|
||||
/* zlib.js 2012 - imaya [ https://github.com/imaya/zlib.js ] The MIT License */(function() {'use strict';var n=void 0,u=!0,aa=this;function ba(e,d){var c=e.split("."),f=aa;!(c[0]in f)&&f.execScript&&f.execScript("var "+c[0]);for(var a;c.length&&(a=c.shift());)!c.length&&d!==n?f[a]=d:f=f[a]?f[a]:f[a]={}};var C="undefined"!==typeof Uint8Array&&"undefined"!==typeof Uint16Array&&"undefined"!==typeof Uint32Array&&"undefined"!==typeof DataView;function K(e,d){this.index="number"===typeof d?d:0;this.d=0;this.buffer=e instanceof(C?Uint8Array:Array)?e:new (C?Uint8Array:Array)(32768);if(2*this.buffer.length<=this.index)throw Error("invalid index");this.buffer.length<=this.index&&ca(this)}function ca(e){var d=e.buffer,c,f=d.length,a=new (C?Uint8Array:Array)(f<<1);if(C)a.set(d);else for(c=0;c<f;++c)a[c]=d[c];return e.buffer=a}
|
||||
K.prototype.a=function(e,d,c){var f=this.buffer,a=this.index,b=this.d,k=f[a],m;c&&1<d&&(e=8<d?(L[e&255]<<24|L[e>>>8&255]<<16|L[e>>>16&255]<<8|L[e>>>24&255])>>32-d:L[e]>>8-d);if(8>d+b)k=k<<d|e,b+=d;else for(m=0;m<d;++m)k=k<<1|e>>d-m-1&1,8===++b&&(b=0,f[a++]=L[k],k=0,a===f.length&&(f=ca(this)));f[a]=k;this.buffer=f;this.d=b;this.index=a};K.prototype.finish=function(){var e=this.buffer,d=this.index,c;0<this.d&&(e[d]<<=8-this.d,e[d]=L[e[d]],d++);C?c=e.subarray(0,d):(e.length=d,c=e);return c};
|
||||
var ga=new (C?Uint8Array:Array)(256),M;for(M=0;256>M;++M){for(var R=M,S=R,ha=7,R=R>>>1;R;R>>>=1)S<<=1,S|=R&1,--ha;ga[M]=(S<<ha&255)>>>0}var L=ga;function ja(e){this.buffer=new (C?Uint16Array:Array)(2*e);this.length=0}ja.prototype.getParent=function(e){return 2*((e-2)/4|0)};ja.prototype.push=function(e,d){var c,f,a=this.buffer,b;c=this.length;a[this.length++]=d;for(a[this.length++]=e;0<c;)if(f=this.getParent(c),a[c]>a[f])b=a[c],a[c]=a[f],a[f]=b,b=a[c+1],a[c+1]=a[f+1],a[f+1]=b,c=f;else break;return this.length};
|
||||
ja.prototype.pop=function(){var e,d,c=this.buffer,f,a,b;d=c[0];e=c[1];this.length-=2;c[0]=c[this.length];c[1]=c[this.length+1];for(b=0;;){a=2*b+2;if(a>=this.length)break;a+2<this.length&&c[a+2]>c[a]&&(a+=2);if(c[a]>c[b])f=c[b],c[b]=c[a],c[a]=f,f=c[b+1],c[b+1]=c[a+1],c[a+1]=f;else break;b=a}return{index:e,value:d,length:this.length}};function ka(e,d){this.e=ma;this.f=0;this.input=C&&e instanceof Array?new Uint8Array(e):e;this.c=0;d&&(d.lazy&&(this.f=d.lazy),"number"===typeof d.compressionType&&(this.e=d.compressionType),d.outputBuffer&&(this.b=C&&d.outputBuffer instanceof Array?new Uint8Array(d.outputBuffer):d.outputBuffer),"number"===typeof d.outputIndex&&(this.c=d.outputIndex));this.b||(this.b=new (C?Uint8Array:Array)(32768))}var ma=2,T=[],U;
|
||||
for(U=0;288>U;U++)switch(u){case 143>=U:T.push([U+48,8]);break;case 255>=U:T.push([U-144+400,9]);break;case 279>=U:T.push([U-256+0,7]);break;case 287>=U:T.push([U-280+192,8]);break;default:throw"invalid literal: "+U;}
|
||||
ka.prototype.h=function(){var e,d,c,f,a=this.input;switch(this.e){case 0:c=0;for(f=a.length;c<f;){d=C?a.subarray(c,c+65535):a.slice(c,c+65535);c+=d.length;var b=d,k=c===f,m=n,g=n,p=n,v=n,x=n,l=this.b,h=this.c;if(C){for(l=new Uint8Array(this.b.buffer);l.length<=h+b.length+5;)l=new Uint8Array(l.length<<1);l.set(this.b)}m=k?1:0;l[h++]=m|0;g=b.length;p=~g+65536&65535;l[h++]=g&255;l[h++]=g>>>8&255;l[h++]=p&255;l[h++]=p>>>8&255;if(C)l.set(b,h),h+=b.length,l=l.subarray(0,h);else{v=0;for(x=b.length;v<x;++v)l[h++]=
|
||||
b[v];l.length=h}this.c=h;this.b=l}break;case 1:var q=new K(C?new Uint8Array(this.b.buffer):this.b,this.c);q.a(1,1,u);q.a(1,2,u);var t=na(this,a),w,da,z;w=0;for(da=t.length;w<da;w++)if(z=t[w],K.prototype.a.apply(q,T[z]),256<z)q.a(t[++w],t[++w],u),q.a(t[++w],5),q.a(t[++w],t[++w],u);else if(256===z)break;this.b=q.finish();this.c=this.b.length;break;case ma:var B=new K(C?new Uint8Array(this.b.buffer):this.b,this.c),ra,J,N,O,P,Ia=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],W,sa,X,ta,ea,ia=Array(19),
|
||||
ua,Q,fa,y,va;ra=ma;B.a(1,1,u);B.a(ra,2,u);J=na(this,a);W=oa(this.j,15);sa=pa(W);X=oa(this.i,7);ta=pa(X);for(N=286;257<N&&0===W[N-1];N--);for(O=30;1<O&&0===X[O-1];O--);var wa=N,xa=O,F=new (C?Uint32Array:Array)(wa+xa),r,G,s,Y,E=new (C?Uint32Array:Array)(316),D,A,H=new (C?Uint8Array:Array)(19);for(r=G=0;r<wa;r++)F[G++]=W[r];for(r=0;r<xa;r++)F[G++]=X[r];if(!C){r=0;for(Y=H.length;r<Y;++r)H[r]=0}r=D=0;for(Y=F.length;r<Y;r+=G){for(G=1;r+G<Y&&F[r+G]===F[r];++G);s=G;if(0===F[r])if(3>s)for(;0<s--;)E[D++]=0,
|
||||
H[0]++;else for(;0<s;)A=138>s?s:138,A>s-3&&A<s&&(A=s-3),10>=A?(E[D++]=17,E[D++]=A-3,H[17]++):(E[D++]=18,E[D++]=A-11,H[18]++),s-=A;else if(E[D++]=F[r],H[F[r]]++,s--,3>s)for(;0<s--;)E[D++]=F[r],H[F[r]]++;else for(;0<s;)A=6>s?s:6,A>s-3&&A<s&&(A=s-3),E[D++]=16,E[D++]=A-3,H[16]++,s-=A}e=C?E.subarray(0,D):E.slice(0,D);ea=oa(H,7);for(y=0;19>y;y++)ia[y]=ea[Ia[y]];for(P=19;4<P&&0===ia[P-1];P--);ua=pa(ea);B.a(N-257,5,u);B.a(O-1,5,u);B.a(P-4,4,u);for(y=0;y<P;y++)B.a(ia[y],3,u);y=0;for(va=e.length;y<va;y++)if(Q=
|
||||
e[y],B.a(ua[Q],ea[Q],u),16<=Q){y++;switch(Q){case 16:fa=2;break;case 17:fa=3;break;case 18:fa=7;break;default:throw"invalid code: "+Q;}B.a(e[y],fa,u)}var ya=[sa,W],za=[ta,X],I,Aa,Z,la,Ba,Ca,Da,Ea;Ba=ya[0];Ca=ya[1];Da=za[0];Ea=za[1];I=0;for(Aa=J.length;I<Aa;++I)if(Z=J[I],B.a(Ba[Z],Ca[Z],u),256<Z)B.a(J[++I],J[++I],u),la=J[++I],B.a(Da[la],Ea[la],u),B.a(J[++I],J[++I],u);else if(256===Z)break;this.b=B.finish();this.c=this.b.length;break;default:throw"invalid compression type";}return this.b};
|
||||
function qa(e,d){this.length=e;this.g=d}
|
||||
var Fa=function(){function e(a){switch(u){case 3===a:return[257,a-3,0];case 4===a:return[258,a-4,0];case 5===a:return[259,a-5,0];case 6===a:return[260,a-6,0];case 7===a:return[261,a-7,0];case 8===a:return[262,a-8,0];case 9===a:return[263,a-9,0];case 10===a:return[264,a-10,0];case 12>=a:return[265,a-11,1];case 14>=a:return[266,a-13,1];case 16>=a:return[267,a-15,1];case 18>=a:return[268,a-17,1];case 22>=a:return[269,a-19,2];case 26>=a:return[270,a-23,2];case 30>=a:return[271,a-27,2];case 34>=a:return[272,
|
||||
a-31,2];case 42>=a:return[273,a-35,3];case 50>=a:return[274,a-43,3];case 58>=a:return[275,a-51,3];case 66>=a:return[276,a-59,3];case 82>=a:return[277,a-67,4];case 98>=a:return[278,a-83,4];case 114>=a:return[279,a-99,4];case 130>=a:return[280,a-115,4];case 162>=a:return[281,a-131,5];case 194>=a:return[282,a-163,5];case 226>=a:return[283,a-195,5];case 257>=a:return[284,a-227,5];case 258===a:return[285,a-258,0];default:throw"invalid length: "+a;}}var d=[],c,f;for(c=3;258>=c;c++)f=e(c),d[c]=f[2]<<24|
|
||||
f[1]<<16|f[0];return d}(),Ga=C?new Uint32Array(Fa):Fa;
|
||||
function na(e,d){function c(a,c){var b=a.g,d=[],f=0,e;e=Ga[a.length];d[f++]=e&65535;d[f++]=e>>16&255;d[f++]=e>>24;var g;switch(u){case 1===b:g=[0,b-1,0];break;case 2===b:g=[1,b-2,0];break;case 3===b:g=[2,b-3,0];break;case 4===b:g=[3,b-4,0];break;case 6>=b:g=[4,b-5,1];break;case 8>=b:g=[5,b-7,1];break;case 12>=b:g=[6,b-9,2];break;case 16>=b:g=[7,b-13,2];break;case 24>=b:g=[8,b-17,3];break;case 32>=b:g=[9,b-25,3];break;case 48>=b:g=[10,b-33,4];break;case 64>=b:g=[11,b-49,4];break;case 96>=b:g=[12,b-
|
||||
65,5];break;case 128>=b:g=[13,b-97,5];break;case 192>=b:g=[14,b-129,6];break;case 256>=b:g=[15,b-193,6];break;case 384>=b:g=[16,b-257,7];break;case 512>=b:g=[17,b-385,7];break;case 768>=b:g=[18,b-513,8];break;case 1024>=b:g=[19,b-769,8];break;case 1536>=b:g=[20,b-1025,9];break;case 2048>=b:g=[21,b-1537,9];break;case 3072>=b:g=[22,b-2049,10];break;case 4096>=b:g=[23,b-3073,10];break;case 6144>=b:g=[24,b-4097,11];break;case 8192>=b:g=[25,b-6145,11];break;case 12288>=b:g=[26,b-8193,12];break;case 16384>=
|
||||
b:g=[27,b-12289,12];break;case 24576>=b:g=[28,b-16385,13];break;case 32768>=b:g=[29,b-24577,13];break;default:throw"invalid distance";}e=g;d[f++]=e[0];d[f++]=e[1];d[f++]=e[2];var k,m;k=0;for(m=d.length;k<m;++k)l[h++]=d[k];t[d[0]]++;w[d[3]]++;q=a.length+c-1;x=null}var f,a,b,k,m,g={},p,v,x,l=C?new Uint16Array(2*d.length):[],h=0,q=0,t=new (C?Uint32Array:Array)(286),w=new (C?Uint32Array:Array)(30),da=e.f,z;if(!C){for(b=0;285>=b;)t[b++]=0;for(b=0;29>=b;)w[b++]=0}t[256]=1;f=0;for(a=d.length;f<a;++f){b=
|
||||
m=0;for(k=3;b<k&&f+b!==a;++b)m=m<<8|d[f+b];g[m]===n&&(g[m]=[]);p=g[m];if(!(0<q--)){for(;0<p.length&&32768<f-p[0];)p.shift();if(f+3>=a){x&&c(x,-1);b=0;for(k=a-f;b<k;++b)z=d[f+b],l[h++]=z,++t[z];break}0<p.length?(v=Ha(d,f,p),x?x.length<v.length?(z=d[f-1],l[h++]=z,++t[z],c(v,0)):c(x,-1):v.length<da?x=v:c(v,0)):x?c(x,-1):(z=d[f],l[h++]=z,++t[z])}p.push(f)}l[h++]=256;t[256]++;e.j=t;e.i=w;return C?l.subarray(0,h):l}
|
||||
function Ha(e,d,c){var f,a,b=0,k,m,g,p,v=e.length;m=0;p=c.length;a:for(;m<p;m++){f=c[p-m-1];k=3;if(3<b){for(g=b;3<g;g--)if(e[f+g-1]!==e[d+g-1])continue a;k=b}for(;258>k&&d+k<v&&e[f+k]===e[d+k];)++k;k>b&&(a=f,b=k);if(258===k)break}return new qa(b,d-a)}
|
||||
function oa(e,d){var c=e.length,f=new ja(572),a=new (C?Uint8Array:Array)(c),b,k,m,g,p;if(!C)for(g=0;g<c;g++)a[g]=0;for(g=0;g<c;++g)0<e[g]&&f.push(g,e[g]);b=Array(f.length/2);k=new (C?Uint32Array:Array)(f.length/2);if(1===b.length)return a[f.pop().index]=1,a;g=0;for(p=f.length/2;g<p;++g)b[g]=f.pop(),k[g]=b[g].value;m=Ja(k,k.length,d);g=0;for(p=b.length;g<p;++g)a[b[g].index]=m[g];return a}
|
||||
function Ja(e,d,c){function f(a){var b=g[a][p[a]];b===d?(f(a+1),f(a+1)):--k[b];++p[a]}var a=new (C?Uint16Array:Array)(c),b=new (C?Uint8Array:Array)(c),k=new (C?Uint8Array:Array)(d),m=Array(c),g=Array(c),p=Array(c),v=(1<<c)-d,x=1<<c-1,l,h,q,t,w;a[c-1]=d;for(h=0;h<c;++h)v<x?b[h]=0:(b[h]=1,v-=x),v<<=1,a[c-2-h]=(a[c-1-h]/2|0)+d;a[0]=b[0];m[0]=Array(a[0]);g[0]=Array(a[0]);for(h=1;h<c;++h)a[h]>2*a[h-1]+b[h]&&(a[h]=2*a[h-1]+b[h]),m[h]=Array(a[h]),g[h]=Array(a[h]);for(l=0;l<d;++l)k[l]=c;for(q=0;q<a[c-1];++q)m[c-
|
||||
1][q]=e[q],g[c-1][q]=q;for(l=0;l<c;++l)p[l]=0;1===b[c-1]&&(--k[0],++p[c-1]);for(h=c-2;0<=h;--h){t=l=0;w=p[h+1];for(q=0;q<a[h];q++)t=m[h+1][w]+m[h+1][w+1],t>e[l]?(m[h][q]=t,g[h][q]=d,w+=2):(m[h][q]=e[l],g[h][q]=l,++l);p[h]=0;1===b[h]&&f(h)}return k}
|
||||
function pa(e){var d=new (C?Uint16Array:Array)(e.length),c=[],f=[],a=0,b,k,m,g;b=0;for(k=e.length;b<k;b++)c[e[b]]=(c[e[b]]|0)+1;b=1;for(k=16;b<=k;b++)f[b]=a,a+=c[b]|0,a<<=1;b=0;for(k=e.length;b<k;b++){a=f[e[b]];f[e[b]]+=1;m=d[b]=0;for(g=e[b];m<g;m++)d[b]=d[b]<<1|a&1,a>>>=1}return d};ba("Zlib.RawDeflate",ka);ba("Zlib.RawDeflate.prototype.compress",ka.prototype.h);var Ka={NONE:0,FIXED:1,DYNAMIC:ma},V,La,$,Ma;if(Object.keys)V=Object.keys(Ka);else for(La in V=[],$=0,Ka)V[$++]=La;$=0;for(Ma=V.length;$<Ma;++$)La=V[$],ba("Zlib.RawDeflate.CompressionType."+La,Ka[La]);}).call(this);
|
@ -1,14 +0,0 @@
|
||||
/* zlib.js 2012 - imaya [ https://github.com/imaya/zlib.js ] The MIT License */(function() {'use strict';var l=this;function p(b,e){var a=b.split("."),c=l;!(a[0]in c)&&c.execScript&&c.execScript("var "+a[0]);for(var d;a.length&&(d=a.shift());)!a.length&&void 0!==e?c[d]=e:c=c[d]?c[d]:c[d]={}};var q="undefined"!==typeof Uint8Array&&"undefined"!==typeof Uint16Array&&"undefined"!==typeof Uint32Array&&"undefined"!==typeof DataView;function t(b){var e=b.length,a=0,c=Number.POSITIVE_INFINITY,d,f,g,h,k,m,r,n,s,J;for(n=0;n<e;++n)b[n]>a&&(a=b[n]),b[n]<c&&(c=b[n]);d=1<<a;f=new (q?Uint32Array:Array)(d);g=1;h=0;for(k=2;g<=a;){for(n=0;n<e;++n)if(b[n]===g){m=0;r=h;for(s=0;s<g;++s)m=m<<1|r&1,r>>=1;J=g<<16|n;for(s=m;s<d;s+=k)f[s]=J;++h}++g;h<<=1;k<<=1}return[f,a,c]};function u(b,e){this.g=[];this.h=32768;this.c=this.f=this.d=this.k=0;this.input=q?new Uint8Array(b):b;this.l=!1;this.i=v;this.q=!1;if(e||!(e={}))e.index&&(this.d=e.index),e.bufferSize&&(this.h=e.bufferSize),e.bufferType&&(this.i=e.bufferType),e.resize&&(this.q=e.resize);switch(this.i){case w:this.a=32768;this.b=new (q?Uint8Array:Array)(32768+this.h+258);break;case v:this.a=0;this.b=new (q?Uint8Array:Array)(this.h);this.e=this.v;this.m=this.s;this.j=this.t;break;default:throw Error("invalid inflate mode");
|
||||
}}var w=0,v=1;
|
||||
u.prototype.u=function(){for(;!this.l;){var b=x(this,3);b&1&&(this.l=!0);b>>>=1;switch(b){case 0:var e=this.input,a=this.d,c=this.b,d=this.a,f=e.length,g=void 0,h=void 0,k=c.length,m=void 0;this.c=this.f=0;if(a+1>=f)throw Error("invalid uncompressed block header: LEN");g=e[a++]|e[a++]<<8;if(a+1>=f)throw Error("invalid uncompressed block header: NLEN");h=e[a++]|e[a++]<<8;if(g===~h)throw Error("invalid uncompressed block header: length verify");if(a+g>e.length)throw Error("input buffer is broken");switch(this.i){case w:for(;d+
|
||||
g>c.length;){m=k-d;g-=m;if(q)c.set(e.subarray(a,a+m),d),d+=m,a+=m;else for(;m--;)c[d++]=e[a++];this.a=d;c=this.e();d=this.a}break;case v:for(;d+g>c.length;)c=this.e({o:2});break;default:throw Error("invalid inflate mode");}if(q)c.set(e.subarray(a,a+g),d),d+=g,a+=g;else for(;g--;)c[d++]=e[a++];this.d=a;this.a=d;this.b=c;break;case 1:this.j(y,z);break;case 2:A(this);break;default:throw Error("unknown BTYPE: "+b);}}return this.m()};
|
||||
var B=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],C=q?new Uint16Array(B):B,D=[3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,258,258],E=q?new Uint16Array(D):D,F=[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0],G=q?new Uint8Array(F):F,H=[1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577],I=q?new Uint16Array(H):H,K=[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,
|
||||
13],L=q?new Uint8Array(K):K,M=new (q?Uint8Array:Array)(288),N,O;N=0;for(O=M.length;N<O;++N)M[N]=143>=N?8:255>=N?9:279>=N?7:8;var y=t(M),P=new (q?Uint8Array:Array)(30),Q,R;Q=0;for(R=P.length;Q<R;++Q)P[Q]=5;var z=t(P);function x(b,e){for(var a=b.f,c=b.c,d=b.input,f=b.d,g=d.length,h;c<e;){if(f>=g)throw Error("input buffer is broken");a|=d[f++]<<c;c+=8}h=a&(1<<e)-1;b.f=a>>>e;b.c=c-e;b.d=f;return h}
|
||||
function S(b,e){for(var a=b.f,c=b.c,d=b.input,f=b.d,g=d.length,h=e[0],k=e[1],m,r;c<k&&!(f>=g);)a|=d[f++]<<c,c+=8;m=h[a&(1<<k)-1];r=m>>>16;b.f=a>>r;b.c=c-r;b.d=f;return m&65535}
|
||||
function A(b){function e(a,b,c){var e,d=this.p,f,g;for(g=0;g<a;)switch(e=S(this,b),e){case 16:for(f=3+x(this,2);f--;)c[g++]=d;break;case 17:for(f=3+x(this,3);f--;)c[g++]=0;d=0;break;case 18:for(f=11+x(this,7);f--;)c[g++]=0;d=0;break;default:d=c[g++]=e}this.p=d;return c}var a=x(b,5)+257,c=x(b,5)+1,d=x(b,4)+4,f=new (q?Uint8Array:Array)(C.length),g,h,k,m;for(m=0;m<d;++m)f[C[m]]=x(b,3);if(!q){m=d;for(d=f.length;m<d;++m)f[C[m]]=0}g=t(f);h=new (q?Uint8Array:Array)(a);k=new (q?Uint8Array:Array)(c);b.p=0;
|
||||
b.j(t(e.call(b,a,g,h)),t(e.call(b,c,g,k)))}u.prototype.j=function(b,e){var a=this.b,c=this.a;this.n=b;for(var d=a.length-258,f,g,h,k;256!==(f=S(this,b));)if(256>f)c>=d&&(this.a=c,a=this.e(),c=this.a),a[c++]=f;else{g=f-257;k=E[g];0<G[g]&&(k+=x(this,G[g]));f=S(this,e);h=I[f];0<L[f]&&(h+=x(this,L[f]));c>=d&&(this.a=c,a=this.e(),c=this.a);for(;k--;)a[c]=a[c++-h]}for(;8<=this.c;)this.c-=8,this.d--;this.a=c};
|
||||
u.prototype.t=function(b,e){var a=this.b,c=this.a;this.n=b;for(var d=a.length,f,g,h,k;256!==(f=S(this,b));)if(256>f)c>=d&&(a=this.e(),d=a.length),a[c++]=f;else{g=f-257;k=E[g];0<G[g]&&(k+=x(this,G[g]));f=S(this,e);h=I[f];0<L[f]&&(h+=x(this,L[f]));c+k>d&&(a=this.e(),d=a.length);for(;k--;)a[c]=a[c++-h]}for(;8<=this.c;)this.c-=8,this.d--;this.a=c};
|
||||
u.prototype.e=function(){var b=new (q?Uint8Array:Array)(this.a-32768),e=this.a-32768,a,c,d=this.b;if(q)b.set(d.subarray(32768,b.length));else{a=0;for(c=b.length;a<c;++a)b[a]=d[a+32768]}this.g.push(b);this.k+=b.length;if(q)d.set(d.subarray(e,e+32768));else for(a=0;32768>a;++a)d[a]=d[e+a];this.a=32768;return d};
|
||||
u.prototype.v=function(b){var e,a=this.input.length/this.d+1|0,c,d,f,g=this.input,h=this.b;b&&("number"===typeof b.o&&(a=b.o),"number"===typeof b.r&&(a+=b.r));2>a?(c=(g.length-this.d)/this.n[2],f=258*(c/2)|0,d=f<h.length?h.length+f:h.length<<1):d=h.length*a;q?(e=new Uint8Array(d),e.set(h)):e=h;return this.b=e};
|
||||
u.prototype.m=function(){var b=0,e=this.b,a=this.g,c,d=new (q?Uint8Array:Array)(this.k+(this.a-32768)),f,g,h,k;if(0===a.length)return q?this.b.subarray(32768,this.a):this.b.slice(32768,this.a);f=0;for(g=a.length;f<g;++f){c=a[f];h=0;for(k=c.length;h<k;++h)d[b++]=c[h]}f=32768;for(g=this.a;f<g;++f)d[b++]=e[f];this.g=[];return this.buffer=d};
|
||||
u.prototype.s=function(){var b,e=this.a;q?this.q?(b=new Uint8Array(e),b.set(this.b.subarray(0,e))):b=this.b.subarray(0,e):(this.b.length>e&&(this.b.length=e),b=this.b);return this.buffer=b};p("Zlib.RawInflate",u);p("Zlib.RawInflate.prototype.decompress",u.prototype.u);var T={ADAPTIVE:v,BLOCK:w},U,V,W,X;if(Object.keys)U=Object.keys(T);else for(V in U=[],W=0,T)U[W++]=V;W=0;for(X=U.length;W<X;++W)V=U[W],p("Zlib.RawInflate.BufferType."+V,T[V]);}).call(this);
|
@ -26,7 +26,7 @@
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
var UAS_parser = {
|
||||
var UAS_parser = module.exports = {
|
||||
|
||||
parse: function (userAgent) {
|
||||
var result = {
|
||||
|
@ -1,31 +0,0 @@
|
||||
/* zlib.js 2012 - imaya [ https://github.com/imaya/zlib.js ] The MIT License */(function() {'use strict';function m(a){throw a;}var q=void 0,u,aa=this;function v(a,b){var c=a.split("."),d=aa;!(c[0]in d)&&d.execScript&&d.execScript("var "+c[0]);for(var f;c.length&&(f=c.shift());)!c.length&&b!==q?d[f]=b:d=d[f]?d[f]:d[f]={}};var w="undefined"!==typeof Uint8Array&&"undefined"!==typeof Uint16Array&&"undefined"!==typeof Uint32Array&&"undefined"!==typeof DataView;new (w?Uint8Array:Array)(256);var x;for(x=0;256>x;++x)for(var y=x,ba=7,y=y>>>1;y;y>>>=1)--ba;var z=[0,1996959894,3993919788,2567524794,124634137,1886057615,3915621685,2657392035,249268274,2044508324,3772115230,2547177864,162941995,2125561021,3887607047,2428444049,498536548,1789927666,4089016648,2227061214,450548861,1843258603,4107580753,2211677639,325883990,1684777152,4251122042,2321926636,335633487,1661365465,4195302755,2366115317,997073096,1281953886,3579855332,2724688242,1006888145,1258607687,3524101629,2768942443,901097722,1119000684,3686517206,2898065728,853044451,1172266101,3705015759,
|
||||
2882616665,651767980,1373503546,3369554304,3218104598,565507253,1454621731,3485111705,3099436303,671266974,1594198024,3322730930,2970347812,795835527,1483230225,3244367275,3060149565,1994146192,31158534,2563907772,4023717930,1907459465,112637215,2680153253,3904427059,2013776290,251722036,2517215374,3775830040,2137656763,141376813,2439277719,3865271297,1802195444,476864866,2238001368,4066508878,1812370925,453092731,2181625025,4111451223,1706088902,314042704,2344532202,4240017532,1658658271,366619977,
|
||||
2362670323,4224994405,1303535960,984961486,2747007092,3569037538,1256170817,1037604311,2765210733,3554079995,1131014506,879679996,2909243462,3663771856,1141124467,855842277,2852801631,3708648649,1342533948,654459306,3188396048,3373015174,1466479909,544179635,3110523913,3462522015,1591671054,702138776,2966460450,3352799412,1504918807,783551873,3082640443,3233442989,3988292384,2596254646,62317068,1957810842,3939845945,2647816111,81470997,1943803523,3814918930,2489596804,225274430,2053790376,3826175755,
|
||||
2466906013,167816743,2097651377,4027552580,2265490386,503444072,1762050814,4150417245,2154129355,426522225,1852507879,4275313526,2312317920,282753626,1742555852,4189708143,2394877945,397917763,1622183637,3604390888,2714866558,953729732,1340076626,3518719985,2797360999,1068828381,1219638859,3624741850,2936675148,906185462,1090812512,3747672003,2825379669,829329135,1181335161,3412177804,3160834842,628085408,1382605366,3423369109,3138078467,570562233,1426400815,3317316542,2998733608,733239954,1555261956,
|
||||
3268935591,3050360625,752459403,1541320221,2607071920,3965973030,1969922972,40735498,2617837225,3943577151,1913087877,83908371,2512341634,3803740692,2075208622,213261112,2463272603,3855990285,2094854071,198958881,2262029012,4057260610,1759359992,534414190,2176718541,4139329115,1873836001,414664567,2282248934,4279200368,1711684554,285281116,2405801727,4167216745,1634467795,376229701,2685067896,3608007406,1308918612,956543938,2808555105,3495958263,1231636301,1047427035,2932959818,3654703836,1088359270,
|
||||
936918E3,2847714899,3736837829,1202900863,817233897,3183342108,3401237130,1404277552,615818150,3134207493,3453421203,1423857449,601450431,3009837614,3294710456,1567103746,711928724,3020668471,3272380065,1510334235,755167117],B=w?new Uint32Array(z):z;function C(a){var b=a.length,c=0,d=Number.POSITIVE_INFINITY,f,h,k,e,g,l,p,s,r,A;for(s=0;s<b;++s)a[s]>c&&(c=a[s]),a[s]<d&&(d=a[s]);f=1<<c;h=new (w?Uint32Array:Array)(f);k=1;e=0;for(g=2;k<=c;){for(s=0;s<b;++s)if(a[s]===k){l=0;p=e;for(r=0;r<k;++r)l=l<<1|p&1,p>>=1;A=k<<16|s;for(r=l;r<f;r+=g)h[r]=A;++e}++k;e<<=1;g<<=1}return[h,c,d]};var D=[],E;for(E=0;288>E;E++)switch(!0){case 143>=E:D.push([E+48,8]);break;case 255>=E:D.push([E-144+400,9]);break;case 279>=E:D.push([E-256+0,7]);break;case 287>=E:D.push([E-280+192,8]);break;default:m("invalid literal: "+E)}
|
||||
var ca=function(){function a(a){switch(!0){case 3===a:return[257,a-3,0];case 4===a:return[258,a-4,0];case 5===a:return[259,a-5,0];case 6===a:return[260,a-6,0];case 7===a:return[261,a-7,0];case 8===a:return[262,a-8,0];case 9===a:return[263,a-9,0];case 10===a:return[264,a-10,0];case 12>=a:return[265,a-11,1];case 14>=a:return[266,a-13,1];case 16>=a:return[267,a-15,1];case 18>=a:return[268,a-17,1];case 22>=a:return[269,a-19,2];case 26>=a:return[270,a-23,2];case 30>=a:return[271,a-27,2];case 34>=a:return[272,
|
||||
a-31,2];case 42>=a:return[273,a-35,3];case 50>=a:return[274,a-43,3];case 58>=a:return[275,a-51,3];case 66>=a:return[276,a-59,3];case 82>=a:return[277,a-67,4];case 98>=a:return[278,a-83,4];case 114>=a:return[279,a-99,4];case 130>=a:return[280,a-115,4];case 162>=a:return[281,a-131,5];case 194>=a:return[282,a-163,5];case 226>=a:return[283,a-195,5];case 257>=a:return[284,a-227,5];case 258===a:return[285,a-258,0];default:m("invalid length: "+a)}}var b=[],c,d;for(c=3;258>=c;c++)d=a(c),b[c]=d[2]<<24|d[1]<<
|
||||
16|d[0];return b}();w&&new Uint32Array(ca);function F(a,b){this.l=[];this.m=32768;this.d=this.f=this.c=this.t=0;this.input=w?new Uint8Array(a):a;this.u=!1;this.n=G;this.L=!1;if(b||!(b={}))b.index&&(this.c=b.index),b.bufferSize&&(this.m=b.bufferSize),b.bufferType&&(this.n=b.bufferType),b.resize&&(this.L=b.resize);switch(this.n){case H:this.a=32768;this.b=new (w?Uint8Array:Array)(32768+this.m+258);break;case G:this.a=0;this.b=new (w?Uint8Array:Array)(this.m);this.e=this.X;this.B=this.S;this.q=this.W;break;default:m(Error("invalid inflate mode"))}}
|
||||
var H=0,G=1;
|
||||
F.prototype.r=function(){for(;!this.u;){var a=I(this,3);a&1&&(this.u=!0);a>>>=1;switch(a){case 0:var b=this.input,c=this.c,d=this.b,f=this.a,h=b.length,k=q,e=q,g=d.length,l=q;this.d=this.f=0;c+1>=h&&m(Error("invalid uncompressed block header: LEN"));k=b[c++]|b[c++]<<8;c+1>=h&&m(Error("invalid uncompressed block header: NLEN"));e=b[c++]|b[c++]<<8;k===~e&&m(Error("invalid uncompressed block header: length verify"));c+k>b.length&&m(Error("input buffer is broken"));switch(this.n){case H:for(;f+k>d.length;){l=
|
||||
g-f;k-=l;if(w)d.set(b.subarray(c,c+l),f),f+=l,c+=l;else for(;l--;)d[f++]=b[c++];this.a=f;d=this.e();f=this.a}break;case G:for(;f+k>d.length;)d=this.e({H:2});break;default:m(Error("invalid inflate mode"))}if(w)d.set(b.subarray(c,c+k),f),f+=k,c+=k;else for(;k--;)d[f++]=b[c++];this.c=c;this.a=f;this.b=d;break;case 1:this.q(da,ea);break;case 2:fa(this);break;default:m(Error("unknown BTYPE: "+a))}}return this.B()};
|
||||
var J=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],K=w?new Uint16Array(J):J,L=[3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,258,258],M=w?new Uint16Array(L):L,ga=[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0],O=w?new Uint8Array(ga):ga,ha=[1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577],ia=w?new Uint16Array(ha):ha,ja=[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,
|
||||
12,12,13,13],P=w?new Uint8Array(ja):ja,Q=new (w?Uint8Array:Array)(288),R,la;R=0;for(la=Q.length;R<la;++R)Q[R]=143>=R?8:255>=R?9:279>=R?7:8;var da=C(Q),S=new (w?Uint8Array:Array)(30),T,ma;T=0;for(ma=S.length;T<ma;++T)S[T]=5;var ea=C(S);function I(a,b){for(var c=a.f,d=a.d,f=a.input,h=a.c,k=f.length,e;d<b;)h>=k&&m(Error("input buffer is broken")),c|=f[h++]<<d,d+=8;e=c&(1<<b)-1;a.f=c>>>b;a.d=d-b;a.c=h;return e}
|
||||
function U(a,b){for(var c=a.f,d=a.d,f=a.input,h=a.c,k=f.length,e=b[0],g=b[1],l,p;d<g&&!(h>=k);)c|=f[h++]<<d,d+=8;l=e[c&(1<<g)-1];p=l>>>16;a.f=c>>p;a.d=d-p;a.c=h;return l&65535}
|
||||
function fa(a){function b(a,b,c){var d,e=this.K,f,g;for(g=0;g<a;)switch(d=U(this,b),d){case 16:for(f=3+I(this,2);f--;)c[g++]=e;break;case 17:for(f=3+I(this,3);f--;)c[g++]=0;e=0;break;case 18:for(f=11+I(this,7);f--;)c[g++]=0;e=0;break;default:e=c[g++]=d}this.K=e;return c}var c=I(a,5)+257,d=I(a,5)+1,f=I(a,4)+4,h=new (w?Uint8Array:Array)(K.length),k,e,g,l;for(l=0;l<f;++l)h[K[l]]=I(a,3);if(!w){l=f;for(f=h.length;l<f;++l)h[K[l]]=0}k=C(h);e=new (w?Uint8Array:Array)(c);g=new (w?Uint8Array:Array)(d);a.K=
|
||||
0;a.q(C(b.call(a,c,k,e)),C(b.call(a,d,k,g)))}u=F.prototype;u.q=function(a,b){var c=this.b,d=this.a;this.C=a;for(var f=c.length-258,h,k,e,g;256!==(h=U(this,a));)if(256>h)d>=f&&(this.a=d,c=this.e(),d=this.a),c[d++]=h;else{k=h-257;g=M[k];0<O[k]&&(g+=I(this,O[k]));h=U(this,b);e=ia[h];0<P[h]&&(e+=I(this,P[h]));d>=f&&(this.a=d,c=this.e(),d=this.a);for(;g--;)c[d]=c[d++-e]}for(;8<=this.d;)this.d-=8,this.c--;this.a=d};
|
||||
u.W=function(a,b){var c=this.b,d=this.a;this.C=a;for(var f=c.length,h,k,e,g;256!==(h=U(this,a));)if(256>h)d>=f&&(c=this.e(),f=c.length),c[d++]=h;else{k=h-257;g=M[k];0<O[k]&&(g+=I(this,O[k]));h=U(this,b);e=ia[h];0<P[h]&&(e+=I(this,P[h]));d+g>f&&(c=this.e(),f=c.length);for(;g--;)c[d]=c[d++-e]}for(;8<=this.d;)this.d-=8,this.c--;this.a=d};
|
||||
u.e=function(){var a=new (w?Uint8Array:Array)(this.a-32768),b=this.a-32768,c,d,f=this.b;if(w)a.set(f.subarray(32768,a.length));else{c=0;for(d=a.length;c<d;++c)a[c]=f[c+32768]}this.l.push(a);this.t+=a.length;if(w)f.set(f.subarray(b,b+32768));else for(c=0;32768>c;++c)f[c]=f[b+c];this.a=32768;return f};
|
||||
u.X=function(a){var b,c=this.input.length/this.c+1|0,d,f,h,k=this.input,e=this.b;a&&("number"===typeof a.H&&(c=a.H),"number"===typeof a.Q&&(c+=a.Q));2>c?(d=(k.length-this.c)/this.C[2],h=258*(d/2)|0,f=h<e.length?e.length+h:e.length<<1):f=e.length*c;w?(b=new Uint8Array(f),b.set(e)):b=e;return this.b=b};
|
||||
u.B=function(){var a=0,b=this.b,c=this.l,d,f=new (w?Uint8Array:Array)(this.t+(this.a-32768)),h,k,e,g;if(0===c.length)return w?this.b.subarray(32768,this.a):this.b.slice(32768,this.a);h=0;for(k=c.length;h<k;++h){d=c[h];e=0;for(g=d.length;e<g;++e)f[a++]=d[e]}h=32768;for(k=this.a;h<k;++h)f[a++]=b[h];this.l=[];return this.buffer=f};
|
||||
u.S=function(){var a,b=this.a;w?this.L?(a=new Uint8Array(b),a.set(this.b.subarray(0,b))):a=this.b.subarray(0,b):(this.b.length>b&&(this.b.length=b),a=this.b);return this.buffer=a};function V(a){a=a||{};this.files=[];this.v=a.comment}V.prototype.M=function(a){this.j=a};V.prototype.s=function(a){var b=a[2]&65535|2;return b*(b^1)>>8&255};V.prototype.k=function(a,b){a[0]=(B[(a[0]^b)&255]^a[0]>>>8)>>>0;a[1]=(6681*(20173*(a[1]+(a[0]&255))>>>0)>>>0)+1>>>0;a[2]=(B[(a[2]^a[1]>>>24)&255]^a[2]>>>8)>>>0};V.prototype.U=function(a){var b=[305419896,591751049,878082192],c,d;w&&(b=new Uint32Array(b));c=0;for(d=a.length;c<d;++c)this.k(b,a[c]&255);return b};function W(a,b){b=b||{};this.input=w&&a instanceof Array?new Uint8Array(a):a;this.c=0;this.ca=b.verify||!1;this.j=b.password}var na={P:0,N:8},X=[80,75,1,2],Y=[80,75,3,4],Z=[80,75,5,6];function oa(a,b){this.input=a;this.offset=b}
|
||||
oa.prototype.parse=function(){var a=this.input,b=this.offset;(a[b++]!==X[0]||a[b++]!==X[1]||a[b++]!==X[2]||a[b++]!==X[3])&&m(Error("invalid file header signature"));this.version=a[b++];this.ja=a[b++];this.$=a[b++]|a[b++]<<8;this.I=a[b++]|a[b++]<<8;this.A=a[b++]|a[b++]<<8;this.time=a[b++]|a[b++]<<8;this.V=a[b++]|a[b++]<<8;this.p=(a[b++]|a[b++]<<8|a[b++]<<16|a[b++]<<24)>>>0;this.z=(a[b++]|a[b++]<<8|a[b++]<<16|a[b++]<<24)>>>0;this.J=(a[b++]|a[b++]<<8|a[b++]<<16|a[b++]<<24)>>>0;this.h=a[b++]|a[b++]<<
|
||||
8;this.g=a[b++]|a[b++]<<8;this.F=a[b++]|a[b++]<<8;this.fa=a[b++]|a[b++]<<8;this.ha=a[b++]|a[b++]<<8;this.ga=a[b++]|a[b++]<<8|a[b++]<<16|a[b++]<<24;this.aa=(a[b++]|a[b++]<<8|a[b++]<<16|a[b++]<<24)>>>0;this.filename=String.fromCharCode.apply(null,w?a.subarray(b,b+=this.h):a.slice(b,b+=this.h));this.Y=w?a.subarray(b,b+=this.g):a.slice(b,b+=this.g);this.v=w?a.subarray(b,b+this.F):a.slice(b,b+this.F);this.length=b-this.offset};function pa(a,b){this.input=a;this.offset=b}var qa={O:1,da:8,ea:2048};
|
||||
pa.prototype.parse=function(){var a=this.input,b=this.offset;(a[b++]!==Y[0]||a[b++]!==Y[1]||a[b++]!==Y[2]||a[b++]!==Y[3])&&m(Error("invalid local file header signature"));this.$=a[b++]|a[b++]<<8;this.I=a[b++]|a[b++]<<8;this.A=a[b++]|a[b++]<<8;this.time=a[b++]|a[b++]<<8;this.V=a[b++]|a[b++]<<8;this.p=(a[b++]|a[b++]<<8|a[b++]<<16|a[b++]<<24)>>>0;this.z=(a[b++]|a[b++]<<8|a[b++]<<16|a[b++]<<24)>>>0;this.J=(a[b++]|a[b++]<<8|a[b++]<<16|a[b++]<<24)>>>0;this.h=a[b++]|a[b++]<<8;this.g=a[b++]|a[b++]<<8;this.filename=
|
||||
String.fromCharCode.apply(null,w?a.subarray(b,b+=this.h):a.slice(b,b+=this.h));this.Y=w?a.subarray(b,b+=this.g):a.slice(b,b+=this.g);this.length=b-this.offset};
|
||||
function $(a){var b=[],c={},d,f,h,k;if(!a.i){if(a.o===q){var e=a.input,g;if(!a.D)a:{var l=a.input,p;for(p=l.length-12;0<p;--p)if(l[p]===Z[0]&&l[p+1]===Z[1]&&l[p+2]===Z[2]&&l[p+3]===Z[3]){a.D=p;break a}m(Error("End of Central Directory Record not found"))}g=a.D;(e[g++]!==Z[0]||e[g++]!==Z[1]||e[g++]!==Z[2]||e[g++]!==Z[3])&&m(Error("invalid signature"));a.ia=e[g++]|e[g++]<<8;a.ka=e[g++]|e[g++]<<8;a.la=e[g++]|e[g++]<<8;a.ba=e[g++]|e[g++]<<8;a.R=(e[g++]|e[g++]<<8|e[g++]<<16|e[g++]<<24)>>>0;a.o=(e[g++]|
|
||||
e[g++]<<8|e[g++]<<16|e[g++]<<24)>>>0;a.w=e[g++]|e[g++]<<8;a.v=w?e.subarray(g,g+a.w):e.slice(g,g+a.w)}d=a.o;h=0;for(k=a.ba;h<k;++h)f=new oa(a.input,d),f.parse(),d+=f.length,b[h]=f,c[f.filename]=h;a.R<d-a.o&&m(Error("invalid file header size"));a.i=b;a.G=c}}u=W.prototype;u.Z=function(){var a=[],b,c,d;this.i||$(this);d=this.i;b=0;for(c=d.length;b<c;++b)a[b]=d[b].filename;return a};
|
||||
u.r=function(a,b){var c;this.G||$(this);c=this.G[a];c===q&&m(Error(a+" not found"));var d;d=b||{};var f=this.input,h=this.i,k,e,g,l,p,s,r,A;h||$(this);h[c]===q&&m(Error("wrong index"));e=h[c].aa;k=new pa(this.input,e);k.parse();e+=k.length;g=k.z;if(0!==(k.I&qa.O)){!d.password&&!this.j&&m(Error("please set password"));s=this.T(d.password||this.j);r=e;for(A=e+12;r<A;++r)ra(this,s,f[r]);e+=12;g-=12;r=e;for(A=e+g;r<A;++r)f[r]=ra(this,s,f[r])}switch(k.A){case na.P:l=w?this.input.subarray(e,e+g):this.input.slice(e,
|
||||
e+g);break;case na.N:l=(new F(this.input,{index:e,bufferSize:k.J})).r();break;default:m(Error("unknown compression type"))}if(this.ca){var t=q,n,N="number"===typeof t?t:t=0,ka=l.length;n=-1;for(N=ka&7;N--;++t)n=n>>>8^B[(n^l[t])&255];for(N=ka>>3;N--;t+=8)n=n>>>8^B[(n^l[t])&255],n=n>>>8^B[(n^l[t+1])&255],n=n>>>8^B[(n^l[t+2])&255],n=n>>>8^B[(n^l[t+3])&255],n=n>>>8^B[(n^l[t+4])&255],n=n>>>8^B[(n^l[t+5])&255],n=n>>>8^B[(n^l[t+6])&255],n=n>>>8^B[(n^l[t+7])&255];p=(n^4294967295)>>>0;k.p!==p&&m(Error("wrong crc: file=0x"+
|
||||
k.p.toString(16)+", data=0x"+p.toString(16)))}return l};u.M=function(a){this.j=a};function ra(a,b,c){c^=a.s(b);a.k(b,c);return c}u.k=V.prototype.k;u.T=V.prototype.U;u.s=V.prototype.s;v("Zlib.Unzip",W);v("Zlib.Unzip.prototype.decompress",W.prototype.r);v("Zlib.Unzip.prototype.getFilenames",W.prototype.Z);v("Zlib.Unzip.prototype.setPassword",W.prototype.M);}).call(this);
|
@ -1,360 +0,0 @@
|
||||
/** @license
|
||||
========================================================================
|
||||
vkBeautify - javascript plugin to pretty-print or minify text in XML, JSON, CSS and SQL formats.
|
||||
|
||||
Version - 0.99.00.beta
|
||||
Copyright (c) 2012 Vadim Kiryukhin
|
||||
vkiryukhin @ gmail.com
|
||||
http://www.eslinstructor.net/vkbeautify/
|
||||
|
||||
Dual licensed under the MIT and GPL licenses:
|
||||
http://www.opensource.org/licenses/mit-license.php
|
||||
http://www.gnu.org/licenses/gpl.html
|
||||
*/
|
||||
|
||||
/*
|
||||
* Pretty print
|
||||
*
|
||||
* vkbeautify.xml(text [,indent_pattern]);
|
||||
* vkbeautify.json(text [,indent_pattern]);
|
||||
* vkbeautify.css(text [,indent_pattern]);
|
||||
* vkbeautify.sql(text [,indent_pattern]);
|
||||
*
|
||||
* @text - String; text to beatufy;
|
||||
* @indent_pattern - Integer | String;
|
||||
* Integer: number of white spaces;
|
||||
* String: character string to visualize indentation ( can also be a set of white spaces )
|
||||
* Minify
|
||||
*
|
||||
* vkbeautify.xmlmin(text [,preserve_comments]);
|
||||
* vkbeautify.jsonmin(text);
|
||||
* vkbeautify.cssmin(text [,preserve_comments]);
|
||||
* vkbeautify.sqlmin(text);
|
||||
*
|
||||
* @text - String; text to minify;
|
||||
* @preserve_comments - Bool; [optional];
|
||||
* Set this flag to true to prevent removing comments from @text ( minxml and mincss functions only. )
|
||||
*
|
||||
* Examples:
|
||||
* vkbeautify.xml(text); // pretty print XML
|
||||
* vkbeautify.json(text, 4 ); // pretty print JSON
|
||||
* vkbeautify.css(text, '. . . .'); // pretty print CSS
|
||||
* vkbeautify.sql(text, '----'); // pretty print SQL
|
||||
*
|
||||
* vkbeautify.xmlmin(text, true);// minify XML, preserve comments
|
||||
* vkbeautify.jsonmin(text);// minify JSON
|
||||
* vkbeautify.cssmin(text);// minify CSS, remove comments ( default )
|
||||
* vkbeautify.sqlmin(text);// minify SQL
|
||||
*
|
||||
*/
|
||||
|
||||
(function() {
|
||||
|
||||
function createShiftArr(step) {
|
||||
|
||||
var space = ' ';
|
||||
|
||||
if ( isNaN(parseInt(step)) ) { // argument is string
|
||||
space = step;
|
||||
} else { // argument is integer
|
||||
switch(step) {
|
||||
case 1: space = ' '; break;
|
||||
case 2: space = ' '; break;
|
||||
case 3: space = ' '; break;
|
||||
case 4: space = ' '; break;
|
||||
case 5: space = ' '; break;
|
||||
case 6: space = ' '; break;
|
||||
case 7: space = ' '; break;
|
||||
case 8: space = ' '; break;
|
||||
case 9: space = ' '; break;
|
||||
case 10: space = ' '; break;
|
||||
case 11: space = ' '; break;
|
||||
case 12: space = ' '; break;
|
||||
}
|
||||
}
|
||||
|
||||
var shift = ['\n']; // array of shifts
|
||||
for(var ix=0;ix<100;ix++){
|
||||
shift.push(shift[ix]+space);
|
||||
}
|
||||
return shift;
|
||||
}
|
||||
|
||||
function vkbeautify(){
|
||||
this.step = ' '; // 4 spaces
|
||||
this.shift = createShiftArr(this.step);
|
||||
};
|
||||
|
||||
vkbeautify.prototype.xml = function(text,step) {
|
||||
|
||||
var ar = text.replace(/>\s{0,}</g,"><")
|
||||
.replace(/</g,"~::~<")
|
||||
.replace(/\s*xmlns\:/g,"~::~xmlns:")
|
||||
.replace(/\s*xmlns\=/g,"~::~xmlns=")
|
||||
.split('~::~'),
|
||||
len = ar.length,
|
||||
inComment = false,
|
||||
deep = 0,
|
||||
str = '',
|
||||
ix = 0,
|
||||
shift = step ? createShiftArr(step) : this.shift;
|
||||
|
||||
for(ix=0;ix<len;ix++) {
|
||||
// start comment or <![CDATA[...]]> or <!DOCTYPE //
|
||||
if(ar[ix].search(/<!/) > -1) {
|
||||
str += shift[deep]+ar[ix];
|
||||
inComment = true;
|
||||
// end comment or <![CDATA[...]]> //
|
||||
if(ar[ix].search(/-->/) > -1 || ar[ix].search(/\]>/) > -1 || ar[ix].search(/!DOCTYPE/) > -1 ) {
|
||||
inComment = false;
|
||||
}
|
||||
} else
|
||||
// end comment or <![CDATA[...]]> //
|
||||
if(ar[ix].search(/-->/) > -1 || ar[ix].search(/\]>/) > -1) {
|
||||
str += ar[ix];
|
||||
inComment = false;
|
||||
} else
|
||||
// <elm></elm> //
|
||||
if( /^<\w/.exec(ar[ix-1]) && /^<\/\w/.exec(ar[ix]) &&
|
||||
/^<[\w:\-\.\,]+/.exec(ar[ix-1]) == /^<\/[\w:\-\.\,]+/.exec(ar[ix])[0].replace('/','')) {
|
||||
str += ar[ix];
|
||||
if(!inComment) deep--;
|
||||
} else
|
||||
// <elm> //
|
||||
if(ar[ix].search(/<\w/) > -1 && ar[ix].search(/<\//) == -1 && ar[ix].search(/\/>/) == -1 ) {
|
||||
str = !inComment ? str += shift[deep++]+ar[ix] : str += ar[ix];
|
||||
} else
|
||||
// <elm>...</elm> //
|
||||
if(ar[ix].search(/<\w/) > -1 && ar[ix].search(/<\//) > -1) {
|
||||
str = !inComment ? str += shift[deep]+ar[ix] : str += ar[ix];
|
||||
} else
|
||||
// </elm> //
|
||||
if(ar[ix].search(/<\//) > -1) {
|
||||
str = !inComment ? str += shift[--deep]+ar[ix] : str += ar[ix];
|
||||
} else
|
||||
// <elm/> //
|
||||
if(ar[ix].search(/\/>/) > -1 ) {
|
||||
str = !inComment ? str += shift[deep]+ar[ix] : str += ar[ix];
|
||||
} else
|
||||
// <? xml ... ?> //
|
||||
if(ar[ix].search(/<\?/) > -1) {
|
||||
str += shift[deep]+ar[ix];
|
||||
} else
|
||||
// xmlns //
|
||||
if( ar[ix].search(/xmlns\:/) > -1 || ar[ix].search(/xmlns\=/) > -1) {
|
||||
str += shift[deep]+ar[ix];
|
||||
}
|
||||
|
||||
else {
|
||||
str += ar[ix];
|
||||
}
|
||||
}
|
||||
|
||||
return (str[0] == '\n') ? str.slice(1) : str;
|
||||
}
|
||||
|
||||
vkbeautify.prototype.json = function(text,step) {
|
||||
|
||||
var step = step ? step : this.step;
|
||||
|
||||
if (typeof JSON === 'undefined' ) return text;
|
||||
|
||||
if ( typeof text === "string" ) return JSON.stringify(JSON.parse(text), null, step);
|
||||
if ( typeof text === "object" ) return JSON.stringify(text, null, step);
|
||||
|
||||
return text; // text is not string nor object
|
||||
}
|
||||
|
||||
vkbeautify.prototype.css = function(text, step) {
|
||||
|
||||
var ar = text.replace(/\s{1,}/g,' ')
|
||||
.replace(/\{/g,"{~::~")
|
||||
.replace(/\}/g,"~::~}~::~")
|
||||
.replace(/\;/g,";~::~")
|
||||
.replace(/\/\*/g,"~::~/*")
|
||||
.replace(/\*\//g,"*/~::~")
|
||||
.replace(/~::~\s{0,}~::~/g,"~::~")
|
||||
.split('~::~'),
|
||||
len = ar.length,
|
||||
deep = 0,
|
||||
str = '',
|
||||
ix = 0,
|
||||
shift = step ? createShiftArr(step) : this.shift;
|
||||
|
||||
for(ix=0;ix<len;ix++) {
|
||||
|
||||
if( /\{/.exec(ar[ix])) {
|
||||
str += shift[deep++]+ar[ix];
|
||||
} else
|
||||
if( /\}/.exec(ar[ix])) {
|
||||
str += shift[--deep]+ar[ix];
|
||||
} else
|
||||
if( /\*\\/.exec(ar[ix])) {
|
||||
str += shift[deep]+ar[ix];
|
||||
}
|
||||
else {
|
||||
str += shift[deep]+ar[ix];
|
||||
}
|
||||
}
|
||||
return str.replace(/^\n{1,}/,'');
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
function isSubquery(str, parenthesisLevel) {
|
||||
return parenthesisLevel - (str.replace(/\(/g,'').length - str.replace(/\)/g,'').length )
|
||||
}
|
||||
|
||||
function split_sql(str, tab) {
|
||||
|
||||
return str.replace(/\s{1,}/g," ")
|
||||
|
||||
.replace(/ AND /ig,"~::~"+tab+tab+"AND ")
|
||||
.replace(/ BETWEEN /ig,"~::~"+tab+"BETWEEN ")
|
||||
.replace(/ CASE /ig,"~::~"+tab+"CASE ")
|
||||
.replace(/ ELSE /ig,"~::~"+tab+"ELSE ")
|
||||
.replace(/ END /ig,"~::~"+tab+"END ")
|
||||
.replace(/ FROM /ig,"~::~FROM ")
|
||||
.replace(/ GROUP\s{1,}BY/ig,"~::~GROUP BY ")
|
||||
.replace(/ HAVING /ig,"~::~HAVING ")
|
||||
//.replace(/ SET /ig," SET~::~")
|
||||
.replace(/ IN /ig," IN ")
|
||||
|
||||
.replace(/ JOIN /ig,"~::~JOIN ")
|
||||
.replace(/ CROSS~::~{1,}JOIN /ig,"~::~CROSS JOIN ")
|
||||
.replace(/ INNER~::~{1,}JOIN /ig,"~::~INNER JOIN ")
|
||||
.replace(/ LEFT~::~{1,}JOIN /ig,"~::~LEFT JOIN ")
|
||||
.replace(/ RIGHT~::~{1,}JOIN /ig,"~::~RIGHT JOIN ")
|
||||
|
||||
.replace(/ ON /ig,"~::~"+tab+"ON ")
|
||||
.replace(/ OR /ig,"~::~"+tab+tab+"OR ")
|
||||
.replace(/ ORDER\s{1,}BY/ig,"~::~ORDER BY ")
|
||||
.replace(/ OVER /ig,"~::~"+tab+"OVER ")
|
||||
|
||||
.replace(/\(\s{0,}SELECT /ig,"~::~(SELECT ")
|
||||
.replace(/\)\s{0,}SELECT /ig,")~::~SELECT ")
|
||||
|
||||
.replace(/ THEN /ig," THEN~::~"+tab+"")
|
||||
.replace(/ UNION /ig,"~::~UNION~::~")
|
||||
.replace(/ USING /ig,"~::~USING ")
|
||||
.replace(/ WHEN /ig,"~::~"+tab+"WHEN ")
|
||||
.replace(/ WHERE /ig,"~::~WHERE ")
|
||||
.replace(/ WITH /ig,"~::~WITH ")
|
||||
|
||||
//.replace(/\,\s{0,}\(/ig,",~::~( ")
|
||||
//.replace(/\,/ig,",~::~"+tab+tab+"")
|
||||
|
||||
.replace(/ ALL /ig," ALL ")
|
||||
.replace(/ AS /ig," AS ")
|
||||
.replace(/ ASC /ig," ASC ")
|
||||
.replace(/ DESC /ig," DESC ")
|
||||
.replace(/ DISTINCT /ig," DISTINCT ")
|
||||
.replace(/ EXISTS /ig," EXISTS ")
|
||||
.replace(/ NOT /ig," NOT ")
|
||||
.replace(/ NULL /ig," NULL ")
|
||||
.replace(/ LIKE /ig," LIKE ")
|
||||
.replace(/\s{0,}SELECT /ig,"SELECT ")
|
||||
.replace(/\s{0,}UPDATE /ig,"UPDATE ")
|
||||
.replace(/ SET /ig," SET ")
|
||||
|
||||
.replace(/~::~{1,}/g,"~::~")
|
||||
.split('~::~');
|
||||
}
|
||||
|
||||
vkbeautify.prototype.sql = function(text,step) {
|
||||
|
||||
var ar_by_quote = text.replace(/\s{1,}/g," ")
|
||||
.replace(/\'/ig,"~::~\'")
|
||||
.split('~::~'),
|
||||
len = ar_by_quote.length,
|
||||
ar = [],
|
||||
deep = 0,
|
||||
tab = this.step,//+this.step,
|
||||
inComment = true,
|
||||
inQuote = false,
|
||||
parenthesisLevel = 0,
|
||||
str = '',
|
||||
ix = 0,
|
||||
shift = step ? createShiftArr(step) : this.shift;;
|
||||
|
||||
for(ix=0;ix<len;ix++) {
|
||||
if(ix%2) {
|
||||
ar = ar.concat(ar_by_quote[ix]);
|
||||
} else {
|
||||
ar = ar.concat(split_sql(ar_by_quote[ix], tab) );
|
||||
}
|
||||
}
|
||||
|
||||
len = ar.length;
|
||||
for(ix=0;ix<len;ix++) {
|
||||
|
||||
parenthesisLevel = isSubquery(ar[ix], parenthesisLevel);
|
||||
|
||||
if( /\s{0,}\s{0,}SELECT\s{0,}/.exec(ar[ix])) {
|
||||
ar[ix] = ar[ix].replace(/\,/g,",\n"+tab+tab+"")
|
||||
}
|
||||
|
||||
if( /\s{0,}\s{0,}SET\s{0,}/.exec(ar[ix])) {
|
||||
ar[ix] = ar[ix].replace(/\,/g,",\n"+tab+tab+"")
|
||||
}
|
||||
|
||||
if( /\s{0,}\(\s{0,}SELECT\s{0,}/.exec(ar[ix])) {
|
||||
deep++;
|
||||
str += shift[deep]+ar[ix];
|
||||
} else
|
||||
if( /\'/.exec(ar[ix]) ) {
|
||||
if(parenthesisLevel<1 && deep) {
|
||||
deep--;
|
||||
}
|
||||
str += ar[ix];
|
||||
}
|
||||
else {
|
||||
str += shift[deep]+ar[ix];
|
||||
if(parenthesisLevel<1 && deep) {
|
||||
deep--;
|
||||
}
|
||||
}
|
||||
var junk = 0;
|
||||
}
|
||||
|
||||
str = str.replace(/^\n{1,}/,'').replace(/\n{1,}/g,"\n");
|
||||
return str;
|
||||
}
|
||||
|
||||
|
||||
vkbeautify.prototype.xmlmin = function(text, preserveComments) {
|
||||
|
||||
var str = preserveComments ? text
|
||||
: text.replace(/\<![ \r\n\t]*(--([^\-]|[\r\n]|-[^\-])*--[ \r\n\t]*)\>/g,"")
|
||||
.replace(/[ \r\n\t]{1,}xmlns/g, ' xmlns');
|
||||
return str.replace(/>\s{0,}</g,"><");
|
||||
}
|
||||
|
||||
vkbeautify.prototype.jsonmin = function(text) {
|
||||
|
||||
if (typeof JSON === 'undefined' ) return text;
|
||||
|
||||
return JSON.stringify(JSON.parse(text), null, 0);
|
||||
|
||||
}
|
||||
|
||||
vkbeautify.prototype.cssmin = function(text, preserveComments) {
|
||||
|
||||
var str = preserveComments ? text
|
||||
: text.replace(/\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+\//g,"") ;
|
||||
|
||||
return str.replace(/\s{1,}/g,' ')
|
||||
.replace(/\{\s{1,}/g,"{")
|
||||
.replace(/\}\s{1,}/g,"}")
|
||||
.replace(/\;\s{1,}/g,";")
|
||||
.replace(/\/\*\s{1,}/g,"/*")
|
||||
.replace(/\*\/\s{1,}/g,"*/");
|
||||
}
|
||||
|
||||
vkbeautify.prototype.sqlmin = function(text) {
|
||||
return text.replace(/\s{1,}/g," ").replace(/\s{1,}\(/,"(").replace(/\s{1,}\)/,")");
|
||||
}
|
||||
|
||||
window.vkbeautify = new vkbeautify();
|
||||
|
||||
})();
|
@ -1,37 +0,0 @@
|
||||
/* zlib.js 2012 - imaya [ https://github.com/imaya/zlib.js ] The MIT License */(function() {'use strict';var n=void 0,y=!0,aa=this;function G(e,b){var a=e.split("."),d=aa;!(a[0]in d)&&d.execScript&&d.execScript("var "+a[0]);for(var c;a.length&&(c=a.shift());)!a.length&&b!==n?d[c]=b:d=d[c]?d[c]:d[c]={}};var H="undefined"!==typeof Uint8Array&&"undefined"!==typeof Uint16Array&&"undefined"!==typeof Uint32Array&&"undefined"!==typeof DataView;function ba(e,b){this.index="number"===typeof b?b:0;this.f=0;this.buffer=e instanceof(H?Uint8Array:Array)?e:new (H?Uint8Array:Array)(32768);if(2*this.buffer.length<=this.index)throw Error("invalid index");this.buffer.length<=this.index&&ca(this)}function ca(e){var b=e.buffer,a,d=b.length,c=new (H?Uint8Array:Array)(d<<1);if(H)c.set(b);else for(a=0;a<d;++a)c[a]=b[a];return e.buffer=c}
|
||||
ba.prototype.b=function(e,b,a){var d=this.buffer,c=this.index,f=this.f,l=d[c],p;a&&1<b&&(e=8<b?(L[e&255]<<24|L[e>>>8&255]<<16|L[e>>>16&255]<<8|L[e>>>24&255])>>32-b:L[e]>>8-b);if(8>b+f)l=l<<b|e,f+=b;else for(p=0;p<b;++p)l=l<<1|e>>b-p-1&1,8===++f&&(f=0,d[c++]=L[l],l=0,c===d.length&&(d=ca(this)));d[c]=l;this.buffer=d;this.f=f;this.index=c};ba.prototype.finish=function(){var e=this.buffer,b=this.index,a;0<this.f&&(e[b]<<=8-this.f,e[b]=L[e[b]],b++);H?a=e.subarray(0,b):(e.length=b,a=e);return a};
|
||||
var da=new (H?Uint8Array:Array)(256),ha;for(ha=0;256>ha;++ha){for(var U=ha,ja=U,ka=7,U=U>>>1;U;U>>>=1)ja<<=1,ja|=U&1,--ka;da[ha]=(ja<<ka&255)>>>0}var L=da;function la(e){var b=n,a,d="number"===typeof b?b:b=0,c=e.length;a=-1;for(d=c&7;d--;++b)a=a>>>8^V[(a^e[b])&255];for(d=c>>3;d--;b+=8)a=a>>>8^V[(a^e[b])&255],a=a>>>8^V[(a^e[b+1])&255],a=a>>>8^V[(a^e[b+2])&255],a=a>>>8^V[(a^e[b+3])&255],a=a>>>8^V[(a^e[b+4])&255],a=a>>>8^V[(a^e[b+5])&255],a=a>>>8^V[(a^e[b+6])&255],a=a>>>8^V[(a^e[b+7])&255];return(a^4294967295)>>>0}
|
||||
var ma=[0,1996959894,3993919788,2567524794,124634137,1886057615,3915621685,2657392035,249268274,2044508324,3772115230,2547177864,162941995,2125561021,3887607047,2428444049,498536548,1789927666,4089016648,2227061214,450548861,1843258603,4107580753,2211677639,325883990,1684777152,4251122042,2321926636,335633487,1661365465,4195302755,2366115317,997073096,1281953886,3579855332,2724688242,1006888145,1258607687,3524101629,2768942443,901097722,1119000684,3686517206,2898065728,853044451,1172266101,3705015759,
|
||||
2882616665,651767980,1373503546,3369554304,3218104598,565507253,1454621731,3485111705,3099436303,671266974,1594198024,3322730930,2970347812,795835527,1483230225,3244367275,3060149565,1994146192,31158534,2563907772,4023717930,1907459465,112637215,2680153253,3904427059,2013776290,251722036,2517215374,3775830040,2137656763,141376813,2439277719,3865271297,1802195444,476864866,2238001368,4066508878,1812370925,453092731,2181625025,4111451223,1706088902,314042704,2344532202,4240017532,1658658271,366619977,
|
||||
2362670323,4224994405,1303535960,984961486,2747007092,3569037538,1256170817,1037604311,2765210733,3554079995,1131014506,879679996,2909243462,3663771856,1141124467,855842277,2852801631,3708648649,1342533948,654459306,3188396048,3373015174,1466479909,544179635,3110523913,3462522015,1591671054,702138776,2966460450,3352799412,1504918807,783551873,3082640443,3233442989,3988292384,2596254646,62317068,1957810842,3939845945,2647816111,81470997,1943803523,3814918930,2489596804,225274430,2053790376,3826175755,
|
||||
2466906013,167816743,2097651377,4027552580,2265490386,503444072,1762050814,4150417245,2154129355,426522225,1852507879,4275313526,2312317920,282753626,1742555852,4189708143,2394877945,397917763,1622183637,3604390888,2714866558,953729732,1340076626,3518719985,2797360999,1068828381,1219638859,3624741850,2936675148,906185462,1090812512,3747672003,2825379669,829329135,1181335161,3412177804,3160834842,628085408,1382605366,3423369109,3138078467,570562233,1426400815,3317316542,2998733608,733239954,1555261956,
|
||||
3268935591,3050360625,752459403,1541320221,2607071920,3965973030,1969922972,40735498,2617837225,3943577151,1913087877,83908371,2512341634,3803740692,2075208622,213261112,2463272603,3855990285,2094854071,198958881,2262029012,4057260610,1759359992,534414190,2176718541,4139329115,1873836001,414664567,2282248934,4279200368,1711684554,285281116,2405801727,4167216745,1634467795,376229701,2685067896,3608007406,1308918612,956543938,2808555105,3495958263,1231636301,1047427035,2932959818,3654703836,1088359270,
|
||||
936918E3,2847714899,3736837829,1202900863,817233897,3183342108,3401237130,1404277552,615818150,3134207493,3453421203,1423857449,601450431,3009837614,3294710456,1567103746,711928724,3020668471,3272380065,1510334235,755167117],V=H?new Uint32Array(ma):ma;function na(e){this.buffer=new (H?Uint16Array:Array)(2*e);this.length=0}na.prototype.getParent=function(e){return 2*((e-2)/4|0)};na.prototype.push=function(e,b){var a,d,c=this.buffer,f;a=this.length;c[this.length++]=b;for(c[this.length++]=e;0<a;)if(d=this.getParent(a),c[a]>c[d])f=c[a],c[a]=c[d],c[d]=f,f=c[a+1],c[a+1]=c[d+1],c[d+1]=f,a=d;else break;return this.length};
|
||||
na.prototype.pop=function(){var e,b,a=this.buffer,d,c,f;b=a[0];e=a[1];this.length-=2;a[0]=a[this.length];a[1]=a[this.length+1];for(f=0;;){c=2*f+2;if(c>=this.length)break;c+2<this.length&&a[c+2]>a[c]&&(c+=2);if(a[c]>a[f])d=a[f],a[f]=a[c],a[c]=d,d=a[f+1],a[f+1]=a[c+1],a[c+1]=d;else break;f=c}return{index:e,value:b,length:this.length}};function pa(e,b){this.k=qa;this.l=0;this.input=H&&e instanceof Array?new Uint8Array(e):e;this.e=0;b&&(b.lazy&&(this.l=b.lazy),"number"===typeof b.compressionType&&(this.k=b.compressionType),b.outputBuffer&&(this.c=H&&b.outputBuffer instanceof Array?new Uint8Array(b.outputBuffer):b.outputBuffer),"number"===typeof b.outputIndex&&(this.e=b.outputIndex));this.c||(this.c=new (H?Uint8Array:Array)(32768))}var qa=2,sa=[],Y;
|
||||
for(Y=0;288>Y;Y++)switch(y){case 143>=Y:sa.push([Y+48,8]);break;case 255>=Y:sa.push([Y-144+400,9]);break;case 279>=Y:sa.push([Y-256+0,7]);break;case 287>=Y:sa.push([Y-280+192,8]);break;default:throw"invalid literal: "+Y;}
|
||||
pa.prototype.g=function(){var e,b,a,d,c=this.input;switch(this.k){case 0:a=0;for(d=c.length;a<d;){b=H?c.subarray(a,a+65535):c.slice(a,a+65535);a+=b.length;var f=b,l=a===d,p=n,k=n,q=n,w=n,u=n,m=this.c,h=this.e;if(H){for(m=new Uint8Array(this.c.buffer);m.length<=h+f.length+5;)m=new Uint8Array(m.length<<1);m.set(this.c)}p=l?1:0;m[h++]=p|0;k=f.length;q=~k+65536&65535;m[h++]=k&255;m[h++]=k>>>8&255;m[h++]=q&255;m[h++]=q>>>8&255;if(H)m.set(f,h),h+=f.length,m=m.subarray(0,h);else{w=0;for(u=f.length;w<u;++w)m[h++]=
|
||||
f[w];m.length=h}this.e=h;this.c=m}break;case 1:var s=new ba(H?new Uint8Array(this.c.buffer):this.c,this.e);s.b(1,1,y);s.b(1,2,y);var t=ta(this,c),r,Q,z;r=0;for(Q=t.length;r<Q;r++)if(z=t[r],ba.prototype.b.apply(s,sa[z]),256<z)s.b(t[++r],t[++r],y),s.b(t[++r],5),s.b(t[++r],t[++r],y);else if(256===z)break;this.c=s.finish();this.e=this.c.length;break;case qa:var A=new ba(H?new Uint8Array(this.c.buffer):this.c,this.e),F,I,N,B,C,g=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],J,ea,O,W,X,oa=Array(19),
|
||||
ya,Z,ia,D,za;F=qa;A.b(1,1,y);A.b(F,2,y);I=ta(this,c);J=ua(this.p,15);ea=va(J);O=ua(this.o,7);W=va(O);for(N=286;257<N&&0===J[N-1];N--);for(B=30;1<B&&0===O[B-1];B--);var Aa=N,Ba=B,P=new (H?Uint32Array:Array)(Aa+Ba),v,R,x,fa,M=new (H?Uint32Array:Array)(316),K,E,S=new (H?Uint8Array:Array)(19);for(v=R=0;v<Aa;v++)P[R++]=J[v];for(v=0;v<Ba;v++)P[R++]=O[v];if(!H){v=0;for(fa=S.length;v<fa;++v)S[v]=0}v=K=0;for(fa=P.length;v<fa;v+=R){for(R=1;v+R<fa&&P[v+R]===P[v];++R);x=R;if(0===P[v])if(3>x)for(;0<x--;)M[K++]=
|
||||
0,S[0]++;else for(;0<x;)E=138>x?x:138,E>x-3&&E<x&&(E=x-3),10>=E?(M[K++]=17,M[K++]=E-3,S[17]++):(M[K++]=18,M[K++]=E-11,S[18]++),x-=E;else if(M[K++]=P[v],S[P[v]]++,x--,3>x)for(;0<x--;)M[K++]=P[v],S[P[v]]++;else for(;0<x;)E=6>x?x:6,E>x-3&&E<x&&(E=x-3),M[K++]=16,M[K++]=E-3,S[16]++,x-=E}e=H?M.subarray(0,K):M.slice(0,K);X=ua(S,7);for(D=0;19>D;D++)oa[D]=X[g[D]];for(C=19;4<C&&0===oa[C-1];C--);ya=va(X);A.b(N-257,5,y);A.b(B-1,5,y);A.b(C-4,4,y);for(D=0;D<C;D++)A.b(oa[D],3,y);D=0;for(za=e.length;D<za;D++)if(Z=
|
||||
e[D],A.b(ya[Z],X[Z],y),16<=Z){D++;switch(Z){case 16:ia=2;break;case 17:ia=3;break;case 18:ia=7;break;default:throw"invalid code: "+Z;}A.b(e[D],ia,y)}var Ca=[ea,J],Da=[W,O],T,Ea,ga,ra,Fa,Ga,Ha,Ia;Fa=Ca[0];Ga=Ca[1];Ha=Da[0];Ia=Da[1];T=0;for(Ea=I.length;T<Ea;++T)if(ga=I[T],A.b(Fa[ga],Ga[ga],y),256<ga)A.b(I[++T],I[++T],y),ra=I[++T],A.b(Ha[ra],Ia[ra],y),A.b(I[++T],I[++T],y);else if(256===ga)break;this.c=A.finish();this.e=this.c.length;break;default:throw"invalid compression type";}return this.c};
|
||||
function wa(e,b){this.length=e;this.n=b}
|
||||
var xa=function(){function e(a){switch(y){case 3===a:return[257,a-3,0];case 4===a:return[258,a-4,0];case 5===a:return[259,a-5,0];case 6===a:return[260,a-6,0];case 7===a:return[261,a-7,0];case 8===a:return[262,a-8,0];case 9===a:return[263,a-9,0];case 10===a:return[264,a-10,0];case 12>=a:return[265,a-11,1];case 14>=a:return[266,a-13,1];case 16>=a:return[267,a-15,1];case 18>=a:return[268,a-17,1];case 22>=a:return[269,a-19,2];case 26>=a:return[270,a-23,2];case 30>=a:return[271,a-27,2];case 34>=a:return[272,
|
||||
a-31,2];case 42>=a:return[273,a-35,3];case 50>=a:return[274,a-43,3];case 58>=a:return[275,a-51,3];case 66>=a:return[276,a-59,3];case 82>=a:return[277,a-67,4];case 98>=a:return[278,a-83,4];case 114>=a:return[279,a-99,4];case 130>=a:return[280,a-115,4];case 162>=a:return[281,a-131,5];case 194>=a:return[282,a-163,5];case 226>=a:return[283,a-195,5];case 257>=a:return[284,a-227,5];case 258===a:return[285,a-258,0];default:throw"invalid length: "+a;}}var b=[],a,d;for(a=3;258>=a;a++)d=e(a),b[a]=d[2]<<24|
|
||||
d[1]<<16|d[0];return b}(),Ja=H?new Uint32Array(xa):xa;
|
||||
function ta(e,b){function a(a,c){var b=a.n,d=[],e=0,f;f=Ja[a.length];d[e++]=f&65535;d[e++]=f>>16&255;d[e++]=f>>24;var g;switch(y){case 1===b:g=[0,b-1,0];break;case 2===b:g=[1,b-2,0];break;case 3===b:g=[2,b-3,0];break;case 4===b:g=[3,b-4,0];break;case 6>=b:g=[4,b-5,1];break;case 8>=b:g=[5,b-7,1];break;case 12>=b:g=[6,b-9,2];break;case 16>=b:g=[7,b-13,2];break;case 24>=b:g=[8,b-17,3];break;case 32>=b:g=[9,b-25,3];break;case 48>=b:g=[10,b-33,4];break;case 64>=b:g=[11,b-49,4];break;case 96>=b:g=[12,b-
|
||||
65,5];break;case 128>=b:g=[13,b-97,5];break;case 192>=b:g=[14,b-129,6];break;case 256>=b:g=[15,b-193,6];break;case 384>=b:g=[16,b-257,7];break;case 512>=b:g=[17,b-385,7];break;case 768>=b:g=[18,b-513,8];break;case 1024>=b:g=[19,b-769,8];break;case 1536>=b:g=[20,b-1025,9];break;case 2048>=b:g=[21,b-1537,9];break;case 3072>=b:g=[22,b-2049,10];break;case 4096>=b:g=[23,b-3073,10];break;case 6144>=b:g=[24,b-4097,11];break;case 8192>=b:g=[25,b-6145,11];break;case 12288>=b:g=[26,b-8193,12];break;case 16384>=
|
||||
b:g=[27,b-12289,12];break;case 24576>=b:g=[28,b-16385,13];break;case 32768>=b:g=[29,b-24577,13];break;default:throw"invalid distance";}f=g;d[e++]=f[0];d[e++]=f[1];d[e++]=f[2];var k,l;k=0;for(l=d.length;k<l;++k)m[h++]=d[k];t[d[0]]++;r[d[3]]++;s=a.length+c-1;u=null}var d,c,f,l,p,k={},q,w,u,m=H?new Uint16Array(2*b.length):[],h=0,s=0,t=new (H?Uint32Array:Array)(286),r=new (H?Uint32Array:Array)(30),Q=e.l,z;if(!H){for(f=0;285>=f;)t[f++]=0;for(f=0;29>=f;)r[f++]=0}t[256]=1;d=0;for(c=b.length;d<c;++d){f=p=
|
||||
0;for(l=3;f<l&&d+f!==c;++f)p=p<<8|b[d+f];k[p]===n&&(k[p]=[]);q=k[p];if(!(0<s--)){for(;0<q.length&&32768<d-q[0];)q.shift();if(d+3>=c){u&&a(u,-1);f=0;for(l=c-d;f<l;++f)z=b[d+f],m[h++]=z,++t[z];break}0<q.length?(w=Ka(b,d,q),u?u.length<w.length?(z=b[d-1],m[h++]=z,++t[z],a(w,0)):a(u,-1):w.length<Q?u=w:a(w,0)):u?a(u,-1):(z=b[d],m[h++]=z,++t[z])}q.push(d)}m[h++]=256;t[256]++;e.p=t;e.o=r;return H?m.subarray(0,h):m}
|
||||
function Ka(e,b,a){var d,c,f=0,l,p,k,q,w=e.length;p=0;q=a.length;a:for(;p<q;p++){d=a[q-p-1];l=3;if(3<f){for(k=f;3<k;k--)if(e[d+k-1]!==e[b+k-1])continue a;l=f}for(;258>l&&b+l<w&&e[d+l]===e[b+l];)++l;l>f&&(c=d,f=l);if(258===l)break}return new wa(f,b-c)}
|
||||
function ua(e,b){var a=e.length,d=new na(572),c=new (H?Uint8Array:Array)(a),f,l,p,k,q;if(!H)for(k=0;k<a;k++)c[k]=0;for(k=0;k<a;++k)0<e[k]&&d.push(k,e[k]);f=Array(d.length/2);l=new (H?Uint32Array:Array)(d.length/2);if(1===f.length)return c[d.pop().index]=1,c;k=0;for(q=d.length/2;k<q;++k)f[k]=d.pop(),l[k]=f[k].value;p=La(l,l.length,b);k=0;for(q=f.length;k<q;++k)c[f[k].index]=p[k];return c}
|
||||
function La(e,b,a){function d(a){var c=k[a][q[a]];c===b?(d(a+1),d(a+1)):--l[c];++q[a]}var c=new (H?Uint16Array:Array)(a),f=new (H?Uint8Array:Array)(a),l=new (H?Uint8Array:Array)(b),p=Array(a),k=Array(a),q=Array(a),w=(1<<a)-b,u=1<<a-1,m,h,s,t,r;c[a-1]=b;for(h=0;h<a;++h)w<u?f[h]=0:(f[h]=1,w-=u),w<<=1,c[a-2-h]=(c[a-1-h]/2|0)+b;c[0]=f[0];p[0]=Array(c[0]);k[0]=Array(c[0]);for(h=1;h<a;++h)c[h]>2*c[h-1]+f[h]&&(c[h]=2*c[h-1]+f[h]),p[h]=Array(c[h]),k[h]=Array(c[h]);for(m=0;m<b;++m)l[m]=a;for(s=0;s<c[a-1];++s)p[a-
|
||||
1][s]=e[s],k[a-1][s]=s;for(m=0;m<a;++m)q[m]=0;1===f[a-1]&&(--l[0],++q[a-1]);for(h=a-2;0<=h;--h){t=m=0;r=q[h+1];for(s=0;s<c[h];s++)t=p[h+1][r]+p[h+1][r+1],t>e[m]?(p[h][s]=t,k[h][s]=b,r+=2):(p[h][s]=e[m],k[h][s]=m,++m);q[h]=0;1===f[h]&&d(h)}return l}
|
||||
function va(e){var b=new (H?Uint16Array:Array)(e.length),a=[],d=[],c=0,f,l,p,k;f=0;for(l=e.length;f<l;f++)a[e[f]]=(a[e[f]]|0)+1;f=1;for(l=16;f<=l;f++)d[f]=c,c+=a[f]|0,c<<=1;f=0;for(l=e.length;f<l;f++){c=d[e[f]];d[e[f]]+=1;p=b[f]=0;for(k=e[f];p<k;p++)b[f]=b[f]<<1|c&1,c>>>=1}return b};function $(e){e=e||{};this.files=[];this.d=e.comment}var Ma=[80,75,1,2],Na=[80,75,3,4],Oa=[80,75,5,6];$.prototype.m=function(e,b){b=b||{};var a,d=e.length,c=0;H&&e instanceof Array&&(e=new Uint8Array(e));"number"!==typeof b.compressionMethod&&(b.compressionMethod=8);if(b.compress)switch(b.compressionMethod){case 0:break;case 8:c=la(e);e=(new pa(e,b.deflateOption)).g();a=y;break;default:throw Error("unknown compression method:"+b.compressionMethod);}this.files.push({buffer:e,a:b,j:a,r:!1,size:d,h:c})};
|
||||
$.prototype.q=function(e){this.i=e};
|
||||
$.prototype.g=function(){var e=this.files,b,a,d,c,f,l=0,p=0,k,q,w,u,m,h,s,t,r,Q,z,A,F,I,N,B,C,g,J;B=0;for(C=e.length;B<C;++B){b=e[B];t=b.a.filename?b.a.filename.length:0;r=b.a.comment?b.a.comment.length:0;if(!b.j)switch(b.h=la(b.buffer),b.a.compressionMethod){case 0:break;case 8:b.buffer=(new pa(b.buffer,b.a.deflateOption)).g();b.j=y;break;default:throw Error("unknown compression method:"+b.a.compressionMethod);}if(b.a.password!==n||this.i!==n){var ea=b.a.password||this.i,O=[305419896,591751049,878082192],
|
||||
W=n,X=n;H&&(O=new Uint32Array(O));W=0;for(X=ea.length;W<X;++W)Pa(O,ea[W]&255);N=O;F=b.buffer;H?(I=new Uint8Array(F.length+12),I.set(F,12),F=I):F.unshift(0,0,0,0,0,0,0,0,0,0,0,0);for(g=0;12>g;++g)F[g]=Qa(N,11===B?b.h&255:256*Math.random()|0);for(J=F.length;g<J;++g)F[g]=Qa(N,F[g]);b.buffer=F}l+=30+t+b.buffer.length;p+=46+t+r}a=new (H?Uint8Array:Array)(l+p+(46+(this.d?this.d.length:0)));d=0;c=l;f=c+p;B=0;for(C=e.length;B<C;++B){b=e[B];t=b.a.filename?b.a.filename.length:0;r=b.a.comment?b.a.comment.length:
|
||||
0;k=d;a[d++]=Na[0];a[d++]=Na[1];a[d++]=Na[2];a[d++]=Na[3];a[c++]=Ma[0];a[c++]=Ma[1];a[c++]=Ma[2];a[c++]=Ma[3];a[c++]=20;a[c++]=b.a.os||0;a[d++]=a[c++]=20;q=a[d++]=a[c++]=0;if(b.a.password||this.i)q|=1;a[d++]=a[c++]=q&255;a[d++]=a[c++]=q>>8&255;w=b.a.compressionMethod;a[d++]=a[c++]=w&255;a[d++]=a[c++]=w>>8&255;u=b.a.date||new Date;a[d++]=a[c++]=(u.getMinutes()&7)<<5|u.getSeconds()/2|0;a[d++]=a[c++]=u.getHours()<<3|u.getMinutes()>>3;a[d++]=a[c++]=(u.getMonth()+1&7)<<5|u.getDate();a[d++]=a[c++]=(u.getFullYear()-
|
||||
1980&127)<<1|u.getMonth()+1>>3;m=b.h;a[d++]=a[c++]=m&255;a[d++]=a[c++]=m>>8&255;a[d++]=a[c++]=m>>16&255;a[d++]=a[c++]=m>>24&255;h=b.buffer.length;a[d++]=a[c++]=h&255;a[d++]=a[c++]=h>>8&255;a[d++]=a[c++]=h>>16&255;a[d++]=a[c++]=h>>24&255;s=b.size;a[d++]=a[c++]=s&255;a[d++]=a[c++]=s>>8&255;a[d++]=a[c++]=s>>16&255;a[d++]=a[c++]=s>>24&255;a[d++]=a[c++]=t&255;a[d++]=a[c++]=t>>8&255;a[d++]=a[c++]=0;a[d++]=a[c++]=0;a[c++]=r&255;a[c++]=r>>8&255;a[c++]=0;a[c++]=0;a[c++]=0;a[c++]=0;a[c++]=0;a[c++]=0;a[c++]=
|
||||
0;a[c++]=0;a[c++]=k&255;a[c++]=k>>8&255;a[c++]=k>>16&255;a[c++]=k>>24&255;if(Q=b.a.filename)if(H)a.set(Q,d),a.set(Q,c),d+=t,c+=t;else for(g=0;g<t;++g)a[d++]=a[c++]=Q[g];if(z=b.a.extraField)if(H)a.set(z,d),a.set(z,c),d+=0,c+=0;else for(g=0;g<r;++g)a[d++]=a[c++]=z[g];if(A=b.a.comment)if(H)a.set(A,c),c+=r;else for(g=0;g<r;++g)a[c++]=A[g];if(H)a.set(b.buffer,d),d+=b.buffer.length;else{g=0;for(J=b.buffer.length;g<J;++g)a[d++]=b.buffer[g]}}a[f++]=Oa[0];a[f++]=Oa[1];a[f++]=Oa[2];a[f++]=Oa[3];a[f++]=0;a[f++]=
|
||||
0;a[f++]=0;a[f++]=0;a[f++]=C&255;a[f++]=C>>8&255;a[f++]=C&255;a[f++]=C>>8&255;a[f++]=p&255;a[f++]=p>>8&255;a[f++]=p>>16&255;a[f++]=p>>24&255;a[f++]=l&255;a[f++]=l>>8&255;a[f++]=l>>16&255;a[f++]=l>>24&255;r=this.d?this.d.length:0;a[f++]=r&255;a[f++]=r>>8&255;if(this.d)if(H)a.set(this.d,f);else{g=0;for(J=r;g<J;++g)a[f++]=this.d[g]}return a};function Qa(e,b){var a,d=e[2]&65535|2;a=d*(d^1)>>8&255;Pa(e,b);return a^b}
|
||||
function Pa(e,b){e[0]=(V[(e[0]^b)&255]^e[0]>>>8)>>>0;e[1]=(6681*(20173*(e[1]+(e[0]&255))>>>0)>>>0)+1>>>0;e[2]=(V[(e[2]^e[1]>>>24)&255]^e[2]>>>8)>>>0};function Ra(e,b){var a,d,c,f;if(Object.keys)a=Object.keys(b);else for(d in a=[],c=0,b)a[c++]=d;c=0;for(f=a.length;c<f;++c)d=a[c],G(e+"."+d,b[d])};G("Zlib.Zip",$);G("Zlib.Zip.prototype.addFile",$.prototype.m);G("Zlib.Zip.prototype.compress",$.prototype.g);G("Zlib.Zip.prototype.setPassword",$.prototype.q);Ra("Zlib.Zip.CompressionMethod",{STORE:0,DEFLATE:8});Ra("Zlib.Zip.OperatingSystem",{MSDOS:0,UNIX:3,MACINTOSH:7});}).call(this);
|
@ -1,55 +0,0 @@
|
||||
/** @license
|
||||
========================================================================
|
||||
zlib.js 2012 - imaya [ https://github.com/imaya/zlib.js ] The MIT License
|
||||
*/
|
||||
(function() {'use strict';function q(b){throw b;}var t=void 0,u=!0,aa=this;function A(b,a){var c=b.split("."),d=aa;!(c[0]in d)&&d.execScript&&d.execScript("var "+c[0]);for(var e;c.length&&(e=c.shift());)!c.length&&a!==t?d[e]=a:d=d[e]?d[e]:d[e]={}};var B="undefined"!==typeof Uint8Array&&"undefined"!==typeof Uint16Array&&"undefined"!==typeof Uint32Array&&"undefined"!==typeof DataView;function F(b,a){this.index="number"===typeof a?a:0;this.m=0;this.buffer=b instanceof(B?Uint8Array:Array)?b:new (B?Uint8Array:Array)(32768);2*this.buffer.length<=this.index&&q(Error("invalid index"));this.buffer.length<=this.index&&this.f()}F.prototype.f=function(){var b=this.buffer,a,c=b.length,d=new (B?Uint8Array:Array)(c<<1);if(B)d.set(b);else for(a=0;a<c;++a)d[a]=b[a];return this.buffer=d};
|
||||
F.prototype.d=function(b,a,c){var d=this.buffer,e=this.index,f=this.m,g=d[e],k;c&&1<a&&(b=8<a?(H[b&255]<<24|H[b>>>8&255]<<16|H[b>>>16&255]<<8|H[b>>>24&255])>>32-a:H[b]>>8-a);if(8>a+f)g=g<<a|b,f+=a;else for(k=0;k<a;++k)g=g<<1|b>>a-k-1&1,8===++f&&(f=0,d[e++]=H[g],g=0,e===d.length&&(d=this.f()));d[e]=g;this.buffer=d;this.m=f;this.index=e};F.prototype.finish=function(){var b=this.buffer,a=this.index,c;0<this.m&&(b[a]<<=8-this.m,b[a]=H[b[a]],a++);B?c=b.subarray(0,a):(b.length=a,c=b);return c};
|
||||
var ba=new (B?Uint8Array:Array)(256),ca;for(ca=0;256>ca;++ca){for(var K=ca,da=K,ea=7,K=K>>>1;K;K>>>=1)da<<=1,da|=K&1,--ea;ba[ca]=(da<<ea&255)>>>0}var H=ba;function ja(b,a,c){var d,e="number"===typeof a?a:a=0,f="number"===typeof c?c:b.length;d=-1;for(e=f&7;e--;++a)d=d>>>8^O[(d^b[a])&255];for(e=f>>3;e--;a+=8)d=d>>>8^O[(d^b[a])&255],d=d>>>8^O[(d^b[a+1])&255],d=d>>>8^O[(d^b[a+2])&255],d=d>>>8^O[(d^b[a+3])&255],d=d>>>8^O[(d^b[a+4])&255],d=d>>>8^O[(d^b[a+5])&255],d=d>>>8^O[(d^b[a+6])&255],d=d>>>8^O[(d^b[a+7])&255];return(d^4294967295)>>>0}
|
||||
var ka=[0,1996959894,3993919788,2567524794,124634137,1886057615,3915621685,2657392035,249268274,2044508324,3772115230,2547177864,162941995,2125561021,3887607047,2428444049,498536548,1789927666,4089016648,2227061214,450548861,1843258603,4107580753,2211677639,325883990,1684777152,4251122042,2321926636,335633487,1661365465,4195302755,2366115317,997073096,1281953886,3579855332,2724688242,1006888145,1258607687,3524101629,2768942443,901097722,1119000684,3686517206,2898065728,853044451,1172266101,3705015759,
|
||||
2882616665,651767980,1373503546,3369554304,3218104598,565507253,1454621731,3485111705,3099436303,671266974,1594198024,3322730930,2970347812,795835527,1483230225,3244367275,3060149565,1994146192,31158534,2563907772,4023717930,1907459465,112637215,2680153253,3904427059,2013776290,251722036,2517215374,3775830040,2137656763,141376813,2439277719,3865271297,1802195444,476864866,2238001368,4066508878,1812370925,453092731,2181625025,4111451223,1706088902,314042704,2344532202,4240017532,1658658271,366619977,
|
||||
2362670323,4224994405,1303535960,984961486,2747007092,3569037538,1256170817,1037604311,2765210733,3554079995,1131014506,879679996,2909243462,3663771856,1141124467,855842277,2852801631,3708648649,1342533948,654459306,3188396048,3373015174,1466479909,544179635,3110523913,3462522015,1591671054,702138776,2966460450,3352799412,1504918807,783551873,3082640443,3233442989,3988292384,2596254646,62317068,1957810842,3939845945,2647816111,81470997,1943803523,3814918930,2489596804,225274430,2053790376,3826175755,
|
||||
2466906013,167816743,2097651377,4027552580,2265490386,503444072,1762050814,4150417245,2154129355,426522225,1852507879,4275313526,2312317920,282753626,1742555852,4189708143,2394877945,397917763,1622183637,3604390888,2714866558,953729732,1340076626,3518719985,2797360999,1068828381,1219638859,3624741850,2936675148,906185462,1090812512,3747672003,2825379669,829329135,1181335161,3412177804,3160834842,628085408,1382605366,3423369109,3138078467,570562233,1426400815,3317316542,2998733608,733239954,1555261956,
|
||||
3268935591,3050360625,752459403,1541320221,2607071920,3965973030,1969922972,40735498,2617837225,3943577151,1913087877,83908371,2512341634,3803740692,2075208622,213261112,2463272603,3855990285,2094854071,198958881,2262029012,4057260610,1759359992,534414190,2176718541,4139329115,1873836001,414664567,2282248934,4279200368,1711684554,285281116,2405801727,4167216745,1634467795,376229701,2685067896,3608007406,1308918612,956543938,2808555105,3495958263,1231636301,1047427035,2932959818,3654703836,1088359270,
|
||||
936918E3,2847714899,3736837829,1202900863,817233897,3183342108,3401237130,1404277552,615818150,3134207493,3453421203,1423857449,601450431,3009837614,3294710456,1567103746,711928724,3020668471,3272380065,1510334235,755167117],O=B?new Uint32Array(ka):ka;function P(){}P.prototype.getName=function(){return this.name};P.prototype.getData=function(){return this.data};P.prototype.Y=function(){return this.Z};A("Zlib.GunzipMember",P);A("Zlib.GunzipMember.prototype.getName",P.prototype.getName);A("Zlib.GunzipMember.prototype.getData",P.prototype.getData);A("Zlib.GunzipMember.prototype.getMtime",P.prototype.Y);function la(b){this.buffer=new (B?Uint16Array:Array)(2*b);this.length=0}la.prototype.getParent=function(b){return 2*((b-2)/4|0)};la.prototype.push=function(b,a){var c,d,e=this.buffer,f;c=this.length;e[this.length++]=a;for(e[this.length++]=b;0<c;)if(d=this.getParent(c),e[c]>e[d])f=e[c],e[c]=e[d],e[d]=f,f=e[c+1],e[c+1]=e[d+1],e[d+1]=f,c=d;else break;return this.length};
|
||||
la.prototype.pop=function(){var b,a,c=this.buffer,d,e,f;a=c[0];b=c[1];this.length-=2;c[0]=c[this.length];c[1]=c[this.length+1];for(f=0;;){e=2*f+2;if(e>=this.length)break;e+2<this.length&&c[e+2]>c[e]&&(e+=2);if(c[e]>c[f])d=c[f],c[f]=c[e],c[e]=d,d=c[f+1],c[f+1]=c[e+1],c[e+1]=d;else break;f=e}return{index:b,value:a,length:this.length}};function ma(b){var a=b.length,c=0,d=Number.POSITIVE_INFINITY,e,f,g,k,h,l,s,p,m,n;for(p=0;p<a;++p)b[p]>c&&(c=b[p]),b[p]<d&&(d=b[p]);e=1<<c;f=new (B?Uint32Array:Array)(e);g=1;k=0;for(h=2;g<=c;){for(p=0;p<a;++p)if(b[p]===g){l=0;s=k;for(m=0;m<g;++m)l=l<<1|s&1,s>>=1;n=g<<16|p;for(m=l;m<e;m+=h)f[m]=n;++k}++g;k<<=1;h<<=1}return[f,c,d]};function na(b,a){this.k=qa;this.I=0;this.input=B&&b instanceof Array?new Uint8Array(b):b;this.b=0;a&&(a.lazy&&(this.I=a.lazy),"number"===typeof a.compressionType&&(this.k=a.compressionType),a.outputBuffer&&(this.a=B&&a.outputBuffer instanceof Array?new Uint8Array(a.outputBuffer):a.outputBuffer),"number"===typeof a.outputIndex&&(this.b=a.outputIndex));this.a||(this.a=new (B?Uint8Array:Array)(32768))}var qa=2,ra={NONE:0,v:1,o:qa,ba:3},sa=[],S;
|
||||
for(S=0;288>S;S++)switch(u){case 143>=S:sa.push([S+48,8]);break;case 255>=S:sa.push([S-144+400,9]);break;case 279>=S:sa.push([S-256+0,7]);break;case 287>=S:sa.push([S-280+192,8]);break;default:q("invalid literal: "+S)}
|
||||
na.prototype.g=function(){var b,a,c,d,e=this.input;switch(this.k){case 0:c=0;for(d=e.length;c<d;){a=B?e.subarray(c,c+65535):e.slice(c,c+65535);c+=a.length;var f=a,g=c===d,k=t,h=t,l=t,s=t,p=t,m=this.a,n=this.b;if(B){for(m=new Uint8Array(this.a.buffer);m.length<=n+f.length+5;)m=new Uint8Array(m.length<<1);m.set(this.a)}k=g?1:0;m[n++]=k|0;h=f.length;l=~h+65536&65535;m[n++]=h&255;m[n++]=h>>>8&255;m[n++]=l&255;m[n++]=l>>>8&255;if(B)m.set(f,n),n+=f.length,m=m.subarray(0,n);else{s=0;for(p=f.length;s<p;++s)m[n++]=
|
||||
f[s];m.length=n}this.b=n;this.a=m}break;case 1:var r=new F(B?new Uint8Array(this.a.buffer):this.a,this.b);r.d(1,1,u);r.d(1,2,u);var v=ta(this,e),x,Q,y;x=0;for(Q=v.length;x<Q;x++)if(y=v[x],F.prototype.d.apply(r,sa[y]),256<y)r.d(v[++x],v[++x],u),r.d(v[++x],5),r.d(v[++x],v[++x],u);else if(256===y)break;this.a=r.finish();this.b=this.a.length;break;case qa:var E=new F(B?new Uint8Array(this.a.buffer):this.a,this.b),Ka,R,X,Y,Z,pb=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],fa,La,ga,Ma,oa,wa=Array(19),
|
||||
Na,$,pa,C,Oa;Ka=qa;E.d(1,1,u);E.d(Ka,2,u);R=ta(this,e);fa=ua(this.W,15);La=va(fa);ga=ua(this.V,7);Ma=va(ga);for(X=286;257<X&&0===fa[X-1];X--);for(Y=30;1<Y&&0===ga[Y-1];Y--);var Pa=X,Qa=Y,J=new (B?Uint32Array:Array)(Pa+Qa),w,L,z,ha,I=new (B?Uint32Array:Array)(316),G,D,M=new (B?Uint8Array:Array)(19);for(w=L=0;w<Pa;w++)J[L++]=fa[w];for(w=0;w<Qa;w++)J[L++]=ga[w];if(!B){w=0;for(ha=M.length;w<ha;++w)M[w]=0}w=G=0;for(ha=J.length;w<ha;w+=L){for(L=1;w+L<ha&&J[w+L]===J[w];++L);z=L;if(0===J[w])if(3>z)for(;0<
|
||||
z--;)I[G++]=0,M[0]++;else for(;0<z;)D=138>z?z:138,D>z-3&&D<z&&(D=z-3),10>=D?(I[G++]=17,I[G++]=D-3,M[17]++):(I[G++]=18,I[G++]=D-11,M[18]++),z-=D;else if(I[G++]=J[w],M[J[w]]++,z--,3>z)for(;0<z--;)I[G++]=J[w],M[J[w]]++;else for(;0<z;)D=6>z?z:6,D>z-3&&D<z&&(D=z-3),I[G++]=16,I[G++]=D-3,M[16]++,z-=D}b=B?I.subarray(0,G):I.slice(0,G);oa=ua(M,7);for(C=0;19>C;C++)wa[C]=oa[pb[C]];for(Z=19;4<Z&&0===wa[Z-1];Z--);Na=va(oa);E.d(X-257,5,u);E.d(Y-1,5,u);E.d(Z-4,4,u);for(C=0;C<Z;C++)E.d(wa[C],3,u);C=0;for(Oa=b.length;C<
|
||||
Oa;C++)if($=b[C],E.d(Na[$],oa[$],u),16<=$){C++;switch($){case 16:pa=2;break;case 17:pa=3;break;case 18:pa=7;break;default:q("invalid code: "+$)}E.d(b[C],pa,u)}var Ra=[La,fa],Sa=[Ma,ga],N,Ta,ia,za,Ua,Va,Wa,Xa;Ua=Ra[0];Va=Ra[1];Wa=Sa[0];Xa=Sa[1];N=0;for(Ta=R.length;N<Ta;++N)if(ia=R[N],E.d(Ua[ia],Va[ia],u),256<ia)E.d(R[++N],R[++N],u),za=R[++N],E.d(Wa[za],Xa[za],u),E.d(R[++N],R[++N],u);else if(256===ia)break;this.a=E.finish();this.b=this.a.length;break;default:q("invalid compression type")}return this.a};
|
||||
function xa(b,a){this.length=b;this.Q=a}
|
||||
var ya=function(){function b(a){switch(u){case 3===a:return[257,a-3,0];case 4===a:return[258,a-4,0];case 5===a:return[259,a-5,0];case 6===a:return[260,a-6,0];case 7===a:return[261,a-7,0];case 8===a:return[262,a-8,0];case 9===a:return[263,a-9,0];case 10===a:return[264,a-10,0];case 12>=a:return[265,a-11,1];case 14>=a:return[266,a-13,1];case 16>=a:return[267,a-15,1];case 18>=a:return[268,a-17,1];case 22>=a:return[269,a-19,2];case 26>=a:return[270,a-23,2];case 30>=a:return[271,a-27,2];case 34>=a:return[272,
|
||||
a-31,2];case 42>=a:return[273,a-35,3];case 50>=a:return[274,a-43,3];case 58>=a:return[275,a-51,3];case 66>=a:return[276,a-59,3];case 82>=a:return[277,a-67,4];case 98>=a:return[278,a-83,4];case 114>=a:return[279,a-99,4];case 130>=a:return[280,a-115,4];case 162>=a:return[281,a-131,5];case 194>=a:return[282,a-163,5];case 226>=a:return[283,a-195,5];case 257>=a:return[284,a-227,5];case 258===a:return[285,a-258,0];default:q("invalid length: "+a)}}var a=[],c,d;for(c=3;258>=c;c++)d=b(c),a[c]=d[2]<<24|d[1]<<
|
||||
16|d[0];return a}(),Aa=B?new Uint32Array(ya):ya;
|
||||
function ta(b,a){function c(a,c){var b=a.Q,d=[],e=0,f;f=Aa[a.length];d[e++]=f&65535;d[e++]=f>>16&255;d[e++]=f>>24;var g;switch(u){case 1===b:g=[0,b-1,0];break;case 2===b:g=[1,b-2,0];break;case 3===b:g=[2,b-3,0];break;case 4===b:g=[3,b-4,0];break;case 6>=b:g=[4,b-5,1];break;case 8>=b:g=[5,b-7,1];break;case 12>=b:g=[6,b-9,2];break;case 16>=b:g=[7,b-13,2];break;case 24>=b:g=[8,b-17,3];break;case 32>=b:g=[9,b-25,3];break;case 48>=b:g=[10,b-33,4];break;case 64>=b:g=[11,b-49,4];break;case 96>=b:g=[12,b-
|
||||
65,5];break;case 128>=b:g=[13,b-97,5];break;case 192>=b:g=[14,b-129,6];break;case 256>=b:g=[15,b-193,6];break;case 384>=b:g=[16,b-257,7];break;case 512>=b:g=[17,b-385,7];break;case 768>=b:g=[18,b-513,8];break;case 1024>=b:g=[19,b-769,8];break;case 1536>=b:g=[20,b-1025,9];break;case 2048>=b:g=[21,b-1537,9];break;case 3072>=b:g=[22,b-2049,10];break;case 4096>=b:g=[23,b-3073,10];break;case 6144>=b:g=[24,b-4097,11];break;case 8192>=b:g=[25,b-6145,11];break;case 12288>=b:g=[26,b-8193,12];break;case 16384>=
|
||||
b:g=[27,b-12289,12];break;case 24576>=b:g=[28,b-16385,13];break;case 32768>=b:g=[29,b-24577,13];break;default:q("invalid distance")}f=g;d[e++]=f[0];d[e++]=f[1];d[e++]=f[2];var h,k;h=0;for(k=d.length;h<k;++h)m[n++]=d[h];v[d[0]]++;x[d[3]]++;r=a.length+c-1;p=null}var d,e,f,g,k,h={},l,s,p,m=B?new Uint16Array(2*a.length):[],n=0,r=0,v=new (B?Uint32Array:Array)(286),x=new (B?Uint32Array:Array)(30),Q=b.I,y;if(!B){for(f=0;285>=f;)v[f++]=0;for(f=0;29>=f;)x[f++]=0}v[256]=1;d=0;for(e=a.length;d<e;++d){f=k=0;
|
||||
for(g=3;f<g&&d+f!==e;++f)k=k<<8|a[d+f];h[k]===t&&(h[k]=[]);l=h[k];if(!(0<r--)){for(;0<l.length&&32768<d-l[0];)l.shift();if(d+3>=e){p&&c(p,-1);f=0;for(g=e-d;f<g;++f)y=a[d+f],m[n++]=y,++v[y];break}0<l.length?(s=Ba(a,d,l),p?p.length<s.length?(y=a[d-1],m[n++]=y,++v[y],c(s,0)):c(p,-1):s.length<Q?p=s:c(s,0)):p?c(p,-1):(y=a[d],m[n++]=y,++v[y])}l.push(d)}m[n++]=256;v[256]++;b.W=v;b.V=x;return B?m.subarray(0,n):m}
|
||||
function Ba(b,a,c){var d,e,f=0,g,k,h,l,s=b.length;k=0;l=c.length;a:for(;k<l;k++){d=c[l-k-1];g=3;if(3<f){for(h=f;3<h;h--)if(b[d+h-1]!==b[a+h-1])continue a;g=f}for(;258>g&&a+g<s&&b[d+g]===b[a+g];)++g;g>f&&(e=d,f=g);if(258===g)break}return new xa(f,a-e)}
|
||||
function ua(b,a){var c=b.length,d=new la(572),e=new (B?Uint8Array:Array)(c),f,g,k,h,l;if(!B)for(h=0;h<c;h++)e[h]=0;for(h=0;h<c;++h)0<b[h]&&d.push(h,b[h]);f=Array(d.length/2);g=new (B?Uint32Array:Array)(d.length/2);if(1===f.length)return e[d.pop().index]=1,e;h=0;for(l=d.length/2;h<l;++h)f[h]=d.pop(),g[h]=f[h].value;k=Ca(g,g.length,a);h=0;for(l=f.length;h<l;++h)e[f[h].index]=k[h];return e}
|
||||
function Ca(b,a,c){function d(b){var c=h[b][l[b]];c===a?(d(b+1),d(b+1)):--g[c];++l[b]}var e=new (B?Uint16Array:Array)(c),f=new (B?Uint8Array:Array)(c),g=new (B?Uint8Array:Array)(a),k=Array(c),h=Array(c),l=Array(c),s=(1<<c)-a,p=1<<c-1,m,n,r,v,x;e[c-1]=a;for(n=0;n<c;++n)s<p?f[n]=0:(f[n]=1,s-=p),s<<=1,e[c-2-n]=(e[c-1-n]/2|0)+a;e[0]=f[0];k[0]=Array(e[0]);h[0]=Array(e[0]);for(n=1;n<c;++n)e[n]>2*e[n-1]+f[n]&&(e[n]=2*e[n-1]+f[n]),k[n]=Array(e[n]),h[n]=Array(e[n]);for(m=0;m<a;++m)g[m]=c;for(r=0;r<e[c-1];++r)k[c-
|
||||
1][r]=b[r],h[c-1][r]=r;for(m=0;m<c;++m)l[m]=0;1===f[c-1]&&(--g[0],++l[c-1]);for(n=c-2;0<=n;--n){v=m=0;x=l[n+1];for(r=0;r<e[n];r++)v=k[n+1][x]+k[n+1][x+1],v>b[m]?(k[n][r]=v,h[n][r]=a,x+=2):(k[n][r]=b[m],h[n][r]=m,++m);l[n]=0;1===f[n]&&d(n)}return g}
|
||||
function va(b){var a=new (B?Uint16Array:Array)(b.length),c=[],d=[],e=0,f,g,k,h;f=0;for(g=b.length;f<g;f++)c[b[f]]=(c[b[f]]|0)+1;f=1;for(g=16;f<=g;f++)d[f]=e,e+=c[f]|0,e<<=1;f=0;for(g=b.length;f<g;f++){e=d[b[f]];d[b[f]]+=1;k=a[f]=0;for(h=b[f];k<h;k++)a[f]=a[f]<<1|e&1,e>>>=1}return a};function Da(b,a){this.input=b;this.b=this.c=0;this.i={};a&&(a.flags&&(this.i=a.flags),"string"===typeof a.filename&&(this.filename=a.filename),"string"===typeof a.comment&&(this.A=a.comment),a.deflateOptions&&(this.l=a.deflateOptions));this.l||(this.l={})}
|
||||
Da.prototype.g=function(){var b,a,c,d,e,f,g,k,h=new (B?Uint8Array:Array)(32768),l=0,s=this.input,p=this.c,m=this.filename,n=this.A;h[l++]=31;h[l++]=139;h[l++]=8;b=0;this.i.fname&&(b|=Ea);this.i.fcomment&&(b|=Fa);this.i.fhcrc&&(b|=Ga);h[l++]=b;a=(Date.now?Date.now():+new Date)/1E3|0;h[l++]=a&255;h[l++]=a>>>8&255;h[l++]=a>>>16&255;h[l++]=a>>>24&255;h[l++]=0;h[l++]=Ha;if(this.i.fname!==t){g=0;for(k=m.length;g<k;++g)f=m.charCodeAt(g),255<f&&(h[l++]=f>>>8&255),h[l++]=f&255;h[l++]=0}if(this.i.comment){g=
|
||||
0;for(k=n.length;g<k;++g)f=n.charCodeAt(g),255<f&&(h[l++]=f>>>8&255),h[l++]=f&255;h[l++]=0}this.i.fhcrc&&(c=ja(h,0,l)&65535,h[l++]=c&255,h[l++]=c>>>8&255);this.l.outputBuffer=h;this.l.outputIndex=l;e=new na(s,this.l);h=e.g();l=e.b;B&&(l+8>h.buffer.byteLength?(this.a=new Uint8Array(l+8),this.a.set(new Uint8Array(h.buffer)),h=this.a):h=new Uint8Array(h.buffer));d=ja(s,t,t);h[l++]=d&255;h[l++]=d>>>8&255;h[l++]=d>>>16&255;h[l++]=d>>>24&255;k=s.length;h[l++]=k&255;h[l++]=k>>>8&255;h[l++]=k>>>16&255;h[l++]=
|
||||
k>>>24&255;this.c=p;B&&l<h.length&&(this.a=h=h.subarray(0,l));return h};var Ha=255,Ga=2,Ea=8,Fa=16;A("Zlib.Gzip",Da);A("Zlib.Gzip.prototype.compress",Da.prototype.g);function T(b,a){this.p=[];this.q=32768;this.e=this.j=this.c=this.u=0;this.input=B?new Uint8Array(b):b;this.w=!1;this.r=Ia;this.M=!1;if(a||!(a={}))a.index&&(this.c=a.index),a.bufferSize&&(this.q=a.bufferSize),a.bufferType&&(this.r=a.bufferType),a.resize&&(this.M=a.resize);switch(this.r){case Ja:this.b=32768;this.a=new (B?Uint8Array:Array)(32768+this.q+258);break;case Ia:this.b=0;this.a=new (B?Uint8Array:Array)(this.q);this.f=this.U;this.B=this.R;this.s=this.T;break;default:q(Error("invalid inflate mode"))}}
|
||||
var Ja=0,Ia=1,Ya={O:Ja,N:Ia};
|
||||
T.prototype.h=function(){for(;!this.w;){var b=U(this,3);b&1&&(this.w=u);b>>>=1;switch(b){case 0:var a=this.input,c=this.c,d=this.a,e=this.b,f=a.length,g=t,k=t,h=d.length,l=t;this.e=this.j=0;c+1>=f&&q(Error("invalid uncompressed block header: LEN"));g=a[c++]|a[c++]<<8;c+1>=f&&q(Error("invalid uncompressed block header: NLEN"));k=a[c++]|a[c++]<<8;g===~k&&q(Error("invalid uncompressed block header: length verify"));c+g>a.length&&q(Error("input buffer is broken"));switch(this.r){case Ja:for(;e+g>d.length;){l=
|
||||
h-e;g-=l;if(B)d.set(a.subarray(c,c+l),e),e+=l,c+=l;else for(;l--;)d[e++]=a[c++];this.b=e;d=this.f();e=this.b}break;case Ia:for(;e+g>d.length;)d=this.f({F:2});break;default:q(Error("invalid inflate mode"))}if(B)d.set(a.subarray(c,c+g),e),e+=g,c+=g;else for(;g--;)d[e++]=a[c++];this.c=c;this.b=e;this.a=d;break;case 1:this.s(Za,$a);break;case 2:ab(this);break;default:q(Error("unknown BTYPE: "+b))}}return this.B()};
|
||||
var bb=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],cb=B?new Uint16Array(bb):bb,db=[3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,258,258],eb=B?new Uint16Array(db):db,fb=[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0],gb=B?new Uint8Array(fb):fb,hb=[1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577],ib=B?new Uint16Array(hb):hb,jb=[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,
|
||||
10,11,11,12,12,13,13],kb=B?new Uint8Array(jb):jb,lb=new (B?Uint8Array:Array)(288),V,mb;V=0;for(mb=lb.length;V<mb;++V)lb[V]=143>=V?8:255>=V?9:279>=V?7:8;var Za=ma(lb),nb=new (B?Uint8Array:Array)(30),ob,qb;ob=0;for(qb=nb.length;ob<qb;++ob)nb[ob]=5;var $a=ma(nb);function U(b,a){for(var c=b.j,d=b.e,e=b.input,f=b.c,g=e.length,k;d<a;)f>=g&&q(Error("input buffer is broken")),c|=e[f++]<<d,d+=8;k=c&(1<<a)-1;b.j=c>>>a;b.e=d-a;b.c=f;return k}
|
||||
function rb(b,a){for(var c=b.j,d=b.e,e=b.input,f=b.c,g=e.length,k=a[0],h=a[1],l,s;d<h&&!(f>=g);)c|=e[f++]<<d,d+=8;l=k[c&(1<<h)-1];s=l>>>16;b.j=c>>s;b.e=d-s;b.c=f;return l&65535}
|
||||
function ab(b){function a(a,b,c){var d,e=this.J,f,g;for(g=0;g<a;)switch(d=rb(this,b),d){case 16:for(f=3+U(this,2);f--;)c[g++]=e;break;case 17:for(f=3+U(this,3);f--;)c[g++]=0;e=0;break;case 18:for(f=11+U(this,7);f--;)c[g++]=0;e=0;break;default:e=c[g++]=d}this.J=e;return c}var c=U(b,5)+257,d=U(b,5)+1,e=U(b,4)+4,f=new (B?Uint8Array:Array)(cb.length),g,k,h,l;for(l=0;l<e;++l)f[cb[l]]=U(b,3);if(!B){l=e;for(e=f.length;l<e;++l)f[cb[l]]=0}g=ma(f);k=new (B?Uint8Array:Array)(c);h=new (B?Uint8Array:Array)(d);
|
||||
b.J=0;b.s(ma(a.call(b,c,g,k)),ma(a.call(b,d,g,h)))}T.prototype.s=function(b,a){var c=this.a,d=this.b;this.C=b;for(var e=c.length-258,f,g,k,h;256!==(f=rb(this,b));)if(256>f)d>=e&&(this.b=d,c=this.f(),d=this.b),c[d++]=f;else{g=f-257;h=eb[g];0<gb[g]&&(h+=U(this,gb[g]));f=rb(this,a);k=ib[f];0<kb[f]&&(k+=U(this,kb[f]));d>=e&&(this.b=d,c=this.f(),d=this.b);for(;h--;)c[d]=c[d++-k]}for(;8<=this.e;)this.e-=8,this.c--;this.b=d};
|
||||
T.prototype.T=function(b,a){var c=this.a,d=this.b;this.C=b;for(var e=c.length,f,g,k,h;256!==(f=rb(this,b));)if(256>f)d>=e&&(c=this.f(),e=c.length),c[d++]=f;else{g=f-257;h=eb[g];0<gb[g]&&(h+=U(this,gb[g]));f=rb(this,a);k=ib[f];0<kb[f]&&(k+=U(this,kb[f]));d+h>e&&(c=this.f(),e=c.length);for(;h--;)c[d]=c[d++-k]}for(;8<=this.e;)this.e-=8,this.c--;this.b=d};
|
||||
T.prototype.f=function(){var b=new (B?Uint8Array:Array)(this.b-32768),a=this.b-32768,c,d,e=this.a;if(B)b.set(e.subarray(32768,b.length));else{c=0;for(d=b.length;c<d;++c)b[c]=e[c+32768]}this.p.push(b);this.u+=b.length;if(B)e.set(e.subarray(a,a+32768));else for(c=0;32768>c;++c)e[c]=e[a+c];this.b=32768;return e};
|
||||
T.prototype.U=function(b){var a,c=this.input.length/this.c+1|0,d,e,f,g=this.input,k=this.a;b&&("number"===typeof b.F&&(c=b.F),"number"===typeof b.P&&(c+=b.P));2>c?(d=(g.length-this.c)/this.C[2],f=258*(d/2)|0,e=f<k.length?k.length+f:k.length<<1):e=k.length*c;B?(a=new Uint8Array(e),a.set(k)):a=k;return this.a=a};
|
||||
T.prototype.B=function(){var b=0,a=this.a,c=this.p,d,e=new (B?Uint8Array:Array)(this.u+(this.b-32768)),f,g,k,h;if(0===c.length)return B?this.a.subarray(32768,this.b):this.a.slice(32768,this.b);f=0;for(g=c.length;f<g;++f){d=c[f];k=0;for(h=d.length;k<h;++k)e[b++]=d[k]}f=32768;for(g=this.b;f<g;++f)e[b++]=a[f];this.p=[];return this.buffer=e};
|
||||
T.prototype.R=function(){var b,a=this.b;B?this.M?(b=new Uint8Array(a),b.set(this.a.subarray(0,a))):b=this.a.subarray(0,a):(this.a.length>a&&(this.a.length=a),b=this.a);return this.buffer=b};function sb(b){this.input=b;this.c=0;this.t=[];this.D=!1}sb.prototype.X=function(){this.D||this.h();return this.t.slice()};
|
||||
sb.prototype.h=function(){for(var b=this.input.length;this.c<b;){var a=new P,c=t,d=t,e=t,f=t,g=t,k=t,h=t,l=t,s=t,p=this.input,m=this.c;a.G=p[m++];a.H=p[m++];(31!==a.G||139!==a.H)&&q(Error("invalid file signature:"+a.G+","+a.H));a.z=p[m++];switch(a.z){case 8:break;default:q(Error("unknown compression method: "+a.z))}a.n=p[m++];l=p[m++]|p[m++]<<8|p[m++]<<16|p[m++]<<24;a.Z=new Date(1E3*l);a.fa=p[m++];a.ea=p[m++];0<(a.n&4)&&(a.aa=p[m++]|p[m++]<<8,m+=a.aa);if(0<(a.n&Ea)){h=[];for(k=0;0<(g=p[m++]);)h[k++]=
|
||||
String.fromCharCode(g);a.name=h.join("")}if(0<(a.n&Fa)){h=[];for(k=0;0<(g=p[m++]);)h[k++]=String.fromCharCode(g);a.A=h.join("")}0<(a.n&Ga)&&(a.S=ja(p,0,m)&65535,a.S!==(p[m++]|p[m++]<<8)&&q(Error("invalid header crc16")));c=p[p.length-4]|p[p.length-3]<<8|p[p.length-2]<<16|p[p.length-1]<<24;p.length-m-4-4<512*c&&(f=c);d=new T(p,{index:m,bufferSize:f});a.data=e=d.h();m=d.c;a.ca=s=(p[m++]|p[m++]<<8|p[m++]<<16|p[m++]<<24)>>>0;ja(e,t,t)!==s&&q(Error("invalid CRC-32 checksum: 0x"+ja(e,t,t).toString(16)+
|
||||
" / 0x"+s.toString(16)));a.da=c=(p[m++]|p[m++]<<8|p[m++]<<16|p[m++]<<24)>>>0;(e.length&4294967295)!==c&&q(Error("invalid input size: "+(e.length&4294967295)+" / "+c));this.t.push(a);this.c=m}this.D=u;var n=this.t,r,v,x=0,Q=0,y;r=0;for(v=n.length;r<v;++r)Q+=n[r].data.length;if(B){y=new Uint8Array(Q);for(r=0;r<v;++r)y.set(n[r].data,x),x+=n[r].data.length}else{y=[];for(r=0;r<v;++r)y[r]=n[r].data;y=Array.prototype.concat.apply([],y)}return y};A("Zlib.Gunzip",sb);A("Zlib.Gunzip.prototype.decompress",sb.prototype.h);A("Zlib.Gunzip.prototype.getMembers",sb.prototype.X);function tb(b){if("string"===typeof b){var a=b.split(""),c,d;c=0;for(d=a.length;c<d;c++)a[c]=(a[c].charCodeAt(0)&255)>>>0;b=a}for(var e=1,f=0,g=b.length,k,h=0;0<g;){k=1024<g?1024:g;g-=k;do e+=b[h++],f+=e;while(--k);e%=65521;f%=65521}return(f<<16|e)>>>0};function ub(b,a){var c,d;this.input=b;this.c=0;if(a||!(a={}))a.index&&(this.c=a.index),a.verify&&(this.$=a.verify);c=b[this.c++];d=b[this.c++];switch(c&15){case vb:this.method=vb;break;default:q(Error("unsupported compression method"))}0!==((c<<8)+d)%31&&q(Error("invalid fcheck flag:"+((c<<8)+d)%31));d&32&&q(Error("fdict flag is not supported"));this.L=new T(b,{index:this.c,bufferSize:a.bufferSize,bufferType:a.bufferType,resize:a.resize})}
|
||||
ub.prototype.h=function(){var b=this.input,a,c;a=this.L.h();this.c=this.L.c;this.$&&(c=(b[this.c++]<<24|b[this.c++]<<16|b[this.c++]<<8|b[this.c++])>>>0,c!==tb(a)&&q(Error("invalid adler-32 checksum")));return a};var vb=8;function wb(b,a){this.input=b;this.a=new (B?Uint8Array:Array)(32768);this.k=W.o;var c={},d;if((a||!(a={}))&&"number"===typeof a.compressionType)this.k=a.compressionType;for(d in a)c[d]=a[d];c.outputBuffer=this.a;this.K=new na(this.input,c)}var W=ra;
|
||||
wb.prototype.g=function(){var b,a,c,d,e,f,g,k=0;g=this.a;b=vb;switch(b){case vb:a=Math.LOG2E*Math.log(32768)-8;break;default:q(Error("invalid compression method"))}c=a<<4|b;g[k++]=c;switch(b){case vb:switch(this.k){case W.NONE:e=0;break;case W.v:e=1;break;case W.o:e=2;break;default:q(Error("unsupported compression type"))}break;default:q(Error("invalid compression method"))}d=e<<6|0;g[k++]=d|31-(256*c+d)%31;f=tb(this.input);this.K.b=k;g=this.K.g();k=g.length;B&&(g=new Uint8Array(g.buffer),g.length<=
|
||||
k+4&&(this.a=new Uint8Array(g.length+4),this.a.set(g),g=this.a),g=g.subarray(0,k+4));g[k++]=f>>24&255;g[k++]=f>>16&255;g[k++]=f>>8&255;g[k++]=f&255;return g};function xb(b,a){var c,d,e,f;if(Object.keys)c=Object.keys(a);else for(d in c=[],e=0,a)c[e++]=d;e=0;for(f=c.length;e<f;++e)d=c[e],A(b+"."+d,a[d])};A("Zlib.Inflate",ub);A("Zlib.Inflate.prototype.decompress",ub.prototype.h);xb("Zlib.Inflate.BufferType",{ADAPTIVE:Ya.N,BLOCK:Ya.O});A("Zlib.Deflate",wb);A("Zlib.Deflate.compress",function(b,a){return(new wb(b,a)).g()});A("Zlib.Deflate.prototype.compress",wb.prototype.g);xb("Zlib.Deflate.CompressionType",{NONE:W.NONE,FIXED:W.v,DYNAMIC:W.o});}).call(this);
|
@ -1,9 +1,9 @@
|
||||
/* globals bzip2 */
|
||||
var rawdeflate = require("zlibjs/bin/rawdeflate.min"),
|
||||
rawinflate = require("zlibjs/bin/rawinflate.min"),
|
||||
zlibAndGzip = require("zlibjs/bin/zlib_and_gzip.min"),
|
||||
zip = require("zlibjs/bin/zip.min"),
|
||||
unzip = require("zlibjs/bin/unzip.min");
|
||||
unzip = require("zlibjs/bin/unzip.min"),
|
||||
bzip2 = require("../lib/bzip2.js");
|
||||
|
||||
var Zlib = {
|
||||
RawDeflate: rawdeflate.Zlib.RawDeflate,
|
||||
|
@ -1,4 +1,4 @@
|
||||
var UAParser = require("uas-parser");
|
||||
var UAParser = require("../lib/uas_parser.js");
|
||||
|
||||
|
||||
/**
|
||||
|
@ -10,3 +10,22 @@ var Chef = require("../../core/Chef.js");
|
||||
var chef = new Chef();
|
||||
|
||||
console.log(chef.bake("test", [{"op":"To Hex", "args":["Space"]}], {}, 0, false));
|
||||
|
||||
console.log(chef.bake("425a6839314159265359b218ed630000031380400104002a438c00200021a9ea601a10003202185d5ed68ca6442f1e177245385090b218ed63",
|
||||
[
|
||||
{
|
||||
"op" : "From Hex",
|
||||
"args" : ["Space"]
|
||||
},
|
||||
{
|
||||
"op" : "Bzip2 Decompress",
|
||||
"args" : []
|
||||
}
|
||||
],
|
||||
{}, 0, false
|
||||
));
|
||||
|
||||
console.log(chef.bake("192.168.0.0/30",
|
||||
[{"op":"Parse IP range", "args":[true, true, false]}],
|
||||
{}, 0, false
|
||||
));
|
||||
|
24
test/tests/operations/Compress.js
Normal file
24
test/tests/operations/Compress.js
Normal file
@ -0,0 +1,24 @@
|
||||
/**
|
||||
* Compress tests.
|
||||
*
|
||||
* @author n1474335 [n1474335@gmail.com]
|
||||
* @copyright Crown Copyright 2017
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
TestRegister.addTests([
|
||||
{
|
||||
name: "Bzip2 decompress",
|
||||
input: "425a6839314159265359b218ed630000031380400104002a438c00200021a9ea601a10003202185d5ed68ca6442f1e177245385090b218ed63",
|
||||
expectedOutput: "The cat sat on the mat.",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op" : "From Hex",
|
||||
"args" : ["Space"]
|
||||
},
|
||||
{
|
||||
"op" : "Bzip2 Decompress",
|
||||
"args" : []
|
||||
}
|
||||
],
|
||||
},
|
||||
]);
|
Loading…
Reference in New Issue
Block a user