Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First sketch for an easier configuration #301

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 0 additions & 103 deletions bn_conversion.c

This file was deleted.

15 changes: 15 additions & 0 deletions bn_mp_get_i32.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include "tommath_private.h"
#ifdef BN_MP_GET_I32_C
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
/* SPDX-License-Identifier: Unlicense */


/* Return the least significant 32 bits */
int32_t mp_get_i32(const mp_int *a)
{
uint64_t res = mp_get_mag32(a);
return (a->sign == MP_NEG) ? (int32_t)-res : (int32_t)res;
}


#endif
15 changes: 15 additions & 0 deletions bn_mp_get_i64.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include "tommath_private.h"
#ifdef BN_MP_GET_I64_C
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
/* SPDX-License-Identifier: Unlicense */


/* Return the least significant 64 bits */
int64_t mp_get_i64(const mp_int *a)
{
uint64_t res = mp_get_mag64(a);
return (a->sign == MP_NEG) ? (int64_t)-res : (int64_t)res;
}


#endif
21 changes: 21 additions & 0 deletions bn_mp_get_mag32.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include "tommath_private.h"
#ifdef BN_MP_GET_MAG32_C
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
/* SPDX-License-Identifier: Unlicense */


/* Return the absolute value of the least significant 32 bits */
uint32_t mp_get_mag32(const mp_int *a)
{
unsigned i = MP_MIN((unsigned)a->used, (unsigned)((32 + MP_DIGIT_BIT - 1) / MP_DIGIT_BIT));
uint32_t res = 0uL;
while (i-- > 0) {
res <<= ((32 <= MP_DIGIT_BIT) ? 0 : MP_DIGIT_BIT);
res |= (uint32_t)a->dp[i];
if (32 <= MP_DIGIT_BIT) {
break;
}
}
return res;
}
#endif
23 changes: 23 additions & 0 deletions bn_mp_get_mag64.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include "tommath_private.h"
#ifdef BN_MP_GET_MAG64_C
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
/* SPDX-License-Identifier: Unlicense */


/* Return the absolute value of the least significant 64 bits */
uint64_t mp_get_mag64(const mp_int *a)
{
unsigned i = MP_MIN((unsigned)a->used, (unsigned)((64 + MP_DIGIT_BIT - 1) / MP_DIGIT_BIT));
uint64_t res = 0uL;
while (i-- > 0) {
res <<= ((64 <= MP_DIGIT_BIT) ? 0 : MP_DIGIT_BIT);
res |= (uint64_t)a->dp[i];
if (64 <= MP_DIGIT_BIT) {
break;
}
}
return res;
}


#endif
19 changes: 19 additions & 0 deletions bn_mp_init_i32.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include "tommath_private.h"
#ifdef BN_MP_INIT_I32_C
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
/* SPDX-License-Identifier: Unlicense */


/* initialize "a" with a signed 32-bit integer */
mp_err mp_init_i32(mp_int *a, int32_t b)
{
mp_err err;
if ((err = mp_init(a)) != 0) {
return err;
}
mp_set_i32(a, b);
return 0;
}


#endif
19 changes: 19 additions & 0 deletions bn_mp_init_i64.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include "tommath_private.h"
#ifdef BN_MP_INIT_I64_C
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
/* SPDX-License-Identifier: Unlicense */


/* initialize "a" with a signed 64-bit integer */
mp_err mp_init_i64(mp_int *a, int64_t b)
{
mp_err err;
if ((err = mp_init(a)) != 0) {
return err;
}
mp_set_i64(a, b);
return 0;
}


#endif
20 changes: 20 additions & 0 deletions bn_mp_init_u32.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include "tommath_private.h"
#ifdef BN_MP_INIT_U32_C
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
/* SPDX-License-Identifier: Unlicense */


/* initialize "a" with an unsigned 32-bit integer */
mp_err mp_init_u32(mp_int *a, uint32_t b)
{
mp_err err;
if ((err = mp_init(a)) != 0) {
return err;
}
mp_set_u32(a, b);
return 0;
}



#endif
20 changes: 20 additions & 0 deletions bn_mp_init_u64.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include "tommath_private.h"
#ifdef BN_MP_INIT_U64_C
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
/* SPDX-License-Identifier: Unlicense */


/* initialize "a" with an unsigned 64-bit integer */
mp_err mp_init_u64(mp_int *a, uint64_t b)
{
mp_err err;
if ((err = mp_init(a)) != 0) {
return err;
}
mp_set_u64(a, b);
return 0;
}



#endif
15 changes: 15 additions & 0 deletions bn_mp_set_i32.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include "tommath_private.h"
#ifdef BN_MP_SET_I32_C
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
/* SPDX-License-Identifier: Unlicense */


/* Set the least signficant 32 bit of "a" to b, signed */
void mp_set_i32(mp_int *a, int32_t b)
{
mp_set_u32(a, (b < 0) ? -(uint32_t)b : (uint32_t)b);
if (b < 0) {
a->sign = MP_NEG;
}
}
#endif
17 changes: 17 additions & 0 deletions bn_mp_set_i64.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include "tommath_private.h"
#ifdef BN_MP_SET_I64_C
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
/* SPDX-License-Identifier: Unlicense */


/* Set the least signficant 64 bit of "a" to b, signed */
void mp_set_i64(mp_int *a, int64_t b)
{
mp_set_u64(a, (b < 0) ? -(uint64_t)b : (uint64_t)b);
if (b < 0) {
a->sign = MP_NEG;
}
}


#endif
22 changes: 22 additions & 0 deletions bn_mp_set_u32.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include "tommath_private.h"
#ifdef BN_MP_SET_U32_C
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
/* SPDX-License-Identifier: Unlicense */


/* Set the least signficant 32 bit of "a" to b, unsigned */
void mp_set_u32(mp_int *a, uint32_t b)
{
int i = 0;
while (b != 0u) {
a->dp[i++] = ((mp_digit)b & MP_MASK);
if (32 <= MP_DIGIT_BIT) {
break;
}
b >>= ((32 <= MP_DIGIT_BIT) ? 0 : MP_DIGIT_BIT);
}
a->used = i;
a->sign = MP_ZPOS;
MP_ZERO_DIGITS(a->dp + a->used, a->alloc - a->used);
}
#endif
24 changes: 24 additions & 0 deletions bn_mp_set_u64.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include "tommath_private.h"
#ifdef BN_MP_SET_U64_C
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
/* SPDX-License-Identifier: Unlicense */


/* Set the least signficant 64 bit of "a" to b, unsigned */
void mp_set_u64(mp_int *a, uint64_t b)
{
int i = 0;
while (b != 0u) {
a->dp[i++] = ((mp_digit)b & MP_MASK);
if (64 <= MP_DIGIT_BIT) {
break;
}
b >>= ((64 <= MP_DIGIT_BIT) ? 0 : MP_DIGIT_BIT);
}
a->used = i;
a->sign = MP_ZPOS;
MP_ZERO_DIGITS(a->dp + a->used, a->alloc - a->used);
}


#endif
Loading