/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 1997 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* Portions of this source code were derived from Berkeley 4.3 BSD
* under license from the Regents of the University of California.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
*/
#include <mp.h>
#include <time.h>
#include <stdlib.h>
extern void des_setparity(char *);
extern void des_setparity_g(des_block *);
/*
* seed the random generator. Here we use the time of day and a supplied
* password for generating the seed.
*/
static void
{
int i;
int rseed;
for (i = 0; i < 8; i++) {
}
}
/*
* Adjust the input key so that it is 0-filled on the left and store
* the results in key out.
*/
static void
{
char *p;
char *s;
for (p = keyin; *p; p++);
*s = *p;
}
while (s >= keyout) {
*s-- = '0';
}
}
/*
* __generic_gen_dhkeys: Classic Diffie-Hellman key pair generation.
* Generate a Diffie-Hellman key pair of a given key length using
* the supplied modulus and root. To calculate the pair we generate
* a random key of the appropriate key length modulo the modulus.
* This random key is the private key of the key pair. We now compute
* the public key as PublicKey = root^PrivateKey % modulus. This routine
* make use of libmp to do the multiprecision interger arithmetic.
*/
void
char *xmodulus, /* The modulus */
int proot, /* The prime root */
char *public, /* Public key */
char *secret, /* Private key */
char *pass /* password to seed with for private key */)
{
int i, len;
/* Convert the modulus from a hex string to a MINT */
unsigned char seed;
char *xkey;
/* Seed the random generate */
/*
* We will break up the private key into groups of BASEBITS where
* BASEBITS is equal to the number of bits in an integer type.
* Curently, basebits is 8 so the integral type is a character.
* We will calculate the number of BASEBITS units that we need so
* that we have at least keylen bits.
*/
/*
* Now for each BASEBITS we calculate a new random number.
* Shift the private key by base bits and then add the
* generated random number.
*/
for (i = 0; i < len; i++) {
/* get a random number */
/* Convert it to a MINT */
/* Shift the private key */
/* Add in the new low order bits */
/* Free tmp */
}
/* Set timp to 0 */
/* We get the private keys as private key modulo the modulus */
/* Done with tmp */
/* The public key is root^sk % modulus */
/* Convert the private key to a hex string */
/* Set leading zeros if necessary and store in secret */
/* Done with xkey */
/* Now set xkey to the hex representation of the public key */
/* Set leading zeros and store in public */
/* Free storage */
}
/*
* Given a key extract keynum des keys
*/
static void
{
MINT *a;
short r;
int i;
char *k;
/* len is the total number of bits we need for keynum des keys */
/* Create a MINT a to hold the common key */
a = mp_itom(0);
/*
* Calculate the middle byte in the key. We will simply extract
* the middle bits of the key for the bits in our DES keys.
*/
/*
* Now take our middle bits referenced by a and shove them
* into the array of DES keys.
*/
k = (char *)keys;
*k++ = r;
}
/* We're done with a */
mp_mfree(a);
/* Set the DES parity for each key */
for (i = 0; i < keynum; i++)
des_setparity((char *)&keys[i]);
else
des_setparity_g(&keys[i]);
}
/*
* __generic_common_dhkeys: Generate a set of DES keys based on
* the Diffie-Hellman common key derived from the supplied key pair
* of the given key length using the passed in modulus. The common key
* is calculated as:
*
* ck = pk ^ sk % modulus
*
* We will use the above routine to extract a set of DES keys for the
* caller.
*/
void
char *skey, /* Our private key */
int keylen, /* All the keys have this many bits */
char *xmodulus, /* The modulus */
int keynum /* The number of DES keys to create */)
{
/* Convert hex string representations to MINTS */
/* Create a MINT for the common key */
/* ck = pk ^ sk % modulus */
/* Set the DES keys */
/* Clean up */
}