cipher.h revision 1.12
1/*	$NetBSD: cipher.h,v 1.12 2018/02/05 00:13:50 christos Exp $	*/
2/* $OpenBSD: cipher.h,v 1.52 2017/05/07 23:12:57 djm 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#define CIPHER_ENCRYPT		1
47#define CIPHER_DECRYPT		0
48
49struct sshcipher;
50#if 0
51struct sshcipher_ctx {
52	int	plaintext;
53	int	encrypt;
54	EVP_CIPHER_CTX *evp;
55	struct chachapoly_ctx cp_ctx; /* XXX union with evp? */
56	struct aesctr_ctx ac_ctx; /* XXX union with evp? */
57	const struct sshcipher *cipher;
58};
59#else
60struct sshcipher_ctx;
61#endif
62
63const struct sshcipher *cipher_by_name(const char *);
64const char *cipher_warning_message(const struct sshcipher_ctx *);
65int	 ciphers_valid(const char *);
66char	*cipher_alg_list(char, int);
67int	 cipher_init(struct sshcipher_ctx **, const struct sshcipher *,
68    const u_char *, u_int, const u_char *, u_int, int);
69int	 cipher_crypt(struct sshcipher_ctx *, u_int, u_char *, const u_char *,
70    u_int, u_int, u_int);
71int	 cipher_get_length(struct sshcipher_ctx *, u_int *, u_int,
72    const u_char *, u_int);
73void	 cipher_free(struct sshcipher_ctx *);
74u_int	 cipher_blocksize(const struct sshcipher *);
75u_int	 cipher_keylen(const struct sshcipher *);
76u_int	 cipher_seclen(const struct sshcipher *);
77u_int	 cipher_authlen(const struct sshcipher *);
78u_int	 cipher_ivlen(const struct sshcipher *);
79u_int	 cipher_is_cbc(const struct sshcipher *);
80
81u_int	 cipher_ctx_is_plaintext(struct sshcipher_ctx *);
82
83int	 cipher_get_keyiv(struct sshcipher_ctx *, u_char *, u_int);
84int	 cipher_set_keyiv(struct sshcipher_ctx *, const u_char *);
85int	 cipher_get_keyiv_len(const struct sshcipher_ctx *);
86
87#endif				/* CIPHER_H */
88