summaryrefslogtreecommitdiffstats
path: root/src/lib/crypto/des/make_pt.c
blob: 27fd5af262266f212cdb03845189aeedc101a9dd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
 * $Source$
 * $Author$
 *
 * Copyright 1985, 1988, 1990 by the Massachusetts Institute of Technology.
 *
 * For copying and distribution information, please see the file
 * <krb5/copyright.h>.
 *
 */

#include <krb5/copyright.h>
#include <krb5/krb5.h>
#include <stdio.h>
#include "des_int.h"
#include "tables.h"

static unsigned char P_temp[32];
static unsigned long P_prime[4][256];

void gen(stream)
    FILE *stream;
{
    register i,j,k,m;
    /* P permutes 32 bit input R1 into 32 bit output R2 */

#ifdef BIG
    /* flip p into p_temp */
    for (i = 0; i<32; i++)
	P_temp[P[rev_swap_bit_pos_0(i)]] = rev_swap_bit_pos_0(i);

    /*
     * now for each byte of input, figure out all possible combinations
     */
    for (i = 0; i <4 ; i ++) {	/* each input byte */
	for (j = 0; j<256; j++) { /* each possible byte value */
	    /* flip bit order */
	    k = j;
	    /* swap_byte_bits(j); */
	    for (m = 0; m < 8; m++) { /* each bit */
		if (k & (1 << m)) {
		    /* set output values */
		    P_prime[i][j] |= 1 << P_temp[(i*8)+m];
		}
	    }
	}
    }

    fprintf(stream,
	    "\n\tstatic unsigned long const P_prime[4][256] = {\n\t");
    for (i = 0; i < 4; i++) {
	fprintf(stream,"\n");
	for (j = 0; j < 64; j++) {
	    fprintf(stream,"\n");
	    for (k = 0; k < 4; k++) {
		fprintf(stream,"0x%08X",P_prime[i][j*4+k]);
		if ((i == 3) && (j == 63) && (k == 3))
		    fprintf(stream,"\n};");
		else
		    fprintf(stream,", ");
	    }
	}
    }

#endif
    fprintf(stream,"\n");
}