vendor/libmcrypt/libmcrypt-2.5.8/modules/algorithms/tripledes.c
static void spinit(TRIPLEDES_KEY * key, int pos)
{
	char pbox[32];
	int p, i, s, j, rowcol;
	word32 val;

	/* Compute pbox, the inverse of p32i.
	 * This is easier to work with
	 */
	for (p = 0; p < 32; p++) {
		for (i = 0; i < 32; i++) {
			if (p32i[i] - 1 == p) {
				pbox[p] = i;
				break;
			}
		}
	}
	for (s = 0; s < 8; s++) {	/* For each S-box */
		for (i = 0; i < 64; i++) {	/* For each possible input */
			val = 0;
			/* The row number is formed from the first and last
			 * bits; the column number is from the middle 4
			 */
			rowcol =
			    (i & 32) | ((i & 1) ? 16 : 0) | ((i >> 1) &
							     0xf);
			for (j = 0; j < 4; j++) {	/* For each output bit */
				if (si[s][rowcol] & (8 >> j)) {
					val |=
					    1L << (31 - pbox[4 * s + j]);
				}
			}
			key->sp[pos][s][i] = val;

#ifdef	DEBUG
			printf("sp[%d][%2d] = %08lx\n", s, i,
			       sp[pos][s][i]);
#endif
		}
	}
}
/* Initialize the lookup table for the combined S and P boxes */
Initialize the lookup table for the combined S and P boxes
Initialize the lookup table for the combined S and P boxes
static void spinit(TRIPLEDES_KEY * key, int pos)
{
	char pbox[32];
	int p, i, s, j, rowcol;
	word32 val;
	for (p = 0; p < 32; p++) {
		for (i = 0; i < 32; i++) {
			if (p32i[i] - 1 == p) {
				pbox[p] = i;
				break;
			}
		}
	}
	for (s = 0; s < 8; s++) {	
		for (i = 0; i < 64; i++) {	
			val = 0;
			rowcol =
			    (i & 32) | ((i & 1) ? 16 : 0) | ((i >> 1) &
							     0xf);
			for (j = 0; j < 4; j++) {	
				if (si[s][rowcol] & (8 >> j)) {
					val |=
					    1L << (31 - pbox[4 * s + j]);
				}
			}
			key->sp[pos][s][i] = val;
#ifdef	DEBUG
			printf("sp[%d][%2d] = %08lx\n", s, i,
			       sp[pos][s][i]);
#endif
		}
	}
}
static void spinit ( TRIPLEDES_KEY * key , int pos ) { char pbox [ 32 ] ; int p , i , s , j , rowcol ; word32 val ; for ( p = 0 ; p < 32 ; p ++ ) { for ( i = 0 ; i < 32 ; i ++ ) { if ( p32i [ i ] - 1 == p ) { pbox [ p ] = i ; break ; } } } for ( s = 0 ; s < 8 ; s ++ ) { for ( i = 0 ; i < 64 ; i ++ ) { val = 0 ; rowcol = ( i & 32 ) | ( ( i & 1 ) ? 16 : 0 ) | ( ( i >> 1 ) & 0xf ) ; for ( j = 0 ; j < 4 ; j ++ ) { if ( si [ s ] [ rowcol ] & ( 8 >> j ) ) { val |= 1L << ( 31 - pbox [ 4 * s + j ] ) ; } } key -> sp [ pos ] [ s ] [ i ] = val ; #ifdef DEBUG printf ( " \n " , s , i , sp [ pos ] [ s ] [ i ] ) ; #endif } } }
Initialize the lookup table for the combined S and P boxes
Initialize the lookup table for the combined S and P boxes
/* Compute pbox, the inverse of p32i.
	 * This is easier to work with
	 */ /* For each S-box */ /* For each possible input */ /* The row number is formed from the first and last
			 * bits; the column number is from the middle 4
			 */ /* For each output bit */