SASC
DVBSoftCAM

cDes Class Reference

#include <crypto.h>

Inheritance diagram for cDes:

List of all members.

Public Member Functions

 cDes (const unsigned char *pc1=0, const unsigned char *pc2=0)
virtual ~cDes ()
void Des (unsigned char *data, const unsigned char *key, int mode) const
 cDes (const unsigned char *pc1=0, const unsigned char *pc2=0)
virtual ~cDes ()
void Des (unsigned char *data, const unsigned char *key, int mode) const

Protected Member Functions

virtual unsigned int Mod (unsigned int R, unsigned int key7) const
void Permute (unsigned char *data, const unsigned char *P, int n) const
virtual unsigned int Mod (unsigned int R, unsigned int key7) const
void Permute (unsigned char *data, const unsigned char *P, int n) const

Protected Attributes

static const unsigned char LS [] = { 1,1,2,2,2,2,2,2,1,2,2,2,2,2,2,1 }
const unsigned char * PC1
const unsigned char * PC2
unsigned char E [48]
unsigned char P [32]

Static Protected Attributes

static const unsigned char S [][64]

Detailed Description

Definition at line 64 of file crypto.h.


Constructor & Destructor Documentation

cDes::cDes ( const unsigned char *  pc1 = 0,
const unsigned char *  pc2 = 0 
)

Definition at line 342 of file crypto.c.

References E, i, P, PC1, and PC2.

{
  PC1=pc1 ? pc1 : _PC1;
  PC2=pc2 ? pc2 : _PC2;
  for(int i=0; i<48; i++) E[i]=32-_E[i];
  for(int i=0; i<32; i++) P[i]=32-_P[31-i];
}
virtual cDes::~cDes ( ) [inline, virtual]

Definition at line 76 of file crypto.h.

{}
cDes::cDes ( const unsigned char *  pc1 = 0,
const unsigned char *  pc2 = 0 
)
virtual cDes::~cDes ( ) [inline, virtual]

Definition at line 76 of file crypto.h.

{}

Member Function Documentation

void cDes::Des ( unsigned char *  data,
const unsigned char *  key,
int  mode 
) const

Definition at line 364 of file crypto.c.

References BYTE4_BE, DES_FP, DES_IP, DES_MOD, DES_PC1, DES_RIGHT, DESHASH, DESROUND, i, LS, Mod(), PC1, Permute(), rol28, ror28, and UINT32_BE.

Referenced by cNagraDES::Crypt(), cViaccess::Decode(), cNagraDES::Decrypt(), cViaccess::Hash(), cSeca2ProvNL::PostCW(), cSeca2ProvFR::PostCW(), cSeca2ProvSSE::PostSSE(), and cSeca2ProvFR::SignatureMod().

{
  unsigned char mkey[8];
  if(mode&DES_PC1) {
    memcpy(mkey,key,sizeof(mkey));
    Permute(mkey,PC1,56);
    key=mkey;
    }
  if(mode&DES_IP) Permute(data,IP,64);
  unsigned int C=UINT32_BE(key  ) >> 4;
  unsigned int D=UINT32_BE(key+3) & 0xfffffffL;
  unsigned int L=UINT32_BE(data  );
  unsigned int R=UINT32_BE(data+4);
  if(!(mode&DES_RIGHT)) {
    for(int i=15; i>=0; i--) {
      C=rol28(C,LS[15-i]); D=rol28(D,LS[15-i]);
      unsigned int T=R;
      if(mode&DES_MOD) T=Mod(T,key[7]); // apply costum mod e.g. Viaccess
      DESROUND(C,D,T);
      DESHASH(T);
      T^=L; L=R; R=T;
      }
    }
  else {
    for(int i=15; i>=0; i--) {
      unsigned int T=R;
      if(mode&DES_MOD) T=Mod(T,key[7]); // apply costum mod e.g. Viaccess
      DESROUND(C,D,T);
      DESHASH(T);
      T^=L; L=R; R=T;
      C=ror28(C,LS[i]); D=ror28(D,LS[i]);
      }
    }
  BYTE4_BE(data  ,R);
  BYTE4_BE(data+4,L);
  if(mode&DES_FP) Permute(data,FP,64);
}
void cDes::Des ( unsigned char *  data,
const unsigned char *  key,
int  mode 
) const
virtual unsigned int cDes::Mod ( unsigned int  R,
unsigned int  key7 
) const [inline, protected, virtual]

Reimplemented in cViaccess, and cViaccess.

Definition at line 72 of file crypto.h.

{ return R; }
virtual unsigned int cDes::Mod ( unsigned int  R,
unsigned int  key7 
) const [inline, protected, virtual]

Reimplemented in cViaccess, and cViaccess.

Definition at line 72 of file crypto.h.

Referenced by Des().

{ return R; }
void cDes::Permute ( unsigned char *  data,
const unsigned char *  P,
int  n 
) const [protected]

Definition at line 350 of file crypto.c.

References i, j, k, and shiftin.

Referenced by Des().

{
  unsigned char pin[8];
  for(int i=0, k=0; k<n; i++) {
    int p=0;
    for(int j=7; j>=0; j--,k++) {
      const int t=P[k]-1;
      p=shiftin(p,data[t>>3],7-(t&7));
      }
    pin[i]=p;
    }
  memcpy(data,pin,8);
}
void cDes::Permute ( unsigned char *  data,
const unsigned char *  P,
int  n 
) const [protected]

Member Data Documentation

unsigned char cDes::E [protected]

Definition at line 70 of file crypto.h.

Referenced by cDes().

static const unsigned char cDes::LS = { 1,1,2,2,2,2,2,2,1,2,2,2,2,2,2,1 } [protected]

Definition at line 68 of file crypto.h.

Referenced by cCwDes::CwDes(), and Des().

unsigned char cDes::P [protected]

Definition at line 70 of file crypto.h.

Referenced by cDes().

const unsigned char * cDes::PC1 [protected]

Definition at line 69 of file crypto.h.

Referenced by cDes(), and Des().

const unsigned char * cDes::PC2 [protected]

Definition at line 69 of file crypto.h.

Referenced by cDes().

static const unsigned char cDes::S [static, protected]

Definition at line 68 of file crypto.h.


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