MCPcopy Index your code
hub / github.com/dcodeIO/bcrypt.js / _crypt

Function _crypt

index.js:942–1023  ·  view source on GitHub ↗

* Internaly crypts a string. * @param {Array. } b Bytes to crypt * @param {Array. } salt Salt bytes to use * @param {number} rounds Number of rounds * @param {function(Error, Array. =)=} callback Callback receiving the error, if any, and the resulting bytes. If * omitted,

(b, salt, rounds, callback, progressCallback)

Source from the content-addressed store, hash-verified

940 * @inner
941 */
942function _crypt(b, salt, rounds, callback, progressCallback) {
943 var cdata = C_ORIG.slice(),
944 clen = cdata.length,
945 err;
946
947 // Validate
948 if (rounds < 4 || rounds > 31) {
949 err = Error("Illegal number of rounds (4-31): " + rounds);
950 if (callback) {
951 nextTick(callback.bind(this, err));
952 return;
953 } else throw err;
954 }
955 if (salt.length !== BCRYPT_SALT_LEN) {
956 err = Error(
957 "Illegal salt length: " + salt.length + " != " + BCRYPT_SALT_LEN,
958 );
959 if (callback) {
960 nextTick(callback.bind(this, err));
961 return;
962 } else throw err;
963 }
964 rounds = (1 << rounds) >>> 0;
965
966 var P,
967 S,
968 i = 0,
969 j;
970
971 //Use typed arrays when available - huge speedup!
972 if (typeof Int32Array === "function") {
973 P = new Int32Array(P_ORIG);
974 S = new Int32Array(S_ORIG);
975 } else {
976 P = P_ORIG.slice();
977 S = S_ORIG.slice();
978 }
979
980 _ekskey(salt, b, P, S);
981
982 /**
983 * Calcualtes the next round.
984 * @returns {Array.<number>|undefined} Resulting array if callback has been omitted, otherwise `undefined`
985 * @inner
986 */
987 function next() {
988 if (progressCallback) progressCallback(i / rounds);
989 if (i < rounds) {
990 var start = Date.now();
991 for (; i < rounds; ) {
992 i = i + 1;
993 _key(b, P, S);
994 _key(salt, P, S);
995 if (Date.now() - start > MAX_EXECUTION_TIME) break;
996 }
997 } else {
998 for (i = 0; i < 64; i++)
999 for (j = 0; j < clen >> 1; j++) _encipher(cdata, j << 1, P, S);

Callers 1

_hashFunction · 0.85

Calls 2

_ekskeyFunction · 0.85
nextFunction · 0.70

Tested by

no test coverage detected