This short program illustrates how to use the DS130x_I2C library. My objective is to share the same RTC with Microchip 18F MCU.

Dependencies:   mbed DebugLibrary

Committer:
Yann
Date:
Wed Feb 09 13:57:49 2011 +0000
Revision:
0:f30e2135b0db
V0.0.0.1

Who changed what in which revision?

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