Changeset 4686 for trunk/reader-dre.c


Ignore:
Timestamp:
Feb 7, 2011, 9:36:44 AM (9 years ago)
Author:
landlord
Message:

Added patch for DRE2 (Platforma HD + Tricolor) SCs.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/reader-dre.c

    r4582 r4686  
     1#include <openssl/des.h>
     2
    13#include "globals.h"
    24#include "reader-common.h"
     
    46#define OK_RESPONSE 0x61
    57#define CMD_BYTE 0x59
     8
     9void DES_Decrypt(DES_cblock *data, const_DES_cblock *key)
     10{
     11  DES_cblock out;
     12  DES_key_schedule schedule;
     13
     14  DES_set_key_unchecked(key, &schedule);
     15  DES_ecb_encrypt(data, &out, &schedule, 0);
     16
     17  memcpy(data, &out, 8);
     18}
    619
    720static uchar xor (const uchar * cmd, int cmdlen)
     
    246259}
    247260
     261static unsigned char DESkeys[16*8]=
     262{
     263  0x4A,0x11,0x23,0xB1,0x45,0x99,0xCF,0x10, // 00
     264  0x21,0x1B,0x18,0xCD,0x02,0xD4,0xA1,0x1F, // 01
     265  0x07,0x56,0xAB,0xB4,0x45,0x31,0xAA,0x23, // 02
     266  0xCD,0xF2,0x55,0xA1,0x13,0x4C,0xF1,0x76, // 03
     267  0x57,0xD9,0x31,0x75,0x13,0x98,0x89,0xC8, // 04
     268  0xA3,0x36,0x5B,0x18,0xC2,0x83,0x45,0xE2, // 05
     269  0x19,0xF7,0x35,0x08,0xC3,0xDA,0xE1,0x28, // 06
     270  0xE7,0x19,0xB5,0xD8,0x8D,0xE3,0x23,0xA4, // 07
     271  0xA7,0xEC,0xD2,0x15,0x8B,0x42,0x59,0xC5, // 08
     272  0x13,0x49,0x83,0x2E,0xFB,0xAD,0x7C,0xD3, // 09
     273  0x37,0x25,0x78,0xE3,0x72,0x19,0x53,0xD9, // 0A
     274  0x7A,0x15,0xA4,0xC7,0x15,0x49,0x32,0xE8, // 0B
     275  0x63,0xD5,0x96,0xA7,0x27,0xD8,0xB2,0x68, // 0C
     276  0x42,0x5E,0x1A,0x8C,0x41,0x69,0x8E,0xE8, // 0D
     277  0xC2,0xAB,0x37,0x29,0xD3,0xCF,0x93,0xA7, // 0E
     278  0x49,0xD3,0x33,0xC2,0xEB,0x71,0xD3,0x14  // 0F
     279};
     280
     281void DREover(unsigned char *ECMdata, unsigned char *DW)
     282{
     283  unsigned char i, data[8], key[8];
     284  if(ECMdata[2] >= (43+4) && ECMdata[40] == 0x3A && ECMdata[41] == 0x4B)
     285  {
     286    for(i = 0; i < 8; i++) key[i] = DESkeys[(ECMdata[42] & 0x0F) * 8 + i];
     287
     288    for(i = 0; i < 8; i++) data[i] = DW[i];
     289    DES_Decrypt(&data, &key);                             // even DW post-process
     290    for(i = 0; i < 8; i++) DW[i] = data[i];
     291
     292    for(i = 0; i < 8; i++) data[i] = DW[8+i];
     293    DES_Decrypt(&data, &key);                             // odd DW post-process
     294    for(i = 0; i < 8; i++) DW[8+i] = data[i];
     295  };
     296};
     297
    248298static int dre_do_ecm (struct s_reader * reader, ECM_REQUEST * er)
    249299{
     
    287337      if ((cta_res[cta_lr - 2] != 0x90) || (cta_res[cta_lr - 1] != 0x00))
    288338                return ERROR;       //exit if response is not 90 00
     339      DREover(er->ecm, cta_res + 3);
    289340      memcpy (er->cw, cta_res + 11, 8);
    290341      memcpy (er->cw + 8, cta_res + 3, 8);
Note: See TracChangeset for help on using the changeset viewer.