-
Notifications
You must be signed in to change notification settings - Fork 1
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
Optimize bls #122
base: main
Are you sure you want to change the base?
Optimize bls #122
Conversation
Unused if the command is SIGN and the curve of the signee key is BLS
a18206b
to
9214c95
Compare
prepare to stop derivating the pk too frequently
Since `global.public_key` is the key associated to `global.path_with_curve`, if the `path_with_curve` to derive is equal to `global.path_with_curve`, then the key associated to the `path_with_curve` is `global.public_key`. There is no need to re-derive it again.
9214c95
to
1c55f5a
Compare
#ifndef TARGET_NANOS | ||
// There is no need to hash the message if it is not used for signing or if it is not sent at | ||
// the end. | ||
if (with_hash || (global.path_with_curve.derivation_type != DERIVATION_TYPE_BLS12_381)) { |
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.
What is the purpose of with_hash here. Is it used for BLS.
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.
I mean if the derivation type is BLS dont hash at all.
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.
The with_hash
comes from the request SIGN_WITH_HASH
.
We have to compute/send it if the sender requests it.
@@ -33,6 +33,26 @@ | |||
#include <stdint.h> | |||
#include <string.h> | |||
|
|||
tz_exc read_path_with_curve(derivation_type_t derivation_type, |
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.
The derivation type is selected at the time of setup. It can not be changed during signing. so it makes sense to derivce the public key when read_path_with_curve is called from handle_setup. Rather create a new function setup_path_with_curve and derive public key there along with a call to read_path_with_curve. Call setup_path_with_curve from handle_setup and read_path_with_curve from other places.
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.
The SETUP
instruction is not required to sign:
AUTHORIZE_BAKING
will setup the authorized key too.- If the authorized key was present in the RAM,
SIGN
with index 0x00 will tell which public key to sign with
The aims of this function is too make sure that, every time the stored Bip32-path-with-curve is updated, the stored PK is updated to.
TZ_ASSERT(read_bip32_path(buf, &tmp_path_with_curve.bip32_path), EXC_WRONG_VALUES); | ||
|
||
// Do not derive the public key if the two path_with_curve are equal | ||
if (!bip32_path_with_curve_eq(path_with_curve, &tmp_path_with_curve)) { |
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.
It seems my previous comment is addressed here. you can still think if a setup_path_with_curve makes sense.
This PR add optimization to BLS signing.