-
Notifications
You must be signed in to change notification settings - Fork 136
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
bls12: implements Marshaler interfaces and SetBytes for Scalar #277
Conversation
if isLessThan(in, order) == 0 { | ||
return nil, errInputRange | ||
} | ||
return conv.BytesBe2Uint64Le(in), nil | ||
} | ||
|
||
func setBytesUnbounded(in []byte, order []byte) []uint64 { | ||
inBig := new(big.Int).SetBytes(in) | ||
inBig.Mod(inBig, new(big.Int).SetBytes(order)) |
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.
Are all scalars non-secret?
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.
this function must be marked as non-constant time. Do you have any ideas on how to perform this operation in constant time?
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 length are we applying it to? I think I only need it for double length ones, in which case a reduction is all that is required.
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.
One alternative possibility is to take in a reader and use it to extract the requisit number of bytes to use as input to a reduction. Either Montgomery or Barrett would work, but I think with this approach Barrett makes the interface cleaner given the next toMont call. That said we could just go to Montgomery directly here, and avoid needing two reductions.
if isLessThan(in, order) == 0 { | ||
return nil, errInputRange | ||
} | ||
return conv.BytesBe2Uint64Le(in), nil | ||
} | ||
|
||
func setBytesUnbounded(in []byte, order []byte) []uint64 { | ||
inBig := new(big.Int).SetBytes(in) | ||
inBig.Mod(inBig, new(big.Int).SetBytes(order)) |
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.
One alternative possibility is to take in a reader and use it to extract the requisit number of bytes to use as input to a reduction. Either Montgomery or Barrett would work, but I think with this approach Barrett makes the interface cleaner given the next toMont call. That said we could just go to Montgomery directly here, and avoid needing two reductions.
6e921df
to
e641304
Compare
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.
Provided we fix the constant-time issue soon enough.
Implements the Marshaler interfaces from go stdlib for serialization and deserialization.
Also, Scalar exposes
SetBytes([]byte)
to set scalars using variable-length data.