Archive for April, 2008

axTLS, embedded security

Monday, April 28th, 2008

Recently we were faced with the fact that our current encryption model isn’t strong enough to satisfy some of our more demanding customers. After discussing the possibilities of writing our own encryption model based on public strong encryption standards we finally decided to go for a SSL solution. Building upon an existing and proven standard carries much more weight than reinventing the wheel and I was faced with the task of locating a suitable SSL implementation for our embedded systems.

The first two implementations that popped into my head were of course GNU TLS and OpenSSL. After investigating both solutions I came to the following conclusions. GNU TLS has some external dependencies, such as libgcrypt and libgpg-error. As I want to keep dependencies to a minimum since we integrate them with our build system, which can be a painful process, that sort of spoke against GNU TLS. Though OpenSSL didn’t have any external dependencies we couldn’t already satisfy it had a problem which also plagued GNU TLS, it had a rather large footprint. Somewhere in the vicinity of five times larger than the binary it was going to be linked with. This was clearly something that would be difficult to motivate.

After some googling I discovered three very interesting alternatives, MatrixSSL, XySSL and axTLS. All designed for embedded systems and having an acceptable footprint.
MatrixSSL costs money for commercial use so I decided to push it to the back of the queue. XySSL had some weird problems on our platform resulting in the infamous “TANGO15 reboot“. axTLS, while only supporting TLSv1, worked flawlessly, was easy to compile and had a footprint of roughly 50% of the binary it would be linked with. Performance isn’t a factor for the application in questions and hence it was not investigated.

If you are looking for an SSL implementation for an embedded system and TLSv1 is good enough for you I can highly recommend axTLS.

Pigs do fly, Apple buys P.A. Semi!

Wednesday, April 23rd, 2008

According to this Forbes article Apple just bought P.A. Semi.

I was really sad when I found out that we weren’t going to see a PowerBook with a PWRficient chip. At the time I pretty much gave up on the idea of a powerful computer reaching home users anytime soon. I doubt we are going to see a PowerBook or PowerMac for that matter based on the PWRficient but at least they reignited the dream again.

Simple Buffer Parsing With C99

Monday, April 21st, 2008

A friend of mine asked some questions relating to socket programming which spurred me to create a simple example based on an application I wrote a while back. It’s pretty basic stuff but I decided to post it here in case anyone has any feedback to offer.

I use flexible arrays where suitable so warm up your C99-compilers. There is virtually no error checking done in the example so be vary, also I didn’t compile it. ;)

static const uint32_t PROTOCOL_MAGIC=0xdead001;
struct HelloHeader {
    uint32_t magic;
    uint32_t version;
};

enum Command {
    Command_NONE,
    Command_FILE_LIST,
    Command_GET_FILE,
};

struct CmdHeader {
    uint32_t cmd;
};

struct File {
    char name[256];
    uint64_t size;
};

struct FileList {
    uint32_t numFiles;
    File[] files;
};

struct GetFile {
    uint64_t len;
    /* null-terminated filename followed by data */
    char[256] name;
    char[] data;
};

uint64_t ntohll(uint64_t n)
{
#ifdef BIG_ENDIAN
    return n;
#else
    return (((uint64_t) ntohl(n)) << 32) + ntohl(n >> 32);
#endif
}

char* processCommand000301(char* buffer, size_t bufferLen)
{
    /* … */
}

char* processCommand010000(char* buffer, size_t bufferLen)
{
    char* ptr = buffer;

    struct CmdHeader* commandHeader = (struct CmdHeader*) ptr;
    commandHeader->cmd = ntohl(commandHeader->cmd);
    ptr += sizeof(struct CmdHeader);
    switch (commandHeader->cmd) {
        case Command_FILE_LIST: {
            struct FileList* fileList = (struct FileList*) ptr;
            fileList->numFiles = ntohl(fileList->numFiles);
            ptr += sizeof(struct FileList);
            for (int i = 0; i < fileList.numFiles; ++i) {
                fileList.files[i].size = ntohll(fileList.files[i].size);
                printf("%s %lld\n", fileList.files[i].name, fileList.files[i].size);
                ptr += sizeof(struct File);
            }
            break;
        }

        case Command_GET_FILE: {
            struct GetFile* getFile = (struct GetFile*) ptr;
            getFile->len = ntohll(getFile->len);
            FILE* file = fopen(getFile.name, “w”);
            fwrite(ptr, 1, getFile.len, file);
            ptr += getFile.len;
            fclose(file);
            break;
        }

        default:
            /* Unrecognized command! */
            return NULL;
    }

    return ptr;
}

int processBuffer(char* buffer, size_t bufferLen)
{
    char* ptr = buffer;

    struct HelloHeader* helloHeader = (struct HelloHeader*) buffer;
    helloHeader->magic = ntohl(helloHeader->magic);
    helloHeader->version = ntohl(helloHeader->version);
    if (helloHeader->magic != PROTOCOL_MAGIC) {
        /* Invalid header! */
        return -1;
    }
    ptr += sizeof(struct HelloHeader);

    while (ptr < (buffer + bufferLen)) {
        switch (helloHeader->version) {
            case 0×00010000:
                /* version 1.0.0 */
                ptr = processCommand010000(buffer, (size_t) ptr - buffer);
                break;

            case 0×00000301:
                /* version 0.3.1 */
                ptr = processCommand000301(buffer, (size_t) ptr - buffer);
                break;

            default:
                /* Unsupported version! */
                return -1;
        }
    }
    return 0;
}

P.S. I’m impressed by WordPress’ ability to consistently botch preformatted text when using the WYSIWYG editor. D.S.

Terrain rendering in Ada

Monday, April 7th, 2008

A while ago I added another old project of mine to the projects page but I neglected to post about it.

The project is based on an old school project of mine from the university. It’s a terrain rendering engine written in Ada which was intended to be capable of handling very large terrains of very high detail, +/- 1 meter at the maximum zoom level if I recall correctly.

Since at the time the few OpenGL-bindings that existed for Ada were highly outdated and of varying quality I quickly decided I had to remedy the situation myself. It resulted in the AdaOpenGL project which to this very day, even though I haven’t updated it in over four years, still has a significant amount of downloads (according to SourceForge statistics). People have even tracked me down and called me personally about it, which was a first for me. For these very reasons I often have a guilty conscience for not bringing the project up to date. Two developers have offered to assist but neither of them every produced any releases.

After I had a viable OpenGL-binding I started on the terrain engine itself. As you might suspect I spent a lot of time on the binding and based on the little time I had left I decided to only implement a basic scene graph for the terrain engine. The idea was that someone else would pick up where I left off but as it turned out the company I did the project with never asked for my source code, which I found rather weird considering their initial enthusiasm.

I gave the project the name AdaTerrainEngine as I cannot recall what I initially named it. The data files belong to the company which I did the project with so I cannot release them. I don’t really remember how useful the source code is but at least it should provide a basic foundation for anyone who is doing OpenGL work in Ada.
The terrain engine is LGPL-licensed and AdaOpenGL is BSD-licensed.

P.S. I blatantly stole the design for the AdaOpenGL-site from an awesome CSS tutorial. After I finished the page I realized I forgot to credit the original author and I couldn’t find the site again. If you have any idea who did this please let me know! D.S.