Add size querying for ECDSA curves.

This commit is contained in:
2019-01-18 21:55:42 -08:00
parent 89deea0337
commit 04b4c79f7a

View File

@@ -7,6 +7,7 @@ pub trait EllipticCurve {
type Unsigned : Clone; type Unsigned : Clone;
type Signed : Clone; type Signed : Clone;
fn size() -> usize;
fn p() -> Self::Unsigned; fn p() -> Self::Unsigned;
fn n() -> Self::Unsigned; fn n() -> Self::Unsigned;
fn SEED() -> Self::Unsigned; fn SEED() -> Self::Unsigned;
@@ -23,6 +24,10 @@ impl EllipticCurve for P192 {
type Unsigned = U192; type Unsigned = U192;
type Signed = I192; type Signed = I192;
fn size() -> usize {
192
}
fn p() -> U192 { fn p() -> U192 {
U192::from_bytes(&[0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, U192::from_bytes(&[0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe,
@@ -82,6 +87,10 @@ impl EllipticCurve for P224 {
type Unsigned = U256; type Unsigned = U256;
type Signed = I256; type Signed = I256;
fn size() -> usize {
224
}
fn p() -> U256 { fn p() -> U256 {
U256::from_bytes(&[ U256::from_bytes(&[
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
@@ -160,6 +169,10 @@ impl EllipticCurve for P256 {
type Signed = I256; type Signed = I256;
type Unsigned = U256; type Unsigned = U256;
fn size() -> usize {
256
}
fn p() -> U256 { fn p() -> U256 {
U256::from_bytes(&[ U256::from_bytes(&[
0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x01,
@@ -239,6 +252,10 @@ impl EllipticCurve for P384 {
type Signed = I384; type Signed = I384;
type Unsigned = U384; type Unsigned = U384;
fn size() -> usize {
384
}
fn p() -> U384 { fn p() -> U384 {
U384::from_bytes(&[ U384::from_bytes(&[
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
@@ -331,6 +348,10 @@ impl EllipticCurve for P521 {
type Signed = I576; type Signed = I576;
type Unsigned = U576; type Unsigned = U576;
fn size() -> usize {
521
}
fn p() -> U576 { fn p() -> U576 {
U576::from_bytes(&[ U576::from_bytes(&[
0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,