MCPcopy Index your code
hub / github.com/bcrypt-ruby/bcrypt-ruby / crypt_raw

Method crypt_raw

ext/jruby/bcrypt_jruby/BCrypt.java:689–723  ·  view source on GitHub ↗

Perform the central password hashing step in the bcrypt scheme @param password the password to hash @param salt the binary salt to hash with the password @param log_rounds the binary logarithm of the number of rounds of hashing to apply @param sign_ext_bug true to implement the 2x bug @param safety

(byte password[], byte salt[], int log_rounds,
							boolean sign_ext_bug, int safety)

Source from the content-addressed store, hash-verified

687 * @return an array containing the binary hashed password
688 */
689 private byte[] crypt_raw(byte password[], byte salt[], int log_rounds,
690 boolean sign_ext_bug, int safety) {
691 long rounds;
692 int i, j;
693 int cdata[] = bf_crypt_ciphertext.clone();
694 int clen = cdata.length;
695 byte ret[];
696
697 if (log_rounds < 4 || log_rounds > 31)
698 throw new IllegalArgumentException ("Bad number of rounds");
699 rounds = roundsForLogRounds(log_rounds);
700 if (salt.length != BCRYPT_SALT_LEN)
701 throw new IllegalArgumentException ("Bad salt length");
702
703 init_key();
704 ekskey(salt, password, sign_ext_bug, safety);
705 for (long r = 0; r < rounds; r++) {
706 key(password, sign_ext_bug, safety);
707 key(salt, false, safety);
708 }
709
710 for (i = 0; i < 64; i++) {
711 for (j = 0; j < (clen >> 1); j++)
712 encipher(cdata, j << 1);
713 }
714
715 ret = new byte[clen * 4];
716 for (i = 0, j = 0; i < clen; i++) {
717 ret[j++] = (byte) ((cdata[i] >> 24) & 0xff);
718 ret[j++] = (byte) ((cdata[i] >> 16) & 0xff);
719 ret[j++] = (byte) ((cdata[i] >> 8) & 0xff);
720 ret[j++] = (byte) (cdata[i] & 0xff);
721 }
722 return ret;
723 }
724
725 /**
726 * Hash a password using the OpenBSD bcrypt scheme

Callers 1

hashpwMethod · 0.95

Calls 5

roundsForLogRoundsMethod · 0.95
init_keyMethod · 0.95
ekskeyMethod · 0.95
keyMethod · 0.95
encipherMethod · 0.95

Tested by

no test coverage detected