mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-09-04 23:17:02 +03:00
Experiments with RSA encryption
This commit is contained in:
parent
11608e5f64
commit
bbcbfdc150
44 changed files with 40066 additions and 71 deletions
196
vendors/cryptico/README.md
vendored
Normal file
196
vendors/cryptico/README.md
vendored
Normal file
|
|
@ -0,0 +1,196 @@
|
|||
# cryptico
|
||||
|
||||
## Overview
|
||||
|
||||
### Generating an RSA key pair & public key string
|
||||
|
||||
Sam wants to send Matt an encrypted message. In order to do this, he first needs Matt's public key string. A public key pair can be generated for Matt like this:
|
||||
|
||||
```javascript
|
||||
// The passphrase used to repeatably generate this RSA key.
|
||||
var PassPhrase = "The Moon is a Harsh Mistress.";
|
||||
|
||||
// The length of the RSA key, in bits.
|
||||
var Bits = 1024;
|
||||
|
||||
var MattsRSAkey = cryptico.generateRSAKey(PassPhrase, Bits);
|
||||
```
|
||||
|
||||
Matt's public key string can then be generated like this:
|
||||
|
||||
```javascript
|
||||
var MattsPublicKeyString = cryptico.publicKeyString(MattsRSAkey);
|
||||
```
|
||||
|
||||
and looks like this:
|
||||
|
||||
uXjrkGqe5WuS7zsTg6Z9DuS8cXLFz38ue+xrFzxrcQJCXtVccCoUFP2qH/AQ
|
||||
4qMvxxvqkSYBpRm1R5a4/NdQ5ei8sE8gfZEq7dlcR+gOSv3nnS4/CX1n5Z5m
|
||||
8bvFPF0lSZnYQ23xlyjXTaNacmV0IuZbqWd4j9LfdAKq5dvDaoE=
|
||||
|
||||
### Encrypting a message
|
||||
|
||||
Matt emails Sam his public key string. Now Sam can encrypt a message for Matt:
|
||||
|
||||
```javascript
|
||||
var PlainText = "Matt, I need you to help me with my Starcraft strategy.";
|
||||
|
||||
var EncryptionResult = cryptico.encrypt(PlainText, MattsPublicKeyString);
|
||||
```
|
||||
|
||||
`EncryptionResult.cipher` is the encrypted message, and looks like this:
|
||||
|
||||
OOHoAlfm6Viyl7afkUVRoYQv24AfdLnxaay5GjcqpxvEK+dph5kUFZEZIFKo
|
||||
vVoHoZbtUMekSbMqHQr3wNNpvcNWr4E3DgNLfMZQA1pCAUVmPjNM1ZQmrkKY
|
||||
HPKvkhmVKaBiYAJGoO/YiFfKnaylLpKOYJZctkZc4wflZcEEqqg=?cJPt71I
|
||||
HcU5c2LgqGXQKcx2BaAbm25Q2Ku94c933LX5MObL9qbTJEVEv29U0C3gIqcd
|
||||
qwMV6nl33GtHjyRdHx5fZcon21glUKIbE9P71NwQ=
|
||||
|
||||
### Decrypting a message
|
||||
|
||||
Sam sends his encrypted message to Matt. The message can be decrypted like this:
|
||||
|
||||
```javascript
|
||||
var CipherText = "OOHoAlfm6Viyl7afkUVRoYQv24AfdLnxaay5GjcqpxvEK+dph5kUFZEZIFKo \
|
||||
vVoHoZbtUMekSbMqHQr3wNNpvcNWr4E3DgNLfMZQA1pCAUVmPjNM1ZQmrkKY \
|
||||
HPKvkhmVKaBiYAJGoO/YiFfKnaylLpKOYJZctkZc4wflZcEEqqg=?cJPt71I \
|
||||
HcU5c2LgqGXQKcx2BaAbm25Q2Ku94c933LX5MObL9qbTJEVEv29U0C3gIqcd \
|
||||
qwMV6nl33GtHjyRdHx5fZcon21glUKIbE9P71NwQ=";
|
||||
|
||||
var DecryptionResult = cryptico.decrypt(CipherText, MattsRSAkey);
|
||||
```
|
||||
|
||||
The decrypted message is in `DecryptionResult.plaintext`.
|
||||
|
||||
### Signatures & Public Key IDs
|
||||
|
||||
If Sam's RSA key is provided to the `cryptico.encrypt` function, the message will be signed by him:
|
||||
|
||||
```javascript
|
||||
var PassPhrase = "There Ain't No Such Thing As A Free Lunch.";
|
||||
|
||||
var SamsRSAkey = cryptico.generateRSAKey(PassPhrase, 1024);
|
||||
|
||||
var PlainText = "Matt, I need you to help me with my Starcraft strategy.";
|
||||
|
||||
var EncryptionResult = cryptico.encrypt(PlainText, MattsPublicKeyString, SamsRSAkey);
|
||||
```
|
||||
|
||||
The public key associated with the signature can be used by Matt to make sure that it was sent by Sam, but there are a lot of characters to examine in the key - it would be easy to make a mistake. Instead, the public key string associated with the signature can be processed like this:
|
||||
|
||||
```javascript
|
||||
var PublicKeyID = cryptico.publicKeyID(EncryptionResult.publickey);
|
||||
```
|
||||
|
||||
and `PublicKeyID` would look something like this:
|
||||
|
||||
d0bffb0c422dfa3d3d8502040b915248
|
||||
|
||||
This shorter key ID can be used to uniquely identify Sam's public key more easily if it must be done manually. Moreover, this key ID can be used by Sam or Matt to make sure they have typed their own passphrases correctly.
|
||||
|
||||
# API Documentation
|
||||
|
||||
## RSA Keys
|
||||
|
||||
cryptico.generateRSAKey(passphrase, bitlength)
|
||||
|
||||
Generates an RSAKey object from a password and bitlength.
|
||||
|
||||
`passphrase`: string from which the RSA key is generated.
|
||||
|
||||
`bitlength`: integer, length of the RSA key (512, 1024, 2048, 4096, 8192).
|
||||
|
||||
Returns an `RSAKey` object.
|
||||
|
||||
cryptico.publicKeyString(rsakey)
|
||||
|
||||
Returns the public key portion of an RSAKey object in ascii-armored
|
||||
string form, which allows it to be used on websites and in text files
|
||||
without fear of corrupting the public key.
|
||||
|
||||
`rsakey`: An `RSAKey` object.
|
||||
|
||||
Returns an ascii-armored public key string.
|
||||
|
||||
cryptico.publicKeyID(publicKeyString)
|
||||
|
||||
Returns an MD5 sum of a `publicKeyString` for easier identification.
|
||||
|
||||
`publicKeyString`: a public key in ascii-armored string form, as generated by the `cryptico.publicKeyString` function.
|
||||
|
||||
Returns an MD5 sum of the public key string.
|
||||
|
||||
## Encryption
|
||||
|
||||
cryptico.encrypt(plaintext, publicKeyString, signingKey)
|
||||
|
||||
Encrypts a string with the provided public key. Optionally signs the encrypted string with an RSAKey object.
|
||||
|
||||
`plaintext`: the string to be encrypted.
|
||||
|
||||
`publicKeyString`: The public key string of the recipient.
|
||||
|
||||
`signingKey`: the `RSAKey` object of the sender.
|
||||
|
||||
Returns: `status`, `cipher`
|
||||
|
||||
`status`: "success" if encryption succeeded, "failure" if it failed.
|
||||
|
||||
`cipher`: An ascii-armored encrypted message string, optionally signed.
|
||||
|
||||
## Decryption
|
||||
|
||||
cryptico.decrypt(ciphertext, key)
|
||||
|
||||
Decrypts an encrypted message with the recipient's RSAKey and verifies the signature, if any.
|
||||
|
||||
`ciphertext`: The encrypted message to be decrypted.
|
||||
|
||||
`key`: The `RSAKey` object of the recipient.
|
||||
|
||||
Returns: `status`, `plaintext`, `signature`, `publicKeyString`
|
||||
|
||||
`status`: "success" if decryption succeeded, "failure" if it failed. **Does not reflect the status of the signature verification.**
|
||||
|
||||
`plaintext`: The decrypted message.
|
||||
|
||||
`signature`: "unsigned" if there was no signature, "verified" if it is signed and valid, **"forged" if the signature fails verification**.
|
||||
|
||||
`publicKeyString`: public key string of the signature (presumably the sender). **Returned even if the signature appears to be forged**.
|
||||
|
||||
# Encryption Technical Documentation
|
||||
|
||||
## Key generation
|
||||
|
||||
A hash is generated of the user's passphrase using the SHA256 algorithm found at <a href="http://www.webtoolkit.info/javascript-sha256.html">webtoolkit.info</a>. This hash is used to seed <a href="http://davidbau.com/archives/2010/01/30/random_seeds_coded_hints_and_quintillions.html">David Bau's seedable random number generator</a>. A (seeded) random RSA key is generated with <a href="http://www-cs-students.stanford.edu/~tjw/jsbn/">Tom Wu's RSA key generator</a> with 3 as a hard-coded public exponent.
|
||||
|
||||
## Encryption
|
||||
|
||||
A 32-byte AES key is generated with <a href="http://www-cs-students.stanford.edu/~tjw/jsbn/">Tom Wu's random number generator</a>. The plaintext message is converted to a byte string and padded with zeros to 16 bytes round. An initialization vector is created with <a href="http://www-cs-students.stanford.edu/~tjw/jsbn/">Tom Wu's random number generator</a>. The AES key is expanded and the plaintext message is encrypted with the Cipher-block chaining mode using the <a href="http://point-at-infinity.org/jsaes/">jsaes</a> library. The AES key is encrypted with the recipient's public key using <a href="http://www-cs-students.stanford.edu/~tjw/jsbn/">Tom Wu's RSA encryption library</a>.
|
||||
|
||||
The encrypted AES key and encrypted message are ascii-armored and concatenated with the "?" character as a delimiter. As an example, here is the result of the phrase "Matt, I need you to help me with my Starcraft strategy." encrypted with
|
||||
the passphrase "The Moon is a Harsh Mistress." used to generate the 1024-bit public key:
|
||||
|
||||
EuvU2Ov3gpgM9B1I3VzEgxaAVO/Iy85NARUFZb/h+HrOP72degP0L1fWiHO3
|
||||
RDm5+kWRaV6oZsn91juJ0L+hrP6BDwlIza9x9DBMEsg3PnOHJENG63RXbu0q
|
||||
PZd2xDJY70i44sufNqHZ0mui9OdNIeE8FvzEOzMtFGCqDx1Z48s=?K3lOtQC
|
||||
2w+emoR4W3yvAaslSzTj/ZZIkOu3MNTW8y/OX0OxTKfpsaI6zX6XYrM0MpPr
|
||||
uw7on1N6VUMpNQO8KUVYl4clquaibKs0marXPFH4=
|
||||
|
||||
## Signing
|
||||
|
||||
When signing the encrypted message, two more pieces of information are attached to the cipher text. The first is the ascii-armored RSA public key of the sender. The second piece of information concatenated with the cipher text is
|
||||
the signature itself, which is generated with the <a href="http://www9.atwiki.jp/kurushima/pub/jsrsa/">rsa-sign extension by Kenji Urushima</a>, along with the SHA256 algorithm found at <a href="http://www.webtoolkit.info/javascript-sha256.html">webtoolkit.info</a>. These two pieces of code are also used when verifying the signature.
|
||||
|
||||
The signature is concatenated with the public key with the string
|
||||
`::52cee64bb3a38f6403386519a39ac91c::` used as the delimiter between the
|
||||
plaintext, the public key of the sender, and the signature:
|
||||
|
||||
plaintext
|
||||
::52cee64bb3a38f6403386519a39ac91c::
|
||||
public key of sender
|
||||
::52cee64bb3a38f6403386519a39ac91c::
|
||||
signature
|
||||
|
||||
This concatenated block is then encrypted with CBC AES and concatenated with the
|
||||
encrypted AES key to form the complete encrypted message.
|
||||
157
vendors/cryptico/aes.js
vendored
Normal file
157
vendors/cryptico/aes.js
vendored
Normal file
|
|
@ -0,0 +1,157 @@
|
|||
/*
|
||||
* jsaes version 0.1 - Copyright 2006 B. Poettering
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||
* 02111-1307 USA
|
||||
*/
|
||||
|
||||
// later modifications by wwwtyro@github
|
||||
|
||||
var aes = (function () {
|
||||
|
||||
var my = {};
|
||||
|
||||
my.Sbox = new Array(99, 124, 119, 123, 242, 107, 111, 197, 48, 1, 103, 43, 254, 215, 171, 118, 202, 130, 201, 125, 250, 89, 71, 240, 173, 212, 162, 175, 156, 164, 114, 192, 183, 253, 147, 38, 54, 63, 247, 204, 52, 165, 229, 241, 113, 216, 49, 21, 4, 199, 35, 195, 24, 150, 5, 154, 7, 18, 128, 226, 235, 39, 178, 117, 9, 131, 44, 26, 27, 110, 90, 160, 82, 59, 214, 179, 41, 227, 47, 132, 83, 209, 0, 237, 32, 252, 177, 91, 106, 203, 190, 57, 74, 76, 88, 207, 208, 239, 170, 251, 67, 77, 51, 133, 69, 249, 2, 127, 80, 60, 159, 168, 81, 163, 64, 143, 146, 157, 56, 245, 188, 182, 218, 33, 16, 255, 243, 210, 205, 12, 19, 236, 95, 151, 68, 23, 196, 167, 126, 61, 100, 93, 25, 115, 96, 129, 79, 220, 34, 42, 144, 136, 70, 238, 184, 20, 222, 94, 11, 219, 224, 50, 58, 10, 73, 6, 36, 92, 194, 211, 172, 98, 145, 149, 228, 121, 231, 200, 55, 109, 141, 213, 78, 169, 108, 86, 244, 234, 101, 122, 174, 8, 186, 120, 37, 46, 28, 166, 180, 198, 232, 221, 116, 31, 75, 189, 139, 138, 112, 62, 181, 102, 72, 3, 246, 14, 97, 53, 87, 185, 134, 193, 29, 158, 225, 248, 152, 17, 105, 217, 142, 148, 155, 30, 135, 233, 206, 85, 40, 223, 140, 161, 137, 13, 191, 230, 66, 104, 65, 153, 45, 15, 176, 84, 187, 22);
|
||||
|
||||
my.ShiftRowTab = new Array(0, 5, 10, 15, 4, 9, 14, 3, 8, 13, 2, 7, 12, 1, 6, 11);
|
||||
|
||||
my.Init = function () {
|
||||
my.Sbox_Inv = new Array(256);
|
||||
for (var i = 0; i < 256; i++)
|
||||
my.Sbox_Inv[my.Sbox[i]] = i;
|
||||
|
||||
my.ShiftRowTab_Inv = new Array(16);
|
||||
for (var i = 0; i < 16; i++)
|
||||
my.ShiftRowTab_Inv[my.ShiftRowTab[i]] = i;
|
||||
|
||||
my.xtime = new Array(256);
|
||||
for (var i = 0; i < 128; i++) {
|
||||
my.xtime[i] = i << 1;
|
||||
my.xtime[128 + i] = (i << 1) ^ 0x1b;
|
||||
}
|
||||
}
|
||||
|
||||
my.Done = function () {
|
||||
delete my.Sbox_Inv;
|
||||
delete my.ShiftRowTab_Inv;
|
||||
delete my.xtime;
|
||||
}
|
||||
|
||||
my.ExpandKey = function (key) {
|
||||
var kl = key.length,
|
||||
ks, Rcon = 1;
|
||||
switch (kl) {
|
||||
case 16:
|
||||
ks = 16 * (10 + 1);
|
||||
break;
|
||||
case 24:
|
||||
ks = 16 * (12 + 1);
|
||||
break;
|
||||
case 32:
|
||||
ks = 16 * (14 + 1);
|
||||
break;
|
||||
default:
|
||||
alert("my.ExpandKey: Only key lengths of 16, 24 or 32 bytes allowed!");
|
||||
}
|
||||
for (var i = kl; i < ks; i += 4) {
|
||||
var temp = key.slice(i - 4, i);
|
||||
if (i % kl == 0) {
|
||||
temp = new Array(my.Sbox[temp[1]] ^ Rcon, my.Sbox[temp[2]], my.Sbox[temp[3]], my.Sbox[temp[0]]);
|
||||
if ((Rcon <<= 1) >= 256) Rcon ^= 0x11b;
|
||||
}
|
||||
else if ((kl > 24) && (i % kl == 16)) temp = new Array(my.Sbox[temp[0]], my.Sbox[temp[1]], my.Sbox[temp[2]], my.Sbox[temp[3]]);
|
||||
for (var j = 0; j < 4; j++)
|
||||
key[i + j] = key[i + j - kl] ^ temp[j];
|
||||
}
|
||||
}
|
||||
|
||||
my.Encrypt = function (block, key) {
|
||||
var l = key.length;
|
||||
my.AddRoundKey(block, key.slice(0, 16));
|
||||
for (var i = 16; i < l - 16; i += 16) {
|
||||
my.SubBytes(block, my.Sbox);
|
||||
my.ShiftRows(block, my.ShiftRowTab);
|
||||
my.MixColumns(block);
|
||||
my.AddRoundKey(block, key.slice(i, i + 16));
|
||||
}
|
||||
my.SubBytes(block, my.Sbox);
|
||||
my.ShiftRows(block, my.ShiftRowTab);
|
||||
my.AddRoundKey(block, key.slice(i, l));
|
||||
}
|
||||
|
||||
my.Decrypt = function (block, key) {
|
||||
var l = key.length;
|
||||
my.AddRoundKey(block, key.slice(l - 16, l));
|
||||
my.ShiftRows(block, my.ShiftRowTab_Inv);
|
||||
my.SubBytes(block, my.Sbox_Inv);
|
||||
for (var i = l - 32; i >= 16; i -= 16) {
|
||||
my.AddRoundKey(block, key.slice(i, i + 16));
|
||||
my.MixColumns_Inv(block);
|
||||
my.ShiftRows(block, my.ShiftRowTab_Inv);
|
||||
my.SubBytes(block, my.Sbox_Inv);
|
||||
}
|
||||
my.AddRoundKey(block, key.slice(0, 16));
|
||||
}
|
||||
|
||||
my.SubBytes = function (state, sbox) {
|
||||
for (var i = 0; i < 16; i++)
|
||||
state[i] = sbox[state[i]];
|
||||
}
|
||||
|
||||
my.AddRoundKey = function (state, rkey) {
|
||||
for (var i = 0; i < 16; i++)
|
||||
state[i] ^= rkey[i];
|
||||
}
|
||||
|
||||
my.ShiftRows = function (state, shifttab) {
|
||||
var h = new Array().concat(state);
|
||||
for (var i = 0; i < 16; i++)
|
||||
state[i] = h[shifttab[i]];
|
||||
}
|
||||
|
||||
my.MixColumns = function (state) {
|
||||
for (var i = 0; i < 16; i += 4) {
|
||||
var s0 = state[i + 0],
|
||||
s1 = state[i + 1];
|
||||
var s2 = state[i + 2],
|
||||
s3 = state[i + 3];
|
||||
var h = s0 ^ s1 ^ s2 ^ s3;
|
||||
state[i + 0] ^= h ^ my.xtime[s0 ^ s1];
|
||||
state[i + 1] ^= h ^ my.xtime[s1 ^ s2];
|
||||
state[i + 2] ^= h ^ my.xtime[s2 ^ s3];
|
||||
state[i + 3] ^= h ^ my.xtime[s3 ^ s0];
|
||||
}
|
||||
}
|
||||
|
||||
my.MixColumns_Inv = function (state) {
|
||||
for (var i = 0; i < 16; i += 4) {
|
||||
var s0 = state[i + 0],
|
||||
s1 = state[i + 1];
|
||||
var s2 = state[i + 2],
|
||||
s3 = state[i + 3];
|
||||
var h = s0 ^ s1 ^ s2 ^ s3;
|
||||
var xh = my.xtime[h];
|
||||
var h1 = my.xtime[my.xtime[xh ^ s0 ^ s2]] ^ h;
|
||||
var h2 = my.xtime[my.xtime[xh ^ s1 ^ s3]] ^ h;
|
||||
state[i + 0] ^= h1 ^ my.xtime[s0 ^ s1];
|
||||
state[i + 1] ^= h2 ^ my.xtime[s1 ^ s2];
|
||||
state[i + 2] ^= h1 ^ my.xtime[s2 ^ s3];
|
||||
state[i + 3] ^= h2 ^ my.xtime[s3 ^ s0];
|
||||
}
|
||||
}
|
||||
|
||||
return my;
|
||||
|
||||
}());
|
||||
405
vendors/cryptico/api.js
vendored
Normal file
405
vendors/cryptico/api.js
vendored
Normal file
|
|
@ -0,0 +1,405 @@
|
|||
|
||||
var cryptico = (function() {
|
||||
|
||||
var my = {};
|
||||
|
||||
aes.Init();
|
||||
|
||||
var base64Chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
||||
|
||||
my.b256to64 = function(t) {
|
||||
var a, c, n;
|
||||
var r = '', l = 0, s = 0;
|
||||
var tl = t.length;
|
||||
for (n = 0; n < tl; n++)
|
||||
{
|
||||
c = t.charCodeAt(n);
|
||||
if (s == 0)
|
||||
{
|
||||
r += base64Chars.charAt((c >> 2) & 63);
|
||||
a = (c & 3) << 4;
|
||||
}
|
||||
else if (s == 1)
|
||||
{
|
||||
r += base64Chars.charAt((a | (c >> 4) & 15));
|
||||
a = (c & 15) << 2;
|
||||
}
|
||||
else if (s == 2)
|
||||
{
|
||||
r += base64Chars.charAt(a | ((c >> 6) & 3));
|
||||
l += 1;
|
||||
r += base64Chars.charAt(c & 63);
|
||||
}
|
||||
l += 1;
|
||||
s += 1;
|
||||
if (s == 3) s = 0;
|
||||
}
|
||||
if (s > 0)
|
||||
{
|
||||
r += base64Chars.charAt(a);
|
||||
l += 1;
|
||||
r += '=';
|
||||
l += 1;
|
||||
}
|
||||
if (s == 1)
|
||||
{
|
||||
r += '=';
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
my.b64to256 = function(t)
|
||||
{
|
||||
var c, n;
|
||||
var r = '', s = 0, a = 0;
|
||||
var tl = t.length;
|
||||
for (n = 0; n < tl; n++)
|
||||
{
|
||||
c = base64Chars.indexOf(t.charAt(n));
|
||||
if (c >= 0)
|
||||
{
|
||||
if (s) r += String.fromCharCode(a | (c >> (6 - s)) & 255);
|
||||
s = (s + 2) & 7;
|
||||
a = (c << s) & 255;
|
||||
}
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
my.b16to64 = function(h) {
|
||||
var i;
|
||||
var c;
|
||||
var ret = "";
|
||||
if(h.length % 2 == 1)
|
||||
{
|
||||
h = "0" + h;
|
||||
}
|
||||
for (i = 0; i + 3 <= h.length; i += 3)
|
||||
{
|
||||
c = parseInt(h.substring(i, i + 3), 16);
|
||||
ret += base64Chars.charAt(c >> 6) + base64Chars.charAt(c & 63);
|
||||
}
|
||||
if (i + 1 == h.length)
|
||||
{
|
||||
c = parseInt(h.substring(i, i + 1), 16);
|
||||
ret += base64Chars.charAt(c << 2);
|
||||
}
|
||||
else if (i + 2 == h.length)
|
||||
{
|
||||
c = parseInt(h.substring(i, i + 2), 16);
|
||||
ret += base64Chars.charAt(c >> 2) + base64Chars.charAt((c & 3) << 4);
|
||||
}
|
||||
while ((ret.length & 3) > 0) ret += "=";
|
||||
return ret;
|
||||
}
|
||||
|
||||
my.b64to16 = function(s) {
|
||||
var ret = "";
|
||||
var i;
|
||||
var k = 0;
|
||||
var slop;
|
||||
for (i = 0; i < s.length; ++i)
|
||||
{
|
||||
if (s.charAt(i) == "=") break;
|
||||
v = base64Chars.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;
|
||||
}
|
||||
|
||||
// Converts a string to a byte array.
|
||||
my.string2bytes = function(string)
|
||||
{
|
||||
var bytes = new Array();
|
||||
for(var i = 0; i < string.length; i++)
|
||||
{
|
||||
bytes.push(string.charCodeAt(i));
|
||||
}
|
||||
return bytes;
|
||||
}
|
||||
|
||||
// Converts a byte array to a string.
|
||||
my.bytes2string = function(bytes)
|
||||
{
|
||||
var string = "";
|
||||
for(var i = 0; i < bytes.length; i++)
|
||||
{
|
||||
string += String.fromCharCode(bytes[i]);
|
||||
}
|
||||
return string;
|
||||
}
|
||||
|
||||
// Returns a XOR b, where a and b are 16-byte byte arrays.
|
||||
my.blockXOR = function(a, b)
|
||||
{
|
||||
var xor = new Array(16);
|
||||
for(var i = 0; i < 16; i++)
|
||||
{
|
||||
xor[i] = a[i] ^ b[i];
|
||||
}
|
||||
return xor;
|
||||
}
|
||||
|
||||
// Returns a 16-byte initialization vector.
|
||||
my.blockIV = function()
|
||||
{
|
||||
var r = new SecureRandom();
|
||||
var IV = new Array(16);
|
||||
r.nextBytes(IV);
|
||||
return IV;
|
||||
}
|
||||
|
||||
// Returns a copy of bytes with zeros appended to the end
|
||||
// so that the (length of bytes) % 16 == 0.
|
||||
my.pad16 = function(bytes)
|
||||
{
|
||||
var newBytes = bytes.slice(0);
|
||||
var padding = (16 - (bytes.length % 16)) % 16;
|
||||
for(i = bytes.length; i < bytes.length + padding; i++)
|
||||
{
|
||||
newBytes.push(0);
|
||||
}
|
||||
return newBytes;
|
||||
}
|
||||
|
||||
// Removes trailing zeros from a byte array.
|
||||
my.depad = function(bytes)
|
||||
{
|
||||
var newBytes = bytes.slice(0);
|
||||
while(newBytes[newBytes.length - 1] == 0)
|
||||
{
|
||||
newBytes = newBytes.slice(0, newBytes.length - 1);
|
||||
}
|
||||
return newBytes;
|
||||
}
|
||||
|
||||
// AES CBC Encryption.
|
||||
my.encryptAESCBC = function(plaintext, key)
|
||||
{
|
||||
var exkey = key.slice(0);
|
||||
aes.ExpandKey(exkey);
|
||||
var blocks = my.string2bytes(plaintext);
|
||||
blocks = my.pad16(blocks);
|
||||
var encryptedBlocks = my.blockIV();
|
||||
for(var i = 0; i < blocks.length/16; i++)
|
||||
{
|
||||
var tempBlock = blocks.slice(i * 16, i * 16 + 16);
|
||||
var prevBlock = encryptedBlocks.slice((i) * 16, (i) * 16 + 16);
|
||||
tempBlock = my.blockXOR(prevBlock, tempBlock);
|
||||
aes.Encrypt(tempBlock, exkey);
|
||||
encryptedBlocks = encryptedBlocks.concat(tempBlock);
|
||||
}
|
||||
var ciphertext = my.bytes2string(encryptedBlocks);
|
||||
return my.b256to64(ciphertext)
|
||||
}
|
||||
|
||||
// AES CBC Decryption.
|
||||
my.decryptAESCBC = function(encryptedText, key)
|
||||
{
|
||||
var exkey = key.slice(0);
|
||||
aes.ExpandKey(exkey);
|
||||
var encryptedText = my.b64to256(encryptedText);
|
||||
var encryptedBlocks = my.string2bytes(encryptedText);
|
||||
var decryptedBlocks = new Array();
|
||||
for(var i = 1; i < encryptedBlocks.length/16; i++)
|
||||
{
|
||||
var tempBlock = encryptedBlocks.slice(i * 16, i * 16 + 16);
|
||||
var prevBlock = encryptedBlocks.slice((i-1) * 16, (i-1) * 16 + 16);
|
||||
aes.Decrypt(tempBlock, exkey);
|
||||
tempBlock = my.blockXOR(prevBlock, tempBlock);
|
||||
decryptedBlocks = decryptedBlocks.concat(tempBlock);
|
||||
}
|
||||
decryptedBlocks = my.depad(decryptedBlocks);
|
||||
return my.bytes2string(decryptedBlocks);
|
||||
}
|
||||
|
||||
// Wraps a string to 60 characters.
|
||||
my.wrap60 = function(string)
|
||||
{
|
||||
var outstr = "";
|
||||
for(var i = 0; i < string.length; i++) {
|
||||
if(i % 60 == 0 && i != 0) outstr += "\n";
|
||||
outstr += string[i]; }
|
||||
return outstr;
|
||||
}
|
||||
|
||||
// Generate a random key for the AES-encrypted message.
|
||||
my.generateAESKey = function()
|
||||
{
|
||||
var key = new Array(32);
|
||||
var r = new SecureRandom();
|
||||
r.nextBytes(key);
|
||||
return key;
|
||||
}
|
||||
|
||||
// Generates an RSA key from a passphrase.
|
||||
my.generateRSAKey = function(passphrase, bitlength)
|
||||
{
|
||||
Math.seedrandom(sha256.hex(passphrase));
|
||||
var rsa = new RSAKey();
|
||||
rsa.generate(bitlength, "03");
|
||||
return rsa;
|
||||
}
|
||||
|
||||
// Returns the ascii-armored version of the public key.
|
||||
my.publicKeyString = function(rsakey)
|
||||
{
|
||||
pubkey = my.b16to64(rsakey.n.toString(16));
|
||||
return pubkey;
|
||||
}
|
||||
|
||||
// Returns an MD5 sum of a publicKeyString for easier identification.
|
||||
my.publicKeyID = function(publicKeyString)
|
||||
{
|
||||
return MD5(publicKeyString);
|
||||
}
|
||||
|
||||
my.publicKeyFromString = function(string)
|
||||
{
|
||||
var N = my.b64to16(string.split("|")[0]);
|
||||
var E = "03";
|
||||
var rsa = new RSAKey();
|
||||
rsa.setPublic(N, E);
|
||||
return rsa
|
||||
}
|
||||
|
||||
my.encrypt = function(plaintext, publickeystring, signingkey)
|
||||
{
|
||||
var cipherblock = "";
|
||||
var aeskey = my.generateAESKey();
|
||||
try
|
||||
{
|
||||
var publickey = my.publicKeyFromString(publickeystring);
|
||||
cipherblock += my.b16to64(publickey.encrypt(my.bytes2string(aeskey))) + "?";
|
||||
}
|
||||
catch(err)
|
||||
{
|
||||
return {status: "Invalid public key"};
|
||||
}
|
||||
if(signingkey)
|
||||
{
|
||||
signString = cryptico.b16to64(signingkey.signString(plaintext, "sha256"));
|
||||
plaintext += "::52cee64bb3a38f6403386519a39ac91c::";
|
||||
plaintext += cryptico.publicKeyString(signingkey);
|
||||
plaintext += "::52cee64bb3a38f6403386519a39ac91c::";
|
||||
plaintext += signString;
|
||||
}
|
||||
cipherblock += my.encryptAESCBC(plaintext, aeskey);
|
||||
return {status: "success", cipher: cipherblock};
|
||||
}
|
||||
|
||||
my.decrypt = function(ciphertext, key)
|
||||
{
|
||||
var cipherblock = ciphertext.split("?");
|
||||
var aeskey = key.decrypt(my.b64to16(cipherblock[0]));
|
||||
if(aeskey == null)
|
||||
{
|
||||
return {status: "failure"};
|
||||
}
|
||||
aeskey = my.string2bytes(aeskey);
|
||||
var plaintext = my.decryptAESCBC(cipherblock[1], aeskey).split("::52cee64bb3a38f6403386519a39ac91c::");
|
||||
if(plaintext.length == 3)
|
||||
{
|
||||
var publickey = my.publicKeyFromString(plaintext[1]);
|
||||
var signature = my.b64to16(plaintext[2]);
|
||||
if(publickey.verifyString(plaintext[0], signature))
|
||||
{
|
||||
return {status: "success",
|
||||
plaintext: plaintext[0],
|
||||
signature: "verified",
|
||||
publicKeyString: my.publicKeyString(publickey)};
|
||||
}
|
||||
else
|
||||
{
|
||||
return {status: "success",
|
||||
plaintext: plaintext[0],
|
||||
signature: "forged",
|
||||
publicKeyString: my.publicKeyString(publickey)};
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return {status: "success", plaintext: plaintext[0], signature: "unsigned"};
|
||||
}
|
||||
}
|
||||
|
||||
return my;
|
||||
|
||||
}());
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
3585
vendors/cryptico/cryptico.js
vendored
Normal file
3585
vendors/cryptico/cryptico.js
vendored
Normal file
File diff suppressed because it is too large
Load diff
107
vendors/cryptico/cryptico.min.js
vendored
Normal file
107
vendors/cryptico/cryptico.min.js
vendored
Normal file
|
|
@ -0,0 +1,107 @@
|
|||
var dbits,canary=244837814094590,j_lm=(canary&16777215)==15715070;function BigInteger(a,b,c){a!=null&&("number"==typeof a?this.fromNumber(a,b,c):b==null&&"string"!=typeof a?this.fromString(a,256):this.fromString(a,b))}function nbi(){return new BigInteger(null)}function am1(a,b,c,d,e,g){for(;--g>=0;){var h=b*this[a++]+c[d]+e,e=Math.floor(h/67108864);c[d++]=h&67108863}return e}
|
||||
function am2(a,b,c,d,e,g){var h=b&32767;for(b>>=15;--g>=0;){var f=this[a]&32767,o=this[a++]>>15,p=b*f+o*h,f=h*f+((p&32767)<<15)+c[d]+(e&1073741823),e=(f>>>30)+(p>>>15)+b*o+(e>>>30);c[d++]=f&1073741823}return e}function am3(a,b,c,d,e,g){var h=b&16383;for(b>>=14;--g>=0;){var f=this[a]&16383,o=this[a++]>>14,p=b*f+o*h,f=h*f+((p&16383)<<14)+c[d]+e,e=(f>>28)+(p>>14)+b*o;c[d++]=f&268435455}return e}
|
||||
j_lm&&navigator.appName=="Microsoft Internet Explorer"?(BigInteger.prototype.am=am2,dbits=30):j_lm&&navigator.appName!="Netscape"?(BigInteger.prototype.am=am1,dbits=26):(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;var BI_RM="0123456789abcdefghijklmnopqrstuvwxyz",BI_RC=[],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(a){return BI_RM.charAt(a)}function intAt(a,b){var c=BI_RC[a.charCodeAt(b)];return c==null?-1:c}function bnpCopyTo(a){for(var b=this.t-1;b>=0;--b)a[b]=this[b];a.t=this.t;a.s=this.s}function bnpFromInt(a){this.t=1;this.s=a<0?-1:0;a>0?this[0]=a:a<-1?this[0]=a+DV:this.t=0}
|
||||
function nbv(a){var b=nbi();b.fromInt(a);return b}
|
||||
function bnpFromString(a,b){var c;if(b==16)c=4;else if(b==8)c=3;else if(b==256)c=8;else if(b==2)c=1;else if(b==32)c=5;else if(b==4)c=2;else{this.fromRadix(a,b);return}this.s=this.t=0;for(var d=a.length,e=!1,g=0;--d>=0;){var h=c==8?a[d]&255:intAt(a,d);h<0?a.charAt(d)=="-"&&(e=!0):(e=!1,g==0?this[this.t++]=h:g+c>this.DB?(this[this.t-1]|=(h&(1<<this.DB-g)-1)<<g,this[this.t++]=h>>this.DB-g):this[this.t-1]|=h<<g,g+=c,g>=this.DB&&(g-=this.DB))}if(c==8&&(a[0]&128)!=0)this.s=-1,g>0&&(this[this.t-1]|=(1<<
|
||||
this.DB-g)-1<<g);this.clamp();e&&BigInteger.ZERO.subTo(this,this)}function bnpClamp(){for(var a=this.s&this.DM;this.t>0&&this[this.t-1]==a;)--this.t}
|
||||
function bnToString(a){if(this.s<0)return"-"+this.negate().toString(a);if(a==16)a=4;else if(a==8)a=3;else if(a==2)a=1;else if(a==32)a=5;else if(a==64)a=6;else if(a==4)a=2;else return this.toRadix(a);var b=(1<<a)-1,c,d=!1,e="",g=this.t,h=this.DB-g*this.DB%a;if(g-- >0){if(h<this.DB&&(c=this[g]>>h)>0)d=!0,e=int2char(c);for(;g>=0;)h<a?(c=(this[g]&(1<<h)-1)<<a-h,c|=this[--g]>>(h+=this.DB-a)):(c=this[g]>>(h-=a)&b,h<=0&&(h+=this.DB,--g)),c>0&&(d=!0),d&&(e+=int2char(c))}return d?e:"0"}
|
||||
function bnNegate(){var a=nbi();BigInteger.ZERO.subTo(this,a);return a}function bnAbs(){return this.s<0?this.negate():this}function bnCompareTo(a){var b=this.s-a.s;if(b!=0)return b;var c=this.t,b=c-a.t;if(b!=0)return b;for(;--c>=0;)if((b=this[c]-a[c])!=0)return b;return 0}function nbits(a){var b=1,c;if((c=a>>>16)!=0)a=c,b+=16;if((c=a>>8)!=0)a=c,b+=8;if((c=a>>4)!=0)a=c,b+=4;if((c=a>>2)!=0)a=c,b+=2;a>>1!=0&&(b+=1);return b}
|
||||
function bnBitLength(){return this.t<=0?0:this.DB*(this.t-1)+nbits(this[this.t-1]^this.s&this.DM)}function bnpDLShiftTo(a,b){var c;for(c=this.t-1;c>=0;--c)b[c+a]=this[c];for(c=a-1;c>=0;--c)b[c]=0;b.t=this.t+a;b.s=this.s}function bnpDRShiftTo(a,b){for(var c=a;c<this.t;++c)b[c-a]=this[c];b.t=Math.max(this.t-a,0);b.s=this.s}
|
||||
function bnpLShiftTo(a,b){var c=a%this.DB,d=this.DB-c,e=(1<<d)-1,g=Math.floor(a/this.DB),h=this.s<<c&this.DM,f;for(f=this.t-1;f>=0;--f)b[f+g+1]=this[f]>>d|h,h=(this[f]&e)<<c;for(f=g-1;f>=0;--f)b[f]=0;b[g]=h;b.t=this.t+g+1;b.s=this.s;b.clamp()}
|
||||
function bnpRShiftTo(a,b){b.s=this.s;var c=Math.floor(a/this.DB);if(c>=this.t)b.t=0;else{var d=a%this.DB,e=this.DB-d,g=(1<<d)-1;b[0]=this[c]>>d;for(var h=c+1;h<this.t;++h)b[h-c-1]|=(this[h]&g)<<e,b[h-c]=this[h]>>d;d>0&&(b[this.t-c-1]|=(this.s&g)<<e);b.t=this.t-c;b.clamp()}}
|
||||
function bnpSubTo(a,b){for(var c=0,d=0,e=Math.min(a.t,this.t);c<e;)d+=this[c]-a[c],b[c++]=d&this.DM,d>>=this.DB;if(a.t<this.t){for(d-=a.s;c<this.t;)d+=this[c],b[c++]=d&this.DM,d>>=this.DB;d+=this.s}else{for(d+=this.s;c<a.t;)d-=a[c],b[c++]=d&this.DM,d>>=this.DB;d-=a.s}b.s=d<0?-1:0;d<-1?b[c++]=this.DV+d:d>0&&(b[c++]=d);b.t=c;b.clamp()}
|
||||
function bnpMultiplyTo(a,b){var c=this.abs(),d=a.abs(),e=c.t;for(b.t=e+d.t;--e>=0;)b[e]=0;for(e=0;e<d.t;++e)b[e+c.t]=c.am(0,d[e],b,e,0,c.t);b.s=0;b.clamp();this.s!=a.s&&BigInteger.ZERO.subTo(b,b)}function bnpSquareTo(a){for(var b=this.abs(),c=a.t=2*b.t;--c>=0;)a[c]=0;for(c=0;c<b.t-1;++c){var d=b.am(c,b[c],a,2*c,0,1);if((a[c+b.t]+=b.am(c+1,2*b[c],a,2*c+1,d,b.t-c-1))>=b.DV)a[c+b.t]-=b.DV,a[c+b.t+1]=1}a.t>0&&(a[a.t-1]+=b.am(c,b[c],a,2*c,0,1));a.s=0;a.clamp()}
|
||||
function bnpDivRemTo(a,b,c){var d=a.abs();if(!(d.t<=0)){var e=this.abs();if(e.t<d.t)b!=null&&b.fromInt(0),c!=null&&this.copyTo(c);else{c==null&&(c=nbi());var g=nbi(),h=this.s,a=a.s,f=this.DB-nbits(d[d.t-1]);f>0?(d.lShiftTo(f,g),e.lShiftTo(f,c)):(d.copyTo(g),e.copyTo(c));d=g.t;e=g[d-1];if(e!=0){var o=e*(1<<this.F1)+(d>1?g[d-2]>>this.F2:0),p=this.FV/o,o=(1<<this.F1)/o,q=1<<this.F2,n=c.t,k=n-d,j=b==null?nbi():b;g.dlShiftTo(k,j);c.compareTo(j)>=0&&(c[c.t++]=1,c.subTo(j,c));BigInteger.ONE.dlShiftTo(d,
|
||||
j);for(j.subTo(g,g);g.t<d;)g[g.t++]=0;for(;--k>=0;){var l=c[--n]==e?this.DM:Math.floor(c[n]*p+(c[n-1]+q)*o);if((c[n]+=g.am(0,l,c,k,0,d))<l){g.dlShiftTo(k,j);for(c.subTo(j,c);c[n]<--l;)c.subTo(j,c)}}b!=null&&(c.drShiftTo(d,b),h!=a&&BigInteger.ZERO.subTo(b,b));c.t=d;c.clamp();f>0&&c.rShiftTo(f,c);h<0&&BigInteger.ZERO.subTo(c,c)}}}}function bnMod(a){var b=nbi();this.abs().divRemTo(a,null,b);this.s<0&&b.compareTo(BigInteger.ZERO)>0&&a.subTo(b,b);return b}function Classic(a){this.m=a}
|
||||
function cConvert(a){return a.s<0||a.compareTo(this.m)>=0?a.mod(this.m):a}function cRevert(a){return a}function cReduce(a){a.divRemTo(this.m,null,a)}function cMulTo(a,b,c){a.multiplyTo(b,c);this.reduce(c)}function cSqrTo(a,b){a.squareTo(b);this.reduce(b)}Classic.prototype.convert=cConvert;Classic.prototype.revert=cRevert;Classic.prototype.reduce=cReduce;Classic.prototype.mulTo=cMulTo;Classic.prototype.sqrTo=cSqrTo;
|
||||
function bnpInvDigit(){if(this.t<1)return 0;var a=this[0];if((a&1)==0)return 0;var b=a&3,b=b*(2-(a&15)*b)&15,b=b*(2-(a&255)*b)&255,b=b*(2-((a&65535)*b&65535))&65535,b=b*(2-a*b%this.DV)%this.DV;return b>0?this.DV-b:-b}function Montgomery(a){this.m=a;this.mp=a.invDigit();this.mpl=this.mp&32767;this.mph=this.mp>>15;this.um=(1<<a.DB-15)-1;this.mt2=2*a.t}
|
||||
function montConvert(a){var b=nbi();a.abs().dlShiftTo(this.m.t,b);b.divRemTo(this.m,null,b);a.s<0&&b.compareTo(BigInteger.ZERO)>0&&this.m.subTo(b,b);return b}function montRevert(a){var b=nbi();a.copyTo(b);this.reduce(b);return b}
|
||||
function montReduce(a){for(;a.t<=this.mt2;)a[a.t++]=0;for(var b=0;b<this.m.t;++b){var c=a[b]&32767,d=c*this.mpl+((c*this.mph+(a[b]>>15)*this.mpl&this.um)<<15)&a.DM,c=b+this.m.t;for(a[c]+=this.m.am(0,d,a,b,0,this.m.t);a[c]>=a.DV;)a[c]-=a.DV,a[++c]++}a.clamp();a.drShiftTo(this.m.t,a);a.compareTo(this.m)>=0&&a.subTo(this.m,a)}function montSqrTo(a,b){a.squareTo(b);this.reduce(b)}function montMulTo(a,b,c){a.multiplyTo(b,c);this.reduce(c)}Montgomery.prototype.convert=montConvert;
|
||||
Montgomery.prototype.revert=montRevert;Montgomery.prototype.reduce=montReduce;Montgomery.prototype.mulTo=montMulTo;Montgomery.prototype.sqrTo=montSqrTo;function bnpIsEven(){return(this.t>0?this[0]&1:this.s)==0}function bnpExp(a,b){if(a>4294967295||a<1)return BigInteger.ONE;var c=nbi(),d=nbi(),e=b.convert(this),g=nbits(a)-1;for(e.copyTo(c);--g>=0;)if(b.sqrTo(c,d),(a&1<<g)>0)b.mulTo(d,e,c);else var h=c,c=d,d=h;return b.revert(c)}
|
||||
function bnModPowInt(a,b){var c;c=a<256||b.isEven()?new Classic(b):new Montgomery(b);return this.exp(a,c)}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;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;
|
||||
BigInteger.ZERO=nbv(0);BigInteger.ONE=nbv(1);function bnClone(){var a=nbi();this.copyTo(a);return a}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;return(this[1]&(1<<32-this.DB)-1)<<this.DB|this[0]}function bnByteValue(){return this.t==0?this.s:this[0]<<24>>24}function bnShortValue(){return this.t==0?this.s:this[0]<<16>>16}
|
||||
function bnpChunkSize(a){return Math.floor(Math.LN2*this.DB/Math.log(a))}function bnSigNum(){return this.s<0?-1:this.t<=0||this.t==1&&this[0]<=0?0:1}function bnpToRadix(a){a==null&&(a=10);if(this.signum()==0||a<2||a>36)return"0";var b=this.chunkSize(a),b=Math.pow(a,b),c=nbv(b),d=nbi(),e=nbi(),g="";for(this.divRemTo(c,d,e);d.signum()>0;)g=(b+e.intValue()).toString(a).substr(1)+g,d.divRemTo(c,d,e);return e.intValue().toString(a)+g}
|
||||
function bnpFromRadix(a,b){this.fromInt(0);b==null&&(b=10);for(var c=this.chunkSize(b),d=Math.pow(b,c),e=!1,g=0,h=0,f=0;f<a.length;++f){var o=intAt(a,f);o<0?a.charAt(f)=="-"&&this.signum()==0&&(e=!0):(h=b*h+o,++g>=c&&(this.dMultiply(d),this.dAddOffset(h,0),h=g=0))}g>0&&(this.dMultiply(Math.pow(b,g)),this.dAddOffset(h,0));e&&BigInteger.ZERO.subTo(this,this)}
|
||||
function bnpFromNumber(a,b,c){if("number"==typeof b)if(a<2)this.fromInt(1);else{this.fromNumber(a,c);this.testBit(a-1)||this.bitwiseTo(BigInteger.ONE.shiftLeft(a-1),op_or,this);for(this.isEven()&&this.dAddOffset(1,0);!this.isProbablePrime(b);)this.dAddOffset(2,0),this.bitLength()>a&&this.subTo(BigInteger.ONE.shiftLeft(a-1),this)}else{var c=[],d=a&7;c.length=(a>>3)+1;b.nextBytes(c);d>0?c[0]&=(1<<d)-1:c[0]=0;this.fromString(c,256)}}
|
||||
function bnToByteArray(){var a=this.t,b=[];b[0]=this.s;var c=this.DB-a*this.DB%8,d,e=0;if(a-- >0){if(c<this.DB&&(d=this[a]>>c)!=(this.s&this.DM)>>c)b[e++]=d|this.s<<this.DB-c;for(;a>=0;)if(c<8?(d=(this[a]&(1<<c)-1)<<8-c,d|=this[--a]>>(c+=this.DB-8)):(d=this[a]>>(c-=8)&255,c<=0&&(c+=this.DB,--a)),(d&128)!=0&&(d|=-256),e==0&&(this.s&128)!=(d&128)&&++e,e>0||d!=this.s)b[e++]=d}return b}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}function bnpBitwiseTo(a,b,c){var d,e,g=Math.min(a.t,this.t);for(d=0;d<g;++d)c[d]=b(this[d],a[d]);if(a.t<this.t){e=a.s&this.DM;for(d=g;d<this.t;++d)c[d]=b(this[d],e);c.t=this.t}else{e=this.s&this.DM;for(d=g;d<a.t;++d)c[d]=b(e,a[d]);c.t=a.t}c.s=b(this.s,a.s);c.clamp()}function op_and(a,b){return a&b}function bnAnd(a){var b=nbi();this.bitwiseTo(a,op_and,b);return b}function op_or(a,b){return a|b}
|
||||
function bnOr(a){var b=nbi();this.bitwiseTo(a,op_or,b);return b}function op_xor(a,b){return a^b}function bnXor(a){var b=nbi();this.bitwiseTo(a,op_xor,b);return b}function op_andnot(a,b){return a&~b}function bnAndNot(a){var b=nbi();this.bitwiseTo(a,op_andnot,b);return b}function bnNot(){for(var a=nbi(),b=0;b<this.t;++b)a[b]=this.DM&~this[b];a.t=this.t;a.s=~this.s;return a}function bnShiftLeft(a){var b=nbi();a<0?this.rShiftTo(-a,b):this.lShiftTo(a,b);return b}
|
||||
function bnShiftRight(a){var b=nbi();a<0?this.lShiftTo(-a,b):this.rShiftTo(a,b);return b}function lbit(a){if(a==0)return-1;var b=0;(a&65535)==0&&(a>>=16,b+=16);(a&255)==0&&(a>>=8,b+=8);(a&15)==0&&(a>>=4,b+=4);(a&3)==0&&(a>>=2,b+=2);(a&1)==0&&++b;return b}function bnGetLowestSetBit(){for(var a=0;a<this.t;++a)if(this[a]!=0)return a*this.DB+lbit(this[a]);return this.s<0?this.t*this.DB:-1}function cbit(a){for(var b=0;a!=0;)a&=a-1,++b;return b}
|
||||
function bnBitCount(){for(var a=0,b=this.s&this.DM,c=0;c<this.t;++c)a+=cbit(this[c]^b);return a}function bnTestBit(a){var b=Math.floor(a/this.DB);return b>=this.t?this.s!=0:(this[b]&1<<a%this.DB)!=0}function bnpChangeBit(a,b){var c=BigInteger.ONE.shiftLeft(a);this.bitwiseTo(c,b,c);return c}function bnSetBit(a){return this.changeBit(a,op_or)}function bnClearBit(a){return this.changeBit(a,op_andnot)}function bnFlipBit(a){return this.changeBit(a,op_xor)}
|
||||
function bnpAddTo(a,b){for(var c=0,d=0,e=Math.min(a.t,this.t);c<e;)d+=this[c]+a[c],b[c++]=d&this.DM,d>>=this.DB;if(a.t<this.t){for(d+=a.s;c<this.t;)d+=this[c],b[c++]=d&this.DM,d>>=this.DB;d+=this.s}else{for(d+=this.s;c<a.t;)d+=a[c],b[c++]=d&this.DM,d>>=this.DB;d+=a.s}b.s=d<0?-1:0;d>0?b[c++]=d:d<-1&&(b[c++]=this.DV+d);b.t=c;b.clamp()}function bnAdd(a){var b=nbi();this.addTo(a,b);return b}function bnSubtract(a){var b=nbi();this.subTo(a,b);return b}
|
||||
function bnMultiply(a){var b=nbi();this.multiplyTo(a,b);return b}function bnSquare(){var a=nbi();this.squareTo(a);return a}function bnDivide(a){var b=nbi();this.divRemTo(a,b,null);return b}function bnRemainder(a){var b=nbi();this.divRemTo(a,null,b);return b}function bnDivideAndRemainder(a){var b=nbi(),c=nbi();this.divRemTo(a,b,c);return[b,c]}function bnpDMultiply(a){this[this.t]=this.am(0,a-1,this,0,0,this.t);++this.t;this.clamp()}
|
||||
function bnpDAddOffset(a,b){if(a!=0){for(;this.t<=b;)this[this.t++]=0;for(this[b]+=a;this[b]>=this.DV;)this[b]-=this.DV,++b>=this.t&&(this[this.t++]=0),++this[b]}}function NullExp(){}function nNop(a){return a}function nMulTo(a,b,c){a.multiplyTo(b,c)}function nSqrTo(a,b){a.squareTo(b)}NullExp.prototype.convert=nNop;NullExp.prototype.revert=nNop;NullExp.prototype.mulTo=nMulTo;NullExp.prototype.sqrTo=nSqrTo;function bnPow(a){return this.exp(a,new NullExp)}
|
||||
function bnpMultiplyLowerTo(a,b,c){var d=Math.min(this.t+a.t,b);c.s=0;for(c.t=d;d>0;)c[--d]=0;var e;for(e=c.t-this.t;d<e;++d)c[d+this.t]=this.am(0,a[d],c,d,0,this.t);for(e=Math.min(a.t,b);d<e;++d)this.am(0,a[d],c,d,0,b-d);c.clamp()}function bnpMultiplyUpperTo(a,b,c){--b;var d=c.t=this.t+a.t-b;for(c.s=0;--d>=0;)c[d]=0;for(d=Math.max(b-this.t,0);d<a.t;++d)c[this.t+d-b]=this.am(b-d,a[d],c,0,0,this.t+d-b);c.clamp();c.drShiftTo(1,c)}
|
||||
function Barrett(a){this.r2=nbi();this.q3=nbi();BigInteger.ONE.dlShiftTo(2*a.t,this.r2);this.mu=this.r2.divide(a);this.m=a}function barrettConvert(a){if(a.s<0||a.t>2*this.m.t)return a.mod(this.m);else if(a.compareTo(this.m)<0)return a;else{var b=nbi();a.copyTo(b);this.reduce(b);return b}}function barrettRevert(a){return a}
|
||||
function barrettReduce(a){a.drShiftTo(this.m.t-1,this.r2);if(a.t>this.m.t+1)a.t=this.m.t+1,a.clamp();this.mu.multiplyUpperTo(this.r2,this.m.t+1,this.q3);for(this.m.multiplyLowerTo(this.q3,this.m.t+1,this.r2);a.compareTo(this.r2)<0;)a.dAddOffset(1,this.m.t+1);for(a.subTo(this.r2,a);a.compareTo(this.m)>=0;)a.subTo(this.m,a)}function barrettSqrTo(a,b){a.squareTo(b);this.reduce(b)}function barrettMulTo(a,b,c){a.multiplyTo(b,c);this.reduce(c)}Barrett.prototype.convert=barrettConvert;
|
||||
Barrett.prototype.revert=barrettRevert;Barrett.prototype.reduce=barrettReduce;Barrett.prototype.mulTo=barrettMulTo;Barrett.prototype.sqrTo=barrettSqrTo;
|
||||
function bnModPow(a,b){var c=a.bitLength(),d,e=nbv(1),g;if(c<=0)return e;else d=c<18?1:c<48?3:c<144?4:c<768?5:6;g=c<8?new Classic(b):b.isEven()?new Barrett(b):new Montgomery(b);var h=[],f=3,o=d-1,p=(1<<d)-1;h[1]=g.convert(this);if(d>1){c=nbi();for(g.sqrTo(h[1],c);f<=p;)h[f]=nbi(),g.mulTo(c,h[f-2],h[f]),f+=2}for(var q=a.t-1,n,k=!0,j=nbi(),c=nbits(a[q])-1;q>=0;){c>=o?n=a[q]>>c-o&p:(n=(a[q]&(1<<c+1)-1)<<o-c,q>0&&(n|=a[q-1]>>this.DB+c-o));for(f=d;(n&1)==0;)n>>=1,--f;if((c-=f)<0)c+=this.DB,--q;if(k)h[n].copyTo(e),
|
||||
k=!1;else{for(;f>1;)g.sqrTo(e,j),g.sqrTo(j,e),f-=2;f>0?g.sqrTo(e,j):(f=e,e=j,j=f);g.mulTo(j,h[n],e)}for(;q>=0&&(a[q]&1<<c)==0;)g.sqrTo(e,j),f=e,e=j,j=f,--c<0&&(c=this.DB-1,--q)}return g.revert(e)}
|
||||
function bnGCD(a){var b=this.s<0?this.negate():this.clone(),a=a.s<0?a.negate():a.clone();if(b.compareTo(a)<0)var c=b,b=a,a=c;var c=b.getLowestSetBit(),d=a.getLowestSetBit();if(d<0)return b;c<d&&(d=c);d>0&&(b.rShiftTo(d,b),a.rShiftTo(d,a));for(;b.signum()>0;)(c=b.getLowestSetBit())>0&&b.rShiftTo(c,b),(c=a.getLowestSetBit())>0&&a.rShiftTo(c,a),b.compareTo(a)>=0?(b.subTo(a,b),b.rShiftTo(1,b)):(a.subTo(b,a),a.rShiftTo(1,a));d>0&&a.lShiftTo(d,a);return a}
|
||||
function bnpModInt(a){if(a<=0)return 0;var b=this.DV%a,c=this.s<0?a-1:0;if(this.t>0)if(b==0)c=this[0]%a;else for(var d=this.t-1;d>=0;--d)c=(b*c+this[d])%a;return c}
|
||||
function bnModInverse(a){var b=a.isEven();if(this.isEven()&&b||a.signum()==0)return BigInteger.ZERO;for(var c=a.clone(),d=this.clone(),e=nbv(1),g=nbv(0),h=nbv(0),f=nbv(1);c.signum()!=0;){for(;c.isEven();){c.rShiftTo(1,c);if(b){if(!e.isEven()||!g.isEven())e.addTo(this,e),g.subTo(a,g);e.rShiftTo(1,e)}else g.isEven()||g.subTo(a,g);g.rShiftTo(1,g)}for(;d.isEven();){d.rShiftTo(1,d);if(b){if(!h.isEven()||!f.isEven())h.addTo(this,h),f.subTo(a,f);h.rShiftTo(1,h)}else f.isEven()||f.subTo(a,f);f.rShiftTo(1,
|
||||
f)}c.compareTo(d)>=0?(c.subTo(d,c),b&&e.subTo(h,e),g.subTo(f,g)):(d.subTo(c,d),b&&h.subTo(e,h),f.subTo(g,f))}if(d.compareTo(BigInteger.ONE)!=0)return BigInteger.ZERO;if(f.compareTo(a)>=0)return f.subtract(a);if(f.signum()<0)f.addTo(a,f);else return f;return f.signum()<0?f.add(a):f}
|
||||
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],lplim=67108864/lowprimes[lowprimes.length-1];
|
||||
function bnIsProbablePrime(a){var b,c=this.abs();if(c.t==1&&c[0]<=lowprimes[lowprimes.length-1]){for(b=0;b<lowprimes.length;++b)if(c[0]==lowprimes[b])return!0;return!1}if(c.isEven())return!1;for(b=1;b<lowprimes.length;){for(var d=lowprimes[b],e=b+1;e<lowprimes.length&&d<lplim;)d*=lowprimes[e++];for(d=c.modInt(d);b<e;)if(d%lowprimes[b++]==0)return!1}return c.millerRabin(a)}
|
||||
function bnpMillerRabin(a){var b=this.subtract(BigInteger.ONE),c=b.getLowestSetBit();if(c<=0)return!1;var d=b.shiftRight(c),a=a+1>>1;if(a>lowprimes.length)a=lowprimes.length;for(var e=nbi(),g=0;g<a;++g){e.fromInt(lowprimes[Math.floor(Math.random()*lowprimes.length)]);var h=e.modPow(d,this);if(h.compareTo(BigInteger.ONE)!=0&&h.compareTo(b)!=0){for(var f=1;f++<c&&h.compareTo(b)!=0;)if(h=h.modPowInt(2,this),h.compareTo(BigInteger.ONE)==0)return!1;if(h.compareTo(b)!=0)return!1}}return!0}
|
||||
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;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;BigInteger.prototype.square=bnSquare;
|
||||
(function(a,b,c,d,e,g,h){function f(a){var b,d,e=this,g=a.length,f=0,h=e.i=e.j=e.m=0;e.S=[];e.c=[];for(g||(a=[g++]);f<c;)e.S[f]=f++;for(f=0;f<c;f++)b=e.S[f],h=h+b+a[f%g]&c-1,d=e.S[h],e.S[f]=d,e.S[h]=b;e.g=function(a){var b=e.S,d=e.i+1&c-1,g=b[d],f=e.j+g&c-1,h=b[f];b[d]=h;b[f]=g;for(var k=b[g+h&c-1];--a;)d=d+1&c-1,g=b[d],f=f+g&c-1,h=b[f],b[d]=h,b[f]=g,k=k*c+b[g+h&c-1];e.i=d;e.j=f;return k};e.g(c)}function o(a,b,c,d,e){c=[];e=typeof a;if(b&&e=="object")for(d in a)if(d.indexOf("S")<5)try{c.push(o(a[d],
|
||||
b-1))}catch(g){}return c.length?c:a+(e!="string"?"\x00":"")}function p(a,b,d,e){a+="";for(e=d=0;e<a.length;e++){var g=b,f=e&c-1,h=(d^=b[e&c-1]*19)+a.charCodeAt(e);g[f]=h&c-1}a="";for(e in b)a+=String.fromCharCode(b[e]);return a}b.seedrandom=function(q,n){var k=[],j,q=p(o(n?[q,a]:arguments.length?q:[(new Date).getTime(),a,window],3),k);j=new f(k);p(j.S,a);b.random=function(){for(var a=j.g(d),b=h,f=0;a<e;)a=(a+f)*c,b*=c,f=j.g(1);for(;a>=g;)a/=2,b/=2,f>>>=1;return(a+f)/b};return q};h=b.pow(c,d);e=b.pow(2,
|
||||
e);g=e*2;p(b.random(),a)})([],Math,256,6,52);function SeededRandom(){}function SRnextBytes(a){var b;for(b=0;b<a.length;b++)a[b]=Math.floor(Math.random()*256)}SeededRandom.prototype.nextBytes=SRnextBytes;function Arcfour(){this.j=this.i=0;this.S=[]}function ARC4init(a){var b,c,d;for(b=0;b<256;++b)this.S[b]=b;for(b=c=0;b<256;++b)c=c+this.S[b]+a[b%a.length]&255,d=this.S[b],this.S[b]=this.S[c],this.S[c]=d;this.j=this.i=0}
|
||||
function ARC4next(){var a;this.i=this.i+1&255;this.j=this.j+this.S[this.i]&255;a=this.S[this.i];this.S[this.i]=this.S[this.j];this.S[this.j]=a;return this.S[a+this.S[this.i]&255]}Arcfour.prototype.init=ARC4init;Arcfour.prototype.next=ARC4next;function prng_newstate(){return new Arcfour}var rng_psize=256,rng_state,rng_pool,rng_pptr;
|
||||
function rng_seed_int(a){rng_pool[rng_pptr++]^=a&255;rng_pool[rng_pptr++]^=a>>8&255;rng_pool[rng_pptr++]^=a>>16&255;rng_pool[rng_pptr++]^=a>>24&255;rng_pptr>=rng_psize&&(rng_pptr-=rng_psize)}function rng_seed_time(){rng_seed_int((new Date).getTime())}
|
||||
if(rng_pool==null){rng_pool=[];rng_pptr=0;var t;if(navigator.appName=="Netscape"&&navigator.appVersion<"5"&&window.crypto){var z=window.crypto.random(32);for(t=0;t<z.length;++t)rng_pool[rng_pptr++]=z.charCodeAt(t)&255}for(;rng_pptr<rng_psize;)t=Math.floor(65536*Math.random()),rng_pool[rng_pptr++]=t>>>8,rng_pool[rng_pptr++]=t&255;rng_pptr=0;rng_seed_time()}
|
||||
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}return rng_state.next()}function rng_get_bytes(a){var b;for(b=0;b<a.length;++b)a[b]=rng_get_byte()}function SecureRandom(){}SecureRandom.prototype.nextBytes=rng_get_bytes;
|
||||
function SHA256(a){function b(a,b){var c=(a&65535)+(b&65535);return(a>>16)+(b>>16)+(c>>16)<<16|c&65535}function c(a,b){return a>>>b|a<<32-b}a=function(a){for(var a=a.replace(/\r\n/g,"\n"),b="",c=0;c<a.length;c++){var h=a.charCodeAt(c);h<128?b+=String.fromCharCode(h):(h>127&&h<2048?b+=String.fromCharCode(h>>6|192):(b+=String.fromCharCode(h>>12|224),b+=String.fromCharCode(h>>6&63|128)),b+=String.fromCharCode(h&63|128))}return b}(a);return function(a){for(var b="",c=0;c<a.length*4;c++)b+="0123456789abcdef".charAt(a[c>>
|
||||
2]>>(3-c%4)*8+4&15)+"0123456789abcdef".charAt(a[c>>2]>>(3-c%4)*8&15);return b}(function(a,e){var g=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,
|
||||
2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298],h=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225],f=Array(64),o,p,q,n,k,j,l,m,s,r,u,w;a[e>>5]|=128<<24-e%32;a[(e+64>>9<<4)+15]=e;for(s=0;s<a.length;s+=16){o=h[0];p=h[1];q=h[2];n=h[3];
|
||||
k=h[4];j=h[5];l=h[6];m=h[7];for(r=0;r<64;r++)f[r]=r<16?a[r+s]:b(b(b(c(f[r-2],17)^c(f[r-2],19)^f[r-2]>>>10,f[r-7]),c(f[r-15],7)^c(f[r-15],18)^f[r-15]>>>3),f[r-16]),u=b(b(b(b(m,c(k,6)^c(k,11)^c(k,25)),k&j^~k&l),g[r]),f[r]),w=b(c(o,2)^c(o,13)^c(o,22),o&p^o&q^p&q),m=l,l=j,j=k,k=b(n,u),n=q,q=p,p=o,o=b(u,w);h[0]=b(o,h[0]);h[1]=b(p,h[1]);h[2]=b(q,h[2]);h[3]=b(n,h[3]);h[4]=b(k,h[4]);h[5]=b(j,h[5]);h[6]=b(l,h[6]);h[7]=b(m,h[7])}return h}(function(a){for(var b=[],c=0;c<a.length*8;c+=8)b[c>>5]|=(a.charCodeAt(c/
|
||||
8)&255)<<24-c%32;return b}(a),a.length*8))}var sha256={hex:function(a){return SHA256(a)}};
|
||||
function SHA1(a){function b(a,b){return a<<b|a>>>32-b}function c(a){var b="",c,d;for(c=7;c>=0;c--)d=a>>>c*4&15,b+=d.toString(16);return b}var d,e,g=Array(80),h=1732584193,f=4023233417,o=2562383102,p=271733878,q=3285377520,n,k,j,l,m,a=function(a){for(var a=a.replace(/\r\n/g,"\n"),b="",c=0;c<a.length;c++){var d=a.charCodeAt(c);d<128?b+=String.fromCharCode(d):(d>127&&d<2048?b+=String.fromCharCode(d>>6|192):(b+=String.fromCharCode(d>>12|224),b+=String.fromCharCode(d>>6&63|128)),b+=String.fromCharCode(d&
|
||||
63|128))}return b}(a);n=a.length;var s=[];for(d=0;d<n-3;d+=4)e=a.charCodeAt(d)<<24|a.charCodeAt(d+1)<<16|a.charCodeAt(d+2)<<8|a.charCodeAt(d+3),s.push(e);switch(n%4){case 0:d=2147483648;break;case 1:d=a.charCodeAt(n-1)<<24|8388608;break;case 2:d=a.charCodeAt(n-2)<<24|a.charCodeAt(n-1)<<16|32768;break;case 3:d=a.charCodeAt(n-3)<<24|a.charCodeAt(n-2)<<16|a.charCodeAt(n-1)<<8|128}for(s.push(d);s.length%16!=14;)s.push(0);s.push(n>>>29);s.push(n<<3&4294967295);for(a=0;a<s.length;a+=16){for(d=0;d<16;d++)g[d]=
|
||||
s[a+d];for(d=16;d<=79;d++)g[d]=b(g[d-3]^g[d-8]^g[d-14]^g[d-16],1);e=h;n=f;k=o;j=p;l=q;for(d=0;d<=19;d++)m=b(e,5)+(n&k|~n&j)+l+g[d]+1518500249&4294967295,l=j,j=k,k=b(n,30),n=e,e=m;for(d=20;d<=39;d++)m=b(e,5)+(n^k^j)+l+g[d]+1859775393&4294967295,l=j,j=k,k=b(n,30),n=e,e=m;for(d=40;d<=59;d++)m=b(e,5)+(n&k|n&j|k&j)+l+g[d]+2400959708&4294967295,l=j,j=k,k=b(n,30),n=e,e=m;for(d=60;d<=79;d++)m=b(e,5)+(n^k^j)+l+g[d]+3395469782&4294967295,l=j,j=k,k=b(n,30),n=e,e=m;h=h+e&4294967295;f=f+n&4294967295;o=o+k&4294967295;
|
||||
p=p+j&4294967295;q=q+l&4294967295}m=c(h)+c(f)+c(o)+c(p)+c(q);return m.toLowerCase()}
|
||||
var sha1={hex:function(a){return SHA1(a)}},MD5=function(a){function b(a,b){var c,d,e,f,g;e=a&2147483648;f=b&2147483648;c=a&1073741824;d=b&1073741824;g=(a&1073741823)+(b&1073741823);return c&d?g^2147483648^e^f:c|d?g&1073741824?g^3221225472^e^f:g^1073741824^e^f:g^e^f}function c(a,c,d,e,f,g,h){a=b(a,b(b(c&d|~c&e,f),h));return b(a<<g|a>>>32-g,c)}function d(a,c,d,e,f,g,h){a=b(a,b(b(c&e|d&~e,f),h));return b(a<<g|a>>>32-g,c)}function e(a,c,d,e,f,g,h){a=b(a,b(b(c^d^e,f),h));return b(a<<g|a>>>32-g,c)}function g(a,
|
||||
c,d,e,f,g,h){a=b(a,b(b(d^(c|~e),f),h));return b(a<<g|a>>>32-g,c)}function h(a){var b="",c="",d;for(d=0;d<=3;d++)c=a>>>d*8&255,c="0"+c.toString(16),b+=c.substr(c.length-2,2);return b}var f=[],o,p,q,n,k,j,l,m,a=function(a){for(var a=a.replace(/\r\n/g,"\n"),b="",c=0;c<a.length;c++){var d=a.charCodeAt(c);d<128?b+=String.fromCharCode(d):(d>127&&d<2048?b+=String.fromCharCode(d>>6|192):(b+=String.fromCharCode(d>>12|224),b+=String.fromCharCode(d>>6&63|128)),b+=String.fromCharCode(d&63|128))}return b}(a),
|
||||
f=function(a){var b,c=a.length;b=c+8;for(var d=((b-b%64)/64+1)*16,e=Array(d-1),f=0,g=0;g<c;)b=(g-g%4)/4,f=g%4*8,e[b]|=a.charCodeAt(g)<<f,g++;e[(g-g%4)/4]|=128<<g%4*8;e[d-2]=c<<3;e[d-1]=c>>>29;return e}(a);k=1732584193;j=4023233417;l=2562383102;m=271733878;for(a=0;a<f.length;a+=16)o=k,p=j,q=l,n=m,k=c(k,j,l,m,f[a+0],7,3614090360),m=c(m,k,j,l,f[a+1],12,3905402710),l=c(l,m,k,j,f[a+2],17,606105819),j=c(j,l,m,k,f[a+3],22,3250441966),k=c(k,j,l,m,f[a+4],7,4118548399),m=c(m,k,j,l,f[a+5],12,1200080426),l=c(l,
|
||||
m,k,j,f[a+6],17,2821735955),j=c(j,l,m,k,f[a+7],22,4249261313),k=c(k,j,l,m,f[a+8],7,1770035416),m=c(m,k,j,l,f[a+9],12,2336552879),l=c(l,m,k,j,f[a+10],17,4294925233),j=c(j,l,m,k,f[a+11],22,2304563134),k=c(k,j,l,m,f[a+12],7,1804603682),m=c(m,k,j,l,f[a+13],12,4254626195),l=c(l,m,k,j,f[a+14],17,2792965006),j=c(j,l,m,k,f[a+15],22,1236535329),k=d(k,j,l,m,f[a+1],5,4129170786),m=d(m,k,j,l,f[a+6],9,3225465664),l=d(l,m,k,j,f[a+11],14,643717713),j=d(j,l,m,k,f[a+0],20,3921069994),k=d(k,j,l,m,f[a+5],5,3593408605),
|
||||
m=d(m,k,j,l,f[a+10],9,38016083),l=d(l,m,k,j,f[a+15],14,3634488961),j=d(j,l,m,k,f[a+4],20,3889429448),k=d(k,j,l,m,f[a+9],5,568446438),m=d(m,k,j,l,f[a+14],9,3275163606),l=d(l,m,k,j,f[a+3],14,4107603335),j=d(j,l,m,k,f[a+8],20,1163531501),k=d(k,j,l,m,f[a+13],5,2850285829),m=d(m,k,j,l,f[a+2],9,4243563512),l=d(l,m,k,j,f[a+7],14,1735328473),j=d(j,l,m,k,f[a+12],20,2368359562),k=e(k,j,l,m,f[a+5],4,4294588738),m=e(m,k,j,l,f[a+8],11,2272392833),l=e(l,m,k,j,f[a+11],16,1839030562),j=e(j,l,m,k,f[a+14],23,4259657740),
|
||||
k=e(k,j,l,m,f[a+1],4,2763975236),m=e(m,k,j,l,f[a+4],11,1272893353),l=e(l,m,k,j,f[a+7],16,4139469664),j=e(j,l,m,k,f[a+10],23,3200236656),k=e(k,j,l,m,f[a+13],4,681279174),m=e(m,k,j,l,f[a+0],11,3936430074),l=e(l,m,k,j,f[a+3],16,3572445317),j=e(j,l,m,k,f[a+6],23,76029189),k=e(k,j,l,m,f[a+9],4,3654602809),m=e(m,k,j,l,f[a+12],11,3873151461),l=e(l,m,k,j,f[a+15],16,530742520),j=e(j,l,m,k,f[a+2],23,3299628645),k=g(k,j,l,m,f[a+0],6,4096336452),m=g(m,k,j,l,f[a+7],10,1126891415),l=g(l,m,k,j,f[a+14],15,2878612391),
|
||||
j=g(j,l,m,k,f[a+5],21,4237533241),k=g(k,j,l,m,f[a+12],6,1700485571),m=g(m,k,j,l,f[a+3],10,2399980690),l=g(l,m,k,j,f[a+10],15,4293915773),j=g(j,l,m,k,f[a+1],21,2240044497),k=g(k,j,l,m,f[a+8],6,1873313359),m=g(m,k,j,l,f[a+15],10,4264355552),l=g(l,m,k,j,f[a+6],15,2734768916),j=g(j,l,m,k,f[a+13],21,1309151649),k=g(k,j,l,m,f[a+4],6,4149444226),m=g(m,k,j,l,f[a+11],10,3174756917),l=g(l,m,k,j,f[a+2],15,718787259),j=g(j,l,m,k,f[a+9],21,3951481745),k=b(k,o),j=b(j,p),l=b(l,q),m=b(m,n);return(h(k)+h(j)+h(l)+
|
||||
h(m)).toLowerCase()};function parseBigInt(a,b){return new BigInteger(a,b)}function linebrk(a,b){for(var c="",d=0;d+b<a.length;)c+=a.substring(d,d+b)+"\n",d+=b;return c+a.substring(d,a.length)}function byte2Hex(a){return a<16?"0"+a.toString(16):a.toString(16)}
|
||||
function pkcs1pad2(a,b){if(b<a.length+11)throw"Message too long for RSA (n="+b+", l="+a.length+")";for(var c=[],d=a.length-1;d>=0&&b>0;){var e=a.charCodeAt(d--);e<128?c[--b]=e:e>127&&e<2048?(c[--b]=e&63|128,c[--b]=e>>6|192):(c[--b]=e&63|128,c[--b]=e>>6&63|128,c[--b]=e>>12|224)}c[--b]=0;d=new SecureRandom;for(e=[];b>2;){for(e[0]=0;e[0]==0;)d.nextBytes(e);c[--b]=e[0]}c[--b]=2;c[--b]=0;return new BigInteger(c)}
|
||||
function RSAKey(){this.n=null;this.e=0;this.coeff=this.dmq1=this.dmp1=this.q=this.p=this.d=null}function RSASetPublic(a,b){a!=null&&b!=null&&a.length>0&&b.length>0?(this.n=parseBigInt(a,16),this.e=parseInt(b,16)):alert("Invalid RSA public key")}function RSADoPublic(a){return a.modPowInt(this.e,this.n)}function RSAEncrypt(a){a=pkcs1pad2(a,this.n.bitLength()+7>>3);if(a==null)return null;a=this.doPublic(a);if(a==null)return null;a=a.toString(16);return(a.length&1)==0?a:"0"+a}
|
||||
RSAKey.prototype.doPublic=RSADoPublic;RSAKey.prototype.setPublic=RSASetPublic;RSAKey.prototype.encrypt=RSAEncrypt;function pkcs1unpad2(a,b){for(var c=a.toByteArray(),d=0;d<c.length&&c[d]==0;)++d;if(c.length-d!=b-1||c[d]!=2)return null;for(++d;c[d]!=0;)if(++d>=c.length)return null;for(var e="";++d<c.length;){var g=c[d]&255;g<128?e+=String.fromCharCode(g):g>191&&g<224?(e+=String.fromCharCode((g&31)<<6|c[d+1]&63),++d):(e+=String.fromCharCode((g&15)<<12|(c[d+1]&63)<<6|c[d+2]&63),d+=2)}return e}
|
||||
function RSASetPrivate(a,b,c){a!=null&&b!=null&&a.length>0&&b.length>0?(this.n=parseBigInt(a,16),this.e=parseInt(b,16),this.d=parseBigInt(c,16)):alert("Invalid RSA private key")}
|
||||
function RSASetPrivateEx(a,b,c,d,e,g,h,f){a!=null&&b!=null&&a.length>0&&b.length>0?(this.n=parseBigInt(a,16),this.e=parseInt(b,16),this.d=parseBigInt(c,16),this.p=parseBigInt(d,16),this.q=parseBigInt(e,16),this.dmp1=parseBigInt(g,16),this.dmq1=parseBigInt(h,16),this.coeff=parseBigInt(f,16)):alert("Invalid RSA private key")}
|
||||
function RSAGenerate(a,b){var c=new SeededRandom,d=a>>1;this.e=parseInt(b,16);for(var e=new BigInteger(b,16);;){for(;;)if(this.p=new BigInteger(a-d,1,c),this.p.subtract(BigInteger.ONE).gcd(e).compareTo(BigInteger.ONE)==0&&this.p.isProbablePrime(10))break;for(;;)if(this.q=new BigInteger(d,1,c),this.q.subtract(BigInteger.ONE).gcd(e).compareTo(BigInteger.ONE)==0&&this.q.isProbablePrime(10))break;if(this.p.compareTo(this.q)<=0){var g=this.p;this.p=this.q;this.q=g}var g=this.p.subtract(BigInteger.ONE),
|
||||
h=this.q.subtract(BigInteger.ONE),f=g.multiply(h);if(f.gcd(e).compareTo(BigInteger.ONE)==0){this.n=this.p.multiply(this.q);this.d=e.modInverse(f);this.dmp1=this.d.mod(g);this.dmq1=this.d.mod(h);this.coeff=this.q.modInverse(this.p);break}}}
|
||||
function RSADoPrivate(a){if(this.p==null||this.q==null)return a.modPow(this.d,this.n);for(var b=a.mod(this.p).modPow(this.dmp1,this.p),a=a.mod(this.q).modPow(this.dmq1,this.q);b.compareTo(a)<0;)b=b.add(this.p);return b.subtract(a).multiply(this.coeff).mod(this.p).multiply(this.q).add(a)}function RSADecrypt(a){a=this.doPrivate(parseBigInt(a,16));return a==null?null:pkcs1unpad2(a,this.n.bitLength()+7>>3)}RSAKey.prototype.doPrivate=RSADoPrivate;RSAKey.prototype.setPrivate=RSASetPrivate;
|
||||
RSAKey.prototype.setPrivateEx=RSASetPrivateEx;RSAKey.prototype.generate=RSAGenerate;RSAKey.prototype.decrypt=RSADecrypt;var _RSASIGN_DIHEAD=[];_RSASIGN_DIHEAD.sha1="3021300906052b0e03021a05000414";_RSASIGN_DIHEAD.sha256="3031300d060960864801650304020105000420";var _RSASIGN_HASHHEXFUNC=[];_RSASIGN_HASHHEXFUNC.sha1=sha1.hex;_RSASIGN_HASHHEXFUNC.sha256=sha256.hex;
|
||||
function _rsasign_getHexPaddedDigestInfoForString(a,b,c){b/=4;for(var a=(0,_RSASIGN_HASHHEXFUNC[c])(a),c="00"+_RSASIGN_DIHEAD[c]+a,a="",b=b-4-c.length,d=0;d<b;d+=2)a+="ff";return sPaddedMessageHex="0001"+a+c}function _rsasign_signString(a,b){var c=_rsasign_getHexPaddedDigestInfoForString(a,this.n.bitLength(),b);return this.doPrivate(parseBigInt(c,16)).toString(16)}
|
||||
function _rsasign_signStringWithSHA1(a){a=_rsasign_getHexPaddedDigestInfoForString(a,this.n.bitLength(),"sha1");return this.doPrivate(parseBigInt(a,16)).toString(16)}function _rsasign_signStringWithSHA256(a){a=_rsasign_getHexPaddedDigestInfoForString(a,this.n.bitLength(),"sha256");return this.doPrivate(parseBigInt(a,16)).toString(16)}function _rsasign_getDecryptSignatureBI(a,b,c){var d=new RSAKey;d.setPublic(b,c);return d.doPublic(a)}
|
||||
function _rsasign_getHexDigestInfoFromSig(a,b,c){return _rsasign_getDecryptSignatureBI(a,b,c).toString(16).replace(/^1f+00/,"")}function _rsasign_getAlgNameAndHashFromHexDisgestInfo(a){for(var b in _RSASIGN_DIHEAD){var c=_RSASIGN_DIHEAD[b],d=c.length;if(a.substring(0,d)==c)return[b,a.substring(d)]}return[]}
|
||||
function _rsasign_verifySignatureWithArgs(a,b,c,d){b=_rsasign_getHexDigestInfoFromSig(b,c,d);c=_rsasign_getAlgNameAndHashFromHexDisgestInfo(b);if(c.length==0)return!1;b=c[1];a=(0,_RSASIGN_HASHHEXFUNC[c[0]])(a);return b==a}function _rsasign_verifyHexSignatureForMessage(a,b){var c=parseBigInt(a,16);return _rsasign_verifySignatureWithArgs(b,c,this.n.toString(16),this.e.toString(16))}
|
||||
function _rsasign_verifyString(a,b){var b=b.replace(/[ \n]+/g,""),c=this.doPublic(parseBigInt(b,16)).toString(16).replace(/^1f+00/,""),d=_rsasign_getAlgNameAndHashFromHexDisgestInfo(c);if(d.length==0)return!1;c=d[1];d=(0,_RSASIGN_HASHHEXFUNC[d[0]])(a);return c==d}RSAKey.prototype.signString=_rsasign_signString;RSAKey.prototype.signStringWithSHA1=_rsasign_signStringWithSHA1;RSAKey.prototype.signStringWithSHA256=_rsasign_signStringWithSHA256;RSAKey.prototype.verifyString=_rsasign_verifyString;
|
||||
RSAKey.prototype.verifyHexSignatureForMessage=_rsasign_verifyHexSignatureForMessage;
|
||||
var aes=function(){var a={Sbox:[99,124,119,123,242,107,111,197,48,1,103,43,254,215,171,118,202,130,201,125,250,89,71,240,173,212,162,175,156,164,114,192,183,253,147,38,54,63,247,204,52,165,229,241,113,216,49,21,4,199,35,195,24,150,5,154,7,18,128,226,235,39,178,117,9,131,44,26,27,110,90,160,82,59,214,179,41,227,47,132,83,209,0,237,32,252,177,91,106,203,190,57,74,76,88,207,208,239,170,251,67,77,51,133,69,249,2,127,80,60,159,168,81,163,64,143,146,157,56,245,188,182,218,33,16,255,243,210,205,12,19,236,
|
||||
95,151,68,23,196,167,126,61,100,93,25,115,96,129,79,220,34,42,144,136,70,238,184,20,222,94,11,219,224,50,58,10,73,6,36,92,194,211,172,98,145,149,228,121,231,200,55,109,141,213,78,169,108,86,244,234,101,122,174,8,186,120,37,46,28,166,180,198,232,221,116,31,75,189,139,138,112,62,181,102,72,3,246,14,97,53,87,185,134,193,29,158,225,248,152,17,105,217,142,148,155,30,135,233,206,85,40,223,140,161,137,13,191,230,66,104,65,153,45,15,176,84,187,22],ShiftRowTab:[0,5,10,15,4,9,14,3,8,13,2,7,12,1,6,11]};a.Init=
|
||||
function(){a.Sbox_Inv=Array(256);for(var b=0;b<256;b++)a.Sbox_Inv[a.Sbox[b]]=b;a.ShiftRowTab_Inv=Array(16);for(b=0;b<16;b++)a.ShiftRowTab_Inv[a.ShiftRowTab[b]]=b;a.xtime=Array(256);for(b=0;b<128;b++)a.xtime[b]=b<<1,a.xtime[128+b]=b<<1^27};a.Done=function(){delete a.Sbox_Inv;delete a.ShiftRowTab_Inv;delete a.xtime};a.ExpandKey=function(b){var c=b.length,d,e=1;switch(c){case 16:d=176;break;case 24:d=208;break;case 32:d=240;break;default:alert("my.ExpandKey: Only key lengths of 16, 24 or 32 bytes allowed!")}for(var g=
|
||||
c;g<d;g+=4){var h=b.slice(g-4,g);if(g%c==0){if(h=[a.Sbox[h[1]]^e,a.Sbox[h[2]],a.Sbox[h[3]],a.Sbox[h[0]]],(e<<=1)>=256)e^=283}else c>24&&g%c==16&&(h=[a.Sbox[h[0]],a.Sbox[h[1]],a.Sbox[h[2]],a.Sbox[h[3]]]);for(var f=0;f<4;f++)b[g+f]=b[g+f-c]^h[f]}};a.Encrypt=function(b,c){var d=c.length;a.AddRoundKey(b,c.slice(0,16));for(var e=16;e<d-16;e+=16)a.SubBytes(b,a.Sbox),a.ShiftRows(b,a.ShiftRowTab),a.MixColumns(b),a.AddRoundKey(b,c.slice(e,e+16));a.SubBytes(b,a.Sbox);a.ShiftRows(b,a.ShiftRowTab);a.AddRoundKey(b,
|
||||
c.slice(e,d))};a.Decrypt=function(b,c){var d=c.length;a.AddRoundKey(b,c.slice(d-16,d));a.ShiftRows(b,a.ShiftRowTab_Inv);a.SubBytes(b,a.Sbox_Inv);for(d-=32;d>=16;d-=16)a.AddRoundKey(b,c.slice(d,d+16)),a.MixColumns_Inv(b),a.ShiftRows(b,a.ShiftRowTab_Inv),a.SubBytes(b,a.Sbox_Inv);a.AddRoundKey(b,c.slice(0,16))};a.SubBytes=function(a,c){for(var d=0;d<16;d++)a[d]=c[a[d]]};a.AddRoundKey=function(a,c){for(var d=0;d<16;d++)a[d]^=c[d]};a.ShiftRows=function(a,c){for(var d=[].concat(a),e=0;e<16;e++)a[e]=d[c[e]]};
|
||||
a.MixColumns=function(b){for(var c=0;c<16;c+=4){var d=b[c+0],e=b[c+1],g=b[c+2],h=b[c+3],f=d^e^g^h;b[c+0]^=f^a.xtime[d^e];b[c+1]^=f^a.xtime[e^g];b[c+2]^=f^a.xtime[g^h];b[c+3]^=f^a.xtime[h^d]}};a.MixColumns_Inv=function(b){for(var c=0;c<16;c+=4){var d=b[c+0],e=b[c+1],g=b[c+2],h=b[c+3],f=d^e^g^h,o=a.xtime[f],p=a.xtime[a.xtime[o^d^g]]^f;f^=a.xtime[a.xtime[o^e^h]];b[c+0]^=p^a.xtime[d^e];b[c+1]^=f^a.xtime[e^g];b[c+2]^=p^a.xtime[g^h];b[c+3]^=f^a.xtime[h^d]}};return a}(),cryptico=function(){var a={};aes.Init();
|
||||
a.b256to64=function(a){var c,d,e,g="",h=0,f=0,o=a.length;for(e=0;e<o;e++)d=a.charCodeAt(e),f==0?(g+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(d>>2&63),c=(d&3)<<4):f==1?(g+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(c|d>>4&15),c=(d&15)<<2):f==2&&(g+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(c|d>>6&3),h+=1,g+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(d&63)),h+=1,f+=1,f==3&&
|
||||
(f=0);f>0&&(g+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(c),g+="=");f==1&&(g+="=");return g};a.b64to256=function(a){var c,d,e="",g=0,h=0,f=a.length;for(d=0;d<f;d++)c="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".indexOf(a.charAt(d)),c>=0&&(g&&(e+=String.fromCharCode(h|c>>6-g&255)),g=g+2&7,h=c<<g&255);return e};a.b16to64=function(a){var c,d,e="";a.length%2==1&&(a="0"+a);for(c=0;c+3<=a.length;c+=3)d=parseInt(a.substring(c,c+3),16),e+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(d>>
|
||||
6)+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(d&63);c+1==a.length?(d=parseInt(a.substring(c,c+1),16),e+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(d<<2)):c+2==a.length&&(d=parseInt(a.substring(c,c+2),16),e+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(d>>2)+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt((d&3)<<4));for(;(e.length&3)>0;)e+="=";return e};a.b64to16=function(a){var c="",
|
||||
d,e=0,g;for(d=0;d<a.length;++d){if(a.charAt(d)=="=")break;v="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".indexOf(a.charAt(d));v<0||(e==0?(c+=int2char(v>>2),g=v&3,e=1):e==1?(c+=int2char(g<<2|v>>4),g=v&15,e=2):e==2?(c+=int2char(g),c+=int2char(v>>2),g=v&3,e=3):(c+=int2char(g<<2|v>>4),c+=int2char(v&15),e=0))}e==1&&(c+=int2char(g<<2));return c};a.string2bytes=function(a){for(var c=[],d=0;d<a.length;d++)c.push(a.charCodeAt(d));return c};a.bytes2string=function(a){for(var c="",d=0;d<
|
||||
a.length;d++)c+=String.fromCharCode(a[d]);return c};a.blockXOR=function(a,c){for(var d=Array(16),e=0;e<16;e++)d[e]=a[e]^c[e];return d};a.blockIV=function(){var a=new SecureRandom,c=Array(16);a.nextBytes(c);return c};a.pad16=function(a){var c=a.slice(0),d=(16-a.length%16)%16;for(i=a.length;i<a.length+d;i++)c.push(0);return c};a.depad=function(a){for(a=a.slice(0);a[a.length-1]==0;)a=a.slice(0,a.length-1);return a};a.encryptAESCBC=function(b,c){var d=c.slice(0);aes.ExpandKey(d);for(var e=a.string2bytes(b),
|
||||
e=a.pad16(e),g=a.blockIV(),h=0;h<e.length/16;h++){var f=e.slice(h*16,h*16+16),o=g.slice(h*16,h*16+16),f=a.blockXOR(o,f);aes.Encrypt(f,d);g=g.concat(f)}d=a.bytes2string(g);return a.b256to64(d)};a.decryptAESCBC=function(b,c){var d=c.slice(0);aes.ExpandKey(d);for(var b=a.b64to256(b),e=a.string2bytes(b),g=[],h=1;h<e.length/16;h++){var f=e.slice(h*16,h*16+16),o=e.slice((h-1)*16,(h-1)*16+16);aes.Decrypt(f,d);f=a.blockXOR(o,f);g=g.concat(f)}g=a.depad(g);return a.bytes2string(g)};a.wrap60=function(a){for(var c=
|
||||
"",d=0;d<a.length;d++)d%60==0&&d!=0&&(c+="\n"),c+=a[d];return c};a.generateAESKey=function(){var a=Array(32);(new SecureRandom).nextBytes(a);return a};a.generateRSAKey=function(a,c){Math.seedrandom(sha256.hex(a));var d=new RSAKey;d.generate(c,"03");return d};a.publicKeyString=function(b){return pubkey=a.b16to64(b.n.toString(16))};a.publicKeyID=function(a){return MD5(a)};a.publicKeyFromString=function(b){var b=a.b64to16(b.split("|")[0]),c=new RSAKey;c.setPublic(b,"03");return c};a.encrypt=function(b,
|
||||
c,d){var e="",g=a.generateAESKey();try{var h=a.publicKeyFromString(c);e+=a.b16to64(h.encrypt(a.bytes2string(g)))+"?"}catch(f){return{status:"Invalid public key"}}d&&(signString=cryptico.b16to64(d.signString(b,"sha256")),b+="::52cee64bb3a38f6403386519a39ac91c::",b+=cryptico.publicKeyString(d),b+="::52cee64bb3a38f6403386519a39ac91c::",b+=signString);e+=a.encryptAESCBC(b,g);return{status:"success",cipher:e}};a.decrypt=function(b,c){var d=b.split("?"),e=c.decrypt(a.b64to16(d[0]));if(e==null)return{status:"failure"};
|
||||
e=a.string2bytes(e);d=a.decryptAESCBC(d[1],e).split("::52cee64bb3a38f6403386519a39ac91c::");if(d.length==3){var e=a.publicKeyFromString(d[1]),g=a.b64to16(d[2]);return e.verifyString(d[0],g)?{status:"success",plaintext:d[0],signature:"verified",publicKeyString:a.publicKeyString(e)}:{status:"success",plaintext:d[0],signature:"forged",publicKeyString:a.publicKeyString(e)}}else return{status:"success",plaintext:d[0],signature:"unsigned"}};return a}();
|
||||
535
vendors/cryptico/hash.js
vendored
Normal file
535
vendors/cryptico/hash.js
vendored
Normal file
|
|
@ -0,0 +1,535 @@
|
|||
|
||||
/**
|
||||
*
|
||||
* Secure Hash Algorithm (SHA256)
|
||||
* http://www.webtoolkit.info/
|
||||
*
|
||||
* Original code by Angel Marin, Paul Johnston.
|
||||
*
|
||||
**/
|
||||
|
||||
function SHA256(s){
|
||||
|
||||
var chrsz = 8;
|
||||
var hexcase = 0;
|
||||
|
||||
function safe_add (x, y) {
|
||||
var lsw = (x & 0xFFFF) + (y & 0xFFFF);
|
||||
var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
|
||||
return (msw << 16) | (lsw & 0xFFFF);
|
||||
}
|
||||
|
||||
function S (X, n) { return ( X >>> n ) | (X << (32 - n)); }
|
||||
function R (X, n) { return ( X >>> n ); }
|
||||
function Ch(x, y, z) { return ((x & y) ^ ((~x) & z)); }
|
||||
function Maj(x, y, z) { return ((x & y) ^ (x & z) ^ (y & z)); }
|
||||
function Sigma0256(x) { return (S(x, 2) ^ S(x, 13) ^ S(x, 22)); }
|
||||
function Sigma1256(x) { return (S(x, 6) ^ S(x, 11) ^ S(x, 25)); }
|
||||
function Gamma0256(x) { return (S(x, 7) ^ S(x, 18) ^ R(x, 3)); }
|
||||
function Gamma1256(x) { return (S(x, 17) ^ S(x, 19) ^ R(x, 10)); }
|
||||
|
||||
function core_sha256 (m, l) {
|
||||
var K = new Array(0x428A2F98, 0x71374491, 0xB5C0FBCF, 0xE9B5DBA5, 0x3956C25B, 0x59F111F1, 0x923F82A4, 0xAB1C5ED5, 0xD807AA98, 0x12835B01, 0x243185BE, 0x550C7DC3, 0x72BE5D74, 0x80DEB1FE, 0x9BDC06A7, 0xC19BF174, 0xE49B69C1, 0xEFBE4786, 0xFC19DC6, 0x240CA1CC, 0x2DE92C6F, 0x4A7484AA, 0x5CB0A9DC, 0x76F988DA, 0x983E5152, 0xA831C66D, 0xB00327C8, 0xBF597FC7, 0xC6E00BF3, 0xD5A79147, 0x6CA6351, 0x14292967, 0x27B70A85, 0x2E1B2138, 0x4D2C6DFC, 0x53380D13, 0x650A7354, 0x766A0ABB, 0x81C2C92E, 0x92722C85, 0xA2BFE8A1, 0xA81A664B, 0xC24B8B70, 0xC76C51A3, 0xD192E819, 0xD6990624, 0xF40E3585, 0x106AA070, 0x19A4C116, 0x1E376C08, 0x2748774C, 0x34B0BCB5, 0x391C0CB3, 0x4ED8AA4A, 0x5B9CCA4F, 0x682E6FF3, 0x748F82EE, 0x78A5636F, 0x84C87814, 0x8CC70208, 0x90BEFFFA, 0xA4506CEB, 0xBEF9A3F7, 0xC67178F2);
|
||||
var HASH = new Array(0x6A09E667, 0xBB67AE85, 0x3C6EF372, 0xA54FF53A, 0x510E527F, 0x9B05688C, 0x1F83D9AB, 0x5BE0CD19);
|
||||
var W = new Array(64);
|
||||
var a, b, c, d, e, f, g, h, i, j;
|
||||
var T1, T2;
|
||||
|
||||
m[l >> 5] |= 0x80 << (24 - l % 32);
|
||||
m[((l + 64 >> 9) << 4) + 15] = l;
|
||||
|
||||
for ( var i = 0; i<m.length; i+=16 ) {
|
||||
a = HASH[0];
|
||||
b = HASH[1];
|
||||
c = HASH[2];
|
||||
d = HASH[3];
|
||||
e = HASH[4];
|
||||
f = HASH[5];
|
||||
g = HASH[6];
|
||||
h = HASH[7];
|
||||
|
||||
for ( var j = 0; j<64; j++) {
|
||||
if (j < 16) W[j] = m[j + i];
|
||||
else W[j] = safe_add(safe_add(safe_add(Gamma1256(W[j - 2]), W[j - 7]), Gamma0256(W[j - 15])), W[j - 16]);
|
||||
|
||||
T1 = safe_add(safe_add(safe_add(safe_add(h, Sigma1256(e)), Ch(e, f, g)), K[j]), W[j]);
|
||||
T2 = safe_add(Sigma0256(a), Maj(a, b, c));
|
||||
|
||||
h = g;
|
||||
g = f;
|
||||
f = e;
|
||||
e = safe_add(d, T1);
|
||||
d = c;
|
||||
c = b;
|
||||
b = a;
|
||||
a = safe_add(T1, T2);
|
||||
}
|
||||
|
||||
HASH[0] = safe_add(a, HASH[0]);
|
||||
HASH[1] = safe_add(b, HASH[1]);
|
||||
HASH[2] = safe_add(c, HASH[2]);
|
||||
HASH[3] = safe_add(d, HASH[3]);
|
||||
HASH[4] = safe_add(e, HASH[4]);
|
||||
HASH[5] = safe_add(f, HASH[5]);
|
||||
HASH[6] = safe_add(g, HASH[6]);
|
||||
HASH[7] = safe_add(h, HASH[7]);
|
||||
}
|
||||
return HASH;
|
||||
}
|
||||
|
||||
function str2binb (str) {
|
||||
var bin = Array();
|
||||
var mask = (1 << chrsz) - 1;
|
||||
for(var i = 0; i < str.length * chrsz; i += chrsz) {
|
||||
bin[i>>5] |= (str.charCodeAt(i / chrsz) & mask) << (24 - i%32);
|
||||
}
|
||||
return bin;
|
||||
}
|
||||
|
||||
function Utf8Encode(string) {
|
||||
string = string.replace(/\r\n/g,"\n");
|
||||
var utftext = "";
|
||||
|
||||
for (var n = 0; n < string.length; n++) {
|
||||
|
||||
var c = string.charCodeAt(n);
|
||||
|
||||
if (c < 128) {
|
||||
utftext += String.fromCharCode(c);
|
||||
}
|
||||
else if((c > 127) && (c < 2048)) {
|
||||
utftext += String.fromCharCode((c >> 6) | 192);
|
||||
utftext += String.fromCharCode((c & 63) | 128);
|
||||
}
|
||||
else {
|
||||
utftext += String.fromCharCode((c >> 12) | 224);
|
||||
utftext += String.fromCharCode(((c >> 6) & 63) | 128);
|
||||
utftext += String.fromCharCode((c & 63) | 128);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return utftext;
|
||||
}
|
||||
|
||||
function binb2hex (binarray) {
|
||||
var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef";
|
||||
var str = "";
|
||||
for(var i = 0; i < binarray.length * 4; i++) {
|
||||
str += hex_tab.charAt((binarray[i>>2] >> ((3 - i%4)*8+4)) & 0xF) +
|
||||
hex_tab.charAt((binarray[i>>2] >> ((3 - i%4)*8 )) & 0xF);
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
s = Utf8Encode(s);
|
||||
return binb2hex(core_sha256(str2binb(s), s.length * chrsz));
|
||||
}
|
||||
|
||||
var sha256 = {}
|
||||
sha256.hex = function(s)
|
||||
{
|
||||
return SHA256(s);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Secure Hash Algorithm (SHA1)
|
||||
* http://www.webtoolkit.info/
|
||||
*
|
||||
**/
|
||||
|
||||
function SHA1 (msg) {
|
||||
|
||||
function rotate_left(n,s) {
|
||||
var t4 = ( n<<s ) | (n>>>(32-s));
|
||||
return t4;
|
||||
};
|
||||
|
||||
function lsb_hex(val) {
|
||||
var str="";
|
||||
var i;
|
||||
var vh;
|
||||
var vl;
|
||||
|
||||
for( i=0; i<=6; i+=2 ) {
|
||||
vh = (val>>>(i*4+4))&0x0f;
|
||||
vl = (val>>>(i*4))&0x0f;
|
||||
str += vh.toString(16) + vl.toString(16);
|
||||
}
|
||||
return str;
|
||||
};
|
||||
|
||||
function cvt_hex(val) {
|
||||
var str="";
|
||||
var i;
|
||||
var v;
|
||||
|
||||
for( i=7; i>=0; i-- ) {
|
||||
v = (val>>>(i*4))&0x0f;
|
||||
str += v.toString(16);
|
||||
}
|
||||
return str;
|
||||
};
|
||||
|
||||
|
||||
function Utf8Encode(string) {
|
||||
string = string.replace(/\r\n/g,"\n");
|
||||
var utftext = "";
|
||||
|
||||
for (var n = 0; n < string.length; n++) {
|
||||
|
||||
var c = string.charCodeAt(n);
|
||||
|
||||
if (c < 128) {
|
||||
utftext += String.fromCharCode(c);
|
||||
}
|
||||
else if((c > 127) && (c < 2048)) {
|
||||
utftext += String.fromCharCode((c >> 6) | 192);
|
||||
utftext += String.fromCharCode((c & 63) | 128);
|
||||
}
|
||||
else {
|
||||
utftext += String.fromCharCode((c >> 12) | 224);
|
||||
utftext += String.fromCharCode(((c >> 6) & 63) | 128);
|
||||
utftext += String.fromCharCode((c & 63) | 128);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return utftext;
|
||||
};
|
||||
|
||||
var blockstart;
|
||||
var i, j;
|
||||
var W = new Array(80);
|
||||
var H0 = 0x67452301;
|
||||
var H1 = 0xEFCDAB89;
|
||||
var H2 = 0x98BADCFE;
|
||||
var H3 = 0x10325476;
|
||||
var H4 = 0xC3D2E1F0;
|
||||
var A, B, C, D, E;
|
||||
var temp;
|
||||
|
||||
msg = Utf8Encode(msg);
|
||||
|
||||
var msg_len = msg.length;
|
||||
|
||||
var word_array = new Array();
|
||||
for( i=0; i<msg_len-3; i+=4 ) {
|
||||
j = msg.charCodeAt(i)<<24 | msg.charCodeAt(i+1)<<16 |
|
||||
msg.charCodeAt(i+2)<<8 | msg.charCodeAt(i+3);
|
||||
word_array.push( j );
|
||||
}
|
||||
|
||||
switch( msg_len % 4 ) {
|
||||
case 0:
|
||||
i = 0x080000000;
|
||||
break;
|
||||
case 1:
|
||||
i = msg.charCodeAt(msg_len-1)<<24 | 0x0800000;
|
||||
break;
|
||||
|
||||
case 2:
|
||||
i = msg.charCodeAt(msg_len-2)<<24 | msg.charCodeAt(msg_len-1)<<16 | 0x08000;
|
||||
break;
|
||||
|
||||
case 3:
|
||||
i = msg.charCodeAt(msg_len-3)<<24 | msg.charCodeAt(msg_len-2)<<16 | msg.charCodeAt(msg_len-1)<<8 | 0x80;
|
||||
break;
|
||||
}
|
||||
|
||||
word_array.push( i );
|
||||
|
||||
while( (word_array.length % 16) != 14 ) word_array.push( 0 );
|
||||
|
||||
word_array.push( msg_len>>>29 );
|
||||
word_array.push( (msg_len<<3)&0x0ffffffff );
|
||||
|
||||
|
||||
for ( blockstart=0; blockstart<word_array.length; blockstart+=16 ) {
|
||||
|
||||
for( i=0; i<16; i++ ) W[i] = word_array[blockstart+i];
|
||||
for( i=16; i<=79; i++ ) W[i] = rotate_left(W[i-3] ^ W[i-8] ^ W[i-14] ^ W[i-16], 1);
|
||||
|
||||
A = H0;
|
||||
B = H1;
|
||||
C = H2;
|
||||
D = H3;
|
||||
E = H4;
|
||||
|
||||
for( i= 0; i<=19; i++ ) {
|
||||
temp = (rotate_left(A,5) + ((B&C) | (~B&D)) + E + W[i] + 0x5A827999) & 0x0ffffffff;
|
||||
E = D;
|
||||
D = C;
|
||||
C = rotate_left(B,30);
|
||||
B = A;
|
||||
A = temp;
|
||||
}
|
||||
|
||||
for( i=20; i<=39; i++ ) {
|
||||
temp = (rotate_left(A,5) + (B ^ C ^ D) + E + W[i] + 0x6ED9EBA1) & 0x0ffffffff;
|
||||
E = D;
|
||||
D = C;
|
||||
C = rotate_left(B,30);
|
||||
B = A;
|
||||
A = temp;
|
||||
}
|
||||
|
||||
for( i=40; i<=59; i++ ) {
|
||||
temp = (rotate_left(A,5) + ((B&C) | (B&D) | (C&D)) + E + W[i] + 0x8F1BBCDC) & 0x0ffffffff;
|
||||
E = D;
|
||||
D = C;
|
||||
C = rotate_left(B,30);
|
||||
B = A;
|
||||
A = temp;
|
||||
}
|
||||
|
||||
for( i=60; i<=79; i++ ) {
|
||||
temp = (rotate_left(A,5) + (B ^ C ^ D) + E + W[i] + 0xCA62C1D6) & 0x0ffffffff;
|
||||
E = D;
|
||||
D = C;
|
||||
C = rotate_left(B,30);
|
||||
B = A;
|
||||
A = temp;
|
||||
}
|
||||
|
||||
H0 = (H0 + A) & 0x0ffffffff;
|
||||
H1 = (H1 + B) & 0x0ffffffff;
|
||||
H2 = (H2 + C) & 0x0ffffffff;
|
||||
H3 = (H3 + D) & 0x0ffffffff;
|
||||
H4 = (H4 + E) & 0x0ffffffff;
|
||||
|
||||
}
|
||||
|
||||
var temp = cvt_hex(H0) + cvt_hex(H1) + cvt_hex(H2) + cvt_hex(H3) + cvt_hex(H4);
|
||||
|
||||
return temp.toLowerCase();
|
||||
|
||||
}
|
||||
|
||||
var sha1 = {}
|
||||
sha1.hex = function(s)
|
||||
{
|
||||
return SHA1(s);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* MD5 (Message-Digest Algorithm)
|
||||
* http://www.webtoolkit.info/
|
||||
*
|
||||
**/
|
||||
|
||||
var MD5 = function (string) {
|
||||
|
||||
function RotateLeft(lValue, iShiftBits) {
|
||||
return (lValue<<iShiftBits) | (lValue>>>(32-iShiftBits));
|
||||
}
|
||||
|
||||
function AddUnsigned(lX,lY) {
|
||||
var lX4,lY4,lX8,lY8,lResult;
|
||||
lX8 = (lX & 0x80000000);
|
||||
lY8 = (lY & 0x80000000);
|
||||
lX4 = (lX & 0x40000000);
|
||||
lY4 = (lY & 0x40000000);
|
||||
lResult = (lX & 0x3FFFFFFF)+(lY & 0x3FFFFFFF);
|
||||
if (lX4 & lY4) {
|
||||
return (lResult ^ 0x80000000 ^ lX8 ^ lY8);
|
||||
}
|
||||
if (lX4 | lY4) {
|
||||
if (lResult & 0x40000000) {
|
||||
return (lResult ^ 0xC0000000 ^ lX8 ^ lY8);
|
||||
} else {
|
||||
return (lResult ^ 0x40000000 ^ lX8 ^ lY8);
|
||||
}
|
||||
} else {
|
||||
return (lResult ^ lX8 ^ lY8);
|
||||
}
|
||||
}
|
||||
|
||||
function F(x,y,z) { return (x & y) | ((~x) & z); }
|
||||
function G(x,y,z) { return (x & z) | (y & (~z)); }
|
||||
function H(x,y,z) { return (x ^ y ^ z); }
|
||||
function I(x,y,z) { return (y ^ (x | (~z))); }
|
||||
|
||||
function FF(a,b,c,d,x,s,ac) {
|
||||
a = AddUnsigned(a, AddUnsigned(AddUnsigned(F(b, c, d), x), ac));
|
||||
return AddUnsigned(RotateLeft(a, s), b);
|
||||
};
|
||||
|
||||
function GG(a,b,c,d,x,s,ac) {
|
||||
a = AddUnsigned(a, AddUnsigned(AddUnsigned(G(b, c, d), x), ac));
|
||||
return AddUnsigned(RotateLeft(a, s), b);
|
||||
};
|
||||
|
||||
function HH(a,b,c,d,x,s,ac) {
|
||||
a = AddUnsigned(a, AddUnsigned(AddUnsigned(H(b, c, d), x), ac));
|
||||
return AddUnsigned(RotateLeft(a, s), b);
|
||||
};
|
||||
|
||||
function II(a,b,c,d,x,s,ac) {
|
||||
a = AddUnsigned(a, AddUnsigned(AddUnsigned(I(b, c, d), x), ac));
|
||||
return AddUnsigned(RotateLeft(a, s), b);
|
||||
};
|
||||
|
||||
function ConvertToWordArray(string) {
|
||||
var lWordCount;
|
||||
var lMessageLength = string.length;
|
||||
var lNumberOfWords_temp1=lMessageLength + 8;
|
||||
var lNumberOfWords_temp2=(lNumberOfWords_temp1-(lNumberOfWords_temp1 % 64))/64;
|
||||
var lNumberOfWords = (lNumberOfWords_temp2+1)*16;
|
||||
var lWordArray=Array(lNumberOfWords-1);
|
||||
var lBytePosition = 0;
|
||||
var lByteCount = 0;
|
||||
while ( lByteCount < lMessageLength ) {
|
||||
lWordCount = (lByteCount-(lByteCount % 4))/4;
|
||||
lBytePosition = (lByteCount % 4)*8;
|
||||
lWordArray[lWordCount] = (lWordArray[lWordCount] | (string.charCodeAt(lByteCount)<<lBytePosition));
|
||||
lByteCount++;
|
||||
}
|
||||
lWordCount = (lByteCount-(lByteCount % 4))/4;
|
||||
lBytePosition = (lByteCount % 4)*8;
|
||||
lWordArray[lWordCount] = lWordArray[lWordCount] | (0x80<<lBytePosition);
|
||||
lWordArray[lNumberOfWords-2] = lMessageLength<<3;
|
||||
lWordArray[lNumberOfWords-1] = lMessageLength>>>29;
|
||||
return lWordArray;
|
||||
};
|
||||
|
||||
function WordToHex(lValue) {
|
||||
var WordToHexValue="",WordToHexValue_temp="",lByte,lCount;
|
||||
for (lCount = 0;lCount<=3;lCount++) {
|
||||
lByte = (lValue>>>(lCount*8)) & 255;
|
||||
WordToHexValue_temp = "0" + lByte.toString(16);
|
||||
WordToHexValue = WordToHexValue + WordToHexValue_temp.substr(WordToHexValue_temp.length-2,2);
|
||||
}
|
||||
return WordToHexValue;
|
||||
};
|
||||
|
||||
function Utf8Encode(string) {
|
||||
string = string.replace(/\r\n/g,"\n");
|
||||
var utftext = "";
|
||||
|
||||
for (var n = 0; n < string.length; n++) {
|
||||
|
||||
var c = string.charCodeAt(n);
|
||||
|
||||
if (c < 128) {
|
||||
utftext += String.fromCharCode(c);
|
||||
}
|
||||
else if((c > 127) && (c < 2048)) {
|
||||
utftext += String.fromCharCode((c >> 6) | 192);
|
||||
utftext += String.fromCharCode((c & 63) | 128);
|
||||
}
|
||||
else {
|
||||
utftext += String.fromCharCode((c >> 12) | 224);
|
||||
utftext += String.fromCharCode(((c >> 6) & 63) | 128);
|
||||
utftext += String.fromCharCode((c & 63) | 128);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return utftext;
|
||||
};
|
||||
|
||||
var x=Array();
|
||||
var k,AA,BB,CC,DD,a,b,c,d;
|
||||
var S11=7, S12=12, S13=17, S14=22;
|
||||
var S21=5, S22=9 , S23=14, S24=20;
|
||||
var S31=4, S32=11, S33=16, S34=23;
|
||||
var S41=6, S42=10, S43=15, S44=21;
|
||||
|
||||
string = Utf8Encode(string);
|
||||
|
||||
x = ConvertToWordArray(string);
|
||||
|
||||
a = 0x67452301; b = 0xEFCDAB89; c = 0x98BADCFE; d = 0x10325476;
|
||||
|
||||
for (k=0;k<x.length;k+=16) {
|
||||
AA=a; BB=b; CC=c; DD=d;
|
||||
a=FF(a,b,c,d,x[k+0], S11,0xD76AA478);
|
||||
d=FF(d,a,b,c,x[k+1], S12,0xE8C7B756);
|
||||
c=FF(c,d,a,b,x[k+2], S13,0x242070DB);
|
||||
b=FF(b,c,d,a,x[k+3], S14,0xC1BDCEEE);
|
||||
a=FF(a,b,c,d,x[k+4], S11,0xF57C0FAF);
|
||||
d=FF(d,a,b,c,x[k+5], S12,0x4787C62A);
|
||||
c=FF(c,d,a,b,x[k+6], S13,0xA8304613);
|
||||
b=FF(b,c,d,a,x[k+7], S14,0xFD469501);
|
||||
a=FF(a,b,c,d,x[k+8], S11,0x698098D8);
|
||||
d=FF(d,a,b,c,x[k+9], S12,0x8B44F7AF);
|
||||
c=FF(c,d,a,b,x[k+10],S13,0xFFFF5BB1);
|
||||
b=FF(b,c,d,a,x[k+11],S14,0x895CD7BE);
|
||||
a=FF(a,b,c,d,x[k+12],S11,0x6B901122);
|
||||
d=FF(d,a,b,c,x[k+13],S12,0xFD987193);
|
||||
c=FF(c,d,a,b,x[k+14],S13,0xA679438E);
|
||||
b=FF(b,c,d,a,x[k+15],S14,0x49B40821);
|
||||
a=GG(a,b,c,d,x[k+1], S21,0xF61E2562);
|
||||
d=GG(d,a,b,c,x[k+6], S22,0xC040B340);
|
||||
c=GG(c,d,a,b,x[k+11],S23,0x265E5A51);
|
||||
b=GG(b,c,d,a,x[k+0], S24,0xE9B6C7AA);
|
||||
a=GG(a,b,c,d,x[k+5], S21,0xD62F105D);
|
||||
d=GG(d,a,b,c,x[k+10],S22,0x2441453);
|
||||
c=GG(c,d,a,b,x[k+15],S23,0xD8A1E681);
|
||||
b=GG(b,c,d,a,x[k+4], S24,0xE7D3FBC8);
|
||||
a=GG(a,b,c,d,x[k+9], S21,0x21E1CDE6);
|
||||
d=GG(d,a,b,c,x[k+14],S22,0xC33707D6);
|
||||
c=GG(c,d,a,b,x[k+3], S23,0xF4D50D87);
|
||||
b=GG(b,c,d,a,x[k+8], S24,0x455A14ED);
|
||||
a=GG(a,b,c,d,x[k+13],S21,0xA9E3E905);
|
||||
d=GG(d,a,b,c,x[k+2], S22,0xFCEFA3F8);
|
||||
c=GG(c,d,a,b,x[k+7], S23,0x676F02D9);
|
||||
b=GG(b,c,d,a,x[k+12],S24,0x8D2A4C8A);
|
||||
a=HH(a,b,c,d,x[k+5], S31,0xFFFA3942);
|
||||
d=HH(d,a,b,c,x[k+8], S32,0x8771F681);
|
||||
c=HH(c,d,a,b,x[k+11],S33,0x6D9D6122);
|
||||
b=HH(b,c,d,a,x[k+14],S34,0xFDE5380C);
|
||||
a=HH(a,b,c,d,x[k+1], S31,0xA4BEEA44);
|
||||
d=HH(d,a,b,c,x[k+4], S32,0x4BDECFA9);
|
||||
c=HH(c,d,a,b,x[k+7], S33,0xF6BB4B60);
|
||||
b=HH(b,c,d,a,x[k+10],S34,0xBEBFBC70);
|
||||
a=HH(a,b,c,d,x[k+13],S31,0x289B7EC6);
|
||||
d=HH(d,a,b,c,x[k+0], S32,0xEAA127FA);
|
||||
c=HH(c,d,a,b,x[k+3], S33,0xD4EF3085);
|
||||
b=HH(b,c,d,a,x[k+6], S34,0x4881D05);
|
||||
a=HH(a,b,c,d,x[k+9], S31,0xD9D4D039);
|
||||
d=HH(d,a,b,c,x[k+12],S32,0xE6DB99E5);
|
||||
c=HH(c,d,a,b,x[k+15],S33,0x1FA27CF8);
|
||||
b=HH(b,c,d,a,x[k+2], S34,0xC4AC5665);
|
||||
a=II(a,b,c,d,x[k+0], S41,0xF4292244);
|
||||
d=II(d,a,b,c,x[k+7], S42,0x432AFF97);
|
||||
c=II(c,d,a,b,x[k+14],S43,0xAB9423A7);
|
||||
b=II(b,c,d,a,x[k+5], S44,0xFC93A039);
|
||||
a=II(a,b,c,d,x[k+12],S41,0x655B59C3);
|
||||
d=II(d,a,b,c,x[k+3], S42,0x8F0CCC92);
|
||||
c=II(c,d,a,b,x[k+10],S43,0xFFEFF47D);
|
||||
b=II(b,c,d,a,x[k+1], S44,0x85845DD1);
|
||||
a=II(a,b,c,d,x[k+8], S41,0x6FA87E4F);
|
||||
d=II(d,a,b,c,x[k+15],S42,0xFE2CE6E0);
|
||||
c=II(c,d,a,b,x[k+6], S43,0xA3014314);
|
||||
b=II(b,c,d,a,x[k+13],S44,0x4E0811A1);
|
||||
a=II(a,b,c,d,x[k+4], S41,0xF7537E82);
|
||||
d=II(d,a,b,c,x[k+11],S42,0xBD3AF235);
|
||||
c=II(c,d,a,b,x[k+2], S43,0x2AD7D2BB);
|
||||
b=II(b,c,d,a,x[k+9], S44,0xEB86D391);
|
||||
a=AddUnsigned(a,AA);
|
||||
b=AddUnsigned(b,BB);
|
||||
c=AddUnsigned(c,CC);
|
||||
d=AddUnsigned(d,DD);
|
||||
}
|
||||
|
||||
var temp = WordToHex(a)+WordToHex(b)+WordToHex(c)+WordToHex(d);
|
||||
|
||||
return temp.toLowerCase();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
1582
vendors/cryptico/jsbn.js
vendored
Normal file
1582
vendors/cryptico/jsbn.js
vendored
Normal file
File diff suppressed because it is too large
Load diff
447
vendors/cryptico/random.js
vendored
Normal file
447
vendors/cryptico/random.js
vendored
Normal file
|
|
@ -0,0 +1,447 @@
|
|||
// seedrandom.js version 2.0.
|
||||
// Author: David Bau 4/2/2011
|
||||
//
|
||||
// Defines a method Math.seedrandom() that, when called, substitutes
|
||||
// an explicitly seeded RC4-based algorithm for Math.random(). Also
|
||||
// supports automatic seeding from local or network sources of entropy.
|
||||
//
|
||||
// Usage:
|
||||
//
|
||||
// <script src=http://davidbau.com/encode/seedrandom-min.js></script>
|
||||
//
|
||||
// Math.seedrandom('yipee'); Sets Math.random to a function that is
|
||||
// initialized using the given explicit seed.
|
||||
//
|
||||
// Math.seedrandom(); Sets Math.random to a function that is
|
||||
// seeded using the current time, dom state,
|
||||
// and other accumulated local entropy.
|
||||
// The generated seed string is returned.
|
||||
//
|
||||
// Math.seedrandom('yowza', true);
|
||||
// Seeds using the given explicit seed mixed
|
||||
// together with accumulated entropy.
|
||||
//
|
||||
// <script src="http://bit.ly/srandom-512"></script>
|
||||
// Seeds using physical random bits downloaded
|
||||
// from random.org.
|
||||
//
|
||||
// <script src="https://jsonlib.appspot.com/urandom?callback=Math.seedrandom">
|
||||
// </script> Seeds using urandom bits from call.jsonlib.com,
|
||||
// which is faster than random.org.
|
||||
//
|
||||
// Examples:
|
||||
//
|
||||
// Math.seedrandom("hello"); // Use "hello" as the seed.
|
||||
// document.write(Math.random()); // Always 0.5463663768140734
|
||||
// document.write(Math.random()); // Always 0.43973793770592234
|
||||
// var rng1 = Math.random; // Remember the current prng.
|
||||
//
|
||||
// var autoseed = Math.seedrandom(); // New prng with an automatic seed.
|
||||
// document.write(Math.random()); // Pretty much unpredictable.
|
||||
//
|
||||
// Math.random = rng1; // Continue "hello" prng sequence.
|
||||
// document.write(Math.random()); // Always 0.554769432473455
|
||||
//
|
||||
// Math.seedrandom(autoseed); // Restart at the previous seed.
|
||||
// document.write(Math.random()); // Repeat the 'unpredictable' value.
|
||||
//
|
||||
// Notes:
|
||||
//
|
||||
// Each time seedrandom('arg') is called, entropy from the passed seed
|
||||
// is accumulated in a pool to help generate future seeds for the
|
||||
// zero-argument form of Math.seedrandom, so entropy can be injected over
|
||||
// time by calling seedrandom with explicit data repeatedly.
|
||||
//
|
||||
// On speed - This javascript implementation of Math.random() is about
|
||||
// 3-10x slower than the built-in Math.random() because it is not native
|
||||
// code, but this is typically fast enough anyway. Seeding is more expensive,
|
||||
// especially if you use auto-seeding. Some details (timings on Chrome 4):
|
||||
//
|
||||
// Our Math.random() - avg less than 0.002 milliseconds per call
|
||||
// seedrandom('explicit') - avg less than 0.5 milliseconds per call
|
||||
// seedrandom('explicit', true) - avg less than 2 milliseconds per call
|
||||
// seedrandom() - avg about 38 milliseconds per call
|
||||
//
|
||||
// LICENSE (BSD):
|
||||
//
|
||||
// Copyright 2010 David Bau, all rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
//
|
||||
// 2. 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.
|
||||
//
|
||||
// 3. Neither the name of this module nor the names of its contributors may
|
||||
// be used to endorse or promote products derived from this software
|
||||
// without specific prior written permission.
|
||||
//
|
||||
// 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
|
||||
// OWNER 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.
|
||||
//
|
||||
/**
|
||||
* All code is in an anonymous closure to keep the global namespace clean.
|
||||
*
|
||||
* @param {number=} overflow
|
||||
* @param {number=} startdenom
|
||||
*/
|
||||
(function (pool, math, width, chunks, significance, overflow, startdenom)
|
||||
{
|
||||
|
||||
|
||||
//
|
||||
// seedrandom()
|
||||
// This is the seedrandom function described above.
|
||||
//
|
||||
math['seedrandom'] = function seedrandom(seed, use_entropy)
|
||||
{
|
||||
var key = [];
|
||||
var arc4;
|
||||
|
||||
// Flatten the seed string or build one from local entropy if needed.
|
||||
seed = mixkey(flatten(
|
||||
use_entropy ? [seed, pool] : arguments.length ? seed : [new Date().getTime(), pool, window], 3), key);
|
||||
|
||||
// Use the seed to initialize an ARC4 generator.
|
||||
arc4 = new ARC4(key);
|
||||
|
||||
// Mix the randomness into accumulated entropy.
|
||||
mixkey(arc4.S, pool);
|
||||
|
||||
// Override Math.random
|
||||
// This function returns a random double in [0, 1) that contains
|
||||
// randomness in every bit of the mantissa of the IEEE 754 value.
|
||||
math['random'] = function random()
|
||||
{ // Closure to return a random double:
|
||||
var n = arc4.g(chunks); // Start with a numerator n < 2 ^ 48
|
||||
var d = startdenom; // and denominator d = 2 ^ 48.
|
||||
var x = 0; // and no 'extra last byte'.
|
||||
while (n < significance)
|
||||
{ // Fill up all significant digits by
|
||||
n = (n + x) * width; // shifting numerator and
|
||||
d *= width; // denominator and generating a
|
||||
x = arc4.g(1); // new least-significant-byte.
|
||||
}
|
||||
while (n >= overflow)
|
||||
{ // To avoid rounding up, before adding
|
||||
n /= 2; // last byte, shift everything
|
||||
d /= 2; // right using integer math until
|
||||
x >>>= 1; // we have exactly the desired bits.
|
||||
}
|
||||
return (n + x) / d; // Form the number within [0, 1).
|
||||
};
|
||||
|
||||
// Return the seed that was used
|
||||
return seed;
|
||||
};
|
||||
|
||||
//
|
||||
// ARC4
|
||||
//
|
||||
// An ARC4 implementation. The constructor takes a key in the form of
|
||||
// an array of at most (width) integers that should be 0 <= x < (width).
|
||||
//
|
||||
// The g(count) method returns a pseudorandom integer that concatenates
|
||||
// the next (count) outputs from ARC4. Its return value is a number x
|
||||
// that is in the range 0 <= x < (width ^ count).
|
||||
//
|
||||
/** @constructor */
|
||||
|
||||
function ARC4(key)
|
||||
{
|
||||
var t, u, me = this,
|
||||
keylen = key.length;
|
||||
var i = 0,
|
||||
j = me.i = me.j = me.m = 0;
|
||||
me.S = [];
|
||||
me.c = [];
|
||||
|
||||
// The empty key [] is treated as [0].
|
||||
if (!keylen)
|
||||
{
|
||||
key = [keylen++];
|
||||
}
|
||||
|
||||
// Set up S using the standard key scheduling algorithm.
|
||||
while (i < width)
|
||||
{
|
||||
me.S[i] = i++;
|
||||
}
|
||||
for (i = 0; i < width; i++)
|
||||
{
|
||||
t = me.S[i];
|
||||
j = lowbits(j + t + key[i % keylen]);
|
||||
u = me.S[j];
|
||||
me.S[i] = u;
|
||||
me.S[j] = t;
|
||||
}
|
||||
|
||||
// The "g" method returns the next (count) outputs as one number.
|
||||
me.g = function getnext(count)
|
||||
{
|
||||
var s = me.S;
|
||||
var i = lowbits(me.i + 1);
|
||||
var t = s[i];
|
||||
var j = lowbits(me.j + t);
|
||||
var u = s[j];
|
||||
s[i] = u;
|
||||
s[j] = t;
|
||||
var r = s[lowbits(t + u)];
|
||||
while (--count)
|
||||
{
|
||||
i = lowbits(i + 1);
|
||||
t = s[i];
|
||||
j = lowbits(j + t);
|
||||
u = s[j];
|
||||
s[i] = u;
|
||||
s[j] = t;
|
||||
r = r * width + s[lowbits(t + u)];
|
||||
}
|
||||
me.i = i;
|
||||
me.j = j;
|
||||
return r;
|
||||
};
|
||||
// For robust unpredictability discard an initial batch of values.
|
||||
// See http://www.rsa.com/rsalabs/node.asp?id=2009
|
||||
me.g(width);
|
||||
}
|
||||
|
||||
//
|
||||
// flatten()
|
||||
// Converts an object tree to nested arrays of strings.
|
||||
//
|
||||
/** @param {Object=} result
|
||||
* @param {string=} prop
|
||||
* @param {string=} typ */
|
||||
|
||||
function flatten(obj, depth, result, prop, typ)
|
||||
{
|
||||
result = [];
|
||||
typ = typeof (obj);
|
||||
if (depth && typ == 'object')
|
||||
{
|
||||
for (prop in obj)
|
||||
{
|
||||
if (prop.indexOf('S') < 5)
|
||||
{ // Avoid FF3 bug (local/sessionStorage)
|
||||
try
|
||||
{
|
||||
result.push(flatten(obj[prop], depth - 1));
|
||||
}
|
||||
catch (e)
|
||||
{}
|
||||
}
|
||||
}
|
||||
}
|
||||
return (result.length ? result : obj + (typ != 'string' ? '\0' : ''));
|
||||
}
|
||||
|
||||
//
|
||||
// mixkey()
|
||||
// Mixes a string seed into a key that is an array of integers, and
|
||||
// returns a shortened string seed that is equivalent to the result key.
|
||||
//
|
||||
/** @param {number=} smear
|
||||
* @param {number=} j */
|
||||
|
||||
function mixkey(seed, key, smear, j)
|
||||
{
|
||||
seed += ''; // Ensure the seed is a string
|
||||
smear = 0;
|
||||
for (j = 0; j < seed.length; j++)
|
||||
{
|
||||
key[lowbits(j)] = lowbits((smear ^= key[lowbits(j)] * 19) + seed.charCodeAt(j));
|
||||
}
|
||||
seed = '';
|
||||
for (j in key)
|
||||
{
|
||||
seed += String.fromCharCode(key[j]);
|
||||
}
|
||||
return seed;
|
||||
}
|
||||
|
||||
//
|
||||
// lowbits()
|
||||
// A quick "n mod width" for width a power of 2.
|
||||
//
|
||||
|
||||
|
||||
function lowbits(n)
|
||||
{
|
||||
return n & (width - 1);
|
||||
}
|
||||
|
||||
//
|
||||
// The following constants are related to IEEE 754 limits.
|
||||
//
|
||||
startdenom = math.pow(width, chunks);
|
||||
significance = math.pow(2, significance);
|
||||
overflow = significance * 2;
|
||||
|
||||
//
|
||||
// When seedrandom.js is loaded, we immediately mix a few bits
|
||||
// from the built-in RNG into the entropy pool. Because we do
|
||||
// not want to intefere with determinstic PRNG state later,
|
||||
// seedrandom will not call math.random on its own again after
|
||||
// initialization.
|
||||
//
|
||||
mixkey(math.random(), pool);
|
||||
|
||||
// End anonymous scope, and pass initial values.
|
||||
})([], // pool: entropy pool starts empty
|
||||
Math, // math: package containing random, pow, and seedrandom
|
||||
256, // width: each RC4 output is 0 <= x < 256
|
||||
6, // chunks: at least six RC4 outputs for each double
|
||||
52 // significance: there are 52 significant digits in a double
|
||||
);
|
||||
|
||||
|
||||
// This is not really a random number generator object, and two SeededRandom
|
||||
// objects will conflict with one another, but it's good enough for generating
|
||||
// the rsa key.
|
||||
function SeededRandom(){}
|
||||
|
||||
function SRnextBytes(ba)
|
||||
{
|
||||
var i;
|
||||
for(i = 0; i < ba.length; i++)
|
||||
{
|
||||
ba[i] = Math.floor(Math.random() * 256);
|
||||
}
|
||||
}
|
||||
|
||||
SeededRandom.prototype.nextBytes = SRnextBytes;
|
||||
|
||||
// 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;
|
||||
|
||||
// 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(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;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
459
vendors/cryptico/rsa.js
vendored
Normal file
459
vendors/cryptico/rsa.js
vendored
Normal file
|
|
@ -0,0 +1,459 @@
|
|||
// 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 (n=" + n + ", l=" + s.length + ")");
|
||||
//return null;
|
||||
throw "Message too long for RSA (n=" + n + ", l=" + s.length + ")";
|
||||
}
|
||||
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;
|
||||
|
||||
// Version 1.1: support utf-8 decoding in pkcs1unpad2
|
||||
// Undo PKCS#1 (type 2, random) padding and, if valid, return the plaintext
|
||||
|
||||
function pkcs1unpad2(d, n)
|
||||
{
|
||||
var b = d.toByteArray();
|
||||
var i = 0;
|
||||
while (i < b.length && b[i] == 0)++i;
|
||||
if (b.length - i != n - 1 || b[i] != 2) return null;
|
||||
++i;
|
||||
while (b[i] != 0)
|
||||
if (++i >= b.length) return null;
|
||||
var ret = "";
|
||||
while (++i < b.length)
|
||||
{
|
||||
var c = b[i] & 255;
|
||||
if (c < 128)
|
||||
{ // utf-8 decode
|
||||
ret += String.fromCharCode(c);
|
||||
}
|
||||
else if ((c > 191) && (c < 224))
|
||||
{
|
||||
ret += String.fromCharCode(((c & 31) << 6) | (b[i + 1] & 63));
|
||||
++i;
|
||||
}
|
||||
else
|
||||
{
|
||||
ret += String.fromCharCode(((c & 15) << 12) | ((b[i + 1] & 63) << 6) | (b[i + 2] & 63));
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Set the private key fields N, e, and d from hex strings
|
||||
function RSASetPrivate(N, E, D)
|
||||
{
|
||||
if (N != null && E != null && N.length > 0 && E.length > 0)
|
||||
{
|
||||
this.n = parseBigInt(N, 16);
|
||||
this.e = parseInt(E, 16);
|
||||
this.d = parseBigInt(D, 16);
|
||||
}
|
||||
else alert("Invalid RSA private key");
|
||||
}
|
||||
|
||||
// Set the private key fields N, e, d and CRT params from hex strings
|
||||
function RSASetPrivateEx(N, E, D, P, Q, DP, DQ, C)
|
||||
{
|
||||
if (N != null && E != null && N.length > 0 && E.length > 0)
|
||||
{
|
||||
this.n = parseBigInt(N, 16);
|
||||
this.e = parseInt(E, 16);
|
||||
this.d = parseBigInt(D, 16);
|
||||
this.p = parseBigInt(P, 16);
|
||||
this.q = parseBigInt(Q, 16);
|
||||
this.dmp1 = parseBigInt(DP, 16);
|
||||
this.dmq1 = parseBigInt(DQ, 16);
|
||||
this.coeff = parseBigInt(C, 16);
|
||||
}
|
||||
else alert("Invalid RSA private key");
|
||||
}
|
||||
|
||||
// Generate a new random private key B bits long, using public expt E
|
||||
function RSAGenerate(B, E)
|
||||
{
|
||||
var rng = new SeededRandom();
|
||||
var qs = B >> 1;
|
||||
this.e = parseInt(E, 16);
|
||||
var ee = new BigInteger(E, 16);
|
||||
for (;;)
|
||||
{
|
||||
for (;;)
|
||||
{
|
||||
this.p = new BigInteger(B - qs, 1, rng);
|
||||
if (this.p.subtract(BigInteger.ONE).gcd(ee).compareTo(BigInteger.ONE) == 0 && this.p.isProbablePrime(10)) break;
|
||||
}
|
||||
for (;;)
|
||||
{
|
||||
this.q = new BigInteger(qs, 1, rng);
|
||||
if (this.q.subtract(BigInteger.ONE).gcd(ee).compareTo(BigInteger.ONE) == 0 && this.q.isProbablePrime(10)) break;
|
||||
}
|
||||
if (this.p.compareTo(this.q) <= 0)
|
||||
{
|
||||
var t = this.p;
|
||||
this.p = this.q;
|
||||
this.q = t;
|
||||
}
|
||||
var p1 = this.p.subtract(BigInteger.ONE);
|
||||
var q1 = this.q.subtract(BigInteger.ONE);
|
||||
var phi = p1.multiply(q1);
|
||||
if (phi.gcd(ee).compareTo(BigInteger.ONE) == 0)
|
||||
{
|
||||
this.n = this.p.multiply(this.q);
|
||||
this.d = ee.modInverse(phi);
|
||||
this.dmp1 = this.d.mod(p1);
|
||||
this.dmq1 = this.d.mod(q1);
|
||||
this.coeff = this.q.modInverse(this.p);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Perform raw private operation on "x": return x^d (mod n)
|
||||
function RSADoPrivate(x)
|
||||
{
|
||||
if (this.p == null || this.q == null) return x.modPow(this.d, this.n);
|
||||
// TODO: re-calculate any missing CRT params
|
||||
var xp = x.mod(this.p).modPow(this.dmp1, this.p);
|
||||
var xq = x.mod(this.q).modPow(this.dmq1, this.q);
|
||||
while (xp.compareTo(xq) < 0)
|
||||
xp = xp.add(this.p);
|
||||
return xp.subtract(xq).multiply(this.coeff).mod(this.p).multiply(this.q).add(xq);
|
||||
}
|
||||
|
||||
// Return the PKCS#1 RSA decryption of "ctext".
|
||||
// "ctext" is an even-length hex string and the output is a plain string.
|
||||
function RSADecrypt(ctext)
|
||||
{
|
||||
var c = parseBigInt(ctext, 16);
|
||||
var m = this.doPrivate(c);
|
||||
if (m == null) return null;
|
||||
return pkcs1unpad2(m, (this.n.bitLength() + 7) >> 3);
|
||||
}
|
||||
|
||||
// protected
|
||||
RSAKey.prototype.doPrivate = RSADoPrivate;
|
||||
|
||||
// public
|
||||
RSAKey.prototype.setPrivate = RSASetPrivate;
|
||||
RSAKey.prototype.setPrivateEx = RSASetPrivateEx;
|
||||
RSAKey.prototype.generate = RSAGenerate;
|
||||
RSAKey.prototype.decrypt = RSADecrypt;
|
||||
|
||||
|
||||
//
|
||||
// rsa-sign.js - adding signing functions to RSAKey class.
|
||||
//
|
||||
//
|
||||
// version: 1.0 (2010-Jun-03)
|
||||
//
|
||||
// Copyright (c) 2010 Kenji Urushima (kenji.urushima@gmail.com)
|
||||
//
|
||||
// This software is licensed under the terms of the MIT License.
|
||||
// http://www.opensource.org/licenses/mit-license.php
|
||||
//
|
||||
// The above copyright and license notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// Depends on:
|
||||
// function sha1.hex(s) of sha1.js
|
||||
// jsbn.js
|
||||
// jsbn2.js
|
||||
// rsa.js
|
||||
// rsa2.js
|
||||
//
|
||||
// keysize / pmstrlen
|
||||
// 512 / 128
|
||||
// 1024 / 256
|
||||
// 2048 / 512
|
||||
// 4096 / 1024
|
||||
// As for _RSASGIN_DIHEAD values for each hash algorithm, see PKCS#1 v2.1 spec (p38).
|
||||
var _RSASIGN_DIHEAD = [];
|
||||
_RSASIGN_DIHEAD['sha1'] = "3021300906052b0e03021a05000414";
|
||||
_RSASIGN_DIHEAD['sha256'] = "3031300d060960864801650304020105000420";
|
||||
//_RSASIGN_DIHEAD['md2'] = "3020300c06082a864886f70d020205000410";
|
||||
//_RSASIGN_DIHEAD['md5'] = "3020300c06082a864886f70d020505000410";
|
||||
//_RSASIGN_DIHEAD['sha384'] = "3041300d060960864801650304020205000430";
|
||||
//_RSASIGN_DIHEAD['sha512'] = "3051300d060960864801650304020305000440";
|
||||
var _RSASIGN_HASHHEXFUNC = [];
|
||||
_RSASIGN_HASHHEXFUNC['sha1'] = sha1.hex;
|
||||
_RSASIGN_HASHHEXFUNC['sha256'] = sha256.hex;
|
||||
|
||||
// ========================================================================
|
||||
// Signature Generation
|
||||
// ========================================================================
|
||||
|
||||
function _rsasign_getHexPaddedDigestInfoForString(s, keySize, hashAlg)
|
||||
{
|
||||
var pmStrLen = keySize / 4;
|
||||
var hashFunc = _RSASIGN_HASHHEXFUNC[hashAlg];
|
||||
var sHashHex = hashFunc(s);
|
||||
|
||||
var sHead = "0001";
|
||||
var sTail = "00" + _RSASIGN_DIHEAD[hashAlg] + sHashHex;
|
||||
var sMid = "";
|
||||
var fLen = pmStrLen - sHead.length - sTail.length;
|
||||
for (var i = 0; i < fLen; i += 2)
|
||||
{
|
||||
sMid += "ff";
|
||||
}
|
||||
sPaddedMessageHex = sHead + sMid + sTail;
|
||||
return sPaddedMessageHex;
|
||||
}
|
||||
|
||||
function _rsasign_signString(s, hashAlg)
|
||||
{
|
||||
var hPM = _rsasign_getHexPaddedDigestInfoForString(s, this.n.bitLength(), hashAlg);
|
||||
var biPaddedMessage = parseBigInt(hPM, 16);
|
||||
var biSign = this.doPrivate(biPaddedMessage);
|
||||
var hexSign = biSign.toString(16);
|
||||
return hexSign;
|
||||
}
|
||||
|
||||
function _rsasign_signStringWithSHA1(s)
|
||||
{
|
||||
var hPM = _rsasign_getHexPaddedDigestInfoForString(s, this.n.bitLength(), 'sha1');
|
||||
var biPaddedMessage = parseBigInt(hPM, 16);
|
||||
var biSign = this.doPrivate(biPaddedMessage);
|
||||
var hexSign = biSign.toString(16);
|
||||
return hexSign;
|
||||
}
|
||||
|
||||
function _rsasign_signStringWithSHA256(s)
|
||||
{
|
||||
var hPM = _rsasign_getHexPaddedDigestInfoForString(s, this.n.bitLength(), 'sha256');
|
||||
var biPaddedMessage = parseBigInt(hPM, 16);
|
||||
var biSign = this.doPrivate(biPaddedMessage);
|
||||
var hexSign = biSign.toString(16);
|
||||
return hexSign;
|
||||
}
|
||||
|
||||
// ========================================================================
|
||||
// Signature Verification
|
||||
// ========================================================================
|
||||
|
||||
function _rsasign_getDecryptSignatureBI(biSig, hN, hE)
|
||||
{
|
||||
var rsa = new RSAKey();
|
||||
rsa.setPublic(hN, hE);
|
||||
var biDecryptedSig = rsa.doPublic(biSig);
|
||||
return biDecryptedSig;
|
||||
}
|
||||
|
||||
function _rsasign_getHexDigestInfoFromSig(biSig, hN, hE)
|
||||
{
|
||||
var biDecryptedSig = _rsasign_getDecryptSignatureBI(biSig, hN, hE);
|
||||
var hDigestInfo = biDecryptedSig.toString(16).replace(/^1f+00/, '');
|
||||
return hDigestInfo;
|
||||
}
|
||||
|
||||
function _rsasign_getAlgNameAndHashFromHexDisgestInfo(hDigestInfo)
|
||||
{
|
||||
for (var algName in _RSASIGN_DIHEAD)
|
||||
{
|
||||
var head = _RSASIGN_DIHEAD[algName];
|
||||
var len = head.length;
|
||||
if (hDigestInfo.substring(0, len) == head)
|
||||
{
|
||||
var a = [algName, hDigestInfo.substring(len)];
|
||||
return a;
|
||||
}
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
function _rsasign_verifySignatureWithArgs(sMsg, biSig, hN, hE)
|
||||
{
|
||||
var hDigestInfo = _rsasign_getHexDigestInfoFromSig(biSig, hN, hE);
|
||||
var digestInfoAry = _rsasign_getAlgNameAndHashFromHexDisgestInfo(hDigestInfo);
|
||||
if (digestInfoAry.length == 0) return false;
|
||||
var algName = digestInfoAry[0];
|
||||
var diHashValue = digestInfoAry[1];
|
||||
var ff = _RSASIGN_HASHHEXFUNC[algName];
|
||||
var msgHashValue = ff(sMsg);
|
||||
return (diHashValue == msgHashValue);
|
||||
}
|
||||
|
||||
function _rsasign_verifyHexSignatureForMessage(hSig, sMsg)
|
||||
{
|
||||
var biSig = parseBigInt(hSig, 16);
|
||||
var result = _rsasign_verifySignatureWithArgs(sMsg, biSig, this.n.toString(16), this.e.toString(16));
|
||||
return result;
|
||||
}
|
||||
|
||||
function _rsasign_verifyString(sMsg, hSig)
|
||||
{
|
||||
hSig = hSig.replace(/[ \n]+/g, "");
|
||||
var biSig = parseBigInt(hSig, 16);
|
||||
var biDecryptedSig = this.doPublic(biSig);
|
||||
var hDigestInfo = biDecryptedSig.toString(16).replace(/^1f+00/, '');
|
||||
var digestInfoAry = _rsasign_getAlgNameAndHashFromHexDisgestInfo(hDigestInfo);
|
||||
|
||||
if (digestInfoAry.length == 0) return false;
|
||||
var algName = digestInfoAry[0];
|
||||
var diHashValue = digestInfoAry[1];
|
||||
var ff = _RSASIGN_HASHHEXFUNC[algName];
|
||||
var msgHashValue = ff(sMsg);
|
||||
return (diHashValue == msgHashValue);
|
||||
}
|
||||
|
||||
RSAKey.prototype.signString = _rsasign_signString;
|
||||
RSAKey.prototype.signStringWithSHA1 = _rsasign_signStringWithSHA1;
|
||||
RSAKey.prototype.signStringWithSHA256 = _rsasign_signStringWithSHA256;
|
||||
|
||||
RSAKey.prototype.verifyString = _rsasign_verifyString;
|
||||
RSAKey.prototype.verifyHexSignatureForMessage = _rsasign_verifyHexSignatureForMessage;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
148
vendors/cryptico/test.html
vendored
Normal file
148
vendors/cryptico/test.html
vendored
Normal file
|
|
@ -0,0 +1,148 @@
|
|||
|
||||
<html>
|
||||
|
||||
<head>
|
||||
|
||||
<script language="JavaScript" type="text/javascript" src="jsbn.js"></script>
|
||||
<script language="JavaScript" type="text/javascript" src="random.js"></script>
|
||||
<script language="JavaScript" type="text/javascript" src="hash.js"></script>
|
||||
<script language="JavaScript" type="text/javascript" src="rsa.js"></script>
|
||||
<script language="JavaScript" type="text/javascript" src="aes.js"></script>
|
||||
<script language="JavaScript" type="text/javascript" src="api.js"></script>
|
||||
|
||||
<script>
|
||||
|
||||
function print(string)
|
||||
{
|
||||
document.write(string + "\n\n");
|
||||
}
|
||||
|
||||
print("<h1>Unsigned:</h1>");
|
||||
|
||||
var PassPhrase = "The Moon is a Harsh Mistress.";
|
||||
var Bits = 512;
|
||||
|
||||
print("Matt's passphrase: " + PassPhrase);
|
||||
print("Bit length: " + Bits);
|
||||
|
||||
var MattsRSAkey = cryptico.generateRSAKey(PassPhrase, Bits);
|
||||
var MattsPublicKeyString = cryptico.publicKeyString(MattsRSAkey);
|
||||
|
||||
print("Matt's public key string:");
|
||||
print(MattsPublicKeyString);
|
||||
|
||||
var PlainText = "Matt, I need you to help me with my Starcraft strategy.";
|
||||
|
||||
print("Sam's message: " + PlainText);
|
||||
|
||||
var EncryptionResult = cryptico.encrypt(PlainText, MattsPublicKeyString);
|
||||
|
||||
print("The encrypted message:");
|
||||
print(EncryptionResult.cipher);
|
||||
|
||||
var DecryptionResult = cryptico.decrypt(EncryptionResult.cipher, MattsRSAkey);
|
||||
|
||||
print("The decrypted message:");
|
||||
print(DecryptionResult.plaintext);
|
||||
print("DecryptionResult.signature: " + DecryptionResult.signature);
|
||||
|
||||
print("<h1>Signed, good signature:</h1>");
|
||||
|
||||
var PassPhrase = "There Ain't No Such Thing As A Free Lunch.";
|
||||
var Bits = 512;
|
||||
var SamsRSAkey = cryptico.generateRSAKey(PassPhrase, Bits);
|
||||
var PlainText = "Matt, I need you to help me with my Starcraft strategy.";
|
||||
var EncryptionResult = cryptico.encrypt(PlainText, MattsPublicKeyString, SamsRSAkey);
|
||||
|
||||
print("Sam's public key ID: " + cryptico.publicKeyID(cryptico.publicKeyString(SamsRSAkey)));
|
||||
|
||||
print("The encrypted message:");
|
||||
print(EncryptionResult.cipher);
|
||||
|
||||
var DecryptionResult = cryptico.decrypt(EncryptionResult.cipher, MattsRSAkey);
|
||||
|
||||
print("The decrypted message:");
|
||||
print(DecryptionResult.plaintext);
|
||||
|
||||
print("DecryptionResult.signature: " + DecryptionResult.signature);
|
||||
|
||||
print("The signature public key string:");
|
||||
print(DecryptionResult.publicKeyString);
|
||||
|
||||
print("The signature public key ID:");
|
||||
print(cryptico.publicKeyID(DecryptionResult.publicKeyString));
|
||||
|
||||
|
||||
|
||||
print("<h1>Signed, forged signature:</h1>");
|
||||
|
||||
EncryptionResult.cipher = "FrD9P9pbSuCpaMExcHI/6WHbrOgLlIWWegHrWRLN027+DekkaVzumh8QbCS7\n\
|
||||
6BZJpfQ0H0b/pEvPCnE9RNqFFQ==?h7W8J7KrqDd7TCDlOolSUPwRNxoJYoQ\n\
|
||||
o7h62SDsfLTfKcdzi6DUTfEq7DgsIKIZd8nYYrDmn3F1utFlgVja2mXSD7FY\n\
|
||||
RRNvYbmpmu3WBozG77hyFup3IlEQeOkKLBk9G1uEYGcrXiIktJiYBvn8ltVP\n\
|
||||
Qdo6cViIkwYjEdNoCIanYsSO+YB20EyuKfDj0p62QW9sAVx8jeQmY+f7cvWj\n\
|
||||
/3evPfZ2D3gaXXT+QY2mu+0ap8P89rPFmrlMgMVFRye4FEWHSkSiKtrddt1y\n\
|
||||
DZoMxwxFytKA2QciN7MHgZRZ16kcO1KjpPlb9jSXDbzllCWDhigN+kvBog4L\n\
|
||||
GvhTe0CEn5HKGpWx1+TGbC7pim6/KOFo34DScLOrclUNGl0VY8W+/+EBXhin\n\
|
||||
dthvRRcjy+0BRn4tDpC4QJjdJoXCqDmT3NRU="
|
||||
|
||||
print("The encrypted message:");
|
||||
print(EncryptionResult.cipher);
|
||||
|
||||
var DecryptionResult = cryptico.decrypt(EncryptionResult.cipher, MattsRSAkey);
|
||||
|
||||
print("The decrypted message:");
|
||||
print(DecryptionResult.plaintext);
|
||||
|
||||
print("DecryptionResult.signature: " + DecryptionResult.signature);
|
||||
|
||||
print("The signature public key string:");
|
||||
print(DecryptionResult.publicKeyString);
|
||||
|
||||
print("The signature public key ID:");
|
||||
print(cryptico.publicKeyID(DecryptionResult.publicKeyString));
|
||||
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
</head>
|
||||
|
||||
<body style="font-family: monospace; white-space:pre;">
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue