- 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)
+ if group is None:
+ raise PKeyError("EC_KEY_get0_group")
+ libcrypto.EC_GROUP_set_asn1_flag(group,1)
+ raw_key=libcrypto.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")
+ order=libcrypto.BN_new()
+ if order is None:
+ raise PKeyError("BN_new")
+ priv_key = libcrypto.BN_new()
+ if priv_key is None:
+ raise PKeyError("BN_new")
+ if libcrypto.EC_GROUP_get_order(group,order,ctx) <=0:
+ raise PKeyError("EC_GROUP_get_order")
+ if libcrypto.BN_nnmod(priv_key,raw_key,order,ctx) <=0:
+ raise PKeyError("BN_nnmod")
+ if libcrypto.EC_KEY_set_private_key(ec,priv_key)<=0:
+ raise PKeyError("EC_KEY_set_private_key")