Dart Sha3 FIPS 202 基于pointycastle

dart项目中需要用到标准的sha3,用的是pointycastle的库,方法很多很全,但是这个库里面的sha3其实是Keccak ,注意看他的readme,“*Keccak is currently implemented as SHA3Digest.”,好吧,那只能自己实现了,其实并不复杂,在原来库中的sha3添加一个偏移量。

复制一份库中sha3,添加一个方法,在doFinal中添加这个方法

 void absorbBits(int data, int bits) {
    if (bits < 1 || bits > 7) {
      throw new StateError("'bits' must be in the range 1 to 7");
    }
    if ((_bitsInQueue % 8) != 0) {
      throw new StateError("attempt to absorb with odd length queue");
    }
    if (_squeezing) {
      throw new StateError("attempt to absorb while squeezing");
    }

    int mask = (1 << bits) - 1;
    _dataQueue[_bitsInQueue >> 3] = data & mask;
    _bitsInQueue += bits;
  }
 int doFinal(Uint8List out, int outOff) {
    absorbBits(0x02, 2);

    _squeeze(out, outOff, _fixedOutputLength);

    reset();

    return digestSize;
  }

就ok了

你可能感兴趣的:(Dart,Dart,Sha3,Keccak,pointycastle)