sha224.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. 'use strict';
  2. /**
  3. * A JavaScript implementation of the Secure Hash Algorithm, SHA-256, as defined
  4. * in FIPS 180-2
  5. * Version 2.2-beta Copyright Angel Marin, Paul Johnston 2000 - 2009.
  6. * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
  7. *
  8. */
  9. var inherits = require('inherits');
  10. var Sha256 = require('./sha256');
  11. var Hash = require('./hash');
  12. var Buffer = require('safe-buffer').Buffer;
  13. var W = new Array(64);
  14. function Sha224() {
  15. this.init();
  16. this._w = W; // new Array(64)
  17. Hash.call(this, 64, 56);
  18. }
  19. inherits(Sha224, Sha256);
  20. Sha224.prototype.init = function () {
  21. this._a = 0xc1059ed8;
  22. this._b = 0x367cd507;
  23. this._c = 0x3070dd17;
  24. this._d = 0xf70e5939;
  25. this._e = 0xffc00b31;
  26. this._f = 0x68581511;
  27. this._g = 0x64f98fa7;
  28. this._h = 0xbefa4fa4;
  29. return this;
  30. };
  31. Sha224.prototype._hash = function () {
  32. var H = Buffer.allocUnsafe(28);
  33. H.writeInt32BE(this._a, 0);
  34. H.writeInt32BE(this._b, 4);
  35. H.writeInt32BE(this._c, 8);
  36. H.writeInt32BE(this._d, 12);
  37. H.writeInt32BE(this._e, 16);
  38. H.writeInt32BE(this._f, 20);
  39. H.writeInt32BE(this._g, 24);
  40. return H;
  41. };
  42. module.exports = Sha224;