0

所以我正在尝试编写一个 AESNI 库。当我用符号编译我的程序并在 GDB 中运行它时。我收到以下错误:

Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: 13 at address: 0x0000000000000000

代码:(g++ -g aesni.c -o aesni; gdb aesni)

int main (int argc, const char *argv[])
{

// Nr = 10 (128bit), 12 (192bit), 14 (256bit)

__attribute__((aligned (16))) unsigned char Key128bit[] = { 0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c,  0x00 };

__attribute__((aligned (16))) unsigned char Key192bit[] = { 0x8e, 0x73, 0xb0, 0xf7, 0xda, 0x0e, 0x64, 0x52, 0xc8, 0x10, 0xf3, 0x2b, 0x80, 0x90, 0x79, 0xe5,
                                                            0x62, 0xf8, 0xea, 0xd2, 0x52, 0x2c, 0x6b, 0x7b,  0x00 };

__attribute__((aligned (16))) unsigned char Key256bit[] = { 0x60, 0x3d, 0xeb, 0x10, 0x15, 0xca, 0x71, 0xbe, 0x2b, 0x73, 0xae, 0xf0, 0x85, 0x7d, 0x77, 0x81,
                                                            0x1f, 0x35, 0x2c, 0x07, 0x3b, 0x61, 0x08, 0xd7, 0x2d, 0x98, 0x10, 0xa3, 0x09, 0x14, 0xdf, 0xf4,  0x00 };

char Nr = 10; // 128bit / 12 for 192bit / 14 for 256bit

//__m128i *KeySchedule = new __m128i[Nr+1];
__m128i *KeySchedule = (__m128i*)(Nr+1);

switch(Nr+1)
{
    case 11:
    KeySchedule[0] = _mm_load_si128((__m128i*)Key128bit);
    break;
    case 13:
    break;
    case 15:
    break;
}

}

所以我在第 33 行设置了断点。

该程序编译没有错误,但是当我尝试在 GDB 中单步执行时它被卡住了。

4

2 回答 2

2

改变:

__m128i *KeySchedule = (__m128i*)(Nr+1); // this declaration is completely broken

至:

__m128i KeySchedule[Nr+1]; // allocate array of (Nr+1) x __m128i
于 2014-01-13T13:30:22.147 回答
1

所指向的地址KeySchedule是 11,这是您稍后用来存储 SSE 加载结果的无效地址。. 字符 Nr = 10; __m128i *KeySchedule = (__m128i*)(Nr+1);

于 2014-01-13T13:29:49.547 回答