Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 21 of 21

Thread: TweetNaCl crypto library compiling on Teensy vs Arduino

  1. #1

    TweetNaCl crypto library compiling on Teensy vs Arduino

    There is a nice looking crypto library in small size. Best one so far I've found for Teensy/Arduino. Other suggestions are welcome if you have some! This one has one header and one source file. See here. However, when compiling in Arduino IDE, it can't handle this:

    #define FOR(i,n) for (i = 0;i < n;++i)

    It says:

    Arduino: 1.8.5 (Windows 10), TD: 1.41, Board: "Teensy 3.5, Serial, 120 MHz, Faster, US English"

    In file included from C:\Users\****\Documents\Arduino\libraries\TweetNaC I/tweetnacl.h:1:0,

    from C:\Users\****\Documents\Arduino\TweetNACLtest2\Twe etNACLtest2.ino:1:

    C:\Users\****\Documents\Arduino\libraries\TweetNaC I/tweetnacl.c:13:3: error: uninitialized const '_0' [-fpermissive]

    _0[16],

    ^

    C:\Users\****\Documents\Arduino\libraries\TweetNaC I/tweetnacl.c:16:3: error: uninitialized const 'gf0' [-fpermissive]

    gf0,

    ^

    C:\Users\****\Documents\Arduino\libraries\TweetNaC I/tweetnacl.c: In function 'int vn(const u8*, const u8*, int)':

    C:\Users\****\Documents\Arduino\libraries\TweetNaC I/tweetnacl.c:2:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]

    #define FOR(i,n) for (i = 0;i < n;++i)

    ^

    C:\Users\****\Documents\Arduino\libraries\TweetNaC I/tweetnacl.c:57:3: note: in expansion of macro 'FOR'

    FOR(i,n) d |= x[i]^y[i];

    ^

    In file included from C:\Users\****\Documents\Arduino\libraries\TweetNaC I/tweetnacl.h:1:0,

    from C:\Users\****\Documents\Arduino\TweetNACLtest2\Twe etNACLtest2.ino:1:

    C:\Users\****\Documents\Arduino\libraries\TweetNaC I/tweetnacl.c: At global scope:

    C:\Users\****\Documents\Arduino\libraries\TweetNaC I/tweetnacl.c:123:29: error: initializer-string for array of chars is too long [-fpermissive]

    static const u8 sigma[16] = "expand 32-byte k";

    ^

    In file included from C:\Users\****\Documents\Arduino\libraries\TweetNaC I/tweetnacl.h:1:0,

    from C:\Users\****\Documents\Arduino\TweetNACLtest2\Twe etNACLtest2.ino:1:

    C:\Users\****\Documents\Arduino\libraries\TweetNaC I/tweetnacl.c: In function 'int crypto_sign(u8*, u64*, const u8*, u64, const u8*)':

    C:\Users\****\Documents\Arduino\libraries\TweetNaC I/tweetnacl.c:2:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]

    #define FOR(i,n) for (i = 0;i < n;++i)

    ^

    C:\Users\****\Documents\Arduino\libraries\TweetNaC I/tweetnacl.c:723:3: note: in expansion of macro 'FOR'

    FOR(i,n) sm[64 + i] = m[i];

    ^

    C:\Users\****\Documents\Arduino\libraries\TweetNaC I/tweetnacl.c: In function 'int crypto_sign_open(u8*, u64*, const u8*, u64, const u8*)':

    C:\Users\****\Documents\Arduino\libraries\TweetNaC I/tweetnacl.c:2:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]

    #define FOR(i,n) for (i = 0;i < n;++i)

    ^

    C:\Users\****\Documents\Arduino\libraries\TweetNaC I/tweetnacl.c:790:3: note: in expansion of macro 'FOR'

    FOR(i,n) m[i] = sm[i];

    ^

    C:\Users\****\Documents\Arduino\libraries\TweetNaC I/tweetnacl.c:2:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]

    #define FOR(i,n) for (i = 0;i < n;++i)

    ^

    C:\Users\****\Documents\Arduino\libraries\TweetNaC I/tweetnacl.c:802:5: note: in expansion of macro 'FOR'

    FOR(i,n) m[i] = 0;

    ^

    C:\Users\****\Documents\Arduino\libraries\TweetNaC I/tweetnacl.c:2:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]

    #define FOR(i,n) for (i = 0;i < n;++i)

    ^

    C:\Users\****\Documents\Arduino\libraries\TweetNaC I/tweetnacl.c:806:3: note: in expansion of macro 'FOR'

    FOR(i,n) m[i] = sm[i + 64];

    ^

    Error compiling for board Teensy 3.5.

    This report would have more information with
    "Show verbose output during compilation"
    option enabled in File -> Preferences.

    and seems to complain for each time it is used in the program. Yet this problem doesn't affect Arduino Uno, since compilation for that platform works correctly (besides a few errors).

    Whats wrong?

    Code:

    #include <tweetnacl.h>

    void setup() {
    // put your setup code here, to run once:

    }

    void loop() {
    // put your main code here, to run repeatedly:

    }
    Last edited by kk12; 02-22-2018 at 09:50 PM. Reason: added whole error log

  2. #2
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,336
    you have other errors, post it here, thats a warning and not necessarily the problem of while compile failed

  3. #3
    Thanks. Didn't notice...
    Sidenote: I had to add into header: #include <tweetnacl.c> and comment //#include "tweetnacl.h" in .c file

  4. #4
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    21,830
    I tried it just now. Compiles without any errors or even warnings.

    Click image for larger version. 

Name:	sc.png 
Views:	75 
Size:	38.2 KB 
ID:	13039

    All I did was create a "tweetnacl" folder inside my libraries folder and put those 2 files into it. Then I just copied your empty sketch into Arduino and clicked Verify.

    No errors here, as you can see in the screenshot.

  5. #5
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    21,830
    Quote Originally Posted by kk12 View Post
    Sidenote: I had to add into header: #include <tweetnacl.c> and comment //#include "tweetnacl.h" in .c file
    Of course it's not going to work if you do that.

  6. #6
    I followed your instructions and compilation works ok. Thank you. Still working on to make functions work, as several complain about undefined references.

    Code:
    #include <tweetnacl.h>
    
    unsigned char ciphertext[512]   =   {0};
    unsigned char key[32]           =   {43, 1, 25, 21, 56, 7, 21, 56, 7, 78, 9, 9, 56, 7, 78, 9,
                                         54, 67, 13, 89, 244, 65, 73, 213, 51, 42, 1, 5, 12, 12, 56, 212
                                        };
    unsigned char nonce[24]         =   {5, 4, 6, 7, 1, 3, 8, 9, 24, 4, 6, 5, 7, 3, 21, 3};
    unsigned char message[128]      =   {'s', 'e', 'c', 'r', 'e', 't', ' ', 'm', 'e', 's', 's', 'a', 'g', 'e'};
    unsigned long long mlen1         =   14;
    unsigned char authenticator[32] =   {0};
    const unsigned char k[crypto_auth_KEYBYTES] = {43, 1, 25, 21, 56, 7, 21, 56, 7, 78, 9, 9, 56, 7, 78, 9,
                                                   54, 67, 13, 89, 244, 65, 73, 213, 51, 42, 1, 5, 12, 12, 56, 212
                                                  };
    const unsigned char m[14] = {'s', 'e', 'c', 'r', 'e', 't', ' ', 'm', 'e', 's', 's', 'a', 'g', 'e'};
    unsigned long long mlen         =   14;
    unsigned char a[crypto_auth_BYTES] = {0};
    int ret                         =   0;
    
    void setup() {}
    void loop() {
      // ret = crypto_stream_xor(&ciphertext[0],&message[0],mlen1,&nonce[0],&key[0]); // uses xsalsa20
      /*
        C:\Users\**\Documents\Arduino\TweetNACLtest3/TweetNACLtest3.ino:12: undefined reference
        to `crypto_stream_xsalsa20_tweet_xor(unsigned char*, unsigned char const*, unsigned long long,
        unsigned char const*, unsigned char const*)' collect2.exe: error: ld returned 1 exit status
      */
      // ret = crypto_auth(authenticator, message, mlen1, key); // uses HMAC-SHA-512-256
      // undefined reference to ...
      ret = crypto_auth(a, m, mlen, k);
      // undefined reference to ...
    }
    Authentication
    Encryption

  7. #7
    How to debug this error and/or are there better options for crypto library, that include symmetric encryption and authentication?

  8. #8
    Senior Member+ manitou's Avatar
    Join Date
    Jan 2013
    Posts
    2,496
    some TLS discussions at https://forum.pjrc.com/threads/29056...-secure-https)

    T3.5/3.6 has hardware crypto acceleration, but i don't know of anyone that has incorporated it into a library
    https://forum.pjrc.com/threads/34808...l=1#post108621

    wolfssl for Arduino
    Last edited by manitou; 06-13-2019 at 09:41 PM.

  9. #9
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    21,830
    Early in the beta testing, I ported Freescale's example code to an Arduino library format.

    https://github.com/PaulStoffregen/CryptoAccel

    But it's only a couple symetric cipherals and a few hashes. The functions are only very low level stuff. So far I've not heard anyone confirmed to have actually used it in a project.

  10. #10
    I took TweetNaCI's one-time authentication function by hand along with its dependencies and put them in same file as main() and loop(). It seems to work. Next project is to take authenticated encryption with Salsa20. I think the problem is with the header file...

    Edit: Encryption is good but not enough without authentication: https://security.stackexchange.com/q...-to-encryption
    Last edited by kk12; 02-24-2018 at 07:25 PM.

  11. #11
    Senior Member+ manitou's Avatar
    Join Date
    Jan 2013
    Posts
    2,496
    fyi, here's a version https://github.com/rjw245/crypto-in-a-box
    that worked for me on T3.2 (tested with included python scripts)

    tweetnacl.h and .c have pragma's to handle C++
    Last edited by manitou; 02-26-2018 at 11:42 AM.

  12. #12
    Quote Originally Posted by manitou View Post
    fyi, here's a version https://github.com/rjw245/crypto-in-a-box
    that worked for me on T3.2 (tested with included python scripts)

    tweetnacl.h and .c have pragma's to handle C++
    Thanks. I will see it, if I can't make authenticated Salsa20 work. Anyway rjw245... is spread across tens of files that are harder to examine, compared to one header and c-files in TweetNaCI. Extracting functions from TweetNaCI feels more convenient and produces less extra code.

  13. #13
    Senior Member+ manitou's Avatar
    Join Date
    Jan 2013
    Posts
    2,496
    yep, the state machine to manage the binary data exchange over the serial port for testing adds complexity, but the nacl stuff is in state_encrypt.cpp and state_decrypt.cpp with the function crypto_secretbox() using the nonce and secret key

    (It is assumed Alice and Bob have each generated the secret key using the public/private key pairs)

    A simpler example (using the tweetnacl.h and .c from rjw245 github)
    Code:
    // standalone test
    #include "tweetnacl.h"
    static const uint8_t secretkey[crypto_secretbox_KEYBYTES] = {
      0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
      0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
      0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
      0, 1
    };
    
    static const uint8_t nonce[crypto_secretbox_NONCEBYTES] = {
      0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
      0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
      0, 1, 2, 3
    };
    
    // Need crypto_secretbox_ZEROBYTES of room at the beginning
    // AND crypto_secretbox_BOXZEROBYTES at the end.
    // The crypto_secretbox_BOXZEROBYTES allows an encrypted input to fit
    // in the buffer when storage STARTS at index [crypto_secretbox_ZEROBYTES]
    #define BUFFER_SIZE (256 + \
                         crypto_secretbox_ZEROBYTES + \
                         crypto_secretbox_BOXZEROBYTES)
    
    static unsigned char input_buffer[BUFFER_SIZE], outdata[BUFFER_SIZE];
    static uint8_t input_len = 0;
    
    static const uint8_t msg[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
    
    void setup() {
      int r;
    
      Serial.begin(9600);
      while (!Serial);
      memset(input_buffer, 0, sizeof(input_buffer));
      input_len = sizeof(msg);
      Serial.println(input_len);
      memcpy(input_buffer + crypto_secretbox_ZEROBYTES, msg, input_len);
      // encrypt
      r = crypto_secretbox(outdata,
                           input_buffer,
                           input_len + crypto_secretbox_ZEROBYTES,
                           nonce,
                           secretkey);
      Serial.print("r "); Serial.println(r);
      for (int i = 0; i < 4; i++) Serial.println(outdata[crypto_secretbox_ZEROBYTES + i], HEX);
      
      //decrypt
      memset(input_buffer, 0, sizeof(input_buffer));
      r = crypto_secretbox_open(input_buffer,
                                outdata,
                                input_len + crypto_secretbox_ZEROBYTES,
                                nonce,
                                secretkey);
      Serial.print("r "); Serial.println(r);
      for (int i = 0; i < 4; i++) Serial.println(input_buffer[crypto_secretbox_ZEROBYTES + i], HEX);
      r = memcmp(msg, input_buffer + crypto_secretbox_ZEROBYTES, input_len);
      Serial.print("result "); Serial.println(r);
    }
    void loop() {}
    Code:
           nacl perf (us)  13 bytes       100         200
                       enc     dec
         T3.2@96hz     319 us  563 us   901 1153   1378 1627
         T3.2@120mhz   256 us  456 us   727  928   1110 1309
         T3.5@120mhz   252     449      720  916   1099 1297
         T3.6@180mhz   170     298      481  608    734  860
         T4@600mhz      30      56       81  105    119  144
         M7@600mhz      50      60
         K64f@120      245     437
         STM32L476     460     833   dragonfly @80mhz
         DUE@84mhz     655    1160
         maple@72mhz   695    1227 -Os   -O3 196 286 us
         LC@48mhz      922    1620
         m4@120mhz     301     527   SAMD51
         esp32@240     270     292
         UNO@16mhz   20484   37004
         T2@16mhz    20756   37392
    Last edited by manitou; 06-13-2019 at 09:33 PM.

  14. #14
    The first line below ends up in compilation error: "initializer-string for array of chars is too long [-fpermissive]"
    Second line compiles just fine. I guess it has to do with null termination in the first one? link But how did you manage to compile it, since Github version does use the first option.

    // static const u8 sigma[16] = "expand 32-byte k";
    // static const u8 sigma[16] = {'e','x','p','a','n','d',' ','3','2','-','b','y','t','e',' ','k'};

    Btw. Nice example! Just debugging my own code by using that as reference.
    Last edited by kk12; 02-27-2018 at 04:55 AM.

  15. #15
    Senior Member+ manitou's Avatar
    Join Date
    Jan 2013
    Posts
    2,496
    I get no compile errors using tweetncal* from https://github.com/rjw245/crypto-in-a-box

    I'm using IDE 1.8.4/1.40

    EDIT: you get a compile error if the declaration is in a .ino or .cpp filea (g++). but it's OK in the .c file tweetncal.c (gcc)

  16. #16
    Alright. Thats the reason why.. I have everything in this .ino file.

    This is the bare minimum from TweetNaCl I'm using successfully to do authenticated encryption. 251 lines of code.

    Code:
    #define crypto_secretbox_xsalsa20poly1305_tweet_KEYBYTES 32
    #define crypto_secretbox_xsalsa20poly1305_tweet_NONCEBYTES 24
    #define crypto_secretbox_xsalsa20poly1305_tweet_ZEROBYTES 32
    #define crypto_secretbox_xsalsa20poly1305_tweet_BOXZEROBYTES 16
    
    #define crypto_secretbox_xsalsa20poly1305_KEYBYTES crypto_secretbox_xsalsa20poly1305_tweet_KEYBYTES
    #define crypto_secretbox_xsalsa20poly1305_NONCEBYTES crypto_secretbox_xsalsa20poly1305_tweet_NONCEBYTES
    #define crypto_secretbox_xsalsa20poly1305_ZEROBYTES crypto_secretbox_xsalsa20poly1305_tweet_ZEROBYTES
    #define crypto_secretbox_xsalsa20poly1305_BOXZEROBYTES crypto_secretbox_xsalsa20poly1305_tweet_BOXZEROBYTES
    
    #define crypto_secretbox_PRIMITIVE "xsalsa20poly1305"
    #define crypto_secretbox crypto_secretbox_xsalsa20poly1305
    #define crypto_secretbox_open crypto_secretbox_xsalsa20poly1305_open
    #define crypto_secretbox_KEYBYTES crypto_secretbox_xsalsa20poly1305_KEYBYTES
    #define crypto_secretbox_NONCEBYTES crypto_secretbox_xsalsa20poly1305_NONCEBYTES
    #define crypto_secretbox_ZEROBYTES crypto_secretbox_xsalsa20poly1305_ZEROBYTES
    #define crypto_secretbox_BOXZEROBYTES crypto_secretbox_xsalsa20poly1305_BOXZEROBYTES
    #define crypto_secretbox_IMPLEMENTATION crypto_secretbox_xsalsa20poly1305_IMPLEMENTATION
    #define crypto_secretbox_VERSION crypto_secretbox_xsalsa20poly1305_VERSION
    
    #define FOR(i,n) for (i = 0;i < n;++i)
    #define sv static void
    
    typedef unsigned char u8;
    typedef unsigned long u32;
    typedef unsigned long long u64;
    typedef long long i64;
    typedef i64 gf[16];
    extern void randombytes(u8 *,u64);
    static u32 L32(u32 x,int c) { return (x << c) | ((x&0xffffffff) >> (32 - c)); }
    // static const u8 sigma[16] = "expand 32-byte k";
    static const u8 sigma[16] = {'e','x','p','a','n','d',' ','3','2','-','b','y','t','e',' ','k'};
    
    
    static u32 ld32(const u8 *x)
    {
      u32 u = x[3];
      u = (u<<8)|x[2];
      u = (u<<8)|x[1];
      return (u<<8)|x[0];
    }
    
    sv st32(u8 *x,u32 u)
    {
      int i;
      FOR(i,4) { x[i] = u; u >>= 8; }
    }
    
    sv add1305(u32 *h,const u32 *c)
    {
      u32 j,u = 0;
      FOR(j,17) {
        u += h[j] + c[j];
        h[j] = u & 255;
        u >>= 8;
      }
    }
    static const u32 minusp[17] = {
      5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 252
    } ;
    
    sv core(u8 *out,const u8 *in,const u8 *k,const u8 *c,int h)
    {
      u32 w[16],x[16],y[16],t[4];
      int i,j,m;
    
      FOR(i,4) {
        x[5*i] = ld32(c+4*i);
        x[1+i] = ld32(k+4*i);
        x[6+i] = ld32(in+4*i);
        x[11+i] = ld32(k+16+4*i);
      }
    
      FOR(i,16) y[i] = x[i];
    
      FOR(i,20) {
        FOR(j,4) {
          FOR(m,4) t[m] = x[(5*j+4*m)%16];
          t[1] ^= L32(t[0]+t[3], 7);
          t[2] ^= L32(t[1]+t[0], 9);
          t[3] ^= L32(t[2]+t[1],13);
          t[0] ^= L32(t[3]+t[2],18);
          FOR(m,4) w[4*j+(j+m)%4] = t[m];
        }
        FOR(m,16) x[m] = w[m];
      }
    
      if (h) {
        FOR(i,16) x[i] += y[i];
        FOR(i,4) {
          x[5*i] -= ld32(c+4*i);
          x[6+i] -= ld32(in+4*i);
        }
        FOR(i,4) {
          st32(out+4*i,x[5*i]);
          st32(out+16+4*i,x[6+i]);
        }
      } else
        FOR(i,16) st32(out + 4 * i,x[i] + y[i]);
    }
    
    int crypto_core_salsa20(u8 *out,const u8 *in,const u8 *k,const u8 *c)
    {
      core(out,in,k,c,0);
      return 0;
    }
    
    int crypto_stream_salsa20_xor(u8 *c,const u8 *m,u64 b,const u8 *n,const u8 *k)
    {
      u8 z[16],x[64];
      u32 u,i;
      if (!b) return 0;
      FOR(i,16) z[i] = 0;
      FOR(i,8) z[i] = n[i];
      while (b >= 64) {
        crypto_core_salsa20(x,z,k,sigma);
        FOR(i,64) c[i] = (m?m[i]:0) ^ x[i];
        u = 1;
        for (i = 8;i < 16;++i) {
          u += (u32) z[i];
          z[i] = u;
          u >>= 8;
        }
        b -= 64;
        c += 64;
        if (m) m += 64;
      }
      if (b) {
        crypto_core_salsa20(x,z,k,sigma);
        FOR(i,b) c[i] = (m?m[i]:0) ^ x[i];
      }
      return 0;
    }
    
    int crypto_onetimeauth(u8 *out,const u8 *m,u64 n,const u8 *k)
    {
      u32 s,i,j,u,x[17],r[17],h[17],c[17],g[17];
    
      FOR(j,17) r[j]=h[j]=0;
      FOR(j,16) r[j]=k[j];
      r[3]&=15;
      r[4]&=252;
      r[7]&=15;
      r[8]&=252;
      r[11]&=15;
      r[12]&=252;
      r[15]&=15;
    
      while (n > 0) {
        FOR(j,17) c[j] = 0;
        for (j = 0;(j < 16) && (j < n);++j) c[j] = m[j];
        c[j] = 1;
        m += j; n -= j;
        add1305(h,c);
        FOR(i,17) {
          x[i] = 0;
          FOR(j,17) x[i] += h[j] * ((j <= i) ? r[i - j] : 320 * r[i + 17 - j]);
        }
        FOR(i,17) h[i] = x[i];
        u = 0;
        FOR(j,16) {
          u += h[j];
          h[j] = u & 255;
          u >>= 8;
        }
        u += h[16]; h[16] = u & 3;
        u = 5 * (u >> 2);
        FOR(j,16) {
          u += h[j];
          h[j] = u & 255;
          u >>= 8;
        }
        u += h[16]; h[16] = u;
      }
    
      FOR(j,17) g[j] = h[j];
      add1305(h,minusp);
      s = -(h[16] >> 7);
      FOR(j,17) h[j] ^= s & (g[j] ^ h[j]);
    
      FOR(j,16) c[j] = k[j + 16];
      c[16] = 0;
      add1305(h,c);
      FOR(j,16) out[j] = h[j];
      return 0;
    }
    
    int crypto_stream_xor(u8 *c,const u8 *m,u64 d,const u8 *n,const u8 *k)
    {
      u8 s[32];
      crypto_core_hsalsa20(s,n,k,sigma);
      return crypto_stream_salsa20_xor(c,m,d,n+16,s);
    }
    
    int crypto_core_hsalsa20(u8 *out,const u8 *in,const u8 *k,const u8 *c)
    {
      core(out,in,k,c,1);
      return 0;
    }
    
    int crypto_onetimeauth_verify(const u8 *h,const u8 *m,u64 n,const u8 *k)
    {
      u8 x[16];
      crypto_onetimeauth(x,m,n,k);
      return crypto_verify_16(h,x);
    }
    static int vn(const u8 *x,const u8 *y,int n)
    {
      u32 i,d = 0;
      FOR(i,n) d |= x[i]^y[i];
      return (1 & ((d - 1) >> 8)) - 1;
    }
    
    int crypto_verify_16(const u8 *x,const u8 *y)
    {
      return vn(x,y,16);
    }
    
    int crypto_stream(u8 *c,u64 d,const u8 *n,const u8 *k)
    {
      u8 s[32];
      crypto_core_hsalsa20(s,n,k,sigma);
      return crypto_stream_salsa20(c,d,n+16,s);
    }
    
    int crypto_stream_salsa20(u8 *c,u64 d,const u8 *n,const u8 *k)
    {
      return crypto_stream_salsa20_xor(c,0,d,n,k);
    }
    
    int crypto_secretbox(u8 *c,const u8 *m,u64 d,const u8 *n,const u8 *k)
    {
      int i;
      if (d < 32) return -1;
      crypto_stream_xor(c,m,d,n,k);
      crypto_onetimeauth(c + 16,c + 32,d - 32,c);
      FOR(i,16) c[i] = 0;
      return 0;
    }
    
    int crypto_secretbox_open(u8 *m,const u8 *c,u64 d,const u8 *n,const u8 *k)
    {
      int i;
      u8 x[32];
      if (d < 32) return -1;
      crypto_stream(x,32,n,k);
      if (crypto_onetimeauth_verify(c + 16,c + 32,d - 32,x) != 0) return -1;
      crypto_stream_xor(m,c,d,n,k);
      FOR(i,32) m[i] = 0;
      return 0;
    }
    These functions work after building the key, nonce etc:

    Code:
      ret=crypto_secretbox(c,m,mlen,n,k);
      ret=crypto_secretbox_open(m, c, clen, n, k);
    Also, crypto_onetimeauth(a,m,mlen,k) could be used alone without encryption.

    Thanks to everyone for help and especially manitou for NaCl specific instructions...

  17. #17
    Junior Member
    Join Date
    Oct 2015
    Posts
    19
    You might find the libraries here helpful - https://github.com/trustcrypto/libraries

    OnlyKey uses tweetnacl and a bunch of other crypto libraries that are teensy compatible. Tweetnacl is great but pretty slow, I'm trying to find a library with better performance on ARM, looking into a AVR NaCl.

  18. #18
    Quote Originally Posted by PaulStoffregen View Post
    Early in the beta testing, I ported Freescale's example code to an Arduino library format.

    https://github.com/PaulStoffregen/CryptoAccel

    But it's only a couple symetric cipherals and a few hashes. The functions are only very low level stuff. So far I've not heard anyone confirmed to have actually used it in a project.
    I use it very intensely, for file sizes up to 1mb. I can confirm proper working for AES256-CBC, and SHA256.
    BUT since I update teensy loader from 1.42 to 1.43, CryptoAccel doesn't work any more.(cannot compile)

  19. #19
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    11,534
    Quote Originally Posted by PeterG. View Post
    I use it very intensely, for file sizes up to 1mb. I can confirm proper working for AES256-CBC, and SHA256.
    BUT since I update teensy loader from 1.42 to 1.43, CryptoAccel doesn't work any more.(cannot compile)
    Post the verbose compile output of the failure. Any update to the IDE?

  20. #20
    Quote Originally Posted by defragster View Post
    Post the verbose compile output of the failure. Any update to the IDE?


    IDE from 1.85 --> 1.86
    Teensy Loader 1.42 --> 1.43


    SOURCE
    Code:
    #include <CryptoAccel.h>
    
    
    
    void setup() {
      // put your setup code here, to run once:
    
    }
    
    void loop() {
      // put your main code here, to run repeatedly:
    
    }
    ERROR

    Code:
    /Applications/Arduino.app/Contents/Java/arduino-builder -dump-prefs -logger=machine -hardware /Applications/Arduino.app/Contents/Java/hardware -tools /Applications/Arduino.app/Contents/Java/tools-builder -tools /Applications/Arduino.app/Contents/Java/hardware/tools/avr -built-in-libraries /Applications/Arduino.app/Contents/Java/libraries -libraries /Users/petergilgen/Documents/Arduino/libraries -fqbn=teensy:avr:teensy35:usb=rawhid,speed=120,opt=o1std,keys=de-ch -ide-version=10806 -build-path /var/folders/nk/x6xdd2mn6gl9zdk2ly6rx40w0000gn/T/arduino_build_247437 -warnings=none -build-cache /var/folders/nk/x6xdd2mn6gl9zdk2ly6rx40w0000gn/T/arduino_cache_327049 -verbose /Users/petergilgen/Documents/Arduino/sketch_sep15b/sketch_sep15b.ino
    /Applications/Arduino.app/Contents/Java/arduino-builder -compile -logger=machine -hardware /Applications/Arduino.app/Contents/Java/hardware -tools /Applications/Arduino.app/Contents/Java/tools-builder -tools /Applications/Arduino.app/Contents/Java/hardware/tools/avr -built-in-libraries /Applications/Arduino.app/Contents/Java/libraries -libraries /Users/petergilgen/Documents/Arduino/libraries -fqbn=teensy:avr:teensy35:usb=rawhid,speed=120,opt=o1std,keys=de-ch -ide-version=10806 -build-path /var/folders/nk/x6xdd2mn6gl9zdk2ly6rx40w0000gn/T/arduino_build_247437 -warnings=none -build-cache /var/folders/nk/x6xdd2mn6gl9zdk2ly6rx40w0000gn/T/arduino_cache_327049 -verbose /Users/petergilgen/Documents/Arduino/sketch_sep15b/sketch_sep15b.ino
    Using board 'teensy35' from platform in folder: /Applications/Arduino.app/Contents/Java/hardware/teensy/avr
    Using core 'teensy3' from platform in folder: /Applications/Arduino.app/Contents/Java/hardware/teensy/avr
    Build options changed, rebuilding all
    Detecting libraries used...
    /Applications/Arduino.app/Contents/Java/hardware/teensy/../tools/arm/bin/arm-none-eabi-g++ -E -CC -x c++ -w -g -Wall -ffunction-sections -fdata-sections -nostdlib -fno-exceptions -felide-constructors -std=gnu++14 -Wno-error=narrowing -fno-rtti -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -fsingle-precision-constant -D__MK64FX512__ -DTEENSYDUINO=143 -DARDUINO=10806 -DF_CPU=120000000 -DUSB_RAWHID -DLAYOUT_GERMAN_SWISS -I/Applications/Arduino.app/Contents/Java/hardware/teensy/avr/cores/teensy3 /var/folders/nk/x6xdd2mn6gl9zdk2ly6rx40w0000gn/T/arduino_build_247437/sketch/sketch_sep15b.ino.cpp -o /dev/null
    /Applications/Arduino.app/Contents/Java/hardware/teensy/../tools/arm/bin/arm-none-eabi-g++ -E -CC -x c++ -w -g -Wall -ffunction-sections -fdata-sections -nostdlib -fno-exceptions -felide-constructors -std=gnu++14 -Wno-error=narrowing -fno-rtti -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -fsingle-precision-constant -D__MK64FX512__ -DTEENSYDUINO=143 -DARDUINO=10806 -DF_CPU=120000000 -DUSB_RAWHID -DLAYOUT_GERMAN_SWISS -I/Applications/Arduino.app/Contents/Java/hardware/teensy/avr/cores/teensy3 -I/Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src /var/folders/nk/x6xdd2mn6gl9zdk2ly6rx40w0000gn/T/arduino_build_247437/sketch/sketch_sep15b.ino.cpp -o /dev/null
    /Applications/Arduino.app/Contents/Java/hardware/teensy/../tools/arm/bin/arm-none-eabi-g++ -E -CC -x c++ -w -g -Wall -ffunction-sections -fdata-sections -nostdlib -fno-exceptions -felide-constructors -std=gnu++14 -Wno-error=narrowing -fno-rtti -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -fsingle-precision-constant -D__MK64FX512__ -DTEENSYDUINO=143 -DARDUINO=10806 -DF_CPU=120000000 -DUSB_RAWHID -DLAYOUT_GERMAN_SWISS -I/Applications/Arduino.app/Contents/Java/hardware/teensy/avr/cores/teensy3 -I/Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S -o /dev/null
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:1:2: error: invalid preprocessing directive #*
     #*******************************************************************************
      ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:2:2: error: invalid preprocessing directive #*
     #*******************************************************************************
      ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:4:3: error: invalid preprocessing directive #Copyright
     # Copyright (c) Freescale Semiconductor, Inc 2011.
       ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:6:3: error: invalid preprocessing directive #FILE
     # FILE NAME      : mmcau_aes_functions.s
       ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:7:3: error: invalid preprocessing directive #VERSION
     # VERSION        : $Id: mmcau_aes_functions.s.rca 1.4 Thu Nov 21 14:17:01 2013 b40907 Experimental $
       ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:8:3: error: invalid preprocessing directive #TYPE
     # TYPE           : Source Cortex-Mx assembly library code
       ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:9:3: error: invalid preprocessing directive #DEPARTMENT
     # DEPARTMENT     : MSG R&D Core and Platforms
       ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:10:3: error: invalid preprocessing directive #AUTHOR
     # AUTHOR         : David Schimke
       ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:11:3: error: invalid preprocessing directive #AUTHOR
     # AUTHOR'S EMAIL : David.Schimke@freescale.com
       ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:12:3: error: invalid preprocessing directive #AUTHOR
     # AUTHOR         : Anthony (Teejay) Ciancio
       ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:13:3: error: invalid preprocessing directive #AUTHOR
     # AUTHOR'S EMAIL : teejay.ciancio@freescale.com
       ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:14:3: error: invalid preprocessing directive #--
     # -----------------------------------------------------------------------------
       ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:15:3: error: invalid preprocessing directive #Release
     # Release history
       ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:16:3: error: invalid preprocessing directive #VERSION
     # VERSION  Date       AUTHOR           DESCRIPTION
       ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:17:14: error: "-" is not a valid filename
     #          08-2010    David Schimke    Initial Release
                  ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:18:14: error: "-" is not a valid filename
     #          12-2010    David Schimke    Remove "global" on data objects
                  ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:19:14: error: "-" is not a valid filename
     #          01-2011    David Schimke    Add byte reverse to correct double word
                  ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:20:40: error: invalid preprocessing directive #read
     #                                      read of byte arrays for little endian,
                                            ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:21:40: error: invalid preprocessing directive #header
     #                                      header added
                                            ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:22:14: error: "-" is not a valid filename
     #          11-2013    Teejay Ciancio   Small performance improvements to
                  ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:23:40: error: invalid preprocessing directive #set_key
     #                                      set_key and decrypt; also, some cleanup
                                            ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:25:2: error: invalid preprocessing directive #*
     #*******************************************************************************
      ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:26:2: error: invalid preprocessing directive #*
     #*******************************************************************************
      ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:37:2: error: invalid preprocessing directive #*
     #*******************************************************************************
      ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:38:2: error: invalid preprocessing directive #*
     #*******************************************************************************
      ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:40:3: error: invalid preprocessing directive #AES
     # AES: Performs an AES key expansion
       ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:41:5: error: invalid preprocessing directive #arguments
     #   arguments
         ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:42:13: error: invalid preprocessing directive #*
     #           *key        pointer to input key (128, 192, 256 bits in length)
                 ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:43:13: error: invalid preprocessing directive #key_size
     #           key_size    key_size in bits (128, 192, 256)
                 ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:44:13: error: invalid preprocessing directive #*
     #           *key_sch    pointer to key schedule output (44, 52, 60 longwords)
                 ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:46:5: error: invalid preprocessing directive #calling
     #   calling convention
         ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:47:5: error: invalid preprocessing directive #void
     #   void    mmcau_aes_set_key (const unsigned char *key,
         ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:48:32: error: invalid preprocessing directive #const
     #                              const int            key_size,
                                    ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:49:32: error: invalid preprocessing directive #unsigned
     #                              unsigned char       *key_sch)
                                    ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:51:4: error: invalid preprocessing directive #register
     #  register allocation
        ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:52:3: error: invalid preprocessing directive #--
     # --------------------
       ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:53:4: error: invalid preprocessing directive #r0
     #  r0      = scratch / input  *key (arg0)
        ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:54:4: error: invalid preprocessing directive #r1
     #  r1      = scratch / input  size (arg1)
        ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:55:4: error: invalid preprocessing directive #r2
     #  r2      = scratch / output *key_sch (arg2)
        ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:56:4: error: invalid preprocessing directive #r3
     #  r3      = scratch
        ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:57:4: error: invalid preprocessing directive #r4
     #  r4      = scratch
        ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:58:4: error: invalid preprocessing directive #r5
     #  r5      = scratch
        ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:59:4: error: invalid preprocessing directive #r6
     #  r6      = scratch
        ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:60:4: error: invalid preprocessing directive #r7
     #  r7      = scratch
        ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:61:4: error: invalid preprocessing directive #r8
     #  r8      = scratch
        ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:62:4: error: invalid preprocessing directive #r9
     #  r9      = scratch
        ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:63:3: error: invalid preprocessing directive #r10
     # r10 (sl) = scratch / pointer to rcon
       ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:64:3: error: invalid preprocessing directive #r11
     # r11 (fp) = scratch / mmcau_1_cmd(AESS+CAA)
       ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:65:3: error: invalid preprocessing directive #r12
     # r12 (ip) = scratch / MMCAU_PPB_DIRECT
       ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:66:3: error: invalid preprocessing directive #r13
     # r13 (sp) = stack pointer
       ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:67:3: error: invalid preprocessing directive #r14
     # r14 (lr) = scratch / link register
       ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:79:3: error: invalid preprocessing directive #prepare
     # prepare for AES operations register load
       ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:90:3: error: invalid preprocessing directive #load
     # load registers needed for mmcau commands from setkey_reg_data:
       ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:114:3: error: invalid preprocessing directive #calculation
     # calculation for key_sch[8-11]
       ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:125:3: error: invalid preprocessing directive #calculation
     # calculation for key_sch[12-15]
       ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:139:3: error: invalid preprocessing directive #calculation
     # calculation for key_sch[16-19]
       ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:150:3: error: invalid preprocessing directive #calculation
     # calculation for key_sch[20-23]
       ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:164:3: error: invalid preprocessing directive #calculation
     # calculation for key_sch[24-27]
       ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:175:3: error: invalid preprocessing directive #calculation
     # calculation for key_sch[28-31]
       ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:189:3: error: invalid preprocessing directive #calculation
     # calculation for key_sch[32-35]
       ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:200:3: error: invalid preprocessing directive #calculation
     # calculation for key_sch[36-39]
       ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:214:3: error: invalid preprocessing directive #calculation
     # calculation for key_sch[40-43]
       ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:225:3: error: invalid preprocessing directive #calculation
     # calculation for key_sch[44-47]
       ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:239:3: error: invalid preprocessing directive #calculation
     # calculation for key_sch[48-51]
       ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:250:3: error: invalid preprocessing directive #calculation
     # calculation for key_sch[52-55]
       ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:264:3: error: invalid preprocessing directive #calculation
     # calculation for key_sch[56-59]
       ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:286:3: error: invalid preprocessing directive #calculation
     # calculation for key_sch[6-11]
       ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:302:3: error: invalid preprocessing directive #calculation
     # calculation for key_sch[12-17]
       ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:318:3: error: invalid preprocessing directive #calculation
     # calculation for key_sch[18-23]
       ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:334:3: error: invalid preprocessing directive #calculation
     # calculation for key_sch[24-29]
       ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:350:3: error: invalid preprocessing directive #calculation
     # calculation for key_sch[30-35]
       ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:366:3: error: invalid preprocessing directive #calculation
     # calculation for key_sch[36-41]
       ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:382:3: error: invalid preprocessing directive #calculation
     # calculation for key_sch[42-47]
       ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:398:3: error: invalid preprocessing directive #calculation
     # calculation for key_sch[48-51]
       ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:415:3: error: invalid preprocessing directive #calculation
     # calculation for key_sch[4-7]
       ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:429:3: error: invalid preprocessing directive #calculation
     # calculation for key_sch[8-11]
       ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:443:3: error: invalid preprocessing directive #calculation
     # calculation for key_sch[12-15]
       ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:457:3: error: invalid preprocessing directive #calculation
     # calculation for key_sch[16-19]
       ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:471:3: error: invalid preprocessing directive #calculation
     # calculation for key_sch[20-23]
       ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:485:3: error: invalid preprocessing directive #calculation
     # calculation for key_sch[24-27]
       ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:499:3: error: invalid preprocessing directive #calculation
     # calculation for key_sch[28-31]
       ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:513:3: error: invalid preprocessing directive #calculation
     # calculation for key_sch[32-35]
       ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:527:3: error: invalid preprocessing directive #calculation
     # calculation for key_sch[36-39]
       ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:541:3: error: invalid preprocessing directive #calculation
     # calculation for key_sch[40-43]
       ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:551:2: error: invalid preprocessing directive #*
     #*******************************************************************************
      ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:552:2: error: invalid preprocessing directive #*
     #*******************************************************************************
      ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:554:3: error: invalid preprocessing directive #AES
     # AES: Encrypts a single 16-byte block
       ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:555:5: error: invalid preprocessing directive #arguments
     #   arguments
         ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:556:13: error: invalid preprocessing directive #*
     #           *in         pointer to 16-byte block of input plaintext
                 ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:557:13: error: invalid preprocessing directive #*
     #           *key_sch    pointer to key schedule (44, 52, 60 longwords)
                 ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:558:13: error: invalid preprocessing directive #nr
     #           nr          number of AES rounds (10, 12, 14 = f(key_schedule))
                 ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:559:13: error: invalid preprocessing directive #*
     #           *out        pointer to 16-byte block of output ciphertext
                 ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:562:5: error: invalid preprocessing directive #calling
     #   calling convention
         ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:563:5: error: invalid preprocessing directive #void
     #   void    mmcau_aes_encrypt (const unsigned char *in,
         ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:564:32: error: invalid preprocessing directive #const
     #                              const unsigned char *key_sch,
                                    ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:565:32: error: invalid preprocessing directive #const
     #                              const int            nr,
                                    ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:566:32: error: invalid preprocessing directive #unsigned
     #                              unsigned char       *out)
                                    ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:576:4: error: invalid preprocessing directive #register
     #  register allocation
        ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:577:3: error: invalid preprocessing directive #--
     # --------------------
       ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:578:4: error: invalid preprocessing directive #r0
     #  r0      = scratch / input  *in  / mmcau_3_cmds(AESS+CA0,AESS+CA1,AESS+CA2)
        ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:579:4: error: invalid preprocessing directive #r1
     #  r1      = scratch / input  *key_sch
        ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:580:4: error: invalid preprocessing directive #r2
     #  r2      = scratch / input   nr
        ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:581:4: error: invalid preprocessing directive #r3
     #  r3      = scratch / output *out
        ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:582:4: error: invalid preprocessing directive #r4
     #  r4      = scratch
        ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:583:4: error: invalid preprocessing directive #r5
     #  r5      = scratch
        ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:584:4: error: invalid preprocessing directive #r6
     #  r6      = scratch
        ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:585:4: error: invalid preprocessing directive #r7
     #  r7      = scratch
        ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:586:4: error: invalid preprocessing directive #r8
     #  r8      = scratch / mmcau_2_cmds(AESS+CA3,AESR)
        ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:587:4: error: invalid preprocessing directive #r9
     #  r9      = scratch / mmcau_indirect_cmd(AESC+CA0)
        ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:588:3: error: invalid preprocessing directive #r10
     # r10 (sl) = scratch / mmcau_indirect_cmd(STR+CA0)
       ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:589:3: error: invalid preprocessing directive #r11
     # r11 (fp) = scratch / mmcau_indirect_cmd(LDR+CA0)
       ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:590:3: error: invalid preprocessing directive #r12
     # r12 (ip) = scratch / pointer to MMCAU_PPB_DIRECT
       ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:591:3: error: invalid preprocessing directive #r13
     # r13 (sp) = stack pointer
       ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:592:3: error: invalid preprocessing directive #r14
     # r14 (lr) = link register
       ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:596:3: error: invalid preprocessing directive #load
     # load the 16 plain text bytes (4 words) into r4-r7
       ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:603:3: error: invalid preprocessing directive #prepare
     # prepare for AES operations register load
       ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:607:3: error: invalid preprocessing directive #XOR
     # XOR the first 4 keys into the 16 plain text bytes
       ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:614:3: error: invalid preprocessing directive #load
     # load registers needed for mmcau commands from encrypt_reg_data:
       ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:617:3: error: invalid preprocessing directive #load
     # load the XOR results into the CAU's CA0 - CA3 registers
       ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:620:3: error: invalid preprocessing directive #send
     # send a series of cau commands to perform the encryption
       ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:696:3: error: invalid preprocessing directive #XOR
     # XOR the last 4 keys into CAO - CA3 ciphertext output
       ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:704:3: error: invalid preprocessing directive #store
     # store the 16-byte ciphertext output block into memory
       ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:714:2: error: invalid preprocessing directive #*
     #*******************************************************************************
      ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:715:2: error: invalid preprocessing directive #*
     #*******************************************************************************
      ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:717:3: error: invalid preprocessing directive #AES
     # AES: Decrypts a single 16-byte block
       ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:718:5: error: invalid preprocessing directive #arguments
     #   arguments
         ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:719:13: error: invalid preprocessing directive #*
     #           *in         pointer to 16-byte block of input chiphertext
                 ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:720:13: error: invalid preprocessing directive #*
     #           *key_sch    pointer to key schedule (44, 52, 60 longwords)
                 ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:721:13: error: invalid preprocessing directive #nr
     #           nr          number of AES rounds (10, 12, 14 = f(key_schedule))
                 ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:722:13: error: invalid preprocessing directive #*
     #           *out        pointer to 16-byte block of output plaintext
                 ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:725:5: error: invalid preprocessing directive #calling
     #   calling convention
         ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:726:5: error: invalid preprocessing directive #void
     #   void    mmcau_aes_decrypt (const unsigned char *in,
         ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:727:32: error: invalid preprocessing directive #const
     #                              const unsigned char *key_sch,
                                    ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:728:32: error: invalid preprocessing directive #const
     #                              const int            nr,
                                    ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:729:32: error: invalid preprocessing directive #unsigned
     #                              unsigned char       *out)
                                    ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:739:4: error: invalid preprocessing directive #register
     #  register allocation
        ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:740:3: error: invalid preprocessing directive #--
     # --------------------
       ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:741:4: error: invalid preprocessing directive #r0
     #  r0      = scratch / input  *in  / mmcau_3_cmds(AESIR,AESIS+CA3,AESIS+CA2)
        ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:742:4: error: invalid preprocessing directive #r1
     #  r1      = scratch / input  *key_sch
        ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:743:4: error: invalid preprocessing directive #r2
     #  r2      = scratch / input   nr
        ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:744:4: error: invalid preprocessing directive #r3
     #  r3      = scratch / output *out
        ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:745:4: error: invalid preprocessing directive #r4
     #  r4      = scratch
        ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:746:4: error: invalid preprocessing directive #r5
     #  r5      = scratch
        ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:747:4: error: invalid preprocessing directive #r6
     #  r6      = scratch
        ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:748:4: error: invalid preprocessing directive #r7
     #  r7      = scratch
        ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:749:4: error: invalid preprocessing directive #r8
     #  r8      = scratch / mmcau_2_cmds(AESIS+CA1,AESIS+CA0)
        ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:750:4: error: invalid preprocessing directive #r9
     #  r9      = scratch / mmcau_indirect_cmd(AESIC+CA0)
        ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:751:3: error: invalid preprocessing directive #r10
     # r10 (sl) = scratch / mmcau_indirect_cmd(STR+CA0)
       ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:752:3: error: invalid preprocessing directive #r11
     # r11 (fp) = scratch / mmcau_indirect_cmd(LDR+CA0)
       ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:753:3: error: invalid preprocessing directive #r12
     # r12 (ip) = scratch / pointer to MMCAU_PPB_DIRECT
       ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:754:3: error: invalid preprocessing directive #r13
     # r13 (sp) = stack pointer
       ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:755:3: error: invalid preprocessing directive #r14
     # r14 (lr) = link register
       ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:759:3: error: invalid preprocessing directive #load
     # load the 16 cipher bytes (4 words) into r4-r7
       ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:766:3: error: invalid preprocessing directive #prepare
     # prepare for AES operations register load
       ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:770:3: error: invalid preprocessing directive #the
     # the key_sch pointer (r1) is adjusted to define the end of the elements
       ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:771:3: error: invalid preprocessing directive #the
     # the adjustment factor = f(nr) is defined by the expression:
       ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:772:5: error: invalid preprocessing directive #end
     #   end of key_sch = 4 x (nr + 1) for nr = {10, 12, 14}
         ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:775:3: error: invalid preprocessing directive #XOR
     # XOR the last 4 keys into the 4 cipher words
       ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:782:3: error: invalid preprocessing directive #load
     # load registers needed for mmcau commands from decrypt_reg_data:
       ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:785:3: error: invalid preprocessing directive #load
     # load the 16 cipher bytes (4 words) into the CAU's CA0 - CA3 registers
       ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:788:3: error: invalid preprocessing directive #send
     # send a series of cau commands to perform the decryption
       ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:865:3: error: invalid preprocessing directive #XOR
     # XOR the first 4 keys into CAO - CA3 plaintext output
       ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:873:3: error: invalid preprocessing directive #store
     # store the 16-byte plain text output block into memory
       ^
    /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel/src/mmcau_aes_functions.S:883:2: error: invalid preprocessing directive #*
     #*******************************************************************************
      ^
    Using library CryptoAccel at version 1.0 in folder: /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/CryptoAccel 
    Error compiling for board Teensy 3.5.

  21. #21
    Senior Member+ manitou's Avatar
    Join Date
    Jan 2013
    Posts
    2,496
    Well, this thread is about TweetNaCl and not CryptoAccel, but whatever. In 2017, we found renaming .s files to .S got Paul's CryptoAccel to build under windows 10. See https://forum.pjrc.com/threads/43363...l=1#post140273

    maybe try changing the library .S files back to .s??

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •