Skip to main content
  • Home
  • login
  • Browse the archive

    swh mirror partner logo
swh logo
SoftwareHeritage
Software
Heritage
Mirror
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

swh:1:snp:dc2a5002442a00b1c0eda7c65d04ea7455e166cd
  • Code
  • Branches (204)
  • Releases (207)
    • Branches
    • Releases
    • HEAD
    • refs/heads/OpenSSL-engine-0_9_6-stable
    • refs/heads/OpenSSL-fips-0_9_7-stable
    • refs/heads/OpenSSL-fips-0_9_8-stable
    • refs/heads/OpenSSL-fips-1_2-stable
    • refs/heads/OpenSSL-fips-2_0-dev
    • refs/heads/OpenSSL-fips-2_0-stable
    • refs/heads/OpenSSL-fips2-0_9_7-stable
    • refs/heads/OpenSSL_0_9_6-stable
    • refs/heads/OpenSSL_0_9_7-stable
    • refs/heads/OpenSSL_0_9_8-stable
    • refs/heads/OpenSSL_0_9_8fg-stable
    • refs/heads/OpenSSL_1_0_0-stable
    • refs/heads/OpenSSL_1_0_1-stable
    • refs/heads/OpenSSL_1_0_2-stable
    • refs/heads/OpenSSL_1_1_0-stable
    • refs/heads/OpenSSL_1_1_1-stable
    • refs/heads/SSLeay
    • refs/heads/feature/dtls-1.3
    • refs/heads/feature/ech
    • refs/heads/feature/quic-server
    • refs/heads/master
    • refs/heads/openssl-3.0
    • refs/heads/openssl-3.1
    • refs/heads/openssl-3.2
    • refs/heads/openssl-3.3
    • refs/heads/openssl-3.4
    • refs/heads/tls1.3-draft-18
    • refs/heads/tls1.3-draft-19
    • refs/tags/AFTER_COMPAQ_PATCH
    • refs/tags/BEFORE_COMPAQ_PATCH
    • refs/tags/BEFORE_engine
    • refs/tags/BEN_FIPS_TEST_1
    • refs/tags/BEN_FIPS_TEST_2
    • refs/tags/BEN_FIPS_TEST_3
    • refs/tags/BEN_FIPS_TEST_4
    • refs/tags/BEN_FIPS_TEST_5
    • refs/tags/BEN_FIPS_TEST_6
    • refs/tags/BEN_FIPS_TEST_7
    • refs/tags/BEN_FIPS_TEST_8
    • refs/tags/FIPS_098_TEST_1
    • refs/tags/FIPS_098_TEST_2
    • refs/tags/FIPS_098_TEST_3
    • refs/tags/FIPS_098_TEST_4
    • refs/tags/FIPS_098_TEST_5
    • refs/tags/FIPS_098_TEST_6
    • refs/tags/FIPS_098_TEST_7
    • refs/tags/FIPS_098_TEST_8
    • refs/tags/FIPS_TEST_10
    • refs/tags/FIPS_TEST_9
    • refs/tags/LEVITTE_after_const
    • refs/tags/LEVITTE_before_const
    • refs/tags/OpenSSL-engine-0_9_6
    • refs/tags/OpenSSL-engine-0_9_6-beta1
    • refs/tags/OpenSSL-engine-0_9_6-beta2
    • refs/tags/OpenSSL-engine-0_9_6-beta3
    • refs/tags/OpenSSL-engine-0_9_6a
    • refs/tags/OpenSSL-engine-0_9_6a-beta1
    • refs/tags/OpenSSL-engine-0_9_6a-beta2
    • refs/tags/OpenSSL-engine-0_9_6a-beta3
    • refs/tags/OpenSSL-engine-0_9_6b
    • refs/tags/OpenSSL-engine-0_9_6c
    • refs/tags/OpenSSL-engine-0_9_6d
    • refs/tags/OpenSSL-engine-0_9_6d-beta1
    • refs/tags/OpenSSL-engine-0_9_6e
    • refs/tags/OpenSSL-engine-0_9_6f
    • refs/tags/OpenSSL-engine-0_9_6g
    • refs/tags/OpenSSL-engine-0_9_6h
    • refs/tags/OpenSSL-engine-0_9_6i
    • refs/tags/OpenSSL-engine-0_9_6j
    • refs/tags/OpenSSL-engine-0_9_6k
    • refs/tags/OpenSSL-engine-0_9_6l
    • refs/tags/OpenSSL-engine-0_9_6m
    • refs/tags/OpenSSL-fips-1_2_0
    • refs/tags/OpenSSL-fips-1_2_1
    • refs/tags/OpenSSL-fips-1_2_2
    • refs/tags/OpenSSL-fips-1_2_3
    • refs/tags/OpenSSL-fips-2_0
    • refs/tags/OpenSSL-fips-2_0-pl1
    • refs/tags/OpenSSL-fips-2_0-rc1
    • refs/tags/OpenSSL-fips-2_0-rc2
    • refs/tags/OpenSSL-fips-2_0-rc3
    • refs/tags/OpenSSL-fips-2_0-rc4
    • refs/tags/OpenSSL-fips-2_0-rc5
    • refs/tags/OpenSSL-fips-2_0-rc6
    • refs/tags/OpenSSL-fips-2_0-rc7
    • refs/tags/OpenSSL-fips-2_0-rc8
    • refs/tags/OpenSSL-fips-2_0-rc9
    • refs/tags/OpenSSL-fips-2_0_1
    • refs/tags/OpenSSL_0_9_1c
    • refs/tags/OpenSSL_0_9_2b
    • refs/tags/OpenSSL_0_9_3
    • refs/tags/OpenSSL_0_9_3a
    • refs/tags/OpenSSL_0_9_3beta1
    • refs/tags/OpenSSL_0_9_3beta2
    • refs/tags/OpenSSL_0_9_4
    • refs/tags/OpenSSL_0_9_5
    • refs/tags/OpenSSL_0_9_5a
    • refs/tags/OpenSSL_0_9_5a-beta1
    • refs/tags/OpenSSL_0_9_5a-beta2
    • refs/tags/OpenSSL_0_9_5beta1
    • refs/tags/OpenSSL_0_9_5beta2
    • refs/tags/OpenSSL_0_9_6
    • refs/tags/OpenSSL_0_9_6-beta1
    • refs/tags/OpenSSL_0_9_6-beta2
    • refs/tags/OpenSSL_0_9_6-beta3
    • refs/tags/OpenSSL_0_9_6a
    • refs/tags/OpenSSL_0_9_6a-beta1
    • refs/tags/OpenSSL_0_9_6a-beta2
    • refs/tags/OpenSSL_0_9_6a-beta3
    • refs/tags/OpenSSL_0_9_6b
    • refs/tags/OpenSSL_0_9_6c
    • refs/tags/OpenSSL_0_9_6d
    • refs/tags/OpenSSL_0_9_6d-beta1
    • refs/tags/OpenSSL_0_9_6e
    • refs/tags/OpenSSL_0_9_6f
    • refs/tags/OpenSSL_0_9_6g
    • refs/tags/OpenSSL_0_9_6h
    • refs/tags/OpenSSL_0_9_6i
    • refs/tags/OpenSSL_0_9_6j
    • refs/tags/OpenSSL_0_9_6k
    • refs/tags/OpenSSL_0_9_6l
    • refs/tags/OpenSSL_0_9_6m
    • refs/tags/OpenSSL_0_9_7
    • refs/tags/OpenSSL_0_9_7-beta1
    • refs/tags/OpenSSL_0_9_7-beta2
    • refs/tags/OpenSSL_0_9_7-beta3
    • refs/tags/OpenSSL_0_9_7-beta4
    • refs/tags/OpenSSL_0_9_7-beta5
    • refs/tags/OpenSSL_0_9_7-beta6
    • refs/tags/OpenSSL_0_9_7a
    • refs/tags/OpenSSL_0_9_7b
    • refs/tags/OpenSSL_0_9_7c
    • refs/tags/OpenSSL_0_9_7d
    • refs/tags/OpenSSL_0_9_7e
    • refs/tags/OpenSSL_0_9_7f
    • refs/tags/OpenSSL_0_9_7g
    • refs/tags/OpenSSL_0_9_7h
    • refs/tags/OpenSSL_0_9_7i
    • refs/tags/OpenSSL_0_9_7j
    • refs/tags/OpenSSL_0_9_7k
    • refs/tags/OpenSSL_0_9_7l
    • refs/tags/OpenSSL_0_9_7m
    • refs/tags/OpenSSL_0_9_8
    • refs/tags/OpenSSL_0_9_8-beta1
    • refs/tags/OpenSSL_0_9_8-beta2
    • refs/tags/OpenSSL_0_9_8-beta3
    • refs/tags/OpenSSL_0_9_8-beta4
    • refs/tags/OpenSSL_0_9_8-beta5
    • refs/tags/OpenSSL_0_9_8-beta6
    • refs/tags/OpenSSL_0_9_8a
    • refs/tags/OpenSSL_0_9_8b
    • refs/tags/OpenSSL_0_9_8c
    • refs/tags/OpenSSL_0_9_8d
    • refs/tags/OpenSSL_0_9_8e
    • refs/tags/OpenSSL_0_9_8f
    • refs/tags/OpenSSL_0_9_8g
    • refs/tags/OpenSSL_0_9_8h
    • refs/tags/OpenSSL_0_9_8i
    • refs/tags/OpenSSL_0_9_8j
    • refs/tags/OpenSSL_0_9_8k
    • refs/tags/OpenSSL_0_9_8l
    • refs/tags/OpenSSL_0_9_8m
    • refs/tags/OpenSSL_0_9_8m-beta1
    • refs/tags/OpenSSL_0_9_8n
    • refs/tags/OpenSSL_0_9_8o
    • refs/tags/OpenSSL_0_9_8p
    • refs/tags/OpenSSL_0_9_8q
    • refs/tags/OpenSSL_0_9_8r
    • refs/tags/OpenSSL_0_9_8s
    • refs/tags/OpenSSL_0_9_8t
    • refs/tags/OpenSSL_0_9_8u
    • refs/tags/OpenSSL_0_9_8v
    • refs/tags/OpenSSL_0_9_8w
    • refs/tags/OpenSSL_0_9_8x
    • refs/tags/OpenSSL_1_0_0
    • refs/tags/OpenSSL_1_0_0-beta1
    • refs/tags/OpenSSL_1_0_0-beta2
    • refs/tags/OpenSSL_1_0_0-beta3
    • refs/tags/OpenSSL_1_0_0-beta4
    • refs/tags/OpenSSL_1_0_0-beta5
    • refs/tags/OpenSSL_1_0_0a
    • refs/tags/OpenSSL_1_0_0b
    • refs/tags/OpenSSL_1_0_0c
    • refs/tags/OpenSSL_1_0_0d
    • refs/tags/OpenSSL_1_0_0e
    • refs/tags/OpenSSL_1_0_0f
    • refs/tags/OpenSSL_1_0_0g
    • refs/tags/OpenSSL_1_0_0h
    • refs/tags/OpenSSL_1_0_0i
    • refs/tags/OpenSSL_1_0_0j
    • refs/tags/OpenSSL_1_0_1
    • refs/tags/OpenSSL_1_0_1-beta1
    • refs/tags/OpenSSL_1_0_1-beta2
    • refs/tags/OpenSSL_1_0_1-beta3
    • refs/tags/OpenSSL_1_0_1a
    • refs/tags/OpenSSL_1_0_1b
    • refs/tags/OpenSSL_1_0_1c
    • refs/tags/OpenSSL_FIPS_1_0
    • refs/tags/SSLeay_0_8_1b
    • refs/tags/SSLeay_0_9_0b
    • refs/tags/SSLeay_0_9_1b
    • refs/tags/STATE_after_zlib
    • refs/tags/STATE_before_zlib
    • refs/tags/rsaref
    • openssl-3.4.0-alpha1
    • openssl-3.3.2
    • openssl-3.3.1
    • openssl-3.3.0-beta1
    • openssl-3.3.0-alpha1
    • openssl-3.3.0
    • openssl-3.2.3
    • openssl-3.2.2
    • openssl-3.2.1
    • openssl-3.2.0-beta1
    • openssl-3.2.0-alpha2
    • openssl-3.2.0-alpha1
    • openssl-3.2.0
    • openssl-3.1.7
    • openssl-3.1.6
    • openssl-3.1.5
    • openssl-3.1.4
    • openssl-3.1.3
    • openssl-3.1.2
    • openssl-3.1.1
    • openssl-3.1.0-beta1
    • openssl-3.1.0-alpha1
    • openssl-3.1.0
    • openssl-3.0.9
    • openssl-3.0.8
    • openssl-3.0.7
    • openssl-3.0.6
    • openssl-3.0.5
    • openssl-3.0.4
    • openssl-3.0.3
    • openssl-3.0.2
    • openssl-3.0.15
    • openssl-3.0.14
    • openssl-3.0.13
    • openssl-3.0.12
    • openssl-3.0.11
    • openssl-3.0.10
    • openssl-3.0.1
    • openssl-3.0.0-beta2
    • openssl-3.0.0-beta1
    • openssl-3.0.0-alpha9
    • openssl-3.0.0-alpha8
    • openssl-3.0.0-alpha7
    • openssl-3.0.0-alpha6
    • openssl-3.0.0-alpha5
    • openssl-3.0.0-alpha4
    • openssl-3.0.0-alpha3
    • openssl-3.0.0-alpha2
    • openssl-3.0.0-alpha17
    • openssl-3.0.0-alpha16
    • openssl-3.0.0-alpha15
    • openssl-3.0.0-alpha14
    • openssl-3.0.0-alpha13
    • openssl-3.0.0-alpha12
    • openssl-3.0.0-alpha11
    • openssl-3.0.0-alpha10
    • openssl-3.0.0-alpha1
    • openssl-3.0.0
    • master-pre-reformat
    • master-pre-auto-reformat
    • master-post-reformat
    • master-post-auto-reformat
    • OpenSSL_1_1_1w
    • OpenSSL_1_1_1v
    • OpenSSL_1_1_1u
    • OpenSSL_1_1_1t
    • OpenSSL_1_1_1s
    • OpenSSL_1_1_1r
    • OpenSSL_1_1_1q
    • OpenSSL_1_1_1p
    • OpenSSL_1_1_1o
    • OpenSSL_1_1_1n
    • OpenSSL_1_1_1m
    • OpenSSL_1_1_1l
    • OpenSSL_1_1_1k
    • OpenSSL_1_1_1j
    • OpenSSL_1_1_1i
    • OpenSSL_1_1_1h
    • OpenSSL_1_1_1g
    • OpenSSL_1_1_1f
    • OpenSSL_1_1_1e
    • OpenSSL_1_1_1d
    • OpenSSL_1_1_1c
    • OpenSSL_1_1_1b
    • OpenSSL_1_1_1a
    • OpenSSL_1_1_1-pre9
    • OpenSSL_1_1_1-pre8
    • OpenSSL_1_1_1-pre7
    • OpenSSL_1_1_1-pre6
    • OpenSSL_1_1_1-pre5
    • OpenSSL_1_1_1-pre4
    • OpenSSL_1_1_1-pre3
    • OpenSSL_1_1_1-pre2
    • OpenSSL_1_1_1-pre1
    • OpenSSL_1_1_1
    • OpenSSL_1_1_0l
    • OpenSSL_1_1_0k
    • OpenSSL_1_1_0j
    • OpenSSL_1_1_0i
    • OpenSSL_1_1_0h
    • OpenSSL_1_1_0g
    • OpenSSL_1_1_0f
    • OpenSSL_1_1_0e
    • OpenSSL_1_1_0d
    • OpenSSL_1_1_0c
    • OpenSSL_1_1_0b
    • OpenSSL_1_1_0a
    • OpenSSL_1_1_0-pre6
    • OpenSSL_1_1_0-pre5
    • OpenSSL_1_1_0-pre4
    • OpenSSL_1_1_0-pre3
    • OpenSSL_1_1_0-pre2
    • OpenSSL_1_1_0-pre1
    • OpenSSL_1_1_0
    • OpenSSL_1_0_2u
    • OpenSSL_1_0_2t
    • OpenSSL_1_0_2s
    • OpenSSL_1_0_2r
    • OpenSSL_1_0_2q
    • OpenSSL_1_0_2p
    • OpenSSL_1_0_2o
    • OpenSSL_1_0_2n
    • OpenSSL_1_0_2m
    • OpenSSL_1_0_2l
    • OpenSSL_1_0_2k
    • OpenSSL_1_0_2j
    • OpenSSL_1_0_2i
    • OpenSSL_1_0_2h
    • OpenSSL_1_0_2g
    • OpenSSL_1_0_2f
    • OpenSSL_1_0_2e
    • OpenSSL_1_0_2d
    • OpenSSL_1_0_2c
    • OpenSSL_1_0_2b
    • OpenSSL_1_0_2a
    • OpenSSL_1_0_2-pre-reformat
    • OpenSSL_1_0_2-pre-auto-reformat
    • OpenSSL_1_0_2-post-reformat
    • OpenSSL_1_0_2-post-auto-reformat
    • OpenSSL_1_0_2-beta3
    • OpenSSL_1_0_2-beta2
    • OpenSSL_1_0_2-beta1
    • OpenSSL_1_0_2
    • OpenSSL_1_0_1u
    • OpenSSL_1_0_1t
    • OpenSSL_1_0_1s
    • OpenSSL_1_0_1r
    • OpenSSL_1_0_1q
    • OpenSSL_1_0_1p
    • OpenSSL_1_0_1o
    • OpenSSL_1_0_1n
    • OpenSSL_1_0_1m
    • OpenSSL_1_0_1l
    • OpenSSL_1_0_1k
    • OpenSSL_1_0_1j
    • OpenSSL_1_0_1i
    • OpenSSL_1_0_1h
    • OpenSSL_1_0_1g
    • OpenSSL_1_0_1f
    • OpenSSL_1_0_1e
    • OpenSSL_1_0_1d
    • OpenSSL_1_0_1-pre-reformat
    • OpenSSL_1_0_1-pre-auto-reformat
    • OpenSSL_1_0_1-post-reformat
    • OpenSSL_1_0_1-post-auto-reformat
    • OpenSSL_1_0_0t
    • OpenSSL_1_0_0s
    • OpenSSL_1_0_0r
    • OpenSSL_1_0_0q
    • OpenSSL_1_0_0p
    • OpenSSL_1_0_0o
    • OpenSSL_1_0_0n
    • OpenSSL_1_0_0m
    • OpenSSL_1_0_0l
    • OpenSSL_1_0_0k
    • OpenSSL_1_0_0-pre-reformat
    • OpenSSL_1_0_0-pre-auto-reformat
    • OpenSSL_1_0_0-post-reformat
    • OpenSSL_1_0_0-post-auto-reformat
    • OpenSSL_0_9_8zh
    • OpenSSL_0_9_8zg
    • OpenSSL_0_9_8zf
    • OpenSSL_0_9_8ze
    • OpenSSL_0_9_8zd
    • OpenSSL_0_9_8zc
    • OpenSSL_0_9_8zb
    • OpenSSL_0_9_8za
    • OpenSSL_0_9_8y
    • OpenSSL_0_9_8-pre-reformat
    • OpenSSL_0_9_8-pre-auto-reformat
    • OpenSSL_0_9_8-post-reformat
    • OpenSSL_0_9_8-post-auto-reformat
    • OpenSSL-fips-2_0_9
    • OpenSSL-fips-2_0_8
    • OpenSSL-fips-2_0_7
    • OpenSSL-fips-2_0_6
    • OpenSSL-fips-2_0_5
    • OpenSSL-fips-2_0_4
    • OpenSSL-fips-2_0_3
    • OpenSSL-fips-2_0_2
    • OpenSSL-fips-2_0_16
    • OpenSSL-fips-2_0_15
    • OpenSSL-fips-2_0_14
    • OpenSSL-fips-2_0_13
    • OpenSSL-fips-2_0_12
    • OpenSSL-fips-2_0_11
    • OpenSSL-fips-2_0_10
  • 2e8faee
  • /
  • ssl
  • /
  • s2_pkt.c
Raw File
Permalinks

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • content
  • directory
  • revision
  • snapshot
  • release
content badge Iframe embedding
swh:1:cnt:7a6188813431f345b2839a1b33873d99a272e3b1
directory badge Iframe embedding
swh:1:dir:20a0735ac3414431b9c455e0ec4d9c3e919bd7ba
revision badge
swh:1:rev:bfe07df40c13ea2564bb4577620180e3f4849e23
snapshot badge
swh:1:snp:dc2a5002442a00b1c0eda7c65d04ea7455e166cd
release badge
swh:1:rel:d299bbd186a06e10ca1c8b12ecc24ee177a07126
Tip revision: bfe07df40c13ea2564bb4577620180e3f4849e23 authored by Matt Caswell on 03 December 2015, 14:44:31 UTC
Prepare for 1.0.2e release
Tip revision: bfe07df
s2_pkt.c
/* ssl/s2_pkt.c */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
 * All rights reserved.
 *
 * This package is an SSL implementation written
 * by Eric Young (eay@cryptsoft.com).
 * The implementation was written so as to conform with Netscapes SSL.
 *
 * This library is free for commercial and non-commercial use as long as
 * the following conditions are aheared to.  The following conditions
 * apply to all code found in this distribution, be it the RC4, RSA,
 * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
 * included with this distribution is covered by the same copyright terms
 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
 *
 * Copyright remains Eric Young's, and as such any Copyright notices in
 * the code are not to be removed.
 * If this package is used in a product, Eric Young should be given attribution
 * as the author of the parts of the library used.
 * This can be in the form of a textual message at program startup or
 * in documentation (online or textual) provided with the package.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *    "This product includes cryptographic software written by
 *     Eric Young (eay@cryptsoft.com)"
 *    The word 'cryptographic' can be left out if the rouines from the library
 *    being used are not cryptographic related :-).
 * 4. If you include any Windows specific code (or a derivative thereof) from
 *    the apps directory (application code) you must include an acknowledgement:
 *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
 *
 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * The licence and distribution terms for any publically available version or
 * derivative of this code cannot be changed.  i.e. this code cannot simply be
 * copied and put under another distribution licence
 * [including the GNU Public Licence.]
 */
/* ====================================================================
 * Copyright (c) 1998-2001 The OpenSSL Project.  All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *
 * 3. All advertising materials mentioning features or use of this
 *    software must display the following acknowledgment:
 *    "This product includes software developed by the OpenSSL Project
 *    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
 *
 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
 *    endorse or promote products derived from this software without
 *    prior written permission. For written permission, please contact
 *    openssl-core@openssl.org.
 *
 * 5. Products derived from this software may not be called "OpenSSL"
 *    nor may "OpenSSL" appear in their names without prior written
 *    permission of the OpenSSL Project.
 *
 * 6. Redistributions of any form whatsoever must retain the following
 *    acknowledgment:
 *    "This product includes software developed by the OpenSSL Project
 *    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
 *
 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 * OF THE POSSIBILITY OF SUCH DAMAGE.
 * ====================================================================
 *
 * This product includes cryptographic software written by Eric Young
 * (eay@cryptsoft.com).  This product includes software written by Tim
 * Hudson (tjh@cryptsoft.com).
 *
 */

#include "ssl_locl.h"
#ifndef OPENSSL_NO_SSL2
# include <stdio.h>
# include <errno.h>
# define USE_SOCKETS

static int read_n(SSL *s, unsigned int n, unsigned int max,
                  unsigned int extend);
static int n_do_ssl_write(SSL *s, const unsigned char *buf, unsigned int len);
static int write_pending(SSL *s, const unsigned char *buf, unsigned int len);
static int ssl_mt_error(int n);

/*
 * SSL 2.0 imlementation for SSL_read/SSL_peek - This routine will return 0
 * to len bytes, decrypted etc if required.
 */
static int ssl2_read_internal(SSL *s, void *buf, int len, int peek)
{
    int n;
    unsigned char mac[MAX_MAC_SIZE];
    unsigned char *p;
    int i;
    int mac_size;

 ssl2_read_again:
    if (SSL_in_init(s) && !s->in_handshake) {
        n = s->handshake_func(s);
        if (n < 0)
            return (n);
        if (n == 0) {
            SSLerr(SSL_F_SSL2_READ_INTERNAL, SSL_R_SSL_HANDSHAKE_FAILURE);
            return (-1);
        }
    }

    clear_sys_error();
    s->rwstate = SSL_NOTHING;
    if (len <= 0)
        return (len);

    if (s->s2->ract_data_length != 0) { /* read from buffer */
        if (len > s->s2->ract_data_length)
            n = s->s2->ract_data_length;
        else
            n = len;

        memcpy(buf, s->s2->ract_data, (unsigned int)n);
        if (!peek) {
            s->s2->ract_data_length -= n;
            s->s2->ract_data += n;
            if (s->s2->ract_data_length == 0)
                s->rstate = SSL_ST_READ_HEADER;
        }

        return (n);
    }

    /*
     * s->s2->ract_data_length == 0 Fill the buffer, then goto
     * ssl2_read_again.
     */

    if (s->rstate == SSL_ST_READ_HEADER) {
        if (s->first_packet) {
            n = read_n(s, 5, SSL2_MAX_RECORD_LENGTH_2_BYTE_HEADER + 2, 0);
            if (n <= 0)
                return (n);     /* error or non-blocking */
            s->first_packet = 0;
            p = s->packet;
            if (!((p[0] & 0x80) && ((p[2] == SSL2_MT_CLIENT_HELLO) ||
                                    (p[2] == SSL2_MT_SERVER_HELLO)))) {
                SSLerr(SSL_F_SSL2_READ_INTERNAL,
                       SSL_R_NON_SSLV2_INITIAL_PACKET);
                return (-1);
            }
        } else {
            n = read_n(s, 2, SSL2_MAX_RECORD_LENGTH_2_BYTE_HEADER + 2, 0);
            if (n <= 0)
                return (n);     /* error or non-blocking */
        }
        /* part read stuff */

        s->rstate = SSL_ST_READ_BODY;
        p = s->packet;
        /* Do header */
        /*
         * s->s2->padding=0;
         */
        s->s2->escape = 0;
        s->s2->rlength = (((unsigned int)p[0]) << 8) | ((unsigned int)p[1]);
        if ((p[0] & TWO_BYTE_BIT)) { /* Two byte header? */
            s->s2->three_byte_header = 0;
            s->s2->rlength &= TWO_BYTE_MASK;
        } else {
            s->s2->three_byte_header = 1;
            s->s2->rlength &= THREE_BYTE_MASK;

            /* security >s2->escape */
            s->s2->escape = ((p[0] & SEC_ESC_BIT)) ? 1 : 0;
        }
    }

    if (s->rstate == SSL_ST_READ_BODY) {
        n = s->s2->rlength + 2 + s->s2->three_byte_header;
        if (n > (int)s->packet_length) {
            n -= s->packet_length;
            i = read_n(s, (unsigned int)n, (unsigned int)n, 1);
            if (i <= 0)
                return (i);     /* ERROR */
        }

        p = &(s->packet[2]);
        s->rstate = SSL_ST_READ_HEADER;
        if (s->s2->three_byte_header)
            s->s2->padding = *(p++);
        else
            s->s2->padding = 0;

        /* Data portion */
        if (s->s2->clear_text) {
            mac_size = 0;
            s->s2->mac_data = p;
            s->s2->ract_data = p;
            if (s->s2->padding) {
                SSLerr(SSL_F_SSL2_READ_INTERNAL, SSL_R_ILLEGAL_PADDING);
                return (-1);
            }
        } else {
            mac_size = EVP_MD_CTX_size(s->read_hash);
            if (mac_size < 0)
                return -1;
            OPENSSL_assert(mac_size <= MAX_MAC_SIZE);
            s->s2->mac_data = p;
            s->s2->ract_data = &p[mac_size];
            if (s->s2->padding + mac_size > s->s2->rlength) {
                SSLerr(SSL_F_SSL2_READ_INTERNAL, SSL_R_ILLEGAL_PADDING);
                return (-1);
            }
        }

        s->s2->ract_data_length = s->s2->rlength;
        /*
         * added a check for length > max_size in case encryption was not
         * turned on yet due to an error
         */
        if ((!s->s2->clear_text) &&
            (s->s2->rlength >= (unsigned int)mac_size)) {
            if (!ssl2_enc(s, 0)) {
                SSLerr(SSL_F_SSL2_READ_INTERNAL, SSL_R_DECRYPTION_FAILED);
                return (-1);
            }
            s->s2->ract_data_length -= mac_size;
            ssl2_mac(s, mac, 0);
            s->s2->ract_data_length -= s->s2->padding;
            if ((CRYPTO_memcmp(mac, s->s2->mac_data, mac_size) != 0) ||
                (s->s2->rlength %
                 EVP_CIPHER_CTX_block_size(s->enc_read_ctx) != 0)) {
                SSLerr(SSL_F_SSL2_READ_INTERNAL, SSL_R_BAD_MAC_DECODE);
                return (-1);
            }
        }
        INC32(s->s2->read_sequence); /* expect next number */
        /* s->s2->ract_data is now available for processing */

        /*
         * Possibly the packet that we just read had 0 actual data bytes.
         * (SSLeay/OpenSSL itself never sends such packets; see ssl2_write.)
         * In this case, returning 0 would be interpreted by the caller as
         * indicating EOF, so it's not a good idea.  Instead, we just
         * continue reading; thus ssl2_read_internal may have to process
         * multiple packets before it can return. [Note that using select()
         * for blocking sockets *never* guarantees that the next SSL_read
         * will not block -- the available data may contain incomplete
         * packets, and except for SSL 2, renegotiation can confuse things
         * even more.]
         */

        goto ssl2_read_again;   /* This should really be "return
                                 * ssl2_read(s,buf,len)", but that would
                                 * allow for denial-of-service attacks if a C
                                 * compiler is used that does not recognize
                                 * end-recursion. */
    } else {
        SSLerr(SSL_F_SSL2_READ_INTERNAL, SSL_R_BAD_STATE);
        return (-1);
    }
}

int ssl2_read(SSL *s, void *buf, int len)
{
    return ssl2_read_internal(s, buf, len, 0);
}

int ssl2_peek(SSL *s, void *buf, int len)
{
    return ssl2_read_internal(s, buf, len, 1);
}

static int read_n(SSL *s, unsigned int n, unsigned int max,
                  unsigned int extend)
{
    int i, off, newb;

    /*
     * if there is stuff still in the buffer from a previous read, and there
     * is more than we want, take some.
     */
    if (s->s2->rbuf_left >= (int)n) {
        if (extend)
            s->packet_length += n;
        else {
            s->packet = &(s->s2->rbuf[s->s2->rbuf_offs]);
            s->packet_length = n;
        }
        s->s2->rbuf_left -= n;
        s->s2->rbuf_offs += n;
        return (n);
    }

    if (!s->read_ahead)
        max = n;
    if (max > (unsigned int)(SSL2_MAX_RECORD_LENGTH_2_BYTE_HEADER + 2))
        max = SSL2_MAX_RECORD_LENGTH_2_BYTE_HEADER + 2;

    /*
     * Else we want more than we have. First, if there is some left or we
     * want to extend
     */
    off = 0;
    if ((s->s2->rbuf_left != 0) || ((s->packet_length != 0) && extend)) {
        newb = s->s2->rbuf_left;
        if (extend) {
            off = s->packet_length;
            if (s->packet != s->s2->rbuf)
                memcpy(s->s2->rbuf, s->packet, (unsigned int)newb + off);
        } else if (s->s2->rbuf_offs != 0) {
            memcpy(s->s2->rbuf, &(s->s2->rbuf[s->s2->rbuf_offs]),
                   (unsigned int)newb);
            s->s2->rbuf_offs = 0;
        }
        s->s2->rbuf_left = 0;
    } else
        newb = 0;

    /*
     * off is the offset to start writing too. r->s2->rbuf_offs is the
     * 'unread data', now 0. newb is the number of new bytes so far
     */
    s->packet = s->s2->rbuf;
    while (newb < (int)n) {
        clear_sys_error();
        if (s->rbio != NULL) {
            s->rwstate = SSL_READING;
            i = BIO_read(s->rbio, (char *)&(s->s2->rbuf[off + newb]),
                         max - newb);
        } else {
            SSLerr(SSL_F_READ_N, SSL_R_READ_BIO_NOT_SET);
            i = -1;
        }
# ifdef PKT_DEBUG
        if (s->debug & 0x01)
            sleep(1);
# endif
        if (i <= 0) {
            s->s2->rbuf_left += newb;
            return (i);
        }
        newb += i;
    }

    /* record unread data */
    if (newb > (int)n) {
        s->s2->rbuf_offs = n + off;
        s->s2->rbuf_left = newb - n;
    } else {
        s->s2->rbuf_offs = 0;
        s->s2->rbuf_left = 0;
    }
    if (extend)
        s->packet_length += n;
    else
        s->packet_length = n;
    s->rwstate = SSL_NOTHING;
    return (n);
}

int ssl2_write(SSL *s, const void *_buf, int len)
{
    const unsigned char *buf = _buf;
    unsigned int n, tot;
    int i;

    if (SSL_in_init(s) && !s->in_handshake) {
        i = s->handshake_func(s);
        if (i < 0)
            return (i);
        if (i == 0) {
            SSLerr(SSL_F_SSL2_WRITE, SSL_R_SSL_HANDSHAKE_FAILURE);
            return (-1);
        }
    }

    if (s->error) {
        ssl2_write_error(s);
        if (s->error)
            return (-1);
    }

    clear_sys_error();
    s->rwstate = SSL_NOTHING;
    if (len <= 0)
        return (len);

    tot = s->s2->wnum;
    s->s2->wnum = 0;

    n = (len - tot);
    for (;;) {
        i = n_do_ssl_write(s, &(buf[tot]), n);
        if (i <= 0) {
            s->s2->wnum = tot;
            return (i);
        }
        if ((i == (int)n) || (s->mode & SSL_MODE_ENABLE_PARTIAL_WRITE)) {
            return (tot + i);
        }

        n -= i;
        tot += i;
    }
}

static int write_pending(SSL *s, const unsigned char *buf, unsigned int len)
{
    int i;

    /* s->s2->wpend_len != 0 MUST be true. */

    /*
     * check that they have given us the same buffer to write
     */
    if ((s->s2->wpend_tot > (int)len) ||
        ((s->s2->wpend_buf != buf) &&
         !(s->mode & SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER))) {
        SSLerr(SSL_F_WRITE_PENDING, SSL_R_BAD_WRITE_RETRY);
        return (-1);
    }

    for (;;) {
        clear_sys_error();
        if (s->wbio != NULL) {
            s->rwstate = SSL_WRITING;
            i = BIO_write(s->wbio,
                          (char *)&(s->s2->write_ptr[s->s2->wpend_off]),
                          (unsigned int)s->s2->wpend_len);
        } else {
            SSLerr(SSL_F_WRITE_PENDING, SSL_R_WRITE_BIO_NOT_SET);
            i = -1;
        }
# ifdef PKT_DEBUG
        if (s->debug & 0x01)
            sleep(1);
# endif
        if (i == s->s2->wpend_len) {
            s->s2->wpend_len = 0;
            s->rwstate = SSL_NOTHING;
            return (s->s2->wpend_ret);
        } else if (i <= 0)
            return (i);
        s->s2->wpend_off += i;
        s->s2->wpend_len -= i;
    }
}

static int n_do_ssl_write(SSL *s, const unsigned char *buf, unsigned int len)
{
    unsigned int j, k, olen, p, bs;
    int mac_size;
    register unsigned char *pp;

    olen = len;

    /*
     * first check if there is data from an encryption waiting to be sent -
     * it must be sent because the other end is waiting. This will happen
     * with non-blocking IO.  We print it and then return.
     */
    if (s->s2->wpend_len != 0)
        return (write_pending(s, buf, len));

    /* set mac_size to mac size */
    if (s->s2->clear_text)
        mac_size = 0;
    else {
        mac_size = EVP_MD_CTX_size(s->write_hash);
        if (mac_size < 0)
            return -1;
    }

    /* lets set the pad p */
    if (s->s2->clear_text) {
        if (len > SSL2_MAX_RECORD_LENGTH_2_BYTE_HEADER)
            len = SSL2_MAX_RECORD_LENGTH_2_BYTE_HEADER;
        p = 0;
        s->s2->three_byte_header = 0;
        /* len=len; */
    } else {
        bs = EVP_CIPHER_CTX_block_size(s->enc_read_ctx);
        j = len + mac_size;
        /*
         * Two-byte headers allow for a larger record length than three-byte
         * headers, but we can't use them if we need padding or if we have to
         * set the escape bit.
         */
        if ((j > SSL2_MAX_RECORD_LENGTH_3_BYTE_HEADER) && (!s->s2->escape)) {
            if (j > SSL2_MAX_RECORD_LENGTH_2_BYTE_HEADER)
                j = SSL2_MAX_RECORD_LENGTH_2_BYTE_HEADER;
            /*
             * set k to the max number of bytes with 2 byte header
             */
            k = j - (j % bs);
            /* how many data bytes? */
            len = k - mac_size;
            s->s2->three_byte_header = 0;
            p = 0;
        } else if ((bs <= 1) && (!s->s2->escape)) {
            /*-
             * j <= SSL2_MAX_RECORD_LENGTH_3_BYTE_HEADER, thus
             * j < SSL2_MAX_RECORD_LENGTH_2_BYTE_HEADER
             */
            s->s2->three_byte_header = 0;
            p = 0;
        } else {                /* we may have to use a 3 byte header */

            /*-
             * If s->s2->escape is not set, then
             * j <= SSL2_MAX_RECORD_LENGTH_3_BYTE_HEADER, and thus
             * j < SSL2_MAX_RECORD_LENGTH_2_BYTE_HEADER.
             */
            p = (j % bs);
            p = (p == 0) ? 0 : (bs - p);
            if (s->s2->escape) {
                s->s2->three_byte_header = 1;
                if (j > SSL2_MAX_RECORD_LENGTH_3_BYTE_HEADER)
                    j = SSL2_MAX_RECORD_LENGTH_3_BYTE_HEADER;
            } else
                s->s2->three_byte_header = (p == 0) ? 0 : 1;
        }
    }

    /*-
     * Now
     *      j <= SSL2_MAX_RECORD_LENGTH_2_BYTE_HEADER
     * holds, and if s->s2->three_byte_header is set, then even
     *      j <= SSL2_MAX_RECORD_LENGTH_3_BYTE_HEADER.
     */

    /*
     * mac_size is the number of MAC bytes len is the number of data bytes we
     * are going to send p is the number of padding bytes (if it is a
     * two-byte header, then p == 0)
     */

    s->s2->wlength = len;
    s->s2->padding = p;
    s->s2->mac_data = &(s->s2->wbuf[3]);
    s->s2->wact_data = &(s->s2->wbuf[3 + mac_size]);

    /*
     * It would be clearer to write this as follows:
     *     if (mac_size + len + p > SSL2_MAX_RECORD_LENGTH_2_BYTE_HEADER)
     * However |len| is user input that could in theory be very large. We
     * know |mac_size| and |p| are small, so to avoid any possibility of
     * overflow we write it like this.
     *
     * In theory this should never fail because the logic above should have
     * modified |len| if it is too big. But we are being cautious.
     */
    if (len > (SSL2_MAX_RECORD_LENGTH_2_BYTE_HEADER - (mac_size + p))) {
        return -1;
    }
    /* we copy the data into s->s2->wbuf */
    memcpy(s->s2->wact_data, buf, len);
    if (p)
        memset(&(s->s2->wact_data[len]), 0, p); /* arbitrary padding */

    if (!s->s2->clear_text) {
        s->s2->wact_data_length = len + p;
        ssl2_mac(s, s->s2->mac_data, 1);
        s->s2->wlength += p + mac_size;
        if (ssl2_enc(s, 1) < 1)
            return -1;
    }

    /* package up the header */
    s->s2->wpend_len = s->s2->wlength;
    if (s->s2->three_byte_header) { /* 3 byte header */
        pp = s->s2->mac_data;
        pp -= 3;
        pp[0] = (s->s2->wlength >> 8) & (THREE_BYTE_MASK >> 8);
        if (s->s2->escape)
            pp[0] |= SEC_ESC_BIT;
        pp[1] = s->s2->wlength & 0xff;
        pp[2] = s->s2->padding;
        s->s2->wpend_len += 3;
    } else {
        pp = s->s2->mac_data;
        pp -= 2;
        pp[0] = ((s->s2->wlength >> 8) & (TWO_BYTE_MASK >> 8)) | TWO_BYTE_BIT;
        pp[1] = s->s2->wlength & 0xff;
        s->s2->wpend_len += 2;
    }
    s->s2->write_ptr = pp;

    INC32(s->s2->write_sequence); /* expect next number */

    /* lets try to actually write the data */
    s->s2->wpend_tot = olen;
    s->s2->wpend_buf = buf;

    s->s2->wpend_ret = len;

    s->s2->wpend_off = 0;
    return (write_pending(s, buf, olen));
}

int ssl2_part_read(SSL *s, unsigned long f, int i)
{
    unsigned char *p;
    int j;

    if (i < 0) {
        /* ssl2_return_error(s); */
        /*
         * for non-blocking io, this is not necessarily fatal
         */
        return (i);
    } else {
        s->init_num += i;

        /*
         * Check for error.  While there are recoverable errors, this
         * function is not called when those must be expected; any error
         * detected here is fatal.
         */
        if (s->init_num >= 3) {
            p = (unsigned char *)s->init_buf->data;
            if (p[0] == SSL2_MT_ERROR) {
                j = (p[1] << 8) | p[2];
                SSLerr((int)f, ssl_mt_error(j));
                s->init_num -= 3;
                if (s->init_num > 0)
                    memmove(p, p + 3, s->init_num);
            }
        }

        /*
         * If it's not an error message, we have some error anyway -- the
         * message was shorter than expected.  This too is treated as fatal
         * (at least if SSL_get_error is asked for its opinion).
         */
        return (0);
    }
}

int ssl2_do_write(SSL *s)
{
    int ret;

    ret = ssl2_write(s, &s->init_buf->data[s->init_off], s->init_num);
    if (ret == s->init_num) {
        if (s->msg_callback)
            s->msg_callback(1, s->version, 0, s->init_buf->data,
                            (size_t)(s->init_off + s->init_num), s,
                            s->msg_callback_arg);
        return (1);
    }
    if (ret < 0)
        return (-1);
    s->init_off += ret;
    s->init_num -= ret;
    return (0);
}

static int ssl_mt_error(int n)
{
    int ret;

    switch (n) {
    case SSL2_PE_NO_CIPHER:
        ret = SSL_R_PEER_ERROR_NO_CIPHER;
        break;
    case SSL2_PE_NO_CERTIFICATE:
        ret = SSL_R_PEER_ERROR_NO_CERTIFICATE;
        break;
    case SSL2_PE_BAD_CERTIFICATE:
        ret = SSL_R_PEER_ERROR_CERTIFICATE;
        break;
    case SSL2_PE_UNSUPPORTED_CERTIFICATE_TYPE:
        ret = SSL_R_PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE;
        break;
    default:
        ret = SSL_R_UNKNOWN_REMOTE_ERROR_TYPE;
        break;
    }
    return (ret);
}
#else                           /* !OPENSSL_NO_SSL2 */

# if PEDANTIC
static void *dummy = &dummy;
# endif

#endif

ENEA — Copyright (C), ENEA. License: GNU AGPLv3+.
Legal notes  ::  JavaScript license information ::  Web API

back to top