13 * This global symbol is also defined in ssh2kex-client.c, to ensure
14 * that these unsafe non-constant-time mp_int functions can't end up
15 * accidentally linked in to any PuTTY tool that actually makes an SSH
18 * (Only _client_ connections, however. Uppity, being a test server
21 const int deliberate_symbol_clash
= 12345;
23 static size_t mp_unsafe_words_needed(mp_int
*x
)
26 while (words
> 1 && !x
->w
[words
-1])
31 mp_int
*mp_unsafe_shrink(mp_int
*x
)
33 x
->nw
= mp_unsafe_words_needed(x
);
34 /* This potentially leaves some allocated words between the new
35 * and old values of x->nw, which won't be wiped by mp_free now
36 * that x->nw doesn't mention that they exist. But we've just
37 * checked they're all zero, so we don't need to wipe them now
42 mp_int
*mp_unsafe_copy(mp_int
*x
)
44 mp_int
*copy
= mp_make_sized(mp_unsafe_words_needed(x
));
45 mp_copy_into(copy
, x
);
49 uint32_t mp_unsafe_mod_integer(mp_int
*x
, uint32_t modulus
)
51 uint64_t accumulator
= 0;
52 for (size_t i
= mp_max_bytes(x
); i
-- > 0 ;) {
53 accumulator
= 0x100 * accumulator
+ mp_get_byte(x
, i
);
54 accumulator
%= modulus
;