This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

elliptic curve cryptography on 8051

Hey guys, I am working on making Elliptic Curve Cryptography El-Gamal in 8051 MCU using Keil uvision 4. I want to make it 128 bit, so I need to use GMP library. However, to use GMP I usually download it in mingw-get-setup first, so I think it won't run if I just copy the gmp.h to my project in Keil.

My questions are :

1. how can I use gmp in 8051 using Keil?

2. Or should I compile it first in gcc, then just download the hex file to 8051? How to program the register in gcc?

Thanks for your attention :D

Best regards

Parents Reply Children
  • On the evidence of this thread, I rather doubt that he could.

  • Okay I have solved the previous problems. Thanks all :D

    I am currently working on modular multiplication 128 bit program, when I run it on GCC,it works. But then I moved it to keil, and it generate error like this :

    compiling led2.c...
    LED2.C(14): error C141: syntax error near 'unsigned'
    LED2.C(14): error C202: 'temp': undefined identifier
    LED2.C(15): error C141: syntax error near 'unsigned'
    LED2.C(15): error C202: 'i': undefined identifier
    LED2.C(59): error C202: 'i': undefined identifier
    LED2.C(61): error C202: 'i': undefined identifier
    
    compiling sub.c...
    SUB.C(9): error C231: '_sub': redefinition
    SUB.C(21): error C141: syntax error near 'char'
    SUB.C(21): error C202: 'i': undefined identifier
    SUB.C(22): error C141: syntax error near 'unsigned'
    SUB.C(22): error C202: 'temp': undefined identifier
    SUB.C(25): error C202: 'i': undefined identifier
    SUB.C(27): error C202: 'i': undefined identifier
    SUB.C(29): error C202: 'i': undefined identifier
    SUB.C(30): error C202: 'temp': undefined identifier
    SUB.C(31): error C202: 'temp': undefined identifier
    SUB.C(32): error C202: 'i': undefined identifier
    SUB.C(35): error C202: 'i': undefined identifier
    SUB.C(40): error C231: '_sub': redefinition
    compiling mod.c...
    

    Although in Led.c I have declared :

    #include <REG51.H>
    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    #include "Li.h"
    #include <string.h>
    
    main()
    {
            unsigned char a[17],b[17],p[16];
            //main function starts
            unsigned char *c = (char*) malloc(17);;
            memset(c,0,17);
            unsigned char temp=0;
            unsigned char i=2;
            memset(a,0,17);
            memset(b,0,17);
            memset(p,0,16);
    
            a[0]=0xB2;
            a[1]=0x21;
    
            b[0]=0x6A;
            b[1]=0x6;
    
            p[0]=0xF0;
            p[1]=0x1F;
    
            for(i=1;i>=0;i--)
            {
                    if ((b[i] & 128) == 128)
                    {
                            c = add(c,a);
                            c = add(c,c);
                            c = mod(c,p);
                            c[3] = 0;
                    }
                    else
                    {
                            c = add(c,c);
                            c = mod(c,p);
                            c[3] = 0;
                    }
    
                    if ((b[i] & 64) == 64)
                    {
                            c = add(c,a);
                            c = add(c,c);
                            c = mod(c,p);
                            c[3] = 0;
                    }
                    else
                    {
                            c = add(c,c);
                            c = mod(c,p);
                            c[3] = 0;
                    }
    
                    if ((b[i] & 32) == 32)
                    {
                            c = add(c,a);
    
                            c = add(c,c);
    
                            c = mod(c,p);
                    }
                    else
                    {
                            c = add(c,c);
                            c = mod(c,p);
                            c[3] = 0;
    
                    }
                    if ((b[i] & 16) == 16)
                    {
                            c= add(c,a);
                            c = add(c,c);
                            c = mod(c,p);
                            c[3] = 0;
    
                    }
                    else
                    {
                            c = add(c,c);
                        c = mod(c,p);
                            c[3] = 0;
                    }
                    if ((b[i] & 8) == 8)
                    {
                            c = add(c,a);
                            c = add(c,c);
                            c = mod(c,p);
                            c[3] = 0;
                    }
                    else
                    {
                            c = add(c,c);
                      c = mod(c,p);
                            c[3] = 0;
                    }
                    if ((b[i] & 4) == 4)
                    {
                            c = add(c,a);
                            c = add(c,c);
                            c = mod(c,p);
                            c[3] = 0;
                    }
                    else
                    {
                    c = add(c,c);
                      c = mod(c,p);
                            c[3] = 0;
                    }
                    if ((b[i] & 2) == 2)
                    {
                            c = add(c,a);
                            c = add(c,c);
                            c = mod(c,p);
                            c[3] = 0;
                    }
                    else
                    {
                    c = add(c,c);
                            c = mod(c,p);
                            c[3] = 0;
                    }
                    if ((b[i] & 1) == 1)
                    {
                            c= add(c,a);
                            c = add(c,c);
                            c = mod(c,p);
                            c[3] = 0;
                    }
                    else
                    {
                    c = add(c,c);
                      c = mod(c,p);
                            c[3] = 0;
                    }
            }
    
            free(c);
            while(1){}
    }
    

    and in sub.c :

    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    #include "Li.h"
    #include <string.h>
    #include <REG51.H>
    
    
    unsigned char *sub(unsigned char a[17],unsigned char b[17]) { /*unsigned d[2],temp,i,shift,k; char a[32],b[32],c[32]; a[31] = 0xA; a[30] = 0xD; a[29] = 0x9; b[31] = 0x8; b[30] = 0xF; b[29] = 0x2; */ unsigned char *c = (char*) malloc(17);; memset(c,0,17); //static char c[3]; char i; unsigned char temp = 0; memcpy(c, a, 17);
    for(i=16; i >= 0 ; i--) { if (c[i] < b[i]) { c[i+1] = c[i+1] - 1; temp = c[i] - b[i]; temp = 255-temp+1; c[i] = 0xFF - temp + 1; } else { c[i] = c[i] - b[i]; } } return c; //free(c); }

    Led.c is the main program, and I just testing it to do multiply of 16 bit to make the debugging easier. Function sub run in function mod. The function mod and add have been proved to run perfectly on GCC, and I don't attach them here. Anyone knows : what's the syntax error near unsigned, and why the variable temp and i is undefined in led.c and sub.c although I have defined it?

    Thanks a lot for your help!

  • and what is the error at last line of sub.c ?
    SUB.C(40): error C231: '_sub': redefinition

    the code at that line is :

     return c;
    

  • put your variable declarations at the top of the block. not after any function calls.

    this depends on the level of c. I can't remember the exact details and I haven't got time to research.

    that is left as an exercise for you.

  • Nice code you have.

    for(i=1;i>=0;i--)
    


    i is unsigned char.

    Start on one and repeat until negative. How often do you see an unsigned character be negative?

  • Yes actually it works after I put the declaration on top. However, the pointer c I create share the same address as the variable a. Anyone know how to make they have different address?

    c : X:0x000000

    a : X:0x000000[...]

    Thus, when I debug it by putting the cursor to while(1) and run to cursor line, the c have value 0, although it should have different value when I run it on GCC. Is it because c and a have the same address?