sha384.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. 'use strict';
  2. var inherits = require('inherits');
  3. var SHA512 = require('./sha512');
  4. var Hash = require('./hash');
  5. var Buffer = require('safe-buffer').Buffer;
  6. var W = new Array(160);
  7. function Sha384() {
  8. this.init();
  9. this._w = W;
  10. Hash.call(this, 128, 112);
  11. }
  12. inherits(Sha384, SHA512);
  13. Sha384.prototype.init = function () {
  14. this._ah = 0xcbbb9d5d;
  15. this._bh = 0x629a292a;
  16. this._ch = 0x9159015a;
  17. this._dh = 0x152fecd8;
  18. this._eh = 0x67332667;
  19. this._fh = 0x8eb44a87;
  20. this._gh = 0xdb0c2e0d;
  21. this._hh = 0x47b5481d;
  22. this._al = 0xc1059ed8;
  23. this._bl = 0x367cd507;
  24. this._cl = 0x3070dd17;
  25. this._dl = 0xf70e5939;
  26. this._el = 0xffc00b31;
  27. this._fl = 0x68581511;
  28. this._gl = 0x64f98fa7;
  29. this._hl = 0xbefa4fa4;
  30. return this;
  31. };
  32. Sha384.prototype._hash = function () {
  33. var H = Buffer.allocUnsafe(48);
  34. function writeInt64BE(h, l, offset) {
  35. H.writeInt32BE(h, offset);
  36. H.writeInt32BE(l, offset + 4);
  37. }
  38. writeInt64BE(this._ah, this._al, 0);
  39. writeInt64BE(this._bh, this._bl, 8);
  40. writeInt64BE(this._ch, this._cl, 16);
  41. writeInt64BE(this._dh, this._dl, 24);
  42. writeInt64BE(this._eh, this._el, 32);
  43. writeInt64BE(this._fh, this._fl, 40);
  44. return H;
  45. };
  46. module.exports = Sha384;