Commit 36d4b664 authored by Simo Sorce's avatar Simo Sorce Committed by Niels Möller

Add mpn_get_base256

Converts limbs to uint8_t buffer without conditional jumps.
Signed-off-by: default avatarSimo Sorce <simo@redhat.com>
parent 269649e6
...@@ -246,6 +246,37 @@ mpn_set_base256_le (mp_limb_t *rp, mp_size_t rn, ...@@ -246,6 +246,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 void
mpn_get_base256_le (uint8_t *rp, size_t rn, mpn_get_base256_le (uint8_t *rp, size_t rn,
const mp_limb_t *xp, mp_size_t xn) const mp_limb_t *xp, mp_size_t xn)
......
...@@ -57,6 +57,7 @@ ...@@ -57,6 +57,7 @@
#define mpz_set_n _nettle_mpz_set_n #define mpz_set_n _nettle_mpz_set_n
#define mpn_set_base256 _nettle_mpn_set_base256 #define mpn_set_base256 _nettle_mpn_set_base256
#define mpn_set_base256_le _nettle_mpn_set_base256_le #define mpn_set_base256_le _nettle_mpn_set_base256_le
#define mpn_get_base256 _nettle_mpn_get_base256
#define mpn_get_base256_le _nettle_mpn_get_base256_le #define mpn_get_base256_le _nettle_mpn_get_base256_le
#define gmp_alloc_limbs _nettle_gmp_alloc_limbs #define gmp_alloc_limbs _nettle_gmp_alloc_limbs
#define gmp_free_limbs _nettle_gmp_free_limbs #define gmp_free_limbs _nettle_gmp_free_limbs
...@@ -150,6 +151,10 @@ void ...@@ -150,6 +151,10 @@ void
mpn_set_base256_le (mp_limb_t *rp, mp_size_t rn, mpn_set_base256_le (mp_limb_t *rp, mp_size_t rn,
const uint8_t *xp, size_t xn); const uint8_t *xp, size_t xn);
void
mpn_get_base256 (uint8_t *rp, size_t rn,
const mp_limb_t *xp, mp_size_t xn);
void void
mpn_get_base256_le (uint8_t *rp, size_t rn, mpn_get_base256_le (uint8_t *rp, size_t rn,
const mp_limb_t *xp, mp_size_t xn); const mp_limb_t *xp, mp_size_t xn);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment