title: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token {
body: <p>I have an encryption library that I am using for the mbed LPC1768 micro-controller.  I am now attempting to compile that same encryption library into custom firmware for the Espruino Pico which uses the STM32F401CDU6 micro-controller. However, I am receiving multiple compiling errors and I am not sure how to fix those errors to successfully compile the firmware using gcc-arm-none-eabi.  </p>
  
  <p>My compiling environment consists of VirtualBox running Ubuntu 14.04 as the guest OS and I am using gcc-arm-none-eabi to custom compile the Espruino Pico firmware.</p>
  
  <p><strong>Compiling errors:</strong></p>
  
  <pre><code>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
  </code></pre>
  
  <p><strong>jswrap_aes_cbc.c file:</strong></p>
  
  <pre><code>#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&lt;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&lt;0x80; i++)
      {
          //if(i%16==0) pc.printf("\r\n");
          //jsiConsolePrint(data[i]);
      }*/
  }
  </code></pre>
  
  <p><strong>BlockCipher.h file:</strong></p>
  
  <pre><code>#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
  </code></pre>
  
  <p><strong>AES.h file:</strong></p>
  
  <pre><code>#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
  </code></pre>