This file contains hidden or 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
#include <iostream> | |
void (*mem_fun_cb)(void); | |
class mem_fun { | |
private: | |
public: | |
mem_fun() { } | |
~mem_fun() { } |
This file contains hidden or 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
#include <iostream> | |
#include <functional> | |
void f() | |
{ | |
std::cout << "called f" << std::endl; | |
} | |
int main() | |
{ |
This file contains hidden or 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
// callback declaration | |
void (*callback)(int); | |
void print_func(int a) | |
{ | |
printf("%d\n", a); | |
} | |
int register_print_callback() | |
{ |
This file contains hidden or 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
static void (*event_callback)(void *user_priv, uint8_t *datap, size_t datap_len); | |
static void *user_priv; | |
int register_event_callback(void *user_ptr) | |
{ | |
event_callback = my_event_callback; | |
user_priv = user_ptr; | |
return 0; | |
} |
This file contains hidden or 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
#include <iostream> | |
#include <string> | |
#include <openssl/evp.h> | |
#include <openssl/err.h> | |
#include <openssl/ecdsa.h> | |
#include <openssl/ec.h> | |
#include <openssl/conf.h> | |
#include <openssl/rand.h> | |
#include <openssl/pem.h> | |
#include <openssl/sha.h> |
This file contains hidden or 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
int generate_keys(std::string pubkeyfile, std::string privkeyfile, std::string curve_name) | |
{ | |
EC_KEY *keygen; | |
int nid = to_nid(curve_name); | |
if (nid == -1) { | |
return -1; | |
} | |
// get curve name |
This file contains hidden or 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
// loads in the pubkey | |
int load_pubkey(std::string pubkey) | |
{ | |
FILE *fp; | |
// load in the keys | |
fp = fopen(pubkey.c_str(), "r"); | |
if (!fp) { | |
return -1; | |
} |
This file contains hidden or 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
int load_privkey(std::string privkey) | |
{ | |
FILE *fp; | |
fp = fopen(privkey.c_str(), "r"); | |
if (!fp) { | |
return -1; | |
} | |
privatekey = PEM_read_ECPrivateKey(fp, NULL, NULL, NULL); |
This file contains hidden or 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
int sign(uint8_t *msg, size_t msglen, std::string sha_alg) | |
{ | |
if (!evp_sign_key || !privatekey) { | |
std::cerr << "invalid sign key or private key is not loaded" << std::endl; | |
return -1; | |
} | |
const EVP_MD *md; | |
// mark the sha alg to use |
This file contains hidden or 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
int verify(uint8_t *msg, size_t msglen, uint8_t *signature, size_t signature_len, std::string sha_alg) | |
{ | |
if (!msg || !signature) { | |
std::cerr << "invalid msg or signature" << std::endl; | |
return -1; | |
} | |
const EVP_MD *md; | |
if (sha_alg == "sha256") { |