Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into ecdh-merge
Browse files Browse the repository at this point in the history
  • Loading branch information
hauke committed Dec 11, 2013
2 parents 4e8b28c + fc22641 commit c0ed926
Show file tree
Hide file tree
Showing 6 changed files with 200 additions and 35 deletions.
10 changes: 9 additions & 1 deletion Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ LDFLAGS:=@LIBS@
ARFLAGS:=cru
doc:=doc

# files that should be ignored by git
GITIGNOREDS:= core \*~ \*.[oa] \*.gz \*.cap \*.pcap Makefile \
autom4te.cache/ config.h config.log config.status configure \
doc/Doxyfile doc/doxygen.out doc/html/ $(LIB) tests/ccm-test \
tests/dtls-client tests/dtls-server tests/prf-test $(package) \
$(DISTDIR)/ TAGS \*.patch .gitignore

.PHONY: all dirs clean install dist distclean .gitignore doc TAGS

.SUFFIXES:
Expand Down Expand Up @@ -122,4 +129,5 @@ TAGS:
mv $@.new $@

.gitignore:
echo "core\n*~\n*.[oa]\n*.gz\n*.cap\n$(PROGRAM)\n$(DISTDIR)\n.gitignore" >$@
echo $(GITIGNOREDS) | sed 's/ /\n/g' > $@

4 changes: 2 additions & 2 deletions 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--2012 Olaf Bergmann <[email protected]>
* Copyright (C) 2011--2013 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 @@ -298,7 +298,7 @@ dtls_ccm_decrypt_message(rijndael_ctx *ctx, size_t M, size_t L,
memxor(msg, S, M);

/* return length if MAC is valid, otherwise continue with error handling */
if (memcmp(X, msg, M) == 0)
if (equals(X, msg, M))
return len - M;

error:
Expand Down
4 changes: 2 additions & 2 deletions configure.in
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
#
# Copyright (C) 2011--2012 Olaf Bergmann <[email protected]>
# Copyright (C) 2011--2013 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 @@ -24,7 +24,7 @@
# SOFTWARE.

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

Expand Down
21 changes: 20 additions & 1 deletion global.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* dtls -- a very basic DTLS implementation
*
* Copyright (C) 2011--2012 Olaf Bergmann <[email protected]>
* Copyright (C) 2011--2013 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 @@ -188,6 +188,25 @@ memxor(unsigned char *x, const unsigned char *y, size_t n) {
}
}

/**
* Compares \p len bytes from @p a with @p b in constant time. This
* functions always traverses the entire length to prevent timing
* attacks.
*
* \param a Byte sequence to compare
* \param b Byte sequence to compare
* \param len Number of bytes to compare.
* \return \c 1 if \p a and \p b are equal, \c 0 otherwise.
*/
static inline int
equals(unsigned char *a, unsigned char *b, size_t len) {
int result = 1;
while (len--) {
result &= (*a++ == *b++);
}
return result;
}

#ifdef HAVE_FLS
#define dtls_fls(i) fls(i)
#else
Expand Down
6 changes: 2 additions & 4 deletions tests/ccm-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ PROCESS_THREAD(ccm_test_process, ev, d)
int main(int argc, char **argv) {
#endif /* WITH_CONTIKI */
long int len;
size_t L; /* max(2,(fls(lm) >> 3) + 1) */
int n;

rijndael_ctx ctx;
Expand All @@ -64,8 +63,7 @@ int main(int argc, char **argv) {
return -1;
}

L = 15 - 13; /* the Nonce in ccm-testdata.c is always 13 Bytes */
len = dtls_ccm_encrypt_message(&ctx, data[n].M, L, data[n].nonce,
len = dtls_ccm_encrypt_message(&ctx, data[n].M, data[n].L, data[n].nonce,
data[n].msg + data[n].la,
data[n].lm - data[n].la,
data[n].msg, data[n].la);
Expand All @@ -80,7 +78,7 @@ int main(int argc, char **argv) {
printf("result is (total length = %lu):\n\t", len);
dump(data[n].msg, len);

len = dtls_ccm_decrypt_message(&ctx, data[n].M, L, data[n].nonce,
len = dtls_ccm_decrypt_message(&ctx, data[n].M, data[n].L, data[n].nonce,
data[n].msg + data[n].la, len - data[n].la,
data[n].msg, data[n].la);

Expand Down
Loading

0 comments on commit c0ed926

Please sign in to comment.