--- /dev/null
+/**
+ * \file
+ * <!--
+ * This file is part of BeRTOS.
+ *
+ * Bertos 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.
+ *
+ * This program 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 this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * As a special exception, you may use this file as part of a free software
+ * library without restriction. Specifically, if other files instantiate
+ * templates or use macros or inline functions from this file, or you compile
+ * this file and link it with other files to produce an executable, this
+ * file does not by itself cause the resulting executable to be covered by
+ * the GNU General Public License. This exception does not however
+ * invalidate any other reasons why the executable file might be covered by
+ * the GNU General Public License.
+ *
+ * Copyright 2003,2004 Develer S.r.l. (http://www.develer.com/)
+ * Copyright 1999 Bernardo Innocenti <bernie@develer.com>
+ *
+ * -->
+ *
+ * \brief CRC table and support routines
+ *
+ * \version $Id$
+ * \author Bernardo Innocenti <bernie@develer.com>
+ */
+
+#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;
+}
+
--- /dev/null
+/**
+ * \file
+ * <!--
+ * This file is part of BeRTOS.
+ *
+ * Bertos 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.
+ *
+ * This program 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 this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * As a special exception, you may use this file as part of a free software
+ * library without restriction. Specifically, if other files instantiate
+ * templates or use macros or inline functions from this file, or you compile
+ * this file and link it with other files to produce an executable, this
+ * file does not by itself cause the resulting executable to be covered by
+ * the GNU General Public License. This exception does not however
+ * invalidate any other reasons why the executable file might be covered by
+ * the GNU General Public License.
+ *
+ * Copyright 2003, 2004 Develer S.r.l. (http://www.develer.com/)
+ * Copyright 1999 Bernardo Innocenti <bernie@develer.com>
+ *
+ * -->
+ *
+ * \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 <bernie@develer.com>
+ */
+
+#ifndef CRC_H
+#define CRC_H
+
+#include <cfg/compiler.h>
+
+#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 */
--- /dev/null
+/**
+ * \file
+ * <!--
+ * This file is part of BeRTOS.
+ *
+ * Bertos 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.
+ *
+ * This program 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 this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * As a special exception, you may use this file as part of a free software
+ * library without restriction. Specifically, if other files instantiate
+ * templates or use macros or inline functions from this file, or you compile
+ * this file and link it with other files to produce an executable, this
+ * file does not by itself cause the resulting executable to be covered by
+ * the GNU General Public License. This exception does not however
+ * invalidate any other reasons why the executable file might be covered by
+ * the GNU General Public License.
+ *
+ * Copyright 2007 Develer S.r.l. (http://www.develer.com/)
+ *
+ * -->
+ *
+ * \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 <asterix@develer.com>
+ */
+
+/*#*
+ *#* $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 <string.h> //memset(), memcpy();
+#include <cfg/compiler.h>
+#include <cfg/debug.h> //ASSERT()
+#include <cfg/macros.h> //MIN(), countof(), ROTR();
+#include <mware/pgm.h>
+
+
+#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 <stdio.h>
+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
+
--- /dev/null
+/**
+ * \file
+ * <!--
+ * This file is part of BeRTOS.
+ *
+ * Bertos 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.
+ *
+ * This program 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 this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * As a special exception, you may use this file as part of a free software
+ * library without restriction. Specifically, if other files instantiate
+ * templates or use macros or inline functions from this file, or you compile
+ * this file and link it with other files to produce an executable, this
+ * file does not by itself cause the resulting executable to be covered by
+ * the GNU General Public License. This exception does not however
+ * invalidate any other reasons why the executable file might be covered by
+ * the GNU General Public License.
+ *
+ * Copyright 2007 Develer S.r.l. (http://www.develer.com/)
+ *
+ * -->
+ *
+ * \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 <asterix@develer.com>
+ */
+
+/*#*
+ *#* $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 <cfg/compiler.h>
+#include <appconfig.h>
+
+#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 */
--- /dev/null
+/**
+ * \file
+ * <!--
+ * This file is part of BeRTOS.
+ *
+ * Bertos 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.
+ *
+ * This program 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 this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * As a special exception, you may use this file as part of a free software
+ * library without restriction. Specifically, if other files instantiate
+ * templates or use macros or inline functions from this file, or you compile
+ * this file and link it with other files to produce an executable, this
+ * file does not by itself cause the resulting executable to be covered by
+ * the GNU General Public License. This exception does not however
+ * invalidate any other reasons why the executable file might be covered by
+ * the GNU General Public License.
+ *
+ * Copyright 2007 Develer S.r.l. (http://www.develer.com/)
+ *
+ * -->
+ *
+ * \brief API function for to manage entropy pool.
+ *
+ * \version $Id$
+ * \author Daniele Basile <asterix@develer.com>
+ */
+
+/*#*
+ *#* $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 <stdio.h> //sprintf();
+#include <string.h> //memset(), memcpy();
+
+#include <cfg/compiler.h>
+#include <cfg/debug.h> //ASSERT()
+#include <cfg/macros.h> //MIN(), ROUND_UP();
+
+#if CONFIG_RANDPOOL_TIMER
+ #include <drv/timer.h> //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;
+}
+
--- /dev/null
+/**
+ * \file
+ * <!--
+ * This file is part of BeRTOS.
+ *
+ * Bertos 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.
+ *
+ * This program 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 this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * As a special exception, you may use this file as part of a free software
+ * library without restriction. Specifically, if other files instantiate
+ * templates or use macros or inline functions from this file, or you compile
+ * this file and link it with other files to produce an executable, this
+ * file does not by itself cause the resulting executable to be covered by
+ * the GNU General Public License. This exception does not however
+ * invalidate any other reasons why the executable file might be covered by
+ * the GNU General Public License.
+ *
+ * Copyright 2007 Develer S.r.l. (http://www.develer.com/);
+ *
+ * -->
+ *
+ * \brief API function for to manage entropy pool.
+ *
+ *
+ * \version $Id$
+ * \author Daniele Basile <asterix@develer.com>
+ */
+
+/*#*
+ *#* $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 <cfg/compiler.h>
+#include <appconfig.h>
+
+
+/**
+ * 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 */
--- /dev/null
+/**
+ * \file
+ * <!--
+ * This file is part of BeRTOS.
+ *
+ * Bertos 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.
+ *
+ * This program 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 this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * As a special exception, you may use this file as part of a free software
+ * library without restriction. Specifically, if other files instantiate
+ * templates or use macros or inline functions from this file, or you compile
+ * this file and link it with other files to produce an executable, this
+ * file does not by itself cause the resulting executable to be covered by
+ * the GNU General Public License. This exception does not however
+ * invalidate any other reasons why the executable file might be covered by
+ * the GNU General Public License.
+ *
+ * Copyright 2007 Develer S.r.l. (http://www.develer.com/)
+ * All Rights Reserved.
+ * -->
+ *
+ * \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 <batt@develer.com>
+ */
+
+
+#ifndef ALGOS_ROTATING_H
+#define ALGOS_ROTATING_H
+
+#include <cfg/compiler.h>
+
+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
--- /dev/null
+/**
+ * \file
+ * <!--
+ * This file is part of BeRTOS.
+ *
+ * Bertos 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.
+ *
+ * This program 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 this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * As a special exception, you may use this file as part of a free software
+ * library without restriction. Specifically, if other files instantiate
+ * templates or use macros or inline functions from this file, or you compile
+ * this file and link it with other files to produce an executable, this
+ * file does not by itself cause the resulting executable to be covered by
+ * the GNU General Public License. This exception does not however
+ * invalidate any other reasons why the executable file might be covered by
+ * the GNU General Public License.
+ *
+ * Copyright 2006 Develer S.r.l. (http://www.develer.com/)
+ *
+ * -->
+ *
+ * \brief TEA Tiny Encription Algorith functions (implementation).
+ *
+ * \version $Id$
+ * \author Francesco Sacchi <batt@develer.com>
+ *
+ * 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 <mware/byteorder.h>
+
+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 <EM>v</EM> with <EM>k</EM> and returns the
+ * encrypted data in <EM>v</EM>.
+ * \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 <EM>v</EM> with <EM>k</EM> and returns the
+ * decrypted data in <EM>v</EM>.
+ * \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);
+}
+
--- /dev/null
+/**
+ * \file
+ * <!--
+ * This file is part of BeRTOS.
+ *
+ * Bertos 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.
+ *
+ * This program 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 this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * As a special exception, you may use this file as part of a free software
+ * library without restriction. Specifically, if other files instantiate
+ * templates or use macros or inline functions from this file, or you compile
+ * this file and link it with other files to produce an executable, this
+ * file does not by itself cause the resulting executable to be covered by
+ * the GNU General Public License. This exception does not however
+ * invalidate any other reasons why the executable file might be covered by
+ * the GNU General Public License.
+ *
+ * Copyright 2006 Develer S.r.l. (http://www.develer.com/)
+ *
+ * -->
+ *
+ * \brief TEA Tiny Encription Algorith functions (interface).
+ *
+ * \version $Id$
+ * \author Francesco Sacchi <batt@develer.com>
+ *
+ * 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 <cfg/compiler.h>
+
+#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 */
+
+++ /dev/null
-/**
- * \file
- * <!--
- * This file is part of BeRTOS.
- *
- * Bertos 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.
- *
- * This program 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 this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * As a special exception, you may use this file as part of a free software
- * library without restriction. Specifically, if other files instantiate
- * templates or use macros or inline functions from this file, or you compile
- * this file and link it with other files to produce an executable, this
- * file does not by itself cause the resulting executable to be covered by
- * the GNU General Public License. This exception does not however
- * invalidate any other reasons why the executable file might be covered by
- * the GNU General Public License.
- *
- * Copyright 2003,2004 Develer S.r.l. (http://www.develer.com/)
- * Copyright 1999 Bernardo Innocenti <bernie@develer.com>
- *
- * -->
- *
- * \brief CRC table and support routines
- *
- * \version $Id$
- * \author Bernardo Innocenti <bernie@develer.com>
- */
-
-#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;
-}
-
+++ /dev/null
-/**
- * \file
- * <!--
- * This file is part of BeRTOS.
- *
- * Bertos 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.
- *
- * This program 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 this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * As a special exception, you may use this file as part of a free software
- * library without restriction. Specifically, if other files instantiate
- * templates or use macros or inline functions from this file, or you compile
- * this file and link it with other files to produce an executable, this
- * file does not by itself cause the resulting executable to be covered by
- * the GNU General Public License. This exception does not however
- * invalidate any other reasons why the executable file might be covered by
- * the GNU General Public License.
- *
- * Copyright 2003, 2004 Develer S.r.l. (http://www.develer.com/)
- * Copyright 1999 Bernardo Innocenti <bernie@develer.com>
- *
- * -->
- *
- * \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 <bernie@develer.com>
- */
-
-#ifndef CRC_H
-#define CRC_H
-
-#include <cfg/compiler.h>
-
-#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 */
+++ /dev/null
-/**
- * \file
- * <!--
- * This file is part of BeRTOS.
- *
- * Bertos 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.
- *
- * This program 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 this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * As a special exception, you may use this file as part of a free software
- * library without restriction. Specifically, if other files instantiate
- * templates or use macros or inline functions from this file, or you compile
- * this file and link it with other files to produce an executable, this
- * file does not by itself cause the resulting executable to be covered by
- * the GNU General Public License. This exception does not however
- * invalidate any other reasons why the executable file might be covered by
- * the GNU General Public License.
- *
- * Copyright 2007 Develer S.r.l. (http://www.develer.com/)
- *
- * -->
- *
- * \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 <asterix@develer.com>
- */
-
-/*#*
- *#* $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 <string.h> //memset(), memcpy();
-#include <cfg/compiler.h>
-#include <cfg/debug.h> //ASSERT()
-#include <cfg/macros.h> //MIN(), countof(), ROTR();
-#include <mware/pgm.h>
-
-
-#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 <stdio.h>
-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
-
+++ /dev/null
-/**
- * \file
- * <!--
- * This file is part of BeRTOS.
- *
- * Bertos 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.
- *
- * This program 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 this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * As a special exception, you may use this file as part of a free software
- * library without restriction. Specifically, if other files instantiate
- * templates or use macros or inline functions from this file, or you compile
- * this file and link it with other files to produce an executable, this
- * file does not by itself cause the resulting executable to be covered by
- * the GNU General Public License. This exception does not however
- * invalidate any other reasons why the executable file might be covered by
- * the GNU General Public License.
- *
- * Copyright 2007 Develer S.r.l. (http://www.develer.com/)
- *
- * -->
- *
- * \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 <asterix@develer.com>
- */
-
-/*#*
- *#* $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 <cfg/compiler.h>
-#include <appconfig.h>
-
-#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 */
+++ /dev/null
-/**
- * \file
- * <!--
- * This file is part of BeRTOS.
- *
- * Bertos 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.
- *
- * This program 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 this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * As a special exception, you may use this file as part of a free software
- * library without restriction. Specifically, if other files instantiate
- * templates or use macros or inline functions from this file, or you compile
- * this file and link it with other files to produce an executable, this
- * file does not by itself cause the resulting executable to be covered by
- * the GNU General Public License. This exception does not however
- * invalidate any other reasons why the executable file might be covered by
- * the GNU General Public License.
- *
- * Copyright 2007 Develer S.r.l. (http://www.develer.com/)
- *
- * -->
- *
- * \brief API function for to manage entropy pool.
- *
- * \version $Id$
- * \author Daniele Basile <asterix@develer.com>
- */
-
-/*#*
- *#* $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 <stdio.h> //sprintf();
-#include <string.h> //memset(), memcpy();
-
-#include <cfg/compiler.h>
-#include <cfg/debug.h> //ASSERT()
-#include <cfg/macros.h> //MIN(), ROUND_UP();
-
-#if CONFIG_RANDPOOL_TIMER
- #include <drv/timer.h> //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;
-}
-
+++ /dev/null
-/**
- * \file
- * <!--
- * This file is part of BeRTOS.
- *
- * Bertos 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.
- *
- * This program 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 this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * As a special exception, you may use this file as part of a free software
- * library without restriction. Specifically, if other files instantiate
- * templates or use macros or inline functions from this file, or you compile
- * this file and link it with other files to produce an executable, this
- * file does not by itself cause the resulting executable to be covered by
- * the GNU General Public License. This exception does not however
- * invalidate any other reasons why the executable file might be covered by
- * the GNU General Public License.
- *
- * Copyright 2007 Develer S.r.l. (http://www.develer.com/);
- *
- * -->
- *
- * \brief API function for to manage entropy pool.
- *
- *
- * \version $Id$
- * \author Daniele Basile <asterix@develer.com>
- */
-
-/*#*
- *#* $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 <cfg/compiler.h>
-#include <appconfig.h>
-
-
-/**
- * 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 */
+++ /dev/null
-/**
- * \file
- * <!--
- * This file is part of BeRTOS.
- *
- * Bertos 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.
- *
- * This program 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 this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * As a special exception, you may use this file as part of a free software
- * library without restriction. Specifically, if other files instantiate
- * templates or use macros or inline functions from this file, or you compile
- * this file and link it with other files to produce an executable, this
- * file does not by itself cause the resulting executable to be covered by
- * the GNU General Public License. This exception does not however
- * invalidate any other reasons why the executable file might be covered by
- * the GNU General Public License.
- *
- * Copyright 2007 Develer S.r.l. (http://www.develer.com/)
- * All Rights Reserved.
- * -->
- *
- * \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 <batt@develer.com>
- */
-
-
-#ifndef ALGOS_ROTATING_H
-#define ALGOS_ROTATING_H
-
-#include <cfg/compiler.h>
-
-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
+++ /dev/null
-/**
- * \file
- * <!--
- * This file is part of BeRTOS.
- *
- * Bertos 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.
- *
- * This program 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 this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * As a special exception, you may use this file as part of a free software
- * library without restriction. Specifically, if other files instantiate
- * templates or use macros or inline functions from this file, or you compile
- * this file and link it with other files to produce an executable, this
- * file does not by itself cause the resulting executable to be covered by
- * the GNU General Public License. This exception does not however
- * invalidate any other reasons why the executable file might be covered by
- * the GNU General Public License.
- *
- * Copyright 2006 Develer S.r.l. (http://www.develer.com/)
- *
- * -->
- *
- * \brief TEA Tiny Encription Algorith functions (implementation).
- *
- * \version $Id$
- * \author Francesco Sacchi <batt@develer.com>
- *
- * 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 <mware/byteorder.h>
-
-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 <EM>v</EM> with <EM>k</EM> and returns the
- * encrypted data in <EM>v</EM>.
- * \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 <EM>v</EM> with <EM>k</EM> and returns the
- * decrypted data in <EM>v</EM>.
- * \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);
-}
-
+++ /dev/null
-/**
- * \file
- * <!--
- * This file is part of BeRTOS.
- *
- * Bertos 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.
- *
- * This program 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 this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * As a special exception, you may use this file as part of a free software
- * library without restriction. Specifically, if other files instantiate
- * templates or use macros or inline functions from this file, or you compile
- * this file and link it with other files to produce an executable, this
- * file does not by itself cause the resulting executable to be covered by
- * the GNU General Public License. This exception does not however
- * invalidate any other reasons why the executable file might be covered by
- * the GNU General Public License.
- *
- * Copyright 2006 Develer S.r.l. (http://www.develer.com/)
- *
- * -->
- *
- * \brief TEA Tiny Encription Algorith functions (interface).
- *
- * \version $Id$
- * \author Francesco Sacchi <batt@develer.com>
- *
- * 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 <cfg/compiler.h>
-
-#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 */
-
#include <string.h>
#include <cfg/compiler.h>
#include <drv/timer.h>
-#include <algos/md2.h>
-#include <algos/randpool.h>
+#include <algo/md2.h>
+#include <algo/randpool.h>
#include <unistd.h>
#define LEN 256 //Size of buffer containing a random number.
#define FS_BATTFS_H
#include <cfg/compiler.h> // uintXX_t; STATIC_ASSERT
-#include <algos/rotating_hash.h>
+#include <algo/rotating_hash.h>
typedef uint16_t filled_t;
typedef uint16_t page_off_t;
#include <appconfig.h>
#include <string.h> /* for memset() */
#include <drv/ser.h>
-#include <algos/crc.h>
+#include <algo/crc.h>
#include <cfg/debug.h>