parisc-linux-initial-support-20011008
[openafs.git] / src / des / make_p_table.c
1 /*
2  * Copyright 1985, 1988 by the Massachusetts Institute of Technology.
3  *
4  * For copying and distribution information, please
5  * see the file <mit-cpyright.h>.
6  *
7  */
8
9 #include <afsconfig.h>
10 #include <afs/param.h>
11
12 RCSID("$Header$");
13
14 #include <mit-cpyright.h>
15 #include <stdio.h>
16 #include "des_internal.h"
17
18 #define WANT_P_TABLE
19 #include "tables.h"
20
21 extern afs_uint32 swap_byte_bits();
22 extern afs_uint32 rev_swap_bit_pos_0();
23 static unsigned char P_temp[32];
24 static afs_uint32 P_prime[4][256];
25
26 void gen(stream)
27     FILE *stream;
28 {
29     register int i,j,k,m;
30     /* P permutes 32 bit input R1 into 32 bit output R2 */
31
32 #ifdef BIG
33     /* flip p into p_temp */
34     for (i = 0; i<32; i++)
35         P_temp[(int) P[rev_swap_bit_pos_0(i)]] = rev_swap_bit_pos_0(i);
36
37     /*
38      * now for each byte of input, figure out all possible combinations
39      */
40     for (i = 0; i <4 ; i ++) {  /* each input byte */
41         for (j = 0; j<256; j++) { /* each possible byte value */
42             /* flip bit order */
43             k = j;
44             /* swap_byte_bits(j); */
45             for (m = 0; m < 8; m++) { /* each bit */
46                 if (k & (1 << m)) {
47                     /* set output values */
48                     P_prime[i][j] |= 1 << P_temp[(i*8)+m];
49                 }
50             }
51         }
52     }
53
54     fprintf(stream,
55             "\n\tstatic afs_uint32 const P_prime[4][256] = {\n\t");
56     for (i = 0; i < 4; i++) {
57         fprintf(stream,"\n{ ");
58         for (j = 0; j < 64; j++) {
59             fprintf(stream,"\n");
60             for (k = 0; k < 4; k++) {
61                 fprintf(stream,"0x%08lX",P_prime[i][j*4+k]);
62                 if ((j == 63) && (k == 3))
63                     fprintf(stream, "}");
64                 if ((i == 3) && (j == 63) && (k == 3))
65                     fprintf(stream,"\n};");
66                 else
67                     fprintf(stream,", ");
68             }
69         }
70     }
71
72 #endif
73     fprintf(stream,"\n");
74 }