xref: /netbsd-src/crypto/external/bsd/openssh/dist/cipher.h (revision 7d62b00eb9ad855ffcd7da46b41e23feb5476fac)
1 /*	$NetBSD: cipher.h,v 1.15 2020/02/27 00:24:40 christos Exp $	*/
2 /* $OpenBSD: cipher.h,v 1.55 2020/01/23 10:24:29 dtucker 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 #ifdef WITH_OPENSSL
43 #include <openssl/evp.h>
44 #endif
45 #include "cipher-chachapoly.h"
46 #include "cipher-aesctr.h"
47 
48 #define CIPHER_ENCRYPT		1
49 #define CIPHER_DECRYPT		0
50 
51 struct sshcipher;
52 #if 0
53 struct sshcipher_ctx {
54 	int	plaintext;
55 	int	encrypt;
56 	EVP_CIPHER_CTX *evp;
57 	struct chachapoly_ctx cp_ctx; /* XXX union with evp? */
58 	struct aesctr_ctx ac_ctx; /* XXX union with evp? */
59 	const struct sshcipher *cipher;
60 };
61 #else
62 struct sshcipher_ctx;
63 #endif
64 
65 const struct sshcipher *cipher_by_name(const char *);
66 const char *cipher_warning_message(const struct sshcipher_ctx *);
67 int	 ciphers_valid(const char *);
68 char	*cipher_alg_list(char, int);
69 const char *compression_alg_list(int);
70 int	 cipher_init(struct sshcipher_ctx **, const struct sshcipher *,
71     const u_char *, u_int, const u_char *, u_int, int);
72 int	 cipher_crypt(struct sshcipher_ctx *, u_int, u_char *, const u_char *,
73     u_int, u_int, u_int);
74 int	 cipher_get_length(struct sshcipher_ctx *, u_int *, u_int,
75     const u_char *, u_int);
76 void	 cipher_free(struct sshcipher_ctx *);
77 u_int	 cipher_blocksize(const struct sshcipher *);
78 u_int	 cipher_keylen(const struct sshcipher *);
79 u_int	 cipher_seclen(const struct sshcipher *);
80 u_int	 cipher_authlen(const struct sshcipher *);
81 u_int	 cipher_ivlen(const struct sshcipher *);
82 u_int	 cipher_is_cbc(const struct sshcipher *);
83 
84 u_int	 cipher_ctx_is_plaintext(struct sshcipher_ctx *);
85 
86 int	 cipher_get_keyiv(struct sshcipher_ctx *, u_char *, size_t);
87 int	 cipher_set_keyiv(struct sshcipher_ctx *, const u_char *, size_t);
88 int	 cipher_get_keyiv_len(const struct sshcipher_ctx *);
89 
90 #endif				/* CIPHER_H */
91