[BACK]Return to kex.h CVS log [TXT][DIR] Up to [local] / src / usr.bin / ssh

Annotation of src/usr.bin/ssh/kex.h, Revision 1.53

1.53    ! markus      1: /* $OpenBSD: kex.h,v 1.52 2010/09/22 05:01:29 djm Exp $ */
1.12      niklas      2:
1.1       markus      3: /*
1.24      markus      4:  * Copyright (c) 2000, 2001 Markus Friedl.  All rights reserved.
1.1       markus      5:  *
                      6:  * Redistribution and use in source and binary forms, with or without
                      7:  * modification, are permitted provided that the following conditions
                      8:  * are met:
                      9:  * 1. Redistributions of source code must retain the above copyright
                     10:  *    notice, this list of conditions and the following disclaimer.
                     11:  * 2. Redistributions in binary form must reproduce the above copyright
                     12:  *    notice, this list of conditions and the following disclaimer in the
                     13:  *    documentation and/or other materials provided with the distribution.
                     14:  *
                     15:  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
                     16:  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
                     17:  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
                     18:  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
                     19:  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
                     20:  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
                     21:  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
                     22:  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
                     23:  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
                     24:  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
                     25:  */
                     26: #ifndef KEX_H
                     27: #define KEX_H
                     28:
1.14      markus     29: #include <openssl/evp.h>
1.45      djm        30: #include <openssl/hmac.h>
1.50      djm        31: #include <openssl/ec.h>
1.47      andreas    32:
                     33: #define KEX_COOKIE_LEN 16
1.14      markus     34:
1.38      djm        35: #define        KEX_DH1                 "diffie-hellman-group1-sha1"
                     36: #define        KEX_DH14                "diffie-hellman-group14-sha1"
                     37: #define        KEX_DHGEX_SHA1          "diffie-hellman-group-exchange-sha1"
1.39      djm        38: #define        KEX_DHGEX_SHA256        "diffie-hellman-group-exchange-sha256"
1.48      andreas    39: #define        KEX_RESUME              "resume@appgate.com"
1.50      djm        40: /* The following represents the family of ECDH methods */
1.51      djm        41: #define        KEX_ECDH_SHA2_STEM      "ecdh-sha2-"
1.37      markus     42:
                     43: #define COMP_NONE      0
                     44: #define COMP_ZLIB      1
                     45: #define COMP_DELAYED   2
1.1       markus     46:
                     47: enum kex_init_proposals {
                     48:        PROPOSAL_KEX_ALGS,
                     49:        PROPOSAL_SERVER_HOST_KEY_ALGS,
                     50:        PROPOSAL_ENC_ALGS_CTOS,
                     51:        PROPOSAL_ENC_ALGS_STOC,
                     52:        PROPOSAL_MAC_ALGS_CTOS,
                     53:        PROPOSAL_MAC_ALGS_STOC,
                     54:        PROPOSAL_COMP_ALGS_CTOS,
                     55:        PROPOSAL_COMP_ALGS_STOC,
                     56:        PROPOSAL_LANG_CTOS,
                     57:        PROPOSAL_LANG_STOC,
                     58:        PROPOSAL_MAX
                     59: };
                     60:
                     61: enum kex_modes {
                     62:        MODE_IN,
                     63:        MODE_OUT,
                     64:        MODE_MAX
                     65: };
                     66:
1.5       provos     67: enum kex_exchange {
1.33      markus     68:        KEX_DH_GRP1_SHA1,
1.35      djm        69:        KEX_DH_GRP14_SHA1,
1.33      markus     70:        KEX_DH_GEX_SHA1,
1.39      djm        71:        KEX_DH_GEX_SHA256,
1.50      djm        72:        KEX_ECDH_SHA2,
1.33      markus     73:        KEX_MAX
1.5       provos     74: };
1.13      stevesk    75:
1.19      markus     76: #define KEX_INIT_SENT  0x0001
                     77:
1.1       markus     78: typedef struct Kex Kex;
                     79: typedef struct Mac Mac;
                     80: typedef struct Comp Comp;
                     81: typedef struct Enc Enc;
1.19      markus     82: typedef struct Newkeys Newkeys;
1.1       markus     83:
                     84: struct Enc {
1.19      markus     85:        char    *name;
                     86:        Cipher  *cipher;
                     87:        int     enabled;
1.29      markus     88:        u_int   key_len;
                     89:        u_int   block_size;
1.10      markus     90:        u_char  *key;
                     91:        u_char  *iv;
1.1       markus     92: };
                     93: struct Mac {
1.19      markus     94:        char    *name;
                     95:        int     enabled;
1.36      djm        96:        u_int   mac_len;
1.10      markus     97:        u_char  *key;
1.36      djm        98:        u_int   key_len;
1.46      pvalchev   99:        int     type;
1.53    ! markus    100:        int     etm;            /* Encrypt-then-MAC */
1.46      pvalchev  101:        const EVP_MD    *evp_md;
                    102:        HMAC_CTX        evp_ctx;
                    103:        struct umac_ctx *umac_ctx;
1.1       markus    104: };
                    105: struct Comp {
1.19      markus    106:        int     type;
                    107:        int     enabled;
                    108:        char    *name;
                    109: };
                    110: struct Newkeys {
                    111:        Enc     enc;
                    112:        Mac     mac;
                    113:        Comp    comp;
1.1       markus    114: };
                    115: struct Kex {
1.19      markus    116:        u_char  *session_id;
1.32      markus    117:        u_int   session_id_len;
1.22      markus    118:        Newkeys *newkeys[MODE_MAX];
1.36      djm       119:        u_int   we_need;
1.19      markus    120:        int     server;
                    121:        char    *name;
                    122:        int     hostkey_type;
                    123:        int     kex_type;
1.48      andreas   124:        int     roaming;
1.19      markus    125:        Buffer  my;
                    126:        Buffer  peer;
1.42      djm       127:        sig_atomic_t done;
1.19      markus    128:        int     flags;
1.38      djm       129:        const EVP_MD *evp_md;
1.19      markus    130:        char    *client_version_string;
                    131:        char    *server_version_string;
1.25      itojun    132:        int     (*verify_host_key)(Key *);
1.49      djm       133:        Key     *(*load_host_public_key)(int);
                    134:        Key     *(*load_host_private_key)(int);
1.30      provos    135:        int     (*host_key_index)(Key *);
1.33      markus    136:        void    (*kex[KEX_MAX])(Kex *);
1.1       markus    137: };
1.52      djm       138:
                    139: int     kex_names_valid(const char *);
1.1       markus    140:
1.25      itojun    141: Kex    *kex_setup(char *[PROPOSAL_MAX]);
1.26      markus    142: void    kex_finish(Kex *);
1.20      markus    143:
1.26      markus    144: void    kex_send_kexinit(Kex *);
1.28      markus    145: void    kex_input_kexinit(int, u_int32_t, void *);
1.38      djm       146: void    kex_derive_keys(Kex *, u_char *, u_int, BIGNUM *);
1.18      markus    147:
1.33      markus    148: Newkeys *kex_get_newkeys(int);
1.19      markus    149:
1.33      markus    150: void    kexdh_client(Kex *);
                    151: void    kexdh_server(Kex *);
                    152: void    kexgex_client(Kex *);
                    153: void    kexgex_server(Kex *);
1.50      djm       154: void    kexecdh_client(Kex *);
                    155: void    kexecdh_server(Kex *);
1.33      markus    156:
1.38      djm       157: void
1.33      markus    158: kex_dh_hash(char *, char *, char *, int, char *, int, u_char *, int,
1.38      djm       159:     BIGNUM *, BIGNUM *, BIGNUM *, u_char **, u_int *);
                    160: void
                    161: kexgex_hash(const EVP_MD *, char *, char *, char *, int, char *,
1.40      deraadt   162:     int, u_char *, int, int, int, int, BIGNUM *, BIGNUM *, BIGNUM *,
1.38      djm       163:     BIGNUM *, BIGNUM *, u_char **, u_int *);
1.50      djm       164: void
                    165: kex_ecdh_hash(const EVP_MD *, const EC_GROUP *, char *, char *, char *, int,
                    166:     char *, int, u_char *, int, const EC_POINT *, const EC_POINT *,
                    167:     const BIGNUM *, u_char **, u_int *);
                    168:
                    169: int    kex_ecdh_name_to_nid(const char *);
1.51      djm       170: const EVP_MD *kex_ecdh_name_to_evpmd(const char *);
1.34      markus    171:
                    172: void
                    173: derive_ssh1_session_id(BIGNUM *, BIGNUM *, u_int8_t[8], u_int8_t[16]);
1.18      markus    174:
1.50      djm       175: #if defined(DEBUG_KEX) || defined(DEBUG_KEXDH) || defined(DEBUG_KEXECDH)
1.25      itojun    176: void   dump_digest(char *, u_char *, int);
1.18      markus    177: #endif
1.1       markus    178:
                    179: #endif