Skip to content

Commit

Permalink
Fix Mod -> mod change.
Browse files Browse the repository at this point in the history
  • Loading branch information
J08nY committed Jul 16, 2024
1 parent 4f04530 commit 2f227ec
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 39 deletions.
8 changes: 4 additions & 4 deletions CPA.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"outputs": [],
"source": [
"from pyecsca.ec.mult import LTRMultiplier\n",
"from pyecsca.ec.mod import Mod\n",
"from pyecsca.ec.mod import mod\n",
"from pyecsca.ec.point import Point, InfinityPoint\n",
"from pyecsca.ec.model import ShortWeierstrassModel\n",
"from pyecsca.ec.curve import EllipticCurve\n",
Expand Down Expand Up @@ -80,11 +80,11 @@
"model = ShortWeierstrassModel()\n",
"coords = model.coordinates[\"projective\"]\n",
"p = 0xd7d1247f\n",
"a = Mod(0xa4a44016, p)\n",
"b = Mod(0x73f76716, p)\n",
"a = mod(0xa4a44016, p)\n",
"b = mod(0x73f76716, p)\n",
"n = 0xd7d2a475\n",
"h = 1\n",
"gx, gy, gz = Mod(0x54eed6d7, p), Mod(0x6f1e55ac, p), Mod(1, p)\n",
"gx, gy, gz = mod(0x54eed6d7, p), mod(0x6f1e55ac, p), mod(1, p)\n",
"generator = Point(coords, X=gx, Y=gy, Z=gz)\n",
"neutral = InfinityPoint(coords)\n",
"\n",
Expand Down
8 changes: 4 additions & 4 deletions DPA.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"outputs": [],
"source": [
"from pyecsca.ec.mult import LTRMultiplier\n",
"from pyecsca.ec.mod import Mod\n",
"from pyecsca.ec.mod import mod\n",
"from pyecsca.ec.point import Point, InfinityPoint\n",
"from pyecsca.ec.model import ShortWeierstrassModel\n",
"from pyecsca.ec.curve import EllipticCurve\n",
Expand Down Expand Up @@ -76,11 +76,11 @@
"model = ShortWeierstrassModel()\n",
"coords = model.coordinates[\"projective\"]\n",
"p = 0xd7d1247f\n",
"a = Mod(0xa4a44016, p)\n",
"b = Mod(0x73f76716, p)\n",
"a = mod(0xa4a44016, p)\n",
"b = mod(0x73f76716, p)\n",
"n = 0xd7d2a475\n",
"h = 1\n",
"gx, gy, gz = Mod(0x54eed6d7, p), Mod(0x6f1e55ac, p), Mod(1, p)\n",
"gx, gy, gz = mod(0x54eed6d7, p), mod(0x6f1e55ac, p), mod(1, p)\n",
"generator = Point(coords, X=gx, Y=gy, Z=gz)\n",
"neutral = InfinityPoint(coords)\n",
"\n",
Expand Down
8 changes: 4 additions & 4 deletions emulator.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"outputs": [],
"source": [
"from pyecsca.ec.mult import LTRMultiplier\n",
"from pyecsca.ec.mod import Mod\n",
"from pyecsca.ec.mod import mod\n",
"from pyecsca.ec.point import Point, InfinityPoint\n",
"from pyecsca.ec.model import ShortWeierstrassModel\n",
"from pyecsca.ec.curve import EllipticCurve\n",
Expand Down Expand Up @@ -74,11 +74,11 @@
"model = ShortWeierstrassModel()\n",
"coords = model.coordinates[\"projective\"]\n",
"p = 0xd7d1247f\n",
"a = Mod(0xa4a44016, p)\n",
"b = Mod(0x73f76716, p)\n",
"a = mod(0xa4a44016, p)\n",
"b = mod(0x73f76716, p)\n",
"n = 0xd7d2a475\n",
"h = 1\n",
"gx, gy, gz = Mod(0x54eed6d7, p), Mod(0x6f1e55ac, p), Mod(1, p)\n",
"gx, gy, gz = mod(0x54eed6d7, p), mod(0x6f1e55ac, p), mod(1, p)\n",
"generator = Point(coords, X=gx, Y=gy, Z=gz)\n",
"neutral = InfinityPoint(coords)\n",
"\n",
Expand Down
14 changes: 7 additions & 7 deletions re/epa.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"from pyecsca.ec.coordinates import AffineCoordinateModel\n",
"from pyecsca.ec.curve import EllipticCurve\n",
"from pyecsca.ec.params import DomainParameters, load_params_ectester\n",
"from pyecsca.ec.mod import Mod, miller_rabin, gcd\n",
"from pyecsca.ec.mod import mod, miller_rabin, gcd\n",
"from pyecsca.ec.point import Point, InfinityPoint\n",
"from pyecsca.ec.error import NonInvertibleError\n",
"from pyecsca.ec.mult import LTRMultiplier, AccumulationOrder\n",
Expand Down Expand Up @@ -155,8 +155,8 @@
" factors = list(results.keys())\n",
" xs = list(map(lambda factor: int(results[factor].x), factors))\n",
" ys = list(map(lambda factor: int(results[factor].y), factors))\n",
" res_x = Mod(int(crt(factors, xs)[0]), top.curve.prime)\n",
" res_y = Mod(int(crt(factors, ys)[0]), top.curve.prime)\n",
" res_x = mod(int(crt(factors, xs)[0]), top.curve.prime)\n",
" res_y = mod(int(crt(factors, ys)[0]), top.curve.prime)\n",
" res = Point(affine, x=res_x, y=res_y)\n",
" return res.to_model(top.curve.coordinate_model, top.curve, randomized=randomized)"
]
Expand All @@ -178,7 +178,7 @@
"source": [
"def project_down(point, subcurve):\n",
" \"\"\"Project a point down onto a subcurve.\"\"\"\n",
" return Point(subcurve.coordinate_model, **{name: Mod(int(value), subcurve.prime) for name, value in point.coords.items()})\n",
" return Point(subcurve.coordinate_model, **{name: mod(int(value), subcurve.prime) for name, value in point.coords.items()})\n",
"\n",
"def split_params(params):\n",
" \"\"\"Split composite \"p\" params into subcurves.\"\"\"\n",
Expand All @@ -189,7 +189,7 @@
" # Construct the curves\n",
" for factor in sorted(factors.keys()):\n",
" p_i = factor\n",
" parameters_i = {name: Mod(int(value), p_i) for name, value in params.curve.parameters.items()}\n",
" parameters_i = {name: mod(int(value), p_i) for name, value in params.curve.parameters.items()}\n",
" curve_i = EllipticCurve(params.curve.model, params.curve.coordinate_model, p_i, params.curve.neutral, parameters_i)\n",
" generator_i = project_down(params.generator, curve_i)\n",
" params_i = DomainParameters(curve_i, generator_i, 0, 1)\n",
Expand Down Expand Up @@ -225,8 +225,8 @@
" factors = list(results.keys())\n",
" xs = list(map(lambda factor: int(results[factor].x), factors))\n",
" ys = list(map(lambda factor: int(results[factor].y), factors))\n",
" res_x = Mod(int(crt(factors, xs)[0]), top.curve.prime)\n",
" res_y = Mod(int(crt(factors, ys)[0]), top.curve.prime)\n",
" res_x = mod(int(crt(factors, xs)[0]), top.curve.prime)\n",
" res_y = mod(int(crt(factors, ys)[0]), top.curve.prime)\n",
" return Point(affine, x=res_x, y=res_y)"
]
},
Expand Down
18 changes: 9 additions & 9 deletions re/rpa.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"from pyecsca.ec.params import DomainParameters, get_params\n",
"from pyecsca.ec.formula import FormulaAction\n",
"from pyecsca.ec.point import Point\n",
"from pyecsca.ec.mod import Mod\n",
"from pyecsca.ec.mod import mod\n",
"from pyecsca.ec.mult import *\n",
"from pyecsca.misc.utils import silent, TaskExecutor\n",
"from pyecsca.sca.trace.sampling import downsample_average, downsample_max\n",
Expand Down Expand Up @@ -94,18 +94,18 @@
"\n",
"# A 64-bit prime order curve for testing things out\n",
"p = 0xc50de883f0e7b167\n",
"a = Mod(0x4833d7aa73fa6694, p)\n",
"b = Mod(0xa6c44a61c5323f6a, p)\n",
"gx = Mod(0x5fd1f7d38d4f2333, p)\n",
"gy = Mod(0x21f43957d7e20ceb, p)\n",
"a = mod(0x4833d7aa73fa6694, p)\n",
"b = mod(0xa6c44a61c5323f6a, p)\n",
"gx = mod(0x5fd1f7d38d4f2333, p)\n",
"gy = mod(0x21f43957d7e20ceb, p)\n",
"n = 0xc50de885003b80eb\n",
"h = 1\n",
"\n",
"# A (0, y) RPA point on the above curve, in affine coords.\n",
"P0_aff = Point(coordsaff, x=Mod(0, p), y=Mod(0x1742befa24cd8a0d, p))\n",
"P0_aff = Point(coordsaff, x=mod(0, p), y=mod(0x1742befa24cd8a0d, p))\n",
"\n",
"infty = Point(coords, X=Mod(0, p), Y=Mod(1, p), Z=Mod(0, p))\n",
"g = Point(coords, X=gx, Y=gy, Z=Mod(1, p))\n",
"infty = Point(coords, X=mod(0, p), Y=mod(1, p), Z=mod(0, p))\n",
"g = Point(coords, X=gx, Y=gy, Z=mod(1, p))\n",
"\n",
"curve = EllipticCurve(model, coords, p, infty, dict(a=a,b=b))\n",
"params = DomainParameters(curve, g, n, h)\n",
Expand Down Expand Up @@ -225,7 +225,7 @@
"outputs": [],
"source": [
"k = 108\n",
"kinv = Mod(k, n).inverse()\n",
"kinv = mod(k, n).inverse()\n",
"P0_target = curve.affine_multiply(P0_aff, int(kinv)).to_model(coords, curve)\n",
"\n",
"print(\"Original P0\", P0_aff)\n",
Expand Down
14 changes: 7 additions & 7 deletions re/structural.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"from pyecsca.ec.formula import FormulaAction\n",
"from pyecsca.ec.op import OpType\n",
"from pyecsca.ec.point import Point\n",
"from pyecsca.ec.mod import Mod\n",
"from pyecsca.ec.mod import mod\n",
"from pyecsca.ec.mult import *\n",
"from pyecsca.ec.context import DefaultContext, local\n",
"from pyecsca.sca.re.rpa import MultipleContext\n",
Expand Down Expand Up @@ -65,15 +65,15 @@
"\n",
"# A 64-bit prime order curve for testing things out\n",
"p = 0xc50de883f0e7b167\n",
"a = Mod(0x4833d7aa73fa6694, p)\n",
"b = Mod(0xa6c44a61c5323f6a, p)\n",
"gx = Mod(0x5fd1f7d38d4f2333, p)\n",
"gy = Mod(0x21f43957d7e20ceb, p)\n",
"a = mod(0x4833d7aa73fa6694, p)\n",
"b = mod(0xa6c44a61c5323f6a, p)\n",
"gx = mod(0x5fd1f7d38d4f2333, p)\n",
"gy = mod(0x21f43957d7e20ceb, p)\n",
"n = 0xc50de885003b80eb\n",
"h = 1\n",
"\n",
"infty = Point(coords, X=Mod(0, p), Y=Mod(1, p), Z=Mod(0, p))\n",
"g = Point(coords, X=gx, Y=gy, Z=Mod(1, p))\n",
"infty = Point(coords, X=mod(0, p), Y=mod(1, p), Z=mod(0, p))\n",
"g = Point(coords, X=gx, Y=gy, Z=mod(1, p))\n",
"\n",
"curve = EllipticCurve(model, coords, p, infty, dict(a=a,b=b))\n",
"params = DomainParameters(curve, g, n, h)"
Expand Down
8 changes: 4 additions & 4 deletions re/zvp.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"from pyecsca.ec.params import DomainParameters, load_params_ecgen\n",
"from pyecsca.ec.formula import FormulaAction, AdditionFormula, DoublingFormula\n",
"from pyecsca.ec.point import Point\n",
"from pyecsca.ec.mod import Mod, gcd, SymbolicMod\n",
"from pyecsca.ec.mod import mod, gcd, SymbolicMod\n",
"from pyecsca.ec.context import DefaultContext, local\n",
"from pyecsca.ec.mult import LTRMultiplier, AccumulationOrder\n",
"from pyecsca.ec.error import NonInvertibleError, UnsatisfiedAssumptionError\n",
Expand Down Expand Up @@ -152,8 +152,8 @@
"n = 0xc50de885003b80eb\n",
"h = 1\n",
"\n",
"infty = Point(coords, X=Mod(0, p), Y=Mod(1, p), Z=Mod(0, p))\n",
"g = Point(coords, X=gx, Y=gy, Z=Mod(1, p))\n",
"infty = Point(coords, X=mod(0, p), Y=mod(1, p), Z=mod(0, p))\n",
"g = Point(coords, X=gx, Y=gy, Z=mod(1, p))\n",
"\n",
"curve = EllipticCurve(model, coords, p, infty, dict(a=a,b=b))\n",
"params = DomainParameters(curve, g, n, h)\n",
Expand Down Expand Up @@ -518,7 +518,7 @@
" k = ks[0]\n",
" else:\n",
" # zvp_points assumes (P, [k]P)\n",
" ks_mod = list(map(lambda v: Mod(v, params.order), ks))\n",
" ks_mod = list(map(lambda v: mod(v, params.order), ks))\n",
" k = int(ks_mod[1] / ks_mod[0])\n",
" polys = polynomials[params][op]\n",
" for poly in polys:\n",
Expand Down

0 comments on commit 2f227ec

Please sign in to comment.