sha224.js 1.0 KB

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