質問

So I'm trying to code an AESNI library. When I compile my program with symbols and run it in GDB. I get the following error:

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

Code: (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;
}

}

So I have my breakpoint set at line 33.

The program compiles without errors, but it's stuck when I try to step through in GDB.

役に立ちましたか?

解決

Change:

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

to:

__m128i KeySchedule[Nr+1]; // allocate array of (Nr+1) x __m128i

他のヒント

The address pointed by KeySchedule is 11 which is an invalid address that you use later to store the result of the SSE load. . char Nr = 10; __m128i *KeySchedule = (__m128i*)(Nr+1);

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top