1262566Sdes/* $OpenBSD: cipher.h,v 1.44 2014/01/25 10:12:50 dtucker Exp $ */
292559Sdes
357429Smarkm/*
457429Smarkm * Author: Tatu Ylonen <ylo@cs.hut.fi>
557429Smarkm * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
657429Smarkm *                    All rights reserved
760576Skris *
865674Skris * As far as I am concerned, the code I have written for this software
965674Skris * can be used freely for any purpose.  Any derived versions of this
1065674Skris * software must be clearly marked as such, and if the derived work is
1165674Skris * incompatible with the protocol description in the RFC file, it must be
1265674Skris * called by a name other than "ssh" or "Secure Shell".
1369591Sgreen *
1469591Sgreen * Copyright (c) 2000 Markus Friedl.  All rights reserved.
1569591Sgreen *
1669591Sgreen * Redistribution and use in source and binary forms, with or without
1769591Sgreen * modification, are permitted provided that the following conditions
1869591Sgreen * are met:
1969591Sgreen * 1. Redistributions of source code must retain the above copyright
2069591Sgreen *    notice, this list of conditions and the following disclaimer.
2169591Sgreen * 2. Redistributions in binary form must reproduce the above copyright
2269591Sgreen *    notice, this list of conditions and the following disclaimer in the
2369591Sgreen *    documentation and/or other materials provided with the distribution.
2469591Sgreen *
2569591Sgreen * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
2669591Sgreen * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
2769591Sgreen * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
2869591Sgreen * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
2969591Sgreen * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
3069591Sgreen * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
3169591Sgreen * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
3269591Sgreen * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
3369591Sgreen * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
3469591Sgreen * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3557429Smarkm */
3657429Smarkm
3757429Smarkm#ifndef CIPHER_H
3857429Smarkm#define CIPHER_H
3957429Smarkm
4092559Sdes#include <openssl/evp.h>
41262566Sdes#include "cipher-chachapoly.h"
42262566Sdes
4369591Sgreen/*
4469591Sgreen * Cipher types for SSH-1.  New types can be added, but old types should not
4569591Sgreen * be removed for compatibility.  The maximum allowed value is 31.
4669591Sgreen */
4769591Sgreen#define SSH_CIPHER_SSH2		-3
48137019Sdes#define SSH_CIPHER_INVALID	-2	/* No valid cipher selected. */
4957429Smarkm#define SSH_CIPHER_NOT_SET	-1	/* None selected (invalid number). */
5057429Smarkm#define SSH_CIPHER_NONE		0	/* no encryption */
5157429Smarkm#define SSH_CIPHER_IDEA		1	/* IDEA CFB */
5257429Smarkm#define SSH_CIPHER_DES		2	/* DES CBC */
5357429Smarkm#define SSH_CIPHER_3DES		3	/* 3DES CBC */
5457429Smarkm#define SSH_CIPHER_BROKEN_TSS	4	/* TRI's Simple Stream encryption CBC */
5557429Smarkm#define SSH_CIPHER_BROKEN_RC4	5	/* Alleged RC4 */
5657429Smarkm#define SSH_CIPHER_BLOWFISH	6
5760576Skris#define SSH_CIPHER_RESERVED	7
5869591Sgreen#define SSH_CIPHER_MAX		31
5957429Smarkm
6092559Sdes#define CIPHER_ENCRYPT		1
6192559Sdes#define CIPHER_DECRYPT		0
6292559Sdes
6369591Sgreentypedef struct Cipher Cipher;
6469591Sgreentypedef struct CipherContext CipherContext;
6560576Skris
6692559Sdesstruct Cipher;
6769591Sgreenstruct CipherContext {
6892559Sdes	int	plaintext;
69248619Sdes	int	encrypt;
7092559Sdes	EVP_CIPHER_CTX evp;
71262566Sdes	struct chachapoly_ctx cp_ctx; /* XXX union with evp? */
72255767Sdes	const Cipher *cipher;
7369591Sgreen};
7457429Smarkm
7592559Sdesu_int	 cipher_mask_ssh1(int);
76255767Sdesconst Cipher	*cipher_by_name(const char *);
77255767Sdesconst Cipher	*cipher_by_number(int);
7892559Sdesint	 cipher_number(const char *);
7992559Sdeschar	*cipher_name(int);
8092559Sdesint	 ciphers_valid(const char *);
81262566Sdeschar	*cipher_alg_list(char, int);
82255767Sdesvoid	 cipher_init(CipherContext *, const Cipher *, const u_char *, u_int,
8392559Sdes    const u_char *, u_int, int);
84262566Sdesint	 cipher_crypt(CipherContext *, u_int, u_char *, const u_char *,
85248619Sdes    u_int, u_int, u_int);
86262566Sdesint	 cipher_get_length(CipherContext *, u_int *, u_int,
87262566Sdes    const u_char *, u_int);
8892559Sdesvoid	 cipher_cleanup(CipherContext *);
89255767Sdesvoid	 cipher_set_key_string(CipherContext *, const Cipher *, const char *, int);
90126277Sdesu_int	 cipher_blocksize(const Cipher *);
91126277Sdesu_int	 cipher_keylen(const Cipher *);
92262566Sdesu_int	 cipher_seclen(const Cipher *);
93248619Sdesu_int	 cipher_authlen(const Cipher *);
94248619Sdesu_int	 cipher_ivlen(const Cipher *);
95192595Sdesu_int	 cipher_is_cbc(const Cipher *);
9698684Sdes
97126277Sdesu_int	 cipher_get_number(const Cipher *);
9898684Sdesvoid	 cipher_get_keyiv(CipherContext *, u_char *, u_int);
9998684Sdesvoid	 cipher_set_keyiv(CipherContext *, u_char *);
100126277Sdesint	 cipher_get_keyiv_len(const CipherContext *);
101126277Sdesint	 cipher_get_keycontext(const CipherContext *, u_char *);
10298684Sdesvoid	 cipher_set_keycontext(CipherContext *, u_char *);
10357429Smarkm#endif				/* CIPHER_H */
104