Skip to content

Commit

Permalink
Merge branch 'ecdh-merge'
Browse files Browse the repository at this point in the history
  • Loading branch information
obgm committed Feb 17, 2014
2 parents 6911915 + 5d014fe commit 9a2e0ad
Show file tree
Hide file tree
Showing 27 changed files with 307 additions and 155 deletions.
7 changes: 4 additions & 3 deletions Makefile.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Makefile for tinydtls
#
# Copyright (C) 2011--2012 Olaf Bergmann <[email protected]>
# Copyright (C) 2011--2014 Olaf Bergmann <[email protected]>
#
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation
Expand Down Expand Up @@ -42,7 +42,7 @@ package = @PACKAGE_TARNAME@-@PACKAGE_VERSION@
install := cp

# files and flags
SOURCES:= dtls.c crypto.c ccm.c hmac.c netq.c peer.c dtls_time.c
SOURCES:= dtls.c crypto.c ccm.c hmac.c netq.c peer.c dtls_time.c session.c
ifneq ("@NDEBUG@", "1")
SOURCES += debug.c
endif
Expand All @@ -51,7 +51,8 @@ ifeq ("@DTLS_ECC@", "1")
OBJECTS += ecc/ecc.o
endif
HEADERS:=dtls.h hmac.h debug.h config.h uthash.h numeric.h crypto.h global.h ccm.h \
netq.h t_list.h alert.h utlist.h prng.h peer.h state.h dtls_time.h
netq.h t_list.h alert.h utlist.h prng.h peer.h state.h dtls_time.h session.h \
tinydtls.h
CFLAGS:=-Wall -pedantic -std=c99 @CFLAGS@
CPPFLAGS:=@CPPFLAGS@ -DDTLS_CHECK_CONTENTTYPE
SUBDIRS:=tests doc sha2 aes
Expand Down
7 changes: 4 additions & 3 deletions alert.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@
#ifndef _DTLS_ALERT_H_
#define _DTLS_ALERT_H_

#include "config.h"

typedef enum {
DTLS_ALERT_LEVEL_WARNING=1,
DTLS_ALERT_LEVEL_FATAL=2
Expand Down Expand Up @@ -63,7 +61,10 @@ typedef enum {
DTLS_ALERT_UNSUPPORTED_EXTENSION = 110 /* unsupported_extension */
} dtls_alert_t;

#define DTLS_EVENT_CONNECTED 0x01DE
#define DTLS_EVENT_CONNECT 0x01DC /**< initiated handshake */
#define DTLS_EVENT_CONNECTED 0x01DE /**< handshake or re-negotiation
* has finished */
#define DTLS_EVENT_RENEGOTIATE 0x01DF /**< re-negotiation has started */

static inline int
dtls_alert_create(dtls_alert_level_t level, dtls_alert_t desc)
Expand Down
4 changes: 3 additions & 1 deletion ccm.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* dtls -- a very basic DTLS implementation
*
* Copyright (C) 2011--2013 Olaf Bergmann <[email protected]>
* Copyright (C) 2011--2014 Olaf Bergmann <[email protected]>
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
Expand All @@ -25,6 +25,8 @@

#include <string.h>

#include "tinydtls.h"
#include "config.h"
#include "global.h"
#include "numeric.h"
#include "ccm.h"
Expand Down
1 change: 0 additions & 1 deletion ccm.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#ifndef _DTLS_CCM_H_
#define _DTLS_CCM_H_

#include "config.h"
#include "aes/rijndael.h"

/* implementation of Counter Mode CBC-MAC, RFC 3610 */
Expand Down
14 changes: 1 addition & 13 deletions config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -91,35 +91,23 @@
/* Define to 1 if you have the `vprintf' function. */
#undef HAVE_VPRINTF

#ifndef PACKAGE_BUGREPORT
/* Define to the address where bug reports for this package should be sent. */
#undef PACKAGE_BUGREPORT
#endif /* PACKAGE_BUGREPORT */

#ifndef PACKAGE_NAME
/* Define to the full name of this package. */
#undef PACKAGE_NAME
#endif /* PACKAGE_NAME */

#ifndef PACKAGE_STRING
/* Define to the full name and version of this package. */
#undef PACKAGE_STRING
#endif /* PACKAGE_STRING */

#ifndef PACKAGE_TARNAME
/* Define to the one symbol short name of this package. */
#undef PACKAGE_TARNAME
#endif /* PACKAGE_TARNAME */

#ifndef PACKAGE_URL
/* Define to the home page for this package. */
#undef PACKAGE_URL
#endif /* PACKAGE_URL */

#ifndef PACKAGE_VERSION
/* Define to the version of this package. */
#undef PACKAGE_VERSION
#endif /* PACKAGE_VERSION */

/* Define to 1 if you have the ANSI C header files. */
#undef STDC_HEADERS
Expand All @@ -144,6 +132,6 @@

/* Define to rpl_malloc if the replacement function should be used. */
#undef malloc

/* Define to `unsigned int' if <sys/types.h> does not define. */

#undef size_t
8 changes: 4 additions & 4 deletions configure.in
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
# SOFTWARE.

AC_PREREQ([2.65])
AC_INIT([tinydtls], [0.5.1])
AC_INIT([tinydtls], [0.5.2])
AC_CONFIG_SRCDIR([dtls.c])
dnl AC_CONFIG_HEADERS([config.h])

Expand Down Expand Up @@ -62,13 +62,13 @@ AC_ARG_WITH(debug,
AC_ARG_WITH(ecc,
[AS_HELP_STRING([--without-ecc],[disable support for TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8])],
[],
[CPPFLAGS="${CPPFLAGS} -DDTLS_ECC"
[AC_DEFINE(DTLS_ECC, 1, [Define to 1 if building with ECC support.])
DTLS_ECC=1])

AC_ARG_WITH(psk,
[AS_HELP_STRING([--without-psk],[disable support for TLS_PSK_WITH_AES_128_CCM_8])],
[],
[CPPFLAGS="${CPPFLAGS} -DDTLS_PSK"
[AC_DEFINE(DTLS_PSK, 1, [Define to 1 if building with PSK support])
DTLS_PSK=1])

CPPFLAGS="${CPPFLAGS} -DDTLSv12 -DWITH_SHA256"
Expand Down Expand Up @@ -99,7 +99,7 @@ AC_CHECK_MEMBER([struct sockaddr_in6.sin6_len],
AC_FUNC_MALLOC
AC_CHECK_FUNCS([memset select socket strdup strerror strnlen fls vprintf])

AC_CONFIG_HEADERS([config.h])
AC_CONFIG_HEADERS([config.h tinydtls.h])

AC_CONFIG_FILES([Makefile
doc/Makefile
Expand Down
6 changes: 6 additions & 0 deletions crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,14 @@
*/

#include <stdio.h>

#include "tinydtls.h"
#include "config.h"

#ifdef HAVE_ASSERT_H
#include <assert.h>
#else
#define assert(x)
#endif

#include "global.h"
Expand Down
4 changes: 2 additions & 2 deletions crypto.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
#ifndef _DTLS_CRYPTO_H_
#define _DTLS_CRYPTO_H_

#include "config.h"

#include <stdlib.h> /* for rand() and srand() */
#include <stdint.h>

#include "t_list.h"

#include "aes/rijndael.h"
Expand Down
10 changes: 10 additions & 0 deletions debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@

static int maxlog = DTLS_LOG_WARN; /* default maximum log level */

const char *dtls_package_name() {
return PACKAGE_NAME;
}

const char *dtls_package_version() {
return PACKAGE_STRING;
}

log_t
dtls_get_log_level() {
return maxlog;
Expand Down Expand Up @@ -102,6 +110,8 @@ strnlen(const char *s, size_t maxlen) {
++n;
return n;
}
#else
extern size_t strnlen(const char *s, size_t maxlen);
#endif /* HAVE_STRNLEN */

#ifndef min
Expand Down
19 changes: 18 additions & 1 deletion debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,20 @@
#ifndef _DTLS_DEBUG_H_
#define _DTLS_DEBUG_H_

#include <stdlib.h>

#include "config.h"
#include "global.h"
#include <stdlib.h>
#include "session.h"

#ifdef WITH_CONTIKI
# ifndef DEBUG
# define DEBUG DEBUG_PRINT
# endif /* DEBUG */
#include "net/uip-debug.h"
#else
#define PRINTF(...)
#endif

#ifdef WITH_CONTIKI
# ifndef DEBUG
Expand All @@ -46,6 +57,12 @@ typedef enum { DTLS_LOG_EMERG=0, DTLS_LOG_ALERT, DTLS_LOG_CRIT, DTLS_LOG_WARN,
DTLS_LOG_NOTICE, DTLS_LOG_INFO, DTLS_LOG_DEBUG
} log_t;

/** Returns a zero-terminated string with the name of this library. */
const char *dtls_package_name();

/** Returns a zero-terminated string with the library version. */
const char *dtls_package_version();

#ifndef NDEBUG
/** Returns the current log level. */
log_t dtls_get_log_level();
Expand Down
17 changes: 16 additions & 1 deletion dtls.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
* SOFTWARE.
*/

#include "tinydtls.h"
#include "config.h"
#include "dtls_time.h"

Expand All @@ -41,6 +42,9 @@
#include "numeric.h"
#include "netq.h"
#include "dtls.h"

#include "alert.h"
#include "session.h"
#include "prng.h"

#ifdef WITH_SHA256
Expand Down Expand Up @@ -3743,6 +3747,7 @@ dtls_connect_peer(dtls_context_t *ctx, dtls_peer_t *peer) {
int
dtls_connect(dtls_context_t *ctx, const session_t *dst) {
dtls_peer_t *peer;
int res;

peer = dtls_get_peer(ctx, dst);

Expand All @@ -3754,7 +3759,17 @@ dtls_connect(dtls_context_t *ctx, const session_t *dst) {
return -1;
}

return dtls_connect_peer(ctx, peer);
res = dtls_connect_peer(ctx, peer);

/* Invoke event callback to indicate connection attempt or
* re-negotiation. */
if (res > 0) {
CALL(ctx, event, &peer->session, 0, DTLS_EVENT_CONNECT);
} else if (res == 0) {
CALL(ctx, event, &peer->session, 0, DTLS_EVENT_RENEGOTIATE);
}

return res;
}

static void
Expand Down
8 changes: 4 additions & 4 deletions dtls.h
Original file line number Diff line number Diff line change
Expand Up @@ -610,12 +610,12 @@ int get_psk_key(struct dtls_context_t *ctx,
* has changed can register an event handling function with the field @c event
* in the dtls_handler_t structure (see \ref dtls_server_example). The call-back
* function is called for alert messages and internal state changes. For alert
* messages, the argument @p level will be set to a value greate than zero, and
* messages, the argument @p level will be set to a value greater than zero, and
* @p code will indicate the notification code. For internal events, @p level
* is @c 0, and @p code a value greater than @c 255.
*
* Currently, the only defined internal event is @c DTLS_EVENT_CONNECTED. It
* indicates successful establishment of a new DTLS channel.
* Internal events are DTLS_EVENT_CONNECTED, @c DTLS_EVENT_CONNECT, and
* @c DTLS_EVENT_RENEGOTIATE.
*
* @code
int handle_event(struct dtls_context_t *ctx, session_t *session,
Expand Down Expand Up @@ -650,7 +650,7 @@ int handle_event(struct dtls_context_t *ctx, session_t *session,
* @code
#include "contiki.h"
#include "config.h"
#include "tinydtls.h"
#include "dtls.h"
#define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN])
Expand Down
2 changes: 2 additions & 0 deletions dtls_time.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
* @brief Clock Handling
*/

#include "tinydtls.h"
#include "config.h"
#include "dtls_time.h"

#ifdef WITH_CONTIKI
Expand Down
16 changes: 5 additions & 11 deletions dtls_time.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,10 @@
#ifndef _DTLS_DTLS_TIME_H_
#define _DTLS_DTLS_TIME_H_

#include "config.h"
#include <stdint.h>

#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#endif /* HAVE_SYS_TIME_H */

#include "tinydtls.h"

/**
* @defgroup clock Clock Handling
Expand All @@ -47,22 +45,18 @@

#ifdef WITH_CONTIKI
#include "clock.h"

typedef clock_time_t dtls_tick_t;
#else /* WITH_CONTIKI */

#ifdef HAVE_TIME_H
#include <time.h>
#endif

#ifndef CLOCK_SECOND
# define CLOCK_SECOND 1000
#endif

typedef uint32_t dtls_tick_t;

typedef uint32_t clock_time_t;
#endif /* WITH_CONTIKI */

typedef clock_time_t dtls_tick_t;

#ifndef DTLS_TICKS_PER_SECOND
#define DTLS_TICKS_PER_SECOND CLOCK_SECOND
#endif /* DTLS_TICKS_PER_SECOND */
Expand Down
Loading

0 comments on commit 9a2e0ad

Please sign in to comment.