1

Following error shows while compilation process:

ccm.c:152:5: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
      HWREG(AES_AES_IV_0) = ((uint32_t *)&ui8A0)[0];

ccm.c:325:5: error: dereferencing type-punned pointer will break strict- aliasing rules [-Werror=strict-aliasing]
      ((uint32_t  *)&ui8MIC)[0] = HWREG(AES_AES_TAG_OUT_0);

Line 152-155:

HWREG(AES_AES_IV_0) = ((uint32_t  *)&ui8A0)[0];
HWREG(AES_AES_IV_1) = ((uint32_t  *)&ui8A0)[1];
HWREG(AES_AES_IV_2) = ((uint32_t  *)&ui8A0)[2];
HWREG(AES_AES_IV_3) = ((uint32_t  *)&ui8A0)[3];

ui8A0 is 16-sized uint8_t array:

uint8_t  ui8A0[16];

Line 325-328:

((uint32_t  *)&ui8MIC)[0] = HWREG(AES_AES_TAG_OUT_0);
((uint32_t  *)&ui8MIC)[1] = HWREG(AES_AES_TAG_OUT_1);
((uint32_t  *)&ui8MIC)[2] = HWREG(AES_AES_TAG_OUT_2);
((uint32_t  *)&ui8MIC)[3] = HWREG(AES_AES_TAG_OUT_3);

ui8MIC is 16-sized uint8_t array:

uint8_t volatile ui8MIC[16];

HWREG macro looks like this:

#define HWREG(x)                                                              \
        (*((volatile uint32_t *)(x)))

That's how I understand it: ui8A0 is an array, &ui8A0 is an address of first element, (uint32_t *)&ui8A0 is an address for array where elements are uint32_t contrary to uint8_t which were before, ((uint32_t *)&ui8A0)[0] is the value of first element of an array which elements are uint32_t.

So basically this code has to pass 4 elements of ui8A0 to HWREG macro.

It looks like this problem: https://stackoverflow.com/a/20956250/1625856 But I would prefer not to use the union-based solution.

Is there any other, easier way to handle it?

My only idea is to replace:

HWREG(AES_AES_IV_1) = ((uint32_t  *)&ui8A0)[1];

with:

HWREG(AES_AES_IV_1) = (uintptr_t)&ui8A0[4];
Victor
  • 148
  • 10
  • 3
    *"Is there any other, easier way to handle it?"* - `memcpy` to a temporary, and then assign the value. You may be able to `memcpy` without the temporary, but I did not dive deep into the code. Also see @KerrekSB's answer at [Fix for dereferencing type-punned pointer will break strict-aliasing](https://stackoverflow.com/a/8825251/608639). You might also be able to use inline ASM because ASM does not suffer C rules. If you provide a [Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve) it will be easier to test things for you. – jww Jun 02 '18 at 17:31

0 Answers0