diff options
author | jsing <> | 2014-05-24 15:25:23 +0000 |
---|---|---|
committer | jsing <> | 2014-05-24 15:25:23 +0000 |
commit | 03c32317f399a254994b5a704297afdf85b96733 (patch) | |
tree | 30ae63ae77f1024d8a860bb6c9cfd61b228b1b00 /src | |
parent | 694736847951a5eb292719b02fe4b0db4d09766f (diff) | |
download | openbsd-03c32317f399a254994b5a704297afdf85b96733.tar.gz openbsd-03c32317f399a254994b5a704297afdf85b96733.tar.bz2 openbsd-03c32317f399a254994b5a704297afdf85b96733.zip |
KNF.
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/libcrypto/rand/rand.h | 29 | ||||
-rw-r--r-- | src/lib/libcrypto/rand/rand_err.c | 49 | ||||
-rw-r--r-- | src/lib/libcrypto/rand/rand_lib.c | 2 | ||||
-rw-r--r-- | src/lib/libcrypto/rand/randfile.c | 102 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/rand/rand.h | 29 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/rand/rand_err.c | 49 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/rand/rand_lib.c | 2 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/rand/randfile.c | 102 |
8 files changed, 182 insertions, 182 deletions
diff --git a/src/lib/libcrypto/rand/rand.h b/src/lib/libcrypto/rand/rand.h index 30b22afaf3..7e0f09d03c 100644 --- a/src/lib/libcrypto/rand/rand.h +++ b/src/lib/libcrypto/rand/rand.h | |||
@@ -5,21 +5,21 @@ | |||
5 | * This package is an SSL implementation written | 5 | * This package is an SSL implementation written |
6 | * by Eric Young (eay@cryptsoft.com). | 6 | * by Eric Young (eay@cryptsoft.com). |
7 | * The implementation was written so as to conform with Netscapes SSL. | 7 | * The implementation was written so as to conform with Netscapes SSL. |
8 | * | 8 | * |
9 | * This library is free for commercial and non-commercial use as long as | 9 | * This library is free for commercial and non-commercial use as long as |
10 | * the following conditions are aheared to. The following conditions | 10 | * the following conditions are aheared to. The following conditions |
11 | * apply to all code found in this distribution, be it the RC4, RSA, | 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 | 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 | 13 | * included with this distribution is covered by the same copyright terms |
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). |
15 | * | 15 | * |
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | 16 | * Copyright remains Eric Young's, and as such any Copyright notices in |
17 | * the code are not to be removed. | 17 | * the code are not to be removed. |
18 | * If this package is used in a product, Eric Young should be given attribution | 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. | 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 | 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. | 21 | * in documentation (online or textual) provided with the package. |
22 | * | 22 | * |
23 | * Redistribution and use in source and binary forms, with or without | 23 | * Redistribution and use in source and binary forms, with or without |
24 | * modification, are permitted provided that the following conditions | 24 | * modification, are permitted provided that the following conditions |
25 | * are met: | 25 | * are met: |
@@ -34,10 +34,10 @@ | |||
34 | * Eric Young (eay@cryptsoft.com)" | 34 | * Eric Young (eay@cryptsoft.com)" |
35 | * The word 'cryptographic' can be left out if the rouines from the library | 35 | * The word 'cryptographic' can be left out if the rouines from the library |
36 | * being used are not cryptographic related :-). | 36 | * being used are not cryptographic related :-). |
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | 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: | 38 | * the apps directory (application code) you must include an acknowledgement: |
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" |
40 | * | 40 | * |
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND |
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
@@ -49,7 +49,7 @@ | |||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 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 | 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
51 | * SUCH DAMAGE. | 51 | * SUCH DAMAGE. |
52 | * | 52 | * |
53 | * The licence and distribution terms for any publically available version or | 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 | 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be |
55 | * copied and put under another distribution licence | 55 | * copied and put under another distribution licence |
@@ -72,15 +72,14 @@ extern "C" { | |||
72 | /* Already defined in ossl_typ.h */ | 72 | /* Already defined in ossl_typ.h */ |
73 | /* typedef struct rand_meth_st RAND_METHOD; */ | 73 | /* typedef struct rand_meth_st RAND_METHOD; */ |
74 | 74 | ||
75 | struct rand_meth_st | 75 | struct rand_meth_st { |
76 | { | ||
77 | void (*seed)(const void *buf, int num); | 76 | void (*seed)(const void *buf, int num); |
78 | int (*bytes)(unsigned char *buf, int num); | 77 | int (*bytes)(unsigned char *buf, int num); |
79 | void (*cleanup)(void); | 78 | void (*cleanup)(void); |
80 | void (*add)(const void *buf, int num, double entropy); | 79 | void (*add)(const void *buf, int num, double entropy); |
81 | int (*pseudorand)(unsigned char *buf, int num); | 80 | int (*pseudorand)(unsigned char *buf, int num); |
82 | int (*status)(void); | 81 | int (*status)(void); |
83 | }; | 82 | }; |
84 | 83 | ||
85 | int RAND_set_rand_method(const RAND_METHOD *meth); | 84 | int RAND_set_rand_method(const RAND_METHOD *meth); |
86 | const RAND_METHOD *RAND_get_rand_method(void); | 85 | const RAND_METHOD *RAND_get_rand_method(void); |
@@ -89,13 +88,13 @@ int RAND_set_rand_engine(ENGINE *engine); | |||
89 | #endif | 88 | #endif |
90 | RAND_METHOD *RAND_SSLeay(void); | 89 | RAND_METHOD *RAND_SSLeay(void); |
91 | void RAND_cleanup(void ); | 90 | void RAND_cleanup(void ); |
92 | int RAND_bytes(unsigned char *buf,int num); | 91 | int RAND_bytes(unsigned char *buf, int num); |
93 | int RAND_pseudo_bytes(unsigned char *buf,int num); | 92 | int RAND_pseudo_bytes(unsigned char *buf, int num); |
94 | void RAND_seed(const void *buf,int num); | 93 | void RAND_seed(const void *buf, int num); |
95 | void RAND_add(const void *buf,int num,double entropy); | 94 | void RAND_add(const void *buf, int num, double entropy); |
96 | int RAND_load_file(const char *file,long max_bytes); | 95 | int RAND_load_file(const char *file, long max_bytes); |
97 | int RAND_write_file(const char *file); | 96 | int RAND_write_file(const char *file); |
98 | const char *RAND_file_name(char *file,size_t num); | 97 | const char *RAND_file_name(char *file, size_t num); |
99 | int RAND_status(void); | 98 | int RAND_status(void); |
100 | int RAND_poll(void); | 99 | int RAND_poll(void); |
101 | 100 | ||
diff --git a/src/lib/libcrypto/rand/rand_err.c b/src/lib/libcrypto/rand/rand_err.c index c4c80fc8cc..64ae6e0650 100644 --- a/src/lib/libcrypto/rand/rand_err.c +++ b/src/lib/libcrypto/rand/rand_err.c | |||
@@ -7,7 +7,7 @@ | |||
7 | * are met: | 7 | * are met: |
8 | * | 8 | * |
9 | * 1. Redistributions of source code must retain the above copyright | 9 | * 1. Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. | 10 | * notice, this list of conditions and the following disclaimer. |
11 | * | 11 | * |
12 | * 2. Redistributions in binary form must reproduce the above copyright | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in | 13 | * notice, this list of conditions and the following disclaimer in |
@@ -68,34 +68,31 @@ | |||
68 | #define ERR_FUNC(func) ERR_PACK(ERR_LIB_RAND,func,0) | 68 | #define ERR_FUNC(func) ERR_PACK(ERR_LIB_RAND,func,0) |
69 | #define ERR_REASON(reason) ERR_PACK(ERR_LIB_RAND,0,reason) | 69 | #define ERR_REASON(reason) ERR_PACK(ERR_LIB_RAND,0,reason) |
70 | 70 | ||
71 | static ERR_STRING_DATA RAND_str_functs[]= | 71 | static ERR_STRING_DATA RAND_str_functs[]= { |
72 | { | 72 | {ERR_FUNC(RAND_F_RAND_GET_RAND_METHOD), "RAND_get_rand_method"}, |
73 | {ERR_FUNC(RAND_F_RAND_GET_RAND_METHOD), "RAND_get_rand_method"}, | 73 | {ERR_FUNC(RAND_F_RAND_INIT_FIPS), "RAND_init_fips"}, |
74 | {ERR_FUNC(RAND_F_RAND_INIT_FIPS), "RAND_init_fips"}, | 74 | {ERR_FUNC(RAND_F_SSLEAY_RAND_BYTES), "SSLEAY_RAND_BYTES"}, |
75 | {ERR_FUNC(RAND_F_SSLEAY_RAND_BYTES), "SSLEAY_RAND_BYTES"}, | 75 | {0, NULL} |
76 | {0,NULL} | 76 | }; |
77 | }; | ||
78 | 77 | ||
79 | static ERR_STRING_DATA RAND_str_reasons[]= | 78 | static ERR_STRING_DATA RAND_str_reasons[]= { |
80 | { | 79 | {ERR_REASON(RAND_R_DUAL_EC_DRBG_DISABLED), "dual ec drbg disabled"}, |
81 | {ERR_REASON(RAND_R_DUAL_EC_DRBG_DISABLED),"dual ec drbg disabled"}, | 80 | {ERR_REASON(RAND_R_ERROR_INITIALISING_DRBG), "error initialising drbg"}, |
82 | {ERR_REASON(RAND_R_ERROR_INITIALISING_DRBG),"error initialising drbg"}, | 81 | {ERR_REASON(RAND_R_ERROR_INSTANTIATING_DRBG), "error instantiating drbg"}, |
83 | {ERR_REASON(RAND_R_ERROR_INSTANTIATING_DRBG),"error instantiating drbg"}, | 82 | {ERR_REASON(RAND_R_NO_FIPS_RANDOM_METHOD_SET), "no fips random method set"}, |
84 | {ERR_REASON(RAND_R_NO_FIPS_RANDOM_METHOD_SET),"no fips random method set"}, | 83 | {ERR_REASON(RAND_R_PRNG_NOT_SEEDED) , "PRNG not seeded"}, |
85 | {ERR_REASON(RAND_R_PRNG_NOT_SEEDED) ,"PRNG not seeded"}, | 84 | {0, NULL} |
86 | {0,NULL} | 85 | }; |
87 | }; | ||
88 | 86 | ||
89 | #endif | 87 | #endif |
90 | 88 | ||
91 | void ERR_load_RAND_strings(void) | 89 | void |
92 | { | 90 | ERR_load_RAND_strings(void) |
91 | { | ||
93 | #ifndef OPENSSL_NO_ERR | 92 | #ifndef OPENSSL_NO_ERR |
94 | 93 | if (ERR_func_error_string(RAND_str_functs[0].error) == NULL) { | |
95 | if (ERR_func_error_string(RAND_str_functs[0].error) == NULL) | 94 | ERR_load_strings(0, RAND_str_functs); |
96 | { | 95 | ERR_load_strings(0, RAND_str_reasons); |
97 | ERR_load_strings(0,RAND_str_functs); | ||
98 | ERR_load_strings(0,RAND_str_reasons); | ||
99 | } | ||
100 | #endif | ||
101 | } | 96 | } |
97 | #endif | ||
98 | } | ||
diff --git a/src/lib/libcrypto/rand/rand_lib.c b/src/lib/libcrypto/rand/rand_lib.c index 6d61b3d3f6..c16c719855 100644 --- a/src/lib/libcrypto/rand/rand_lib.c +++ b/src/lib/libcrypto/rand/rand_lib.c | |||
@@ -74,7 +74,7 @@ RAND_status(void) | |||
74 | int | 74 | int |
75 | RAND_poll(void) | 75 | RAND_poll(void) |
76 | { | 76 | { |
77 | return 1; | 77 | return 1; |
78 | } | 78 | } |
79 | 79 | ||
80 | /* | 80 | /* |
diff --git a/src/lib/libcrypto/rand/randfile.c b/src/lib/libcrypto/rand/randfile.c index 5326f710c5..0689908ce0 100644 --- a/src/lib/libcrypto/rand/randfile.c +++ b/src/lib/libcrypto/rand/randfile.c | |||
@@ -5,21 +5,21 @@ | |||
5 | * This package is an SSL implementation written | 5 | * This package is an SSL implementation written |
6 | * by Eric Young (eay@cryptsoft.com). | 6 | * by Eric Young (eay@cryptsoft.com). |
7 | * The implementation was written so as to conform with Netscapes SSL. | 7 | * The implementation was written so as to conform with Netscapes SSL. |
8 | * | 8 | * |
9 | * This library is free for commercial and non-commercial use as long as | 9 | * This library is free for commercial and non-commercial use as long as |
10 | * the following conditions are aheared to. The following conditions | 10 | * the following conditions are aheared to. The following conditions |
11 | * apply to all code found in this distribution, be it the RC4, RSA, | 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 | 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 | 13 | * included with this distribution is covered by the same copyright terms |
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). |
15 | * | 15 | * |
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | 16 | * Copyright remains Eric Young's, and as such any Copyright notices in |
17 | * the code are not to be removed. | 17 | * the code are not to be removed. |
18 | * If this package is used in a product, Eric Young should be given attribution | 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. | 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 | 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. | 21 | * in documentation (online or textual) provided with the package. |
22 | * | 22 | * |
23 | * Redistribution and use in source and binary forms, with or without | 23 | * Redistribution and use in source and binary forms, with or without |
24 | * modification, are permitted provided that the following conditions | 24 | * modification, are permitted provided that the following conditions |
25 | * are met: | 25 | * are met: |
@@ -34,10 +34,10 @@ | |||
34 | * Eric Young (eay@cryptsoft.com)" | 34 | * Eric Young (eay@cryptsoft.com)" |
35 | * The word 'cryptographic' can be left out if the rouines from the library | 35 | * The word 'cryptographic' can be left out if the rouines from the library |
36 | * being used are not cryptographic related :-). | 36 | * being used are not cryptographic related :-). |
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | 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: | 38 | * the apps directory (application code) you must include an acknowledgement: |
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" |
40 | * | 40 | * |
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND |
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
@@ -49,7 +49,7 @@ | |||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 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 | 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
51 | * SUCH DAMAGE. | 51 | * SUCH DAMAGE. |
52 | * | 52 | * |
53 | * The licence and distribution terms for any publically available version or | 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 | 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be |
55 | * copied and put under another distribution licence | 55 | * copied and put under another distribution licence |
@@ -75,7 +75,8 @@ | |||
75 | 75 | ||
76 | /* Note that these functions should not be used. */ | 76 | /* Note that these functions should not be used. */ |
77 | 77 | ||
78 | int RAND_load_file(const char *file, long bytes) | 78 | int |
79 | RAND_load_file(const char *file, long bytes) | ||
79 | { | 80 | { |
80 | /* the "whole" file */ | 81 | /* the "whole" file */ |
81 | if (bytes == -1) | 82 | if (bytes == -1) |
@@ -84,65 +85,68 @@ int RAND_load_file(const char *file, long bytes) | |||
84 | return bytes; | 85 | return bytes; |
85 | } | 86 | } |
86 | 87 | ||
87 | int RAND_write_file(const char *file) | 88 | int |
88 | { | 89 | RAND_write_file(const char *file) |
90 | { | ||
89 | unsigned char buf[BUFSIZE]; | 91 | unsigned char buf[BUFSIZE]; |
90 | int i,ret=0,rand_err=0; | 92 | int i, ret = 0, rand_err = 0; |
91 | FILE *out = NULL; | 93 | FILE *out = NULL; |
92 | int n; | 94 | int n; |
93 | struct stat sb; | 95 | struct stat sb; |
94 | 96 | ||
95 | i=stat(file,&sb); | 97 | i = stat(file, &sb); |
96 | if (i != -1) { | 98 | if (i != -1) { |
97 | if (S_ISBLK(sb.st_mode) || S_ISCHR(sb.st_mode)) { | 99 | if (S_ISBLK(sb.st_mode) || S_ISCHR(sb.st_mode)) { |
98 | /* this file is a device. we don't write back to it. | 100 | /* this file is a device. we don't write back to it. |
99 | * we "succeed" on the assumption this is some sort | 101 | * we "succeed" on the assumption this is some sort |
100 | * of random device. Otherwise attempting to write to | 102 | * of random device. Otherwise attempting to write to |
101 | * and chmod the device causes problems. | 103 | * and chmod the device causes problems. |
102 | */ | 104 | */ |
103 | return(1); | 105 | return (1); |
104 | } | 106 | } |
105 | } | 107 | } |
106 | 108 | ||
107 | { | 109 | { |
108 | /* chmod(..., 0600) is too late to protect the file, | 110 | /* chmod(..., 0600) is too late to protect the file, |
109 | * permissions should be restrictive from the start */ | 111 | * permissions should be restrictive from the start */ |
110 | int fd = open(file, O_WRONLY|O_CREAT, 0600); | 112 | int fd = open(file, O_WRONLY|O_CREAT, 0600); |
111 | if (fd != -1) | 113 | if (fd != -1) |
112 | out = fdopen(fd, "wb"); | 114 | out = fdopen(fd, "wb"); |
113 | } | 115 | } |
114 | 116 | ||
115 | if (out == NULL) | 117 | if (out == NULL) |
116 | out = fopen(file,"wb"); | 118 | out = fopen(file, "wb"); |
117 | if (out == NULL) goto err; | 119 | if (out == NULL) |
120 | goto err; | ||
118 | 121 | ||
119 | chmod(file,0600); | 122 | chmod(file, 0600); |
120 | n=RAND_DATA; | 123 | n = RAND_DATA; |
121 | for (;;) | 124 | for (;;) { |
122 | { | 125 | i = (n > BUFSIZE) ? BUFSIZE : n; |
123 | i=(n > BUFSIZE)?BUFSIZE:n; | 126 | n -= BUFSIZE; |
124 | n-=BUFSIZE; | 127 | if (RAND_bytes(buf, i) <= 0) |
125 | if (RAND_bytes(buf,i) <= 0) | 128 | rand_err = 1; |
126 | rand_err=1; | 129 | i = fwrite(buf, 1, i, out); |
127 | i=fwrite(buf,1,i,out); | 130 | if (i <= 0) { |
128 | if (i <= 0) | 131 | ret = 0; |
129 | { | ||
130 | ret=0; | ||
131 | break; | 132 | break; |
132 | } | 133 | } |
133 | ret+=i; | 134 | ret += i; |
134 | if (n <= 0) break; | 135 | if (n <= 0) |
135 | } | 136 | break; |
137 | } | ||
136 | 138 | ||
137 | fclose(out); | 139 | fclose(out); |
138 | OPENSSL_cleanse(buf,BUFSIZE); | 140 | OPENSSL_cleanse(buf, BUFSIZE); |
141 | |||
139 | err: | 142 | err: |
140 | return (rand_err ? -1 : ret); | 143 | return (rand_err ? -1 : ret); |
141 | } | 144 | } |
142 | 145 | ||
143 | const char *RAND_file_name(char *buf, size_t size) | 146 | const char * |
147 | RAND_file_name(char *buf, size_t size) | ||
144 | { | 148 | { |
145 | if (strlcpy(buf,"/dev/urandom",size) >= size) | 149 | if (strlcpy(buf, "/dev/urandom", size) >= size) |
146 | return(NULL); | 150 | return (NULL); |
147 | return buf; | 151 | return buf; |
148 | } | 152 | } |
diff --git a/src/lib/libssl/src/crypto/rand/rand.h b/src/lib/libssl/src/crypto/rand/rand.h index 30b22afaf3..7e0f09d03c 100644 --- a/src/lib/libssl/src/crypto/rand/rand.h +++ b/src/lib/libssl/src/crypto/rand/rand.h | |||
@@ -5,21 +5,21 @@ | |||
5 | * This package is an SSL implementation written | 5 | * This package is an SSL implementation written |
6 | * by Eric Young (eay@cryptsoft.com). | 6 | * by Eric Young (eay@cryptsoft.com). |
7 | * The implementation was written so as to conform with Netscapes SSL. | 7 | * The implementation was written so as to conform with Netscapes SSL. |
8 | * | 8 | * |
9 | * This library is free for commercial and non-commercial use as long as | 9 | * This library is free for commercial and non-commercial use as long as |
10 | * the following conditions are aheared to. The following conditions | 10 | * the following conditions are aheared to. The following conditions |
11 | * apply to all code found in this distribution, be it the RC4, RSA, | 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 | 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 | 13 | * included with this distribution is covered by the same copyright terms |
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). |
15 | * | 15 | * |
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | 16 | * Copyright remains Eric Young's, and as such any Copyright notices in |
17 | * the code are not to be removed. | 17 | * the code are not to be removed. |
18 | * If this package is used in a product, Eric Young should be given attribution | 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. | 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 | 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. | 21 | * in documentation (online or textual) provided with the package. |
22 | * | 22 | * |
23 | * Redistribution and use in source and binary forms, with or without | 23 | * Redistribution and use in source and binary forms, with or without |
24 | * modification, are permitted provided that the following conditions | 24 | * modification, are permitted provided that the following conditions |
25 | * are met: | 25 | * are met: |
@@ -34,10 +34,10 @@ | |||
34 | * Eric Young (eay@cryptsoft.com)" | 34 | * Eric Young (eay@cryptsoft.com)" |
35 | * The word 'cryptographic' can be left out if the rouines from the library | 35 | * The word 'cryptographic' can be left out if the rouines from the library |
36 | * being used are not cryptographic related :-). | 36 | * being used are not cryptographic related :-). |
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | 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: | 38 | * the apps directory (application code) you must include an acknowledgement: |
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" |
40 | * | 40 | * |
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND |
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
@@ -49,7 +49,7 @@ | |||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 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 | 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
51 | * SUCH DAMAGE. | 51 | * SUCH DAMAGE. |
52 | * | 52 | * |
53 | * The licence and distribution terms for any publically available version or | 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 | 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be |
55 | * copied and put under another distribution licence | 55 | * copied and put under another distribution licence |
@@ -72,15 +72,14 @@ extern "C" { | |||
72 | /* Already defined in ossl_typ.h */ | 72 | /* Already defined in ossl_typ.h */ |
73 | /* typedef struct rand_meth_st RAND_METHOD; */ | 73 | /* typedef struct rand_meth_st RAND_METHOD; */ |
74 | 74 | ||
75 | struct rand_meth_st | 75 | struct rand_meth_st { |
76 | { | ||
77 | void (*seed)(const void *buf, int num); | 76 | void (*seed)(const void *buf, int num); |
78 | int (*bytes)(unsigned char *buf, int num); | 77 | int (*bytes)(unsigned char *buf, int num); |
79 | void (*cleanup)(void); | 78 | void (*cleanup)(void); |
80 | void (*add)(const void *buf, int num, double entropy); | 79 | void (*add)(const void *buf, int num, double entropy); |
81 | int (*pseudorand)(unsigned char *buf, int num); | 80 | int (*pseudorand)(unsigned char *buf, int num); |
82 | int (*status)(void); | 81 | int (*status)(void); |
83 | }; | 82 | }; |
84 | 83 | ||
85 | int RAND_set_rand_method(const RAND_METHOD *meth); | 84 | int RAND_set_rand_method(const RAND_METHOD *meth); |
86 | const RAND_METHOD *RAND_get_rand_method(void); | 85 | const RAND_METHOD *RAND_get_rand_method(void); |
@@ -89,13 +88,13 @@ int RAND_set_rand_engine(ENGINE *engine); | |||
89 | #endif | 88 | #endif |
90 | RAND_METHOD *RAND_SSLeay(void); | 89 | RAND_METHOD *RAND_SSLeay(void); |
91 | void RAND_cleanup(void ); | 90 | void RAND_cleanup(void ); |
92 | int RAND_bytes(unsigned char *buf,int num); | 91 | int RAND_bytes(unsigned char *buf, int num); |
93 | int RAND_pseudo_bytes(unsigned char *buf,int num); | 92 | int RAND_pseudo_bytes(unsigned char *buf, int num); |
94 | void RAND_seed(const void *buf,int num); | 93 | void RAND_seed(const void *buf, int num); |
95 | void RAND_add(const void *buf,int num,double entropy); | 94 | void RAND_add(const void *buf, int num, double entropy); |
96 | int RAND_load_file(const char *file,long max_bytes); | 95 | int RAND_load_file(const char *file, long max_bytes); |
97 | int RAND_write_file(const char *file); | 96 | int RAND_write_file(const char *file); |
98 | const char *RAND_file_name(char *file,size_t num); | 97 | const char *RAND_file_name(char *file, size_t num); |
99 | int RAND_status(void); | 98 | int RAND_status(void); |
100 | int RAND_poll(void); | 99 | int RAND_poll(void); |
101 | 100 | ||
diff --git a/src/lib/libssl/src/crypto/rand/rand_err.c b/src/lib/libssl/src/crypto/rand/rand_err.c index c4c80fc8cc..64ae6e0650 100644 --- a/src/lib/libssl/src/crypto/rand/rand_err.c +++ b/src/lib/libssl/src/crypto/rand/rand_err.c | |||
@@ -7,7 +7,7 @@ | |||
7 | * are met: | 7 | * are met: |
8 | * | 8 | * |
9 | * 1. Redistributions of source code must retain the above copyright | 9 | * 1. Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. | 10 | * notice, this list of conditions and the following disclaimer. |
11 | * | 11 | * |
12 | * 2. Redistributions in binary form must reproduce the above copyright | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in | 13 | * notice, this list of conditions and the following disclaimer in |
@@ -68,34 +68,31 @@ | |||
68 | #define ERR_FUNC(func) ERR_PACK(ERR_LIB_RAND,func,0) | 68 | #define ERR_FUNC(func) ERR_PACK(ERR_LIB_RAND,func,0) |
69 | #define ERR_REASON(reason) ERR_PACK(ERR_LIB_RAND,0,reason) | 69 | #define ERR_REASON(reason) ERR_PACK(ERR_LIB_RAND,0,reason) |
70 | 70 | ||
71 | static ERR_STRING_DATA RAND_str_functs[]= | 71 | static ERR_STRING_DATA RAND_str_functs[]= { |
72 | { | 72 | {ERR_FUNC(RAND_F_RAND_GET_RAND_METHOD), "RAND_get_rand_method"}, |
73 | {ERR_FUNC(RAND_F_RAND_GET_RAND_METHOD), "RAND_get_rand_method"}, | 73 | {ERR_FUNC(RAND_F_RAND_INIT_FIPS), "RAND_init_fips"}, |
74 | {ERR_FUNC(RAND_F_RAND_INIT_FIPS), "RAND_init_fips"}, | 74 | {ERR_FUNC(RAND_F_SSLEAY_RAND_BYTES), "SSLEAY_RAND_BYTES"}, |
75 | {ERR_FUNC(RAND_F_SSLEAY_RAND_BYTES), "SSLEAY_RAND_BYTES"}, | 75 | {0, NULL} |
76 | {0,NULL} | 76 | }; |
77 | }; | ||
78 | 77 | ||
79 | static ERR_STRING_DATA RAND_str_reasons[]= | 78 | static ERR_STRING_DATA RAND_str_reasons[]= { |
80 | { | 79 | {ERR_REASON(RAND_R_DUAL_EC_DRBG_DISABLED), "dual ec drbg disabled"}, |
81 | {ERR_REASON(RAND_R_DUAL_EC_DRBG_DISABLED),"dual ec drbg disabled"}, | 80 | {ERR_REASON(RAND_R_ERROR_INITIALISING_DRBG), "error initialising drbg"}, |
82 | {ERR_REASON(RAND_R_ERROR_INITIALISING_DRBG),"error initialising drbg"}, | 81 | {ERR_REASON(RAND_R_ERROR_INSTANTIATING_DRBG), "error instantiating drbg"}, |
83 | {ERR_REASON(RAND_R_ERROR_INSTANTIATING_DRBG),"error instantiating drbg"}, | 82 | {ERR_REASON(RAND_R_NO_FIPS_RANDOM_METHOD_SET), "no fips random method set"}, |
84 | {ERR_REASON(RAND_R_NO_FIPS_RANDOM_METHOD_SET),"no fips random method set"}, | 83 | {ERR_REASON(RAND_R_PRNG_NOT_SEEDED) , "PRNG not seeded"}, |
85 | {ERR_REASON(RAND_R_PRNG_NOT_SEEDED) ,"PRNG not seeded"}, | 84 | {0, NULL} |
86 | {0,NULL} | 85 | }; |
87 | }; | ||
88 | 86 | ||
89 | #endif | 87 | #endif |
90 | 88 | ||
91 | void ERR_load_RAND_strings(void) | 89 | void |
92 | { | 90 | ERR_load_RAND_strings(void) |
91 | { | ||
93 | #ifndef OPENSSL_NO_ERR | 92 | #ifndef OPENSSL_NO_ERR |
94 | 93 | if (ERR_func_error_string(RAND_str_functs[0].error) == NULL) { | |
95 | if (ERR_func_error_string(RAND_str_functs[0].error) == NULL) | 94 | ERR_load_strings(0, RAND_str_functs); |
96 | { | 95 | ERR_load_strings(0, RAND_str_reasons); |
97 | ERR_load_strings(0,RAND_str_functs); | ||
98 | ERR_load_strings(0,RAND_str_reasons); | ||
99 | } | ||
100 | #endif | ||
101 | } | 96 | } |
97 | #endif | ||
98 | } | ||
diff --git a/src/lib/libssl/src/crypto/rand/rand_lib.c b/src/lib/libssl/src/crypto/rand/rand_lib.c index 6d61b3d3f6..c16c719855 100644 --- a/src/lib/libssl/src/crypto/rand/rand_lib.c +++ b/src/lib/libssl/src/crypto/rand/rand_lib.c | |||
@@ -74,7 +74,7 @@ RAND_status(void) | |||
74 | int | 74 | int |
75 | RAND_poll(void) | 75 | RAND_poll(void) |
76 | { | 76 | { |
77 | return 1; | 77 | return 1; |
78 | } | 78 | } |
79 | 79 | ||
80 | /* | 80 | /* |
diff --git a/src/lib/libssl/src/crypto/rand/randfile.c b/src/lib/libssl/src/crypto/rand/randfile.c index 5326f710c5..0689908ce0 100644 --- a/src/lib/libssl/src/crypto/rand/randfile.c +++ b/src/lib/libssl/src/crypto/rand/randfile.c | |||
@@ -5,21 +5,21 @@ | |||
5 | * This package is an SSL implementation written | 5 | * This package is an SSL implementation written |
6 | * by Eric Young (eay@cryptsoft.com). | 6 | * by Eric Young (eay@cryptsoft.com). |
7 | * The implementation was written so as to conform with Netscapes SSL. | 7 | * The implementation was written so as to conform with Netscapes SSL. |
8 | * | 8 | * |
9 | * This library is free for commercial and non-commercial use as long as | 9 | * This library is free for commercial and non-commercial use as long as |
10 | * the following conditions are aheared to. The following conditions | 10 | * the following conditions are aheared to. The following conditions |
11 | * apply to all code found in this distribution, be it the RC4, RSA, | 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 | 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 | 13 | * included with this distribution is covered by the same copyright terms |
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). |
15 | * | 15 | * |
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | 16 | * Copyright remains Eric Young's, and as such any Copyright notices in |
17 | * the code are not to be removed. | 17 | * the code are not to be removed. |
18 | * If this package is used in a product, Eric Young should be given attribution | 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. | 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 | 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. | 21 | * in documentation (online or textual) provided with the package. |
22 | * | 22 | * |
23 | * Redistribution and use in source and binary forms, with or without | 23 | * Redistribution and use in source and binary forms, with or without |
24 | * modification, are permitted provided that the following conditions | 24 | * modification, are permitted provided that the following conditions |
25 | * are met: | 25 | * are met: |
@@ -34,10 +34,10 @@ | |||
34 | * Eric Young (eay@cryptsoft.com)" | 34 | * Eric Young (eay@cryptsoft.com)" |
35 | * The word 'cryptographic' can be left out if the rouines from the library | 35 | * The word 'cryptographic' can be left out if the rouines from the library |
36 | * being used are not cryptographic related :-). | 36 | * being used are not cryptographic related :-). |
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | 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: | 38 | * the apps directory (application code) you must include an acknowledgement: |
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" |
40 | * | 40 | * |
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND |
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
@@ -49,7 +49,7 @@ | |||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 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 | 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
51 | * SUCH DAMAGE. | 51 | * SUCH DAMAGE. |
52 | * | 52 | * |
53 | * The licence and distribution terms for any publically available version or | 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 | 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be |
55 | * copied and put under another distribution licence | 55 | * copied and put under another distribution licence |
@@ -75,7 +75,8 @@ | |||
75 | 75 | ||
76 | /* Note that these functions should not be used. */ | 76 | /* Note that these functions should not be used. */ |
77 | 77 | ||
78 | int RAND_load_file(const char *file, long bytes) | 78 | int |
79 | RAND_load_file(const char *file, long bytes) | ||
79 | { | 80 | { |
80 | /* the "whole" file */ | 81 | /* the "whole" file */ |
81 | if (bytes == -1) | 82 | if (bytes == -1) |
@@ -84,65 +85,68 @@ int RAND_load_file(const char *file, long bytes) | |||
84 | return bytes; | 85 | return bytes; |
85 | } | 86 | } |
86 | 87 | ||
87 | int RAND_write_file(const char *file) | 88 | int |
88 | { | 89 | RAND_write_file(const char *file) |
90 | { | ||
89 | unsigned char buf[BUFSIZE]; | 91 | unsigned char buf[BUFSIZE]; |
90 | int i,ret=0,rand_err=0; | 92 | int i, ret = 0, rand_err = 0; |
91 | FILE *out = NULL; | 93 | FILE *out = NULL; |
92 | int n; | 94 | int n; |
93 | struct stat sb; | 95 | struct stat sb; |
94 | 96 | ||
95 | i=stat(file,&sb); | 97 | i = stat(file, &sb); |
96 | if (i != -1) { | 98 | if (i != -1) { |
97 | if (S_ISBLK(sb.st_mode) || S_ISCHR(sb.st_mode)) { | 99 | if (S_ISBLK(sb.st_mode) || S_ISCHR(sb.st_mode)) { |
98 | /* this file is a device. we don't write back to it. | 100 | /* this file is a device. we don't write back to it. |
99 | * we "succeed" on the assumption this is some sort | 101 | * we "succeed" on the assumption this is some sort |
100 | * of random device. Otherwise attempting to write to | 102 | * of random device. Otherwise attempting to write to |
101 | * and chmod the device causes problems. | 103 | * and chmod the device causes problems. |
102 | */ | 104 | */ |
103 | return(1); | 105 | return (1); |
104 | } | 106 | } |
105 | } | 107 | } |
106 | 108 | ||
107 | { | 109 | { |
108 | /* chmod(..., 0600) is too late to protect the file, | 110 | /* chmod(..., 0600) is too late to protect the file, |
109 | * permissions should be restrictive from the start */ | 111 | * permissions should be restrictive from the start */ |
110 | int fd = open(file, O_WRONLY|O_CREAT, 0600); | 112 | int fd = open(file, O_WRONLY|O_CREAT, 0600); |
111 | if (fd != -1) | 113 | if (fd != -1) |
112 | out = fdopen(fd, "wb"); | 114 | out = fdopen(fd, "wb"); |
113 | } | 115 | } |
114 | 116 | ||
115 | if (out == NULL) | 117 | if (out == NULL) |
116 | out = fopen(file,"wb"); | 118 | out = fopen(file, "wb"); |
117 | if (out == NULL) goto err; | 119 | if (out == NULL) |
120 | goto err; | ||
118 | 121 | ||
119 | chmod(file,0600); | 122 | chmod(file, 0600); |
120 | n=RAND_DATA; | 123 | n = RAND_DATA; |
121 | for (;;) | 124 | for (;;) { |
122 | { | 125 | i = (n > BUFSIZE) ? BUFSIZE : n; |
123 | i=(n > BUFSIZE)?BUFSIZE:n; | 126 | n -= BUFSIZE; |
124 | n-=BUFSIZE; | 127 | if (RAND_bytes(buf, i) <= 0) |
125 | if (RAND_bytes(buf,i) <= 0) | 128 | rand_err = 1; |
126 | rand_err=1; | 129 | i = fwrite(buf, 1, i, out); |
127 | i=fwrite(buf,1,i,out); | 130 | if (i <= 0) { |
128 | if (i <= 0) | 131 | ret = 0; |
129 | { | ||
130 | ret=0; | ||
131 | break; | 132 | break; |
132 | } | 133 | } |
133 | ret+=i; | 134 | ret += i; |
134 | if (n <= 0) break; | 135 | if (n <= 0) |
135 | } | 136 | break; |
137 | } | ||
136 | 138 | ||
137 | fclose(out); | 139 | fclose(out); |
138 | OPENSSL_cleanse(buf,BUFSIZE); | 140 | OPENSSL_cleanse(buf, BUFSIZE); |
141 | |||
139 | err: | 142 | err: |
140 | return (rand_err ? -1 : ret); | 143 | return (rand_err ? -1 : ret); |
141 | } | 144 | } |
142 | 145 | ||
143 | const char *RAND_file_name(char *buf, size_t size) | 146 | const char * |
147 | RAND_file_name(char *buf, size_t size) | ||
144 | { | 148 | { |
145 | if (strlcpy(buf,"/dev/urandom",size) >= size) | 149 | if (strlcpy(buf, "/dev/urandom", size) >= size) |
146 | return(NULL); | 150 | return (NULL); |
147 | return buf; | 151 | return buf; |
148 | } | 152 | } |