简体   繁体   English

匿名结构不在命名类型内

[英]Anonymous struct not inside named type

I have trouble with DES algorithm. 我在使用DES算法时遇到了麻烦。 How to solve this? 如何解决呢?

(I'm using DevC++ v5.11) (我正在使用DevC ++ v5.11)

图片

I don't completely understand what DES are. 我不完全了解DES是什么。 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);
}

This code is relying on a Microsoft extension . 此代码依赖于Microsoft扩展

Your compiler, GCC, does not understand it. 您的编译器GCC无法理解。

You cannot use this code unless you make it standard C++, or switch compilers. 除非将其设置为标准C ++或切换编译器,否则无法使用此代码。

You are declaring anonymous struct s inside of unnamed union s, just like the compiler errors say. 您在未命名的union中声明了匿名struct ,就像编译器错误所说的那样。 You need to assign names to the union s (and for portability, you should name the struct s, too): 您需要为union分配名称(并且为了可移植性,还应该为struct命名):

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);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM