Jump to content
Tuts 4 You

Miracl ECDSA Issue


ghandi

Recommended Posts

Posted

Hi all,

While playing with the Miracl large integer package and using the example code as a base, i made 3 ECDSA functions:

1. Keypair generation.

2. Data signing.

3. Signature verification.

Using the 'cinstr' function i am able to load parameters from ascii strings to bignum variables and it works just fine, all 3 functions are operational and correct. Using the 'big_to_bytes' function i am able to get the octet string which represents the bignums in use and i can load them back to bignum variables using 'bytes_to_big' and following along in OllyDbg i can see that all of the values are correct and exactly the same as if i had loaded them from strings.

However, when it reaches the stage of initializing the point x,y of order q, it fails even though the numbers are exactly the same as the working, functional version which uses only strings. Following in Olly it appears as though everything is the same, so I am stumped where it could be going wrong, does anybody have any insight they could lend to this please?

HR,

Ghandi

Posted

I don't know much about MIRACL, only that it's big and sometimes kinda slow. I once used some other library for ECDSA functions. http://mattmccutchen.net/bigint/ it's actually small and really fast. Maybe it's helpful, I don't know.

Posted

Thank you, i haven't looked into that one in detail although i have seen it before.

There are a lot of libraries to consider, some being:

Miracl

GNU MP (GMP)

MPIR

LIP

BigInt

If i were looking for speed i might look at MPIR because it is a Windows port of GMP, branched off a couple of versions ago and if hype is to be believed GMP seems to be one of the faster large integer packages available. I have several (as many as i could find at the time) different libraries, either in code form, i have used different ones for different needs.

But for this particular project i am wanting to use Miracl and size is not a worry nor is speed, although i don't believe either will be as bad as though, especially with link time code generation and other optimizations enabled.

To this end i am still asking if anybody has any idea why using raw binary data would give a different result than converting ascii to binary and performing the exact same operations? All of the values are correct in their binary form, so i can't see why Miracl would give different results...

HR,

Ghandi

Posted

Hmm, maybe you could try using older versions of Miracl. Another option is to use another bignum library to convert the data to strings, after which you pass them to the miracl functions in string form. It's kind of lame, but if speed and size do not matter it's worth the consideration.

Greetings,

Mr. eXoDia

Posted (edited)

I have the data in both string and binary form, i was just looking at storing parameters as binary rather than ascii.

But just converting from byte form to ascii or back again, base 16, is done easily with no need for API or libraries, i guess i probably could have made that a little clearer by giving the base im using as well.

EDIT: I printed out the values of the curve parameters, using the example ones from the Miracl source and 'A' was going from a negative number to a positive number, spoiling further calculations. After using the negify() function on the suspect number, i was able to convert the numbers to bytes and back again and the function still worked okay.

BigNum: P

cotstr result: FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF7FFFFFFF

big_to_bytes: FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF7FFFFFFF

bytes_to_big: FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF7FFFFFFF

BigNum: A

cotstr result: -3

big_to_bytes: 03

bytes_to_big: 3

BigNum: B

cotstr result: 1C97BEFC54BD7A8B65ACF89F81D4D4ADC565FA45

big_to_bytes: 1C97BEFC54BD7A8B65ACF89F81D4D4ADC565FA45

bytes_to_big: 1C97BEFC54BD7A8B65ACF89F81D4D4ADC565FA45

BigNum: Q

cotstr result: 100000000000000000001F4C8F927AED3CA752257

big_to_bytes: 0100000000000000000001F4C8F927AED3CA752257

bytes_to_big: 100000000000000000001F4C8F927AED3CA752257

BigNum: X

cotstr result: 4A96B5688EF573284664698968C38BB913CBFC82

big_to_bytes: 4A96B5688EF573284664698968C38BB913CBFC82

bytes_to_big: 4A96B5688EF573284664698968C38BB913CBFC82

BigNum: Y

cotstr result: 23A628553168947D59DCC912042351377AC5FB32

big_to_bytes: 23A628553168947D59DCC912042351377AC5FB32

bytes_to_big: 23A628553168947D59DCC912042351377AC5FB32

So, in a nutshell, it was me not using Miracl correctly...

HR,

Ghandi

Edited by ghandi
Posted

Ok then, nice to hear your problems are solved so far :)

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...