Back to home page

EIC code displayed by LXR

 
 

    


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

0001 /* hmac.h
0002 
0003    HMAC message authentication code (RFC-2104).
0004 
0005    Copyright (C) 2001, 2002 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_HMAC_H_INCLUDED
0035 #define NETTLE_HMAC_H_INCLUDED
0036 
0037 #include "nettle-meta.h"
0038 
0039 #include "gosthash94.h"
0040 #include "md5.h"
0041 #include "ripemd160.h"
0042 #include "sha1.h"
0043 #include "sha2.h"
0044 #include "streebog.h"
0045 #include "sm3.h"
0046 
0047 #ifdef __cplusplus
0048 extern "C" {
0049 #endif
0050 
0051 /* Namespace mangling */
0052 #define hmac_set_key nettle_hmac_set_key
0053 #define hmac_update nettle_hmac_update
0054 #define hmac_digest nettle_hmac_digest
0055 #define hmac_md5_set_key nettle_hmac_md5_set_key
0056 #define hmac_md5_update nettle_hmac_md5_update
0057 #define hmac_md5_digest nettle_hmac_md5_digest
0058 #define hmac_ripemd160_set_key nettle_hmac_ripemd160_set_key
0059 #define hmac_ripemd160_update nettle_hmac_ripemd160_update
0060 #define hmac_ripemd160_digest nettle_hmac_ripemd160_digest
0061 #define hmac_sha1_set_key nettle_hmac_sha1_set_key
0062 #define hmac_sha1_update nettle_hmac_sha1_update
0063 #define hmac_sha1_digest nettle_hmac_sha1_digest
0064 #define hmac_sha224_set_key nettle_hmac_sha224_set_key
0065 #define hmac_sha224_digest nettle_hmac_sha224_digest
0066 #define hmac_sha256_set_key nettle_hmac_sha256_set_key
0067 #define hmac_sha256_update nettle_hmac_sha256_update
0068 #define hmac_sha256_digest nettle_hmac_sha256_digest
0069 #define hmac_sha384_set_key nettle_hmac_sha384_set_key
0070 #define hmac_sha384_digest nettle_hmac_sha384_digest
0071 #define hmac_sha512_set_key nettle_hmac_sha512_set_key
0072 #define hmac_sha512_update nettle_hmac_sha512_update
0073 #define hmac_sha512_digest nettle_hmac_sha512_digest
0074 #define hmac_gosthash94_set_key nettle_hmac_gosthash94_set_key
0075 #define hmac_gosthash94_update nettle_hmac_gosthash94_update
0076 #define hmac_gosthash94_digest nettle_hmac_gosthash94_digest
0077 #define hmac_gosthash94cp_set_key nettle_hmac_gosthash94cp_set_key
0078 #define hmac_gosthash94cp_update nettle_hmac_gosthash94cp_update
0079 #define hmac_gosthash94cp_digest nettle_hmac_gosthash94cp_digest
0080 #define hmac_streebog256_set_key nettle_hmac_streebog256_set_key
0081 #define hmac_streebog256_digest nettle_hmac_streebog256_digest
0082 #define hmac_streebog512_set_key nettle_hmac_streebog512_set_key
0083 #define hmac_streebog512_update nettle_hmac_streebog512_update
0084 #define hmac_streebog512_digest nettle_hmac_streebog512_digest
0085 #define hmac_sm3_set_key nettle_hmac_sm3_set_key
0086 #define hmac_sm3_update nettle_hmac_sm3_update
0087 #define hmac_sm3_digest nettle_hmac_sm3_digest
0088 
0089 void
0090 hmac_set_key(void *outer, void *inner, void *state,
0091          const struct nettle_hash *hash,
0092          size_t length, const uint8_t *key);
0093 
0094 /* This function is not strictly needed, it's s just the same as the
0095  * hash update function. */
0096 void
0097 hmac_update(void *state,
0098         const struct nettle_hash *hash,
0099         size_t length, const uint8_t *data);
0100 
0101 void
0102 hmac_digest(const void *outer, const void *inner, void *state,
0103         const struct nettle_hash *hash,
0104         size_t length, uint8_t *digest);
0105 
0106 
0107 #define HMAC_CTX(type) \
0108 { type outer; type inner; type state; }
0109 
0110 #define HMAC_SET_KEY(ctx, hash, length, key)            \
0111   hmac_set_key( &(ctx)->outer, &(ctx)->inner, &(ctx)->state,    \
0112                 (hash), (length), (key) )
0113 
0114 #define HMAC_DIGEST(ctx, hash, length, digest)          \
0115   hmac_digest( &(ctx)->outer, &(ctx)->inner, &(ctx)->state, \
0116                (hash), (length), (digest) )
0117 
0118 /* HMAC using specific hash functions */
0119 
0120 /* hmac-md5 */
0121 struct hmac_md5_ctx HMAC_CTX(struct md5_ctx);
0122 
0123 void
0124 hmac_md5_set_key(struct hmac_md5_ctx *ctx,
0125          size_t key_length, const uint8_t *key);
0126 
0127 void
0128 hmac_md5_update(struct hmac_md5_ctx *ctx,
0129         size_t length, const uint8_t *data);
0130 
0131 void
0132 hmac_md5_digest(struct hmac_md5_ctx *ctx,
0133         size_t length, uint8_t *digest);
0134 
0135 
0136 /* hmac-ripemd160 */
0137 struct hmac_ripemd160_ctx HMAC_CTX(struct ripemd160_ctx);
0138 
0139 void
0140 hmac_ripemd160_set_key(struct hmac_ripemd160_ctx *ctx,
0141                size_t key_length, const uint8_t *key);
0142 
0143 void
0144 hmac_ripemd160_update(struct hmac_ripemd160_ctx *ctx,
0145               size_t length, const uint8_t *data);
0146 
0147 void
0148 hmac_ripemd160_digest(struct hmac_ripemd160_ctx *ctx,
0149               size_t length, uint8_t *digest);
0150 
0151 
0152 /* hmac-sha1 */
0153 struct hmac_sha1_ctx HMAC_CTX(struct sha1_ctx);
0154 
0155 void
0156 hmac_sha1_set_key(struct hmac_sha1_ctx *ctx,
0157           size_t key_length, const uint8_t *key);
0158 
0159 void
0160 hmac_sha1_update(struct hmac_sha1_ctx *ctx,
0161          size_t length, const uint8_t *data);
0162 
0163 void
0164 hmac_sha1_digest(struct hmac_sha1_ctx *ctx,
0165          size_t length, uint8_t *digest);
0166 
0167 /* hmac-sha256 */
0168 struct hmac_sha256_ctx HMAC_CTX(struct sha256_ctx);
0169 
0170 void
0171 hmac_sha256_set_key(struct hmac_sha256_ctx *ctx,
0172             size_t key_length, const uint8_t *key);
0173 
0174 void
0175 hmac_sha256_update(struct hmac_sha256_ctx *ctx,
0176            size_t length, const uint8_t *data);
0177 
0178 void
0179 hmac_sha256_digest(struct hmac_sha256_ctx *ctx,
0180            size_t length, uint8_t *digest);
0181 
0182 /* hmac-sha224 */
0183 #define hmac_sha224_ctx hmac_sha256_ctx
0184 
0185 void
0186 hmac_sha224_set_key(struct hmac_sha224_ctx *ctx,
0187             size_t key_length, const uint8_t *key);
0188 
0189 #define hmac_sha224_update nettle_hmac_sha256_update
0190 
0191 void
0192 hmac_sha224_digest(struct hmac_sha224_ctx *ctx,
0193            size_t length, uint8_t *digest);
0194 
0195 /* hmac-sha512 */
0196 struct hmac_sha512_ctx HMAC_CTX(struct sha512_ctx);
0197 
0198 void
0199 hmac_sha512_set_key(struct hmac_sha512_ctx *ctx,
0200             size_t key_length, const uint8_t *key);
0201 
0202 void
0203 hmac_sha512_update(struct hmac_sha512_ctx *ctx,
0204            size_t length, const uint8_t *data);
0205 
0206 void
0207 hmac_sha512_digest(struct hmac_sha512_ctx *ctx,
0208            size_t length, uint8_t *digest);
0209 
0210 /* hmac-sha384 */
0211 #define hmac_sha384_ctx hmac_sha512_ctx
0212 
0213 void
0214 hmac_sha384_set_key(struct hmac_sha512_ctx *ctx,
0215             size_t key_length, const uint8_t *key);
0216 
0217 #define hmac_sha384_update nettle_hmac_sha512_update
0218 
0219 void
0220 hmac_sha384_digest(struct hmac_sha512_ctx *ctx,
0221            size_t length, uint8_t *digest);
0222 
0223 /* hmac-gosthash94 */
0224 struct hmac_gosthash94_ctx HMAC_CTX(struct gosthash94_ctx);
0225 
0226 void
0227 hmac_gosthash94_set_key(struct hmac_gosthash94_ctx *ctx,
0228             size_t key_length, const uint8_t *key);
0229 
0230 void
0231 hmac_gosthash94_update(struct hmac_gosthash94_ctx *ctx,
0232                size_t length, const uint8_t *data);
0233 
0234   void
0235 hmac_gosthash94_digest(struct hmac_gosthash94_ctx *ctx,
0236                size_t length, uint8_t *digest);
0237 
0238 struct hmac_gosthash94cp_ctx HMAC_CTX(struct gosthash94cp_ctx);
0239 
0240 void
0241 hmac_gosthash94cp_set_key(struct hmac_gosthash94cp_ctx *ctx,
0242               size_t key_length, const uint8_t *key);
0243 
0244 void
0245 hmac_gosthash94cp_update(struct hmac_gosthash94cp_ctx *ctx,
0246              size_t length, const uint8_t *data);
0247 
0248 void
0249 hmac_gosthash94cp_digest(struct hmac_gosthash94cp_ctx *ctx,
0250              size_t length, uint8_t *digest);
0251 
0252 
0253 /* hmac-streebog */
0254 struct hmac_streebog512_ctx HMAC_CTX(struct streebog512_ctx);
0255 
0256 void
0257 hmac_streebog512_set_key(struct hmac_streebog512_ctx *ctx,
0258             size_t key_length, const uint8_t *key);
0259 
0260 void
0261 hmac_streebog512_update(struct hmac_streebog512_ctx *ctx,
0262            size_t length, const uint8_t *data);
0263 
0264 void
0265 hmac_streebog512_digest(struct hmac_streebog512_ctx *ctx,
0266            size_t length, uint8_t *digest);
0267 
0268 #define hmac_streebog256_ctx hmac_streebog512_ctx
0269 
0270 void
0271 hmac_streebog256_set_key(struct hmac_streebog256_ctx *ctx,
0272             size_t key_length, const uint8_t *key);
0273 
0274 #define hmac_streebog256_update hmac_streebog512_update
0275 
0276 void
0277 hmac_streebog256_digest(struct hmac_streebog256_ctx *ctx,
0278            size_t length, uint8_t *digest);
0279 
0280 /* hmac-sm3 */
0281 struct hmac_sm3_ctx HMAC_CTX(struct sm3_ctx);
0282 
0283 void
0284 hmac_sm3_set_key(struct hmac_sm3_ctx *ctx,
0285          size_t key_length, const uint8_t *key);
0286 
0287 void
0288 hmac_sm3_update(struct hmac_sm3_ctx *ctx,
0289         size_t length, const uint8_t *data);
0290 
0291 void
0292 hmac_sm3_digest(struct hmac_sm3_ctx *ctx,
0293         size_t length, uint8_t *digest);
0294 
0295 #ifdef __cplusplus
0296 }
0297 #endif
0298 
0299 #endif /* NETTLE_HMAC_H_INCLUDED */