1295367Sdes/* $OpenBSD: cipher.h,v 1.48 2015/07/08 19:09:25 markus 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 40295367Sdes#include <sys/types.h> 4192559Sdes#include <openssl/evp.h> 42262566Sdes#include "cipher-chachapoly.h" 43295367Sdes#include "cipher-aesctr.h" 44262566Sdes 4569591Sgreen/* 4669591Sgreen * Cipher types for SSH-1. New types can be added, but old types should not 4769591Sgreen * be removed for compatibility. The maximum allowed value is 31. 4869591Sgreen */ 4969591Sgreen#define SSH_CIPHER_SSH2 -3 50137019Sdes#define SSH_CIPHER_INVALID -2 /* No valid cipher selected. */ 5157429Smarkm#define SSH_CIPHER_NOT_SET -1 /* None selected (invalid number). */ 5257429Smarkm#define SSH_CIPHER_NONE 0 /* no encryption */ 5357429Smarkm#define SSH_CIPHER_IDEA 1 /* IDEA CFB */ 5457429Smarkm#define SSH_CIPHER_DES 2 /* DES CBC */ 5557429Smarkm#define SSH_CIPHER_3DES 3 /* 3DES CBC */ 5657429Smarkm#define SSH_CIPHER_BROKEN_TSS 4 /* TRI's Simple Stream encryption CBC */ 5757429Smarkm#define SSH_CIPHER_BROKEN_RC4 5 /* Alleged RC4 */ 5857429Smarkm#define SSH_CIPHER_BLOWFISH 6 5960576Skris#define SSH_CIPHER_RESERVED 7 6069591Sgreen#define SSH_CIPHER_MAX 31 6157429Smarkm 6292559Sdes#define CIPHER_ENCRYPT 1 6392559Sdes#define CIPHER_DECRYPT 0 6492559Sdes 65295367Sdesstruct sshcipher; 66295367Sdesstruct sshcipher_ctx { 6792559Sdes int plaintext; 68248619Sdes int encrypt; 6992559Sdes EVP_CIPHER_CTX evp; 70262566Sdes struct chachapoly_ctx cp_ctx; /* XXX union with evp? */ 71295367Sdes struct aesctr_ctx ac_ctx; /* XXX union with evp? */ 72295367Sdes const struct sshcipher *cipher; 7369591Sgreen}; 7457429Smarkm 7592559Sdesu_int cipher_mask_ssh1(int); 76295367Sdesconst struct sshcipher *cipher_by_name(const char *); 77295367Sdesconst struct sshcipher *cipher_by_number(int); 7892559Sdesint cipher_number(const char *); 7992559Sdeschar *cipher_name(int); 80295367Sdesconst char *cipher_warning_message(const struct sshcipher_ctx *); 8192559Sdesint ciphers_valid(const char *); 82262566Sdeschar *cipher_alg_list(char, int); 83295367Sdesint cipher_init(struct sshcipher_ctx *, const struct sshcipher *, 84295367Sdes const u_char *, u_int, const u_char *, u_int, int); 85295367Sdesint cipher_crypt(struct sshcipher_ctx *, u_int, u_char *, const u_char *, 86248619Sdes u_int, u_int, u_int); 87295367Sdesint cipher_get_length(struct sshcipher_ctx *, u_int *, u_int, 88262566Sdes const u_char *, u_int); 89295367Sdesint cipher_cleanup(struct sshcipher_ctx *); 90295367Sdesint cipher_set_key_string(struct sshcipher_ctx *, const struct sshcipher *, 91295367Sdes const char *, int); 92295367Sdesu_int cipher_blocksize(const struct sshcipher *); 93295367Sdesu_int cipher_keylen(const struct sshcipher *); 94295367Sdesu_int cipher_seclen(const struct sshcipher *); 95295367Sdesu_int cipher_authlen(const struct sshcipher *); 96295367Sdesu_int cipher_ivlen(const struct sshcipher *); 97295367Sdesu_int cipher_is_cbc(const struct sshcipher *); 9898684Sdes 99295367Sdesu_int cipher_get_number(const struct sshcipher *); 100295367Sdesint cipher_get_keyiv(struct sshcipher_ctx *, u_char *, u_int); 101295367Sdesint cipher_set_keyiv(struct sshcipher_ctx *, const u_char *); 102295367Sdesint cipher_get_keyiv_len(const struct sshcipher_ctx *); 103295367Sdesint cipher_get_keycontext(const struct sshcipher_ctx *, u_char *); 104295367Sdesvoid cipher_set_keycontext(struct sshcipher_ctx *, const u_char *); 10557429Smarkm#endif /* CIPHER_H */ 106