X-Git-Url: http://wagner.pp.ru/gitweb/?a=blobdiff_plain;f=ctypescrypto%2Fec.py;fp=ctypescrypto%2Fec.py;h=d325212c7781d196b1d416575436a5e1845005fe;hb=b4ee51a0aca14c0af5853545b9e524cc1b57b656;hp=0000000000000000000000000000000000000000;hpb=bda9492c89eb38a1aec85220294f6d637ad68724;p=oss%2Fctypescrypto.git diff --git a/ctypescrypto/ec.py b/ctypescrypto/ec.py new file mode 100644 index 0000000..d325212 --- /dev/null +++ b/ctypescrypto/ec.py @@ -0,0 +1,33 @@ +""" +Support for EC keypair operation missing form public libcrypto API +""" + + +def create(curve,num): + """ + Creates EC keypair from the just secret key and curve name + + @param curve - name of elliptic curve + @param num - long number representing key + """ + p=libcrypto.EVP_PKEY_new() + ec=libcrypto.EC_KEY_new_by_curvename(curve.nid) + group=libcrypto.EC_KEY_get0_group(ec) + EC_KEY_set_private_key(ec,bn) + priv_key=libcrypt.BN_new() + ctx=BN_CTX_new() + h="%x"%(num) + libcrypto.BN_hex2bn(byref(priv_key),h) + libcrypto.EC_KEY_set_private_key(ec,priv_key) + pub_key=libcrypto.EC_POINT_new(group) + libcrypto.EC_POINT_mul(group,pub_key,priv_key,None,None,ctx) + libcrypto.BN_free(a) + libcrypto.EVP_PKEY_set1_EC_KEY(p,ec) + libcrypto.EC_KEY_free(ec) + return PKey(ptr=p,cansign=True) + + +libcrypto.EVP_PKEY_new.restype=c_void_p +libcrypto.BN_new.restype=c_void_p +libcrypto.BN_hex2bn.argtypes(POINTER(c_void_p),c_char_p) +libcrypto.EC_KEY_set_private_key