Handle negative scaling factors.

This commit is contained in:
2018-12-30 21:16:16 -08:00
parent eb82edea7e
commit f3494d8524
3 changed files with 5024 additions and 5016 deletions

View File

@@ -30,7 +30,7 @@ impl Clone for Point<P192> {
impl ECCPoint for Point<P192> {
type Curve = P192;
type Scale = U192;
type Scale = I192;
fn default() -> Point<P192>
{
@@ -93,7 +93,7 @@ impl ECCPoint for Point<P192> {
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());
#[allow(non_snake_case)]
@@ -118,9 +118,13 @@ impl ECCPoint for Point<P192> {
bit -= 1;
}
if d.is_negative() {
Q.negate()
} else {
Q
}
}
}
#[cfg(test)]
mod tests {
@@ -204,7 +208,7 @@ mod tests {
let x = I192::new(*negx, U192::from_bytes(xbytes));
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 b = I192::new(*negb, U192::from_bytes(bbytes));
let point = Point{ x: x, y: y };

View File

@@ -5,7 +5,8 @@ module ECDSATesting(
import Crypto.PubKey.ECC.Prim(scalarGenerate,pointAdd,pointNegate,pointDouble,pointBaseMul,pointMul)
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 Math(showX)
import Task(Task(..))
@@ -87,16 +88,19 @@ scaleTest name curve = Task {
go (memory0, drg0) =
let (scalar0, drg1) = withDRG drg0 (scalarGenerate curve)
(scalar1, drg2) = withDRG drg1 (scalarGenerate curve)
(negbs, drg3) = randomBytesGenerate 1 drg2
[negbyte] = S.unpack negbs
k = if odd negbyte then scalar1 else -scalar1
point = pointBaseMul curve scalar0
respnt = pointMul curve scalar1 point
respnt = pointMul curve k point
in case (point, respnt) of
(PointO, _) -> go (memory0, drg2)
(_, PointO) -> go (memory0, drg2)
(PointO, _) -> go (memory0, drg3)
(_, PointO) -> go (memory0, drg3)
(Point basex basey, Point resx resy) ->
let res = Map.fromList [("x", showX basex), ("y", showX basey),
("k", showX scalar1),
("k", showX k),
("a", showX resx), ("b", showX resy)]
in (res, scalar0, (memory0, drg2))
in (res, scalar0, (memory0, drg3))
generateTasks :: (String, Curve) -> [Task]
generateTasks (name, curve) = [negateTest name curve,

File diff suppressed because it is too large Load Diff