ANF to CNF conversion

Algebraic Normal Form, or simply ANF, is the form used to describe cryptographic functions. It looks like this: a∗b⊕b∗c⊕b⊕d=0b∗c⊕c⊕a=0… a*b \oplus b*c \oplus b \oplus d = 0\\ b*c \oplus c \oplus a = 0\\ \ldots a∗b⊕b∗c⊕b⊕d=0b∗c⊕c⊕a=0… Where a,…da,\ldots da,…d are binary variables, the ⊕\oplus⊕ sign is binary XOR, and the ∗*∗ sign is binary AND. Every item that is connected with the XOR-s is called a monomial, and its degree is the number of independent variables inside it. So, a∗ba*ba∗b is a 2-degree monomial in the first equation, and ccc is a 1-degree monomial in the second equation. ...

July 6, 2010 · 4 min · msoos

How to bit-stuff pointers

In my last post I have described a small problem I had regarding a C++ union that had to store a pointer and a value at the same time, plus an indicator that told us which of the two was active: class WhatLeadHere { public: bool wasPointer; union{Clause* pointer; uint32_t lit;}; }; Martin Maurer has wrote this enlightening email regarding this: The Clause * pointer is [..] located at least on a 4 byte boundary (at least when not forced by e.g. #pragma). If it is not at least on a 4 byte boundary, CPU must (at least some of them) do two accesses: one lower DWORD, one upper DWORD, and merge both together, which reduces speed. So the lower two bits are always zero :-) Why not move the “wasPointer” to lower two bits (i think you need only one, have one spare bit). Of course before accessing the “pointer” (Clause *), you must “and” the two lower bits back to zero. ...

June 30, 2010 · 2 min · msoos

Propagating binary clauses

Binary clauses are somewhat special. They are clauses that look like: -v1 or v20 = true -v1 or v21 = true which basically mean: if v1 is TRUE, then both v20 and v21 must be TRUE. We put these clauses into a special datastructure, that looks like this: watchlist[-v1] = v20,v21, ... This makes us all very happy, since this datastructure is very simple: just literals (negated or non-negated variables) one after the other, in a very trivial list. This makes the whole thing very compact, and very efficient. ...

June 27, 2010 · 3 min · msoos