tinydtls  0.8.1
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
hmac.h
Go to the documentation of this file.
1 /* dtls -- a very basic DTLS implementation
2  *
3  * Copyright (C) 2011--2012 Olaf Bergmann <bergmann@tzi.org>
4  *
5  * Permission is hereby granted, free of charge, to any person
6  * obtaining a copy of this software and associated documentation
7  * files (the "Software"), to deal in the Software without
8  * restriction, including without limitation the rights to use, copy,
9  * modify, merge, publish, distribute, sublicense, and/or sell copies
10  * of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23  * SOFTWARE.
24  */
25 
26 #ifndef _DTLS_HMAC_H_
27 #define _DTLS_HMAC_H_
28 
29 #include <sys/types.h>
30 
31 #include "global.h"
32 
33 #ifdef WITH_SHA256
34 
36 #include "sha2/sha2.h"
37 
38 typedef SHA256_CTX dtls_hash_ctx;
40 #define DTLS_HASH_CTX_SIZE sizeof(SHA256_CTX)
41 
42 static inline void
44  SHA256_Init((SHA256_CTX *)ctx);
45 }
46 
47 static inline void
48 dtls_hash_update(dtls_hash_t ctx, const unsigned char *input, size_t len) {
49  SHA256_Update((SHA256_CTX *)ctx, input, len);
50 }
51 
52 static inline size_t
53 dtls_hash_finalize(unsigned char *buf, dtls_hash_t ctx) {
54  SHA256_Final(buf, (SHA256_CTX *)ctx);
55  return SHA256_DIGEST_LENGTH;
56 }
57 #endif /* WITH_SHA256 */
58 
59 #ifndef WITH_CONTIKI
60 static inline void dtls_hmac_storage_init()
61 { }
62 #else
64 #endif
65 
73 #define DTLS_HMAC_BLOCKSIZE 64
74 #define DTLS_HMAC_DIGEST_SIZE 32
75 #define DTLS_HMAC_MAX 64
83 typedef enum {
87 
95 typedef struct {
96  unsigned char pad[DTLS_HMAC_BLOCKSIZE];
99 
107 void dtls_hmac_init(dtls_hmac_context_t *ctx, const unsigned char *key, size_t klen);
108 
119 dtls_hmac_context_t *dtls_hmac_new(const unsigned char *key, size_t klen);
120 
128 
137  const unsigned char *input, size_t ilen);
138 
150 int dtls_hmac_finalize(dtls_hmac_context_t *ctx, unsigned char *result);
151 
154 #endif /* _DTLS_HMAC_H_ */
void dtls_hmac_update(dtls_hmac_context_t *ctx, const unsigned char *input, size_t ilen)
Definition: hmac.c:76
SHA256_CTX dtls_hash_ctx
Definition: hmac.h:38
void dtls_hmac_free(dtls_hmac_context_t *ctx)
Definition: hmac.c:121
void dtls_hmac_init(dtls_hmac_context_t *ctx, const unsigned char *key, size_t klen)
Definition: hmac.c:94
dtls_hmac_context_t * dtls_hmac_new(const unsigned char *key, size_t klen)
Definition: hmac.c:83
static void dtls_hash_init(dtls_hash_t ctx)
Definition: hmac.h:43
Definition: hmac.h:84
Definition: hmac.h:84
dtls_hash_ctx * dtls_hash_t
Definition: hmac.h:39
static void dtls_hash_update(dtls_hash_t ctx, const unsigned char *input, size_t len)
Definition: hmac.h:48
int dtls_hmac_finalize(dtls_hmac_context_t *ctx, unsigned char *result)
Definition: hmac.c:127
Definition: hmac.h:84
#define DTLS_HMAC_BLOCKSIZE
Definition: hmac.h:73
dtls_hashfunc_t
Definition: hmac.h:83
static size_t dtls_hash_finalize(unsigned char *buf, dtls_hash_t ctx)
Definition: hmac.h:53
static void dtls_hmac_storage_init()
Definition: hmac.h:60
dtls_hash_ctx data
Definition: hmac.h:97