Example #1
0
void csa_key_free(csakey_t **pcsakey) {
	struct csakey *key = *((struct csakey **)pcsakey);
	if (key) {
		dvbcsa_key_free(key->s_csakey[0]);
		dvbcsa_key_free(key->s_csakey[1]);
		dvbcsa_bs_key_free(key->bs_csakey[0]);
		dvbcsa_bs_key_free(key->bs_csakey[1]);
		ffdecsa_key_free(key->ff_csakey);
		FREE(*pcsakey);
	}
}
Example #2
0
/** @internal @This frees a dvbcsa encryption pipe.
 *
 * @param upipe description structure of the pipe
 */
static void upipe_dvbcsa_enc_free(struct upipe *upipe)
{
    struct upipe_dvbcsa_enc *upipe_dvbcsa_enc =
        upipe_dvbcsa_enc_from_upipe(upipe);
    struct upipe_dvbcsa_common *common =
        upipe_dvbcsa_enc_to_common(upipe_dvbcsa_enc);

    upipe_throw_dead(upipe);

    dvbcsa_key_free(upipe_dvbcsa_enc->key);
    upipe_dvbcsa_common_clean(common);
    upipe_dvbcsa_enc_clean_output(upipe);
    upipe_dvbcsa_enc_clean_urefcount(upipe);
    upipe_dvbcsa_enc_free_void(upipe);
}
Example #3
0
/** @internal @This sets the dvbcsa key.
 *
 * @param upipe description structure of the pipe
 * @param key dvbcsa key to set
 * @return an error code
 */
static int upipe_dvbcsa_enc_set_key(struct upipe *upipe, const char *key)
{
    struct upipe_dvbcsa_enc *upipe_dvbcsa_enc =
        upipe_dvbcsa_enc_from_upipe(upipe);

    dvbcsa_key_free(upipe_dvbcsa_enc->key);
    upipe_dvbcsa_enc->key = NULL;

    if (!key)
        return UBASE_ERR_NONE;

    struct ustring_dvbcsa_cw cw = ustring_to_dvbcsa_cw(ustring_from_str(key));
    if (unlikely(ustring_is_empty(cw.str) || strlen(key) != cw.str.len))
        return UBASE_ERR_INVALID;

    upipe_notice(upipe, "key chanhed");
    upipe_dvbcsa_enc->key = dvbcsa_key_alloc();
    UBASE_ALLOC_RETURN(upipe_dvbcsa_enc->key);
    dvbcsa_key_set(cw.value, upipe_dvbcsa_enc->key);
    return UBASE_ERR_NONE;
}
Example #4
0
int
main		(void)
{
  struct dvbcsa_key_s	*key = dvbcsa_key_alloc();
  unsigned int		i;
  uint8_t		data[256];

#ifdef HAVE_ASSERT_H
  assert(key != NULL);
#endif

  puts("* CSA decryption *");

  for (i = 0; i < sizeof(csa_tests) / sizeof(struct test_s); i++)
    {
      printf(" test %u\n", i + 1);

      dvbcsa_key_set(csa_tests[i].key, key);

      memcpy(data, csa_tests[i].in, TS_SIZE);
      dvbcsa_decrypt(key, data, TS_SIZE);

      if (memcmp(data, csa_tests[i].out, TS_SIZE))
	{
	  puts("\nTest failed\n");
	  hexdump("control words", csa_tests[i].key, sizeof(dvbcsa_cw_t));
	  hexdump("input data", csa_tests[i].out, TS_SIZE);
	  hexdump("expected stream", csa_tests[i].in, TS_SIZE);
	  hexdump("output stream", data, TS_SIZE);
	  return (1);
	}
    }

  dvbcsa_key_free(key);

  puts("* Done *");

  return (0);
}