Skip to content

added integer log with positive integer base #174

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

Closed
wants to merge 19 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
44 changes: 40 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ matrix:
- libc6-dev-i386
sudo: required

# GCC for the 32-bit architecture (no valgrind yet)
- env: BUILDOPTIONS='--with-cc=gcc --with-m32 --cflags=-DLTM_USE_EXTRA_FUNCTIONS'
addons:
apt:
packages:
- libc6-dev-i386
sudo: required

# clang for the 32-bit architecture (no valgrind yet)
- env: BUILDOPTIONS='--with-cc=clang --with-m32'
addons:
Expand All @@ -73,6 +81,14 @@ matrix:
- libc6-dev-i386
sudo: required

# clang for the 32-bit architecture (no valgrind yet)
- env: BUILDOPTIONS='--with-cc=clang --with-m32 --cflags=-DLTM_USE_EXTRA_FUNCTIONS'
addons:
apt:
packages:
- libc6-dev-i386
sudo: required

# GCC for the x64_32 architecture (32-bit longs and 32-bit pointers)
# TODO: Probably not possible to run anything in x32 in Travis
# but needs to be checked to be sure.
Expand All @@ -83,6 +99,14 @@ matrix:
- libc6-dev-x32
sudo: required

- env: BUILDOPTIONS='--with-cc=gcc --with-mx32 --cflags=-DLTM_USE_EXTRA_FUNCTIONS'
addons:
apt:
packages:
- libc6-dev-x32
sudo: required


# clang for the x64_32 architecture
- env: BUILDOPTIONS='--with-cc=clang --with-mx32'
addons:
Expand All @@ -91,22 +115,38 @@ matrix:
- libc6-dev-x32
sudo: required

- env: BUILDOPTIONS='--with-cc=clang --with-mx32 --cflags=-DLTM_USE_EXTRA_FUNCTIONS'
addons:
apt:
packages:
- libc6-dev-x32
sudo: required

# GCC for the x86-64 architecture (64-bit longs and 64-bit pointers)
- env: BUILDOPTIONS='--with-cc=gcc --with-m64 --with-valgrind'
- env: BUILDOPTIONS='--with-cc=gcc --with-m64 --with-valgrind --cflags=-DLTM_USE_EXTRA_FUNCTIONS'
# clang for x86-64 architecture (64-bit longs and 64-bit pointers)
- env: BUILDOPTIONS='--with-cc=clang --with-m64 --with-valgrind'
- env: BUILDOPTIONS='--with-cc=clang --with-m64 --with-valgrind --cflags=-DLTM_USE_EXTRA_FUNCTIONS'

# GCC for the x86-64 architecture with restricted limb sizes
# formerly started with the option "--with-low-mp" to testme.sh
# but testing all three in one run took to long and timed out.
- env: BUILDOPTIONS='--with-cc=gcc --cflags=-DMP_8BIT --with-valgrind'
- env: BUILDOPTIONS='--with-cc=gcc --cflags=-DMP_8BIT --with-valgrind --cflags=-DLTM_USE_EXTRA_FUNCTIONS'
- env: BUILDOPTIONS='--with-cc=gcc --cflags=-DMP_16BIT --with-valgrind'
- env: BUILDOPTIONS='--with-cc=gcc --cflags=-DMP_16BIT --with-valgrind --cflags=-DLTM_USE_EXTRA_FUNCTIONS'
- env: BUILDOPTIONS='--with-cc=gcc --cflags=-DMP_32BIT --with-valgrind'
- env: BUILDOPTIONS='--with-cc=gcc --cflags=-DMP_32BIT --with-valgrind --cflags=-DLTM_USE_EXTRA_FUNCTIONS'


# clang for the x86-64 architecture with restricted limb sizes
- env: BUILDOPTIONS='--with-cc=clang --cflags=-DMP_8BIT --with-valgrind'
- env: BUILDOPTIONS='--with-cc=clang --cflags=-DMP_8BIT --with-valgrind --cflags=-DLTM_USE_EXTRA_FUNCTIONS'
- env: BUILDOPTIONS='--with-cc=clang --cflags=-DMP_16BIT --with-valgrind'
- env: BUILDOPTIONS='--with-cc=clang --cflags=-DMP_16BIT --with-valgrind --cflags=-DLTM_USE_EXTRA_FUNCTIONS'
- env: BUILDOPTIONS='--with-cc=clang --cflags=-DMP_32BIT --with-valgrind'
- env: BUILDOPTIONS='--with-cc=clang --cflags=-DMP_32BIT --with-valgrind --cflags=-DLTM_USE_EXTRA_FUNCTIONS'

# GCC for the x86-64 architecture testing against a different Bigint-implementation
# with 333333 different inputs.
Expand All @@ -124,10 +164,6 @@ notifications:
irc: "chat.freenode.net#libtom-notifications"

# The actual script the jobs run.
# Because of a default timeout of 10 minutes it was necessary to use
# a Travis tool to extend that timeout to 40 minutes. 50 minutes
# seem to be the max and 20 the default if travis_wait is called without
# any options.
script:
- ./testme.sh ${BUILDOPTIONS}

46 changes: 46 additions & 0 deletions bn_mp_decr.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include "tommath_private.h"
#ifdef BN_MP_DECR_C
/* LibTomMath, multiple-precision integer library -- Tom St Denis
*
* LibTomMath is a library that provides multiple-precision
* integer arithmetic as well as number theoretic functionality.
*
* The library was designed directly after the MPI library by
* Michael Fromberger but has been written from scratch with
* additional optimizations in place.
*
* SPDX-License-Identifier: Unlicense
*/

/* Decrement "a" by one like "a--". Changes input! */
#ifdef LTM_USE_EXTRA_FUNCTIONS
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO this macro can be removed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It changes the input, not a very common thing in LibTomMath, so I was a bit cautious here.

But if that (remove the macro for this function and this function only) is not what you meant drop me a note please.

int mp_decr(mp_int *a)
{
int e;
if (IS_ZERO(a)) {
mp_set(a,1uL);
a->sign = MP_NEG;
return MP_OKAY;
} else if (a->sign == MP_NEG) {
a->sign = MP_ZPOS;
if ((e = mp_incr(a)) != MP_OKAY) {
a->sign = MP_NEG;
return e;
}
a->sign = MP_NEG;
return MP_OKAY;
} else if ((a->used == 1) && (a->dp[0] > 1uL)) {
a->dp[0]--;
if (a->dp[0] == 0) {
mp_zero(a);
}
return MP_OKAY;
} else {
return mp_sub_d(a, 1uL,a);
}
}
#endif
#endif
/* ref: \$Format:\%D$ */
/* git commit: \$Format:\%H$ */
/* commit time: \$Format:\%ai$ */
63 changes: 63 additions & 0 deletions bn_mp_expt.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#include "tommath_private.h"
#ifdef BN_MP_EXPT_C
/* LibTomMath, multiple-precision integer library -- Tom St Denis
*
* LibTomMath is a library that provides multiple-precision
* integer arithmetic as well as number theoretic functionality.
*
* The library was designed directly after the MPI library by
* Michael Fromberger but has been written from scratch with
* additional optimizations in place.
*
* SPDX-License-Identifier: Unlicense
*/

/* exponentiate a^b = c with a, b, c big integers */
int mp_expt(const mp_int *a, const mp_int *b, mp_int *c)
{
mp_int tmp,e;
int err;

/* only positive exponents for now */
if (b->sign == MP_NEG) {
return MP_VAL;
}

if ((err = mp_init_multi(&tmp,&e,NULL)) != MP_OKAY) {
return err;
}
if ((err = mp_copy(a,&tmp)) != MP_OKAY) {
return err;
}
if ((err = mp_copy(b,&e)) != MP_OKAY) {
return err;
}
if ((err = mp_set_int(c,1)) != MP_OKAY) {
return err;
}
while (!IS_ZERO(&e)) {
if (mp_isodd(&e)) {
if ((err = mp_mul(c,&tmp,c)) != MP_OKAY) {
return err;
}
}
if ((err = mp_div_2(&e, &e)) != MP_OKAY) {
return err;
}
if (!IS_ZERO(&e)) {
if ((err = mp_sqr(&tmp,&tmp)) != MP_OKAY) {
return err;
}
}
}
if (a->sign == MP_NEG) {
c->sign = (mp_isodd(b))?MP_NEG:MP_ZPOS;
}
mp_clear_multi(&tmp,&e,NULL);
return MP_OKAY;
}

#endif
/* ref: \$Format:\%D$ */
/* git commit: \$Format:\%H$ */
/* commit time: \$Format:\%ai$ */
Loading