Category Archives: C

Detecting clang in C code

If you’re looking for a way to detect when your code is being compiled by clang, try the command

clang -dM -E -x c /dev/null

In the large list presented, you’ll find these macros the most interesting ones:

#define __clang__ 1
#define __clang_major__ 3
#define __clang_minor__ 3
#define __clang_patchlevel__ 0
#define __clang_version__ "3.3 (tags/RELEASE_33/final 183502)"
#define __llvm__ 1
#define __GNUC__ 4
#define __GNUC_MINOR__ 2
#define __GNUC_PATCHLEVEL__ 1
#define __VERSION__ "4.2.1 Compatible FreeBSD Clang 3.3 (tags/RELEASE_33/final 183502)"

Continue reading Detecting clang in C code

Secret splitting

A few days ago I resurrected all my files from a desktop system I haven’t used for almost six years. Below is my implementation of secret splitting as described in Bruce Schneier’s book “Applied Cryptography, 2nd edition”.

The idea is basically: generate a random keystream, xor the plaintext with the random keystream, use separate couriers and send the random keystream and the ciphertext to the final destination using separate routes, and finally combine the random keystream with the ciphertext to recreate the plaintext. None of the couriers know which piece they are carrying.

To improve this idea would be to generate more than one random keystream, xor the keystreams and the plaintext, thus requiring more couriers and different routes for each datastream.

And, by the way, xor crypto isn’t really that strong. Continue reading Secret splitting

endofepoch.c

Jeg børstet støvet av noen tilårskomne filer forleden dag. Jeg fant et lite program som jeg skrev en gang i 2000. Programmet teller ned til slutten av Unix-epoken.

Den opprinnelige definisjonen av datatypen time_t, 32-bit heltall med fortegn, vil få overflyt i midten av januar 2038. Moderne 64-bit OS som FreeBSD/amd64 9.0 har for lengst gått over til 64-bit time_t. Bare ta en titt i fila /usr/src/sys/amd64/include/_types.h, omtrent ved linje 83. Problemet med overflyten i år 2038 vil fortsatt gjelde alt utstyr og (binære) filformater som bruker den gamle definisjonen, slik som FreeBSD/i386 9.0. Ta en titt i fila /usr/src/sys/i386/include/_types.h, omtrent ved linje 91. Den engelske utgaven av Wikipedia har en utfyllende artikkel om problemet.

Kildekoden for det søte, lille programmet mitt, er gjengitt under. Continue reading endofepoch.c