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 | */ |
---|
13 | |
---|
14 | /* |
---|
15 | * $Id: cipher.h,v 1.1.1.3 1999-03-08 17:43:33 danw Exp $ |
---|
16 | * $Log: not supported by cvs2svn $ |
---|
17 | * Revision 1.9 1998/04/30 01:51:26 kivinen |
---|
18 | * Reserved cipher number 7 to Bernard Perrot |
---|
19 | * <perrot@lal.in2p3.fr> for some weak 40 bit encryption method. |
---|
20 | * |
---|
21 | * Revision 1.8 1998/03/27 17:24:03 kivinen |
---|
22 | * Removed TSS. |
---|
23 | * |
---|
24 | * Revision 1.7 1997/03/26 07:11:22 kivinen |
---|
25 | * Fixed prototypes. |
---|
26 | * |
---|
27 | * Revision 1.6 1997/03/19 22:26:24 kivinen |
---|
28 | * Removed WITH_3DES ifdefs, as it is mandatory. |
---|
29 | * |
---|
30 | * Revision 1.5 1997/03/19 17:35:09 kivinen |
---|
31 | * Made all ciphers optional. |
---|
32 | * |
---|
33 | * Revision 1.4 1996/09/28 12:01:15 ylo |
---|
34 | * Removed TSS (put inside #ifdef WITH_TSS). |
---|
35 | * |
---|
36 | * Revision 1.3 1996/09/27 13:55:03 ttsalo |
---|
37 | * Added blowfish |
---|
38 | * |
---|
39 | * Revision 1.2 1996/02/18 21:52:35 ylo |
---|
40 | * Added comments that len must be multiple of 8. |
---|
41 | * |
---|
42 | * Revision 1.1.1.1 1996/02/18 21:38:11 ylo |
---|
43 | * Imported ssh-1.2.13. |
---|
44 | * |
---|
45 | * Revision 1.3 1995/08/18 22:48:27 ylo |
---|
46 | * Made IDEA optional. |
---|
47 | * |
---|
48 | * Revision 1.2 1995/07/13 01:19:52 ylo |
---|
49 | * Removed "Last modified" header. |
---|
50 | * Added cvs log. |
---|
51 | * |
---|
52 | * $Endlog$ |
---|
53 | */ |
---|
54 | |
---|
55 | #ifndef CIPHER_H |
---|
56 | #define CIPHER_H |
---|
57 | |
---|
58 | #ifndef WITHOUT_IDEA |
---|
59 | #include "idea.h" |
---|
60 | #endif /* WITHOUT_IDEA */ |
---|
61 | #include "des.h" |
---|
62 | #ifdef WITH_ARCFOUR |
---|
63 | #include "arcfour.h" |
---|
64 | #endif /* WITH_ARCFOUR */ |
---|
65 | #ifdef WITH_BLOWFISH |
---|
66 | #include "blowfish.h" |
---|
67 | #endif /* WITH_BLOWFISH */ |
---|
68 | |
---|
69 | /* Cipher types. New types can be added, but old types should not be removed |
---|
70 | for compatibility. The maximum allowed value is 31. */ |
---|
71 | #define SSH_CIPHER_NOT_SET -1 /* None selected (invalid number). */ |
---|
72 | #define SSH_CIPHER_NONE 0 /* no encryption */ |
---|
73 | #define SSH_CIPHER_IDEA 1 /* IDEA CFB */ |
---|
74 | #define SSH_CIPHER_DES 2 /* DES CBC */ |
---|
75 | #define SSH_CIPHER_3DES 3 /* 3DES CBC */ |
---|
76 | #define SSH_CIPHER_ARCFOUR 5 /* Arcfour */ |
---|
77 | #define SSH_CIPHER_BLOWFISH 6 /* Bruce Schneier's Blowfish */ |
---|
78 | #define SSH_CIPHER_RESERVED 7 /* Reserved for 40 bit crippled encryption, |
---|
79 | Bernard Perrot <perrot@lal.in2p3.fr> */ |
---|
80 | |
---|
81 | typedef struct { |
---|
82 | unsigned int type; |
---|
83 | union { |
---|
84 | #ifndef WITHOUT_IDEA |
---|
85 | struct { |
---|
86 | IDEAContext key; |
---|
87 | unsigned char iv[8]; |
---|
88 | } idea; |
---|
89 | #endif /* WITHOUT_IDEA */ |
---|
90 | #ifdef WITH_DES |
---|
91 | struct { |
---|
92 | DESContext key; |
---|
93 | unsigned char iv[8]; |
---|
94 | } des; |
---|
95 | #endif /* WITH_DES */ |
---|
96 | struct { |
---|
97 | DESContext key1; |
---|
98 | unsigned char iv1[8]; |
---|
99 | DESContext key2; |
---|
100 | unsigned char iv2[8]; |
---|
101 | DESContext key3; |
---|
102 | unsigned char iv3[8]; |
---|
103 | } des3; |
---|
104 | #ifdef WITH_ARCFOUR |
---|
105 | ArcfourContext arcfour; |
---|
106 | #endif |
---|
107 | #ifdef WITH_BLOWFISH |
---|
108 | BlowfishContext blowfish; |
---|
109 | #endif /* WITH_BLOWFISH */ |
---|
110 | } u; |
---|
111 | } CipherContext; |
---|
112 | |
---|
113 | /* Returns a bit mask indicating which ciphers are supported by this |
---|
114 | implementation. The bit mask has the corresponding bit set of each |
---|
115 | supported cipher. */ |
---|
116 | unsigned int cipher_mask(void); |
---|
117 | |
---|
118 | /* Returns the name of the cipher. */ |
---|
119 | const char *cipher_name(int cipher); |
---|
120 | |
---|
121 | /* Parses the name of the cipher. Returns the number of the corresponding |
---|
122 | cipher, or -1 on error. */ |
---|
123 | int cipher_number(const char *name); |
---|
124 | |
---|
125 | /* Selects the cipher to use and sets the key. If for_encryption is true, |
---|
126 | the key is setup for encryption; otherwise it is setup for decryption. */ |
---|
127 | void cipher_set_key(CipherContext *context, int cipher, |
---|
128 | const unsigned char *key, int keylen, int for_encryption); |
---|
129 | |
---|
130 | /* Sets key for the cipher by computing the MD5 checksum of the passphrase, |
---|
131 | and using the resulting 16 bytes as the key. */ |
---|
132 | void cipher_set_key_string(CipherContext *context, int cipher, |
---|
133 | const char *passphrase, int for_encryption); |
---|
134 | |
---|
135 | /* Encrypts data using the cipher. For most ciphers, len should be a |
---|
136 | multiple of 8. */ |
---|
137 | void cipher_encrypt(CipherContext *context, unsigned char *dest, |
---|
138 | const unsigned char *src, unsigned int len); |
---|
139 | |
---|
140 | /* Decrypts data using the cipher. For most ciphers, len should be a |
---|
141 | multiple of 8. */ |
---|
142 | void cipher_decrypt(CipherContext *context, unsigned char *dest, |
---|
143 | const unsigned char *src, unsigned int len); |
---|
144 | |
---|
145 | #endif /* CIPHER_H */ |
---|