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

Add call to retrieve public key from private key #17

Closed
wants to merge 1 commit into from
Closed

Add call to retrieve public key from private key #17

wants to merge 1 commit into from

Conversation

vszakats
Copy link
Contributor

@vszakats vszakats commented Oct 6, 2017

No description provided.

@vszakats vszakats changed the title add call to retrieve public key from private key Add call to retrieve public key from private key Oct 6, 2017
@vszakats vszakats closed this Nov 9, 2017
@vszakats
Copy link
Contributor Author

vszakats commented Nov 9, 2017

@orlp: Please feel free to reopen these if you get around to dealing with ed25519. They are valid patches, that — I believe — don't have much risk involved and add value to your project. I've been maintaining these patches for years now downstream, they work well.

@vszakats
Copy link
Contributor Author

This proposed function can also fix or mitigate this vulnerability: https://github.com/MystenLabs/ed25519-unsafe-libs

@vszakats
Copy link
Contributor Author

Updated patch, which additionally fixes the above vulnerability by ignoring the passed public_key and deriving it from private_key instead. The function remains compatible and automatically fixes the vulnerability for all callers:

diff --git a/src/ed25519.h b/src/ed25519.h
index 8924659..b0d0347 100644
--- a/src/ed25519.h
+++ b/src/ed25519.h
@@ -25,7 +25,8 @@ int ED25519_DECLSPEC ed25519_create_seed(unsigned char *seed);
 #endif
 
 void ED25519_DECLSPEC ed25519_create_keypair(unsigned char *public_key, unsigned char *private_key, const unsigned char *seed);
-void ED25519_DECLSPEC ed25519_sign(unsigned char *signature, const unsigned char *message, size_t message_len, const unsigned char *public_key, const unsigned char *private_key);
+void ED25519_DECLSPEC ed25519_get_pubkey(unsigned char *public_key, const unsigned char *private_key);
+void ED25519_DECLSPEC ed25519_sign(unsigned char *signature, const unsigned char *message, size_t message_len, const unsigned char *unused, const unsigned char *private_key);
 int ED25519_DECLSPEC ed25519_verify(const unsigned char *signature, const unsigned char *message, size_t message_len, const unsigned char *public_key);
 void ED25519_DECLSPEC ed25519_add_scalar(unsigned char *public_key, unsigned char *private_key, const unsigned char *scalar);
 void ED25519_DECLSPEC ed25519_key_exchange(unsigned char *shared_secret, const unsigned char *public_key, const unsigned char *private_key);
diff --git a/src/sign.c b/src/sign.c
index 199a839..8251252 100644
--- a/src/sign.c
+++ b/src/sign.c
@@ -3,13 +3,23 @@
 #include "ge.h"
 #include "sc.h"
 
+void ed25519_get_pubkey(unsigned char *public_key, const unsigned char *private_key) {
+    ge_p3 A;
 
-void ed25519_sign(unsigned char *signature, const unsigned char *message, size_t message_len, const unsigned char *public_key, const unsigned char *private_key) {
+    ge_scalarmult_base(&A, private_key);
+    ge_p3_tobytes(public_key, &A);
+}
+
+void ed25519_sign(unsigned char *signature, const unsigned char *message, size_t message_len, const unsigned char *unused, const unsigned char *private_key) {
     sha512_context hash;
     unsigned char hram[64];
     unsigned char r[64];
     ge_p3 R;
+    unsigned char public_key[ 32 ];
+
+    (void)unused;
 
+    ed25519_get_pubkey(public_key, private_key);
 
     sha512_init(&hash);
     sha512_update(&hash, private_key + 32, 32);

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

Successfully merging this pull request may close these issues.

None yet

1 participant