death to register
[openafs.git] / src / des / make_s_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 #include <afsconfig.h>
9 #include <afs/param.h>
10
11
12 #include "mit-cpyright.h"
13 #include <stdio.h>
14 #include "des.h"
15 #include "des_internal.h"
16 #include "des_prototypes.h"
17
18 #define WANT_S_TABLE
19 #include "tables.h"
20
21 char temp[8][64];
22 int des_debug;
23
24 void
25 gen(FILE * stream)
26 {
27     afs_uint32 i, j, k, l, m, n;
28
29     /* rearrange the S table entries, and adjust for host bit order */
30
31     fprintf(stream, "static unsigned char const S_adj[8][64] = {");
32     fprintf(stream, "    /* adjusted */\n");
33
34     for (i = 0; i <= 7; i++) {
35         for (j = 0; j <= 63; j++) {
36             /*
37              * figure out which one to put in the new S[i][j]
38              *
39              * start by assuming the value of the input bits is "j" in
40              * host order, then figure out what it means in standard
41              * form.
42              */
43             k = swap_six_bits_to_ansi(j);
44             /* figure out the index for k */
45             l = (((k >> 5) & 01) << 5)
46                 + ((k & 01) << 4) + ((k >> 1) & 0xf);
47             m = S[i][l];
48             /* restore in host order */
49             n = swap_four_bits_to_ansi(m);
50             if (des_debug)
51                 fprintf(stderr,
52                         "i = %ld, j = %ld, k = %ld, l = %ld, m = %ld, n = %ld\n",
53                         (long)i, (long)j, (long)k, (long)l, (long)m, (long)n);
54             temp[i][j] = n;
55         }
56     }
57
58     for (i = 0; i <= 7; i++) {
59         fprintf(stream, "\n{ ");
60         k = 0;
61         for (j = 0; j <= 3; j++) {
62             fprintf(stream, "\n");
63             for (m = 0; m <= 15; m++) {
64                 fprintf(stream, "%2d", temp[i][k]);
65                 if (k == 63) {
66                     fprintf(stream, "\n}");
67                 }
68                 if ((k++ != 63) || (i != 7)) {
69                     fprintf(stream, ", ");
70                 }
71             }
72         }
73     }
74
75     fprintf(stream, "\n};\n");
76 }