📄 yassl_types.hpp
字号:
/* yassl_types.hpp
*
* Copyright (C) 2003 Sawtooth Consulting Ltd.
*
* This file is part of yaSSL.
*
* yaSSL is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* yaSSL is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
/* yaSSL types header defines all constants, enums, and typedefs
* from the SSL.v3 specification "draft-freier-ssl-version3-02.txt"
*/
#ifndef yaSSL_TYPES_HPP
#define yaSSL_TYPES_HPP
#include <stddef.h>
#include <assert.h>
#include "type_traits.hpp"
namespace yaSSL {
#ifdef YASSL_PURE_C
// library allocation
struct new_t {}; // yaSSL New type
extern new_t ys; // pass in parameter
} // namespace yaSSL
void* operator new (size_t, yaSSL::new_t);
void* operator new[](size_t, yaSSL::new_t);
void operator delete (void*, yaSSL::new_t);
void operator delete[](void*, yaSSL::new_t);
namespace yaSSL {
template<typename T>
void ysDelete(T* ptr)
{
if (ptr) ptr->~T();
::operator delete(ptr, yaSSL::ys);
}
template<typename T>
void ysArrayDelete(T* ptr)
{
// can't do array placement destruction since not tracking size in
// allocation, only allow builtins to use array placement since they
// don't need destructors called
typedef char builtin[TaoCrypt::IsFundamentalType<T>::Yes ? 1 : -1];
(void)sizeof(builtin);
::operator delete[](ptr, yaSSL::ys);
}
#define NEW_YS new (ys)
// to resolve compiler generated operator delete on base classes with
// virtual destructors (when on stack), make sure doesn't get called
class virtual_base {
public:
static void operator delete(void*) { assert(0); }
};
#else // YASSL_PURE_C
template<typename T>
void ysDelete(T* ptr)
{
delete ptr;
}
template<typename T>
void ysArrayDelete(T* ptr)
{
delete[] ptr;
}
#define NEW_YS new
class virtual_base {};
#endif // YASSL_PURE_C
typedef unsigned char uint8;
typedef unsigned short uint16;
typedef unsigned int uint32;
typedef uint8 uint24[3];
typedef uint32 uint64[2];
typedef uint8 opaque;
typedef opaque byte;
typedef unsigned int uint;
// all length constants in bytes
const int ID_LEN = 32; // session id length
const int SUITE_LEN = 2; // cipher suite length
const int SECRET_LEN = 48; // pre RSA and all master secret length
const int MASTER_ROUNDS = 3; // master secret derivation rounds
const int RAN_LEN = 32; // client and server random length
const int MAC_BLOCK_SZ = 64; // MAC block size, & padding
const int MD5_LEN = 16; // MD5 digest length
const int SHA_LEN = 20; // SHA digest length
const int RMD_LEN = 20; // RIPEMD-160 digest length
const int PREFIX = 3; // up to 3 prefix letters for secret rounds
const int KEY_PREFIX = 7; // up to 7 prefix letters for key rounds
const int FORTEZZA_MAX = 128; // Maximum Fortezza Key length
const int MAX_SUITE_SZ = 64; // 32 max suites * sizeof(suite)
const int MAX_SUITE_NAME = 48; // max length of suite name
const int MAX_CIPHERS = 32; // max supported ciphers for cipher list
const int SIZEOF_ENUM = 1; // SSL considers an enum 1 byte, not 4
const int SIZEOF_SENDER = 4; // Sender constant, for finished generation
const int PAD_MD5 = 48; // pad length 1 and 2 for md5 finished
const int PAD_SHA = 40; // should be 44, specd wrong by netscape
const int PAD_RMD = 44; // pad length for RIPEMD-160, some use 40??
const int CERT_HEADER = 3; // always use 3 bytes for certificate
const int CERT_TYPES = 7; // certificate request types
const int REQUEST_HEADER = 2; // request uses 2 bytes
const int VERIFY_HEADER = 2; // verify length field
const int MIN_CERT_TYPES = 1; // minimum certificate request types
const int MIN_DIS_NAMES = 3; // minimum distinguished names
const int MIN_DIS_SIZE = 1; // minimum distinguished name size
const int RECORD_HEADER = 5; // type + version + length(2)
const int HANDSHAKE_HEADER = 4; // type + length(3)
const int FINISHED_SZ = MD5_LEN + SHA_LEN; // sizeof finished data
const int TLS_FINISHED_SZ = 12; // TLS verify data size
const int SEQ_SZ = 8; // 64 bit sequence number
const int LENGTH_SZ = 2; // length field for HMAC, data only
const int VERSION_SZ = SIZEOF_ENUM * 2; // SSL/TLS length of version
const int DES_KEY_SZ = 8; // DES Key length
const int DES_EDE_KEY_SZ = 24; // DES EDE Key length
const int DES_BLOCK = 8; // DES is always fixed block size 8
const int DES_IV_SZ = DES_BLOCK; // Init Vector length for DES
const int RC4_KEY_SZ = 16; // RC4 Key length
const int AES_128_KEY_SZ = 16; // AES 128bit Key length
const int AES_256_KEY_SZ = 32; // AES 256bit Key length
const int AES_BLOCK_SZ = 16; // AES 128bit block size, rfc 3268
const int AES_IV_SZ = AES_BLOCK_SZ; // AES Init Vector length
const int DSS_SIG_SZ = 40; // two 20 byte high byte first Integers
const int DSS_ENCODED_EXTRA = 6; // seqID + len(1) + (intID + len(1)) * 2
const int EVP_SALT_SZ = 8;
const int MASTER_LABEL_SZ = 13; // TLS master secret label size
const int KEY_LABEL_SZ = 13; // TLS key block expansion size
const int FINISHED_LABEL_SZ = 15; // TLS finished lable length
const int SEED_LEN = RAN_LEN * 2; // TLS seed, client + server random
const int DEFAULT_TIMEOUT = 500; // Default Session timeout in seconds
const int MAX_RECORD_SIZE = 16384; // 2^14, max size by standard
typedef uint8 Cipher; // first byte is always 0x00 for SSLv3 & TLS
typedef opaque Random[RAN_LEN];
typedef opaque* DistinguishedName;
typedef bool IsExportable;
enum CompressionMethod { no_compression = 0 };
enum CipherType { stream, block };
enum CipherChoice { change_cipher_spec_choice = 1 };
enum PublicValueEncoding { implicit_encoding, explicit_encoding };
enum ConnectionEnd { server_end, client_end };
enum AlertLevel { warning = 1, fatal = 2 };
// Record Layer Header identifier from page 12
enum ContentType {
no_type = 0,
change_cipher_spec = 20,
alert = 21,
handshake = 22,
application_data = 23
};
// HandShake Layer Header identifier from page 20
enum HandShakeType {
no_shake = -1,
hello_request = 0,
client_hello = 1,
server_hello = 2,
certificate = 11,
server_key_exchange = 12,
certificate_request = 13,
server_hello_done = 14,
certificate_verify = 15,
client_key_exchange = 16,
finished = 20
};
// Valid Alert types from page 16/17
enum AlertDescription {
close_notify = 0,
unexpected_message = 10,
bad_record_mac = 20,
decompression_failure = 30,
handshake_failure = 40,
no_certificate = 41,
bad_certificate = 42,
unsupported_certificate = 43,
certificate_revoked = 44,
certificate_expired = 45,
certificate_unknown = 46,
illegal_parameter = 47
};
// Supported Key Exchange Protocols
enum KeyExchangeAlgorithm {
no_kea = 0,
rsa_kea,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -