示例#1
0
tr_dh_secret_t
tr_dh_agree (tr_dh_ctx_t     handle,
             const uint8_t * other_public_key,
             size_t          other_public_key_length)
{
  struct tr_dh_secret * ret;
  int dh_size, secret_key_length;
  BIGNUM * other_key;

  assert (handle != NULL);
  assert (other_public_key != NULL);

  if (!check_pointer (other_key = BN_bin2bn (other_public_key, other_public_key_length, NULL)))
    return NULL;

  dh_size = DH_size (handle);
  ret = tr_dh_secret_new (dh_size);

  secret_key_length = DH_compute_key (ret->key, other_key, handle);
  if (check_result_neq (secret_key_length, -1))
    {
      tr_dh_secret_align (ret, secret_key_length);
    }
  else
    {
      tr_dh_secret_free (ret);
      ret = NULL;
    }

  BN_free (other_key);
  return ret;
}
示例#2
0
tr_dh_secret_t
tr_dh_agree (tr_dh_ctx_t     raw_handle,
             const uint8_t * other_public_key,
             size_t          other_public_key_length)
{
  struct tr_dh_ctx * handle = raw_handle;
  struct tr_dh_secret * ret;
  word32 my_secret_key_length;

  assert (handle != NULL);
  assert (other_public_key != NULL);

  ret = tr_dh_secret_new (handle->key_length);

  if (check_result (DhAgree (&handle->dh,
                             ret->key, &my_secret_key_length,
                             handle->private_key, handle->private_key_length,
                             other_public_key, other_public_key_length)))
    {
      tr_dh_secret_align (ret, my_secret_key_length);
    }
  else
    {
      tr_dh_secret_free (ret);
      ret = NULL;
    }

  return ret;
}