Skip to content

Commit 5dc0fc5

Browse files
committed
Minimal configuration for Posix, merged global.h into tinydtls.h,
made DTLS configuration file configurable.
1 parent 1fb60dc commit 5dc0fc5

25 files changed

+182
-193
lines changed

Diff for: Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ DTLS_DIRS:= aes ecc sta2 $(DTLS_SUPPORT)
2929
OBJECTS:= $(SOURCES:.c=.o)
3030
# CFLAGS:=-Wall -pedantic -std=c99 -g -O2 -I. ${addprefix -I,$(DTLS_DIRS)}
3131
CFLAGS:=-Wall -std=c99 -g -O2 -I. ${addprefix -I,$(DTLS_DIRS)}
32-
CPPFLAGS:= -DDTLSv12 -DWITH_SHA256 -DDTLS_CHECK_CONTENTTYPE
32+
CPPFLAGS:=
3333
LIB:=libtinydtls.a
3434
LDFLAGS:=
3535
ARFLAGS:=cru

Diff for: ccm.c

+2-3
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717

1818
#include <string.h>
1919

20-
#include "dtls_config.h"
21-
#include "global.h"
20+
#include "tinydtls.h"
2221
#include "numeric.h"
2322
#include "ccm.h"
2423

@@ -295,7 +294,7 @@ dtls_ccm_decrypt_message(rijndael_ctx *ctx, size_t M, size_t L,
295294
memxor(msg, S, M);
296295

297296
/* return length if MAC is valid, otherwise continue with error handling */
298-
if (equals(X, msg, M))
297+
if (dtls_equals(X, msg, M))
299298
return len - M;
300299

301300
error:

Diff for: crypto.c

+1-4
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,13 @@
1818
#include <stdio.h>
1919

2020
#include "tinydtls.h"
21-
#include "dtls_config.h"
2221

2322
#ifdef HAVE_ASSERT_H
2423
#include <assert.h>
2524
#else
2625
#define assert(x)
2726
#endif
2827

29-
#include "global.h"
3028
#include "dtls_debug.h"
3129
#include "numeric.h"
3230
#include "dtls.h"
@@ -35,7 +33,7 @@
3533
#include "ecc/ecc.h"
3634
#include "prng.h"
3735
#include "netq.h"
38-
#include "memb.h"
36+
#include "lib/memb.h"
3937

4038
#ifndef WITH_CONTIKI
4139
#include <pthread.h>
@@ -541,4 +539,3 @@ dtls_decrypt(const unsigned char *src, size_t length,
541539
dtls_cipher_context_release();
542540
return ret;
543541
}
544-

Diff for: crypto.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@
2121
#include <stdlib.h> /* for rand() and srand() */
2222
#include <stdint.h>
2323

24+
#include "tinydtls.h"
25+
2426
#include "aes/rijndael.h"
2527

26-
#include "global.h"
2728
#include "state.h"
2829
#include "numeric.h"
2930
#include "hmac.h"

Diff for: dtls.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
*******************************************************************************/
1919

2020
#include "tinydtls.h"
21-
#include "dtls_config.h"
2221
#include "dtls_time.h"
2322

2423
#include <stdio.h>
@@ -28,7 +27,6 @@
2827
#endif
2928
#ifndef WITH_CONTIKI
3029
#include <stdlib.h>
31-
#include "global.h"
3230
#endif /* WITH_CONTIKI */
3331

3432
#include "utlist.h"
@@ -40,6 +38,7 @@
4038
#include "numeric.h"
4139
#include "netq.h"
4240
#include "dtls.h"
41+
#include "hmac.h"
4342

4443
#include "alert.h"
4544
#include "session.h"
@@ -156,6 +155,7 @@ void
156155
dtls_init() {
157156
dtls_clock_init();
158157
crypto_init();
158+
dtls_hmac_storage_init();
159159
netq_init();
160160
peer_init();
161161
dtls_support_init();
@@ -1165,7 +1165,7 @@ check_finished(dtls_context_t *ctx, dtls_peer_t *peer,
11651165
dtls_debug_dump("v:", b.verify_data, sizeof(b.verify_data));
11661166

11671167
/* compare verify data and create DTLS alert code when they differ */
1168-
return equals(data + DTLS_HS_LENGTH, b.verify_data, sizeof(b.verify_data))
1168+
return dtls_equals(data + DTLS_HS_LENGTH, b.verify_data, sizeof(b.verify_data))
11691169
? 0
11701170
: dtls_alert_create(DTLS_ALERT_LEVEL_FATAL, DTLS_ALERT_HANDSHAKE_FAILURE);
11711171
}

Diff for: dtls.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
#include "crypto.h"
3636
#include "hmac.h"
3737

38-
#include "global.h"
38+
#include "tinydtls.h"
3939
#include "dtls_time.h"
4040

4141
#ifndef DTLSv12

Diff for: dtls_config.h

+34-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/* dtls_config.h. Generated from dtls_config.h.in by configure. */
2-
/* dtls_config.h.in. Generated from configure.ac by autoheader. */
31

42
/* Define if building universal (internal helper macro) */
53
/* #undef AC_APPLE_UNIVERSAL_BUILD */
@@ -118,3 +116,37 @@
118116

119117
/* Define to 1 if you have the ANSI C header files. */
120118
/* #undef STDC_HEADERS */
119+
120+
#define SHA2_USE_INTTYPES_H 1
121+
122+
/* global constants for constrained devices */
123+
#ifndef DTLS_PEER_MAX
124+
/** The maximum number DTLS peers (i.e. sessions). */
125+
#define DTLS_PEER_MAX 1
126+
#endif
127+
128+
#ifndef DTLS_HANDSHAKE_MAX
129+
/** The maximum number of concurrent DTLS handshakes. */
130+
#define DTLS_HANDSHAKE_MAX 1
131+
#endif
132+
133+
#ifndef DTLS_SECURITY_MAX
134+
/** The maximum number of concurrently used cipher keys */
135+
#define DTLS_SECURITY_MAX (DTLS_PEER_MAX + DTLS_HANDSHAKE_MAX)
136+
#endif
137+
138+
#ifndef DTLS_HASH_MAX
139+
/** The maximum number of hash functions that can be used in parallel. */
140+
#define DTLS_HASH_MAX (3 * DTLS_PEER_MAX)
141+
#endif
142+
143+
/** Defined to 1 if tinydtls is built with support for ECC */
144+
#define DTLS_ECC 1
145+
146+
/** Defined to 1 if tinydtls is built with support for PSK */
147+
#define DTLS_PSK 1
148+
149+
/** do not use uthash hash tables */
150+
/* #define DTLS_PEERS_NOHASH 1 */
151+
152+
#define DTLS_CHECK_CONTENTTYPE 1

Diff for: dtls_debug.c

-6
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
*******************************************************************************/
1717

1818
#include "tinydtls.h"
19-
#include "dtls_config.h"
2019

2120
#if defined(HAVE_ASSERT_H) && !defined(assert)
2221
#include <assert.h>
@@ -25,15 +24,10 @@
2524
#include <stdarg.h>
2625
#include <stdio.h>
2726

28-
#ifdef HAVE_ARPA_INET_H
29-
#include <arpa/inet.h>
30-
#endif
31-
3227
#ifdef HAVE_TIME_H
3328
#include <time.h>
3429
#endif
3530

36-
#include "global.h"
3731
#include "dtls_debug.h"
3832

3933
#ifndef min

Diff for: dtls_debug.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@
2020

2121
#include <stdlib.h>
2222

23-
#include "dtls_config.h"
24-
#include "global.h"
23+
#include "tinydtls.h"
2524
#include "session.h"
2625

2726
#ifdef WITH_CONTIKI

Diff for: global.h

-141
This file was deleted.

Diff for: hmac.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#include <stdlib.h>
2020
#include <string.h>
2121

22-
#include "dtls_config.h"
22+
#include "tinydtls.h"
2323

2424
#ifdef HAVE_ASSERT_H
2525
#include <assert.h>
@@ -29,7 +29,7 @@
2929

3030
#include "dtls_debug.h"
3131
#include "hmac.h"
32-
#include "memb.h"
32+
#include "lib/memb.h"
3333

3434
MEMB(hmac_context_storage, dtls_hmac_context_t, DTLS_HASH_MAX);
3535

@@ -44,7 +44,8 @@ dtls_hmac_context_free(dtls_hmac_context_t *ctx) {
4444
}
4545

4646
void
47-
dtls_hmac_storage_init() {
47+
dtls_hmac_storage_init(void)
48+
{
4849
memb_init(&hmac_context_storage);
4950
}
5051

Diff for: hmac.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
#include <sys/types.h>
2222

23-
#include "global.h"
23+
#include "tinydtls.h"
2424

2525
#ifdef WITH_SHA256
2626
/** Aaron D. Gifford's implementation of SHA256
@@ -48,7 +48,7 @@ dtls_hash_finalize(unsigned char *buf, dtls_hash_t ctx) {
4848
}
4949
#endif /* WITH_SHA256 */
5050

51-
static inline void dtls_hmac_storage_init(void);
51+
void dtls_hmac_storage_init(void);
5252

5353
/**
5454
* \defgroup HMAC Keyed-Hash Message Authentication Code (HMAC)

0 commit comments

Comments
 (0)