Commit 84ecd429 authored by Ondrej Mosnáček's avatar Ondrej Mosnáček

Initial commit

parents
# Compiled Object files
*.slo
*.lo
*.o
*.obj
# Precompiled Headers
*.gch
*.pch
# Compiled Dynamic libraries
*.so
*.dylib
*.dll
# Fortran module files
*.mod
*.smod
# Compiled Static libraries
*.lai
*.la
*.a
*.lib
# Executables
*.exe
*.out
*.app
# CMake
CMakeFiles/
*.cmake
CMakeCache.txt
Makefile
# Qt Creator
*.user
cmake_minimum_required(VERSION 2.6)
project(argon2-gpu CXX)
set(BINARY_INSTALL_DIR /usr/local/bin)
set(LIBRARY_INSTALL_DIR /usr/local/lib)
set(INCLUDE_INSTALL_DIR /usr/local/include)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(CUDA REQUIRED)
add_library(argon2-gpu-common SHARED
lib/argon2-gpu-common/argon2params.cpp
lib/argon2-gpu-common/blake2b.cpp
)
target_include_directories(argon2-gpu-common INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
target_include_directories(argon2-gpu-common PRIVATE
include/argon2-gpu-common
lib/argon2-gpu-common
)
cuda_add_library(argon2-cuda SHARED
lib/argon2-cuda/device.cpp
lib/argon2-cuda/globalcontext.cpp
lib/argon2-cuda/programcontext.cpp
lib/argon2-cuda/processingunit.cpp
lib/argon2-cuda/kernels.cu
)
target_include_directories(argon2-cuda INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
target_include_directories(argon2-cuda PRIVATE
include/argon2-cuda
lib/argon2-cuda
)
target_link_libraries(argon2-cuda argon2-gpu-common)
add_library(argon2-opencl SHARED
lib/argon2-opencl/device.cpp
lib/argon2-opencl/globalcontext.cpp
lib/argon2-opencl/kernelloader.cpp
lib/argon2-opencl/programcontext.cpp
lib/argon2-opencl/processingunit.cpp
)
target_include_directories(argon2-opencl INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
target_include_directories(argon2-opencl PRIVATE
include/argon2-opencl
lib/argon2-opencl
)
target_link_libraries(argon2-opencl
argon2-gpu-common -lOpenCL
)
add_executable(argon2-gpu-test src/argon2-gpu-test/main.cpp)
target_include_directories(argon2-gpu-test PRIVATE src/argon2-gpu-test)
target_link_libraries(argon2-gpu-test
argon2-cuda argon2-opencl -lOpenCL
)
add_executable(argon2-gpu-bench
src/argon2-gpu-bench/cudaexecutive.cpp
src/argon2-gpu-bench/openclexecutive.cpp
src/argon2-gpu-bench/benchmark.cpp
src/argon2-gpu-bench/main.cpp
)
target_include_directories(argon2-gpu-bench PRIVATE src/argon2-gpu-bench)
target_link_libraries(argon2-gpu-bench
argon2-cuda argon2-opencl -lOpenCL
)
add_test(test argon2-gpu-test)
install(TARGETS argon2-opencl DESTINATION ${LIBRARY_INSTALL_DIR})
install(FILES
include/argon2-opencl/cl.hpp
include/argon2-opencl/opencl.h
include/argon2-opencl/argon2-common.h
include/argon2-opencl/argon2params.h
include/argon2-opencl/device.h
include/argon2-opencl/globalcontext.h
include/argon2-opencl/programcontext.h
include/argon2-opencl/processingunit.h
DESTINATION ${INCLUDE_INSTALL_DIR}
)
install(TARGETS argon2-gpu-bench argon2-gpu-test DESTINATION ${BINARY_INSTALL_DIR})
MIT License
Copyright (c) 2016 Ondrej Mosnáček
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 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.
../argon2-gpu-v2/data
\ No newline at end of file
This diff is collapsed.
#ifndef ARGON2_CUDA_CUDAEXCEPTION_H
#define ARGON2_CUDA_CUDAEXCEPTION_H
#include <cuda_runtime.h>
#include <exception>
namespace argon2 {
namespace cuda {
class CudaException : public std::exception {
private:
cudaError_t res;
public:
CudaException(cudaError_t res) : res(res) { }
const char *what() const noexcept override
{
return cudaGetErrorString(res);
}
static void check(cudaError_t res)
{
if (res != cudaSuccess) {
throw CudaException(res);
}
}
};
} // namespace cuda
} // namespace argon2
#endif // ARGON2_CUDA_CUDAEXCEPTION_H
/*
* Copyright (C) 2015, Ondrej Mosnacek <omosnacek@gmail.com>
*
* This program is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation: either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ARGON2_CUDA_DEVICE_H
#define ARGON2_CUDA_DEVICE_H
#include <cuda_runtime.h>
#include <string>
namespace argon2 {
namespace cuda {
class Device
{
private:
int deviceIndex;
public:
std::string getName() const;
std::string getInfo() const;
int getDeviceIndex() const { return deviceIndex; }
/**
* @brief Empty constructor.
* NOTE: Calling methods other than the destructor on an instance initialized
* with empty constructor results in undefined behavior.
*/
Device() { }
Device(int deviceIndex) : deviceIndex(deviceIndex)
{
}
Device(const Device &) = default;
Device(Device &&) = default;
Device &operator=(const Device &) = default;
};
} // namespace cuda
} // namespace argon2
#endif // ARGON2_CUDA_DEVICE_H
/*
* Copyright (C) 2015, Ondrej Mosnacek <omosnacek@gmail.com>
*
* This program is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation: either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ARGON2_CUDA_GLOBALCONTEXT_H
#define ARGON2_CUDA_GLOBALCONTEXT_H
#include "device.h"
#include <string>
#include <vector>
namespace argon2 {
namespace cuda {
class GlobalContext
{
private:
std::vector<Device> devices;
public:
const std::vector<Device> &getAllDevices() const { return devices; }
GlobalContext();
};
} // namespace cuda
} // namespace argon2
#endif // ARGON2_CUDA_GLOBALCONTEXT_H
#ifndef ARGON2_CUDA_PROCESSINGUNIT_H
#define ARGON2_CUDA_PROCESSINGUNIT_H
#include <memory>
#include "programcontext.h"
#include "argon2-gpu-common/argon2params.h"
namespace argon2 {
namespace cuda {
class ProcessingUnit
{
private:
const ProgramContext *programContext;
const Argon2Params *params;
const Device *device;
std::size_t batchSize;
std::size_t memorySize;
bool bySegment;
cudaStream_t stream;
void *memoryBuffer;
public:
class PasswordWriter
{
private:
const Argon2Params *params;
Type type;
Version version;
std::uint8_t *dest;
public:
PasswordWriter(ProcessingUnit &parent, std::size_t index = 0);
void moveForward(std::size_t offset);
void moveBackwards(std::size_t offset);
void setPassword(const void *pw, std::size_t pwSize) const;
};
class HashReader
{
private:
const Argon2Params *params;
const std::uint8_t *src;
std::unique_ptr<uint8_t[]> buffer;
public:
HashReader(ProcessingUnit &parent, std::size_t index = 0);
void moveForward(std::size_t offset);
void moveBackwards(std::size_t offset);
const void *getHash() const;
};
std::size_t getBatchSize() const { return batchSize; }
ProcessingUnit(
const ProgramContext *programContext, const Argon2Params *params,
const Device *device, std::size_t batchSize,
bool bySegment = true);
~ProcessingUnit();
void beginProcessing();
void endProcessing();
};
} // namespace cuda
} // namespace argon2
#endif // ARGON2_CUDA_PROCESSINGUNIT_H
#ifndef ARGON2_CUDA_PROGRAMCONTEXT_H
#define ARGON2_CUDA_PROGRAMCONTEXT_H
#include "globalcontext.h"
#include "argon2-gpu-common/argon2-common.h"
namespace argon2 {
namespace cuda {
class ProgramContext
{
private:
const GlobalContext *globalContext;
Type type;
Version version;
public:
const GlobalContext *getGlobalContext() const { return globalContext; }
Type getArgon2Type() const { return type; }
Version getArgon2Version() const { return version; }
ProgramContext(
const GlobalContext *globalContext,
const std::vector<Device> &devices,
Type type, Version version);
};
} // namespace cuda
} // namespace argon2
#endif // ARGON2_CUDA_PROGRAMCONTEXT_H
#ifndef ARGON2COMMON_H
#define ARGON2COMMON_H
namespace argon2 {
enum {
ARGON2_BLOCK_SIZE = 1024,
ARGON2_SYNC_POINTS = 4,
ARGON2_PREHASH_DIGEST_LENGTH = 64,
ARGON2_PREHASH_SEED_LENGTH = 72,
};
enum Type {
ARGON2_D = 0,
ARGON2_I = 1,
};
enum Version {
ARGON2_VERSION_10 = 0x10,
ARGON2_VERSION_13 = 0x13,
};
} // namespace argon2
#endif // ARGON2COMMON_H
#ifndef ARGON2_ARGON2PARAMS_H
#define ARGON2_ARGON2PARAMS_H
#include <cstdint>
#include "argon2-common.h"
namespace argon2 {
class Argon2Params
{
private:
const void *salt, *secret, *ad;
std::uint32_t outLen, saltLen, secretLen, adLen;
std::uint32_t t_cost, m_cost, lanes;
std::uint32_t segmentBlocks;
static void digestLong(void *out, std::size_t outLen,
const void *in, std::size_t inLen);
void initialHash(void *out, const void *pwd, std::size_t pwdLen,
Type type, Version version) const;
public:
std::uint32_t getOutputLength() const { return outLen; }
const void *getSalt() const { return salt; }
std::uint32_t getSaltLength() const { return saltLen; }
const void *getSecret() const { return secret; }
std::uint32_t getSecretLength() const { return secretLen; }
const void *getAssocData() const { return ad; }
std::uint32_t getAssocDataLength() const { return adLen; }
std::uint32_t getTimeCost() const { return t_cost; }
std::uint32_t getMemoryCost() const { return m_cost; }
std::uint32_t getLanes() const { return lanes; }
std::uint32_t getSegmentBlocks() const { return segmentBlocks; }
std::uint32_t getLaneBlocks() const {
return segmentBlocks * ARGON2_SYNC_POINTS;
}
std::uint32_t getMemoryBlocks() const { return getLaneBlocks() * lanes; }
std::size_t getMemorySize() const {
return static_cast<std::size_t>(getMemoryBlocks()) * ARGON2_BLOCK_SIZE;
}
Argon2Params(
std::size_t outLen,
const void *salt, std::size_t saltLen,
const void *secret, std::size_t secretLen,
const void *ad, std::size_t adLen,
std::size_t t_cost, std::size_t m_cost, std::size_t lanes);
void fillFirstBlocks(void *memory, const void *pwd, std::size_t pwdLen,
Type type, Version version) const;
void finalize(void *out, const void *memory) const;
};
} // namespace argon2
#endif // ARGON2_ARGON2PARAMS_H
This diff is collapsed.
/*
* Copyright (C) 2015, Ondrej Mosnacek <omosnacek@gmail.com>
*
* This program is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation: either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ARGON2_OPENCL_DEVICE_H
#define ARGON2_OPENCL_DEVICE_H
#include "opencl.h"
namespace argon2 {
namespace opencl {
class Device
{
private:
cl::Device device;
public:
std::string getName() const;
std::string getInfo() const;
const cl::Device &getCLDevice() const { return device; }
/**
* @brief Empty constructor.
* NOTE: Calling methods other than the destructor on an instance initialized
* with empty constructor results in undefined behavior.
*/
Device() { }
Device(const cl::Device &device)
: device(device)
{
}
Device(const Device &) = default;
Device(Device &&) = default;
Device &operator=(const Device &) = default;
};
} // namespace opencl
} // namespace argon2
#endif // ARGON2_OPENCL_DEVICE_H
/*
* Copyright (C) 2015, Ondrej Mosnacek <omosnacek@gmail.com>
*
* This program is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation: either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ARGON2_OPENCL_GLOBALCONTEXT_H
#define ARGON2_OPENCL_GLOBALCONTEXT_H
#include "device.h"
#include <string>
#include <vector>
namespace argon2 {
namespace opencl {
class GlobalContext
{
private:
std::vector<Device> devices;
public:
const std::vector<Device> &getAllDevices() const { return devices; }
GlobalContext();
};
} // namespace opencl
} // namespace argon2
#endif // ARGON2_OPENCL_GLOBALCONTEXT_H
/*
* Copyright (C) 2015, Ondrej Mosnacek <omosnacek@gmail.com>
*
* This program is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation: either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef OPENCL_H
#define OPENCL_H
/* Some compatibility hacks: */
#define CL_USE_DEPRECATED_OPENCL_1_1_APIS
#define CL_USE_DEPRECATED_OPENCL_1_2_APIS
#include <CL/cl.h>
#undef CL_VERSION_2_0
/* Throw exceptions on errors: */
#define __CL_ENABLE_EXCEPTIONS
/* Include local version of <CL/cl.hpp>
* because not all platforms ship with it: */
#include "cl.hpp"
#endif // OPENCL_H
#ifndef ARGON2_OPENCL_PROCESSINGUNIT_H
#define ARGON2_OPENCL_PROCESSINGUNIT_H
#include <memory>
#include "programcontext.h"
#include "argon2-gpu-common/argon2params.h"
namespace argon2 {
namespace opencl {
class ProcessingUnit
{
private:
const ProgramContext *programContext;
const Argon2Params *params;
const Device *device;
std::size_t batchSize;
std::size_t memorySize;
bool bySegment;
cl::CommandQueue cmdQueue;
cl::Buffer memoryBuffer;
cl::Buffer debugBuffer;
void *mappedMemoryBuffer;
cl::Kernel kernel;
cl::Event event;
public:
class PasswordWriter
{
private:
const Argon2Params *params;
Type type;
Version version;
std::uint8_t *dest;
public:
PasswordWriter(ProcessingUnit &parent, std::size_t index = 0);
void moveForward(std::size_t offset);
void moveBackwards(std::size_t offset);
void setPassword(const void *pw, std::size_t pwSize) const;
};
class HashReader
{
private:
const Argon2Params *params;
const std::uint8_t *src;
std::unique_ptr<uint8_t[]> buffer;
public:
HashReader(ProcessingUnit &parent, std::size_t index = 0);
void moveForward(std::size_t offset);
void moveBackwards(std::size_t offset);
const void *getHash() const;
};
std::size_t getBatchSize() const { return batchSize; }
ProcessingUnit(
const ProgramContext *programContext, const Argon2Params *params,
const Device *device, std::size_t batchSize,
bool bySegment = true);
void beginProcessing();
void endProcessing();
};
} // namespace opencl
} // namespace argon2
#endif // ARGON2_OPENCL_PROCESSINGUNIT_H
#ifndef ARGON2_OPENCL_PROGRAMCONTEXT_H
#define ARGON2_OPENCL_PROGRAMCONTEXT_H
#include "globalcontext.h"
#include "argon2-gpu-common/argon2-common.h"
namespace argon2 {
namespace opencl {