1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-09 17:38:00 +00:00

mpint: add mp_lshift_fixed().

This is a version of mp_lshift_fixed_into() which allocates the output
number, which it can do because you know the size of the original
number and are allowed to treat the shift count as non-secret.

(By contrast, mp_lshift_safe() would be a nonsensical function - if
you're trying to keep the shift count secret, you _can't_ use it as a
parameter of memory allocation! In that situation you have no choice
but to allocate memory based on a fixed upper bound.)
This commit is contained in:
Simon Tatham 2020-02-21 19:51:31 +00:00
parent 18678ba9bc
commit d4a4111fec
2 changed files with 9 additions and 0 deletions

View File

@ -1115,6 +1115,14 @@ void mp_rshift_fixed_into(mp_int *r, mp_int *a, size_t bits)
}
}
mp_int *mp_lshift_fixed(mp_int *x, size_t bits)
{
size_t words = (bits + BIGNUM_INT_BITS - 1) / BIGNUM_INT_BITS;
mp_int *r = mp_make_sized(x->nw + words);
mp_lshift_fixed_into(r, x, bits);
return r;
}
mp_int *mp_rshift_fixed(mp_int *x, size_t bits)
{
size_t words = bits / BIGNUM_INT_BITS;

View File

@ -383,6 +383,7 @@ mp_int *mp_rshift_safe(mp_int *x, size_t shift);
*/
void mp_lshift_fixed_into(mp_int *r, mp_int *a, size_t shift);
void mp_rshift_fixed_into(mp_int *r, mp_int *x, size_t shift);
mp_int *mp_lshift_fixed(mp_int *x, size_t shift);
mp_int *mp_rshift_fixed(mp_int *x, size_t shift);
/*