📄 ck_crp.c
字号:
#elseencrypt_send_keyid(dir, keyid, keylen, saveit) int dir; unsigned char *keyid; int keylen; int saveit;#endif{ unsigned char *strp;#ifdef CK_SSL if (TELOPT_SB(TELOPT_START_TLS).start_tls.me_follows) return(0);#endif /* CK_SSL */ str_keyid[3] = (dir == DIR_ENCRYPT) ? ENCRYPT_ENC_KEYID : ENCRYPT_DEC_KEYID; if (saveit && keylen <= MAXKEYLEN) { struct key_info *kp = &ki[(dir == DIR_ENCRYPT) ? 0 : 1]; memcpy(kp->keyid, keyid, keylen); kp->keylen = keylen; } for (strp = &str_keyid[4]; keylen > 0; --keylen) { if ((*strp++ = *keyid++) == IAC) *strp++ = IAC; } *strp++ = IAC; *strp++ = SE; if (deblog || tn_deb || debses) { int i; sprintf(tn_msg,"TELNET SENT SB %s %s ", TELOPT(TELOPT_ENCRYPTION), (dir == DIR_ENCRYPT) ? "ENC-KEYID" : "DEC-KEYID"); /* safe */ tn_hex(tn_msg,TN_MSG_LEN,&str_keyid[4],strp-str_keyid-2-4); ckstrncat(tn_msg,"IAC SE",TN_MSG_LEN); debug(F100,tn_msg,"",0); if (tn_deb || debses) tn_debug(tn_msg); }#ifdef OS2 RequestTelnetMutex( SEM_INDEFINITE_WAIT );#endif ttol(str_keyid, strp - str_keyid);#ifdef OS2 ReleaseTelnetMutex();#endif return(0);}VOID#ifdef CK_ANSICencrypt_auto(int on)#elseencrypt_auto(on) int on;#endif{ if (on < 0) autoencrypt ^= 1; else autoencrypt = on ? 1 : 0;}VOID#ifdef CK_ANSICdecrypt_auto(int on)#elsedecrypt_auto(on) int on;#endif{ if (on < 0) autodecrypt ^= 1; else autodecrypt = on ? 1 : 0;}VOID#ifdef CK_ANSICencrypt_start_output(int type)#elseencrypt_start_output(type) int type;#endif{ Encryptions *ep; register unsigned char *p; register int i;#ifdef CK_SSL if (TELOPT_SB(TELOPT_START_TLS).start_tls.me_follows) return;#endif /* CK_SSL */ if (!(ep = findencryption(type))) {#ifdef DEBUG if (encrypt_debug_mode) { sprintf(dbgbuf, ">>>Can't encrypt with type %s (%d)\n", ENCTYPE_NAME_OK(type) ? ENCTYPE_NAME(type) : "(unknown)", type); /* safe */ debug(F110,"encrypt_start_output",dbgbuf,0); }#endif return; } if (ep->start) { i = (*ep->start)(DIR_ENCRYPT, 0);#ifdef DEBUG if (encrypt_debug_mode) { sprintf(dbgbuf, ">>>Encrypt start: %s (%d) %s\n", (i < 0) ? "failed" : "initial negotiation in progress", i, ENCTYPE_NAME(type)); /* safe */ debug(F110,"encrypt_start_output",dbgbuf,0); }#endif if (i) return; } if ( encrypt_output != ep->output ) { p = str_start; *p++ = IAC; *p++ = SB; *p++ = TELOPT_ENCRYPTION; *p++ = ENCRYPT_START; for (i = 0; i < ki[0].keylen; ++i) { if (( *p++ = ki[0].keyid[i]) == IAC) *p++ = IAC; } *p++ = IAC; *p++ = SE; if (deblog || tn_deb || debses) { int i; sprintf(tn_msg,"TELNET SENT SB %s START ", TELOPT(TELOPT_ENCRYPTION)); /* safe */ tn_hex(tn_msg,TN_MSG_LEN,&str_start[4],p-str_start-2-4); ckstrncat(tn_msg,"IAC SE",TN_MSG_LEN); debug(F100,tn_msg,"",0); if (tn_deb || debses) tn_debug(tn_msg); }#ifdef OS2 RequestTelnetMutex( SEM_INDEFINITE_WAIT );#endif ttol(str_start, p - str_start);#ifdef OS2 ReleaseTelnetMutex();#endif /* * If we are already encrypting in some mode, then * encrypt the ring (which includes our request) in * the old mode, mark it all as "clear text" and then * switch to the new mode. */ encrypt_output = ep->output; EncryptKSGlobalHack->encrypt = encrypt_ks_stream; EncryptKSGlobalHack->encrypt_type = type; encrypt_mode = type;#ifdef DEBUG if (encrypt_debug_mode) { sprintf(dbgbuf, ">>>Started to encrypt output with type %s", ENCTYPE_NAME(type)); /* safe */ debug(F110,"encrypt_start_output",dbgbuf,0); }#endif if (encrypt_verbose) { sprintf(dbgbuf, "Output is now encrypted with type %s", ENCTYPE_NAME(type)); /* safe */ debug(F110,"encrypt_start_output",dbgbuf,0); printf("%s\n",dbgbuf); } }}VOID#ifdef CK_ANSICencrypt_send_end(VOID)#elseencrypt_send_end()#endif{#ifdef CK_SSL if (TELOPT_SB(TELOPT_START_TLS).start_tls.me_follows) return;#endif /* CK_SSL */ if (!encrypt_output) return; str_end[0] = IAC; str_end[1] = SB; str_end[2] = TELOPT_ENCRYPTION; str_end[3] = ENCRYPT_END; str_end[4] = IAC; str_end[5] = SE; if (deblog || tn_deb || debses) { int i; sprintf(tn_msg,"TELNET SENT SB %s END IAC SE", TELOPT(TELOPT_ENCRYPTION)); /* safe */ debug(F100,tn_msg,"",0); if (tn_deb || debses) tn_debug(tn_msg); }#ifdef OS2 RequestTelnetMutex( SEM_INDEFINITE_WAIT );#endif ttol(str_end, sizeof(str_end));#ifdef OS2 ReleaseTelnetMutex();#endif encrypt_output = 0; EncryptKSGlobalHack->encrypt = NULL; EncryptKSGlobalHack->encrypt_type = ENCTYPE_ANY;#ifdef DEBUG if (encrypt_debug_mode) { sprintf(dbgbuf, ">>>Output is back to clear text"); /* safe */ debug(F110,"encrypt_send_end",dbgbuf,0); }#endif if (encrypt_verbose) { sprintf(dbgbuf, "Output is now clear text"); /* safe */ debug(F110,"encrypt_send_end",dbgbuf,0); printf("%s\n",dbgbuf); }}VOID#ifdef CK_ANSICencrypt_send_request_start(VOID)#elseencrypt_send_request_start()#endif{ register unsigned char *p; register int i;#ifdef CK_SSL if (TELOPT_SB(TELOPT_START_TLS).start_tls.me_follows) return;#endif /* CK_SSL */ p = str_start; *p++ = IAC; *p++ = SB; *p++ = TELOPT_ENCRYPTION; *p++ = ENCRYPT_REQSTART; for (i = 0; i < ki[1].keylen; ++i) { if (( *p++ = ki[1].keyid[i]) == IAC) *p++ = IAC; } *p++ = IAC; *p++ = SE; if (deblog || tn_deb || debses) { int i; sprintf(tn_msg,"TELNET SENT SB %s REQUEST-START ", TELOPT(TELOPT_ENCRYPTION)); /* safe */ tn_hex(tn_msg,TN_MSG_LEN,&str_start[4],p-str_start-2-4); ckstrncat(tn_msg,"IAC SE",TN_MSG_LEN); debug(F100,tn_msg,"",0); if (tn_deb || debses) tn_debug(tn_msg); }#ifdef OS2 RequestTelnetMutex( SEM_INDEFINITE_WAIT );#endif ttol(str_start, p - str_start);#ifdef OS2 ReleaseTelnetMutex();#endif if (encrypt_debug_mode) { sprintf(dbgbuf, ">>>Request input to be encrypted\n"); /* safe */ debug(F110,"encrypt_send_request_start",dbgbuf,0); }}VOID#ifdef CK_ANSICencrypt_send_request_end(VOID)#elseencrypt_send_request_end()#endif{#ifdef CK_SSL if (TELOPT_SB(TELOPT_START_TLS).start_tls.me_follows) return;#endif /* CK_SSL */ str_end[0] = IAC; str_end[1] = SB; str_end[2] = TELOPT_ENCRYPTION; str_end[3] = ENCRYPT_REQEND; str_end[4] = IAC; str_end[5] = SE; if (deblog || tn_deb || debses) { int i; sprintf(tn_msg,"TELNET SENT SB %s REQEND IAC SE", TELOPT(TELOPT_ENCRYPTION)); /* safe */ debug(F100,tn_msg,"",0); if (tn_deb || debses) tn_debug(tn_msg); }#ifdef OS2 RequestTelnetMutex( SEM_INDEFINITE_WAIT );#endif ttol(str_end, sizeof(str_end));#ifdef OS2 ReleaseTelnetMutex();#endif if (encrypt_debug_mode) { sprintf(dbgbuf, ">>>Request input to be clear text\n"); /* safe */ debug(F110,"encrypt_send_request_end",dbgbuf,0); }}int#ifdef CK_ANSICencrypt_is_encrypting(VOID)#elseencrypt_is_encrypting()#endif{ if (encrypt_output) return 1; return 0;}int#ifdef CK_ANSICencrypt_is_decrypting(VOID)#elseencrypt_is_decrypting()#endif{ if (decrypt_input) return 1; return 0;}#ifdef DEBUGvoidencrypt_debug(mode) int mode;{ encrypt_debug_mode = mode;}#endif#ifdef CK_DES/*- * Copyright (c) 1991, 1993 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. *//* based on @(#)enc_des.c 8.1 (Berkeley) 6/4/93 */#define CFB 0#define OFB 1#define NO_SEND_IV 1#define NO_RECV_IV 2#define NO_KEYID 4#define IN_PROGRESS (NO_SEND_IV|NO_RECV_IV|NO_KEYID)#define SUCCESS 0#define xFAILED -1Schedule test_sched;struct des_stinfo { Block str_output; Block str_feed; Block str_iv; Block str_ikey;#ifdef MIT_CURRENT unsigned char str_keybytes[8]; krb5_keyblock str_key;#else /* MIT_CURRENT */ Schedule str_sched; int str_index;#endif /* MIT_CURRENT */ int str_flagshift;};struct des_fb {#ifndef MIT_CURRENT Block krbdes_key; Schedule krbdes_sched;#endif /* MIT_CURRENT */ Block temp_feed; unsigned char fb_feed[64]; int need_start; int state[2]; int keyid[2]; int once;#ifdef MIT_CURRENT int validkey;#endif /* MIT_CURRENT */ struct des_stinfo streams[2];};static struct des_fb des_fb[2];struct des3_stinfo { Block str_output; Block str_feed; Block str_iv; Block str_ikey[3]; Schedule str_sched[3]; int str_index; int str_flagshift;};struct des3_fb {#ifndef MIT_CURRENT Block krbdes_key[3]; Schedule krbdes_sched[3];#endif /* MIT_CURRENT */ Block temp_feed; unsigned char fb_feed[64]; int need_start; int state[2]; int keyid[2]; int once;#ifdef MIT_CURRENT int validkey;#endif /* MIT_CURRENT */ struct des3_stinfo streams[2];};static struct des3_fb des3_fb[2];struct keyidlist { char *keyid; int keyidlen; char *key; int keylen; int flags;} keyidlist [] = { { "\0", 1, 0, 0, 0 }, /* default key of zero */ { 0, 0, 0, 0, 0 }};#define KEYFLAG_MASK 03#define KEYFLAG_NOINIT 00#define KEYFLAG_INIT 01#define KEYFLAG_OK 02#define KEYFLAG_BAD 03#define KEYFLAG_SHIFT 2#define SHIFT_VAL(a,b) (KEYFLAG_SHIFT*((a)+((b)*2)))#define FB64_IV 1#define FB64_IV_OK 2#define FB64_IV_BAD 3#define FB64_CHALLENGE 4#define FB64_RESPONSE 5void fb64_stream_iv P((Block, struct des_stinfo *));void fb64_init P((struct des_fb *));static int fb64_start P((struct des_fb *, int, int));int fb64_is P((unsigned char *, int, struct des_fb *));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -