SASC-NG
DVBSoftCAM

cCCcamCrypt Class Reference

List of all members.

Public Member Functions

void Init (const unsigned char *key, int length, bool l=false)
void Decrypt (const unsigned char *in, unsigned char *out, int length)
void DecryptRC4 (const unsigned char *in, unsigned char *out, int length)
void Encrypt (const unsigned char *in, unsigned char *out, int length)

Static Public Member Functions

static void ScrambleDcw (unsigned char *data, const unsigned char *nodeid, unsigned int shareid)
static bool DcwChecksum (const unsigned char *data)
static bool CheckConnectChecksum (const unsigned char *data, int length)
static void Xor (unsigned char *data, int length)

Detailed Description

Definition at line 41 of file cccam2.c.


Member Function Documentation

bool cCCcamCrypt::CheckConnectChecksum ( const unsigned char *  data,
int  length 
) [static]

Definition at line 143 of file cccam2.c.

Referenced by cCardClientCCcam2::Login().

{
  if(length==16) {
    bool valid=true;
    // CCcam 2.1.2 don't use connect checksum
    //for(int i=0; i<4; i++)
    //  if(((data[i+0]+data[i+4]+data[i+8])&0xFF)!=data[i+12]) valid=false;
    return valid;
    }
  return false;
}
bool cCCcamCrypt::DcwChecksum ( const unsigned char *  data) [static]

Definition at line 127 of file cccam2.c.

References L_CC_CCCAM2EX, and PRINTF.

{
  bool res=true;
  if(((data[0]+data[1]+data[2])&0xff)!=data[3] ||
     ((data[4]+data[5]+data[6])&0xff)!=data[7]) {
    res=false;
    PRINTF(L_CC_CCCAM2EX,"warning: even CW checksum failed");
    }
  if(((data[8]+data[9]+data[10])&0xff)!=data[11] ||
     ((data[12]+data[13]+data[14])&0xff)!=data[15]) {
    res=false;
    PRINTF(L_CC_CCCAM2EX,"warning: odd CW checksum failed");
    }
  return res;
}
void cCCcamCrypt::Decrypt ( const unsigned char *  in,
unsigned char *  out,
int  length 
)

Definition at line 74 of file cccam2.c.

References L_CC_CCCAM2EX, and LDUMP.

Referenced by cCardClientCCcam2::Action(), cCmd0cCrypt::Decrypt(), and cCardClientCCcam2::Login().

{
  for(int pos=0; pos<length; pos++) {
    sum+=keytable[++counter];
    Swap(keytable+counter,keytable+sum);
    out[pos]=in[pos] ^ state ^ keytable[(keytable[sum]+keytable[counter])&0xFF];
    state^=out[pos];
    }
  if(log) LDUMP(L_CC_CCCAM2EX,keytable,sizeof(keytable),"cccrypt decrypt state=%d table",state);
}
void cCCcamCrypt::DecryptRC4 ( const unsigned char *  in,
unsigned char *  out,
int  length 
)

Definition at line 85 of file cccam2.c.

References L_CC_CCCAM2EX, and LDUMP.

{
  for(int pos=0; pos<length; pos++) {
    sum+=keytable[++counter];
    Swap(keytable+counter,keytable+sum);
    out[pos]=in[pos] ^ keytable[(keytable[sum]+keytable[counter])&0xFF];
    state^=out[pos];
    }
  if(log) LDUMP(L_CC_CCCAM2EX,keytable,sizeof(keytable),"rc4crypt decrypt state=%d table",state);
}
void cCCcamCrypt::Encrypt ( const unsigned char *  in,
unsigned char *  out,
int  length 
)

Definition at line 96 of file cccam2.c.

References L_CC_CCCAM2EX, and LDUMP.

Referenced by cCmd0cCrypt::Decrypt(), and cCardClientCCcam2::Login().

{
  // There is a side-effect in this function:
  // If in & out pointer are the same, then state is xor'ed with modified input
  // (because output(=in ptr) is written before state xor)
  // This side-effect is used when initialising the encrypt state!
  for(int pos=0; pos<length; pos++) {
    sum+=keytable[++counter];
    Swap(keytable+counter,keytable+sum);
    out[pos]=in[pos] ^ state ^ keytable[(keytable[sum]+keytable[counter])&0xFF];
    state^=in[pos];
    }
  if(log) LDUMP(L_CC_CCCAM2EX,keytable,sizeof(keytable),"cccrypt encrypt state=%d table",state);
}
void cCCcamCrypt::Init ( const unsigned char *  key,
int  length,
bool  l = false 
)

Definition at line 59 of file cccam2.c.

References L_CC_CCCAM2EX, and LDUMP.

Referenced by cCardClientCCcam2::Login(), and cCmd0cCrypt::SetKey().

{
  log=l;
  for(int pos=0; pos<=255; pos++) keytable[pos]=pos;
  int result=0;
  unsigned char curr_char=0;
  for(int pos=0; pos<=255; pos++) {
    curr_char+=keytable[pos] + key[result];
    Swap(keytable+pos,keytable+curr_char);
    result=(result+1)%length;
    }
  state=key[0]; counter=0; sum=0;
  if(log) LDUMP(L_CC_CCCAM2EX,keytable,sizeof(keytable),"cccrypt init state=%d table",state);
}
void cCCcamCrypt::ScrambleDcw ( unsigned char *  data,
const unsigned char *  nodeid,
unsigned int  shareid 
) [static]

Definition at line 116 of file cccam2.c.

References i.

{
  long long n=bswap_64(*(long long *)nodeid);
  for(unsigned int i=0; i<16; i++) {
    char final=data[i]^(n&0xFF);
    if(i&1) final=~final;
    data[i]=final^(shareid&0xFF);
    n>>=4; shareid>>=2;
    }
}
void cCCcamCrypt::Xor ( unsigned char *  data,
int  length 
) [static]

Definition at line 155 of file cccam2.c.

References cccamstr.

Referenced by cCardClientCCcam2::Login().

{
  if(length>=16)
    for(int index=0; index<8; index++) {
      data[8]=index*data[0];
      if(index<=5) data[0]^=cccamstr[index];
      data++;
      }
}

The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines