0

I have trouble with DES algorithm. How to solve this?

(I'm using DevC++ v5.11)

image

I don't completely understand what DES are. What should I do/try ?

// Triple DES (3DES) 
void DES::inital_key(const char key[64],char ekey[16][48],bool is_crypt)
{      
    union{                               //Error here
    char pkey[56];
    struct{char l[28],r[28];};
  };
  permute(key,pkey,_DES::perm1,56); 
  for(uint n=0; n<16; n++) {
    lshift(l,_DES::sc[n]);
    lshift(r,_DES::sc[n]);
    permute(pkey,ekey[is_crypt?n:15-n],_DES::perm2,48); 
  }
}

/////////////////////////////////////////////////////////////////////////////
void DES::work(const char in[64],char out[64],const char key[64],bool is_crypt)
{
  char ekey[16][48];                
  union{                                 //And here
    char pin[64];
    struct{char l[32],r[32];};
  };
  inital_key(key,ekey,is_crypt);
  permute(in,pin,_DES::perm3,64);
  for(uint n=0; n<16;) round(l,r,ekey[n++]),round(r,l,ekey[n++]);
  permute(pin,out,_DES::perm6,64);
}
Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770

2 Answers2

0

This code is relying on a Microsoft extension.

Your compiler, GCC, does not understand it.

You cannot use this code unless you make it standard C++, or switch compilers.

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
0

You are declaring anonymous structs inside of unnamed unions, just like the compiler errors say. You need to assign names to the unions (and for portability, you should name the structs, too):

void DES::inital_key(const char key[64], char ekey[16][48], bool is_crypt)
{      
  union {
    char pkey[56];
    struct { char l[28], r[28]; } s;
  } u;
  permute(key, u.pkey, _DES::perm1, 56); 
  for(uint n = 0; n < 16; n++) {
    lshift(u.s.l, _DES::sc[n]);
    lshift(u.s.r, _DES::sc[n]);
    permute(u.pkey, ekey[is_crypt ? n : 15-n], _DES::perm2, 48); 
  }
}

void DES::work(const char in[64], char out[64], const char key[64], bool is_crypt)
{
  char ekey[16][48];                
  union {
    char pin[64];
    struct { char l[32], r[32]; } s;
  } u;
  inital_key(key, ekey, is_crypt);
  permute(in, u.pin, _DES::perm3, 64);
  for(uint n = 0; n < 16;) round(u.s.l,  u.s.r, ekey[n++]), round(u.s.r, u.s.l, ekey[n++]);
  permute(u.pin, out, _DES::perm6, 64);
}
Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770