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