bcrypt_hash function

void bcrypt_hash(
  1. Uint8List sha2pass,
  2. Uint8List sha2salt,
  3. Uint8List out
)

Implementation

void bcrypt_hash(Uint8List sha2pass, Uint8List sha2salt, Uint8List out) {
  final state = Blowfish();
  final cdata = Uint32List(BCRYPT_BLOCKS);
  final ciphertext =
      Uint8List.fromList('OxychromaticBlowfishSwatDynamite'.codeUnits);

  state.expandstate(sha2salt, 64, sha2pass, 64);
  for (var i = 0; i < 64; i++) {
    state.expand0state(sha2salt, 64);
    state.expand0state(sha2pass, 64);
  }

  for (var i = 0; i < BCRYPT_BLOCKS; i++) {
    cdata[i] = stream2word(ciphertext, ciphertext.lengthInBytes);
  }

  for (var i = 0; i < 64; i++) {
    state.enc(cdata, cdata.lengthInBytes ~/ 8);
  }

  for (var i = 0; i < BCRYPT_BLOCKS; i++) {
    out[4 * i + 3] = cdata[i] >>> 24;
    out[4 * i + 2] = cdata[i] >>> 16;
    out[4 * i + 1] = cdata[i] >>> 8;
    out[4 * i + 0] = cdata[i];
  }
}