mirror of
https://github.com/eosswedenorg/antelope-keygen
synced 2026-06-17 03:50:03 +02:00
checksum.h: implement using templates instead of nasty macro + header only as we don't have openssl specific code there anymore.
This commit is contained in:
parent
ce5dda06fe
commit
8e7b132ca1
3 changed files with 14 additions and 54 deletions
|
|
@ -19,7 +19,6 @@ set (PROGRAM_EXE ${CMAKE_PROJECT_NAME})
|
|||
set (PROGRAM_SOURCE
|
||||
src/string.cpp
|
||||
src/base58.cpp
|
||||
src/checksum.cpp
|
||||
src/WIF.cpp
|
||||
src/key_search.cpp
|
||||
src/key_search_helpers.cpp
|
||||
|
|
|
|||
|
|
@ -1,51 +0,0 @@
|
|||
/**
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2019-2020 EOS Sw/eden
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
#include <cstring>
|
||||
#include "crypto/hash.h"
|
||||
#include "checksum.h"
|
||||
|
||||
namespace eoskeygen {
|
||||
|
||||
inline void sha256d(const unsigned char *data, std::size_t len, sha256_t *out) {
|
||||
sha256(data, len, out);
|
||||
sha256(out->data, 32, out);
|
||||
}
|
||||
|
||||
#define checksum_impl(func, type) \
|
||||
checksum_t checksum_##func(const unsigned char *data, std::size_t len) { \
|
||||
\
|
||||
checksum_t crc; \
|
||||
type hash; \
|
||||
\
|
||||
func(data, len, &hash); \
|
||||
\
|
||||
std::memcpy(crc.data(), &hash, crc.size()); \
|
||||
return crc; \
|
||||
}
|
||||
|
||||
|
||||
checksum_impl(sha256d, sha256_t)
|
||||
checksum_impl(ripemd160, ripemd160_t)
|
||||
|
||||
} // namespace eosio-keygen
|
||||
|
|
@ -25,7 +25,9 @@
|
|||
#define EOSIOKEYGEN_CHECKSUM_H
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstring>
|
||||
#include <array>
|
||||
#include "crypto/hash.h"
|
||||
|
||||
namespace eoskeygen {
|
||||
|
||||
|
|
@ -33,9 +35,19 @@ namespace eoskeygen {
|
|||
|
||||
typedef std::array<unsigned char, CHECKSUM_SIZE> checksum_t;
|
||||
|
||||
checksum_t checksum_sha256d(const unsigned char *data, std::size_t len);
|
||||
template <typename T, T* (*F)(const unsigned char *, std::size_t, T*)>
|
||||
inline checksum_t checksum(const unsigned char* data, std::size_t len) {
|
||||
checksum_t crc;
|
||||
T hash;
|
||||
|
||||
checksum_t checksum_ripemd160(const unsigned char *data, std::size_t len);
|
||||
F(data, len, &hash);
|
||||
std::memcpy(crc.data(), &hash, crc.size());
|
||||
return crc;
|
||||
}
|
||||
|
||||
#define checksum_sha256 checksum<sha256_t, sha256>
|
||||
#define checksum_sha256d checksum<sha256_t, sha256d>
|
||||
#define checksum_ripemd160 checksum<ripemd160_t, ripemd160>
|
||||
|
||||
} // namespace eoskeygen
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue