Debian Codegraph @

libtelnet/encrypt.h

raw
1 /*
2 Copyright (C) 1996-2026 Free Software Foundation, Inc.
3
4 This file is part of GNU Inetutils.
5
6 GNU Inetutils is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or (at
9 your option) any later version.
10
11 GNU Inetutils is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see `http://www.gnu.org/licenses/'. */
18
19 /*
20 * Copyright (c) 1991, 1993
21 * The Regents of the University of California. All rights reserved.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the above copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. Neither the name of the University nor the names of its contributors
32 * may be used to endorse or promote products derived from this software
33 * without specific prior written permission.
34 *
35 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
36 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
38 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
39 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
40 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
41 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
42 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
43 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
44 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
45 * SUCH DAMAGE.
46 */
47
48 /*
49 * Copyright (C) 1990 by the Massachusetts Institute of Technology
50 *
51 * Export of this software from the United States of America is assumed
52 * to require a specific license from the United States Government.
53 * It is the responsibility of any person or organization contemplating
54 * export to obtain such a license before exporting.
55 *
56 * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
57 * distribute this software and its documentation for any purpose and
58 * without fee is hereby granted, provided that the above copyright
59 * notice appear in all copies and that both that copyright notice and
60 * this permission notice appear in supporting documentation, and that
61 * the name of M.I.T. not be used in advertising or publicity pertaining
62 * to distribution of the software without specific, written prior
63 * permission. M.I.T. makes no representations about the suitability of
64 * this software for any purpose. It is provided "as is" without express
65 * or implied warranty.
66 */
67
68 #ifdef ENCRYPTION
69 # ifndef __ENCRYPTION__
70 # define __ENCRYPTION__
71
72 # define DIR_DECRYPT 1
73 # define DIR_ENCRYPT 2
74
75 /* Cope with variants of <arpa/telnet.h>. */
76 # if !defined ENCTYPE_ANY && defined TELOPT_ENCTYPE_NULL
77 # define ENCTYPE_ANY TELOPT_ENCTYPE_NULL
78 # endif
79 # if !defined ENCTYPE_DES_CFB64 && defined TELOPT_ENCTYPE_DES_CFB64
80 # define ENCTYPE_DES_CFB64 TELOPT_ENCTYPE_DES_CFB64
81 # endif
82 # if !defined ENCTYPE_DES_OFB64 && defined TELOPT_ENCTYPE_DES_OFB64
83 # define ENCTYPE_DES_OFB64 TELOPT_ENCTYPE_DES_OFB64
84 # endif
85 # if !defined ENCTYPE_CNT && defined TELOPT_ENCTYPE_CNT
86 # define ENCTYPE_CNT TELOPT_ENCTYPE_CNT
87 # endif
88
89 /*
90 * Our capabilities are restricted to the encryption types
91 * DES_CFB64 and DES_OFB64. The latter type is sometimes
92 * missing in <arpa/telnet.h>. On the other hand, the same
93 * header file may indicate more encryption types than are
94 * supported by the present code.
95 */
96 # ifndef ENCTYPE_DES_OFB64
97 # define ENCTYPE_DES_OFB64 2 /* RFC 2953 */
98 # endif
99 # undef ENCTYPE_CNT
100 # define ENCTYPE_CNT 3 /* Up to DES_OFB64. */
101
102 # undef ENCTYPE_NAME_OK
103 # define ENCTYPE_NAME_OK(x) ((unsigned int)(x) < ENCTYPE_CNT)
104
105 typedef unsigned char Block[8];
106 typedef unsigned char *BlockT;
107
108 # ifndef HAVE_ARPA_TELNET_H_SCHEDULE
109 typedef struct
110 {
111 Block _;
112 } Schedule[16];
113 # endif
114 /* !HAVE_ARPA_TELNET_H_SCHEDULE */
115
116 # ifndef VALIDKEY
117 # define VALIDKEY(key) ( key[0] | key[1] | key[2] | key[3] | \
118 key[4] | key[5] | key[6] | key[7])
119 # endif
120
121 # define SAMEKEY(k1, k2) (!memcmp ((void *) k1, (void *) k2, sizeof (Block)))
122
123 # ifndef HAVE_ARPA_TELNET_H_SESSION_KEY
124 typedef struct
125 {
126 short type;
127 int length;
128 const unsigned char *data;
129 } Session_Key;
130 # endif
131 /* !HAVE_ARPA_TELNET_H_SESSION_KEY */
132
133 typedef struct
134 {
135 char *name;
136 int type;
137 void (*output) (unsigned char *, int);
138 int (*input) (int);
139 void (*init) (int);
140 int (*start) (int, int);
141 int (*is) (unsigned char *, int);
142 int (*reply) (unsigned char *, int);
143 void (*session) (Session_Key *, int);
144 int (*keyid) (int, unsigned char *, int *);
145 void (*printsub) (unsigned char *, int, char *, int);
146 } Encryptions;
147
148 # define SK_DES 1
149 /* Matched Kerberos v5 KEYTYPE_DES */
150 # define SK_OTHER 2 /* Non-DES key. */
151
152 # include "enc-proto.h"
153
154 extern int encrypt_debug_mode;
155 extern int (*decrypt_input) (int);
156 extern void (*encrypt_output) (unsigned char *, int);
157 # endif/* __ENCRYPTION__ */
158 #endif /* ENCRYPTION */