我有一个加密库,我用于mbed LPC1768微控制器。我现在正在尝试将相同的加密库编译为使用STM32F401CDU6微控制器的Espruino Pico的自定义固件。但是,我收到多个编译错误,我不知道如何使用gcc-arm-none-eabi修复这些错误以成功编译固件。
我的编译环境包括运行Ubuntu 14.04作为客户操作系统的VirtualBox,我使用gcc-arm-none-eabi来自定义编译Espruino Pico固件。
编译错误:
CC libs/crypto/jswrap_aes_cbc.o
In file included from libs/crypto/cipher/BlockCipher.h:4:0,
from libs/crypto/cipher/AES.h:4,
from libs/crypto/crypto.h:4,
from libs/crypto/jswrap_aes_cbc.c:1:
libs/crypto/cipher/Cipher.h:12:1: error: unknown type name 'class'
class Cipher
^
libs/crypto/cipher/Cipher.h:13:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token
{
^
In file included from libs/crypto/cipher/AES.h:4:0,
from libs/crypto/crypto.h:4,
from libs/crypto/jswrap_aes_cbc.c:1:
libs/crypto/cipher/BlockCipher.h:13:1: error: unknown type name 'class'
class BlockCipher : public Cipher
^
libs/crypto/cipher/BlockCipher.h:13:19: error: expected '=', ',', ';', 'asm' or '__attribute__' before ':' token
class BlockCipher : public Cipher
^
In file included from libs/crypto/crypto.h:4:0,
from libs/crypto/jswrap_aes_cbc.c:1:
libs/crypto/cipher/AES.h:13:1: error: unknown type name 'class'
class AES : public BlockCipher
^
libs/crypto/cipher/AES.h:13:11: error: expected '=', ',', ';', 'asm' or '__attribute__' before ':' token
class AES : public BlockCipher
^
libs/crypto/jswrap_aes_cbc.c: In function 'jswrap_aes_cbc':
libs/crypto/jswrap_aes_cbc.c:25:5: error: unknown type name 'AES'
AES myAES(AES_128, myKEY, myIV, CBC_MODE); // specify all params, look at BlockCipher.h for modes
^
libs/crypto/jswrap_aes_cbc.c:25:5: warning: parameter names (without types) in function declaration
libs/crypto/jswrap_aes_cbc.c:28:10: error: request for member 'encrypt' in something not a structure or union
myAES.encrypt(data, data, 0x80); // same in and out buffer can be used
^
libs/crypto/jswrap_aes_cbc.c:39:10: error: request for member 'decrypt' in something not a structure or union
myAES.decrypt(data, data, 0x80);
^
make: *** [libs/crypto/jswrap_aes_cbc.o] Error 1
Build failed
jswrap_aes_cbc.c文件:
#include "crypto.h"
#include "jswrap_aes_cbc.h"
#include "jsinteractive.h"
unsigned char myKEY[16] = { 'm', 'n', 'b', 'v', 'c', 'x', 'z', 'l', 'k', 'j', 'h', 'g', 'f', 'd', 's', 'a' };
unsigned char myIV[16] = { 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'p', 'o', 'i', 'u', 'y', 't', 'r' };
unsigned char data[0x80] = { };
// Let's define the JavaScript class that will contain our `aescbc()` method. We'll call it `Crypto`
/*JSON{
"type" : "class",
"class" : "Crypto"
}*/
// Now, we define the `jswrap_aes_cbc` to be a `staticmethod` on the `Crypto` class
/*JSON{
"type" : "staticmethod",
"class" : "Crypto",
"name" : "aescbc",
"generate" : "jswrap_aes_cbc"
}*/
void jswrap_aes_cbc()
{
AES myAES(AES_128, myKEY, myIV, CBC_MODE); // specify all params, look at BlockCipher.h for modes
jsiConsolePrint("\r\n\r\nFirst run\r\n");
myAES.encrypt(data, data, 0x80); // same in and out buffer can be used
jsiConsolePrint("\r\nEncrypted: ");
/*for(char i=0; i<0x80; i++)
{
//if(i%16==0) pc.printf("\r\n");
//jsiConsolePrint(data[i]);
}*/
jsiConsolePrint("\r\nDecrypted again: ");
myAES.decrypt(data, data, 0x80);
/*for(char i=0; i<0x80; i++)
{
//if(i%16==0) pc.printf("\r\n");
//jsiConsolePrint(data[i]);
}*/
}
BlockCipher.h文件:
#ifndef BLOCK_CIPHER_H
#define BLOCK_CIPHER_H
#include "Cipher.h"
enum BLOCK_CIPHER_MODE
{
ECB_MODE,
CBC_MODE,
PCBC_MODE
};
class BlockCipher : public Cipher
{
public :
BlockCipher(uint32_t bs, BLOCK_CIPHER_MODE m, uint8_t *iv = 0);
virtual ~BlockCipher();
virtual CIPHER_TYPE getType() const;
uint32_t getBlockSize() const;
void setIV(uint8_t *iv);
virtual void encrypt(uint8_t *out, uint8_t *in, uint32_t length);
virtual void decrypt(uint8_t *out, uint8_t *in, uint32_t length);
protected :
virtual void encryptBlock(uint8_t *out, uint8_t *in) = 0;
virtual void decryptBlock(uint8_t *out, uint8_t *in) = 0;
private :
uint32_t blockSize;
BLOCK_CIPHER_MODE mode;
uint8_t *IV;
uint8_t *tmpIV;
uint8_t *tmpdatain;
uint8_t *tmpdata;
};
#endif
AES.h文件:
#ifndef AES_H
#define AES_H
#include "BlockCipher.h"
enum AES_TYPE
{
AES_128 = 4,
AES_192 = 6,
AES_256 = 8
};
class AES : public BlockCipher
{
public :
AES(const AES_TYPE type, uint8_t *key);
AES(const AES_TYPE type, uint8_t *key, uint8_t *iv, BLOCK_CIPHER_MODE m=CBC_MODE);
void keyExpansion(uint8_t *key);
private :
virtual void encryptBlock(uint8_t *out, uint8_t *in);
virtual void decryptBlock(uint8_t *out, uint8_t *in);
uint32_t rotWord(uint32_t w);
uint32_t invRotWord(uint32_t w);
uint32_t subWord(uint32_t w);
void subBytes();
void invSubBytes();
void shiftRows();
void invShiftRows();
void mul(uint8_t *r);
void invMul(uint8_t *r);
void mixColumns();
void invMixColumns();
void addRoundKey(int round);
uint8_t state[16];
uint32_t w[60];
uint8_t nr,nk;
};
#endif