Handle negative scaling factors.
This commit is contained in:
@@ -30,7 +30,7 @@ impl Clone for Point<P192> {
|
|||||||
|
|
||||||
impl ECCPoint for Point<P192> {
|
impl ECCPoint for Point<P192> {
|
||||||
type Curve = P192;
|
type Curve = P192;
|
||||||
type Scale = U192;
|
type Scale = I192;
|
||||||
|
|
||||||
fn default() -> Point<P192>
|
fn default() -> Point<P192>
|
||||||
{
|
{
|
||||||
@@ -93,7 +93,7 @@ impl ECCPoint for Point<P192> {
|
|||||||
Point{ x: I192::from(xr), y: I192::from(yr) }
|
Point{ x: I192::from(xr), y: I192::from(yr) }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn scale(&self, d: &U192) -> Point<P192>
|
fn scale(&self, d: &I192) -> Point<P192>
|
||||||
{
|
{
|
||||||
assert!(!d.is_zero());
|
assert!(!d.is_zero());
|
||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
@@ -118,7 +118,11 @@ impl ECCPoint for Point<P192> {
|
|||||||
bit -= 1;
|
bit -= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
Q
|
if d.is_negative() {
|
||||||
|
Q.negate()
|
||||||
|
} else {
|
||||||
|
Q
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -204,7 +208,7 @@ mod tests {
|
|||||||
|
|
||||||
let x = I192::new(*negx, U192::from_bytes(xbytes));
|
let x = I192::new(*negx, U192::from_bytes(xbytes));
|
||||||
let y = I192::new(*negy, U192::from_bytes(ybytes));
|
let y = I192::new(*negy, U192::from_bytes(ybytes));
|
||||||
let k = U192::from_bytes(kbytes);
|
let k = I192::new(*negk, U192::from_bytes(kbytes));
|
||||||
let a = I192::new(*nega, U192::from_bytes(abytes));
|
let a = I192::new(*nega, U192::from_bytes(abytes));
|
||||||
let b = I192::new(*negb, U192::from_bytes(bbytes));
|
let b = I192::new(*negb, U192::from_bytes(bbytes));
|
||||||
let point = Point{ x: x, y: y };
|
let point = Point{ x: x, y: y };
|
||||||
|
|||||||
@@ -5,7 +5,8 @@ module ECDSATesting(
|
|||||||
|
|
||||||
import Crypto.PubKey.ECC.Prim(scalarGenerate,pointAdd,pointNegate,pointDouble,pointBaseMul,pointMul)
|
import Crypto.PubKey.ECC.Prim(scalarGenerate,pointAdd,pointNegate,pointDouble,pointBaseMul,pointMul)
|
||||||
import Crypto.PubKey.ECC.Types(Curve,CurveName(..),Point(..),getCurveByName)
|
import Crypto.PubKey.ECC.Types(Curve,CurveName(..),Point(..),getCurveByName)
|
||||||
import Crypto.Random(withDRG)
|
import Crypto.Random(DRG(..),withDRG)
|
||||||
|
import qualified Data.ByteString as S
|
||||||
import qualified Data.Map.Strict as Map
|
import qualified Data.Map.Strict as Map
|
||||||
import Math(showX)
|
import Math(showX)
|
||||||
import Task(Task(..))
|
import Task(Task(..))
|
||||||
@@ -87,16 +88,19 @@ scaleTest name curve = Task {
|
|||||||
go (memory0, drg0) =
|
go (memory0, drg0) =
|
||||||
let (scalar0, drg1) = withDRG drg0 (scalarGenerate curve)
|
let (scalar0, drg1) = withDRG drg0 (scalarGenerate curve)
|
||||||
(scalar1, drg2) = withDRG drg1 (scalarGenerate curve)
|
(scalar1, drg2) = withDRG drg1 (scalarGenerate curve)
|
||||||
point = pointBaseMul curve scalar0
|
(negbs, drg3) = randomBytesGenerate 1 drg2
|
||||||
respnt = pointMul curve scalar1 point
|
[negbyte] = S.unpack negbs
|
||||||
|
k = if odd negbyte then scalar1 else -scalar1
|
||||||
|
point = pointBaseMul curve scalar0
|
||||||
|
respnt = pointMul curve k point
|
||||||
in case (point, respnt) of
|
in case (point, respnt) of
|
||||||
(PointO, _) -> go (memory0, drg2)
|
(PointO, _) -> go (memory0, drg3)
|
||||||
(_, PointO) -> go (memory0, drg2)
|
(_, PointO) -> go (memory0, drg3)
|
||||||
(Point basex basey, Point resx resy) ->
|
(Point basex basey, Point resx resy) ->
|
||||||
let res = Map.fromList [("x", showX basex), ("y", showX basey),
|
let res = Map.fromList [("x", showX basex), ("y", showX basey),
|
||||||
("k", showX scalar1),
|
("k", showX k),
|
||||||
("a", showX resx), ("b", showX resy)]
|
("a", showX resx), ("b", showX resy)]
|
||||||
in (res, scalar0, (memory0, drg2))
|
in (res, scalar0, (memory0, drg3))
|
||||||
|
|
||||||
generateTasks :: (String, Curve) -> [Task]
|
generateTasks :: (String, Curve) -> [Task]
|
||||||
generateTasks (name, curve) = [negateTest name curve,
|
generateTasks (name, curve) = [negateTest name curve,
|
||||||
|
|||||||
10010
testdata/ecc/scale/P192.test
vendored
10010
testdata/ecc/scale/P192.test
vendored
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user