diff options
author | Simo Sorce <simo@redhat.com> | 2018-11-12 13:59:06 -0500 |
---|---|---|
committer | Niels Möller <nisse@lysator.liu.se> | 2018-11-25 10:23:17 +0100 |
commit | 36d4b664adba3a927b1708d68f4754e90997b42f (patch) | |
tree | 00e344e10c427343fc127311ed13674fbe365756 /gmp-glue.c | |
parent | 269649e6a467537837cfe635a9496879dccea9ff (diff) | |
download | nettle-36d4b664adba3a927b1708d68f4754e90997b42f.tar.gz |
Add mpn_get_base256
Converts limbs to uint8_t buffer without conditional jumps.
Signed-off-by: Simo Sorce <simo@redhat.com>
Diffstat (limited to 'gmp-glue.c')
-rw-r--r-- | gmp-glue.c | 31 |
1 files changed, 31 insertions, 0 deletions
@@ -247,6 +247,37 @@ mpn_set_base256_le (mp_limb_t *rp, mp_size_t rn, } void +mpn_get_base256 (uint8_t *rp, size_t rn, + const mp_limb_t *xp, mp_size_t xn) +{ + unsigned bits; + mp_limb_t in; + for (bits = in = 0; xn > 0 && rn > 0; ) + { + if (bits >= 8) + { + rp[--rn] = in; + in >>= 8; + bits -= 8; + } + else + { + uint8_t old = in; + in = *xp++; + xn--; + rp[--rn] = old | (in << bits); + in >>= (8 - bits); + bits += GMP_NUMB_BITS - 8; + } + } + while (rn > 0) + { + rp[--rn] = in; + in >>= 8; + } +} + +void mpn_get_base256_le (uint8_t *rp, size_t rn, const mp_limb_t *xp, mp_size_t xn) { |