Port of TI's CC3100 Websock camera demo. Using FreeRTOS, mbedTLS, also parts of Arducam for cams ov5642 and 0v2640. Can also use MT9D111. Work in progress. Be warned some parts maybe a bit flacky. This is for Seeed Arch max only, for an M3, see the demo for CM3 using the 0v5642 aducam mini.

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers md5.h Source File

md5.h

Go to the documentation of this file.
00001 /**
00002  * \file md5.h
00003  *
00004  * \brief MD5 message digest algorithm (hash function)
00005  *
00006  *  Copyright (C) 2006-2013, ARM Limited, All Rights Reserved
00007  *
00008  *  This file is part of mbed TLS (https://tls.mbed.org)
00009  *
00010  *  This program is free software; you can redistribute it and/or modify
00011  *  it under the terms of the GNU General Public License as published by
00012  *  the Free Software Foundation; either version 2 of the License, or
00013  *  (at your option) any later version.
00014  *
00015  *  This program is distributed in the hope that it will be useful,
00016  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  *  GNU General Public License for more details.
00019  *
00020  *  You should have received a copy of the GNU General Public License along
00021  *  with this program; if not, write to the Free Software Foundation, Inc.,
00022  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00023  */
00024 #ifndef POLARSSL_MD5_H
00025 #define POLARSSL_MD5_H
00026 
00027 #if !defined(POLARSSL_CONFIG_FILE)
00028 #include "config.h"
00029 #else
00030 #include POLARSSL_CONFIG_FILE
00031 #endif
00032 
00033 #include <stddef.h>
00034 
00035 #if defined(_MSC_VER) && !defined(EFIX64) && !defined(EFI32)
00036 #include <basetsd.h>
00037 typedef UINT32 uint32_t;
00038 #else
00039 #include <inttypes.h>
00040 #endif
00041 
00042 #define POLARSSL_ERR_MD5_FILE_IO_ERROR                 -0x0074  /**< Read/write error in file. */
00043 
00044 #if !defined(POLARSSL_MD5_ALT)
00045 // Regular implementation
00046 //
00047 
00048 #ifdef __cplusplus
00049 extern "C" {
00050 #endif
00051 
00052 /**
00053  * \brief          MD5 context structure
00054  */
00055 typedef struct
00056 {
00057     uint32_t total[2];          /*!< number of bytes processed  */
00058     uint32_t state[4];          /*!< intermediate digest state  */
00059     unsigned char buffer[64];   /*!< data block being processed */
00060 
00061     unsigned char ipad[64];     /*!< HMAC: inner padding        */
00062     unsigned char opad[64];     /*!< HMAC: outer padding        */
00063 }
00064 md5_context;
00065 
00066 /**
00067  * \brief          Initialize MD5 context
00068  *
00069  * \param ctx      MD5 context to be initialized
00070  */
00071 void md5_init( md5_context *ctx );
00072 
00073 /**
00074  * \brief          Clear MD5 context
00075  *
00076  * \param ctx      MD5 context to be cleared
00077  */
00078 void md5_free( md5_context *ctx );
00079 
00080 /**
00081  * \brief          MD5 context setup
00082  *
00083  * \param ctx      context to be initialized
00084  */
00085 void md5_starts( md5_context *ctx );
00086 
00087 /**
00088  * \brief          MD5 process buffer
00089  *
00090  * \param ctx      MD5 context
00091  * \param input    buffer holding the  data
00092  * \param ilen     length of the input data
00093  */
00094 void md5_update( md5_context *ctx, const unsigned char *input, size_t ilen );
00095 
00096 /**
00097  * \brief          MD5 final digest
00098  *
00099  * \param ctx      MD5 context
00100  * \param output   MD5 checksum result
00101  */
00102 void md5_finish( md5_context *ctx, unsigned char output[16] );
00103 
00104 /* Internal use */
00105 void md5_process( md5_context *ctx, const unsigned char data[64] );
00106 
00107 #ifdef __cplusplus
00108 }
00109 #endif
00110 
00111 #else  /* POLARSSL_MD5_ALT */
00112 #include "md5_alt.h"
00113 #endif /* POLARSSL_MD5_ALT */
00114 
00115 #ifdef __cplusplus
00116 extern "C" {
00117 #endif
00118 
00119 /**
00120  * \brief          Output = MD5( input buffer )
00121  *
00122  * \param input    buffer holding the  data
00123  * \param ilen     length of the input data
00124  * \param output   MD5 checksum result
00125  */
00126 void md5( const unsigned char *input, size_t ilen, unsigned char output[16] );
00127 
00128 /**
00129  * \brief          Output = MD5( file contents )
00130  *
00131  * \param path     input file name
00132  * \param output   MD5 checksum result
00133  *
00134  * \return         0 if successful, or POLARSSL_ERR_MD5_FILE_IO_ERROR
00135  */
00136 int md5_file( const char *path, unsigned char output[16] );
00137 
00138 /**
00139  * \brief          MD5 HMAC context setup
00140  *
00141  * \param ctx      HMAC context to be initialized
00142  * \param key      HMAC secret key
00143  * \param keylen   length of the HMAC key
00144  */
00145 void md5_hmac_starts( md5_context *ctx,
00146                       const unsigned char *key, size_t keylen );
00147 
00148 /**
00149  * \brief          MD5 HMAC process buffer
00150  *
00151  * \param ctx      HMAC context
00152  * \param input    buffer holding the  data
00153  * \param ilen     length of the input data
00154  */
00155 void md5_hmac_update( md5_context *ctx,
00156                       const unsigned char *input, size_t ilen );
00157 
00158 /**
00159  * \brief          MD5 HMAC final digest
00160  *
00161  * \param ctx      HMAC context
00162  * \param output   MD5 HMAC checksum result
00163  */
00164 void md5_hmac_finish( md5_context *ctx, unsigned char output[16] );
00165 
00166 /**
00167  * \brief          MD5 HMAC context reset
00168  *
00169  * \param ctx      HMAC context to be reset
00170  */
00171 void md5_hmac_reset( md5_context *ctx );
00172 
00173 /**
00174  * \brief          Output = HMAC-MD5( hmac key, input buffer )
00175  *
00176  * \param key      HMAC secret key
00177  * \param keylen   length of the HMAC key
00178  * \param input    buffer holding the  data
00179  * \param ilen     length of the input data
00180  * \param output   HMAC-MD5 result
00181  */
00182 void md5_hmac( const unsigned char *key, size_t keylen,
00183                const unsigned char *input, size_t ilen,
00184                unsigned char output[16] );
00185 
00186 /**
00187  * \brief          Checkup routine
00188  *
00189  * \return         0 if successful, or 1 if the test failed
00190  */
00191 int md5_self_test( int verbose );
00192 
00193 #ifdef __cplusplus
00194 }
00195 #endif
00196 
00197 #endif /* md5.h */
00198