-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix Makefile PHONY targets * add libcryptopp submodule and build recipe * make CI build libcryptopp instead of using package Packaged version does not provide needed symbols * add blake2b hash function with 256 bit digest size * add sha2 hash function with 512 bit digest size * Update libcryptopp submodule to ignore untracked files Co-authored-by: Everett Hildenbrandt <[email protected]> * extract common utility functions * move problematic hash functions to separate file * remove inline attribute from allocString to fix compile error Co-authored-by: Everett Hildenbrandt <[email protected]>
- Loading branch information
Showing
9 changed files
with
92 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#include <cryptopp/blake2.h> | ||
#include "plugin_util.h" | ||
|
||
using namespace CryptoPP; | ||
|
||
extern "C" { | ||
|
||
struct string *hook_KRYPTO_blake2b256raw(struct string *str) { | ||
BLAKE2b h(false,32); | ||
unsigned char digest[32]; | ||
h.CalculateDigest(digest, (unsigned char *)str->data, len(str)); | ||
return raw(digest, sizeof(digest)); | ||
} | ||
|
||
struct string *hook_KRYPTO_blake2b256(struct string *str) { | ||
BLAKE2b h(false,32); | ||
unsigned char digest[32]; | ||
h.CalculateDigest(digest, (unsigned char *)str->data, len(str)); | ||
return hexEncode(digest, sizeof(digest)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#include "plugin_util.h" | ||
|
||
extern "C" { | ||
string* allocString(size_t len) { | ||
struct string *result = (struct string *)koreAllocToken(len + sizeof(string)); | ||
set_len(result, len); | ||
return result; | ||
} | ||
|
||
string *hexEncode(unsigned char *digest, size_t len) { | ||
uint64_t hexLen = len * 2; | ||
char byte[3]; | ||
struct string *result = allocString(hexLen); | ||
for (size_t i = 0, j = 0; i < len; i++, j += 2) { | ||
sprintf(byte, "%02x", digest[i]); | ||
result->data[j] = byte[0]; | ||
result->data[j+1] = byte[1]; | ||
} | ||
return result; | ||
} | ||
|
||
string *raw(unsigned char *digest, size_t len) { | ||
struct string *result = allocString(len); | ||
memcpy(result->data, digest, len); | ||
return result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#ifndef PLUGIN_UTIL_H | ||
#define PLUGIN_UTIL_H | ||
|
||
#include <cstdint> | ||
#include <cstring> | ||
#include <gmp.h> | ||
#include "runtime/alloc.h" | ||
#include "runtime/header.h" | ||
|
||
extern "C" { | ||
string* allocString(size_t len); | ||
string *hexEncode(unsigned char *digest, size_t len); | ||
string *raw(unsigned char *digest, size_t len); | ||
} | ||
|
||
#endif |