0

I need a small, like a two pieced, version of an AES encryption. I googled and found AES - Advanced Encryption Standard (source code), but the code seems to be written for Windows and I need a multi-platform one.

Is there any other small version of an AES encrpytion known or a fix for the used functions which seem to be unknown on Linux?

My compiler says that those are unknown functions:

./aes/AES.cpp:198:17: error: ‘_rotl’ was not declared in this scope
./aes/AES.cpp:608:20: error: ‘_rotr’ was not declared in this scope

I also got:

./aes/AES.cpp:764:34: error: ‘memset’ was not declared in this scope
./aes/AES.cpp:770:36: error: ‘memcpy’ was not declared in this scope

As those should be known, considering those includes:

#include "AES.hpp"
#include <assert.h>
#include <stdio.h>
#include <cstdio>
#include <cstdlib>
#include <fstream>
#include <iostream>
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Sim
  • 4,199
  • 4
  • 39
  • 77

3 Answers3

4

Use a well-tested crypto library, like cryptlib or OpenSSL, instead of some random snippets found on 40th page of search results. Depending on what you're doing, you probably also should be using higher-level constructs rather than AES directly.

Cat Plus Plus
  • 125,936
  • 27
  • 200
  • 224
  • well i just need some encryption, nothing fancy. Nothing really serious. It is just a small project i am doing to stay in shape. So i favor something small even though it might not be as good. – Sim Sep 29 '11 at 16:47
  • 2
    Even if this is *really* just to "stay in shape" and you'll never unleash this on anyone else, you're still not doing yourself a favour by doing something half-assed like that. If you want a quick and small library, check out `libmcrypt` or something like that. – Kerrek SB Sep 29 '11 at 17:42
0

since this comes up high in a google search for that error, here's what I did for my program which was refusing to compile on an x64 CentOS system that lacks ia32intrin.h:

#if !defined(_rotr) && (defined(__i386__) || defined(__x86_64__))
static inline unsigned int _rotr(unsigned int n, const int count) {
 asm volatile (
  "rorl %1, %0;"
  : "=r" (n)
  : "nI" (count), "0" (n)
 );
 return n;
}
#endif

as avakar mentioned, you need to include cstring, or alternatively string.h, to get memset and memcpy.

the code for _rotl would be identical except for the opcode mnemonic, which would be roll.

jcomeau_ictx
  • 37,688
  • 6
  • 92
  • 107
0

The reference implementation for AES can be found here: http://www.efgh.com/software/rijndael.htm. The main source file only includes <stdio.h>, but it doesn't even depend on that; you should have absolutely no problem using it on any platform.

avakar
  • 32,009
  • 9
  • 68
  • 103