2 * Copyright (C) 2010 Martin Willi
3 * Copyright (C) 2010 revosec AG
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 * @defgroup tls_crypto tls_crypto
24 typedef struct tls_crypto_t tls_crypto_t
;
29 #include <credentials/keys/private_key.h>
32 * TLS crypto helper functions.
37 * Get a list of supported TLS cipher suites.
39 * @param suites list of suites, points to internal data
40 * @return number of suites returned
42 int (*get_cipher_suites
)(tls_crypto_t
*this, tls_cipher_suite_t
**suites
);
45 * Select and store a cipher suite from a given list of candidates.
47 * @param suites list of candidates to select from
48 * @param count number of suites
49 * @return selected suite, 0 if none acceptable
51 tls_cipher_suite_t (*select_cipher_suite
)(tls_crypto_t
*this,
52 tls_cipher_suite_t
*suites
, int count
);
55 * Store exchanged handshake data, used for cryptographic operations.
57 * @param type handshake sub type
58 * @param data data to append to handshake buffer
60 void (*append_handshake
)(tls_crypto_t
*this,
61 tls_handshake_type_t type
, chunk_t data
);
64 * Create a signature of the handshake data using a given private key.
66 * @param key private key to use for signature
67 * @param sig allocated signature
68 * @return TRUE if signature create successfully
70 bool (*sign_handshake
)(tls_crypto_t
*this, private_key_t
*key
, chunk_t
*sig
);
73 * Calculate the data of a TLS finished message.
75 * @param label ASCII label to use for calculation
76 * @param out buffer to write finished data to
77 * @return TRUE if calculation successful
79 bool (*calculate_finished
)(tls_crypto_t
*this, char *label
, char out
[12]);
82 * Derive the master secret, MAC and encryption keys.
84 * @param premaster premaster secret
85 * @param client_random random data from client hello
86 * @param server_random random data from server hello
88 void (*derive_secrets
)(tls_crypto_t
*this, chunk_t premaster
,
89 chunk_t client_random
, chunk_t server_random
);
92 * Change the cipher used at protection layer.
94 * @param inbound TRUE to change inbound cipher, FALSE for outbound
96 void (*change_cipher
)(tls_crypto_t
*this, bool inbound
);
99 * Derive the EAP-TLS MSK.
101 * @param client_random random data from client hello
102 * @param server_random random data from server hello
104 void (*derive_eap_msk
)(tls_crypto_t
*this,
105 chunk_t client_random
, chunk_t server_random
);
108 * Get the MSK to use in EAP-TLS.
110 * @return MSK, points to internal data
112 chunk_t (*get_eap_msk
)(tls_crypto_t
*this);
115 * Destroy a tls_crypto_t.
117 void (*destroy
)(tls_crypto_t
*this);
121 * Create a tls_crypto instance.
123 tls_crypto_t
*tls_crypto_create(tls_t
*tls
);
125 #endif /** TLS_CRYPTO_H_ @}*/