cipher.h revision 1.5
1/* $NetBSD: cipher.h,v 1.5 2013/11/08 19:18:25 christos Exp $ */ 2/* $OpenBSD: cipher.h,v 1.40 2013/04/19 01:06:50 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 <openssl/evp.h> 42/* 43 * Cipher types for SSH-1. New types can be added, but old types should not 44 * be removed for compatibility. The maximum allowed value is 31. 45 */ 46#define SSH_CIPHER_SSH2 -3 47#define SSH_CIPHER_INVALID -2 /* No valid cipher selected. */ 48#define SSH_CIPHER_NOT_SET -1 /* None selected (invalid number). */ 49#define SSH_CIPHER_NONE 0 /* no encryption */ 50#define SSH_CIPHER_IDEA 1 /* IDEA CFB */ 51#define SSH_CIPHER_DES 2 /* DES CBC */ 52#define SSH_CIPHER_3DES 3 /* 3DES CBC */ 53#define SSH_CIPHER_BROKEN_TSS 4 /* TRI's Simple Stream encryption CBC */ 54#define SSH_CIPHER_BROKEN_RC4 5 /* Alleged RC4 */ 55#define SSH_CIPHER_BLOWFISH 6 56#define SSH_CIPHER_RESERVED 7 57#define SSH_CIPHER_MAX 31 58 59#define CIPHER_ENCRYPT 1 60#define CIPHER_DECRYPT 0 61 62typedef struct Cipher Cipher; 63typedef struct CipherContext CipherContext; 64 65struct Cipher; 66struct CipherContext { 67 int plaintext; 68 int encrypt; 69 EVP_CIPHER_CTX evp; 70 const Cipher *cipher; 71}; 72 73u_int cipher_mask_ssh1(int); 74const Cipher *cipher_by_name(const char *); 75const Cipher *cipher_by_number(int); 76int cipher_number(const char *); 77const char *cipher_name(int); 78int ciphers_valid(const char *); 79char *cipher_alg_list(void); 80void cipher_init(CipherContext *, const Cipher *, const u_char *, u_int, 81 const u_char *, u_int, int); 82void cipher_crypt(CipherContext *, u_char *, const u_char *, 83 u_int, u_int, u_int); 84void cipher_cleanup(CipherContext *); 85void cipher_set_key_string(CipherContext *, const Cipher *, const char *, int); 86u_int cipher_blocksize(const Cipher *); 87u_int cipher_keylen(const Cipher *); 88u_int cipher_authlen(const Cipher *); 89u_int cipher_ivlen(const Cipher *); 90u_int cipher_is_cbc(const Cipher *); 91 92u_int cipher_get_number(const Cipher *); 93void cipher_get_keyiv(CipherContext *, u_char *, u_int); 94void cipher_set_keyiv(CipherContext *, u_char *); 95int cipher_get_keyiv_len(const CipherContext *); 96int cipher_get_keycontext(const CipherContext *, u_char *); 97void cipher_set_keycontext(CipherContext *, u_char *); 98#endif /* CIPHER_H */ 99