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: endianness option to scalar serde for Banderwagon #342

Merged
merged 5 commits into from
Jan 16, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions constantine/serialization/codecs_banderwagon.nim
Original file line number Diff line number Diff line change
Expand Up @@ -130,19 +130,19 @@ func deserialize*(dst: var EC_Prj, src: array[32, byte]): CttCodecEccStatus =
## Banderwagon Scalar Serialization
##
## ############################################################
##
func serialize_scalar*(dst: var array[32, byte], scalar: matchingOrderBigInt(Banderwagon)): CttCodecScalarStatus =
## Adding an optional Endianness param default at BigEndian
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

procedure comments are below the procedure in Nim

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image
image

very weird

func serialize_scalar*(dst: var array[32, byte], scalar: matchingOrderBigInt(Banderwagon), order: static Endianness = bigEndian): CttCodecScalarStatus =
## Serialize a scalar
## Returns cttCodecScalar_Success if successful
dst.marshal(scalar, bigEndian)
dst.marshal(scalar, order)
return cttCodecScalar_Success
## ############################################################
##
## Banderwagon Scalar Deserialization
##
## ############################################################
##
func deserialize_scalar*(dst: var matchingOrderBigInt(Banderwagon), src: array[32, byte]): CttCodecScalarStatus =
## Adding an optional Endianness param default at BigEndian
func deserialize_scalar*(dst: var matchingOrderBigInt(Banderwagon), src: array[32, byte], order: static Endianness = bigEndian): CttCodecScalarStatus =
## Deserialize a scalar
## Also validates the scalar range
##
Expand All @@ -151,7 +151,7 @@ func deserialize_scalar*(dst: var matchingOrderBigInt(Banderwagon), src: array[3
##
## This special-cases (and leaks) 0 scalar as this is a special-case in most protocols
## or completely invalid (for secret keys).
dst.unmarshal(src, bigEndian)
dst.unmarshal(src, order)
let status = validate_scalar(dst)
if status != cttCodecScalar_Success:
dst.setZero()
Expand Down
Loading