code: function fermat(n, b) {
    b = b || new BN(2);
    return b.toRed(BN.mont(n)).redPow(n.subn(1)).fromRed().cmpn(1) === 0;
  }
docs: Tests whether n is probably prime or not using Fermat's test with b = 2.
  Fails if b^(n-1) mod n === 1.
  @param {BN}      n Number to test
  @param {Integer} b Optional Fermat test base
  @returns {boolean}