blob: ae37b0bb87b1cce5d566cccf00d1e70bd22a55a7 [file] [log] [blame]
Damien Millerd4a8b7e1999-10-27 13:42:43 +10001/*
Damien Miller95def091999-11-25 00:26:21 +11002 *
3 * cipher.h
4 *
5 * Author: Tatu Ylonen <ylo@cs.hut.fi>
6 *
7 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
8 * All rights reserved
9 *
10 * Created: Wed Apr 19 16:50:42 1995 ylo
11 *
12 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +100013
Damien Miller95def091999-11-25 00:26:21 +110014/* RCSID("$Id: cipher.h,v 1.4 1999/11/24 13:26:22 damien Exp $"); */
Damien Millerd4a8b7e1999-10-27 13:42:43 +100015
16#ifndef CIPHER_H
17#define CIPHER_H
18
Damien Miller7e8e8201999-11-16 13:37:16 +110019#include "config.h"
20
Damien Miller7f6ea021999-10-28 13:25:17 +100021#ifdef HAVE_OPENSSL
Damien Millerd4a8b7e1999-10-27 13:42:43 +100022#include <openssl/des.h>
23#include <openssl/blowfish.h>
Damien Miller7f6ea021999-10-28 13:25:17 +100024#endif
25#ifdef HAVE_SSL
26#include <ssl/des.h>
27#include <ssl/blowfish.h>
28#endif
Damien Millerd4a8b7e1999-10-27 13:42:43 +100029
30/* Cipher types. New types can be added, but old types should not be removed
31 for compatibility. The maximum allowed value is 31. */
Damien Miller95def091999-11-25 00:26:21 +110032#define SSH_CIPHER_NOT_SET -1 /* None selected (invalid number). */
33#define SSH_CIPHER_NONE 0 /* no encryption */
34#define SSH_CIPHER_IDEA 1 /* IDEA CFB */
35#define SSH_CIPHER_DES 2 /* DES CBC */
36#define SSH_CIPHER_3DES 3 /* 3DES CBC */
37#define SSH_CIPHER_BROKEN_TSS 4 /* TRI's Simple Stream encryption CBC */
38#define SSH_CIPHER_BROKEN_RC4 5 /* Alleged RC4 */
Damien Millerd4a8b7e1999-10-27 13:42:43 +100039#define SSH_CIPHER_BLOWFISH 6
40
41typedef struct {
Damien Miller95def091999-11-25 00:26:21 +110042 unsigned int type;
43 union {
44 struct {
45 des_key_schedule key1;
46 des_key_schedule key2;
47 des_cblock iv2;
48 des_key_schedule key3;
49 des_cblock iv3;
50 } des3;
51 struct {
52 struct bf_key_st key;
53 unsigned char iv[8];
54 } bf;
55 } u;
56} CipherContext;
Damien Millerd4a8b7e1999-10-27 13:42:43 +100057/* Returns a bit mask indicating which ciphers are supported by this
58 implementation. The bit mask has the corresponding bit set of each
59 supported cipher. */
60unsigned int cipher_mask();
61
62/* Returns the name of the cipher. */
63const char *cipher_name(int cipher);
64
65/* Parses the name of the cipher. Returns the number of the corresponding
66 cipher, or -1 on error. */
Damien Miller95def091999-11-25 00:26:21 +110067int cipher_number(const char *name);
Damien Millerd4a8b7e1999-10-27 13:42:43 +100068
69/* Selects the cipher to use and sets the key. If for_encryption is true,
70 the key is setup for encryption; otherwise it is setup for decryption. */
Damien Miller95def091999-11-25 00:26:21 +110071void
72cipher_set_key(CipherContext * context, int cipher,
73 const unsigned char *key, int keylen, int for_encryption);
Damien Millerd4a8b7e1999-10-27 13:42:43 +100074
75/* Sets key for the cipher by computing the MD5 checksum of the passphrase,
76 and using the resulting 16 bytes as the key. */
Damien Miller95def091999-11-25 00:26:21 +110077void
78cipher_set_key_string(CipherContext * context, int cipher,
79 const char *passphrase, int for_encryption);
Damien Millerd4a8b7e1999-10-27 13:42:43 +100080
81/* Encrypts data using the cipher. */
Damien Miller95def091999-11-25 00:26:21 +110082void
83cipher_encrypt(CipherContext * context, unsigned char *dest,
84 const unsigned char *src, unsigned int len);
Damien Millerd4a8b7e1999-10-27 13:42:43 +100085
86/* Decrypts data using the cipher. */
Damien Miller95def091999-11-25 00:26:21 +110087void
88cipher_decrypt(CipherContext * context, unsigned char *dest,
89 const unsigned char *src, unsigned int len);
Damien Millerd4a8b7e1999-10-27 13:42:43 +100090
91/* If and CRC-32 attack is detected this function is called. Defaults
92 * to fatal, changed to packet_disconnect in sshd and ssh. */
Damien Miller95def091999-11-25 00:26:21 +110093extern void (*cipher_attack_detected) (const char *fmt,...);
Damien Millerd4a8b7e1999-10-27 13:42:43 +100094
Damien Miller95def091999-11-25 00:26:21 +110095#endif /* CIPHER_H */