Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v6.0.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
exclude: 'sha2/testvectors/.*dat$'
- id: check-merge-conflict

- repo: https://github.com/codespell-project/codespell
rev: v2.4.3
hooks:
Expand Down
1 change: 0 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,3 @@ dtls_peer_t *dtls_get_peer(const dtls_context_t *context,
let the library be backward compatible and mark the old function as
@deprecated in the doxygen comment. Please discuss needed changes
on the mailing list.

4 changes: 2 additions & 2 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
* Copyright (c) 2011, 2012, 2013, 2014, 2015, 2016 Olaf Bergmann (TZI) and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v. 1.0 which accompanies this distribution.
* and Eclipse Distribution License v. 1.0 which accompanies this distribution.
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
* Contributors:
* Olaf Bergmann - initial API and implementation
Expand Down
13 changes: 6 additions & 7 deletions Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# and Eclipse Distribution License v. 1.0 which accompanies this distribution.
#
# The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
# and the Eclipse Distribution License is available at
# and the Eclipse Distribution License is available at
# http://www.eclipse.org/org/documents/edl-v10.php.
#
# Contributors:
Expand Down Expand Up @@ -94,7 +94,7 @@ $(LIB).so: $(OBJECTS)
$(LINK.c) $(LDFLAGS) -shared $^ -o $@

$(LIB).a: $(OBJECTS)
$(AR) $(ARFLAGS) $@ $^
$(AR) $(ARFLAGS) $@ $^
$(RANLIB) $@

clean:
Expand All @@ -104,7 +104,7 @@ clean:
done
endif # WITH_CONTIKI

doc:
doc:
$(MAKE) -C doc

distclean: clean
Expand Down Expand Up @@ -141,9 +141,9 @@ uninstall:
done
if test -d $(DESTDIR)$(includedir) ; then $(RMDIR) $(DESTDIR)$(includedir) ; fi

TAGS:
$(ETAGS) -o $@.new $(SOURCES)
$(ETAGS) -a -o $@.new $(HEADERS)
TAGS:
$(ETAGS) -o $@.new $(SOURCES)
$(ETAGS) -a -o $@.new $(HEADERS)
mv $@.new $@

# files that should be ignored by git
Expand All @@ -158,4 +158,3 @@ GITIGNOREDS:= core \*~ \*.[oa] \*.gz \*.cap \*.pcap Makefile \

.gitignore:
echo $(GITIGNOREDS) | sed 's/ /\n/g' > $@

1 change: 0 additions & 1 deletion Makefile.tinydtls
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,3 @@ tinydtls_src = dtls.c crypto.c hmac.c rijndael.c rijndael_wrap.c sha2.c ccm.c ne
# This activates debugging support
# CFLAGS += -DNDEBUG
tinydtls_src += dtls_debug.c

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# About tinydtls

tinydtls is a library for Datagram Transport Layer Security (DTLS 1.2
tinydtls is a library for Datagram Transport Layer Security (DTLS 1.2
[RFC 6347](https://www.rfc-editor.org/rfc/rfc6347)) covering both the client
and the server state machine. It is implemented in C and provides support
for a minimal set of cipher suites suitable for the Internet of Things.
Expand Down
6 changes: 3 additions & 3 deletions aes/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# and Eclipse Distribution License v. 1.0 which accompanies this distribution.
#
# The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
# and the Eclipse Distribution License is available at
# and the Eclipse Distribution License is available at
# http://www.eclipse.org/org/documents/edl-v10.php.
#
# Contributors:
Expand All @@ -33,7 +33,7 @@ CPPFLAGS=@CPPFLAGS@
CFLAGS=-Wall -std=c99 -pedantic @CFLAGS@ @WARNING_CFLAGS@ $(EXTRA_CFLAGS)
LDFLAGS=@LDFLAGS@
LDLIBS=@LIBS@
FILES:=Makefile.in $(SOURCES) $(HEADERS)
FILES:=Makefile.in $(SOURCES) $(HEADERS)
DISTDIR=$(top_builddir)/@PACKAGE_TARNAME@-@PACKAGE_VERSION@

.PHONY: all dirs clean install dist distclean .gitignore doc uninstall
Expand All @@ -43,7 +43,7 @@ DISTDIR=$(top_builddir)/@PACKAGE_TARNAME@-@PACKAGE_VERSION@

all:

check:
check:
echo DISTDIR: $(DISTDIR)
echo top_builddir: $(top_builddir)

Expand Down
1 change: 0 additions & 1 deletion aes/rijndael.c
Original file line number Diff line number Diff line change
Expand Up @@ -1228,4 +1228,3 @@ rijndaelDecrypt(const aes_u32 rk[/*4*(Nr + 1)*/], int Nr, const aes_u8 ct[16],
PUTU32(pt + 12, s3);
}
#endif /* WITH_AES_DECRYPT */

2 changes: 1 addition & 1 deletion alert.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* and Eclipse Distribution License v. 1.0 which accompanies this distribution.
*
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* Contributors:
Expand Down
54 changes: 27 additions & 27 deletions ccm.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* and Eclipse Distribution License v. 1.0 which accompanies this distribution.
*
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* Contributors:
Expand Down Expand Up @@ -38,7 +38,7 @@
(A)[i_] |= (C) & 0xFF; \
}

static inline void
static inline void
block0(size_t M, /* number of auth bytes */
size_t L, /* number of bytes to encode message length */
size_t la, /* l(a) octets additional authenticated data */
Expand All @@ -51,16 +51,16 @@ block0(size_t M, /* number of auth bytes */

/* copy the nonce */
memcpy(result + 1, nonce, DTLS_CCM_BLOCKSIZE - L - 1);

for (i=0; i < L; i++) {
result[15-i] = lm & 0xff;
lm >>= 8;
}
}

/**
/**
* Creates the CBC-MAC for the additional authentication data that
* is sent in cleartext.
* is sent in cleartext.
*
* \param ctx The crypto context for the AES encryption.
* \param msg The message starting with the additional authentication data.
Expand All @@ -73,7 +73,7 @@ block0(size_t M, /* number of auth bytes */
*/
static void
add_auth_data(rijndael_ctx *ctx, const unsigned char *msg, uint64_t la,
unsigned char B[DTLS_CCM_BLOCKSIZE],
unsigned char B[DTLS_CCM_BLOCKSIZE],
unsigned char X[DTLS_CCM_BLOCKSIZE]) {
uint64_t i,j;

Expand Down Expand Up @@ -114,26 +114,26 @@ add_auth_data(rijndael_ctx *ctx, const unsigned char *msg, uint64_t la,
memcpy(B + j, msg, i);
la -= i;
msg += i;

memxor(B, X, DTLS_CCM_BLOCKSIZE);

rijndael_encrypt(ctx, B, X);

while (la > DTLS_CCM_BLOCKSIZE) {
for (i = 0; i < DTLS_CCM_BLOCKSIZE; ++i)
B[i] = X[i] ^ *msg++;
la -= DTLS_CCM_BLOCKSIZE;

rijndael_encrypt(ctx, B, X);
}

if (la) {
memset(B, 0, DTLS_CCM_BLOCKSIZE);
memcpy(B, msg, la);
memxor(B, X, DTLS_CCM_BLOCKSIZE);

rijndael_encrypt(ctx, B, X);
}
rijndael_encrypt(ctx, B, X);
}
}

static inline void
Expand All @@ -144,13 +144,13 @@ encrypt(rijndael_ctx *ctx, size_t L, unsigned long counter,

static unsigned long counter_tmp;

SET_COUNTER(A, L, counter, counter_tmp);
SET_COUNTER(A, L, counter, counter_tmp);
rijndael_encrypt(ctx, A, S);
memxor(msg, S, len);
}

static inline void
mac(rijndael_ctx *ctx,
mac(rijndael_ctx *ctx,
unsigned char *msg, size_t len,
unsigned char B[DTLS_CCM_BLOCKSIZE],
unsigned char X[DTLS_CCM_BLOCKSIZE]) {
Expand All @@ -164,9 +164,9 @@ mac(rijndael_ctx *ctx,
}

long int
dtls_ccm_encrypt_message(rijndael_ctx *ctx, size_t M, size_t L,
dtls_ccm_encrypt_message(rijndael_ctx *ctx, size_t M, size_t L,
const unsigned char nonce[DTLS_CCM_BLOCKSIZE],
unsigned char *msg, size_t lm,
unsigned char *msg, size_t lm,
const unsigned char *aad, size_t la) {
size_t i, len;
unsigned long counter_tmp;
Expand All @@ -187,7 +187,7 @@ dtls_ccm_encrypt_message(rijndael_ctx *ctx, size_t M, size_t L,

/* copy the nonce */
memcpy(A + 1, nonce, DTLS_CCM_BLOCKSIZE - L - 1);

while (lm >= DTLS_CCM_BLOCKSIZE) {
/* calculate MAC */
mac(ctx, msg, DTLS_CCM_BLOCKSIZE, B, X);
Expand Down Expand Up @@ -216,8 +216,8 @@ dtls_ccm_encrypt_message(rijndael_ctx *ctx, size_t M, size_t L,
/* update local pointers */
msg += lm;
}
/* calculate S_0 */

/* calculate S_0 */
SET_COUNTER(A, L, 0, counter_tmp);
rijndael_encrypt(ctx, A, S);

Expand All @@ -230,9 +230,9 @@ dtls_ccm_encrypt_message(rijndael_ctx *ctx, size_t M, size_t L,
long int
dtls_ccm_decrypt_message(rijndael_ctx *ctx, size_t M, size_t L,
const unsigned char nonce[DTLS_CCM_BLOCKSIZE],
unsigned char *msg, size_t lm,
unsigned char *msg, size_t lm,
const unsigned char *aad, size_t la) {

size_t len;
unsigned long counter_tmp;
unsigned long counter = 1; /* \bug does not work correctly on ia32 when
Expand All @@ -257,11 +257,11 @@ dtls_ccm_decrypt_message(rijndael_ctx *ctx, size_t M, size_t L,

/* copy the nonce */
memcpy(A + 1, nonce, DTLS_CCM_BLOCKSIZE - L - 1);

while (lm >= DTLS_CCM_BLOCKSIZE) {
/* decrypt */
encrypt(ctx, L, counter, msg, DTLS_CCM_BLOCKSIZE, A, S);

/* calculate MAC */
mac(ctx, msg, DTLS_CCM_BLOCKSIZE, B, X);

Expand All @@ -281,13 +281,13 @@ dtls_ccm_decrypt_message(rijndael_ctx *ctx, size_t M, size_t L,
* (i.e., we can use memcpy() here).
*/
memcpy(B + lm, X + lm, DTLS_CCM_BLOCKSIZE - lm);
mac(ctx, msg, lm, B, X);
mac(ctx, msg, lm, B, X);

/* update local pointers */
msg += lm;
}
/* calculate S_0 */

/* calculate S_0 */
SET_COUNTER(A, L, 0, counter_tmp);
rijndael_encrypt(ctx, A, S);

Expand All @@ -296,7 +296,7 @@ dtls_ccm_decrypt_message(rijndael_ctx *ctx, size_t M, size_t L,
/* return length if MAC is valid, otherwise continue with error handling */
if (equals(X, msg, M))
return len - M;

error:
return -1;
}
20 changes: 10 additions & 10 deletions ccm.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* and Eclipse Distribution License v. 1.0 which accompanies this distribution.
*
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* Contributors:
Expand All @@ -26,18 +26,18 @@
#define DTLS_CCM_MAX 16 /**< max number of bytes in digest */
#define DTLS_CCM_NONCE_SIZE 12 /**< size of nonce */

/**
/**
* Authenticates and encrypts a message using AES in CCM mode. Please
* see also RFC 3610 for the meaning of \p M, \p L, \p lm and \p la.
*
*
* \param ctx The initialized rijndael_ctx object to be used for AES operations.
* \param M The number of authentication octets.
* \param L The number of bytes used to encode the message length.
* \param nonce The nonce value to use. You must provide \c DTLS_CCM_BLOCKSIZE
* \param nonce The nonce value to use. You must provide \c DTLS_CCM_BLOCKSIZE
* nonce octets, although only the first \c 16 - \p L - 1 are used.
* \param msg The message to encrypt. The first \p la octets are additional
* authentication data that will be cleartext. Note that the
* encryption operation modifies the contents of \p msg and adds
* authentication data that will be cleartext. Note that the
* encryption operation modifies the contents of \p msg and adds
* \p M bytes MAC. Therefore, the buffer must be at least
* \p lm + \p M bytes large.
* \param lm The actual length of \p msg.
Expand All @@ -47,15 +47,15 @@
* \return FIXME
*/
long int
dtls_ccm_encrypt_message(rijndael_ctx *ctx, size_t M, size_t L,
dtls_ccm_encrypt_message(rijndael_ctx *ctx, size_t M, size_t L,
const unsigned char nonce[DTLS_CCM_BLOCKSIZE],
unsigned char *msg, size_t lm,
unsigned char *msg, size_t lm,
const unsigned char *aad, size_t la);

long int
dtls_ccm_decrypt_message(rijndael_ctx *ctx, size_t M, size_t L,
dtls_ccm_decrypt_message(rijndael_ctx *ctx, size_t M, size_t L,
const unsigned char nonce[DTLS_CCM_BLOCKSIZE],
unsigned char *msg, size_t lm,
unsigned char *msg, size_t lm,
const unsigned char *aad, size_t la);

#endif /* _DTLS_CCM_H_ */
8 changes: 4 additions & 4 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# and Eclipse Distribution License v. 1.0 which accompanies this distribution.
#
# The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
# and the Eclipse Distribution License is available at
# and the Eclipse Distribution License is available at
# http://www.eclipse.org/org/documents/edl-v10.php.
#
# Contributors:
Expand Down Expand Up @@ -68,7 +68,7 @@ AC_SEARCH_LIBS([socket], [socket])
AC_ARG_WITH(debug,
[AS_HELP_STRING([--without-debug],[disable all debug output and assertions])],
[CPPFLAGS="${CPPFLAGS} -DNDEBUG"
NDEBUG=1],
NDEBUG=1],
[])

AC_ARG_WITH(ecc,
Expand Down Expand Up @@ -151,8 +151,8 @@ AC_C_INLINE
AC_TYPE_SIZE_T

AC_CHECK_MEMBER([struct sockaddr_in6.sin6_len],
[AC_DEFINE(HAVE_SOCKADDR_IN6_SIN6_LEN, [1],
[Define to 1 if struct sockaddr_in6 has a member sin6_len.])], [],
[AC_DEFINE(HAVE_SOCKADDR_IN6_SIN6_LEN, [1],
[Define to 1 if struct sockaddr_in6 has a member sin6_len.])], [],
[#include <netinet/in.h>])

# Checks for library functions.
Expand Down
Loading
Loading