CryptoMath.js 793 B

12345678910111213141516171819202122232425262728293031323334353637
  1. (function(){
  2. var C = (typeof window === 'undefined') ? require('./Crypto').Crypto : window.Crypto;
  3. // Shortcut
  4. var util = C.util;
  5. // Convert n to unsigned 32-bit integer
  6. util.u32 = function (n) {
  7. return n >>> 0;
  8. };
  9. // Unsigned 32-bit addition
  10. util.add = function () {
  11. var result = this.u32(arguments[0]);
  12. for (var i = 1; i < arguments.length; i++)
  13. result = this.u32(result + this.u32(arguments[i]));
  14. return result;
  15. };
  16. // Unsigned 32-bit multiplication
  17. util.mult = function (m, n) {
  18. return this.add((n & 0xFFFF0000) * m,
  19. (n & 0x0000FFFF) * m);
  20. };
  21. // Unsigned 32-bit greater than (>) comparison
  22. util.gt = function (m, n) {
  23. return this.u32(m) > this.u32(n);
  24. };
  25. // Unsigned 32-bit less than (<) comparison
  26. util.lt = function (m, n) {
  27. return this.u32(m) < this.u32(n);
  28. };
  29. })();