Back to home page

EIC code displayed by LXR

 
 

    


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

0001 /* sha2.h
0002 
0003    The sha2 family of hash functions.
0004 
0005    Copyright (C) 2001, 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_SHA2_H_INCLUDED
0035 #define NETTLE_SHA2_H_INCLUDED
0036 
0037 #include "nettle-types.h"
0038 
0039 #ifdef __cplusplus
0040 extern "C" {
0041 #endif
0042 
0043 /* Name mangling */
0044 #define sha224_init nettle_sha224_init
0045 #define sha224_digest nettle_sha224_digest
0046 #define sha256_init nettle_sha256_init
0047 #define sha256_update nettle_sha256_update
0048 #define sha256_digest nettle_sha256_digest
0049 #define sha256_compress nettle_sha256_compress
0050 #define sha384_init nettle_sha384_init
0051 #define sha384_digest nettle_sha384_digest
0052 #define sha512_init nettle_sha512_init
0053 #define sha512_update nettle_sha512_update
0054 #define sha512_digest nettle_sha512_digest
0055 #define sha512_compress nettle_sha512_compress
0056 #define sha512_224_init   nettle_sha512_224_init
0057 #define sha512_224_digest nettle_sha512_224_digest
0058 #define sha512_256_init   nettle_sha512_256_init
0059 #define sha512_256_digest nettle_sha512_256_digest
0060 
0061 /* For backwards compatibility */
0062 #define SHA224_DATA_SIZE SHA256_BLOCK_SIZE
0063 #define SHA256_DATA_SIZE SHA256_BLOCK_SIZE
0064 #define SHA512_DATA_SIZE SHA512_BLOCK_SIZE
0065 #define SHA384_DATA_SIZE SHA512_BLOCK_SIZE
0066 
0067 /* SHA256 */
0068 
0069 #define SHA256_DIGEST_SIZE 32
0070 #define SHA256_BLOCK_SIZE 64
0071 
0072 /* Digest is kept internally as 8 32-bit words. */
0073 #define _SHA256_DIGEST_LENGTH 8
0074 
0075 struct sha256_ctx
0076 {
0077   uint32_t state[_SHA256_DIGEST_LENGTH];    /* State variables */
0078   uint64_t count;                           /* 64-bit block count */
0079   unsigned int index;                       /* index into buffer */
0080   uint8_t block[SHA256_BLOCK_SIZE];          /* SHA256 data buffer */
0081 };
0082 
0083 void
0084 sha256_init(struct sha256_ctx *ctx);
0085 
0086 void
0087 sha256_update(struct sha256_ctx *ctx,
0088           size_t length,
0089           const uint8_t *data);
0090 
0091 void
0092 sha256_digest(struct sha256_ctx *ctx,
0093           size_t length,
0094           uint8_t *digest);
0095 
0096 void
0097 sha256_compress(uint32_t *state, const uint8_t *input);
0098 
0099 /* SHA224, a truncated SHA256 with different initial state. */
0100 
0101 #define SHA224_DIGEST_SIZE 28
0102 #define SHA224_BLOCK_SIZE SHA256_BLOCK_SIZE
0103 #define sha224_ctx sha256_ctx
0104 
0105 void
0106 sha224_init(struct sha256_ctx *ctx);
0107 
0108 #define sha224_update nettle_sha256_update
0109 
0110 void
0111 sha224_digest(struct sha256_ctx *ctx,
0112           size_t length,
0113           uint8_t *digest);
0114 
0115 
0116 /* SHA512 */
0117 
0118 #define SHA512_DIGEST_SIZE 64
0119 #define SHA512_BLOCK_SIZE 128
0120 
0121 /* Digest is kept internally as 8 64-bit words. */
0122 #define _SHA512_DIGEST_LENGTH 8
0123 
0124 struct sha512_ctx
0125 {
0126   uint64_t state[_SHA512_DIGEST_LENGTH];    /* State variables */
0127   uint64_t count_low, count_high;           /* 128-bit block count */
0128   unsigned int index;                       /* index into buffer */
0129   uint8_t block[SHA512_BLOCK_SIZE];          /* SHA512 data buffer */
0130 };
0131 
0132 void
0133 sha512_init(struct sha512_ctx *ctx);
0134 
0135 void
0136 sha512_update(struct sha512_ctx *ctx,
0137           size_t length,
0138           const uint8_t *data);
0139 
0140 void
0141 sha512_digest(struct sha512_ctx *ctx,
0142           size_t length,
0143           uint8_t *digest);
0144 
0145 void
0146 sha512_compress(uint64_t *state, const uint8_t *input);
0147 
0148 /* SHA384, a truncated SHA512 with different initial state. */
0149 
0150 #define SHA384_DIGEST_SIZE 48
0151 #define SHA384_BLOCK_SIZE SHA512_BLOCK_SIZE
0152 #define sha384_ctx sha512_ctx
0153 
0154 void
0155 sha384_init(struct sha512_ctx *ctx);
0156 
0157 #define sha384_update nettle_sha512_update
0158 
0159 void
0160 sha384_digest(struct sha512_ctx *ctx,
0161           size_t length,
0162           uint8_t *digest);
0163 
0164 
0165 /* SHA512_224 and SHA512_256, two truncated versions of SHA512 
0166    with different initial states. */
0167 
0168 #define SHA512_224_DIGEST_SIZE 28
0169 #define SHA512_224_BLOCK_SIZE SHA512_BLOCK_SIZE
0170 #define sha512_224_ctx sha512_ctx
0171 
0172 void
0173 sha512_224_init(struct sha512_224_ctx *ctx);
0174 
0175 #define sha512_224_update nettle_sha512_update
0176 
0177 void
0178 sha512_224_digest(struct sha512_224_ctx *ctx,
0179                   size_t length,
0180                   uint8_t *digest);
0181 
0182 #define SHA512_256_DIGEST_SIZE 32
0183 #define SHA512_256_BLOCK_SIZE SHA512_BLOCK_SIZE
0184 #define sha512_256_ctx sha512_ctx
0185 
0186 void
0187 sha512_256_init(struct sha512_256_ctx *ctx);
0188 
0189 #define sha512_256_update nettle_sha512_update
0190 
0191 void
0192 sha512_256_digest(struct sha512_256_ctx *ctx,
0193                   size_t length,
0194                   uint8_t *digest);
0195 
0196 #ifdef __cplusplus
0197 }
0198 #endif
0199 
0200 #endif /* NETTLE_SHA2_H_INCLUDED */