tinydtls  0.8.6
global.h
Go to the documentation of this file.
1 /*******************************************************************************
2  *
3  * Copyright (c) 2011, 2012, 2013, 2014, 2015 Olaf Bergmann (TZI) and others.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * and Eclipse Distribution License v. 1.0 which accompanies this distribution.
7  *
8  * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
9  * and the Eclipse Distribution License is available at
10  * http://www.eclipse.org/org/documents/edl-v10.php.
11  *
12  * Contributors:
13  * Olaf Bergmann - initial API and implementation
14  * Hauke Mehrtens - memory optimization, ECC integration
15  *
16  *******************************************************************************/
17 
18 #ifndef _DTLS_GLOBAL_H_
19 #define _DTLS_GLOBAL_H_
20 
21 #include <stdlib.h>
22 #include <sys/types.h>
23 
24 #include "tinydtls.h"
25 
26 #ifndef DTLSv12
27 /* The current version of tinyDTLS supports DTLSv1.2 only. */
28 #define DTLSv12 1
29 #endif
30 
31 #ifndef WITH_SHA256
32 /* The current version of tinyDTLS supports DTLSv1.2 with SHA256 PRF
33  only. */
34 #define WITH_SHA256 1
35 #endif
36 
37 /* Define our own types as at least uint32_t does not work on my amd64. */
38 
39 typedef unsigned char uint8;
40 typedef unsigned char uint16[2];
41 typedef unsigned char uint24[3];
42 typedef unsigned char uint32[4];
43 typedef unsigned char uint48[6];
44 
45 #ifndef DTLS_MAX_BUF
46 
49 #ifdef WITH_CONTIKI
50 #ifdef DTLS_ECC
51 #define DTLS_MAX_BUF 200
52 #else /* DTLS_ECC */
53 #define DTLS_MAX_BUF 100
54 #endif /* DTLS_ECC */
55 #else /* WITH_CONTIKI */
56 #define DTLS_MAX_BUF 1400
57 #endif /* WITH_CONTIKI */
58 #endif
59 
60 #ifndef DTLS_DEFAULT_MAX_RETRANSMIT
61 
62 #define DTLS_DEFAULT_MAX_RETRANSMIT 7
63 #endif
64 
66 typedef enum {
71 
73 typedef enum {
74  TLS_COMPRESSION_NULL = 0x0000 /* NULL compression */
76 
77 #define TLS_EXT_ELLIPTIC_CURVES 10 /* see RFC 4492 */
78 #define TLS_EXT_EC_POINT_FORMATS 11 /* see RFC 4492 */
79 #define TLS_EXT_SIG_HASH_ALGO 13 /* see RFC 5246 */
80 #define TLS_EXT_CLIENT_CERTIFICATE_TYPE 19 /* see RFC 7250 */
81 #define TLS_EXT_SERVER_CERTIFICATE_TYPE 20 /* see RFC 7250 */
82 #define TLS_EXT_ENCRYPT_THEN_MAC 22 /* see RFC 7366 */
83 
84 #define TLS_CERT_TYPE_RAW_PUBLIC_KEY 2 /* see RFC 7250 */
85 
86 #define TLS_EXT_ELLIPTIC_CURVES_SECP256R1 23 /* see RFC 4492 */
87 
88 #define TLS_EXT_EC_POINT_FORMATS_UNCOMPRESSED 0 /* see RFC 4492 */
89 
90 #define TLS_EC_CURVE_TYPE_NAMED_CURVE 3 /* see RFC 4492 */
91 
92 #define TLS_CLIENT_CERTIFICATE_TYPE_ECDSA_SIGN 64 /* see RFC 4492 */
93 
94 #define TLS_EXT_SIG_HASH_ALGO_SHA256 4 /* see RFC 5246 */
95 #define TLS_EXT_SIG_HASH_ALGO_ECDSA 3 /* see RFC 5246 */
96 
100 static inline void
101 memxor(unsigned char *x, const unsigned char *y, size_t n) {
102  while(n--) {
103  *x ^= *y;
104  x++; y++;
105  }
106 }
107 
118 static inline int
119 equals(unsigned char *a, unsigned char *b, size_t len) {
120  int result = 1;
121  while (len--) {
122  result &= (*a++ == *b++);
123  }
124  return result;
125 }
126 
127 #ifdef HAVE_FLS
128 #define dtls_fls(i) fls(i)
129 #else
130 static inline int
131 dtls_fls(unsigned int i) {
132  int n;
133  for (n = 0; i; n++)
134  i >>= 1;
135  return n;
136 }
137 #endif /* HAVE_FLS */
138 
139 #undef uthash_fatal
140 #define uthash_fatal(msg) return(-1) /* fatal error in uthash */
141 
142 #endif /* _DTLS_GLOBAL_H_ */
public tinydtls API
dtls_compression_t
Definition: global.h:73
static void memxor(unsigned char *x, const unsigned char *y, size_t n)
Definition: global.h:101
unsigned char uint48[6]
Definition: global.h:43
unsigned char uint24[3]
Definition: global.h:41
unsigned char uint8
Definition: global.h:39
dtls_cipher_t
Definition: global.h:66
static int equals(unsigned char *a, unsigned char *b, size_t len)
Definition: global.h:119
unsigned char uint32[4]
Definition: global.h:42
static int dtls_fls(unsigned int i)
Definition: global.h:131
unsigned char uint16[2]
Definition: global.h:40