Wrapping a C library in Java

Introduction It can’t be argued that Java is popular and successful. It is consistently the number one language on TIOBE’s popularity list, above C which comes in as number two. This ranking is based on popularity and doesn’t mean Java is more used than C but that doesn’t change the fact that there is a lot of Java code out there. Unlike other languages interop with Java is not what I’d call easy....

June 6, 2017 · John

Recursive Create Directory in C

C has a very large gap when it comes to working with files and directories. It is C, so all the building blocks are there. Thankfully, it’s pretty easy to put together something useful. In a project I’ve been working on I needed to create a directory. This is pretty trivial but I needed to create a directory tree where all the parts might not already exist. Unfortunately C’s directory creation functions can’t make directories recursively....

May 17, 2017 · John

Poddown a simple podcast downloader

I have been listing to podcasts for a long time and many years ago I wrote a podcast downloader. Back then I had a media center and I wanted my favorite podcasts to automatically download each night. At that time there wasn’t anything that really did that. Well, there was but they were full management and play back applications. All I wanted was a simple downloader and not seeing any I wrote my own....

May 6, 2017 · John

String Splitting in C

For a project I’ve been working on I needed to split a string into it’s component parts. There is strtok which I find useless for pretty much any task. It is not thread-safe, nor is it re-entrant, which makes it impossible to parse two strings (in a loop) at once. Yet another issue with strtok is that after splitting, parts are returned by multiple calls to the function. The only way to know the number of parts is to loop until you’ve gone through all of them....

April 9, 2017 · John

Constant Time String Comparison in C

Comparing strings in C is typically handled with strncmp. This is fine in most cases but if you need to compare sensitive information, such as a message digest, it’s a really bad choice. strncmp is susceptible to timing attacks because it will stop comparing once the first difference is encountered. The overall design of constant time comparison is pretty well known. The OR XOR combo has been reviewed and vetted by crypto researchers....

April 2, 2017 · John

Efficient C String Builder

One task that always annoys me when I work with C is building strings. snprintf is all well and good if I know exactly the format I want. It falls down with anything that needs to be build iteratively and dynamically. Other languages that have built in strings will automatically create a new string when concatenating but C doesn’t actually have “strings”. I realize that concatenating strings is really inefficient and should be avoided for all but the smallest and simplest string....

February 26, 2017 · John

Lua-randxoxoxo a Lua Pseudo Random Number Generator

I spent a lot of time writing a number library in Lua just so I could write a hash library in Lua. Since I have this nice little number library I decided I should do more things with it. With that said, I’d like to introduce lua-randxoxoxo! lua-randxoxoxo is a pseudo random number generator. It’s pure Lua and allows you to have different random number generators with different seeds. Internally I’m using David Blackman and Sebastiano Vigna xoroshiro128+ algorithm....

November 23, 2016 · John

Lua-perforator a Lua Profiling Module

When I wrote the fixed width integer part of my Lua number library there were some performance issues. Even though I kept it simple and I knew a it wasn’t going to be quick, I did find there were a few places that needed to be optimized. To this end I wrote a bit of code to do some tracing and give me some statistics about what was happening. For example, the reduction code that handles wrapping was a major bottleneck....

November 11, 2016 · John

Lua-hashings a Lua Hash Library

A while back I wrote lua-nums and said it was working on a project that needed its features. Well, this is that project! lua-hashings is a pure Lua cryptographic hash library. This all started with crc32 and a work project. I was working with a third party API and they provided the ability to verify files using crc32 (only). At that time I wrote a crc32 calculation script. This got me thinking about Lua and hashing so I looked around to see what was out there....

October 20, 2016 · John

Lua-nums a Lua Number Library

One area that I’ve always found problematic in Lua is its number type. It’s a one size fits all solution and there are things I want to do that doesn’t really work with it. I’m mainly a C programmer and I’ve found unsigned integer wrapping to be useful in many situations. Especially when dealing with crypto algorithms. Another lacking feature of Lua’s number type is its range. Lua 5.3 internally uses a signed 64 bit type which provides a decent range but it’s not always enough....

September 14, 2016 · John