mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-01-09 17:38:00 +00:00
Add mp_copy_integer_into function.
Even simpler than the existing mp_add_integer_into.
This commit is contained in:
parent
6b27999500
commit
20a9912c7c
8
mpint.c
8
mpint.c
@ -90,6 +90,14 @@ void mp_copy_into(mp_int *dest, mp_int *src)
|
|||||||
smemclr(dest->w + copy_nw, (dest->nw - copy_nw) * sizeof(BignumInt));
|
smemclr(dest->w + copy_nw, (dest->nw - copy_nw) * sizeof(BignumInt));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void mp_copy_integer_into(mp_int *r, uintmax_t n)
|
||||||
|
{
|
||||||
|
for (size_t i = 0; i < r->nw; i++) {
|
||||||
|
r->w[i] = (BignumInt)n;
|
||||||
|
n = (BIGNUM_INT_BYTES < sizeof(n)) ? n >> BIGNUM_INT_BITS : 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Conditional selection is done by negating 'which', to give a mask
|
* Conditional selection is done by negating 'which', to give a mask
|
||||||
* word which is all 1s if which==1 and all 0s if which==0. Then you
|
* word which is all 1s if which==1 and all 0s if which==0. Then you
|
||||||
|
3
mpint.h
3
mpint.h
@ -176,9 +176,10 @@ mp_int *mp_max(mp_int *x, mp_int *y);
|
|||||||
void mp_dump(FILE *fp, const char *prefix, mp_int *x, const char *suffix);
|
void mp_dump(FILE *fp, const char *prefix, mp_int *x, const char *suffix);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Overwrite one mp_int with another.
|
* Overwrite one mp_int with another, or with a plain integer.
|
||||||
*/
|
*/
|
||||||
void mp_copy_into(mp_int *dest, mp_int *src);
|
void mp_copy_into(mp_int *dest, mp_int *src);
|
||||||
|
void mp_copy_integer_into(mp_int *dest, uintmax_t n);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Conditional selection. Overwrites dest with either src0 or src1,
|
* Conditional selection. Overwrites dest with either src0 or src1,
|
||||||
|
@ -349,12 +349,14 @@ class mpint(MyTestBase):
|
|||||||
|
|
||||||
x = mp_new(mp_max_bits(initial) + 64)
|
x = mp_new(mp_max_bits(initial) + 64)
|
||||||
|
|
||||||
# mp_{add,sub}_integer_into should be able to cope with any
|
# mp_{add,sub,copy}_integer_into should be able to cope with
|
||||||
# uintmax_t. Test a number that requires more than 32 bits.
|
# any uintmax_t. Test a number that requires more than 32 bits.
|
||||||
mp_add_integer_into(x, initial, 123123123123123)
|
mp_add_integer_into(x, initial, 123123123123123)
|
||||||
self.assertEqual(int(x), 4444444444567567567567567)
|
self.assertEqual(int(x), 4444444444567567567567567)
|
||||||
mp_sub_integer_into(x, initial, 123123123123123)
|
mp_sub_integer_into(x, initial, 123123123123123)
|
||||||
self.assertEqual(int(x), 4444444444321321321321321)
|
self.assertEqual(int(x), 4444444444321321321321321)
|
||||||
|
mp_copy_integer_into(x, 123123123123123)
|
||||||
|
self.assertEqual(int(x), 123123123123123)
|
||||||
|
|
||||||
# mp_mul_integer_into only takes a uint16_t integer input
|
# mp_mul_integer_into only takes a uint16_t integer input
|
||||||
mp_mul_integer_into(x, initial, 10001)
|
mp_mul_integer_into(x, initial, 10001)
|
||||||
|
@ -41,6 +41,7 @@ FUNC3(void, mp_and_into, val_mpint, val_mpint, val_mpint)
|
|||||||
FUNC3(void, mp_or_into, val_mpint, val_mpint, val_mpint)
|
FUNC3(void, mp_or_into, val_mpint, val_mpint, val_mpint)
|
||||||
FUNC3(void, mp_xor_into, val_mpint, val_mpint, val_mpint)
|
FUNC3(void, mp_xor_into, val_mpint, val_mpint, val_mpint)
|
||||||
FUNC3(void, mp_bic_into, val_mpint, val_mpint, val_mpint)
|
FUNC3(void, mp_bic_into, val_mpint, val_mpint, val_mpint)
|
||||||
|
FUNC2(void, mp_copy_integer_into, val_mpint, uint)
|
||||||
FUNC3(void, mp_add_integer_into, val_mpint, val_mpint, uint)
|
FUNC3(void, mp_add_integer_into, val_mpint, val_mpint, uint)
|
||||||
FUNC3(void, mp_sub_integer_into, val_mpint, val_mpint, uint)
|
FUNC3(void, mp_sub_integer_into, val_mpint, val_mpint, uint)
|
||||||
FUNC3(void, mp_mul_integer_into, val_mpint, val_mpint, uint)
|
FUNC3(void, mp_mul_integer_into, val_mpint, val_mpint, uint)
|
||||||
|
Loading…
Reference in New Issue
Block a user