Simplify and fix ec_GFp_simple_points_make_affine
[oweals/openssl.git] / ssl / ssl_locl.h
index 54b34d48ac01b306a8c38834107d322aee2bf133..d4b642c5aafb6d59ba2595885def1e1628bd4927 100644 (file)
 #include "e_os.h"
 
 #include <openssl/buffer.h>
+#ifndef OPENSSL_NO_COMP
 #include <openssl/comp.h>
+#endif
 #include <openssl/bio.h>
 #include <openssl/stack.h>
+#ifndef OPENSSL_NO_RSA
 #include <openssl/rsa.h>
+#endif
+#ifndef OPENSSL_NO_DSA
 #include <openssl/dsa.h>
+#endif
 #include <openssl/err.h>
 #include <openssl/ssl.h>
 #include <openssl/symhacks.h>
                         *((c)++)=(unsigned char)(((l)>> 8)&0xff), \
                         *((c)++)=(unsigned char)(((l)    )&0xff))
 
+#define l2n8(l,c)      (*((c)++)=(unsigned char)(((l)>>56)&0xff), \
+                        *((c)++)=(unsigned char)(((l)>>48)&0xff), \
+                        *((c)++)=(unsigned char)(((l)>>40)&0xff), \
+                        *((c)++)=(unsigned char)(((l)>>32)&0xff), \
+                        *((c)++)=(unsigned char)(((l)>>24)&0xff), \
+                        *((c)++)=(unsigned char)(((l)>>16)&0xff), \
+                        *((c)++)=(unsigned char)(((l)>> 8)&0xff), \
+                        *((c)++)=(unsigned char)(((l)    )&0xff))
+
 #define n2l6(c,l)      (l =((BN_ULLONG)(*((c)++)))<<40, \
                         l|=((BN_ULLONG)(*((c)++)))<<32, \
                         l|=((BN_ULLONG)(*((c)++)))<<24, \
 #define SSL_FZA                        (SSL_aFZA|SSL_kFZA|SSL_eFZA)
 #define SSL_KRB5                (SSL_kKRB5|SSL_aKRB5)
 
-#define SSL_ENC_MASK           0x043F8000L
+#define SSL_ENC_MASK           0x1C3F8000L
 #define SSL_DES                        0x00008000L
 #define SSL_3DES               0x00010000L
 #define SSL_RC4                        0x00020000L
 #define SSL_eFZA               0x00100000L
 #define SSL_eNULL              0x00200000L
 #define SSL_AES                        0x04000000L
+#define SSL_CAMELLIA           0x08000000L
+#define SSL_SEED               0x10000000L
 
 #define SSL_MAC_MASK           0x00c00000L
 #define SSL_MD5                        0x00400000L
 #define SSL_SSLV3              0x02000000L
 #define SSL_TLSV1              SSL_SSLV3       /* for now */
 
-/* we have used 07ffffff - 5 bits left to go. */
+/* we have used 1fffffff - 3 bits left to go. */
 
 /*
  * Export and cipher strength information. For each cipher we have to decide
 #define SSL_LOW                        0x00000020L
 #define SSL_MEDIUM             0x00000040L
 #define SSL_HIGH               0x00000080L
+#define SSL_FIPS               0x00000100L
 
-/* we have used 000000ff - 24 bits left to go */
+/* we have used 000001ff - 23 bits left to go */
 
 /*
  * Macros to check the export status and cipher strength for export ciphers.
@@ -493,6 +511,7 @@ typedef struct ssl3_enc_method
        int (*alert_value)(int);
        } SSL3_ENC_METHOD;
 
+#ifndef OPENSSL_NO_COMP
 /* Used for holding the relevant compression methods loaded into SSL_CTX */
 typedef struct ssl3_comp_st
        {
@@ -500,6 +519,7 @@ typedef struct ssl3_comp_st
        char *name;     /* Text name used for the compression type */
        COMP_METHOD *method; /* The method :-) */
        } SSL3_COMP;
+#endif
 
 extern SSL3_ENC_METHOD ssl3_undef_enc_method;
 OPENSSL_EXTERN SSL_CIPHER ssl2_ciphers[];
@@ -511,6 +531,195 @@ SSL_METHOD *sslv2_base_method(void);
 SSL_METHOD *sslv23_base_method(void);
 SSL_METHOD *sslv3_base_method(void);
 
+extern SSL3_ENC_METHOD TLSv1_enc_data;
+extern SSL3_ENC_METHOD SSLv3_enc_data;
+extern SSL3_ENC_METHOD DTLSv1_enc_data;
+
+#define IMPLEMENT_tls1_meth_func(func_name, s_accept, s_connect, s_get_meth) \
+SSL_METHOD *func_name(void)  \
+       { \
+       static SSL_METHOD func_name##_data= { \
+               TLS1_VERSION, \
+               tls1_new, \
+               tls1_clear, \
+               tls1_free, \
+               s_accept, \
+               s_connect, \
+               ssl3_read, \
+               ssl3_peek, \
+               ssl3_write, \
+               ssl3_shutdown, \
+               ssl3_renegotiate, \
+               ssl3_renegotiate_check, \
+               ssl3_get_message, \
+               ssl3_read_bytes, \
+               ssl3_write_bytes, \
+               ssl3_dispatch_alert, \
+               ssl3_ctrl, \
+               ssl3_ctx_ctrl, \
+               ssl3_get_cipher_by_char, \
+               ssl3_put_cipher_by_char, \
+               ssl3_pending, \
+               ssl3_num_ciphers, \
+               ssl3_get_cipher, \
+               s_get_meth, \
+               tls1_default_timeout, \
+               &TLSv1_enc_data, \
+               ssl_undefined_void_function, \
+               ssl3_callback_ctrl, \
+               ssl3_ctx_callback_ctrl, \
+       }; \
+       return &func_name##_data; \
+       }
+
+#define IMPLEMENT_ssl3_meth_func(func_name, s_accept, s_connect, s_get_meth) \
+SSL_METHOD *func_name(void)  \
+       { \
+       static SSL_METHOD func_name##_data= { \
+               SSL3_VERSION, \
+               ssl3_new, \
+               ssl3_clear, \
+               ssl3_free, \
+               s_accept, \
+               s_connect, \
+               ssl3_read, \
+               ssl3_peek, \
+               ssl3_write, \
+               ssl3_shutdown, \
+               ssl3_renegotiate, \
+               ssl3_renegotiate_check, \
+               ssl3_get_message, \
+               ssl3_read_bytes, \
+               ssl3_write_bytes, \
+               ssl3_dispatch_alert, \
+               ssl3_ctrl, \
+               ssl3_ctx_ctrl, \
+               ssl3_get_cipher_by_char, \
+               ssl3_put_cipher_by_char, \
+               ssl3_pending, \
+               ssl3_num_ciphers, \
+               ssl3_get_cipher, \
+               s_get_meth, \
+               ssl3_default_timeout, \
+               &SSLv3_enc_data, \
+               ssl_undefined_void_function, \
+               ssl3_callback_ctrl, \
+               ssl3_ctx_callback_ctrl, \
+       }; \
+       return &func_name##_data; \
+       }
+
+#define IMPLEMENT_ssl23_meth_func(func_name, s_accept, s_connect, s_get_meth) \
+SSL_METHOD *func_name(void)  \
+       { \
+       static SSL_METHOD func_name##_data= { \
+       TLS1_VERSION, \
+       tls1_new, \
+       tls1_clear, \
+       tls1_free, \
+       s_accept, \
+       s_connect, \
+       ssl23_read, \
+       ssl23_peek, \
+       ssl23_write, \
+       ssl_undefined_function, \
+       ssl_undefined_function, \
+       ssl_ok, \
+       ssl3_get_message, \
+       ssl3_read_bytes, \
+       ssl3_write_bytes, \
+       ssl3_dispatch_alert, \
+       ssl3_ctrl, \
+       ssl3_ctx_ctrl, \
+       ssl23_get_cipher_by_char, \
+       ssl23_put_cipher_by_char, \
+       ssl_undefined_const_function, \
+       ssl23_num_ciphers, \
+       ssl23_get_cipher, \
+       s_get_meth, \
+       ssl23_default_timeout, \
+       &ssl3_undef_enc_method, \
+       ssl_undefined_void_function, \
+       ssl3_callback_ctrl, \
+       ssl3_ctx_callback_ctrl, \
+       }; \
+       return &func_name##_data; \
+       }
+
+#define IMPLEMENT_ssl2_meth_func(func_name, s_accept, s_connect, s_get_meth) \
+SSL_METHOD *func_name(void)  \
+       { \
+       static SSL_METHOD func_name##_data= { \
+               SSL2_VERSION, \
+               ssl2_new,       /* local */ \
+               ssl2_clear,     /* local */ \
+               ssl2_free,      /* local */ \
+               s_accept, \
+               s_connect, \
+               ssl2_read, \
+               ssl2_peek, \
+               ssl2_write, \
+               ssl2_shutdown, \
+               ssl_ok, /* NULL - renegotiate */ \
+               ssl_ok, /* NULL - check renegotiate */ \
+               NULL, /* NULL - ssl_get_message */ \
+               NULL, /* NULL - ssl_get_record */ \
+               NULL, /* NULL - ssl_write_bytes */ \
+               NULL, /* NULL - dispatch_alert */ \
+               ssl2_ctrl,      /* local */ \
+               ssl2_ctx_ctrl,  /* local */ \
+               ssl2_get_cipher_by_char, \
+               ssl2_put_cipher_by_char, \
+               ssl2_pending, \
+               ssl2_num_ciphers, \
+               ssl2_get_cipher, \
+               s_get_meth, \
+               ssl2_default_timeout, \
+               &ssl3_undef_enc_method, \
+               ssl_undefined_void_function, \
+               ssl2_callback_ctrl,     /* local */ \
+               ssl2_ctx_callback_ctrl, /* local */ \
+       }; \
+       return &func_name##_data; \
+       }
+
+#define IMPLEMENT_dtls1_meth_func(func_name, s_accept, s_connect, s_get_meth) \
+SSL_METHOD *func_name(void)  \
+       { \
+       static SSL_METHOD func_name##_data= { \
+               DTLS1_VERSION, \
+               dtls1_new, \
+               dtls1_clear, \
+               dtls1_free, \
+               s_accept, \
+               s_connect, \
+               ssl3_read, \
+               ssl3_peek, \
+               ssl3_write, \
+               ssl3_shutdown, \
+               ssl3_renegotiate, \
+               ssl3_renegotiate_check, \
+               dtls1_get_message, \
+               dtls1_read_bytes, \
+               dtls1_write_app_data_bytes, \
+               dtls1_dispatch_alert, \
+               dtls1_ctrl, \
+               ssl3_ctx_ctrl, \
+               ssl3_get_cipher_by_char, \
+               ssl3_put_cipher_by_char, \
+               ssl3_pending, \
+               ssl3_num_ciphers, \
+               dtls1_get_cipher, \
+               s_get_meth, \
+               dtls1_default_timeout, \
+               &DTLSv1_enc_data, \
+               ssl_undefined_void_function, \
+               ssl3_callback_ctrl, \
+               ssl3_ctx_callback_ctrl, \
+       }; \
+       return &func_name##_data; \
+       }
+
 void ssl_clear_cipher_ctx(SSL *s);
 int ssl_clear_bad_session(SSL *s);
 CERT *ssl_cert_new(void);
@@ -521,13 +730,14 @@ SESS_CERT *ssl_sess_cert_new(void);
 void ssl_sess_cert_free(SESS_CERT *sc);
 int ssl_set_peer_cert_type(SESS_CERT *c, int type);
 int ssl_get_new_session(SSL *s, int session);
-int ssl_get_prev_session(SSL *s, unsigned char *session,int len);
+int ssl_get_prev_session(SSL *s, unsigned char *session,int len, const unsigned char *limit);
 int ssl_cipher_id_cmp(const SSL_CIPHER *a,const SSL_CIPHER *b);
 int ssl_cipher_ptr_id_cmp(const SSL_CIPHER * const *ap,
                        const SSL_CIPHER * const *bp);
 STACK_OF(SSL_CIPHER) *ssl_bytes_to_cipher_list(SSL *s,unsigned char *p,int num,
                                               STACK_OF(SSL_CIPHER) **skp);
-int ssl_cipher_list_to_bytes(SSL *s,STACK_OF(SSL_CIPHER) *sk,unsigned char *p);
+int ssl_cipher_list_to_bytes(SSL *s,STACK_OF(SSL_CIPHER) *sk,unsigned char *p,
+                             int (*put_cb)(const SSL_CIPHER *, unsigned char *));
 STACK_OF(SSL_CIPHER) *ssl_create_cipher_list(const SSL_METHOD *meth,
                                             STACK_OF(SSL_CIPHER) **pref,
                                             STACK_OF(SSL_CIPHER) **sorted,
@@ -539,12 +749,14 @@ int ssl_verify_cert_chain(SSL *s,STACK_OF(X509) *sk);
 int ssl_undefined_function(SSL *s);
 int ssl_undefined_void_function(void);
 int ssl_undefined_const_function(const SSL *s);
-X509 *ssl_get_server_send_cert(SSL *);
+CERT_PKEY *ssl_get_server_send_pkey(const SSL *s);
+X509 *ssl_get_server_send_cert(const SSL *);
 EVP_PKEY *ssl_get_sign_pkey(SSL *,SSL_CIPHER *);
 int ssl_cert_type(X509 *x,EVP_PKEY *pkey);
 void ssl_set_cert_masks(CERT *c, SSL_CIPHER *cipher);
 STACK_OF(SSL_CIPHER) *ssl_get_ciphers_by_id(SSL *s);
 int ssl_verify_alarm_type(long type);
+void ssl_load_ciphers(void);
 
 int ssl2_enc_init(SSL *s, int client);
 int ssl2_generate_key_material(SSL *s);
@@ -573,18 +785,21 @@ long      ssl2_ctx_ctrl(SSL_CTX *s,int cmd, long larg, void *parg);
 long   ssl2_callback_ctrl(SSL *s,int cmd, void (*fp)(void));
 long   ssl2_ctx_callback_ctrl(SSL_CTX *s,int cmd, void (*fp)(void));
 int    ssl2_pending(const SSL *s);
+long   ssl2_default_timeout(void );
 
 SSL_CIPHER *ssl3_get_cipher_by_char(const unsigned char *p);
 int ssl3_put_cipher_by_char(const SSL_CIPHER *c,unsigned char *p);
 void ssl3_init_finished_mac(SSL *s);
 int ssl3_send_server_certificate(SSL *s);
+int ssl3_send_newsession_ticket(SSL *s);
+int ssl3_send_cert_status(SSL *s);
 int ssl3_get_finished(SSL *s,int state_a,int state_b);
 int ssl3_setup_key_block(SSL *s);
 int ssl3_send_change_cipher_spec(SSL *s,int state_a,int state_b);
 int ssl3_change_cipher_state(SSL *s,int which);
 void ssl3_cleanup_key_block(SSL *s);
 int ssl3_do_write(SSL *s,int type);
-void ssl3_send_alert(SSL *s,int level, int desc);
+int ssl3_send_alert(SSL *s,int level, int desc);
 int ssl3_generate_master_secret(SSL *s, unsigned char *out,
        unsigned char *p, int len);
 int ssl3_get_req_cert_type(SSL *s,unsigned char *p);
@@ -624,7 +839,18 @@ int        ssl3_pending(const SSL *s);
 
 void ssl3_record_sequence_update(unsigned char *seq);
 int ssl3_do_change_cipher_spec(SSL *ssl);
-
+long ssl3_default_timeout(void );
+
+int ssl23_num_ciphers(void );
+SSL_CIPHER *ssl23_get_cipher(unsigned int u);
+int ssl23_read(SSL *s, void *buf, int len);
+int ssl23_peek(SSL *s, void *buf, int len);
+int ssl23_write(SSL *s, const void *buf, int len);
+int ssl23_put_cipher_by_char(const SSL_CIPHER *c, unsigned char *p);
+SSL_CIPHER *ssl23_get_cipher_by_char(const unsigned char *p);
+long ssl23_default_timeout(void );
+
+long tls1_default_timeout(void);
 int dtls1_do_write(SSL *s,int type);
 int ssl3_read_n(SSL *s, int n, int max, int extend);
 int dtls1_read_bytes(SSL *s, int type, unsigned char *buf, int len, int peek);
@@ -635,6 +861,7 @@ int ssl3_write_pending(SSL *s, int type, const unsigned char *buf,
 unsigned char *dtls1_set_message_header(SSL *s, 
        unsigned char *p, unsigned char mt,     unsigned long len, 
        unsigned long frag_off, unsigned long frag_len);
+
 int dtls1_write_app_data_bytes(SSL *s, int type, const void *buf, int len);
 int dtls1_write_bytes(SSL *s, int type, const void *buf, int len);
 
@@ -645,23 +872,42 @@ int dtls1_read_failed(SSL *s, int code);
 int dtls1_buffer_message(SSL *s, int ccs);
 int dtls1_retransmit_message(SSL *s, unsigned short seq, 
        unsigned long frag_off, int *found);
+int dtls1_get_queue_priority(unsigned short seq, int is_ccs);
+int dtls1_retransmit_buffered_messages(SSL *s);
 void dtls1_clear_record_buffer(SSL *s);
 void dtls1_get_message_header(unsigned char *data, struct hm_header_st *msg_hdr);
 void dtls1_get_ccs_header(unsigned char *data, struct ccs_header_st *ccs_hdr);
 void dtls1_reset_seq_numbers(SSL *s, int rw);
+long dtls1_default_timeout(void);
+struct timeval* dtls1_get_timeout(SSL *s, struct timeval* timeleft);
+int dtls1_check_timeout_num(SSL *s);
+int dtls1_handle_timeout(SSL *s);
+SSL_CIPHER *dtls1_get_cipher(unsigned int u);
+void dtls1_start_timer(SSL *s);
+void dtls1_stop_timer(SSL *s);
+int dtls1_is_timer_expired(SSL *s);
+void dtls1_double_timeout(SSL *s);
+int dtls1_send_newsession_ticket(SSL *s);
+unsigned int dtls1_min_mtu(void);
 
 
 /* some client-only functions */
 int ssl3_client_hello(SSL *s);
 int ssl3_get_server_hello(SSL *s);
 int ssl3_get_certificate_request(SSL *s);
+int ssl3_get_new_session_ticket(SSL *s);
+int ssl3_get_cert_status(SSL *s);
 int ssl3_get_server_done(SSL *s);
 int ssl3_send_client_verify(SSL *s);
+int ssl_do_client_cert_cb(SSL *s, X509 **px509, EVP_PKEY **ppkey);
 int ssl3_send_client_certificate(SSL *s);
 int ssl3_send_client_key_exchange(SSL *s);
 int ssl3_get_key_exchange(SSL *s);
 int ssl3_get_server_certificate(SSL *s);
 int ssl3_check_cert_and_algorithm(SSL *s);
+#ifndef OPENSSL_NO_TLSEXT
+int ssl3_check_finished(SSL *s);
+#endif
 
 int dtls1_client_hello(SSL *s);
 int dtls1_send_client_certificate(SSL *s);
@@ -736,5 +982,63 @@ int check_srvr_ecc_cert_and_alg(X509 *x, SSL_CIPHER *cs);
 
 SSL_COMP *ssl3_comp_find(STACK_OF(SSL_COMP) *sk, int n);
 
+#ifndef OPENSSL_NO_TLSEXT
+unsigned char *ssl_add_clienthello_tlsext(SSL *s, unsigned char *p, unsigned char *limit); 
+unsigned char *ssl_add_serverhello_tlsext(SSL *s, unsigned char *p, unsigned char *limit); 
+int ssl_parse_clienthello_tlsext(SSL *s, unsigned char **data, unsigned char *d, int n, int *al);
+int ssl_parse_serverhello_tlsext(SSL *s, unsigned char **data, unsigned char *d, int n, int *al);
+int ssl_prepare_clienthello_tlsext(SSL *s);
+int ssl_prepare_serverhello_tlsext(SSL *s);
+int ssl_check_clienthello_tlsext_early(SSL *s);
+int ssl_check_clienthello_tlsext_late(SSL *s);
+int ssl_check_serverhello_tlsext(SSL *s);
+
+#ifdef OPENSSL_NO_SHA256
+#define tlsext_tick_md EVP_sha1
+#else
+#define tlsext_tick_md EVP_sha256
+#endif
+int tls1_process_ticket(SSL *s, unsigned char *session_id, int len,
+                               const unsigned char *limit, SSL_SESSION **ret);
+EVP_MD_CTX* ssl_replace_hash(EVP_MD_CTX **hash,const EVP_MD *md) ;
+void ssl_clear_hash_ctx(EVP_MD_CTX **hash);
+
+int ssl_add_serverhello_renegotiate_ext(SSL *s, unsigned char *p, int *len,
+                                       int maxlen);
+int ssl_parse_serverhello_renegotiate_ext(SSL *s, unsigned char *d, int len,
+                                         int *al);
+int ssl_add_clienthello_renegotiate_ext(SSL *s, unsigned char *p, int *len,
+                                       int maxlen);
+int ssl_parse_clienthello_renegotiate_ext(SSL *s, unsigned char *d, int len,
+                                         int *al);
+#endif
+/* s3_cbc.c */
+void ssl3_cbc_copy_mac(unsigned char* out,
+                      const SSL3_RECORD *rec,
+                      unsigned md_size,unsigned orig_len);
+int ssl3_cbc_remove_padding(const SSL* s,
+                           SSL3_RECORD *rec,
+                           unsigned block_size,
+                           unsigned mac_size);
+int tls1_cbc_remove_padding(const SSL* s,
+                           SSL3_RECORD *rec,
+                           unsigned block_size,
+                           unsigned mac_size);
+char ssl3_cbc_record_digest_supported(const EVP_MD *hash);
+void ssl3_cbc_digest_record(
+       const EVP_MD *hash,
+       unsigned char* md_out,
+       size_t* md_out_size,
+       const unsigned char header[13],
+       const unsigned char *data,
+       size_t data_plus_mac_size,
+       size_t data_plus_mac_plus_padding_size,
+       const unsigned char *mac_secret,
+       unsigned mac_secret_length,
+       char is_sslv3);
+
+void tls_fips_digest_extra(
+       const EVP_CIPHER_CTX *cipher_ctx, const EVP_MD *hash, HMAC_CTX *hctx,
+       const unsigned char *data, size_t data_len, size_t orig_len);
 
 #endif