EldoS | Feel safer!

Software components for data protection, secure storage and transfer

ECDSA custom curve

Also by EldoS: Solid File System
A virtual file system that offers a feature-rich storage for application documents and data with built-in compression and encryption.
Posted: 03/08/2012 09:21:37
by Mykola Olshevsky (Basic support level)
Joined: 07/07/2005
Posts: 450

SigSize returns the needed size for signature buffer. So resize buffer to appropriate length and call it the second time.
0x6001 is the constant for SB_EC_FLD_TYPE_FP, so everything is ok with this (for unknown field it should be 0x6000).
Posted: 03/08/2012 09:43:04
by Spiros Poulis (Standard support level)
Joined: 02/21/2012
Posts: 11

Thank you for your help. I encoded succefully the signature but still verification fails..

I was confused with the result of ElECKeyMaterial.FieldType, because according to the help file 0x6001 is the constant for SB_EC_FLD_TYPE_UNKNOWN, and
0x6002 is the constant for SB_EC_FLD_TYPE_FP. There is no 0x6000 value...

SB_EC_FLD_TYPE_UNKNOWN 24577 (0x6001) Unknown field
SB_EC_FLD_TYPE_FP 24578 (0x6002) Prime field
SB_EC_FLD_TYPE_F2MP 24579 (0x6003) Binary extended field

Should the data array in .Verify be the hash value of the real data, or hashing happens internally?
Posted: 03/08/2012 09:47:00
by Mykola Olshevsky (Basic support level)
Joined: 07/07/2005
Posts: 450

It seems to be a misprint in help document, we will fix it.

To control if input is hash you should use property .InputIsHash, set it to true if you are passing hash value, or to false if you pass the raw data.
Posted: 03/08/2012 10:00:49
by Spiros Poulis (Standard support level)
Joined: 02/21/2012
Posts: 11

I had used .InputHash with no luck..
Do you have something more to advise or should I open with a Helpdesk ticket now?
Posted: 03/08/2012 10:07:02
by Mykola Olshevsky (Basic support level)
Joined: 07/07/2005
Posts: 450

Better open a ticket and post curve parameters, sample signature, message (or message's hash) and public key there.
Posted: 03/08/2012 10:10:00
by Spiros Poulis (Standard support level)
Joined: 02/21/2012
Posts: 11

Ok thanks a lot for your help and quick responses.
Posted: 03/08/2012 11:36:41
by Spiros Poulis (Standard support level)
Joined: 02/21/2012
Posts: 11

Unfortunatelly I cannot provide the public key and ecc parameters as we have signed an NDA with our customer but I can ensure you that the ecc parameters and keys are valid.
The only thing I can provide helpdesk is a working test program I had wrote in c++ using openssl libraries and the non-working c# program I try to write with your library.
Do you think that this would be helpful?

thanks again.
Posted: 03/08/2012 12:05:52
by Eugene Mayevski (EldoS Corp.)

No, ensuring us that you have valid parameters is not enough to recreate your issue, sorry.

Sincerely yours
Eugene Mayevski
Posted: 03/11/2012 14:58:28
by Spiros Poulis (Standard support level)
Joined: 02/21/2012
Posts: 11

Problem resolved with the valuable help of ELDOS's support team, after being moved to HelpDesk. Thank you for your prompt responses!

The main problem was in the negative value of 'a' parameter, which should be converted to positive integer by adding p, before converting to byte array.
The second problem was the missing of the signature encoding function.

The following code verifies correctly now.

Thanks again,

string data_p = "...";
string data_a = "...";
string data_b = "...";
string data_x = "...";
string data_y = "...";
string data_r = "...";
string data_pub_x = "...";
string data_pub_y = "...";
BigInteger big_p = BigInteger.Parse(data_p, NumberStyles.Integer);
byte[] p = big_p.ToByteArray();
BigInteger big_a = BigInteger.Parse(data_a, NumberStyles.Integer);
big_a = big_a + big_p;
byte[] a = big_a.ToByteArray();
BigInteger big_b = BigInteger.Parse(data_b, NumberStyles.Integer);
byte[] b = big_b.ToByteArray();
BigInteger big_x = BigInteger.Parse(data_x, NumberStyles.Integer);
byte[] x = big_x.ToByteArray();
BigInteger big_y = BigInteger.Parse(data_y, NumberStyles.Integer);
byte[] y = big_y.ToByteArray();
BigInteger big_r = BigInteger.Parse(data_r, NumberStyles.Integer);
byte[] r = big_r.ToByteArray();
Array.Reverse( r );
BigInteger big_pub_x = BigInteger.Parse(data_pub_x, NumberStyles.Integer);
byte[] pub_x = big_pub_x.ToByteArray();
BigInteger big_pub_y = BigInteger.Parse(data_pub_y, NumberStyles.Integer);
byte[] pub_y = big_pub_y.ToByteArray();
TElECKeyMaterial key_material = new TElECKeyMaterial();
key_material.P = p;
key_material.A = a;
key_material.B = b;
key_material.X = x;
key_material.Y = y;
key_material.N = r;
key_material.QX = pub_x;
key_material.QY = pub_y;
key_material.HashAlgorithm = SBConstants.Unit.SB_ALGORITHM_DGST_SHA1;
// data and signature input from file here
FileStream fIn = new FileStream(@"data.dat", FileMode.Open);
byte[] data_buff = new byte[fIn.Length];
fIn.Read(data_buff, 0, (int)fIn.Length);
fIn = new FileStream(@"signature.dat", FileMode.Open);
byte[] sig_buff = new byte[fIn.Length];
fIn.Read(sig_buff, 0, (int)fIn.Length);
TElECDSAPublicKeyCrypto o1 = new TElECDSAPublicKeyCrypto();

int sigSize = 0;
o1.EncodeSignature(sig_buff, 0, 20, sig_buff, 20, 20, ref sig_buff, 0, ref sigSize);
byte[] new_sig_buff = new byte[sigSize];
o1.EncodeSignature(sig_buff, 0, 20, sig_buff, 20, 20, ref new_sig_buff, 0, ref sigSize);
o1.KeyMaterial = key_material;
o1.InputIsHash = false;
TSBPublicKeyVerificationResult les = o1.VerifyDetached(data_buff, 0, data_buff.Length, new_sig_buff, 0, sigSize);
Also by EldoS: CallbackDisk
Create virtual disks backed by memory or custom location, expose disk images as disks and more.



Topic viewed 2567 times

Number of guests: 1, registered members: 0, in total hidden: 0


Back to top

As of July 15, 2016 EldoS Corporation will operate as a division of /n software inc. For more information, please read the announcement.

Got it!