amd64-linux-port-20030428
[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 RCSID("$Header$");
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_S_TABLE
20 #include "tables.h"
21
22 char temp[8][64];
23 int des_debug;
24
25 void gen(FILE *stream)
26 {
27     register 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                 {
67                     fprintf(stream,"\n}");
68                 }
69                 if ((k++ != 63) || (i !=7)) {
70                     fprintf(stream,", ");
71                 }
72             }
73         }
74     }
75
76     fprintf(stream,"\n};\n");
77 }