tinydtls  0.8.6
hmac.h
Go to the documentation of this file.
1 /*******************************************************************************
2  *
3  * Copyright (c) 2011, 2012, 2013, 2014, 2015 Olaf Bergmann (TZI) and others.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * and Eclipse Distribution License v. 1.0 which accompanies this distribution.
7  *
8  * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
9  * and the Eclipse Distribution License is available at
10  * http://www.eclipse.org/org/documents/edl-v10.php.
11  *
12  * Contributors:
13  * Olaf Bergmann - initial API and implementation
14  * Hauke Mehrtens - memory optimization, ECC integration
15  *
16  *******************************************************************************/
17 
18 #ifndef _DTLS_HMAC_H_
19 #define _DTLS_HMAC_H_
20 
21 #include <sys/types.h>
22 
23 #include "tinydtls.h"
24 #include "global.h"
25 
26 #ifdef WITH_SHA256
27 
29 #include "sha2/sha2.h"
30 
31 typedef dtls_sha256_ctx dtls_hash_ctx;
33 #define DTLS_HASH_CTX_SIZE sizeof(dtls_sha256_ctx)
34 
35 static inline void
37  dtls_sha256_init((dtls_sha256_ctx *)ctx);
38 }
39 
40 static inline void
41 dtls_hash_update(dtls_hash_t ctx, const unsigned char *input, size_t len) {
42  dtls_sha256_update((dtls_sha256_ctx *)ctx, input, len);
43 }
44 
45 static inline size_t
46 dtls_hash_finalize(unsigned char *buf, dtls_hash_t ctx) {
47  dtls_sha256_final(buf, (dtls_sha256_ctx *)ctx);
48  return DTLS_SHA256_DIGEST_LENGTH;
49 }
50 #endif /* WITH_SHA256 */
51 
52 void dtls_hmac_storage_init(void);
53 
61 #define DTLS_HMAC_BLOCKSIZE 64
62 #define DTLS_HMAC_DIGEST_SIZE 32
63 #define DTLS_HMAC_MAX 64
71 typedef enum {
75 
83 typedef struct {
84  unsigned char pad[DTLS_HMAC_BLOCKSIZE];
87 
95 void dtls_hmac_init(dtls_hmac_context_t *ctx, const unsigned char *key, size_t klen);
96 
107 dtls_hmac_context_t *dtls_hmac_new(const unsigned char *key, size_t klen);
108 
116 
125  const unsigned char *input, size_t ilen);
126 
138 int dtls_hmac_finalize(dtls_hmac_context_t *ctx, unsigned char *result);
139 
142 #endif /* _DTLS_HMAC_H_ */
public tinydtls API
void dtls_hmac_update(dtls_hmac_context_t *ctx, const unsigned char *input, size_t ilen)
Definition: hmac.c:70
void dtls_hmac_free(dtls_hmac_context_t *ctx)
Definition: hmac.c:115
dtls_sha256_ctx dtls_hash_ctx
Definition: hmac.h:31
void dtls_hmac_init(dtls_hmac_context_t *ctx, const unsigned char *key, size_t klen)
Definition: hmac.c:88
dtls_hmac_context_t * dtls_hmac_new(const unsigned char *key, size_t klen)
Definition: hmac.c:77
static void dtls_hash_init(dtls_hash_t ctx)
Definition: hmac.h:36
Definition: hmac.h:72
Definition: hmac.h:72
dtls_hash_ctx * dtls_hash_t
Definition: hmac.h:32
static void dtls_hash_update(dtls_hash_t ctx, const unsigned char *input, size_t len)
Definition: hmac.h:41
int dtls_hmac_finalize(dtls_hmac_context_t *ctx, unsigned char *result)
Definition: hmac.c:121
Definition: hmac.h:72
#define DTLS_HMAC_BLOCKSIZE
Definition: hmac.h:61
dtls_hashfunc_t
Definition: hmac.h:71
static size_t dtls_hash_finalize(unsigned char *buf, dtls_hash_t ctx)
Definition: hmac.h:46
void dtls_hmac_storage_init(void)
Definition: hmac.c:46
dtls_hash_ctx data
Definition: hmac.h:85