diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 236c8d4d..486fe6ce 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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: diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 9d73884e..aa51c140 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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. - diff --git a/LICENSE b/LICENSE index f4111b7f..87952ad2 100644 --- a/LICENSE +++ b/LICENSE @@ -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 diff --git a/Makefile.in b/Makefile.in index 1866b44a..89cf90f3 100644 --- a/Makefile.in +++ b/Makefile.in @@ -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: @@ -94,7 +94,7 @@ $(LIB).so: $(OBJECTS) $(LINK.c) $(LDFLAGS) -shared $^ -o $@ $(LIB).a: $(OBJECTS) - $(AR) $(ARFLAGS) $@ $^ + $(AR) $(ARFLAGS) $@ $^ $(RANLIB) $@ clean: @@ -104,7 +104,7 @@ clean: done endif # WITH_CONTIKI -doc: +doc: $(MAKE) -C doc distclean: clean @@ -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 @@ -158,4 +158,3 @@ GITIGNOREDS:= core \*~ \*.[oa] \*.gz \*.cap \*.pcap Makefile \ .gitignore: echo $(GITIGNOREDS) | sed 's/ /\n/g' > $@ - diff --git a/Makefile.tinydtls b/Makefile.tinydtls index e8cf956b..3ee2fb77 100644 --- a/Makefile.tinydtls +++ b/Makefile.tinydtls @@ -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 - diff --git a/README.md b/README.md index da5aeda6..16d14684 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/aes/Makefile.in b/aes/Makefile.in index 30d5bc5a..f315fe44 100644 --- a/aes/Makefile.in +++ b/aes/Makefile.in @@ -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: @@ -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 @@ -43,7 +43,7 @@ DISTDIR=$(top_builddir)/@PACKAGE_TARNAME@-@PACKAGE_VERSION@ all: -check: +check: echo DISTDIR: $(DISTDIR) echo top_builddir: $(top_builddir) diff --git a/aes/rijndael.c b/aes/rijndael.c index ac4395d2..7cf3613c 100644 --- a/aes/rijndael.c +++ b/aes/rijndael.c @@ -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 */ - diff --git a/alert.h b/alert.h index 081e898b..e40dc354 100644 --- a/alert.h +++ b/alert.h @@ -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: diff --git a/ccm.c b/ccm.c index ac809593..26538d1b 100644 --- a/ccm.c +++ b/ccm.c @@ -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: @@ -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 */ @@ -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. @@ -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; @@ -114,11 +114,11 @@ 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++; @@ -126,14 +126,14 @@ add_auth_data(rijndael_ctx *ctx, const unsigned char *msg, uint64_t la, 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 @@ -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]) { @@ -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; @@ -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); @@ -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); @@ -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 @@ -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); @@ -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); @@ -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; } diff --git a/ccm.h b/ccm.h index def7fe82..02e01da3 100644 --- a/ccm.h +++ b/ccm.h @@ -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: @@ -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. @@ -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_ */ diff --git a/configure.ac b/configure.ac index 92c6cd23..cb20630e 100644 --- a/configure.ac +++ b/configure.ac @@ -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: @@ -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, @@ -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 ]) # Checks for library functions. diff --git a/crypto.c b/crypto.c index ff54bb5d..6177a40a 100644 --- a/crypto.c +++ b/crypto.c @@ -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: @@ -258,7 +258,7 @@ dtls_p_hash(dtls_hashfunc_t h, return buflen; } -size_t +size_t dtls_prf(const unsigned char *key, size_t keylen, const unsigned char *label, size_t labellen, const unsigned char *random1, size_t random1len, @@ -267,16 +267,16 @@ dtls_prf(const unsigned char *key, size_t keylen, /* Clear the result buffer */ memset(buf, 0, buflen); - return dtls_p_hash(HASH_SHA256, - key, keylen, - label, labellen, + return dtls_p_hash(HASH_SHA256, + key, keylen, + label, labellen, random1, random1len, random2, random2len, buf, buflen); } void -dtls_mac(dtls_hmac_context_t *hmac_ctx, +dtls_mac(dtls_hmac_context_t *hmac_ctx, const unsigned char *record, const unsigned char *packet, size_t length, unsigned char *buf) { @@ -288,13 +288,13 @@ dtls_mac(dtls_hmac_context_t *hmac_ctx, dtls_hmac_update(hmac_ctx, record, sizeof(uint8) + sizeof(uint16)); dtls_hmac_update(hmac_ctx, L, sizeof(uint16)); dtls_hmac_update(hmac_ctx, packet, length); - + dtls_hmac_finalize(hmac_ctx, buf); } static size_t dtls_ccm_encrypt(aes128_ccm_t *ccm_ctx, const unsigned char *src, size_t srclen, - unsigned char *buf, + unsigned char *buf, const unsigned char *nonce, const unsigned char *aad, size_t la) { long int len; @@ -348,7 +348,7 @@ dtls_psk_pre_master_secret(unsigned char *key, size_t keylen, memcpy(p, result, sizeof(uint16)); p += sizeof(uint16); - + memcpy(p, key, keylen); return 2 * (sizeof(uint16) + keylen); @@ -389,7 +389,7 @@ int dtls_ec_key_asn1_from_uint32(const uint32_t *key, size_t key_size, uint8_t *buf) { int i = 0; uint8_t *lptr; - + /* ASN.1 Integer r */ dtls_int_to_uint8(buf, 0x02); buf += sizeof(uint8); @@ -399,7 +399,7 @@ int dtls_ec_key_asn1_from_uint32(const uint32_t *key, size_t key_size, buf += sizeof(uint8); dtls_ec_key_from_uint32(key, key_size, buf); - + /* skip leading 0's */ while (i < (int)key_size && buf[i] == 0) { ++i; @@ -410,7 +410,7 @@ int dtls_ec_key_asn1_from_uint32(const uint32_t *key, size_t key_size, return 0; } if (buf[i] >= 0x80) { - /* + /* * Preserve unsigned by adding leading 0 (i may go negative which is * explicitly handled below with the assumption that buf is at least 33 * bytes in size). @@ -429,7 +429,7 @@ int dtls_ec_key_asn1_from_uint32(const uint32_t *key, size_t key_size, } /* Update the length of positive ASN.1 integer */ dtls_int_to_uint8(lptr, key_size); - return key_size + 2; + return key_size + 2; } int dtls_ecdh_pre_master_secret(unsigned char *priv_key, @@ -488,7 +488,7 @@ dtls_ecdsa_create_sig_hash(const unsigned char *priv_key, size_t key_size, uint32_t priv[8]; uint32_t hash[8]; uint32_t randv[8]; - + dtls_ec_key_to_uint32(priv_key, key_size, priv); dtls_ec_key_to_uint32(sign_hash, sign_hash_size, hash); do { @@ -511,7 +511,7 @@ dtls_ecdsa_create_sig(const unsigned char *priv_key, size_t key_size, dtls_hash_update(&data, server_random, server_random_size); dtls_hash_update(&data, keyx_params, keyx_params_size); dtls_hash_finalize(sha256hash, &data); - + dtls_ecdsa_create_sig_hash(priv_key, key_size, sha256hash, sizeof(sha256hash), point_r, point_s); } @@ -546,7 +546,7 @@ dtls_ecdsa_verify_sig(const unsigned char *pub_key_x, unsigned char *result_r, unsigned char *result_s) { dtls_hash_ctx data; unsigned char sha256hash[DTLS_HMAC_DIGEST_SIZE]; - + dtls_hash_init(&data); dtls_hash_update(&data, client_random, client_random_size); dtls_hash_update(&data, server_random, server_random_size); @@ -585,7 +585,7 @@ dtls_encrypt_params(const dtls_ccm_params_t *params, return ret; } -int +int dtls_encrypt(const unsigned char *src, size_t length, unsigned char *buf, const unsigned char *nonce, diff --git a/crypto.h b/crypto.h index 18616832..70cfafb5 100644 --- a/crypto.h +++ b/crypto.h @@ -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: @@ -40,9 +40,9 @@ /* EC key size for curve secp256r1 */ #define DTLS_EC_KEY_SIZE 32 -/** - * Maximum size of the generated keyblock. Note that MAX_KEYBLOCK_LENGTH must - * be large enough to hold the pre_master_secret, i.e. twice the length of the +/** + * Maximum size of the generated keyblock. Note that MAX_KEYBLOCK_LENGTH must + * be large enough to hold the pre_master_secret, i.e. twice the length of the * pre-shared key + 1. */ #define MAX_KEYBLOCK_LENGTH \ @@ -60,7 +60,7 @@ typedef uint8_t dtls_cipher_index_t; /** Maximum number of cipher suites */ #define DTLS_MAX_CIPHER_SUITES 4 -typedef enum { AES128=0 +typedef enum { AES128=0 } dtls_crypto_alg; typedef enum { @@ -120,14 +120,14 @@ typedef struct { uint16_t epoch; /**< counter for cipher state changes*/ uint64_t rseq; /**< sequence number of last record sent */ - /** + /** * The key block generated from PRF applied to client and server * random bytes. The actual size is given by the selected cipher and * can be calculated using dtls_kb_size(). Use \c dtls_kb_ macros to * access the components of the key block. */ uint8 key_block[MAX_KEYBLOCK_LENGTH]; - + seqnum_t cseq; /**ifindex to send the data. @@ -82,26 +82,26 @@ typedef struct { * remote peer where the data shall be sent. * @param buf The data to send. * @param len The actual length of @p buf. - * @return The callback function must return the number of bytes - * that were sent, or a value less than zero to indicate an + * @return The callback function must return the number of bytes + * that were sent, or a value less than zero to indicate an * error. */ - int (*write)(struct dtls_context_t *ctx, + int (*write)(struct dtls_context_t *ctx, session_t *session, uint8 *buf, size_t len); - /** - * Called from dtls_handle_message() deliver application data that was + /** + * Called from dtls_handle_message() deliver application data that was * received on the given session. The data is delivered only after - * decryption and verification have succeeded. + * decryption and verification have succeeded. * * @param ctx The current DTLS context. * @param session The session object, including the address of the - * data's origin. + * data's origin. * @param buf The received data packet. * @param len The actual length of @p buf. * @return ignored */ - int (*read)(struct dtls_context_t *ctx, + int (*read)(struct dtls_context_t *ctx, session_t *session, uint8 *buf, size_t len); /** @@ -110,13 +110,13 @@ typedef struct { * * @param ctx The current dtls context. * @param session The session object that was affected. - * @param level The alert level or @c 0 when an event occurred that - * is not an alert. + * @param level The alert level or @c 0 when an event occurred that + * is not an alert. * @param code Values less than @c 256 indicate alerts, while * @c 256 or greater indicate internal DTLS session changes. * @return ignored */ - int (*event)(struct dtls_context_t *ctx, session_t *session, + int (*event)(struct dtls_context_t *ctx, session_t *session, dtls_alert_level_t level, unsigned short code); /** @@ -165,14 +165,14 @@ typedef struct { #ifdef DTLS_ECC /** * Called during handshake to get the server's or client's ecdsa - * key used to authenticate this server or client in this - * session. If found, the key must be stored in @p result and - * the return value must be @c 0. If not found, @p result is + * key used to authenticate this server or client in this + * session. If found, the key must be stored in @p result and + * the return value must be @c 0. If not found, @p result is * undefined and the return value must be less than zero. * * If ECDSA should not be supported, set this pointer to NULL. * - * Implement this if you want to provide your own certificate to + * Implement this if you want to provide your own certificate to * the other peer. This is mandatory for a server providing ECDSA * support and optional for a client. A client doing DTLS client * authentication has to implementing this callback. @@ -183,7 +183,7 @@ typedef struct { * session. * @return @c 0 if result is set, or less than zero on error. */ - int (*get_ecdsa_key)(struct dtls_context_t *ctx, + int (*get_ecdsa_key)(struct dtls_context_t *ctx, const session_t *session, const dtls_ecdsa_key_t **result); @@ -213,7 +213,7 @@ typedef struct { * return dtls_alert_fatal_create(DTLS_ALERT_CERTIFICATE_UNKNOWN); * return dtls_alert_fatal_create(DTLS_ALERT_UNKNOWN_CA); */ - int (*verify_ecdsa_key)(struct dtls_context_t *ctx, + int (*verify_ecdsa_key)(struct dtls_context_t *ctx, const session_t *session, const unsigned char *other_pub_x, const unsigned char *other_pub_y, @@ -240,13 +240,13 @@ typedef struct dtls_context_t { dtls_handler_t *h; /**< callback handlers */ } dtls_context_t; -/** +/** * This function initializes the tinyDTLS memory management and must * be called first. */ void dtls_init(void); -/** +/** * Creates a new context object. The storage allocated for the new * object must be released with dtls_free_context(). */ dtls_context_t *dtls_new_context(void *app_data); @@ -309,15 +309,15 @@ int dtls_writev(struct dtls_context_t *ctx, session_t *session, uint8 *buf_array[], size_t buf_len_array[], size_t buf_array_len); -/** +/** * Writes the application data given in @p buf to the peer specified * by @p session. - * + * * @param ctx The DTLS context to use. * @param session The remote transport address and local interface. * @param buf The data to write. * @param len The actual length of @p data. - * + * * @return The number of bytes written, @c -1 on error or @c 0 * if the peer already exists but is not connected yet. */ @@ -326,7 +326,7 @@ int dtls_write(struct dtls_context_t *ctx, session_t *session, /** * Checks sendqueue of given DTLS context object for any outstanding - * packets to be transmitted. + * packets to be transmitted. * * @param context The DTLS context object to use. * @param next If not NULL, @p next is filled with the timestamp @@ -405,21 +405,21 @@ PACK(typedef struct) { uint16 version; /**< Server version */ uint8 cookie_length; /**< Length of the included cookie */ uint8 cookie[]; /**< up to 32 bytes making up the cookie */ -} dtls_hello_verify_t; +} dtls_hello_verify_t; #if 0 -/** +/** * Checks a received DTLS record for consistency and eventually decrypt, - * verify, decompress and reassemble the contained fragment for - * delivery to high-lever clients. - * - * \param state The DTLS record state for the current session. - * \param + * verify, decompress and reassemble the contained fragment for + * delivery to high-lever clients. + * + * \param state The DTLS record state for the current session. + * \param */ int dtls_record_read(dtls_state_t *state, uint8 *msg, int msglen); #endif -/** +/** * Handles incoming data as DTLS message from given peer. * * @param ctx The dtls context to use. @@ -454,7 +454,7 @@ void dtls_reset_peer(dtls_context_t *context, dtls_peer_t *peer); #endif /* _DTLS_DTLS_H_ */ /** - * @mainpage + * @mainpage * * @author Olaf Bergmann, TZI Uni Bremen * @@ -465,9 +465,9 @@ void dtls_reset_peer(dtls_context_t *context, dtls_peer_t *peer); * * @section license License * - * This software is under the MIT License. - * + * * @subsection uthash UTHash * * This library uses uthash to manage @@ -476,22 +476,22 @@ void dtls_reset_peer(dtls_context_t *context, dtls_peer_t *peer); * * @subsection sha256 Aaron D. Gifford's SHA256 Implementation * - * tinyDTLS provides HMAC-SHA256 with BSD-licensed code from Aaron D. Gifford, + * tinyDTLS provides HMAC-SHA256 with BSD-licensed code from Aaron D. Gifford, * see www.aarongifford.com. * * @subsection aes Rijndael Implementation From OpenBSD * - * The AES implementation is taken from rijndael.{c,h} contained in the crypto + * The AES implementation is taken from rijndael.{c,h} contained in the crypto * sub-system of the OpenBSD operating system. It is copyright by Vincent Rijmen, * - * Antoon Bosselaers and Paulo Barreto. See rijndael.c + * Antoon Bosselaers and Paulo Barreto. See rijndael.c * for License info. * * @section download Getting the Files * - * You can get the sources either from the downloads section or - * through git from the downloads section or + * through git from the project develop page. * * @section config Configuration @@ -501,7 +501,7 @@ void dtls_reset_peer(dtls_context_t *context, dtls_peer_t *peer); * * @section build Building * - * After configuration, just type + * After configuration, just type * @code make * @endcode @@ -517,18 +517,18 @@ make install * * @section dtls_server_example DTLS Server Example * - * This section shows how to use the DTLS library functions to setup a + * This section shows how to use the DTLS library functions to setup a * simple secure UDP echo server. The application is responsible for the * entire network communication and thus will look like a usual UDP * server with socket creation and binding and a typical select-loop as - * shown below. The minimum configuration required for DTLS is the + * shown below. The minimum configuration required for DTLS is the * creation of the dtls_context_t using dtls_new_context(), and a callback * for sending data. Received packets are read by the application and - * passed to dtls_handle_message() as shown in @ref dtls_read_cb. - * For any useful communication to happen, read and write call backs - * and a key management function should be registered as well. - * - * @code + * passed to dtls_handle_message() as shown in @ref dtls_read_cb. + * For any useful communication to happen, read and write call backs + * and a key management function should be registered as well. + * + * @code dtls_context_t *the_context = NULL; int fd, result; @@ -549,21 +549,21 @@ make install while (1) { ...initialize fd_set rfds and timeout ... result = select(fd+1, &rfds, NULL, 0, NULL); - + if (FD_ISSET(fd, &rfds)) dtls_handle_read(the_context); } dtls_free_context(the_context); * @endcode - * + * * @subsection dtls_read_cb The Read Callback * * The DTLS library expects received raw data to be passed to * dtls_handle_message(). The application is responsible for * filling a session_t structure with the address data of the * remote peer as illustrated by the following example: - * + * * @code int dtls_handle_read(struct dtls_context_t *ctx) { int *fd; @@ -577,23 +577,23 @@ int dtls_handle_read(struct dtls_context_t *ctx) { session.size = sizeof(session.addr); len = recvfrom(*fd, buf, sizeof(buf), 0, &session.addr.sa, &session.size); - + return len < 0 ? len : dtls_handle_message(ctx, &session, buf, len); -} - * @endcode - * +} + * @endcode + * * Once a new DTLS session was established and DTLS ApplicationData has been - * received, the DTLS server invokes the read callback with the MAC-verified + * received, the DTLS server invokes the read callback with the MAC-verified * cleartext data as its argument. A read callback for a simple echo server * could look like this: * @code int read_from_peer(struct dtls_context_t *ctx, session_t *session, uint8 *data, size_t len) { return dtls_write(ctx, session, data, len); } - * @endcode - * + * @endcode + * * @subsection dtls_send_cb The Send Callback - * + * * The callback function send_to_peer() is called whenever data must be * sent over the network. Here, the sendto() system call is used to * transmit data within the given session. The socket descriptor required @@ -608,22 +608,22 @@ int send_to_peer(struct dtls_context_t *ctx, session_t *session, uint8 *data, si return sendto(fd, data, len, MSG_DONTWAIT, &session->addr.sa, session->size); } * @endcode - * + * * @subsection dtls_get_psk_info The Key Storage * * When a new DTLS session is created, the library must ask the application * for keying material. To do so, it invokes the registered call-back function * get_psk_info() with the current context and session information as parameter. - * When the call-back function is invoked with the parameter @p type set to + * When the call-back function is invoked with the parameter @p type set to * @c DTLS_PSK_IDENTITY, the result parameter @p result must be filled with - * the psk_identity_hint in case of a server, or the actual psk_identity in + * the psk_identity_hint in case of a server, or the actual psk_identity in * case of a client. When @p type is @c DTLS_PSK_KEY, the result parameter * must be filled with a key for the given identity @p id. The function must * return the number of bytes written to @p result which must not exceed * @p result_length. - * In case of an error, the function must return a negative value that + * In case of an error, the function must return a negative value that * corresponds to a valid error code defined in alert.h. - * + * * @code int get_psk_info(struct dtls_context_t *ctx UNUSED_PARAM, const session_t *session UNUSED_PARAM, @@ -658,7 +658,7 @@ int get_psk_info(struct dtls_context_t *ctx UNUSED_PARAM, return dtls_alert_fatal_create(DTLS_ALERT_INTERNAL_ERROR); } * @endcode - * + * * @subsection dtls_events The Event Notifier * * Applications that want to be notified whenever the status of a DTLS session @@ -667,13 +667,13 @@ int get_psk_info(struct dtls_context_t *ctx UNUSED_PARAM, * function is called for alert messages and internal state changes. For alert * 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. + * is @c 0, and @p code a value greater than @c 255. * * 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, +int handle_event(struct dtls_context_t *ctx, session_t *session, dtls_alert_level_t level, unsigned short code) { ... do something with event ... return 0; @@ -693,14 +693,14 @@ int handle_event(struct dtls_context_t *ctx, session_t *session, /** * @addtogroup contiki Contiki * - * To use tinyDTLS as Contiki application, place the source code in the directory + * To use tinyDTLS as Contiki application, place the source code in the directory * @c apps/tinydtls in the Contiki source tree and invoke configure with the option - * @c --with-contiki. This will define WITH_CONTIKI in tinydtls.h and include + * @c --with-contiki. This will define WITH_CONTIKI in tinydtls.h and include * @c Makefile.contiki in the main Makefile. To cross-compile for another platform * you will need to set your host and build system accordingly. For example, * when configuring for ARM, you would invoke * @code -./configure --with-contiki --build=x86_64-linux-gnu --host=arm-none-eabi +./configure --with-contiki --build=x86_64-linux-gnu --host=arm-none-eabi * @endcode * on an x86_64 linux host. * @@ -756,7 +756,7 @@ PROCESS_THREAD(server_process, ev, data) uip_ipaddr_copy(&session.addr, &UIP_IP_BUF->srcipaddr); session.port = UIP_UDP_BUF->srcport; session.size = sizeof(session.addr) + sizeof(session.port); - + dtls_handle_message(ctx, &session, uip_appdata, uip_datalen()); } } diff --git a/dtls_config.h.cmake.in b/dtls_config.h.cmake.in index 89bf5548..44293b47 100644 --- a/dtls_config.h.cmake.in +++ b/dtls_config.h.cmake.in @@ -6,7 +6,7 @@ * information regarding copyright ownership. * * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 1.0 + * terms of the Eclipse Public License 1.0 * which is available at https://www.eclipse.org/legal/epl-v10.html * and the Eclipse Distribution License v. 1.0 * available at http://www.eclipse.org/org/documents/edl-v10.php @@ -156,10 +156,10 @@ /* TODO Define to `__inline__' or `__inline' if that's what the C compiler - calls it, or to nothing if 'inline' is not supported under any name. + calls it, or to nothing if 'inline' is not supported under any name. #ifndef __cplusplus #undef inline #endif - Define to `unsigned int' if does not define. + Define to `unsigned int' if does not define. #undef size_t */ diff --git a/dtls_debug.h b/dtls_debug.h index a02cab4e..04f9384e 100644 --- a/dtls_debug.h +++ b/dtls_debug.h @@ -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: @@ -62,7 +62,7 @@ static inline void check_stack(void) { #endif /** Pre-defined log levels akin to what is used in \b syslog. */ -typedef enum { DTLS_LOG_EMERG=0, DTLS_LOG_ALERT, DTLS_LOG_CRIT, DTLS_LOG_WARN, +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; @@ -96,7 +96,7 @@ typedef void (*dtls_log_handler_t) (log_t level, const char *message); */ void dtls_set_log_handler(dtls_log_handler_t app_handler); -/** +/** * Writes the given text to \c stdout. The text is output only when \p * level is below or equal to the log level that set by * set_log_level(). */ diff --git a/dtls_mutex.h b/dtls_mutex.h index fe46ca1b..dfe8dee4 100644 --- a/dtls_mutex.h +++ b/dtls_mutex.h @@ -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: diff --git a/dtls_prng.c b/dtls_prng.c index 1ccbf553..704b8a6c 100644 --- a/dtls_prng.c +++ b/dtls_prng.c @@ -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: diff --git a/dtls_prng.h b/dtls_prng.h index c445c80d..90a51ec3 100644 --- a/dtls_prng.h +++ b/dtls_prng.h @@ -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: @@ -16,7 +16,7 @@ * *******************************************************************************/ -/** +/** * @file dtls_prng.h * @brief Pseudo Random Numbers */ @@ -27,7 +27,7 @@ #include "tinydtls.h" #include -/** +/** * @defgroup prng Pseudo Random Numbers * @{ */ diff --git a/dtls_time.c b/dtls_time.c index 9a9cecf9..2b7f2d7c 100644 --- a/dtls_time.c +++ b/dtls_time.c @@ -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: @@ -87,8 +87,8 @@ dtls_clock_init(void) { dtls_clock_offset = time(NULL); #else # ifdef __GNUC__ - /* Issue a warning when using gcc. Other prepropressors do - * not seem to have a similar feature. */ + /* Issue a warning when using gcc. Other prepropressors do + * not seem to have a similar feature. */ # warning "cannot initialize clock" # endif dtls_clock_offset = 0; @@ -99,14 +99,14 @@ void dtls_ticks(dtls_tick_t *t) { #ifdef HAVE_SYS_TIME_H struct timeval tv; gettimeofday(&tv, NULL); - *t = (tv.tv_sec - dtls_clock_offset) * DTLS_TICKS_PER_SECOND + *t = (tv.tv_sec - dtls_clock_offset) * DTLS_TICKS_PER_SECOND + (tv.tv_usec * DTLS_TICKS_PER_SECOND / 1000000); #elif defined(_MSC_VER) SYSTEMTIME current_time; GetSystemTime(¤t_time); - *t = (current_time.wSecond - dtls_clock_offset) * DTLS_TICKS_PER_SECOND + *t = (current_time.wSecond - dtls_clock_offset) * DTLS_TICKS_PER_SECOND + (current_time.wMilliseconds * DTLS_TICKS_PER_SECOND / 1000); #else diff --git a/dtls_time.h b/dtls_time.h index ee2eaedd..fc6692a3 100644 --- a/dtls_time.h +++ b/dtls_time.h @@ -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: diff --git a/ecc/Makefile.in b/ecc/Makefile.in index 9ecc0426..868c3537 100644 --- a/ecc/Makefile.in +++ b/ecc/Makefile.in @@ -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: @@ -29,7 +29,7 @@ top_srcdir:= @top_srcdir@ ECC_SOURCES:= ecc.c testecc.c testfield.c test_helper.c ECC_HEADERS:= ecc.h test_helper.h -FILES:=Makefile.in Makefile.contiki $(ECC_SOURCES) $(ECC_HEADERS) +FILES:=Makefile.in Makefile.contiki $(ECC_SOURCES) $(ECC_HEADERS) DISTDIR=$(top_builddir)/@PACKAGE_TARNAME@-@PACKAGE_VERSION@ ifeq ("@WITH_CONTIKI@", "1") @@ -56,7 +56,7 @@ testecc: ecc_test.o test_helper.o testfield: ecc_test.o test_helper.o -check: +check: echo DISTDIR: $(DISTDIR) echo top_builddir: $(top_builddir) diff --git a/ecc/ecc.c b/ecc/ecc.c index f39a7b0a..d65ef088 100644 --- a/ecc/ecc.c +++ b/ecc/ecc.c @@ -51,7 +51,7 @@ static uint32_t add( const uint32_t *x, const uint32_t *y, uint32_t *result, uin result[v] = d; d = d>>32; //save carry } - + return (uint32_t)d; } @@ -63,7 +63,7 @@ static uint32_t sub( const uint32_t *x, const uint32_t *y, uint32_t *result, uin result[v] = d & 0xFFFFFFFF; d = d>>32; d &= 0x1; - } + } return (uint32_t)d; } @@ -81,7 +81,7 @@ static void rshiftby(const uint32_t *in, uint8_t in_size, uint32_t *out, uint8_t static const uint32_t ecc_prime_m[8] = {0xffffffff, 0xffffffff, 0xffffffff, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0xffffffff}; - + /* This is added after an static byte addition if the answer has a carry in MSB*/ static const uint32_t ecc_prime_r[8] = {0x00000001, 0x00000000, 0x00000000, 0xffffffff, 0xffffffff, 0xffffffff, 0xfffffffe, 0x00000000}; @@ -165,7 +165,7 @@ static int fieldMult(const uint32_t *x, const uint32_t *y, uint32_t *result, uin uint8_t k, n; uint64_t l; for (k = 0; k < length; k++){ - for (n = 0; n < length; n++){ + for (n = 0; n < length; n++){ l = (uint64_t)x[n]*(uint64_t)y[k]; temp[n+k] = l&0xFFFFFFFF; temp[n+k+1] = l>>32; @@ -186,66 +186,66 @@ static void fieldModP(uint32_t *A, const uint32_t *B) uint8_t n; setZero(tempm, 8); setZero(tempm2, 8); - /* A = T */ + /* A = T */ copy(B,A,arrayLength); - /* Form S1 */ - for(n=0;n<3;n++) tempm[n]=0; + /* Form S1 */ + for(n=0;n<3;n++) tempm[n]=0; for(n=3;n<8;n++) tempm[n]=B[n+8]; - /* tempm2=T+S1 */ + /* tempm2=T+S1 */ fieldAdd(A,tempm,ecc_prime_r,tempm2); - /* A=T+S1+S1 */ + /* A=T+S1+S1 */ fieldAdd(tempm2,tempm,ecc_prime_r,A); - /* Form S2 */ - for(n=0;n<3;n++) tempm[n]=0; - for(n=3;n<7;n++) tempm[n]=B[n+9]; + /* Form S2 */ + for(n=0;n<3;n++) tempm[n]=0; + for(n=3;n<7;n++) tempm[n]=B[n+9]; for(n=7;n<8;n++) tempm[n]=0; - /* tempm2=T+S1+S1+S2 */ + /* tempm2=T+S1+S1+S2 */ fieldAdd(A,tempm,ecc_prime_r,tempm2); - /* A=T+S1+S1+S2+S2 */ + /* A=T+S1+S1+S2+S2 */ fieldAdd(tempm2,tempm,ecc_prime_r,A); - /* Form S3 */ - for(n=0;n<3;n++) tempm[n]=B[n+8]; - for(n=3;n<6;n++) tempm[n]=0; + /* Form S3 */ + for(n=0;n<3;n++) tempm[n]=B[n+8]; + for(n=3;n<6;n++) tempm[n]=0; for(n=6;n<8;n++) tempm[n]=B[n+8]; - /* tempm2=T+S1+S1+S2+S2+S3 */ + /* tempm2=T+S1+S1+S2+S2+S3 */ fieldAdd(A,tempm,ecc_prime_r,tempm2); - /* Form S4 */ - for(n=0;n<3;n++) tempm[n]=B[n+9]; - for(n=3;n<6;n++) tempm[n]=B[n+10]; - for(n=6;n<7;n++) tempm[n]=B[n+7]; + /* Form S4 */ + for(n=0;n<3;n++) tempm[n]=B[n+9]; + for(n=3;n<6;n++) tempm[n]=B[n+10]; + for(n=6;n<7;n++) tempm[n]=B[n+7]; for(n=7;n<8;n++) tempm[n]=B[n+1]; - /* A=T+S1+S1+S2+S2+S3+S4 */ + /* A=T+S1+S1+S2+S2+S3+S4 */ fieldAdd(tempm2,tempm,ecc_prime_r,A); - /* Form D1 */ - for(n=0;n<3;n++) tempm[n]=B[n+11]; - for(n=3;n<6;n++) tempm[n]=0; - for(n=6;n<7;n++) tempm[n]=B[n+2]; + /* Form D1 */ + for(n=0;n<3;n++) tempm[n]=B[n+11]; + for(n=3;n<6;n++) tempm[n]=0; + for(n=6;n<7;n++) tempm[n]=B[n+2]; for(n=7;n<8;n++) tempm[n]=B[n+3]; - /* tempm2=T+S1+S1+S2+S2+S3+S4-D1 */ + /* tempm2=T+S1+S1+S2+S2+S3+S4-D1 */ fieldSub(A,tempm,ecc_prime_m,tempm2); - /* Form D2 */ - for(n=0;n<4;n++) tempm[n]=B[n+12]; - for(n=4;n<6;n++) tempm[n]=0; - for(n=6;n<7;n++) tempm[n]=B[n+3]; + /* Form D2 */ + for(n=0;n<4;n++) tempm[n]=B[n+12]; + for(n=4;n<6;n++) tempm[n]=0; + for(n=6;n<7;n++) tempm[n]=B[n+3]; for(n=7;n<8;n++) tempm[n]=B[n+4]; - /* A=T+S1+S1+S2+S2+S3+S4-D1-D2 */ + /* A=T+S1+S1+S2+S2+S3+S4-D1-D2 */ fieldSub(tempm2,tempm,ecc_prime_m,A); - /* Form D3 */ - for(n=0;n<3;n++) tempm[n]=B[n+13]; - for(n=3;n<6;n++) tempm[n]=B[n+5]; - for(n=6;n<7;n++) tempm[n]=0; + /* Form D3 */ + for(n=0;n<3;n++) tempm[n]=B[n+13]; + for(n=3;n<6;n++) tempm[n]=B[n+5]; + for(n=6;n<7;n++) tempm[n]=0; for(n=7;n<8;n++) tempm[n]=B[n+5]; - /* tempm2=T+S1+S1+S2+S2+S3+S4-D1-D2-D3 */ + /* tempm2=T+S1+S1+S2+S2+S3+S4-D1-D2-D3 */ fieldSub(A,tempm,ecc_prime_m,tempm2); - /* Form D4 */ - for(n=0;n<2;n++) tempm[n]=B[n+14]; - for(n=2;n<3;n++) tempm[n]=0; - for(n=3;n<6;n++) tempm[n]=B[n+6]; - for(n=6;n<7;n++) tempm[n]=0; + /* Form D4 */ + for(n=0;n<2;n++) tempm[n]=B[n+14]; + for(n=2;n<3;n++) tempm[n]=0; + for(n=3;n<6;n++) tempm[n]=B[n+6]; + for(n=6;n<7;n++) tempm[n]=0; for(n=7;n<8;n++) tempm[n]=B[n+6]; - /* A=T+S1+S1+S2+S2+S3+S4-D1-D2-D3-D4 */ + /* A=T+S1+S1+S2+S2+S3+S4-D1-D2-D3-D4 */ fieldSub(tempm2,tempm,ecc_prime_m,A); if(isGreater(A, ecc_prime_m, arrayLength) >= 0){ fieldSub(A, ecc_prime_m, ecc_prime_m, tempm); @@ -262,9 +262,9 @@ static void fieldModP(uint32_t *A, const uint32_t *B) * result: result of modulo calculation (max 36 bytes) * size: size of A * - * This uses the Barrett modular reduction as described in the Handbook - * of Applied Cryptography 14.42 Algorithm Barrett modular reduction, - * see http://cacr.uwaterloo.ca/hac/about/chap14.pdf and + * This uses the Barrett modular reduction as described in the Handbook + * of Applied Cryptography 14.42 Algorithm Barrett modular reduction, + * see http://cacr.uwaterloo.ca/hac/about/chap14.pdf and * http://everything2.com/title/Barrett+Reduction * * b = 32 (bite size of the processor architecture) @@ -361,7 +361,7 @@ static int fieldAddAndDivide(const uint32_t *x, const uint32_t *modulus, const u add(result, reducer, tempas, 8); copy(tempas, result, arrayLength); } - + } return 0; } @@ -379,12 +379,12 @@ static void fieldInv(const uint32_t *A, const uint32_t *modulus, const uint32_t setZero(v, 8); uint8_t t; - copy(A,u,arrayLength); - copy(modulus,v,arrayLength); + copy(A,u,arrayLength); + copy(modulus,v,arrayLength); setZero(x1, 8); setZero(x2, 8); - x1[0]=1; - /* While u !=1 and v !=1 */ + x1[0]=1; + /* While u !=1 and v !=1 */ while ((isOne(u) || isOne(v))==0) { while(!(u[0]&1)) { /* While u is even */ rshift(u); /* divide by 2 */ @@ -395,19 +395,19 @@ static void fieldInv(const uint32_t *A, const uint32_t *modulus, const uint32_t copy(tempm,x1,arrayLength); /* x1=tempm */ //rshift(x1); /* Divide by 2 */ } - } + } while(!(v[0]&1)) { /* While v is even */ - rshift(v); /* divide by 2 */ + rshift(v); /* divide by 2 */ if (!(x2[0]&1)) /*ifx1iseven*/ rshift(x2); /* Divide by 2 */ else { fieldAddAndDivide(x2,modulus,reducer,tempm); /* tempm=x1+p */ - copy(tempm,x2,arrayLength); /* x1=tempm */ + copy(tempm,x2,arrayLength); /* x1=tempm */ //rshift(x2); /* Divide by 2 */ } - - } + + } t=sub(u,v,tempm,arrayLength); /* tempm=u-v */ if (t==0) { /* If u > 0 */ copy(tempm,u,arrayLength); /* u=u-v */ @@ -419,9 +419,9 @@ static void fieldInv(const uint32_t *A, const uint32_t *modulus, const uint32_t fieldSub(x2,x1,modulus,tempm); /* tempm=x2-x1 */ copy(tempm,x2,arrayLength); /* x2=x2-x1 */ } - } + } if (isOne(u)) { - copy(x1,B,arrayLength); + copy(x1,B,arrayLength); } else { copy(x2,B,arrayLength); } @@ -493,7 +493,7 @@ static void ec_add(const uint32_t *px, const uint32_t *py, const uint32_t *qx, c fieldSub(py, qy, ecc_prime_m, tempA); fieldSub(px, qx, ecc_prime_m, tempB); fieldInv(tempB, ecc_prime_m, ecc_prime_r, tempB); - fieldMult(tempA, tempB, tempD, arrayLength); + fieldMult(tempA, tempB, tempD, arrayLength); fieldModP(tempC, tempD); //tempC = lambda fieldMult(tempC, tempC, tempD, arrayLength); //tempA = lambda^2 diff --git a/ecc/test_helper.c b/ecc/test_helper.c index bda44ba9..2c747ce8 100644 --- a/ecc/test_helper.c +++ b/ecc/test_helper.c @@ -61,7 +61,7 @@ void ecc_setRandom(uint32_t *secret){ const uint32_t ecc_prime_m[8] = {0xffffffff, 0xffffffff, 0xffffffff, 0x00000000, 0x00000000, 0x00000000, 0x00000001, 0xffffffff}; - + /* This is added after an static byte addition if the answer has a carry in MSB*/ const uint32_t ecc_prime_r[8] = {0x00000001, 0x00000000, 0x00000000, 0xffffffff, 0xffffffff, 0xffffffff, 0xfffffffe, 0x00000000}; diff --git a/ecc/testecc.c b/ecc/testecc.c index 28d2134e..f4f84efe 100644 --- a/ecc/testecc.c +++ b/ecc/testecc.c @@ -60,7 +60,7 @@ uint32_t BasePointy[8] = { 0x37bf51f5, 0xcbb64068, 0x6b315ece, 0x2bce3357, 0x7c0f9e16, 0x8ee7eb4a, 0xfe1a7f9b, 0x4fe342e2}; //de2444be bc8d36e6 82edd27e 0f271508 617519b3 221a8fa0 b77cab39 89da97c9 -uint32_t Sx[8] = { 0x89da97c9, 0xb77cab39, 0x221a8fa0, 0x617519b3, +uint32_t Sx[8] = { 0x89da97c9, 0xb77cab39, 0x221a8fa0, 0x617519b3, 0x0f271508, 0x82edd27e, 0xbc8d36e6, 0xde2444be}; //c093ae7f f36e5380 fc01a5aa d1e66659 702de80f 53cec576 b6350b24 3042a256 @@ -78,7 +78,7 @@ uint32_t Ty[8] = { 0xc8b24316, 0xb656e9d8, 0x598b9e7a, 0xf61a8a52, //c51e4753 afdec1e6 b6c6a5b9 92f43f8d d0c7a893 3072708b 6522468b 2ffb06fd uint32_t secret[8] = { 0x2ffb06fd, 0x6522468b, 0x3072708b, 0xd0c7a893, 0x92f43f8d, 0xb6c6a5b9, 0xafdec1e6, 0xc51e4753}; - + //72b13dd4 354b6b81 745195e9 8cc5ba69 70349191 ac476bd4 553cf35a 545a067e uint32_t resultAddx[8] = { 0x545a067e, 0x553cf35a, 0xac476bd4, 0x70349191, 0x8cc5ba69, 0x745195e9, 0x354b6b81, 0x72b13dd4}; @@ -154,7 +154,7 @@ eccdhTest(void){ uint32_t tempBx1[8]; uint32_t tempBy1[8]; uint32_t tempBx2[8]; - uint32_t tempBy2[8]; + uint32_t tempBy2[8]; uint32_t secretA[8]; uint32_t secretB[8]; ecc_setRandom(secretA); diff --git a/global.h b/global.h index d915aed1..5e7696fe 100644 --- a/global.h +++ b/global.h @@ -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: @@ -72,7 +72,7 @@ typedef unsigned char uint48[6]; #endif /** Known cipher suites.*/ -typedef enum { +typedef enum { TLS_NULL_WITH_NULL_NULL = 0x0000, /**< NULL cipher */ TLS_EMPTY_RENEGOTIATION_INFO_SCSV = 0x00FF, /**< see RFC 5746 */ TLS_PSK_WITH_AES_128_CCM = 0xC0A4, /**< see RFC 6655 */ @@ -108,7 +108,7 @@ typedef enum { #define TLS_EXT_SIG_HASH_ALGO_SHA256 4 /* see RFC 5246 */ #define TLS_EXT_SIG_HASH_ALGO_ECDSA 3 /* see RFC 5246 */ -/** +/** * XORs \p n bytes byte-by-byte starting at \p y to the memory area * starting at \p x. */ static inline void @@ -141,7 +141,7 @@ equals(unsigned char *a, unsigned char *b, size_t len) { #ifdef HAVE_FLS #define dtls_fls(i) fls(i) #else -static inline int +static inline int dtls_fls(unsigned int i) { int n; for (n = 0; i; n++) diff --git a/hmac.c b/hmac.c index 9c3c028f..8530741a 100644 --- a/hmac.c +++ b/hmac.c @@ -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: @@ -64,11 +64,11 @@ dtls_hmac_init(dtls_hmac_context_t *ctx, const unsigned char *key, size_t klen) int dtls_hmac_finalize(dtls_hmac_context_t *ctx, unsigned char *result) { unsigned char buf[DTLS_HMAC_DIGEST_SIZE]; - size_t len; + size_t len; assert(ctx); assert(result); - + len = dtls_hash_finalize(buf, &ctx->data); dtls_hash_init(&ctx->data); @@ -95,10 +95,10 @@ int main(int argc, char **argv) { dtls_hmac_init(&ctx, argv[1], strlen(argv[1])); dtls_hmac_update(ctx, argv[2], strlen(argv[2])); - + len = dtls_hmac_finalize(ctx, buf); - for(i = 0; i < len; i++) + for(i = 0; i < len; i++) printf("%02x", buf[i]); printf("\n"); diff --git a/hmac.h b/hmac.h index 67ceaa7a..23357c3a 100644 --- a/hmac.h +++ b/hmac.h @@ -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: @@ -68,7 +68,7 @@ dtls_hash_init(dtls_hash_t ctx) { dtls_sha256_init((dtls_sha256_ctx *)ctx); } -static inline void +static inline void dtls_hash_update(dtls_hash_t ctx, const unsigned char *input, size_t len) { dtls_sha256_update((dtls_sha256_ctx *)ctx, input, len); } @@ -82,7 +82,7 @@ dtls_hash_finalize(unsigned char *buf, dtls_hash_t ctx) { /** * \defgroup HMAC Keyed-Hash Message Authentication Code (HMAC) - * NIST Standard FIPS 198 describes the Keyed-Hash Message Authentication + * NIST Standard FIPS 198 describes the Keyed-Hash Message Authentication * Code (HMAC) which is used as hash function for the DTLS PRF. * @{ */ @@ -93,11 +93,11 @@ dtls_hash_finalize(unsigned char *buf, dtls_hash_t ctx) { /** * List of known hash functions for use in dtls_hmac_init(). The - * identifiers are the same as the HashAlgorithm defined in + * identifiers are the same as the HashAlgorithm defined in * Section 7.4.1.4.1 of RFC 5246. */ -typedef enum { +typedef enum { HASH_NONE=0, HASH_MD5=1, HASH_SHA1=2, HASH_SHA224=3, HASH_SHA256=4, HASH_SHA384=5, HASH_SHA512=6 } dtls_hashfunc_t; @@ -107,7 +107,7 @@ typedef enum { * dtls_hmac_init() and must be passed to dtls_hmac_update() and * dtls_hmac_finalize(). Once, finalized, the component \c H is * invalid and must be initialized again with dtls_hmac_init() before - * the structure can be used again. + * the structure can be used again. */ typedef struct { unsigned char pad[DTLS_HMAC_BLOCKSIZE]; /**< ipad and opad storage */ @@ -115,7 +115,7 @@ typedef struct { } dtls_hmac_context_t; /** - * Initializes an existing HMAC context. + * Initializes an existing HMAC context. * * @param ctx The HMAC context to initialize. * @param key The secret key. @@ -124,8 +124,8 @@ typedef struct { void dtls_hmac_init(dtls_hmac_context_t *ctx, const unsigned char *key, size_t klen); /** - * Updates the HMAC context with data from \p input. - * + * Updates the HMAC context with data from \p input. + * * \param ctx The HMAC context. * \param input The input data. * \param ilen Size of \p input. @@ -133,12 +133,12 @@ void dtls_hmac_init(dtls_hmac_context_t *ctx, const unsigned char *key, size_t k void dtls_hmac_update(dtls_hmac_context_t *ctx, const unsigned char *input, size_t ilen); -/** +/** * Completes the HMAC generation and writes the result to the given * output parameter \c result. The buffer must be large enough to hold * the message digest created by the actual hash function. If in * doubt, use \c DTLS_HMAC_MAX. The function returns the number of - * bytes written to \c result. + * bytes written to \c result. * * \param ctx The HMAC context. * \param result Output parameter where the MAC is written to. diff --git a/netq.c b/netq.c index a6d17a15..4e003969 100644 --- a/netq.c +++ b/netq.c @@ -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: @@ -89,7 +89,7 @@ netq_init(void) { #endif /* WITH_CONTIKI */ -int +int netq_insert_node(netq_t **queue, netq_t *node) { netq_t *p; @@ -136,10 +136,10 @@ netq_remove(netq_t **queue, netq_t *p) { netq_t *netq_pop_first(netq_t **queue) { netq_t *p = netq_head(queue); - + if (p) LL_DELETE(*queue, p); - + return p; } @@ -157,13 +157,13 @@ netq_node_new(size_t size) { return node; } -void +void netq_node_free(netq_t *node) { if (node) netq_free_node(node); } -void +void netq_delete_all(netq_t **queue) { netq_t *p, *tmp; if (queue) { diff --git a/netq.h b/netq.h index 61876ccf..19199c7d 100644 --- a/netq.h +++ b/netq.h @@ -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: @@ -47,9 +47,9 @@ typedef enum netq_job_type_t { TIMEOUT /**< timeout of the related alert */ } netq_job_type_t; -/** +/** * Datagrams in the netq_t structure have a fixed maximum size of - * DTLS_MAX_BUF to simplify memory management on constrained nodes. */ + * DTLS_MAX_BUF to simplify memory management on constrained nodes. */ typedef unsigned char netq_packet_t[DTLS_MAX_BUF]; typedef struct netq_t { @@ -80,7 +80,7 @@ static inline void netq_init(void) void netq_init(void); #endif -/** +/** * Adds a node to the given queue, ordered by their time-stamp t. * This function returns @c 0 on error, or non-zero if @p node has * been added successfully. @@ -103,7 +103,7 @@ netq_t *netq_node_new(size_t size); /** * Returns a pointer to the first item in given queue or NULL if - * empty. + * empty. */ netq_t *netq_head(netq_t **queue); diff --git a/numeric.h b/numeric.h index e8d1f561..9f336a95 100644 --- a/numeric.h +++ b/numeric.h @@ -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: diff --git a/peer.c b/peer.c index e66dd86d..464fe491 100644 --- a/peer.c +++ b/peer.c @@ -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: diff --git a/peer.h b/peer.h index bd327fa7..7d570e6c 100644 --- a/peer.h +++ b/peer.h @@ -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: @@ -38,7 +38,7 @@ typedef enum { DTLS_CLIENT=0, DTLS_SERVER } dtls_peer_type; -/** +/** * Holds security parameters, local state and the transport address * for each peer. */ typedef struct dtls_peer_t { diff --git a/platform-specific/Makefile.in b/platform-specific/Makefile.in index d46f3482..7e7de76b 100644 --- a/platform-specific/Makefile.in +++ b/platform-specific/Makefile.in @@ -16,9 +16,9 @@ clean: distclean: clean @rm -rf $(DISTDIR) - @rm -f *~ + @rm -f *~ -dist: +dist: test -d $(DISTDIR)/$(THIS) || mkdir $(DISTDIR)/$(THIS) cp -r $(FILES) $(DISTDIR)/$(THIS) diff --git a/platform-specific/dtls_prng_contiki.c b/platform-specific/dtls_prng_contiki.c index 4730f77b..4b550b66 100644 --- a/platform-specific/dtls_prng_contiki.c +++ b/platform-specific/dtls_prng_contiki.c @@ -57,4 +57,3 @@ dtls_prng_init(unsigned seed) random_init(seed); #endif } - diff --git a/platform-specific/dtls_prng_espidf.c b/platform-specific/dtls_prng_espidf.c index 084bcecb..56020ccc 100644 --- a/platform-specific/dtls_prng_espidf.c +++ b/platform-specific/dtls_prng_espidf.c @@ -39,4 +39,3 @@ void dtls_prng_init(unsigned seed) { return; } - diff --git a/platform-specific/dtls_prng_lwip.c b/platform-specific/dtls_prng_lwip.c index 40ad3ef0..85591b05 100644 --- a/platform-specific/dtls_prng_lwip.c +++ b/platform-specific/dtls_prng_lwip.c @@ -39,4 +39,3 @@ void dtls_prng_init(unsigned seed) { (void) seed; } - diff --git a/platform-specific/dtls_prng_posix.c b/platform-specific/dtls_prng_posix.c index 2c3f3e71..7575ff2a 100644 --- a/platform-specific/dtls_prng_posix.c +++ b/platform-specific/dtls_prng_posix.c @@ -104,4 +104,3 @@ dtls_prng_init(unsigned seed) { #endif #endif /* !HAVE_GETRANDOM */ } - diff --git a/platform-specific/dtls_prng_riot.c b/platform-specific/dtls_prng_riot.c index 3a03b7ff..3a5d77e5 100644 --- a/platform-specific/dtls_prng_riot.c +++ b/platform-specific/dtls_prng_riot.c @@ -32,4 +32,3 @@ void dtls_prng_init(unsigned seed) { (void) seed; } - diff --git a/platform-specific/dtls_prng_zephyr.c b/platform-specific/dtls_prng_zephyr.c index b9576378..eab3aa7c 100644 --- a/platform-specific/dtls_prng_zephyr.c +++ b/platform-specific/dtls_prng_zephyr.c @@ -38,4 +38,3 @@ void dtls_prng_init(unsigned seed) { (void) seed; } - diff --git a/session.c b/session.c index d2f74f27..927dba29 100644 --- a/session.c +++ b/session.c @@ -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: @@ -64,23 +64,23 @@ #else /* ! WITH_CONTIKI && !WITH_RIOT_SOCK && ! WITH_LWIP_NO_SOCKET */ -static inline int +static inline int _dtls_address_equals_impl(const session_t *a, const session_t *b) { if (a->ifindex != b->ifindex || a->size != b->size || a->addr.sa.sa_family != b->addr.sa.sa_family) return 0; - + /* need to compare only relevant parts of sockaddr_in6 */ switch (a->addr.sa.sa_family) { case AF_INET: - return - a->addr.sin.sin_port == b->addr.sin.sin_port && - memcmp(&a->addr.sin.sin_addr, &b->addr.sin.sin_addr, + return + a->addr.sin.sin_port == b->addr.sin.sin_port && + memcmp(&a->addr.sin.sin_addr, &b->addr.sin.sin_addr, sizeof(struct in_addr)) == 0; case AF_INET6: - return a->addr.sin6.sin6_port == b->addr.sin6.sin6_port && - memcmp(&a->addr.sin6.sin6_addr, &b->addr.sin6.sin6_addr, + return a->addr.sin6.sin6_port == b->addr.sin6.sin6_port && + memcmp(&a->addr.sin6.sin6_addr, &b->addr.sin6.sin6_addr, sizeof(struct in6_addr)) == 0; default: /* fall through and signal error */ ; diff --git a/session.h b/session.h index b791ea4c..ba2059fc 100644 --- a/session.h +++ b/session.h @@ -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: @@ -121,11 +121,11 @@ typedef struct { } session_t; #endif /* ! WITH_CONTIKI && ! WITH_RIOT_SOCK && ! WITH_LWIP_NO_LWIP_SOCKET */ -/** +/** * Resets the given session_t object @p sess to its default * values. In particular, the member rlen must be initialized to the * available size for storing addresses. - * + * * @param sess The session_t object to initialize. */ void dtls_session_init(session_t *sess); diff --git a/sha2/Makefile.in b/sha2/Makefile.in index 5c880c7c..3e7e007e 100644 --- a/sha2/Makefile.in +++ b/sha2/Makefile.in @@ -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: @@ -33,7 +33,7 @@ CPPFLAGS=@CPPFLAGS@ -I$(top_srcdir) CFLAGS=-DSHA2_USE_INTTYPES_H -Wall -std=c99 -pedantic @CFLAGS@ @WARNING_CFLAGS@ $(EXTRA_CFLAGS) LDFLAGS=@LDFLAGS@ LDLIBS=@LIBS@ -FILES:=Makefile.in $(SOURCES) $(HEADERS) README sha2prog.c sha2speed.c sha2test.pl +FILES:=Makefile.in $(SOURCES) $(HEADERS) README sha2prog.c sha2speed.c sha2test.pl DISTDIR=$(top_builddir)/@PACKAGE_TARNAME@-@PACKAGE_VERSION@ .PHONY: all dirs clean install dist distclean .gitignore doc uninstall @@ -43,7 +43,7 @@ DISTDIR=$(top_builddir)/@PACKAGE_TARNAME@-@PACKAGE_VERSION@ all: -check: +check: echo DISTDIR: $(DISTDIR) echo top_builddir: $(top_builddir) diff --git a/sha2/README b/sha2/README index 95e57f39..ff32192b 100644 --- a/sha2/README +++ b/sha2/README @@ -269,4 +269,3 @@ and then running the perl testing script: That's all folks! Have fun! Aaron out. - diff --git a/sha2/sha2.h b/sha2/sha2.h index 698f1f2b..5278eee6 100644 --- a/sha2/sha2.h +++ b/sha2/sha2.h @@ -1,7 +1,7 @@ /* * FILE: sha2.h * AUTHOR: Aaron D. Gifford - http://www.aarongifford.com/ - * + * * Copyright (c) 2000-2001, Aaron D. Gifford * All rights reserved. * @@ -16,7 +16,7 @@ * 3. Neither the name of the copyright holder nor the names of contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTOR(S) ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE @@ -95,7 +95,7 @@ typedef unsigned long long u_int64_t; /* 8-bytes (64-bits) */ * * #include * - * If you choose to use then please define: + * If you choose to use then please define: * * #define SHA2_USE_INTTYPES_H * @@ -223,4 +223,3 @@ char* dtls_sha512_data(); #endif /* __cplusplus */ #endif /* __SHA2_H__ */ - diff --git a/sha2/sha2prog.c b/sha2/sha2prog.c index df8725cb..d1a8280e 100644 --- a/sha2/sha2prog.c +++ b/sha2/sha2prog.c @@ -1,7 +1,7 @@ /* * FILE: sha2prog.c * AUTHOR: Aaron D. Gifford - http://www.aarongifford.com/ - * + * * Copyright (c) 2000-2001, Aaron D. Gifford * All rights reserved. * @@ -16,7 +16,7 @@ * 3. Neither the name of the copyright holder nor the names of contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTOR(S) ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE @@ -131,4 +131,3 @@ int main(int argc, char **argv) { return 1; } - diff --git a/sha2/sha2speed.c b/sha2/sha2speed.c index 9cf44a56..47bf8d8e 100644 --- a/sha2/sha2speed.c +++ b/sha2/sha2speed.c @@ -1,7 +1,7 @@ /* * FILE: sha2speed.c * AUTHOR: Aaron D. Gifford - http://www.aarongifford.com/ - * + * * Copyright (c) 2000-2001, Aaron D. Gifford * All rights reserved. * @@ -16,7 +16,7 @@ * 3. Neither the name of the copyright holder nor the names of contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTOR(S) ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE @@ -102,7 +102,7 @@ int main(int argc, char **argv) { dtls_sha256_init(&c256); dtls_sha384_init(&c384); dtls_sha512_init(&c512); - + gettimeofday(&start, (struct timezone*)0); for (j = 0; j < blocks; j++) { dtls_sha256_update(&c256, (unsigned char*)buf, BUFSIZE); @@ -173,4 +173,3 @@ int main(int argc, char **argv) { return 1; } - diff --git a/sha2/sha2test.pl b/sha2/sha2test.pl index dc884d8c..994909e3 100755 --- a/sha2/sha2test.pl +++ b/sha2/sha2test.pl @@ -2,7 +2,7 @@ # # FILE: sha2test.pl # AUTHOR: Aaron D. Gifford - http://www.aarongifford.com/ -# +# # Copyright (c) 2001, Aaron D. Gifford # All rights reserved. # @@ -17,7 +17,7 @@ # 3. Neither the name of the copyright holder nor the names of contributors # may be used to endorse or promote products derived from this software # without specific prior written permission. -# +# # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTOR(S) ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE @@ -355,4 +355,3 @@ sub usage { $pass = $tests - $errors; print "TOTAL: ".substr(" $tests", -12)."\t".substr(" $pass", -6)."\t".substr(" $errors", -6)."\n\n"; print "NO ERRORS! ALL TESTS WERE SUCCESSFUL!\n\n" if (!$errors); - diff --git a/sha2/testvectors/vector001.info b/sha2/testvectors/vector001.info index 57b444ed..6b096b84 100644 --- a/sha2/testvectors/vector001.info +++ b/sha2/testvectors/vector001.info @@ -2,7 +2,7 @@ DESCRIPTION: This test vector is taken from the PDF document that describes the SHA-256/384/512 algorithms. That document contains sample output for all three versions (SHA-256, SHA-384, and SHA-512). - + (Total length of test vector data: 3) FILE: @@ -18,4 +18,3 @@ SHA384: SHA512: ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a 2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f - diff --git a/sha2/testvectors/vector002.info b/sha2/testvectors/vector002.info index 0fc1ed3c..3cda8e50 100644 --- a/sha2/testvectors/vector002.info +++ b/sha2/testvectors/vector002.info @@ -2,7 +2,7 @@ DESCRIPTION: The PDF document only provided sample output for SHA-256 using this test data. I have provided SHA-384 and SHA-512 sample output from my own implementation which may not be correct. - + (Total length of test vector data: 56) FILE: @@ -18,4 +18,3 @@ SHA384: SHA512: 204a8fc6dda82f0a0ced7beb8e08a41657c16ef468b228a8279be331a703c335 96fd15c13b1b07f9aa1d3bea57789ca031ad85c7a71dd70354ec631238ca3445 - diff --git a/sha2/testvectors/vector003.info b/sha2/testvectors/vector003.info index 17a2ad85..9fc64b75 100644 --- a/sha2/testvectors/vector003.info +++ b/sha2/testvectors/vector003.info @@ -3,7 +3,7 @@ DESCRIPTION: was provided for SHA-256 (SHA-384 and SHA-512 samples were provided), so the sample for SHA-256 comes from the output of my own implementation and so may not be correct. - + (Total length of test vector data: 112) FILE: @@ -19,4 +19,3 @@ SHA384: SHA512: 8e959b75dae313da8cf4f72814fc143f8f7779c6eb9f7fa17299aeadb6889018 501d289e4900f7e4331b99dec4b5433ac7d329eeb6dd26545e96e55b874be909 - diff --git a/sha2/testvectors/vector004.info b/sha2/testvectors/vector004.info index eed148cf..dbf37b26 100644 --- a/sha2/testvectors/vector004.info +++ b/sha2/testvectors/vector004.info @@ -3,7 +3,7 @@ DESCRIPTION: own implementation and so may be completely incorrect. Use with a very large grain of salt. The input sample comes from...well most anyone in the U.S. will know and many outside the U.S. too. - + (Total length of test vector data: 1515) FILE: @@ -19,4 +19,3 @@ SHA384: SHA512: 23450737795d2f6a13aa61adcca0df5eef6df8d8db2b42cd2ca8f783734217a7 3e9cabc3c9b8a8602f8aeaeb34562b6b1286846060f9809b90286b3555751f09 - diff --git a/sha2/testvectors/vector005.info b/sha2/testvectors/vector005.info index 37602d30..5880be9a 100644 --- a/sha2/testvectors/vector005.info +++ b/sha2/testvectors/vector005.info @@ -4,7 +4,7 @@ DESCRIPTION: a very large grain of salt. The input sample is EMPTY (no bits). Mr. David A. Ireland's SHA-256 implementation agrees with my own implementation on the output of this test vector (SHA-256 only). - + (Total length of test vector data: 0) FILE: @@ -20,4 +20,3 @@ SHA384: SHA512: cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce 47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e - diff --git a/sha2/testvectors/vector006.info b/sha2/testvectors/vector006.info index 39ddcc02..f79c6e33 100644 --- a/sha2/testvectors/vector006.info +++ b/sha2/testvectors/vector006.info @@ -3,7 +3,7 @@ DESCRIPTION: own implementation and so may be completely incorrect. Use with a very large grain of salt. The input sample exactly the same length as the SHA-256 block length. - + (Total length of test vector data: 64) FILE: @@ -19,4 +19,3 @@ SHA384: SHA512: 70aefeaa0e7ac4f8fe17532d7185a289bee3b428d950c14fa8b713ca09814a38 7d245870e007a80ad97c369d193e41701aa07f3221d15f0e65a1ff970cedf030 - diff --git a/sha2/testvectors/vector007.info b/sha2/testvectors/vector007.info index 9c10f8df..c22cf44d 100644 --- a/sha2/testvectors/vector007.info +++ b/sha2/testvectors/vector007.info @@ -3,7 +3,7 @@ DESCRIPTION: own implementation and so may be completely incorrect. Use with a very large grain of salt. The input sample one byte shorter than the SHA-256 block length. - + (Total length of test vector data: 63) FILE: @@ -19,4 +19,3 @@ SHA384: SHA512: b3de4afbc516d2478fe9b518d063bda6c8dd65fc38402dd81d1eb7364e72fb6e 6663cf6d2771c8f5a6da09601712fb3d2a36c6ffea3e28b0818b05b0a8660766 - diff --git a/sha2/testvectors/vector008.info b/sha2/testvectors/vector008.info index d2fb344c..5b280698 100644 --- a/sha2/testvectors/vector008.info +++ b/sha2/testvectors/vector008.info @@ -3,7 +3,7 @@ DESCRIPTION: own implementation and so may be completely incorrect. Use with a very large grain of salt. The input sample exactly the same length as the SHA-384 and SHA-512 block lengths. - + (Total length of test vector data: 128) FILE: @@ -19,4 +19,3 @@ SHA384: SHA512: 97fb4ec472f3cb698b9c3c12a12768483e5b62bcdad934280750b4fa4701e5e0 550a80bb0828342c19631ba55a55e1cee5de2fda91fc5d40e7bee1d4e6d415b3 - diff --git a/sha2/testvectors/vector009.info b/sha2/testvectors/vector009.info index f8b96048..ca3d696d 100644 --- a/sha2/testvectors/vector009.info +++ b/sha2/testvectors/vector009.info @@ -3,7 +3,7 @@ DESCRIPTION: own implementation and so may be completely incorrect. Use with a very large grain of salt. The input sample is one byte shorter in length than the SHA-384 and SHA-512 block lengths. - + (Total length of test vector data: 127) FILE: @@ -19,4 +19,3 @@ SHA384: SHA512: d399507bbf5f2d0da51db1ff1fc51c1c9ff1de0937e00d01693b240e84fcc340 0601429f45c297acc6e8fcf1e4e4abe9ff21a54a0d3d88888f298971bd206cd5 - diff --git a/sha2/testvectors/vector010.info b/sha2/testvectors/vector010.info index 9532ad84..2031b2fa 100644 --- a/sha2/testvectors/vector010.info +++ b/sha2/testvectors/vector010.info @@ -3,7 +3,7 @@ DESCRIPTION: own implementation and so may be completely incorrect. Use with a very large grain of salt. The input sample is exactly 5 times size of the SHA-256 block length. - + (Total length of test vector data: 320) FILE: @@ -19,4 +19,3 @@ SHA384: SHA512: caf970d3638e21053173a638c4b94d6d1ff87bc47b58f8ee928fbe9e245c23ab f81019e45bf017ecc8610e5e0b95e3b025ccd611a772ca4fb3dfba26f0859725 - diff --git a/sha2/testvectors/vector011.info b/sha2/testvectors/vector011.info index 2071c015..47d6302f 100644 --- a/sha2/testvectors/vector011.info +++ b/sha2/testvectors/vector011.info @@ -3,7 +3,7 @@ DESCRIPTION: own implementation and so may be completely incorrect. Use with a very large grain of salt. The input sample is one byte less than 7 times the size of the SHA-256 block length. - + (Total length of test vector data: 447) FILE: @@ -19,4 +19,3 @@ SHA384: SHA512: ee5d07460183b130687c977e9f8d43110989b0864b18fe6ee00a53dec5eda111 f3aaa3bac7ab8dae26ed545a4de33ed45190f18fa0c327c44642ab9424265330 - diff --git a/sha2/testvectors/vector012.info b/sha2/testvectors/vector012.info index 056695e4..ae426e46 100644 --- a/sha2/testvectors/vector012.info +++ b/sha2/testvectors/vector012.info @@ -3,7 +3,7 @@ DESCRIPTION: own implementation and so may be completely incorrect. Use with a very large grain of salt. The input sample is exactly 5 times size of the SHA-384 and SHA-512 block lengths. - + (Total length of test vector data: 640) FILE: @@ -19,4 +19,3 @@ SHA384: SHA512: 73ffeb67716c3495fbc33f2d62fe08e2616706a5599881c7e67e9ef2b68f4988 ea8b3b604ba87e50b07962692705c420fa31a00be41d6aaa9f3b11eafe9cf49b - diff --git a/sha2/testvectors/vector013.info b/sha2/testvectors/vector013.info index 2e0141bc..c88cbddc 100644 --- a/sha2/testvectors/vector013.info +++ b/sha2/testvectors/vector013.info @@ -3,7 +3,7 @@ DESCRIPTION: own implementation and so may be completely incorrect. Use with a very large grain of salt. The input sample is one byte short of 17 times size of the SHA-384 and SHA-512 block lengths. - + (Total length of test vector data: 2175) FILE: @@ -19,4 +19,3 @@ SHA384: SHA512: 0e928db6207282bfb498ee871202f2337f4074f3a1f5055a24f08e912ac118f8 101832cdb9c2f702976e629183db9bacfdd7b086c800687c3599f15de7f7b9dd - diff --git a/sha2/testvectors/vector014.info b/sha2/testvectors/vector014.info index d4ba170a..c182cf91 100644 --- a/sha2/testvectors/vector014.info +++ b/sha2/testvectors/vector014.info @@ -3,7 +3,7 @@ DESCRIPTION: own implementation and so may be completely incorrect. Use with a very large grain of salt. The input sample 4 KB of misc. data. - + (Total length of test vector data: 16384) FILE: @@ -19,4 +19,3 @@ SHA384: SHA512: a001636f3ff1ce34f432f8e8f7785b78be84318beb8485a406650a8b243c419f 7db6435cf6bf3000c6524adb5b52bad01afb76b3ceff701331e18b85b0e4cbd3 - diff --git a/sha2/testvectors/vector015.info b/sha2/testvectors/vector015.info index d0357826..72da8c75 100644 --- a/sha2/testvectors/vector015.info +++ b/sha2/testvectors/vector015.info @@ -2,7 +2,7 @@ DESCRIPTION: This is yet another of my own test vectors for a larger input data set. The input data is the string "qwerty repeated 65536 times. - + (Total length of test vector data: 393216) FILE: @@ -18,4 +18,3 @@ SHA384: SHA512: 735bd6bebfe6f8070d70069105bc761f35ed1ac3742f2e372fdc14d2a51898e6 153ccaff9073324130abdc451c730dc5dab5a0452487b1171c4dd97f92e267b7 - diff --git a/sha2/testvectors/vector016.info b/sha2/testvectors/vector016.info index effb114a..0db4f875 100644 --- a/sha2/testvectors/vector016.info +++ b/sha2/testvectors/vector016.info @@ -4,7 +4,7 @@ DESCRIPTION: and SHA-512 implementations. My own implementations match his output exactly. The input data data set is the string "Rijndael is AES" repeated 1024 times. - + (Total length of test vector data: 15360) FILE: @@ -20,4 +20,3 @@ SHA384: SHA512: fae25ec70bcb3bbdef9698b9d579da49db68318dbdf18c021d1f76aaceff9628 38873235597e7cce0c68aabc610e0deb79b13a01c302abc108e459ddfbe9bee8 - diff --git a/sha2/testvectors/vector017.info b/sha2/testvectors/vector017.info index 5d6c632b..9ad1cf7e 100644 --- a/sha2/testvectors/vector017.info +++ b/sha2/testvectors/vector017.info @@ -13,7 +13,7 @@ DESCRIPTION: with a "<=" test. Thanks, Rogier! - + (Total length of test vector data: 12271) FILE: @@ -29,4 +29,3 @@ SHA384: SHA512: 211bec83fbca249c53668802b857a9889428dc5120f34b3eac1603f13d1b4796 5c387b39ef6af15b3a44c5e7b6bbb6c1096a677dc98fc8f472737540a332f378 - diff --git a/sha2/testvectors/vector018.info b/sha2/testvectors/vector018.info index 7ee34445..5da5be9b 100644 --- a/sha2/testvectors/vector018.info +++ b/sha2/testvectors/vector018.info @@ -8,7 +8,7 @@ DESCRIPTION: fix was easy, once the problem was fully diagnosed. Thanks, Rogier! - + (Total length of test vector data: 1079) FILE: diff --git a/state.h b/state.h index aaa129b9..d7970897 100644 --- a/state.h +++ b/state.h @@ -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: @@ -29,11 +29,11 @@ #include "global.h" #include "hmac.h" -typedef enum { +typedef enum { DTLS_STATE_INIT = 0, DTLS_STATE_WAIT_CLIENTHELLO, DTLS_STATE_WAIT_CLIENTCERTIFICATE, DTLS_STATE_WAIT_CLIENTKEYEXCHANGE, DTLS_STATE_WAIT_CERTIFICATEVERIFY, DTLS_STATE_WAIT_CHANGECIPHERSPEC, - DTLS_STATE_WAIT_FINISHED, DTLS_STATE_FINISHED, + DTLS_STATE_WAIT_FINISHED, DTLS_STATE_FINISHED, /* client states */ DTLS_STATE_CLIENTHELLO, DTLS_STATE_WAIT_SERVERCERTIFICATE, DTLS_STATE_WAIT_SERVERKEYEXCHANGE, DTLS_STATE_WAIT_SERVERHELLODONE, diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 6f431041..a784f07d 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -6,7 +6,7 @@ # information regarding copyright ownership. # # This program and the accompanying materials are made available under the -# terms of the Eclipse Public License 1.0 +# terms of the Eclipse Public License 1.0 # which is available at https://www.eclipse.org/legal/epl-v10.html # and the Eclipse Distribution License v. 1.0 # available at http://www.eclipse.org/org/documents/edl-v10.php @@ -43,4 +43,3 @@ target_compile_options(dtls-client PUBLIC -Wall -DTEST_INCLUDE -DDTLSv12 -DWITH_ if(${WARNING_TO_ERROR}) target_compile_options(dtls-client PUBLIC -Werror) endif() - diff --git a/tests/Makefile.in b/tests/Makefile.in index f7ef52ec..1b7e0795 100644 --- a/tests/Makefile.in +++ b/tests/Makefile.in @@ -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: @@ -49,7 +49,7 @@ all: $(PROGRAMS) dtls-client dtls-server:: dtls_ciphers_util.o -check: +check: echo DISTDIR: $(DISTDIR) echo top_builddir: $(top_builddir) @@ -59,7 +59,7 @@ clean: $(MAKE) -C $$dir clean ; \ done -doc: +doc: $(MAKE) -C doc distclean: clean diff --git a/tests/cbc_aes128-test.c b/tests/cbc_aes128-test.c index 7065f95a..fd7700fb 100644 --- a/tests/cbc_aes128-test.c +++ b/tests/cbc_aes128-test.c @@ -8,7 +8,7 @@ #include "cbc_aes128-testdata.c" -void +void dump(unsigned char *buf, size_t len) { size_t i = 0; while (i < len) { @@ -30,7 +30,7 @@ int main(int argc, char **argv) { cipher = dtls_new_cipher(&ciphers[AES128], data[n].key, sizeof(data[n].key)); - + if (!cipher) { fprintf(stderr, "cannot set key\n"); exit(-1); @@ -47,9 +47,9 @@ int main(int argc, char **argv) { if (len != data[n].r_lm || memcmp(data[n].msg, data[n].result, len)) printf("FAILED, "); - else + else printf("OK, "); - + printf("result is (total length = %d):\n\t", (int)len); dump(data[n].msg, len); diff --git a/tests/cbc_aes128-testdata.c b/tests/cbc_aes128-testdata.c index ba6f9641..f238a440 100644 --- a/tests/cbc_aes128-testdata.c +++ b/tests/cbc_aes128-testdata.c @@ -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: @@ -16,7 +16,7 @@ /** * @file cbc_aes128-testdata.c - * @brief test vectors from Appendix F.2.{1,2} of NIST SP 800-38A, ed. 2001 + * @brief test vectors from Appendix F.2.{1,2} of NIST SP 800-38A, ed. 2001 */ struct test_vector { @@ -46,7 +46,7 @@ struct test_vector data[] = { 0x3f, 0xf1, 0xca, 0xa1, 0x68, 0x1f, 0xac, 0x09, 0x12, 0x0e, 0xca, 0x30, 0x75, 0x86, 0xe1, 0xa7 } /* result */ }, - + /* F.2.2 (decrypt) */ { 1, 4 * AES_BLKLEN, 0, { 0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c }, /* AES key */ diff --git a/tests/ccm-test.c b/tests/ccm-test.c index aca94348..aaa880d0 100644 --- a/tests/ccm-test.c +++ b/tests/ccm-test.c @@ -18,7 +18,7 @@ #include "ccm-testdata.c" -static void +static void dump(unsigned char *buf, size_t len) { size_t i = 0; while (i < len) { @@ -58,11 +58,11 @@ int main(int argc, char **argv) { return 1; } - 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, + 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); - + len += + data[n].la; printf("Packet Vector #%zu ", n+1); if ((size_t)len != data[n].r_lm || memcmp(data[n].msg, data[n].result, len)) { @@ -71,14 +71,14 @@ int main(int argc, char **argv) { } else { printf("OK, "); } - + printf("result is (total length = %lu):\n\t", len); dump(data[n].msg, len); - 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, + 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); - + if (len < 0) { printf("Packet Vector #%zu: cannot decrypt message\n", n+1); ret = 1; diff --git a/tests/ccm-testdata.c b/tests/ccm-testdata.c index 1ff289d2..451ab13f 100644 --- a/tests/ccm-testdata.c +++ b/tests/ccm-testdata.c @@ -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: @@ -16,7 +16,7 @@ /** * @file ccm-testdata.c - * @brief test vectors from RFC 3610 + * @brief test vectors from RFC 3610 */ struct test_vector { @@ -39,7 +39,7 @@ struct test_vector data[] = { 39, /* length of result */ { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x58, 0x8C, 0x97, 0x9A, 0x61, 0xC6, 0x63, 0xD2, 0xF0, 0x66, 0xD0, 0xC2, 0xC0, 0xF9, 0x89, 0x80, 0x6D, 0x5F, 0x6B, 0x61, 0xDA, 0xC3, 0x84, 0x17, 0xE8, 0xD1, 0x2C, 0xFD, 0xF9, 0x26, 0xE0} /* result */ }, - + /* #2 */ { 8, 2, 32, 8, { 0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF}, /* AES key */ @@ -250,11 +250,11 @@ struct test_vector data[] = { /* #25 */ /* Cipher: AES-128 M=16 L=2 K_LEN=1 N_LEN=13 K=0x00 N=0x00000000000000000000000000 */ { 16, 2, 0, 0, - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, /* AES key */ + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, /* AES key */ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, /* Nonce */ { 0 }, /* msg */ 16, /* length of result */ - { 0x8b, 0x60, 0xab, 0xcd, 0x60, 0x43, 0x81, 0x0b, + { 0x8b, 0x60, 0xab, 0xcd, 0x60, 0x43, 0x81, 0x0b, 0xa3, 0x78, 0xa0, 0x1d, 0x4a, 0x29, 0x83, 0x0b } /* result */ }, @@ -262,11 +262,11 @@ struct test_vector data[] = { /* #26 */ /* Cipher: AES-128 M=16 L=2 K_LEN=1 N_LEN=13 K=0x00 N=0x00000000000000000000000000 */ { 16, 2, 37, 0, - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, /* AES key */ - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, /* AES key */ + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, /* Nonce */ - { 0x45, 0x69, 0x6e, 0x20, 0x6b, 0x6c, 0x65, 0x69, + { 0x45, 0x69, 0x6e, 0x20, 0x6b, 0x6c, 0x65, 0x69, 0x6e, 0x65, 0x72, 0x20, 0x54, 0x65, 0x78, 0x74, 0x0a, 0x7a, 0x75, 0x6d, 0x20, 0x54, 0x65, 0x73, 0x74, 0x65, 0x6e, 0x20, 0x76, 0x6f, 0x6e, 0x20, @@ -275,7 +275,7 @@ struct test_vector data[] = { 53, /* length of result */ { 0x90, 0x11, 0x9c, 0x2d, 0x6b, 0xf9, 0xe9, 0x05, 0x3e, 0x0b, 0x44, 0x56, 0xca, 0xc8, 0xb6, 0x1a, - 0x00, 0x57, 0xa9, 0x8b, 0x6b, 0x69, 0x09, 0x7e, + 0x00, 0x57, 0xa9, 0x8b, 0x6b, 0x69, 0x09, 0x7e, 0x8e, 0x50, 0x50, 0x63, 0x50, 0x58, 0x0f, 0x78, 0x75, 0x69, 0x6e, 0x9f, 0x3d, 0x63, 0x93, 0xe7, 0x7a, 0x84, 0xe9, 0x9f, 0x11, 0x93, 0x95, 0xa0, @@ -302,7 +302,7 @@ struct test_vector data[] = { 0xef, 0xdc, 0xaf, 0xfe, 0xed, 0x39, 0x21, 0xee }, /* AES key */ { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99 }, /* Nonce */ - { 0x45, 0x69, 0x6e, 0x20, 0x6b, 0x6c, 0x65, 0x69, + { 0x45, 0x69, 0x6e, 0x20, 0x6b, 0x6c, 0x65, 0x69, 0x6e, 0x65, 0x72, 0x20, 0x54, 0x65, 0x78, 0x74, 0x0a, 0x7a, 0x75, 0x6d, 0x20, 0x54, 0x65, 0x73, 0x74, 0x65, 0x6e, 0x20, 0x76, 0x6f, 0x6e, 0x20, @@ -338,7 +338,7 @@ struct test_vector data[] = { 0xef, 0xdc, 0xaf, 0xfe, 0xed, 0x39, 0x21, 0xee }, /* AES key */ { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0x00, 0x00 }, /* Nonce */ - { 0x45, 0x69, 0x6e, 0x20, 0x6b, 0x6c, 0x65, 0x69, + { 0x45, 0x69, 0x6e, 0x20, 0x6b, 0x6c, 0x65, 0x69, 0x6e, 0x65, 0x72, 0x20, 0x54, 0x65, 0x78, 0x74, 0x0a, 0x7a, 0x75, 0x6d, 0x20, 0x54, 0x65, 0x73, 0x74, 0x65, 0x6e, 0x20, 0x76, 0x6f, 0x6e, 0x20, @@ -372,7 +372,7 @@ struct test_vector data[] = { { 0x11, 0x22, 0x33, 0x44, 0xaa, 0xbb }, /* AES key */ { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99 }, /* Nonce */ - { 0x45, 0x69, 0x6e, 0x20, 0x6b, 0x6c, 0x65, 0x69, + { 0x45, 0x69, 0x6e, 0x20, 0x6b, 0x6c, 0x65, 0x69, 0x6e, 0x65, 0x72, 0x20, 0x54, 0x65, 0x78, 0x74, 0x0a, 0x7a, 0x75, 0x6d, 0x20, 0x54, 0x65, 0x73, 0x74, 0x65, 0x6e, 0x20, 0x76, 0x6f, 0x6e, 0x20, diff --git a/tests/dsrv-test.c b/tests/dsrv-test.c index 4ef46051..20f359c8 100644 --- a/tests/dsrv-test.c +++ b/tests/dsrv-test.c @@ -8,7 +8,7 @@ #include #endif /* HAVE_SYS_TIME_H */ -#include "dsrv.h" +#include "dsrv.h" void handle_read(struct dsrv_context_t *ctx) { @@ -18,14 +18,14 @@ handle_read(struct dsrv_context_t *ctx) { socklen_t srclen = sizeof(src); int fd = dsrv_get_fd(ctx, DSRV_READ); - len = recvfrom(fd, buf, sizeof(buf), 0, + len = recvfrom(fd, buf, sizeof(buf), 0, (struct sockaddr *)&src, &srclen); if (len < 0) { perror("recvfrom"); } else { printf("read %d bytes: '%*s'\n", len, len, buf); - if (dsrv_sendto(ctx, (struct sockaddr *)&src, srclen, 0, buf, len) + if (dsrv_sendto(ctx, (struct sockaddr *)&src, srclen, 0, buf, len) == NULL) { fprintf(stderr, "cannot add packet to sendqueue\n"); } @@ -44,10 +44,10 @@ handle_write(struct dsrv_context_t *ctx) { return -1; len = sendto(fd, p->buf, p->len, 0, p->raddr, p->rlen); - + if (len < 0) perror("sendto"); - else + else nq_pop(ctx->wq); return len; @@ -65,7 +65,7 @@ int main(int argc, char **argv) { struct dsrv_context_t *ctx; int result; - ctx = dsrv_new_context((struct sockaddr *)&listen_addr, sizeof(listen_addr), + ctx = dsrv_new_context((struct sockaddr *)&listen_addr, sizeof(listen_addr), 200,200); if (!ctx) { @@ -79,7 +79,7 @@ int main(int argc, char **argv) { dsrv_prepare(ctx, &rfds, DSRV_READ); dsrv_prepare(ctx, &wfds, DSRV_WRITE); - + #if 0 timeout.tv_sec = 0; timeout.tv_usec = dsrv_get_timeout(ctx); @@ -87,14 +87,14 @@ int main(int argc, char **argv) { timeout.tv_sec = 5; timeout.tv_usec = 0; #endif - + result = select( FD_SETSIZE, &rfds, &wfds, 0, &timeout); - + if (result < 0) { /* error */ if (errno != EINTR) perror("select"); } else if (result == 0) { /* timeout */ - printf("."); + printf("."); } else { /* ok */ if (dsrv_check(ctx, &wfds, DSRV_WRITE)) handle_write(ctx); diff --git a/tests/dtls-client.c b/tests/dtls-client.c index 5d856b61..240d22c7 100644 --- a/tests/dtls-client.c +++ b/tests/dtls-client.c @@ -412,7 +412,7 @@ static dtls_handler_t cb = { #define DTLS_CLIENT_CMD_EXIT "client:exit" -int +int main(int argc, char **argv) { fd_set rfds, wfds; struct timeval timeout; diff --git a/tests/dtls-server.c b/tests/dtls-server.c index 1db0203d..f947a98b 100644 --- a/tests/dtls-server.c +++ b/tests/dtls-server.c @@ -29,7 +29,7 @@ #include "tinydtls.h" #include "dtls_debug.h" #include "dtls_ciphers_util.h" -#include "dtls.h" +#include "dtls.h" #ifdef IS_WINDOWS #include @@ -238,7 +238,7 @@ dtls_handle_read(struct dtls_context_t *ctx) { perror("recvfrom"); return -1; } else { - dtls_debug("got %d bytes from port %d\n", len, + dtls_debug("got %d bytes from port %d\n", len, ntohs(session.addr.sin6.sin6_port)); if (len <= DTLS_MAX_BUF) { dtls_debug_dump("bytes from peer", buf, len); diff --git a/tests/dtls_ciphers_util.c b/tests/dtls_ciphers_util.c index d8444f9a..3905f649 100644 --- a/tests/dtls_ciphers_util.c +++ b/tests/dtls_ciphers_util.c @@ -93,4 +93,3 @@ cipher_suites_usage(FILE* file, const char* head) { } fprintf(file, ")\n"); } - diff --git a/tests/netq-test.c b/tests/netq-test.c index 901a3424..e327f98e 100644 --- a/tests/netq-test.c +++ b/tests/netq-test.c @@ -1,8 +1,8 @@ #include #include -#include "utlist.h" -#include "netq.h" +#include "utlist.h" +#include "netq.h" void dump_queue(struct netq_t *queue) { @@ -21,7 +21,7 @@ dump_queue(struct netq_t *queue) { int main(int argc, char **argv) { struct netq_t *nq = NULL, *node; int i; - + clock_time_t timestamps[] = { 300, 100, 200, 400, 500 }; for (i = 0; i < sizeof(timestamps)/sizeof(clock_time_t); i++) { @@ -53,7 +53,7 @@ int main(int argc, char **argv) { dump_queue(nq); netq_node_free(node); - + printf("------------------------------------------------------------------------\n"); printf("queue head:\n"); node = netq_head(&nq); @@ -108,7 +108,7 @@ int main(int argc, char **argv) { printf("------------------------------------------------------------------------\n"); printf("remove all:\n"); - + netq_delete_all(&nq); dump_queue(nq); diff --git a/tests/pcap.c b/tests/pcap.c index 90f7f180..f64fbe8c 100644 --- a/tests/pcap.c +++ b/tests/pcap.c @@ -16,7 +16,7 @@ size_t pre_master_len = 0; unsigned char master_secret[DTLS_MASTER_SECRET_LENGTH]; size_t master_secret_len = 0; -dtls_security_parameters_t security_params[2]; +dtls_security_parameters_t security_params[2]; int config = 0; unsigned int epoch[2] = { 0, 0 }; @@ -27,7 +27,7 @@ dtls_hash_t hs_hash[1]; #endif static inline void -update_hash(uint8 *record, size_t rlength, +update_hash(uint8 *record, size_t rlength, uint8 *data, size_t data_length) { int i; @@ -53,8 +53,8 @@ finalize_hash(uint8 *buf) { /* temporarily store hash status for roll-back after finalize */ #if DTLS_VERSION == 0xfeff memcpy(statebuf, hs_hash[0], sizeof(md5_state_t)); - memcpy(statebuf + sizeof(md5_state_t), - hs_hash[1], + memcpy(statebuf + sizeof(md5_state_t), + hs_hash[1], sizeof(SHA_CTX)); #elif DTLS_VERSION == 0xfefd memcpy(statebuf, hs_hash[0], sizeof(statebuf)); @@ -68,8 +68,8 @@ finalize_hash(uint8 *buf) { /* restore hash status */ #if DTLS_VERSION == 0xfeff memcpy(hs_hash[0], statebuf, sizeof(md5_state_t)); - memcpy(hs_hash[1], - statebuf + sizeof(md5_state_t), + memcpy(hs_hash[1], + statebuf + sizeof(md5_state_t), sizeof(SHA_CTX)); #elif DTLS_VERSION == 0xfefd memcpy(hs_hash[0], statebuf, sizeof(statebuf)); @@ -94,7 +94,7 @@ clear_hash() { int pcap_verify(dtls_security_parameters_t *sec, - int is_client, + int is_client, const unsigned char *record, size_t record_length, const unsigned char *cleartext, size_t cleartext_length) { @@ -105,8 +105,8 @@ pcap_verify(dtls_security_parameters_t *sec, if (cleartext_length < dtls_kb_digest_size(sec)) return 0; - dtls_hmac_init(&hmac_ctx, - is_client + dtls_hmac_init(&hmac_ctx, + is_client ? dtls_kb_client_mac_secret(sec) : dtls_kb_server_mac_secret(sec), dtls_kb_mac_secret_size(sec)); @@ -114,12 +114,12 @@ pcap_verify(dtls_security_parameters_t *sec, cleartext_length -= dtls_kb_digest_size(sec); /* calculate MAC even if padding is wrong */ - dtls_mac(&hmac_ctx, + dtls_mac(&hmac_ctx, record, /* the pre-filled record header */ cleartext, cleartext_length, mac); - ok = memcmp(mac, cleartext + cleartext_length, + ok = memcmp(mac, cleartext + cleartext_length, dtls_kb_digest_size(sec)) == 0; #ifndef NDEBUG printf("MAC (%s): ", ok ? "valid" : "invalid"); @@ -128,7 +128,7 @@ pcap_verify(dtls_security_parameters_t *sec, #endif return ok; } - + int decrypt_verify(int is_client, const uint8 *packet, size_t length, uint8 **cleartext, size_t *clen) { @@ -136,7 +136,7 @@ decrypt_verify(int is_client, const uint8 *packet, size_t length, dtls_cipher_context_t *cipher; static unsigned char buf[1000]; - + switch (CURRENT_CONFIG->cipher) { case AES128: /* TLS_PSK_WITH_AES128_CBC_SHA */ *cleartext = buf; @@ -144,18 +144,18 @@ decrypt_verify(int is_client, const uint8 *packet, size_t length, if (is_client) cipher = CURRENT_CONFIG->read_cipher; - else - cipher = CURRENT_CONFIG->write_cipher; + else + cipher = CURRENT_CONFIG->write_cipher; res = dtls_decrypt(cipher, - (uint8 *)packet + sizeof(dtls_record_header_t), *clen, + (uint8 *)packet + sizeof(dtls_record_header_t), *clen, buf, NULL, 0); if (res < 0) { warn("decryption failed!\n"); } else { - ok = pcap_verify(CURRENT_CONFIG, is_client, (uint8 *)packet, length, - *cleartext, res); + ok = pcap_verify(CURRENT_CONFIG, is_client, (uint8 *)packet, length, + *cleartext, res); if (ok) *clen = res - dtls_kb_digest_size(CURRENT_CONFIG); @@ -164,10 +164,10 @@ decrypt_verify(int is_client, const uint8 *packet, size_t length, default: /* no cipher suite selected */ *cleartext = (uint8 *)packet + sizeof(dtls_record_header_t); *clen = length - sizeof(dtls_record_header_t); - + ok = 1; } - + if (ok) printf("verify OK\n"); else @@ -191,7 +191,7 @@ decrypt_verify(int is_client, const uint8 *packet, size_t length, if (((M)[0] & 0xF0) == 0x60) { /* IPv6 */ \ (M) += 40; \ (L) -= 40; \ - } + } #define SKIP_UDP_HEADER(M,L) { \ (M) += 8; \ @@ -201,10 +201,10 @@ decrypt_verify(int is_client, const uint8 *packet, size_t length, void handle_packet(const u_char *packet, int length) { static int n = 0; - static unsigned char initial_hello[] = { - 0x16, 0xfe, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + static unsigned char initial_hello[] = { + 0x16, 0xfe, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - uint8 *data; + uint8 *data; size_t data_length, rlen; int i, res; #if DTLS_VERSION == 0xfeff @@ -244,17 +244,17 @@ handle_packet(const u_char *packet, int length) { if (res <= 0) goto next; - + printf("packet %d (from %s):\n", n, is_client ? "client" : "server"); hexdump(packet, sizeof(dtls_record_header_t)); printf("\n"); hexdump(data, data_length); printf("\n"); - + if (packet[0] == 22 && data[0] == 1) { /* ClientHello */ if (memcmp(packet, initial_hello, sizeof(initial_hello)) == 0) goto next; - + memcpy(dtls_kb_client_iv(OTHER_CONFIG), data + 14, 32); clear_hash(); @@ -268,28 +268,28 @@ handle_packet(const u_char *packet, int length) { dtls_hash_init(hs_hash[0]); #endif } - + if (packet[0] == 22 && data[0] == 2) { /* ServerHello */ memcpy(dtls_kb_server_iv(OTHER_CONFIG), data + 14, 32); /* FIXME: search in ciphers */ OTHER_CONFIG->cipher = TLS_PSK_WITH_AES_128_CCM_8; } - + if (packet[0] == 20 && data[0] == 1) { /* ChangeCipherSpec */ printf("client random: "); dump(dtls_kb_client_iv(OTHER_CONFIG), 32); printf("\nserver random: "); dump(dtls_kb_server_iv(OTHER_CONFIG), 32); printf("\n"); - master_secret_len = + master_secret_len = dtls_prf(pre_master_secret, pre_master_len, (unsigned char *)"master secret", 13, dtls_kb_client_iv(OTHER_CONFIG), 32, dtls_kb_server_iv(OTHER_CONFIG), 32, master_secret, DTLS_MASTER_SECRET_LENGTH); - + printf("master_secret:\n "); - for(i = 0; i < master_secret_len; i++) + for(i = 0; i < master_secret_len; i++) printf("%02x", master_secret[i]); printf("\n"); @@ -300,10 +300,10 @@ handle_packet(const u_char *packet, int length) { (unsigned char *)"key expansion", 13, dtls_kb_server_iv(OTHER_CONFIG), 32, dtls_kb_client_iv(OTHER_CONFIG), 32, - OTHER_CONFIG->key_block, + OTHER_CONFIG->key_block, dtls_kb_size(OTHER_CONFIG)); - OTHER_CONFIG->read_cipher = + OTHER_CONFIG->read_cipher = dtls_cipher_new(OTHER_CONFIG->cipher, dtls_kb_client_write_key(OTHER_CONFIG), dtls_kb_key_size(OTHER_CONFIG)); @@ -316,11 +316,11 @@ handle_packet(const u_char *packet, int length) { dtls_kb_iv_size(OTHER_CONFIG)); } - OTHER_CONFIG->write_cipher = - dtls_cipher_new(OTHER_CONFIG->cipher, + OTHER_CONFIG->write_cipher = + dtls_cipher_new(OTHER_CONFIG->cipher, dtls_kb_server_write_key(OTHER_CONFIG), dtls_kb_key_size(OTHER_CONFIG)); - + if (!OTHER_CONFIG->write_cipher) { warn("cannot create write cipher\n"); } else { @@ -334,36 +334,36 @@ handle_packet(const u_char *packet, int length) { epoch[is_client]++; printf("key_block:\n"); - printf(" client_MAC_secret:\t"); - dump(dtls_kb_client_mac_secret(CURRENT_CONFIG), + printf(" client_MAC_secret:\t"); + dump(dtls_kb_client_mac_secret(CURRENT_CONFIG), dtls_kb_mac_secret_size(CURRENT_CONFIG)); printf("\n"); - printf(" server_MAC_secret:\t"); - dump(dtls_kb_server_mac_secret(CURRENT_CONFIG), + printf(" server_MAC_secret:\t"); + dump(dtls_kb_server_mac_secret(CURRENT_CONFIG), dtls_kb_mac_secret_size(CURRENT_CONFIG)); printf("\n"); - printf(" client_write_key:\t"); - dump(dtls_kb_client_write_key(CURRENT_CONFIG), + printf(" client_write_key:\t"); + dump(dtls_kb_client_write_key(CURRENT_CONFIG), dtls_kb_key_size(CURRENT_CONFIG)); printf("\n"); - printf(" server_write_key:\t"); - dump(dtls_kb_server_write_key(CURRENT_CONFIG), + printf(" server_write_key:\t"); + dump(dtls_kb_server_write_key(CURRENT_CONFIG), dtls_kb_key_size(CURRENT_CONFIG)); printf("\n"); - printf(" client_IV:\t\t"); - dump(dtls_kb_client_iv(CURRENT_CONFIG), + printf(" client_IV:\t\t"); + dump(dtls_kb_client_iv(CURRENT_CONFIG), dtls_kb_iv_size(CURRENT_CONFIG)); printf("\n"); - - printf(" server_IV:\t\t"); - dump(dtls_kb_server_iv(CURRENT_CONFIG), + + printf(" server_IV:\t\t"); + dump(dtls_kb_server_iv(CURRENT_CONFIG), dtls_kb_iv_size(CURRENT_CONFIG)); printf("\n"); - + } if (packet[0] == 22) { @@ -375,9 +375,9 @@ handle_packet(const u_char *packet, int length) { data, data_length); dtls_prf(master_secret, master_secret_len, - is_client - ? (unsigned char *)"client finished" - : (unsigned char *)"server finished" + is_client + ? (unsigned char *)"client finished" + : (unsigned char *)"server finished" , 15, hash_buf, sizeof(hash_buf), NULL, 0, @@ -440,7 +440,7 @@ int main(int argc, char **argv) { switch (c) { case 'p': - pre_master_len = dtls_pre_master_secret((unsigned char *)optarg, + pre_master_len = dtls_pre_master_secret((unsigned char *)optarg, strlen(optarg), pre_master_secret); break; } @@ -461,14 +461,14 @@ int main(int argc, char **argv) { for (;;) { res = pcap_next_ex(pcap, &pkthdr, &packet); - + switch(res) { case -2: goto done; case -1: pcap_perror(pcap, "read packet"); break; case 1: handle_packet(packet, pkthdr->caplen); break; - default: + default: ; - } + } } done: diff --git a/tests/unit-tests/Makefile.in b/tests/unit-tests/Makefile.in index 8c24c91c..ee737eb3 100644 --- a/tests/unit-tests/Makefile.in +++ b/tests/unit-tests/Makefile.in @@ -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. # @@ -47,7 +47,7 @@ all: $(PROGRAM) $(PROGRAM):: $(OBJECTS) -check: +check: ./testdriver clean: @@ -56,7 +56,7 @@ clean: $(MAKE) -C $$dir clean ; \ done -doc: +doc: $(MAKE) -C doc distclean: clean diff --git a/tests/unit-tests/test_ccm.c b/tests/unit-tests/test_ccm.c index f54df8f9..6b7f7307 100644 --- a/tests/unit-tests/test_ccm.c +++ b/tests/unit-tests/test_ccm.c @@ -59,7 +59,7 @@ t_test_decrypt_message(void) { assert(data[n].r_lm - data[n].la <= sizeof(buf)); memcpy(buf, data[n].result + data[n].la, data[n].r_lm - data[n].la); - len = dtls_ccm_decrypt_message(&ctx, data[n].M, data[n].L, data[n].nonce, + len = dtls_ccm_decrypt_message(&ctx, data[n].M, data[n].L, data[n].nonce, buf, data[n].r_lm - data[n].la, data[n].result, data[n].la); @@ -72,7 +72,7 @@ static void t_test_dtls_encrypt_params(void) { size_t n; int len; - + for (n = 0; n < sizeof(data)/sizeof(struct test_vector); ++n) { dtls_ccm_params_t params = { .nonce = data[n].nonce, @@ -126,7 +126,7 @@ static void t_test_dtls_encrypt(void) { size_t n; int len; - + for (n = 0; n < sizeof(data)/sizeof(struct test_vector); ++n) { /* The backwards-compatible dtls_encrypt() and dtls_decrypt() * only handle cipher suites with M=8 and L=3. */ @@ -149,7 +149,7 @@ static void t_test_dtls_decrypt(void) { size_t n; int len; - + for (n = 0; n < sizeof(data)/sizeof(struct test_vector); ++n) { /* The backwards-compatible dtls_encrypt() and dtls_decrypt() * only handle cipher suites with M=8 and L=3. */ @@ -212,4 +212,3 @@ t_init_ccm_tests(void) { return suite; } - diff --git a/tests/unit-tests/test_ecc.c b/tests/unit-tests/test_ecc.c index a2dc99fe..f57920b8 100644 --- a/tests/unit-tests/test_ecc.c +++ b/tests/unit-tests/test_ecc.c @@ -32,7 +32,7 @@ uint32_t BasePointy[8] = { 0x37bf51f5, 0xcbb64068, 0x6b315ece, 0x2bce3357, 0x7c0f9e16, 0x8ee7eb4a, 0xfe1a7f9b, 0x4fe342e2}; //de2444be bc8d36e6 82edd27e 0f271508 617519b3 221a8fa0 b77cab39 89da97c9 -uint32_t Sx[8] = { 0x89da97c9, 0xb77cab39, 0x221a8fa0, 0x617519b3, +uint32_t Sx[8] = { 0x89da97c9, 0xb77cab39, 0x221a8fa0, 0x617519b3, 0x0f271508, 0x82edd27e, 0xbc8d36e6, 0xde2444be}; //c093ae7f f36e5380 fc01a5aa d1e66659 702de80f 53cec576 b6350b24 3042a256 @@ -50,7 +50,7 @@ uint32_t Ty[8] = { 0xc8b24316, 0xb656e9d8, 0x598b9e7a, 0xf61a8a52, //c51e4753 afdec1e6 b6c6a5b9 92f43f8d d0c7a893 3072708b 6522468b 2ffb06fd uint32_t secret[8] = { 0x2ffb06fd, 0x6522468b, 0x3072708b, 0xd0c7a893, 0x92f43f8d, 0xb6c6a5b9, 0xafdec1e6, 0xc51e4753}; - + //72b13dd4 354b6b81 745195e9 8cc5ba69 70349191 ac476bd4 553cf35a 545a067e uint32_t resultAddx[8] = { 0x545a067e, 0x553cf35a, 0xac476bd4, 0x70349191, 0x8cc5ba69, 0x745195e9, 0x354b6b81, 0x72b13dd4}; @@ -184,7 +184,7 @@ t_test_ecc_ecdsa0(void) { ecc_ec_mult(BasePointx, BasePointy, ecdsaTestSecret, pub_x, pub_y); ret = ecc_ecdsa_sign(ecdsaTestSecret, ecdsaTestMessage, ecdsaTestRand1, tempx, tempy); - + memset(tempy, 0, sizeof(tempy)); ret = ecc_ecdsa_validate(pub_x, pub_y, ecdsaTestMessage, tempx, tempy); CU_ASSERT(ret == -1); @@ -206,7 +206,7 @@ t_init_ecc_tests(void) { * the seed. For other platforms, the random sequence will be the * same for each run. */ dtls_prng_init(0); - + if (!CU_ADD_TEST(suite,t_test_ecc_add)) { fprintf(stderr, "W: cannot add test for ECC add (%s)\n", CU_get_error_msg()); @@ -239,4 +239,3 @@ t_init_ecc_tests(void) { return suite; } - diff --git a/tests/unit-tests/test_prf.c b/tests/unit-tests/test_prf.c index 1fb53f12..ab3be97a 100644 --- a/tests/unit-tests/test_prf.c +++ b/tests/unit-tests/test_prf.c @@ -284,4 +284,3 @@ t_init_prf_tests(void) { return suite; } - diff --git a/zephyr/CMakeLists.txt b/zephyr/CMakeLists.txt index a279f770..58a2aba9 100644 --- a/zephyr/CMakeLists.txt +++ b/zephyr/CMakeLists.txt @@ -6,7 +6,7 @@ # information regarding copyright ownership. # # This program and the accompanying materials are made available under the -# terms of the Eclipse Public License 1.0 +# terms of the Eclipse Public License 1.0 # which is available at http://www.eclipse.org/legal/epl-v10.html # and the Eclipse Distribution License v. 1.0 # available at http://www.eclipse.org/org/documents/edl-v10.php diff --git a/zephyr/Kconfig b/zephyr/Kconfig index 2ffc3b01..2958e00e 100644 --- a/zephyr/Kconfig +++ b/zephyr/Kconfig @@ -6,7 +6,7 @@ # information regarding copyright ownership. # # This program and the accompanying materials are made available under the -# terms of the Eclipse Public License 1.0 +# terms of the Eclipse Public License 1.0 # which is available at http://www.eclipse.org/legal/epl-v10.html # and the Eclipse Distribution License v. 1.0 # available at http://www.eclipse.org/org/documents/edl-v10.php