BSD 4_4 development
authorCSRG <csrg@ucbvax.Berkeley.EDU>
Thu, 14 Feb 1991 11:50:15 +0000 (03:50 -0800)
committerCSRG <csrg@ucbvax.Berkeley.EDU>
Thu, 14 Feb 1991 11:50:15 +0000 (03:50 -0800)
Work on file usr/src/kerberosIV/make_odd/make_odd.c

Synthesized-from: CSRG/cd3/4.4

usr/src/kerberosIV/make_odd/make_odd.c [new file with mode: 0644]

diff --git a/usr/src/kerberosIV/make_odd/make_odd.c b/usr/src/kerberosIV/make_odd/make_odd.c
new file mode 100644 (file)
index 0000000..91100e9
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * $Source: /usr/src/kerberosIV/make_odd/RCS/make_odd.c,v $
+ * $Author: bostic $
+ *
+ * Copyright 1988 by the Massachusetts Institute of Technology.
+ *
+ * For copying and distribution information, please see
+ * the file <mit-copyright.h>.
+ *
+ * This routine generates an odd-parity table for use in key generation.
+ */
+
+#include <mit-copyright.h>
+#include <stdio.h>
+
+void gen(stream)
+    FILE *stream;
+{
+    /*
+     * map a byte into its equivalent with odd parity, where odd
+     * parity is in the least significant bit
+     */
+    register i, j, k, odd;
+
+    fprintf(stream,
+            "#include <sys/cdefs.h>\n");
+    fprintf(stream,
+            "static unsigned char const odd_parity[256] = {\n");
+
+    for (i = 0; i < 256; i++) {
+        odd = 0;
+        /* shift out the lsb parity bit */
+        k = i >> 1;
+        /* then count the other bits */
+        for (j = 0; j < 7; j++) {
+            odd ^= (k&1);
+            k = k >> 1;
+        }
+        k = i&~1;
+        if (!odd)
+            k |= 1;
+        fprintf(stream, "%3d", k);
+        if (i < 255)
+            fprintf(stream, ", ");
+        if (i%8 == 0)
+            fprintf(stream, "\n");
+    }
+    fprintf(stream, "};\n");
+}