Git Product home page Git Product logo

tomsfastmath's Introduction

tomsfastmath's People

Contributors

aewag avatar bchauvaux avatar jwillemsen avatar perlun avatar rasky avatar reinerh avatar sebastianas avatar sjaeckel avatar theraynman avatar timotheecour avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tomsfastmath's Issues

`cd doc && make` fails on osx

cd doc
make
cp tfm.tex tfm.bak
touch --reference=tfm.tex tfm.bak
touch: illegal option -- -
usage:
touch [-A [-][[hh]mm]SS] [-acfhm] [-r file] [-t [[CC]YY]MMDDhhmm[.SS]] file ...
make: *** [docdvi] Error 1

how to build on macos x86_64

ifndef SIGCLD
define SIGCLD SIGCHLD
endif
solved

2.src/mont/fp_montgomery_reduce.c:514:15: error: unknown register name '%cc' in
asm
INNERMUL8;

Can you please make a new release?

I'm trying to package Tomsfastmath for Homebrew, but the latest release (0.13.1) was published in April 2017, and requires patching in the Homebrew formula to build. There have also been a lot of changes since Tomsfastmath 0.13.1, in addition to a license change. Therefore, it would be great if you would publish a new release.

multiple precision

One thing we found productive is TFM can be fairly easily ported to be variable precision. This in turn saves a lot of memory at a small (trivial) cost in performance.

I can't contribute code (right now) but it's something that is worth looking into. It would also make FP_MAX_SIZE obsolete.

Buffer overflow in fp_read_unsigned_bin.c

If neither ENDIAN_BIG nor ENDIAN_LITTLE is defined, the following code is executed in fp_read_unsigned_bin

#else
  /* read the bytes in */
  for (; c > 0; c--) {
     fp_mul_2d (a, 8, a);
     a->dp[0] |= *b++;
     a->used += 1;
  }
#endif

This will overflow a->dp array if c is large enough. I implemented a local change by having fp_read_unsigned_bin return a failure status in such case but I see now that the code above seems to truncate the input.

Support mingw makefile

LibTomCrypt and LibTomMath come with mingw makefiles, thanks for that. Please add this makefile also for TomsFastMath.

fp_lshd/fp_rshd mistake

Hi Tom,
I am trying to perform left and right shift x digits via the functions fp_lshd and fp_rshd:

  fp_int a;

  fp_set(&a, 60); fp_print("", "\n", a, 10);
  fp_lshd(&a, 1); fp_print("", "\n", a, 10);

  fp_set(&a, 60); fp_print("", "\n", a, 10);
  fp_rshd(&a, 1); fp_print("", "\n", a, 10);

  printf("%d\n", (60 << 1));
  printf("%d\n", (60 >> 1));

The output is:

60
1106804644422573096960
60
0
120
30

fp_print defined as follows:

void fp_print(const char *start, const char *end, const fp_int u, int base)
{
  int size_u;
  fp_radix_size((fp_int *)&u, base, &size_u);
  char *buf_u = malloc(size_u);
  fp_toradix_n((fp_int *)&u, buf_u, base, size_u);
  printf("%s%s%s", start, buf_u, end);
}

Am I wrong using it?

Obviously my use case is for larger numbers

fp_iseven() implementation

Hi Tom

fp_iseven() appears a little incorrect to me, and it should be the following IMO:

diff --git a/src/headers/tfm.h b/src/headers/tfm.h
index 0d1dbf1..6f00c08 100644
--- a/src/headers/tfm.h
+++ b/src/headers/tfm.h
@@ -335,7 +335,7 @@ const char *fp_ident(void);
 
 /* zero/even/odd ? */
 #define fp_iszero(a) (((a)->used == 0) ? FP_YES : FP_NO)
-#define fp_iseven(a) (((a)->used >= 0 && (((a)->dp[0] & 1) == 0)) ? FP_YES : FP_NO)
+#define fp_iseven(a) (((a)->used == 0 || (((a)->dp[0] & 1) == 0)) ? FP_YES : FP_NO)
 #define fp_isodd(a)  (((a)->used > 0  && (((a)->dp[0] & 1) == 1)) ? FP_YES : FP_NO)
 
 /* set to a small digit */

Incorrect fp_exptmod result

Setting M to "2 ^ 4423 - 1", then "exptmod(3,M,M)" should give '3'.

The current code returns 1 from fp_exptmod, presumably because the modulus is so large.

#include "stdio.h"
#include "tfm.h"

void s_mp_sqr(fp_int *x)
{
	fp_int tmp;
	fp_init(&tmp);
	fp_sqr(x,&tmp);
	fp_copy(&tmp, x);
}

void fp_expt(fp_int *a, fp_int *b, fp_int *c)
{
	fp_int   s, x;
	fp_digit d;
	int      dig, bit;


	if (b->sign == FP_NEG)
		return ;

	fp_init(&s);

	fp_set(&s, 1);

	fp_init_copy(&x, a);

	/* Loop over low-order digits in ascending order */
	for(dig = 0; dig < (b->used - 1); dig++) {
		d = b->dp[dig];

		/* Loop over bits of each non-maximal digit */
		fp_int tmp;
		for(bit = 0; bit < DIGIT_BIT; bit++) {
			if(d & 1) {
				s.sign = FP_ZPOS;
				x.sign = FP_ZPOS;
				fp_init(&tmp);
				fp_mul(&s, &x, &tmp);
				fp_copy(&tmp, &s);
			}

			d >>= 1;

			s_mp_sqr(&x);
		}
	}

	/* Consider now the last digit... */
	d = b->dp[dig];

	fp_int tmp;
	while(d) {
		if(d & 1) {
			s.sign = x.sign = FP_ZPOS;
			fp_init(&tmp);
			fp_mul(&s, &x, &tmp);
			fp_copy(&tmp, &s);
		}

		d >>= 1;

		s_mp_sqr(&x);
	}

	if(fp_iseven(b))
		s.sign = FP_ZPOS;
	else
		s.sign = a->sign;

	fp_copy(&s, c);

} /* end fp_expt() */

int main(int argc, char ** argv )
{
	fp_int a,b,c,d;
	fp_init(&a);
	fp_init(&b);
	fp_init(&c);
	fp_init(&d);

	fp_set(&a, 3);
	fp_set(&b, 2);
	fp_set(&c, 4423);
	fp_expt(&b, &c, &d);
	fp_copy(&d, &b);

	fp_init(&d);
	int rc = fp_exptmod(&a, &b, &b, &d);

	int size=0;
	fp_radix_size(&d, 10, &size);
	char * outstr = (char *) malloc(size+1);
	fp_toradix(&d, outstr, 10);
	outstr[size] = '\0';
	printf("rc = %d, result (should be 3): %s\n", rc, outstr);
	return 0;
}

fp_sqr does not handle case when parameter a = 0

fp_sqr does not handle case when parameter a = 00....00

When a=00.....00 the result b is not updated.

Adding the following code after y = A->used; seems to resolve this
if (y==0) {
B->used = 0;
goto clean;
}

documentation does not mention fp_read_unsigned_bin

imo everybody intending to do any real-life work with tomsfastmath will require this function to import his binary private keys etc. it should be mentioned right after fp_init() and fp_set(). i spent about half an hour to search for this functionality in both tfm pdf and ltm pdf without success, and only found out by digging through the ltc rsa code.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.