TI's CC3100 websocket camera demo with Arducam mini ov5642 and freertos. Should work with other M3's. Work in progress test demo.

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers sha512.h Source File

sha512.h

Go to the documentation of this file.
00001 /**
00002  * \file sha512.h
00003  *
00004  * \brief SHA-384 and SHA-512 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_SHA512_H
00025 #define POLARSSL_SHA512_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(__WATCOMC__)
00036   typedef unsigned __int64 uint64_t;
00037 #else
00038   #include <inttypes.h>
00039 #endif
00040 
00041 #define POLARSSL_ERR_SHA512_FILE_IO_ERROR              -0x007A  /**< Read/write error in file. */
00042 
00043 #if !defined(POLARSSL_SHA512_ALT)
00044 // Regular implementation
00045 //
00046 
00047 #ifdef __cplusplus
00048 extern "C" {
00049 #endif
00050 
00051 /**
00052  * \brief          SHA-512 context structure
00053  */
00054 typedef struct
00055 {
00056     uint64_t total[2];          /*!< number of bytes processed  */
00057     uint64_t state[8];          /*!< intermediate digest state  */
00058     unsigned char buffer[128];  /*!< data block being processed */
00059 
00060     unsigned char ipad[128];    /*!< HMAC: inner padding        */
00061     unsigned char opad[128];    /*!< HMAC: outer padding        */
00062     int is384 ;                  /*!< 0 => SHA-512, else SHA-384 */
00063 }
00064 sha512_context;
00065 
00066 /**
00067  * \brief          Initialize SHA-512 context
00068  *
00069  * \param ctx      SHA-512 context to be initialized
00070  */
00071 void sha512_init( sha512_context *ctx );
00072 
00073 /**
00074  * \brief          Clear SHA-512 context
00075  *
00076  * \param ctx      SHA-512 context to be cleared
00077  */
00078 void sha512_free( sha512_context *ctx );
00079 
00080 /**
00081  * \brief          SHA-512 context setup
00082  *
00083  * \param ctx      context to be initialized
00084  * \param is384    0 = use SHA512, 1 = use SHA384
00085  */
00086 void sha512_starts( sha512_context *ctx, int is384 );
00087 
00088 /**
00089  * \brief          SHA-512 process buffer
00090  *
00091  * \param ctx      SHA-512 context
00092  * \param input    buffer holding the  data
00093  * \param ilen     length of the input data
00094  */
00095 void sha512_update( sha512_context *ctx, const unsigned char *input,
00096                     size_t ilen );
00097 
00098 /**
00099  * \brief          SHA-512 final digest
00100  *
00101  * \param ctx      SHA-512 context
00102  * \param output   SHA-384/512 checksum result
00103  */
00104 void sha512_finish( sha512_context *ctx, unsigned char output[64] );
00105 
00106 #ifdef __cplusplus
00107 }
00108 #endif
00109 
00110 #else  /* POLARSSL_SHA512_ALT */
00111 #include "sha512_alt.h"
00112 #endif /* POLARSSL_SHA512_ALT */
00113 
00114 #ifdef __cplusplus
00115 extern "C" {
00116 #endif
00117 
00118 /**
00119  * \brief          Output = SHA-512( input buffer )
00120  *
00121  * \param input    buffer holding the  data
00122  * \param ilen     length of the input data
00123  * \param output   SHA-384/512 checksum result
00124  * \param is384    0 = use SHA512, 1 = use SHA384
00125  */
00126 void sha512( const unsigned char *input, size_t ilen,
00127              unsigned char output[64], int is384 );
00128 
00129 /**
00130  * \brief          Output = SHA-512( file contents )
00131  *
00132  * \param path     input file name
00133  * \param output   SHA-384/512 checksum result
00134  * \param is384    0 = use SHA512, 1 = use SHA384
00135  *
00136  * \return         0 if successful, or POLARSSL_ERR_SHA512_FILE_IO_ERROR
00137  */
00138 int sha512_file( const char *path, unsigned char output[64], int is384 );
00139 
00140 /**
00141  * \brief          SHA-512 HMAC context setup
00142  *
00143  * \param ctx      HMAC context to be initialized
00144  * \param is384    0 = use SHA512, 1 = use SHA384
00145  * \param key      HMAC secret key
00146  * \param keylen   length of the HMAC key
00147  */
00148 void sha512_hmac_starts( sha512_context *ctx, const unsigned char *key,
00149                          size_t keylen, int is384 );
00150 
00151 /**
00152  * \brief          SHA-512 HMAC process buffer
00153  *
00154  * \param ctx      HMAC context
00155  * \param input    buffer holding the  data
00156  * \param ilen     length of the input data
00157  */
00158 void sha512_hmac_update( sha512_context *ctx, const unsigned char *input,
00159                          size_t ilen );
00160 
00161 /**
00162  * \brief          SHA-512 HMAC final digest
00163  *
00164  * \param ctx      HMAC context
00165  * \param output   SHA-384/512 HMAC checksum result
00166  */
00167 void sha512_hmac_finish( sha512_context *ctx, unsigned char output[64] );
00168 
00169 /**
00170  * \brief          SHA-512 HMAC context reset
00171  *
00172  * \param ctx      HMAC context to be reset
00173  */
00174 void sha512_hmac_reset( sha512_context *ctx );
00175 
00176 /**
00177  * \brief          Output = HMAC-SHA-512( hmac key, input buffer )
00178  *
00179  * \param key      HMAC secret key
00180  * \param keylen   length of the HMAC key
00181  * \param input    buffer holding the  data
00182  * \param ilen     length of the input data
00183  * \param output   HMAC-SHA-384/512 result
00184  * \param is384    0 = use SHA512, 1 = use SHA384
00185  */
00186 void sha512_hmac( const unsigned char *key, size_t keylen,
00187                 const unsigned char *input, size_t ilen,
00188                 unsigned char output[64], int is384 );
00189 
00190 /**
00191  * \brief          Checkup routine
00192  *
00193  * \return         0 if successful, or 1 if the test failed
00194  */
00195 int sha512_self_test( int verbose );
00196 
00197 /* Internal use */
00198 void sha512_process( sha512_context *ctx, const unsigned char data[128] );
00199 
00200 #ifdef __cplusplus
00201 }
00202 #endif
00203 
00204 #endif /* sha512.h */
00205