Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 1 | /* |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 2 | * |
| 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 Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 13 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 14 | /* RCSID("$Id: cipher.h,v 1.5 1999/11/25 00:54:58 damien Exp $"); */ |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 15 | |
| 16 | #ifndef CIPHER_H |
| 17 | #define CIPHER_H |
Damien Miller | 7e8e820 | 1999-11-16 13:37:16 +1100 | [diff] [blame] | 18 | |
| 19 | #include "config.h" |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 20 | |
Damien Miller | 7f6ea02 | 1999-10-28 13:25:17 +1000 | [diff] [blame] | 21 | #ifdef HAVE_OPENSSL |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 22 | #include <openssl/des.h> |
| 23 | #include <openssl/blowfish.h> |
Damien Miller | 7f6ea02 | 1999-10-28 13:25:17 +1000 | [diff] [blame] | 24 | #endif |
| 25 | #ifdef HAVE_SSL |
| 26 | #include <ssl/des.h> |
| 27 | #include <ssl/blowfish.h> |
| 28 | #endif |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 29 | |
| 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 Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 32 | #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 Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 39 | #define SSH_CIPHER_BLOWFISH 6 |
| 40 | |
| 41 | typedef struct { |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 42 | 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 Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 57 | /* |
| 58 | * Returns a bit mask indicating which ciphers are supported by this |
| 59 | * implementation. The bit mask has the corresponding bit set of each |
| 60 | * supported cipher. |
| 61 | */ |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 62 | unsigned int cipher_mask(); |
| 63 | |
| 64 | /* Returns the name of the cipher. */ |
| 65 | const char *cipher_name(int cipher); |
| 66 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 67 | /* |
| 68 | * Parses the name of the cipher. Returns the number of the corresponding |
| 69 | * cipher, or -1 on error. |
| 70 | */ |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 71 | int cipher_number(const char *name); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 72 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 73 | /* |
| 74 | * Selects the cipher to use and sets the key. If for_encryption is true, |
| 75 | * the key is setup for encryption; otherwise it is setup for decryption. |
| 76 | */ |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 77 | void |
| 78 | cipher_set_key(CipherContext * context, int cipher, |
| 79 | const unsigned char *key, int keylen, int for_encryption); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 80 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 81 | /* |
| 82 | * Sets key for the cipher by computing the MD5 checksum of the passphrase, |
| 83 | * and using the resulting 16 bytes as the key. |
| 84 | */ |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 85 | void |
| 86 | cipher_set_key_string(CipherContext * context, int cipher, |
| 87 | const char *passphrase, int for_encryption); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 88 | |
| 89 | /* Encrypts data using the cipher. */ |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 90 | void |
| 91 | cipher_encrypt(CipherContext * context, unsigned char *dest, |
| 92 | const unsigned char *src, unsigned int len); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 93 | |
| 94 | /* Decrypts data using the cipher. */ |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 95 | void |
| 96 | cipher_decrypt(CipherContext * context, unsigned char *dest, |
| 97 | const unsigned char *src, unsigned int len); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 98 | |
Damien Miller | 5428f64 | 1999-11-25 11:54:57 +1100 | [diff] [blame] | 99 | /* |
| 100 | * If and CRC-32 attack is detected this function is called. Defaults to |
| 101 | * fatal, changed to packet_disconnect in sshd and ssh. |
| 102 | */ |
| 103 | extern void (*cipher_attack_detected) (const char *fmt, ...); |
Damien Miller | d4a8b7e | 1999-10-27 13:42:43 +1000 | [diff] [blame] | 104 | |
Damien Miller | 95def09 | 1999-11-25 00:26:21 +1100 | [diff] [blame] | 105 | #endif /* CIPHER_H */ |