Skip to content
Merged
Changes from all 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
14 changes: 12 additions & 2 deletions p256/src/arithmetic/projective.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,11 @@ impl GroupEncoding for ProjectivePoint {
}

fn to_bytes(&self) -> Self::Repr {
CompressedPoint::clone_from_slice(self.to_affine().to_encoded_point(true).as_bytes())
let bytes = self.to_affine().to_encoded_point(true);
let bytes = bytes.as_bytes();
let mut result = CompressedPoint::default();
result[..bytes.len()].copy_from_slice(bytes);
result
}
}

Expand Down Expand Up @@ -521,7 +525,7 @@ impl<'a> Neg for &'a ProjectivePoint {
mod tests {
use super::{AffinePoint, ProjectivePoint, Scalar};
use crate::test_vectors::group::{ADD_TEST_VECTORS, MUL_TEST_VECTORS};
use elliptic_curve::group::{ff::PrimeField, prime::PrimeCurveAffine};
use elliptic_curve::group::{ff::PrimeField, prime::PrimeCurveAffine, GroupEncoding};

#[test]
fn affine_to_projective() {
Expand Down Expand Up @@ -665,4 +669,10 @@ mod tests {
assert_eq!(res.y.to_bytes(), coords.1.into());
}
}

#[test]
fn projective_identity_to_bytes() {
// This is technically an invalid SEC1 encoding, but is preferable to panicking.
assert_eq!([0; 33], ProjectivePoint::identity().to_bytes().as_slice());
}
}