2014-12-17 02:47:57 +01:00
|
|
|
// Copyright (c) 2014 The Bitcoin Core developers
|
2014-09-27 13:49:21 +02:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
2014-05-03 01:04:18 +02:00
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
|
|
|
#ifndef BITCOIN_CRYPTO_COMMON_H
|
|
|
|
#define BITCOIN_CRYPTO_COMMON_H
|
|
|
|
|
2014-06-09 21:05:28 +02:00
|
|
|
#if defined(HAVE_CONFIG_H)
|
|
|
|
#include "bitcoin-config.h"
|
|
|
|
#endif
|
2014-09-27 13:49:21 +02:00
|
|
|
|
2014-05-03 01:04:18 +02:00
|
|
|
#include <stdint.h>
|
2014-09-27 13:49:21 +02:00
|
|
|
|
2014-12-19 09:53:43 +01:00
|
|
|
#include "compat/endian.h"
|
|
|
|
|
|
|
|
uint16_t static inline ReadLE16(const unsigned char* ptr)
|
|
|
|
{
|
|
|
|
return le16toh(*((uint16_t*)ptr));
|
|
|
|
}
|
2014-06-09 21:05:28 +02:00
|
|
|
|
2014-09-25 08:23:32 +02:00
|
|
|
uint32_t static inline ReadLE32(const unsigned char* ptr)
|
|
|
|
{
|
2014-06-09 21:05:28 +02:00
|
|
|
return le32toh(*((uint32_t*)ptr));
|
|
|
|
}
|
|
|
|
|
2014-09-25 08:23:32 +02:00
|
|
|
uint64_t static inline ReadLE64(const unsigned char* ptr)
|
|
|
|
{
|
2014-06-09 21:05:28 +02:00
|
|
|
return le64toh(*((uint64_t*)ptr));
|
2014-12-19 09:53:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void static inline WriteLE16(unsigned char* ptr, uint16_t x)
|
|
|
|
{
|
|
|
|
*((uint16_t*)ptr) = htole16(x);
|
2014-06-09 21:05:28 +02:00
|
|
|
}
|
2014-05-03 01:04:18 +02:00
|
|
|
|
2014-09-25 08:23:32 +02:00
|
|
|
void static inline WriteLE32(unsigned char* ptr, uint32_t x)
|
|
|
|
{
|
2014-06-09 21:05:28 +02:00
|
|
|
*((uint32_t*)ptr) = htole32(x);
|
|
|
|
}
|
|
|
|
|
2014-09-25 08:23:32 +02:00
|
|
|
void static inline WriteLE64(unsigned char* ptr, uint64_t x)
|
|
|
|
{
|
2014-06-09 21:05:28 +02:00
|
|
|
*((uint64_t*)ptr) = htole64(x);
|
|
|
|
}
|
2014-05-03 01:04:18 +02:00
|
|
|
|
2014-09-25 08:23:32 +02:00
|
|
|
uint32_t static inline ReadBE32(const unsigned char* ptr)
|
|
|
|
{
|
2014-06-09 21:05:28 +02:00
|
|
|
return be32toh(*((uint32_t*)ptr));
|
2014-05-03 01:04:18 +02:00
|
|
|
}
|
|
|
|
|
2014-09-25 08:23:32 +02:00
|
|
|
uint64_t static inline ReadBE64(const unsigned char* ptr)
|
|
|
|
{
|
2014-06-09 21:05:28 +02:00
|
|
|
return be64toh(*((uint64_t*)ptr));
|
2014-05-03 01:04:18 +02:00
|
|
|
}
|
|
|
|
|
2014-09-25 08:23:32 +02:00
|
|
|
void static inline WriteBE32(unsigned char* ptr, uint32_t x)
|
|
|
|
{
|
2014-06-09 21:05:28 +02:00
|
|
|
*((uint32_t*)ptr) = htobe32(x);
|
2014-05-03 01:04:18 +02:00
|
|
|
}
|
|
|
|
|
2014-09-25 08:23:32 +02:00
|
|
|
void static inline WriteBE64(unsigned char* ptr, uint64_t x)
|
|
|
|
{
|
2014-06-09 21:05:28 +02:00
|
|
|
*((uint64_t*)ptr) = htobe64(x);
|
2014-05-03 01:04:18 +02:00
|
|
|
}
|
|
|
|
|
2014-09-27 13:49:21 +02:00
|
|
|
#endif // BITCOIN_CRYPTO_COMMON_H
|