155714Skris/* ssl/ssl2.h */
255714Skris/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
355714Skris * All rights reserved.
455714Skris *
555714Skris * This package is an SSL implementation written
655714Skris * by Eric Young (eay@cryptsoft.com).
755714Skris * The implementation was written so as to conform with Netscapes SSL.
8280304Sjkim *
955714Skris * This library is free for commercial and non-commercial use as long as
1055714Skris * the following conditions are aheared to.  The following conditions
1155714Skris * apply to all code found in this distribution, be it the RC4, RSA,
1255714Skris * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
1355714Skris * included with this distribution is covered by the same copyright terms
1455714Skris * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15280304Sjkim *
1655714Skris * Copyright remains Eric Young's, and as such any Copyright notices in
1755714Skris * the code are not to be removed.
1855714Skris * If this package is used in a product, Eric Young should be given attribution
1955714Skris * as the author of the parts of the library used.
2055714Skris * This can be in the form of a textual message at program startup or
2155714Skris * in documentation (online or textual) provided with the package.
22280304Sjkim *
2355714Skris * Redistribution and use in source and binary forms, with or without
2455714Skris * modification, are permitted provided that the following conditions
2555714Skris * are met:
2655714Skris * 1. Redistributions of source code must retain the copyright
2755714Skris *    notice, this list of conditions and the following disclaimer.
2855714Skris * 2. Redistributions in binary form must reproduce the above copyright
2955714Skris *    notice, this list of conditions and the following disclaimer in the
3055714Skris *    documentation and/or other materials provided with the distribution.
3155714Skris * 3. All advertising materials mentioning features or use of this software
3255714Skris *    must display the following acknowledgement:
3355714Skris *    "This product includes cryptographic software written by
3455714Skris *     Eric Young (eay@cryptsoft.com)"
3555714Skris *    The word 'cryptographic' can be left out if the rouines from the library
3655714Skris *    being used are not cryptographic related :-).
37280304Sjkim * 4. If you include any Windows specific code (or a derivative thereof) from
3855714Skris *    the apps directory (application code) you must include an acknowledgement:
3955714Skris *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40280304Sjkim *
4155714Skris * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
4255714Skris * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
4355714Skris * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
4455714Skris * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
4555714Skris * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
4655714Skris * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
4755714Skris * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
4855714Skris * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
4955714Skris * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
5055714Skris * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
5155714Skris * SUCH DAMAGE.
52280304Sjkim *
5355714Skris * The licence and distribution terms for any publically available version or
5455714Skris * derivative of this code cannot be changed.  i.e. this code cannot simply be
5555714Skris * copied and put under another distribution licence
5655714Skris * [including the GNU Public Licence.]
5755714Skris */
5855714Skris
59280304Sjkim#ifndef HEADER_SSL2_H
60280304Sjkim# define HEADER_SSL2_H
6155714Skris
6255714Skris#ifdef  __cplusplus
6355714Skrisextern "C" {
6455714Skris#endif
6555714Skris
6655714Skris/* Protocol Version Codes */
67280304Sjkim# define SSL2_VERSION            0x0002
68280304Sjkim# define SSL2_VERSION_MAJOR      0x00
69280304Sjkim# define SSL2_VERSION_MINOR      0x02
70280304Sjkim/* #define SSL2_CLIENT_VERSION  0x0002 */
71280304Sjkim/* #define SSL2_SERVER_VERSION  0x0002 */
7255714Skris
7355714Skris/* Protocol Message Codes */
74280304Sjkim# define SSL2_MT_ERROR                   0
75280304Sjkim# define SSL2_MT_CLIENT_HELLO            1
76280304Sjkim# define SSL2_MT_CLIENT_MASTER_KEY       2
77280304Sjkim# define SSL2_MT_CLIENT_FINISHED         3
78280304Sjkim# define SSL2_MT_SERVER_HELLO            4
79280304Sjkim# define SSL2_MT_SERVER_VERIFY           5
80280304Sjkim# define SSL2_MT_SERVER_FINISHED         6
81280304Sjkim# define SSL2_MT_REQUEST_CERTIFICATE     7
82280304Sjkim# define SSL2_MT_CLIENT_CERTIFICATE      8
8355714Skris
8455714Skris/* Error Message Codes */
85280304Sjkim# define SSL2_PE_UNDEFINED_ERROR         0x0000
86280304Sjkim# define SSL2_PE_NO_CIPHER               0x0001
87280304Sjkim# define SSL2_PE_NO_CERTIFICATE          0x0002
88280304Sjkim# define SSL2_PE_BAD_CERTIFICATE         0x0004
89280304Sjkim# define SSL2_PE_UNSUPPORTED_CERTIFICATE_TYPE 0x0006
9055714Skris
9155714Skris/* Cipher Kind Values */
92280304Sjkim# define SSL2_CK_NULL_WITH_MD5                   0x02000000/* v3 */
93280304Sjkim# define SSL2_CK_RC4_128_WITH_MD5                0x02010080
94280304Sjkim# define SSL2_CK_RC4_128_EXPORT40_WITH_MD5       0x02020080
95280304Sjkim# define SSL2_CK_RC2_128_CBC_WITH_MD5            0x02030080
96280304Sjkim# define SSL2_CK_RC2_128_CBC_EXPORT40_WITH_MD5   0x02040080
97280304Sjkim# define SSL2_CK_IDEA_128_CBC_WITH_MD5           0x02050080
98280304Sjkim# define SSL2_CK_DES_64_CBC_WITH_MD5             0x02060040
99280304Sjkim# define SSL2_CK_DES_64_CBC_WITH_SHA             0x02060140/* v3 */
100280304Sjkim# define SSL2_CK_DES_192_EDE3_CBC_WITH_MD5       0x020700c0
101280304Sjkim# define SSL2_CK_DES_192_EDE3_CBC_WITH_SHA       0x020701c0/* v3 */
102280304Sjkim# define SSL2_CK_RC4_64_WITH_MD5                 0x02080080/* MS hack */
10355714Skris
104280304Sjkim# define SSL2_CK_DES_64_CFB64_WITH_MD5_1         0x02ff0800/* SSLeay */
105280304Sjkim# define SSL2_CK_NULL                            0x02ff0810/* SSLeay */
10655714Skris
107280304Sjkim# define SSL2_TXT_DES_64_CFB64_WITH_MD5_1        "DES-CFB-M1"
108280304Sjkim# define SSL2_TXT_NULL_WITH_MD5                  "NULL-MD5"
109280304Sjkim# define SSL2_TXT_RC4_128_WITH_MD5               "RC4-MD5"
110280304Sjkim# define SSL2_TXT_RC4_128_EXPORT40_WITH_MD5      "EXP-RC4-MD5"
111280304Sjkim# define SSL2_TXT_RC2_128_CBC_WITH_MD5           "RC2-CBC-MD5"
112280304Sjkim# define SSL2_TXT_RC2_128_CBC_EXPORT40_WITH_MD5  "EXP-RC2-CBC-MD5"
113280304Sjkim# define SSL2_TXT_IDEA_128_CBC_WITH_MD5          "IDEA-CBC-MD5"
114280304Sjkim# define SSL2_TXT_DES_64_CBC_WITH_MD5            "DES-CBC-MD5"
115280304Sjkim# define SSL2_TXT_DES_64_CBC_WITH_SHA            "DES-CBC-SHA"
116280304Sjkim# define SSL2_TXT_DES_192_EDE3_CBC_WITH_MD5      "DES-CBC3-MD5"
117280304Sjkim# define SSL2_TXT_DES_192_EDE3_CBC_WITH_SHA      "DES-CBC3-SHA"
118280304Sjkim# define SSL2_TXT_RC4_64_WITH_MD5                "RC4-64-MD5"
11955714Skris
120280304Sjkim# define SSL2_TXT_NULL                           "NULL"
121280304Sjkim
12255714Skris/* Flags for the SSL_CIPHER.algorithm2 field */
123280304Sjkim# define SSL2_CF_5_BYTE_ENC                      0x01
124280304Sjkim# define SSL2_CF_8_BYTE_ENC                      0x02
12555714Skris
12655714Skris/* Certificate Type Codes */
127280304Sjkim# define SSL2_CT_X509_CERTIFICATE                0x01
12855714Skris
12955714Skris/* Authentication Type Code */
130280304Sjkim# define SSL2_AT_MD5_WITH_RSA_ENCRYPTION         0x01
13155714Skris
132280304Sjkim# define SSL2_MAX_SSL_SESSION_ID_LENGTH          32
13355714Skris
13455714Skris/* Upper/Lower Bounds */
135280304Sjkim# define SSL2_MAX_MASTER_KEY_LENGTH_IN_BITS      256
136280304Sjkim# ifdef OPENSSL_SYS_MPE
137280304Sjkim#  define SSL2_MAX_RECORD_LENGTH_2_BYTE_HEADER    29998u
138280304Sjkim# else
139280304Sjkim#  define SSL2_MAX_RECORD_LENGTH_2_BYTE_HEADER    32767u
140280304Sjkim                                                       /* 2^15-1 */
141280304Sjkim# endif
142280304Sjkim# define SSL2_MAX_RECORD_LENGTH_3_BYTE_HEADER    16383/* 2^14-1 */
14355714Skris
144280304Sjkim# define SSL2_CHALLENGE_LENGTH   16
145280304Sjkim/*
146280304Sjkim * #define SSL2_CHALLENGE_LENGTH 32
147280304Sjkim */
148280304Sjkim# define SSL2_MIN_CHALLENGE_LENGTH       16
149280304Sjkim# define SSL2_MAX_CHALLENGE_LENGTH       32
150280304Sjkim# define SSL2_CONNECTION_ID_LENGTH       16
151280304Sjkim# define SSL2_MAX_CONNECTION_ID_LENGTH   16
152280304Sjkim# define SSL2_SSL_SESSION_ID_LENGTH      16
153280304Sjkim# define SSL2_MAX_CERT_CHALLENGE_LENGTH  32
154280304Sjkim# define SSL2_MIN_CERT_CHALLENGE_LENGTH  16
155280304Sjkim# define SSL2_MAX_KEY_MATERIAL_LENGTH    24
15655714Skris
157280304Sjkim# ifndef HEADER_SSL_LOCL_H
158280304Sjkim#  define  CERT           char
159280304Sjkim# endif
16055714Skris
161280304Sjkim# ifndef OPENSSL_NO_SSL_INTERN
162238405Sjkim
163280304Sjkimtypedef struct ssl2_state_st {
164280304Sjkim    int three_byte_header;
165280304Sjkim    int clear_text;             /* clear text */
166280304Sjkim    int escape;                 /* not used in SSLv2 */
167280304Sjkim    int ssl2_rollback;          /* used if SSLv23 rolled back to SSLv2 */
168280304Sjkim    /*
169280304Sjkim     * non-blocking io info, used to make sure the same args were passwd
170280304Sjkim     */
171280304Sjkim    unsigned int wnum;          /* number of bytes sent so far */
172280304Sjkim    int wpend_tot;
173280304Sjkim    const unsigned char *wpend_buf;
174280304Sjkim    int wpend_off;              /* offset to data to write */
175280304Sjkim    int wpend_len;              /* number of bytes passwd to write */
176280304Sjkim    int wpend_ret;              /* number of bytes to return to caller */
177280304Sjkim    /* buffer raw data */
178280304Sjkim    int rbuf_left;
179280304Sjkim    int rbuf_offs;
180280304Sjkim    unsigned char *rbuf;
181280304Sjkim    unsigned char *wbuf;
182280304Sjkim    unsigned char *write_ptr;   /* used to point to the start due to 2/3 byte
183280304Sjkim                                 * header. */
184280304Sjkim    unsigned int padding;
185280304Sjkim    unsigned int rlength;       /* passed to ssl2_enc */
186280304Sjkim    int ract_data_length;       /* Set when things are encrypted. */
187280304Sjkim    unsigned int wlength;       /* passed to ssl2_enc */
188280304Sjkim    int wact_data_length;       /* Set when things are decrypted. */
189280304Sjkim    unsigned char *ract_data;
190280304Sjkim    unsigned char *wact_data;
191280304Sjkim    unsigned char *mac_data;
192280304Sjkim    unsigned char *read_key;
193280304Sjkim    unsigned char *write_key;
194280304Sjkim    /* Stuff specifically to do with this SSL session */
195280304Sjkim    unsigned int challenge_length;
196280304Sjkim    unsigned char challenge[SSL2_MAX_CHALLENGE_LENGTH];
197280304Sjkim    unsigned int conn_id_length;
198280304Sjkim    unsigned char conn_id[SSL2_MAX_CONNECTION_ID_LENGTH];
199280304Sjkim    unsigned int key_material_length;
200280304Sjkim    unsigned char key_material[SSL2_MAX_KEY_MATERIAL_LENGTH * 2];
201280304Sjkim    unsigned long read_sequence;
202280304Sjkim    unsigned long write_sequence;
203280304Sjkim    struct {
204280304Sjkim        unsigned int conn_id_length;
205280304Sjkim        unsigned int cert_type;
206280304Sjkim        unsigned int cert_length;
207280304Sjkim        unsigned int csl;
208280304Sjkim        unsigned int clear;
209280304Sjkim        unsigned int enc;
210280304Sjkim        unsigned char ccl[SSL2_MAX_CERT_CHALLENGE_LENGTH];
211280304Sjkim        unsigned int cipher_spec_length;
212280304Sjkim        unsigned int session_id_length;
213280304Sjkim        unsigned int clen;
214280304Sjkim        unsigned int rlen;
215280304Sjkim    } tmp;
216280304Sjkim} SSL2_STATE;
21755714Skris
218280304Sjkim# endif
21955714Skris
22055714Skris/* SSLv2 */
22155714Skris/* client */
222280304Sjkim# define SSL2_ST_SEND_CLIENT_HELLO_A             (0x10|SSL_ST_CONNECT)
223280304Sjkim# define SSL2_ST_SEND_CLIENT_HELLO_B             (0x11|SSL_ST_CONNECT)
224280304Sjkim# define SSL2_ST_GET_SERVER_HELLO_A              (0x20|SSL_ST_CONNECT)
225280304Sjkim# define SSL2_ST_GET_SERVER_HELLO_B              (0x21|SSL_ST_CONNECT)
226280304Sjkim# define SSL2_ST_SEND_CLIENT_MASTER_KEY_A        (0x30|SSL_ST_CONNECT)
227280304Sjkim# define SSL2_ST_SEND_CLIENT_MASTER_KEY_B        (0x31|SSL_ST_CONNECT)
228280304Sjkim# define SSL2_ST_SEND_CLIENT_FINISHED_A          (0x40|SSL_ST_CONNECT)
229280304Sjkim# define SSL2_ST_SEND_CLIENT_FINISHED_B          (0x41|SSL_ST_CONNECT)
230280304Sjkim# define SSL2_ST_SEND_CLIENT_CERTIFICATE_A       (0x50|SSL_ST_CONNECT)
231280304Sjkim# define SSL2_ST_SEND_CLIENT_CERTIFICATE_B       (0x51|SSL_ST_CONNECT)
232280304Sjkim# define SSL2_ST_SEND_CLIENT_CERTIFICATE_C       (0x52|SSL_ST_CONNECT)
233280304Sjkim# define SSL2_ST_SEND_CLIENT_CERTIFICATE_D       (0x53|SSL_ST_CONNECT)
234280304Sjkim# define SSL2_ST_GET_SERVER_VERIFY_A             (0x60|SSL_ST_CONNECT)
235280304Sjkim# define SSL2_ST_GET_SERVER_VERIFY_B             (0x61|SSL_ST_CONNECT)
236280304Sjkim# define SSL2_ST_GET_SERVER_FINISHED_A           (0x70|SSL_ST_CONNECT)
237280304Sjkim# define SSL2_ST_GET_SERVER_FINISHED_B           (0x71|SSL_ST_CONNECT)
238280304Sjkim# define SSL2_ST_CLIENT_START_ENCRYPTION         (0x80|SSL_ST_CONNECT)
239280304Sjkim# define SSL2_ST_X509_GET_CLIENT_CERTIFICATE     (0x90|SSL_ST_CONNECT)
24055714Skris/* server */
241280304Sjkim# define SSL2_ST_GET_CLIENT_HELLO_A              (0x10|SSL_ST_ACCEPT)
242280304Sjkim# define SSL2_ST_GET_CLIENT_HELLO_B              (0x11|SSL_ST_ACCEPT)
243280304Sjkim# define SSL2_ST_GET_CLIENT_HELLO_C              (0x12|SSL_ST_ACCEPT)
244280304Sjkim# define SSL2_ST_SEND_SERVER_HELLO_A             (0x20|SSL_ST_ACCEPT)
245280304Sjkim# define SSL2_ST_SEND_SERVER_HELLO_B             (0x21|SSL_ST_ACCEPT)
246280304Sjkim# define SSL2_ST_GET_CLIENT_MASTER_KEY_A         (0x30|SSL_ST_ACCEPT)
247280304Sjkim# define SSL2_ST_GET_CLIENT_MASTER_KEY_B         (0x31|SSL_ST_ACCEPT)
248280304Sjkim# define SSL2_ST_SEND_SERVER_VERIFY_A            (0x40|SSL_ST_ACCEPT)
249280304Sjkim# define SSL2_ST_SEND_SERVER_VERIFY_B            (0x41|SSL_ST_ACCEPT)
250280304Sjkim# define SSL2_ST_SEND_SERVER_VERIFY_C            (0x42|SSL_ST_ACCEPT)
251280304Sjkim# define SSL2_ST_GET_CLIENT_FINISHED_A           (0x50|SSL_ST_ACCEPT)
252280304Sjkim# define SSL2_ST_GET_CLIENT_FINISHED_B           (0x51|SSL_ST_ACCEPT)
253280304Sjkim# define SSL2_ST_SEND_SERVER_FINISHED_A          (0x60|SSL_ST_ACCEPT)
254280304Sjkim# define SSL2_ST_SEND_SERVER_FINISHED_B          (0x61|SSL_ST_ACCEPT)
255280304Sjkim# define SSL2_ST_SEND_REQUEST_CERTIFICATE_A      (0x70|SSL_ST_ACCEPT)
256280304Sjkim# define SSL2_ST_SEND_REQUEST_CERTIFICATE_B      (0x71|SSL_ST_ACCEPT)
257280304Sjkim# define SSL2_ST_SEND_REQUEST_CERTIFICATE_C      (0x72|SSL_ST_ACCEPT)
258280304Sjkim# define SSL2_ST_SEND_REQUEST_CERTIFICATE_D      (0x73|SSL_ST_ACCEPT)
259280304Sjkim# define SSL2_ST_SERVER_START_ENCRYPTION         (0x80|SSL_ST_ACCEPT)
260280304Sjkim# define SSL2_ST_X509_GET_SERVER_CERTIFICATE     (0x90|SSL_ST_ACCEPT)
26155714Skris
26255714Skris#ifdef  __cplusplus
26355714Skris}
26455714Skris#endif
26555714Skris#endif
266