libtom / libtomcrypt

LibTomCrypt is a fairly comprehensive, modular and portable cryptographic toolkit that provides developers with a vast array of well known published block ciphers, one-way hash functions, chaining modes, pseudo-random number generators, public key cryptography and a plethora of other routines.
https://www.libtom.net
Other
1.56k stars 458 forks source link

README on MPIs #354

Open mg262 opened 6 years ago

mg262 commented 6 years ago

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.

J08nY commented 6 years ago

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

sjaeckel commented 6 years ago

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!

aewag commented 3 years ago

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");
}