Re: [libtom] libtomcrypt + libtommath on 64bit MS Windows

729 views
Skip to first unread message

Derek Godfrey

unread,
Apr 18, 2013, 9:25:44 AM4/18/13
to <libtom@googlegroups.com>
Yes mp_digit is supposed to be ~32 bit and mp_word ~64 for 64 bit machine that is mp_digit * mp_digit fits in a mp_word. (30bit * 30bit -> 60 bit)
There is a comment explaining this before the typedefs.

-Derek

On Apr 17, 2013, at 1:50 PM, Karel Miko <karel...@gmail.com<mailto:karel...@gmail.com>> wrote:

Hi,

does anybody tried to build libtomcrypt + libtommath on 64bit MS Windows?

I am trying 64bit mingw-w64 gcc compiler

*/ some tweaking with mp_digit's typedef was necessary ('unsigned long' is only 32bit on Win64)

*/ even after I managed to compile libtommath without warnings libtomcrypt's rsa implementation does not seem to work correctly (it gives incorrect results)

--
Karel

--
You received this message because you are subscribed to the Google Groups "LibTom Projects" group.
To unsubscribe from this group and stop receiving emails from it, send an email to libtom+un...@googlegroups.com<mailto:libtom+un...@googlegroups.com>.
To post to this group, send email to lib...@googlegroups.com<mailto:lib...@googlegroups.com>.
Visit this group at http://groups.google.com/group/libtom?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.



Karel Miko

unread,
Apr 18, 2013, 4:03:34 PM4/18/13
to lib...@googlegroups.com, dgod...@gracenote.com
My interpretation of tommath.h was that on 64bit architecture
*/ DIGIT_BIT is expected to be 60
*/ mp_digit should be 64bit unsigned int
*/ mp_word should be 128bit unsigned int
(of course I might be completely wrong)

The trouble (or at least one of them) is that 'typedef unsigned long      mp_digit'
*/ is 64bit on linux/x86_64
*/ but only 32bit on Windows/x86_64

--
Karel

Karel Miko

unread,
Apr 18, 2013, 4:20:18 PM4/18/13
to lib...@googlegroups.com, dgod...@gracenote.com
Anyway - you were right. My new rebuild with:

#ifdef __WIN64
   typedef unsigned long       mp_digit;
   typedef unsigned long long  mp_word;
   #define DIGIT_BIT           28
   #define MP_28BIT
#endif

works but I am still in doubts whether this setup is using the whole potential of 64bit architecture.

Thanks for your hint.

--
Karel

Derek Godfrey

unread,
Apr 18, 2013, 5:02:02 PM4/18/13
to Karel Miko, lib...@googlegroups.com
Unless you wish to use the mantissa of the floating point types (I have done that for a javascript version of libtommath) or use 64 bit for mp_digit and have
a windows compiler that allows you to use the MMX 128 bit instructions in a C type (that can be done for recent gcc non-windows -
this is what 'typedef unsigned long fp_word __attribute__ ((mode(TI)));' is) then yes. In theory using twice
as many bits could gain you 4 times the performance.

-Derek

Steffen Jaeckel

unread,
Apr 19, 2013, 4:38:22 AM4/19/13
to Karel Miko, lib...@googlegroups.com
Hi Karel,

you can have a look at these two branches.

https://github.com/libtom/libtomcrypt/commits/fix/mingw64
https://github.com/libtom/libtommath/commits/fix/mingw64

The changes aren't really fixes, since they simply disable the
optimizations, but it works for me with the cygwin stock mingw 64bit
gcc.

> $ x86_64-w64-mingw32-gcc -v
> Using built-in specs.
> COLLECT_GCC=x86_64-w64-mingw32-gcc
> COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-w64-mingw32/4.5.3/lto-wrapper.exe
> Target: x86_64-w64-mingw32
> Configured with: ...
> Thread model: win32
> gcc version 4.5.3 (GCC)

Both, testme.sh for LTC and "test vs mtest" for LTM finish successfully!

> $ x86_64-w64-mingw32-objdump.exe -t test.exe
> test.exe: file format pei-x86-64


There's still a warning left in src/prngs/rng_get_bytes.c but I
currently don't have the time to fix it.

The same for bn_mp_get_int.c and bn_mp_reduce.c when trying to use
MP_64BIT.


Any feedback?
Volunteers to fix the issues?


Steffen
--
Steffen Jaeckel
www.libtom.org https://github.com/libtom
#libtom on irc.freenode.net

Reply all
Reply to author
Forward
0 new messages