tinydtls  0.8.1
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
global.h
Go to the documentation of this file.
1 /* dtls -- a very basic DTLS implementation
2  *
3  * Copyright (C) 2011--2014 Olaf Bergmann <bergmann@tzi.org>
4  *
5  * Permission is hereby granted, free of charge, to any person
6  * obtaining a copy of this software and associated documentation
7  * files (the "Software"), to deal in the Software without
8  * restriction, including without limitation the rights to use, copy,
9  * modify, merge, publish, distribute, sublicense, and/or sell copies
10  * of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23  * SOFTWARE.
24  */
25 
26 #ifndef _DTLS_GLOBAL_H_
27 #define _DTLS_GLOBAL_H_
28 
29 #include <stdlib.h>
30 #include <sys/types.h>
31 
32 #include "tinydtls.h"
33 
34 #ifndef DTLSv12
35 /* The current version of tinyDTLS supports DTLSv1.2 only. */
36 #define DTLSv12 1
37 #endif
38 
39 #ifndef WITH_SHA256
40 /* The current version of tinyDTLS supports DTLSv1.2 with SHA256 PRF
41  only. */
42 #define WITH_SHA256 1
43 #endif
44 
45 /* Define our own types as at least uint32_t does not work on my amd64. */
46 
47 typedef unsigned char uint8;
48 typedef unsigned char uint16[2];
49 typedef unsigned char uint24[3];
50 typedef unsigned char uint32[4];
51 typedef unsigned char uint48[6];
52 
53 #ifndef DTLS_MAX_BUF
54 
57 #ifdef WITH_CONTIKI
58 #ifdef DTLS_ECC
59 #define DTLS_MAX_BUF 200
60 #else /* DTLS_ECC */
61 #define DTLS_MAX_BUF 100
62 #endif /* DTLS_ECC */
63 #else /* WITH_CONTIKI */
64 #define DTLS_MAX_BUF 1400
65 #endif /* WITH_CONTIKI */
66 #endif
67 
68 #ifndef DTLS_DEFAULT_MAX_RETRANSMIT
69 
70 #define DTLS_DEFAULT_MAX_RETRANSMIT 7
71 #endif
72 
74 typedef enum {
79 
81 typedef enum {
82  TLS_COMPRESSION_NULL = 0x0000 /* NULL compression */
84 
85 #define TLS_EXT_ELLIPTIC_CURVES 10 /* see RFC 4492 */
86 #define TLS_EXT_EC_POINT_FORMATS 11 /* see RFC 4492 */
87 #define TLS_EXT_SIG_HASH_ALGO 13 /* see RFC 5246 */
88 #define TLS_EXT_CLIENT_CERTIFICATE_TYPE 19 /* see RFC 7250 */
89 #define TLS_EXT_SERVER_CERTIFICATE_TYPE 20 /* see RFC 7250 */
90 #define TLS_EXT_ENCRYPT_THEN_MAC 22 /* see RFC 7366 */
91 
92 #define TLS_CERT_TYPE_RAW_PUBLIC_KEY 2 /* see RFC 7250 */
93 
94 #define TLS_EXT_ELLIPTIC_CURVES_SECP256R1 23 /* see RFC 4492 */
95 
96 #define TLS_EXT_EC_POINT_FORMATS_UNCOMPRESSED 0 /* see RFC 4492 */
97 
98 #define TLS_EC_CURVE_TYPE_NAMED_CURVE 3 /* see RFC 4492 */
99 
100 #define TLS_CLIENT_CERTIFICATE_TYPE_ECDSA_SIGN 64 /* see RFC 4492 */
101 
102 #define TLS_EXT_SIG_HASH_ALGO_SHA256 4 /* see RFC 5246 */
103 #define TLS_EXT_SIG_HASH_ALGO_ECDSA 3 /* see RFC 5246 */
104 
108 static inline void
109 memxor(unsigned char *x, const unsigned char *y, size_t n) {
110  while(n--) {
111  *x ^= *y;
112  x++; y++;
113  }
114 }
115 
126 static inline int
127 equals(unsigned char *a, unsigned char *b, size_t len) {
128  int result = 1;
129  while (len--) {
130  result &= (*a++ == *b++);
131  }
132  return result;
133 }
134 
135 #ifdef HAVE_FLS
136 #define dtls_fls(i) fls(i)
137 #else
138 static inline int
139 dtls_fls(unsigned int i) {
140  int n;
141  for (n = 0; i; n++)
142  i >>= 1;
143  return n;
144 }
145 #endif /* HAVE_FLS */
146 
147 #endif /* _DTLS_GLOBAL_H_ */
public tinydtls API
dtls_compression_t
Definition: global.h:81
static void memxor(unsigned char *x, const unsigned char *y, size_t n)
Definition: global.h:109
unsigned char uint48[6]
Definition: global.h:51
unsigned char uint24[3]
Definition: global.h:49
unsigned char uint8
Definition: global.h:47
dtls_cipher_t
Definition: global.h:74
static int equals(unsigned char *a, unsigned char *b, size_t len)
Definition: global.h:127
unsigned char uint32[4]
Definition: global.h:50
static int dtls_fls(unsigned int i)
Definition: global.h:139
unsigned char uint16[2]
Definition: global.h:48