libssh 0.5.4
|
00001 /* 00002 * This file is part of the SSH Library 00003 * 00004 * Copyright (c) 2003,2009 by Aris Adamantiadis 00005 * 00006 * The SSH Library is free software; you can redistribute it and/or modify 00007 * it under the terms of the GNU Lesser General Public License as published by 00008 * the Free Software Foundation; either version 2.1 of the License, or (at your 00009 * option) any later version. 00010 * 00011 * The SSH Library is distributed in the hope that it will be useful, but 00012 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 00013 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 00014 * License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public License 00017 * along with the SSH Library; see the file COPYING. If not, write to 00018 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, 00019 * MA 02111-1307, USA. 00020 */ 00021 00022 /* 00023 * crypto.h is an include file for internal cryptographic structures of libssh 00024 */ 00025 00026 #ifndef _CRYPTO_H_ 00027 #define _CRYPTO_H_ 00028 00029 #include "config.h" 00030 00031 #ifdef HAVE_LIBGCRYPT 00032 #include <gcrypt.h> 00033 #endif 00034 #include "libssh/wrapper.h" 00035 00036 #ifdef cbc_encrypt 00037 #undef cbc_encrypt 00038 #endif 00039 #ifdef cbc_decrypt 00040 #undef cbc_decrypt 00041 #endif 00042 00043 struct ssh_crypto_struct { 00044 bignum e,f,x,k,y; 00045 unsigned char session_id[SHA_DIGEST_LEN]; 00046 00047 unsigned char encryptIV[SHA_DIGEST_LEN*2]; 00048 unsigned char decryptIV[SHA_DIGEST_LEN*2]; 00049 00050 unsigned char decryptkey[SHA_DIGEST_LEN*2]; 00051 unsigned char encryptkey[SHA_DIGEST_LEN*2]; 00052 00053 unsigned char encryptMAC[SHA_DIGEST_LEN]; 00054 unsigned char decryptMAC[SHA_DIGEST_LEN]; 00055 unsigned char hmacbuf[EVP_MAX_MD_SIZE]; 00056 struct crypto_struct *in_cipher, *out_cipher; /* the cipher structures/objects */ 00057 ssh_string server_pubkey; 00058 const char *server_pubkey_type; 00059 int do_compress_out; /* idem */ 00060 int do_compress_in; /* don't set them, set the option instead */ 00061 int delayed_compress_in; /* Use of zlib@openssh.org */ 00062 int delayed_compress_out; 00063 void *compress_out_ctx; /* don't touch it */ 00064 void *compress_in_ctx; /* really, don't */ 00065 }; 00066 00067 struct crypto_struct { 00068 const char *name; /* ssh name of the algorithm */ 00069 unsigned int blocksize; /* blocksize of the algo */ 00070 unsigned int keylen; /* length of the key structure */ 00071 #ifdef HAVE_LIBGCRYPT 00072 gcry_cipher_hd_t *key; 00073 #elif defined HAVE_LIBCRYPTO 00074 void *key; /* a key buffer allocated for the algo */ 00075 #endif 00076 unsigned int keysize; /* bytes of key used. != keylen */ 00077 #ifdef HAVE_LIBGCRYPT 00078 /* sets the new key for immediate use */ 00079 int (*set_encrypt_key)(struct crypto_struct *cipher, void *key, void *IV); 00080 int (*set_decrypt_key)(struct crypto_struct *cipher, void *key, void *IV); 00081 void (*cbc_encrypt)(struct crypto_struct *cipher, void *in, void *out, 00082 unsigned long len); 00083 void (*cbc_decrypt)(struct crypto_struct *cipher, void *in, void *out, 00084 unsigned long len); 00085 #elif defined HAVE_LIBCRYPTO 00086 /* sets the new key for immediate use */ 00087 int (*set_encrypt_key)(struct crypto_struct *cipher, void *key); 00088 int (*set_decrypt_key)(struct crypto_struct *cipher, void *key); 00089 void (*cbc_encrypt)(struct crypto_struct *cipher, void *in, void *out, 00090 unsigned long len, void *IV); 00091 void (*cbc_decrypt)(struct crypto_struct *cipher, void *in, void *out, 00092 unsigned long len, void *IV); 00093 #endif 00094 }; 00095 00096 /* vim: set ts=2 sw=2 et cindent: */ 00097 #endif /* _CRYPTO_H_ */