#define RES_O_SMNC 9
#define RES_O_SMCC 10
-#define VALUE_NETWORK_BEARER_GSM 0 //GSM see
+#define VALUE_NETWORK_BEARER_GSM 0 //GSM see
#define VALUE_AVL_NETWORK_BEARER_1 0 //GSM
#define VALUE_AVL_NETWORK_BEARER_2 21 //WLAN
#define VALUE_AVL_NETWORK_BEARER_3 41 //Ethernet
#define HORIZONTAL_VELOCITY_VERTICAL 1 // set vertical direction bit!
#define HORIZONTAL_VELOCITY_WITH_UNCERTAINTY 2
-#define VELOCITY_OCTETS 5 // for HORIZONTAL_VELOCITY_WITH_UNCERTAINTY
+#define VELOCITY_OCTETS 5 // for HORIZONTAL_VELOCITY_WITH_UNCERTAINTY
typedef struct {
float latitude;
/**
* @fn :tc_libc_pthread_pthread_setcancelstate
* @brief :This tc tests pthread_setcancelstate()
-* @Scenario :The function shall atomically both set the calling thread's cancelability state to the indicated state
+* @Scenario :The function shall atomically both set the calling thread's cancelability state to the indicated state
* and return the previous cancelability state at the location referenced by oldstate
* If successful pthread_setcancelstate() function shall return zero;
* otherwise, an error number shall be returned to indicate the error.
/**
* @fn :tc_libc_pthread_pthread_setcanceltype
* @brief :This tc tests pthread_setcanceltype()
-* @Scenario :The function shall atomically both set the calling thread's cancelability type to the indicated type
+* @Scenario :The function shall atomically both set the calling thread's cancelability type to the indicated type
* and return the previous cancelability type at the location referenced by oldtype
* If successful pthread_setcanceltype() function shall return zero;
* otherwise, an error number shall be returned to indicate the error.
/**
* @fn :tc_pthread_pthread_setcanceltype
* @brief :This tc tests pthread_setcanceltype()
-* @Scenario :The function shall atomically both set the calling thread's cancelability type to the indicated type
+* @Scenario :The function shall atomically both set the calling thread's cancelability type to the indicated type
* and return the previous cancelability type at the location referenced by oldtype
* If successful pthread_setcanceltype() function shall return zero;
* otherwise, an error number shall be returned to indicate the error.
if (waitTime <= 0) {
printf("[AutoConnect]WiFi is not working. Test Canceled\n");
return 0;
- }
+ }
return 1;
}
return ret;
}
static void prv_wakaama_start(void)
-{
+{
if (dm_lwm2m_start_client(&dm_context) != DM_ERROR_NONE) {
fprintf(stderr, "Error creating wakaama thread\n");
} else {
}
sleep(10);
if (dm_conn_get_scan_result(&appwifiscan_result) == DM_ERROR_NONE) {
- wifi_iterator = appwifiscan_result;
+ wifi_iterator = appwifiscan_result;
while (wifi_iterator != NULL) {
for (i = 0; i < sizeof(wifi_aps) / sizeof(char *); i++) {
if (!strncmp(wifi_iterator->ssid, wifi_aps[i], strlen(wifi_aps[i]))) {
} else { \
(Offset)--; \
} \
-
+
/**
* Adds Char to Buf if Offset is zero and Buf is less than Bufend.
*/
milli = INFINITE;
}
- // Wait for the given time
+ // Wait for the given time
if (!SleepConditionVariableCS(&eventInfo->cond, &mutexInfo->mutex, milli))
{
if (GetLastError() == ERROR_TIMEOUT)
OICFree(val->arr.iArray);
break;
case OCREP_PROP_STRING:
- if (val->arr.strArray != NULL)
+ if (val->arr.strArray != NULL)
{
for(size_t i = 0; i < dimTotal; ++i)
{
static void ConnectedCallback(wifi_error_e err, void* data)
{
if(err == WIFI_ERROR_NONE) {
- OIC_LOG(DEBUG, ES_WIFICONN_TAG, "Success to Connect AP");
+ OIC_LOG(DEBUG, ES_WIFICONN_TAG, "Success to Connect AP");
}
else {
- OIC_LOG(ERROR, ES_WIFICONN_TAG, "Fail to Connect AP");
+ OIC_LOG(ERROR, ES_WIFICONN_TAG, "Fail to Connect AP");
}
}
OIC_LOG(ERROR, ES_WIFICONN_TAG, "Fail to connect wifi");
OIC_LOG_V(INFO, ES_WIFICONN_TAG, "Connect Fail Status : %s", PrintWifiErr((wifi_error_e) ret));
g_free(foundAP);
- return false;
+ return false;
}
else {
OIC_LOG_V(INFO, ES_WIFICONN_TAG, "Success to connect wifi : %s", PrintWifiErr((wifi_error_e) ret));
gWiFiConnFlag = true;
g_free(foundAP);
- return false;
+ return false;
}
#ifdef __TIZENRT__
-static int
-embos_pthread_create(pthread_t *thread,
- pthread_attr_t *attr,
- pthread_startroutine_t start_routine,
- pthread_addr_t arg,
+static int
+embos_pthread_create(pthread_t *thread,
+ pthread_attr_t *attr,
+ pthread_startroutine_t start_routine,
+ pthread_addr_t arg,
const char *task_name, int stack_size)
{
/* All callers have null attr, so ignore it for simple implementation*/
prv_tagServer(contextP, dataP[i].id);
}
}
-
+
if(result != COAP_204_CHANGED) // Stop object create or write when result is error
{
break;
// get object level attributes
objParamP = prv_findAttributes(contextP, &tempUri, serverP);
-
+
// get object instance level attributes
tempUri.instanceId = uriP->instanceId;
tempUri.flag = LWM2M_URI_FLAG_INSTANCE_ID;
* Simon Bernard - Please refer to git log
* Toby Jaffey - Please refer to git log
* Pascal Rieux - Please refer to git log
- *
+ *
*******************************************************************************/
/*
*
* Contributors:
* David Navarro, Intel Corporation - initial API and implementation
- *
+ *
*******************************************************************************/
#include "internals.h"
* Toby Jaffey - Please refer to git log
* Bosch Software Innovations GmbH - Please refer to git log
* Pascal Rieux - Please refer to git log
- *
+ *
*******************************************************************************/
/*
Copyright (c) 2013, 2014 Intel Corporation
* Benjamin Cabé - Please refer to git log
* Bosch Software Innovations GmbH - Please refer to git log
* Pascal Rieux - Please refer to git log
- *
+ *
*******************************************************************************/
/*
targetP = (lwm2m_object_t *)LWM2M_LIST_FIND(contextP->objectList, uriP->objectId);
if (NULL == targetP) return COAP_404_NOT_FOUND;
- if (NULL == targetP->createFunc)
+ if (NULL == targetP->createFunc)
{
return COAP_405_METHOD_NOT_ALLOWED;
}
targetP = (lwm2m_object_t *)LWM2M_LIST_FIND(contextP->objectList, uriP->objectId);
if (NULL == targetP) return COAP_404_NOT_FOUND;
- if (NULL == targetP->writeFunc)
+ if (NULL == targetP->writeFunc)
{
return COAP_405_METHOD_NOT_ALLOWED;
}
* David Navarro, Intel Corporation - initial API and implementation
* Toby Jaffey - Please refer to git log
* Bosch Software Innovations GmbH - Please refer to git log
- *
+ *
*******************************************************************************/
/*
uint8_t result;
LOG_ARG("State: %s", STR_STATE(contextP->state));
-
+
result = COAP_NO_ERROR;
targetP = contextP->serverList;
{
data += 1;
length -= 2;
- }
+ }
else
{
return 0;
* David Navarro, Intel Corporation - initial API and implementation
* Fabien Fleutot - Please refer to git log
* Bosch Software Innovations GmbH - Please refer to git log
- *
+ *
*******************************************************************************/
#include "internals.h"
}
-int tlv_serialize(bool isResourceInstance,
+int tlv_serialize(bool isResourceInstance,
int size,
lwm2m_data_t * dataP,
uint8_t ** bufferP)
coap_init_message(response, proto, COAP_TYPE_ACK, 0, message->mid);
message_send(contextP, response, fromSessionH);
}
-
+
if ((COAP_401_UNAUTHORIZED == message->code) && (COAP_MAX_RETRANSMIT > transacP->retrans_counter))
{
transacP->ack_received = false;
transacP->retrans_time += COAP_RESPONSE_TIMEOUT;
return true;
}
- }
+ }
if (transacP->callback != NULL)
{
transacP->callback(transacP, message);
* Toby Jaffey - Please refer to git log
* Bosch Software Innovations GmbH - Please refer to git log
* Pascal Rieux - Please refer to git log
- *
+ *
*******************************************************************************/
/*
* Contributors:
* David Navarro, Intel Corporation - initial API and implementation
* Toby Jaffey - Please refer to git log
- *
+ *
*******************************************************************************/
/*
void utils_copyValue(void * dst,
const void * src,
size_t len)
-{
+{
#ifdef LWM2M_BIG_ENDIAN
memcpy(dst, src, len);
#else
}
size_t utils_base64Encode(uint8_t * dataP,
- size_t dataLen,
+ size_t dataLen,
uint8_t * bufferP,
size_t bufferLen)
{
lwm2m_free(*bufferP);
*bufferP = NULL;
}
-
+
return result_len;
}
int readonce(FAR const char *filename, FAR char *buffer, uint8_t buflen)
{
int ret;
-
+
printf("opening %s\n", filename);
int fd = open(filename, O_RDONLY);
-
+
memset(buffer, 0x00, buflen);
if (fd < 0)
{
}
else
{
- size_t nbytes;
-
-
+ size_t nbytes;
+
+
/* Read until we hit the end of the file, until we have exhausted the
* buffer space, or until some irrecoverable error occurs
*/
*buffer = '\0'; /* NUL terminate the empty buffer */
ret = ERROR; /* Assume failure */
-
- nbytes = read(fd, buffer, buflen);
+
+ nbytes = read(fd, buffer, buflen);
printf("%d bytes read\n", nbytes);
if (nbytes < 0)
{
/* Read error */
-
+
int errcode = errno;
DEBUGASSERT(errcode > 0);
-
+
/* EINTR is not a read error. It simply means that a signal was
* received while waiting for the read to complete.
*/
-
+
if (errcode != EINTR)
{
/* Fatal error */
-
- printf("EINTR error\n");
+
+ printf("EINTR error\n");
}
}
else if (nbytes >= 0)
}
}
-
+
/* Close the file and return. */
close(fd);
//ssize_t nread;
ssize_t ntotal;
int ret;
-
+
printf("opening %s\n", filename);
int fd = open(filename, O_RDONLY);
-
+
if (fd < 0)
{
printf("error reading file %s\n", filename);
}
else
{
- size_t nbytes;
-
-
+ size_t nbytes;
+
+
/* Read until we hit the end of the file, until we have exhausted the
* buffer space, or until some irrecoverable error occurs
*/
bufptr = buffer; /* Working pointer */
remaining = buflen - 1; /* Reserve one byte for a NUL terminator */
ret = ERROR; /* Assume failure */
-
+
do {
- nbytes = read(fd, buffer, buflen);
+ nbytes = read(fd, buffer, buflen);
printf("%d bytes read\n", nbytes);
if (nbytes < 0)
{
/* Read error */
-
+
int errcode = errno;
DEBUGASSERT(errcode > 0);
-
+
/* EINTR is not a read error. It simply means that a signal was
* received while waiting for the read to complete.
*/
-
+
if (errcode != EINTR)
{
/* Fatal error */
-
+
printf("EINTR error\n");
break;
}
}
} while (buflen > 0);
}
-
+
/* Close the file and return. */
close(fd);
void mount_procfs(void)
{
- int ret;
+ int ret;
ret = mount(NULL, PROC_MOUNTPOINT, "procfs", 0, NULL);
}
*
* Description:
* Get the underlined interface name
- *
+ *
*
* Returned Value:
*
****************************************************************************/
-
+
void get_interface_name(char *mac)
{
#if defined(CONFIG_WICED)
* Fetch IPv4/IPv6 address
*
* Returned Value:
- *
+ *
*
****************************************************************************/
-
+
void get_ip_address(char *ipAddr)
{
- int ret;
+ int ret;
char *filepath;
ret = mount(NULL, PROC_MOUNTPOINT, "procfs", 0, NULL);
printf("mount returns value %d\n", ret);
ret = asprintf(&filepath, "%s/connectivity/ipaddr", PROC_MOUNTPOINT);
ret = readonce(filepath, cm_iobuffer, PROC_BUFFER_LEN);
- strncpy(ipAddr, cm_iobuffer, strlen(cm_iobuffer));
+ strncpy(ipAddr, cm_iobuffer, strlen(cm_iobuffer));
if (ret == OK)
{
printf("IP addr is %s\n", ipAddr);
- }
+ }
}
/****************************************************************************
* Get the router IPv4/IPv6 address
*
* Returned Value:
- *
+ *
*
****************************************************************************/
-
+
void get_router_ip_address(char *routerIPAddr)
{
char mac[4];
get_interface_name(mac);
-#ifdef CONFIG_NET_IPv4
+#ifdef CONFIG_NET_IPv4
struct in_addr addr;
netlib_get_dripv4addr(mac,addr);
inet_ntop(AF_INET, &addr, routerIPAddr, INET_ADDRSTRLEN);
#endif
#ifdef CONFIG_NET_IPv6
struct in6_addr addr;
- netlib_get_dripv6addr(mac,addr);
- inet_ntop(AF_INET6, &addr, routerIPAddr, INET6_ADDRSTRLEN);
-#endif
+ netlib_get_dripv6addr(mac,addr);
+ inet_ntop(AF_INET6, &addr, routerIPAddr, INET6_ADDRSTRLEN);
+#endif
}
/****************************************************************************
* Name: get_signal_strength
*
* Description:
- * Get Signal Strength value (RSSI in case of IEEE 802.15.4)
+ * Get Signal Strength value (RSSI in case of IEEE 802.15.4)
*
* Returned Value:
* Return the appropriate Callback flags
*
****************************************************************************/
-
+
void get_signal_strength(int *rssi_value)
{
- int ret;
+ int ret;
char *filepath;
ret = mount(NULL, PROC_MOUNTPOINT, "procfs", 0, NULL);
printf("mount returns value %d\n", ret);
// *rssi_value = atoi(cm_iobuffer);
sscanf(cm_iobuffer, "%d", rssi_value);
printf("rssi is %d\n", *rssi_value);
- }
+ }
}
/****************************************************************************
* Get link quality index value from MAC/PHY
*
* Returned Value:
- *
+ *
*
****************************************************************************/
* Get link utilization statictics from MAC/PHY
*
* Returned Value:
- *
+ *
*
****************************************************************************/
-
+
int get_link_utilization()
{
return 0;
* Get tx data value from MAC/PHY
*
* Returned Value:
- *
+ *
*
****************************************************************************/
-
+
int get_tx_data()
{
//TODO: Feature implementation
* Get rx data value from MAC/PHY
*
* Returned Value:
- *
+ *
*
****************************************************************************/
-
+
int get_rx_data()
{
///TODO: Feature implementation
* Get maximum message size
*
* Returned Value:
- *
+ *
*
****************************************************************************/
int get_max_message_size()
* Get bitrate
*
* Returned Value:
- *
*
- ****************************************************************************/
+ *
+ ****************************************************************************/
void get_bitrate(int *bitrate)
{
- int ret;
+ int ret;
char *filepath;
ret = mount(NULL, PROC_MOUNTPOINT, "procfs", 0, NULL);
printf("mount returns value %d\n", ret);
if (ret == OK)
{
*bitrate = atoi(cm_iobuffer);
- }
+ }
}
/****************************************************************************
* Get Network Bearer
*
* Returned Value:
- *
*
- ****************************************************************************/
+ *
+ ****************************************************************************/
void get_network_bearer(int *nwbearer)
{
- int ret;
+ int ret;
char *filepath;
ret = mount(NULL, PROC_MOUNTPOINT, "procfs", 0, NULL);
printf("mount returns value %d\n", ret);
* Get Available Network Bearer
*
* Returned Value:
- *
+ *
*
****************************************************************************/
void get_avl_network_bearer(int *nwbearer)
{
- int ret;
+ int ret;
char *filepath;
ret = mount(NULL, PROC_MOUNTPOINT, "procfs", 0, NULL);
printf("mount returns value %d\n", ret);
* Contributors:
* Bosch Software Innovations GmbH - Please refer to git log
* Pascal Rieux - please refer to git log
- *
+ *
******************************************************************************/
/*
* This "Access Control" object is optional and multiple instantiated
- *
+ *
* Resources:
*
* Name | ID | Oper. | Inst. | Mand.| Type | Range | Units |
/*******************************************************************************
*
- * Copyright (c) 2014 Bosch Software Innovations GmbH Germany.
+ * Copyright (c) 2014 Bosch Software Innovations GmbH Germany.
* 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 v1.0 which accompany this distribution.
* Contributors:
* Bosch Software Innovations GmbH - Please refer to git log
* Pascal Rieux - Please refer to git log
- *
+ *
*******************************************************************************/
/*
* This Connectivity Monitoring object is optional and has a single instance
- *
+ *
* Resources:
*
* Name | ID | Oper. | Inst. | Mand.| Type | Range | Units |
#define RES_O_SMNC 9
#define RES_O_SMCC 10
-#define VALUE_NETWORK_BEARER_GSM 0 //GSM see
+#define VALUE_NETWORK_BEARER_GSM 0 //GSM see
#define VALUE_AVL_NETWORK_BEARER_1 0 //GSM
#define VALUE_AVL_NETWORK_BEARER_2 21 //WLAN
#define VALUE_AVL_NETWORK_BEARER_3 41 //Ethernet
#define VALUE_APN_2 "cda.vodafone.de"
#define VALUE_CELL_ID 69696969
#define VALUE_RADIO_SIGNAL_STRENGTH 80 //dBm
-#define VALUE_LINK_QUALITY 98
+#define VALUE_LINK_QUALITY 98
#define VALUE_LINK_UTILIZATION 666
#define VALUE_SMNC 33
#define VALUE_SMCC 44
* It assigns his unique ID
*/
connObj->objID = LWM2M_CONN_MONITOR_OBJECT_ID;
-
+
/*
* and its unique instance
*
lwm2m_free(connObj);
return NULL;
}
-
+
/*
* And the private function that will access the object.
* Those function will be called when a read/write/execute query is made by the server. In fact the library don't need to
*
* Contributors:
* Bosch Software Innovations GmbH - Please refer to git log
- *
+ *
*******************************************************************************/
/*
* This connectivity statistics object is optional and single instance only
- *
+ *
* Resources:
*
* Name | ID | Oper. | Inst. | Mand.| Type | Range | Units | Description |
* Axel Lorente - Please refer to git log
* Bosch Software Innovations GmbH - Please refer to git log
* Pascal Rieux - Please refer to git log
- *
+ *
*******************************************************************************/
/*
case RES_O_FACTORY_RESET:
return COAP_405_METHOD_NOT_ALLOWED;
- case RES_O_AVL_POWER_SOURCES:
+ case RES_O_AVL_POWER_SOURCES:
{
lwm2m_data_t * subTlvP;
lwm2m_data_encode_int(PRV_POWER_CURRENT_1, &subTlvP[0]);
subTlvP[1].id = 1;
lwm2m_data_encode_int(PRV_POWER_CURRENT_2, &subTlvP[1]);
-
+
lwm2m_data_encode_instances(subTlvP, 2, dataP);
return COAP_205_CONTENT;
lwm2m_data_encode_instances(subTlvP, 1, dataP);
return COAP_205_CONTENT;
- }
+ }
case RES_O_RESET_ERROR_CODE:
return COAP_405_METHOD_NOT_ALLOWED;
case RES_O_TIMEZONE:
lwm2m_data_encode_string(PRV_TIME_ZONE, dataP);
return COAP_205_CONTENT;
-
+
case RES_M_BINDING_MODES:
lwm2m_data_encode_string(PRV_BINDING_MODE, dataP);
return COAP_205_CONTENT;
//ToDo IANA TZ Format
result = COAP_501_NOT_IMPLEMENTED;
break;
-
+
default:
result = COAP_405_METHOD_NOT_ALLOWED;
}
lwm2m_free(deviceObj);
return NULL;
}
-
+
/*
* And the private function that will access the object.
* Those function will be called when a read/write/execute query is made by the server. In fact the library don't need to
deviceObj->userData = lwm2m_malloc(sizeof(device_data_t));
/*
- * Also some user data can be stored in the object with a private structure containing the needed variables
+ * Also some user data can be stored in the object with a private structure containing the needed variables
*/
if (NULL != deviceObj->userData)
{
result = COAP_405_METHOD_NOT_ALLOWED;
break;
}
-
+
return result;
}
* David Navarro, Intel Corporation - Please refer to git log
* Bosch Software Innovations GmbH - Please refer to git log
* Pascal Rieux - Please refer to git log
- *
+ *
*******************************************************************************/
/*
/*******************************************************************************
- *
+ *
* Copyright (c) 2014 Bosch Software Innovations GmbH, Germany.
*
* All rights reserved. This program and the accompanying materials
* Contributors:
* Bosch Software Innovations GmbH - Please refer to git log
* Pascal Rieux - Please refer to git log
- *
+ *
******************************************************************************/
/*! \file
LWM2M object "Location" implementation
#define HORIZONTAL_VELOCITY_VERTICAL 1 // set vertical direction bit!
#define HORIZONTAL_VELOCITY_WITH_UNCERTAINTY 2
-#define VELOCITY_OCTETS 5 // for HORIZONTAL_VELOCITY_WITH_UNCERTAINTY
+#define VELOCITY_OCTETS 5 // for HORIZONTAL_VELOCITY_WITH_UNCERTAINTY
typedef struct
{
location_data_t* locDataP)
{
//-------------------------------------------------------------------- JH --
- uint8_t ret = COAP_205_CONTENT;
+ uint8_t ret = COAP_205_CONTENT;
switch (dataP->id) // location resourceId
{
case RES_M_LATITUDE:
ret = COAP_404_NOT_FOUND;
break;
}
-
+
return ret;
}
int* numDataP,
lwm2m_data_t** tlvArrayP,
lwm2m_object_t* objectP)
-{
+{
//-------------------------------------------------------------------- JH --
int i;
uint8_t result = COAP_500_INTERNAL_SERVER_ERROR;
RES_M_TIMESTAMP,
RES_O_SPEED
}; // readable resources!
-
+
*numDataP = sizeof(readResIds)/sizeof(uint16_t);
*tlvArrayP = lwm2m_data_new(*numDataP);
if (*tlvArrayP == NULL) return COAP_500_INTERNAL_SERVER_ERROR;
-
+
// init readable resource id's
for (i = 0 ; i < *numDataP ; i++)
{
(*tlvArrayP)[i].id = readResIds[i];
}
}
-
+
for (i = 0 ; i < *numDataP ; i++)
{
result = prv_res2tlv ((*tlvArrayP)+i, locDataP);
if (result!=COAP_205_CONTENT) break;
}
-
+
return result;
}
}
/**
- * This function creates the LWM2M Location.
- * @return gives back allocated LWM2M data object structure pointer. On error,
+ * This function creates the LWM2M Location.
+ * @return gives back allocated LWM2M data object structure pointer. On error,
* NULL value is returned.
*/
lwm2m_object_t * get_object_location(void)
// It assigns its unique ID
// The 6 is the standard ID for the optional object "Location".
locationObj->objID = LWM2M_LOCATION_OBJECT_ID;
-
+
// and its unique instance
locationObj->instanceList = (lwm2m_list_t *)lwm2m_malloc(sizeof(lwm2m_list_t));
if (NULL != locationObj->instanceList)
locationObj = NULL;
}
}
-
+
return locationObj;
}
* Bosch Software Innovations GmbH - Please refer to git log
* Pascal Rieux - Please refer to git log
* Ville Skytta - Please refer to git log
- *
+ *
*******************************************************************************/
/*
struct _security_instance_ * next; // matches lwm2m_list_t::next
uint16_t instanceId; // matches lwm2m_list_t::id
char * uri;
- bool isBootstrap;
+ bool isBootstrap;
uint8_t securityMode;
char * publicIdentity;
uint16_t publicIdLen;
memset(targetP, 0, sizeof(security_instance_t));
targetP->instanceId = 0;
- targetP->uri = (char*)lwm2m_malloc(strlen(serverUri)+1);
+ targetP->uri = (char*)lwm2m_malloc(strlen(serverUri)+1);
strcpy(targetP->uri, serverUri);
targetP->securityMode = LWM2M_SECURITY_MODE_NONE;
* Julien Vermillard, Sierra Wireless
* Bosch Software Innovations GmbH - Please refer to git log
* Pascal Rieux - Please refer to git log
- *
+ *
*******************************************************************************/
/*
* Achim Kraus, Bosch Software Innovations GmbH - Please refer to git log
* Pascal Rieux - Please refer to git log
* Ville Skytta - Please refer to git log
- *
+ *
*******************************************************************************/
/*
* Axel Lorente - Please refer to git log
* Bosch Software Innovations GmbH - Please refer to git log
* Pascal Rieux - Please refer to git log
- *
+ *
*******************************************************************************/
/*
case RES_M_REBOOT:
return COAP_405_METHOD_NOT_ALLOWED;
-
+
case RES_M_BINDING_MODES:
lwm2m_data_encode_string(PRV_BINDING_MODE, dataP);
return COAP_205_CONTENT;
lwm2m_free(deviceObj);
return NULL;
}
-
+
/*
* And the private function that will access the object.
* Those function will be called when a read/write/execute query is made by the server. In fact the library don't need to
* David Navarro, Intel Corporation - initial API and implementation
* Bosch Software Innovations GmbH - Please refer to git log
* Pascal Rieux - Please refer to git log
- *
+ *
*******************************************************************************/
/*
* Julien Vermillard, Sierra Wireless
* Bosch Software Innovations GmbH - Please refer to git log
* Pascal Rieux - Please refer to git log
- *
+ *
*******************************************************************************/
/*
* Axel Lorente - Please refer to git log
* Achim Kraus, Bosch Software Innovations GmbH - Please refer to git log
* Pascal Rieux - Please refer to git log
- *
+ *
*******************************************************************************/
/*
* Contributors:
* David Navarro, Intel Corporation - initial API and implementation
* Fabien Fleutot - Please refer to git log
- *
+ *
*******************************************************************************/
#include <string.h>
* Gregory Lemercier, Samsung Semiconductor - support for TCP/TLS
* David Navarro, Intel Corporation - initial API and implementation
* Pascal Rieux - Please refer to git log
- *
+ *
*******************************************************************************/
#include <stdlib.h>
(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 */
/* copy the nonce */
memcpy(result + 1, nonce, DTLS_CCM_BLOCKSIZE - L);
-
+
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.
*/
static void
add_auth_data(rijndael_ctx *ctx, const unsigned char *msg, size_t la,
- unsigned char B[DTLS_CCM_BLOCKSIZE],
+ unsigned char B[DTLS_CCM_BLOCKSIZE],
unsigned char X[DTLS_CCM_BLOCKSIZE]) {
- size_t i,j;
+ size_t i,j;
rijndael_encrypt(ctx, B, X);
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++;
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
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]) {
}
long int
-dtls_ccm_encrypt_message(rijndael_ctx *ctx, size_t M, size_t L,
- unsigned char nonce[DTLS_CCM_BLOCKSIZE],
- unsigned char *msg, size_t lm,
+dtls_ccm_encrypt_message(rijndael_ctx *ctx, size_t M, size_t L,
+ unsigned char nonce[DTLS_CCM_BLOCKSIZE],
+ unsigned char *msg, size_t lm,
const unsigned char *aad, size_t la) {
size_t i, len;
unsigned long counter_tmp;
/* copy the nonce */
memcpy(A + 1, nonce, DTLS_CCM_BLOCKSIZE - L);
-
+
while (lm >= DTLS_CCM_BLOCKSIZE) {
/* calculate MAC */
mac(ctx, msg, DTLS_CCM_BLOCKSIZE, 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);
long int
dtls_ccm_decrypt_message(rijndael_ctx *ctx, size_t M, size_t L,
- unsigned char nonce[DTLS_CCM_BLOCKSIZE],
- unsigned char *msg, size_t lm,
+ unsigned char nonce[DTLS_CCM_BLOCKSIZE],
+ 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
/* copy the nonce */
memcpy(A + 1, nonce, DTLS_CCM_BLOCKSIZE - L);
-
+
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);
* (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);
/* return length if MAC is valid, otherwise continue with error handling */
if (equals(X, msg, M))
return len - M;
-
+
error:
return -1;
}
/* initialize the handshake hash wrt. the hard-coded DTLS version */
dtls_debug("DTLSv12: initialize HASH_SHA256\n");
/* TLS 1.2: PRF(secret, label, seed) = P_<hash>(secret, label + seed) */
- /* FIXME: we use the default SHA256 here, might need to support other
+ /* FIXME: we use the default SHA256 here, might need to support other
hash functions as well */
dtls_hash_init(&handshake->hs_state.hs_hash);
}
dtls_hmac_init(hmac_p, key, keylen);
dtls_hmac_update(hmac_p, A, dlen);
-
+
HMAC_UPDATE_SEED(hmac_p, label, labellen);
HMAC_UPDATE_SEED(hmac_p, random1, random1len);
HMAC_UPDATE_SEED(hmac_p, random2, random2len);
-
+
dtls_hmac_finalize(hmac_p, tmp);
memcpy(buf, tmp, buflen - len);
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,
/* 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) {
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,
unsigned char *nounce,
const unsigned char *aad, size_t la) {
long int len;
assert(ccm_ctx);
- len = dtls_ccm_encrypt_message(&ccm_ctx->ctx, 8 /* M */,
+ len = dtls_ccm_encrypt_message(&ccm_ctx->ctx, 8 /* M */,
max(2, 15 - DTLS_CCM_NONCE_SIZE),
nounce,
- buf, srclen,
+ buf, srclen,
aad, la);
return len;
}
assert(ccm_ctx);
- len = dtls_ccm_decrypt_message(&ccm_ctx->ctx, 8 /* M */,
+ len = dtls_ccm_decrypt_message(&ccm_ctx->ctx, 8 /* M */,
max(2, 15 - DTLS_CCM_NONCE_SIZE),
nounce,
- buf, srclen,
+ buf, srclen,
aad, la);
return len;
}
memcpy(p, result, sizeof(uint16));
p += sizeof(uint16);
-
+
memcpy(p, key, keylen);
return 2 * (sizeof(uint16) + keylen);
unsigned char *buf) {
int i;
unsigned char *buf_orig = buf;
- int first = 1;
+ int first = 1;
for (i = (key_size / sizeof(uint32_t)) - 1; i >= 0 ; i--) {
if (key[i] == 0)
*buf = 0;
buf++;
dtls_int_to_uint32(buf, key[i]);
- buf += 4;
+ buf += 4;
} else if (first && !(key[i] & 0xFF800000)) {
buf[0] = (key[i] >> 16) & 0xff;
buf[1] = (key[i] >> 8) & 0xff;
uint32_t priv[8];
uint32_t hash[8];
uint32_t rand[8];
-
+
dtls_ec_key_to_uint32(priv_key, key_size, priv);
dtls_ec_key_to_uint32(sign_hash, sign_hash_size, hash);
do {
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);
}
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);
}
#endif /* DTLS_ECC */
-int
+int
dtls_encrypt(const unsigned char *src, size_t length,
unsigned char *buf,
unsigned char *nounce,
return ret;
}
-int
+int
dtls_decrypt(const unsigned char *src, size_t length,
unsigned char *buf,
unsigned char *nounce,
unsigned char type, uint8 *buf_array[],
size_t buf_len_array[], size_t buf_array_len);
-/**
+/**
* Sends the fragment of length \p buflen given in \p buf to the
* specified \p peer. The data will be MAC-protected and encrypted
* according to the selected cipher and split into one or more DTLS
*
* \param ctx The DTLS context to use.
* \param peer The remote peer.
- * \param type The content type of the record.
+ * \param type The content type of the record.
* \param buf The data to send.
* \param buflen The actual length of \p buf.
* \return Less than zero on error, the number of bytes written otherwise.
if (dtls_session_equals(&p->session, session))
return p;
#endif /* WITH_CONTIKI */
-
+
return p;
}
}
int
-dtls_write(struct dtls_context_t *ctx,
+dtls_write(struct dtls_context_t *ctx,
session_t *dst, uint8 *buf, size_t len) {
-
+
dtls_peer_t *peer = dtls_get_peer(ctx, dst);
/* Check if peer connection already exists */
return (res >= 0) ? 0 : res;
} else { /* a session exists, check if it is in state connected */
-
+
if (peer->state != DTLS_STATE_CONNECTED) {
return 0;
} else {
if (msglen < (*msg & 0xff) + sizeof(uint8))
return dtls_alert_fatal_create(DTLS_ALERT_HANDSHAKE_FAILURE);
-
+
*cookie = msg + sizeof(uint8);
return dtls_uint8_to_int(msg);
}
static int
-dtls_create_cookie(dtls_context_t *ctx,
+dtls_create_cookie(dtls_context_t *ctx,
session_t *session,
uint8 *msg, size_t msglen,
uint8 *cookie, int *clen) {
/* create cookie with HMAC-SHA256 over:
* - SECRET
* - session parameters (only IP address?)
- * - client version
+ * - client version
* - random gmt and bytes
* - session id
- * - cipher_suites
+ * - cipher_suites
* - compression method
*/
dtls_hmac_context_t hmac_context;
dtls_hmac_init(&hmac_context, ctx->cookie_secret, DTLS_COOKIE_SECRET_LENGTH);
- dtls_hmac_update(&hmac_context,
+ dtls_hmac_update(&hmac_context,
(unsigned char *)&session->addr, session->size);
/* feed in the beginning of the Client Hello up to and including the
return dtls_alert_fatal_create(DTLS_ALERT_HANDSHAKE_FAILURE);
dtls_hmac_update(&hmac_context, msg + DTLS_HS_LENGTH, e);
-
+
/* skip cookie bytes and length byte */
e += *(uint8 *)(msg + DTLS_HS_LENGTH + e) & 0xff;
e += sizeof(uint8);
if (e + DTLS_HS_LENGTH > msglen)
return dtls_alert_fatal_create(DTLS_ALERT_HANDSHAKE_FAILURE);
- dtls_hmac_update(&hmac_context,
+ dtls_hmac_update(&hmac_context,
msg + DTLS_HS_LENGTH + e,
dtls_get_fragment_length(DTLS_HANDSHAKE_HEADER(msg)) - e);
memset(cookie + len, 0, *clen - len);
*clen = len;
}
-
+
memcpy(cookie, buf, *clen);
return 0;
}
#ifdef DTLS_CHECK_CONTENTTYPE
/* used to check if a received datagram contains a DTLS message */
-static char const content_types[] = {
+static char const content_types[] = {
DTLS_CT_CHANGE_CIPHER_SPEC,
DTLS_CT_ALERT,
DTLS_CT_HANDSHAKE,
/**
* Checks if \p msg points to a valid DTLS record. If
- *
+ *
*/
static unsigned int
is_record(uint8 *msg, size_t msglen) {
&& strchr(content_types, msg[0])
#endif
&& msg[1] == HIGH(DTLS_VERSION)
- && msg[2] == LOW(DTLS_VERSION))
+ && msg[2] == LOW(DTLS_VERSION))
{
- rlen = DTLS_RH_LENGTH +
+ rlen = DTLS_RH_LENGTH +
dtls_uint16_to_int(DTLS_RECORD_HEADER(msg)->length);
-
+
/* we do not accept wrong length field in record header */
- if (rlen > msglen)
+ if (rlen > msglen)
rlen = 0;
- }
-
+ }
+
return rlen;
}
* bytes. Increments sequence number counter of \p security.
* \return pointer to the next byte after the written header.
* The length will be set to 0 and has to be changed before sending.
- */
+ */
static inline uint8 *
dtls_set_record_header(uint8 type, dtls_security_parameters_t *security,
uint8 *buf) {
-
+
dtls_int_to_uint8(buf, type);
buf += sizeof(uint8);
* buf is capable of holding at least \c sizeof(dtls_handshake_header_t)
* bytes. Increments message sequence number counter of \p peer.
* \return pointer to the next byte after \p buf
- */
+ */
static inline uint8 *
-dtls_set_handshake_header(uint8 type, dtls_peer_t *peer,
- int length,
- int frag_offset, int frag_length,
+dtls_set_handshake_header(uint8 type, dtls_peer_t *peer,
+ int length,
+ int frag_offset, int frag_length,
uint8 *buf) {
-
+
dtls_int_to_uint8(buf, type);
buf += sizeof(uint8);
/* increment handshake message sequence counter by 1 */
peer->handshake_params->hs_state.mseq_s++;
} else {
- memset(buf, 0, sizeof(uint16));
+ memset(buf, 0, sizeof(uint16));
}
buf += sizeof(uint16);
-
+
dtls_int_to_uint24(buf, frag_offset);
buf += sizeof(uint24);
dtls_int_to_uint24(buf, frag_length);
buf += sizeof(uint24);
-
+
return buf;
}
static inline int is_ecdsa_supported(dtls_context_t *ctx, int is_client)
{
#ifdef DTLS_ECC
- return ctx && ctx->h && ((!is_client && ctx->h->get_ecdsa_key) ||
+ return ctx && ctx->h && ((!is_client && ctx->h->get_ecdsa_key) ||
(is_client && ctx->h->verify_ecdsa_key));
#else
return 0;
* @param code The cipher suite identifier to check
* @param is_client 1 for a dtls client, 0 for server
* @return @c 1 iff @p code is recognized,
- */
+ */
static int
known_cipher(dtls_context_t *ctx, dtls_cipher_t code, int is_client) {
int psk;
* Calculate the pre master secret and after that calculate the master-secret.
*/
static int
-calculate_key_block(dtls_context_t *ctx,
+calculate_key_block(dtls_context_t *ctx,
dtls_handshake_parameters_t *handshake,
dtls_peer_t *peer,
session_t *session,
int ext_ec_point_formats = 0;
dtls_handshake_parameters_t *handshake = peer->handshake_params;
- if (data_length < sizeof(uint16)) {
+ if (data_length < sizeof(uint16)) {
/* no tls extensions specified */
if (is_tls_ecdhe_ecdsa_with_aes_128_ccm_8(handshake->cipher)) {
goto error;
break;
case TLS_EXT_ENCRYPT_THEN_MAC:
/* As only AEAD cipher suites are currently available, this
- * extension can be skipped.
+ * extension can be skipped.
*/
dtls_info("skipped encrypt-then-mac extension\n");
break;
*
* \param ctx The current DTLS context.
* \param peer The remote peer whose security parameters are about to change.
- * \param data The handshake message with a ClientHello.
+ * \param data The handshake message with a ClientHello.
* \param data_length The actual size of \p data.
* \return \c -Something if an error occurred, \c 0 on success.
*/
static int
-dtls_update_parameters(dtls_context_t *ctx,
+dtls_update_parameters(dtls_context_t *ctx,
dtls_peer_t *peer,
uint8 *data, size_t data_length) {
int i, j;
goto error;
}
- if (data_length < sizeof(uint8)) {
+ if (data_length < sizeof(uint8)) {
/* no compression specified, take the current compression method */
if (security)
config->compression = security->compression;
ok = 1;
}
i -= sizeof(uint8);
- data += sizeof(uint8);
+ data += sizeof(uint8);
}
if (!ok) {
/* reset config cipher to a well-defined value */
goto error;
}
-
+
return dtls_check_tls_extension(peer, data, data_length, 1);
error:
if (peer->state == DTLS_STATE_CONNECTED) {
* the new data.
*/
static inline int
-check_client_keyexchange(dtls_context_t *ctx,
+check_client_keyexchange(dtls_context_t *ctx,
dtls_handshake_parameters_t *handshake,
uint8 *data, size_t length) {
dtls_hash_init(&peer->handshake_params->hs_state.hs_hash);
}
-/**
+/**
* Checks if \p record + \p data contain a Finished message with valid
- * verify_data.
+ * verify_data.
*
* \param ctx The current DTLS context.
* \param peer The remote peer of the security association.
* \param data_array_len The number of payloads given.
* \param sendbuf The output buffer where the encrypted record
* will be placed.
- * \param rlen This parameter must be initialized with the
+ * \param rlen This parameter must be initialized with the
* maximum size of \p sendbuf and will be updated
* to hold the actual size of the stored packet
* on success. On error, the value of \p rlen is
- * undefined.
+ * undefined.
* \return Less than zero on error, or greater than zero success.
*/
static int
uint8 *p, *start;
int res;
unsigned int i;
-
+
if (*rlen < DTLS_RH_LENGTH) {
dtls_alert("The sendbuf (%zu bytes) is too small\n", *rlen);
return dtls_alert_fatal_create(DTLS_ALERT_INTERNAL_ERROR);
p += data_len_array[i];
res += data_len_array[i];
}
- } else { /* TLS_PSK_WITH_AES_128_CCM_8 or TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8 */
- /**
+ } else { /* TLS_PSK_WITH_AES_128_CCM_8 or TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8 */
+ /**
* length of additional_data for the AEAD cipher which consists of
* seq_num(2+6) + type(1) + version(2) + length(2)
*/
dtls_debug("dtls_prepare_record(): encrypt using unknown cipher\n");
}
- /* set nonce
+ /* set nonce
from RFC 6655:
The "nonce" input to the AEAD algorithm is exactly that of [RFC5288]:
the "nonce" SHALL be 12 bytes long and is constructed as follows:
dtls_debug_dump("nonce:", nonce, DTLS_CCM_BLOCKSIZE);
dtls_debug_dump("key:", dtls_kb_local_write_key(security, peer->role),
dtls_kb_key_size(security, peer->role));
-
+
/* re-use N to create additional data according to RFC 5246, Section 6.2.3.3:
- *
+ *
* additional_data = seq_num + TLSCompressed.type +
* TLSCompressed.version + TLSCompressed.length;
*/
memcpy(A_DATA, &DTLS_RECORD_HEADER(sendbuf)->epoch, 8); /* epoch and seq_num */
memcpy(A_DATA + 8, &DTLS_RECORD_HEADER(sendbuf)->content_type, 3); /* type and version */
dtls_int_to_uint16(A_DATA + 11, res - 8); /* length */
-
+
res = dtls_encrypt(start + 8, res - 8, start + 8, nonce,
dtls_kb_local_write_key(security, peer->role),
dtls_kb_key_size(security, peer->role),
/* fix length of fragment in sendbuf */
dtls_int_to_uint16(sendbuf + 11, res);
-
+
*rlen = DTLS_RH_LENGTH + res;
return 0;
}
header_type, data, data_length, 1);
}
-/**
+/**
* Returns true if the message @p Data is a handshake message that
* must be included in the calculation of verify_data in the Finished
* message.
- *
- * @param Type The message type. Only handshake messages but the initial
+ *
+ * @param Type The message type. Only handshake messages but the initial
* Client Hello and Hello Verify Request are included in the hash,
* @param Data The PDU to examine.
* @param Length The length of @p Data.
- *
+ *
* @return @c 1 if @p Data must be included in hash, @c 0 otherwise.
*
* @hideinitializer
dtls_debug("copied to sendqueue\n");
#endif /* WITH_CONTIKI */
}
- } else
+ } else
dtls_warn("retransmit buffer full\n");
}
return 0;
}
-int
+int
dtls_close(dtls_context_t *ctx, const session_t *remote) {
int res = -1;
dtls_peer_t *peer;
* Client Hello contains no cookie, the function fails and a Hello
* Verify Request is sent to the peer (using the write callback function
* registered with \p ctx). The return value is \c -1 on error, \c 0 when
- * undecided, and \c 1 if the Client Hello was good.
- *
+ * undecided, and \c 1 if the Client Hello was good.
+ *
* \param ctx The DTLS context.
* \param peer The remote party we are talking to, if any.
* \param session Transport address of the remote peer.
* \c -1 otherwise.
*/
static int
-dtls_verify_peer(dtls_context_t *ctx,
- dtls_peer_t *peer,
+dtls_verify_peer(dtls_context_t *ctx,
+ dtls_peer_t *peer,
session_t *session,
uint8 *data, size_t data_length)
{
dtls_debug_dump("create cookie", mycookie, len);
assert(len == DTLS_COOKIE_LENGTH);
-
+
/* Perform cookie check. */
len = dtls_get_cookie(data, data_length, &cookie);
if (len < 0) {
}
static int
-check_client_certificate_verify(dtls_context_t *ctx,
+check_client_certificate_verify(dtls_context_t *ctx,
dtls_peer_t *peer,
uint8 *data, size_t data_length)
{
uint8 buf[DTLS_CE_LENGTH];
uint8 *p;
- /* Certificate
+ /* Certificate
*
* Start message construction at beginning of buffer. */
p = buf;
dtls_int_to_uint24(p, 91); /* length of this certificate */
p += sizeof(uint24);
-
+
memcpy(p, &cert_asn1_header, sizeof(cert_asn1_header));
p += sizeof(cert_asn1_header);
uint32_t point_s[9];
dtls_handshake_parameters_t *config = peer->handshake_params;
- /* ServerKeyExchange
+ /* ServerKeyExchange
*
* Start message construction at beginning of buffer. */
p = buf;
uint8 buf[8];
uint8 *p;
- /* ServerHelloDone
+ /* ServerHelloDone
*
* Start message construction at beginning of buffer. */
p = buf;
dtls_send_server_hello_done(dtls_context_t *ctx, dtls_peer_t *peer)
{
- /* ServerHelloDone
+ /* ServerHelloDone
*
* Start message construction at beginning of buffer. */
return 0;
}
-static inline int
+static inline int
dtls_send_ccs(dtls_context_t *ctx, dtls_peer_t *peer) {
uint8 buf[1] = {1};
return dtls_send(ctx, peer, DTLS_CT_CHANGE_CIPHER_SPEC, buf, 1);
}
-
+
static int
dtls_send_client_key_exchange(dtls_context_t *ctx, dtls_peer_t *peer)
{
dtls_hash_ctx hs_hash;
unsigned char sha256hash[DTLS_HMAC_DIGEST_SIZE];
- /* ServerKeyExchange
+ /* ServerKeyExchange
*
* Start message construction at beginning of buffer. */
p = buf;
dtls_prf(peer->handshake_params->tmp.master_secret,
DTLS_MASTER_SECRET_LENGTH,
label, labellen,
- PRF_LABEL(finished), PRF_LABEL_SIZE(finished),
+ PRF_LABEL(finished), PRF_LABEL_SIZE(finished),
hash, length,
p, DTLS_FIN_LENGTH);
}
static int
-check_server_hello(dtls_context_t *ctx,
+check_server_hello(dtls_context_t *ctx,
dtls_peer_t *peer,
uint8 *data, size_t data_length)
{
* and compression method (like dtls_update_parameters().
* Then calculate master secret and wait for ServerHelloDone. When received,
* send ClientKeyExchange (?) and ChangeCipherSpec + ClientFinished. */
-
+
/* check server version */
data += DTLS_HS_LENGTH;
data_length -= DTLS_HS_LENGTH;
-
+
if (dtls_uint16_to_int(data) != DTLS_VERSION) {
dtls_alert("unknown DTLS version\n");
return dtls_alert_fatal_create(DTLS_ALERT_PROTOCOL_VERSION);
data_length -= DTLS_RANDOM_LENGTH;
SKIP_VAR_FIELD(data, data_length, uint8); /* skip session id */
-
+
/* Check cipher suite. As we offer all we have, it is sufficient
* to check if the cipher suite selected by the server is in our
* list of known cipher suites. Subsets are not supported. */
#ifdef DTLS_ECC
static int
-check_server_certificate(dtls_context_t *ctx,
+check_server_certificate(dtls_context_t *ctx,
dtls_peer_t *peer,
uint8 *data, size_t data_length)
{
#endif /* DTLS_PSK */
static int
-check_certificate_request(dtls_context_t *ctx,
+check_certificate_request(dtls_context_t *ctx,
dtls_peer_t *peer,
uint8 *data, size_t data_length)
{
current_sig_alg = dtls_uint8_to_int(data);
data += sizeof(uint8);
- if (current_hash_alg == TLS_EXT_SIG_HASH_ALGO_SHA256 && hash_alg == 0 &&
+ if (current_hash_alg == TLS_EXT_SIG_HASH_ALGO_SHA256 && hash_alg == 0 &&
current_sig_alg == TLS_EXT_SIG_HASH_ALGO_ECDSA && sig_alg == 0) {
hash_alg = current_hash_alg;
sig_alg = current_sig_alg;
}
static int
-check_server_hellodone(dtls_context_t *ctx,
+check_server_hellodone(dtls_context_t *ctx,
dtls_peer_t *peer,
uint8 *data, size_t data_length)
{
dtls_record_header_t *header = DTLS_RECORD_HEADER(packet);
dtls_security_parameters_t *security = dtls_security_params_epoch(peer, dtls_get_epoch(header));
int clen;
-
+
*cleartext = (uint8 *)packet + sizeof(dtls_record_header_t);
clen = length - sizeof(dtls_record_header_t);
/* no cipher suite selected */
return clen;
} else { /* TLS_PSK_WITH_AES_128_CCM_8 or TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8 */
- /**
+ /**
* length of additional_data for the AEAD cipher which consists of
* seq_num(2+6) + type(1) + version(2) + length(2)
*/
dtls_debug_dump("ciphertext", *cleartext, clen);
/* re-use N to create additional data according to RFC 5246, Section 6.2.3.3:
- *
+ *
* additional_data = seq_num + TLSCompressed.type +
* TLSCompressed.version + TLSCompressed.length;
*/
return err;
}
-
+
static int
handle_handshake(dtls_context_t *ctx, dtls_peer_t *peer, session_t *session,
const dtls_peer_type role, const dtls_state_t state,
}
static int
-handle_ccs(dtls_context_t *ctx, dtls_peer_t *peer,
+handle_ccs(dtls_context_t *ctx, dtls_peer_t *peer,
uint8 *record_header, uint8 *data, size_t data_length)
{
int err;
* updated successfully and a ChangeCipherSpec message was sent
* by ourself, the security context is switched and the record
* sequence number is reset. */
-
+
if (!peer || peer->state != DTLS_STATE_WAIT_CHANGECIPHERSPEC) {
dtls_warn("expected ChangeCipherSpec during handshake\n");
return 0;
return err;
}
}
-
+
peer->state = DTLS_STATE_WAIT_FINISHED;
return 0;
-}
+}
-/**
+/**
* Handles incoming Alert messages. This function returns \c 1 if the
* connection should be closed and the peer is to be invalidated.
*/
static int
-handle_alert(dtls_context_t *ctx, dtls_peer_t *peer,
+handle_alert(dtls_context_t *ctx, dtls_peer_t *peer,
uint8 *record_header, uint8 *data, size_t data_length) {
int free_peer = 0; /* indicates whether to free peer */
*/
if (data[0] == DTLS_ALERT_LEVEL_FATAL || data[1] == DTLS_ALERT_CLOSE_NOTIFY) {
dtls_alert("%d invalidate peer\n", data[1]);
-
+
#ifndef WITH_CONTIKI
HASH_DEL_PEER(ctx->peers, peer);
#else /* WITH_CONTIKI */
}
- (void)CALL(ctx, event, &peer->session,
+ (void)CALL(ctx, event, &peer->session,
(dtls_alert_level_t)data[0], (unsigned short)data[1]);
switch (data[1]) {
case DTLS_ALERT_CLOSE_NOTIFY:
default:
;
}
-
+
if (free_peer) {
dtls_stop_retransmission(ctx, peer);
dtls_destroy_peer(ctx, peer, 0);
return -1;
}
-/**
+/**
* Handles incoming data as DTLS message from given peer.
*/
int
-dtls_handle_message(dtls_context_t *ctx,
+dtls_handle_message(dtls_context_t *ctx,
session_t *session,
uint8 *msg, int msglen) {
dtls_peer_t *peer = NULL;
unsigned int rlen; /* record length */
uint8 *data; /* (decrypted) payload */
- int data_length; /* length of decrypted payload
+ int data_length; /* length of decrypted payload
(without MAC and padding) */
int err;
if (peer) {
uint16_t expected_epoch = dtls_security_params(peer)->epoch;
- uint16_t msg_epoch =
+ uint16_t msg_epoch =
dtls_uint16_to_int(DTLS_RECORD_HEADER(msg)->epoch);
/* The new security parameters must be used for all messages
memset(c, 0, sizeof(dtls_context_t));
c->app = app_data;
-
+
LIST_STRUCT_INIT(c, sendqueue);
#ifdef WITH_CONTIKI
LIST_STRUCT_INIT(c, peers);
/* LIST_STRUCT_INIT(c, key_store); */
-
+
process_start(&dtls_retransmit_process, (char *)c);
PROCESS_CONTEXT_BEGIN(&dtls_retransmit_process);
/* the retransmit timer must be initialized to some large value */
if (dtls_prng(c->cookie_secret, DTLS_COOKIE_SECRET_LENGTH))
c->cookie_secret_age = now;
- else
+ else
goto error;
-
+
return c;
error:
dtls_debug("found peer, try to re-connect\n");
return dtls_renegotiate(ctx, &peer->session);
}
-
+
/* set local peer role to client, remote is server */
peer->role = DTLS_CLIENT;
res = dtls_send_client_hello(ctx, peer, NULL, 0);
if (res < 0)
dtls_warn("cannot send ClientHello\n");
- else
+ else
peer->state = DTLS_STATE_CLIENTHELLO;
return res;
int res;
peer = dtls_get_peer(ctx, dst);
-
+
if (!peer)
peer = dtls_new_peer(dst);
} else if (res == 0) {
CALL(ctx, event, &peer->session, 0, DTLS_EVENT_RENEGOTIATE);
}
-
+
return res;
}
node->retransmit_cnt++;
node->t = now + (node->timeout << node->retransmit_cnt);
netq_insert_node(context->sendqueue, node);
-
+
if (node->type == DTLS_CT_HANDSHAKE) {
dtls_handshake_header_t *hs_header = DTLS_HANDSHAKE_HEADER(data);
} else {
dtls_debug("** retransmit packet\n");
}
-
+
err = dtls_prepare_record(node->peer, security, node->type, &data, &length,
1, sendbuf, &len);
if (err < 0) {
}
/* no more retransmissions, remove node from system */
-
+
dtls_debug("** removed transaction\n");
/* And finally delete the node */
static void
dtls_stop_retransmission(dtls_context_t *context, dtls_peer_t *peer) {
netq_t *node;
- node = list_head(context->sendqueue);
+ node = list_head(context->sendqueue);
while (node) {
if (dtls_session_equals(&node->peer->session, &peer->session)) {
list_remove(context->sendqueue, tmp);
netq_node_free(tmp);
} else
- node = list_item_next(node);
+ node = list_item_next(node);
}
}
PROCESS_YIELD();
if (ev == PROCESS_EVENT_TIMER) {
if (etimer_expired(&the_dtls_context.retransmit_timer)) {
-
+
node = list_head(the_dtls_context.sendqueue);
-
+
now = clock_time();
if (node && node->t <= now) {
dtls_retransmit(&the_dtls_context, list_pop(the_dtls_context.sendqueue));
/* need to set timer to some value even if no nextpdu is available */
if (node) {
- etimer_set(&the_dtls_context.retransmit_timer,
+ etimer_set(&the_dtls_context.retransmit_timer,
node->t <= now ? 1 : node->t - now);
} else {
etimer_set(&the_dtls_context.retransmit_timer, 0xFFFF);
}
- }
+ }
}
}
-
+
PROCESS_END();
}
#endif /* WITH_CONTIKI */
return PACKAGE_VERSION;
}
-log_t
+log_t
dtls_get_log_level() {
return maxlog;
}
/* this array has the same order as the type log_t */
static char *loglevels[] = {
- "EMRG", "ALRT", "CRIT", "WARN", "NOTE", "INFO", "DEBG"
+ "EMRG", "ALRT", "CRIT", "WARN", "NOTE", "INFO", "DEBG"
};
#ifdef HAVE_TIME_H
static inline size_t
print_timestamp(char *s, size_t len, clock_time_t t) {
#ifdef HAVE_SNPRINTF
- return snprintf(s, len, "%u.%03u",
- (unsigned int)(t / CLOCK_SECOND),
+ return snprintf(s, len, "%u.%03u",
+ (unsigned int)(t / CLOCK_SECOND),
(unsigned int)(t % CLOCK_SECOND));
#else /* HAVE_SNPRINTF */
/* @todo do manual conversion of timestamp */
#endif /* HAVE_TIME_H */
-/**
- * A length-safe strlen() fake.
- *
+/**
+ * A length-safe strlen() fake.
+ *
* @param s The string to count characters != 0.
* @param maxlen The maximum length of @p s.
- *
+ *
* @return The length of @p s.
*/
static inline size_t
char *p = buf;
switch (addr->addr.sa.sa_family) {
- case AF_INET:
+ case AF_INET:
if (len < INET_ADDRSTRLEN)
return 0;
-
+
addrptr = &addr->addr.sin.sin_addr;
port = ntohs(addr->addr.sin.sin_port);
break;
if (addr->addr.sa.sa_family == AF_INET6) {
if (p < buf + len) {
*p++ = ']';
- } else
+ } else
return 0;
}
}
#ifndef WITH_CONTIKI
-void
+void
dsrv_log(log_t level, char *format, ...) {
static char timebuf[32];
va_list ap;
if (print_timestamp(timebuf,sizeof(timebuf), time(NULL)))
fprintf(log_fd, "%s ", timebuf);
- if (level <= DTLS_LOG_DEBUG)
+ if (level <= DTLS_LOG_DEBUG)
fprintf(log_fd, "%s ", loglevels[level]);
va_start(ap, format);
fflush(log_fd);
}
#elif defined (HAVE_VPRINTF) /* WITH_CONTIKI */
-void
+void
dsrv_log(log_t level, char *format, ...) {
static char timebuf[32];
va_list ap;
if (print_timestamp(timebuf,sizeof(timebuf), clock_time()))
PRINTF("%s ", timebuf);
- if (level <= DTLS_LOG_DEBUG)
+ if (level <= DTLS_LOG_DEBUG)
PRINTF("%s ", loglevels[level]);
va_start(ap, format);
void hexdump(const unsigned char *packet, int length) {
int n = 0;
- while (length--) {
+ while (length--) {
if (n % 16 == 0)
printf("%08X ",n);
printf("%02X ", *packet++);
-
+
n++;
if (n % 8 == 0) {
if (n % 16 == 0)
/** dump as narrow string of hex digits */
void dump(unsigned char *buf, size_t len) {
- while (len--)
+ while (len--)
printf("%02x", *buf++);
}
}
#ifndef WITH_CONTIKI
-void
+void
dtls_dsrv_hexdump_log(log_t level, const char *name, const unsigned char *buf, size_t length, int extend) {
static char timebuf[32];
FILE *log_fd;
if (print_timestamp(timebuf, sizeof(timebuf), time(NULL)))
fprintf(log_fd, "%s ", timebuf);
- if (level <= DTLS_LOG_DEBUG)
+ if (level <= DTLS_LOG_DEBUG)
fprintf(log_fd, "%s ", loglevels[level]);
if (extend) {
}
} else {
fprintf(log_fd, "%s: (%zu bytes): ", name, length);
- while (length--)
+ while (length--)
fprintf(log_fd, "%02X", *buf++);
}
fprintf(log_fd, "\n");
fflush(log_fd);
}
#else /* WITH_CONTIKI */
-void
+void
dtls_dsrv_hexdump_log(log_t level, const char *name, const unsigned char *buf, size_t length, int extend) {
static char timebuf[32];
int n = 0;
if (print_timestamp(timebuf,sizeof(timebuf), clock_time()))
PRINTF("%s ", timebuf);
- if (level >= 0 && level <= DTLS_LOG_DEBUG)
+ if (level >= 0 && level <= DTLS_LOG_DEBUG)
PRINTF("%s ", loglevels[level]);
if (extend) {
}
} else {
PRINTF("%s: (%zu bytes): ", name, length);
- while (length--)
+ while (length--)
PRINTF("%02X", *buf++);
}
PRINTF("\n");
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;
#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);
#else
#error "clock not implemented"
result[v] = d;
d = d>>32; //save carry
}
-
+
return (uint32_t)d;
}
result[v] = d & 0xFFFFFFFF;
d = d>>32;
d &= 0x1;
- }
+ }
return (uint32_t)d;
}
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};
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;
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);
* 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)
}
static int isOne(const uint32_t* A){
- uint8_t n;
- for(n=1;n<8;n++)
- if (A[n]!=0)
+ uint8_t n;
+ for(n=1;n<8;n++)
+ if (A[n]!=0)
break;
- if ((n==8)&&(A[0]==1))
+ if ((n==8)&&(A[0]==1))
return 1;
- else
+ else
return 0;
}
add(result, reducer, tempas, 8);
copy(tempas, result, arrayLength);
}
-
+
}
return 0;
}
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 */
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 */
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);
}
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
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
//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};
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);
}
static int
-read_from_peer(struct dtls_context_t *ctx,
+read_from_peer(struct dtls_context_t *ctx,
session_t *session, uint8 *data, size_t len) {
size_t i;
for (i = 0; i < len; i++)
}
static int
-send_to_peer(struct dtls_context_t *ctx,
+send_to_peer(struct dtls_context_t *ctx,
session_t *session, uint8 *data, size_t len) {
struct uip_udp_conn *conn = (struct uip_udp_conn *)dtls_get_app_data(ctx);
if (buflen) {
if (!connected)
connected = dtls_connect(dtls_context, &dst) >= 0;
-
+
try_send(dtls_context, &dst);
}
}
-
+
PROCESS_END();
}
/*---------------------------------------------------------------------------*/
0x17, 0xDE, 0x43, 0xF9, 0xF9, 0xAD, 0xEE, 0x70};
static int
-read_from_peer(struct dtls_context_t *ctx,
+read_from_peer(struct dtls_context_t *ctx,
session_t *session, uint8 *data, size_t len) {
size_t i;
for (i = 0; i < len; i++)
}
static int
-send_to_peer(struct dtls_context_t *ctx,
+send_to_peer(struct dtls_context_t *ctx,
session_t *session, uint8 *data, size_t len) {
struct uip_udp_conn *conn = (struct uip_udp_conn *)dtls_get_app_data(ctx);
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());
}
}
if(root_if != NULL) {
rpl_dag_t *dag;
uip_ipaddr_t prefix;
-
+
rpl_set_root(RPL_DEFAULT_INSTANCE, ipaddr);
dag = rpl_get_any_dag();
uip_ip6addr(&prefix, 0xaaaa, 0, 0, 0, 0, 0, 0, 0);
}
#ifdef ENABLE_POWERTRACE
- powertrace_start(CLOCK_SECOND * 2);
+ powertrace_start(CLOCK_SECOND * 2);
#endif
while(1) {
dtls_hmac_context_t *ctx;
ctx = dtls_hmac_context_new();
- if (ctx)
+ if (ctx)
dtls_hmac_init(ctx, key, klen);
return ctx;
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);
ctx = dtls_hmac_new(argv[1], strlen(argv[1]));
assert(ctx);
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");
}
#endif /* WITH_CONTIKI */
-int
+int
netq_insert_node(list_t queue, netq_t *node) {
netq_t *p;
if (node)
memset(node, 0, sizeof(netq_t));
- return node;
+ return node;
}
-void
+void
netq_node_free(netq_t *node) {
if (node)
netq_free_node(node);
}
-void
+void
netq_delete_all(list_t queue) {
netq_t *p;
if (queue) {
while((p = list_pop(queue)))
- netq_free_node(p);
+ netq_free_node(p);
}
}
#else /* WITH_CONTIKI */
-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 */
;
/*
* FILE: sha2.c
* AUTHOR: Aaron D. Gifford - http://www.aarongifford.com/
- *
+ *
* Copyright (c) 2000-2001, Aaron D. Gifford
* All rights reserved.
*
* 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
*
* And for little-endian machines, add:
*
- * #define BYTE_ORDER LITTLE_ENDIAN
+ * #define BYTE_ORDER LITTLE_ENDIAN
*
* Or for big-endian machines:
*
/* Part of the message block expansion: */
s0 = W256[(j+1)&0x0f];
s0 = sigma0_256(s0);
- s1 = W256[(j+14)&0x0f];
+ s1 = W256[(j+14)&0x0f];
s1 = sigma1_256(s1);
/* Apply the SHA-256 compression function to update a..h */
- T1 = h + Sigma1_256(e) + Ch(e, f, g) + K256[j] +
+ T1 = h + Sigma1_256(e) + Ch(e, f, g) + K256[j] +
(W256[j&0x0f] += s1 + W256[(j+9)&0x0f] + s0);
T2 = Sigma0_256(a) + Maj(a, b, c);
h = g;
/*
* FILE: sha2prog.c
* AUTHOR: Aaron D. Gifford - http://www.aarongifford.com/
- *
+ *
* Copyright (c) 2000-2001, Aaron D. Gifford
* All rights reserved.
*
* 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
/*
* FILE: sha2speed.c
* AUTHOR: Aaron D. Gifford - http://www.aarongifford.com/
- *
+ *
* Copyright (c) 2000-2001, Aaron D. Gifford
* All rights reserved.
*
* 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
SHA256_Init(&c256);
SHA384_Init(&c384);
SHA512_Init(&c512);
-
+
gettimeofday(&start, (struct timezone*)0);
for (j = 0; j < blocks; j++) {
SHA256_Update(&c256, (unsigned char*)buf, BUFSIZE);
}
#endif
-void
+void
dump(unsigned char *buf, size_t len) {
size_t i = 0;
while (i < len) {
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 #%d ", n+1);
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 = %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 #%d: cannot decrypt message\n", n+1);
- else
+ else
printf("\t*** MAC verified (total length = %lu) ***\n", len + data[n].la);
}
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 */
/* #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 */
{ }, /* 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 */
},
/* #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,
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,
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,
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,
{ 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,
-#include "tinydtls.h"
+#include "tinydtls.h"
/* This is needed for apple */
#define __APPLE_USE_RFC_3542
#include <netdb.h>
#include <signal.h>
-#include "global.h"
-#include "debug.h"
-#include "dtls.h"
+#include "global.h"
+#include "debug.h"
+#include "dtls.h"
#define DEFAULT_PORT 20220
}
static int
-read_from_peer(struct dtls_context_t *ctx,
+read_from_peer(struct dtls_context_t *ctx,
session_t *session, uint8 *data, size_t len) {
size_t i;
for (i = 0; i < len; i++)
}
static int
-send_to_peer(struct dtls_context_t *ctx,
+send_to_peer(struct dtls_context_t *ctx,
session_t *session, uint8 *data, size_t len) {
int fd = *(int *)dtls_get_app_data(ctx);
int len;
fd = *(int *)dtls_get_app_data(ctx);
-
+
if (!fd)
return -1;
memset(&session, 0, sizeof(session_t));
session.size = sizeof(session.addr);
- len = recvfrom(fd, buf, MAX_READ_BUF, 0,
+ len = recvfrom(fd, buf, MAX_READ_BUF, 0,
&session.addr.sa, &session.size);
-
+
if (len < 0) {
perror("recvfrom");
return -1;
}
return dtls_handle_message(ctx, &session, buf, len);
-}
+}
static void dtls_handle_signal(int sig)
{
/* stolen from libcoap: */
static int
resolve_address(const char *server, struct sockaddr *dst) {
-
+
struct addrinfo *res, *ainfo;
struct addrinfo hints;
static char addrstr[256];
#define DTLS_CLIENT_CMD_CLOSE "client:close"
#define DTLS_CLIENT_CMD_RENEGOTIATE "client:renegotiate"
-int
+int
main(int argc, char **argv) {
fd_set rfds, wfds;
struct timeval timeout;
case 'o' :
output_file.length = strlen(optarg);
output_file.s = (unsigned char *)malloc(output_file.length + 1);
-
+
if (!output_file.s) {
dtls_crit("cannot set output file: insufficient memory\n");
exit(-1);
}
dtls_set_log_level(log_level);
-
+
if (argc <= optind) {
usage(argv[0], dtls_package_version());
exit(1);
}
-
+
memset(&dst, 0, sizeof(session_t));
/* resolve destination address where server should be sent */
res = resolve_address(argv[optind++], &dst.addr.sa);
port, otherwise */
dst.addr.sin.sin_port = htons(atoi(optind < argc ? argv[optind++] : port_str));
-
+
/* init socket and set it to non-blocking */
fd = socket(dst.addr.sa.sa_family, SOCK_DGRAM, 0);
FD_SET(fileno(stdin), &rfds);
FD_SET(fd, &rfds);
/* FD_SET(fd, &wfds); */
-
+
timeout.tv_sec = 5;
timeout.tv_usec = 0;
-
+
result = select(fd+1, &rfds, &wfds, 0, &timeout);
-
+
if (result < 0) { /* error */
if (errno != EINTR)
perror("select");
}
}
}
-
+
dtls_free_context(dtls_context);
exit(0);
}
#include <netdb.h>
#include <signal.h>
-#include "tinydtls.h"
-#include "dtls.h"
-#include "debug.h"
+#include "tinydtls.h"
+#include "dtls.h"
+#include "debug.h"
#define DEFAULT_PORT 20220
#define DTLS_SERVER_CMD_RENEGOTIATE "server:renegotiate"
static int
-read_from_peer(struct dtls_context_t *ctx,
+read_from_peer(struct dtls_context_t *ctx,
session_t *session, uint8 *data, size_t len) {
size_t i;
for (i = 0; i < len; i++)
}
static int
-send_to_peer(struct dtls_context_t *ctx,
+send_to_peer(struct dtls_context_t *ctx,
session_t *session, uint8 *data, size_t len) {
int fd = *(int *)dtls_get_app_data(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 (sizeof(buf) < len) {
dtls_warn("packet was truncated (%d bytes lost)\n", len - sizeof(buf));
}
return dtls_handle_message(ctx, &session, buf, len);
-}
+}
static int
resolve_address(const char *server, struct sockaddr *dst) {
-
+
struct addrinfo *res, *ainfo;
struct addrinfo hints;
static char addrstr[256];
#endif /* DTLS_ECC */
};
-int
+int
main(int argc, char **argv) {
dtls_context_t *the_context = NULL;
log_t log_level = DTLS_LOG_WARN;
FD_SET(fd, &rfds);
/* FD_SET(fd, &wfds); */
-
+
timeout.tv_sec = 5;
timeout.tv_usec = 0;
-
+
result = select( fd+1, &rfds, &wfds, 0, &timeout);
-
+
if (result < 0) { /* error */
if (errno != EINTR)
perror("select");
}
}
}
-
+
error:
dtls_free_context(the_context);
exit(0);
#include "global.h"
#include "crypto.h"
-int
+int
main() {
/* see http://www.ietf.org/mail-archive/web/tls/current/msg03416.html */
- unsigned char key[] = { 0x9b, 0xbe, 0x43, 0x6b, 0xa9, 0x40, 0xf0, 0x17,
+ unsigned char key[] = { 0x9b, 0xbe, 0x43, 0x6b, 0xa9, 0x40, 0xf0, 0x17,
0xb1, 0x76, 0x52, 0x84, 0x9a, 0x71, 0xdb, 0x35 };
- unsigned char label[] = { 0x74, 0x65, 0x73, 0x74, 0x20, 0x6c, 0x61, 0x62,
+ unsigned char label[] = { 0x74, 0x65, 0x73, 0x74, 0x20, 0x6c, 0x61, 0x62,
0x65, 0x6c};
unsigned char random1[] = { 0xa0, 0xba, 0x9f, 0x93, 0x6c, 0xda, 0x31, 0x18};
unsigned char random2[] = {0x27, 0xa6, 0xf7, 0x96, 0xff, 0xd5, 0x19, 0x8c
};
unsigned char buf[200];
size_t result;
-
+
result = dtls_prf(key, sizeof(key),
label, sizeof(label),
random1, sizeof(random1),
sdbg("Returning EDEADLK\n");
ret = EDEADLK;
}
- } else
+ } else
#endif /* CONFIG_PTHREAD_MUTEX_TYPES */
#endif /* CONFIG_PTHREAD_MUTEX_TYPES */
#else /* CONFIG_PTHREAD_MUTEX_ROBUST */
/* This mutex is always robust, whatever type it is. */
- if (mutex->pid > 0 && sched_gettcb(mutex->pid) == NULL)
+ if (mutex->pid > 0 && sched_gettcb(mutex->pid) == NULL)
#endif
{
DEBUGASSERT(mutex->pid != 0); /* < 0: available, >0 owned, ==0 error */
mutex->flags |= _PTHREAD_MFLAGS_INCONSISTENT;
ret = EOWNERDEAD;
- } else
+ } else
#endif /* !CONFIG_PTHREAD_MUTEX_UNSAFE */
{
#endif /* CONFIG_PTHREAD_MUTEX_TYPES */
#else /* CONFIG_PTHREAD_MUTEX_ROBUST */
/* This mutex is always robust, whatever type it is. */
- if (mutex->pid > 0 && sched_gettcb(mutex->pid) == NULL)
+ if (mutex->pid > 0 && sched_gettcb(mutex->pid) == NULL)
#endif
{
DEBUGASSERT(mutex->pid != 0); /* < 0: available, >0 owned, ==0 error */
/* The mutex is locked by another, active thread */
- else
+ else
#endif /* CONFIG_PTHREAD_MUTEX_UNSAFE */
{
ret = EBUSY;
}
}
-
+
/* Some other, unhandled error occurred */
else {
ret = status;
DEBUGASSERT(g_wdnfree <= CONFIG_PREALLOC_WDOGS);
irqrestore(state);
} else {
- /* There is no guarantee that, this API is not called for statically
+ /* There is no guarantee that, this API is not called for statically
* allocated timers as wd_delete is a global function. So restore the
* irq properly so that it does not break the system */
*olen = 6;
}
-#endif /* MBEDTLS_ECDH_C || MBEDTLS_ECDSA_C ||
+#endif /* MBEDTLS_ECDH_C || MBEDTLS_ECDSA_C ||
MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED */
#if defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED)
MBEDTLS_SSL_DEBUG_MSG(1, ("no point format in common"));
return (MBEDTLS_ERR_SSL_BAD_HS_SERVER_HELLO);
}
-#endif /* MBEDTLS_ECDH_C || MBEDTLS_ECDSA_C ||
+#endif /* MBEDTLS_ECDH_C || MBEDTLS_ECDSA_C ||
MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED */
#if defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED)