1 /* dtls -- a very basic DTLS implementation
3 * Copyright (C) 2011--2014 Olaf Bergmann <bergmann@tzi.org>
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:
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
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
26 #ifndef _DTLS_GLOBAL_H_
27 #define _DTLS_GLOBAL_H_
30 #include <sys/types.h>
35 /* The current version of tinyDTLS supports DTLSv1.2 only. */
40 /* The current version of tinyDTLS supports DTLSv1.2 with SHA256 PRF
45 /* Define our own types as at least uint32_t does not work on my amd64. */
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];
54 /** Maximum size of DTLS message.
55 When Peers are sending bigger messages this causes problems. Californium
56 with ECDSA needs at least 220 */
58 #if defined(DTLS_ECC) || defined(DTLS_X509)
59 #define DTLS_MAX_BUF 200
61 #define DTLS_MAX_BUF 100
63 #else /* WITH_CONTIKI */
64 #define DTLS_MAX_BUF 1400
65 #endif /* WITH_CONTIKI */
68 #ifndef DTLS_DEFAULT_MAX_RETRANSMIT
69 /** Number of message retransmissions. */
70 #define DTLS_DEFAULT_MAX_RETRANSMIT 7
73 /** Known cipher suites.*/
75 TLS_NULL_WITH_NULL_NULL = 0x0000, /**< NULL cipher */
76 TLS_ECDH_anon_WITH_AES_128_CBC_SHA_256 = 0xC018, /**< see RFC 4492 */
77 TLS_PSK_WITH_AES_128_CCM_8 = 0xC0A8, /**< see RFC 6655 */
78 TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA_256 = 0xC037, /**< see RFC 5489 */
79 TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8 = 0xC0AE /**< see RFC 7251 */
83 DTLS_CIPHER_DISABLE = 0,
84 DTLS_CIPHER_ENABLE = 1
85 } dtls_cipher_enable_t;
87 /** Known compression suites.*/
89 TLS_COMPRESSION_NULL = 0x0000 /* NULL compression */
92 #define TLS_EXT_ELLIPTIC_CURVES 10 /* see RFC 4492 */
93 #define TLS_EXT_EC_POINT_FORMATS 11 /* see RFC 4492 */
94 #define TLS_EXT_SIG_HASH_ALGO 13 /* see RFC 5246 */
95 #define TLS_EXT_CLIENT_CERTIFICATE_TYPE 19 /* see RFC 7250 */
96 #define TLS_EXT_SERVER_CERTIFICATE_TYPE 20 /* see RFC 7250 */
97 #define TLS_EXT_ENCRYPT_THEN_MAC 22 /* see RFC 7366 */
99 /* see http://www.iana.org/assignments/tls-extensiontype-values/tls-extensiontype-values.xhtml#tls-extensiontype-values-3 */
100 #define TLS_CERT_TYPE_X509 0 /* see RFC 6091 */
101 #define TLS_CERT_TYPE_RAW_PUBLIC_KEY 2 /* see RFC 7250 */
104 #define TLS_EXT_ELLIPTIC_CURVES_SECP256R1 23 /* see RFC 4492 */
106 #define TLS_EXT_EC_POINT_FORMATS_UNCOMPRESSED 0 /* see RFC 4492 */
108 #define TLS_EC_CURVE_TYPE_NAMED_CURVE 3 /* see RFC 4492 */
110 #define TLS_CLIENT_CERTIFICATE_TYPE_ECDSA_SIGN 64 /* see RFC 4492 */
112 #define TLS_EXT_SIG_HASH_ALGO_SHA256 4 /* see RFC 5246 */
113 #define TLS_EXT_SIG_HASH_ALGO_ECDSA 3 /* see RFC 5246 */
116 * XORs \p n bytes byte-by-byte starting at \p y to the memory area
117 * starting at \p x. */
119 memxor(unsigned char *x, const unsigned char *y, size_t n) {
127 * Compares \p len bytes from @p a with @p b in constant time. This
128 * functions always traverses the entire length to prevent timing
131 * \param a Byte sequence to compare
132 * \param b Byte sequence to compare
133 * \param len Number of bytes to compare.
134 * \return \c 1 if \p a and \p b are equal, \c 0 otherwise.
137 equals(unsigned char *a, unsigned char *b, size_t len) {
140 result &= (*a++ == *b++);
146 #define dtls_fls(i) fls(i)
149 dtls_fls(unsigned int i) {
155 #endif /* HAVE_FLS */
157 #endif /* _DTLS_GLOBAL_H_ */