feat():initial version
This commit is contained in:
74
install/boost_1_75_0/include/boost/uuid/detail/config.hpp
Normal file
74
install/boost_1_75_0/include/boost/uuid/detail/config.hpp
Normal file
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Copyright Andrey Semashev 2013.
|
||||
* Distributed under the Boost Software License, Version 1.0.
|
||||
* (See accompanying file LICENSE_1_0.txt or copy at
|
||||
* https://www.boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
/*!
|
||||
* \file uuid/detail/config.hpp
|
||||
*
|
||||
* \brief This header defines configuration macros for Boost.UUID.
|
||||
*/
|
||||
|
||||
#ifndef BOOST_UUID_DETAIL_CONFIG_HPP_INCLUDED_
|
||||
#define BOOST_UUID_DETAIL_CONFIG_HPP_INCLUDED_
|
||||
|
||||
#include <boost/config.hpp>
|
||||
|
||||
#ifdef BOOST_HAS_PRAGMA_ONCE
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#if !defined(BOOST_UUID_NO_SIMD)
|
||||
|
||||
#if defined(__GNUC__) && defined(__SSE2__)
|
||||
|
||||
// GCC and its pretenders go here
|
||||
#ifndef BOOST_UUID_USE_SSE2
|
||||
#define BOOST_UUID_USE_SSE2
|
||||
#endif
|
||||
|
||||
#if defined(__SSE3__) && !defined(BOOST_UUID_USE_SSE3)
|
||||
#define BOOST_UUID_USE_SSE3
|
||||
#endif
|
||||
|
||||
#if defined(__SSE4_1__) && !defined(BOOST_UUID_USE_SSE41)
|
||||
#define BOOST_UUID_USE_SSE41
|
||||
#endif
|
||||
|
||||
#elif defined(_MSC_VER)
|
||||
|
||||
#if (defined(_M_X64) || (defined(_M_IX86) && defined(_M_IX86_FP) && _M_IX86_FP >= 2)) && !defined(BOOST_UUID_USE_SSE2)
|
||||
#define BOOST_UUID_USE_SSE2
|
||||
#endif
|
||||
|
||||
#if defined(__AVX__)
|
||||
#if !defined(BOOST_UUID_USE_SSE41)
|
||||
#define BOOST_UUID_USE_SSE41
|
||||
#endif
|
||||
#if !defined(BOOST_UUID_USE_SSE3)
|
||||
#define BOOST_UUID_USE_SSE3
|
||||
#endif
|
||||
#if !defined(BOOST_UUID_USE_SSE2)
|
||||
#define BOOST_UUID_USE_SSE2
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
// More advanced ISA extensions imply less advanced are also available
|
||||
#if !defined(BOOST_UUID_USE_SSE3) && defined(BOOST_UUID_USE_SSE41)
|
||||
#define BOOST_UUID_USE_SSE3
|
||||
#endif
|
||||
|
||||
#if !defined(BOOST_UUID_USE_SSE2) && defined(BOOST_UUID_USE_SSE3)
|
||||
#define BOOST_UUID_USE_SSE2
|
||||
#endif
|
||||
|
||||
#if !defined(BOOST_UUID_NO_SIMD) && !defined(BOOST_UUID_USE_SSE41) && !defined(BOOST_UUID_USE_SSE3) && !defined(BOOST_UUID_USE_SSE2)
|
||||
#define BOOST_UUID_NO_SIMD
|
||||
#endif
|
||||
|
||||
#endif // !defined(BOOST_UUID_NO_SIMD)
|
||||
|
||||
#endif // BOOST_UUID_DETAIL_CONFIG_HPP_INCLUDED_
|
||||
381
install/boost_1_75_0/include/boost/uuid/detail/md5.hpp
Normal file
381
install/boost_1_75_0/include/boost/uuid/detail/md5.hpp
Normal file
@@ -0,0 +1,381 @@
|
||||
/*
|
||||
* This RFC 1321 compatible MD5 implementation originated at:
|
||||
* http://openwall.info/wiki/people/solar/software/public-domain-source-code/md5
|
||||
*
|
||||
* Author:
|
||||
* Alexander Peslyak, better known as Solar Designer <solar at openwall.com>
|
||||
*
|
||||
* This software was written by Alexander Peslyak in 2001. No copyright is
|
||||
* claimed, and the software is hereby placed in the public domain.
|
||||
* In case this attempt to disclaim copyright and place the software in the
|
||||
* public domain is deemed null and void, then the software is
|
||||
* Copyright (c) 2001 Alexander Peslyak and it is hereby released to the
|
||||
* general public under the following terms:
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted.
|
||||
*
|
||||
* There's ABSOLUTELY NO WARRANTY, express or implied.
|
||||
*
|
||||
*/
|
||||
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
// https://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef BOOST_UUID_MD5_HPP
|
||||
#define BOOST_UUID_MD5_HPP
|
||||
|
||||
#include <boost/cast.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/cstdint.hpp>
|
||||
#include <boost/uuid/uuid.hpp> // for version
|
||||
#include <boost/predef/other/endian.h>
|
||||
#include <string.h>
|
||||
|
||||
namespace boost {
|
||||
namespace uuids {
|
||||
namespace detail {
|
||||
|
||||
class md5
|
||||
{
|
||||
public:
|
||||
typedef unsigned int(digest_type)[4];
|
||||
|
||||
md5()
|
||||
{
|
||||
MD5_Init(&ctx_);
|
||||
}
|
||||
|
||||
void process_byte(unsigned char byte)
|
||||
{
|
||||
MD5_Update(&ctx_, &byte, 1);
|
||||
}
|
||||
|
||||
void process_bytes(void const* buffer, std::size_t byte_count)
|
||||
{
|
||||
MD5_Update(&ctx_, buffer, boost::numeric_cast<unsigned long>(byte_count));
|
||||
}
|
||||
|
||||
void get_digest(digest_type& digest)
|
||||
{
|
||||
MD5_Final(reinterpret_cast<unsigned char *>(&digest[0]), &ctx_);
|
||||
}
|
||||
|
||||
unsigned char get_version() const
|
||||
{
|
||||
// RFC 4122 Section 4.1.3
|
||||
return uuid::version_name_based_md5;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
/* Any 32-bit or wider unsigned integer data type will do */
|
||||
typedef uint32_t MD5_u32plus;
|
||||
|
||||
typedef struct {
|
||||
MD5_u32plus lo, hi;
|
||||
MD5_u32plus a, b, c, d;
|
||||
unsigned char buffer[64];
|
||||
MD5_u32plus block[16];
|
||||
} MD5_CTX;
|
||||
|
||||
/*
|
||||
* The basic MD5 functions.
|
||||
*
|
||||
* F and G are optimized compared to their RFC 1321 definitions for
|
||||
* architectures that lack an AND-NOT instruction, just like in Colin Plumb's
|
||||
* implementation.
|
||||
*/
|
||||
BOOST_FORCEINLINE MD5_u32plus BOOST_UUID_DETAIL_MD5_F(MD5_u32plus x, MD5_u32plus y, MD5_u32plus z) { return ((z) ^ ((x) & ((y) ^ (z)))); }
|
||||
BOOST_FORCEINLINE MD5_u32plus BOOST_UUID_DETAIL_MD5_G(MD5_u32plus x, MD5_u32plus y, MD5_u32plus z) { return ((y) ^ ((z) & ((x) ^ (y)))); }
|
||||
BOOST_FORCEINLINE MD5_u32plus BOOST_UUID_DETAIL_MD5_H(MD5_u32plus x, MD5_u32plus y, MD5_u32plus z) { return (((x) ^ (y)) ^ (z)); }
|
||||
BOOST_FORCEINLINE MD5_u32plus BOOST_UUID_DETAIL_MD5_H2(MD5_u32plus x, MD5_u32plus y, MD5_u32plus z) { return ((x) ^ ((y) ^ (z))); }
|
||||
BOOST_FORCEINLINE MD5_u32plus BOOST_UUID_DETAIL_MD5_I(MD5_u32plus x, MD5_u32plus y, MD5_u32plus z) { return ((y) ^ ((x) | ~(z))); }
|
||||
|
||||
/*
|
||||
* The MD5 transformation for all four rounds.
|
||||
*/
|
||||
#define BOOST_UUID_DETAIL_MD5_STEP(f, a, b, c, d, x, t, s) \
|
||||
(a) += f((b), (c), (d)) + (x) + (t); \
|
||||
(a) = (((a) << (s)) | (((a) & 0xffffffff) >> (32 - (s)))); \
|
||||
(a) += (b);
|
||||
|
||||
/*
|
||||
* SET reads 4 input bytes in little-endian byte order and stores them in a
|
||||
* properly aligned word in host byte order.
|
||||
*
|
||||
* The check for little-endian architectures that tolerate unaligned memory
|
||||
* accesses is just an optimization. Nothing will break if it fails to detect
|
||||
* a suitable architecture.
|
||||
*
|
||||
* Unfortunately, this optimization may be a C strict aliasing rules violation
|
||||
* if the caller's data buffer has effective type that cannot be aliased by
|
||||
* MD5_u32plus. In practice, this problem may occur if these MD5 routines are
|
||||
* inlined into a calling function, or with future and dangerously advanced
|
||||
* link-time optimizations. For the time being, keeping these MD5 routines in
|
||||
* their own translation unit avoids the problem.
|
||||
*/
|
||||
#if defined(__i386__) || defined(__x86_64__) || defined(__vax__)
|
||||
#define BOOST_UUID_DETAIL_MD5_SET(n) \
|
||||
(*(MD5_u32plus *)&ptr[(n) * 4])
|
||||
#define BOOST_UUID_DETAIL_MD5_GET(n) \
|
||||
BOOST_UUID_DETAIL_MD5_SET(n)
|
||||
#else
|
||||
#define BOOST_UUID_DETAIL_MD5_SET(n) \
|
||||
(ctx->block[(n)] = \
|
||||
(MD5_u32plus)ptr[(n) * 4] | \
|
||||
((MD5_u32plus)ptr[(n) * 4 + 1] << 8) | \
|
||||
((MD5_u32plus)ptr[(n) * 4 + 2] << 16) | \
|
||||
((MD5_u32plus)ptr[(n) * 4 + 3] << 24))
|
||||
#define BOOST_UUID_DETAIL_MD5_GET(n) \
|
||||
(ctx->block[(n)])
|
||||
#endif
|
||||
|
||||
/*
|
||||
* This processes one or more 64-byte data blocks, but does NOT update the bit
|
||||
* counters. There are no alignment requirements.
|
||||
*/
|
||||
const void *body(MD5_CTX *ctx, const void *data, unsigned long size)
|
||||
{
|
||||
const unsigned char *ptr;
|
||||
MD5_u32plus a, b, c, d;
|
||||
MD5_u32plus saved_a, saved_b, saved_c, saved_d;
|
||||
|
||||
ptr = (const unsigned char *)data;
|
||||
|
||||
a = ctx->a;
|
||||
b = ctx->b;
|
||||
c = ctx->c;
|
||||
d = ctx->d;
|
||||
|
||||
do {
|
||||
saved_a = a;
|
||||
saved_b = b;
|
||||
saved_c = c;
|
||||
saved_d = d;
|
||||
|
||||
/* Round 1 */
|
||||
BOOST_UUID_DETAIL_MD5_STEP(BOOST_UUID_DETAIL_MD5_F, a, b, c, d, BOOST_UUID_DETAIL_MD5_SET(0), 0xd76aa478, 7)
|
||||
BOOST_UUID_DETAIL_MD5_STEP(BOOST_UUID_DETAIL_MD5_F, d, a, b, c, BOOST_UUID_DETAIL_MD5_SET(1), 0xe8c7b756, 12)
|
||||
BOOST_UUID_DETAIL_MD5_STEP(BOOST_UUID_DETAIL_MD5_F, c, d, a, b, BOOST_UUID_DETAIL_MD5_SET(2), 0x242070db, 17)
|
||||
BOOST_UUID_DETAIL_MD5_STEP(BOOST_UUID_DETAIL_MD5_F, b, c, d, a, BOOST_UUID_DETAIL_MD5_SET(3), 0xc1bdceee, 22)
|
||||
BOOST_UUID_DETAIL_MD5_STEP(BOOST_UUID_DETAIL_MD5_F, a, b, c, d, BOOST_UUID_DETAIL_MD5_SET(4), 0xf57c0faf, 7)
|
||||
BOOST_UUID_DETAIL_MD5_STEP(BOOST_UUID_DETAIL_MD5_F, d, a, b, c, BOOST_UUID_DETAIL_MD5_SET(5), 0x4787c62a, 12)
|
||||
BOOST_UUID_DETAIL_MD5_STEP(BOOST_UUID_DETAIL_MD5_F, c, d, a, b, BOOST_UUID_DETAIL_MD5_SET(6), 0xa8304613, 17)
|
||||
BOOST_UUID_DETAIL_MD5_STEP(BOOST_UUID_DETAIL_MD5_F, b, c, d, a, BOOST_UUID_DETAIL_MD5_SET(7), 0xfd469501, 22)
|
||||
BOOST_UUID_DETAIL_MD5_STEP(BOOST_UUID_DETAIL_MD5_F, a, b, c, d, BOOST_UUID_DETAIL_MD5_SET(8), 0x698098d8, 7)
|
||||
BOOST_UUID_DETAIL_MD5_STEP(BOOST_UUID_DETAIL_MD5_F, d, a, b, c, BOOST_UUID_DETAIL_MD5_SET(9), 0x8b44f7af, 12)
|
||||
BOOST_UUID_DETAIL_MD5_STEP(BOOST_UUID_DETAIL_MD5_F, c, d, a, b, BOOST_UUID_DETAIL_MD5_SET(10), 0xffff5bb1, 17)
|
||||
BOOST_UUID_DETAIL_MD5_STEP(BOOST_UUID_DETAIL_MD5_F, b, c, d, a, BOOST_UUID_DETAIL_MD5_SET(11), 0x895cd7be, 22)
|
||||
BOOST_UUID_DETAIL_MD5_STEP(BOOST_UUID_DETAIL_MD5_F, a, b, c, d, BOOST_UUID_DETAIL_MD5_SET(12), 0x6b901122, 7)
|
||||
BOOST_UUID_DETAIL_MD5_STEP(BOOST_UUID_DETAIL_MD5_F, d, a, b, c, BOOST_UUID_DETAIL_MD5_SET(13), 0xfd987193, 12)
|
||||
BOOST_UUID_DETAIL_MD5_STEP(BOOST_UUID_DETAIL_MD5_F, c, d, a, b, BOOST_UUID_DETAIL_MD5_SET(14), 0xa679438e, 17)
|
||||
BOOST_UUID_DETAIL_MD5_STEP(BOOST_UUID_DETAIL_MD5_F, b, c, d, a, BOOST_UUID_DETAIL_MD5_SET(15), 0x49b40821, 22)
|
||||
|
||||
/* Round 2 */
|
||||
BOOST_UUID_DETAIL_MD5_STEP(BOOST_UUID_DETAIL_MD5_G, a, b, c, d, BOOST_UUID_DETAIL_MD5_GET(1), 0xf61e2562, 5)
|
||||
BOOST_UUID_DETAIL_MD5_STEP(BOOST_UUID_DETAIL_MD5_G, d, a, b, c, BOOST_UUID_DETAIL_MD5_GET(6), 0xc040b340, 9)
|
||||
BOOST_UUID_DETAIL_MD5_STEP(BOOST_UUID_DETAIL_MD5_G, c, d, a, b, BOOST_UUID_DETAIL_MD5_GET(11), 0x265e5a51, 14)
|
||||
BOOST_UUID_DETAIL_MD5_STEP(BOOST_UUID_DETAIL_MD5_G, b, c, d, a, BOOST_UUID_DETAIL_MD5_GET(0), 0xe9b6c7aa, 20)
|
||||
BOOST_UUID_DETAIL_MD5_STEP(BOOST_UUID_DETAIL_MD5_G, a, b, c, d, BOOST_UUID_DETAIL_MD5_GET(5), 0xd62f105d, 5)
|
||||
BOOST_UUID_DETAIL_MD5_STEP(BOOST_UUID_DETAIL_MD5_G, d, a, b, c, BOOST_UUID_DETAIL_MD5_GET(10), 0x02441453, 9)
|
||||
BOOST_UUID_DETAIL_MD5_STEP(BOOST_UUID_DETAIL_MD5_G, c, d, a, b, BOOST_UUID_DETAIL_MD5_GET(15), 0xd8a1e681, 14)
|
||||
BOOST_UUID_DETAIL_MD5_STEP(BOOST_UUID_DETAIL_MD5_G, b, c, d, a, BOOST_UUID_DETAIL_MD5_GET(4), 0xe7d3fbc8, 20)
|
||||
BOOST_UUID_DETAIL_MD5_STEP(BOOST_UUID_DETAIL_MD5_G, a, b, c, d, BOOST_UUID_DETAIL_MD5_GET(9), 0x21e1cde6, 5)
|
||||
BOOST_UUID_DETAIL_MD5_STEP(BOOST_UUID_DETAIL_MD5_G, d, a, b, c, BOOST_UUID_DETAIL_MD5_GET(14), 0xc33707d6, 9)
|
||||
BOOST_UUID_DETAIL_MD5_STEP(BOOST_UUID_DETAIL_MD5_G, c, d, a, b, BOOST_UUID_DETAIL_MD5_GET(3), 0xf4d50d87, 14)
|
||||
BOOST_UUID_DETAIL_MD5_STEP(BOOST_UUID_DETAIL_MD5_G, b, c, d, a, BOOST_UUID_DETAIL_MD5_GET(8), 0x455a14ed, 20)
|
||||
BOOST_UUID_DETAIL_MD5_STEP(BOOST_UUID_DETAIL_MD5_G, a, b, c, d, BOOST_UUID_DETAIL_MD5_GET(13), 0xa9e3e905, 5)
|
||||
BOOST_UUID_DETAIL_MD5_STEP(BOOST_UUID_DETAIL_MD5_G, d, a, b, c, BOOST_UUID_DETAIL_MD5_GET(2), 0xfcefa3f8, 9)
|
||||
BOOST_UUID_DETAIL_MD5_STEP(BOOST_UUID_DETAIL_MD5_G, c, d, a, b, BOOST_UUID_DETAIL_MD5_GET(7), 0x676f02d9, 14)
|
||||
BOOST_UUID_DETAIL_MD5_STEP(BOOST_UUID_DETAIL_MD5_G, b, c, d, a, BOOST_UUID_DETAIL_MD5_GET(12), 0x8d2a4c8a, 20)
|
||||
|
||||
/* Round 3 */
|
||||
BOOST_UUID_DETAIL_MD5_STEP(BOOST_UUID_DETAIL_MD5_H, a, b, c, d, BOOST_UUID_DETAIL_MD5_GET(5), 0xfffa3942, 4)
|
||||
BOOST_UUID_DETAIL_MD5_STEP(BOOST_UUID_DETAIL_MD5_H2, d, a, b, c, BOOST_UUID_DETAIL_MD5_GET(8), 0x8771f681, 11)
|
||||
BOOST_UUID_DETAIL_MD5_STEP(BOOST_UUID_DETAIL_MD5_H, c, d, a, b, BOOST_UUID_DETAIL_MD5_GET(11), 0x6d9d6122, 16)
|
||||
BOOST_UUID_DETAIL_MD5_STEP(BOOST_UUID_DETAIL_MD5_H2, b, c, d, a, BOOST_UUID_DETAIL_MD5_GET(14), 0xfde5380c, 23)
|
||||
BOOST_UUID_DETAIL_MD5_STEP(BOOST_UUID_DETAIL_MD5_H, a, b, c, d, BOOST_UUID_DETAIL_MD5_GET(1), 0xa4beea44, 4)
|
||||
BOOST_UUID_DETAIL_MD5_STEP(BOOST_UUID_DETAIL_MD5_H2, d, a, b, c, BOOST_UUID_DETAIL_MD5_GET(4), 0x4bdecfa9, 11)
|
||||
BOOST_UUID_DETAIL_MD5_STEP(BOOST_UUID_DETAIL_MD5_H, c, d, a, b, BOOST_UUID_DETAIL_MD5_GET(7), 0xf6bb4b60, 16)
|
||||
BOOST_UUID_DETAIL_MD5_STEP(BOOST_UUID_DETAIL_MD5_H2, b, c, d, a, BOOST_UUID_DETAIL_MD5_GET(10), 0xbebfbc70, 23)
|
||||
BOOST_UUID_DETAIL_MD5_STEP(BOOST_UUID_DETAIL_MD5_H, a, b, c, d, BOOST_UUID_DETAIL_MD5_GET(13), 0x289b7ec6, 4)
|
||||
BOOST_UUID_DETAIL_MD5_STEP(BOOST_UUID_DETAIL_MD5_H2, d, a, b, c, BOOST_UUID_DETAIL_MD5_GET(0), 0xeaa127fa, 11)
|
||||
BOOST_UUID_DETAIL_MD5_STEP(BOOST_UUID_DETAIL_MD5_H, c, d, a, b, BOOST_UUID_DETAIL_MD5_GET(3), 0xd4ef3085, 16)
|
||||
BOOST_UUID_DETAIL_MD5_STEP(BOOST_UUID_DETAIL_MD5_H2, b, c, d, a, BOOST_UUID_DETAIL_MD5_GET(6), 0x04881d05, 23)
|
||||
BOOST_UUID_DETAIL_MD5_STEP(BOOST_UUID_DETAIL_MD5_H, a, b, c, d, BOOST_UUID_DETAIL_MD5_GET(9), 0xd9d4d039, 4)
|
||||
BOOST_UUID_DETAIL_MD5_STEP(BOOST_UUID_DETAIL_MD5_H2, d, a, b, c, BOOST_UUID_DETAIL_MD5_GET(12), 0xe6db99e5, 11)
|
||||
BOOST_UUID_DETAIL_MD5_STEP(BOOST_UUID_DETAIL_MD5_H, c, d, a, b, BOOST_UUID_DETAIL_MD5_GET(15), 0x1fa27cf8, 16)
|
||||
BOOST_UUID_DETAIL_MD5_STEP(BOOST_UUID_DETAIL_MD5_H2, b, c, d, a, BOOST_UUID_DETAIL_MD5_GET(2), 0xc4ac5665, 23)
|
||||
|
||||
/* Round 4 */
|
||||
BOOST_UUID_DETAIL_MD5_STEP(BOOST_UUID_DETAIL_MD5_I, a, b, c, d, BOOST_UUID_DETAIL_MD5_GET(0), 0xf4292244, 6)
|
||||
BOOST_UUID_DETAIL_MD5_STEP(BOOST_UUID_DETAIL_MD5_I, d, a, b, c, BOOST_UUID_DETAIL_MD5_GET(7), 0x432aff97, 10)
|
||||
BOOST_UUID_DETAIL_MD5_STEP(BOOST_UUID_DETAIL_MD5_I, c, d, a, b, BOOST_UUID_DETAIL_MD5_GET(14), 0xab9423a7, 15)
|
||||
BOOST_UUID_DETAIL_MD5_STEP(BOOST_UUID_DETAIL_MD5_I, b, c, d, a, BOOST_UUID_DETAIL_MD5_GET(5), 0xfc93a039, 21)
|
||||
BOOST_UUID_DETAIL_MD5_STEP(BOOST_UUID_DETAIL_MD5_I, a, b, c, d, BOOST_UUID_DETAIL_MD5_GET(12), 0x655b59c3, 6)
|
||||
BOOST_UUID_DETAIL_MD5_STEP(BOOST_UUID_DETAIL_MD5_I, d, a, b, c, BOOST_UUID_DETAIL_MD5_GET(3), 0x8f0ccc92, 10)
|
||||
BOOST_UUID_DETAIL_MD5_STEP(BOOST_UUID_DETAIL_MD5_I, c, d, a, b, BOOST_UUID_DETAIL_MD5_GET(10), 0xffeff47d, 15)
|
||||
BOOST_UUID_DETAIL_MD5_STEP(BOOST_UUID_DETAIL_MD5_I, b, c, d, a, BOOST_UUID_DETAIL_MD5_GET(1), 0x85845dd1, 21)
|
||||
BOOST_UUID_DETAIL_MD5_STEP(BOOST_UUID_DETAIL_MD5_I, a, b, c, d, BOOST_UUID_DETAIL_MD5_GET(8), 0x6fa87e4f, 6)
|
||||
BOOST_UUID_DETAIL_MD5_STEP(BOOST_UUID_DETAIL_MD5_I, d, a, b, c, BOOST_UUID_DETAIL_MD5_GET(15), 0xfe2ce6e0, 10)
|
||||
BOOST_UUID_DETAIL_MD5_STEP(BOOST_UUID_DETAIL_MD5_I, c, d, a, b, BOOST_UUID_DETAIL_MD5_GET(6), 0xa3014314, 15)
|
||||
BOOST_UUID_DETAIL_MD5_STEP(BOOST_UUID_DETAIL_MD5_I, b, c, d, a, BOOST_UUID_DETAIL_MD5_GET(13), 0x4e0811a1, 21)
|
||||
BOOST_UUID_DETAIL_MD5_STEP(BOOST_UUID_DETAIL_MD5_I, a, b, c, d, BOOST_UUID_DETAIL_MD5_GET(4), 0xf7537e82, 6)
|
||||
BOOST_UUID_DETAIL_MD5_STEP(BOOST_UUID_DETAIL_MD5_I, d, a, b, c, BOOST_UUID_DETAIL_MD5_GET(11), 0xbd3af235, 10)
|
||||
BOOST_UUID_DETAIL_MD5_STEP(BOOST_UUID_DETAIL_MD5_I, c, d, a, b, BOOST_UUID_DETAIL_MD5_GET(2), 0x2ad7d2bb, 15)
|
||||
BOOST_UUID_DETAIL_MD5_STEP(BOOST_UUID_DETAIL_MD5_I, b, c, d, a, BOOST_UUID_DETAIL_MD5_GET(9), 0xeb86d391, 21)
|
||||
|
||||
a += saved_a;
|
||||
b += saved_b;
|
||||
c += saved_c;
|
||||
d += saved_d;
|
||||
|
||||
ptr += 64;
|
||||
} while (size -= 64);
|
||||
|
||||
ctx->a = a;
|
||||
ctx->b = b;
|
||||
ctx->c = c;
|
||||
ctx->d = d;
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void MD5_Init(MD5_CTX *ctx)
|
||||
{
|
||||
ctx->a = 0x67452301;
|
||||
ctx->b = 0xefcdab89;
|
||||
ctx->c = 0x98badcfe;
|
||||
ctx->d = 0x10325476;
|
||||
|
||||
ctx->lo = 0;
|
||||
ctx->hi = 0;
|
||||
}
|
||||
|
||||
void MD5_Update(MD5_CTX *ctx, const void *data, unsigned long size)
|
||||
{
|
||||
MD5_u32plus saved_lo;
|
||||
unsigned long used, available;
|
||||
|
||||
saved_lo = ctx->lo;
|
||||
if ((ctx->lo = (saved_lo + size) & 0x1fffffff) < saved_lo)
|
||||
ctx->hi++;
|
||||
ctx->hi += size >> 29;
|
||||
|
||||
used = saved_lo & 0x3f;
|
||||
|
||||
if (used) {
|
||||
available = 64 - used;
|
||||
|
||||
if (size < available) {
|
||||
memcpy(&ctx->buffer[used], data, size);
|
||||
return;
|
||||
}
|
||||
|
||||
memcpy(&ctx->buffer[used], data, available);
|
||||
data = (const unsigned char *)data + available;
|
||||
size -= available;
|
||||
body(ctx, ctx->buffer, 64);
|
||||
}
|
||||
|
||||
if (size >= 64) {
|
||||
data = body(ctx, data, size & ~(unsigned long)0x3f);
|
||||
size &= 0x3f;
|
||||
}
|
||||
|
||||
memcpy(ctx->buffer, data, size);
|
||||
}
|
||||
|
||||
// This must remain consistent no matter the endianness
|
||||
#define BOOST_UUID_DETAIL_MD5_OUT(dst, src) \
|
||||
(dst)[0] = (unsigned char)(src); \
|
||||
(dst)[1] = (unsigned char)((src) >> 8); \
|
||||
(dst)[2] = (unsigned char)((src) >> 16); \
|
||||
(dst)[3] = (unsigned char)((src) >> 24);
|
||||
|
||||
//
|
||||
// A big-endian issue with MD5 results was resolved
|
||||
// in boost 1.71. If you generated md5 name-based uuids
|
||||
// with boost 1.66 through 1.70 and stored them, then
|
||||
// set the following compatibility flag to ensure that
|
||||
// your hash generation remains consistent.
|
||||
//
|
||||
#if defined(BOOST_UUID_COMPAT_PRE_1_71_MD5)
|
||||
#define BOOST_UUID_DETAIL_MD5_BYTE_OUT(dst, src) \
|
||||
BOOST_UUID_DETAIL_MD5_OUT(dst, src)
|
||||
#else
|
||||
//
|
||||
// We're copying into a byte buffer which is actually
|
||||
// backed by an unsigned int array, which later on
|
||||
// is then swabbed one more time by the basic name
|
||||
// generator. Therefore the logic here is reversed.
|
||||
// This was done to minimize the impact to existing
|
||||
// name-based hash generation. The correct fix would
|
||||
// be to make this and name generation endian-correct
|
||||
// but that would even break previously generated sha1
|
||||
// hashes too.
|
||||
//
|
||||
#if BOOST_ENDIAN_LITTLE_BYTE
|
||||
#define BOOST_UUID_DETAIL_MD5_BYTE_OUT(dst, src) \
|
||||
(dst)[0] = (unsigned char)((src) >> 24); \
|
||||
(dst)[1] = (unsigned char)((src) >> 16); \
|
||||
(dst)[2] = (unsigned char)((src) >> 8); \
|
||||
(dst)[3] = (unsigned char)(src);
|
||||
#else
|
||||
#define BOOST_UUID_DETAIL_MD5_BYTE_OUT(dst, src) \
|
||||
(dst)[0] = (unsigned char)(src); \
|
||||
(dst)[1] = (unsigned char)((src) >> 8); \
|
||||
(dst)[2] = (unsigned char)((src) >> 16); \
|
||||
(dst)[3] = (unsigned char)((src) >> 24);
|
||||
#endif
|
||||
#endif // BOOST_UUID_COMPAT_PRE_1_71_MD5
|
||||
|
||||
void MD5_Final(unsigned char *result, MD5_CTX *ctx)
|
||||
{
|
||||
unsigned long used, available;
|
||||
|
||||
used = ctx->lo & 0x3f;
|
||||
|
||||
ctx->buffer[used++] = 0x80;
|
||||
|
||||
available = 64 - used;
|
||||
|
||||
if (available < 8) {
|
||||
memset(&ctx->buffer[used], 0, available);
|
||||
body(ctx, ctx->buffer, 64);
|
||||
used = 0;
|
||||
available = 64;
|
||||
}
|
||||
|
||||
memset(&ctx->buffer[used], 0, available - 8);
|
||||
|
||||
ctx->lo <<= 3;
|
||||
BOOST_UUID_DETAIL_MD5_OUT(&ctx->buffer[56], ctx->lo)
|
||||
BOOST_UUID_DETAIL_MD5_OUT(&ctx->buffer[60], ctx->hi)
|
||||
|
||||
body(ctx, ctx->buffer, 64);
|
||||
|
||||
BOOST_UUID_DETAIL_MD5_BYTE_OUT(&result[0], ctx->a)
|
||||
BOOST_UUID_DETAIL_MD5_BYTE_OUT(&result[4], ctx->b)
|
||||
BOOST_UUID_DETAIL_MD5_BYTE_OUT(&result[8], ctx->c)
|
||||
BOOST_UUID_DETAIL_MD5_BYTE_OUT(&result[12], ctx->d)
|
||||
|
||||
memset(ctx, 0, sizeof(*ctx));
|
||||
}
|
||||
|
||||
#undef BOOST_UUID_DETAIL_MD5_OUT
|
||||
#undef BOOST_UUID_DETAIL_MD5_SET
|
||||
#undef BOOST_UUID_DETAIL_MD5_GET
|
||||
#undef BOOST_UUID_DETAIL_MD5_STEP
|
||||
|
||||
MD5_CTX ctx_;
|
||||
};
|
||||
|
||||
|
||||
} // detail
|
||||
} // uuids
|
||||
} // boost
|
||||
|
||||
#endif // BOOST_UUID_MD5_HPP
|
||||
@@ -0,0 +1,91 @@
|
||||
//
|
||||
// Copyright (c) 2017 James E. King III
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// https://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// Platform-specific random entropy provider
|
||||
//
|
||||
|
||||
#ifndef BOOST_UUID_DETAIL_RANDOM_PROVIDER_HPP
|
||||
#define BOOST_UUID_DETAIL_RANDOM_PROVIDER_HPP
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/cstdint.hpp>
|
||||
#include <boost/limits.hpp>
|
||||
#include <boost/static_assert.hpp>
|
||||
#include <boost/move/core.hpp>
|
||||
#include <boost/move/utility_core.hpp>
|
||||
#include <boost/type_traits/is_integral.hpp>
|
||||
#include <boost/type_traits/is_unsigned.hpp>
|
||||
#include <boost/uuid/entropy_error.hpp>
|
||||
#include <climits>
|
||||
#include <iterator>
|
||||
|
||||
// Detection of the platform is separated from inclusion of the correct
|
||||
// header to facilitate mock testing of the provider implementations.
|
||||
|
||||
#include <boost/uuid/detail/random_provider_detect_platform.hpp>
|
||||
#include <boost/uuid/detail/random_provider_include_platform.hpp>
|
||||
|
||||
|
||||
namespace boost {
|
||||
namespace uuids {
|
||||
namespace detail {
|
||||
|
||||
//! \brief Contains code common to all random_provider implementations.
|
||||
//! \note random_provider_base is required to provide this method:
|
||||
//! void get_random_bytes(void *buf, size_t siz);
|
||||
//! \note noncopyable because of some base implementations so
|
||||
//! this makes it uniform across platforms to avoid any
|
||||
//! porting surprises
|
||||
class random_provider :
|
||||
public detail::random_provider_base
|
||||
{
|
||||
BOOST_MOVABLE_BUT_NOT_COPYABLE(random_provider)
|
||||
|
||||
public:
|
||||
BOOST_DEFAULTED_FUNCTION(random_provider(), {})
|
||||
|
||||
random_provider(BOOST_RV_REF(random_provider) that) BOOST_NOEXCEPT :
|
||||
detail::random_provider_base(boost::move(static_cast< detail::random_provider_base& >(that)))
|
||||
{
|
||||
}
|
||||
|
||||
random_provider& operator= (BOOST_RV_REF(random_provider) that) BOOST_NOEXCEPT
|
||||
{
|
||||
static_cast< detail::random_provider_base& >(*this) = boost::move(static_cast< detail::random_provider_base& >(that));
|
||||
return *this;
|
||||
}
|
||||
|
||||
//! Leverage the provider as a SeedSeq for
|
||||
//! PseudoRandomNumberGeneration seeing.
|
||||
//! \note: See Boost.Random documentation for more details
|
||||
template<class Iter>
|
||||
void generate(Iter first, Iter last)
|
||||
{
|
||||
typedef typename std::iterator_traits<Iter>::value_type value_type;
|
||||
BOOST_STATIC_ASSERT(is_integral<value_type>::value);
|
||||
BOOST_STATIC_ASSERT(is_unsigned<value_type>::value);
|
||||
BOOST_STATIC_ASSERT(sizeof(value_type) * CHAR_BIT >= 32);
|
||||
|
||||
for (; first != last; ++first)
|
||||
{
|
||||
get_random_bytes(&*first, sizeof(*first));
|
||||
*first &= (std::numeric_limits<boost::uint32_t>::max)();
|
||||
}
|
||||
}
|
||||
|
||||
//! Return the name of the selected provider
|
||||
const char * name() const
|
||||
{
|
||||
return BOOST_UUID_RANDOM_PROVIDER_STRINGIFY(BOOST_UUID_RANDOM_PROVIDER_NAME);
|
||||
}
|
||||
};
|
||||
|
||||
} // detail
|
||||
} // uuids
|
||||
} // boost
|
||||
|
||||
#endif // BOOST_UUID_DETAIL_RANDOM_PROVIDER_HPP
|
||||
@@ -0,0 +1,33 @@
|
||||
//
|
||||
// Copyright (c) 2017 James E. King III
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// https://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// "A Replacement Call for Random"
|
||||
// https://man.openbsd.org/arc4random.3
|
||||
//
|
||||
|
||||
#include <cstddef>
|
||||
#include <stdlib.h>
|
||||
|
||||
namespace boost {
|
||||
namespace uuids {
|
||||
namespace detail {
|
||||
|
||||
class random_provider_base
|
||||
{
|
||||
public:
|
||||
//! Obtain entropy and place it into a memory location
|
||||
//! \param[in] buf the location to write entropy
|
||||
//! \param[in] siz the number of bytes to acquire
|
||||
void get_random_bytes(void *buf, std::size_t siz)
|
||||
{
|
||||
arc4random_buf(buf, siz);
|
||||
}
|
||||
};
|
||||
|
||||
} // detail
|
||||
} // uuids
|
||||
} // boost
|
||||
@@ -0,0 +1,107 @@
|
||||
//
|
||||
// Copyright (c) 2017 James E. King III
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// https://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// BCrypt provider for entropy
|
||||
//
|
||||
|
||||
#include <cstddef>
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/core/ignore_unused.hpp>
|
||||
#include <boost/move/core.hpp>
|
||||
#include <boost/numeric/conversion/cast.hpp>
|
||||
#include <boost/winapi/bcrypt.hpp>
|
||||
#include <boost/winapi/get_last_error.hpp>
|
||||
#include <boost/throw_exception.hpp>
|
||||
|
||||
#if defined(BOOST_UUID_FORCE_AUTO_LINK) || (!defined(BOOST_ALL_NO_LIB) && !defined(BOOST_UUID_RANDOM_PROVIDER_NO_LIB))
|
||||
# define BOOST_LIB_NAME "bcrypt"
|
||||
# if defined(BOOST_AUTO_LINK_NOMANGLE)
|
||||
# include <boost/config/auto_link.hpp>
|
||||
# else
|
||||
# define BOOST_AUTO_LINK_NOMANGLE
|
||||
# include <boost/config/auto_link.hpp>
|
||||
# undef BOOST_AUTO_LINK_NOMANGLE
|
||||
# endif
|
||||
#endif
|
||||
|
||||
namespace boost {
|
||||
namespace uuids {
|
||||
namespace detail {
|
||||
|
||||
class random_provider_base
|
||||
{
|
||||
BOOST_MOVABLE_BUT_NOT_COPYABLE(random_provider_base)
|
||||
|
||||
public:
|
||||
random_provider_base()
|
||||
: hProv_(NULL)
|
||||
{
|
||||
boost::winapi::NTSTATUS_ status =
|
||||
boost::winapi::BCryptOpenAlgorithmProvider(
|
||||
&hProv_,
|
||||
boost::winapi::BCRYPT_RNG_ALGORITHM_,
|
||||
NULL,
|
||||
0);
|
||||
|
||||
if (BOOST_UNLIKELY(status != 0))
|
||||
{
|
||||
BOOST_THROW_EXCEPTION(entropy_error(status, "BCryptOpenAlgorithmProvider"));
|
||||
}
|
||||
}
|
||||
|
||||
random_provider_base(BOOST_RV_REF(random_provider_base) that) BOOST_NOEXCEPT : hProv_(that.hProv_)
|
||||
{
|
||||
that.hProv_ = NULL;
|
||||
}
|
||||
|
||||
random_provider_base& operator= (BOOST_RV_REF(random_provider_base) that) BOOST_NOEXCEPT
|
||||
{
|
||||
destroy();
|
||||
hProv_ = that.hProv_;
|
||||
that.hProv_ = NULL;
|
||||
return *this;
|
||||
}
|
||||
|
||||
~random_provider_base() BOOST_NOEXCEPT
|
||||
{
|
||||
destroy();
|
||||
}
|
||||
|
||||
//! Obtain entropy and place it into a memory location
|
||||
//! \param[in] buf the location to write entropy
|
||||
//! \param[in] siz the number of bytes to acquire
|
||||
void get_random_bytes(void *buf, std::size_t siz)
|
||||
{
|
||||
boost::winapi::NTSTATUS_ status =
|
||||
boost::winapi::BCryptGenRandom(
|
||||
hProv_,
|
||||
static_cast<boost::winapi::PUCHAR_>(buf),
|
||||
boost::numeric_cast<boost::winapi::ULONG_>(siz),
|
||||
0);
|
||||
|
||||
if (BOOST_UNLIKELY(status != 0))
|
||||
{
|
||||
BOOST_THROW_EXCEPTION(entropy_error(status, "BCryptGenRandom"));
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
void destroy() BOOST_NOEXCEPT
|
||||
{
|
||||
if (hProv_)
|
||||
{
|
||||
boost::ignore_unused(boost::winapi::BCryptCloseAlgorithmProvider(hProv_, 0));
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
boost::winapi::BCRYPT_ALG_HANDLE_ hProv_;
|
||||
};
|
||||
|
||||
} // detail
|
||||
} // uuids
|
||||
} // boost
|
||||
@@ -0,0 +1,80 @@
|
||||
//
|
||||
// Copyright (c) 2017 James E. King III
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// https://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// Platform-specific random entropy provider platform detection
|
||||
//
|
||||
|
||||
#ifndef BOOST_UUID_DETAIL_RANDOM_PROVIDER_PLATFORM_DETECTION_HPP
|
||||
#define BOOST_UUID_DETAIL_RANDOM_PROVIDER_PLATFORM_DETECTION_HPP
|
||||
|
||||
#include <boost/predef/library/c/cloudabi.h>
|
||||
#include <boost/predef/library/c/gnu.h>
|
||||
#include <boost/predef/os/bsd/open.h>
|
||||
#include <boost/predef/os/windows.h>
|
||||
|
||||
// Note: Don't use Boost.Predef to detect Linux and Android as it may give different results depending on header inclusion order.
|
||||
// https://github.com/boostorg/predef/issues/81#issuecomment-413329061
|
||||
#if (defined(__linux__) || defined(__linux) || defined(linux)) && (!defined(__ANDROID__) || __ANDROID_API__ >= 28)
|
||||
#include <sys/syscall.h>
|
||||
#if defined(SYS_getrandom)
|
||||
#define BOOST_UUID_RANDOM_PROVIDER_HAS_GETRANDOM
|
||||
#endif // defined(SYS_getrandom)
|
||||
#endif
|
||||
|
||||
// On Linux, getentropy is implemented via getrandom. If we know that getrandom is not supported by the kernel, getentropy
|
||||
// will certainly not work, even if libc provides a wrapper function for it. There is no reason, ever, to use getentropy on that platform.
|
||||
#if !defined(BOOST_UUID_RANDOM_PROVIDER_DISABLE_GETENTROPY) && (defined(__linux__) || defined(__linux) || defined(linux) || defined(__ANDROID__))
|
||||
#define BOOST_UUID_RANDOM_PROVIDER_DISABLE_GETENTROPY
|
||||
#endif
|
||||
|
||||
//
|
||||
// Platform Detection - will load in the correct header and
|
||||
// will define the class <tt>random_provider_base</tt>.
|
||||
//
|
||||
|
||||
#if BOOST_OS_BSD_OPEN >= BOOST_VERSION_NUMBER(2, 1, 0) || BOOST_LIB_C_CLOUDABI
|
||||
# define BOOST_UUID_RANDOM_PROVIDER_ARC4RANDOM
|
||||
# define BOOST_UUID_RANDOM_PROVIDER_NAME arc4random
|
||||
|
||||
#elif BOOST_OS_WINDOWS
|
||||
# include <boost/winapi/config.hpp>
|
||||
# if BOOST_WINAPI_PARTITION_APP_SYSTEM && \
|
||||
!defined(BOOST_UUID_RANDOM_PROVIDER_FORCE_WINCRYPT) && \
|
||||
!defined(_WIN32_WCE) && \
|
||||
(BOOST_USE_WINAPI_VERSION >= BOOST_WINAPI_VERSION_WIN6)
|
||||
# define BOOST_UUID_RANDOM_PROVIDER_BCRYPT
|
||||
# define BOOST_UUID_RANDOM_PROVIDER_NAME bcrypt
|
||||
|
||||
# elif BOOST_WINAPI_PARTITION_DESKTOP || BOOST_WINAPI_PARTITION_SYSTEM
|
||||
# define BOOST_UUID_RANDOM_PROVIDER_WINCRYPT
|
||||
# define BOOST_UUID_RANDOM_PROVIDER_NAME wincrypt
|
||||
# else
|
||||
# error Unable to find a suitable windows entropy provider
|
||||
# endif
|
||||
|
||||
#elif defined(BOOST_UUID_RANDOM_PROVIDER_HAS_GETRANDOM) && !defined(BOOST_UUID_RANDOM_PROVIDER_FORCE_POSIX) && !defined(BOOST_UUID_RANDOM_PROVIDER_DISABLE_GETRANDOM)
|
||||
# define BOOST_UUID_RANDOM_PROVIDER_GETRANDOM
|
||||
# define BOOST_UUID_RANDOM_PROVIDER_NAME getrandom
|
||||
|
||||
#elif BOOST_LIB_C_GNU >= BOOST_VERSION_NUMBER(2, 25, 0) && !defined(BOOST_UUID_RANDOM_PROVIDER_FORCE_POSIX) && !defined(BOOST_UUID_RANDOM_PROVIDER_DISABLE_GETENTROPY)
|
||||
# define BOOST_UUID_RANDOM_PROVIDER_GETENTROPY
|
||||
# define BOOST_UUID_RANDOM_PROVIDER_NAME getentropy
|
||||
|
||||
#else
|
||||
# define BOOST_UUID_RANDOM_PROVIDER_POSIX
|
||||
# define BOOST_UUID_RANDOM_PROVIDER_NAME posix
|
||||
|
||||
#endif
|
||||
|
||||
#define BOOST_UUID_RANDOM_PROVIDER_STRINGIFY2(X) #X
|
||||
#define BOOST_UUID_RANDOM_PROVIDER_STRINGIFY(X) BOOST_UUID_RANDOM_PROVIDER_STRINGIFY2(X)
|
||||
|
||||
#if defined(BOOST_UUID_RANDOM_PROVIDER_SHOW)
|
||||
#pragma message("BOOST_UUID_RANDOM_PROVIDER_NAME " BOOST_UUID_RANDOM_PROVIDER_STRINGIFY(BOOST_UUID_RANDOM_PROVIDER_NAME))
|
||||
#endif
|
||||
|
||||
#endif // BOOST_UUID_DETAIL_RANDOM_PROVIDER_PLATFORM_DETECTION_HPP
|
||||
@@ -0,0 +1,40 @@
|
||||
//
|
||||
// Copyright (c) 2017 James E. King III
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// https://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// getentropy() capable platforms
|
||||
//
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/throw_exception.hpp>
|
||||
#include <cerrno>
|
||||
#include <cstddef>
|
||||
#include <unistd.h>
|
||||
|
||||
namespace boost {
|
||||
namespace uuids {
|
||||
namespace detail {
|
||||
|
||||
class random_provider_base
|
||||
{
|
||||
public:
|
||||
//! Obtain entropy and place it into a memory location
|
||||
//! \param[in] buf the location to write entropy
|
||||
//! \param[in] siz the number of bytes to acquire
|
||||
void get_random_bytes(void *buf, std::size_t siz)
|
||||
{
|
||||
int res = getentropy(buf, siz);
|
||||
if (BOOST_UNLIKELY(-1 == res))
|
||||
{
|
||||
int err = errno;
|
||||
BOOST_THROW_EXCEPTION(entropy_error(err, "getentropy"));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
} // detail
|
||||
} // uuids
|
||||
} // boost
|
||||
@@ -0,0 +1,77 @@
|
||||
//
|
||||
// Copyright (c) 2018 Andrey Semashev
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// https://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// getrandom() capable platforms
|
||||
//
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/throw_exception.hpp>
|
||||
#include <boost/predef/library/c/gnu.h>
|
||||
#include <cerrno>
|
||||
#include <cstddef>
|
||||
|
||||
#if !defined(BOOST_UUID_RANDOM_PROVIDER_GETRANDOM_IMPL_GETRANDOM)
|
||||
#if BOOST_LIB_C_GNU >= BOOST_VERSION_NUMBER(2, 25, 0)
|
||||
#define BOOST_UUID_RANDOM_PROVIDER_GETRANDOM_HAS_LIBC_WRAPPER
|
||||
#elif defined(__has_include)
|
||||
#if __has_include(<sys/random.h>)
|
||||
#define BOOST_UUID_RANDOM_PROVIDER_GETRANDOM_HAS_LIBC_WRAPPER
|
||||
#endif
|
||||
#endif
|
||||
#endif // !defined(BOOST_UUID_RANDOM_PROVIDER_GETRANDOM_IMPL_GETRANDOM)
|
||||
|
||||
#if defined(BOOST_UUID_RANDOM_PROVIDER_GETRANDOM_HAS_LIBC_WRAPPER)
|
||||
#include <sys/random.h>
|
||||
#else
|
||||
#include <stddef.h> // ssize_t
|
||||
#endif
|
||||
|
||||
namespace boost {
|
||||
namespace uuids {
|
||||
namespace detail {
|
||||
|
||||
class random_provider_base
|
||||
{
|
||||
public:
|
||||
//! Obtain entropy and place it into a memory location
|
||||
//! \param[in] buf the location to write entropy
|
||||
//! \param[in] siz the number of bytes to acquire
|
||||
void get_random_bytes(void *buf, std::size_t siz)
|
||||
{
|
||||
std::size_t offset = 0;
|
||||
while (offset < siz)
|
||||
{
|
||||
ssize_t sz = get_random(static_cast< char* >(buf) + offset, siz - offset, 0u);
|
||||
|
||||
if (BOOST_UNLIKELY(sz < 0))
|
||||
{
|
||||
int err = errno;
|
||||
if (err == EINTR)
|
||||
continue;
|
||||
BOOST_THROW_EXCEPTION(entropy_error(err, "getrandom"));
|
||||
}
|
||||
|
||||
offset += sz;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
static ssize_t get_random(void *buf, std::size_t size, unsigned int flags)
|
||||
{
|
||||
#if defined(BOOST_UUID_RANDOM_PROVIDER_GETRANDOM_IMPL_GETRANDOM)
|
||||
return BOOST_UUID_RANDOM_PROVIDER_GETRANDOM_IMPL_GETRANDOM(buf, size, flags);
|
||||
#elif defined(BOOST_UUID_RANDOM_PROVIDER_GETRANDOM_HAS_LIBC_WRAPPER)
|
||||
return ::getrandom(buf, size, flags);
|
||||
#else
|
||||
return ::syscall(SYS_getrandom, buf, size, flags);
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
||||
} // detail
|
||||
} // uuids
|
||||
} // boost
|
||||
@@ -0,0 +1,29 @@
|
||||
//
|
||||
// Copyright (c) 2017 James E. King III
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// https://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// Platform-specific random entropy provider platform definition
|
||||
//
|
||||
|
||||
#ifndef BOOST_UUID_DETAIL_RANDOM_PROVIDER_PLATFORM_INCLUDE_HPP
|
||||
#define BOOST_UUID_DETAIL_RANDOM_PROVIDER_PLATFORM_INCLUDE_HPP
|
||||
|
||||
#if defined(BOOST_UUID_RANDOM_PROVIDER_ARC4RANDOM)
|
||||
# include <boost/uuid/detail/random_provider_arc4random.ipp>
|
||||
#elif defined(BOOST_UUID_RANDOM_PROVIDER_BCRYPT)
|
||||
# include <boost/uuid/detail/random_provider_bcrypt.ipp>
|
||||
#elif defined(BOOST_UUID_RANDOM_PROVIDER_GETENTROPY)
|
||||
# include <boost/uuid/detail/random_provider_getentropy.ipp>
|
||||
#elif defined(BOOST_UUID_RANDOM_PROVIDER_GETRANDOM)
|
||||
# include <boost/uuid/detail/random_provider_getrandom.ipp>
|
||||
#elif defined(BOOST_UUID_RANDOM_PROVIDER_POSIX)
|
||||
# include <boost/uuid/detail/random_provider_posix.ipp>
|
||||
#elif defined(BOOST_UUID_RANDOM_PROVIDER_WINCRYPT)
|
||||
# include <boost/uuid/detail/random_provider_wincrypt.ipp>
|
||||
#endif
|
||||
|
||||
#endif // BOOST_UUID_DETAIL_RANDOM_PROVIDER_PLATFORM_INCLUDE_HPP
|
||||
|
||||
@@ -0,0 +1,120 @@
|
||||
/* boost uuid/detail/random_provider_posix implementation
|
||||
*
|
||||
* Copyright Jens Maurer 2000
|
||||
* Copyright 2007 Andy Tompkins.
|
||||
* Copyright Steven Watanabe 2010-2011
|
||||
* Copyright 2017 James E. King III
|
||||
*
|
||||
* Distributed under the Boost Software License, Version 1.0. (See
|
||||
* accompanying file LICENSE_1_0.txt or copy at
|
||||
* https://www.boost.org/LICENSE_1_0.txt)
|
||||
*
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/core/ignore_unused.hpp>
|
||||
#include <boost/move/core.hpp>
|
||||
#include <boost/throw_exception.hpp>
|
||||
#include <boost/uuid/entropy_error.hpp>
|
||||
#include <cerrno>
|
||||
#include <cstddef>
|
||||
#include <fcntl.h> // open
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#if defined(BOOST_HAS_UNISTD_H)
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#ifndef BOOST_UUID_RANDOM_PROVIDER_POSIX_IMPL_CLOSE
|
||||
#define BOOST_UUID_RANDOM_PROVIDER_POSIX_IMPL_CLOSE ::close
|
||||
#endif
|
||||
#ifndef BOOST_UUID_RANDOM_PROVIDER_POSIX_IMPL_OPEN
|
||||
#define BOOST_UUID_RANDOM_PROVIDER_POSIX_IMPL_OPEN ::open
|
||||
#endif
|
||||
#ifndef BOOST_UUID_RANDOM_PROVIDER_POSIX_IMPL_READ
|
||||
#define BOOST_UUID_RANDOM_PROVIDER_POSIX_IMPL_READ ::read
|
||||
#endif
|
||||
|
||||
namespace boost {
|
||||
namespace uuids {
|
||||
namespace detail {
|
||||
|
||||
class random_provider_base
|
||||
{
|
||||
BOOST_MOVABLE_BUT_NOT_COPYABLE(random_provider_base)
|
||||
|
||||
public:
|
||||
random_provider_base()
|
||||
: fd_(-1)
|
||||
{
|
||||
int flags = O_RDONLY;
|
||||
#if defined(O_CLOEXEC)
|
||||
flags |= O_CLOEXEC;
|
||||
#endif
|
||||
fd_ = BOOST_UUID_RANDOM_PROVIDER_POSIX_IMPL_OPEN("/dev/urandom", flags);
|
||||
|
||||
if (BOOST_UNLIKELY(-1 == fd_))
|
||||
{
|
||||
int err = errno;
|
||||
BOOST_THROW_EXCEPTION(entropy_error(err, "open /dev/urandom"));
|
||||
}
|
||||
}
|
||||
|
||||
random_provider_base(BOOST_RV_REF(random_provider_base) that) BOOST_NOEXCEPT : fd_(that.fd_)
|
||||
{
|
||||
that.fd_ = -1;
|
||||
}
|
||||
|
||||
random_provider_base& operator= (BOOST_RV_REF(random_provider_base) that) BOOST_NOEXCEPT
|
||||
{
|
||||
destroy();
|
||||
fd_ = that.fd_;
|
||||
that.fd_ = -1;
|
||||
return *this;
|
||||
}
|
||||
|
||||
~random_provider_base() BOOST_NOEXCEPT
|
||||
{
|
||||
destroy();
|
||||
}
|
||||
|
||||
//! Obtain entropy and place it into a memory location
|
||||
//! \param[in] buf the location to write entropy
|
||||
//! \param[in] siz the number of bytes to acquire
|
||||
void get_random_bytes(void *buf, std::size_t siz)
|
||||
{
|
||||
std::size_t offset = 0;
|
||||
while (offset < siz)
|
||||
{
|
||||
ssize_t sz = BOOST_UUID_RANDOM_PROVIDER_POSIX_IMPL_READ(
|
||||
fd_, static_cast<char *>(buf) + offset, siz - offset);
|
||||
|
||||
if (BOOST_UNLIKELY(sz < 0))
|
||||
{
|
||||
int err = errno;
|
||||
if (err == EINTR)
|
||||
continue;
|
||||
BOOST_THROW_EXCEPTION(entropy_error(err, "read"));
|
||||
}
|
||||
|
||||
offset += sz;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
void destroy() BOOST_NOEXCEPT
|
||||
{
|
||||
if (fd_ >= 0)
|
||||
{
|
||||
boost::ignore_unused(BOOST_UUID_RANDOM_PROVIDER_POSIX_IMPL_CLOSE(fd_));
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
int fd_;
|
||||
};
|
||||
|
||||
} // detail
|
||||
} // uuids
|
||||
} // boost
|
||||
@@ -0,0 +1,113 @@
|
||||
/* boost uuid/detail/random_provider_wincrypt implementation
|
||||
*
|
||||
* Copyright Jens Maurer 2000
|
||||
* Copyright 2007 Andy Tompkins.
|
||||
* Copyright Steven Watanabe 2010-2011
|
||||
* Copyright 2017 James E. King III
|
||||
*
|
||||
* Distributed under the Boost Software License, Version 1.0. (See
|
||||
* accompanying file LICENSE_1_0.txt or copy at
|
||||
* https://www.boost.org/LICENSE_1_0.txt)
|
||||
*
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
#include <cstddef>
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/core/ignore_unused.hpp>
|
||||
#include <boost/move/core.hpp>
|
||||
#include <boost/numeric/conversion/cast.hpp>
|
||||
#include <boost/winapi/crypt.hpp>
|
||||
#include <boost/winapi/get_last_error.hpp>
|
||||
#include <boost/throw_exception.hpp>
|
||||
|
||||
#if defined(BOOST_UUID_FORCE_AUTO_LINK) || (!defined(BOOST_ALL_NO_LIB) && !defined(BOOST_UUID_RANDOM_PROVIDER_NO_LIB))
|
||||
# if defined(_WIN32_WCE)
|
||||
# define BOOST_LIB_NAME "coredll"
|
||||
# else
|
||||
# define BOOST_LIB_NAME "advapi32"
|
||||
# endif
|
||||
# if defined(BOOST_AUTO_LINK_NOMANGLE)
|
||||
# include <boost/config/auto_link.hpp>
|
||||
# else
|
||||
# define BOOST_AUTO_LINK_NOMANGLE
|
||||
# include <boost/config/auto_link.hpp>
|
||||
# undef BOOST_AUTO_LINK_NOMANGLE
|
||||
# endif
|
||||
#endif
|
||||
|
||||
namespace boost {
|
||||
namespace uuids {
|
||||
namespace detail {
|
||||
|
||||
class random_provider_base
|
||||
{
|
||||
BOOST_MOVABLE_BUT_NOT_COPYABLE(random_provider_base)
|
||||
|
||||
public:
|
||||
random_provider_base()
|
||||
: hProv_(0)
|
||||
{
|
||||
boost::winapi::BOOL_ res = boost::winapi::CryptAcquireContextW(
|
||||
&hProv_,
|
||||
NULL,
|
||||
NULL,
|
||||
boost::winapi::PROV_RSA_FULL_,
|
||||
boost::winapi::CRYPT_VERIFYCONTEXT_ | boost::winapi::CRYPT_SILENT_);
|
||||
if (BOOST_UNLIKELY(!res))
|
||||
{
|
||||
boost::winapi::DWORD_ err = boost::winapi::GetLastError();
|
||||
BOOST_THROW_EXCEPTION(entropy_error(err, "CryptAcquireContext"));
|
||||
}
|
||||
}
|
||||
|
||||
random_provider_base(BOOST_RV_REF(random_provider_base) that) BOOST_NOEXCEPT : hProv_(that.hProv_)
|
||||
{
|
||||
that.hProv_ = 0;
|
||||
}
|
||||
|
||||
random_provider_base& operator= (BOOST_RV_REF(random_provider_base) that) BOOST_NOEXCEPT
|
||||
{
|
||||
destroy();
|
||||
hProv_ = that.hProv_;
|
||||
that.hProv_ = 0;
|
||||
return *this;
|
||||
}
|
||||
|
||||
~random_provider_base() BOOST_NOEXCEPT
|
||||
{
|
||||
destroy();
|
||||
}
|
||||
|
||||
//! Obtain entropy and place it into a memory location
|
||||
//! \param[in] buf the location to write entropy
|
||||
//! \param[in] siz the number of bytes to acquire
|
||||
void get_random_bytes(void *buf, std::size_t siz)
|
||||
{
|
||||
boost::winapi::BOOL_ res = boost::winapi::CryptGenRandom(
|
||||
hProv_,
|
||||
boost::numeric_cast<boost::winapi::DWORD_>(siz),
|
||||
static_cast<boost::winapi::BYTE_ *>(buf));
|
||||
if (BOOST_UNLIKELY(!res))
|
||||
{
|
||||
boost::winapi::DWORD_ err = boost::winapi::GetLastError();
|
||||
BOOST_THROW_EXCEPTION(entropy_error(err, "CryptGenRandom"));
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
void destroy() BOOST_NOEXCEPT
|
||||
{
|
||||
if (hProv_)
|
||||
{
|
||||
boost::ignore_unused(boost::winapi::CryptReleaseContext(hProv_, 0));
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
boost::winapi::HCRYPTPROV_ hProv_;
|
||||
};
|
||||
|
||||
} // detail
|
||||
} // uuids
|
||||
} // boost
|
||||
237
install/boost_1_75_0/include/boost/uuid/detail/sha1.hpp
Normal file
237
install/boost_1_75_0/include/boost/uuid/detail/sha1.hpp
Normal file
@@ -0,0 +1,237 @@
|
||||
// Copyright 2007 Andy Tompkins.
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
// https://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// Revision History
|
||||
// 29 May 2007 - Initial Revision
|
||||
// 25 Feb 2008 - moved to namespace boost::uuids::detail
|
||||
// 10 Jan 2012 - can now handle the full size of messages (2^64 - 1 bits)
|
||||
|
||||
// This is a byte oriented implementation
|
||||
|
||||
#ifndef BOOST_UUID_SHA1_H
|
||||
#define BOOST_UUID_SHA1_H
|
||||
|
||||
#include <boost/static_assert.hpp>
|
||||
#include <boost/throw_exception.hpp>
|
||||
#include <boost/uuid/uuid.hpp> // for version
|
||||
#include <cstddef>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
||||
#ifdef BOOST_NO_STDC_NAMESPACE
|
||||
namespace std {
|
||||
using ::size_t;
|
||||
} // namespace std
|
||||
#endif
|
||||
|
||||
namespace boost {
|
||||
namespace uuids {
|
||||
namespace detail {
|
||||
|
||||
BOOST_STATIC_ASSERT(sizeof(unsigned char)*8 == 8);
|
||||
BOOST_STATIC_ASSERT(sizeof(unsigned int)*8 == 32);
|
||||
|
||||
inline unsigned int left_rotate(unsigned int x, std::size_t n)
|
||||
{
|
||||
return (x<<n) ^ (x>> (32-n));
|
||||
}
|
||||
|
||||
class sha1
|
||||
{
|
||||
public:
|
||||
typedef unsigned int(digest_type)[5];
|
||||
public:
|
||||
sha1();
|
||||
|
||||
void reset();
|
||||
|
||||
void process_byte(unsigned char byte);
|
||||
void process_block(void const* bytes_begin, void const* bytes_end);
|
||||
void process_bytes(void const* buffer, std::size_t byte_count);
|
||||
|
||||
void get_digest(digest_type& digest);
|
||||
unsigned char get_version() const;
|
||||
|
||||
private:
|
||||
void process_block();
|
||||
void process_byte_impl(unsigned char byte);
|
||||
|
||||
private:
|
||||
unsigned int h_[5];
|
||||
|
||||
unsigned char block_[64];
|
||||
|
||||
std::size_t block_byte_index_;
|
||||
std::size_t bit_count_low;
|
||||
std::size_t bit_count_high;
|
||||
};
|
||||
|
||||
inline sha1::sha1()
|
||||
{
|
||||
reset();
|
||||
}
|
||||
|
||||
inline void sha1::reset()
|
||||
{
|
||||
h_[0] = 0x67452301;
|
||||
h_[1] = 0xEFCDAB89;
|
||||
h_[2] = 0x98BADCFE;
|
||||
h_[3] = 0x10325476;
|
||||
h_[4] = 0xC3D2E1F0;
|
||||
|
||||
block_byte_index_ = 0;
|
||||
bit_count_low = 0;
|
||||
bit_count_high = 0;
|
||||
}
|
||||
|
||||
inline void sha1::process_byte(unsigned char byte)
|
||||
{
|
||||
process_byte_impl(byte);
|
||||
|
||||
// size_t max value = 0xFFFFFFFF
|
||||
//if (bit_count_low + 8 >= 0x100000000) { // would overflow
|
||||
//if (bit_count_low >= 0x100000000-8) {
|
||||
if (bit_count_low < 0xFFFFFFF8) {
|
||||
bit_count_low += 8;
|
||||
} else {
|
||||
bit_count_low = 0;
|
||||
|
||||
if (bit_count_high <= 0xFFFFFFFE) {
|
||||
++bit_count_high;
|
||||
} else {
|
||||
BOOST_THROW_EXCEPTION(std::runtime_error("sha1 too many bytes"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline void sha1::process_byte_impl(unsigned char byte)
|
||||
{
|
||||
block_[block_byte_index_++] = byte;
|
||||
|
||||
if (block_byte_index_ == 64) {
|
||||
block_byte_index_ = 0;
|
||||
process_block();
|
||||
}
|
||||
}
|
||||
|
||||
inline void sha1::process_block(void const* bytes_begin, void const* bytes_end)
|
||||
{
|
||||
unsigned char const* begin = static_cast<unsigned char const*>(bytes_begin);
|
||||
unsigned char const* end = static_cast<unsigned char const*>(bytes_end);
|
||||
for(; begin != end; ++begin) {
|
||||
process_byte(*begin);
|
||||
}
|
||||
}
|
||||
|
||||
inline void sha1::process_bytes(void const* buffer, std::size_t byte_count)
|
||||
{
|
||||
unsigned char const* b = static_cast<unsigned char const*>(buffer);
|
||||
process_block(b, b+byte_count);
|
||||
}
|
||||
|
||||
inline void sha1::process_block()
|
||||
{
|
||||
unsigned int w[80];
|
||||
for (std::size_t i=0; i<16; ++i) {
|
||||
w[i] = (block_[i*4 + 0] << 24);
|
||||
w[i] |= (block_[i*4 + 1] << 16);
|
||||
w[i] |= (block_[i*4 + 2] << 8);
|
||||
w[i] |= (block_[i*4 + 3]);
|
||||
}
|
||||
for (std::size_t i=16; i<80; ++i) {
|
||||
w[i] = left_rotate((w[i-3] ^ w[i-8] ^ w[i-14] ^ w[i-16]), 1);
|
||||
}
|
||||
|
||||
unsigned int a = h_[0];
|
||||
unsigned int b = h_[1];
|
||||
unsigned int c = h_[2];
|
||||
unsigned int d = h_[3];
|
||||
unsigned int e = h_[4];
|
||||
|
||||
for (std::size_t i=0; i<80; ++i) {
|
||||
unsigned int f;
|
||||
unsigned int k;
|
||||
|
||||
if (i<20) {
|
||||
f = (b & c) | (~b & d);
|
||||
k = 0x5A827999;
|
||||
} else if (i<40) {
|
||||
f = b ^ c ^ d;
|
||||
k = 0x6ED9EBA1;
|
||||
} else if (i<60) {
|
||||
f = (b & c) | (b & d) | (c & d);
|
||||
k = 0x8F1BBCDC;
|
||||
} else {
|
||||
f = b ^ c ^ d;
|
||||
k = 0xCA62C1D6;
|
||||
}
|
||||
|
||||
unsigned temp = left_rotate(a, 5) + f + e + k + w[i];
|
||||
e = d;
|
||||
d = c;
|
||||
c = left_rotate(b, 30);
|
||||
b = a;
|
||||
a = temp;
|
||||
}
|
||||
|
||||
h_[0] += a;
|
||||
h_[1] += b;
|
||||
h_[2] += c;
|
||||
h_[3] += d;
|
||||
h_[4] += e;
|
||||
}
|
||||
|
||||
inline unsigned char sha1::get_version() const
|
||||
{
|
||||
// RFC 4122 Section 4.1.3
|
||||
return uuid::version_name_based_sha1;
|
||||
}
|
||||
|
||||
inline void sha1::get_digest(digest_type& digest)
|
||||
{
|
||||
// append the bit '1' to the message
|
||||
process_byte_impl(0x80);
|
||||
|
||||
// append k bits '0', where k is the minimum number >= 0
|
||||
// such that the resulting message length is congruent to 56 (mod 64)
|
||||
// check if there is enough space for padding and bit_count
|
||||
if (block_byte_index_ > 56) {
|
||||
// finish this block
|
||||
while (block_byte_index_ != 0) {
|
||||
process_byte_impl(0);
|
||||
}
|
||||
|
||||
// one more block
|
||||
while (block_byte_index_ < 56) {
|
||||
process_byte_impl(0);
|
||||
}
|
||||
} else {
|
||||
while (block_byte_index_ < 56) {
|
||||
process_byte_impl(0);
|
||||
}
|
||||
}
|
||||
|
||||
// append length of message (before pre-processing)
|
||||
// as a 64-bit big-endian integer
|
||||
process_byte_impl( static_cast<unsigned char>((bit_count_high>>24) & 0xFF) );
|
||||
process_byte_impl( static_cast<unsigned char>((bit_count_high>>16) & 0xFF) );
|
||||
process_byte_impl( static_cast<unsigned char>((bit_count_high>>8 ) & 0xFF) );
|
||||
process_byte_impl( static_cast<unsigned char>((bit_count_high) & 0xFF) );
|
||||
process_byte_impl( static_cast<unsigned char>((bit_count_low>>24) & 0xFF) );
|
||||
process_byte_impl( static_cast<unsigned char>((bit_count_low>>16) & 0xFF) );
|
||||
process_byte_impl( static_cast<unsigned char>((bit_count_low>>8 ) & 0xFF) );
|
||||
process_byte_impl( static_cast<unsigned char>((bit_count_low) & 0xFF) );
|
||||
|
||||
// get final digest
|
||||
digest[0] = h_[0];
|
||||
digest[1] = h_[1];
|
||||
digest[2] = h_[2];
|
||||
digest[3] = h_[3];
|
||||
digest[4] = h_[4];
|
||||
}
|
||||
|
||||
}}} // namespace boost::uuids::detail
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright Andy Tompkins 2006.
|
||||
* Distributed under the Boost Software License, Version 1.0.
|
||||
* (See accompanying file LICENSE_1_0.txt or copy at
|
||||
* https://www.boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
/*!
|
||||
* \file uuid/detail/uuid_generic.ipp
|
||||
*
|
||||
* \brief This header contains generic implementation of \c boost::uuid operations.
|
||||
*/
|
||||
|
||||
#ifndef BOOST_UUID_DETAIL_UUID_GENERIC_IPP_INCLUDED_
|
||||
#define BOOST_UUID_DETAIL_UUID_GENERIC_IPP_INCLUDED_
|
||||
|
||||
#include <string.h>
|
||||
|
||||
namespace boost {
|
||||
namespace uuids {
|
||||
|
||||
inline bool uuid::is_nil() const BOOST_NOEXCEPT
|
||||
{
|
||||
for (std::size_t i = 0; i < sizeof(data); ++i)
|
||||
{
|
||||
if (data[i] != 0U)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
inline void uuid::swap(uuid& rhs) BOOST_NOEXCEPT
|
||||
{
|
||||
uuid tmp = *this;
|
||||
*this = rhs;
|
||||
rhs = tmp;
|
||||
}
|
||||
|
||||
inline bool operator== (uuid const& lhs, uuid const& rhs) BOOST_NOEXCEPT
|
||||
{
|
||||
return memcmp(lhs.data, rhs.data, sizeof(lhs.data)) == 0;
|
||||
}
|
||||
|
||||
inline bool operator< (uuid const& lhs, uuid const& rhs) BOOST_NOEXCEPT
|
||||
{
|
||||
return memcmp(lhs.data, rhs.data, sizeof(lhs.data)) < 0;
|
||||
}
|
||||
|
||||
} // namespace uuids
|
||||
} // namespace boost
|
||||
|
||||
#endif // BOOST_UUID_DETAIL_UUID_GENERIC_IPP_INCLUDED_
|
||||
135
install/boost_1_75_0/include/boost/uuid/detail/uuid_x86.ipp
Normal file
135
install/boost_1_75_0/include/boost/uuid/detail/uuid_x86.ipp
Normal file
@@ -0,0 +1,135 @@
|
||||
/*
|
||||
* Copyright Andrey Semashev 2013.
|
||||
* Distributed under the Boost Software License, Version 1.0.
|
||||
* (See accompanying file LICENSE_1_0.txt or copy at
|
||||
* https://www.boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
/*!
|
||||
* \file uuid/detail/uuid_x86.ipp
|
||||
*
|
||||
* \brief This header contains optimized SSE implementation of \c boost::uuid operations.
|
||||
*/
|
||||
|
||||
#ifndef BOOST_UUID_DETAIL_UUID_X86_IPP_INCLUDED_
|
||||
#define BOOST_UUID_DETAIL_UUID_X86_IPP_INCLUDED_
|
||||
|
||||
// MSVC does not always have immintrin.h (at least, not up to MSVC 10), so include the appropriate header for each instruction set
|
||||
#if defined(BOOST_UUID_USE_SSE41)
|
||||
#include <smmintrin.h>
|
||||
#elif defined(BOOST_UUID_USE_SSE3)
|
||||
#include <pmmintrin.h>
|
||||
#else
|
||||
#include <emmintrin.h>
|
||||
#endif
|
||||
|
||||
#if defined(BOOST_MSVC) && defined(_M_X64) && !defined(BOOST_UUID_USE_SSE3) && (BOOST_MSVC < 1900 /* Fixed in Visual Studio 2015 */ )
|
||||
// At least MSVC 9 (VS2008) and 12 (VS2013) have an optimizer bug that sometimes results in incorrect SIMD code
|
||||
// generated in Release x64 mode. In particular, it affects operator==, where the compiler sometimes generates
|
||||
// pcmpeqd with a memory opereand instead of movdqu followed by pcmpeqd. The problem is that uuid can be
|
||||
// not aligned to 16 bytes and pcmpeqd causes alignment violation in this case. We cannot be sure that other
|
||||
// MSVC versions are not affected so we apply the workaround for all versions, except VS2015 on up where
|
||||
// the bug has been fixed.
|
||||
//
|
||||
// https://svn.boost.org/trac/boost/ticket/8509#comment:3
|
||||
// https://connect.microsoft.com/VisualStudio/feedbackdetail/view/981648#tabs
|
||||
#define BOOST_UUID_DETAIL_MSVC_BUG981648
|
||||
#if BOOST_MSVC >= 1600
|
||||
extern "C" void _ReadWriteBarrier(void);
|
||||
#pragma intrinsic(_ReadWriteBarrier)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
namespace boost {
|
||||
namespace uuids {
|
||||
namespace detail {
|
||||
|
||||
BOOST_FORCEINLINE __m128i load_unaligned_si128(const uint8_t* p) BOOST_NOEXCEPT
|
||||
{
|
||||
#if defined(BOOST_UUID_USE_SSE3)
|
||||
return _mm_lddqu_si128(reinterpret_cast< const __m128i* >(p));
|
||||
#elif !defined(BOOST_UUID_DETAIL_MSVC_BUG981648)
|
||||
return _mm_loadu_si128(reinterpret_cast< const __m128i* >(p));
|
||||
#elif defined(BOOST_MSVC) && BOOST_MSVC >= 1600
|
||||
__m128i mm = _mm_loadu_si128(reinterpret_cast< const __m128i* >(p));
|
||||
// Make sure this load doesn't get merged with the subsequent instructions
|
||||
_ReadWriteBarrier();
|
||||
return mm;
|
||||
#else
|
||||
// VS2008 x64 doesn't respect _ReadWriteBarrier above, so we have to generate this crippled code to load unaligned data
|
||||
return _mm_unpacklo_epi64(_mm_loadl_epi64(reinterpret_cast< const __m128i* >(p)), _mm_loadl_epi64(reinterpret_cast< const __m128i* >(p + 8)));
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
|
||||
inline bool uuid::is_nil() const BOOST_NOEXCEPT
|
||||
{
|
||||
__m128i mm = uuids::detail::load_unaligned_si128(data);
|
||||
#if defined(BOOST_UUID_USE_SSE41)
|
||||
return _mm_test_all_zeros(mm, mm) != 0;
|
||||
#else
|
||||
mm = _mm_cmpeq_epi32(mm, _mm_setzero_si128());
|
||||
return _mm_movemask_epi8(mm) == 0xFFFF;
|
||||
#endif
|
||||
}
|
||||
|
||||
inline void uuid::swap(uuid& rhs) BOOST_NOEXCEPT
|
||||
{
|
||||
__m128i mm_this = uuids::detail::load_unaligned_si128(data);
|
||||
__m128i mm_rhs = uuids::detail::load_unaligned_si128(rhs.data);
|
||||
_mm_storeu_si128(reinterpret_cast< __m128i* >(rhs.data), mm_this);
|
||||
_mm_storeu_si128(reinterpret_cast< __m128i* >(data), mm_rhs);
|
||||
}
|
||||
|
||||
inline bool operator== (uuid const& lhs, uuid const& rhs) BOOST_NOEXCEPT
|
||||
{
|
||||
__m128i mm_left = uuids::detail::load_unaligned_si128(lhs.data);
|
||||
__m128i mm_right = uuids::detail::load_unaligned_si128(rhs.data);
|
||||
|
||||
#if defined(BOOST_UUID_USE_SSE41)
|
||||
__m128i mm = _mm_xor_si128(mm_left, mm_right);
|
||||
return _mm_test_all_zeros(mm, mm) != 0;
|
||||
#else
|
||||
__m128i mm_cmp = _mm_cmpeq_epi32(mm_left, mm_right);
|
||||
return _mm_movemask_epi8(mm_cmp) == 0xFFFF;
|
||||
#endif
|
||||
}
|
||||
|
||||
inline bool operator< (uuid const& lhs, uuid const& rhs) BOOST_NOEXCEPT
|
||||
{
|
||||
__m128i mm_left = uuids::detail::load_unaligned_si128(lhs.data);
|
||||
__m128i mm_right = uuids::detail::load_unaligned_si128(rhs.data);
|
||||
|
||||
// To emulate lexicographical_compare behavior we have to perform two comparisons - the forward and reverse one.
|
||||
// Then we know which bytes are equivalent and which ones are different, and for those different the comparison results
|
||||
// will be opposite. Then we'll be able to find the first differing comparison result (for both forward and reverse ways),
|
||||
// and depending on which way it is for, this will be the result of the operation. There are a few notes to consider:
|
||||
//
|
||||
// 1. Due to little endian byte order the first bytes go into the lower part of the xmm registers,
|
||||
// so the comparison results in the least significant bits will actually be the most signigicant for the final operation result.
|
||||
// This means we have to determine which of the comparison results have the least significant bit on, and this is achieved with
|
||||
// the "(x - 1) ^ x" trick.
|
||||
// 2. Because there is only signed comparison in SSE/AVX, we have to invert byte comparison results whenever signs of the corresponding
|
||||
// bytes are different. I.e. in signed comparison it's -1 < 1, but in unsigned it is the opposite (255 > 1). To do that we XOR left and right,
|
||||
// making the most significant bit of each byte 1 if the signs are different, and later apply this mask with another XOR to the comparison results.
|
||||
// 3. pcmpgtw compares for "greater" relation, so we swap the arguments to get what we need.
|
||||
|
||||
const __m128i mm_signs_mask = _mm_xor_si128(mm_left, mm_right);
|
||||
|
||||
__m128i mm_cmp = _mm_cmpgt_epi8(mm_right, mm_left), mm_rcmp = _mm_cmpgt_epi8(mm_left, mm_right);
|
||||
|
||||
mm_cmp = _mm_xor_si128(mm_signs_mask, mm_cmp);
|
||||
mm_rcmp = _mm_xor_si128(mm_signs_mask, mm_rcmp);
|
||||
|
||||
uint32_t cmp = static_cast< uint32_t >(_mm_movemask_epi8(mm_cmp)), rcmp = static_cast< uint32_t >(_mm_movemask_epi8(mm_rcmp));
|
||||
|
||||
cmp = (cmp - 1u) ^ cmp;
|
||||
rcmp = (rcmp - 1u) ^ rcmp;
|
||||
|
||||
return cmp < rcmp;
|
||||
}
|
||||
|
||||
} // namespace uuids
|
||||
} // namespace boost
|
||||
|
||||
#endif // BOOST_UUID_DETAIL_UUID_X86_IPP_INCLUDED_
|
||||
Reference in New Issue
Block a user