Exemple #1
0
def generateId(n):
    field = ec.SubGroup(p=0x05177b8a2a0fd6a4ff55cda06b0924e125f86cad9b,
                        g=(0x0017e7012277e1b4e43f7bf74657e8be08baca175b,
                           0x00aa03a0a82690704697e8c504cb135b2b6eef3c83),
                        n=0x03177f8a2a0fd674ff556aa7b8a7851f88bd53b2c1,
                        h=1)
    curve = ec.Curve(a=0x043182d283fce3880730c9a2fdd3f6016529a166af,
                     b=0x020c61e9459e53d8871bcaadc2dfc8ad5225228035,
                     field=field,
                     name='p1707')
    #k = 0xa78a2374871236e
    k = 0x03177b8a2a0fd674ff556aa7b8a7851f88bd53b2c1
    P = curve.g
    p = curve.field.p
    for i in range(1, n + 1):
        S = k * P
        xn = S.x

        if (xn == None):
            yn1 = S1.y
            k = yn1 + (i - 1) % p
            S = k * P
            xn = S.xp
        #print(xn)
        if (i == n):
            break
        else:
            k = xn + i % p
        S1 = S
    return xn
Exemple #2
0
def get_curve_safe(ec_enum: EC_CURVE_REGISTRY):
    curve_params = ec_enum.value
    try:
        sub_group = ec.SubGroup(
            curve_params["p"], curve_params["g"], curve_params["n"], curve_params["h"])
        curve = ec.Curve(
            curve_params["a"], curve_params["b"], sub_group, ec_enum.name)
    except KeyError:
        raise RuntimeError("Missing parameters for curve %s" % ec_enum.name)
    return curve
def get_curve(name):
    curve_params = {}
    for k, v in EC_CURVE_REGISTRY.items():
        if name.lower() == k.lower():
            curve_params = v
    if curve_params == {}:
        raise ValueError("Unknown elliptic curve name")
    try:
        sub_group = ec.SubGroup(curve_params["p"], curve_params["g"],
                                curve_params["n"], curve_params["h"])
        curve = ec.Curve(curve_params["a"], curve_params["b"], sub_group, name)
    except KeyError:
        raise RuntimeError("Missing parameters for curve %s" % name)
    return curve
Exemple #4
0
import secrets
import base64
from Crypto.Cipher import AES
import hashlib, secrets, binascii


# y^2 = x^3 + ax^2 +b 
a = 2
b = 3

#start point
point = (22,5)

field = ec.SubGroup(97, point, 2000, 1)
#curve = reg.get_curve('brainpoolP256r1')
curve =  ec.Curve(a, b, field)

def compress_point(point):
    return hex(point.x) + hex(point.y % 2)[2:]

def ecc_calc_encryption_keys(pubKey):
    ciphertextPrivKey = secrets.randbelow(curve.field.n)
    ciphertextPubKey = ciphertextPrivKey * curve.g
    sharedECCKey = pubKey * ciphertextPrivKey
    return (sharedECCKey, ciphertextPubKey)

def ecc_calc_decryption_key(privKey, ciphertextPubKey):
    sharedECCKey = ciphertextPubKey * privKey
    return sharedECCKey

def ecc_point_to_256_bit_key(point):
Exemple #5
0
import tinyec.ec as ec

# p la truong cua E
# g la diem sinh

# n la bac cua E
field = ec.SubGroup(p=0x05177b8a2a0fd6a4ff55cda06b0924e125f86cad9b,
                    g=(0x0017e7012277e1b4e43f7bf74657e8be08baca175b,
                       0x00aa03a0a82690704697e8c504cb135b2b6eef3c83),
                    n=0x03177f8a2a0fd674ff556aa7b8a7851f88bd53b2c1,
                    h=1)
curve = ec.Curve(a=0x043182d283fce3880730c9a2fdd3f6016529a166af,
                 b=0x020c61e9459e53d8871bcaadc2dfc8ad5225228035,
                 field=field,
                 name='p1707')
print('curve:', curve)
#k = 0xa78a2374871236e
k = 0x03177b8a2a0fd674ff556aa7b8a7851f88bd53b2c1
P = curve.g
p = curve.field.p
n = 10
for i in range(1, n + 1):
    S = k * P
    xn = S.x

    if (xn == None):
        yn1 = S1.y
        k = yn1 + (i - 1) % p
        S = k * P
        xn = S.xp
    #print(xn)
Exemple #6
0
 def setUp(self):
     self.field = ec.SubGroup(97, (1, 2), 5, 1)
     self.curve = ec.Curve(2, 3, self.field)
     super(TestPoint, self).setUp()
Exemple #7
0
 def test_when_specific_a_and_b_are_used_then_curve_is_singular(self):
     self.assertTrue(ec.Curve(0, 0, self.field).is_singular())
     self.assertTrue(ec.Curve(-3, 2, self.field).is_singular())
     self.assertFalse(ec.Curve(-3, 1, self.field).is_singular())
     self.assertFalse(ec.Curve(2, 2, self.field).is_singular())
2. brainpoolP192r1
3. brainpoolP224r1
4. brainpoolP256r1
5. brainpoolP320r1
6. brainpoolP384r1
7. brainpoolP512r1
8. secp192r1
9. secp224r1
10. secp256r1
11. secp384r1
12. secp521r1
'''
# Example: curve = registry.get_curve('brainpoolP256r1')

field = ec.SubGroup(p=p, g=g, n=n, h=h)
curve = ec.Curve(a=a, b=b, field=field, name=name)

print('The curve is:')
print(curve)
print("Generator point is: ")
print(curve.g)
print("The integer points possible on the curve are: ")
for k in range(0, 14):
    p = k * curve.g
    print(str(k).zfill(2), "*", "G = ", (p.x, p.y))

print()
# User A select private key:
n_a = n
while (n_a >= n):
    n_a = int(input("Enter A's private key(less than n): "))