SASC-NG
DVBSoftCAM

cCryptoworks Class Reference

Inheritance diagram for cCryptoworks:

List of all members.

Public Member Functions

 cCryptoworks (void)
void Signature (const unsigned char *data, int len, const unsigned char *key22, unsigned char *sig)
void DecryptDES (unsigned char *data, unsigned char algo, const unsigned char *key22)
bool DecryptRSA (unsigned char *data, int len, unsigned char algo, const unsigned char *key22, BIGNUM *mod)

Detailed Description

Definition at line 209 of file cryptoworks.c.


Constructor & Destructor Documentation

cCryptoworks::cCryptoworks ( void  )

Definition at line 223 of file cryptoworks.c.

{
  BN_set_word(exp,2);
}

Member Function Documentation

void cCryptoworks::DecryptDES ( unsigned char *  data,
unsigned char  algo,
const unsigned char *  key22 
)

Definition at line 269 of file cryptoworks.c.

References DES_RIGHT, i, and k.

Referenced by cSystemCryptoworks::ProcessECM().

{
  algo&=7;
  if(algo<7) {
    EncDec(data,key22,algo,DES_RIGHT);
    }
  else {
    unsigned char k[22], t[8];
    memcpy(k,key22,22);
    for(int i=0; i<3; i++) {
      EncDec(data,k,algo,i&1);
      memcpy(t,k,8); memcpy(k,k+8,8); memcpy(k+8,t,8);
      }
    }
}
bool cCryptoworks::DecryptRSA ( unsigned char *  data,
int  len,
unsigned char  algo,
const unsigned char *  key22,
BIGNUM *  mod 
)

Definition at line 285 of file cryptoworks.c.

References AUTOMEM, DES_LEFT, i, k, L_SYS_CRYPTO, L_SYS_VERBOSE, LDUMP, min(), PRINTF, RotateBytes(), cRSA::RSA(), and xxor.

Referenced by cSystemCryptoworks::ProcessECM().

{
  unsigned char buf[64], *mask=AUTOMEM(len);

  LDUMP(L_SYS_VERBOSE,data+len,8,"rsa in:");
  memcpy(buf,data+len,8);
  EncDec(buf,key22,algo,DES_LEFT);
  buf[0]|=0x80;
  if((algo&0x18)<0x18) buf[0]=0xFF;
  if(algo&8) buf[1]=0xFF;
  LDUMP(L_SYS_VERBOSE,buf,8,"rsa seed:");
  
  static const unsigned char t1[] = { 0xE,0x3,0x5,0x8,0x9,0x4,0x2,0xF,0x0,0xD,0xB,0x6,0x7,0xA,0xC,0x1 };
  for(int k=0; k<len; k+=32) {
    memcpy(buf+8,buf,8);
    for(int i=0; i<8; i++) {
      int n=i<<1;
      buf[n+1]=buf[i+8];
      buf[n  ]=(t1[buf[n+1]>>4]<<4) | t1[buf[i+8]&0xF];
      LDUMP(L_SYS_VERBOSE,buf,16,"rsa buf:");
      }
    for(int i=16; i<64; i+=16) memcpy(&buf[i],buf,16);
    buf[31]=((buf[15]<<4)&0xFF) | 6;
    buf[16]=buf[0]^1;
    buf[32]&=0x7F;
    buf[32]|=0x40;
    RotateBytes(buf,32);
    RotateBytes(buf+32,32);
    LDUMP(L_SYS_VERBOSE,buf,64,"rsa data:");

    if(rsa.RSA(buf,buf,64,exp,mod,true)==0) {
      PRINTF(L_SYS_CRYPTO,"RSA failed");
      return false;
      }
    RotateBytes(buf,8);
    RotateBytes(mask+k,buf+8,min(32,len-k));
    }
  LDUMP(L_SYS_VERBOSE,mask,len,"rsa out:");

  xxor(data,len,data,mask);
  return true;
}
void cCryptoworks::Signature ( const unsigned char *  data,
int  len,
const unsigned char *  key22,
unsigned char *  sig 
)

Definition at line 239 of file cryptoworks.c.

References cCwDes::CwDes(), cCwDes::CwL2Des(), cCwDes::CwR2Des(), DES_LEFT, i, j, L_SYS_VERBOSE, LDUMP, and PRINTF.

Referenced by cSystemCryptoworks::ProcessECM().

{
  PRINTF(L_SYS_VERBOSE,"sig start");
  int algo=data[0]&7;
  if(algo==7) algo=6;
  memset(sig,0,8);
  int j=0;
  bool first=true;
  for(int i=0; i<len; i++) {
    sig[j]^=data[i];
    if(++j>7) {
      LDUMP(L_SYS_VERBOSE,sig,8,"sig buf");
      if(first) {
        des.CwL2Des(sig,key22,algo);
        LDUMP(L_SYS_VERBOSE,sig,8,"sig -> ");
        }
      des.CwDes(sig,key22,DES_LEFT);
      j=0; first=false;
      LDUMP(L_SYS_VERBOSE,sig,8,"sig -> ");
      }
    }
  if(j>0) {
    LDUMP(L_SYS_VERBOSE,sig,8,"sig buf final ");
    des.CwDes(sig,key22,DES_LEFT);
    LDUMP(L_SYS_VERBOSE,sig,8,"sig        -> ");
    }
  des.CwR2Des(sig,key22,algo);
  LDUMP(L_SYS_VERBOSE,sig,8,"sig calc ");
}

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