From: batt Date: Wed, 28 Nov 2007 21:49:30 +0000 (+0000) Subject: Rename algos directory to algo. X-Git-Tag: 1.0.0~234 X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=35ae4275d8730a376ca61a92f08fb447eb2935b3;p=bertos.git Rename algos directory to algo. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@1008 38d2e660-2303-0410-9eaa-f027e97ec537 --- diff --git a/algo/crc.c b/algo/crc.c new file mode 100644 index 00000000..d465e260 --- /dev/null +++ b/algo/crc.c @@ -0,0 +1,88 @@ +/** + * \file + * + * + * \brief CRC table and support routines + * + * \version $Id$ + * \author Bernardo Innocenti + */ + +#include "crc.h" + +/** + * crctab calculated by Mark G. Mendel, Network Systems Corporation + */ +const uint16_t crc16tab[256] = { + 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7, + 0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef, + 0x1231, 0x0210, 0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6, + 0x9339, 0x8318, 0xb37b, 0xa35a, 0xd3bd, 0xc39c, 0xf3ff, 0xe3de, + 0x2462, 0x3443, 0x0420, 0x1401, 0x64e6, 0x74c7, 0x44a4, 0x5485, + 0xa56a, 0xb54b, 0x8528, 0x9509, 0xe5ee, 0xf5cf, 0xc5ac, 0xd58d, + 0x3653, 0x2672, 0x1611, 0x0630, 0x76d7, 0x66f6, 0x5695, 0x46b4, + 0xb75b, 0xa77a, 0x9719, 0x8738, 0xf7df, 0xe7fe, 0xd79d, 0xc7bc, + 0x48c4, 0x58e5, 0x6886, 0x78a7, 0x0840, 0x1861, 0x2802, 0x3823, + 0xc9cc, 0xd9ed, 0xe98e, 0xf9af, 0x8948, 0x9969, 0xa90a, 0xb92b, + 0x5af5, 0x4ad4, 0x7ab7, 0x6a96, 0x1a71, 0x0a50, 0x3a33, 0x2a12, + 0xdbfd, 0xcbdc, 0xfbbf, 0xeb9e, 0x9b79, 0x8b58, 0xbb3b, 0xab1a, + 0x6ca6, 0x7c87, 0x4ce4, 0x5cc5, 0x2c22, 0x3c03, 0x0c60, 0x1c41, + 0xedae, 0xfd8f, 0xcdec, 0xddcd, 0xad2a, 0xbd0b, 0x8d68, 0x9d49, + 0x7e97, 0x6eb6, 0x5ed5, 0x4ef4, 0x3e13, 0x2e32, 0x1e51, 0x0e70, + 0xff9f, 0xefbe, 0xdfdd, 0xcffc, 0xbf1b, 0xaf3a, 0x9f59, 0x8f78, + 0x9188, 0x81a9, 0xb1ca, 0xa1eb, 0xd10c, 0xc12d, 0xf14e, 0xe16f, + 0x1080, 0x00a1, 0x30c2, 0x20e3, 0x5004, 0x4025, 0x7046, 0x6067, + 0x83b9, 0x9398, 0xa3fb, 0xb3da, 0xc33d, 0xd31c, 0xe37f, 0xf35e, + 0x02b1, 0x1290, 0x22f3, 0x32d2, 0x4235, 0x5214, 0x6277, 0x7256, + 0xb5ea, 0xa5cb, 0x95a8, 0x8589, 0xf56e, 0xe54f, 0xd52c, 0xc50d, + 0x34e2, 0x24c3, 0x14a0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405, + 0xa7db, 0xb7fa, 0x8799, 0x97b8, 0xe75f, 0xf77e, 0xc71d, 0xd73c, + 0x26d3, 0x36f2, 0x0691, 0x16b0, 0x6657, 0x7676, 0x4615, 0x5634, + 0xd94c, 0xc96d, 0xf90e, 0xe92f, 0x99c8, 0x89e9, 0xb98a, 0xa9ab, + 0x5844, 0x4865, 0x7806, 0x6827, 0x18c0, 0x08e1, 0x3882, 0x28a3, + 0xcb7d, 0xdb5c, 0xeb3f, 0xfb1e, 0x8bf9, 0x9bd8, 0xabbb, 0xbb9a, + 0x4a75, 0x5a54, 0x6a37, 0x7a16, 0x0af1, 0x1ad0, 0x2ab3, 0x3a92, + 0xfd2e, 0xed0f, 0xdd6c, 0xcd4d, 0xbdaa, 0xad8b, 0x9de8, 0x8dc9, + 0x7c26, 0x6c07, 0x5c64, 0x4c45, 0x3ca2, 0x2c83, 0x1ce0, 0x0cc1, + 0xef1f, 0xff3e, 0xcf5d, 0xdf7c, 0xaf9b, 0xbfba, 0x8fd9, 0x9ff8, + 0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0 +}; + +uint16_t crc16(uint16_t crc, const void *buffer, size_t len) +{ + const unsigned char *buf = (const unsigned char *)buffer; + while(len--) + crc = UPDCRC16(*buf++, crc); + + return crc; +} + diff --git a/algo/crc.h b/algo/crc.h new file mode 100644 index 00000000..475e70d1 --- /dev/null +++ b/algo/crc.h @@ -0,0 +1,102 @@ +/** + * \file + * + * + * \brief XModem-CRC16 algorithm (interface) + * + * \note This algorithm is incompatible with the CCITT-CRC16. + * + * This code is based on the article Copyright 1986 Stephen Satchell. + * + * Programmers may incorporate any or all code into their programs, + * giving proper credit within the source. Publication of the + * source routines is permitted so long as proper credit is given + * to Stephen Satchell, Satchell Evaluations and Chuck Forsberg, + * Omen Technology. + * + * \version $Id$ + * \author Bernardo Innocenti + */ + +#ifndef CRC_H +#define CRC_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + + +/* CRC table */ +extern const uint16_t crc16tab[256]; + + +/** + * \brief Compute the updated CRC16 value for one octet (macro version) + * + * \note This version is only intended for old/broken compilers. + * Use the inline function in new code. + * + * \param c New octet (range 0-255) + * \param oldcrc Previous CRC16 value (referenced twice, beware of side effects) + */ +#define UPDCRC16(c, oldcrc) (crc16tab[((oldcrc) >> 8) ^ ((unsigned char)(c))] ^ ((oldcrc) << 8)) + + +#ifdef INLINE +/** + * \brief Compute the updated CRC16 value for one octet (macro version) + */ +INLINE uint16_t updcrc16(uint8_t c, uint16_t oldcrc) +{ + return crc16tab[(oldcrc >> 8) ^ c] ^ (oldcrc << 8); +} +#endif // INLINE + + +/** + * This function implements the CRC 16 calculation on a buffer. + * + * \param crc Current CRC16 value. + * \param buf The buffer to perform CRC calculation on. + * \param len The length of the Buffer. + * + * \return The updated CRC16 value. + */ +extern uint16_t crc16(uint16_t crc, const void *buf, size_t len); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* CRC_H */ diff --git a/algo/md2.c b/algo/md2.c new file mode 100644 index 00000000..53b44865 --- /dev/null +++ b/algo/md2.c @@ -0,0 +1,377 @@ +/** + * \file + * + * + * \brief MD2 Message-Digest algorithm. + * + * The MD2 algorithm work with a constant array of 256 permutationt + * defined in RFC1319. If you don't want to use a standard array of + * permutatione you can use a md2_perm() function that generate an + * array of 256 "casual" permutation. To swich from a standard array + * to md2_perm function you must chanche CONFIG_MD2_STD_PERM defined in + * appconfig.h. + * If you need to store array in program memory you must define + * a macro _PROGMEM (for more info see mware/pgm.h). + * + * + * \version $Id$ + * \author Daniele Basile + */ + +/*#* + *#* $Log$ + *#* Revision 1.17 2007/06/07 16:06:39 batt + *#* Fix some doxygen errors. + *#* + *#* Revision 1.16 2007/02/15 13:29:49 asterix + *#* Add MD2_DIGEST_LEN macro. + *#* + *#* Revision 1.15 2007/02/06 15:53:34 asterix + *#* Add ROTR macro in m2d_perm, add comments, typos. + *#* + *#* Revision 1.13 2007/02/05 18:44:42 asterix + *#* Add md2_perm function. + *#* + *#* Revision 1.12 2007/02/05 16:52:44 asterix + *#* Add define for harvard architecture. + *#* + *#* Revision 1.11 2007/02/02 18:15:31 asterix + *#* Add function MD2_test. Fix bug in md2_update function. + *#* + *#* Revision 1.9 2007/02/02 13:10:01 asterix + *#* Fix some bugs in md2_pad and md2_update fuction. + *#* + *#* Revision 1.8 2007/02/01 14:45:56 asterix + *#* Rewrite md2_update function and fix some bug. + *#* + *#* Revision 1.7 2007/01/31 18:04:15 asterix + *#* Write md2_end function + *#* + *#* Revision 1.4 2007/01/31 13:51:57 asterix + *#* Write md2_compute function. + *#* + *#* Revision 1.2 2007/01/30 17:31:44 asterix + *#* Add function prototypes. + *#* + *#* Revision 1.1 2007/01/30 15:53:26 batt + *#* Add first md2 skel. + *#* + *#*/ + +#include "md2.h" + +#include //memset(), memcpy(); +#include +#include //ASSERT() +#include //MIN(), countof(), ROTR(); +#include + + +#if CONFIG_MD2_STD_PERM + /* + * Official array of 256 byte pemutation contructed from digits of pi, defined + * in the RFC 1319. + */ + static const uint8_t PGM_ATTR md2_perm[256] = + { + 41, 46, 67, 201, 162, 216, 124, 1, 61, 54, 84, 161, 236, 240, 6, + 19, 98, 167, 5, 243, 192, 199, 115, 140, 152, 147, 43, 217, 188, + 76, 130, 202, 30, 155, 87, 60, 253, 212, 224, 22, 103, 66, 111, 24, + 138, 23, 229, 18, 190, 78, 196, 214, 218, 158, 222, 73, 160, 251, + 245, 142, 187, 47, 238, 122, 169, 104, 121, 145, 21, 178, 7, 63, + 148, 194, 16, 137, 11, 34, 95, 33, 128, 127, 93, 154, 90, 144, 50, + 39, 53, 62, 204, 231, 191, 247, 151, 3, 255, 25, 48, 179, 72, 165, + 181, 209, 215, 94, 146, 42, 172, 86, 170, 198, 79, 184, 56, 210, + 150, 164, 125, 182, 118, 252, 107, 226, 156, 116, 4, 241, 69, 157, + 112, 89, 100, 113, 135, 32, 134, 91, 207, 101, 230, 45, 168, 2, 27, + 96, 37, 173, 174, 176, 185, 246, 28, 70, 97, 105, 52, 64, 126, 15, + 85, 71, 163, 35, 221, 81, 175, 58, 195, 92, 249, 206, 186, 197, + 234, 38, 44, 83, 13, 110, 133, 40, 132, 9, 211, 223, 205, 244, 65, + 129, 77, 82, 106, 220, 55, 200, 108, 193, 171, 250, 36, 225, 123, + 8, 12, 189, 177, 74, 120, 136, 149, 139, 227, 99, 232, 109, 233, + 203, 213, 254, 59, 0, 29, 57, 242, 239, 183, 14, 102, 88, 208, 228, + 166, 119, 114, 248, 235, 117, 75, 10, 49, 68, 80, 180, 143, 237, + 31, 26, 219, 153, 141, 51, 159, 17, 131, 20 + }; + + #define MD2_PERM(x) PGM_READ_CHAR(&md2_perm[x]) +#else + /** + * Md2_perm() function generate an array of 256 "casual" permutation. + */ + + /** + * Costant define for computing an array of 256 "casual" permutation. + * \{ + */ + #define K1 5 + #define K2 3 + #define R 2 + #define X 172 + /*\}*/ + + static uint8_t md2_perm(uint8_t i) + { + + i = i * K1; + i = ROTR(i, R); + i ^= X; + i = i * K2; + + return i; + } + + #define MD2_PERM(x) md2_perm(x) + +#endif + + +/** + * Pad function. Put len_pad unsigned char in + * input block. + */ +static void md2_pad(void *_block, size_t len_pad) +{ + uint8_t *block; + + block = (uint8_t *)_block; + + ASSERT(len_pad <= CONFIG_MD2_BLOCK_LEN); + + /* + * Fill input block with len_pad char. + */ + memset(block, len_pad, len_pad); + +} + +static void md2_compute(void *_state, void *_checksum, void *_block) +{ + int i = 0; + uint16_t t = 0; + uint8_t compute_array[COMPUTE_ARRAY_LEN]; + uint8_t *state; + uint8_t *checksum; + uint8_t *block; + + state = (uint8_t *)_state; + checksum = (uint8_t *)_checksum; + block = (uint8_t *)_block; + + /* + * Copy state and checksum context in compute array. + */ + memcpy(compute_array, state, CONFIG_MD2_BLOCK_LEN); + memcpy(compute_array + CONFIG_MD2_BLOCK_LEN, block, CONFIG_MD2_BLOCK_LEN); + + /* + * Fill compute array with state XOR block + */ + for(i = 0; i < CONFIG_MD2_BLOCK_LEN; i++) + compute_array[i + (CONFIG_MD2_BLOCK_LEN * 2)] = state[i] ^ block[i]; + + /* + * Encryt block. + */ + for(i = 0; i < NUM_COMPUTE_ROUNDS; i++) + { + for(int j = 0; j < COMPUTE_ARRAY_LEN; j++) + { + compute_array[j] ^= MD2_PERM(t); + t = compute_array[j]; + } + + t = (t + i) & 0xff; //modulo 256. + } + /* + * Update checksum. + */ + t = checksum[CONFIG_MD2_BLOCK_LEN - 1]; + + for(i = 0; i < CONFIG_MD2_BLOCK_LEN; i++) + { + checksum[i] ^= MD2_PERM(block[i] ^ t); + t = checksum[i]; + } + + /* + * Update state and clean compute array. + */ + memcpy(state, compute_array, CONFIG_MD2_BLOCK_LEN); + memset(compute_array, 0, sizeof(compute_array)); +} + +/** + * Algorithm initialization. + * + * \param context empty context. + */ +void md2_init(Md2Context *context) +{ + + memset(context, 0, sizeof(Md2Context)); + +} + +/** + * Update block. + */ +void md2_update(Md2Context *context, const void *_block_in, size_t block_len) +{ + + const uint8_t *block_in; + size_t cpy_len; + + + block_in = (const uint8_t *)_block_in; + + while(block_len > 0) + { + /* + * Choose a number of block that fill input context buffer. + */ + cpy_len = MIN(block_len, CONFIG_MD2_BLOCK_LEN - context->counter); + + + /* + * Copy in the buffer input block. + */ + memcpy(&context->buffer[context->counter], block_in, cpy_len); + + /* + * Update a context counter, input block length and remaning + * context buffer block lenght. + */ + context->counter += cpy_len; + block_len -= cpy_len; + block_in += cpy_len; + + /* + * If buffer is full, compute it. + */ + if (context->counter >= CONFIG_MD2_BLOCK_LEN) + { + md2_compute(context->state, context->checksum, context->buffer); + context->counter = 0; + } + } + + +} +/** + * Ends an MD2 message digest operation. + * This fuction take an context and return a pointer + * to context state. + * + * \param context in input. + * \return a pointer to context state (message digest). + */ +uint8_t *md2_end(Md2Context *context) +{ + + uint8_t buf[CONFIG_MD2_BLOCK_LEN]; + + /* + * Fill remaning empty context buffer. + */ + md2_pad(buf, CONFIG_MD2_BLOCK_LEN - context->counter); + + /* + * Update context buffer and compute it. + */ + md2_update(context, buf, CONFIG_MD2_BLOCK_LEN - context->counter); + + /* + * Add context checksum to message input. + */ + md2_update(context, context->checksum, CONFIG_MD2_BLOCK_LEN); + + + return context->state; //return a pointer to message digest. +} +/** + * MD2 test fuction. + * This function test MD2 algorithm with a standard string specified + * in RFC 1319. + * + * \note This test work with official array of 256 byte pemutation + * contructed from digits of pi, defined in the RFC 1319. + * + */ +bool md2_test(void) +{ + + Md2Context context; + + const char *test[] = + { + "", + "message digest", + "abcdefghijklmnopqrstuvwxyz", + "12345678901234567890123456789012345678901234567890123456789012345678901234567890" + }; + + + const uint8_t *result[] = { + "\x83\x50\xe5\xa3\xe2\x4c\x15\x3d\xf2\x27\x5c\x9f\x80\x69\x27\x73", + "\xab\x4f\x49\x6b\xfb\x2a\x53\x0b\x21\x9f\xf3\x30\x31\xfe\x06\xb0", + "\x4e\x8d\xdf\xf3\x65\x02\x92\xab\x5a\x41\x08\xc3\xaa\x47\x94\x0b", + "\xd5\x97\x6f\x79\xd8\x3d\x3a\x0d\xc9\x80\x6c\x3c\x66\xf3\xef\xd8", + }; + + + for (int i = 0; i < countof(test); i++) + { + md2_init(&context); + md2_update(&context, test[i], strlen(test[i])); + + if(memcmp(result[i], md2_end(&context), MD2_DIGEST_LEN)) + return false; + } + + return true; +} + +#if 0 + +#include +int main(int argc, char * argv[]) +{ + + if(md2_test()) + printf("MD2 algorithm work well!\n"); + else + printf("MD2 algorithm doesn't work well.\n"); + +} + +#endif + diff --git a/algo/md2.h b/algo/md2.h new file mode 100644 index 00000000..44ba32c6 --- /dev/null +++ b/algo/md2.h @@ -0,0 +1,98 @@ +/** + * \file + * + * + * \brief MD2 Message-Digest algorithm. + * + * The algorithm takes as input a message of arbitrary length and produces + * as output a 128-bit message digest of the input. + * It is conjectured that it is computationally infeasible to produce + * two messages having the same message digest, or to produce any + * message having a given prespecified target message digest. + * + * + * + * \version $Id$ + * \author Daniele Basile + */ + +/*#* + *#* $Log$ + *#* Revision 1.7 2007/02/15 13:29:49 asterix + *#* Add MD2_DIGEST_LEN macro. + *#* + *#* Revision 1.6 2007/02/02 18:15:31 asterix + *#* Add function MD2_test. Fix bug in md2_update function. + *#* + *#* Revision 1.5 2007/02/02 15:37:45 asterix + *#* Change md2_end prototype. Remove a unneeded memcpy in md2_end. Add comments. + *#* + *#* Revision 1.4 2007/01/31 13:53:36 asterix + *#* Define COMPUTE_ARRAY_LEN. + *#* + *#* Revision 1.3 2007/01/31 11:16:48 asterix + *#* Defined constants for algorithm compute + *#* + *#* Revision 1.2 2007/01/30 17:31:44 asterix + *#* Add function prototypes. + *#* + *#* Revision 1.1 2007/01/30 15:53:26 batt + *#* Add first md2 skel. + *#* + *#*/ + +#ifndef ALGOS_MD2_H +#define ALGOS_MD2_H + +#include +#include + +#define NUM_COMPUTE_ROUNDS 18 ///< Number of compute rounds. +#define COMPUTE_ARRAY_LEN CONFIG_MD2_BLOCK_LEN * 3 ///< Lenght of compute array. +#define MD2_DIGEST_LEN CONFIG_MD2_BLOCK_LEN +/** + * Context for MD2 computation. + */ +typedef struct Md2Context +{ + uint8_t buffer[CONFIG_MD2_BLOCK_LEN]; ///< Input buffer. + uint8_t state[CONFIG_MD2_BLOCK_LEN]; ///< Current state buffer. + uint8_t checksum[CONFIG_MD2_BLOCK_LEN]; ///< Checksum. + size_t counter; ///< Counter of remaining bytes. + +} Md2Context; + +void md2_init(Md2Context *context); +void md2_update(Md2Context *context, const void *block_in, size_t block_len); +uint8_t *md2_end(Md2Context *context); +bool md2_test(void); + +#endif /* ALGOS_MD2_H */ diff --git a/algo/randpool.c b/algo/randpool.c new file mode 100644 index 00000000..a32fdff4 --- /dev/null +++ b/algo/randpool.c @@ -0,0 +1,298 @@ +/** + * \file + * + * + * \brief API function for to manage entropy pool. + * + * \version $Id$ + * \author Daniele Basile + */ + +/*#* + *#* $Log$ + *#* Revision 1.20 2007/06/07 16:06:39 batt + *#* Fix some doxygen errors. + *#* + *#* Revision 1.19 2007/02/15 13:54:26 asterix + *#* Rename randpool_getN in randpool_get. Fix bug in randpool_get. + *#* + *#* Revision 1.17 2007/02/15 13:40:42 asterix + *#* Fix bug in randpool_add and randpool_strir. + *#* + *#* Revision 1.16 2007/02/13 15:11:37 asterix + *#* Typo. + *#* + *#* Revision 1.14 2007/02/13 09:57:12 asterix + *#* Add directive #if in struct EntropyPool, and remove #else in randpool_add. + *#* + *#* Revision 1.13 2007/02/12 18:25:34 asterix + *#* Fix bug in randpool_getN. + *#* + *#* Revision 1.12 2007/02/12 09:47:39 asterix + *#* Remove randpool_save. Add randpool_pool. + *#* + *#* Revision 1.10 2007/02/12 09:03:32 asterix + *#* Add CONFIG_RANDPOOL_TIMER macro to swich on or off timer support + *#* + *#* Revision 1.9 2007/02/09 17:58:09 asterix + *#* Add macro CONFIG_RANDPOOL_TIMER. + *#* + *#* Revision 1.6 2007/02/09 09:24:38 asterix + *#* Typos. Add data_len in randpool_add and n_byte in randpool_push pototypes. + *#* + *#* Revision 1.3 2007/02/08 14:25:29 asterix + *#* Write static funcion push_byte. + *#* + *#*/ + +#include "randpool.h" +#include "md2.h" + +#include //sprintf(); +#include //memset(), memcpy(); + +#include +#include //ASSERT() +#include //MIN(), ROUND_UP(); + +#if CONFIG_RANDPOOL_TIMER + #include //timer_clock(); +#endif + + + +/* + * Insert bytes in entropy pool, making a XOR of bytes present + * in entropy pool. + */ +static void randpool_push(EntropyPool *pool, void *_byte, size_t n_byte) +{ + size_t i = pool->pos_add; // Current number of byte insert in entropy pool. + uint8_t *byte; + + byte = (uint8_t *)_byte; + + /* + * Insert a bytes in entropy pool. + */ + for(int j = 0; j < n_byte; j++) + { + pool->pool_entropy[i] = pool->pool_entropy[i] ^ byte[j]; + i = (++i) % CONFIG_SIZE_ENTROPY_POOL; + } + + pool->pos_add = i; // Update a insert bytes. +} + + +/* + * This function stir entropy pool with MD2 function hash. + * + */ +static void randpool_stir(EntropyPool *pool) +{ + size_t entropy = pool->entropy; //Save current calue of entropy. + Md2Context context; + uint8_t tmp_buf[((sizeof(size_t) * 2) + sizeof(int)) * 2 + 1]; //Temporary buffer. + + md2_init(&context); //Init MD2 algorithm. + + randpool_add(pool, NULL, 0); + + for (int i = 0; i < (CONFIG_SIZE_ENTROPY_POOL / MD2_DIGEST_LEN); i++) + { + sprintf(tmp_buf, "%0x%0x%0x",pool->counter, i, pool->pos_add); + + /* + * Hash with MD2 algorithm the entropy pool. + */ + md2_update(&context, pool->pool_entropy, CONFIG_SIZE_ENTROPY_POOL); + + md2_update(&context, tmp_buf, sizeof(tmp_buf) - 1); + + /*Insert a message digest in entropy pool.*/ + randpool_push(pool, md2_end(&context), MD2_DIGEST_LEN); + + pool->counter = pool->counter + 1; + + } + + /*Insert in pool the difference between a two call of this function (see above).*/ + randpool_add(pool, NULL, 0); + + pool->entropy = entropy; //Restore old value of entropy. We haven't add entropy. +} + +/** + * Add \param entropy bits from \param data buffer to the entropy \param pool + */ +void randpool_add(EntropyPool *pool, void *data, size_t entropy) +{ + uint8_t sep[] = "\xaa\xaa\xaa\xaa"; // ?? + size_t data_len = ROUND_UP(entropy, 8) / 8; //Number of entropy byte in input. + + randpool_push(pool, data, data_len); //Insert data to entropy pool. + +#if CONFIG_RANDPOOL_TIMER + + ticks_t event = timer_clock(); + ticks_t delta; + + /*Difference of time between a two accese to entropy pool.*/ + delta = event - pool->last_counter; + + randpool_push(pool, &event, sizeof(ticks_t)); + randpool_push(pool, sep, sizeof(sep) - 1); // ?? + randpool_push(pool, &delta, sizeof(delta)); + + /* + * Count of number entropy bit add with delta. + */ + delta = delta & 0xff; + while(delta) + { + delta >>= 1; + entropy++; + } + + pool->last_counter = event; + +#endif + + pool->entropy += entropy; //Update a entropy of the pool. +} + +/** + * Randpool function initialization. + * The entropy pool can be initialize also with + * a previous entropy pool. + */ +void randpool_init(EntropyPool *pool, void *_data, size_t len) +{ + uint8_t *data; + + data = (uint8_t *)_data; + + memset(pool, 0, sizeof(EntropyPool)); + pool->pos_get = MD2_DIGEST_LEN; + +#if CONFIG_RANDPOOL_TIMER + pool->last_counter = timer_clock(); +#endif + + if(data) + { + /* + * Initialize a entropy pool with a + * previous pool, and assume all pool as + * entropy. + */ + len = MIN(len,(size_t)CONFIG_SIZE_ENTROPY_POOL); + memcpy(pool->pool_entropy, data, len); + pool->entropy = len; + } + +} + +/** + * Get the actual value of entropy. + */ +size_t randpool_size(EntropyPool *pool) +{ + return pool->entropy; +} + +/** + * Get \param n_byte from entropy pool. If n_byte is larger than number + * byte of entropy in entropy pool, randpool_get continue + * to generate pseudocasual value from previous state of + * pool. + * \param n_byte number fo bytes to read. + * \param pool is the pool entropy context. + * \param _data is the pointer to write the random data to. + */ +void randpool_get(EntropyPool *pool, void *_data, size_t n_byte) +{ + Md2Context context; + size_t i = pool->pos_get; + size_t n = n_byte; + size_t pos_write = 0; //Number of block has been written in data. + size_t len = MIN((size_t)MD2_DIGEST_LEN, n_byte); + uint8_t *data; + + data = (uint8_t *)_data; + + /* Test if i + CONFIG_MD2_BLOCK_LEN is inside of entropy pool.*/ + ASSERT((MD2_DIGEST_LEN + i) < CONFIG_SIZE_ENTROPY_POOL); + + md2_init(&context); + + while(n > 0) + { + + /*Hash previous state of pool*/ + md2_update(&context, &pool->pool_entropy[i], MD2_DIGEST_LEN); + + memcpy(&data[pos_write], md2_end(&context), len); + + pos_write += len; //Update number of block has been written in data. + n -= len; //Number of byte copied in data. + + len = MIN(n,(size_t)MD2_DIGEST_LEN); + + i = (i + MD2_DIGEST_LEN) % CONFIG_SIZE_ENTROPY_POOL; + + /* If we haven't more entropy pool to hash, we stir it.*/ + if(i < MD2_DIGEST_LEN) + { + randpool_stir(pool); + i = pool->pos_get; + } + + } + + pool->pos_get = i; //Current number of byte we get from pool. + pool->entropy -= n_byte; //Update a entropy. + + /*If we get all entropy entropy is 0*/ + if(pool->entropy < 0) + pool->entropy = 0; + +} + +/** + * Return a pointer to entropy pool. + */ +uint8_t *randpool_pool(EntropyPool *pool) +{ + return pool->pool_entropy; +} + diff --git a/algo/randpool.h b/algo/randpool.h new file mode 100644 index 00000000..18d13f4c --- /dev/null +++ b/algo/randpool.h @@ -0,0 +1,106 @@ +/** + * \file + * + * + * \brief API function for to manage entropy pool. + * + * + * \version $Id$ + * \author Daniele Basile + */ + +/*#* + *#* $Log$ + *#* Revision 1.11 2007/02/15 13:54:26 asterix + *#* Rename randpool_getN in randpool_get. Fix bug in randpool_get. + *#* + *#* Revision 1.10 2007/02/15 13:40:42 asterix + *#* Fix bug in randpool_add and randpool_strir. + *#* + *#* Revision 1.9 2007/02/13 09:57:12 asterix + *#* Add directive #if in struct EntropyPool, and remove #else in randpool_add. + *#* + *#* Revision 1.8 2007/02/12 09:47:39 asterix + *#* Remove randpool_save. Add randpool_pool. + *#* + *#* Revision 1.6 2007/02/09 15:49:54 asterix + *#* Fix bug in randpool_stir and randpool_add. Typos. + *#* + *#* Revision 1.5 2007/02/09 09:24:38 asterix + *#* Typos. Add data_len in randpool_add and n_byte in randpool_push pototypes. + *#* + *#* Revision 1.4 2007/02/08 17:18:01 asterix + *#* Write add_data and stir function. Typos + *#* + *#* Revision 1.3 2007/02/08 14:25:56 asterix + *#* Typos. + *#* + *#* Revision 1.2 2007/02/08 11:53:03 asterix + *#* Add EntropyPool struct. Typos. + *#* + *#* Revision 1.1 2007/02/08 11:13:41 asterix + *#* Add function prototypes. + *#* + *#*/ + +#ifndef RANDPOOL_H +#define RANDPOOL_H + +#include +#include + + +/** + * Sturct data of entropy pool. + */ +typedef struct EntropyPool +{ + size_t entropy; ///< Actual value of entropy (byte). + size_t pos_add; ///< Number of byte idd in entropy pool. + size_t pos_get; ///< Number of byte get in entropy pool. + size_t counter; ///< Counter. + +#if CONFIG_RANDPOOL_TIMER + size_t last_counter; ///< Last timer value. +#endif + + uint8_t pool_entropy[CONFIG_SIZE_ENTROPY_POOL]; ///< Entropy pool. + +} EntropyPool; + + +void randpool_add(EntropyPool *pool, void *data, size_t entropy); +void randpool_init(EntropyPool *pool, void *_data, size_t len); +size_t randpool_size(EntropyPool *pool); +void randpool_get(EntropyPool *pool, void *data, size_t n_byte); +uint8_t *randpool_pool(EntropyPool *pool); + +#endif /* RANDPOOL_H */ diff --git a/algo/rotating_hash.h b/algo/rotating_hash.h new file mode 100644 index 00000000..123f2d3b --- /dev/null +++ b/algo/rotating_hash.h @@ -0,0 +1,82 @@ +/** + * \file + * + * + * \brief Rotating Hash algorithm (interface). + * + * This is a simple yet powerfull checksum algorithm. + * Instead of just xor-ing the data, rotating hash + * circular shift the checksum 4 place left before xoring. + * This is a bit more stronger than simply sum the data. + * + * \version $Id$ + * + * \author Francesco Sacchi + */ + + +#ifndef ALGOS_ROTATING_H +#define ALGOS_ROTATING_H + +#include + +typedef uint16_t rotating_t; + + +/** + * Init rotating checksum. + */ +INLINE void rotating_init(rotating_t *rot) +{ + *rot = 0; +} + +/** + * Update checksum pointed by \c rot with \c c data. + */ +INLINE void rotating_update1(uint8_t c, rotating_t *rot) +{ + *rot = (*rot << 4) ^ (*rot >> 12) ^ c; +} + +/** + * Update checksum pointed by \c rot with data supplied in \c buf. + */ +INLINE void rotating_update(const void *_buf, size_t len, rotating_t *rot) +{ + const uint8_t *buf = (const uint8_t *)_buf; + + while (len--) + rotating_update1(*buf++, rot); +} + + +#endif // ALGOS_ROTATING_H diff --git a/algo/tea.c b/algo/tea.c new file mode 100644 index 00000000..f67d4c5e --- /dev/null +++ b/algo/tea.c @@ -0,0 +1,145 @@ +/** + * \file + * + * + * \brief TEA Tiny Encription Algorith functions (implementation). + * + * \version $Id$ + * \author Francesco Sacchi + * + * The Tiny Encryption Algorithm (TEA) by David Wheeler and Roger Needham + * of the Cambridge Computer Laboratory + * + * Placed in the Public Domain by David Wheeler and Roger Needham. + * + * **** ANSI C VERSION **** + * + * Notes: + * + * TEA is a Feistel cipher with XOR and and addition as the non-linear + * mixing functions. + * + * Takes 64 bits of data in v[0] and v[1]. Returns 64 bits of data in w[0] + * and w[1]. Takes 128 bits of key in k[0] - k[3]. + * + * TEA can be operated in any of the modes of DES. Cipher Block Chaining is, + * for example, simple to implement. + * + * n is the number of iterations. 32 is ample, 16 is sufficient, as few + * as eight may be OK. The algorithm achieves good dispersion after six + * iterations. The iteration count can be made variable if required. + * + * Note this is optimised for 32-bit CPUs with fast shift capabilities. It + * can very easily be ported to assembly language on most CPUs. + * + * delta is chosen to be the real part of (the golden ratio Sqrt(5/4) - + * 1/2 ~ 0.618034 multiplied by 2^32). + */ + +/*#* + *#* $Log$ + *#* Revision 1.2 2007/09/19 16:23:27 batt + *#* Fix doxygen warnings. + *#* + *#* Revision 1.1 2007/06/07 09:13:40 batt + *#* Add TEA enc/decryption algorithm. + *#* + *#* Revision 1.1 2007/01/10 17:30:10 batt + *#* Add cryptographic routines. + *#* + *#*/ + +#include "tea.h" +#include + +static uint32_t tea_func(uint32_t *in, uint32_t *sum, uint32_t *k) +{ + return ((*in << 4) + cpu_to_le32(k[0])) ^ (*in + *sum) ^ ((*in >> 5) + cpu_to_le32(k[1])); +} + +/** + * \brief TEA encryption function. + * This function encrypts v with k and returns the + * encrypted data in v. + * \param _v Array of two long values containing the data block. + * \param _k Array of four long values containing the key. + */ +void tea_enc(void *_v, void *_k) +{ + uint32_t y, z; + uint32_t sum = 0; + uint8_t n = ROUNDS; + uint32_t *v = (uint32_t *)_v; + uint32_t *k = (uint32_t *)_k; + + y=cpu_to_le32(v[0]); + z=cpu_to_le32(v[1]); + + while(n-- > 0) + { + sum += DELTA; + y += tea_func(&z, &sum, &(k[0])); + z += tea_func(&y, &sum, &(k[2])); + } + + v[0] = le32_to_cpu(y); + v[1] = le32_to_cpu(z); +} + +/** + * \brief TEA decryption function. + * This function decrypts v with k and returns the + * decrypted data in v. + * \param _v Array of two long values containing the data block. + * \param _k Array of four long values containing the key. + */ +void tea_dec(void *_v, void *_k) +{ + uint32_t y, z; + uint32_t sum = DELTA * ROUNDS; + uint8_t n = ROUNDS; + uint32_t *v = (uint32_t *)_v; + uint32_t *k = (uint32_t *)_k; + + y = cpu_to_le32(v[0]); + z = cpu_to_le32(v[1]); + + while(n-- > 0) + { + z -= tea_func(&y, &sum, &(k[2])); + y -= tea_func(&z, &sum, &(k[0])); + sum -= DELTA; + } + + v[0] = le32_to_cpu(y); + v[1] = le32_to_cpu(z); +} + diff --git a/algo/tea.h b/algo/tea.h new file mode 100644 index 00000000..6e4f935a --- /dev/null +++ b/algo/tea.h @@ -0,0 +1,57 @@ +/** + * \file + * + * + * \brief TEA Tiny Encription Algorith functions (interface). + * + * \version $Id$ + * \author Francesco Sacchi + * + * Documentation for TEA is available at + * http://www.cl.cam.ac.uk/ftp/users/djw3/tea.ps. + */ + +#ifndef ALGOS_TEA_H +#define ALGOS_TEA_H + +#include + +#define TEA_KEY_LEN 16 //!< TEA key size. +#define TEA_BLOCK_LEN 8 //!< TEA block length. + +#define DELTA 0x9E3779B9 //!< Magic value. (Golden number * 2^31) +#define ROUNDS 32 //!< Number of rounds. + +void tea_enc(void *_v, void *_k); +void tea_dec(void *_v, void *_k); + +#endif /* ALGOS_TEA_H */ + diff --git a/algos/crc.c b/algos/crc.c deleted file mode 100644 index d465e260..00000000 --- a/algos/crc.c +++ /dev/null @@ -1,88 +0,0 @@ -/** - * \file - * - * - * \brief CRC table and support routines - * - * \version $Id$ - * \author Bernardo Innocenti - */ - -#include "crc.h" - -/** - * crctab calculated by Mark G. Mendel, Network Systems Corporation - */ -const uint16_t crc16tab[256] = { - 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7, - 0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef, - 0x1231, 0x0210, 0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6, - 0x9339, 0x8318, 0xb37b, 0xa35a, 0xd3bd, 0xc39c, 0xf3ff, 0xe3de, - 0x2462, 0x3443, 0x0420, 0x1401, 0x64e6, 0x74c7, 0x44a4, 0x5485, - 0xa56a, 0xb54b, 0x8528, 0x9509, 0xe5ee, 0xf5cf, 0xc5ac, 0xd58d, - 0x3653, 0x2672, 0x1611, 0x0630, 0x76d7, 0x66f6, 0x5695, 0x46b4, - 0xb75b, 0xa77a, 0x9719, 0x8738, 0xf7df, 0xe7fe, 0xd79d, 0xc7bc, - 0x48c4, 0x58e5, 0x6886, 0x78a7, 0x0840, 0x1861, 0x2802, 0x3823, - 0xc9cc, 0xd9ed, 0xe98e, 0xf9af, 0x8948, 0x9969, 0xa90a, 0xb92b, - 0x5af5, 0x4ad4, 0x7ab7, 0x6a96, 0x1a71, 0x0a50, 0x3a33, 0x2a12, - 0xdbfd, 0xcbdc, 0xfbbf, 0xeb9e, 0x9b79, 0x8b58, 0xbb3b, 0xab1a, - 0x6ca6, 0x7c87, 0x4ce4, 0x5cc5, 0x2c22, 0x3c03, 0x0c60, 0x1c41, - 0xedae, 0xfd8f, 0xcdec, 0xddcd, 0xad2a, 0xbd0b, 0x8d68, 0x9d49, - 0x7e97, 0x6eb6, 0x5ed5, 0x4ef4, 0x3e13, 0x2e32, 0x1e51, 0x0e70, - 0xff9f, 0xefbe, 0xdfdd, 0xcffc, 0xbf1b, 0xaf3a, 0x9f59, 0x8f78, - 0x9188, 0x81a9, 0xb1ca, 0xa1eb, 0xd10c, 0xc12d, 0xf14e, 0xe16f, - 0x1080, 0x00a1, 0x30c2, 0x20e3, 0x5004, 0x4025, 0x7046, 0x6067, - 0x83b9, 0x9398, 0xa3fb, 0xb3da, 0xc33d, 0xd31c, 0xe37f, 0xf35e, - 0x02b1, 0x1290, 0x22f3, 0x32d2, 0x4235, 0x5214, 0x6277, 0x7256, - 0xb5ea, 0xa5cb, 0x95a8, 0x8589, 0xf56e, 0xe54f, 0xd52c, 0xc50d, - 0x34e2, 0x24c3, 0x14a0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405, - 0xa7db, 0xb7fa, 0x8799, 0x97b8, 0xe75f, 0xf77e, 0xc71d, 0xd73c, - 0x26d3, 0x36f2, 0x0691, 0x16b0, 0x6657, 0x7676, 0x4615, 0x5634, - 0xd94c, 0xc96d, 0xf90e, 0xe92f, 0x99c8, 0x89e9, 0xb98a, 0xa9ab, - 0x5844, 0x4865, 0x7806, 0x6827, 0x18c0, 0x08e1, 0x3882, 0x28a3, - 0xcb7d, 0xdb5c, 0xeb3f, 0xfb1e, 0x8bf9, 0x9bd8, 0xabbb, 0xbb9a, - 0x4a75, 0x5a54, 0x6a37, 0x7a16, 0x0af1, 0x1ad0, 0x2ab3, 0x3a92, - 0xfd2e, 0xed0f, 0xdd6c, 0xcd4d, 0xbdaa, 0xad8b, 0x9de8, 0x8dc9, - 0x7c26, 0x6c07, 0x5c64, 0x4c45, 0x3ca2, 0x2c83, 0x1ce0, 0x0cc1, - 0xef1f, 0xff3e, 0xcf5d, 0xdf7c, 0xaf9b, 0xbfba, 0x8fd9, 0x9ff8, - 0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0 -}; - -uint16_t crc16(uint16_t crc, const void *buffer, size_t len) -{ - const unsigned char *buf = (const unsigned char *)buffer; - while(len--) - crc = UPDCRC16(*buf++, crc); - - return crc; -} - diff --git a/algos/crc.h b/algos/crc.h deleted file mode 100644 index 475e70d1..00000000 --- a/algos/crc.h +++ /dev/null @@ -1,102 +0,0 @@ -/** - * \file - * - * - * \brief XModem-CRC16 algorithm (interface) - * - * \note This algorithm is incompatible with the CCITT-CRC16. - * - * This code is based on the article Copyright 1986 Stephen Satchell. - * - * Programmers may incorporate any or all code into their programs, - * giving proper credit within the source. Publication of the - * source routines is permitted so long as proper credit is given - * to Stephen Satchell, Satchell Evaluations and Chuck Forsberg, - * Omen Technology. - * - * \version $Id$ - * \author Bernardo Innocenti - */ - -#ifndef CRC_H -#define CRC_H - -#include - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - - -/* CRC table */ -extern const uint16_t crc16tab[256]; - - -/** - * \brief Compute the updated CRC16 value for one octet (macro version) - * - * \note This version is only intended for old/broken compilers. - * Use the inline function in new code. - * - * \param c New octet (range 0-255) - * \param oldcrc Previous CRC16 value (referenced twice, beware of side effects) - */ -#define UPDCRC16(c, oldcrc) (crc16tab[((oldcrc) >> 8) ^ ((unsigned char)(c))] ^ ((oldcrc) << 8)) - - -#ifdef INLINE -/** - * \brief Compute the updated CRC16 value for one octet (macro version) - */ -INLINE uint16_t updcrc16(uint8_t c, uint16_t oldcrc) -{ - return crc16tab[(oldcrc >> 8) ^ c] ^ (oldcrc << 8); -} -#endif // INLINE - - -/** - * This function implements the CRC 16 calculation on a buffer. - * - * \param crc Current CRC16 value. - * \param buf The buffer to perform CRC calculation on. - * \param len The length of the Buffer. - * - * \return The updated CRC16 value. - */ -extern uint16_t crc16(uint16_t crc, const void *buf, size_t len); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* CRC_H */ diff --git a/algos/md2.c b/algos/md2.c deleted file mode 100644 index 53b44865..00000000 --- a/algos/md2.c +++ /dev/null @@ -1,377 +0,0 @@ -/** - * \file - * - * - * \brief MD2 Message-Digest algorithm. - * - * The MD2 algorithm work with a constant array of 256 permutationt - * defined in RFC1319. If you don't want to use a standard array of - * permutatione you can use a md2_perm() function that generate an - * array of 256 "casual" permutation. To swich from a standard array - * to md2_perm function you must chanche CONFIG_MD2_STD_PERM defined in - * appconfig.h. - * If you need to store array in program memory you must define - * a macro _PROGMEM (for more info see mware/pgm.h). - * - * - * \version $Id$ - * \author Daniele Basile - */ - -/*#* - *#* $Log$ - *#* Revision 1.17 2007/06/07 16:06:39 batt - *#* Fix some doxygen errors. - *#* - *#* Revision 1.16 2007/02/15 13:29:49 asterix - *#* Add MD2_DIGEST_LEN macro. - *#* - *#* Revision 1.15 2007/02/06 15:53:34 asterix - *#* Add ROTR macro in m2d_perm, add comments, typos. - *#* - *#* Revision 1.13 2007/02/05 18:44:42 asterix - *#* Add md2_perm function. - *#* - *#* Revision 1.12 2007/02/05 16:52:44 asterix - *#* Add define for harvard architecture. - *#* - *#* Revision 1.11 2007/02/02 18:15:31 asterix - *#* Add function MD2_test. Fix bug in md2_update function. - *#* - *#* Revision 1.9 2007/02/02 13:10:01 asterix - *#* Fix some bugs in md2_pad and md2_update fuction. - *#* - *#* Revision 1.8 2007/02/01 14:45:56 asterix - *#* Rewrite md2_update function and fix some bug. - *#* - *#* Revision 1.7 2007/01/31 18:04:15 asterix - *#* Write md2_end function - *#* - *#* Revision 1.4 2007/01/31 13:51:57 asterix - *#* Write md2_compute function. - *#* - *#* Revision 1.2 2007/01/30 17:31:44 asterix - *#* Add function prototypes. - *#* - *#* Revision 1.1 2007/01/30 15:53:26 batt - *#* Add first md2 skel. - *#* - *#*/ - -#include "md2.h" - -#include //memset(), memcpy(); -#include -#include //ASSERT() -#include //MIN(), countof(), ROTR(); -#include - - -#if CONFIG_MD2_STD_PERM - /* - * Official array of 256 byte pemutation contructed from digits of pi, defined - * in the RFC 1319. - */ - static const uint8_t PGM_ATTR md2_perm[256] = - { - 41, 46, 67, 201, 162, 216, 124, 1, 61, 54, 84, 161, 236, 240, 6, - 19, 98, 167, 5, 243, 192, 199, 115, 140, 152, 147, 43, 217, 188, - 76, 130, 202, 30, 155, 87, 60, 253, 212, 224, 22, 103, 66, 111, 24, - 138, 23, 229, 18, 190, 78, 196, 214, 218, 158, 222, 73, 160, 251, - 245, 142, 187, 47, 238, 122, 169, 104, 121, 145, 21, 178, 7, 63, - 148, 194, 16, 137, 11, 34, 95, 33, 128, 127, 93, 154, 90, 144, 50, - 39, 53, 62, 204, 231, 191, 247, 151, 3, 255, 25, 48, 179, 72, 165, - 181, 209, 215, 94, 146, 42, 172, 86, 170, 198, 79, 184, 56, 210, - 150, 164, 125, 182, 118, 252, 107, 226, 156, 116, 4, 241, 69, 157, - 112, 89, 100, 113, 135, 32, 134, 91, 207, 101, 230, 45, 168, 2, 27, - 96, 37, 173, 174, 176, 185, 246, 28, 70, 97, 105, 52, 64, 126, 15, - 85, 71, 163, 35, 221, 81, 175, 58, 195, 92, 249, 206, 186, 197, - 234, 38, 44, 83, 13, 110, 133, 40, 132, 9, 211, 223, 205, 244, 65, - 129, 77, 82, 106, 220, 55, 200, 108, 193, 171, 250, 36, 225, 123, - 8, 12, 189, 177, 74, 120, 136, 149, 139, 227, 99, 232, 109, 233, - 203, 213, 254, 59, 0, 29, 57, 242, 239, 183, 14, 102, 88, 208, 228, - 166, 119, 114, 248, 235, 117, 75, 10, 49, 68, 80, 180, 143, 237, - 31, 26, 219, 153, 141, 51, 159, 17, 131, 20 - }; - - #define MD2_PERM(x) PGM_READ_CHAR(&md2_perm[x]) -#else - /** - * Md2_perm() function generate an array of 256 "casual" permutation. - */ - - /** - * Costant define for computing an array of 256 "casual" permutation. - * \{ - */ - #define K1 5 - #define K2 3 - #define R 2 - #define X 172 - /*\}*/ - - static uint8_t md2_perm(uint8_t i) - { - - i = i * K1; - i = ROTR(i, R); - i ^= X; - i = i * K2; - - return i; - } - - #define MD2_PERM(x) md2_perm(x) - -#endif - - -/** - * Pad function. Put len_pad unsigned char in - * input block. - */ -static void md2_pad(void *_block, size_t len_pad) -{ - uint8_t *block; - - block = (uint8_t *)_block; - - ASSERT(len_pad <= CONFIG_MD2_BLOCK_LEN); - - /* - * Fill input block with len_pad char. - */ - memset(block, len_pad, len_pad); - -} - -static void md2_compute(void *_state, void *_checksum, void *_block) -{ - int i = 0; - uint16_t t = 0; - uint8_t compute_array[COMPUTE_ARRAY_LEN]; - uint8_t *state; - uint8_t *checksum; - uint8_t *block; - - state = (uint8_t *)_state; - checksum = (uint8_t *)_checksum; - block = (uint8_t *)_block; - - /* - * Copy state and checksum context in compute array. - */ - memcpy(compute_array, state, CONFIG_MD2_BLOCK_LEN); - memcpy(compute_array + CONFIG_MD2_BLOCK_LEN, block, CONFIG_MD2_BLOCK_LEN); - - /* - * Fill compute array with state XOR block - */ - for(i = 0; i < CONFIG_MD2_BLOCK_LEN; i++) - compute_array[i + (CONFIG_MD2_BLOCK_LEN * 2)] = state[i] ^ block[i]; - - /* - * Encryt block. - */ - for(i = 0; i < NUM_COMPUTE_ROUNDS; i++) - { - for(int j = 0; j < COMPUTE_ARRAY_LEN; j++) - { - compute_array[j] ^= MD2_PERM(t); - t = compute_array[j]; - } - - t = (t + i) & 0xff; //modulo 256. - } - /* - * Update checksum. - */ - t = checksum[CONFIG_MD2_BLOCK_LEN - 1]; - - for(i = 0; i < CONFIG_MD2_BLOCK_LEN; i++) - { - checksum[i] ^= MD2_PERM(block[i] ^ t); - t = checksum[i]; - } - - /* - * Update state and clean compute array. - */ - memcpy(state, compute_array, CONFIG_MD2_BLOCK_LEN); - memset(compute_array, 0, sizeof(compute_array)); -} - -/** - * Algorithm initialization. - * - * \param context empty context. - */ -void md2_init(Md2Context *context) -{ - - memset(context, 0, sizeof(Md2Context)); - -} - -/** - * Update block. - */ -void md2_update(Md2Context *context, const void *_block_in, size_t block_len) -{ - - const uint8_t *block_in; - size_t cpy_len; - - - block_in = (const uint8_t *)_block_in; - - while(block_len > 0) - { - /* - * Choose a number of block that fill input context buffer. - */ - cpy_len = MIN(block_len, CONFIG_MD2_BLOCK_LEN - context->counter); - - - /* - * Copy in the buffer input block. - */ - memcpy(&context->buffer[context->counter], block_in, cpy_len); - - /* - * Update a context counter, input block length and remaning - * context buffer block lenght. - */ - context->counter += cpy_len; - block_len -= cpy_len; - block_in += cpy_len; - - /* - * If buffer is full, compute it. - */ - if (context->counter >= CONFIG_MD2_BLOCK_LEN) - { - md2_compute(context->state, context->checksum, context->buffer); - context->counter = 0; - } - } - - -} -/** - * Ends an MD2 message digest operation. - * This fuction take an context and return a pointer - * to context state. - * - * \param context in input. - * \return a pointer to context state (message digest). - */ -uint8_t *md2_end(Md2Context *context) -{ - - uint8_t buf[CONFIG_MD2_BLOCK_LEN]; - - /* - * Fill remaning empty context buffer. - */ - md2_pad(buf, CONFIG_MD2_BLOCK_LEN - context->counter); - - /* - * Update context buffer and compute it. - */ - md2_update(context, buf, CONFIG_MD2_BLOCK_LEN - context->counter); - - /* - * Add context checksum to message input. - */ - md2_update(context, context->checksum, CONFIG_MD2_BLOCK_LEN); - - - return context->state; //return a pointer to message digest. -} -/** - * MD2 test fuction. - * This function test MD2 algorithm with a standard string specified - * in RFC 1319. - * - * \note This test work with official array of 256 byte pemutation - * contructed from digits of pi, defined in the RFC 1319. - * - */ -bool md2_test(void) -{ - - Md2Context context; - - const char *test[] = - { - "", - "message digest", - "abcdefghijklmnopqrstuvwxyz", - "12345678901234567890123456789012345678901234567890123456789012345678901234567890" - }; - - - const uint8_t *result[] = { - "\x83\x50\xe5\xa3\xe2\x4c\x15\x3d\xf2\x27\x5c\x9f\x80\x69\x27\x73", - "\xab\x4f\x49\x6b\xfb\x2a\x53\x0b\x21\x9f\xf3\x30\x31\xfe\x06\xb0", - "\x4e\x8d\xdf\xf3\x65\x02\x92\xab\x5a\x41\x08\xc3\xaa\x47\x94\x0b", - "\xd5\x97\x6f\x79\xd8\x3d\x3a\x0d\xc9\x80\x6c\x3c\x66\xf3\xef\xd8", - }; - - - for (int i = 0; i < countof(test); i++) - { - md2_init(&context); - md2_update(&context, test[i], strlen(test[i])); - - if(memcmp(result[i], md2_end(&context), MD2_DIGEST_LEN)) - return false; - } - - return true; -} - -#if 0 - -#include -int main(int argc, char * argv[]) -{ - - if(md2_test()) - printf("MD2 algorithm work well!\n"); - else - printf("MD2 algorithm doesn't work well.\n"); - -} - -#endif - diff --git a/algos/md2.h b/algos/md2.h deleted file mode 100644 index 44ba32c6..00000000 --- a/algos/md2.h +++ /dev/null @@ -1,98 +0,0 @@ -/** - * \file - * - * - * \brief MD2 Message-Digest algorithm. - * - * The algorithm takes as input a message of arbitrary length and produces - * as output a 128-bit message digest of the input. - * It is conjectured that it is computationally infeasible to produce - * two messages having the same message digest, or to produce any - * message having a given prespecified target message digest. - * - * - * - * \version $Id$ - * \author Daniele Basile - */ - -/*#* - *#* $Log$ - *#* Revision 1.7 2007/02/15 13:29:49 asterix - *#* Add MD2_DIGEST_LEN macro. - *#* - *#* Revision 1.6 2007/02/02 18:15:31 asterix - *#* Add function MD2_test. Fix bug in md2_update function. - *#* - *#* Revision 1.5 2007/02/02 15:37:45 asterix - *#* Change md2_end prototype. Remove a unneeded memcpy in md2_end. Add comments. - *#* - *#* Revision 1.4 2007/01/31 13:53:36 asterix - *#* Define COMPUTE_ARRAY_LEN. - *#* - *#* Revision 1.3 2007/01/31 11:16:48 asterix - *#* Defined constants for algorithm compute - *#* - *#* Revision 1.2 2007/01/30 17:31:44 asterix - *#* Add function prototypes. - *#* - *#* Revision 1.1 2007/01/30 15:53:26 batt - *#* Add first md2 skel. - *#* - *#*/ - -#ifndef ALGOS_MD2_H -#define ALGOS_MD2_H - -#include -#include - -#define NUM_COMPUTE_ROUNDS 18 ///< Number of compute rounds. -#define COMPUTE_ARRAY_LEN CONFIG_MD2_BLOCK_LEN * 3 ///< Lenght of compute array. -#define MD2_DIGEST_LEN CONFIG_MD2_BLOCK_LEN -/** - * Context for MD2 computation. - */ -typedef struct Md2Context -{ - uint8_t buffer[CONFIG_MD2_BLOCK_LEN]; ///< Input buffer. - uint8_t state[CONFIG_MD2_BLOCK_LEN]; ///< Current state buffer. - uint8_t checksum[CONFIG_MD2_BLOCK_LEN]; ///< Checksum. - size_t counter; ///< Counter of remaining bytes. - -} Md2Context; - -void md2_init(Md2Context *context); -void md2_update(Md2Context *context, const void *block_in, size_t block_len); -uint8_t *md2_end(Md2Context *context); -bool md2_test(void); - -#endif /* ALGOS_MD2_H */ diff --git a/algos/randpool.c b/algos/randpool.c deleted file mode 100644 index a32fdff4..00000000 --- a/algos/randpool.c +++ /dev/null @@ -1,298 +0,0 @@ -/** - * \file - * - * - * \brief API function for to manage entropy pool. - * - * \version $Id$ - * \author Daniele Basile - */ - -/*#* - *#* $Log$ - *#* Revision 1.20 2007/06/07 16:06:39 batt - *#* Fix some doxygen errors. - *#* - *#* Revision 1.19 2007/02/15 13:54:26 asterix - *#* Rename randpool_getN in randpool_get. Fix bug in randpool_get. - *#* - *#* Revision 1.17 2007/02/15 13:40:42 asterix - *#* Fix bug in randpool_add and randpool_strir. - *#* - *#* Revision 1.16 2007/02/13 15:11:37 asterix - *#* Typo. - *#* - *#* Revision 1.14 2007/02/13 09:57:12 asterix - *#* Add directive #if in struct EntropyPool, and remove #else in randpool_add. - *#* - *#* Revision 1.13 2007/02/12 18:25:34 asterix - *#* Fix bug in randpool_getN. - *#* - *#* Revision 1.12 2007/02/12 09:47:39 asterix - *#* Remove randpool_save. Add randpool_pool. - *#* - *#* Revision 1.10 2007/02/12 09:03:32 asterix - *#* Add CONFIG_RANDPOOL_TIMER macro to swich on or off timer support - *#* - *#* Revision 1.9 2007/02/09 17:58:09 asterix - *#* Add macro CONFIG_RANDPOOL_TIMER. - *#* - *#* Revision 1.6 2007/02/09 09:24:38 asterix - *#* Typos. Add data_len in randpool_add and n_byte in randpool_push pototypes. - *#* - *#* Revision 1.3 2007/02/08 14:25:29 asterix - *#* Write static funcion push_byte. - *#* - *#*/ - -#include "randpool.h" -#include "md2.h" - -#include //sprintf(); -#include //memset(), memcpy(); - -#include -#include //ASSERT() -#include //MIN(), ROUND_UP(); - -#if CONFIG_RANDPOOL_TIMER - #include //timer_clock(); -#endif - - - -/* - * Insert bytes in entropy pool, making a XOR of bytes present - * in entropy pool. - */ -static void randpool_push(EntropyPool *pool, void *_byte, size_t n_byte) -{ - size_t i = pool->pos_add; // Current number of byte insert in entropy pool. - uint8_t *byte; - - byte = (uint8_t *)_byte; - - /* - * Insert a bytes in entropy pool. - */ - for(int j = 0; j < n_byte; j++) - { - pool->pool_entropy[i] = pool->pool_entropy[i] ^ byte[j]; - i = (++i) % CONFIG_SIZE_ENTROPY_POOL; - } - - pool->pos_add = i; // Update a insert bytes. -} - - -/* - * This function stir entropy pool with MD2 function hash. - * - */ -static void randpool_stir(EntropyPool *pool) -{ - size_t entropy = pool->entropy; //Save current calue of entropy. - Md2Context context; - uint8_t tmp_buf[((sizeof(size_t) * 2) + sizeof(int)) * 2 + 1]; //Temporary buffer. - - md2_init(&context); //Init MD2 algorithm. - - randpool_add(pool, NULL, 0); - - for (int i = 0; i < (CONFIG_SIZE_ENTROPY_POOL / MD2_DIGEST_LEN); i++) - { - sprintf(tmp_buf, "%0x%0x%0x",pool->counter, i, pool->pos_add); - - /* - * Hash with MD2 algorithm the entropy pool. - */ - md2_update(&context, pool->pool_entropy, CONFIG_SIZE_ENTROPY_POOL); - - md2_update(&context, tmp_buf, sizeof(tmp_buf) - 1); - - /*Insert a message digest in entropy pool.*/ - randpool_push(pool, md2_end(&context), MD2_DIGEST_LEN); - - pool->counter = pool->counter + 1; - - } - - /*Insert in pool the difference between a two call of this function (see above).*/ - randpool_add(pool, NULL, 0); - - pool->entropy = entropy; //Restore old value of entropy. We haven't add entropy. -} - -/** - * Add \param entropy bits from \param data buffer to the entropy \param pool - */ -void randpool_add(EntropyPool *pool, void *data, size_t entropy) -{ - uint8_t sep[] = "\xaa\xaa\xaa\xaa"; // ?? - size_t data_len = ROUND_UP(entropy, 8) / 8; //Number of entropy byte in input. - - randpool_push(pool, data, data_len); //Insert data to entropy pool. - -#if CONFIG_RANDPOOL_TIMER - - ticks_t event = timer_clock(); - ticks_t delta; - - /*Difference of time between a two accese to entropy pool.*/ - delta = event - pool->last_counter; - - randpool_push(pool, &event, sizeof(ticks_t)); - randpool_push(pool, sep, sizeof(sep) - 1); // ?? - randpool_push(pool, &delta, sizeof(delta)); - - /* - * Count of number entropy bit add with delta. - */ - delta = delta & 0xff; - while(delta) - { - delta >>= 1; - entropy++; - } - - pool->last_counter = event; - -#endif - - pool->entropy += entropy; //Update a entropy of the pool. -} - -/** - * Randpool function initialization. - * The entropy pool can be initialize also with - * a previous entropy pool. - */ -void randpool_init(EntropyPool *pool, void *_data, size_t len) -{ - uint8_t *data; - - data = (uint8_t *)_data; - - memset(pool, 0, sizeof(EntropyPool)); - pool->pos_get = MD2_DIGEST_LEN; - -#if CONFIG_RANDPOOL_TIMER - pool->last_counter = timer_clock(); -#endif - - if(data) - { - /* - * Initialize a entropy pool with a - * previous pool, and assume all pool as - * entropy. - */ - len = MIN(len,(size_t)CONFIG_SIZE_ENTROPY_POOL); - memcpy(pool->pool_entropy, data, len); - pool->entropy = len; - } - -} - -/** - * Get the actual value of entropy. - */ -size_t randpool_size(EntropyPool *pool) -{ - return pool->entropy; -} - -/** - * Get \param n_byte from entropy pool. If n_byte is larger than number - * byte of entropy in entropy pool, randpool_get continue - * to generate pseudocasual value from previous state of - * pool. - * \param n_byte number fo bytes to read. - * \param pool is the pool entropy context. - * \param _data is the pointer to write the random data to. - */ -void randpool_get(EntropyPool *pool, void *_data, size_t n_byte) -{ - Md2Context context; - size_t i = pool->pos_get; - size_t n = n_byte; - size_t pos_write = 0; //Number of block has been written in data. - size_t len = MIN((size_t)MD2_DIGEST_LEN, n_byte); - uint8_t *data; - - data = (uint8_t *)_data; - - /* Test if i + CONFIG_MD2_BLOCK_LEN is inside of entropy pool.*/ - ASSERT((MD2_DIGEST_LEN + i) < CONFIG_SIZE_ENTROPY_POOL); - - md2_init(&context); - - while(n > 0) - { - - /*Hash previous state of pool*/ - md2_update(&context, &pool->pool_entropy[i], MD2_DIGEST_LEN); - - memcpy(&data[pos_write], md2_end(&context), len); - - pos_write += len; //Update number of block has been written in data. - n -= len; //Number of byte copied in data. - - len = MIN(n,(size_t)MD2_DIGEST_LEN); - - i = (i + MD2_DIGEST_LEN) % CONFIG_SIZE_ENTROPY_POOL; - - /* If we haven't more entropy pool to hash, we stir it.*/ - if(i < MD2_DIGEST_LEN) - { - randpool_stir(pool); - i = pool->pos_get; - } - - } - - pool->pos_get = i; //Current number of byte we get from pool. - pool->entropy -= n_byte; //Update a entropy. - - /*If we get all entropy entropy is 0*/ - if(pool->entropy < 0) - pool->entropy = 0; - -} - -/** - * Return a pointer to entropy pool. - */ -uint8_t *randpool_pool(EntropyPool *pool) -{ - return pool->pool_entropy; -} - diff --git a/algos/randpool.h b/algos/randpool.h deleted file mode 100644 index 18d13f4c..00000000 --- a/algos/randpool.h +++ /dev/null @@ -1,106 +0,0 @@ -/** - * \file - * - * - * \brief API function for to manage entropy pool. - * - * - * \version $Id$ - * \author Daniele Basile - */ - -/*#* - *#* $Log$ - *#* Revision 1.11 2007/02/15 13:54:26 asterix - *#* Rename randpool_getN in randpool_get. Fix bug in randpool_get. - *#* - *#* Revision 1.10 2007/02/15 13:40:42 asterix - *#* Fix bug in randpool_add and randpool_strir. - *#* - *#* Revision 1.9 2007/02/13 09:57:12 asterix - *#* Add directive #if in struct EntropyPool, and remove #else in randpool_add. - *#* - *#* Revision 1.8 2007/02/12 09:47:39 asterix - *#* Remove randpool_save. Add randpool_pool. - *#* - *#* Revision 1.6 2007/02/09 15:49:54 asterix - *#* Fix bug in randpool_stir and randpool_add. Typos. - *#* - *#* Revision 1.5 2007/02/09 09:24:38 asterix - *#* Typos. Add data_len in randpool_add and n_byte in randpool_push pototypes. - *#* - *#* Revision 1.4 2007/02/08 17:18:01 asterix - *#* Write add_data and stir function. Typos - *#* - *#* Revision 1.3 2007/02/08 14:25:56 asterix - *#* Typos. - *#* - *#* Revision 1.2 2007/02/08 11:53:03 asterix - *#* Add EntropyPool struct. Typos. - *#* - *#* Revision 1.1 2007/02/08 11:13:41 asterix - *#* Add function prototypes. - *#* - *#*/ - -#ifndef RANDPOOL_H -#define RANDPOOL_H - -#include -#include - - -/** - * Sturct data of entropy pool. - */ -typedef struct EntropyPool -{ - size_t entropy; ///< Actual value of entropy (byte). - size_t pos_add; ///< Number of byte idd in entropy pool. - size_t pos_get; ///< Number of byte get in entropy pool. - size_t counter; ///< Counter. - -#if CONFIG_RANDPOOL_TIMER - size_t last_counter; ///< Last timer value. -#endif - - uint8_t pool_entropy[CONFIG_SIZE_ENTROPY_POOL]; ///< Entropy pool. - -} EntropyPool; - - -void randpool_add(EntropyPool *pool, void *data, size_t entropy); -void randpool_init(EntropyPool *pool, void *_data, size_t len); -size_t randpool_size(EntropyPool *pool); -void randpool_get(EntropyPool *pool, void *data, size_t n_byte); -uint8_t *randpool_pool(EntropyPool *pool); - -#endif /* RANDPOOL_H */ diff --git a/algos/rotating_hash.h b/algos/rotating_hash.h deleted file mode 100644 index 123f2d3b..00000000 --- a/algos/rotating_hash.h +++ /dev/null @@ -1,82 +0,0 @@ -/** - * \file - * - * - * \brief Rotating Hash algorithm (interface). - * - * This is a simple yet powerfull checksum algorithm. - * Instead of just xor-ing the data, rotating hash - * circular shift the checksum 4 place left before xoring. - * This is a bit more stronger than simply sum the data. - * - * \version $Id$ - * - * \author Francesco Sacchi - */ - - -#ifndef ALGOS_ROTATING_H -#define ALGOS_ROTATING_H - -#include - -typedef uint16_t rotating_t; - - -/** - * Init rotating checksum. - */ -INLINE void rotating_init(rotating_t *rot) -{ - *rot = 0; -} - -/** - * Update checksum pointed by \c rot with \c c data. - */ -INLINE void rotating_update1(uint8_t c, rotating_t *rot) -{ - *rot = (*rot << 4) ^ (*rot >> 12) ^ c; -} - -/** - * Update checksum pointed by \c rot with data supplied in \c buf. - */ -INLINE void rotating_update(const void *_buf, size_t len, rotating_t *rot) -{ - const uint8_t *buf = (const uint8_t *)_buf; - - while (len--) - rotating_update1(*buf++, rot); -} - - -#endif // ALGOS_ROTATING_H diff --git a/algos/tea.c b/algos/tea.c deleted file mode 100644 index f67d4c5e..00000000 --- a/algos/tea.c +++ /dev/null @@ -1,145 +0,0 @@ -/** - * \file - * - * - * \brief TEA Tiny Encription Algorith functions (implementation). - * - * \version $Id$ - * \author Francesco Sacchi - * - * The Tiny Encryption Algorithm (TEA) by David Wheeler and Roger Needham - * of the Cambridge Computer Laboratory - * - * Placed in the Public Domain by David Wheeler and Roger Needham. - * - * **** ANSI C VERSION **** - * - * Notes: - * - * TEA is a Feistel cipher with XOR and and addition as the non-linear - * mixing functions. - * - * Takes 64 bits of data in v[0] and v[1]. Returns 64 bits of data in w[0] - * and w[1]. Takes 128 bits of key in k[0] - k[3]. - * - * TEA can be operated in any of the modes of DES. Cipher Block Chaining is, - * for example, simple to implement. - * - * n is the number of iterations. 32 is ample, 16 is sufficient, as few - * as eight may be OK. The algorithm achieves good dispersion after six - * iterations. The iteration count can be made variable if required. - * - * Note this is optimised for 32-bit CPUs with fast shift capabilities. It - * can very easily be ported to assembly language on most CPUs. - * - * delta is chosen to be the real part of (the golden ratio Sqrt(5/4) - - * 1/2 ~ 0.618034 multiplied by 2^32). - */ - -/*#* - *#* $Log$ - *#* Revision 1.2 2007/09/19 16:23:27 batt - *#* Fix doxygen warnings. - *#* - *#* Revision 1.1 2007/06/07 09:13:40 batt - *#* Add TEA enc/decryption algorithm. - *#* - *#* Revision 1.1 2007/01/10 17:30:10 batt - *#* Add cryptographic routines. - *#* - *#*/ - -#include "tea.h" -#include - -static uint32_t tea_func(uint32_t *in, uint32_t *sum, uint32_t *k) -{ - return ((*in << 4) + cpu_to_le32(k[0])) ^ (*in + *sum) ^ ((*in >> 5) + cpu_to_le32(k[1])); -} - -/** - * \brief TEA encryption function. - * This function encrypts v with k and returns the - * encrypted data in v. - * \param _v Array of two long values containing the data block. - * \param _k Array of four long values containing the key. - */ -void tea_enc(void *_v, void *_k) -{ - uint32_t y, z; - uint32_t sum = 0; - uint8_t n = ROUNDS; - uint32_t *v = (uint32_t *)_v; - uint32_t *k = (uint32_t *)_k; - - y=cpu_to_le32(v[0]); - z=cpu_to_le32(v[1]); - - while(n-- > 0) - { - sum += DELTA; - y += tea_func(&z, &sum, &(k[0])); - z += tea_func(&y, &sum, &(k[2])); - } - - v[0] = le32_to_cpu(y); - v[1] = le32_to_cpu(z); -} - -/** - * \brief TEA decryption function. - * This function decrypts v with k and returns the - * decrypted data in v. - * \param _v Array of two long values containing the data block. - * \param _k Array of four long values containing the key. - */ -void tea_dec(void *_v, void *_k) -{ - uint32_t y, z; - uint32_t sum = DELTA * ROUNDS; - uint8_t n = ROUNDS; - uint32_t *v = (uint32_t *)_v; - uint32_t *k = (uint32_t *)_k; - - y = cpu_to_le32(v[0]); - z = cpu_to_le32(v[1]); - - while(n-- > 0) - { - z -= tea_func(&y, &sum, &(k[2])); - y -= tea_func(&z, &sum, &(k[0])); - sum -= DELTA; - } - - v[0] = le32_to_cpu(y); - v[1] = le32_to_cpu(z); -} - diff --git a/algos/tea.h b/algos/tea.h deleted file mode 100644 index 6e4f935a..00000000 --- a/algos/tea.h +++ /dev/null @@ -1,57 +0,0 @@ -/** - * \file - * - * - * \brief TEA Tiny Encription Algorith functions (interface). - * - * \version $Id$ - * \author Francesco Sacchi - * - * Documentation for TEA is available at - * http://www.cl.cam.ac.uk/ftp/users/djw3/tea.ps. - */ - -#ifndef ALGOS_TEA_H -#define ALGOS_TEA_H - -#include - -#define TEA_KEY_LEN 16 //!< TEA key size. -#define TEA_BLOCK_LEN 8 //!< TEA block length. - -#define DELTA 0x9E3779B9 //!< Magic value. (Golden number * 2^31) -#define ROUNDS 32 //!< Number of rounds. - -void tea_enc(void *_v, void *_k); -void tea_dec(void *_v, void *_k); - -#endif /* ALGOS_TEA_H */ - diff --git a/app/randpool/randpool_demo.c b/app/randpool/randpool_demo.c index 612eda4c..3010cd10 100644 --- a/app/randpool/randpool_demo.c +++ b/app/randpool/randpool_demo.c @@ -60,8 +60,8 @@ #include #include #include -#include -#include +#include +#include #include #define LEN 256 //Size of buffer containing a random number. diff --git a/fs/battfs.h b/fs/battfs.h index 4b8fcbe8..33f241b3 100644 --- a/fs/battfs.h +++ b/fs/battfs.h @@ -42,7 +42,7 @@ #define FS_BATTFS_H #include // uintXX_t; STATIC_ASSERT -#include +#include typedef uint16_t filled_t; typedef uint16_t page_off_t; diff --git a/mware/xmodem.c b/mware/xmodem.c index e4104779..030783d3 100644 --- a/mware/xmodem.c +++ b/mware/xmodem.c @@ -51,7 +51,7 @@ #include #include /* for memset() */ #include -#include +#include #include