Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/127.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
实现AES密钥调度 我现在在C++中实现AES,但是我遇到了算法的密钥扩展部分的问题。My函数将128位密钥作为一个参数,并将扩展密钥放在作为第二个参数传递的数组中: void Expand(const unsigned char input[16], unsigned char output[16*11]) { unsigned int i; unsigned int j; unsigned int t; for(i = 0; i < 16; i++) { output[i] = input[i]; } for(i = 1; i < 11; i++) { j = i*16; cout << std::dec << i << ", " << j << endl; t = *(unsigned int*)(output + j - sizeof(unsigned int)); //Key schedule core cout << std::hex << "0x" << t << " "; t = (t >> 8) | (t << 24); cout << "0x" << t << " "; ((unsigned char*) &t)[0] = sbox[((unsigned char*) &t)[0]]; ((unsigned char*) &t)[1] = sbox[((unsigned char*) &t)[1]]; ((unsigned char*) &t)[2] = sbox[((unsigned char*) &t)[2]]; ((unsigned char*) &t)[3] = sbox[((unsigned char*) &t)[3]]; ((unsigned char*) &t)[0] ^= rcon[i]; cout << "0x" << t << " "; //First column of current round key t ^= *(unsigned int*)(output + j - 4*sizeof(unsigned int)); *(unsigned int*)(output + j) = t; cout << "0x" << t << " "; //Second column of current round key t ^= *(unsigned int*)(output + j - 3*sizeof(unsigned int)); *(unsigned int*)(output + j + 1*sizeof(unsigned int)) = t; cout << "0x" << t << " "; //Third column of current round key t ^= *((unsigned int*)output + j - 2*sizeof(unsigned int)); *(unsigned int*)(output + j + 2*sizeof(unsigned int)) = t; cout << "0x" << t << " "; //Fourth column of current round key t ^= *(unsigned int*)(output + j - 1*sizeof(unsigned int)); *(unsigned int*)(output + j + 3*sizeof(unsigned int)) = t; cout << "0x" << t << endl; } }_C++_Aes - Fatal编程技术网

实现AES密钥调度 我现在在C++中实现AES,但是我遇到了算法的密钥扩展部分的问题。My函数将128位密钥作为一个参数,并将扩展密钥放在作为第二个参数传递的数组中: void Expand(const unsigned char input[16], unsigned char output[16*11]) { unsigned int i; unsigned int j; unsigned int t; for(i = 0; i < 16; i++) { output[i] = input[i]; } for(i = 1; i < 11; i++) { j = i*16; cout << std::dec << i << ", " << j << endl; t = *(unsigned int*)(output + j - sizeof(unsigned int)); //Key schedule core cout << std::hex << "0x" << t << " "; t = (t >> 8) | (t << 24); cout << "0x" << t << " "; ((unsigned char*) &t)[0] = sbox[((unsigned char*) &t)[0]]; ((unsigned char*) &t)[1] = sbox[((unsigned char*) &t)[1]]; ((unsigned char*) &t)[2] = sbox[((unsigned char*) &t)[2]]; ((unsigned char*) &t)[3] = sbox[((unsigned char*) &t)[3]]; ((unsigned char*) &t)[0] ^= rcon[i]; cout << "0x" << t << " "; //First column of current round key t ^= *(unsigned int*)(output + j - 4*sizeof(unsigned int)); *(unsigned int*)(output + j) = t; cout << "0x" << t << " "; //Second column of current round key t ^= *(unsigned int*)(output + j - 3*sizeof(unsigned int)); *(unsigned int*)(output + j + 1*sizeof(unsigned int)) = t; cout << "0x" << t << " "; //Third column of current round key t ^= *((unsigned int*)output + j - 2*sizeof(unsigned int)); *(unsigned int*)(output + j + 2*sizeof(unsigned int)) = t; cout << "0x" << t << " "; //Fourth column of current round key t ^= *(unsigned int*)(output + j - 1*sizeof(unsigned int)); *(unsigned int*)(output + j + 3*sizeof(unsigned int)) = t; cout << "0x" << t << endl; } }

实现AES密钥调度 我现在在C++中实现AES,但是我遇到了算法的密钥扩展部分的问题。My函数将128位密钥作为一个参数,并将扩展密钥放在作为第二个参数传递的数组中: void Expand(const unsigned char input[16], unsigned char output[16*11]) { unsigned int i; unsigned int j; unsigned int t; for(i = 0; i < 16; i++) { output[i] = input[i]; } for(i = 1; i < 11; i++) { j = i*16; cout << std::dec << i << ", " << j << endl; t = *(unsigned int*)(output + j - sizeof(unsigned int)); //Key schedule core cout << std::hex << "0x" << t << " "; t = (t >> 8) | (t << 24); cout << "0x" << t << " "; ((unsigned char*) &t)[0] = sbox[((unsigned char*) &t)[0]]; ((unsigned char*) &t)[1] = sbox[((unsigned char*) &t)[1]]; ((unsigned char*) &t)[2] = sbox[((unsigned char*) &t)[2]]; ((unsigned char*) &t)[3] = sbox[((unsigned char*) &t)[3]]; ((unsigned char*) &t)[0] ^= rcon[i]; cout << "0x" << t << " "; //First column of current round key t ^= *(unsigned int*)(output + j - 4*sizeof(unsigned int)); *(unsigned int*)(output + j) = t; cout << "0x" << t << " "; //Second column of current round key t ^= *(unsigned int*)(output + j - 3*sizeof(unsigned int)); *(unsigned int*)(output + j + 1*sizeof(unsigned int)) = t; cout << "0x" << t << " "; //Third column of current round key t ^= *((unsigned int*)output + j - 2*sizeof(unsigned int)); *(unsigned int*)(output + j + 2*sizeof(unsigned int)) = t; cout << "0x" << t << " "; //Fourth column of current round key t ^= *(unsigned int*)(output + j - 1*sizeof(unsigned int)); *(unsigned int*)(output + j + 3*sizeof(unsigned int)) = t; cout << "0x" << t << endl; } },c++,aes,C++,Aes,其中t是大小为4的无符号字符数组。然而,我仍然无法理解为什么我的其他代码不正确。有什么建议吗 j = i*16; t[0] = sbox[output[j-3]] ^ rcon[i]; t[1] = sbox[output[j-2]]; t[2] = sbox[output[j-1]]; t[3] = sbox[output[j-4]]; output[j] = output[j-16] ^ t[0]; output[j+1] = ou

其中t是大小为4的无符号字符数组。然而,我仍然无法理解为什么我的其他代码不正确。有什么建议吗

    j = i*16;

    t[0] = sbox[output[j-3]] ^ rcon[i];
    t[1] = sbox[output[j-2]];
    t[2] = sbox[output[j-1]];
    t[3] = sbox[output[j-4]];

    output[j] = output[j-16] ^ t[0];
    output[j+1] = output[j-15] ^ t[1];
    output[j+2] = output[j-14] ^ t[2];
    output[j+3] = output[j-13] ^ t[3];

    output[j+4] = output[j-12] ^ output[j];
    output[j+5] = output[j-11] ^ output[j+1];
    output[j+6] = output[j-10] ^ output[j+2];
    output[j+7] = output[j-9] ^ output[j+3];

    output[j+8] = output[j-8] ^ output[j+4];
    output[j+9] = output[j-7] ^ output[j+5];
    output[j+10] = output[j-6] ^ output[j+6];
    output[j+11] = output[j-5] ^ output[j+7];

    output[j+12] = output[j-4] ^ output[j+8];
    output[j+13] = output[j-3] ^ output[j+9];
    output[j+14] = output[j-2] ^ output[j+10];
    output[j+15] = output[j-1] ^ output[j+11];