Category Archives: C

Safe Kernel Programming with Rust

The discussion on whether FreeBSD should eventually replace C with Rust, produced a link to “Safe Kernel Programming with Rust“, a degree project in computer science and engineering, written by Johannes Lundberg while at KTH in Sweden.

If you aim for printing the PDF file as two-sided, then print the following pages in the following order: 1-3,2,4-56. If booklet printing is desired, then this order produces a good result: 1-3,2,4-55,2,2,2,56.

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