X-Git-Url: https://git.distorted.org.uk/~mdw/become/blobdiff_plain/fe59d3d70fc7337b7a50c4fcff72d20967672157..f60a34341fee6aafd5b878dce23b80af7c60064d:/src/tx.c diff --git a/src/tx.c b/src/tx.c deleted file mode 100644 index 281902f..0000000 --- a/src/tx.c +++ /dev/null @@ -1,184 +0,0 @@ -/* -*-c-*- - * - * $Id: tx.c,v 1.3 1998/01/12 16:46:31 mdw Exp $ - * - * Transfer for keys and other large integers - * - * (c) 1998 Mark Wooding - */ - -/*----- Licensing notice --------------------------------------------------* - * - * This file is part of `become' - * - * `Become' is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * `Become' is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with `become'; if not, write to the Free Software Foundation, - * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -/*----- Revision history --------------------------------------------------* - * - * $Log: tx.c,v $ - * Revision 1.3 1998/01/12 16:46:31 mdw - * Fix copyright date. - * - * Revision 1.2 1997/08/04 10:24:25 mdw - * Sources placed under CVS control. - * - * Revision 1.1 1997/07/21 13:47:43 mdw - * Initial revision - * - */ - -/*----- Header files ------------------------------------------------------*/ - -/* --- ANSI headers --- */ - -#include -#include -#include -#include - -/* --- Local headers --- */ - -#include "config.h" -#include "tx.h" - -/*----- Main code ---------------------------------------------------------*/ - -/* --- @tx_getBits@ --- * - * - * Arguments: @unsigned char *k@ = pointer to key array to unpack into - * @size_t sz@ = number of bits to read (elements in array) - * @FILE *fp@ = stream to read from - * - * Returns: --- - * - * Use: Reads a number of bits into an array. The least significant - * bits of the final word are cleared to zero. - */ - -void tx_getBits(unsigned char *k, size_t sz, FILE *fp) -{ - int i = 0; - unsigned char a = 0; - unsigned int ch; - size_t wsz = (size_t)((sz + 7ul) & ~7ul); - int t; - - while ((t = getc(fp)) != EOF) { - - /* --- Allow separators for readbility --- */ - - if (t == '-') - continue; - - /* --- Standard converting-from-hex-digit code --- * - * - * Assumes that 'a'--'f' and 'A'--'F' are contiguous and in order, in - * addition to the guarantee that '0'--'9' are like this. The assumption - * is true in ASCII (and character sets based thereon) and EBCDIC. - */ - - ch = (unsigned)t; - ch -= '0'; - if (ch > 9) ch -= 'A' - '0' - 10; - if (ch > 15) ch -= 'a' - 'A'; - if (ch > 15) break; - - /* --- Accumulate and maybe store --- */ - - a = (a << 4) | ch; - i++; - sz -= 4, wsz -= 4; - if ((i & 1) == 0) - *k++ = a, a = 0; - if (!sz) - break; - } - - /* --- Pad the rest out with zeros --- */ - - while (wsz) { - a <<= 4; - i++; - wsz -= 4; - if ((i & 1) == 0) - *k++ = a, a = 0; - } -} - -/* --- @tx_putBits@ --- * - * - * Arguments: @unsigned char *k@ = pointer to key block - * @size_t sz@ = number of bits to write - * @FILE *fp@ = pointer to stream to write on - * - * Returns: --- - * - * Use: Complements @tx_getBits@ above. Writes a number of bits - * to a file in an easy-to-read and transportable format (hex!) - */ - -void tx_putBits(unsigned char *k, size_t sz, FILE *fp) -{ - const static char hex[16] = "0123456789abcdef"; - size_t dash; - size_t d; - unsigned char i; - - /* --- Don't do anything unless we have to --- */ - - if (!sz) - return; - - /* --- Now decide where to `dash' the output --- */ - - if (sz % 32 == 0) - dash = 4; - else if (sz % 40 == 0) - dash = 5; - else - dash = 0; - - /* --- Start writing values out --- */ - - d = dash; - - for (;;) { - - /* --- Write next byte out --- */ - - i = *k++; - putc(hex[(i >> 4) & 0x0fu], fp); - putc(hex[(i >> 0) & 0x0fu], fp); - - /* --- If done, stop now --- */ - - if (sz -= 8, sz == 0) - break; - - /* --- If need a dash, print one --- */ - - if (!--d) { - putc('-', fp); - d = dash; - } - } - - /* --- Print the final newline --- */ - - fputc('\n', fp); -} - -/*----- That's all, folks -------------------------------------------------*/