Exemplo n.º 1
0
void dvbcsa_key_set (const dvbcsa_cw_t cw, struct dvbcsa_key_s *key)
{
  uint64_t a = dvbcsa_load_le64(cw);
  dvbcsa_store_le64(key->cw,  a);
  dvbcsa_store_le64(key->cws, ((a & 0xf0f0f0f0f0f0f0f0ULL) >> 4) |
		              ((a & 0x0f0f0f0f0f0f0f0fULL) << 4));

  dvbcsa_key_schedule_block(cw, key->sch);
}
Exemplo n.º 2
0
void
dvbcsa_bs_key_set (const dvbcsa_cw_t cw, struct dvbcsa_bs_key_s *key)
{
  dvbcsa_keys_t kk;
  int i;

  /* precalculations for stream */

  uint64_t ck = dvbcsa_load_le64(cw);

  for (i = 0; i < DVBCSA_CWBITS_SIZE; i++)
    key->stream[i] = (ck >> (i^4)) & 1 ? BS_VAL8(ff) : BS_VAL8(00);

  /* precalculations for block */

  dvbcsa_key_schedule_block(cw, kk);

  for (i = 0; i < DVBCSA_KEYSBUFF_SIZE; i++)
    {
#if BS_BATCH_SIZE == 32
      *(uint32_t*)(key->block + i) = kk[i] * 0x01010101;

#elif BS_BATCH_SIZE == 64
      *(uint64_t*)(key->block + i) = kk[i] * 0x0101010101010101ULL;

#elif BS_BATCH_SIZE > 64 && BS_BATCH_SIZE % 64 == 0
      uint64_t v = kk[i] * 0x0101010101010101ULL;
      int j;

      for (j = 0; j < BS_BATCH_BYTES / 8; j++)
	*((uint64_t*)(key->block + i) + j) = v;
#else
# error
#endif
    }
}
Exemplo n.º 3
0
void dvbcsa_bs_stream_transpose_in(const struct dvbcsa_bs_batch_s *pcks, dvbcsa_bs_word_t *row)
{
  int i, j;

  for (i = 0; pcks[i].data; i++)
    if (pcks[i].len >= 8)
      row[i] = BS_VAL(dvbcsa_load_le64(pcks[i].data));

  for (i = 0; i < 32; i++)
    {
      dvbcsa_bs_word_t t, b;

      t = row[i];
      b = row[32 + i];
      row[i]      = BS_OR(BS_AND(t, BS_VAL64(00000000ffffffff)), BS_SHL8(b, 4));
      row[32 + i] = BS_OR(BS_AND(b, BS_VAL64(ffffffff00000000)), BS_SHR8(t, 4));
    }

  for (j = 0; j < 64; j += 32)
    {
      dvbcsa_bs_word_t t, b;

      for (i = 0; i < 16; i++)
	{
	  t = row[j + i];
	  b = row[j + 16 + i];
	  row[j + i]      = BS_OR(BS_AND(t, BS_VAL32(0000ffff)), BS_SHL8(BS_AND(b, BS_VAL32(0000ffff)), 2));
	  row[j + 16 + i] = BS_OR(BS_AND(b, BS_VAL32(ffff0000)), BS_SHR8(BS_AND(t, BS_VAL32(ffff0000)), 2));
	}
    }

  for (j = 0; j < 64; j += 16)
    {
      dvbcsa_bs_word_t t, b;

      for (i = 0; i < 8; i++)
	{
	  t = row[j + i];
	  b = row[j + 8 + i];
	  row[j + i]     = BS_OR(BS_AND(t, BS_VAL16(00ff)), BS_SHL8(BS_AND(b, BS_VAL16(00ff)), 1));
	  row[j + 8 + i] = BS_OR(BS_AND(b, BS_VAL16(ff00)), BS_SHR8(BS_AND(t, BS_VAL16(ff00)), 1));
	}
    }

  for (j = 0; j < 64; j += 8)
    {
      dvbcsa_bs_word_t t, b;

      for (i = 0; i < 4; i++)
	{
	  b = row[j + i];
	  t = row[j + 4 + i];
	  row[j + i]     = BS_OR(BS_AND(b, BS_VAL8(0f)), BS_SHL(BS_AND(t, BS_VAL8(0f)), 4));
	  row[j + 4 + i] = BS_OR(BS_AND(t, BS_VAL8(f0)), BS_SHR(BS_AND(b, BS_VAL8(f0)), 4));
	}
    }

  for (j = 0; j < 64; j += 4)
    {
      dvbcsa_bs_word_t t, b;

      for (i = 0; i < 2; i++)
	{
	  b = row[j + i];
	  t = row[j + 2 + i];
	  row[j + i]     = BS_OR(BS_AND(b, BS_VAL8(33)), BS_SHL(BS_AND(t, BS_VAL8(33)), 2));
	  row[j + 2 + i] = BS_OR(BS_AND(t, BS_VAL8(cc)), BS_SHR(BS_AND(b, BS_VAL8(cc)), 2));
	}
    }

  for (j = 0; j < 64; j += 2)
    {
      dvbcsa_bs_word_t t, b;

      b = row[j];
      t = row[j + 1];
      row[j]     = BS_OR(BS_AND(b, BS_VAL8(55)), BS_SHL(BS_AND(t, BS_VAL8(55)), 1));
      row[j + 1] = BS_OR(BS_AND(t, BS_VAL8(aa)), BS_SHR(BS_AND(b, BS_VAL8(aa)), 1));
    }
}