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