-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
crypto: ECDH convertKey to convert public keys between different formats #19080
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
Changes from 1 commit
41a17db
9ded80c
e876f36
810cb37
17f1703
d5f07d9
c201c26
541a651
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
refactored ECDH::BufferToPoint and key formatting
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4684,18 +4684,21 @@ void ECDH::GenerateKeys(const FunctionCallbackInfo<Value>& args) { | |
| } | ||
|
|
||
|
|
||
| EC_POINT* ECDH::BufferToPoint(char* data, size_t len) { | ||
| EC_POINT* ECDH::BufferToPoint(Environment* env, | ||
| const EC_GROUP* group, | ||
| char* data, | ||
| size_t len) { | ||
| EC_POINT* pub; | ||
| int r; | ||
|
|
||
| pub = EC_POINT_new(group_); | ||
| pub = EC_POINT_new(group); | ||
| if (pub == nullptr) { | ||
| env()->ThrowError("Failed to allocate EC_POINT for a public key"); | ||
| env->ThrowError("Failed to allocate EC_POINT for a public key"); | ||
| return nullptr; | ||
| } | ||
|
|
||
| r = EC_POINT_oct2point( | ||
| group_, | ||
| group, | ||
| pub, | ||
| reinterpret_cast<unsigned char*>(data), | ||
| len, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since you're making changes here, you might want to get rid of the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done! |
||
|
|
@@ -4725,7 +4728,9 @@ void ECDH::ComputeSecret(const FunctionCallbackInfo<Value>& args) { | |
| if (!ecdh->IsKeyPairValid()) | ||
| return env->ThrowError("Invalid key pair"); | ||
|
|
||
| EC_POINT* pub = ecdh->BufferToPoint(Buffer::Data(args[0]), | ||
| EC_POINT* pub = ECDH::BufferToPoint(env, | ||
| ecdh->group_, | ||
| Buffer::Data(args[0]), | ||
| Buffer::Length(args[0])); | ||
| if (pub == nullptr) { | ||
| args.GetReturnValue().Set( | ||
|
|
@@ -4874,7 +4879,9 @@ void ECDH::SetPublicKey(const FunctionCallbackInfo<Value>& args) { | |
|
|
||
| MarkPopErrorOnReturn mark_pop_error_on_return; | ||
|
|
||
| EC_POINT* pub = ecdh->BufferToPoint(Buffer::Data(args[0].As<Object>()), | ||
| EC_POINT* pub = ECDH::BufferToPoint(env, | ||
| ecdh->group_, | ||
| Buffer::Data(args[0].As<Object>()), | ||
| Buffer::Length(args[0].As<Object>())); | ||
| if (pub == nullptr) | ||
| return env->ThrowError("Failed to convert Buffer to EC_POINT"); | ||
|
|
@@ -5574,19 +5581,10 @@ void ConvertKey(const FunctionCallbackInfo<Value>& args) { | |
| if (group == nullptr) | ||
| return env->ThrowError("Failed to get EC_GROUP"); | ||
|
|
||
| EC_POINT* pub = EC_POINT_new(group); | ||
| if (pub == nullptr) | ||
| return env->ThrowError("Failed to allocate EC_POINT for a public key"); | ||
|
|
||
| int r = EC_POINT_oct2point( | ||
| group, | ||
| pub, | ||
| reinterpret_cast<unsigned char*>(Buffer::Data(args[0])), | ||
| len, | ||
| nullptr); | ||
| if (!r) | ||
| return env->ThrowError("Failed to convert key to point"); | ||
|
|
||
| EC_POINT* pub = ECDH::BufferToPoint(env, | ||
| group, | ||
| Buffer::Data(args[0]), | ||
| len); | ||
| if (pub == nullptr) | ||
| return env->ThrowError("Failed to convert Buffer to EC_POINT"); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
|
|
@@ -5601,7 +5599,7 @@ void ConvertKey(const FunctionCallbackInfo<Value>& args) { | |
|
|
||
| unsigned char* out = node::Malloc<unsigned char>(size); | ||
|
|
||
| r = EC_POINT_point2oct(group, pub, form, out, size, nullptr); | ||
| int r = EC_POINT_point2oct(group, pub, form, out, size, nullptr); | ||
| if (r != size) { | ||
| free(out); | ||
| return env->ThrowError("Failed to get public key"); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bnoordhuis I also added the
encodefunction since I noticed that the test for'buffer'encoding happens a lot in this file. Should I also change that in this PR or should I submit another PR for that?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, doing it in this PR is fine.