summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/rand
diff options
context:
space:
mode:
authorcvs2svn <admin@example.com>2016-07-23 19:31:36 +0000
committercvs2svn <admin@example.com>2016-07-23 19:31:36 +0000
commit86c49b31af735796dfde37aa29473a30d36367db (patch)
treee9a354a92a348338fe2b361e2eda703cae23cfab /src/lib/libcrypto/rand
parent19d5fe348e8926bac4521c5807aa64c45b8f7a41 (diff)
downloadopenbsd-OPENBSD_6_0_BASE.tar.gz
openbsd-OPENBSD_6_0_BASE.tar.bz2
openbsd-OPENBSD_6_0_BASE.zip
This commit was manufactured by cvs2git to create tag 'OPENBSD_6_0_BASE'.OPENBSD_6_0_BASE
Diffstat (limited to '')
-rw-r--r--src/lib/libcrypto/rand/rand.h127
-rw-r--r--src/lib/libcrypto/rand/rand_err.c101
-rw-r--r--src/lib/libcrypto/rand/rand_lib.c100
-rw-r--r--src/lib/libcrypto/rand/randfile.c143
4 files changed, 0 insertions, 471 deletions
diff --git a/src/lib/libcrypto/rand/rand.h b/src/lib/libcrypto/rand/rand.h
deleted file mode 100644
index fcb2e9218d..0000000000
--- a/src/lib/libcrypto/rand/rand.h
+++ /dev/null
@@ -1,127 +0,0 @@
1/* $OpenBSD: rand.h,v 1.22 2014/10/22 14:02:52 jsing Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdlib.h>
60
61#ifndef HEADER_RAND_H
62#define HEADER_RAND_H
63
64#include <openssl/opensslconf.h>
65
66#include <openssl/ossl_typ.h>
67
68#ifdef __cplusplus
69extern "C" {
70#endif
71
72/* Already defined in ossl_typ.h */
73/* typedef struct rand_meth_st RAND_METHOD; */
74
75struct rand_meth_st {
76 void (*seed)(const void *buf, int num);
77 int (*bytes)(unsigned char *buf, int num);
78 void (*cleanup)(void);
79 void (*add)(const void *buf, int num, double entropy);
80 int (*pseudorand)(unsigned char *buf, int num);
81 int (*status)(void);
82};
83
84int RAND_set_rand_method(const RAND_METHOD *meth);
85const RAND_METHOD *RAND_get_rand_method(void);
86#ifndef OPENSSL_NO_ENGINE
87int RAND_set_rand_engine(ENGINE *engine);
88#endif
89RAND_METHOD *RAND_SSLeay(void);
90
91#ifndef LIBRESSL_INTERNAL
92void RAND_cleanup(void );
93int RAND_bytes(unsigned char *buf, int num);
94int RAND_pseudo_bytes(unsigned char *buf, int num);
95void RAND_seed(const void *buf, int num);
96void RAND_add(const void *buf, int num, double entropy);
97int RAND_load_file(const char *file, long max_bytes);
98int RAND_write_file(const char *file);
99const char *RAND_file_name(char *file, size_t num);
100int RAND_status(void);
101int RAND_poll(void);
102#endif
103
104/* BEGIN ERROR CODES */
105/* The following lines are auto generated by the script mkerr.pl. Any changes
106 * made after this point may be overwritten when the script is next run.
107 */
108void ERR_load_RAND_strings(void);
109
110/* Error codes for the RAND functions. (no longer used) */
111
112/* Function codes. */
113#define RAND_F_RAND_GET_RAND_METHOD 101
114#define RAND_F_RAND_INIT_FIPS 102
115#define RAND_F_SSLEAY_RAND_BYTES 100
116
117/* Reason codes. */
118#define RAND_R_DUAL_EC_DRBG_DISABLED 104
119#define RAND_R_ERROR_INITIALISING_DRBG 102
120#define RAND_R_ERROR_INSTANTIATING_DRBG 103
121#define RAND_R_NO_FIPS_RANDOM_METHOD_SET 101
122#define RAND_R_PRNG_NOT_SEEDED 100
123
124#ifdef __cplusplus
125}
126#endif
127#endif
diff --git a/src/lib/libcrypto/rand/rand_err.c b/src/lib/libcrypto/rand/rand_err.c
deleted file mode 100644
index 3f91fcb37b..0000000000
--- a/src/lib/libcrypto/rand/rand_err.c
+++ /dev/null
@@ -1,101 +0,0 @@
1/* $OpenBSD: rand_err.c,v 1.14 2014/07/10 22:45:57 jsing Exp $ */
2/* ====================================================================
3 * Copyright (c) 1999-2011 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/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file,
58 * only reason strings will be preserved.
59 */
60
61#include <stdio.h>
62
63#include <openssl/opensslconf.h>
64
65#include <openssl/err.h>
66#include <openssl/rand.h>
67
68/* BEGIN ERROR CODES */
69#ifndef OPENSSL_NO_ERR
70
71#define ERR_FUNC(func) ERR_PACK(ERR_LIB_RAND,func,0)
72#define ERR_REASON(reason) ERR_PACK(ERR_LIB_RAND,0,reason)
73
74static ERR_STRING_DATA RAND_str_functs[] = {
75 {ERR_FUNC(RAND_F_RAND_GET_RAND_METHOD), "RAND_get_rand_method"},
76 {ERR_FUNC(RAND_F_RAND_INIT_FIPS), "RAND_init_fips"},
77 {ERR_FUNC(RAND_F_SSLEAY_RAND_BYTES), "SSLEAY_RAND_BYTES"},
78 {0, NULL}
79};
80
81static ERR_STRING_DATA RAND_str_reasons[] = {
82 {ERR_REASON(RAND_R_DUAL_EC_DRBG_DISABLED), "dual ec drbg disabled"},
83 {ERR_REASON(RAND_R_ERROR_INITIALISING_DRBG), "error initialising drbg"},
84 {ERR_REASON(RAND_R_ERROR_INSTANTIATING_DRBG), "error instantiating drbg"},
85 {ERR_REASON(RAND_R_NO_FIPS_RANDOM_METHOD_SET), "no fips random method set"},
86 {ERR_REASON(RAND_R_PRNG_NOT_SEEDED) , "PRNG not seeded"},
87 {0, NULL}
88};
89
90#endif
91
92void
93ERR_load_RAND_strings(void)
94{
95#ifndef OPENSSL_NO_ERR
96 if (ERR_func_error_string(RAND_str_functs[0].error) == NULL) {
97 ERR_load_strings(0, RAND_str_functs);
98 ERR_load_strings(0, RAND_str_reasons);
99 }
100#endif
101}
diff --git a/src/lib/libcrypto/rand/rand_lib.c b/src/lib/libcrypto/rand/rand_lib.c
deleted file mode 100644
index 8342a55f05..0000000000
--- a/src/lib/libcrypto/rand/rand_lib.c
+++ /dev/null
@@ -1,100 +0,0 @@
1/* $OpenBSD: rand_lib.c,v 1.20 2014/10/22 13:02:04 jsing Exp $ */
2/*
3 * Copyright (c) 2014 Ted Unangst <tedu@openbsd.org>
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18#include <stdlib.h>
19
20#include <openssl/opensslconf.h>
21
22#include <openssl/rand.h>
23
24/*
25 * The useful functions in this file are at the bottom.
26 */
27int
28RAND_set_rand_method(const RAND_METHOD *meth)
29{
30 return 1;
31}
32
33const RAND_METHOD *
34RAND_get_rand_method(void)
35{
36 return NULL;
37}
38
39RAND_METHOD *
40RAND_SSLeay(void)
41{
42 return NULL;
43}
44
45#ifndef OPENSSL_NO_ENGINE
46int
47RAND_set_rand_engine(ENGINE *engine)
48{
49 return 1;
50}
51#endif
52
53void
54RAND_cleanup(void)
55{
56
57}
58
59void
60RAND_seed(const void *buf, int num)
61{
62
63}
64
65void
66RAND_add(const void *buf, int num, double entropy)
67{
68
69}
70
71int
72RAND_status(void)
73{
74 return 1;
75}
76
77int
78RAND_poll(void)
79{
80 return 1;
81}
82
83/*
84 * Hurray. You've made it to the good parts.
85 */
86int
87RAND_bytes(unsigned char *buf, int num)
88{
89 if (num > 0)
90 arc4random_buf(buf, num);
91 return 1;
92}
93
94int
95RAND_pseudo_bytes(unsigned char *buf, int num)
96{
97 if (num > 0)
98 arc4random_buf(buf, num);
99 return 1;
100}
diff --git a/src/lib/libcrypto/rand/randfile.c b/src/lib/libcrypto/rand/randfile.c
deleted file mode 100644
index 72c065c48d..0000000000
--- a/src/lib/libcrypto/rand/randfile.c
+++ /dev/null
@@ -1,143 +0,0 @@
1/* $OpenBSD: randfile.c,v 1.42 2015/09/10 15:56:25 jsing Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <errno.h>
60#include <stdio.h>
61#include <stdlib.h>
62#include <unistd.h>
63#include <string.h>
64
65#include <openssl/crypto.h>
66#include <openssl/rand.h>
67#include <openssl/buffer.h>
68
69#include <sys/types.h>
70#include <sys/stat.h>
71#include <fcntl.h>
72
73#undef BUFSIZE
74#define BUFSIZE 1024
75#define RAND_DATA 1024
76
77/* Note that these functions should not be used. */
78
79int
80RAND_load_file(const char *file, long bytes)
81{
82 /* the "whole" file */
83 if (bytes == -1)
84 return 123456;
85 else
86 return bytes;
87}
88
89int
90RAND_write_file(const char *file)
91{
92 unsigned char buf[BUFSIZE];
93 int i, ret = 0;
94 FILE *out = NULL;
95 int n, fd;
96 struct stat sb;
97
98 /*
99 * If this file is a device, avoid opening it.
100 * XXX TOCTOU
101 */
102 if (stat(file, &sb) != -1 &&
103 (S_ISBLK(sb.st_mode) || S_ISCHR(sb.st_mode))) {
104 return (1);
105 }
106
107 fd = open(file, O_WRONLY|O_CREAT, 0600);
108 if (fd == -1)
109 return (1);
110 out = fdopen(fd, "wb");
111
112 if (out == NULL) {
113 close(fd);
114 return (1);
115 }
116
117 n = RAND_DATA;
118 for (;;) {
119 i = (n > BUFSIZE) ? BUFSIZE : n;
120 n -= BUFSIZE;
121 arc4random_buf(buf, i);
122 i = fwrite(buf, 1, i, out);
123 if (i <= 0) {
124 ret = 0;
125 break;
126 }
127 ret += i;
128 if (n <= 0)
129 break;
130 }
131
132 fclose(out);
133 explicit_bzero(buf, BUFSIZE);
134 return ret;
135}
136
137const char *
138RAND_file_name(char * buf, size_t size)
139{
140 if (strlcpy(buf, "/dev/urandom", size) >= size)
141 return (NULL);
142 return buf;
143}