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