155714Skris/* crypto/des/rand_key.c */ 259191Skris/* ==================================================================== 359191Skris * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved. 455714Skris * 555714Skris * Redistribution and use in source and binary forms, with or without 655714Skris * modification, are permitted provided that the following conditions 755714Skris * are met: 859191Skris * 959191Skris * 1. Redistributions of source code must retain the above copyright 10296465Sdelphij * notice, this list of conditions and the following disclaimer. 1159191Skris * 1255714Skris * 2. Redistributions in binary form must reproduce the above copyright 1359191Skris * notice, this list of conditions and the following disclaimer in 1459191Skris * the documentation and/or other materials provided with the 1559191Skris * distribution. 1659191Skris * 1759191Skris * 3. All advertising materials mentioning features or use of this 1859191Skris * software must display the following acknowledgment: 1959191Skris * "This product includes software developed by the OpenSSL Project 2059191Skris * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" 2159191Skris * 2259191Skris * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to 2359191Skris * endorse or promote products derived from this software without 2459191Skris * prior written permission. For written permission, please contact 2559191Skris * openssl-core@openssl.org. 2659191Skris * 2759191Skris * 5. Products derived from this software may not be called "OpenSSL" 2859191Skris * nor may "OpenSSL" appear in their names without prior written 2959191Skris * permission of the OpenSSL Project. 3059191Skris * 3159191Skris * 6. Redistributions of any form whatsoever must retain the following 3259191Skris * acknowledgment: 3359191Skris * "This product includes software developed by the OpenSSL Project 3459191Skris * for use in the OpenSSL Toolkit (http://www.openssl.org/)" 3559191Skris * 3659191Skris * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY 3759191Skris * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 3859191Skris * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 3959191Skris * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR 4059191Skris * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 4159191Skris * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 4259191Skris * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 4359191Skris * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 4459191Skris * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 4559191Skris * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 4659191Skris * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 4759191Skris * OF THE POSSIBILITY OF SUCH DAMAGE. 4859191Skris * ==================================================================== 4959191Skris * 5059191Skris * This product includes cryptographic software written by Eric Young 5159191Skris * (eay@cryptsoft.com). This product includes software written by Tim 5259191Skris * Hudson (tjh@cryptsoft.com). 5359191Skris * 5455714Skris */ 5555714Skris 5659191Skris#include <openssl/des.h> 5759191Skris#include <openssl/rand.h> 5855714Skris 59109998Smarkmint DES_random_key(DES_cblock *ret) 60296465Sdelphij{ 61296465Sdelphij do { 62296465Sdelphij if (RAND_bytes((unsigned char *)ret, sizeof(DES_cblock)) != 1) 63296465Sdelphij return (0); 64296465Sdelphij } while (DES_is_weak_key(ret)); 65296465Sdelphij DES_set_odd_parity(ret); 66296465Sdelphij return (1); 67296465Sdelphij} 68