![]() |
Macintosh Development |
[Home]
[About Us]
[People]
[Information Systems]
[Kerberos for Macintosh]
[Applications]
[Miscellaneous Documentation]
![]() |
DES Library API Functions |
intdes_cbc_encrypt (des_cblock *in,
des_cblock *out,
long length,
des_key_schedule schedule,
des_cblock ivec,
int encrypt );voiddes_3cbc_encrypt (des_cblock *in,
des_cblock *out,
long length,
des_key_schedule ks1,
des_key_schedule ks2,
des_key_schedule ks3,
des_cblock ivec,
int encrypt );
des_cbc_encrypt()encrypts/decrypts using the cipher-blockchaining mode of DES.If the
encryptargument is nonzero, the routine cipher-block-chain encrypts the cleartext data pointed to by theinargument into the ciphertext pointed to by theoutargument, using the key schedule provided by thescheduleargument, and initialization vector provided by theivecargument. If thelengthargument is not an integral multiple of eight bytes, the last block is copied to a temp and zero filled (highest addresses).outis ALWAYS an integral multiple of eight bytes.If
encryptis zero, the routine cipher-block chain decrypts the (now) ciphertext data pointed to by theinargument into (now) cleartext pointed to by theoutargument using the key schedule provided by thescheduleargument, and initialization vector provided by theivecargument. Decryption ALWAYS operates on integral multiples of 8 bytes, so it will round the length provided up to the appropriate multiple. Consequently, it will always produce the rounded-up number of bytes of output cleartext. The application must determine if the output cleartext was zero-padded due to original cleartext lengths that were not integral multiples of 8.
des_3cbc_encrypt()does the same thing asdes_cbc_encrypt(), except using Kerberos 5 triple DES. In order to have enough bits of key,des_3cbc_encrypt()requires 3 key schedules.No errors or meaningful values are returned by either function.
unsigned longdes_cbc_cksum (des_cblock *in,
des_cblock *out,
long length,
des_key_schedule schedule,
des_cblock *ivec );
des_cbc_cksum()produces an 8 byte cryptographic checksum by cipher-block-chain encrypting the cleartext data pointed to by theinargument. All of the ciphertext output is discarded, except the last 8-byte ciphertext block, which is written into the area pointed to by theoutargument. It uses the key schedule, provided by thescheduleargument and initialization vector provided by theivecargument. If the length argument is not an integral multiple of eight bytes, the last cleartext block is copied to a temp and zero filled (highest addresses). The output is ALWAYS eight bytes.The routine also returns an unsigned long, which is the last (highest address) half of the 8 byte checksum computed.
intdes_ecb_encrypt (des_cblock *in,
des_cblock *out,
des_key_schedule schedule,
int encrypt );voiddes_3ebc_encrypt (des_cblock *in,
des_cblock *out,
des_key_schedule ks1,
des_key_schedule ks2,
des_key_schedule ks3,
int encrypt );
des_ecb_encrypt()is the basic DES encryption routine that encrypts or decrypts a single 8-byte block in electronic code book mode. It always transforms the input data, pointed to byin, into the output data, pointed to by theoutargument.If the
encryptargument is non-zero, thein(cleartext) is encrypted into theout(ciphertext) using the key schedule specified by thescheduleargument, previously set viades_set_key().If
encryptis zero, thein(now ciphertext) is decrypted into theout(now cleartext).Input and output may overlap. No errors or meaningful values are returned by either function.
intdes_pcbc_encrypt (des_cblock *in,
des_cblock *out,
long length,
des_key_schedule schedule,
des_cblock *ivec,
int encrypt );
des_pcbc_encrypt()encrypts/decrypts using a modified block chaining mode. Its calling sequence is identical todes_cbc_encrypt(). It differs in its error propagation characteristics.
des_pcbc_encrypt()is recommended for most encryption purposes, in that modification of a single bit of the ciphertext will affect ALL the subsequent (decrypted) cleartext. Similarly, modifying a single bit of the cleartext will affect ALL the subsequent (encrypted) ciphertext. "PCBC" mode, on encryption, "xors" both the cleartext of block N and the ciphertext resulting from block N with the cleartext for block N+1 prior to encrypting block N+1.No errors or meaningful values are returned by either function.
unsigned longdes_quad_cksum (unsigned char *in, unsigned long *out, long length, int out_count, des_cblock *c_seed );
des_quad_cksum()calculates a manipulation detection code for a message. It is a much faster alternative to the DES-checksum method. No guarantees are offered for its security. Refer to "Message Authentication" R.R. Jueneman, S. M. Matyas, C.H. Meyer IEEE Communications Magazine, Sept 1985 Vol 23 No 9 p 29-40 for more information.
intdes_random_key (des_cblock *key );
des_random_key()generates a random DES encryption key (eight bytes), set to odd parity per FIPS specifications. This routine uses the current time, and a counter as a seed for the random number generator. The caller must supply space for the output key, pointed to by argumentkey, then after callingdes_random_key()should call thedes_set_key()routine when needed.No meaningful value is returned. Void is not used for compatibility with other compilers.
voiddes_init_random_number_generator (des_cblock key );voiddes_set_random_generator_seed (des_cblock key );intdes_new_random_key (des_cblock key );voiddes_set_sequence_number (des_cblock new_sequence_number );voiddes_generate_random_block (des_cblock block );These functions provide a better interface for creating random keys. By allowing the programmer to specify seeds, and the sequence number, the programmer can control randomness better than with des_random_key().
des_init_random_number_generator()takes a secret key possibly shared by a number of servers and uses it to generate a random number stream that is not shared by any of the other servers. It does this by callingdes_set_random_generator_seed()with the current time to the nearest 1/60th of a second. The resulting stream seed is not useful information for cracking the secret key. Moreover, this routine keeps no copy of the secret key.
des_new_random_key()setskeyto a new random key. The returned key has correct parity and is guaranteed not to be a weak DES key.des_generate_random_block()is used to provide the random bits.des_set_random_generator_seed()must be at called least once before this routine is called (callingdes_init_random_number_generator()is sufficient).
des_set_random_generator_seed()is used to select a random number stream. The stream that results is totally determined by the passed in key. (I.e., calling this routine again with the same key allows repeating a sequence of random numbers). The key must be a valid DES key: it must have correct parity and not be a weak DES key. Use this function if you do not want the key to be seeded by the current time.
des_set_sequence_number()is used to set the sequence number of the current random number stream. This routine may be used to "seek" within the current random number stream. Note thatdes_set_random_generator_seed()resets the sequence number to 0.
des_generate_random_block()returns the next random number from the current random number stream. The returned number is 64 bits long.des_set_random_generator_seed()must have been called at least once before this routine is called.
intdes_check_key_parity (register des_cblock key );voiddes_fixup_key_parity (register des_cblock key );
des_check_key_parity()returns true if key has the correct DES parity, false if not. Correct parity is defined as odd parity per byte; parity is bits 8,16,...64 in DES order, implies 0, 8, 16, ... in VAX byte order.
des_fixup_key_parity()modifies a key so that it has the correct parity for DES.
voiddes_is_weak_key (des_cblock key );
des_is_weak_key()returns true if key is a [semi-]weak DES key, false if the key is strong. You should not use weak keys.
intdes_string_to_key (char *str,
des_cblock key );intafs_des_string_to_key (char *str,
char *cell,
des_cblock key );
des_string_to_key()andafs_des_string_to_key()convert an arbitrary length null-terminated string to an 8 byte DES key, with odd byte parity, per FIPS specification. A one-way function is used to convert the string to a key, making it very difficult to reconstruct the string from the key. Thestrargument is a pointer to the string, andkeyshould point to a des_cblock supplied by the caller to receive the generated key.afs_des_string_to_key()also requirescell: the name of the AFS cell to authenticate to.Note:
des_string_to_key()is the MIT string to key function andafs_des_string_to_key()is the AFS string to key function. If you need to use a different string to key than either the MIT string to key or the AFS string to key, you will have to implement it yourself..No meaningful value is returned. Void is not used for compatibility with other compilers.
intdes_set_key (des_cblock *key,
des_key_schedule schedule );
des_set_key()calculates a key schedule from all eight bytes of the input key, pointed to by thekeyargument, and outputs the schedule into thedes_key_scheduleindicated by thescheduleargument. Make sure to pass a valid eight byte key; no padding is done. The key schedule may then be used in subsequent encryption/decryption/checksum operations. Many key schedules may be cached for later use. The user is responsible to clear keys and schedules as soon as no longer needed, to prevent their disclosure.The routine also checks the key parity, and returns a zero if the key parity is correct (odd), a -1 indicating a key parity error, or a -2 indicating use of an illegal weak key. If an error is returned, the key schedule was not created.
intmake_key_sched (des_cblock *key,
des_key_schedule schedule );intdes_key_sched (des_cblock k,
des_key_schedule schedule );
make_key_sched()computes the DES key schedule given a key
des_key_sched()does the same thing asmake_key_sched()except it also checks to make sure the key is not weak and has the correct parity. It returns a zero if successful, a -1 indicating a key parity error, or a -2 indicating use of a weak key.
char *des_crypt (const char *buf,
const char *salt );char *des_fcrypt (const char *buf,
const char *salt,
char *ret );
des_crypt()is effectively the UNIX crypt function.bufis the NULL-terminated C string to encrypt andsaltis the two character salt for the crypt cipher.des_crypt()returns the encrypted string. You should copy this string before callingdes_crypt()again.
des_fcrypt()is the same asdes_crypt(), except that the encrypted string is placed inret. You must allocate enough space for the encrypted string inret(14 bytes will be sufficient).
intdes_read_password (des_cblock *k,
char *prompt,
int verify );intdes_read_pw_string (char *s,
int max,
char *prompt,
int verify );
des_read_password()writes the string specified bypromptto the standard output, turns off echo (if possible) and reads an input string from standard input until terminated with a newline. Ifverifyis non-zero, it prompts and reads input again, for use in applications such as changing a password; both versions are compared, and the input is requested repeatedly until they match. Thendes_read_password()converts the input string into a valid DES key, internally usingdes_string_to_key(). The newly created key is copied to the area pointed to by thekeyargument.des_read_password()returns a zero if no errors occurred, or a -1 indicating that an error occurred trying to manipulate the terminal echo.
des_read_pw_string()reads in a password without callingdes_string_to_key()(des_read_password()callsdes_read_pw_string()internally).NOTE!
des_read_password()anddes_read_pw_string()are only for use with the Metrowerks SIOUX command line interfaces in Kerberos Support Library. If you are not using SIOUX, read in the password yourself and calldes_string_to_key()manually. Normally you will only use these functions for testing.
voiddes_cblock_print_file (des_cblock *x,
FILE *fp );
des_cblock_print_file()is a debugging function used to print out a key to a given FILE descriptor.des_cblock_print_file()is only for use with the Metrowerks SIOUX command line interfaces in MIT Support Library.
Questions or comments? Send mail to macdev@mit.edu
Last updated on $Date: 2003/11/19 20:42:25 $
Last modified by $Author: smcguire $