Skip to content

Instantly share code, notes, and snippets.

💭
reading..

Dev DevNaga

💭
reading..
Block or report user

Report or block DevNaga

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@DevNaga
DevNaga / gcd.cc
Created Oct 8, 2019
Grand Central Dispatch in C++
View gcd.cc
/**
* @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>
@DevNaga
DevNaga / hkdf.c
Created Oct 3, 2019
deriving keys with HKDF
View hkdf.c
#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
View singleton.cc
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);
View singleton.h
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();
View hash_table.c
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
struct linked_list {
void *data;
struct linked_list *next;
};
@DevNaga
DevNaga / lsof.c
Created Mar 21, 2019
find a set of opened files / files currently in use by a process in linux
View lsof.c
/**
* 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>
View hmac.cpp
/**
*
* HMAC tutorial
*
* Written by Devendra Naga (devendra.aaru@gmail.com)
*
* License MIT
*/
#include <iostream>
#include <stdint.h>
View verify_demo.cc
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") {
View sign_demo.cc
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
View load_pkey.cc
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);
You can’t perform that action at this time.