Skip to content

Instantly share code, notes, and snippets.

View Yawning's full-sized avatar
💭
🐈‍⬛

Yawning Angel Yawning

💭
🐈‍⬛
View GitHub Profile
@Yawning
Yawning / gist:9501996
Created March 12, 2014 06:39
Python CTR_DRBG (CTR-AES-128)
""" NIST SP 800-90A style CTR_DRBG, using CTR-AES-128. """
import obfsproxy.common.aes as aes
import binascii
import os
import random
class CtrDrbg(random.Random):
"""
@Yawning
Yawning / gist:9515778
Created March 12, 2014 20:37
CTR_DRBG tests
import twisted.trial.unittest
import obfsproxy.common.ctr_drbg as ctr_drbg
import binascii
import math
import struct
class testCtrDrbg_NIST(twisted.trial.unittest.TestCase):
"""
@Yawning
Yawning / gist:330f55df5638577dd5cd
Created July 10, 2014 18:03
gpg2 patch to support RSA keys > 16384 bits
diff -uNr gnupg-2.0.22/g10/gpg.c gnupg-2.0.22-large-keys/g10/gpg.c
--- gnupg-2.0.22/g10/gpg.c 2013-10-04 12:32:53.000000000 +0000
+++ gnupg-2.0.22-large-keys/g10/gpg.c 2013-10-26 22:14:18.933010862 +0000
@@ -2050,7 +2050,7 @@
#endif
/* Initialize the secure memory. */
- if (!gcry_control (GCRYCTL_INIT_SECMEM, 32768, 0))
+ if (!gcry_control (GCRYCTL_INIT_SECMEM, 131072, 0))
got_secmem = 1;
@Yawning
Yawning / gist:4cca041c456ccf113700
Created December 23, 2014 04:15
Don't use GMPY rand for key generation, ever.
#!/usr/bin/env python2
# Extract the "improved" key generation code from cryptowrapper.py
# and tunnelcrypto.py, as of: a623e25e10e5e96ea1d5b85853b23bea00ee439f
from gmpy import mpz, rand
DIFFIE_HELLMAN_MODULUS = mpz(0xFFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7EDEE386BFB5A899FA5AE9F24117C4B1FE649286651ECE65381FFFFFFFFFFFFFFFF)
rand('init', 128)
@Yawning
Yawning / gist:2829f9adf889f1334005
Created January 2, 2015 10:41
gettimeofday() benchmark.
#include <stdint.h>
#include <stdio.h>
#include <time.h>
#include <sys/time.h>
#include <assert.h>
#define ITERS 1000000000
static uint64_t gettime(void) {
struct timespec ts;
@Yawning
Yawning / gist:fda95db37092669958b1
Last active August 29, 2015 14:13
Simple helper that checks if Linux filesystem capabilites() are set without using external libraries.
#include <sys/types.h>
#include <sys/xattr.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
/*
* A quick and dirty test to see if a given file has any Linux capabilities
* set.
From 6d23b7b45581a218cf1fdfd9ef580f3c628ffdbe Mon Sep 17 00:00:00 2001
From: Yawning Angel <yawning@schwanenlied.me>
Date: Fri, 27 Mar 2015 14:15:57 +0000
Subject: [PATCH 1/1] (squash) Fixup handle_control_hspost().
* Use C99 to bring variable declarations closer to where they are
allocated/initialized.
* Don't leak a smartlist_t (args was initialized, and getargs_helper()
trampled over it).
* Don't leak a rend_encoded_v2_service_descriptor_t when the descriptor
@Yawning
Yawning / linux_get_external_addr.c
Last active October 5, 2022 15:16
Querying the address used to reach the outside world, the correct way. (Linux).
#include <asm/types.h>
#include <linux/netlink.h>
#include <linux/rtnetlink.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <sys/uio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
@Yawning
Yawning / orhttp_example.go
Created April 29, 2015 14:41
How to dispatch HTTP requests via Tor in Go.
// To the extent possible under law, the Yawning Angel has waived all copyright
// and related or neighboring rights to orhttp_example, using the creative
// commons "cc0" public domain dedication. See LICENSE or
// <http://creativecommons.org/publicdomain/zero/1.0/> for full details.
package main
import (
// Things needed by the actual interface.
"golang.org/x/net/proxy"
@Yawning
Yawning / elligator2.h
Last active March 20, 2020 07:38
(DEPRECATED) A mostly drop in elligator2 for ed25519-donna.
There used to be something that resembled an Elligator2 implementation here ported from agl's
Go code. The implementation is unmaintained and has severe issues (as pointed out in a comment),
and should not be used for anything.