Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:02:16

0001 /* sha3.h
0002 
0003    The sha3 hash function (aka Keccak).
0004 
0005    Copyright (C) 2012 Niels Möller
0006 
0007    This file is part of GNU Nettle.
0008 
0009    GNU Nettle is free software: you can redistribute it and/or
0010    modify it under the terms of either:
0011 
0012      * the GNU Lesser General Public License as published by the Free
0013        Software Foundation; either version 3 of the License, or (at your
0014        option) any later version.
0015 
0016    or
0017 
0018      * the GNU General Public License as published by the Free
0019        Software Foundation; either version 2 of the License, or (at your
0020        option) any later version.
0021 
0022    or both in parallel, as here.
0023 
0024    GNU Nettle is distributed in the hope that it will be useful,
0025    but WITHOUT ANY WARRANTY; without even the implied warranty of
0026    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0027    General Public License for more details.
0028 
0029    You should have received copies of the GNU General Public License and
0030    the GNU Lesser General Public License along with this program.  If
0031    not, see http://www.gnu.org/licenses/.
0032 */
0033  
0034 #ifndef NETTLE_SHA3_H_INCLUDED
0035 #define NETTLE_SHA3_H_INCLUDED
0036 
0037 #include "nettle-types.h"
0038 
0039 #ifdef __cplusplus
0040 extern "C" {
0041 #endif
0042 
0043 /* Name mangling */
0044 #define sha3_permute nettle_sha3_permute
0045 #define sha3_224_init nettle_sha3_224_init
0046 #define sha3_224_update nettle_sha3_224_update
0047 #define sha3_224_digest nettle_sha3_224_digest
0048 #define sha3_256_init nettle_sha3_256_init
0049 #define sha3_256_update nettle_sha3_256_update
0050 #define sha3_256_digest nettle_sha3_256_digest
0051 #define sha3_256_shake nettle_sha3_256_shake
0052 #define sha3_384_init nettle_sha3_384_init
0053 #define sha3_384_update nettle_sha3_384_update
0054 #define sha3_384_digest nettle_sha3_384_digest
0055 #define sha3_512_init nettle_sha3_512_init
0056 #define sha3_512_update nettle_sha3_512_update
0057 #define sha3_512_digest nettle_sha3_512_digest
0058 
0059 /* Indicates that SHA3 is the NIST FIPS 202 version. */
0060 #define NETTLE_SHA3_FIPS202 1
0061 
0062 /* The sha3 state is a 5x5 matrix of 64-bit words. In the notation of
0063    Keccak description, S[x,y] is element x + 5*y, so if x is
0064    interpreted as the row index and y the column index, it is stored
0065    in column-major order. */
0066 #define SHA3_STATE_LENGTH 25
0067 
0068 /* The "width" is 1600 bits or 200 octets */
0069 struct sha3_state
0070 {
0071   uint64_t a[SHA3_STATE_LENGTH];
0072 };
0073 
0074 void
0075 sha3_permute (struct sha3_state *state);
0076 
0077 /* The "capacity" is set to 2*(digest size), 512 bits or 64 octets.
0078    The "rate" is the width - capacity, or width - 2 * (digest
0079    size). */
0080 
0081 #define SHA3_224_DIGEST_SIZE 28
0082 #define SHA3_224_BLOCK_SIZE 144
0083 
0084 #define SHA3_256_DIGEST_SIZE 32
0085 #define SHA3_256_BLOCK_SIZE 136
0086 
0087 #define SHA3_384_DIGEST_SIZE 48
0088 #define SHA3_384_BLOCK_SIZE 104
0089 
0090 #define SHA3_512_DIGEST_SIZE 64
0091 #define SHA3_512_BLOCK_SIZE 72
0092 
0093 /* For backwards compatibility */
0094 #define SHA3_224_DATA_SIZE SHA3_224_BLOCK_SIZE
0095 #define SHA3_256_DATA_SIZE SHA3_256_BLOCK_SIZE
0096 #define SHA3_384_DATA_SIZE SHA3_384_BLOCK_SIZE
0097 #define SHA3_512_DATA_SIZE SHA3_512_BLOCK_SIZE
0098 
0099 struct sha3_224_ctx
0100 {
0101   struct sha3_state state;
0102   unsigned index;
0103   uint8_t block[SHA3_224_BLOCK_SIZE];
0104 };
0105 
0106 void
0107 sha3_224_init (struct sha3_224_ctx *ctx);
0108 
0109 void
0110 sha3_224_update (struct sha3_224_ctx *ctx,
0111          size_t length,
0112          const uint8_t *data);
0113 
0114 void
0115 sha3_224_digest(struct sha3_224_ctx *ctx,
0116         size_t length,
0117         uint8_t *digest);
0118 
0119 struct sha3_256_ctx
0120 {
0121   struct sha3_state state;
0122   unsigned index;
0123   uint8_t block[SHA3_256_BLOCK_SIZE];
0124 };
0125 
0126 void
0127 sha3_256_init (struct sha3_256_ctx *ctx);
0128 
0129 void
0130 sha3_256_update (struct sha3_256_ctx *ctx,
0131          size_t length,
0132          const uint8_t *data);
0133 
0134 void
0135 sha3_256_digest(struct sha3_256_ctx *ctx,
0136         size_t length,
0137         uint8_t *digest);
0138 
0139 /* Alternative digest function implementing shake256, with arbitrary
0140    digest size */
0141 void
0142 sha3_256_shake(struct sha3_256_ctx *ctx,
0143            size_t length,
0144            uint8_t *digest);
0145 
0146 struct sha3_384_ctx
0147 {
0148   struct sha3_state state;
0149   unsigned index;
0150   uint8_t block[SHA3_384_BLOCK_SIZE];
0151 };
0152 
0153 void
0154 sha3_384_init (struct sha3_384_ctx *ctx);
0155 
0156 void
0157 sha3_384_update (struct sha3_384_ctx *ctx,
0158          size_t length,
0159          const uint8_t *data);
0160 
0161 void
0162 sha3_384_digest(struct sha3_384_ctx *ctx,
0163         size_t length,
0164         uint8_t *digest);
0165 
0166 struct sha3_512_ctx
0167 {
0168   struct sha3_state state;
0169   unsigned index;
0170   uint8_t block[SHA3_512_BLOCK_SIZE];
0171 };
0172 
0173 void
0174 sha3_512_init (struct sha3_512_ctx *ctx);
0175 
0176 void
0177 sha3_512_update (struct sha3_512_ctx *ctx,
0178          size_t length,
0179          const uint8_t *data);
0180 
0181 void
0182 sha3_512_digest(struct sha3_512_ctx *ctx,
0183         size_t length,
0184         uint8_t *digest);
0185 
0186 #ifdef __cplusplus
0187 }
0188 #endif
0189 
0190 #endif /* NETTLE_SHA3_H_INCLUDED */