xref: /freebsd/crypto/openssh/cipher.h (revision 80628bacb0b4bc1daaef4e038e755602c972bede)
180628bacSDag-Erling Smørgrav /*	$OpenBSD: cipher.h,v 1.33 2002/03/18 17:13:15 markus Exp $	*/
2af12a3e7SDag-Erling Smørgrav /*	$FreeBSD$	*/
3af12a3e7SDag-Erling Smørgrav 
4511b41d2SMark Murray /*
5511b41d2SMark Murray  * Author: Tatu Ylonen <ylo@cs.hut.fi>
6511b41d2SMark Murray  * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
7511b41d2SMark Murray  *                    All rights reserved
8511b41d2SMark Murray  *
9c2d3a559SKris Kennaway  * As far as I am concerned, the code I have written for this software
10c2d3a559SKris Kennaway  * can be used freely for any purpose.  Any derived versions of this
11c2d3a559SKris Kennaway  * software must be clearly marked as such, and if the derived work is
12c2d3a559SKris Kennaway  * incompatible with the protocol description in the RFC file, it must be
13c2d3a559SKris Kennaway  * called by a name other than "ssh" or "Secure Shell".
1409958426SBrian Feldman  *
1509958426SBrian Feldman  * Copyright (c) 2000 Markus Friedl.  All rights reserved.
1609958426SBrian Feldman  *
1709958426SBrian Feldman  * Redistribution and use in source and binary forms, with or without
1809958426SBrian Feldman  * modification, are permitted provided that the following conditions
1909958426SBrian Feldman  * are met:
2009958426SBrian Feldman  * 1. Redistributions of source code must retain the above copyright
2109958426SBrian Feldman  *    notice, this list of conditions and the following disclaimer.
2209958426SBrian Feldman  * 2. Redistributions in binary form must reproduce the above copyright
2309958426SBrian Feldman  *    notice, this list of conditions and the following disclaimer in the
2409958426SBrian Feldman  *    documentation and/or other materials provided with the distribution.
2509958426SBrian Feldman  *
2609958426SBrian Feldman  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
2709958426SBrian Feldman  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
2809958426SBrian Feldman  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
2909958426SBrian Feldman  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
3009958426SBrian Feldman  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
3109958426SBrian Feldman  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
3209958426SBrian Feldman  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
3309958426SBrian Feldman  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
3409958426SBrian Feldman  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
3509958426SBrian Feldman  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36511b41d2SMark Murray  */
37511b41d2SMark Murray 
38511b41d2SMark Murray #ifndef CIPHER_H
39511b41d2SMark Murray #define CIPHER_H
40511b41d2SMark Murray 
41af12a3e7SDag-Erling Smørgrav #include <openssl/evp.h>
4209958426SBrian Feldman /*
4309958426SBrian Feldman  * Cipher types for SSH-1.  New types can be added, but old types should not
4409958426SBrian Feldman  * be removed for compatibility.  The maximum allowed value is 31.
4509958426SBrian Feldman  */
4609958426SBrian Feldman #define SSH_CIPHER_SSH2		-3
47e8aafc91SKris Kennaway #define SSH_CIPHER_ILLEGAL	-2	/* No valid cipher selected. */
48511b41d2SMark Murray #define SSH_CIPHER_NOT_SET	-1	/* None selected (invalid number). */
49511b41d2SMark Murray #define SSH_CIPHER_NONE		0	/* no encryption */
50511b41d2SMark Murray #define SSH_CIPHER_IDEA		1	/* IDEA CFB */
51511b41d2SMark Murray #define SSH_CIPHER_DES		2	/* DES CBC */
52511b41d2SMark Murray #define SSH_CIPHER_3DES		3	/* 3DES CBC */
53511b41d2SMark Murray #define SSH_CIPHER_BROKEN_TSS	4	/* TRI's Simple Stream encryption CBC */
54511b41d2SMark Murray #define SSH_CIPHER_BROKEN_RC4	5	/* Alleged RC4 */
55511b41d2SMark Murray #define SSH_CIPHER_BLOWFISH	6
56e8aafc91SKris Kennaway #define SSH_CIPHER_RESERVED	7
5709958426SBrian Feldman #define SSH_CIPHER_MAX		31
58e8aafc91SKris Kennaway 
59af12a3e7SDag-Erling Smørgrav #define CIPHER_ENCRYPT		1
60af12a3e7SDag-Erling Smørgrav #define CIPHER_DECRYPT		0
61af12a3e7SDag-Erling Smørgrav 
6209958426SBrian Feldman typedef struct Cipher Cipher;
6309958426SBrian Feldman typedef struct CipherContext CipherContext;
64511b41d2SMark Murray 
65af12a3e7SDag-Erling Smørgrav struct Cipher;
6609958426SBrian Feldman struct CipherContext {
67af12a3e7SDag-Erling Smørgrav 	int	plaintext;
68af12a3e7SDag-Erling Smørgrav 	EVP_CIPHER_CTX evp;
6909958426SBrian Feldman 	Cipher *cipher;
7009958426SBrian Feldman };
71511b41d2SMark Murray 
72af12a3e7SDag-Erling Smørgrav u_int	 cipher_mask_ssh1(int);
73af12a3e7SDag-Erling Smørgrav Cipher	*cipher_by_name(const char *);
74af12a3e7SDag-Erling Smørgrav Cipher	*cipher_by_number(int);
75af12a3e7SDag-Erling Smørgrav int	 cipher_number(const char *);
76af12a3e7SDag-Erling Smørgrav char	*cipher_name(int);
77af12a3e7SDag-Erling Smørgrav int	 ciphers_valid(const char *);
78af12a3e7SDag-Erling Smørgrav void	 cipher_init(CipherContext *, Cipher *, const u_char *, u_int,
79af12a3e7SDag-Erling Smørgrav     const u_char *, u_int, int);
80af12a3e7SDag-Erling Smørgrav void	 cipher_crypt(CipherContext *, u_char *, const u_char *, u_int);
81af12a3e7SDag-Erling Smørgrav void	 cipher_cleanup(CipherContext *);
82af12a3e7SDag-Erling Smørgrav void	 cipher_set_key_string(CipherContext *, Cipher *, const char *, int);
83af12a3e7SDag-Erling Smørgrav u_int	 cipher_blocksize(Cipher *);
84af12a3e7SDag-Erling Smørgrav u_int	 cipher_keylen(Cipher *);
8580628bacSDag-Erling Smørgrav 
8680628bacSDag-Erling Smørgrav u_int	 cipher_get_number(Cipher *);
8780628bacSDag-Erling Smørgrav void	 cipher_get_keyiv(CipherContext *, u_char *, u_int);
8880628bacSDag-Erling Smørgrav void	 cipher_set_keyiv(CipherContext *, u_char *);
8980628bacSDag-Erling Smørgrav int	 cipher_get_keyiv_len(CipherContext *);
9080628bacSDag-Erling Smørgrav int	 cipher_get_keycontext(CipherContext *, u_char *);
9180628bacSDag-Erling Smørgrav void	 cipher_set_keycontext(CipherContext *, u_char *);
92511b41d2SMark Murray #endif				/* CIPHER_H */
93