Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Redundancy of Fields among curves #41

Merged
merged 12 commits into from
Mar 5, 2019
Merged
9 changes: 6 additions & 3 deletions py_ecc/bls12_381/bls12_381_curve.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
from __future__ import absolute_import

from py_ecc.fields import (
bls12_381_FQ as FQ,
bls12_381_FQ2 as FQ2,
bls12_381_FQ12 as FQ12,
)

from .bls12_381_field_elements import (
field_modulus,
FQ,
FQ2,
FQ12,
)


Expand Down
7 changes: 5 additions & 2 deletions py_ecc/bls12_381/bls12_381_pairing.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
from __future__ import absolute_import

from py_ecc.fields import (
bls12_381_FQ as FQ,
bls12_381_FQ12 as FQ12,
)

from .bls12_381_curve import (
double,
add,
Expand All @@ -13,8 +18,6 @@
)
from .bls12_381_field_elements import (
field_modulus,
FQ,
FQ12,
)


Expand Down
11 changes: 7 additions & 4 deletions py_ecc/bn128/bn128_curve.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
cast,
)

from py_ecc.fields import (
bn128_FQ as FQ,
bn128_FQ2 as FQ2,
bn128_FQ12 as FQ12,
bn128_FQP as FQP,
)

from py_ecc.typing import (
Field,
GeneralPoint,
Expand All @@ -12,10 +19,6 @@

from .bn128_field_elements import (
field_modulus,
FQ,
FQ2,
FQ12,
FQP,
)


Expand Down
9 changes: 6 additions & 3 deletions py_ecc/bn128/bn128_pairing.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
cast,
)

from py_ecc.fields import (
bn128_FQ as FQ,
bn128_FQ12 as FQ12,
bn128_FQP as FQP,
)

from py_ecc.typing import (
Field,
FQPoint2D,
Expand All @@ -25,9 +31,6 @@
)
from .bn128_field_elements import (
field_modulus,
FQ,
FQ12,
FQP,
)


Expand Down
160 changes: 160 additions & 0 deletions py_ecc/fields/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
from .field_elements import (
FQ,
FQP,
FQ2,
FQ12,
)

from .field_properties import (
field_properties,
)

from .optimized_field_elements import (
FQ as optimized_FQ,
FQP as optimized_FQP,
FQ2 as optimized_FQ2,
FQ12 as optimized_FQ12,
)


# Create seperate classes for all Fields for each curve

bn128_FQ = type(
Bhargavasomu marked this conversation as resolved.
Show resolved Hide resolved
"bn128_FQ",
(FQ,),
{
'curve_name': "bn128",
'field_modulus': field_properties["bn128"]["field_modulus"],
}
)
bn128_FQP = type(
"bn128_FQP",
(FQP,),
{
'curve_name': "bn128",
'field_modulus': field_properties["bn128"]["field_modulus"],
}
)
bn128_FQ2 = type(
"bn128_FQ2",
(FQ2,),
{
'curve_name': "bn128",
'field_modulus': field_properties["bn128"]["field_modulus"],
'FQ2_MODULUS_COEFFS': field_properties["bn128"]["fq2_modulus_coeffs"],
}
)
bn128_FQ12 = type(
"bn128_FQ12",
(FQ12,),
{
'curve_name': "bn128",
'field_modulus': field_properties["bn128"]["field_modulus"],
'FQ12_MODULUS_COEFFS': field_properties["bn128"]["fq12_modulus_coeffs"],
}
)

bls12_381_FQ = type(
"bls12_381_FQ",
(FQ,),
{
'curve_name': "bls12_381",
'field_modulus': field_properties["bls12_381"]["field_modulus"],
}
)
bls12_381_FQP = type(
"bls12_381_FQP",
(FQP,),
{
'curve_name': "bls12_381",
'field_modulus': field_properties["bls12_381"]["field_modulus"],
}
)
bls12_381_FQ2 = type(
"bls12_381_FQ2",
(FQ2,),
{
'curve_name': "bls12_381",
'field_modulus': field_properties["bls12_381"]["field_modulus"],
'FQ2_MODULUS_COEFFS': field_properties["bls12_381"]["fq2_modulus_coeffs"],
}
)
bls12_381_FQ12 = type(
"bls12_381_FQ12",
(FQ12,),
{
'curve_name': "bls12_381",
'field_modulus': field_properties["bls12_381"]["field_modulus"],
'FQ12_MODULUS_COEFFS': field_properties["bls12_381"]["fq12_modulus_coeffs"],
}
)

optimized_bn128_FQ = type(
"optimized_bn128_FQ",
(optimized_FQ,),
{
'curve_name': "bn128",
'field_modulus': field_properties["bn128"]["field_modulus"],
}
)
optimized_bn128_FQP = type(
"optimized_bn128_FQP",
(optimized_FQP,),
{
'curve_name': "bn128",
'field_modulus': field_properties["bn128"]["field_modulus"],
}
)
optimized_bn128_FQ2 = type(
"optimized_bn128_FQ2",
(optimized_FQ2,),
{
'curve_name': "bn128",
'field_modulus': field_properties["bn128"]["field_modulus"],
'FQ2_MODULUS_COEFFS': field_properties["bn128"]["fq2_modulus_coeffs"],
}
)
optimized_bn128_FQ12 = type(
"optimized_bn128_FQ12",
(optimized_FQ12,),
{
'curve_name': "bn128",
'field_modulus': field_properties["bn128"]["field_modulus"],
'FQ12_MODULUS_COEFFS': field_properties["bn128"]["fq12_modulus_coeffs"],
}
)

optimized_bls12_381_FQ = type(
"optimized_bls12_381_FQ",
(optimized_FQ,),
{
'curve_name': "bls12_381",
'field_modulus': field_properties["bls12_381"]["field_modulus"],
}
)
optimized_bls12_381_FQP = type(
"optimized_bls12_381_FQP",
(optimized_FQP,),
{
'curve_name': "bls12_381",
'field_modulus': field_properties["bls12_381"]["field_modulus"],
}
)
optimized_bls12_381_FQ2 = type(
"optimized_bls12_381_FQ2",
(optimized_FQ2,),
{
'curve_name': "bls12_381",
'field_modulus': field_properties["bls12_381"]["field_modulus"],
'FQ2_MODULUS_COEFFS': field_properties["bls12_381"]["fq2_modulus_coeffs"],
}
)
optimized_bls12_381_FQ12 = type(
"optimized_bls12_381_FQ12",
(optimized_FQ12,),
{
'curve_name': "bls12_381",
'field_modulus': field_properties["bls12_381"]["field_modulus"],
'FQ12_MODULUS_COEFFS': field_properties["bls12_381"]["fq12_modulus_coeffs"],
}
)
Loading