code: function squareMod_(x, n) {
    var i, j, d, c, kx, kn, k;
    for (kx=x.length; kx>0 && !x[kx-1]; kx--);  //ignore leading zeros in x
    k=kx>n.length ? 2*kx : 2*n.length; //k=# elements in the product, which is twice the elements in the larger of x and n
    if (s0.length!=k)
      s0=new Array(k);
    copyInt_(s0, 0);
    for (i=0; i<kx; i++) {
      c=s0[2*i]+x[i]*x[i];
      s0[2*i]=c & mask;
      c>>=bpe;
      for (j=i+1; j<kx; j++) {
        c=s0[i+j]+2*x[i]*x[j]+c;
        s0[i+j]=(c & mask);
        c>>=bpe;
      }
      s0[i+kx]=c;
    }
    mod_(s0, n);
    copy_(x, s0);
  }
docs: do x=x*x mod n for bigInts x,n.