Commit cf42c36e authored by Pieter Wuille's avatar Pieter Wuille

Apply clang-format on crypto/* and compat/*

parent ea69592a
......@@ -18,11 +18,11 @@ extern "C" void* memcpy(void* a, const void* b, size_t c)
return memmove(a, b, c);
}
extern "C" void __chk_fail (void) __attribute__((__noreturn__));
extern "C" void __chk_fail(void) __attribute__((__noreturn__));
extern "C" FDELT_TYPE __fdelt_warn(FDELT_TYPE a)
{
if (a >= FD_SETSIZE)
__chk_fail ();
__chk_fail();
return a / __NFDBITS;
}
extern "C" FDELT_TYPE __fdelt_chk(FDELT_TYPE) __attribute__((weak, alias("__fdelt_warn")));
......@@ -14,10 +14,11 @@
extern "C" void* memcpy(void* a, const void* b, size_t c);
void* memcpy_int(void* a, const void* b, size_t c)
{
return memcpy(a,b,c);
return memcpy(a, b, c);
}
namespace {
namespace
{
// trigger: Use the memcpy_int wrapper which calls our internal memcpy.
// A direct call to memcpy may be optimized away by the compiler.
// test: Fill an array with a sequence of integers. memcpy to a new empty array.
......@@ -31,11 +32,10 @@ bool sanity_test_memcpy()
for (unsigned int i = 0; i != T; ++i)
memcpy_test[i] = i;
memcpy_int(memcpy_verify,memcpy_test,sizeof(memcpy_test));
memcpy_int(memcpy_verify, memcpy_test, sizeof(memcpy_test));
for (unsigned int i = 0; i != T; ++i)
{
if(memcpy_verify[i] != i)
for (unsigned int i = 0; i != T; ++i) {
if (memcpy_verify[i] != i)
return false;
}
return true;
......@@ -51,7 +51,7 @@ bool sanity_test_fdelt()
fd_set fds;
FD_ZERO(&fds);
FD_SET(0, &fds);
return FD_ISSET(0,&fds);
return FD_ISSET(0, &fds);
}
#endif
......
......@@ -11,8 +11,8 @@
#define _GLIBCXX_USE_NOEXCEPT throw()
#endif
namespace std {
namespace std
{
const char* bad_exception::what() const throw()
{
return "std::bad_exception";
......@@ -30,9 +30,8 @@ const char* bad_alloc::what() const throw()
namespace __detail
{
struct _List_node_base
{
void _M_hook(std::__detail::_List_node_base* const __position) throw () __attribute__((used))
struct _List_node_base {
void _M_hook(std::__detail::_List_node_base* const __position) throw() __attribute__((used))
{
_M_next = __position;
_M_prev = __position->_M_prev;
......@@ -62,9 +61,9 @@ template ostream& __ostream_insert(ostream&, const char*, streamsize);
template istream& istream::_M_extract(long&);
template istream& istream::_M_extract(unsigned short&);
out_of_range::~out_of_range() _GLIBCXX_USE_NOEXCEPT { }
out_of_range::~out_of_range() _GLIBCXX_USE_NOEXCEPT {}
length_error::~length_error() _GLIBCXX_USE_NOEXCEPT { }
length_error::~length_error() _GLIBCXX_USE_NOEXCEPT {}
// Used with permission.
// See: https://github.com/madlib/madlib/commit/c3db418c0d34d6813608f2137fef1012ce03043d
......@@ -85,11 +84,11 @@ void ctype<char>::_M_widen_init() const
}
}
void __throw_out_of_range_fmt(const char*, ...) __attribute__((__noreturn__));
void __throw_out_of_range_fmt(const char* err, ...)
void __throw_out_of_range_fmt(const char*, ...) __attribute__((__noreturn__));
void __throw_out_of_range_fmt(const char* err, ...)
{
// Safe and over-simplified version. Ignore the format and print it as-is.
__throw_out_of_range(err);
}
}// namespace std
} // namespace std
......@@ -6,15 +6,15 @@
#include <locale>
#include <stdexcept>
namespace{
namespace
{
// trigger: use ctype<char>::widen to trigger ctype<char>::_M_widen_init().
// test: convert a char from narrow to wide and back. Verify that the result
// matches the original.
bool sanity_test_widen(char testchar)
{
const std::ctype<char>& test(std::use_facet< std::ctype<char> >(std::locale()));
return test.narrow(test.widen(testchar),'b') == testchar;
const std::ctype<char>& test(std::use_facet<std::ctype<char> >(std::locale()));
return test.narrow(test.widen(testchar), 'b') == testchar;
}
// trigger: use list::push_back and list::pop_back to trigger _M_hook and
......@@ -25,14 +25,13 @@ bool sanity_test_list(unsigned int size)
{
std::list<unsigned int> test;
for (unsigned int i = 0; i != size; ++i)
test.push_back(i+1);
test.push_back(i + 1);
if (test.size() != size)
return false;
while (!test.empty())
{
if(test.back() != test.size())
while (!test.empty()) {
if (test.back() != test.size())
return false;
test.pop_back();
}
......@@ -47,15 +46,12 @@ bool sanity_test_list(unsigned int size)
bool sanity_test_range_fmt()
{
std::string test;
try
{
try {
test.at(1);
}
catch (const std::out_of_range&)
{
} catch (const std::out_of_range&) {
return true;
} catch (...) {
}
catch (...){}
return false;
}
......
......@@ -13,7 +13,8 @@
#include <endian.h>
#endif
uint32_t static inline ReadLE32(const unsigned char *ptr) {
uint32_t static inline ReadLE32(const unsigned char* ptr)
{
#if HAVE_DECL_LE32TOH == 1
return le32toh(*((uint32_t*)ptr));
#elif !defined(WORDS_BIGENDIAN)
......@@ -23,8 +24,8 @@ uint32_t static inline ReadLE32(const unsigned char *ptr) {
#endif
}
uint64_t static inline ReadLE64(const unsigned char *ptr) {
uint64_t static inline ReadLE64(const unsigned char* ptr)
{
#if HAVE_DECL_LE64TOH == 1
return le64toh(*((uint64_t*)ptr));
#elif !defined(WORDS_BIGENDIAN)
......@@ -35,28 +36,40 @@ uint64_t static inline ReadLE64(const unsigned char *ptr) {
#endif
}
void static inline WriteLE32(unsigned char *ptr, uint32_t x) {
void static inline WriteLE32(unsigned char* ptr, uint32_t x)
{
#if HAVE_DECL_HTOLE32 == 1
*((uint32_t*)ptr) = htole32(x);
#elif !defined(WORDS_BIGENDIAN)
*((uint32_t*)ptr) = x;
#else
ptr[3] = x >> 24; ptr[2] = x >> 16; ptr[1] = x >> 8; ptr[0] = x;
ptr[3] = x >> 24;
ptr[2] = x >> 16;
ptr[1] = x >> 8;
ptr[0] = x;
#endif
}
void static inline WriteLE64(unsigned char *ptr, uint64_t x) {
void static inline WriteLE64(unsigned char* ptr, uint64_t x)
{
#if HAVE_DECL_HTOLE64 == 1
*((uint64_t*)ptr) = htole64(x);
#elif !defined(WORDS_BIGENDIAN)
*((uint64_t*)ptr) = x;
#else
ptr[7] = x >> 56; ptr[6] = x >> 48; ptr[5] = x >> 40; ptr[4] = x >> 32;
ptr[3] = x >> 24; ptr[2] = x >> 16; ptr[1] = x >> 8; ptr[0] = x;
ptr[7] = x >> 56;
ptr[6] = x >> 48;
ptr[5] = x >> 40;
ptr[4] = x >> 32;
ptr[3] = x >> 24;
ptr[2] = x >> 16;
ptr[1] = x >> 8;
ptr[0] = x;
#endif
}
uint32_t static inline ReadBE32(const unsigned char *ptr) {
uint32_t static inline ReadBE32(const unsigned char* ptr)
{
#if HAVE_DECL_BE32TOH == 1
return be32toh(*((uint32_t*)ptr));
#else
......@@ -64,7 +77,8 @@ uint32_t static inline ReadBE32(const unsigned char *ptr) {
#endif
}
uint64_t static inline ReadBE64(const unsigned char *ptr) {
uint64_t static inline ReadBE64(const unsigned char* ptr)
{
#if HAVE_DECL_BE64TOH == 1
return be64toh(*((uint64_t*)ptr));
#else
......@@ -73,20 +87,31 @@ uint64_t static inline ReadBE64(const unsigned char *ptr) {
#endif
}
void static inline WriteBE32(unsigned char *ptr, uint32_t x) {
void static inline WriteBE32(unsigned char* ptr, uint32_t x)
{
#if HAVE_DECL_HTOBE32 == 1
*((uint32_t*)ptr) = htobe32(x);
#else
ptr[0] = x >> 24; ptr[1] = x >> 16; ptr[2] = x >> 8; ptr[3] = x;
ptr[0] = x >> 24;
ptr[1] = x >> 16;
ptr[2] = x >> 8;
ptr[3] = x;
#endif
}
void static inline WriteBE64(unsigned char *ptr, uint64_t x) {
void static inline WriteBE64(unsigned char* ptr, uint64_t x)
{
#if HAVE_DECL_HTOBE64 == 1
*((uint64_t*)ptr) = htobe64(x);
#else
ptr[0] = x >> 56; ptr[1] = x >> 48; ptr[2] = x >> 40; ptr[3] = x >> 32;
ptr[4] = x >> 24; ptr[5] = x >> 16; ptr[6] = x >> 8; ptr[7] = x;
ptr[0] = x >> 56;
ptr[1] = x >> 48;
ptr[2] = x >> 40;
ptr[3] = x >> 32;
ptr[4] = x >> 24;
ptr[5] = x >> 16;
ptr[6] = x >> 8;
ptr[7] = x;
#endif
}
......
This diff is collapsed.
......@@ -9,7 +9,8 @@
#include <stdlib.h>
/** A hasher class for RIPEMD-160. */
class CRIPEMD160 {
class CRIPEMD160
{
private:
uint32_t s[5];
unsigned char buf[64];
......@@ -19,7 +20,7 @@ public:
static const size_t OUTPUT_SIZE = 20;
CRIPEMD160();
CRIPEMD160& Write(const unsigned char *data, size_t len);
CRIPEMD160& Write(const unsigned char* data, size_t len);
void Finalize(unsigned char hash[OUTPUT_SIZE]);
CRIPEMD160& Reset();
};
......
This diff is collapsed.
......@@ -9,7 +9,8 @@
#include <stdlib.h>
/** A hasher class for SHA1. */
class CSHA1 {
class CSHA1
{
private:
uint32_t s[5];
unsigned char buf[64];
......@@ -19,7 +20,7 @@ public:
static const size_t OUTPUT_SIZE = 20;
CSHA1();
CSHA1& Write(const unsigned char *data, size_t len);
CSHA1& Write(const unsigned char* data, size_t len);
void Finalize(unsigned char hash[OUTPUT_SIZE]);
CSHA1& Reset();
};
......
This diff is collapsed.
......@@ -9,7 +9,8 @@
#include <stdlib.h>
/** A hasher class for SHA-256. */
class CSHA256 {
class CSHA256
{
private:
uint32_t s[8];
unsigned char buf[64];
......@@ -19,13 +20,14 @@ public:
static const size_t OUTPUT_SIZE = 32;
CSHA256();
CSHA256& Write(const unsigned char *data, size_t len);
CSHA256& Write(const unsigned char* data, size_t len);
void Finalize(unsigned char hash[OUTPUT_SIZE]);
CSHA256& Reset();
};
/** A hasher class for SHA-512. */
class CSHA512 {
class CSHA512
{
private:
uint64_t s[8];
unsigned char buf[128];
......@@ -35,13 +37,14 @@ public:
static const size_t OUTPUT_SIZE = 64;
CSHA512();
CSHA512& Write(const unsigned char *data, size_t len);
CSHA512& Write(const unsigned char* data, size_t len);
void Finalize(unsigned char hash[OUTPUT_SIZE]);
CSHA512& Reset();
};
/** A hasher class for HMAC-SHA-512. */
class CHMAC_SHA512 {
class CHMAC_SHA512
{
private:
CSHA512 outer;
CSHA512 inner;
......@@ -49,8 +52,9 @@ private:
public:
static const size_t OUTPUT_SIZE = 64;
CHMAC_SHA512(const unsigned char *key, size_t keylen);
CHMAC_SHA512& Write(const unsigned char *data, size_t len) {
CHMAC_SHA512(const unsigned char* key, size_t keylen);
CHMAC_SHA512& Write(const unsigned char* data, size_t len)
{
inner.Write(data, len);
return *this;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment