diff options
author | Loic Blot <loic.blot@unix-experience.fr> | 2017-04-07 08:50:17 +0200 |
---|---|---|
committer | Loic Blot <loic.blot@unix-experience.fr> | 2017-04-07 08:50:17 +0200 |
commit | f7088f69ab7406ea9fefa853fa7ce11f914e88cf (patch) | |
tree | a2457b54c9f5ed6ea65342b3a1fadeeee036d501 /src/util | |
parent | b751c59f43e04f698f517383b62a9c4e1f82523e (diff) | |
download | minetest-f7088f69ab7406ea9fefa853fa7ce11f914e88cf.tar.gz minetest-f7088f69ab7406ea9fefa853fa7ce11f914e88cf.tar.bz2 minetest-f7088f69ab7406ea9fefa853fa7ce11f914e88cf.zip |
Clang-format: fix some header files and remove them from whitelist
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/hex.h | 13 | ||||
-rw-r--r-- | src/util/sha1.h | 33 | ||||
-rw-r--r-- | src/util/sha2.h | 107 |
3 files changed, 78 insertions, 75 deletions
diff --git a/src/util/hex.h b/src/util/hex.h index 6f00a79bf..c205d01da 100644 --- a/src/util/hex.h +++ b/src/util/hex.h @@ -30,9 +30,8 @@ static inline std::string hex_encode(const char *data, unsigned int data_size) char buf2[3]; buf2[2] = '\0'; - for(unsigned int i = 0; i < data_size; i++) - { - unsigned char c = (unsigned char) data[i]; + for (unsigned int i = 0; i < data_size; i++) { + unsigned char c = (unsigned char)data[i]; buf2[0] = hex_chars[(c & 0xf0) >> 4]; buf2[1] = hex_chars[c & 0x0f]; ret.append(buf2); @@ -43,16 +42,16 @@ static inline std::string hex_encode(const char *data, unsigned int data_size) static inline std::string hex_encode(const std::string &data) { - return hex_encode(data.c_str(), data.size()); + return hex_encode(data.c_str(), data.size()); } static inline bool hex_digit_decode(char hexdigit, unsigned char &value) { - if(hexdigit >= '0' && hexdigit <= '9') + if (hexdigit >= '0' && hexdigit <= '9') value = hexdigit - '0'; - else if(hexdigit >= 'A' && hexdigit <= 'F') + else if (hexdigit >= 'A' && hexdigit <= 'F') value = hexdigit - 'A' + 10; - else if(hexdigit >= 'a' && hexdigit <= 'f') + else if (hexdigit >= 'a' && hexdigit <= 'f') value = hexdigit - 'a' + 10; else return false; diff --git a/src/util/sha1.h b/src/util/sha1.h index c04947373..0ac08c67b 100644 --- a/src/util/sha1.h +++ b/src/util/sha1.h @@ -29,22 +29,23 @@ typedef unsigned int Uint32; class SHA1 { - private: - // fields - Uint32 H0, H1, H2, H3, H4; - unsigned char bytes[64]; - int unprocessedBytes; - Uint32 size; - void process(); - public: - SHA1(); - ~SHA1(); - void addBytes( const char* data, int num ); - unsigned char* getDigest(); - // utility methods - static Uint32 lrot( Uint32 x, int bits ); - static void storeBigEndianUint32( unsigned char* byte, Uint32 num ); - static void hexPrinter( unsigned char* c, int l ); +private: + // fields + Uint32 H0, H1, H2, H3, H4; + unsigned char bytes[64]; + int unprocessedBytes; + Uint32 size; + void process(); + +public: + SHA1(); + ~SHA1(); + void addBytes(const char *data, int num); + unsigned char *getDigest(); + // utility methods + static Uint32 lrot(Uint32 x, int bits); + static void storeBigEndianUint32(unsigned char *byte, Uint32 num); + static void hexPrinter(unsigned char *c, int l); }; #define SHA1_HEADER diff --git a/src/util/sha2.h b/src/util/sha2.h index 6ac045feb..233c85a81 100644 --- a/src/util/sha2.h +++ b/src/util/sha2.h @@ -57,21 +57,21 @@ */ #ifndef HEADER_SHA_H -# define HEADER_SHA_H +#define HEADER_SHA_H -# include <stddef.h> +#include <stddef.h> -#ifdef __cplusplus +#ifdef __cplusplus extern "C" { #endif -# if defined(OPENSSL_NO_SHA) || (defined(OPENSSL_NO_SHA0) && defined(OPENSSL_NO_SHA1)) -# error SHA is disabled. -# endif +#if defined(OPENSSL_NO_SHA) || (defined(OPENSSL_NO_SHA0) && defined(OPENSSL_NO_SHA1)) +#error SHA is disabled. +#endif -# if defined(OPENSSL_FIPS) -# define FIPS_SHA_SIZE_T size_t -# endif +#if defined(OPENSSL_FIPS) +#define FIPS_SHA_SIZE_T size_t +#endif /* Compat stuff from OpenSSL land @@ -79,11 +79,10 @@ extern "C" { /* crypto.h */ -# define fips_md_init(alg) fips_md_init_ctx(alg, alg) +#define fips_md_init(alg) fips_md_init_ctx(alg, alg) -# define fips_md_init_ctx(alg, cx) \ - int alg##_Init(cx##_CTX *c) -# define fips_cipher_abort(alg) while(0) +#define fips_md_init_ctx(alg, cx) int alg##_Init(cx##_CTX *c) +#define fips_cipher_abort(alg) while (0) /*- * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! @@ -92,47 +91,51 @@ extern "C" { * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */ -# if defined(__LP32__) -# define SHA_LONG unsigned long -# elif defined(__ILP64__) -# define SHA_LONG unsigned long -# define SHA_LONG_LOG2 3 -# else -# define SHA_LONG unsigned int -# endif - -# define SHA_LBLOCK 16 -# define SHA_CBLOCK (SHA_LBLOCK*4)/* SHA treats input data as a - * contiguous array of 32 bit wide - * big-endian values. */ -# define SHA_LAST_BLOCK (SHA_CBLOCK-8) -# define SHA_DIGEST_LENGTH 20 - -typedef struct SHAstate_st { - SHA_LONG h0, h1, h2, h3, h4; - SHA_LONG Nl, Nh; - SHA_LONG data[SHA_LBLOCK]; - unsigned int num; +#if defined(__LP32__) +#define SHA_LONG unsigned long +#elif defined(__ILP64__) +#define SHA_LONG unsigned long +#define SHA_LONG_LOG2 3 +#else +#define SHA_LONG unsigned int +#endif + +#define SHA_LBLOCK 16 +#define SHA_CBLOCK \ + (SHA_LBLOCK * 4) /* SHA treats input data as a \ + * contiguous array of 32 bit wide \ + * big-endian values. */ +#define SHA_LAST_BLOCK (SHA_CBLOCK - 8) +#define SHA_DIGEST_LENGTH 20 + +typedef struct SHAstate_st +{ + SHA_LONG h0, h1, h2, h3, h4; + SHA_LONG Nl, Nh; + SHA_LONG data[SHA_LBLOCK]; + unsigned int num; } SHA_CTX; -# define SHA256_CBLOCK (SHA_LBLOCK*4)/* SHA-256 treats input data as a - * contiguous array of 32 bit wide - * big-endian values. */ -# define SHA224_DIGEST_LENGTH 28 -# define SHA256_DIGEST_LENGTH 32 - -typedef struct SHA256state_st { - SHA_LONG h[8]; - SHA_LONG Nl, Nh; - SHA_LONG data[SHA_LBLOCK]; - unsigned int num, md_len; +#define SHA256_CBLOCK \ + (SHA_LBLOCK * 4) /* SHA-256 treats input data as a \ + * contiguous array of 32 bit wide \ + * big-endian values. */ +#define SHA224_DIGEST_LENGTH 28 +#define SHA256_DIGEST_LENGTH 32 + +typedef struct SHA256state_st +{ + SHA_LONG h[8]; + SHA_LONG Nl, Nh; + SHA_LONG data[SHA_LBLOCK]; + unsigned int num, md_len; } SHA256_CTX; -# ifndef OPENSSL_NO_SHA256 -# ifdef OPENSSL_FIPS +#ifndef OPENSSL_NO_SHA256 +#ifdef OPENSSL_FIPS int private_SHA224_Init(SHA256_CTX *c); int private_SHA256_Init(SHA256_CTX *c); -# endif +#endif int SHA224_Init(SHA256_CTX *c); int SHA224_Update(SHA256_CTX *c, const void *data, size_t len); int SHA224_Final(unsigned char *md, SHA256_CTX *c); @@ -142,12 +145,12 @@ int SHA256_Update(SHA256_CTX *c, const void *data, size_t len); int SHA256_Final(unsigned char *md, SHA256_CTX *c); unsigned char *SHA256(const unsigned char *d, size_t n, unsigned char *md); void SHA256_Transform(SHA256_CTX *c, const unsigned char *data); -# endif +#endif -# define SHA384_DIGEST_LENGTH 48 -# define SHA512_DIGEST_LENGTH 64 +#define SHA384_DIGEST_LENGTH 48 +#define SHA512_DIGEST_LENGTH 64 -#ifdef __cplusplus +#ifdef __cplusplus } #endif |