Skip to content

Instantly share code, notes, and snippets.

View devendranaga's full-sized avatar
🍈

Dev devendranaga

🍈
  • <>
View GitHub Profile
// 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;
}
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
@devendranaga
devendranaga / ecc_demo.cc
Last active February 14, 2019 05:11
ECC keygen / sign and verify in C++
#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>
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;
}
// callback declaration
void (*callback)(int);
void print_func(int a)
{
printf("%d\n", a);
}
int register_print_callback()
{
#include <iostream>
#include <functional>
void f()
{
std::cout << "called f" << std::endl;
}
int main()
{
#include <iostream>
void (*mem_fun_cb)(void);
class mem_fun {
private:
public:
mem_fun() { }
~mem_fun() { }
#include <iostream>
#include <string>
#include <vector>
#include <unistd.h>
#include <functional>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <iostream>
#include <functional>
void f(int i)
{
std::cout << " called f" << std::endl;
}
class my_class {
private:
@devendranaga
devendranaga / README.md
Last active February 8, 2019 02:30 — forked from gburd/README.md
Hardening C code at compile time

Hardening C code

format

Adds the -Wformat -Wformat-security -Werror=format-security compiler options. At present, this warns about calls to printf and scanf functions where the format string is not a string literal and there are no format arguments, as in printf(foo). This may be a security hole if the format string came from untrusted input and contains %n.

-Wformat is usually added with the -Wformat=2 option to be more stricter.

stackprotector