jens@0: /* mnemonic.h jens@0: jens@0: Copyright (c) 2000 Oren Tirosh jens@0: jens@0: Permission is hereby granted, free of charge, to any person obtaining a copy jens@0: of this software and associated documentation files (the "Software"), to deal jens@0: in the Software without restriction, including without limitation the rights jens@0: to use, copy, modify, merge, publish, distribute, sublicense, and/or sell jens@0: copies of the Software, and to permit persons to whom the Software is jens@0: furnished to do so, subject to the following conditions: jens@0: jens@0: The above copyright notice and this permission notice shall be included in jens@0: all copies or substantial portions of the Software. jens@0: jens@0: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR jens@0: IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, jens@0: FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE jens@0: AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER jens@0: LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, jens@0: OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN jens@0: THE SOFTWARE. jens@0: jens@0: */ jens@0: jens@0: #define MN_BASE 1626 /* cubic root of 2^32, rounded up */ jens@0: #define MN_REMAINDER 7 /* extra words for 24 bit remainders */ jens@0: #define MN_WORDS (MN_BASE+MN_REMAINDER) /* total number of words */ jens@0: #define MN_WORD_BUFLEN 25 /* size for a word buffer+headroom */ jens@0: jens@0: #define MN_EOF 0 /* signal end to mn_decode_word_index */ jens@0: jens@0: /* result codes */ jens@0: #define MN_OK 0 /* decoding ok */ jens@0: #define MN_EREM -1 /* unexpected arithmetic remainder */ jens@0: #define MN_EOVERRUN -2 /* output buffer overrun */ jens@0: #define MN_EOVERRUN24 -3 /* data after 24 bit remainder */ jens@0: #define MN_EINDEX -4 /* bad word index */ jens@0: #define MN_EINDEX24 -5 /* unexpected 24 bit remainder word */ jens@0: #define MN_EENCODING -6 /* invalid arithmetic encoding */ jens@0: #define MN_EWORD -7 /* unrecognized word */ jens@0: #define MN_EFORMAT -8 /* bad format string */ jens@0: jens@0: /* Sample formats for mn_encode */ jens@0: #define MN_FDEFAULT "x-x-x--" jens@0: #define MN_F64BITSPERLINE " x-x-x--x-x-x\n" jens@0: #define MN_F96BITSPERLINE " x-x-x--x-x-x--x-x-x\n" jens@0: #define MN_F128BITSPERLINE " x-x-x--x-x-x--x-x-x--x-x-x\n" jens@0: /* Note that the last format does not fit in a standard 80 character line */ jens@0: jens@0: typedef unsigned char mn_byte; /* 8 bit quantity */ jens@0: typedef unsigned long mn_word32; /* temporary value, at least 32 bits */ jens@0: typedef unsigned int mn_index; /* index into wordlist */ jens@0: jens@0: extern const char *mn_words[]; /* the word list itself */ jens@0: extern const char *mn_wordlist_version; /* version notice string */ jens@0: jens@0: int mn_decode (char *src, void *dest, int destsize); jens@0: int mn_encode (void *src , int srcsize, jens@0: char *dest, int destsize, char *format); jens@0: jens@0: int mn_words_required (int size); jens@0: mn_index mn_encode_word_index (void *src, int srcsize, int n); jens@0: const char* mn_encode_word (void *src, int srcsize, int n); jens@0: mn_index mn_next_word_index (char **ptr); jens@0: int mn_decode_word_index (mn_index index, void *dest, jens@0: int destsize, int *offset); jens@0: jens@0: