PageRenderTime 82ms CodeModel.GetById 40ms app.highlight 5ms RepoModel.GetById 35ms app.codeStats 0ms

/thirdparty/liblastfm2/src/fingerprint/Sha256.h

http://github.com/tomahawk-player/tomahawk
C++ Header | 180 lines | 69 code | 30 blank | 81 comment | 1 complexity | 597e2a1000eebe0bbc354ffeeb1e8044 MD5 | raw file
  1/*-
  2 * Copyright (c) 2001-2003 Allan Saddi <allan@saddi.com>
  3 * All rights reserved.
  4 *
  5 * Redistribution and use in source and binary forms, with or without
  6 * modification, are permitted provided that the following conditions
  7 * are met:
  8 * 1. Redistributions of source code must retain the above copyright
  9 *    notice, this list of conditions and the following disclaimer.
 10 * 2. Redistributions in binary form must reproduce the above copyright
 11 *    notice, this list of conditions and the following disclaimer in the
 12 *    documentation and/or other materials provided with the distribution.
 13 *
 14 * THIS SOFTWARE IS PROVIDED BY ALLAN SADDI AND HIS CONTRIBUTORS ``AS IS''
 15 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 17 * ARE DISCLAIMED.  IN NO EVENT SHALL ALLAN SADDI OR HIS CONTRIBUTORS BE
 18 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 19 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 20 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 21 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 22 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 23 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 24 * POSSIBILITY OF SUCH DAMAGE.
 25 *
 26 * $Id: sha256.h 348 2003-02-23 22:12:06Z asaddi $
 27 */
 28//
 29/////////// EXAMPLE /////////////////////////////////
 30//
 31// SHA256Context sha256;
 32// SHA256Init (&sha256);
 33//
 34// uint8_t* pBuffer = new uint8_t[SHA_BUFFER_SIZE + 7];
 35// // Ensure it is on a 64-bit boundary. 
 36// INTPTR offs;
 37// if ((offs = reinterpret_cast<INTPTR>(pBuffer) & 7L))
 38//    pBuffer += 8 - offs;
 39//
 40// unsigned int len;
 41//
 42// ifstream inFile("test.txt", ios::binary);
 43//
 44// for (;;)
 45// {
 46//    inFile.read( reinterpret_cast<char*>(pBuffer), SHA_BUFFER_SIZE );
 47//    len = inFile.gcount();
 48//
 49//    if ( len == 0)
 50//      break;
 51//
 52//    SHA256Update (&sha256, pBuffer, len);
 53// }
 54//
 55// uint8_t hash[SHA256_HASH_SIZE];
 56// SHA256Final (&sha256, hash);
 57//
 58// cout << "Hash: ";
 59// for (int i = 0; i < SHA256_HASH_SIZE; ++i)
 60//    printf ("%02x", hash[i]);
 61// cout << endl;
 62
 63
 64#ifndef _SHA256_H
 65#define _SHA256_H
 66
 67// ----------------------------------------------------------------------------
 68// ----------------------------------------------------------------------------
 69
 70/* Define to 1 if you have the <inttypes.h> header file. */
 71#ifndef WIN32
 72#define HAVE_INTTYPES_H 1
 73#endif
 74
 75/* Define to 1 if you have the <memory.h> header file. */
 76#define HAVE_MEMORY_H 1
 77
 78/* Define to 1 if you have the <stdint.h> header file. */
 79#ifndef WIN32
 80#define HAVE_STDINT_H 1
 81#endif
 82
 83/* Define to 1 if you have the <stdlib.h> header file. */
 84#define HAVE_STDLIB_H 1
 85
 86/* Define to 1 if you have the <strings.h> header file. */
 87#define HAVE_STRINGS_H 1
 88
 89/* Define to 1 if you have the <string.h> header file. */
 90#define HAVE_STRING_H 1
 91
 92/* Define to 1 if you have the `strerror' function. */
 93#ifndef WIN32
 94#define HAVE_STRERROR 1
 95#endif
 96
 97/* Define to 1 if you have the <sys/stat.h> header file. */
 98#define HAVE_SYS_STAT_H 1
 99
100/* Define to 1 if you have the <sys/types.h> header file. */
101#ifndef WIN32
102#define HAVE_SYS_TYPES_H 1
103#endif
104
105/* Define to 1 if you have the <unistd.h> header file. */
106#ifndef WIN32
107#define HAVE_UNISTD_H 1
108#endif
109
110/* Define to 1 if you have the ANSI C header files. */
111#define STDC_HEADERS 1
112
113/* Define as `__inline' if that's what the C compiler calls it, or to nothing
114   if it is not supported. */
115#ifdef WIN32
116#define inline __inline
117#endif
118
119/* Define to `unsigned' if <sys/types.h> does not define. */
120/* #undef size_t */
121
122#ifdef WIN32
123#define uint64_t  unsigned __int64
124#define uint32_t  unsigned int 
125#define uint8_t   unsigned char
126#endif // WIN32
127
128#ifdef WIN32
129#define INTPTR intptr_t
130#else
131#define INTPTR long
132#endif
133
134#define SHA_BUFFER_SIZE 65536
135
136// ----------------------------------------------------------------------------
137// ----------------------------------------------------------------------------
138
139
140#if HAVE_INTTYPES_H
141# include <inttypes.h>
142#else
143# if HAVE_STDINT_H
144#  include <stdint.h>
145# endif
146#endif
147
148#define SHA256_HASH_SIZE 32
149
150/* Hash size in 32-bit words */
151#define SHA256_HASH_WORDS 8
152
153struct _SHA256Context {
154  uint64_t totalLength;
155  uint32_t hash[SHA256_HASH_WORDS];
156  uint32_t bufferLength;
157  union {
158    uint32_t words[16];
159    uint8_t bytes[64];
160  } buffer;
161#ifdef RUNTIME_ENDIAN
162  int littleEndian;
163#endif /* RUNTIME_ENDIAN */
164};
165
166typedef struct _SHA256Context SHA256Context;
167
168#ifdef __cplusplus
169extern "C" {
170#endif
171
172void SHA256Init (SHA256Context *sc);
173void SHA256Update (SHA256Context *sc, const void *data, uint32_t len);
174void SHA256Final (SHA256Context *sc, uint8_t hash[SHA256_HASH_SIZE]);
175
176#ifdef __cplusplus
177}
178#endif
179
180#endif /* !_SHA256_H */