tinydtls: correct server random format

The ServerHello message uses the normal Random accordingly to RFC5246,
7.4.1.3. Server Hello. This Random attribute consist of 4 bytes Unix
time stamp followed by 28 bytes of random data, see RFC5246, 7.4.1.2.
Client Hello.

Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
tinydtls: do not generate random which is replaced by timestamp

The first 4 bytes of this are overwrite with the timestamp.

Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
tinydtls: add new function to send the ClientHello

Instead of having the code for sending the ClientHello without cookie
in dtls_connect() and with a cookie in check_server_hello() use one
function dtls_send_client_hello(), which can handle both cases and is
called by the other functions.

Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
tinydtls: call dtls_init() also for the test server

This call was missing, but it worked somehow with the current code.

Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
tinydtls: use Message Sequence number == 0 is first Client Hello again

The message Sequence number should be set to 0 in the first Client Hello send to the server.

This fixes a regression introduced in:
commit 9a166b6d9372b20684f38f46b470bde39fcb0541
Author: Hauke Mehrtens <hauke@hauke-m.de>
Date:   Sun Mar 31 14:51:11 2013 +0200

    tinydtls: add new function to send the ClientHello

Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
tinydtls: add .gitignore file

Ignore the files generated by the build process.

Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
crypto: rename dtls_pre_master_secret() to dtls_psk_pre_master_secret()

This function is only needed for generating the pre master secret when
using a PSK cipher suite.

Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
dtls: rework getting the psk key

This patch reworks some parts affecting the psk key in preparation for
using other cipher methods like ECDH_ECDSA based ones. The get_key
callback was renamed to get_psk_key to only be used for fetching the
psk. dtls_key_t was also renamed to dtls_psk_key_t and only contains
information for the psk and no type any more. A client should indicate
the supported types by providing the needed callbacks. Other ciphers do
need different informations and also different callbacks.

The handling in the dtls code was changed to not check what key was
configured but which key exchange algorithm was chosen, this should
make it possible to support different authentication protocols with one
server or client instance.

Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
dtls: only advertise PSK cipher if supported

Only advertise and support the PSK cipher if the corresponding callback
was implemented and fail otherwise.

Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
ecc: add new ECC library

Adding a new ECC library which will be used to implement
TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8. This library was developed in the
GOBI project: http://gobi.tzi.de and extended by me for ECDSA support.

Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
dtls: add interface to provide EC public keys

Add new callback functions get_ecdsa_key and verify_ecdsa_key to fetch
the own private and public EC key and to verify the public key of the
remote peer.

Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
dtls: add tls extensions needed for OOB with ECDSA

This ads some TLS extensions to the Client Hello needed for Raw public
keys and ECDAE_ECDSA. The creating and the parsing of client hello was
extended.

Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
dtls: add server tls extensions needed for OOB with ECDSA

When ECDH_ECDSA is used we only support OOB and secp256r1 curve,
indicate this in the server hello.

Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
dtls: extract init_cipher into own function

This code was copied for client and server, now it used put into an own
function. This function is now called later directly before the
ChangeCipherSpec message is send.

Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
dtls: calculate the key block later

For other key exchange methods we have to wait before we received the
key exchange till we are able to calculate the key block. Do the
calculate key block only after we received the other key exchange and
send our own. Now the key block is calculated right before sending
the change cipher spec.

Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
dtls: split dtls_send_server_hello() into more functions

This should not change anything to to behavior, this just splits the
dtls_send_server_hello() function into different functions for each
packet.

Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
dtls: add server certificate and server key exchange

This makes the server send the certificate and the server key exchange
when ECDSA cipher is used.

Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
dtls: parse server certificate and key exchange

This makes the dtls client handle the server certificate and the server
key exchange.

Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
dtls: send ecdh client key exchange

Add sending the client key exchange when ECDHE_ECDSA is used.

Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
dtls: increase buffer size for ecdsa

The server Hello, Certificate and server key exchange flight is needs
more space.

Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>