SASC
DVBSoftCAM

cMapCore Class Reference

#include <nagra2.h>

Inheritance diagram for cMapCore:

List of all members.

Public Member Functions

 cMapCore (void)
virtual ~cMapCore ()
 cMapCore (void)
virtual ~cMapCore ()

Protected Member Functions

void MonInit (int bits=0)
void MonExp (BIGNUM *scalar)
void MonExpNeg (void)
void IMakeJ (void)
void IMonInit0 (int bits=0)
void IMonInit (int bits=0)
void DoubleP (int temp)
void AddP (int temp)
void ToProjective (int set, BIGNUM *x, BIGNUM *y)
void ToAffine (void)
void CurveInit (BIGNUM *a)
int GetOpSize (int l)
void DoMap (int f, unsigned char *data=0, int l=0)
virtual bool Map (int f, unsigned char *data, int l)
void SetMapIdent (int Mapid)
bool Interruptible (void)
bool Interrupted (void)
virtual void AddMapCycles (unsigned int num)
unsigned int MapCycles (void)
virtual unsigned int CpuCycles (void)
virtual void PostDecryptSetup (bool ecm)
void MonInit (int bits=0)
void MonExp (BIGNUM *scalar)
void MonExpNeg (void)
void IMakeJ (void)
void IMonInit0 (int bits=0)
void IMonInit (int bits=0)
void DoubleP (int temp)
void AddP (int temp)
void ToProjective (int set, BIGNUM *x, BIGNUM *y)
void ToAffine (void)
void CurveInit (BIGNUM *a)
int GetOpSize (int l)
void DoMap (int f, unsigned char *data=0, int l=0)
virtual bool Map (int f, unsigned char *data, int l)
void SetMapIdent (int Mapid)
bool Interruptible (void)
bool Interrupted (void)
virtual void AddMapCycles (unsigned int num)
unsigned int MapCycles (void)
virtual unsigned int CpuCycles (void)
virtual void PostDecryptSetup (bool ecm)

Protected Attributes

unsigned int cycles
cBN Px
cBN Py
cBN Pz
cBN Qx
cBN Qy
cBN Qz
cBN sA0
cBN sC0
cBN sE0
cBN s100
cBN s120
cBN s140
cBN s160

Detailed Description

Definition at line 145 of file nagra2.h.


Constructor & Destructor Documentation

cMapCore::cMapCore ( void  )

Definition at line 597 of file nagra2.c.

References cMapMath::A, cMapMath::B, cMapMath::C, cMapMath::D, and cMapMath::J.

{
  last=1; mapid=0;
  regs[0]=&J; regs[1]=&A; regs[2]=&B; regs[3]=&C; regs[4]=&D;
  interruptible=false;
}
virtual cMapCore::~cMapCore ( ) [inline, virtual]

Definition at line 184 of file nagra2.h.

{}
cMapCore::cMapCore ( void  )
virtual cMapCore::~cMapCore ( ) [inline, virtual]

Definition at line 184 of file nagra2.h.

{}

Member Function Documentation

virtual void cMapCore::AddMapCycles ( unsigned int  num) [inline, protected, virtual]

Reimplemented in cN2Prov0101, cN2Prov0501, cN2Prov0101, and cN2Prov0501.

Definition at line 178 of file nagra2.h.

Referenced by DoMap(), IMakeJ(), IMonInit0(), and cMap0101::Map().

{}
virtual void cMapCore::AddMapCycles ( unsigned int  num) [inline, protected, virtual]

Reimplemented in cN2Prov0101, cN2Prov0501, cN2Prov0101, and cN2Prov0501.

Definition at line 178 of file nagra2.h.

{}
void cMapCore::AddP ( int  temp) [protected]

Definition at line 746 of file nagra2.c.

References cMapMath::A, cMapMath::B, cMapMath::D, cMapMath::I, cMapMath::ModAdd(), cMapMath::ModSub(), cMapMath::MonMul(), Px, Py, Pz, Qx, Qy, s100, s120, s140, sA0, sC0, and sE0.

Referenced by cMap4101::Map(), and cMap0101::Map().

{
  MonMul(B,Pz,Pz);
  MonMul(sA0,Pz,B);
  MonMul(B,Qx,B);
  BN_copy(A,B);
  ModSub(B,D,B);
  ModAdd(B,Px,B,D);
  BN_copy(sC0,B);
  MonMul(I,Pz,B);
  if(temp==0) BN_copy(Pz,I); else BN_copy(sA0,I);
  MonMul(B,B,B);
  BN_copy(sE0,B);
  ModAdd(A,Px,A,D);
  MonMul(A,A,B);
  BN_copy(s100,A);
  MonMul(B,sA0,Qy);
  BN_copy(sA0,B);
  ModSub(B,D,B);
  ModAdd(B,Py,B,D);
  BN_copy(s120,B);
  MonMul(B,B,B);
  BN_swap(A,B);
  ModSub(B,D,B);
  ModAdd(B,A,B,D);
  if(temp==0) BN_copy(Px,B); else BN_copy(sA0,B);
  ModAdd(B,B,B,D);
  ModSub(B,D,B);
  ModAdd(B,B,s100,D);
  ModAdd(A,sA0,Py,D);
  MonMul(sA0,s120,B);
  MonMul(B,sE0,sC0);
  MonMul(B,A,B);
  ModSub(B,D,B);
  ModAdd(B,B,sA0,D);
  MonMul(B,s140,B);
  if(temp==0) BN_copy(Py,B); else BN_copy(sA0,B);
}
void cMapCore::AddP ( int  temp) [protected]
virtual unsigned int cMapCore::CpuCycles ( void  ) [inline, protected, virtual]

Reimplemented in cN2Prov0101, cN2Prov0501, cN2Prov0101, and cN2Prov0501.

Definition at line 180 of file nagra2.h.

Referenced by DoMap().

{ return 0; }
virtual unsigned int cMapCore::CpuCycles ( void  ) [inline, protected, virtual]

Reimplemented in cN2Prov0101, cN2Prov0501, cN2Prov0101, and cN2Prov0501.

Definition at line 180 of file nagra2.h.

{ return 0; }
void cMapCore::CurveInit ( BIGNUM *  a) [protected]
void cMapCore::CurveInit ( BIGNUM *  a) [protected]

Definition at line 809 of file nagra2.c.

References cMapMath::A, cMapMath::B, cMapMath::D, cMapMath::I, MonInit(), cMapMath::MonMul(), Px, Py, Pz, Qx, Qy, Qz, s100, s120, s140, s160, sA0, sC0, sE0, and cMapMath::wordsize.

Referenced by cMap4101::Map(), and cMap0101::Map().

{
  BN_zero(Px); BN_zero(Py); BN_zero(Pz); BN_zero(Qx); BN_zero(Qy); BN_zero(Qz);
  BN_zero(sA0); BN_zero(sC0); BN_zero(sE0); BN_zero(s100);
  BN_zero(s120); BN_zero(s140); BN_zero(s160);
  MonInit();
  BN_copy(A,B);
  BN_copy(I,D);
  BN_add_word(I,1);
  BN_mask_bits(I,wordsize<<6);
  BN_rshift(I,I,1);
  MonMul(s140,I,B);
  MonMul(s160,B,a);
}
void cMapCore::DoMap ( int  f,
unsigned char *  data = 0,
int  l = 0 
) [protected]
void cMapCore::DoMap ( int  f,
unsigned char *  data = 0,
int  l = 0 
) [protected]

Definition at line 835 of file nagra2.c.

References AddMapCycles(), CpuCycles(), cycles, L_SYS_MAP, Map(), and PRINTF.

Referenced by cN2Prov0501::Algo(), cMap4101::Map(), and cN2Prov4101::ProcessBx().

{
  PRINTF(L_SYS_MAP,"%04x: calling function %02X",mapid,f);
  cycles=0;
  unsigned int startcycles=CpuCycles();
  interrupted=false; interruptible=true;
  try {
    if(!Map(f,data,l) && !MapGeneric(f,data,l))
      PRINTF(L_SYS_MAP,"%04x: unsupported map call %02x",mapid,f);
    if(cycles) {
      unsigned int elapsed=CpuCycles()-startcycles;
      if(cycles>elapsed) AddMapCycles(cycles-elapsed);
      }
    }
  catch(int) {
    interrupted=true;
    PRINTF(L_SYS_MAP,"%04x: call %02x interrupted (%d cycles)",mapid,f,CpuCycles()-startcycles);
    }
  interruptible=false;
  cycles=CpuCycles()-startcycles;
}
void cMapCore::DoubleP ( int  temp) [protected]

Definition at line 712 of file nagra2.c.

References cMapMath::A, cMapMath::B, cMapMath::C, cMapMath::D, cMapMath::ModAdd(), cMapMath::ModSub(), cMapMath::MonMul(), Px, Py, Pz, s160, sA0, and sC0.

Referenced by cMap4101::Map(), and cMap0101::Map().

{
  ModAdd(B,Py,Py,D);
  MonMul(sC0,Pz,B);
  MonMul(B,B,B);
  MonMul(B,Px,B);
  ModSub(sA0,D,B);
  MonMul(B,Px,Px);
  BN_copy(A,B);
  ModAdd(B,B,B,D);
  ModAdd(A,B,A,D);
  MonMul(B,Pz,Pz);
  MonMul(B,B,B);
  MonMul(B,s160,B);
  ModAdd(B,B,A,D);
  BN_copy(A,B);
  MonMul(B,B,B);
  BN_copy(C,sA0);
  ModAdd(B,C,B,D);
  ModAdd(B,C,B,D);
  if(temp==0) BN_copy(Px,B); else BN_copy(sA0,B);
  ModAdd(B,C,B,D);
  MonMul(B,A,B);
  BN_copy(A,B);
  MonMul(B,Py,Py);
  ModAdd(B,B,B,D);
  MonMul(B,B,B);
  ModAdd(B,B,B,D);
  ModAdd(B,B,A,D);
  ModSub(B,D,B);
  if(temp==0) { BN_copy(Py,B); BN_copy(Pz,sC0); }
  else BN_copy(sA0,sC0);
}
void cMapCore::DoubleP ( int  temp) [protected]
int cMapCore::GetOpSize ( int  l) [protected]
int cMapCore::GetOpSize ( int  l) [protected]

Definition at line 830 of file nagra2.c.

References cMapMath::wordsize.

Referenced by cMap0501::Map(), and cMap0101::Map().

{
  return l!=0 ? l : wordsize;
}
void cMapCore::IMakeJ ( void  ) [protected]
void cMapCore::IMakeJ ( void  ) [protected]

Definition at line 604 of file nagra2.c.

References AddMapCycles(), cMapMath::C, cMapMath::D, cMapMath::J, cMapMath::MakeJ0(), WS_END, and WS_START.

Referenced by IMonInit(), and cMap0101::Map().

{
  AddMapCycles(19);
  WS_START(1);
  AddMapCycles(102);
  MakeJ0(J,D,C);
  AddMapCycles(303);
  BN_zero(C);
  AddMapCycles(34);
  WS_END();
  AddMapCycles(10);
}
void cMapCore::IMonInit ( int  bits = 0) [protected]
void cMapCore::IMonInit ( int  bits = 0) [protected]

Definition at line 654 of file nagra2.c.

References IMakeJ(), and IMonInit0().

Referenced by cMap0101::Map().

{
  IMakeJ();
  IMonInit0(bits);
}
void cMapCore::IMonInit0 ( int  bits = 0) [protected]

Definition at line 617 of file nagra2.c.

References AddMapCycles(), cMapMath::B, cMapMath::C, cMapMath::ctx, cMapMath::D, cMapMath::I, i, cMapMath::J, cMapMath::MonFin(), cMapMath::MonMul0(), cMapReg::SetPos(), and cMapMath::wordsize.

Referenced by IMonInit(), and cMap0101::Map().

{
  AddMapCycles(114+(wordsize*8+3)/5*5);
  D.SetPos(2);
  AddMapCycles(18);
  if(BN_num_bits(D)>1)
    for(int i=3; i<=8; i++) {
      D.SetPos(i);
      AddMapCycles(9);
      }
  D.SetPos(0);
  if(!BN_is_zero(D)) {
    AddMapCycles(54);
    BN_zero(I);
    BN_set_bit(I,bits ? bits : 68*wordsize);
    BN_zero(B);
    AddMapCycles(157+(wordsize*8+3)/5*5+72*(wordsize-1));
    BN_set_bit(B,64*(wordsize-1));
    B.SetPos(8*(wordsize-1)+1);
    AddMapCycles(17);
    for(int i=8*(wordsize-1)+2; i<=8*wordsize; i++) {
      B.SetPos(i);
      AddMapCycles(9);
      }
    B.SetPos(0);
    AddMapCycles(68);
    BN_mod(B,I,D,ctx);
    AddMapCycles(639);
    }
   AddMapCycles(52);
   for(int i=0; i<4; i++) {
     MonMul0(B,B,B,C,D,J,0);
     AddMapCycles(96+6*(i>0));
     MonFin(B,D);
     }
}
void cMapCore::IMonInit0 ( int  bits = 0) [protected]
bool cMapCore::Interrupted ( void  ) [inline, protected]

Definition at line 177 of file nagra2.h.

{ return interrupted; }
bool cMapCore::Interrupted ( void  ) [inline, protected]

Definition at line 177 of file nagra2.h.

{ return interrupted; }
bool cMapCore::Interruptible ( void  ) [inline, protected]

Definition at line 176 of file nagra2.h.

Referenced by cN2Prov0101::TimerHandler().

{ return interruptible; }
bool cMapCore::Interruptible ( void  ) [inline, protected]

Definition at line 176 of file nagra2.h.

{ return interruptible; }
virtual bool cMapCore::Map ( int  f,
unsigned char *  data,
int  l 
) [inline, protected, virtual]

Reimplemented in cMap0101, cMap0501, cMap4101, cMap0101, cMap0501, and cMap4101.

Definition at line 174 of file nagra2.h.

{ return false; }
virtual bool cMapCore::Map ( int  f,
unsigned char *  data,
int  l 
) [inline, protected, virtual]

Reimplemented in cMap0101, cMap0501, cMap4101, cMap0101, cMap0501, and cMap4101.

Definition at line 174 of file nagra2.h.

Referenced by DoMap().

{ return false; }
unsigned int cMapCore::MapCycles ( void  ) [inline, protected]

Definition at line 179 of file nagra2.h.

References cycles.

{ return cycles; }
unsigned int cMapCore::MapCycles ( void  ) [inline, protected]

Definition at line 179 of file nagra2.h.

References cycles.

{ return cycles; }
void cMapCore::MonExp ( BIGNUM *  scalar) [protected]
void cMapCore::MonExp ( BIGNUM *  scalar) [protected]

Definition at line 672 of file nagra2.c.

References cMapMath::A, cMapMath::B, cMapMath::D, i, and cMapMath::MonMul().

{
  if(BN_is_zero(D)) { BN_one(A); return; }
  BN_copy(A,B);
  for(int i=BN_num_bits(scalar)-2; i>-1; i--) {
    MonMul(B,B,B);
    if(BN_is_bit_set(scalar,i)) MonMul(B,A,B);
    }
  BN_one(A);
  MonMul(B,A,B);
}
void cMapCore::MonExpNeg ( void  ) [protected]
void cMapCore::MonExpNeg ( void  ) [protected]

Definition at line 684 of file nagra2.c.

References cMapMath::A, cMapMath::B, cMapMath::D, i, and cMapMath::MonMul().

Referenced by cMap0101::Map(), and ToAffine().

{
  if(BN_is_zero(D) || BN_is_word(D,2)) {
    BN_one(A);
    if(!BN_is_zero(D)) BN_zero(B);
    return;
    }
  int bits=0;
  for(int i=BN_num_bits(D)-1; i>=0; i--) if(BN_is_bit_set(D,i)) bits++;
  BN_copy(e,D);
  BN_mask_bits(e,8);            // check LSB
  unsigned int n=BN_get_word(e);
  BN_copy(e,D);
  if(n) BN_sub_word(e,0x02);    // N -2
  else  BN_add_word(e,0xFE);    // N + 254 ('carryless' -2)
  BN_copy(A,B);
  for(int i=BN_num_bits(e)-2+(bits==1 && BN_num_bits(D)<=8); i>-1; i--) {
    MonMul(B,B,B);
    if(BN_is_bit_set(e,i)) MonMul(B,A,B);
    }
  if(bits==2 && BN_is_bit_set(D,0)) {
    MonMul(B,B,B);
    MonMul(B,A,B);
    }
  BN_one(A);
  MonMul(B,A,B);
}
void cMapCore::MonInit ( int  bits = 0) [protected]

Definition at line 660 of file nagra2.c.

References cMapMath::B, cMapMath::C, cMapMath::ctx, cMapMath::D, i, cMapMath::I, cMapMath::J, cMapMath::MakeJ0(), cMapMath::MonMul(), and cMapMath::wordsize.

Referenced by CurveInit().

{
  // Calculate J0 & H montgomery elements in J and B
  MakeJ0(J,D,C);
  if(!BN_is_zero(D)) {
    BN_zero(I);
    BN_set_bit(I,bits ? bits : 68*wordsize);
    BN_mod(B,I,D,ctx);
    }
  for(int i=0; i<4; i++) MonMul(B,B,B);
}
void cMapCore::MonInit ( int  bits = 0) [protected]
void cMapCore::PostDecryptSetup ( bool  ecm) [protected, virtual]

Definition at line 824 of file nagra2.c.

References cMapMath::wordsize.

Referenced by cN2Prov0501::PostDecrypt(), and cN2Prov0101::PostDecrypt().

{
  if(ecm) wordsize=0x8;
  else    wordsize=0xC;
}
virtual void cMapCore::PostDecryptSetup ( bool  ecm) [protected, virtual]
void cMapCore::SetMapIdent ( int  Mapid) [inline, protected]

Definition at line 175 of file nagra2.h.

Referenced by cN2Prov0101::cN2Prov0101(), cN2Prov0501::cN2Prov0501(), and cN2Prov4101::cN2Prov4101().

{ mapid=Mapid; }
void cMapCore::SetMapIdent ( int  Mapid) [inline, protected]

Definition at line 175 of file nagra2.h.

{ mapid=Mapid; }
void cMapCore::ToAffine ( void  ) [protected]
void cMapCore::ToAffine ( void  ) [protected]

Definition at line 799 of file nagra2.c.

References cMapMath::A, cMapMath::B, cMapMath::I, MonExpNeg(), cMapMath::MonMul(), Px, Py, and Pz.

Referenced by cMap4101::Map(), and cMap0101::Map().

{
  BN_set_word(I,1);
  MonMul(B,Pz,Pz); MonMul(B,Pz,B); MonMul(B,I,B);
  MonExpNeg();
  BN_set_word(I,1);
  MonMul(A,Py,B); MonMul(Py,I,A);
  MonMul(B,Pz,B); MonMul(B,Px,B); MonMul(Px,I,B);
}
void cMapCore::ToProjective ( int  set,
BIGNUM *  x,
BIGNUM *  y 
) [protected]

Definition at line 785 of file nagra2.c.

References cMapMath::B, cMapMath::I, cMapMath::MonMul(), Px, Py, Pz, Qx, Qy, and Qz.

Referenced by cMap4101::Map(), and cMap0101::Map().

{
  if(set==0) {
    BN_set_word(I,1); MonMul(Pz,I,B);
    BN_copy(Qz,Pz);
    MonMul(Px,x,B);
    MonMul(Py,y,B);
    }
  else {
    MonMul(Qx,x,B);
    MonMul(Qy,y,B);
    }
}
void cMapCore::ToProjective ( int  set,
BIGNUM *  x,
BIGNUM *  y 
) [protected]

Member Data Documentation

unsigned int cMapCore::cycles [protected]

Definition at line 154 of file nagra2.h.

Referenced by DoMap(), cMap0101::Map(), and MapCycles().

cBN cMapCore::Px [protected]

Definition at line 155 of file nagra2.h.

Referenced by AddP(), CurveInit(), DoubleP(), cMap4101::Map(), cMap0101::Map(), ToAffine(), and ToProjective().

cBN cMapCore::Py [protected]

Definition at line 155 of file nagra2.h.

Referenced by AddP(), CurveInit(), DoubleP(), cMap4101::Map(), cMap0101::Map(), ToAffine(), and ToProjective().

cBN cMapCore::Pz [protected]

Definition at line 155 of file nagra2.h.

Referenced by AddP(), CurveInit(), DoubleP(), cMap0101::Map(), ToAffine(), and ToProjective().

cBN cMapCore::Qx [protected]

Definition at line 155 of file nagra2.h.

Referenced by AddP(), CurveInit(), cMap4101::Map(), cMap0101::Map(), and ToProjective().

cBN cMapCore::Qy [protected]

Definition at line 155 of file nagra2.h.

Referenced by AddP(), CurveInit(), cMap4101::Map(), cMap0101::Map(), and ToProjective().

cBN cMapCore::Qz [protected]

Definition at line 155 of file nagra2.h.

Referenced by CurveInit(), cMap0101::Map(), and ToProjective().

cBN cMapCore::s100 [protected]

Definition at line 156 of file nagra2.h.

Referenced by AddP(), and CurveInit().

cBN cMapCore::s120 [protected]

Definition at line 156 of file nagra2.h.

Referenced by AddP(), and CurveInit().

cBN cMapCore::s140 [protected]

Definition at line 156 of file nagra2.h.

Referenced by AddP(), and CurveInit().

cBN cMapCore::s160 [protected]

Definition at line 156 of file nagra2.h.

Referenced by CurveInit(), and DoubleP().

cBN cMapCore::sA0 [protected]

Definition at line 156 of file nagra2.h.

Referenced by AddP(), CurveInit(), and DoubleP().

cBN cMapCore::sC0 [protected]

Definition at line 156 of file nagra2.h.

Referenced by AddP(), CurveInit(), and DoubleP().

cBN cMapCore::sE0 [protected]

Definition at line 156 of file nagra2.h.

Referenced by AddP(), and CurveInit().


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