~registry/dolphin-emu/triforce

« back to all changes in this revision

Viewing changes to Externals/polarssl/include/polarssl/sha4.h

  • Committer: Sérgio Benjamim
  • Date: 2015-02-13 05:54:40 UTC
  • Revision ID: sergio_br2@yahoo.com.br-20150213055440-ey2rt3sjpy27km78
Dolphin Triforce branch from code.google, commit b957980 (4.0-315).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * \file sha4.h
 
3
 *
 
4
 * \brief SHA-384 and SHA-512 cryptographic hash function
 
5
 *
 
6
 *  Copyright (C) 2006-2013, Brainspark B.V.
 
7
 *
 
8
 *  This file is part of PolarSSL (http://www.polarssl.org)
 
9
 *  Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
 
10
 *
 
11
 *  All rights reserved.
 
12
 *
 
13
 *  This program is free software; you can redistribute it and/or modify
 
14
 *  it under the terms of the GNU General Public License as published by
 
15
 *  the Free Software Foundation; either version 2 of the License, or
 
16
 *  (at your option) any later version.
 
17
 *
 
18
 *  This program is distributed in the hope that it will be useful,
 
19
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
20
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
21
 *  GNU General Public License for more details.
 
22
 *
 
23
 *  You should have received a copy of the GNU General Public License along
 
24
 *  with this program; if not, write to the Free Software Foundation, Inc.,
 
25
 *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 
26
 */
 
27
#ifndef POLARSSL_SHA4_H
 
28
#define POLARSSL_SHA4_H
 
29
 
 
30
#include "config.h"
 
31
 
 
32
#include <string.h>
 
33
 
 
34
#if defined(_MSC_VER) || defined(__WATCOMC__)
 
35
  #define UL64(x) x##ui64
 
36
  typedef unsigned __int64 uint64_t;
 
37
#else
 
38
  #include <inttypes.h>
 
39
  #define UL64(x) x##ULL
 
40
#endif
 
41
 
 
42
#define POLARSSL_ERR_SHA4_FILE_IO_ERROR                -0x007A  /**< Read/write error in file. */
 
43
 
 
44
#if !defined(POLARSSL_SHA1_ALT)
 
45
// Regular implementation
 
46
//
 
47
 
 
48
/**
 
49
 * \brief          SHA-512 context structure
 
50
 */
 
51
typedef struct
 
52
{
 
53
    uint64_t total[2];          /*!< number of bytes processed  */
 
54
    uint64_t state[8];          /*!< intermediate digest state  */
 
55
    unsigned char buffer[128];  /*!< data block being processed */
 
56
 
 
57
    unsigned char ipad[128];    /*!< HMAC: inner padding        */
 
58
    unsigned char opad[128];    /*!< HMAC: outer padding        */
 
59
    int is384;                  /*!< 0 => SHA-512, else SHA-384 */
 
60
}
 
61
sha4_context;
 
62
 
 
63
#ifdef __cplusplus
 
64
extern "C" {
 
65
#endif
 
66
 
 
67
/**
 
68
 * \brief          SHA-512 context setup
 
69
 *
 
70
 * \param ctx      context to be initialized
 
71
 * \param is384    0 = use SHA512, 1 = use SHA384
 
72
 */
 
73
void sha4_starts( sha4_context *ctx, int is384 );
 
74
 
 
75
/**
 
76
 * \brief          SHA-512 process buffer
 
77
 *
 
78
 * \param ctx      SHA-512 context
 
79
 * \param input    buffer holding the  data
 
80
 * \param ilen     length of the input data
 
81
 */
 
82
void sha4_update( sha4_context *ctx, const unsigned char *input, size_t ilen );
 
83
 
 
84
/**
 
85
 * \brief          SHA-512 final digest
 
86
 *
 
87
 * \param ctx      SHA-512 context
 
88
 * \param output   SHA-384/512 checksum result
 
89
 */
 
90
void sha4_finish( sha4_context *ctx, unsigned char output[64] );
 
91
 
 
92
#ifdef __cplusplus
 
93
}
 
94
#endif
 
95
 
 
96
#else  /* POLARSSL_SHA4_ALT */
 
97
#include "sha4_alt.h"
 
98
#endif /* POLARSSL_SHA4_ALT */
 
99
 
 
100
#ifdef __cplusplus
 
101
extern "C" {
 
102
#endif
 
103
 
 
104
/**
 
105
 * \brief          Output = SHA-512( input buffer )
 
106
 *
 
107
 * \param input    buffer holding the  data
 
108
 * \param ilen     length of the input data
 
109
 * \param output   SHA-384/512 checksum result
 
110
 * \param is384    0 = use SHA512, 1 = use SHA384
 
111
 */
 
112
void sha4( const unsigned char *input, size_t ilen,
 
113
           unsigned char output[64], int is384 );
 
114
 
 
115
/**
 
116
 * \brief          Output = SHA-512( file contents )
 
117
 *
 
118
 * \param path     input file name
 
119
 * \param output   SHA-384/512 checksum result
 
120
 * \param is384    0 = use SHA512, 1 = use SHA384
 
121
 *
 
122
 * \return         0 if successful, or POLARSSL_ERR_SHA4_FILE_IO_ERROR
 
123
 */
 
124
int sha4_file( const char *path, unsigned char output[64], int is384 );
 
125
 
 
126
/**
 
127
 * \brief          SHA-512 HMAC context setup
 
128
 *
 
129
 * \param ctx      HMAC context to be initialized
 
130
 * \param is384    0 = use SHA512, 1 = use SHA384
 
131
 * \param key      HMAC secret key
 
132
 * \param keylen   length of the HMAC key
 
133
 */
 
134
void sha4_hmac_starts( sha4_context *ctx, const unsigned char *key, size_t keylen,
 
135
                       int is384 );
 
136
 
 
137
/**
 
138
 * \brief          SHA-512 HMAC process buffer
 
139
 *
 
140
 * \param ctx      HMAC context
 
141
 * \param input    buffer holding the  data
 
142
 * \param ilen     length of the input data
 
143
 */
 
144
void sha4_hmac_update( sha4_context *ctx, const unsigned char *input, size_t ilen );
 
145
 
 
146
/**
 
147
 * \brief          SHA-512 HMAC final digest
 
148
 *
 
149
 * \param ctx      HMAC context
 
150
 * \param output   SHA-384/512 HMAC checksum result
 
151
 */
 
152
void sha4_hmac_finish( sha4_context *ctx, unsigned char output[64] );
 
153
 
 
154
/**
 
155
 * \brief          SHA-512 HMAC context reset
 
156
 *
 
157
 * \param ctx      HMAC context to be reset
 
158
 */
 
159
void sha4_hmac_reset( sha4_context *ctx );
 
160
 
 
161
/**
 
162
 * \brief          Output = HMAC-SHA-512( hmac key, input buffer )
 
163
 *
 
164
 * \param key      HMAC secret key
 
165
 * \param keylen   length of the HMAC key
 
166
 * \param input    buffer holding the  data
 
167
 * \param ilen     length of the input data
 
168
 * \param output   HMAC-SHA-384/512 result
 
169
 * \param is384    0 = use SHA512, 1 = use SHA384
 
170
 */
 
171
void sha4_hmac( const unsigned char *key, size_t keylen,
 
172
                const unsigned char *input, size_t ilen,
 
173
                unsigned char output[64], int is384 );
 
174
 
 
175
/**
 
176
 * \brief          Checkup routine
 
177
 *
 
178
 * \return         0 if successful, or 1 if the test failed
 
179
 */
 
180
int sha4_self_test( int verbose );
 
181
 
 
182
#ifdef __cplusplus
 
183
}
 
184
#endif
 
185
 
 
186
#endif /* sha4.h */