Example program with HTTPServer and sensor data streaming over TCPSockets, using Donatien Garnier's Net APIs and services code on top of LWIP. Files StreamServer.h and .cpp encapsulate streaming over TCPSockets. Broadcast is done by sendToAll(), and all incoming data is echoed back to the client. Echo code can be replaced with some remote control of the streaming interface. See main() that shows how to periodically send some data to all subscribed clients. To subscribe, a client should open a socket at <mbed_ip> port 123. I used few lines in TCL code to set up a quick sink for the data. HTTP files are served on port 80 concurrently to the streaming.

Dependencies:   mbed

Committer:
iva2k
Date:
Sat Jun 12 06:01:50 2010 +0000
Revision:
0:e614f7875b60

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
iva2k 0:e614f7875b60 1 /**
iva2k 0:e614f7875b60 2 * \file sha1.h
iva2k 0:e614f7875b60 3 *
iva2k 0:e614f7875b60 4 * Copyright (C) 2006-2010, Paul Bakker <polarssl_maintainer at polarssl.org>
iva2k 0:e614f7875b60 5 * All rights reserved.
iva2k 0:e614f7875b60 6 *
iva2k 0:e614f7875b60 7 * This program is free software; you can redistribute it and/or modify
iva2k 0:e614f7875b60 8 * it under the terms of the GNU General Public License as published by
iva2k 0:e614f7875b60 9 * the Free Software Foundation; either version 2 of the License, or
iva2k 0:e614f7875b60 10 * (at your option) any later version.
iva2k 0:e614f7875b60 11 *
iva2k 0:e614f7875b60 12 * This program is distributed in the hope that it will be useful,
iva2k 0:e614f7875b60 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
iva2k 0:e614f7875b60 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
iva2k 0:e614f7875b60 15 * GNU General Public License for more details.
iva2k 0:e614f7875b60 16 *
iva2k 0:e614f7875b60 17 * You should have received a copy of the GNU General Public License along
iva2k 0:e614f7875b60 18 * with this program; if not, write to the Free Software Foundation, Inc.,
iva2k 0:e614f7875b60 19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
iva2k 0:e614f7875b60 20 */
iva2k 0:e614f7875b60 21 #ifndef POLARSSL_SHA1_H
iva2k 0:e614f7875b60 22 #define POLARSSL_SHA1_H
iva2k 0:e614f7875b60 23
iva2k 0:e614f7875b60 24 /**
iva2k 0:e614f7875b60 25 * \brief SHA-1 context structure
iva2k 0:e614f7875b60 26 */
iva2k 0:e614f7875b60 27 typedef struct
iva2k 0:e614f7875b60 28 {
iva2k 0:e614f7875b60 29 unsigned long total[2]; /*!< number of bytes processed */
iva2k 0:e614f7875b60 30 unsigned long state[5]; /*!< intermediate digest state */
iva2k 0:e614f7875b60 31 unsigned char buffer[64]; /*!< data block being processed */
iva2k 0:e614f7875b60 32
iva2k 0:e614f7875b60 33 unsigned char ipad[64]; /*!< HMAC: inner padding */
iva2k 0:e614f7875b60 34 unsigned char opad[64]; /*!< HMAC: outer padding */
iva2k 0:e614f7875b60 35 }
iva2k 0:e614f7875b60 36 sha1_context;
iva2k 0:e614f7875b60 37
iva2k 0:e614f7875b60 38 #ifdef __cplusplus
iva2k 0:e614f7875b60 39 extern "C" {
iva2k 0:e614f7875b60 40 #endif
iva2k 0:e614f7875b60 41
iva2k 0:e614f7875b60 42 /**
iva2k 0:e614f7875b60 43 * \brief SHA-1 context setup
iva2k 0:e614f7875b60 44 *
iva2k 0:e614f7875b60 45 * \param ctx context to be initialized
iva2k 0:e614f7875b60 46 */
iva2k 0:e614f7875b60 47 void sha1_starts( sha1_context *ctx );
iva2k 0:e614f7875b60 48
iva2k 0:e614f7875b60 49 /**
iva2k 0:e614f7875b60 50 * \brief SHA-1 process buffer
iva2k 0:e614f7875b60 51 *
iva2k 0:e614f7875b60 52 * \param ctx SHA-1 context
iva2k 0:e614f7875b60 53 * \param input buffer holding the data
iva2k 0:e614f7875b60 54 * \param ilen length of the input data
iva2k 0:e614f7875b60 55 */
iva2k 0:e614f7875b60 56 void sha1_update( sha1_context *ctx, const unsigned char *input, int ilen );
iva2k 0:e614f7875b60 57
iva2k 0:e614f7875b60 58 /**
iva2k 0:e614f7875b60 59 * \brief SHA-1 final digest
iva2k 0:e614f7875b60 60 *
iva2k 0:e614f7875b60 61 * \param ctx SHA-1 context
iva2k 0:e614f7875b60 62 * \param output SHA-1 checksum result
iva2k 0:e614f7875b60 63 */
iva2k 0:e614f7875b60 64 void sha1_finish( sha1_context *ctx, unsigned char output[20] );
iva2k 0:e614f7875b60 65
iva2k 0:e614f7875b60 66 /**
iva2k 0:e614f7875b60 67 * \brief Output = SHA-1( input buffer )
iva2k 0:e614f7875b60 68 *
iva2k 0:e614f7875b60 69 * \param input buffer holding the data
iva2k 0:e614f7875b60 70 * \param ilen length of the input data
iva2k 0:e614f7875b60 71 * \param output SHA-1 checksum result
iva2k 0:e614f7875b60 72 */
iva2k 0:e614f7875b60 73 void sha1( const unsigned char *input, int ilen, unsigned char output[20] );
iva2k 0:e614f7875b60 74
iva2k 0:e614f7875b60 75 #if 0 //No need for that
iva2k 0:e614f7875b60 76 /**
iva2k 0:e614f7875b60 77 * \brief Output = SHA-1( file contents )
iva2k 0:e614f7875b60 78 *
iva2k 0:e614f7875b60 79 * \param path input file name
iva2k 0:e614f7875b60 80 * \param output SHA-1 checksum result
iva2k 0:e614f7875b60 81 *
iva2k 0:e614f7875b60 82 * \return 0 if successful, 1 if fopen failed,
iva2k 0:e614f7875b60 83 * or 2 if fread failed
iva2k 0:e614f7875b60 84 */
iva2k 0:e614f7875b60 85 int sha1_file( const char *path, unsigned char output[20] );
iva2k 0:e614f7875b60 86 #endif
iva2k 0:e614f7875b60 87
iva2k 0:e614f7875b60 88 /**
iva2k 0:e614f7875b60 89 * \brief SHA-1 HMAC context setup
iva2k 0:e614f7875b60 90 *
iva2k 0:e614f7875b60 91 * \param ctx HMAC context to be initialized
iva2k 0:e614f7875b60 92 * \param key HMAC secret key
iva2k 0:e614f7875b60 93 * \param keylen length of the HMAC key
iva2k 0:e614f7875b60 94 */
iva2k 0:e614f7875b60 95 void sha1_hmac_starts( sha1_context *ctx, const unsigned char *key, int keylen );
iva2k 0:e614f7875b60 96
iva2k 0:e614f7875b60 97 /**
iva2k 0:e614f7875b60 98 * \brief SHA-1 HMAC process buffer
iva2k 0:e614f7875b60 99 *
iva2k 0:e614f7875b60 100 * \param ctx HMAC context
iva2k 0:e614f7875b60 101 * \param input buffer holding the data
iva2k 0:e614f7875b60 102 * \param ilen length of the input data
iva2k 0:e614f7875b60 103 */
iva2k 0:e614f7875b60 104 void sha1_hmac_update( sha1_context *ctx, const unsigned char *input, int ilen );
iva2k 0:e614f7875b60 105
iva2k 0:e614f7875b60 106 /**
iva2k 0:e614f7875b60 107 * \brief SHA-1 HMAC final digest
iva2k 0:e614f7875b60 108 *
iva2k 0:e614f7875b60 109 * \param ctx HMAC context
iva2k 0:e614f7875b60 110 * \param output SHA-1 HMAC checksum result
iva2k 0:e614f7875b60 111 */
iva2k 0:e614f7875b60 112 void sha1_hmac_finish( sha1_context *ctx, unsigned char output[20] );
iva2k 0:e614f7875b60 113
iva2k 0:e614f7875b60 114 /**
iva2k 0:e614f7875b60 115 * \brief SHA-1 HMAC context reset
iva2k 0:e614f7875b60 116 *
iva2k 0:e614f7875b60 117 * \param ctx HMAC context to be reset
iva2k 0:e614f7875b60 118 */
iva2k 0:e614f7875b60 119 void sha1_hmac_reset( sha1_context *ctx );
iva2k 0:e614f7875b60 120
iva2k 0:e614f7875b60 121 /**
iva2k 0:e614f7875b60 122 * \brief Output = HMAC-SHA-1( hmac key, input buffer )
iva2k 0:e614f7875b60 123 *
iva2k 0:e614f7875b60 124 * \param key HMAC secret key
iva2k 0:e614f7875b60 125 * \param keylen length of the HMAC key
iva2k 0:e614f7875b60 126 * \param input buffer holding the data
iva2k 0:e614f7875b60 127 * \param ilen length of the input data
iva2k 0:e614f7875b60 128 * \param output HMAC-SHA-1 result
iva2k 0:e614f7875b60 129 */
iva2k 0:e614f7875b60 130 void sha1_hmac( const unsigned char *key, int keylen,
iva2k 0:e614f7875b60 131 const unsigned char *input, int ilen,
iva2k 0:e614f7875b60 132 unsigned char output[20] );
iva2k 0:e614f7875b60 133
iva2k 0:e614f7875b60 134 /**
iva2k 0:e614f7875b60 135 * \brief Checkup routine
iva2k 0:e614f7875b60 136 *
iva2k 0:e614f7875b60 137 * \return 0 if successful, or 1 if the test failed
iva2k 0:e614f7875b60 138 */
iva2k 0:e614f7875b60 139 int sha1_self_test( int verbose );
iva2k 0:e614f7875b60 140
iva2k 0:e614f7875b60 141 #ifdef __cplusplus
iva2k 0:e614f7875b60 142 }
iva2k 0:e614f7875b60 143 #endif
iva2k 0:e614f7875b60 144
iva2k 0:e614f7875b60 145 #endif /* sha1.h */