📄 mit_stringtokey.c
字号:
#ifdef M_KERB/* * $Id: mit_stringtokey.c,v 1.1.1.1 2001/08/10 20:49:28 bonze Exp $ * * Copyright 1985, 1986, 1987, 1988, 1989 by the Massachusetts Institute * of Technology. * * For copying and distribution information, please see the file * <mit-copyright.h>. * * These routines perform encryption and decryption using the DES * private key algorithm, or else a subset of it-- fewer inner loops. * (AUTH_DES_ITER defaults to 16, may be less.) * * Under U.S. law, this software may not be exported outside the US * without license from the U.S. Commerce department. * * The key schedule is passed as an arg, as well as the cleartext or * ciphertext. The cleartext and ciphertext should be in host order. * * These routines form the library interface to the DES facilities. * * spm 8/85 MIT project athena */#ifndef lintstatic char rcsid_string_to_key_c[] ="$Id: mit_stringtokey.c,v 1.1.1.1 2001/08/10 20:49:28 bonze Exp $";#endif /* lint */#include <mit-copyright.h>#include <stdio.h>#include <memory.h>#include <des.h>/*#include "des_internal.h"*/#if 1#include <krb.h>#endifextern int des_debug;extern int des_debug_print ();extern void des_fixup_key_parity ();/* * convert an arbitrary length string to a DES key */intmit_string_to_key (str, key)char *str;register des_cblock *key;{ register char *in_str; register unsigned temp, i; register int j; register long length; static unsigned char *k_p; static int forward; register char *p_char; static char k_char[64]; static des_key_schedule key_sked; extern unsigned long des_cbc_cksum (); in_str = str; forward = 1; p_char = k_char; length = strlen (str); /* init key array for bits */ memset (k_char, '\0', sizeof (k_char)); /* get next 8 bytes, strip parity, xor */ for (i = 1; i <= length; i++) { /* get next input key byte */ temp = (unsigned int) *str++; /* loop through bits within byte, ignore parity */ for (j = 0; j <= 6; j++) { if (forward) *p_char++ ^= (int) temp & 01; else *--p_char ^= (int) temp & 01; temp = temp >> 1; } while (--j > 0); /* check and flip direction */ if ((i % 8) == 0) forward = !forward; } /* now stuff into the key des_cblock, and force odd parity */ p_char = k_char; k_p = (unsigned char *) key; for (i = 0; i <= 7; i++) { temp = 0; for (j = 0; j <= 6; j++) temp |= *p_char++ << (1 + j); *k_p++ = (unsigned char) temp; } /* fix key parity */ des_fixup_key_parity (key); /* Now one-way encrypt it with the folded key */ (void) des_key_sched (key, key_sked); (void) des_cbc_cksum ((des_cblock *) in_str, key, length, key_sked, key); /* erase key_sked */ memset ((char *) key_sked, '\0', sizeof (key_sked)); /* now fix up key parity again */ des_fixup_key_parity (key);}int mit_passwd_to_key (user, instance, realm, passwd, key)char *user;char *instance;char *realm;char *passwd;C_Block key;{ mit_string_to_key (passwd, key); return (0);}#endif /* #ifdef M_KERB */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -