X-Git-Url: http://wagner.pp.ru/gitweb/?a=blobdiff_plain;ds=sidebyside;f=ctypescrypto%2Fec.py;h=047aad97a1d6db7225d8f6b5c967647df364ba22;hb=ec92bf04b008b0401014cae90fa2dfca18efa02c;hp=3d880cb6a5c174ec671b24e42de555ec11680dab;hpb=d817f7ee1103370ab5355871e744dfb5c15bf2b4;p=oss%2Fctypescrypto.git diff --git a/ctypescrypto/ec.py b/ctypescrypto/ec.py index 3d880cb..047aad9 100644 --- a/ctypescrypto/ec.py +++ b/ctypescrypto/ec.py @@ -5,12 +5,14 @@ from ctypescrypto.pkey import PKey, PKeyError from ctypes import c_void_p,c_char_p,c_int,byref from ctypescrypto import libcrypto +__all__ = [ 'create'] + def create(curve,data): """ Creates EC keypair from the just secret key and curve name @param curve - name of elliptic curve - @param num - long number representing key + @param num - byte array or long number representing key """ ec=libcrypto.EC_KEY_new_by_curve_name(curve.nid) if ec is None: @@ -20,13 +22,16 @@ def create(curve,data): raise PKeyError("EC_KEY_get0_group") libcrypto.EC_GROUP_set_asn1_flag(group,1) raw_key=libcrypto.BN_new() - if raw_key is None: - raise PKeyError("BN_new") + if isinstance(data,int): + BN_hex2bn(byref(raw_key),hex(data)) + else: + if raw_key is None: + raise PKeyError("BN_new") + if libcrypto.BN_bin2bn(data,len(data),raw_key) is None: + raise PKeyError("BN_bin2bn") ctx=libcrypto.BN_CTX_new() if ctx is None: raise PKeyError("BN_CTX_new") - if libcrypto.BN_bin2bn(data,len(data),raw_key) is None: - raise PKeyError("BN_bin2bn") order=libcrypto.BN_new() if order is None: raise PKeyError("BN_new")