diff options
author | Joel Sing <jsing@cvs.openbsd.org> | 2014-05-24 15:25:24 +0000 |
---|---|---|
committer | Joel Sing <jsing@cvs.openbsd.org> | 2014-05-24 15:25:24 +0000 |
commit | 0449e3a93cfb5afaee25b3c7272ee7edfe32f5cd (patch) | |
tree | 62992a4496220215c44da0072361b1a22b5c4568 | |
parent | ef7d808b3fa8ba5079f52fa9ba77e9a51ea267ca (diff) |
KNF.
-rw-r--r-- | lib/libcrypto/rand/rand.h | 29 | ||||
-rw-r--r-- | lib/libcrypto/rand/rand_err.c | 49 | ||||
-rw-r--r-- | lib/libcrypto/rand/rand_lib.c | 2 | ||||
-rw-r--r-- | lib/libcrypto/rand/randfile.c | 102 |
4 files changed, 91 insertions, 91 deletions
diff --git a/lib/libcrypto/rand/rand.h b/lib/libcrypto/rand/rand.h index 30b22afaf38..7e0f09d03c4 100644 --- a/lib/libcrypto/rand/rand.h +++ b/lib/libcrypto/rand/rand.h @@ -5,21 +5,21 @@ * This package is an SSL implementation written * by Eric Young (eay@cryptsoft.com). * The implementation was written so as to conform with Netscapes SSL. - * + * * This library is free for commercial and non-commercial use as long as * the following conditions are aheared to. The following conditions * apply to all code found in this distribution, be it the RC4, RSA, * lhash, DES, etc., code; not just the SSL code. The SSL documentation * included with this distribution is covered by the same copyright terms * except that the holder is Tim Hudson (tjh@cryptsoft.com). - * + * * Copyright remains Eric Young's, and as such any Copyright notices in * the code are not to be removed. * If this package is used in a product, Eric Young should be given attribution * as the author of the parts of the library used. * This can be in the form of a textual message at program startup or * in documentation (online or textual) provided with the package. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -34,10 +34,10 @@ * Eric Young (eay@cryptsoft.com)" * The word 'cryptographic' can be left out if the rouines from the library * being used are not cryptographic related :-). - * 4. If you include any Windows specific code (or a derivative thereof) from + * 4. If you include any Windows specific code (or a derivative thereof) from * the apps directory (application code) you must include an acknowledgement: * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" - * + * * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE @@ -49,7 +49,7 @@ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. - * + * * The licence and distribution terms for any publically available version or * derivative of this code cannot be changed. i.e. this code cannot simply be * copied and put under another distribution licence @@ -72,15 +72,14 @@ extern "C" { /* Already defined in ossl_typ.h */ /* typedef struct rand_meth_st RAND_METHOD; */ -struct rand_meth_st - { +struct rand_meth_st { void (*seed)(const void *buf, int num); int (*bytes)(unsigned char *buf, int num); void (*cleanup)(void); void (*add)(const void *buf, int num, double entropy); int (*pseudorand)(unsigned char *buf, int num); int (*status)(void); - }; +}; int RAND_set_rand_method(const RAND_METHOD *meth); const RAND_METHOD *RAND_get_rand_method(void); @@ -89,13 +88,13 @@ int RAND_set_rand_engine(ENGINE *engine); #endif RAND_METHOD *RAND_SSLeay(void); void RAND_cleanup(void ); -int RAND_bytes(unsigned char *buf,int num); -int RAND_pseudo_bytes(unsigned char *buf,int num); -void RAND_seed(const void *buf,int num); -void RAND_add(const void *buf,int num,double entropy); -int RAND_load_file(const char *file,long max_bytes); +int RAND_bytes(unsigned char *buf, int num); +int RAND_pseudo_bytes(unsigned char *buf, int num); +void RAND_seed(const void *buf, int num); +void RAND_add(const void *buf, int num, double entropy); +int RAND_load_file(const char *file, long max_bytes); int RAND_write_file(const char *file); -const char *RAND_file_name(char *file,size_t num); +const char *RAND_file_name(char *file, size_t num); int RAND_status(void); int RAND_poll(void); diff --git a/lib/libcrypto/rand/rand_err.c b/lib/libcrypto/rand/rand_err.c index c4c80fc8cca..64ae6e0650f 100644 --- a/lib/libcrypto/rand/rand_err.c +++ b/lib/libcrypto/rand/rand_err.c @@ -7,7 +7,7 @@ * are met: * * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in @@ -68,34 +68,31 @@ #define ERR_FUNC(func) ERR_PACK(ERR_LIB_RAND,func,0) #define ERR_REASON(reason) ERR_PACK(ERR_LIB_RAND,0,reason) -static ERR_STRING_DATA RAND_str_functs[]= - { -{ERR_FUNC(RAND_F_RAND_GET_RAND_METHOD), "RAND_get_rand_method"}, -{ERR_FUNC(RAND_F_RAND_INIT_FIPS), "RAND_init_fips"}, -{ERR_FUNC(RAND_F_SSLEAY_RAND_BYTES), "SSLEAY_RAND_BYTES"}, -{0,NULL} - }; +static ERR_STRING_DATA RAND_str_functs[]= { + {ERR_FUNC(RAND_F_RAND_GET_RAND_METHOD), "RAND_get_rand_method"}, + {ERR_FUNC(RAND_F_RAND_INIT_FIPS), "RAND_init_fips"}, + {ERR_FUNC(RAND_F_SSLEAY_RAND_BYTES), "SSLEAY_RAND_BYTES"}, + {0, NULL} +}; -static ERR_STRING_DATA RAND_str_reasons[]= - { -{ERR_REASON(RAND_R_DUAL_EC_DRBG_DISABLED),"dual ec drbg disabled"}, -{ERR_REASON(RAND_R_ERROR_INITIALISING_DRBG),"error initialising drbg"}, -{ERR_REASON(RAND_R_ERROR_INSTANTIATING_DRBG),"error instantiating drbg"}, -{ERR_REASON(RAND_R_NO_FIPS_RANDOM_METHOD_SET),"no fips random method set"}, -{ERR_REASON(RAND_R_PRNG_NOT_SEEDED) ,"PRNG not seeded"}, -{0,NULL} - }; +static ERR_STRING_DATA RAND_str_reasons[]= { + {ERR_REASON(RAND_R_DUAL_EC_DRBG_DISABLED), "dual ec drbg disabled"}, + {ERR_REASON(RAND_R_ERROR_INITIALISING_DRBG), "error initialising drbg"}, + {ERR_REASON(RAND_R_ERROR_INSTANTIATING_DRBG), "error instantiating drbg"}, + {ERR_REASON(RAND_R_NO_FIPS_RANDOM_METHOD_SET), "no fips random method set"}, + {ERR_REASON(RAND_R_PRNG_NOT_SEEDED) , "PRNG not seeded"}, + {0, NULL} +}; #endif -void ERR_load_RAND_strings(void) - { +void +ERR_load_RAND_strings(void) +{ #ifndef OPENSSL_NO_ERR - - if (ERR_func_error_string(RAND_str_functs[0].error) == NULL) - { - ERR_load_strings(0,RAND_str_functs); - ERR_load_strings(0,RAND_str_reasons); - } -#endif + if (ERR_func_error_string(RAND_str_functs[0].error) == NULL) { + ERR_load_strings(0, RAND_str_functs); + ERR_load_strings(0, RAND_str_reasons); } +#endif +} diff --git a/lib/libcrypto/rand/rand_lib.c b/lib/libcrypto/rand/rand_lib.c index 6d61b3d3f62..c16c7198552 100644 --- a/lib/libcrypto/rand/rand_lib.c +++ b/lib/libcrypto/rand/rand_lib.c @@ -74,7 +74,7 @@ RAND_status(void) int RAND_poll(void) { - return 1; + return 1; } /* diff --git a/lib/libcrypto/rand/randfile.c b/lib/libcrypto/rand/randfile.c index 5326f710c5e..0689908ce0a 100644 --- a/lib/libcrypto/rand/randfile.c +++ b/lib/libcrypto/rand/randfile.c @@ -5,21 +5,21 @@ * This package is an SSL implementation written * by Eric Young (eay@cryptsoft.com). * The implementation was written so as to conform with Netscapes SSL. - * + * * This library is free for commercial and non-commercial use as long as * the following conditions are aheared to. The following conditions * apply to all code found in this distribution, be it the RC4, RSA, * lhash, DES, etc., code; not just the SSL code. The SSL documentation * included with this distribution is covered by the same copyright terms * except that the holder is Tim Hudson (tjh@cryptsoft.com). - * + * * Copyright remains Eric Young's, and as such any Copyright notices in * the code are not to be removed. * If this package is used in a product, Eric Young should be given attribution * as the author of the parts of the library used. * This can be in the form of a textual message at program startup or * in documentation (online or textual) provided with the package. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -34,10 +34,10 @@ * Eric Young (eay@cryptsoft.com)" * The word 'cryptographic' can be left out if the rouines from the library * being used are not cryptographic related :-). - * 4. If you include any Windows specific code (or a derivative thereof) from + * 4. If you include any Windows specific code (or a derivative thereof) from * the apps directory (application code) you must include an acknowledgement: * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" - * + * * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE @@ -49,7 +49,7 @@ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. - * + * * The licence and distribution terms for any publically available version or * derivative of this code cannot be changed. i.e. this code cannot simply be * copied and put under another distribution licence @@ -75,7 +75,8 @@ /* Note that these functions should not be used. */ -int RAND_load_file(const char *file, long bytes) +int +RAND_load_file(const char *file, long bytes) { /* the "whole" file */ if (bytes == -1) @@ -84,65 +85,68 @@ int RAND_load_file(const char *file, long bytes) return bytes; } -int RAND_write_file(const char *file) - { +int +RAND_write_file(const char *file) +{ unsigned char buf[BUFSIZE]; - int i,ret=0,rand_err=0; + int i, ret = 0, rand_err = 0; FILE *out = NULL; int n; struct stat sb; - - i=stat(file,&sb); - if (i != -1) { - if (S_ISBLK(sb.st_mode) || S_ISCHR(sb.st_mode)) { - /* this file is a device. we don't write back to it. - * we "succeed" on the assumption this is some sort - * of random device. Otherwise attempting to write to - * and chmod the device causes problems. - */ - return(1); - } + + i = stat(file, &sb); + if (i != -1) { + if (S_ISBLK(sb.st_mode) || S_ISCHR(sb.st_mode)) { + /* this file is a device. we don't write back to it. + * we "succeed" on the assumption this is some sort + * of random device. Otherwise attempting to write to + * and chmod the device causes problems. + */ + return (1); + } } { - /* chmod(..., 0600) is too late to protect the file, - * permissions should be restrictive from the start */ - int fd = open(file, O_WRONLY|O_CREAT, 0600); - if (fd != -1) - out = fdopen(fd, "wb"); + /* chmod(..., 0600) is too late to protect the file, + * permissions should be restrictive from the start */ + int fd = open(file, O_WRONLY|O_CREAT, 0600); + if (fd != -1) + out = fdopen(fd, "wb"); } if (out == NULL) - out = fopen(file,"wb"); - if (out == NULL) goto err; + out = fopen(file, "wb"); + if (out == NULL) + goto err; - chmod(file,0600); - n=RAND_DATA; - for (;;) - { - i=(n > BUFSIZE)?BUFSIZE:n; - n-=BUFSIZE; - if (RAND_bytes(buf,i) <= 0) - rand_err=1; - i=fwrite(buf,1,i,out); - if (i <= 0) - { - ret=0; + chmod(file, 0600); + n = RAND_DATA; + for (;;) { + i = (n > BUFSIZE) ? BUFSIZE : n; + n -= BUFSIZE; + if (RAND_bytes(buf, i) <= 0) + rand_err = 1; + i = fwrite(buf, 1, i, out); + if (i <= 0) { + ret = 0; break; - } - ret+=i; - if (n <= 0) break; - } + } + ret += i; + if (n <= 0) + break; + } fclose(out); - OPENSSL_cleanse(buf,BUFSIZE); + OPENSSL_cleanse(buf, BUFSIZE); + err: return (rand_err ? -1 : ret); - } +} -const char *RAND_file_name(char *buf, size_t size) +const char * +RAND_file_name(char *buf, size_t size) { - if (strlcpy(buf,"/dev/urandom",size) >= size) - return(NULL); + if (strlcpy(buf, "/dev/urandom", size) >= size) + return (NULL); return buf; } |