|
SASC-NG
DVBSoftCAM
|
#include <nagra2.h>
Inheritance diagram for cMapCore:Public Member Functions | |
| 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) |
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 |
| cMapCore::cMapCore | ( | void | ) |
Definition at line 597 of file nagra2.c.
References cMapMath::A, cMapMath::B, cMapMath::C, cMapMath::D, and cMapMath::J.
| virtual void cMapCore::AddMapCycles | ( | unsigned int | num | ) | [inline, protected, virtual] |
Reimplemented in cN2Prov0101, and cN2Prov0501.
Definition at line 178 of file nagra2.h.
Referenced by DoMap(), IMakeJ(), IMonInit0(), and cMap0101::Map().
{}
| 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);
}
| virtual unsigned int cMapCore::CpuCycles | ( | void | ) | [inline, protected, virtual] |
Reimplemented in cN2Prov0101, and cN2Prov0501.
Definition at line 180 of file nagra2.h.
Referenced by DoMap().
{ return 0; }
| 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] |
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);
}
| 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] |
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] |
Definition at line 654 of file nagra2.c.
References IMakeJ(), and IMonInit0().
Referenced by cMap0101::Map().
| 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);
}
}
| bool cMapCore::Interrupted | ( | void | ) | [inline, protected] |
| bool cMapCore::Interruptible | ( | void | ) | [inline, protected] |
Definition at line 176 of file nagra2.h.
Referenced by cN2Prov0101::TimerHandler().
{ return interruptible; }
| virtual bool cMapCore::Map | ( | int | f, |
| unsigned char * | data, | ||
| int | l | ||
| ) | [inline, protected, virtual] |
| unsigned int cMapCore::MapCycles | ( | void | ) | [inline, 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().
| 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().
| 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().
| 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::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().
| 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().
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().