]> www.vanbest.org Git - sasc-ng.git/commitdiff
nagra: fix MECM cache for seedsize>5
authorleslie <unknown>
Tue, 15 Jan 2008 21:28:22 +0000 (22:28 +0100)
committerleslie <unknown>
Tue, 15 Jan 2008 21:28:22 +0000 (22:28 +0100)
systems/nagra/nagra2-0101.c
systems/nagra/nagra2-0501.c
systems/nagra/nagra2.c
systems/nagra/nagra2.h

index e0c085b2d6f4aa4ea002fd73b89fad799f5e3aef..0a999d2798f5dc278623652ba0da54ba1f17d6d5 100644 (file)
@@ -542,7 +542,8 @@ protected:
   int mecmAddr[2];
   int mecmKeyId;
   //
-  virtual bool Algo(int algo, unsigned char *hd, const unsigned char *ed, unsigned char *hw);
+  virtual bool Algo(int algo, const unsigned char *hd, unsigned char *hw);
+  virtual void DynamicHD(unsigned char *hd, const unsigned char *ed);
   virtual bool RomInit(void);
   virtual void Stepper(void);
   virtual void TimerHandler(unsigned int num);
@@ -564,7 +565,16 @@ cN2Prov0101::cN2Prov0101(int Id, int Flags)
   desSize=16; hwMapper=0;
 }
 
-bool cN2Prov0101::Algo(int algo, unsigned char *hd, const unsigned char *ed, unsigned char *hw)
+void cN2Prov0101::DynamicHD(unsigned char *hd, const unsigned char *ed)
+{
+  hd[5]=ed[5];
+  hd[6]=(ed[7]&0xEF) | ((ed[6]&0x40)>>2);
+  hd[7]=ed[8];
+  hd[8]=(ed[9]&0x7F) | ((ed[6]&0x20)<<2);
+  hd[9]=ed[6]&0x80;
+}
+
+bool cN2Prov0101::Algo(int algo, const unsigned char *hd, unsigned char *hw)
 {
   if(algo!=0x40 && algo!=0x60) {
     PRINTF(L_SYS_ECM,"%04X: unknown MECM algo %02x",id,algo);
@@ -603,12 +613,6 @@ bool cN2Prov0101::Algo(int algo, unsigned char *hd, const unsigned char *ed, uns
      return false;
     }
 
-  // dynamic expand
-  hd[5]=ed[5];
-  hd[6]=(ed[7]&0xEF) | ((ed[6]&0x40)>>2);
-  hd[7]=ed[8];
-  hd[8]=(ed[9]&0x7F) | ((ed[6]&0x20)<<2);
-  hd[9]=ed[6]&0x80;
   memcpy(hw,hd,seedSize);
   ExpandInput(hw);
 
index 16a84a0d99fbf8e93756c14828dcf85eb34bd2da..e5992c65ac3aa456e097674349db9f25c55ecde4 100644 (file)
@@ -71,7 +71,7 @@ private:
   bool RomCallbacks(void);
   void AddRomCallbacks(void);
 protected:
-  virtual bool Algo(int algo, unsigned char *hd, const unsigned char *ed, unsigned char *hw);
+  virtual bool Algo(int algo, const unsigned char *hd, unsigned char *hw);
   virtual bool NeedsCwSwap(void) { return true; }
   virtual bool RomInit(void);
   virtual void TimerHandler(unsigned int num);
@@ -89,7 +89,7 @@ cN2Prov0501::cN2Prov0501(int Id, int Flags)
   hwMapper=0;
 }
 
-bool cN2Prov0501::Algo(int algo, unsigned char *hd, const unsigned char *ed, unsigned char *hw)
+bool cN2Prov0501::Algo(int algo, const unsigned char *hd, unsigned char *hw)
 {
   if(algo==0x60) {
     hw[0]=hd[0];
index 84c2212c9ad2a3261a214e21903855d7fa0c3d0b..0589bb9a562325cdeb4c77ea8ad5319c5cf413e6 100644 (file)
@@ -587,13 +587,14 @@ bool cN2Prov::MECM(unsigned char in15, int algo, const unsigned char *ed, unsign
   hd[2]=cw[15];
   hd[3]=cw[6];
   hd[4]=cw[7];
+  DynamicHD(hd,ed);
 
   if(keyValid && !memcmp(seed,hd,seedSize)) {  // key cached
     memcpy(buf,cwkey,8);
     }
   else {                               // key not cached
     memset(hw,0,sizeof(hw));
-    if(!Algo(algo,hd,ed,hw)) return false;
+    if(!Algo(algo,hd,hw)) return false;
     memcpy(&hw[128],hw,64);
     RotateBytes(&hw[64],128);
     SHA1(&hw[64],128,buf);
index be5ce3082f23df78b0c82b7d0075af2ce6183843..db94f3f18aac36b8a6e5202815784b24988bd878 100644 (file)
@@ -201,7 +201,8 @@ protected:
   int id, flags, seedSize;
   cIDEA idea;
   //
-  virtual bool Algo(int algo, unsigned char *hd, const unsigned char *ed, unsigned char *hw) { return false; }
+  virtual bool Algo(int algo, const unsigned char *hd, unsigned char *hw) { return false; }
+  virtual void DynamicHD(unsigned char *hd, const unsigned char *ed) {}
   virtual bool NeedsCwSwap(void) { return false; }
   void ExpandInput(unsigned char *hw);
 public: