/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
*
* Copyright 1990,1991 by the Massachusetts Institute of Technology.
* All Rights Reserved.
*
* 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 <k5-int.h>
#include <des_int.h>
/*
converts the string pointed to by "data" into an encryption key
of type "enctype". *keyblock is filled in with the key info;
in particular, keyblock->contents is to be set to allocated storage.
It is the responsibility of the caller to release this storage
when the generated key no longer needed.
The routine may use "salt" to seed or alter the conversion
algorithm.
If the particular function called does not know how to make a
key of type "enctype", an error may be returned.
returns: errors
*/
{
register unsigned temp;
register long i;
register int j;
register long length;
unsigned char *k_p;
int forward;
register char *p_char;
#ifndef min
#define min(A, B) ((A) < (B) ? (A): (B))
#endif
if (salt
/* XXX Yuck! Aren't we done with this yet? */
char *at;
if (at) {
*at = 0;
} else
}
if (!copystr) {
return ENOMEM;
}
if (salt)
/* convert to des key */
forward = 1;
/* init key array for bits */
#if 0
if (mit_des_debug)
"\n\ninput str length = %d string = %*s\nstring = 0x ",
#endif
/* get next 8 bytes, strip parity, xor */
for (i = 1; i <= length; i++) {
/* get next input key byte */
#if 0
if (mit_des_debug)
#endif
/* loop through bits within byte, ignore parity */
for (j = 0; j <= 6; j++) {
if (forward)
else
}
/* check and flip direction */
if ((i%8) == 0)
}
/* now stuff into the key mit_des_cblock, and force odd parity */
for (i = 0; i <= 7; i++) {
temp = 0;
for (j = 0; j <= 6; j++)
}
/* fix key parity */
if (mit_des_is_weak_key(key))
/* clean & free the input string */
/* now fix up key parity again */
if (mit_des_is_weak_key(key))
/*
* Because this routine actually modifies the original keyblock
* in place we cannot use the PKCS#11 key object handle created earlier.
* Destroy the existing object handle associated with the key,
* a correct handle will get created when the key is actually
* used for the first time.
*/
}
return retval;
}