* $Source: /mit/kerberos/src/lib/des/RCS/misc.c,v $
* Copyright 1988 by the Massachusetts Institute of Technology.
* For copying and distribution information,
* please seethe file <mit-copyright.h>.
* This file contains most of the routines needed by the various
* make_foo programs, to account for bit- and byte-ordering on
* different machine types. It also contains other routines useful in
* generating the intermediate source files.
#include <mit-copyright.h>
#include "des_internal.h"
* The DES algorithm is defined in terms of MSBFIRST, so sometimes,
* e.g. VAXes, we need to fix it up. ANSI order means the DES
#if 0 /* These don't seem to get used anywhere.... */
/* for an eight byte block-- */
/* flips the bit order within each byte from 0 lsb to 0 msb */
new |= old
& 01; /* copy a bit */
/* rotate in opposite directions */
unsigned long long_swap_bits(x
)
char *array
= (char *) &x
;
/* flips the bit order within each byte from 0 lsb to 0 msb */
for (i
= 0; i
<= (sizeof(long)-1); i
++) {
unsigned long swap_six_bits_to_ansi(old
)
register unsigned long new, j
;
/* flips the bit order within each byte from 0 lsb to 0 msb */
new |= old
& 01; /* copy a bit */
/* rotate in opposite directions */
unsigned long swap_four_bits_to_ansi(old
)
register unsigned long new,j
;
/* flips the bit order within each byte from 0 lsb to 0 msb */
new |= (old
& 01); /* copy a bit */
unsigned long swap_bit_pos_1(x
)
* This corrects for the bit ordering of the algorithm, e.g.
* bit 0 ==> msb, bit 7 lsb.
* given the number of a bit position, >=1, flips the bit order
* each byte. e.g. bit 3 --> bit 6, bit 13 --> bit 12
/* always do it, only used by des_make_key_perm.c so far */
unsigned long swap_bit_pos_0(x
)
* This corrects for the bit ordering of the algorithm, e.g.
* bit 0 ==> msb, bit 7 lsb.
* given the number of a bit position, >=0, flips the bit order
* each byte. e.g. bit 3 --> bit 6, bit 13 --> bit 12
unsigned long swap_bit_pos_0_to_ansi(x
)
* This corrects for the bit ordering of the algorithm, e.g.
* bit 0 ==> msb, bit 7 lsb.
* given the number of a bit position, >=0, flips the bit order each
* byte. e.g. bit 3 --> bit 6, bit 13 --> bit 12
unsigned long rev_swap_bit_pos_0(x
)
* This corrects for the bit ordering of the algorithm, e.g.
* bit 0 ==> msb, bit 7 lsb.
* Role of LSB and MSB flipped from the swap_bit_pos_0()
* given the number of a bit position, >=0, flips the bit order each
* byte. e.g. bit 3 --> bit 6, bit 13 --> bit 12
unsigned long swap_byte_bits(x
)
char *array
= (char *) &x
;
register unsigned long old
,new,j
;
/* flips the bit order within each byte from 0 lsb to 0 msb */
new |= (old
& 01); /* copy a bit */
swap_long_bytes_bit_number(x
)
* given a bit number (0-31) from a vax, swap the byte part of the
* bit number to change the byte ordering to mSBFIRST type
y
= x
/8; /* initial byte component */
z
= x
%8; /* bit within byte */
void test_set(stream
, src
, testbit
, dest
, setbit
)
fprintf(stream
, " %s |= %s & (1<<%2d);\n",
fprintf(stream
, " %s |= (%s & (1<<%2d)) %s %2d;\n",
(testbit
< setbit
) ? "<<" : ">>",
" if (%s & (1<<%2d)) %s |= 1<<%2d;\n",
src
, testbit
, dest
, setbit
);
extern void gen
PROTOTYPE((FILE * stream
));
while (argc
--, *++argv
) {
if (!strcmp(arg
, "-d") && !strcmp(arg
, "-debug"))
fprintf(stderr
, "%s: unknown control argument %s\n",
"%s: multiple file names provided: %s, %s\n",
fprintf(stderr
, "%s: no file name provided\n", whoami
);
stream
= fopen(filename
, "w");
fprintf(stderr
, "usage: %s [-debug] filename\n", whoami
);
"/* This file is automatically generated. Do not edit it. */\n",
/* This routine will generate the contents of the file. */
if (fclose(stream
) == EOF
) {