Mercurial > dovecot > core-2.2
annotate src/lib/hmac.h @ 22664:fea53c2725c0
director: Fix director_max_parallel_moves/kicks type
Should be uint, not time.
author | Timo Sirainen <timo.sirainen@dovecot.fi> |
---|---|
date | Thu, 09 Nov 2017 12:24:16 +0200 |
parents | b861c0860dd2 |
children |
rev | line source |
---|---|
15172
8802322d7257
lib: Generalize hmac to be hash independent
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
1 #ifndef HMAC_H |
8802322d7257
lib: Generalize hmac to be hash independent
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
2 #define HMAC_H |
8802322d7257
lib: Generalize hmac to be hash independent
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
3 |
8802322d7257
lib: Generalize hmac to be hash independent
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
4 #include "hash-method.h" |
8802322d7257
lib: Generalize hmac to be hash independent
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
5 #include "sha1.h" |
8802322d7257
lib: Generalize hmac to be hash independent
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
6 |
8802322d7257
lib: Generalize hmac to be hash independent
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
7 #define HMAC_MAX_CONTEXT_SIZE 256 |
8802322d7257
lib: Generalize hmac to be hash independent
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
8 |
16718
92a54bb2ee00
hmac: Fixed crashes on CPUs that don't allow unaligned memory access.
Timo Sirainen <tss@iki.fi>
parents:
15172
diff
changeset
|
9 struct hmac_context_priv { |
15172
8802322d7257
lib: Generalize hmac to be hash independent
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
10 char ctx[HMAC_MAX_CONTEXT_SIZE]; |
8802322d7257
lib: Generalize hmac to be hash independent
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
11 char ctxo[HMAC_MAX_CONTEXT_SIZE]; |
8802322d7257
lib: Generalize hmac to be hash independent
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
12 const struct hash_method *hash; |
8802322d7257
lib: Generalize hmac to be hash independent
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
13 }; |
8802322d7257
lib: Generalize hmac to be hash independent
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
14 |
16718
92a54bb2ee00
hmac: Fixed crashes on CPUs that don't allow unaligned memory access.
Timo Sirainen <tss@iki.fi>
parents:
15172
diff
changeset
|
15 struct hmac_context { |
92a54bb2ee00
hmac: Fixed crashes on CPUs that don't allow unaligned memory access.
Timo Sirainen <tss@iki.fi>
parents:
15172
diff
changeset
|
16 union { |
92a54bb2ee00
hmac: Fixed crashes on CPUs that don't allow unaligned memory access.
Timo Sirainen <tss@iki.fi>
parents:
15172
diff
changeset
|
17 struct hmac_context_priv priv; |
92a54bb2ee00
hmac: Fixed crashes on CPUs that don't allow unaligned memory access.
Timo Sirainen <tss@iki.fi>
parents:
15172
diff
changeset
|
18 uint64_t padding_requirement; |
92a54bb2ee00
hmac: Fixed crashes on CPUs that don't allow unaligned memory access.
Timo Sirainen <tss@iki.fi>
parents:
15172
diff
changeset
|
19 } u; |
92a54bb2ee00
hmac: Fixed crashes on CPUs that don't allow unaligned memory access.
Timo Sirainen <tss@iki.fi>
parents:
15172
diff
changeset
|
20 }; |
92a54bb2ee00
hmac: Fixed crashes on CPUs that don't allow unaligned memory access.
Timo Sirainen <tss@iki.fi>
parents:
15172
diff
changeset
|
21 |
15172
8802322d7257
lib: Generalize hmac to be hash independent
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
22 void hmac_init(struct hmac_context *ctx, const unsigned char *key, |
8802322d7257
lib: Generalize hmac to be hash independent
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
23 size_t key_len, const struct hash_method *meth); |
8802322d7257
lib: Generalize hmac to be hash independent
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
24 void hmac_final(struct hmac_context *ctx, unsigned char *digest); |
8802322d7257
lib: Generalize hmac to be hash independent
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
25 |
8802322d7257
lib: Generalize hmac to be hash independent
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
26 |
8802322d7257
lib: Generalize hmac to be hash independent
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
27 static inline void |
16718
92a54bb2ee00
hmac: Fixed crashes on CPUs that don't allow unaligned memory access.
Timo Sirainen <tss@iki.fi>
parents:
15172
diff
changeset
|
28 hmac_update(struct hmac_context *_ctx, const void *data, size_t size) |
15172
8802322d7257
lib: Generalize hmac to be hash independent
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
29 { |
16718
92a54bb2ee00
hmac: Fixed crashes on CPUs that don't allow unaligned memory access.
Timo Sirainen <tss@iki.fi>
parents:
15172
diff
changeset
|
30 struct hmac_context_priv *ctx = &_ctx->u.priv; |
92a54bb2ee00
hmac: Fixed crashes on CPUs that don't allow unaligned memory access.
Timo Sirainen <tss@iki.fi>
parents:
15172
diff
changeset
|
31 |
15172
8802322d7257
lib: Generalize hmac to be hash independent
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
32 ctx->hash->loop(ctx->ctx, data, size); |
8802322d7257
lib: Generalize hmac to be hash independent
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
33 } |
8802322d7257
lib: Generalize hmac to be hash independent
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
34 |
21266 | 35 buffer_t *t_hmac_data(const struct hash_method *meth, |
36 const unsigned char *key, size_t key_len, | |
37 const void *data, size_t data_len); | |
38 buffer_t *t_hmac_buffer(const struct hash_method *meth, | |
39 const unsigned char *key, size_t key_len, | |
40 const buffer_t *data); | |
41 buffer_t *t_hmac_str(const struct hash_method *meth, | |
42 const unsigned char *key, size_t key_len, | |
43 const char *data); | |
44 | |
15172
8802322d7257
lib: Generalize hmac to be hash independent
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
45 #endif |