|
1 |
| -#include <cstdint> |
2 | 1 | #include <cryptopp/keccak.h>
|
3 | 2 | #include <cryptopp/ripemd.h>
|
4 | 3 | #include <cryptopp/sha.h>
|
5 | 4 | #include <cryptopp/sha3.h>
|
6 | 5 | #include <secp256k1_recovery.h>
|
7 |
| -#include <gmp.h> |
8 | 6 | #include <libff/algebra/curves/alt_bn128/alt_bn128_pp.hpp>
|
9 | 7 | #include <libff/common/profiling.hpp>
|
10 |
| -#include "runtime/alloc.h" |
11 |
| -#include "runtime/header.h" |
12 | 8 | #include "blake2.h"
|
| 9 | +#include "plugin_util.h" |
13 | 10 |
|
14 | 11 | using namespace CryptoPP;
|
15 | 12 | using namespace libff;
|
16 | 13 |
|
17 | 14 | extern "C" {
|
18 |
| -static inline string* allocString(size_t len) { |
19 |
| - struct string *result = (struct string *)koreAllocToken(len + sizeof(string)); |
20 |
| - set_len(result, len); |
21 |
| - return result; |
22 |
| -} |
23 | 15 |
|
24 |
| -static string *hexEncode(unsigned char *digest, size_t len) { |
25 |
| - uint64_t hexLen = len * 2; |
26 |
| - char byte[3]; |
27 |
| - struct string *result = allocString(hexLen); |
28 |
| - for (size_t i = 0, j = 0; i < len; i++, j += 2) { |
29 |
| - sprintf(byte, "%02x", digest[i]); |
30 |
| - result->data[j] = byte[0]; |
31 |
| - result->data[j+1] = byte[1]; |
32 |
| - } |
33 |
| - return result; |
| 16 | +struct string *hook_KRYPTO_sha512raw(struct string *str) { |
| 17 | + SHA512 h; |
| 18 | + unsigned char digest[64]; |
| 19 | + h.CalculateDigest(digest, (unsigned char *)str->data, len(str)); |
| 20 | + return raw(digest, sizeof(digest)); |
34 | 21 | }
|
35 | 22 |
|
36 |
| -static string *raw(unsigned char *digest, size_t len) { |
37 |
| - struct string *result = allocString(len); |
38 |
| - memcpy(result->data, digest, len); |
39 |
| - return result; |
| 23 | +struct string *hook_KRYPTO_sha512(struct string *str) { |
| 24 | + SHA512 h; |
| 25 | + unsigned char digest[64]; |
| 26 | + h.CalculateDigest(digest, (unsigned char *)str->data, len(str)); |
| 27 | + return hexEncode(digest, sizeof(digest)); |
40 | 28 | }
|
41 | 29 |
|
42 | 30 | struct string *hook_KRYPTO_sha3raw(struct string *str) {
|
|
0 commit comments