Merge branch 'release/0.13.1'

This commit is contained in:
Steffen Jaeckel 2017-04-04 12:24:49 +02:00
commit e3b0c71363
11 changed files with 101 additions and 13 deletions

View File

@ -28,5 +28,5 @@ after_failure:
after_script: after_script:
- cat test_gcc_2.txt - cat test_gcc_2.txt
notifications: notifications:
irc: "chat.freenode.net#libtom" irc: "chat.freenode.net#libtom-notifications"

View File

@ -9,3 +9,4 @@ Project Status
master: [![Build Status](https://travis-ci.org/libtom/tomsfastmath.svg?branch=master)](https://travis-ci.org/libtom/tomsfastmath) master: [![Build Status](https://travis-ci.org/libtom/tomsfastmath.svg?branch=master)](https://travis-ci.org/libtom/tomsfastmath)
develop: [![Build Status](https://travis-ci.org/libtom/tomsfastmath.svg?branch=develop)](https://travis-ci.org/libtom/tomsfastmath)

View File

@ -1,3 +1,9 @@
April 4th, 2017
v0.13.1
-- Fix missing fp_rand symbol in shared library
-- Fix some parameters in API signatures that should've been const
-- Bugfixes and improvements contributed by Sebastian Siewior, Reiner Herrmann and Mathias Tausig
October 24th, 2015 October 24th, 2015
v0.13.0 v0.13.0
-- Add fp_rand() -- Add fp_rand()

Binary file not shown.

View File

@ -31,6 +31,7 @@ fp_mul_d
fp_mulmod fp_mulmod
fp_prime_random_ex fp_prime_random_ex
fp_radix_size fp_radix_size
fp_rand
fp_read_radix fp_read_radix
fp_read_signed_bin fp_read_signed_bin
fp_read_unsigned_bin fp_read_unsigned_bin

View File

@ -1,7 +1,7 @@
#makefile for TomsFastMath #makefile for TomsFastMath
# #
# #
VERSION=0.13 VERSION=0.13.1
CFLAGS += -Wall -W -Wshadow -Isrc/headers CFLAGS += -Wall -W -Wshadow -Isrc/headers
@ -21,6 +21,22 @@ ifndef MAKE
MAKE=make MAKE=make
endif endif
ifeq ($V,1)
silent=
else
silent=@
endif
%.o: %.c
ifneq ($V,1)
@echo " * ${CC} $@"
endif
${silent} ${CC} ${CFLAGS} -c $< -o $@
ifdef COMPILE_DEBUG
#debug
CFLAGS += -g3
else
ifndef IGNORE_SPEED ifndef IGNORE_SPEED
CFLAGS += -O3 -funroll-loops CFLAGS += -O3 -funroll-loops
@ -32,6 +48,7 @@ CFLAGS += -O3 -funroll-loops
#speed #speed
CFLAGS += -fomit-frame-pointer CFLAGS += -fomit-frame-pointer
endif
endif endif
#START_INS #START_INS
@ -103,6 +120,11 @@ install: $(LIBNAME)
install -g $(GROUP) -o $(USER) $(LIBNAME) $(DESTDIR)$(LIBPATH) install -g $(GROUP) -o $(USER) $(LIBNAME) $(DESTDIR)$(LIBPATH)
install -g $(GROUP) -o $(USER) $(HEADERS_PUB) $(DESTDIR)$(INCPATH) install -g $(GROUP) -o $(USER) $(HEADERS_PUB) $(DESTDIR)$(INCPATH)
HEADER_FILES=$(notdir $(HEADERS_PUB))
uninstall:
rm $(DESTDIR)$(LIBPATH)/$(LIBNAME)
rm $(HEADER_FILES:%=$(DESTDIR)$(INCPATH)/%)
.PHONY: mtest .PHONY: mtest
mtest: $(LIBNAME) mtest: $(LIBNAME)
cd mtest; CC="$(CC)" CFLAGS="$(CFLAGS) -I../" MAKE=${MAKE} ${MAKE} mtest cd mtest; CC="$(CC)" CFLAGS="$(CFLAGS) -I../" MAKE=${MAKE} ${MAKE} mtest
@ -189,9 +211,10 @@ zipup:
rm -rf ../tomsfastmath-$(VERSION) && rm -f ../tfm-$(VERSION).zip ../tfm-$(VERSION).tar.bz2 && \ rm -rf ../tomsfastmath-$(VERSION) && rm -f ../tfm-$(VERSION).zip ../tfm-$(VERSION).tar.bz2 && \
expsrc.sh -i . -o ../tomsfastmath-$(VERSION) --svntags --no-fetch -p '*.c' -p '*.h' && \ expsrc.sh -i . -o ../tomsfastmath-$(VERSION) --svntags --no-fetch -p '*.c' -p '*.h' && \
MAKE=${MAKE} ${MAKE} -C ../tomsfastmath-$(VERSION) docs && \ MAKE=${MAKE} ${MAKE} -C ../tomsfastmath-$(VERSION) docs && \
tar -c ../tomsfastmath-$(VERSION)/* | bzip2 -9vvc > ../tfm-$(VERSION).tar.bz2 && \ tar -c ../tomsfastmath-$(VERSION)/* | xz -cz > ../tfm-$(VERSION).tar.xz && \
find ../tomsfastmath-$(VERSION)/ -type f -exec unix2dos -q {} \; && \
zip -9 -r ../tfm-$(VERSION).zip ../tomsfastmath-$(VERSION)/* && \ zip -9 -r ../tfm-$(VERSION).zip ../tomsfastmath-$(VERSION)/* && \
gpg -b -a ../tfm-$(VERSION).tar.bz2 && gpg -b -a ../tfm-$(VERSION).zip gpg -b -a ../tfm-$(VERSION).tar.xz && gpg -b -a ../tfm-$(VERSION).zip
new_file: new_file:
bash updatemakes.sh bash updatemakes.sh

View File

@ -47,7 +47,8 @@ src/sqr/fp_sqr_comba_48.o src/sqr/fp_sqr_comba_4.o src/sqr/fp_sqr_comba_64.o src
src/sqr/fp_sqr_comba_7.o src/sqr/fp_sqr_comba_8.o src/sqr/fp_sqr_comba_9.o src/sqr/fp_sqr_comba.o \ src/sqr/fp_sqr_comba_7.o src/sqr/fp_sqr_comba_8.o src/sqr/fp_sqr_comba_9.o src/sqr/fp_sqr_comba.o \
src/sqr/fp_sqr_comba_generic.o src/sqr/fp_sqr_comba_small_set.o src/sqr/fp_sqrmod.o src/sqr/fp_sqr_comba_generic.o src/sqr/fp_sqr_comba_small_set.o src/sqr/fp_sqrmod.o
HEADERS=src/headers/tfm.h HEADERS_PUB:=src/headers/tfm.h
HEADERS=src/headers/tfm_private.h $(HEADERS_PUB)
#END_INS #END_INS
@ -88,13 +89,18 @@ $(OBJECTS): $(HEADERS)
$(LTCOMPILE) $(CFLAGS) $(LDFLAGS) -o $@ -c $< $(LTCOMPILE) $(CFLAGS) $(LDFLAGS) -o $@ -c $<
$(LIBNAME): $(OBJECTS) $(LIBNAME): $(OBJECTS)
libtool --silent --mode=link --tag=CC $(CC) $(CFLAGS) $(LDFLAGS) `find . -type f | grep "[.]lo" | xargs` -o $(LIBNAME) -rpath $(LIBPATH) -version-info $(VERSION) -export-symbols libtfm.symbols libtool --mode=link --tag=CC $(CC) $(CFLAGS) $(LDFLAGS) `find . -type f | LC_ALL=C sort | grep "[.]lo" | xargs` -o $(LIBNAME) -rpath $(LIBPATH) -version-info $(VERSION) -export-symbols libtfm.symbols
install: $(LIBNAME) install: $(LIBNAME)
install -d -g $(GROUP) -o $(USER) $(DESTDIR)$(LIBPATH) install -d -g $(GROUP) -o $(USER) $(DESTDIR)$(LIBPATH)
libtool --silent --mode=install install -c $(LIBNAME) $(DESTDIR)$(LIBPATH)/$(LIBNAME) libtool --mode=install install -c $(LIBNAME) $(DESTDIR)$(LIBPATH)/$(LIBNAME)
install -d -g $(GROUP) -o $(USER) $(DESTDIR)$(INCPATH) install -d -g $(GROUP) -o $(USER) $(DESTDIR)$(INCPATH)
install -g $(GROUP) -o $(USER) $(HEADERS) $(DESTDIR)$(INCPATH) install -g $(GROUP) -o $(USER) $(HEADERS_PUB) $(DESTDIR)$(INCPATH)
HEADER_FILES=$(notdir $(HEADERS_PUB))
uninstall:
libtool --mode=uninstall rm $(DESTDIR)$(LIBPATH)/$(LIBNAME)
rm $(HEADER_FILES:%=$(DESTDIR)$(INCPATH)/%)
mtest/mtest: mtest/mtest.c mtest/mtest: mtest/mtest.c
cd mtest ; make mtest cd mtest ; make mtest

View File

@ -9,6 +9,7 @@
*/ */
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv) int main(int argc, char **argv)
{ {

View File

@ -22,8 +22,8 @@
* Patch * Patch
* XX - undefined * XX - undefined
*/ */
#define TFM_VERSION 0x000D0000 #define TFM_VERSION 0x000D0100
#define TFM_VERSION_S "v0.13.0" #define TFM_VERSION_S "v0.13.1"
#ifndef MIN #ifndef MIN
#define MIN(x,y) ((x)<(y)?(x):(y)) #define MIN(x,y) ((x)<(y)?(x):(y))
@ -252,6 +252,17 @@
#endif #endif
#endif #endif
/* use arc4random on platforms that support it */
#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__DragonFly__)
#define FP_GEN_RANDOM() arc4random()
#define FP_GEN_RANDOM_MAX 0xffffffff
#endif
/* use rand() as fall-back if there's no better rand function */
#ifndef FP_GEN_RANDOM
#define FP_GEN_RANDOM() rand()
#define FP_GEN_RANDOM_MAX RAND_MAX
#endif
/* some default configurations. /* some default configurations.
*/ */

View File

@ -9,7 +9,31 @@
*/ */
#include <tfm_private.h> #include <tfm_private.h>
#if FP_GEN_RANDOM_MAX == 0xffffffff
#define FP_GEN_RANDOM_SHIFT 32
#elif FP_GEN_RANDOM_MAX == 32767
/* SHRT_MAX */
#define FP_GEN_RANDOM_SHIFT 15
#elif FP_GEN_RANDOM_MAX == 2147483647
/* INT_MAX */
#define FP_GEN_RANDOM_SHIFT 31
#elif !defined(FP_GEN_RANDOM_SHIFT)
#error Thou shalt define their own valid FP_GEN_RANDOM_SHIFT
#endif
/* makes a pseudo-random int of a given size */ /* makes a pseudo-random int of a given size */
static fp_digit fp_gen_random(void)
{
fp_digit d = 0, msk = 0;
do {
d <<= FP_GEN_RANDOM_SHIFT;
d |= ((fp_digit) FP_GEN_RANDOM());
msk <<= FP_GEN_RANDOM_SHIFT;
msk |= FP_GEN_RANDOM_MAX;
} while ((FP_MASK & msk) != FP_MASK);
d &= FP_MASK;
return d;
}
void fp_rand(fp_int *a, int digits) void fp_rand(fp_int *a, int digits)
{ {
@ -22,14 +46,14 @@ void fp_rand(fp_int *a, int digits)
/* first place a random non-zero digit */ /* first place a random non-zero digit */
do { do {
d = ((fp_digit) abs (rand ())) & FP_MASK; d = fp_gen_random();
} while (d == 0); } while (d == 0);
fp_add_d (a, d, a); fp_add_d (a, d, a);
while (--digits > 0) { while (--digits > 0) {
fp_lshd (a, 1); fp_lshd (a, 1);
fp_add_d (a, ((fp_digit) abs (rand ())), a); fp_add_d (a, fp_gen_random(), a);
} }
return; return;

17
tfm.tex
View File

@ -49,7 +49,7 @@
\begin{document} \begin{document}
\frontmatter \frontmatter
\pagestyle{empty} \pagestyle{empty}
\title{TomsFastMath User Manual \\ v0.13.0} \title{TomsFastMath User Manual \\ v0.13.1}
\author{Tom St Denis \\ tomstdenis@gmail.com} \author{Tom St Denis \\ tomstdenis@gmail.com}
\maketitle \maketitle
This text and library are all hereby placed in the public domain. This book has been formatted for B5 This text and library are all hereby placed in the public domain. This book has been formatted for B5
@ -279,6 +279,21 @@ void fp_init_copy(fp_int *a, fp_int *b)
This will initialize $a$ as a copy of $b$. Note that for compatibility with LibTomMath the function This will initialize $a$ as a copy of $b$. Note that for compatibility with LibTomMath the function
fp\_copy() is also provided. fp\_copy() is also provided.
\subsection{Initialization with a random value}
To initialize an integer with a random value of a specific length use the fp\_rand() function.
\index{fp\_rand}
\begin{verbatim}
void fp_rand(fp_int *a, int digits)
\end{verbatim}
This will initialize $a$ with $digits$ random digits.
\index{FP\_GEN\_RANDOM} \index{FP\_GEN\_RANDOM\_MAX}
The source of the random data is \textbf{arc4random()} on *BSD systems that provide this function
and the standard C function \textbf{rand()} on all other systems. It can be configured at compile time
by pre-defining \textbf{FP\_GEN\_RANDOM} and \textbf{FP\_GEN\_RANDOM\_MAX}.
\chapter{Arithmetic Operations} \chapter{Arithmetic Operations}
\section{Odds and Evens} \section{Odds and Evens}
To quickly and easily tell if an integer is zero, odd or even use the following functions. To quickly and easily tell if an integer is zero, odd or even use the following functions.