Skip to content

Instantly share code, notes, and snippets.

const std = @import("std");
// Old implementation (current master)
fn gcd_old(a: anytype, b: anytype) @TypeOf(a, b) {
const N = switch (@TypeOf(a, b)) {
comptime_int => std.math.IntFittingRange(@min(a, b), @max(a, b)),
else => |T| T,
};
if (@typeInfo(N) != .int or @typeInfo(N).int.signedness != .unsigned) {
@compileError("`a` and `b` must be unsigned integers");
const std = @import("std");
const crypto = std.crypto;
const mem = std.mem;
const debug = std.debug;
const modes = crypto.core.modes;
const AuthenticationError = crypto.errors.AuthenticationError;
const cbc_mac = @import("cbc_mac.zig");
/// CCM (Counter with CBC-MAC) authenticated encryption mode
/// RFC 3610: https://www.rfc-editor.org/rfc/rfc3610
const std = @import("std");
const crypto = std.crypto;
const mem = std.mem;
/// CBC-MAC (Cipher Block Chaining Message Authentication Code)
///
/// CBC-MAC is a simple MAC construction: MAC = Encrypt(prev_mac XOR block)
/// Unlike CMAC (RFC 4493), CBC-MAC does not derive subkeys or perform special
/// final block processing. It is less secure than CMAC (vulnerable to length
/// extension attacks), but is required by certain standards like CCM (RFC 3610).
@jedisct1
jedisct1 / fastly-block.sh
Created July 31, 2025 08:14
Block all connections to Fastly
#! /bin/sh
IPV4_RANGES=(
"23.235.32.0/20"
"43.249.72.0/22"
"103.244.50.0/24"
"103.245.222.0/23"
"103.245.224.0/24"
"104.156.80.0/20"
"140.248.64.0/18"
@jedisct1
jedisct1 / anthropic_oauth.py
Created June 22, 2025 21:13 — forked from changjonathanc/anthropic_oauth.py
Anthropic OAuth CLI - Simplified Claude Code spoof demo
#!/usr/bin/env python3
import argparse
import base64
import hashlib
import json
import os
import secrets
import sys
import time
@jedisct1
jedisct1 / sign.go
Last active February 13, 2025 09:34
SIgning a CSR in Go, for mTLS (using ECDSA keys)
// Create a key pair for the app and a CSR:
// $ openssl ecparam -genkey -name prime256v1 -out application.key
// $ openssl req -new -sha256 -key application.key -out request.csr
package main
import (
"crypto/ecdsa"
"crypto/elliptic"
"crypto/rand"
@jedisct1
jedisct1 / foo.go
Last active January 3, 2025 18:01
package main
import (
"crypto/rand"
"crypto/rsa"
"crypto/x509"
"encoding/pem"
"fmt"
"log"
"os"
@jedisct1
jedisct1 / b.rs
Last active September 17, 2024 14:48
// Cargo.toml:
// [dependencies]
// boring = { package = "superboring", version = "0.1.2" }
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Ciphertext
let ciphertext = include_bytes!("signed_message.bin");
// Unencrypted RSA private key in PEM format
let rsa_pem = include_str!("sessionprivatekey.pem");
@jedisct1
jedisct1 / a.rs
Created September 17, 2024 14:45
// Cargo.toml:
// [dependencies]
// rsa = "0.9.6"
// rand = "0.8.5"
fn main() -> Result<(), Box<dyn std::error::Error>> {
use rsa::pkcs8::DecodePrivateKey as _;
// Ciphertext
let ciphertext = include_bytes!("signed_message.bin");
@jedisct1
jedisct1 / compiling-c-to-webassembly-and-rust.md
Last active January 11, 2025 07:18
Compiling C code to WebAssembly and Rust

How to embed C/C++ code in a Rust project targeting WebAssembly

When targeting WebAssembly, C/C++ code can be compiled as a library, and then get statically linked to a Rust project.

Step 1

Install the Zig toolchain in order to compile C and C++ code to WebAssembly.

zig cc is available for many platforms including Windows, and makes it easy to switch back and forth between native and wasm targets. WebAssembly is a Tier-1 target, and it was successfully used to port libraries such as ffmpeg, zlib, openssl, boringssl and libsodium.