pull-prototypes-to-head-20020821
[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("$Header$");
15
16 #include <mit-cpyright.h>
17 #include <stdio.h>
18 #include <stdlib.h>
19 #include <des.h>
20 #include "des_internal.h"
21
22 #define WANT_IP_TABLE
23 #include "tables.h"
24
25 #include "des_prototypes.h"
26
27 #define SWAP(x) swap_long_bytes_bit_number(swap_bit_pos_0_to_ansi(x))
28
29 void gen(FILE *stream)
30 {
31     register int i;
32
33     /* clear the output */
34     fprintf(stream,"    L2 = 0; R2 = 0;\n");
35
36     /* first setup IP */
37     fprintf(stream,"/* IP operations */\n/* first left to left */\n");
38
39     /* first list mapping from left to left */
40     for (i = 0; i <= 31; i++)
41         if (IP[i] < 32)
42             test_set(stream, "L1", SWAP(IP[i]), "L2", i);
43
44     /* now mapping from right to left */
45     fprintf(stream,"\n/* now from right to left */\n");
46     for (i = 0; i <= 31; i++)
47         if (IP[i] >= 32)
48             test_set(stream, "R1", SWAP(IP[i]-32), "L2", i);
49
50     fprintf(stream,"\n/* now from left to right */\n");
51     /*  list mapping from left to right */
52     for (i = 32; i <= 63; i++)
53         if (IP[i] <32)
54             test_set(stream, "L1", SWAP(IP[i]), "R2", i-32);
55
56     /* now mapping from right to right */
57     fprintf(stream,"\n/* last from right to right */\n");
58     for (i = 32; i <= 63; i++)
59         if (IP[i] >= 32)
60             test_set(stream, "R1", SWAP(IP[i]-32), "R2", i-32);
61     exit(0);
62 }