2 * Copyright 1988 by the Massachusetts Institute of Technology.
4 * For copying and distribution information,
5 * please seethe file <mit-cpyright.h>.
7 * This file contains most of the routines needed by the various
8 * make_foo programs, to account for bit- and byte-ordering on
9 * different machine types. It also contains other routines useful in
10 * generating the intermediate source files.
13 #include <afsconfig.h>
14 #include <afs/param.h>
18 #include <mit-cpyright.h>
20 #include "des_internal.h"
25 * The DES algorithm is defined in terms of MSBFIRST, so sometimes,
26 * e.g. VAXes, we need to fix it up. ANSI order means the DES
30 #if 0 /* These don't seem to get used anywhere.... */
38 register int old,new,i,j;
40 /* for an eight byte block-- */
41 /* flips the bit order within each byte from 0 lsb to 0 msb */
42 for (i = 0; i<=7; i++) {
45 for (j = 0; j<=7; j++) {
46 new |= old & 01; /* copy a bit */
48 /* rotate in opposite directions */
58 afs_uint32 long_swap_bits(x)
64 char *array = (char *) &x;
65 register int old,new,i,j;
67 /* flips the bit order within each byte from 0 lsb to 0 msb */
68 for (i = 0; i <= (sizeof(afs_int32)-1); i++) {
71 for (j = 0; j<=7; j++) {
86 afs_uint32 swap_six_bits_to_ansi(old)
89 register afs_uint32 new, j;
91 /* flips the bit order within each byte from 0 lsb to 0 msb */
93 for (j = 0; j<=5; j++) {
94 new |= old & 01; /* copy a bit */
96 /* rotate in opposite directions */
104 afs_uint32 swap_four_bits_to_ansi(old)
107 register afs_uint32 new,j;
109 /* flips the bit order within each byte from 0 lsb to 0 msb */
111 for (j = 0; j<=3; j++) {
112 new |= (old & 01); /* copy a bit */
121 afs_uint32 swap_bit_pos_1(x)
125 * This corrects for the bit ordering of the algorithm, e.g.
126 * bit 0 ==> msb, bit 7 lsb.
128 * given the number of a bit position, >=1, flips the bit order
129 * each byte. e.g. bit 3 --> bit 6, bit 13 --> bit 12
133 /* always do it, only used by des_make_key_perm.c so far */
142 afs_uint32 swap_bit_pos_0(x)
145 /* zero based version */
148 * This corrects for the bit ordering of the algorithm, e.g.
149 * bit 0 ==> msb, bit 7 lsb.
158 * given the number of a bit position, >=0, flips the bit order
159 * each byte. e.g. bit 3 --> bit 6, bit 13 --> bit 12
167 #endif /* LSBFIRST */
170 afs_uint32 swap_bit_pos_0_to_ansi(x)
173 /* zero based version */
176 * This corrects for the bit ordering of the algorithm, e.g.
177 * bit 0 ==> msb, bit 7 lsb.
182 * given the number of a bit position, >=0, flips the bit order each
183 * byte. e.g. bit 3 --> bit 6, bit 13 --> bit 12
193 afs_uint32 rev_swap_bit_pos_0(x)
196 /* zero based version */
199 * This corrects for the bit ordering of the algorithm, e.g.
200 * bit 0 ==> msb, bit 7 lsb.
202 * Role of LSB and MSB flipped from the swap_bit_pos_0()
212 * given the number of a bit position, >=0, flips the bit order each
213 * byte. e.g. bit 3 --> bit 6, bit 13 --> bit 12
221 #endif /* MSBFIRST */
224 afs_uint32 swap_byte_bits(x)
231 char *array = (char *) &x;
232 register afs_uint32 old,new,j;
234 /* flips the bit order within each byte from 0 lsb to 0 msb */
237 for (j = 0; j<=7; j++) {
238 new |= (old & 01); /* copy a bit */
245 #endif /* LSBFIRST */
248 int swap_long_bytes_bit_number(x)
252 * given a bit number (0-31) from a vax, swap the byte part of the
253 * bit number to change the byte ordering to mSBFIRST type
260 y = x/8; /* initial byte component */
261 z = x%8; /* bit within byte */
265 #endif /* MSBFIRST */
268 void test_set(stream, src, testbit, dest, setbit)
275 #ifdef DES_SHIFT_SHIFT
276 if (testbit == setbit)
277 fprintf(stream, " %s |= %s & (1<<%2d);\n",
280 fprintf(stream, " %s |= (%s & (1<<%2d)) %s %2d;\n",
282 (testbit < setbit) ? "<<" : ">>",
283 abs(testbit - setbit));
286 " if (%s & (1<<%2d)) %s |= 1<<%2d;\n",
287 src, testbit, dest, setbit);