SASC-NG
DVBSoftCAM

cCamCryptNagra Class Reference

Inheritance diagram for cCamCryptNagra:

List of all members.

Public Member Functions

 cCamCryptNagra (void)
void SetCardData (unsigned int id, const unsigned char *bk, BIGNUM *exp)
void SetCamMod (BIGNUM *m)
bool HasCamMod (void)
bool DecryptDT08 (const unsigned char *dt08, unsigned int irdid, cBN *irdmod, bool fakeid)
bool MakeSessionKey (unsigned char *out, const unsigned char *in)
void DecryptCW (unsigned char *cw, const unsigned char *ecw1, const unsigned char *ecw2)

Detailed Description

Definition at line 104 of file sc-nagra.c.


Constructor & Destructor Documentation

cCamCryptNagra::cCamCryptNagra ( void  )

Definition at line 126 of file sc-nagra.c.

{
  hasMod=false;
}

Member Function Documentation

void cCamCryptNagra::DecryptCW ( unsigned char *  cw,
const unsigned char *  ecw1,
const unsigned char *  ecw2 
)

Definition at line 233 of file sc-nagra.c.

References cIDEA::Decrypt().

Referenced by cSmartCardNagra::Decode().

{
  memcpy(cw+0,ecw1,8);
  idea.Decrypt(cw+0,8,&sessKey,0);
  memcpy(cw+8,ecw2,8);
  idea.Decrypt(cw+8,8,&sessKey,0);
}
bool cCamCryptNagra::DecryptDT08 ( const unsigned char *  dt08,
unsigned int  irdid,
cBN *  irdmod,
bool  fakeid 
)

Definition at line 169 of file sc-nagra.c.

References BYTE4_BE, cIDEA::Decrypt(), L_SC_PROC, LDUMP, LOG, PRINTF, cBN::Put(), cRSA::RSA(), and cIDEA::SetDecKey().

{
  if(LOG(L_SC_PROC)) {
    unsigned char bb[64];
    irdmod->Put(bb,sizeof(bb));
    LDUMP(L_SC_PROC,bb,sizeof(bb),"DT08 decrypt IRDID: %08x IRDMOD:",irdid);
    }
  unsigned char buff[72];
  if(rsa.RSA(buff,dt08+1,64,camExp,*irdmod)!=64) return false;
  memcpy(buff+64,dt08+1+64,8);
  buff[63]|=dt08[0]&0x80;
  LDUMP(L_SC_PROC,buff,72,"DT08 after RSA");

  unsigned char key[16];
  InitKey(key,boxkey,irdid);
  LDUMP(L_SC_PROC,key,16,"DT08 IDEA key");
  IdeaKS dks;
  idea.SetDecKey(key,&dks);
  idea.Decrypt(buff,72,&dks,0);
  LDUMP(L_SC_PROC,buff,72,"DT08 after IDEA");

  memcpy(signature,buff,8);
  LDUMP(L_SC_PROC,signature,8,"signature");
  BYTE4_BE(buff  ,0);
  BYTE4_BE(buff+4,fakeid?0xFFFFFFFF:cardid);
  Signature(buff,key,buff,72);
  LDUMP(L_SC_PROC,buff,8,"check sig");
  if(memcmp(signature,buff,8)) {
    PRINTF(L_SC_PROC,"DT08 signature failed");
    return false;
    }
  BN_bin2bn(buff+8,64,camMod);
  hasMod=true;
  return true;
}
bool cCamCryptNagra::HasCamMod ( void  ) [inline]

Definition at line 120 of file sc-nagra.c.

Referenced by cSmartCardNagra::Init().

{ return hasMod; }
bool cCamCryptNagra::MakeSessionKey ( unsigned char *  out,
const unsigned char *  in 
)

Definition at line 205 of file sc-nagra.c.

References L_SC_PROC, LDUMP, LOG, cBN::Put(), cRSA::RSA(), and cIDEA::SetDecKey().

{
  if(!hasMod) return false;
  if(LOG(L_SC_PROC)) {
    unsigned char bb[64];
    camMod.Put(bb,sizeof(bb));
    LDUMP(L_SC_PROC,bb,sizeof(bb),"Sessionkey negotiation CAMMOD:");
    }
  //decrypt $2A data here and prepare $2B reply
  if(rsa.RSA(out,camdata,64,camExp,camMod)!=64) return false;
  LDUMP(L_SC_PROC,out,64,"CMD 2A/26 after RSA:");

  unsigned char key[16], sess[16];
  InitKey(key,signature,cardid);
  LDUMP(L_SC_PROC,key,16,"first IDEA key: ");
  Signature(sess,key,out,32);
  memcpy(key,sess,8);
  memcpy(key+8,sess,8);
  LDUMP(L_SC_PROC,key,16,"second IDEA key:");
  Signature(sess+8,key,out,32);
  LDUMP(L_SC_PROC,sess,16,"SESSION KEY:    ");
  idea.SetDecKey(sess,&sessKey);

  if(rsa.RSA(out,out,64,camExp,camMod)!=64) return false;
  LDUMP(L_SC_PROC,out,64,"CMD 2B/27 data:");
  return true;
}
void cCamCryptNagra::SetCamMod ( BIGNUM *  m)

Definition at line 143 of file sc-nagra.c.

Referenced by cSmartCardNagra::Init().

{
  BN_copy(camMod,m);
  memcpy(signature,boxkey,sizeof(signature));
  hasMod=true;
}
void cCamCryptNagra::SetCardData ( unsigned int  id,
const unsigned char *  bk,
BIGNUM *  exp 
)

Definition at line 131 of file sc-nagra.c.

References id, L_SC_PROC, LDUMP, LOG, and cBN::Put().

Referenced by cSmartCardNagra::Init().

{
  cardid=id;
  memcpy(boxkey,bk,sizeof(boxkey));
  BN_copy(camExp,exp);
  if(LOG(L_SC_PROC)) {
    unsigned char bb[4];
    camExp.Put(bb,2);
    LDUMP(L_SC_PROC,boxkey,sizeof(boxkey),"Active card data: CARDID: %08x EXP: %02x%02x BOXKEY:",cardid,bb[0],bb[1]);
    }
}

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