src/crypto/p224.cc
// Reduce reduces the coefficients of in_out to smaller bounds.
//
// On entry: a[i] < 2**31 + 2**30
// On exit: a[i] < 2**29
Reduce reduces the coefficients of in_out to smaller bounds.
Reduce reduces the coefficients of in_out to smaller bounds .
void Reduce(FieldElement* in_out) {
  FieldElement& a = *in_out;
  for (int i = 0; i < 7; i++) {
    a[i+1] += a[i] >> 28;
    a[i] &= kBottom28Bits;
  }
  uint32_t top = a[7] >> 28;
  a[7] &= kBottom28Bits;
  uint32_t mask = top;
  mask |= mask >> 2;
  mask |= mask >> 1;
  mask <<= 31;
  mask = static_cast<uint32_t>(static_cast<int32_t>(mask) >> 31);
  a[0] -= top;
  a[3] += top << 12;
  a[3] -= 1 & mask;
  a[2] += mask & ((1<<28) - 1);
  a[1] += mask & ((1<<28) - 1);
  a[0] += mask & (1<<28);
}
void Reduce ( FieldElement * in_out ) { FieldElement & a = * in_out ; for ( int i = 0 ; i < 7 ; i ++ ) { a [ i + 1 ] += a [ i ] >> 28 ; a [ i ] &= kBottom28Bits ; } uint32_t top = a [ 7 ] >> 28 ; a [ 7 ] &= kBottom28Bits ; uint32_t mask = top ; mask |= mask >> 2 ; mask |= mask >> 1 ; mask <<= 31 ; mask = static_cast < uint32_t > ( static_cast < int32_t > ( mask ) >> 31 ) ; a [ 0 ] -= top ; a [ 3 ] += top << 12 ; a [ 3 ] -= 1 & mask ; a [ 2 ] += mask & ( ( 1 << 28 ) - 1 ) ; a [ 1 ] += mask & ( ( 1 << 28 ) - 1 ) ; a [ 0 ] += mask & ( 1 << 28 ) ; }
Reduce reduces the coefficients of in_out to smaller bounds.
Reduce reduces the coefficients of in_out to smaller bounds .
// top < 2**4 // Constant-time: mask = (top != 0) ? 0xffffffff : 0 // Eliminate top while maintaining the same value mod p. // We may have just made a[0] negative but, if we did, then we must // have added something to a[3], thus it's > 2**12. Therefore we can // carry down to a[0].