コード例 #1
0
ファイル: BCrypt.java プロジェクト: rikkert/casino-play
  /**
   * 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
   * @return an array containing the binary hashed password
   */
  private byte[] crypt_raw(byte password[], byte salt[], int log_rounds) {
    int rounds, i, j;
    int cdata[] = (int[]) bf_crypt_ciphertext.clone();
    int clen = cdata.length;
    byte ret[];

    if (log_rounds < 4 || log_rounds > 31)
      throw new IllegalArgumentException("Bad number of rounds");
    rounds = 1 << log_rounds;
    if (salt.length != BCRYPT_SALT_LEN) throw new IllegalArgumentException("Bad salt length");

    init_key();
    ekskey(salt, password);
    for (i = 0; i < rounds; i++) {
      key(password);
      key(salt);
    }

    for (i = 0; i < 64; i++) {
      for (j = 0; j < (clen >> 1); j++) encipher(cdata, j << 1);
    }

    ret = new byte[clen * 4];
    for (i = 0, j = 0; i < clen; i++) {
      ret[j++] = (byte) ((cdata[i] >> 24) & 0xff);
      ret[j++] = (byte) ((cdata[i] >> 16) & 0xff);
      ret[j++] = (byte) ((cdata[i] >> 8) & 0xff);
      ret[j++] = (byte) (cdata[i] & 0xff);
    }
    return ret;
  }