xref: /netbsd-src/crypto/external/bsd/openssh/dist/cipher.h (revision d909946ca08dceb44d7d0f22ec9488679695d976)
1 /*	$NetBSD: cipher.h,v 1.8 2015/08/13 10:33:21 christos Exp $	*/
2 /* $OpenBSD: cipher.h,v 1.48 2015/07/08 19:09:25 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 <sys/types.h>
42 #include <openssl/evp.h>
43 #include "cipher-chachapoly.h"
44 #include "cipher-aesctr.h"
45 
46 /*
47  * Cipher types for SSH-1.  New types can be added, but old types should not
48  * be removed for compatibility.  The maximum allowed value is 31.
49  */
50 #define SSH_CIPHER_SSH2		-3
51 #define SSH_CIPHER_INVALID	-2	/* No valid cipher selected. */
52 #define SSH_CIPHER_NOT_SET	-1	/* None selected (invalid number). */
53 #define SSH_CIPHER_NONE		0	/* no encryption */
54 #define SSH_CIPHER_IDEA		1	/* IDEA CFB */
55 #define SSH_CIPHER_DES		2	/* DES CBC */
56 #define SSH_CIPHER_3DES		3	/* 3DES CBC */
57 #define SSH_CIPHER_BROKEN_TSS	4	/* TRI's Simple Stream encryption CBC */
58 #define SSH_CIPHER_BROKEN_RC4	5	/* Alleged RC4 */
59 #define SSH_CIPHER_BLOWFISH	6
60 #define SSH_CIPHER_RESERVED	7
61 #define SSH_CIPHER_MAX		31
62 
63 #define CIPHER_ENCRYPT		1
64 #define CIPHER_DECRYPT		0
65 
66 struct sshcipher;
67 struct sshcipher_ctx {
68 	int	plaintext;
69 	int	encrypt;
70 	EVP_CIPHER_CTX evp;
71 	struct chachapoly_ctx cp_ctx; /* XXX union with evp? */
72 	struct aesctr_ctx ac_ctx; /* XXX union with evp? */
73 	const struct sshcipher *cipher;
74 };
75 
76 u_int	 cipher_mask_ssh1(int);
77 const struct sshcipher *cipher_by_name(const char *);
78 const struct sshcipher *cipher_by_number(int);
79 int	 cipher_number(const char *);
80 const char	*cipher_name(int);
81 const char *cipher_warning_message(const struct sshcipher_ctx *);
82 int	 ciphers_valid(const char *);
83 char	*cipher_alg_list(char, int);
84 int	 cipher_init(struct sshcipher_ctx *, const struct sshcipher *,
85     const u_char *, u_int, const u_char *, u_int, int);
86 int	 cipher_crypt(struct sshcipher_ctx *, u_int, u_char *, const u_char *,
87     u_int, u_int, u_int);
88 int	 cipher_get_length(struct sshcipher_ctx *, u_int *, u_int,
89     const u_char *, u_int);
90 int	 cipher_cleanup(struct sshcipher_ctx *);
91 int	 cipher_set_key_string(struct sshcipher_ctx *, const struct sshcipher *,
92     const char *, int);
93 u_int	 cipher_blocksize(const struct sshcipher *);
94 u_int	 cipher_keylen(const struct sshcipher *);
95 u_int	 cipher_seclen(const struct sshcipher *);
96 u_int	 cipher_authlen(const struct sshcipher *);
97 u_int	 cipher_ivlen(const struct sshcipher *);
98 u_int	 cipher_is_cbc(const struct sshcipher *);
99 
100 u_int	 cipher_get_number(const struct sshcipher *);
101 int	 cipher_get_keyiv(struct sshcipher_ctx *, u_char *, u_int);
102 int	 cipher_set_keyiv(struct sshcipher_ctx *, const u_char *);
103 int	 cipher_get_keyiv_len(const struct sshcipher_ctx *);
104 int	 cipher_get_keycontext(const struct sshcipher_ctx *, u_char *);
105 void	 cipher_set_keycontext(struct sshcipher_ctx *, const u_char *);
106 #endif				/* CIPHER_H */
107