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 sha1.h Source File

sha1.h

Go to the documentation of this file.
00001 /**
00002  * \file sha1.h
00003  *
00004  * \brief SHA-1 cryptographic hash function
00005  *
00006  *  Copyright (C) 2006-2014, 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_SHA1_H
00025 #define POLARSSL_SHA1_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_SHA1_FILE_IO_ERROR                -0x0076  /**< Read/write error in file. */
00043 
00044 #if !defined(POLARSSL_SHA1_ALT)
00045 // Regular implementation
00046 //
00047 
00048 #ifdef __cplusplus
00049 extern "C" {
00050 #endif
00051 
00052 /**
00053  * \brief          SHA-1 context structure
00054  */
00055 typedef struct
00056 {
00057     uint32_t total[2];          /*!< number of bytes processed  */
00058     uint32_t state[5];          /*!< 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 sha1_context;
00065 
00066 /**
00067  * \brief          Initialize SHA-1 context
00068  *
00069  * \param ctx      SHA-1 context to be initialized
00070  */
00071 void sha1_init( sha1_context *ctx );
00072 
00073 /**
00074  * \brief          Clear SHA-1 context
00075  *
00076  * \param ctx      SHA-1 context to be cleared
00077  */
00078 void sha1_free( sha1_context *ctx );
00079 
00080 /**
00081  * \brief          SHA-1 context setup
00082  *
00083  * \param ctx      context to be initialized
00084  */
00085 void sha1_starts( sha1_context *ctx );
00086 
00087 /**
00088  * \brief          SHA-1 process buffer
00089  *
00090  * \param ctx      SHA-1 context
00091  * \param input    buffer holding the  data
00092  * \param ilen     length of the input data
00093  */
00094 void sha1_update( sha1_context *ctx, const unsigned char *input, size_t ilen );
00095 
00096 /**
00097  * \brief          SHA-1 final digest
00098  *
00099  * \param ctx      SHA-1 context
00100  * \param output   SHA-1 checksum result
00101  */
00102 void sha1_finish( sha1_context *ctx, unsigned char output[20] );
00103 
00104 /* Internal use */
00105 void sha1_process( sha1_context *ctx, const unsigned char data[64] );
00106 
00107 #ifdef __cplusplus
00108 }
00109 #endif
00110 
00111 #else  /* POLARSSL_SHA1_ALT */
00112 #include "sha1_alt.h"
00113 #endif /* POLARSSL_SHA1_ALT */
00114 
00115 #ifdef __cplusplus
00116 extern "C" {
00117 #endif
00118 
00119 /**
00120  * \brief          Output = SHA-1( input buffer )
00121  *
00122  * \param input    buffer holding the  data
00123  * \param ilen     length of the input data
00124  * \param output   SHA-1 checksum result
00125  */
00126 void sha1( const unsigned char *input, size_t ilen, unsigned char output[20] );
00127 
00128 /**
00129  * \brief          Output = SHA-1( file contents )
00130  *
00131  * \param path     input file name
00132  * \param output   SHA-1 checksum result
00133  *
00134  * \return         0 if successful, or POLARSSL_ERR_SHA1_FILE_IO_ERROR
00135  */
00136 int sha1_file( const char *path, unsigned char output[20] );
00137 
00138 /**
00139  * \brief          SHA-1 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 sha1_hmac_starts( sha1_context *ctx, const unsigned char *key,
00146                        size_t keylen );
00147 
00148 /**
00149  * \brief          SHA-1 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 sha1_hmac_update( sha1_context *ctx, const unsigned char *input,
00156                        size_t ilen );
00157 
00158 /**
00159  * \brief          SHA-1 HMAC final digest
00160  *
00161  * \param ctx      HMAC context
00162  * \param output   SHA-1 HMAC checksum result
00163  */
00164 void sha1_hmac_finish( sha1_context *ctx, unsigned char output[20] );
00165 
00166 /**
00167  * \brief          SHA-1 HMAC context reset
00168  *
00169  * \param ctx      HMAC context to be reset
00170  */
00171 void sha1_hmac_reset( sha1_context *ctx );
00172 
00173 /**
00174  * \brief          Output = HMAC-SHA-1( 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-SHA-1 result
00181  */
00182 void sha1_hmac( const unsigned char *key, size_t keylen,
00183                 const unsigned char *input, size_t ilen,
00184                 unsigned char output[20] );
00185 
00186 /**
00187  * \brief          Checkup routine
00188  *
00189  * \return         0 if successful, or 1 if the test failed
00190  */
00191 int sha1_self_test( int verbose );
00192 
00193 #ifdef __cplusplus
00194 }
00195 #endif
00196 
00197 #endif /* sha1.h */
00198