mirror of
https://github.com/darkrenaissance/darkfi.git
synced 2026-01-09 14:48:08 -05:00
rename script/research/elliptic_curves/ to script/research/ec/
This commit is contained in:
40
script/research/ec/curve.py
Normal file
40
script/research/ec/curve.py
Normal file
@@ -0,0 +1,40 @@
|
||||
from finite_fields import finitefield
|
||||
|
||||
def add(x_1, y_1, x_2, y_2):
|
||||
if (x_1, y_1) == (x_2, y_2):
|
||||
if y_1 == 0:
|
||||
return None
|
||||
|
||||
# slope of the tangent line
|
||||
m = (3 * x_1 * x_1 + a) / (2 * y_1)
|
||||
return None
|
||||
else:
|
||||
if x_1 == x_2:
|
||||
return None
|
||||
|
||||
# slope of the secant line
|
||||
m = (y_2 - y_1) / (x_2 - x_1)
|
||||
|
||||
x_3 = m*m - x_1 - x_2
|
||||
y_3 = m*(x_1 - x_3) - y_1
|
||||
|
||||
return (x_3, y_3)
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Vesta
|
||||
q = 0x40000000000000000000000000000000224698fc0994a8dd8c46eb2100000001
|
||||
fq = finitefield.IntegersModP(q)
|
||||
|
||||
a, b = fq(0x00), fq(0x05)
|
||||
|
||||
p = 0x40000000000000000000000000000000224698fc094cf91b992d30ed00000001
|
||||
|
||||
C = (fq(0x1ca18c7c3fcb110f9e92c694ce552238f95e9f9b911599cedaff6018cfc5ed52), fq(0x3ad6133a791e41f3e062d370b40e97e77d20effc00b7ee88c4bb097d245cb438))
|
||||
D = (fq(0x3e544e611bb895166afe1a46c6e551c47968daf962d824f79f795cb53585b098), fq(0x2fd03c4da47baf2dfd251e85d18864d4885ddd0e8df648550565b850b79349e3))
|
||||
C_plus_D = (fq(0x06f822cbde350215558c46aac9e60eee31afd942ca6da568845ca4f8fe911e17), fq(0x3e294e73970abc197dfff1a14e74cb20c11b81422d9f920c7b0b0c63affdf67b))
|
||||
|
||||
result = add(C[0], C[1], D[0], D[1])
|
||||
print(result)
|
||||
print(list("%x" % x.n for x in result))
|
||||
assert result[0] == C_plus_D[0]
|
||||
assert result[1] == C_plus_D[1]
|
||||
1
script/research/ec/finite_fields
Symbolic link
1
script/research/ec/finite_fields
Symbolic link
@@ -0,0 +1 @@
|
||||
../finite_fields/
|
||||
26
script/research/ec/pairing/2.2.2-ecdlp.sage
Normal file
26
script/research/ec/pairing/2.2.2-ecdlp.sage
Normal file
@@ -0,0 +1,26 @@
|
||||
q = 1021
|
||||
K = GF(q)
|
||||
E = EllipticCurve(K, [905, 100])
|
||||
print(E)
|
||||
print(f"Group order is: {E.cardinality()}")
|
||||
P = E(1006, 416)
|
||||
assert P.additive_order() == E.cardinality()
|
||||
|
||||
Q = E(612, 827)
|
||||
|
||||
matches = {}
|
||||
|
||||
for j, m in factor(E.cardinality()):
|
||||
assert m == 1
|
||||
|
||||
P_j = int(E.cardinality() / j) * P
|
||||
Q_j = int(E.cardinality() / j) * Q
|
||||
|
||||
for k in range(j):
|
||||
if k * P_j == Q_j:
|
||||
#print(f"Match found for j = {j}!")
|
||||
matches[j] = k
|
||||
break
|
||||
|
||||
k = crt(list(matches.values()), list(matches.keys()))
|
||||
print(f"k = {k} mod {E.cardinality()}")
|
||||
22
script/research/ec/pairing/2.2.4-deuring.sage
Normal file
22
script/research/ec/pairing/2.2.4-deuring.sage
Normal file
@@ -0,0 +1,22 @@
|
||||
import math
|
||||
def hasse_interval(q):
|
||||
interval = (q + 1 - 2 * sqrt(q)).n(), (q + 1 + 2 * sqrt(q)).n()
|
||||
return math.ceil(interval[0]), math.floor(interval[1])
|
||||
|
||||
q = 23
|
||||
K = GF(q)
|
||||
|
||||
low, high = hasse_interval(23)
|
||||
|
||||
for i in range(100):
|
||||
a = K.random_element()
|
||||
b = K.random_element()
|
||||
|
||||
try:
|
||||
E = EllipticCurve(K, [a, b])
|
||||
except:
|
||||
continue
|
||||
|
||||
assert E.cardinality() >= low
|
||||
assert E.cardinality() <= high
|
||||
|
||||
Reference in New Issue
Block a user