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