]> www.wagner.pp.ru Git - oss/ctypescrypto.git/blob - ctypescrypto/ec.py
d325212c7781d196b1d416575436a5e1845005fe
[oss/ctypescrypto.git] / ctypescrypto / ec.py
1 """
2 Support for EC keypair operation missing form public libcrypto API
3 """
4
5
6 def create(curve,num):
7         """
8                 Creates EC keypair from the just secret key and curve name
9                 
10                 @param curve - name of elliptic curve
11                 @param num - long number representing key
12         """
13         p=libcrypto.EVP_PKEY_new()
14         ec=libcrypto.EC_KEY_new_by_curvename(curve.nid)
15         group=libcrypto.EC_KEY_get0_group(ec)
16         EC_KEY_set_private_key(ec,bn)
17         priv_key=libcrypt.BN_new()
18         ctx=BN_CTX_new()
19         h="%x"%(num)
20         libcrypto.BN_hex2bn(byref(priv_key),h)
21         libcrypto.EC_KEY_set_private_key(ec,priv_key)
22         pub_key=libcrypto.EC_POINT_new(group)
23         libcrypto.EC_POINT_mul(group,pub_key,priv_key,None,None,ctx)
24         libcrypto.BN_free(a)
25         libcrypto.EVP_PKEY_set1_EC_KEY(p,ec)
26         libcrypto.EC_KEY_free(ec)
27         return PKey(ptr=p,cansign=True)
28
29
30 libcrypto.EVP_PKEY_new.restype=c_void_p
31 libcrypto.BN_new.restype=c_void_p
32 libcrypto.BN_hex2bn.argtypes(POINTER(c_void_p),c_char_p)
33 libcrypto.EC_KEY_set_private_key