sha256.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // Copyright 2012 The Closure Library Authors. All Rights Reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS-IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. /**
  15. * @fileoverview SHA-256 cryptographic hash.
  16. *
  17. * Usage:
  18. * var sha256 = new goog.crypt.Sha256();
  19. * sha256.update(bytes);
  20. * var hash = sha256.digest();
  21. *
  22. */
  23. goog.provide('goog.crypt.Sha256');
  24. goog.require('goog.crypt.Sha2');
  25. /**
  26. * SHA-256 cryptographic hash constructor.
  27. *
  28. * @constructor
  29. * @extends {goog.crypt.Sha2}
  30. * @final
  31. * @struct
  32. */
  33. goog.crypt.Sha256 = function() {
  34. goog.crypt.Sha256.base(
  35. this, 'constructor', 8, goog.crypt.Sha256.INIT_HASH_BLOCK_);
  36. };
  37. goog.inherits(goog.crypt.Sha256, goog.crypt.Sha2);
  38. /** @private {!Array<number>} */
  39. goog.crypt.Sha256.INIT_HASH_BLOCK_ = [
  40. 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c,
  41. 0x1f83d9ab, 0x5be0cd19
  42. ];