Skip to content

Instantly share code, notes, and snippets.

View randombit's full-sized avatar

Jack Lloyd randombit

View GitHub Profile
PHPSeclib's backup PRNG (if no mcrypt extension or /dev/urandom) is nominally X9.31
https://github.com/phpseclib/phpseclib/blob/master/phpseclib/Crypt/Random.php#L241
except it uses CTR mode (or RC4!?) rather than ECB mode:
https://github.com/phpseclib/phpseclib/blob/master/phpseclib/Crypt/Random.php#L191
So the first time through the loop,

Keybase proof

I hereby claim:

  • I am randombit on github.
  • I am jacklloyd (https://keybase.io/jacklloyd) on keybase.
  • I have a public key whose fingerprint is B169 2A9D 2785 5933 6A02 6C20 EB6F 4E97 FF25 3353

To claim this, I am signing this object:

### Keybase proof
I hereby claim:
* I am randombit on github.
* I am jacklloyd (https://keybase.io/jacklloyd) on keybase.
* I have a public key whose fingerprint is 4E60 C735 51AF 2188 DF0A 5A62 78E9 8043 5712 3B60
To claim this, I am signing this object:
*** This is just my personal todo file for botan. It is not supposed
to make any sense to you. Some of these things may happen some day.
If something in here excites you feel free to take it on though.
The easy way to do a FIPS 140 validation is to not need to do a FIPS 140 validation.
FIPS just cares about the crypto impl, if we're just an 'application calling OpenSSL FIPS object'
that happens to implement TLS, all is well. This requires a special mode that enables
only OpenSSL's AES, SHA, RSA, ECDSA, RNG, etc and disable the builtins including our
HMAC_DRBG (instead AutoSeeded_RNG calls OpenSSL's FIPS RNG), plus probably 2-3
exposed API functions for the application to control the OpenSSL self tests and etc.
/*
Compile time string switch
Requires C++14 constexpr
*/
#include <cstdint>
#include <cstdio>
#if 0
// C++14 version
@randombit
randombit / gist:d1c9ec22e0b5d31dba460d791e24e05d
Last active December 28, 2021 19:45
Advanced Cryptography Topics
Pallier Cryptosystem
Voting protocols, systems, mixnets
Homomorphic encryption (ElGamal, mixnets, voting)
Sigma protocols
Zero Knowledge Proofs, Fiat-Shamir Transform
ID based signatures and encryption
SNARKs
Ring signatures, group signatures
Signcryption
Pairings, uses thereof
#include <botan/fpe_fe1.h>
#include <assert.h>
#include <iostream>
using namespace Botan;
BigInt power(size_t g, size_t x)
{
BigInt r = 1;
for(size_t i = 0; i != x; ++i)
@randombit
randombit / mr_iterations.py
Created April 10, 2018 15:41
Miller-Rabin error probabilities
#!/usr/bin/python
from math import log, pow, sqrt
import sys
# Estimate Miller-Rabin error probability based on bitsize (k)
# and number of MR tests (t)
# https://www.math.dartmouth.edu//~carlp/PDF/paper88.pdf
@randombit
randombit / format_ecdsa.py
Created May 31, 2018 21:15
Format Wycheproof ECDSA test data
!/usr/bin/python
import json
import hashlib
import binascii
from pyasn1.codec.der.decoder import decode as der_decoder
from pyasn1.type.univ import Sequence
from pyasn1.type.univ import Integer
from pyasn1.type.namedtype import NamedTypes
from pyasn1.type.namedtype import NamedType
@randombit
randombit / dsa_groups.txt
Created August 2, 2018 16:34
DSA groups generated by lexicographical first working seed
P=1024 Q=160
Seed=000000000000000000000000000000000000021
-----BEGIN X9.42 DH PARAMETERS-----
MIIBHwKBgQCEoKuNbWMqbPuFOqSWKMGJyQ8VMSWLMtQ80wj0Is3RxrGpz0Bpshd7
Q9EL7BVjwTi+bZe68bXwU8GsHNLq6qplevvfsmpeHaJn0vt/gHRjmWWB68phAuPe
+CcU9X4ESl8e869AkSq3rnCnpTHauBDMkOWvXiMRUNEE5QbPdNHlhQKBgQCBrdzE
HRHk662S9/WZnuZpAeZjQCZZug1DToG97W4Z9xOycttPZ50N5mC4+NOhmfV4t3a+
1wTe7vuYdL8zHt/dcIx9ow/uriqlaFX2Hh/jTYeC8r0m1JDcBxKV21aE5QLqpCfu
Jr8h/76s55aY1m2OWaR1K//y54GWZ4sxoxgS8gIVANnk4S2TxAhgZKmIVOksz0sn
dNlL