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
/** | |
* @description GCD in C++ | |
* | |
* @copyright 2019-present Devendra Naga (devnaga@tuta.io) All rights reserved | |
*/ | |
#include <iostream> | |
#include <memory> | |
#include <string> | |
#include <vector> | |
#include <thread> |
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
#include <stdio.h> | |
#include <sys/types.h> | |
#include <sys/stat.h> | |
#include <unistd.h> | |
#include <fcntl.h> | |
#include <mbedtls/hkdf.h> | |
#include <stdint.h> | |
#include <string.h> | |
// salt is shared between server and client |
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
static shared_data *shared_data::get() | |
{ | |
static shared_data sh; | |
return &sh; | |
} | |
void shared_data::put_data(T &data) | |
{ | |
std::unique_lock<std::mnutex> lock(lock); |
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
template <typename T> | |
class shared_data { | |
public: | |
~shared_data() { } | |
explicit shared_data(const shared_data &) = delete; | |
shared_data &operator=(const shared_data &) = delete; | |
// get shared object of this instance | |
static shared_data *get(); |
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
#include <stdio.h> | |
#include <stdint.h> | |
#include <stdlib.h> | |
#include <string.h> | |
struct linked_list { | |
void *data; | |
struct linked_list *next; | |
}; |
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
/** | |
* Find current files in use for a specific process | |
* | |
* @Author: Devendra Naga (devendra.aaru@gmail.com) | |
* | |
* License MIT | |
*/ | |
#include <stdio.h> | |
#include <string.h> | |
#include <unistd.h> |
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
/** | |
* | |
* HMAC tutorial | |
* | |
* Written by Devendra Naga (devendra.aaru@gmail.com) | |
* | |
* License MIT | |
*/ | |
#include <iostream> | |
#include <stdint.h> |
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
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") { |
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
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 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); |