libtomcrypt icon indicating copy to clipboard operation
libtomcrypt copied to clipboard

README on MPIs

Open mg262 opened this issue 7 years ago • 3 comments
trafficstars

Hi,

Thanks for the great library! The docs say:

As of v1.06 of the library, the build process has been moved to two steps for the typical LibTomCrypt application. This is because LibTomCrypt no longer provides a math API on its own and relies on third party libraries (such as LibTomMath, GnuMP, or TomsFastMath).

This bit isn't clear from the README -- when first playing with the library, I wasn't sure whether the math libs were optional or not. If you had a chance to add a sentence on that, I think it could help new users.

mg262 avatar Mar 05 '18 16:03 mg262

Agreed, was bitten by this as well when trying out LibTomCrypt for the first time.

J08nY avatar Mar 22 '18 22:03 J08nY

Sorry, it true... you're not the first ones who had those problems... but I don't really know how to describe what is missing as information. Now that you've figured out what is missing, could you please make a proposal? I'll happily update the README & documentation!

sjaeckel avatar Mar 23 '18 09:03 sjaeckel

I really struggled as well to understand this. For me the main thing I didn't see/understand was that i had to set the ltc_mp actively. For me this was especially hard to grasp as SHA256 worked without (I later read in the manual that the MP is only needed for the PK crypto, which makes totally sense). It may already explicitly stated in the manual and I simply overread it, but if not, this is something I think is valuable for someone being unfamiliar with ltc.

My minimal dummy working example using libtomcrypt with tomsfastmath is:

libtomcrypt-minimal/
├── build.sh
├── libtomcrypt
├── main.c
└── tomsfastmath

build.sh

cd tomsfastmath
make
cd ..
cd libtomcrypt
make CFLAGS="-DLTC_EASY -DTFM_DESC -I../tomsfastmath/src/headers" EXTRALIBS="../tomsfastmath/libtfm.a"
cd ..
gcc main.c -g -DTFM_DESC -DUSE_TFM -o main -Ilibtomcrypt/src/headers -Llibtomcrypt/libtomcrypt -Itomsfastmath/src/headers libtomcrypt/libtomcrypt.a tomsfastmath/libtfm.a

main.c

#include <stdio.h>
#include "tomcrypt.h"

const unsigned char pk[] = {0x00, 0x00, 0x00, 0x00};
unsigned long pk_len = 4;


void main(void) {
    ltc_mp = tfm_desc;
    printf("Start\n");
    hash_state md;
    sha256_init(&md);
    printf("SHA256 done\n");
    rsa_key key;
    rsa_import(pk, pk_len, &key);
    printf("RSA done\n");
}

aewag avatar Dec 12 '20 14:12 aewag