github.com/jincm/wesharechain@v0.0.0-20210122032815-1537409ce26a/app/lib/crypto1/sha1/sha1.js (about)

     1  /*!
     2   * Crypto-JS v1.1.0
     3   * http://code.google.com/p/crypto-js/
     4   * Copyright (c) 2009, Jeff Mott. All rights reserved.
     5   * http://code.google.com/p/crypto-js/wiki/License
     6   */
     7  (function(){
     8  
     9  // Shortcut
    10  var util = Crypto.util;
    11  
    12  // Public API
    13  var SHA1 = Crypto.SHA1 = function (message, options) {
    14  	var digestbytes = util.wordsToBytes(SHA1._sha1(message));
    15  	return options && options.asBytes ? digestbytes :
    16  	       options && options.asString ? util.bytesToString(digestbytes) :
    17  	       util.bytesToHex(digestbytes);
    18  };
    19  
    20  // The core
    21  SHA1._sha1 = function (message) {
    22  
    23  	var m  = util.stringToWords(message),
    24  	    l  = message.length * 8,
    25  	    w  =  [],
    26  	    H0 =  1732584193,
    27  	    H1 = -271733879,
    28  	    H2 = -1732584194,
    29  	    H3 =  271733878,
    30  	    H4 = -1009589776;
    31  
    32  	// Padding
    33  	m[l >> 5] |= 0x80 << (24 - l % 32);
    34  	m[((l + 64 >>> 9) << 4) + 15] = l;
    35  
    36  	for (var i = 0; i < m.length; i += 16) {
    37  
    38  		var a = H0,
    39  		    b = H1,
    40  		    c = H2,
    41  		    d = H3,
    42  		    e = H4;
    43  
    44  		for (var j = 0; j < 80; j++) {
    45  
    46  			if (j < 16) w[j] = m[i + j];
    47  			else {
    48  				var n = w[j-3] ^ w[j-8] ^ w[j-14] ^ w[j-16];
    49  				w[j] = (n << 1) | (n >>> 31);
    50  			}
    51  
    52  			var t = ((H0 << 5) | (H0 >>> 27)) + H4 + (w[j] >>> 0) + (
    53  			         j < 20 ? (H1 & H2 | ~H1 & H3) + 1518500249 :
    54  			         j < 40 ? (H1 ^ H2 ^ H3) + 1859775393 :
    55  			         j < 60 ? (H1 & H2 | H1 & H3 | H2 & H3) - 1894007588 :
    56  			                  (H1 ^ H2 ^ H3) - 899497514);
    57  
    58  			H4 =  H3;
    59  			H3 =  H2;
    60  			H2 = (H1 << 30) | (H1 >>> 2);
    61  			H1 =  H0;
    62  			H0 =  t;
    63  
    64  		}
    65  
    66  		H0 += a;
    67  		H1 += b;
    68  		H2 += c;
    69  		H3 += d;
    70  		H4 += e;
    71  
    72  	}
    73  
    74  	return [H0, H1, H2, H3, H4];
    75  
    76  };
    77  
    78  // Package private blocksize
    79  SHA1._blocksize = 16;
    80  
    81  })();