diff options
| author | tb <> | 2023-12-20 06:28:04 +0000 |
|---|---|---|
| committer | tb <> | 2023-12-20 06:28:04 +0000 |
| commit | a64dedb93dbc7012516776b59fb61ecf77b553f7 (patch) | |
| tree | 9d7f2b4d85018c448bfac2b2337cbf21bd97c149 /src | |
| parent | b1a87d3488f8cb56f4a1453e4ac6f8c2170da70b (diff) | |
| download | openbsd-a64dedb93dbc7012516776b59fb61ecf77b553f7.tar.gz openbsd-a64dedb93dbc7012516776b59fb61ecf77b553f7.tar.bz2 openbsd-a64dedb93dbc7012516776b59fb61ecf77b553f7.zip | |
DES_random_key() sets the key
There's no need to have 60 lines of license for 4 lines of actual code.
Move DES_random_key() to set_key.c.
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/libcrypto/Makefile | 3 | ||||
| -rw-r--r-- | src/lib/libcrypto/des/rand_key.c | 68 | ||||
| -rw-r--r-- | src/lib/libcrypto/des/set_key.c | 15 |
3 files changed, 15 insertions, 71 deletions
diff --git a/src/lib/libcrypto/Makefile b/src/lib/libcrypto/Makefile index 2a793f8aee..d97358900d 100644 --- a/src/lib/libcrypto/Makefile +++ b/src/lib/libcrypto/Makefile | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.156 2023/11/12 10:49:27 robert Exp $ | 1 | # $OpenBSD: Makefile,v 1.157 2023/12/20 06:28:04 tb Exp $ |
| 2 | 2 | ||
| 3 | LIB= crypto | 3 | LIB= crypto |
| 4 | LIBREBUILD=y | 4 | LIBREBUILD=y |
| @@ -284,7 +284,6 @@ SRCS+= ofb64enc.c | |||
| 284 | SRCS+= ofb_enc.c | 284 | SRCS+= ofb_enc.c |
| 285 | SRCS+= pcbc_enc.c | 285 | SRCS+= pcbc_enc.c |
| 286 | SRCS+= qud_cksm.c | 286 | SRCS+= qud_cksm.c |
| 287 | SRCS+= rand_key.c | ||
| 288 | SRCS+= set_key.c | 287 | SRCS+= set_key.c |
| 289 | SRCS+= str2key.c | 288 | SRCS+= str2key.c |
| 290 | SRCS+= xcbc_enc.c | 289 | SRCS+= xcbc_enc.c |
diff --git a/src/lib/libcrypto/des/rand_key.c b/src/lib/libcrypto/des/rand_key.c deleted file mode 100644 index aba899fe0a..0000000000 --- a/src/lib/libcrypto/des/rand_key.c +++ /dev/null | |||
| @@ -1,68 +0,0 @@ | |||
| 1 | /* $OpenBSD: rand_key.c,v 1.9 2023/07/08 07:11:07 beck Exp $ */ | ||
| 2 | /* ==================================================================== | ||
| 3 | * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved. | ||
| 4 | * | ||
| 5 | * Redistribution and use in source and binary forms, with or without | ||
| 6 | * modification, are permitted provided that the following conditions | ||
| 7 | * are met: | ||
| 8 | * | ||
| 9 | * 1. Redistributions of source code must retain the above copyright | ||
| 10 | * notice, this list of conditions and the following disclaimer. | ||
| 11 | * | ||
| 12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer in | ||
| 14 | * the documentation and/or other materials provided with the | ||
| 15 | * distribution. | ||
| 16 | * | ||
| 17 | * 3. All advertising materials mentioning features or use of this | ||
| 18 | * software must display the following acknowledgment: | ||
| 19 | * "This product includes software developed by the OpenSSL Project | ||
| 20 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | ||
| 21 | * | ||
| 22 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 23 | * endorse or promote products derived from this software without | ||
| 24 | * prior written permission. For written permission, please contact | ||
| 25 | * openssl-core@openssl.org. | ||
| 26 | * | ||
| 27 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 28 | * nor may "OpenSSL" appear in their names without prior written | ||
| 29 | * permission of the OpenSSL Project. | ||
| 30 | * | ||
| 31 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 32 | * acknowledgment: | ||
| 33 | * "This product includes software developed by the OpenSSL Project | ||
| 34 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | ||
| 35 | * | ||
| 36 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 37 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 38 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 39 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 40 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 41 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 42 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 43 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 44 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 45 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 46 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 47 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 48 | * ==================================================================== | ||
| 49 | * | ||
| 50 | * This product includes cryptographic software written by Eric Young | ||
| 51 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 52 | * Hudson (tjh@cryptsoft.com). | ||
| 53 | * | ||
| 54 | */ | ||
| 55 | |||
| 56 | #include <stdlib.h> | ||
| 57 | |||
| 58 | #include <openssl/des.h> | ||
| 59 | |||
| 60 | int | ||
| 61 | DES_random_key(DES_cblock *ret) | ||
| 62 | { | ||
| 63 | do { | ||
| 64 | arc4random_buf(ret, sizeof(DES_cblock)); | ||
| 65 | DES_set_odd_parity(ret); | ||
| 66 | } while (DES_is_weak_key(ret)); | ||
| 67 | return (1); | ||
| 68 | } | ||
diff --git a/src/lib/libcrypto/des/set_key.c b/src/lib/libcrypto/des/set_key.c index c1fd02846f..d1b6fa6e8d 100644 --- a/src/lib/libcrypto/des/set_key.c +++ b/src/lib/libcrypto/des/set_key.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: set_key.c,v 1.24 2023/12/20 06:22:27 tb Exp $ */ | 1 | /* $OpenBSD: set_key.c,v 1.25 2023/12/20 06:28:04 tb Exp $ */ |
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
| 3 | * All rights reserved. | 3 | * All rights reserved. |
| 4 | * | 4 | * |
| @@ -63,7 +63,10 @@ | |||
| 63 | * 1.1 added norm_expand_bits | 63 | * 1.1 added norm_expand_bits |
| 64 | * 1.0 First working version | 64 | * 1.0 First working version |
| 65 | */ | 65 | */ |
| 66 | #include <stdlib.h> | ||
| 67 | |||
| 66 | #include <openssl/crypto.h> | 68 | #include <openssl/crypto.h> |
| 69 | |||
| 67 | #include "des_local.h" | 70 | #include "des_local.h" |
| 68 | 71 | ||
| 69 | int DES_check_key = 0; /* defaults to false */ | 72 | int DES_check_key = 0; /* defaults to false */ |
| @@ -398,3 +401,13 @@ DES_key_sched(const_DES_cblock *key, DES_key_schedule *schedule) | |||
| 398 | { | 401 | { |
| 399 | return (DES_set_key(key, schedule)); | 402 | return (DES_set_key(key, schedule)); |
| 400 | } | 403 | } |
| 404 | |||
| 405 | int | ||
| 406 | DES_random_key(DES_cblock *ret) | ||
| 407 | { | ||
| 408 | do { | ||
| 409 | arc4random_buf(ret, sizeof(DES_cblock)); | ||
| 410 | DES_set_odd_parity(ret); | ||
| 411 | } while (DES_is_weak_key(ret)); | ||
| 412 | return (1); | ||
| 413 | } | ||
