xref: /freebsd/crypto/openssh/cipher.h (revision 2b15cb3d0922bd70ea592f0da9b4a5b167f4d53f)
1 /* $OpenBSD: cipher.h,v 1.44 2014/01/25 10:12:50 dtucker Exp $ */
2 
3 /*
4  * Author: Tatu Ylonen <ylo@cs.hut.fi>
5  * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
6  *                    All rights reserved
7  *
8  * As far as I am concerned, the code I have written for this software
9  * can be used freely for any purpose.  Any derived versions of this
10  * software must be clearly marked as such, and if the derived work is
11  * incompatible with the protocol description in the RFC file, it must be
12  * called by a name other than "ssh" or "Secure Shell".
13  *
14  * Copyright (c) 2000 Markus Friedl.  All rights reserved.
15  *
16  * Redistribution and use in source and binary forms, with or without
17  * modification, are permitted provided that the following conditions
18  * are met:
19  * 1. Redistributions of source code must retain the above copyright
20  *    notice, this list of conditions and the following disclaimer.
21  * 2. Redistributions in binary form must reproduce the above copyright
22  *    notice, this list of conditions and the following disclaimer in the
23  *    documentation and/or other materials provided with the distribution.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
26  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
27  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
28  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
29  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
30  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
34  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35  */
36 
37 #ifndef CIPHER_H
38 #define CIPHER_H
39 
40 #include <openssl/evp.h>
41 #include "cipher-chachapoly.h"
42 
43 /*
44  * Cipher types for SSH-1.  New types can be added, but old types should not
45  * be removed for compatibility.  The maximum allowed value is 31.
46  */
47 #define SSH_CIPHER_SSH2		-3
48 #define SSH_CIPHER_INVALID	-2	/* No valid cipher selected. */
49 #define SSH_CIPHER_NOT_SET	-1	/* None selected (invalid number). */
50 #define SSH_CIPHER_NONE		0	/* no encryption */
51 #define SSH_CIPHER_IDEA		1	/* IDEA CFB */
52 #define SSH_CIPHER_DES		2	/* DES CBC */
53 #define SSH_CIPHER_3DES		3	/* 3DES CBC */
54 #define SSH_CIPHER_BROKEN_TSS	4	/* TRI's Simple Stream encryption CBC */
55 #define SSH_CIPHER_BROKEN_RC4	5	/* Alleged RC4 */
56 #define SSH_CIPHER_BLOWFISH	6
57 #define SSH_CIPHER_RESERVED	7
58 #define SSH_CIPHER_MAX		31
59 
60 #define CIPHER_ENCRYPT		1
61 #define CIPHER_DECRYPT		0
62 
63 typedef struct Cipher Cipher;
64 typedef struct CipherContext CipherContext;
65 
66 struct Cipher;
67 struct CipherContext {
68 	int	plaintext;
69 	int	encrypt;
70 	EVP_CIPHER_CTX evp;
71 	struct chachapoly_ctx cp_ctx; /* XXX union with evp? */
72 	const Cipher *cipher;
73 };
74 
75 u_int	 cipher_mask_ssh1(int);
76 const Cipher	*cipher_by_name(const char *);
77 const Cipher	*cipher_by_number(int);
78 int	 cipher_number(const char *);
79 char	*cipher_name(int);
80 int	 ciphers_valid(const char *);
81 char	*cipher_alg_list(char, int);
82 void	 cipher_init(CipherContext *, const Cipher *, const u_char *, u_int,
83     const u_char *, u_int, int);
84 int	 cipher_crypt(CipherContext *, u_int, u_char *, const u_char *,
85     u_int, u_int, u_int);
86 int	 cipher_get_length(CipherContext *, u_int *, u_int,
87     const u_char *, u_int);
88 void	 cipher_cleanup(CipherContext *);
89 void	 cipher_set_key_string(CipherContext *, const Cipher *, const char *, int);
90 u_int	 cipher_blocksize(const Cipher *);
91 u_int	 cipher_keylen(const Cipher *);
92 u_int	 cipher_seclen(const Cipher *);
93 u_int	 cipher_authlen(const Cipher *);
94 u_int	 cipher_ivlen(const Cipher *);
95 u_int	 cipher_is_cbc(const Cipher *);
96 
97 u_int	 cipher_get_number(const Cipher *);
98 void	 cipher_get_keyiv(CipherContext *, u_char *, u_int);
99 void	 cipher_set_keyiv(CipherContext *, u_char *);
100 int	 cipher_get_keyiv_len(const CipherContext *);
101 int	 cipher_get_keycontext(const CipherContext *, u_char *);
102 void	 cipher_set_keycontext(CipherContext *, u_char *);
103 #endif				/* CIPHER_H */
104