3b9624c1568335054fc1b9114bb2d7e22885af88
[openafs.git] / src / des / make_ip.c
1 /*
2  * Copyright 1987, 1988 by the Massachusetts Institute of Technology.
3  *
4  * For copying and distribution information, please see the file
5  * <mit-cpyright.h>.
6  *
7  * This routine generates source code implementing the initial
8  * permutation of the DES.
9  */
10
11 #include <afsconfig.h>
12 #include <afs/param.h>
13
14 RCSID
15     ("$Header$");
16
17 #include <mit-cpyright.h>
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include <des.h>
21 #include "des_internal.h"
22
23 #define WANT_IP_TABLE
24 #include "tables.h"
25
26 #include "des_prototypes.h"
27
28 #define SWAP(x) swap_long_bytes_bit_number(swap_bit_pos_0_to_ansi(x))
29
30 void
31 gen(FILE * stream)
32 {
33     register int i;
34 #ifdef AFS_DARWIN80_ENV
35     int j;
36
37 #define swap_long_bytes_bit_number _darwin_swap_long_bytes_bit_number
38 #endif /* AFS_DARWIN80_ENV */
39
40     /* clear the output */
41     fprintf(stream, "    L2 = 0; R2 = 0;\n");
42
43 #ifdef AFS_DARWIN80_ENV
44   for(j = 0;; j++) {
45     fprintf(stream, _darwin_whichstr[j]);
46     if (j == 2)
47         break;
48 #endif /* AFS_DARWIN80_ENV */
49     /* first setup IP */
50     fprintf(stream, "/* IP operations */\n/* first left to left */\n");
51
52     /* first list mapping from left to left */
53     for (i = 0; i <= 31; i++)
54         if (IP[i] < 32)
55             test_set(stream, "L1", SWAP(IP[i]), "L2", i);
56
57     /* now mapping from right to left */
58     fprintf(stream, "\n/* now from right to left */\n");
59     for (i = 0; i <= 31; i++)
60         if (IP[i] >= 32)
61             test_set(stream, "R1", SWAP(IP[i] - 32), "L2", i);
62
63     fprintf(stream, "\n/* now from left to right */\n");
64     /*  list mapping from left to right */
65     for (i = 32; i <= 63; i++)
66         if (IP[i] < 32)
67             test_set(stream, "L1", SWAP(IP[i]), "R2", i - 32);
68
69     /* now mapping from right to right */
70     fprintf(stream, "\n/* last from right to right */\n");
71     for (i = 32; i <= 63; i++)
72         if (IP[i] >= 32)
73             test_set(stream, "R1", SWAP(IP[i] - 32), "R2", i - 32);
74 #ifdef AFS_DARWIN80_ENV
75     _darwin_which = !_darwin_which;
76   }
77 #endif /* AFS_DARWIN80_ENV */
78     exit(0);
79 }