?
Solved

Crypto using Libtom with ECDSA

Posted on 2013-12-24
11
Medium Priority
?
977 Views
Last Modified: 2014-01-05
Hi,
In the ecc_test.c how does tom use yarrow_prng (line 223) without initialize it?
I copied his code from line 218 to 230 as is, trying to sign a hashed charstream but Visual Studio tell me that there is an error yarrow_prng undeclared identifier.
Below is my code:
#include<stdio.h>
#include<tomcrypt.h>

void main()
{
	unsigned long x;
	unsigned char buf[4][4096];
	int stat, stat2;
	ecc_key usera, userb, pubKey, privKey;
	//prng_state yarrow_prng;

	for (x = 0; x < 16; x++) {
		buf[0][x] = x;
	}
	x = sizeof (buf[1]);
	ecc_sign_hash (buf[0], 16, buf[1], &x, &yarrow_prng, find_prng ("yarrow"), &privKey);
	ecc_verify_hash (buf[1], x, buf[0], 16, &stat, &pubKey);
	buf[0][0] ^= 1;
	ecc_verify_hash (buf[1], x, buf[0], 16, &stat2, &privKey);
	if (!(stat == 1 && stat2 == 0)) { 
		fprintf(stderr, "ecc_verify_hash failed %d, %d, ", stat, stat2);
	}
}

Open in new window

0
Comment
Question by:Wathan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
11 Comments
 
LVL 64

Expert Comment

by:btan
ID: 39738900
can try uncomment this line below  e.g. remove the "//" suffix (exclude the quotes).

//prng_state yarrow_prng;

the "tomcrypt.h" should have include of "tomcrypt_prng.h"
the "tomcrypt_prng.h" should have something as below

#ifdef LTC_YARROW
struct yarrow_prng {
    int                   cipher, hash;
    unsigned char         pool[MAXBLOCKSIZE];
    symmetric_CTR         ctr;
    LTC_MUTEX_TYPE(prng_lock)
};
#endif

typedef union Prng_state {
    char dummy[1];
#ifdef LTC_YARROW
    struct yarrow_prng    yarrow;
#endif
#ifdef LTC_RC4
    struct rc4_prng       rc4;
#endif
#ifdef LTC_FORTUNA
    struct fortuna_prng   fortuna;
#endif
#ifdef LTC_SOBER128
    struct sober128_prng  sober128;
#endif
} prng_state;
0
 

Author Comment

by:Wathan
ID: 39739027
when i uncomment this line, 4 externals erors appearsExternals errors
0
 
LVL 64

Expert Comment

by:btan
ID: 39739048
Using the the entire LibTomCrypt source, you would have built a library file with Visual Studio 2010 which compiles without issue. The error is likely due to your simple test console application that links the with TomCrypt library, hence receive a linker error.

Some try the debug library build which may works with the test code. However, the release build of tomcrypt.lib seems to be always missing some symbols as in your case. The project configs for visual studio may include custom steps for building
e.g. - crypt_find_prng.c
(http://libtomcrypt.sourcearchive.com/documentation/1.17-3.1/crypt__find__prng_8c_a53cfb5c7551b314e634a08e8be20a69c.html)
Likewise for
-libtomcrypt/src/pk/ecc/ecc_sign_hash.c and
-libtomcrypt/src/pk/ecc/ecc_verify_hash.c

Using gcc to build this code with the static library may not work. Also likely for variable flagged also need to add those into the makefile's CFLAGS and CPPFLAGS variables so the headers will declare those variable as an extern variable....
0
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 
LVL 64

Expert Comment

by:btan
ID: 39740994
I saw your other posting in previous - did you tried the debug version? if that is alright then have to check it makefile build configurations which are not avail in the release makefile build.

Also there are 5 different library besides the libtomcrypt, such as  libtommath, tomsfastmath, libtomfloat and libtompoly. @ http://libtom.

Also I believe there is some VS solution file in github
0
 

Author Comment

by:Wathan
ID: 39741844
Can you explain me exactly what do i have to do to use libtomcrypt and libtommath in my project? What is, step by step, the way from the creation of my project to the using of the libtom libraries?
0
 
LVL 64

Expert Comment

by:btan
ID: 39741908
Using the the entire LibTomCrypt source, you should have built a library file with Visual Studio (using the  "makefile.msvc" which is used for VS 6) to create a
>"tomcrypt.lib" (lib /out:tomcrypt.lib $(OBJECTS))
>"tommath.lib" (lib /out:tommath.lib $(OBJECTS))

These above Libs can then be linked into the your main project file as static library.
I afraid there is not much steps written in open for VS...
http://msdn.microsoft.com/en-us/library/ms235627.aspx#BKMK_CreateAppToRefTheLib
 
In case you need to run nmake to build your project using the makefile.
http://msdn.microsoft.com/en-us/library/txcwa2xx(v=vs.90).aspx
http://msdn.microsoft.com/en-us/library/a23f7tc4(v=vs.90).aspx

Fyi, I believe there are also other who has created libtomcrypt_VS2005.sln. libtomcrypt_VS2005.vcproj. libtomcrypt_VS2008.sln. libtomcrypt_VS2008.vcproj (need to googled it), similarly I saw there is for libtommath. They may be used

Do note in crypt.pdf, its chapter 13 talks about the compiling and building but for gcc.  
https://github.com/libtom/libtomcrypt

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 TomsFast-
Math).

The build process now consists of installing a math library first,
and then building and installing LibTomCrypt with a math library
configured. Note that LibTomCrypt can be built with no internal
math descriptors.
0
 

Author Comment

by:Wathan
ID: 39744053
I don't understand the first step, how can i transform the project libtmmath to library? I do Open an existing project?
0
 
LVL 64

Expert Comment

by:btan
ID: 39744141
You need to download libtommath from the original site https://github.com/libtom, and compile it using the makefile as you did for  libtomcrypt. There is existing sln and vproj too in that download. With the two  tommath.lib and tomcrypt.lib, linked them into your main project.
0
 

Author Comment

by:Wathan
ID: 39744693
For libtomcrypt i didn't use makefile but Additionnal include directories.
Can you explain how to use makefile?
0
 

Author Comment

by:Wathan
ID: 39744704
I succeed to make the tommath.lib and tomcrypt.lib files, so now how can i do to use them and their function in another project??
I tried to creat an other project in the same solution and i already do the references (as explained in msdn) and the include file attribution, and i receive an ERROR 1083 that saying me it can't open the header file of libtom (both of them, tommath and tomcrypt of course).
0
 
LVL 64

Accepted Solution

by:
btan earned 2000 total points
ID: 39745275
In order for the code to compile, the file must be present in the file system of your computer in one of the paths that the specified as search paths for header files of this solution. It is not present, hence the error.

E.g  see that the directory the header is included in the project's settings (C/C++ ¿ General ¿ Additional Include Directories).

http://social.msdn.microsoft.com/Forums/en-US/7843071f-0767-4af4-b645-508e3ffcf56f/visual-c-fatal-error-c1083-cannot-open-include-file?forum=Vsexpressvc
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article provides a convenient collection of links to Microsoft provided Security Patches for operating systems that have reached their End of Life support cycle. Included operating systems covered by this article are Windows XP,  Windows Server…
With the rising number of cyber attacks in recent years, keeping your personal data safe has become more important than ever. The tips outlined in this article will help you keep your identitfy safe.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Suggested Courses

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question