Skip to content

Instantly share code, notes, and snippets.

// Extracted from https://github.com/pyjamask-cipher/pyjamask-reference-implementation/blob/master/pyjamask.c
#include <cstdint>
#define right_rotate(row) \
row = (row >> 1) | (row << 31);
#define COL_M0 0xa3861085
#define COL_M1 0x63417021
#define COL_M2 0x692cf280
#include <stdint.h>
#include <stdlib.h>
uint32_t crc32b(uint8_t* data, size_t len) {
uint32_t crc = 0xFFFFFFFF;
for (size_t i = 0; i < len; ++i) {
const uint8_t v = data[i];
crc ^= v;
for (size_t j = 0; j < 8; ++j) {
const uint32_t bit = crc & 1;
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <inttypes.h>
#define CST 11246805480246805480ULL
static uint64_t load64_le(uint8_t const* V)
{
import struct
import pydffi
import llvmlite.ir as ll
FFI = pydffi.FFI()
CU = FFI.cdef('''
#include <stdbool.h>
typedef struct {
bool b;
int i;
#define _CRT_SECURE_NO_WARNINGS
#include "targetver.h"
#include <stdio.h>
#include <tchar.h>
#include <Windows.h>
#include <Wincrypt.h>
#include <array>
#include <cstdio>
template <class Array, class F, class Seq>
struct map_impl;
template <class Array, class F, size_t... I>
struct map_impl<Array, F, std::index_sequence<I...>>
{
template <class... Args>
@aguinet
aguinet / custom_static_inits.cpp
Last active February 28, 2017 07:32
Custom static C++ initializers list
// The idea is to statically create a list of initializers that would be
// launched when the "user" wants. This question has been asked by @lapinhib0u
// for the shell-factory project (https://github.com/gdelugre/shell-factory).
// The idea is that some classes might define initializers that needs to be
// launched at the beggining of the shell code, and each class might define
// whether it needs such initializer or not. Even if the whole code ends up in
// one compilation unit in the end, the construction of the initializer list is
// splitted accross various include files.
//
// Here is below one implementation of this that uses the __COUNTER__ macro.
@aguinet
aguinet / asm_reg.py
Created December 12, 2016 10:21
llvmlite {load,store}_reg example
import llvmlite.ir as ll
module = ll.Module()
Int64 = ll.IntType(64)
fntype = ll.FunctionType(ll.VoidType(), [])
func = ll.Function(module, fntype, name='foo')
BB = func.append_basic_block()
@aguinet
aguinet / func_static_assert.cpp
Created May 10, 2016 15:20
Helper templates to easily check whether a function type has the right signature (without std::function)
// Copyright (c) 2016 Adrien Guinet
// Helper templates to easily check whether a function type has the right
// signature (without std::function).
// If you have std::function, simply do
//
// template <class F, class R, class... Args>
// struct has_sign:
// public std::is_convertible<F, std::function<R(Args...)>>
// { };
//