From a3e5ce889d5071e415f4fa266037656a0b0fdc8f Mon Sep 17 00:00:00 2001 From: anon Date: Sat, 5 Apr 2008 16:11:17 +0200 Subject: [PATCH] nagra-0101: map2a --- systems/nagra/nagra2-0101.c | 11 +++++++++-- systems/nagra/nagra2.c | 13 ++++++++++--- systems/nagra/nagra2.h | 4 ++-- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/systems/nagra/nagra2-0101.c b/systems/nagra/nagra2-0101.c index 12be059..f0f51d4 100644 --- a/systems/nagra/nagra2-0101.c +++ b/systems/nagra/nagra2-0101.c @@ -443,8 +443,15 @@ void cMap0101::DoMap(int f, unsigned char *data, int l) if(data) data[0]=b; if(b) BN_mask_bits(B,wordsize<<6); cycles=501+(8*wordsize+3)/5*5-6; - } break; + } + case 0x2a: + { + bool b=ModSub(B,B,D); + if(data) data[0]=b; + BN_zero(C); + break; + } case 0x30: BN_sqr(D,B,ctx); BN_rshift(C,D,wordsize<<6); @@ -814,7 +821,7 @@ bool cN2Prov0101::ProcessMap(int f) AddCycles(MapCycles()); break; case 0x29: - GetMem(HILO(0x44),tmp,dl,0); + case 0x2a: DoMap(f,tmp); Set(0x4b,tmp[0]); AddCycles(MapCycles()); diff --git a/systems/nagra/nagra2.c b/systems/nagra/nagra2.c index 8edcf3b..38f0bce 100644 --- a/systems/nagra/nagra2.c +++ b/systems/nagra/nagra2.c @@ -255,19 +255,26 @@ cMapMath::cMapMath(void) wordsize=DEF_WORDSIZE; } -void cMapMath::ModAdd(BIGNUM *r, BIGNUM *a, BIGNUM *b, BIGNUM *d) +bool cMapMath::ModAdd(BIGNUM *r, BIGNUM *a, BIGNUM *b, BIGNUM *d) { BN_add(r,a,b); - if(BN_cmp(r,d)>=0) BN_sub(r,r,d); + bool ret=false; + if(BN_cmp(r,d)>=0) { + BN_sub(r,r,d); + ret=true; + } BN_mask_bits(r,wordsize<<6); + return ret; } -void cMapMath::ModSub(BIGNUM *r, BIGNUM *d, BIGNUM *b) +bool cMapMath::ModSub(BIGNUM *r, BIGNUM *d, BIGNUM *b) { 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; } void cMapMath::MakeJ0(BIGNUM *j, BIGNUM *d, int bits) diff --git a/systems/nagra/nagra2.h b/systems/nagra/nagra2.h index af00a3e..f1003ea 100644 --- a/systems/nagra/nagra2.h +++ b/systems/nagra/nagra2.h @@ -66,8 +66,8 @@ protected: SHA_CTX sctx; // stateless void MakeJ0(BIGNUM *j, BIGNUM *d, int bits=64); - void ModAdd(BIGNUM *r, BIGNUM *a, BIGNUM *b, BIGNUM *d); - void ModSub(BIGNUM *r, BIGNUM *d, BIGNUM *b); + 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 MonStart(int w); void MonLoop(BIGNUM *o, BIGNUM *a, BIGNUM *b, BIGNUM *c, BIGNUM *d, BIGNUM *j); -- 2.39.5