📄 ck_crp.c
字号:
char *ckcrpv = "Encryption Engine, 8.0.114, 9 Oct 2003";/* C K _ C R P . C - Cryptography for C-Kermit" Copyright (C) 1998, 2004, Trustees of Columbia University in the City of New York. All rights reserved. See the C-Kermit COPYING.TXT file or the copyright text in the ckcmai.c module for disclaimer and permissions. Author: Jeffrey E Altman (jaltman@secure-endpoints.com) Secure Endpoints Inc., New York City*/#define CK_CRP_C#ifdef CK_DES#ifdef CK_SSL#ifndef LIBDES#define LIBDES#endif /* LIBDES */#endif /* CK_SSL */#endif /* CK_DES */#ifdef CRYPT_DLL#define CK_AUTHENTICATION#define CK_ENCRYPTION#define CK_DES#define CK_CAST#ifndef LIBDES#define LIBDES#endif /* LIBDES */#define TELCMDS /* to define name array */#define TELOPTS /* to define name array */#define ENCRYPT_NAMES#endif /* CRYPT_DLL */#include "ckcsym.h"#include "ckcdeb.h"#include "ckcnet.h"#ifdef DEBUG#undef DEBUG#endif /* DEBUG */#ifdef CK_AUTHENTICATION#ifdef CK_ENCRYPTION#define ENCRYPTION#ifdef CK_DES#define DES_ENCRYPTION#endif /* CK_DES */#ifdef CK_CAST#define CAST_ENCRYPTION#endif /* CK_CAST */#ifdef COMMENT#define CAST_EXPORT_ENCRYPTION#endif /* COMMENT */#endif /* CK_ENCRYPTION */#endif /* CK_AUTHENTICATION */#ifdef CK_ENCRYPTION#include "ckucmd.h" /* For struct keytab definition */#include "ckuath.h"#include "ckuat2.h"#ifdef MIT_CURRENT#include <krb5.h>#endif /* MIT_CURRENT */#include <stdlib.h>#include <string.h>#ifdef OS2#include <stdarg.h>#ifdef OS2ONLY#include <os2.h>#endif /* OS2ONLY */#include "ckosyn.h"#else /* OS2 */static char * tmpstring = NULL;#endif /* OS2 */#ifndef CAST_OR_EXPORT#ifdef CAST_ENCRYPTION#define CAST_OR_EXPORT#endif /* CAST_ENCRYPTION */#ifdef CAST_EXPORT_ENCRYPTION#define CAST_OR_EXPORT#endif /* CAST_EXPORT_ENCRYPTION */#endif /* CAST_OR_EXPORT */#ifdef CRYPT_DLLint cmd_quoting = 0;#ifndef TELOPT_MACROinttelopt_index(opt) int opt; { if ( opt >= 0 && opt <= TELOPT_SEND_URL ) return(opt); else if ( opt >= TELOPT_PRAGMA_LOGON && opt <= TELOPT_PRAGMA_HEARTBEAT ) return(opt-89); else return(NTELOPTS);}inttelopt_ok(opt) int opt; { return((opt >= TELOPT_BINARY && opt <= TELOPT_SEND_URL) || (opt >= TELOPT_PRAGMA_LOGON && opt <= TELOPT_PRAGMA_HEARTBEAT));}CHAR *telopt(opt) int opt; { if ( telopt_ok(opt) ) return(telopts[telopt_index(opt)]); else return("UNKNOWN");}#endif /* TELOPT_MACRO */static int (*p_ttol)(char *,int)=NULL;static int (*p_dodebug)(int,char *,char *,long)=NULL;static int (*p_dohexdump)(char *,char *,int)=NULL;static void (*p_tn_debug)(char *)=NULL;static int (*p_vscrnprintf)(char *, ...)=NULL;static void * p_k5_context=NULL;static unsigned long (*p_reqtelmutex)(unsigned long)=NULL;static unsigned long (*p_reltelmutex)(void)=NULL;unsigned longRequestTelnetMutex(unsigned long x){ if ( p_reqtelmutex ) return p_reqtelmutex(x); return 0;}unsigned longReleaseTelnetMutex(void){ if ( p_reltelmutex ) return p_reltelmutex(); return 0;}intttol(char * s, int n){ if ( p_ttol ) return(p_ttol(s,n)); else return(-1);}intdodebug(int flag, char * s1, char * s2, long n){ if ( p_dodebug ) return(p_dodebug(flag,s1,s2,n)); else return(-1);}intdohexdump( char * s1, char * s2, int n ){ if ( p_dohexdump ) p_dohexdump(s1,s2,n); return(0);}voidtn_debug( char * s ){ if ( p_tn_debug ) p_tn_debug(s);}static char myprtfstr[4096];intVscrnprintf(const char * format, ...) { int i, len, rc=0; char *cp; va_list ap; va_start(ap, format);#ifdef NT rc = _vsnprintf(myprtfstr, sizeof(myprtfstr)-1, format, ap);#else /* NT */ rc = vsprintf(myprtfstr, format, ap);#endif /* NT */ va_end(ap); if ( p_vscrnprintf ) return(p_vscrnprintf(myprtfstr)); else return(-1);}int#ifdef CK_ANSICtn_hex(CHAR * buf, int buflen, CHAR * data, int datalen)#else /* CK_ANSIC */tn_hex(buf, buflen, data, datalen) CHAR * buf; int buflen; CHAR * data; int datalen;#endif /* CK_ANSIC */{ int i = 0, j = 0, k = 0; CHAR tmp[8];#ifdef COMMENT int was_hex = 1; for (k=0; k < datalen; k++) { if (data[k] < 32 || data[k] >= 127) { sprintf(tmp,"%s%02X ",was_hex?"":"\" ",data[k]); was_hex = 1; } else { sprintf(tmp,"%s%c",was_hex?"\"":"",data[k]); was_hex = 0; } ckstrncat(buf,tmp,buflen); } if (!was_hex) ckstrncat(buf,"\" ",buflen);#else /* COMMENT */ if (datalen <= 0 || data == NULL) return(0); for (i = 0; i < datalen; i++) { ckstrncat(buf,"\r\n ",buflen); for (j = 0 ; (j < 16); j++) { if ((i + j) < datalen) sprintf(tmp, "%s%02x ", (j == 8 ? "| " : ""), (CHAR) data[i + j] ); else sprintf(tmp, "%s ", (j == 8 ? "| " : "") ); ckstrncat(buf,tmp,buflen); } ckstrncat(buf," ",buflen); for (k = 0; (k < 16) && ((i + k) < datalen); k++) { sprintf(tmp, "%s%c", (k == 8 ? " " : ""), isprint(data[i + k]) ? data[i + k] : '.' ); ckstrncat(buf,tmp,buflen); } i += j - 1; } /* end for */ ckstrncat(buf,"\r\n ",buflen);#endif /* COMMENT */ return(strlen(buf));}#ifdef COMMENT#define ttol dll_ttol#define dodebug dll_dodebug#define dohexdump dll_dohexdump#define tn_debug dll_tn_debug#define Vscrnprintf dll_vscrnprintf#endif /* COMMENT */char tn_msg[TN_MSG_LEN], hexbuf[TN_MSG_LEN]; /* from ckcnet.c */int deblog=1, debses=1, tn_deb=1;#else /* CRYPT_DLL */extern char tn_msg[], hexbuf[]; /* from ckcnet.c */extern int deblog, debses, tn_deb;#ifdef MIT_CURRENTextern krb5_context k5_context;#endif /* MIT_CURRENT */#endif /* CRYPT_DLL */#ifdef LIBDES#ifndef UNIX#define des_new_random_key des_random_key#define des_set_random_generator_seed des_random_seed#endif /* UNIX */#define des_fixup_key_parity des_set_odd_parity#ifdef OPENSSL_097#define OPENSSL_ENABLE_OLD_DES_SUPPORT#include <openssl/des.h>#endif /* OPENSSL_097 */#else /* LIBDES */#ifdef UNIX#define des_set_random_generator_seed(x) des_init_random_number_generator(x)#endif /* UNIX */#ifdef OS2#define des_new_random_key ck_des_new_random_key#define des_set_random_generator_seed ck_des_set_random_generator_seed#define des_key_sched ck_des_key_sched#define des_ecb_encrypt ck_des_ecb_encrypt#define des_string_to_key ck_des_string_to_key#define des_fixup_key_parity ck_des_fixup_key_parity#endif /* OS2 */#endif /* LIBDES */#ifdef CK_DES/* This code comes from Eric Young's libdes package and is not part *//* of the standard MIT DES library that is part of Kerberos. However, *//* it is extremely useful. So we add it here. *//* Weak and semi week keys as take from * %A D.W. Davies * %A W.L. Price * %T Security for Computer Networks * %I John Wiley & Sons * %D 1984 * Many thanks to smb@ulysses.att.com (Steven Bellovin) for the reference * (and actual cblock values). */#define NUM_WEAK_KEY 16static Block weak_keys[NUM_WEAK_KEY]={ /* weak keys */ {0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01}, {0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE}, {0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F}, {0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0}, /* semi-weak keys */ {0x01,0xFE,0x01,0xFE,0x01,0xFE,0x01,0xFE}, {0xFE,0x01,0xFE,0x01,0xFE,0x01,0xFE,0x01}, {0x1F,0xE0,0x1F,0xE0,0x0E,0xF1,0x0E,0xF1}, {0xE0,0x1F,0xE0,0x1F,0xF1,0x0E,0xF1,0x0E}, {0x01,0xE0,0x01,0xE0,0x01,0xF1,0x01,0xF1}, {0xE0,0x01,0xE0,0x01,0xF1,0x01,0xF1,0x01}, {0x1F,0xFE,0x1F,0xFE,0x0E,0xFE,0x0E,0xFE}, {0xFE,0x1F,0xFE,0x1F,0xFE,0x0E,0xFE,0x0E}, {0x01,0x1F,0x01,0x1F,0x01,0x0E,0x01,0x0E}, {0x1F,0x01,0x1F,0x01,0x0E,0x01,0x0E,0x01}, {0xE0,0xFE,0xE0,0xFE,0xF1,0xFE,0xF1,0xFE}, {0xFE,0xE0,0xFE,0xE0,0xFE,0xF1,0xFE,0xF1}};intck_des_is_weak_key(key)Block key;{ int i; for (i=0; i<NUM_WEAK_KEY; i++) { /* Added == 0 to comparision, I obviously don't run * this section very often :-(, thanks to * engineering@MorningStar.Com for the fix * eay 93/06/29 * Another problem, I was comparing only the first 4 * bytes, 97/03/18 */ if (memcmp(weak_keys[i],key,sizeof(Block)) == 0) return(1); } return(0);}#ifdef UNIX#ifdef LIBDES/* These functions are not part of Eric Young's DES library *//* _unix_time_gmt_unixsec *//* _des_set_random_generator_seed *//* _des_fixup_key_parity (added in 0.9.5) *//* _des_new_random_key */#include <sys/time.h>unsigned longunix_time_gmt_unixsec (usecptr) unsigned long *usecptr;{ struct timeval now; (void) gettimeofday (&now, (struct timezone *)0); if (usecptr) *usecptr = now.tv_usec; return now.tv_sec;}voiddes_set_random_generator_seed(Block B){ des_random_seed(B); return;}#ifdef COMMENT/* added to openssl in 0.9.5 */voiddes_fixup_key_parity(Block B){ des_set_odd_parity(B); return;}#endif /* COMMENT */intdes_new_random_key(Block B){ int rc=0; rc = des_random_key(B); return(rc);}#endif /* LIBDES */#endif /* UNIX */#endif /* 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 @(#)encrypt.c 8.1 (Berkeley) 6/4/93 *//* * Copyright (C) 1990 by the Massachusetts Institute of Technology * * Export of this software from the United States of America may * require a specific license from the United States Government. * It is the responsibility of any person or organization contemplating * export to obtain such a license before exporting. * * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and * distribute this software and its documentation for any purpose and * without fee is hereby granted, provided that the above copyright * notice appear in all copies and that both that copyright notice and * this permission notice appear in supporting documentation, and that * the name of M.I.T. not be used in advertising or publicity pertaining * to distribution of the software without specific, written prior * permission. M.I.T. makes no representations about the suitability of * this software for any purpose. It is provided "as is" without express * or implied warranty. */#include <stdio.h>/* * These function pointers point to the current routines * for encrypting and decrypting data. */static VOID (*encrypt_output) P((unsigned char *, int));static int (*decrypt_input) P((int));#ifdef DEBUGstatic int encrypt_debug_mode = 1;static int encrypt_verbose = 1;#elsestatic int encrypt_verbose = 1;static int encrypt_debug_mode = 0;#endifstatic char dbgbuf [16384];static int decrypt_mode = 0;static int encrypt_mode = 0;static int autoencrypt = 1;static int autodecrypt = 1;static int havesessionkey = 0;static kstream EncryptKSGlobalHack = NULL;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -