Вам необходимо войти в систему или зарегистрироваться.
-
Loup Vaillant создал
This patch is meant to check that the invariants of carry propagation are respected. The invariants are such that operands are allowed to be added twice before carry propagation must happen (typically during a multiplication). For instance: x = constant1; // okay (1x) y = constant2; // okay (1x) a = x + y; // still okay (2x) b = a + x; // still okay (3x) c = b + y; // OVERFLOW (4x) The patch works by instrumenting fundamental field operations. We add a "carry limb" to field elements, which traces how far we've taken the addition chains. If we exceed 3, that's an overflow. - fe_0() set the carry limb to 0; - fe_1() and fe_frombytes() set the carry limb to 1; - fe_copy() copy the carry limb. - fe_cswap() and fe_ccopy() take the maximum of the carry limb, and copy it to the relevant operands. This guarantees an upper bound. - fe_mul_small(), fe_mul(), and fe_sq() actually perform carry propagation, so they reset the carry limb to 1. - fe_add() and fe_neg() add the carry limbs. Note that zeroes are interpreted as if they were ones. This allows us to leave the constants alone (C initialises unspecified elements with 0 when the array is not on the stack, and constants are all declared static). Two functions have stringer requirements on carry propagation. For them the carry limb must not exceed 1, and a stricter check is performed: - Some fast fe_sq2() implementations have slightly more stringent requirements on its inputs than the other functions. In practice, this matters neither for Monocypher nor SUPERCOP ref10, (i) in practice its input are always fully carried, and (ii) it felt prudent to apply the strict check in case. - The fe_tobytes() proof in SUPERCOP requires fully carried operands. While fe_tobytes() proper works correctly on a much wider range, it is both more prudent and easier on auditors to abide the original invariants, rather than come up with a new proof. If the tests fail no assert, that's pretty strong evidence that the code does not have any limb overflow problem. This assurance is even stronger when we pass the full test suite, with the sanitisers.3defe29c