SASC-NG
DVBSoftCAM

cSeca2Prov Class Reference

Inheritance diagram for cSeca2Prov:

List of all members.

Public Member Functions

 cSeca2Prov (unsigned short Id)
virtual ~cSeca2Prov ()
virtual void PreSSE (unsigned char *data, int pos)
virtual void PostSSE (unsigned char *data, int pos)
virtual void SignatureMod (unsigned char *MD, const unsigned char *PK)
virtual void PreCW (unsigned char *data)
virtual void PostCW (unsigned char *data)
virtual void ChainTableXor (unsigned char *data, unsigned short index)=0
virtual bool DoSigCheck (void)
virtual bool Init (void)
void CalcSHASignature (const unsigned char *data, int n, unsigned char *signature, bool PadMode=true)
bool DecryptSE (unsigned char *data, const unsigned char *key, int n, int start, const unsigned char *T1, const unsigned char *T2)
bool Matches (unsigned short Id) const
const unsigned char * T1 (int index) const
const unsigned char * T2 (int index) const
struct Perm * P (int index) const
const unsigned char * MT (void) const
int MTSize (void) const
const unsigned char * FP (void) const

Protected Member Functions

cFileMap * GetMap (const char *type, int size, bool generic) const

Protected Attributes

struct ProvData * pData
struct Perm * perm

Detailed Description

Definition at line 396 of file seca.c.


Constructor & Destructor Documentation

cSeca2Prov::cSeca2Prov ( unsigned short  Id)

Definition at line 432 of file seca.c.

References hash, pData, and perm.

{
  id=Id;
  pData=0; perm=0; hash=0; mask=0;
}
cSeca2Prov::~cSeca2Prov ( ) [virtual]

Definition at line 438 of file seca.c.

References hash, and cFileMap::Unmap().

{
  if(hash) hash->Unmap();
  if(mask) mask->Unmap();
}

Member Function Documentation

void cSeca2Prov::CalcSHASignature ( const unsigned char *  data,
int  n,
unsigned char *  signature,
bool  PadMode = true 
)

Definition at line 550 of file seca.c.

References pData, ProvData::SHA1End, and ProvData::SHA1Pad.

Referenced by cSeca2ProvSSE::PostSSE(), cSystemSeca::ProcessECM(), and cSystemSeca::ProcessEMM().

{
  SHA_CTX ctx;
  SHA1_Init(&ctx);
  SHA1_Update(&ctx,data,n);
  unsigned char Pad=0;
  if(PadMode) {
    unsigned char End=pData->SHA1End;
    SHA1_Update(&ctx,&End,1);
    int l=(n&63)+1;
    Pad=pData->SHA1Pad;
    if(l>62) {
      for(; l<64; l++) SHA1_Update(&ctx,&Pad,1);
      l=0;
      }
    for(; l<62; l++) SHA1_Update(&ctx,&Pad,1);
    unsigned short s=bswap_16(n);
    SHA1_Update(&ctx,&s,2);
    }
  else for(; n&63; n++) SHA1_Update(&ctx,&Pad,1);

  *((unsigned int *)(signature   ))=bswap_32(ctx.h0);
  *((unsigned int *)(signature+ 4))=bswap_32(ctx.h1);
  *((unsigned int *)(signature+ 8))=bswap_32(ctx.h2);
  *((unsigned int *)(signature+12))=bswap_32(ctx.h3);
  *((unsigned int *)(signature+16))=bswap_32(ctx.h4);
}
virtual void cSeca2Prov::ChainTableXor ( unsigned char *  data,
unsigned short  index 
) [pure virtual]

Implemented in cSeca2ProvFR, cSeca2ProvNL, cSeca2ProvPL, and cSeca2ProvSPA.

Referenced by DecryptSE().

bool cSeca2Prov::DecryptSE ( unsigned char *  data,
const unsigned char *  key,
int  n,
int  start,
const unsigned char *  T1,
const unsigned char *  T2 
)

Definition at line 516 of file seca.c.

References ChainTableXor(), cSeca::Decrypt(), and i.

Referenced by cSystemSeca::ProcessECM(), and cSystemSeca::ProcessEMM().

{
  const int sigStart=n-data[n-1]-9; // 82 <8 bytes> P5(sigStart)
  const int encrLen=sigStart-16;

#ifdef DEBUG_SECA_EXTRA
  if(encrLen>=n || encrLen<0) printf("encrLen error in SE\n");
  if(sigStart<16) printf("sigStart error in SE\n");
#endif
  if(encrLen>=n || encrLen<0 || sigStart<16) return false;

  Decrypt(data+sigStart-8,key,T1,T2);
  ChainTableXor(data+sigStart-8,Sum(data+start,sigStart-8-start));
  int i;

  for(i=start; i<encrLen; i+=8) {
    Decrypt(data+i,key,T1,T2);
    ChainTableXor(data+i,Sum(&data[i+8],8));
    }

  int restBytes=sigStart&0x07;
  if(!restBytes) restBytes=8;

  // Last Block
  unsigned char lastBlock[8];
  memset(lastBlock,0,sizeof(lastBlock));
  memcpy(lastBlock,data+sigStart-restBytes,restBytes);
  Decrypt(lastBlock,key,T1,T2);

  Decrypt(data+i,key,T1,T2);
  ChainTableXor(data+i,Sum(lastBlock,sizeof(lastBlock)));
  return true;
}
virtual bool cSeca2Prov::DoSigCheck ( void  ) [inline, virtual]

Reimplemented in cSeca2ProvNL.

Definition at line 417 of file seca.c.

Referenced by cSystemSeca::ProcessECM().

{ return true; }
const unsigned char* cSeca2Prov::FP ( void  ) const [inline]

Definition at line 429 of file seca.c.

References ProvData::FP, and pData.

{ return pData->FP; }
cFileMap * cSeca2Prov::GetMap ( const char *  type,
int  size,
bool  generic 
) const [protected]

Definition at line 452 of file seca.c.

References FILEMAP_DOMAIN, filemaps, cFileMaps::GetFileMap(), L_SYS_CRYPTO, ProvData::LoadId, cFileMap::Map(), pData, PRINTF, cFileMap::Size(), and cFileMap::Unmap().

Referenced by Init(), cSeca2ProvNL::InitSSE(), and cSeca2ProvFR::InitSSE().

{
  char name[32];
  snprintf(name,sizeof(name),generic ? "s2_%s.bin" : "s2_%s_%04x.bin",type,pData->LoadId);
  cFileMap *map=filemaps.GetFileMap(name,FILEMAP_DOMAIN,false);
  if(!map)
    PRINTF(L_SYS_CRYPTO,"no filemap for %s",name);
  else if(!map->Map()) {
    PRINTF(L_SYS_CRYPTO,"mapping failed for %s",name);
    map=0;
    }
  else if(map->Size()<size) {
    PRINTF(L_SYS_CRYPTO,"%s file %s has wrong size (has=%d wanted=%d)",type,name,map->Size(),size);
    map->Unmap();
    map=0;
    }
  return map;
}
bool cSeca2Prov::Init ( void  ) [virtual]

Reimplemented in cSeca2ProvSSE.

Definition at line 444 of file seca.c.

References GetMap(), hash, ProvData::MTLoadSize, and pData.

Referenced by cSeca2Providers::GetProv().

{
  hash=GetMap("hash",1536,false);
  mask=GetMap("mt",pData->MTLoadSize,false);
  if(!hash || !mask) return false;
  return true;
}
bool cSeca2Prov::Matches ( unsigned short  Id) const [inline]

Definition at line 422 of file seca.c.

References id.

{ return Id==id; }
const unsigned char* cSeca2Prov::MT ( void  ) const [inline]
int cSeca2Prov::MTSize ( void  ) const [inline]

Definition at line 428 of file seca.c.

References ProvData::MTSize, and pData.

{ return pData->MTSize; }
struct Perm * cSeca2Prov::P ( int  index) const [read]

Definition at line 499 of file seca.c.

References L_SYS_CRYPTO, MAX_PERMS, perm, and PRINTF.

{
  if(index>=0 && index<MAX_PERMS && perm) {
    return &perm[index];
    }
  PRINTF(L_SYS_CRYPTO,"no perm table or bad index %d",index);
  return 0;
}
virtual void cSeca2Prov::PostCW ( unsigned char *  data) [inline, virtual]

Reimplemented in cSeca2ProvFR, and cSeca2ProvNL.

Definition at line 415 of file seca.c.

Referenced by cSystemSeca::ProcessECM().

{}
virtual void cSeca2Prov::PostSSE ( unsigned char *  data,
int  pos 
) [inline, virtual]

Reimplemented in cSeca2ProvSSE.

Definition at line 412 of file seca.c.

Referenced by cSystemSeca::ProcessECM().

{}
virtual void cSeca2Prov::PreCW ( unsigned char *  data) [inline, virtual]

Reimplemented in cSeca2ProvPL.

Definition at line 414 of file seca.c.

Referenced by cSystemSeca::ProcessECM().

{}
virtual void cSeca2Prov::PreSSE ( unsigned char *  data,
int  pos 
) [inline, virtual]

Reimplemented in cSeca2ProvSSE.

Definition at line 411 of file seca.c.

Referenced by cSystemSeca::ProcessECM().

{}
virtual void cSeca2Prov::SignatureMod ( unsigned char *  MD,
const unsigned char *  PK 
) [inline, virtual]

Reimplemented in cSeca2ProvFR.

Definition at line 413 of file seca.c.

Referenced by cSystemSeca::ProcessECM().

{}
const unsigned char * cSeca2Prov::T1 ( int  index) const

Definition at line 479 of file seca.c.

References hash, L_SYS_CRYPTO, and PRINTF.

Referenced by cSystemSeca::ProcessECM(), and cSystemSeca::ProcessEMM().

{
  static int idxTrans[] = { 0,1,2,2 };
  if(index>=0 && index<=3) {
    return hash->Addr()+(idxTrans[index]*256);
    }
  PRINTF(L_SYS_CRYPTO,"bad T1 table index %d",index);
  return 0;
}
const unsigned char * cSeca2Prov::T2 ( int  index) const

Definition at line 489 of file seca.c.

References hash, L_SYS_CRYPTO, and PRINTF.

Referenced by cSystemSeca::ProcessECM(), and cSystemSeca::ProcessEMM().

{
  static int idxTrans[] = { 0,1,2,2 };
  if(index>=0 && index<=3) {
    return hash->Addr()+(idxTrans[index]*256)+768;
    }
  PRINTF(L_SYS_CRYPTO,"bad T2 table index %d",index);
  return 0;
}

Member Data Documentation

struct Perm* cSeca2Prov::perm [protected]

Definition at line 404 of file seca.c.

Referenced by cSeca2Prov(), cSeca2ProvPL::cSeca2ProvPL(), cSeca2ProvSPA::cSeca2ProvSPA(), and P().


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