def _truncate_digest_for_ecdsa(ec_key_cdata, digest, backend):
 _lib = backend._lib
 _ffi = backend._ffi
 group = _lib.EC_KEY_get0_group(ec_key_cdata)
 with backend._tmp_bn_ctx() as bn_ctx:
  order = _lib.BN_CTX_get(bn_ctx)
  assert (order != _ffi.NULL)
  res = _lib.EC_GROUP_get_order(group, order, bn_ctx)
  assert (res == 1)
  order_bits = _lib.BN_num_bits(order)
 return _truncate_digest(digest, order_bits)

def _truncate_digest_for_ecdsa ( ec_key_cdata , digest , backend ) : _lib = backend . _lib _ffi = backend . _ffi group = _lib . EC_KEY_get0_group ( ec_key_cdata ) with backend . _tmp_bn_ctx ( ) as bn_ctx : order = _lib . BN_CTX_get ( bn_ctx ) assert ( order != _ffi . NULL ) res = _lib . EC_GROUP_get_order ( group , order , bn_ctx ) assert ( res == 1 ) order_bits = _lib . BN_num_bits ( order ) return _truncate_digest ( digest , order_bits )
this function truncates digests that are longer than a given elliptic curve keys length so they can be signed .