SASC
DVBSoftCAM

cViaccess Class Reference

Inheritance diagram for cViaccess:

List of all members.

Public Member Functions

 cViaccess (void)
 cViaccess (void)

Protected Member Functions

void SetV2Mode (const unsigned char *key2)
void SetHashKey (const unsigned char *key)
void HashByte (unsigned char c)
void HashClear (void)
void Hash (void)
void Decode (unsigned char *data, const unsigned char *key)
bool Decrypt (const unsigned char *work_key, const unsigned char *data, int len, unsigned char *des_data1, unsigned char *des_data2)
virtual unsigned int Mod (unsigned int R, unsigned int key7) const
void SetV2Mode (const unsigned char *key2)
void SetHashKey (const unsigned char *key)
void HashByte (unsigned char c)
void HashClear (void)
void Hash (void)
void Decode (unsigned char *data, const unsigned char *key)
bool Decrypt (const unsigned char *work_key, const unsigned char *data, int len, unsigned char *des_data1, unsigned char *des_data2)
virtual unsigned int Mod (unsigned int R, unsigned int key7) const

Protected Attributes

unsigned char hbuff [8]
unsigned char hkey [8]
int pH

Detailed Description

Definition at line 161 of file viaccess.c.


Constructor & Destructor Documentation

cViaccess::cViaccess ( void  )

Definition at line 186 of file viaccess.c.

:cDes()
{
  v2mode=false;
}
cViaccess::cViaccess ( void  )

Member Function Documentation

void cViaccess::Decode ( unsigned char *  data,
const unsigned char *  key 
) [protected]

Definition at line 232 of file viaccess.c.

References cDes::Des(), and VIA_DES.

Referenced by Decrypt(), and cSystemViaccess::ProcessEMM().

{
  if(v2mode) Via2Mod(v2key,data);
  Des(data,key,VIA_DES);
  if(v2mode) Via2Mod(v2key,data);
}
void cViaccess::Decode ( unsigned char *  data,
const unsigned char *  key 
) [protected]
bool cViaccess::Decrypt ( const unsigned char *  work_key,
const unsigned char *  data,
int  len,
unsigned char *  des_data1,
unsigned char *  des_data2 
) [protected]

Definition at line 287 of file viaccess.c.

References Decode(), Hash(), HashByte(), HashClear(), hbuff, i, k, pH, and SetHashKey().

Referenced by cSystemViaccess::ProcessECM().

{
  int pos=0, encStart=0;
  unsigned char signatur[8];
  while(pos<len) {
    switch(data[pos]) {
      case 0xea:                 // encrypted bytes
        encStart = pos + 2;
        memcpy(des_data1,&data[pos+2],8);
        memcpy(des_data2,&data[pos+2+8],8);
        break;
      case 0xf0:                 // signature
        memcpy(signatur,&data[pos+2],8);
        break;
      }
    pos += data[pos+1]+2;
    }
  HashClear();
  SetHashKey(work_key);
  // key preparation
  unsigned char prepared_key[8];
  if(work_key[7]==0) {
    // 8th key-byte = 0 then like Eurocrypt-M but with viaccess mods
    HashNanos(data,encStart+16);
    memcpy(prepared_key,work_key,sizeof(prepared_key));
    }
  else { // key8 not zero
    // rotate the key 2x left
    prepared_key[0]=work_key[2];
    prepared_key[1]=work_key[3];
    prepared_key[2]=work_key[4];
    prepared_key[3]=work_key[5];
    prepared_key[4]=work_key[6];
    prepared_key[5]=work_key[0];
    prepared_key[6]=work_key[1];
    prepared_key[7]=work_key[7];
    // test if key8 odd
    if(work_key[7]&1) {
      HashNanos(data,encStart);
      // test if low nibble zero
      unsigned char k = ((work_key[7] & 0xf0) == 0) ? 0x5a : 0xa5;
      for(int i=0; i<8; i++) {
        unsigned char tmp=des_data1[i];
        des_data1[i]=(k & hbuff[pH]) ^ tmp;
        HashByte(tmp);
        }
      for(int i=0; i<8; i++) {
        unsigned char tmp=des_data2[i];
        des_data2[i]=(k & hbuff[pH]) ^ tmp;
        HashByte(tmp);
        }
      }
    else {
      HashNanos(data,encStart+16);
      }
    }
  Decode(des_data1,prepared_key);
  Decode(des_data2,prepared_key);
  Hash();
  return (memcmp(signatur,hbuff,8)==0);
}
bool cViaccess::Decrypt ( const unsigned char *  work_key,
const unsigned char *  data,
int  len,
unsigned char *  des_data1,
unsigned char *  des_data2 
) [protected]
void cViaccess::Hash ( void  ) [protected]
void cViaccess::Hash ( void  ) [protected]

Definition at line 266 of file viaccess.c.

References cDes::Des(), hbuff, hkey, and VIA_DES_HASH.

Referenced by Decrypt(), HashByte(), and cSystemViaccess::ProcessEMM().

{
  if(v2mode) Via2Mod(v2key,hbuff);
  Des(hbuff,hkey,VIA_DES_HASH);
  if(v2mode) Via2Mod(v2key,hbuff);
}
void cViaccess::HashByte ( unsigned char  c) [protected]

Definition at line 254 of file viaccess.c.

References Hash(), hbuff, and pH.

Referenced by Decrypt(), and cSystemViaccess::ProcessEMM().

{
  hbuff[pH++]^=c;
  if(pH==8) { pH=0; Hash(); }
}
void cViaccess::HashByte ( unsigned char  c) [protected]
void cViaccess::HashClear ( void  ) [protected]

Definition at line 260 of file viaccess.c.

References hbuff, and pH.

Referenced by Decrypt(), and cSystemViaccess::ProcessEMM().

{
  memset(hbuff,0,sizeof(hbuff));
  pH=0;
}
void cViaccess::HashClear ( void  ) [protected]
unsigned int cViaccess::Mod ( unsigned int  R,
unsigned int  key7 
) const [protected, virtual]

Reimplemented from cDes.

Definition at line 194 of file viaccess.c.

{
  if(key7!=0) {
    const unsigned int key5=(R>>24)&0xff;
    unsigned int al=key7*key5 + key7 + key5;
    al=(al&0xff)-((al>>8)&0xff);
    if(al&0x100) al++;
    R=(R&0x00ffffffL) + (al<<24);
    }
  return R;
}
virtual unsigned int cViaccess::Mod ( unsigned int  R,
unsigned int  key7 
) const [protected, virtual]

Reimplemented from cDes.

void cViaccess::SetHashKey ( const unsigned char *  key) [protected]
void cViaccess::SetHashKey ( const unsigned char *  key) [protected]

Definition at line 249 of file viaccess.c.

References hkey.

Referenced by Decrypt(), and cSystemViaccess::ProcessEMM().

{
  memcpy(hkey,key,sizeof(hkey));
}
void cViaccess::SetV2Mode ( const unsigned char *  key2) [protected]

Definition at line 239 of file viaccess.c.

Referenced by cSystemViaccess::ProcessECM().

{
  if(key2) {
    memcpy(v2key,key2,sizeof(v2key));
    v2mode=true;
    }
  else v2mode=false;
}
void cViaccess::SetV2Mode ( const unsigned char *  key2) [protected]

Member Data Documentation

unsigned char cViaccess::hbuff [protected]

Definition at line 169 of file viaccess.c.

Referenced by Decrypt(), Hash(), HashByte(), HashClear(), and cSystemViaccess::ProcessEMM().

unsigned char cViaccess::hkey [protected]

Definition at line 169 of file viaccess.c.

Referenced by Hash(), and SetHashKey().

int cViaccess::pH [protected]

Definition at line 170 of file viaccess.c.

Referenced by Decrypt(), HashByte(), HashClear(), and cSystemViaccess::ProcessEMM().


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