RSA support

421 views
Skip to first unread message

Daniel Misak

unread,
Aug 14, 2013, 6:27:20 AM8/14/13
to lib...@googlegroups.com
Hi LibTom Team,

I have downloaded the LibTomCrypt library and have been trying to do RSA encryption with it. First I was trying to run the rsa_test in the demo tests to see how it works, but the code did not work. After some research in the code I found that the RSA needs the tfm_desc as ltc_math_descriptor. Therefore I added the USE_TFM
to the provided makefile. However, it seemed that it was still not enough, I found that some functions of the TomsFastMath library are also used in functions of the LibTomCrypt library, but they are not included among the source files. After I added them as well to the makefile, I found that some LibTomMath functions are also necessary to run the RSA. After adding the LibTomMath library as well, the demo test was finally able to execute, but the results were not good. As I saw, the generated  p and q initial prime numbers for RSA were not prime (they were even...).

After that I tried to put some debug messages in some used functions to see where the execution goes wrong. 
For example the debug messages I put in the mp_read_unsigned_bin function of the LibTomMath library (it is used in rsa_make_key(...) --> rand_prime(...) --> mp_read_unsigned_bin(...) ), were not printed on the screen, even if I flushed the stdout. I saw in its source file that in order to be compiled, it needs the BN_MP_READ_UNSIGNED_BIN_C defined. As I see, it is defined (in tommath_class.h) because the LTM_ALL it requires is defined by default in the tommath_superclass.h file that is included in tommath_class.h. Also, neither of LTM1, LTM2 and LTM3 are defined, so all the tommath_class.h file is getting compiled. So to sum up, I don't understand why my messages are not getting printed and why the RSA calculation is wrong. Maybe I am missing some other defines or other files?

Thanks in advance for your answer,
Best regards,
Daniel Misak
--
Daniel Misak
Duolog Technologies Ltd.
H-1053 Budapest, Karolyi Mihaly u. 9.
Hungary
www.duolog.com

Steffen Jaeckel

unread,
Aug 14, 2013, 8:40:00 AM8/14/13
to Daniel Misak, lib...@googlegroups.com
> *Revolutionary Tools for IP/SoC Integration and Verification*
> *Evaluate the Socrates Tools instantly in the
> cloud<http://www.xuropa.com/company.php?comp_id=491>
> *
> Learn more about Duolog's Conference Programme - SOC Integration and
> Verification<http://www.duolog.com/duolog-is-exhibiting-at-the-49th-design-automation-conference-dac-san-francisco-ca-june-3-7/>

Hi Daniel,

please have a look at chapter 13 of the doc.

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

Daniel Misak

unread,
Aug 16, 2013, 6:54:47 AM8/16/13
to Steffen Jaeckel, lib...@googlegroups.com
Hi Steffen,

I installed it according to the document, but I still have an issue. Now every necessary source file is included from the additional libraries (TomsFastMath, LibTomMath), but the functions of the libtommath library that expect an input parameter of mp_int* type, freeze down on using the variable of that type.

Is it possible that maybe you can provide me a working example of RSA encryption of some random data? Maybe I'm missing some defines that skip compilation of some code parts or some necessary initialization that avoided my attention.

Thanks very much in advance for your answer,
Best regards,
Daniel

Larry Bugbee

unread,
Aug 17, 2013, 1:32:07 AM8/17/13
to lib...@googlegroups.com
------------------------------------------------
On Aug 16, 2013, at 3:54 AM, Daniel Misak wrote:

Hi Steffen,

I installed it according to the document, but I still have an issue. Now every necessary source file is included from the additional libraries (TomsFastMath, LibTomMath), but the functions of the libtommath library that expect an input parameter of mp_int* type, freeze down on using the variable of that type.

Is it possible that maybe you can provide me a working example of RSA encryption of some random data? Maybe I'm missing some defines that skip compilation of some code parts or some necessary initialization that avoided my attention.

Thanks very much in advance for your answer,
Best regards,
Daniel

Daniel,

Let's go back to basics.  What are you running?  CPU?  OS?  Compiler/linker?

Fm where and what versions did you download?  Did you get them fm here?

TFM can be problematic so let's set it aside for a moment.  

Build LTM with a simple "make clean install test timing".  What happens when you run "./test" and "./ltmtest"?  (If you have a 64-bit Intel processor you might want to build prefixing with "CFLAGS="-D__x86_64__" make ...".)

Now build LTC with "CFLAGS="-DLTM_DESC -DUSE_LTM" EXTRALIBS=-ltommath make clean install test timing".  What happens when you run "./test" and "./timing"?

Finally, rebuild your test app.  Did it all work?  

Are the speeds sufficient for your application?  

Larry







--
*** Please reply-to-all at all times ***
*** (do not pretend to know who is subscribed and who is not) ***
*** Please avoid top-posting. ***
---
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.
To post to this group, send email to lib...@googlegroups.com.
Visit this group at http://groups.google.com/group/libtom.
For more options, visit https://groups.google.com/groups/opt_out.

Matthis Hauschild

unread,
Aug 16, 2013, 10:50:46 AM8/16/13
to lib...@googlegroups.com
Hi Daniel,

does the RSA Encryption Example provided in the manual (see section 7.10) help you?

Here's an example on how to get it working with Tomsfastmath library. I don't install the libraries but just use them locally and statically linked:

I assume you always stay in one folder and execute everything from there (let's say ~/tmp).

1. Get LTC v1.17 and TFM 0.12 and unpack them.
    tar xfj tfm-0.12.tar.bz2
    tar xfj crypt-1.17.tar.bz2

2. Build both:
    make -Ctomsfastmath-0.12/
    CFLAGS="-DTFM_DESC -I../tomsfastmath-0.12/src/headers" make -Clibtomcrypt-1.17

3. Create your program "rsa_example.c" (see attachment)

4. Build and run it:
    gcc -o rsa_example -DTFM_DESC -Ilibtomcrypt-1.17/src/headers/ -Llibtomcrypt-1.17/ -Ltomsfastmath-0.12/ rsa_example.c -ltomcrypt -ltfm
    ./rsa_example

That works for me, hope I could help you with that.

Greetings,
Matthis



2013/8/16 Daniel Misak <daniel...@duolog.com>
rsa_example.c
Message has been deleted

m.lot...@gmail.com

unread,
Mar 17, 2017, 2:58:26 PM3/17/17
to LibTom Projects, daniel...@duolog.com
Hi LibTom Team,

I am trying to implement RSA encryption using LibTomCrypt for a project. I am able to compile the rsa_test program given in the document (I actually got help from steps given in this thread so Thank You for that!).
My problem is that I need to be able to test the implementations for RSA (and some other symmetric algorithm later) against the test vector files provided on NIST website, here:

http://csrc.nist.gov/groups/STM/cavp/component-testing.html#RSADP

I started with the RSADP test vectors that would apparently be used against the function  rsa_exptmod().  I am some issues here as the rsa_key structure requires p and q and the test file provides only n,e,d values plus k , data to be encrypted and c, the ciphertext. It also gives intermediate values before the mod operation.


Has any one written tests to run with the test vectors from NIST website and if yes  will appreciate any pointers regarding the same.


Thanks!
Mrinali

1.)  

Steffen Jaeckel

unread,
Mar 20, 2017, 2:28:52 PM3/20/17
to lib...@googlegroups.com, daniel...@duolog.com
Hi Mrinali,

On 17.03.2017 19:58, m.lot...@gmail.com wrote:
> Hi LibTom Team,
>
> I am trying to implement RSA encryption using LibTomCrypt for a project.

Uhm, that's already there?

> I am able to compile the rsa_test program given in the document (I
> actually got help from steps given in this thread so Thank You for that!).
> My problem is that I need to be able to test the implementations for RSA
> (and some other symmetric algorithm later) against the test vector files
> provided on NIST website, here:
>
> http://csrc.nist.gov/groups/STM/cavp/component-testing.html#RSADP

That's also already there (at least all the PKCS testvectors (c.f.
https://github.com/libtom/libtomcrypt/tree/develop/notes/rsa-testvectors )

> I started with the RSADP test vectors that would apparently be used
> against the function rsa_exptmod(). I am some issues here as the
> rsa_key structure requires p and q and the test file provides only n,e,d
> values plus k , data to be encrypted and c, the ciphertext. It also
> gives intermediate values before the mod operation.

It's pretty obvious from the rsa_exptmod() implementation that there's
no need for the CRT parts and you only need n, e & d.

> Has any one written tests to run with the test vectors from NIST website
> and if yes will appreciate any pointers regarding the same.

If you plan to somehow add a parser for the "SP 800-56B Section 7.1.2"
testvectors feel free to submit a PR.


HTH,
Steffen
> www.duolog.com <http://www.duolog.com/>
>
> *Revolutionary Tools for IP/SoC Integration and Verification*
> *Evaluate the Socrates Tools instantly in the cloud
> <http://www.xuropa.com/company.php?comp_id=491>*
> Learn more about Duolog's Conference Programme - SOC Integration and
> Verification
> <http://www.duolog.com/duolog-is-exhibiting-at-the-49th-design-automation-conference-dac-san-francisco-ca-june-3-7/>
>
> --
> *** Please reply-to-all at all times ***
> *** (do not pretend to know who is subscribed and who is not) ***
> *** Please avoid top-posting. ***
> ---
> 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 https://groups.google.com/group/libtom.
> For more options, visit https://groups.google.com/d/optout.


--
Steffen Jaeckel - s_ja...@gmx.de
GnuPG fingerprint: C438 6A23 7ED4 3A47 5541 B942 7B2C D0DD 4BCF F59B
My OTR key has changed on 30. Sept. 2015!
jabber: jae...@jabber.ccc.de F052DE29 4FA9A02D 44A794E5 AE5AC0FB C5865C64

Steffen Jaeckel

unread,
Mar 22, 2017, 1:31:42 PM3/22/17
to ML, LibTom Projects
Hi Mrinali,

On 22.03.2017 18:26, ML wrote:
> I tried :
> gcc -o test -DTFM_DESC -DLTM_DESC
> -L/home/m1/Downloads/tmp/libtomcrypt-develop/demos
> -I/home/m1/Downloads/tmp/tomsfastmath-develop/src/headers
> -I../testprof -I../src/headers/ test.c -ltomcrypt_prof -ltomcrypt
> -ltfm

Can you try to add -L/home/m1/Downloads/tmp/tomsfastmath-develop

That's the only obvious thing I can see...

Cheers,
Steffen

ML

unread,
Apr 13, 2017, 4:28:05 AM4/13/17
to LibTom Projects, m.lot...@gmail.com, s_ja...@gmx.de
Hi Steffen,

I am sorry to be re posting this issue. I am struggling with it for quite some time now.
I was able to compile the test.c program.

I am using the following command to compile:

gcc -o test -DTFM_DESC -DUSE_TFM -Ilibtomcrypt-develop/testprof/  -Ilibtomcrypt-develop/testprof/ -I/home/m1/Downloads/tmp123/libtomcrypt-develop/src/headers/ -Llibtomcrypt-develop/ -L/home/m1/Downloads/tmp123/libtomcrypt-develop/testprof/ -Ltomsfastmath-develop/ -Llibtommath-develop/ test.c -ltomcrypt_prof  -ltomcrypt -ltfm -ltommath


The compilation output is:


In file included from /home/m1/Downloads/tmp123/libtomcrypt-develop/src/headers/tomcrypt.h:13:0,
                 from libtomcrypt-develop/testprof/tomcrypt_test.h:5,
                 from test.c:1:
/home/m1/Downloads/tmp123/libtomcrypt-develop/src/headers/tomcrypt_custom.h:480:6: warning: #warning RSA blinding currently not supported in combination with TFM [-Wcpp]
     #warning RSA blinding currently not supported in combination with TFM


When I execute ./test I get the following output (the last few lines of outpur):


Various others:  ADLER32  BASE64  BASE64-URL-SAFE  CRC32  DER  LTC_DER_MAX_PUBKEY_SIZE=4096  PKCS#1  PKCS#5  HKDF  LTC_DEVRANDOM  LTC_TRY_URANDOM_FIRST  LTC_RNG_GET_BYTES  LTC_RNG_MAKE_PRNG  LTC_HASH_HELPERS  LTC_TEST  LTC_FAST  LTC_ROx_ASM  LTM_DESC  TFM_DESC  LTC_MECC_ACCEL  LTC_ECC_SHAMIR

MP_DIGIT_BIT = 32

store_test....passed
misc_test.....passed
cipher_test...passed
mac_test......passed
modes_test....passed
der_test......Segmentation fault (core dump





I will appreciate any pointers regarding why the test might be failing. When I commented the call to der_test 2 of the tests after it pass and the rest fail.

Many Thanks!
Mrinali
Reply all
Reply to author
Forward
0 new messages