Diffstat (limited to 'frontend/gamma/js/Clipperz/Crypto/BigInt.js') (more/less context) (ignore whitespace changes)
-rw-r--r-- | frontend/gamma/js/Clipperz/Crypto/BigInt.js | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/frontend/gamma/js/Clipperz/Crypto/BigInt.js b/frontend/gamma/js/Clipperz/Crypto/BigInt.js index d4d05d2..41483a3 100644 --- a/frontend/gamma/js/Clipperz/Crypto/BigInt.js +++ b/frontend/gamma/js/Clipperz/Crypto/BigInt.js | |||
@@ -1,120 +1,117 @@ | |||
1 | /* | 1 | /* |
2 | 2 | ||
3 | Copyright 2008-2011 Clipperz Srl | 3 | Copyright 2008-2011 Clipperz Srl |
4 | 4 | ||
5 | This file is part of Clipperz's Javascript Crypto Library. | 5 | This file is part of Clipperz Community Edition. |
6 | Javascript Crypto Library provides web developers with an extensive | 6 | Clipperz Community Edition is an online password manager. |
7 | and efficient set of cryptographic functions. The library aims to | ||
8 | obtain maximum execution speed while preserving modularity and | ||
9 | reusability. | ||
10 | For further information about its features and functionalities please | 7 | For further information about its features and functionalities please |
11 | refer to http://www.clipperz.com | 8 | refer to http://www.clipperz.com. |
12 | 9 | ||
13 | * Javascript Crypto Library is free software: you can redistribute | 10 | * Clipperz Community Edition is free software: you can redistribute |
14 | it and/or modify it under the terms of the GNU Affero General Public | 11 | it and/or modify it under the terms of the GNU Affero General Public |
15 | License as published by the Free Software Foundation, either version | 12 | License as published by the Free Software Foundation, either version |
16 | 3 of the License, or (at your option) any later version. | 13 | 3 of the License, or (at your option) any later version. |
17 | 14 | ||
18 | * Javascript Crypto Library is distributed in the hope that it will | 15 | * Clipperz Community Edition is distributed in the hope that it will |
19 | be useful, but WITHOUT ANY WARRANTY; without even the implied | 16 | be useful, but WITHOUT ANY WARRANTY; without even the implied |
20 | warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | 17 | warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
21 | See the GNU Affero General Public License for more details. | 18 | See the GNU Affero General Public License for more details. |
22 | 19 | ||
23 | * You should have received a copy of the GNU Affero General Public | 20 | * You should have received a copy of the GNU Affero General Public |
24 | License along with Javascript Crypto Library. If not, see | 21 | License along with Clipperz Community Edition. If not, see |
25 | <http://www.gnu.org/licenses/>. | 22 | <http://www.gnu.org/licenses/>. |
26 | 23 | ||
27 | */ | 24 | */ |
28 | 25 | ||
29 | if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } | 26 | if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } |
30 | if (typeof(Clipperz.Crypto) == 'undefined') { Clipperz.Crypto = {}; } | 27 | if (typeof(Clipperz.Crypto) == 'undefined') { Clipperz.Crypto = {}; } |
31 | 28 | ||
32 | //############################################################################# | 29 | //############################################################################# |
33 | //Downloaded on March 05, 2007 from http://www.leemon.com/crypto/BigInt.js | 30 | //Downloaded on March 05, 2007 from http://www.leemon.com/crypto/BigInt.js |
34 | //############################################################################# | 31 | //############################################################################# |
35 | 32 | ||
36 | 33 | ||
37 | //////////////////////////////////////////////////////////////////////////////////////// | 34 | //////////////////////////////////////////////////////////////////////////////////////// |
38 | // Big Integer Library v. 5.0 | 35 | // Big Integer Library v. 5.0 |
39 | // Created 2000, last modified 2006 | 36 | // Created 2000, last modified 2006 |
40 | // Leemon Baird | 37 | // Leemon Baird |
41 | // www.leemon.com | 38 | // www.leemon.com |
42 | // | 39 | // |
43 | // This file is public domain. You can use it for any purpose without restriction. | 40 | // This file is public domain. You can use it for any purpose without restriction. |
44 | // I do not guarantee that it is correct, so use it at your own risk. If you use | 41 | // I do not guarantee that it is correct, so use it at your own risk. If you use |
45 | // it for something interesting, I'd appreciate hearing about it. If you find | 42 | // it for something interesting, I'd appreciate hearing about it. If you find |
46 | // any bugs or make any improvements, I'd appreciate hearing about those too. | 43 | // any bugs or make any improvements, I'd appreciate hearing about those too. |
47 | // It would also be nice if my name and address were left in the comments. | 44 | // It would also be nice if my name and address were left in the comments. |
48 | // But none of that is required. | 45 | // But none of that is required. |
49 | // | 46 | // |
50 | // This code defines a bigInt library for arbitrary-precision integers. | 47 | // This code defines a bigInt library for arbitrary-precision integers. |
51 | // A bigInt is an array of integers storing the value in chunks of bpe bits, | 48 | // A bigInt is an array of integers storing the value in chunks of bpe bits, |
52 | // little endian (buff[0] is the least significant word). | 49 | // little endian (buff[0] is the least significant word). |
53 | // Negative bigInts are stored two's complement. | 50 | // Negative bigInts are stored two's complement. |
54 | // Some functions assume their parameters have at least one leading zero element. | 51 | // Some functions assume their parameters have at least one leading zero element. |
55 | // Functions with an underscore at the end of the name have unpredictable behavior in case of overflow, | 52 | // Functions with an underscore at the end of the name have unpredictable behavior in case of overflow, |
56 | // so the caller must make sure overflow won't happen. | 53 | // so the caller must make sure overflow won't happen. |
57 | // For each function where a parameter is modified, that same | 54 | // For each function where a parameter is modified, that same |
58 | // variable must not be used as another argument too. | 55 | // variable must not be used as another argument too. |
59 | // So, you cannot square x by doing multMod_(x,x,n). | 56 | // So, you cannot square x by doing multMod_(x,x,n). |
60 | // You must use squareMod_(x,n) instead, or do y=dup(x); multMod_(x,y,n). | 57 | // You must use squareMod_(x,n) instead, or do y=dup(x); multMod_(x,y,n). |
61 | // | 58 | // |
62 | // These functions are designed to avoid frequent dynamic memory allocation in the inner loop. | 59 | // These functions are designed to avoid frequent dynamic memory allocation in the inner loop. |
63 | // For most functions, if it needs a BigInt as a local variable it will actually use | 60 | // For most functions, if it needs a BigInt as a local variable it will actually use |
64 | // a global, and will only allocate to it when it's not the right size. This ensures | 61 | // a global, and will only allocate to it when it's not the right size. This ensures |
65 | // that when a function is called repeatedly with same-sized parameters, it only allocates | 62 | // that when a function is called repeatedly with same-sized parameters, it only allocates |
66 | // memory on the first call. | 63 | // memory on the first call. |
67 | // | 64 | // |
68 | // Note that for cryptographic purposes, the calls to Math.random() must | 65 | // Note that for cryptographic purposes, the calls to Math.random() must |
69 | // be replaced with calls to a better pseudorandom number generator. | 66 | // be replaced with calls to a better pseudorandom number generator. |
70 | // | 67 | // |
71 | // In the following, "bigInt" means a bigInt with at least one leading zero element, | 68 | // In the following, "bigInt" means a bigInt with at least one leading zero element, |
72 | // and "integer" means a nonnegative integer less than radix. In some cases, integer | 69 | // and "integer" means a nonnegative integer less than radix. In some cases, integer |
73 | // can be negative. Negative bigInts are 2s complement. | 70 | // can be negative. Negative bigInts are 2s complement. |
74 | // | 71 | // |
75 | // The following functions do not modify their inputs, but dynamically allocate memory every time they are called: | 72 | // The following functions do not modify their inputs, but dynamically allocate memory every time they are called: |
76 | // | 73 | // |
77 | // function bigInt2str(x,base) //convert a bigInt into a string in a given base, from base 2 up to base 95 | 74 | // function bigInt2str(x,base) //convert a bigInt into a string in a given base, from base 2 up to base 95 |
78 | // function dup(x) //returns a copy of bigInt x | 75 | // function dup(x) //returns a copy of bigInt x |
79 | // function findPrimes(n) //return array of all primes less than integer n | 76 | // function findPrimes(n) //return array of all primes less than integer n |
80 | // function int2bigInt(t,n,m) //convert integer t to a bigInt with at least n bits and m array elements | 77 | // function int2bigInt(t,n,m) //convert integer t to a bigInt with at least n bits and m array elements |
81 | // function int2bigInt(s,b,n,m) //convert string s in base b to a bigInt with at least n bits and m array elements | 78 | // function int2bigInt(s,b,n,m) //convert string s in base b to a bigInt with at least n bits and m array elements |
82 | // function trim(x,k) //return a copy of x with exactly k leading zero elements | 79 | // function trim(x,k) //return a copy of x with exactly k leading zero elements |
83 | // | 80 | // |
84 | // The following functions do not modify their inputs, so there is never a problem with the result being too big: | 81 | // The following functions do not modify their inputs, so there is never a problem with the result being too big: |
85 | // | 82 | // |
86 | // function bitSize(x) //returns how many bits long the bigInt x is, not counting leading zeros | 83 | // function bitSize(x) //returns how many bits long the bigInt x is, not counting leading zeros |
87 | // function equals(x,y) //is the bigInt x equal to the bigint y? | 84 | // function equals(x,y) //is the bigInt x equal to the bigint y? |
88 | // function equalsInt(x,y) //is bigint x equal to integer y? | 85 | // function equalsInt(x,y) //is bigint x equal to integer y? |
89 | // function greater(x,y) //is x>y? (x and y are nonnegative bigInts) | 86 | // function greater(x,y) //is x>y? (x and y are nonnegative bigInts) |
90 | // function greaterShift(x,y,shift)//is (x <<(shift*bpe)) > y? | 87 | // function greaterShift(x,y,shift)//is (x <<(shift*bpe)) > y? |
91 | // function isZero(x) //is the bigInt x equal to zero? | 88 | // function isZero(x) //is the bigInt x equal to zero? |
92 | // function millerRabin(x,b) //does one round of Miller-Rabin base integer b say that bigInt x is possibly prime (as opposed to definitely composite)? | 89 | // function millerRabin(x,b) //does one round of Miller-Rabin base integer b say that bigInt x is possibly prime (as opposed to definitely composite)? |
93 | // function modInt(x,n) //return x mod n for bigInt x and integer n. | 90 | // function modInt(x,n) //return x mod n for bigInt x and integer n. |
94 | // function negative(x) //is bigInt x negative? | 91 | // function negative(x) //is bigInt x negative? |
95 | // | 92 | // |
96 | // The following functions do not modify their inputs, but allocate memory and call functions with underscores | 93 | // The following functions do not modify their inputs, but allocate memory and call functions with underscores |
97 | // | 94 | // |
98 | // function add(x,y) //return (x+y) for bigInts x and y. | 95 | // function add(x,y) //return (x+y) for bigInts x and y. |
99 | // function addInt(x,n) //return (x+n) where x is a bigInt and n is an integer. | 96 | // function addInt(x,n) //return (x+n) where x is a bigInt and n is an integer. |
100 | // function expand(x,n) //return a copy of x with at least n elements, adding leading zeros if needed | 97 | // function expand(x,n) //return a copy of x with at least n elements, adding leading zeros if needed |
101 | // function inverseMod(x,n) //return (x**(-1) mod n) for bigInts x and n. If no inverse exists, it returns null | 98 | // function inverseMod(x,n) //return (x**(-1) mod n) for bigInts x and n. If no inverse exists, it returns null |
102 | // function mod(x,n) //return a new bigInt equal to (x mod n) for bigInts x and n. | 99 | // function mod(x,n) //return a new bigInt equal to (x mod n) for bigInts x and n. |
103 | // function mult(x,y) //return x*y for bigInts x and y. This is faster when y<x. | 100 | // function mult(x,y) //return x*y for bigInts x and y. This is faster when y<x. |
104 | // function multMod(x,y,n) //return (x*y mod n) for bigInts x,y,n. For greater speed, let y<x. | 101 | // function multMod(x,y,n) //return (x*y mod n) for bigInts x,y,n. For greater speed, let y<x. |
105 | // function powMod(x,y,n) //return (x**y mod n) where x,y,n are bigInts and ** is exponentiation. 0**0=1. Faster for odd n. | 102 | // function powMod(x,y,n) //return (x**y mod n) where x,y,n are bigInts and ** is exponentiation. 0**0=1. Faster for odd n. |
106 | // function randTruePrime(k) //return a new, random, k-bit, true prime using Maurer's algorithm. | 103 | // function randTruePrime(k) //return a new, random, k-bit, true prime using Maurer's algorithm. |
107 | // function sub(x,y) //return (x-y) for bigInts x and y. Negative answers will be 2s complement | 104 | // function sub(x,y) //return (x-y) for bigInts x and y. Negative answers will be 2s complement |
108 | // | 105 | // |
109 | // The following functions write a bigInt result to one of the parameters, but | 106 | // The following functions write a bigInt result to one of the parameters, but |
110 | // the result is never bigger than the original, so there can't be overflow problems: | 107 | // the result is never bigger than the original, so there can't be overflow problems: |
111 | // | 108 | // |
112 | // function divInt_(x,n) //do x=floor(x/n) for bigInt x and integer n, and return the remainder | 109 | // function divInt_(x,n) //do x=floor(x/n) for bigInt x and integer n, and return the remainder |
113 | // function GCD_(x,y) //set x to the greatest common divisor of bigInts x and y, (y is destroyed). | 110 | // function GCD_(x,y) //set x to the greatest common divisor of bigInts x and y, (y is destroyed). |
114 | // function halve_(x) //do x=floor(|x|/2)*sgn(x) for bigInt x in 2's complement | 111 | // function halve_(x) //do x=floor(|x|/2)*sgn(x) for bigInt x in 2's complement |
115 | // function mod_(x,n) //do x=x mod n for bigInts x and n. | 112 | // function mod_(x,n) //do x=x mod n for bigInts x and n. |
116 | // function rightShift_(x,n) //right shift bigInt x by n bits. 0 <= n < bpe. | 113 | // function rightShift_(x,n) //right shift bigInt x by n bits. 0 <= n < bpe. |
117 | // | 114 | // |
118 | // The following functions write a bigInt result to one of the parameters. The caller is responsible for | 115 | // The following functions write a bigInt result to one of the parameters. The caller is responsible for |
119 | // ensuring it is large enough to hold the result. | 116 | // ensuring it is large enough to hold the result. |
120 | // | 117 | // |