This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

MSP430FR5739: DES_102612 seems not to fit in MSP430FR5739

Part Number: MSP430FR5739

I'm trying to encrypt data by using the example code of DES_102612.zip from "Cryptography for TI Devices". In the manual, it says all the code was tested  in an MSP430FR5739 using IAR. I'm trying to use the code but using CCS. However, when I run it, it does not complete the encryption. Is due to the program does not fit in the memory?

  • I expect that your program would fail to build (link) if the program proper (text+constants/RAM variables) didn't fit.

    The linker can't check the dynamic behavior -- stack and heap. Notable by its absence from the Report is mention of how the IAR stack size was set. I see a fair number of stack variables in the code. I don't see any malloc() calls.

    Try increasing the stack size (Build Settings->Build->Linker->Basic Options). You can probably shrink the heap very small (say 16 bytes) to make up for it.

    What does "does not complete" mean exactly? Does the program freeze? Or does a function return with half-processed results?
  • Hello Abundis,

    you have not mentioned which example fails.
    Could you post your main.c code?
    It will help me to do a quick check.
  • Hi Tomasz,

    Thanks for your answer. I mentioned I'm using the DES_102612.zip project. I attached the original main.c anyways:

    #include "DES.h"

    void main(void){
    des_ctx dc;
    int i;
    unsigned char Data[16];
    unsigned char *cp,key[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
    unsigned char key1[8] = {0xda, 0xff, 0x37, 0x8c, 0x02, 0x46, 0x10, 0xfb};
    unsigned char key2[8] = {0x01,0x23,0x45,0x67,0x89,0xab,0xdc,0xfe};
    unsigned char x[24] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8b, 0xe9, 0xed, 0xb5, 0x00, 0x00, 0x00}; //enc(RndB
    unsigned char v[] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10, 0x11, 0x12, 0x13, 0x14,0x15,0x16};
    unsigned char y[8] = {0x05, 0x3F, 0x41,0xDA, 0x27, 0x26, 0xE4, 0x29};//RnadA
    unsigned char temp[8];
    unsigned char rb[] = {0x51, 0x5f, 0xbc, 0x06,0x10, 0xf4,0xaf,0x03};
    unsigned char ra[] = {0x79, 0xd4, 0x66, 0x29,0xf7,0xe1,0x12,0xc3};
    unsigned char IV[8];
    unsigned char IV2[8];
    unsigned char t1,t2;

    cp = x;

    TripleDES_ENC_CBC( &dc,cp, 2, key,key1,key2,&IV[0]);

    TripleDES_DEC_CBC( &dc,cp, 2, key,key1,key2, &IV[0]);

    /*
    Des_Key(&dc,key, ENDE);
    for(i=0;i<8;i++){
    IV[i] = rb[i];
    IV2[i] = rb[i];
    }
    Des_Dec (&dc,&rb[0],1);

    y[0] = x[1];
    t1= rb[0];
    rb[0] = rb[1];
    rb[1] = rb[2];
    rb[2] = rb[3];
    rb[3] = rb[4];
    rb[4] = rb[5];
    rb[5] = rb[6];
    rb[6] = rb[7];
    rb[7] =t1;
    y[1] = x[1];

    for(i=0;i<8;i++){
    v[i] = ra[i];
    v[8+i] = rb[i];
    }
    y[1] = x[1];

    DES_Enc_CBC (&dc,&v[0],2, &IV[0]);

    temp[0] =x[1];
    DES_Dec_CBC (&dc,&v[0],2, &IV2[0]);
    DES_Enc_CBC (&dc,&temp[0],1, IV);
    DES_Enc_CBC (&dc,&y[0],1, IV);*/
    /* des_key(&dc,key, ENDE);
    cp = v;
    des_enc(&dc,cp,1);
    for (i=0; i <8; i++){
    v[i+8] ^= v[i];
    }
    cp+=8;
    des_enc(&dc,cp,1);
    for (i=8; i <16; i++){
    v[i+8] ^= v[i];
    }
    cp+=8;
    des_enc(&dc,cp,1);
    for (i=16; i <24; i++){
    v[i+8] ^= v[i];
    }
    cp+=8;
    des_enc(&dc,cp,1);

    temp[0] =x[1];*/
    /*des_key(&dc,key, ENDE);
    des_dec(&dc,cp,1); // dec(enk(RndB))

    temp[0] =x[1];
    temp[1] =x[2];
    temp[2] =x[3];
    temp[3] =x[4];
    temp[4] =x[5];
    temp[5] =x[6];
    temp[6] =x[7];
    temp[7] =x[0];

    for ( i=0; i<8; i++){
    Data[i] = y[i];
    Data[i+8] = temp[i];
    }
    cp = Data;

    des_key(&dc,key, ENDE);
    des_enc(&dc,cp,1);
    des_key(&dc,key, ENDE);
    des_enc(&dc,&cp[8],1);


    des_key(&dc,key1, ENDE);
    /* for( i =0; i<8; i++){
    Data[i] = x[i];
    } */
    /*
    des_key(&dc, key, DE1);
    des_dec(&dc, cp, 1);

    for( i =0; i<8; i++){
    Data[i+8] = x[i];
    }*/
    /*
    des_dec(&dc,cp,1);

    cp = (char *) data;
    for(i=0;i<10;i++)data[i]=i;
    des_enc(&dc,cp,5); // Enc 5 blocks.


    des_dec(&dc,cp,1);
    des_dec(&dc,cp+8,4);

    */

    while (1);

    }

  • I count >130 bytes of stack taken up just in your main() function. This is most of the 160 bytes CCS (automatically) assigns me. The library then nibbles on the 30 bytes remaining.

    -> Increase your stack size.
  • Hi,

    my DES_102612.zip file does not contain main.c
    It contains DES.c, DES.h, manifest and an application note.
    That is the reason a I have asked for main.c.

    A tip for you.
    When you post a code,
    please use "Insert Code, Attache Files and more..." which is on the right to the Replay button,
    then "Insert code using Syntaxhighlighter".
    It will save indents.
  • Where your main.c comes from?

    TripleDES_ENC_CBC( &dc,cp, 2, key,key1,key2,&IV[0]);
    TripleDES_DEC_CBC( &dc,cp, 2, key,key1,key2, &IV[0]);

    You call the above functions with 7 arguments.
    Both have 6.

    Could you explain and fix that?
  • I'm using Des_Enc(&dc,cp,1); instead
  • Why do you post code you are not using?
    What kind of help do you expect if you give us something while you are doing totally different things.
    You waste my time.
  • Because I was using TripleDES_DEC_CBC( &dc,cp, 2, key,key1,key2, &IV[0]); first and becuase it didn't work I used a simpler one to see. Don't waste your time please!! Do something better!!
  • Bruce,

    in main.c some function calls are inconsistent with their declarations and definitions,
    the application note is inconsistent with both of the above.
    Took me some time to fix it.
    Works fine with both the stack and the heap at their 160 bytes defaults.

**Attention** This is a public forum