Commit 4450cc66 authored by Sam Hocevar's avatar Sam Hocevar

* modules/demux/mp4/drms.c:

    + Removed unreachable code here and there.
    + Refactored some shuffling functions and got rid of the ext structure.
    + More code cleanup.
parent 30be512f
...@@ -107,18 +107,6 @@ struct shuffle_s ...@@ -107,18 +107,6 @@ struct shuffle_s
uint32_t p_bordel[ 16 ]; uint32_t p_bordel[ 16 ];
}; };
/*****************************************************************************
* shuffle_ext_s: extended shuffle structure
*****************************************************************************
* This structure stores the static information needed to shuffle data using
* a custom algorithm.
*****************************************************************************/
struct shuffle_ext_s
{
uint32_t * p_bordel;
uint32_t i_cmd, i_jc, i_tmp;
};
#define SWAP( a, b ) { (a) ^= (b); (b) ^= (a); (a) ^= (b); } #define SWAP( a, b ) { (a) ^= (b); (b) ^= (a); (a) ^= (b); }
/***************************************************************************** /*****************************************************************************
...@@ -154,14 +142,17 @@ static void InitShuffle ( struct shuffle_s *, uint32_t *, uint32_t ); ...@@ -154,14 +142,17 @@ static void InitShuffle ( struct shuffle_s *, uint32_t *, uint32_t );
static void DoShuffle ( struct shuffle_s *, uint32_t *, uint32_t ); static void DoShuffle ( struct shuffle_s *, uint32_t *, uint32_t );
static uint32_t FirstPass ( uint32_t * ); static uint32_t FirstPass ( uint32_t * );
static void SecondPass ( struct shuffle_ext_s * ); static void SecondPass ( uint32_t *, uint32_t );
static uint32_t ThirdPass ( uint32_t * ); static void ThirdPass ( uint32_t * );
static void FourthPass ( uint32_t *, uint32_t ); static void FourthPass ( uint32_t * );
static void FifthPass ( uint32_t * );
static void BigShuffle1 ( struct shuffle_ext_s * );
static void BigShuffle2 ( struct shuffle_ext_s * );
static void TinyShuffle1 ( uint32_t * ); static void TinyShuffle1 ( uint32_t * );
static void TinyShuffle2 ( uint32_t * ); static void TinyShuffle2 ( uint32_t * );
static void TinyShuffle3 ( uint32_t * );
static void TinyShuffle4 ( uint32_t * );
static void TinyShuffle5 ( uint32_t * );
static void TinyShuffle6 ( uint32_t * );
static void TinyShuffle7 ( uint32_t * );
static void TinyShuffle8 ( uint32_t * );
static void DoExtShuffle ( uint32_t * ); static void DoExtShuffle ( uint32_t * );
static int GetSystemKey ( uint32_t *, vlc_bool_t ); static int GetSystemKey ( uint32_t *, vlc_bool_t );
...@@ -821,51 +812,21 @@ static void DoShuffle( struct shuffle_s *p_shuffle, ...@@ -821,51 +812,21 @@ static void DoShuffle( struct shuffle_s *p_shuffle,
static void DoExtShuffle( uint32_t * p_bordel ) static void DoExtShuffle( uint32_t * p_bordel )
{ {
uint32_t i_ret; uint32_t i_ret;
struct shuffle_ext_s exs;
exs.p_bordel = p_bordel;
exs.i_tmp = FirstPass( p_bordel );
SecondPass( &exs ); i_ret = FirstPass( p_bordel );
i_ret = ThirdPass( p_bordel ); SecondPass( p_bordel, i_ret );
FourthPass( p_bordel, i_ret ); ThirdPass( p_bordel );
FifthPass( p_bordel ); FourthPass( p_bordel );
} }
static uint32_t FirstPass( uint32_t * p_bordel ) static uint32_t FirstPass( uint32_t * p_bordel )
{ {
uint32_t i, j; uint32_t i, i_cmd, i_ret = 5;
uint32_t i_cmd, i_ret;
i_ret = 5; TinyShuffle1( p_bordel );
i_cmd = (p_bordel[ 5 ] + 10) >> 2;
if( p_bordel[ 5 ] > 0x7D0 )
{
i_cmd -= 0x305;
}
switch( i_cmd & 3 )
{
case 0:
p_bordel[ 5 ] += 5;
break;
case 1:
p_bordel[ 4 ] -= 1;
break;
case 2:
if( p_bordel[ 4 ] & 5 )
{
p_bordel[ 1 ] ^= 0x4D;
}
/* no break */
case 3:
p_bordel[ 12 ] += 5;
break;
}
for( ; ; ) for( ; ; )
{ {
...@@ -884,9 +845,7 @@ static uint32_t FirstPass( uint32_t * p_bordel ) ...@@ -884,9 +845,7 @@ static uint32_t FirstPass( uint32_t * p_bordel )
if( (p_bordel[ 1 ] + p_bordel[ 2 ]) >= 0x7D0 ) if( (p_bordel[ 1 ] + p_bordel[ 2 ]) >= 0x7D0 )
{ {
i_cmd = ((p_bordel[ 3 ] ^ 0x567F) >> 2) & 7; switch( ((p_bordel[ 3 ] ^ 0x567F) >> 2) & 7 )
switch( i_cmd )
{ {
case 0: case 0:
for( i = 0; i < 3; i++ ) for( i = 0; i < 3; i++ )
...@@ -1012,305 +971,150 @@ break2: ...@@ -1012,305 +971,150 @@ break2:
break; break;
} }
for( i = 0, j = 0; i < 16; i++ ) TinyShuffle2( p_bordel );
{
if( (p_bordel[ i ] & 0x777) > (p_bordel[ j ] & 0x777) )
{
j = i;
}
}
if( j > 5 )
{
for( ; j < 15; j++ )
{
p_bordel[ j ] += p_bordel[ j + 1 ];
}
}
else
{
p_bordel[ 2 ] &= 0xB62FC;
}
return i_ret; return i_ret;
} }
static void SecondPass( struct shuffle_ext_s * p_exs ) static void SecondPass( uint32_t * p_bordel, uint32_t i_tmp )
{ {
uint32_t i; uint32_t i, i_cmd, i_jc = 5;
p_exs->i_cmd = p_exs->p_bordel[ 6 ] + 0x194B; TinyShuffle3( p_bordel );
if( p_exs->p_bordel[ 6 ] > 0x2710 )
{
p_exs->i_cmd >>= 1;
}
switch( p_exs->i_cmd & 3 ) for( i = 0, i_cmd = 0; i < 16; i++ )
{
case 1:
p_exs->p_bordel[ 3 ] += 0x19FE;
break;
case 2:
p_exs->p_bordel[ 7 ] -= p_exs->p_bordel[ 3 ] >> 2;
/* no break */
case 0:
p_exs->p_bordel[ 5 ] ^= 0x248A;
break;
}
p_exs->i_jc = 5;
for( i = 0, p_exs->i_cmd = 0; i < 16; i++ )
{ {
if( p_exs->p_bordel[ i ] > p_exs->p_bordel[ p_exs->i_cmd ] ) if( p_bordel[ i ] > p_bordel[ i_cmd ] )
{ {
p_exs->i_cmd = i; i_cmd = i;
} }
} }
switch( p_exs->i_cmd ) switch( i_cmd )
{ {
case 0: case 0:
if( p_exs->p_bordel[ 1 ] < p_exs->p_bordel[ 8 ] ) if( p_bordel[ 1 ] < p_bordel[ 8 ] )
{ {
p_exs->p_bordel[ 5 ] += 1; p_bordel[ 5 ] += 1;
} }
break; break;
case 4: case 4:
if( (p_exs->p_bordel[ 9 ] & 0x7777) == 0x3333 ) if( (p_bordel[ 9 ] & 0x7777) == 0x3333 )
{ {
p_exs->p_bordel[ 5 ] -= 1; p_bordel[ 5 ] -= 1;
} }
else else
{ {
p_exs->i_jc--; i_jc--;
if( p_exs->p_bordel[ 1 ] < p_exs->p_bordel[ 8 ] ) if( p_bordel[ 1 ] < p_bordel[ 8 ] )
{ {
p_exs->p_bordel[ 5 ] += 1; p_bordel[ 5 ] += 1;
} }
break; break;
} }
/* no break */ /* no break */
case 7: case 7:
p_exs->p_bordel[ 2 ] -= 1; p_bordel[ 2 ] -= 1;
p_exs->p_bordel[ 1 ] -= p_exs->p_bordel[ 5 ]; p_bordel[ 1 ] -= p_bordel[ 5 ];
TinyShuffle1( p_exs->p_bordel );
return;
case 10:
p_exs->p_bordel[ 4 ] -= 1;
p_exs->p_bordel[ 5 ] += 1;
p_exs->p_bordel[ 6 ] -= 1;
p_exs->p_bordel[ 7 ] += 1;
break;
default:
p_exs->p_bordel[ 15 ] ^= 0x18547EFF;
break;
}
BigShuffle1( p_exs );
}
static void BigShuffle1( struct shuffle_ext_s * p_exs )
{
uint32_t i, j;
for( i = 0; i < 3; i++ ) for( i = 0; i < 3; i++ )
{ {
p_exs->i_cmd = p_exs->p_bordel[ 12 ] + p_exs->p_bordel[ 13 ] + p_exs->p_bordel[ 6 ]; switch( p_bordel[ 1 ] & 3 )
p_exs->i_cmd -= (((uint32_t)(((uint64_t)p_exs->i_cmd * 0x0CCCCCCCD) >> 32)) >> 2) * 5;
if( p_exs->i_cmd > 4 )
{
break;
}
switch( p_exs->i_cmd )
{ {
case 0: case 0:
p_exs->p_bordel[ 12 ] -= 1; p_bordel[ 1 ] += 1;
/* no break */ /* no break */
case 1: case 1:
p_exs->p_bordel[ 12 ] -= 1; p_bordel[ 3 ] -= 8;
p_exs->p_bordel[ 13 ] += 1;
break; break;
case 2: case 2:
p_exs->p_bordel[ 13 ] += 4; p_bordel[ 13 ] &= 0xFEFEFEF7;
/* no break */
case 3:
p_exs->p_bordel[ 12 ] -= 1;
break; break;
case 4: case 3:
if( p_exs->i_jc ) p_bordel[ 8 ] |= 0x80080011;
{
p_exs->i_jc--;
p_exs->p_bordel[ 5 ] += 1;
p_exs->p_bordel[ 6 ] -= 1;
p_exs->p_bordel[ 7 ] += 1;
BigShuffle1( p_exs );
return;
}
break; break;
} }
} }
return;
for( i = 0, j = 0; i < 16; i++ ) case 10:
{ p_bordel[ 4 ] -= 1;
if( p_exs->p_bordel[ i ] < p_exs->p_bordel[ j ] ) p_bordel[ 5 ] += 1;
{ p_bordel[ 6 ] -= 1;
j = i; p_bordel[ 7 ] += 1;
} break;
} default:
p_bordel[ 15 ] ^= 0x18547EFF;
if( (p_exs->p_bordel[ j ] % (j + 1)) > 10 ) break;
{
p_exs->p_bordel[ 1 ] -= 1;
p_exs->p_bordel[ 2 ] += 0x13;
p_exs->p_bordel[ 12 ] += 1;
} }
BigShuffle2( p_exs ); for( i = 3; i--; )
}
static void BigShuffle2( struct shuffle_ext_s * p_exs )
{
uint32_t i;
p_exs->p_bordel[ 2 ] &= 0x7F3F;
for( i = 0; i < 5; i++ )
{ {
p_exs->i_cmd = (p_exs->p_bordel[ 2 ] + 0xA) + i; switch( ( p_bordel[ 12 ] + p_bordel[ 13 ] + p_bordel[ 6 ] ) % 5 )
p_exs->i_cmd -= (((uint32_t)(((uint64_t)p_exs->i_cmd * 0x0CCCCCCCD) >> 32)) >> 2) * 5;
if( p_exs->i_cmd > 4 )
{
continue;
}
switch( p_exs->i_cmd )
{ {
case 0: case 0:
p_exs->p_bordel[ 12 ] &= p_exs->p_bordel[ 2 ]; p_bordel[ 12 ] -= 1;
/* no break */ /* no break */
case 1: case 1:
p_exs->p_bordel[ 3 ] ^= p_exs->p_bordel[ 15 ]; p_bordel[ 12 ] -= 1;
p_bordel[ 13 ] += 1;
break; break;
case 2: case 2:
p_exs->p_bordel[ 15 ] += 0x576; p_bordel[ 13 ] += 4;
/* no break */ /* no break */
case 3: case 3:
p_exs->p_bordel[ 7 ] -= 0x2D; p_bordel[ 12 ] -= 1;
/* no break */ break;
case 4: case 4:
p_exs->p_bordel[ 1 ] <<= 1; i_jc--;
p_bordel[ 5 ] += 1;
p_bordel[ 6 ] -= 1;
p_bordel[ 7 ] += 1;
i = 3; /* Restart the whole loop */
break; break;
} }
} }
p_exs->i_cmd = (p_exs->p_bordel[ 2 ] * 2) + 15; TinyShuffle4( p_bordel );
p_exs->i_cmd -= (((uint32_t)(((uint64_t)p_exs->i_cmd * 0x0CCCCCCCD) >> 32)) >> 2) * 5;
switch( p_exs->i_cmd ) for( ; ; )
{
case 0:
if( ( p_exs->p_bordel[ 3 ] + p_exs->i_tmp ) <=
( p_exs->p_bordel[ 1 ] + p_exs->p_bordel[ 15 ] ) )
{
p_exs->p_bordel[ 3 ] += 1;
}
break;
case 3:
p_exs->p_bordel[ 5 ] >>= 2;
break;
case 4:
p_exs->p_bordel[ 10 ] -= 0x13;
break;
}
p_exs->i_cmd = ((p_exs->p_bordel[ 2 ] * 2) + 10) >> 1;
if( p_exs->p_bordel[ 2 ] & 1 )
{
if( p_exs->i_jc )
{ {
p_exs->i_jc--; TinyShuffle5( p_bordel );
p_exs->p_bordel[ 2 ] += 0x13;
p_exs->p_bordel[ 12 ] += 1;
BigShuffle2( p_exs );
return;
}
}
p_exs->i_cmd -= p_exs->p_bordel[ 2 ]; switch( ( p_bordel[ 2 ] * 2 + 15 ) % 5 )
p_exs->i_cmd -= (((uint32_t)(((uint64_t)p_exs->i_cmd * 0x0CCCCCCCD) >> 32)) >> 3) * 10;
switch( p_exs->i_cmd )
{ {
case 0: case 0:
for( i = 0; i < 5; i++ ) if( ( p_bordel[ 3 ] + i_tmp ) <=
{ ( p_bordel[ 1 ] + p_bordel[ 15 ] ) )
if( ( p_exs->p_bordel[ 1 ] & p_exs->p_bordel[ 2 ] ) >
( p_exs->p_bordel[ 7 ] & p_exs->p_bordel[ 12 ] ) )
{ {
p_exs->p_bordel[ 2 ] += 1; p_bordel[ 3 ] += 1;
p_exs->p_bordel[ 7 ] ^= p_exs->p_bordel[ 2 ];
} }
}
case 1:
p_exs->p_bordel[ 3 ] -= 1;
p_exs->p_bordel[ 4 ] |= 0x400000;
break;
case 2:
if( p_exs->p_bordel[ 13 ] >= p_exs->p_bordel[ 3 ] )
{
if( p_exs->i_jc )
{
p_exs->i_jc--;
p_exs->p_bordel[ 5 ] += 1;
p_exs->p_bordel[ 6 ] -= 1;
p_exs->p_bordel[ 7 ] += 1;
BigShuffle1( p_exs );
}
return;
}
else
{
p_exs->p_bordel[ 5 ] += 3;
}
break;
case 3:
p_exs->p_bordel[ 1 ] ^= (p_exs->p_bordel[ 5 ] + p_exs->p_bordel[ 15 ]);
break; break;
case 4: case 4:
p_exs->p_bordel[ 14 ] += 1; p_bordel[ 10 ] -= 0x13;
break;
case 5:
p_exs->p_bordel[ 2 ] &= 0x10076000;
break; break;
case 6: case 3:
p_exs->p_bordel[ 1 ] -= p_exs->p_bordel[ 5 ]; p_bordel[ 5 ] >>= 2;
/* no break */
case 7:
TinyShuffle1( p_exs->p_bordel );
break;
case 8:
p_exs->p_bordel[ 7 ] ^= ((p_exs->p_bordel[ 1 ] + p_exs->p_bordel[ 5 ]) - p_exs->p_bordel[ 8 ]);
break; break;
case 9:
if( (p_exs->p_bordel[ 1 ] ^ p_exs->p_bordel[ 10 ]) > 0x6000 )
{
p_exs->p_bordel[ 11 ] += 1;
} }
if( !( p_bordel[ 2 ] & 1 ) || i_jc == 0 )
{
break; break;
} }
i_jc--;
p_bordel[ 2 ] += 0x13;
p_bordel[ 12 ] += 1;
}
p_bordel[ 2 ] &= 0x10076000;
} }
static uint32_t ThirdPass( uint32_t * p_bordel ) static void ThirdPass( uint32_t * p_bordel )
{ {
uint32_t i_cmd, i_ret = 5; uint32_t i_cmd;
i_cmd = ((p_bordel[ 7 ] + p_bordel[ 14 ] + 10) >> 1) - p_bordel[ 14 ]; i_cmd = ((p_bordel[ 7 ] + p_bordel[ 14 ] + 10) >> 1) - p_bordel[ 14 ];
i_cmd -= (((uint32_t)(((uint64_t)i_cmd * 0x0CCCCCCCD) >> 32)) >> 3) * 10; i_cmd = i_cmd % 10;
switch( i_cmd ) switch( i_cmd )
{ {
...@@ -1321,16 +1125,16 @@ static uint32_t ThirdPass( uint32_t * p_bordel ) ...@@ -1321,16 +1125,16 @@ static uint32_t ThirdPass( uint32_t * p_bordel )
break; break;
case 6: case 6:
p_bordel[ i_cmd + 3 ] &= 0x5EDE36B; p_bordel[ i_cmd + 3 ] &= 0x5EDE36B;
p_bordel[ 5 ] += p_bordel[ 8 ];
p_bordel[ 4 ] += p_bordel[ 7 ];
p_bordel[ 3 ] += p_bordel[ 6 ];
p_bordel[ 2 ] += p_bordel[ 5 ];
/* no break */ /* no break */
case 2: case 2:
while( i_cmd ) p_bordel[ 1 ] += p_bordel[ 4 ];
{ p_bordel[ 0 ] += p_bordel[ 3 ];
i_cmd -= 1; TinyShuffle6( p_bordel );
p_bordel[ i_cmd ] += p_bordel[ i_cmd + 3 ]; return; /* jc = 4 */
}
i_ret--;
TinyShuffle2( p_bordel );
return i_ret;
case 3: case 3:
if( (p_bordel[ 11 ] & p_bordel[ 2 ]) > 0x211B ) if( (p_bordel[ 11 ] & p_bordel[ 2 ]) > 0x211B )
{ {
...@@ -1348,8 +1152,7 @@ static uint32_t ThirdPass( uint32_t * p_bordel ) ...@@ -1348,8 +1152,7 @@ static uint32_t ThirdPass( uint32_t * p_bordel )
break; break;
case 8: case 8:
p_bordel[ 0 ] -= p_bordel[ 11 ] & p_bordel[ 15 ]; p_bordel[ 0 ] -= p_bordel[ 11 ] & p_bordel[ 15 ];
i_ret--; return; /* jc = 4 */
return i_ret;
case 9: case 9:
p_bordel[ 6 ] >>= (p_bordel[ 14 ] & 3); p_bordel[ 6 ] >>= (p_bordel[ 14 ] & 3);
break; break;
...@@ -1357,29 +1160,18 @@ static uint32_t ThirdPass( uint32_t * p_bordel ) ...@@ -1357,29 +1160,18 @@ static uint32_t ThirdPass( uint32_t * p_bordel )
SWAP( p_bordel[ 0 ], p_bordel[ 10 ] ); SWAP( p_bordel[ 0 ], p_bordel[ 10 ] );
TinyShuffle2( p_bordel ); TinyShuffle6( p_bordel );
return i_ret; return; /* jc = 5 */
} }
static void FourthPass( uint32_t * p_bordel, uint32_t i_jc ) static void FourthPass( uint32_t * p_bordel )
{ {
uint32_t i, j; uint32_t i, j;
uint32_t i_cmd;
i = (((p_bordel[ 9 ] + p_bordel[ 15 ] + 12) >> 2) - p_bordel[ 4 ]) & 7; TinyShuffle7( p_bordel );
while( i-- ) switch( p_bordel[ 5 ] % 5)
{
SWAP( p_bordel[ i ], p_bordel[ i + 3 ] );
}
SWAP( p_bordel[ 10 ], p_bordel[ 1 ] );
i_cmd = p_bordel[ 5 ];
i_cmd -= (((uint32_t)(((uint64_t)i_cmd * 0x0CCCCCCCD) >> 32)) >> 2) * 5;
switch( i_cmd )
{ {
case 0: case 0:
p_bordel[ 0 ] += 1; p_bordel[ 0 ] += 1;
...@@ -1388,27 +1180,19 @@ static void FourthPass( uint32_t * p_bordel, uint32_t i_jc ) ...@@ -1388,27 +1180,19 @@ static void FourthPass( uint32_t * p_bordel, uint32_t i_jc )
p_bordel[ 11 ] ^= (p_bordel[ 3 ] + p_bordel[ 6 ] + p_bordel[ 8 ]); p_bordel[ 11 ] ^= (p_bordel[ 3 ] + p_bordel[ 6 ] + p_bordel[ 8 ]);
break; break;
case 3: case 3:
for( i = 4; i < 15; i++ ) for( i = 4; i < 15 && (p_bordel[ i ] & 5) == 0; i++ )
{
if( p_bordel[ i ] & 5 )
{ {
break;
}
SWAP( p_bordel[ i ], p_bordel[ 15 - i ] ); SWAP( p_bordel[ i ], p_bordel[ 15 - i ] );
} }
break; break;
case 4: case 4:
if( i_jc )
{
p_bordel[ 12 ] -= 1; p_bordel[ 12 ] -= 1;
p_bordel[ 13 ] += 1; p_bordel[ 13 ] += 1;
p_bordel[ 2 ] -= 0x64; p_bordel[ 2 ] -= 0x64;
p_bordel[ 3 ] += 0x64; p_bordel[ 3 ] += 0x64;
TinyShuffle8( p_bordel );
return; return;
} }
break;
}
for( i = 0, j = 0; i < 16; i++ ) for( i = 0, j = 0; i < 16; i++ )
{ {
...@@ -1418,108 +1202,256 @@ static void FourthPass( uint32_t * p_bordel, uint32_t i_jc ) ...@@ -1418,108 +1202,256 @@ static void FourthPass( uint32_t * p_bordel, uint32_t i_jc )
} }
} }
i_cmd = p_bordel[ j ]; switch( p_bordel[ j ] % 100 )
i_cmd -= (((uint32_t)(((uint64_t)i_cmd * 0x51EB851F) >> 32)) >> 5) * 0x64;
switch( i_cmd )
{ {
case 0x0: case 0:
SWAP( p_bordel[ j ], p_bordel[ 0 ] ); SWAP( p_bordel[ 0 ], p_bordel[ j ] );
break; break;
case 0x8: case 8:
p_bordel[ 1 ] >>= 1; p_bordel[ 1 ] >>= 1;
p_bordel[ 2 ] <<= 1; p_bordel[ 2 ] <<= 1;
p_bordel[ 14 ] >>= 3; p_bordel[ 14 ] >>= 3;
p_bordel[ 15 ] <<= 4; p_bordel[ 15 ] <<= 4;
break; break;
case 0x39: case 57:
p_bordel[ j ] += p_bordel[ 13 ]; p_bordel[ j ] += p_bordel[ 13 ];
break; break;
case 0x4c: case 76:
if( i_jc )
{
p_bordel[ 1 ] += 0x20E; p_bordel[ 1 ] += 0x20E;
p_bordel[ 5 ] += 0x223D; p_bordel[ 5 ] += 0x223D;
p_bordel[ 13 ] -= 0x576; p_bordel[ 13 ] -= 0x576;
p_bordel[ 15 ] += 0x576; p_bordel[ 15 ] += 0x576;
} return;
break; case 91:
case 0x5b:
p_bordel[ 2 ] -= 0x64; p_bordel[ 2 ] -= 0x64;
p_bordel[ 3 ] += 0x64; p_bordel[ 3 ] += 0x64;
p_bordel[ 12 ] -= 1; p_bordel[ 12 ] -= 1;
p_bordel[ 13 ] += 1; p_bordel[ 13 ] += 1;
break; break;
case 0x63: case 99:
p_bordel[ 0 ] += 1; p_bordel[ 0 ] += 1;
p_bordel[ j ] += p_bordel[ 13 ]; p_bordel[ j ] += p_bordel[ 13 ];
break; break;
} }
TinyShuffle8( p_bordel );
} }
static void FifthPass( uint32_t * p_bordel ) /*****************************************************************************
* TinyShuffle[12345678]: tiny shuffle subroutines
*****************************************************************************
* These standalone functions are little helpers for the shuffling process.
*****************************************************************************/
static void TinyShuffle1( uint32_t * p_bordel )
{
uint32_t i_cmd = (p_bordel[ 5 ] + 10) >> 2;
if( p_bordel[ 5 ] > 0x7D0 )
{
i_cmd -= 0x305;
}
switch( i_cmd & 3 )
{
case 0:
p_bordel[ 5 ] += 5;
break;
case 1:
p_bordel[ 4 ] -= 1;
break;
case 2:
if( p_bordel[ 4 ] & 5 )
{
p_bordel[ 1 ] ^= 0x4D;
}
/* no break */
case 3:
p_bordel[ 12 ] += 5;
break;
}
}
static void TinyShuffle2( uint32_t * p_bordel )
{
uint32_t i, j;
for( i = 0, j = 0; i < 16; i++ )
{
if( (p_bordel[ i ] & 0x777) > (p_bordel[ j ] & 0x777) )
{
j = i;
}
}
if( j > 5 )
{
for( ; j < 15; j++ )
{
p_bordel[ j ] += p_bordel[ j + 1 ];
}
}
else
{
p_bordel[ 2 ] &= 0xB62FC;
}
}
static void TinyShuffle3( uint32_t * p_bordel )
{
uint32_t i_cmd = p_bordel[ 6 ] + 0x194B;
if( p_bordel[ 6 ] > 0x2710 )
{
i_cmd >>= 1;
}
switch( i_cmd & 3 )
{
case 1:
p_bordel[ 3 ] += 0x19FE;
break;
case 2:
p_bordel[ 7 ] -= p_bordel[ 3 ] >> 2;
/* no break */
case 0:
p_bordel[ 5 ] ^= 0x248A;
break;
}
}
static void TinyShuffle4( uint32_t * p_bordel )
{
uint32_t i, j;
for( i = 0, j = 0; i < 16; i++ )
{
if( p_bordel[ i ] < p_bordel[ j ] )
{
j = i;
}
}
if( (p_bordel[ j ] % (j + 1)) > 10 )
{
p_bordel[ 1 ] -= 1;
p_bordel[ 2 ] += 0x13;
p_bordel[ 12 ] += 1;
}
}
static void TinyShuffle5( uint32_t * p_bordel )
{ {
uint32_t i; uint32_t i;
uint32_t i_cmd;
i = (p_bordel[ 0 ] & p_bordel[ 6 ]) & 0xF; p_bordel[ 2 ] &= 0x7F3F;
i_cmd = p_bordel[ i ]; for( i = 0; i < 5; i++ )
i_cmd -= ((((uint32_t)(((uint64_t)i_cmd * 0x10624DD3) >> 32)) >> 6) * 0x3E8); {
switch( ( p_bordel[ 2 ] + 10 + i ) % 5 )
{
case 0:
p_bordel[ 12 ] &= p_bordel[ 2 ];
/* no break */
case 1:
p_bordel[ 3 ] ^= p_bordel[ 15 ];
break;
case 2:
p_bordel[ 15 ] += 0x576;
/* no break */
case 3:
p_bordel[ 7 ] -= 0x2D;
/* no break */
case 4:
p_bordel[ 1 ] <<= 1;
break;
}
}
}
switch( i_cmd ) static void TinyShuffle6( uint32_t * p_bordel )
{
uint32_t i, j;
for( i = 0; i < 8; i++ )
{
j = p_bordel[ 3 ] & 0x7514 ? 5 : 7;
SWAP( p_bordel[ i ], p_bordel[ i + j ] );
}
}
static void TinyShuffle7( uint32_t * p_bordel )
{
uint32_t i;
i = (((p_bordel[ 9 ] + p_bordel[ 15 ] + 12) >> 2) - p_bordel[ 4 ]) & 7;
while( i-- )
{
SWAP( p_bordel[ i ], p_bordel[ i + 3 ] );
}
SWAP( p_bordel[ 1 ], p_bordel[ 10 ] );
}
static void TinyShuffle8( uint32_t * p_bordel )
{
uint32_t i;
i = (p_bordel[ 0 ] & p_bordel[ 6 ]) & 0xF;
switch( p_bordel[ i ] % 1000 )
{ {
case 0x7: case 7:
if( (p_bordel[ i ] & 0x777) > (p_bordel[ 7 ] & 0x5555) ) if( (p_bordel[ i ] & 0x777) > (p_bordel[ 7 ] & 0x5555) )
{ {
p_bordel[ i ] ^= p_bordel[ 5 ] & p_bordel[ 3 ]; p_bordel[ i ] ^= p_bordel[ 5 ] & p_bordel[ 3 ];
} }
break; break;
case 0x13: case 19:
p_bordel[ 15 ] &= 0x5555; p_bordel[ 15 ] &= 0x5555;
break; break;
case 0x5d: case 93:
p_bordel[ i ] ^= p_bordel[ 15 ]; p_bordel[ i ] ^= p_bordel[ 15 ];
break; break;
case 0x64: case 100:
SWAP( p_bordel[ 0 ], p_bordel[ 1 ] ); SWAP( p_bordel[ 0 ], p_bordel[ 3 ] );
SWAP( p_bordel[ 1 ], p_bordel[ 7 ] ); SWAP( p_bordel[ 1 ], p_bordel[ 6 ] );
SWAP( p_bordel[ 3 ], p_bordel[ 6 ] );
SWAP( p_bordel[ 4 ], p_bordel[ 9 ] ); SWAP( p_bordel[ 4 ], p_bordel[ 9 ] );
SWAP( p_bordel[ 8 ], p_bordel[ 5 ] ); SWAP( p_bordel[ 5 ], p_bordel[ 8 ] );
SWAP( p_bordel[ 6 ], p_bordel[ 1 ] ); SWAP( p_bordel[ 6 ], p_bordel[ 7 ] );
SWAP( p_bordel[ 3 ], p_bordel[ 0 ] );
SWAP( p_bordel[ 13 ], p_bordel[ 14 ] ); SWAP( p_bordel[ 13 ], p_bordel[ 14 ] );
break; break;
case 0x149: case 329:
p_bordel[ i ] += p_bordel[ 1 ] ^ 0x80080011; p_bordel[ i ] += p_bordel[ 1 ] ^ 0x80080011;
p_bordel[ i ] += p_bordel[ 2 ] ^ 0xBEEFDEAD; p_bordel[ i ] += p_bordel[ 2 ] ^ 0xBEEFDEAD;
p_bordel[ i ] += p_bordel[ 3 ] ^ 0x8765F444; p_bordel[ i ] += p_bordel[ 3 ] ^ 0x8765F444;
p_bordel[ i ] += p_bordel[ 4 ] ^ 0x78145326; p_bordel[ i ] += p_bordel[ 4 ] ^ 0x78145326;
break; break;
case 0x237: case 567:
p_bordel[ 12 ] -= p_bordel[ i ]; p_bordel[ 12 ] -= p_bordel[ i ];
p_bordel[ 13 ] += p_bordel[ i ]; p_bordel[ 13 ] += p_bordel[ i ];
break; break;
case 0x264: case 612:
p_bordel[ i ] += p_bordel[ 1 ]; p_bordel[ i ] += p_bordel[ 1 ];
p_bordel[ i ] -= p_bordel[ 7 ]; p_bordel[ i ] -= p_bordel[ 7 ];
p_bordel[ i ] -= p_bordel[ 8 ]; p_bordel[ i ] -= p_bordel[ 8 ];
p_bordel[ i ] += p_bordel[ 9 ]; p_bordel[ i ] += p_bordel[ 9 ];
p_bordel[ i ] += p_bordel[ 13 ]; p_bordel[ i ] += p_bordel[ 13 ];
break; break;
case 0x2f2: case 754:
i = __MIN( i, 12 ); i = __MIN( i, 12 );
p_bordel[ i + 1 ] >>= 1; p_bordel[ i + 1 ] >>= 1;
p_bordel[ i + 2 ] <<= 4; p_bordel[ i + 2 ] <<= 4;
p_bordel[ i + 3 ] >>= 3; p_bordel[ i + 3 ] >>= 3;
break; break;
case 0x309: case 777:
p_bordel[ 1 ] += 0x20E; p_bordel[ 1 ] += 0x20E;
p_bordel[ 5 ] += 0x223D; p_bordel[ 5 ] += 0x223D;
p_bordel[ 13 ] -= 0x576; p_bordel[ 13 ] -= 0x576;
p_bordel[ 15 ] += 0x576; p_bordel[ 15 ] += 0x576;
break; break;
case 0x3d5: case 981:
if( (p_bordel[ i ] ^ 0x8765F441) < 0x2710 ) if( (p_bordel[ i ] ^ 0x8765F441) < 0x2710 )
{ {
SWAP( p_bordel[ 0 ], p_bordel[ 1 ] ); SWAP( p_bordel[ 0 ], p_bordel[ 1 ] );
...@@ -1532,47 +1464,6 @@ static void FifthPass( uint32_t * p_bordel ) ...@@ -1532,47 +1464,6 @@ static void FifthPass( uint32_t * p_bordel )
} }
} }
static void TinyShuffle1( uint32_t * p_bordel )
{
uint32_t i;
for( i = 0; i < 3; i++ )
{
switch( p_bordel[ 1 ] & 3 )
{
case 0:
p_bordel[ 1 ] += 1;
/* no break */
case 1:
p_bordel[ 3 ] -= 8;
break;
case 2:
p_bordel[ 13 ] &= 0xFEFEFEF7;
break;
case 3:
p_bordel[ 8 ] |= 0x80080011;
break;
}
}
}
static void TinyShuffle2( uint32_t * p_bordel )
{
uint32_t i;
for( i = 0; i < 8; i++ )
{
if( p_bordel[ 3 ] & 0x7514 )
{
SWAP( p_bordel[ i ], p_bordel[ i + 5 ] );
}
else
{
SWAP( p_bordel[ i ], p_bordel[ i + 7 ] );
}
}
}
/***************************************************************************** /*****************************************************************************
* GetSystemKey: get the system key * GetSystemKey: get the system key
***************************************************************************** *****************************************************************************
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment