Skip to content

Instantly share code, notes, and snippets.

View randombit's full-sized avatar

Jack Lloyd randombit

View GitHub Profile
@randombit
randombit / secp.cpp
Created November 13, 2024 13:22
Generate EC mul test vectors using OpenSSL
#define OPENSSL_SUPPRESS_DEPRECATED
#include <openssl/bn.h>
#include <openssl/ec.h>
#include <openssl/obj_mac.h>
#include <openssl/objects.h>
#include <stdio.h>
#include <vector>
void check_rc(const char* where, int rc, int expected_rc = 1) {
if(rc != expected_rc) {
@randombit
randombit / camellia.cpp
Created August 6, 2024 11:56
Camellia using GFNI
#include <botan/internal/simd_avx2.h>
#include <botan/internal/simd_avx2_gfni.h>
#include <immintrin.h>
#include <botan/hex.h>
#include <botan/system_rng.h>
namespace Botan {
SIMD_8x32 camellia_s1(SIMD_8x32 x) {
constexpr uint64_t pre_a = gfni_matrix(R"(
@randombit
randombit / ct_asm.cpp
Created July 28, 2024 01:09
Compile time generation of asm
// Demo of constexpr asm (gcc 15)
#include <stdlib.h>
#include <array>
#include <string>
#include <algorithm>
consteval std::string body_i(std::string_view x, size_t i) {
std::string out;
for(char c : x) {
@randombit
randombit / nums.cpp
Last active November 13, 2024 12:16
Generate numsp512d1 test vectors using OpenSSL
#define OPENSSL_SUPPRESS_DEPRECATED
#include <openssl/bn.h>
#include <openssl/ec.h>
#include <stdio.h>
void check_rc(const char* where, int rc, int expected_rc = 1) {
if(rc != expected_rc) {
printf("%s returned %d\n", where, rc);
exit(1);
}
def mods(ki, w):
if ki >= (1 << (w-1)):
return ki - (1 << w)
else:
return ki
def wnaf(k, w):
assert(w >= 2)
mask = (1 << w) - 1
naf = []
@randombit
randombit / gitconfig
Created June 4, 2024 12:50
Git pull GH PRs
[remote "origin"]
url = [email protected]:randombit/foo.git
fetch = +refs/heads/*:refs/remotes/origin/*
fetch = +refs/pull/*/head:refs/remotes/origin/pr/*
/**
Minimization of https://github.com/randombit/botan/issues/3637
*/
#define CAUSE_CODEGEN_BUG
#include <stdint.h>
#include <stdlib.h>
#include <type_traits>
#include <cstring>
@randombit
randombit / argon2_bench.cpp
Created March 4, 2022 13:03
Benchmark of libargon2
#include <argon2.h>
#include <stdint.h>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
uint64_t timestamp()
{
struct timespec ts;
if(::clock_gettime(CLOCK_MONOTONIC_RAW, &ts) == 0)
via https://twitter.com/mjos_crypto/status/1219610073816801286
Cloned https://github.com/daniel-thompson/pinebook-pro-debian-installer/
Inserted a 32GB sdcard into the built-in slot.
./install-debian
Installs the a system there, reboot from sdcard.
Clone again, now do:
./install-debian CRYPT=y BLKDEV=/dev/mmcblk2
Answer questions, done!
Supafresh Debian with LUKS on PineBook Pro.
@randombit
randombit / seccomp.c
Created January 14, 2019 18:41
Apply seccomp filters
void apply_simple_seccomp_filter(const std::vector<std::string>& allowed_syscalls)
{
//scmp_filter_ctx seccomp_ctx = ::seccomp_init(SCMP_ACT_ERRNO(EPERM));
scmp_filter_ctx seccomp_ctx = ::seccomp_init(SCMP_ACT_TRAP);
if(seccomp_ctx == NULL)
throw std::runtime_error("seccomp_init failed");
for(std::string syscall : allowed_syscalls)
{
int syscall_num = ::seccomp_syscall_resolve_name(syscall.c_str());