SASC
DVBSoftCAM

cMapMath Class Reference

#include <nagra2.h>

Inheritance diagram for cMapMath:

List of all members.

Public Member Functions

 cMapMath (void)
 cMapMath (void)

Protected Member Functions

void MakeJ0 (BIGNUM *j, BIGNUM *d, BIGNUM *c=0, int bits=64)
bool ModAdd (BIGNUM *r, BIGNUM *a, BIGNUM *b, BIGNUM *d)
bool ModSub (BIGNUM *r, BIGNUM *d, BIGNUM *b)
void MonMul (BIGNUM *o, BIGNUM *a, BIGNUM *b, BIGNUM *c, BIGNUM *d, BIGNUM *j, int w)
void MonMul0 (BIGNUM *o, BIGNUM *a, BIGNUM *b, BIGNUM *c, BIGNUM *d, BIGNUM *j, int w)
void MonStart (int w)
void MonLoop (BIGNUM *o, BIGNUM *a, BIGNUM *b, BIGNUM *c, BIGNUM *d, BIGNUM *j)
void MonFin (BIGNUM *s, BIGNUM *d)
void MonMul (BIGNUM *o, BIGNUM *a, BIGNUM *b)
void MonMul (BIGNUM *o, BIGNUM *a, BIGNUM *b, int w)
void MakeJ0 (BIGNUM *j, BIGNUM *d, BIGNUM *c=0, int bits=64)
bool ModAdd (BIGNUM *r, BIGNUM *a, BIGNUM *b, BIGNUM *d)
bool ModSub (BIGNUM *r, BIGNUM *d, BIGNUM *b)
void MonMul (BIGNUM *o, BIGNUM *a, BIGNUM *b, BIGNUM *c, BIGNUM *d, BIGNUM *j, int w)
void MonMul0 (BIGNUM *o, BIGNUM *a, BIGNUM *b, BIGNUM *c, BIGNUM *d, BIGNUM *j, int w)
void MonStart (int w)
void MonLoop (BIGNUM *o, BIGNUM *a, BIGNUM *b, BIGNUM *c, BIGNUM *d, BIGNUM *j)
void MonFin (BIGNUM *s, BIGNUM *d)
void MonMul (BIGNUM *o, BIGNUM *a, BIGNUM *b)
void MonMul (BIGNUM *o, BIGNUM *a, BIGNUM *b, int w)

Protected Attributes

int wordsize
int regpos
cMapReg A
cMapReg B
cMapReg C
cMapReg D
cMapReg J
cMapReg I
cBN H
cBN scalar
cBNctx ctx
SHA_CTX sctx

Detailed Description

Definition at line 89 of file nagra2.h.


Constructor & Destructor Documentation

cMapMath::cMapMath ( void  )

Definition at line 470 of file nagra2.c.

References DEF_WORDSIZE, regpos, and wordsize.

cMapMath::cMapMath ( void  )

Member Function Documentation

void cMapMath::MakeJ0 ( BIGNUM *  j,
BIGNUM *  d,
BIGNUM *  c = 0,
int  bits = 64 
) [protected]

Definition at line 499 of file nagra2.c.

References ctx.

Referenced by cMapCore::IMakeJ(), cMap0101::Map(), and cMapCore::MonInit().

{
#if OPENSSL_VERSION_NUMBER < 0x0090700fL
#error BN_mod_inverse is probably buggy in your openssl version
#endif
  BN_zero(x);
  BN_sub(j,x,d); j->neg=1;
  BN_set_bit(j,0);
  BN_set_bit(x,bits);
  BN_mod_inverse(j,j,x,ctx);
  if(c) {
    BN_copy(c,d);
    BN_mask_bits(c,bits);
    BN_mul(c,j,c,ctx);
    BN_rshift(c,c,bits);
    BN_mask_bits(c,bits);
    }
}
void cMapMath::MakeJ0 ( BIGNUM *  j,
BIGNUM *  d,
BIGNUM *  c = 0,
int  bits = 64 
) [protected]
bool cMapMath::ModAdd ( BIGNUM *  r,
BIGNUM *  a,
BIGNUM *  b,
BIGNUM *  d 
) [protected]

Definition at line 477 of file nagra2.c.

References wordsize.

Referenced by cMapCore::AddP(), and cMapCore::DoubleP().

{
  BN_add(r,a,b);
  bool ret=false;
  if(BN_cmp(r,d)>=0) {
    BN_sub(r,r,d);
    ret=true;
    }
  BN_mask_bits(r,wordsize<<6);
  return ret;
}
bool cMapMath::ModAdd ( BIGNUM *  r,
BIGNUM *  a,
BIGNUM *  b,
BIGNUM *  d 
) [protected]
bool cMapMath::ModSub ( BIGNUM *  r,
BIGNUM *  d,
BIGNUM *  b 
) [protected]

Definition at line 489 of file nagra2.c.

References ctx, and wordsize.

Referenced by cMapCore::AddP(), cMapCore::DoubleP(), and cMap0101::Map().

{
  cBN p;
  bool ret=BN_cmp(d,b)<0;
  BN_set_bit(p,wordsize<<6);
  BN_mod_sub(r,d,b,p,ctx);
  BN_mask_bits(r,wordsize<<6);
  return ret;
}
bool cMapMath::ModSub ( BIGNUM *  r,
BIGNUM *  d,
BIGNUM *  b 
) [protected]
void cMapMath::MonFin ( BIGNUM *  s,
BIGNUM *  d 
) [protected]

Definition at line 589 of file nagra2.c.

Referenced by cMapCore::IMonInit0(), cMap0101::Map(), MonLoop(), and MonMul().

{
  if(BN_cmp(s,d)>=0)
    BN_sub(s,s,d);
}
void cMapMath::MonFin ( BIGNUM *  s,
BIGNUM *  d 
) [protected]
void cMapMath::MonLoop ( BIGNUM *  o,
BIGNUM *  a,
BIGNUM *  b,
BIGNUM *  c,
BIGNUM *  d,
BIGNUM *  j 
) [protected]
void cMapMath::MonLoop ( BIGNUM *  o,
BIGNUM *  a,
BIGNUM *  b,
BIGNUM *  c,
BIGNUM *  d,
BIGNUM *  j 
) [protected]

Definition at line 554 of file nagra2.c.

References ctx, MonFin(), and wordsize.

Referenced by MonMul0().

{
  words--;
  BN_mask_bits(a,64);
  BN_mul(a,a,b,ctx);
  BN_add(s,s,a);

  BN_copy(x,s);
  BN_mask_bits(x,64);
  BN_mul(x,x,j,ctx);
  if(!words) {
    BN_lshift(y,x,64);
    BN_add(y,y,x);
    // Low
    BN_rshift(c,y,2);
    BN_add(c,c,s);
    BN_rshift(c,c,52);
    BN_mask_bits(c,12);
    }

  BN_mask_bits(x,64);
  BN_mul(x,x,d,ctx);
  BN_add(s,s,x);
  if(!words) {
    // High
    BN_lshift(y,s,12);
    BN_add(c,c,y);
    BN_mask_bits(c,wordsize<<6);
    }

  BN_rshift(s,s,64);
  if(words) MonFin(s,d);
  if(!words) BN_copy(o,s);
}
void cMapMath::MonMul ( BIGNUM *  o,
BIGNUM *  a,
BIGNUM *  b,
int  w 
) [protected]

Definition at line 523 of file nagra2.c.

References C, D, J, and MonMul().

{
  MonMul(o,a,b,C,D,J,w);
}
void cMapMath::MonMul ( BIGNUM *  o,
BIGNUM *  a,
BIGNUM *  b 
) [protected]

Definition at line 518 of file nagra2.c.

References C, D, J, and MonMul().

{
  MonMul(o,a,b,C,D,J,0);
}
void cMapMath::MonMul ( BIGNUM *  o,
BIGNUM *  a,
BIGNUM *  b 
) [protected]
void cMapMath::MonMul ( BIGNUM *  o,
BIGNUM *  a,
BIGNUM *  b,
int  w 
) [protected]
void cMapMath::MonMul ( BIGNUM *  o,
BIGNUM *  a,
BIGNUM *  b,
BIGNUM *  c,
BIGNUM *  d,
BIGNUM *  j,
int  w 
) [protected]
void cMapMath::MonMul ( BIGNUM *  o,
BIGNUM *  a,
BIGNUM *  b,
BIGNUM *  c,
BIGNUM *  d,
BIGNUM *  j,
int  w 
) [protected]
void cMapMath::MonMul0 ( BIGNUM *  o,
BIGNUM *  a,
BIGNUM *  b,
BIGNUM *  c,
BIGNUM *  d,
BIGNUM *  j,
int  w 
) [protected]
void cMapMath::MonMul0 ( BIGNUM *  o,
BIGNUM *  a,
BIGNUM *  b,
BIGNUM *  c,
BIGNUM *  d,
BIGNUM *  j,
int  w 
) [protected]

Definition at line 534 of file nagra2.c.

References i, MonLoop(), MonStart(), and wordsize.

Referenced by cMapCore::IMonInit0(), cMap0101::Map(), and MonMul().

{
  if(!w) w=wordsize;
  MonStart(w);
  int i=0;
  while(words>0) {
    BN_rshift(x,a,(i++)<<6);
    MonLoop(o,x,b,c,d,j);
    }
}
void cMapMath::MonStart ( int  w) [protected]

Definition at line 545 of file nagra2.c.

Referenced by MonMul0().

{
  if(words<=0) {
    words=w;
    BN_zero(s);
    }
}
void cMapMath::MonStart ( int  w) [protected]

Member Data Documentation

cBNctx cMapMath::ctx [protected]

Definition at line 97 of file nagra2.h.

Referenced by cMapCore::IMonInit0(), MakeJ0(), cMap0101::Map(), ModSub(), cMapCore::MonInit(), and MonLoop().

cBN cMapMath::H [protected]

Definition at line 96 of file nagra2.h.

int cMapMath::regpos [protected]

Definition at line 94 of file nagra2.h.

Referenced by cMapMath().

cBN cMapMath::scalar [protected]

Definition at line 96 of file nagra2.h.

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

SHA_CTX cMapMath::sctx [protected]

Definition at line 98 of file nagra2.h.

Referenced by cMap4101::Map().


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