crypt-take-voids-20041005
[openafs.git] / src / des / make_p.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  * This routine generates the P permutation code for the DES.
8  */
9
10 #include <afsconfig.h>
11 #include <afs/param.h>
12
13 RCSID
14     ("$Header$");
15
16 #include <mit-cpyright.h>
17 #include <stdio.h>
18 #include <des.h>
19 #include "des_internal.h"
20 #include "tables.h"
21 #include "des_prototypes.h"
22
23 void
24 gen(FILE * stream)
25 {
26     /* P permutes 32 bit input R1 into 32 bit output R2 */
27
28     /* clear the output */
29     fprintf(stream, "    L2 = 0;\n");
30 #ifndef BIG
31     fprintf(stream, "    R2 = 0;\n");
32     fprintf(stream, "/* P operations */\n/* from right to right */\n");
33     /* first list mapping from left to left */
34     for (i = 0; i <= 31; i++)
35         if (P[i] < 32)
36             fprintf(stream, "    if (R1 & (1<<%d)) R2 |= 1<<%d;\n", P[i], i);
37 #else /* BIG */
38     /* flip p into p_temp */
39     fprintf(stream, "    P_temp = R1;\n");
40     fprintf(stream, "    P_temp_p = (unsigned char *) &P_temp;\n");
41
42 #ifdef  LSBFIRST
43     fprintf(stream, "    R2 = P_prime[0][*P_temp_p++];\n");
44     fprintf(stream, "    R2 |= P_prime[1][*P_temp_p++];\n");
45     fprintf(stream, "    R2 |= P_prime[2][*P_temp_p++];\n");
46     fprintf(stream, "    R2 |= P_prime[3][*P_temp_p];\n");
47 #else /* MSBFIRST */
48     fprintf(stream, "    R2 = P_prime[3][*P_temp_p++];\n");
49     fprintf(stream, "    R2 |= P_prime[2][*P_temp_p++];\n");
50     fprintf(stream, "    R2 |= P_prime[1][*P_temp_p++];\n");
51     fprintf(stream, "    R2 |= P_prime[0][*P_temp_p];\n");
52 #endif /* MSBFIRST */
53 #endif /* BIG */
54 }