From 04b4c79f7a786f241f3691c3475cc173f77cb0b5 Mon Sep 17 00:00:00 2001 From: Adam Wick Date: Fri, 18 Jan 2019 21:55:42 -0800 Subject: [PATCH] Add size querying for ECDSA curves. --- src/ecdsa/curve.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/ecdsa/curve.rs b/src/ecdsa/curve.rs index 7b523ae..b98529a 100644 --- a/src/ecdsa/curve.rs +++ b/src/ecdsa/curve.rs @@ -7,6 +7,7 @@ pub trait EllipticCurve { type Unsigned : Clone; type Signed : Clone; + fn size() -> usize; fn p() -> Self::Unsigned; fn n() -> Self::Unsigned; fn SEED() -> Self::Unsigned; @@ -23,6 +24,10 @@ impl EllipticCurve for P192 { type Unsigned = U192; type Signed = I192; + fn size() -> usize { + 192 + } + fn p() -> U192 { U192::from_bytes(&[0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, @@ -82,6 +87,10 @@ impl EllipticCurve for P224 { type Unsigned = U256; type Signed = I256; + fn size() -> usize { + 224 + } + fn p() -> U256 { U256::from_bytes(&[ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, @@ -160,6 +169,10 @@ impl EllipticCurve for P256 { type Signed = I256; type Unsigned = U256; + fn size() -> usize { + 256 + } + fn p() -> U256 { U256::from_bytes(&[ 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x01, @@ -239,6 +252,10 @@ impl EllipticCurve for P384 { type Signed = I384; type Unsigned = U384; + fn size() -> usize { + 384 + } + fn p() -> U384 { U384::from_bytes(&[ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, @@ -331,6 +348,10 @@ impl EllipticCurve for P521 { type Signed = I576; type Unsigned = U576; + fn size() -> usize { + 521 + } + fn p() -> U576 { U576::from_bytes(&[ 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,