Skip to content

Instantly share code, notes, and snippets.

View devendranaga's full-sized avatar
🍈

Dev devendranaga

🍈
  • Bangalore
View GitHub Profile
@devendranaga
devendranaga / gcd.cc
Created October 8, 2019 16:24
Grand Central Dispatch in C++
/**
* @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>
@devendranaga
devendranaga / hkdf.c
Created October 3, 2019 17:01
deriving keys with HKDF
#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
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);
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();
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
struct linked_list {
void *data;
struct linked_list *next;
};
@devendranaga
devendranaga / lsof.c
Created March 21, 2019 12:04
find a set of opened files / files currently in use by a process in linux
/**
* 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>
/**
*
* HMAC tutorial
*
* Written by Devendra Naga (devendra.aaru@gmail.com)
*
* License MIT
*/
#include <iostream>
#include <stdint.h>
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") {
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
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);