Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AMCL JS ECDSA Key data structure and signing procedure #19

Closed
CryptoMathician opened this issue Sep 16, 2020 · 6 comments
Closed

AMCL JS ECDSA Key data structure and signing procedure #19

CryptoMathician opened this issue Sep 16, 2020 · 6 comments

Comments

@CryptoMathician
Copy link
Contributor

Hi,
in my example I want to create a key pair for ECDSA from a given byte seed and was searching for a data structure which holds the key pair and the keys in the library.
I am not sure, but it seems that it don't exist such a data structure right?
Should it not exist is it possible to add a data structure for it like for the RSA keys in rsa.js?
I was thinking about an object like KeyPair (Java) or something similar.

Thank you in advance!

Pascal

@CryptoMathician
Copy link
Contributor Author

CryptoMathician commented Sep 16, 2020

Or is it possible to store the generated key pair into the CryptoKeyPair object from the JS web crypto API [1]?
I am not sure, if that is possible.

Pascal

[1] https://developer.mozilla.org/en-US/docs/Web/API/CryptoKey

@mcarrickscott
Copy link
Contributor

In general I like to keep public and secret keys separate from one another. The public key can always be generated from the secret key if needed.

@CryptoMathician
Copy link
Contributor Author

CryptoMathician commented Sep 17, 2020

Ok. Do you maybe know, if it is possible to import the created key from the library into the CryptoKeyPair/CryptoKey to use the standardized methods for signatures? Or is it possible to do the same behavior as in java (below) with this library?

Signature sig = Signature.getInstance("SHA256withECDSA");
		sig.initSign(privateKey);
		for(byte[] bytes : message) {
			sig.update(bytes);
		}
		return sig.sign();

The method sig.sign() gives me an byte array, but with the

ECDH.ECPSP_DSA(sha, rng ,privateKey,message,CS, DS);

I get the signature in form of CSand DS. Is it possible to create a signature as it is in java (above)?
The message is defined as follows:

List<byte[]> message

Thank you in advance!

EDIT:
In general I want to sign a nonce and a uid with the private key and want to get a byte array back.

@CryptoMathician CryptoMathician changed the title AMCL JS ECDSA Key data structure AMCL JS ECDSA Key data structure and signing procedure Sep 17, 2020
@CryptoMathician
Copy link
Contributor Author

CryptoMathician commented Sep 17, 2020

Have I only to convert the CS (I think that is the r value) and DS (I thin it is the s value) [1] to a DER format like this example [2]

3045022065A67F8FF9CB5EA8BE899E94CB338FE09E2E596BC047D936FC2B96DC013B5DFC022100BE123D3F143AF91E4551AAFAE49C9187F64E323F5660D6C6198A9446C3F818A1

DER encoding:
30 - Sequence
45 - 45 hex bytes (69 decimal)
02 - Integer
20 - 20 hex bytes (32 decimal)
65A67F8FF9CB5EA8BE899E94CB338FE09E2E596BC047D936FC2B96DC013B5DFC - 32 bytes integer signature (r)
02 - Integer
21 - 21 hex (33 decimal) bytes
00BE123D3F143AF91E4551AAFAE49C9187F64E323F5660D6C6198A9446C3F818A1 - 33 bytes integer signature (s)

or is there something more to do? I am not sure, but it seems to me that the Java Signature object gives a byte array back, which are in DER format.

[1] https://en.wikipedia.org/wiki/Elliptic_Curve_Digital_Signature_Algorithm#Signature_generation_algorithm
[2] https://crypto.stackexchange.com/questions/78248/difference-between-der-encoded-signatures-in-javascript-java-and-c

@mcarrickscott
Copy link
Contributor

I am sure it is possible, it seems just a case of transforming the signature from one format to another, but I'm afraid I don't have the time to look into it right now...

@CryptoMathician
Copy link
Contributor Author

Ok, thank you anyway!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants