Skip to content

Commit

Permalink
elliptic-curve: fix FieldBytesEncoding ranges (#1287)
Browse files Browse the repository at this point in the history
  • Loading branch information
wangwillian0 committed Apr 3, 2023
1 parent 3562e79 commit e8804f6
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions elliptic-curve/src/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ where
fn decode_field_bytes(field_bytes: &FieldBytes<C>) -> Self {
debug_assert!(field_bytes.len() <= Self::ByteSize::USIZE);
let mut byte_array = ByteArray::<Self>::default();
byte_array[..field_bytes.len()].copy_from_slice(field_bytes);
let offset = Self::ByteSize::USIZE - field_bytes.len();
byte_array[offset..].copy_from_slice(field_bytes);
Self::from_be_byte_array(byte_array)
}

Expand All @@ -43,8 +44,8 @@ where
let mut field_bytes = FieldBytes::<C>::default();
debug_assert!(field_bytes.len() <= Self::ByteSize::USIZE);

let len = field_bytes.len();
field_bytes.copy_from_slice(&self.to_be_byte_array()[..len]);
let offset = Self::ByteSize::USIZE - field_bytes.len();
field_bytes.copy_from_slice(&self.to_be_byte_array()[offset..]);
field_bytes
}
}

0 comments on commit e8804f6

Please sign in to comment.