OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2003-2005 Tom Wu | 2 * Copyright (c) 2003-2005 Tom Wu |
3 * All Rights Reserved. | 3 * All Rights Reserved. |
4 * | 4 * |
5 * Permission is hereby granted, free of charge, to any person obtaining | 5 * Permission is hereby granted, free of charge, to any person obtaining |
6 * a copy of this software and associated documentation files (the | 6 * a copy of this software and associated documentation files (the |
7 * "Software"), to deal in the Software without restriction, including | 7 * "Software"), to deal in the Software without restriction, including |
8 * without limitation the rights to use, copy, modify, merge, publish, | 8 * without limitation the rights to use, copy, modify, merge, publish, |
9 * distribute, sublicense, and/or sell copies of the Software, and to | 9 * distribute, sublicense, and/or sell copies of the Software, and to |
10 * permit persons to whom the Software is furnished to do so, subject to | 10 * permit persons to whom the Software is furnished to do so, subject to |
(...skipping 1388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1399 function rng_seed_int(x) { | 1399 function rng_seed_int(x) { |
1400 rng_pool[rng_pptr++] ^= x & 255; | 1400 rng_pool[rng_pptr++] ^= x & 255; |
1401 rng_pool[rng_pptr++] ^= (x >> 8) & 255; | 1401 rng_pool[rng_pptr++] ^= (x >> 8) & 255; |
1402 rng_pool[rng_pptr++] ^= (x >> 16) & 255; | 1402 rng_pool[rng_pptr++] ^= (x >> 16) & 255; |
1403 rng_pool[rng_pptr++] ^= (x >> 24) & 255; | 1403 rng_pool[rng_pptr++] ^= (x >> 24) & 255; |
1404 if(rng_pptr >= rng_psize) rng_pptr -= rng_psize; | 1404 if(rng_pptr >= rng_psize) rng_pptr -= rng_psize; |
1405 } | 1405 } |
1406 | 1406 |
1407 // Mix in the current time (w/milliseconds) into the pool | 1407 // Mix in the current time (w/milliseconds) into the pool |
1408 function rng_seed_time() { | 1408 function rng_seed_time() { |
1409 rng_seed_int(new Date().getTime()); | 1409 // Use pre-computed date to avoid making the benchmark |
| 1410 // results dependent on the current date. |
| 1411 rng_seed_int(1122926989487); |
1410 } | 1412 } |
1411 | 1413 |
1412 // Initialize the pool with junk if needed. | 1414 // Initialize the pool with junk if needed. |
1413 if(rng_pool == null) { | 1415 if(rng_pool == null) { |
1414 rng_pool = new Array(); | 1416 rng_pool = new Array(); |
1415 rng_pptr = 0; | 1417 rng_pptr = 0; |
1416 var t; | 1418 var t; |
1417 while(rng_pptr < rng_psize) { // extract some randomness from Math.random() | 1419 while(rng_pptr < rng_psize) { // extract some randomness from Math.random() |
1418 t = Math.floor(65536 * Math.random()); | 1420 t = Math.floor(65536 * Math.random()); |
1419 rng_pool[rng_pptr++] = t >>> 8; | 1421 rng_pool[rng_pptr++] = t >>> 8; |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1687 | 1689 |
1688 function decrypt() { | 1690 function decrypt() { |
1689 var RSA = new RSAKey(); | 1691 var RSA = new RSAKey(); |
1690 RSA.setPublic(nValue, eValue); | 1692 RSA.setPublic(nValue, eValue); |
1691 RSA.setPrivateEx(nValue, eValue, dValue, pValue, qValue, dmp1Value, dmq1Value,
coeffValue); | 1693 RSA.setPrivateEx(nValue, eValue, dValue, pValue, qValue, dmp1Value, dmq1Value,
coeffValue); |
1692 var decrypted = RSA.decrypt(encrypted); | 1694 var decrypted = RSA.decrypt(encrypted); |
1693 if (decrypted != TEXT) { | 1695 if (decrypted != TEXT) { |
1694 throw new Error("Crypto operation failed"); | 1696 throw new Error("Crypto operation failed"); |
1695 } | 1697 } |
1696 } | 1698 } |
OLD | NEW |