xref: /freebsd/crypto/openssh/cipher.h (revision 56ca39961bd1c9946a505c41c3fc634ef63fdd42)
1 /*
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  * $FreeBSD$
13  */
14 
15 /* RCSID("$Id: cipher.h,v 1.11 2000/03/22 09:55:10 markus Exp $"); */
16 
17 #ifndef CIPHER_H
18 #define CIPHER_H
19 
20 #include <openssl/des.h>
21 #include <openssl/blowfish.h>
22 
23 /* Cipher types.  New types can be added, but old types should not be removed
24    for compatibility.  The maximum allowed value is 31. */
25 #define SSH_CIPHER_NOT_SET	-1	/* None selected (invalid number). */
26 #define SSH_CIPHER_NONE		0	/* no encryption */
27 #define SSH_CIPHER_IDEA		1	/* IDEA CFB */
28 #define SSH_CIPHER_DES		2	/* DES CBC */
29 #define SSH_CIPHER_3DES		3	/* 3DES CBC */
30 #define SSH_CIPHER_BROKEN_TSS	4	/* TRI's Simple Stream encryption CBC */
31 #define SSH_CIPHER_BROKEN_RC4	5	/* Alleged RC4 */
32 #define SSH_CIPHER_BLOWFISH	6
33 
34 typedef struct {
35 	unsigned int type;
36 	union {
37 		struct {
38 			des_key_schedule key1;
39 			des_key_schedule key2;
40 			des_cblock iv2;
41 			des_key_schedule key3;
42 			des_cblock iv3;
43 		}       des3;
44 		struct {
45 			struct bf_key_st key;
46 			unsigned char iv[8];
47 		}       bf;
48 	}       u;
49 }       CipherContext;
50 /*
51  * Returns a bit mask indicating which ciphers are supported by this
52  * implementation.  The bit mask has the corresponding bit set of each
53  * supported cipher.
54  */
55 unsigned int cipher_mask();
56 
57 /* Returns the name of the cipher. */
58 const char *cipher_name(int cipher);
59 
60 /*
61  * Parses the name of the cipher.  Returns the number of the corresponding
62  * cipher, or -1 on error.
63  */
64 int     cipher_number(const char *name);
65 
66 /*
67  * Selects the cipher to use and sets the key.  If for_encryption is true,
68  * the key is setup for encryption; otherwise it is setup for decryption.
69  */
70 void
71 cipher_set_key(CipherContext * context, int cipher,
72     const unsigned char *key, int keylen, int for_encryption);
73 
74 /*
75  * Sets key for the cipher by computing the MD5 checksum of the passphrase,
76  * and using the resulting 16 bytes as the key.
77  */
78 void
79 cipher_set_key_string(CipherContext * context, int cipher,
80     const char *passphrase, int for_encryption);
81 
82 /* Encrypts data using the cipher. */
83 void
84 cipher_encrypt(CipherContext * context, unsigned char *dest,
85     const unsigned char *src, unsigned int len);
86 
87 /* Decrypts data using the cipher. */
88 void
89 cipher_decrypt(CipherContext * context, unsigned char *dest,
90     const unsigned char *src, unsigned int len);
91 
92 #endif				/* CIPHER_H */
93