1
0
Fork 0
mirror of https://github.com/eosswedenorg/antelope-keygen synced 2026-06-17 03:50:03 +02:00

adding crypto/hash.h and move openssl specific code from checksum.cpp to crypto/openssl/hash.cpp

This commit is contained in:
Henrik Hautakoski 2020-02-11 15:42:41 +01:00
parent 7a4cc43ec9
commit fc5614eff2
5 changed files with 96 additions and 13 deletions

View file

@ -45,7 +45,10 @@ endif()
# Libraries
find_package(OpenSSL 1.1 REQUIRED)
set (PROGRAM_SOURCE ${PROGRAM_SOURCE} src/crypto/openssl/ec.cpp)
set (PROGRAM_SOURCE ${PROGRAM_SOURCE}
src/crypto/openssl/ec.cpp
src/crypto/openssl/hash.cpp
)
if (USE_THREADS)
find_package(Threads)

View file

@ -21,32 +21,31 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#include <openssl/sha.h>
#include <openssl/ripemd.h>
#include <cstring>
#include "crypto/hash.h"
#include "checksum.h"
namespace eoskeygen {
inline void sha256d(const unsigned char *data, std::size_t len, unsigned char *out) {
SHA256(data, len, out);
SHA256(out, 32, out);
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(name, func) \
checksum_t checksum_##name(const unsigned char *data, std::size_t len) { \
#define checksum_impl(func, type) \
checksum_t checksum_##func(const unsigned char *data, std::size_t len) { \
\
checksum_t crc; \
unsigned char hash[32]; \
type hash; \
\
func(data, len, hash); \
func(data, len, &hash); \
\
std::memcpy(crc.data(), hash, crc.size()); \
std::memcpy(crc.data(), &hash, crc.size()); \
return crc; \
}
checksum_impl(sha256d, sha256d)
checksum_impl(ripemd160, RIPEMD160)
checksum_impl(sha256d, sha256_t)
checksum_impl(ripemd160, ripemd160_t)
} // namespace eosio-keygen

38
src/crypto/hash.h Normal file
View file

@ -0,0 +1,38 @@
/**
* 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.
*/
#ifndef EOSIOKEYGEN_CRYPTO_HASH_H
#define EOSIOKEYGEN_CRYPTO_HASH_H
#include <cstddef>
#include "types.h"
namespace eoskeygen {
sha256_t* sha256(const unsigned char *data, std::size_t len, sha256_t* out);
ripemd160_t* ripemd160(const unsigned char *data, std::size_t len, ripemd160_t* out);
} // namespace eoskeygen
#endif /* EOSIOKEYGEN_CRYPTO_HASH_H */

View file

@ -0,0 +1,38 @@
/**
* 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 <openssl/sha.h>
#include <openssl/ripemd.h>
#include "../hash.h"
namespace eoskeygen {
sha256_t* sha256(const unsigned char *data, std::size_t len, sha256_t* out) {
return (sha256_t *) SHA256(data, len, out->data);
}
ripemd160_t* ripemd160(const unsigned char *data, std::size_t len, ripemd160_t* out) {
return (ripemd160_t *) RIPEMD160(data, len, out->data);
}
} // namespace eoskeygen

View file

@ -45,6 +45,11 @@ struct ec_keypair {
ec_pubkey_t pub;
};
// Hashes.
typedef struct { unsigned char data[20]; } ripemd160_t;
typedef struct { unsigned char data[32]; } sha256_t;
} // namespace eoskeygen
#endif /* EOSIOKEYGEN_CRYPTO_TYPES_H */