warning-cleanup-20010414
[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 <mit-cpyright.h>
10 #include <stdio.h>
11 #include "des_internal.h"
12
13 #define WANT_P_TABLE
14 #include "tables.h"
15
16 extern afs_uint32 swap_byte_bits();
17 extern afs_uint32 rev_swap_bit_pos_0();
18 static unsigned char P_temp[32];
19 static afs_uint32 P_prime[4][256];
20
21 void gen(stream)
22     FILE *stream;
23 {
24     register int i,j,k,m;
25     /* P permutes 32 bit input R1 into 32 bit output R2 */
26
27 #ifdef BIG
28     /* flip p into p_temp */
29     for (i = 0; i<32; i++)
30         P_temp[(int) P[rev_swap_bit_pos_0(i)]] = rev_swap_bit_pos_0(i);
31
32     /*
33      * now for each byte of input, figure out all possible combinations
34      */
35     for (i = 0; i <4 ; i ++) {  /* each input byte */
36         for (j = 0; j<256; j++) { /* each possible byte value */
37             /* flip bit order */
38             k = j;
39             /* swap_byte_bits(j); */
40             for (m = 0; m < 8; m++) { /* each bit */
41                 if (k & (1 << m)) {
42                     /* set output values */
43                     P_prime[i][j] |= 1 << P_temp[(i*8)+m];
44                 }
45             }
46         }
47     }
48
49     fprintf(stream,
50             "\n\tstatic afs_uint32 const P_prime[4][256] = {\n\t");
51     for (i = 0; i < 4; i++) {
52         fprintf(stream,"\n{ ");
53         for (j = 0; j < 64; j++) {
54             fprintf(stream,"\n");
55             for (k = 0; k < 4; k++) {
56                 fprintf(stream,"0x%08X",P_prime[i][j*4+k]);
57                 if ((j == 63) && (k == 3))
58                     fprintf(stream, "}");
59                 if ((i == 3) && (j == 63) && (k == 3))
60                     fprintf(stream,"\n};");
61                 else
62                     fprintf(stream,", ");
63             }
64         }
65     }
66
67 #endif
68     fprintf(stream,"\n");
69 }