libssh  0.5.4
crypto.h
1 /*
2  * This file is part of the SSH Library
3  *
4  * Copyright (c) 2003,2009 by Aris Adamantiadis
5  *
6  * The SSH Library is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation; either version 2.1 of the License, or (at your
9  * option) any later version.
10  *
11  * The SSH Library is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14  * License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with the SSH Library; see the file COPYING. If not, write to
18  * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
19  * MA 02111-1307, USA.
20  */
21 
22 /*
23  * crypto.h is an include file for internal cryptographic structures of libssh
24  */
25 
26 #ifndef _CRYPTO_H_
27 #define _CRYPTO_H_
28 
29 #include "config.h"
30 
31 #ifdef HAVE_LIBGCRYPT
32 #include <gcrypt.h>
33 #endif
34 #include "libssh/wrapper.h"
35 
36 #ifdef cbc_encrypt
37 #undef cbc_encrypt
38 #endif
39 #ifdef cbc_decrypt
40 #undef cbc_decrypt
41 #endif
42 
43 struct ssh_crypto_struct {
44  bignum e,f,x,k,y;
45  unsigned char session_id[SHA_DIGEST_LEN];
46 
47  unsigned char encryptIV[SHA_DIGEST_LEN*2];
48  unsigned char decryptIV[SHA_DIGEST_LEN*2];
49 
50  unsigned char decryptkey[SHA_DIGEST_LEN*2];
51  unsigned char encryptkey[SHA_DIGEST_LEN*2];
52 
53  unsigned char encryptMAC[SHA_DIGEST_LEN];
54  unsigned char decryptMAC[SHA_DIGEST_LEN];
55  unsigned char hmacbuf[EVP_MAX_MD_SIZE];
56  struct crypto_struct *in_cipher, *out_cipher; /* the cipher structures/objects */
57  ssh_string server_pubkey;
58  const char *server_pubkey_type;
59  int do_compress_out; /* idem */
60  int do_compress_in; /* don't set them, set the option instead */
61  int delayed_compress_in; /* Use of zlib@openssh.org */
62  int delayed_compress_out;
63  void *compress_out_ctx; /* don't touch it */
64  void *compress_in_ctx; /* really, don't */
65 };
66 
67 struct crypto_struct {
68  const char *name; /* ssh name of the algorithm */
69  unsigned int blocksize; /* blocksize of the algo */
70  unsigned int keylen; /* length of the key structure */
71 #ifdef HAVE_LIBGCRYPT
72  gcry_cipher_hd_t *key;
73 #elif defined HAVE_LIBCRYPTO
74  void *key; /* a key buffer allocated for the algo */
75 #endif
76  unsigned int keysize; /* bytes of key used. != keylen */
77 #ifdef HAVE_LIBGCRYPT
78  /* sets the new key for immediate use */
79  int (*set_encrypt_key)(struct crypto_struct *cipher, void *key, void *IV);
80  int (*set_decrypt_key)(struct crypto_struct *cipher, void *key, void *IV);
81  void (*cbc_encrypt)(struct crypto_struct *cipher, void *in, void *out,
82  unsigned long len);
83  void (*cbc_decrypt)(struct crypto_struct *cipher, void *in, void *out,
84  unsigned long len);
85 #elif defined HAVE_LIBCRYPTO
86  /* sets the new key for immediate use */
87  int (*set_encrypt_key)(struct crypto_struct *cipher, void *key);
88  int (*set_decrypt_key)(struct crypto_struct *cipher, void *key);
89  void (*cbc_encrypt)(struct crypto_struct *cipher, void *in, void *out,
90  unsigned long len, void *IV);
91  void (*cbc_decrypt)(struct crypto_struct *cipher, void *in, void *out,
92  unsigned long len, void *IV);
93 #endif
94 };
95 
96 /* vim: set ts=2 sw=2 et cindent: */
97 #endif /* _CRYPTO_H_ */