"wrappers/vscode:/vscode.git/clone" did not exist on "8a01b345bfd5d056fe1f3a117fda1fb2e86252e8"
Commit 46b35a36 authored by Robert McGibbon's avatar Robert McGibbon
Browse files

separate files

parent 4b1c362c
......@@ -40,7 +40,7 @@
#include <string>
#include <vector>
#include "internal/windowsExport.h"
#include "internal/osrngseed.h"
#include "internal/OSRngSeed.h"
namespace OpenMM {
......
......@@ -33,15 +33,7 @@
* USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */
#include <stdexcept>
#if defined(_WIN32) || defined(__CYGWIN__)
#include <windows.h>
static HCRYPTPROV hCryptProv = 0;
#pragma comment(lib, "advapi32.lib")
#else
#include <fcntl.h>
#include <unistd.h>
#endif
/**
* Return an integer int for use as a seed for a random number generator.
......@@ -50,30 +42,6 @@ static HCRYPTPROV hCryptProv = 0;
* this uses CryptGenRandom from the CryptoAPI to get a single int. On other
* platforms (*nix, apple), we read from /dev/urandom
*/
int osrngseed(void) {
int value;
#if defined(_WIN32) || defined(__CYGWIN__)
if (!::CryptAcquireContextW(&hCryptProv, 0, 0, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT | CRYPT_SILENT)) {
throw std::runtime_error("Failed to initialize Windows random API (CryptoGen)");
}
if (!CryptGenRandom(hCryptProv, sizeof(int), (BYTE*) &value)) {
::CryptReleaseContext(hCryptProv, 0);
throw std::runtime_error("Failed to get random numbers");
}
if (!::CryptReleaseContext(hCryptProv, 0)) {
throw std::runtime_error("Failed to release Windows random API context");
}
#else
int m_fd = open("/dev/urandom", O_RDONLY);
if (m_fd == -1) {
throw std::runtime_error("Failed to open /dev/urandom");
}
if (read(m_fd, &value, sizeof(int)) != sizeof(int)) {
throw std::runtime_error("Failed to read bytes from /dev/urandom");
}
close(m_fd);
#endif
return value;
}
int osrngseed(void);
#endif /* OPENMM_OSRNGSEED_H_ */
\ No newline at end of file
......@@ -31,7 +31,7 @@
#include "openmm/AndersenThermostat.h"
#include "openmm/internal/AndersenThermostatImpl.h"
#include "openmm/internal/osrngseed.h"
#include "openmm/internal/OSRngSeed.h"
using namespace OpenMM;
......
......@@ -33,7 +33,7 @@
#include "openmm/Context.h"
#include "openmm/OpenMMException.h"
#include "openmm/internal/ContextImpl.h"
#include "openmm/internal/osrngseed.h"
#include "openmm/internal/OSRngSeed.h"
#include "openmm/kernels.h"
#include <string>
......
......@@ -34,7 +34,7 @@
#include "openmm/OpenMMException.h"
#include "openmm/internal/AssertionUtilities.h"
#include "openmm/internal/ContextImpl.h"
#include "openmm/internal/osrngseed.h"
#include "openmm/internal/OSRngSeed.h"
#include "openmm/kernels.h"
#include <string>
......
......@@ -33,7 +33,7 @@
#include "openmm/Context.h"
#include "openmm/OpenMMException.h"
#include "openmm/internal/ContextImpl.h"
#include "openmm/internal/osrngseed.h"
#include "openmm/internal/OSRngSeed.h"
#include "openmm/kernels.h"
#include <string>
......
......@@ -31,7 +31,7 @@
#include "openmm/MonteCarloAnisotropicBarostat.h"
#include "openmm/internal/MonteCarloAnisotropicBarostatImpl.h"
#include "openmm/internal/osrngseed.h"
#include "openmm/internal/OSRngSeed.h"
using namespace OpenMM;
......
......@@ -31,7 +31,7 @@
#include "openmm/MonteCarloBarostat.h"
#include "openmm/internal/MonteCarloBarostatImpl.h"
#include "openmm/internal/osrngseed.h"
#include "openmm/internal/OSRngSeed.h"
using namespace OpenMM;
......
/* -------------------------------------------------------------------------- *
* OpenMM *
* -------------------------------------------------------------------------- *
* This is part of the OpenMM molecular simulation toolkit originating from *
* Simbios, the NIH National Center for Physics-Based Simulation of *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2013 Stanford University and the Authors. *
* Authors: Robert T. McGibbon *
* Contributors: *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *
* THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
* USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */
#include <stdexcept>
#if defined(_WIN32) || defined(__CYGWIN__)
#include <windows.h>
static HCRYPTPROV hCryptProv = 0;
#pragma comment(lib, "advapi32.lib")
#else
#include <fcntl.h>
#include <unistd.h>
#endif
#include "internal/OSRngSeed.h"
int osrngseed(void) {
int value;
#if defined(_WIN32) || defined(__CYGWIN__)
if (!::CryptAcquireContextW(&hCryptProv, 0, 0, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT | CRYPT_SILENT)) {
throw std::runtime_error("Failed to initialize Windows random API (CryptoGen)");
}
if (!CryptGenRandom(hCryptProv, sizeof(int), (BYTE*) &value)) {
::CryptReleaseContext(hCryptProv, 0);
throw std::runtime_error("Failed to get random numbers");
}
if (!::CryptReleaseContext(hCryptProv, 0)) {
throw std::runtime_error("Failed to release Windows random API context");
}
#else
int m_fd = open("/dev/urandom", O_RDONLY);
if (m_fd == -1) {
throw std::runtime_error("Failed to open /dev/urandom");
}
if (read(m_fd, &value, sizeof(int)) != sizeof(int)) {
throw std::runtime_error("Failed to read bytes from /dev/urandom");
}
close(m_fd);
#endif
return value;
}
\ No newline at end of file
......@@ -33,7 +33,7 @@
#include "openmm/Context.h"
#include "openmm/OpenMMException.h"
#include "openmm/internal/ContextImpl.h"
#include "openmm/internal/osrngseed.h"
#include "openmm/internal/OSRngSeed.h"
#include "openmm/kernels.h"
#include <limits>
#include <string>
......
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