Sim
Sim

Reputation: 4194

AES cryption quellcode

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>

Upvotes: 0

Views: 713

Answers (3)

jcomeau_ictx
jcomeau_ictx

Reputation: 38492

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.

Upvotes: 0

avakar
avakar

Reputation: 32655

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.

Upvotes: 0

Cat Plus Plus
Cat Plus Plus

Reputation: 129934

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.

Upvotes: 4

Related Questions