#3 testsuite violates 32-bit-alignment assumption

open
nobody
None
5
2008-03-11
2008-03-11
Martin Guy
No

The testsuite fails on architectures where 32-bit accesses must be 32-bit aligned because test/srtp_driver.c hands unaligned data to srtp_protect() and srtp_unprotect(). This makes the testsuite fail on arm.

There are #ifdef ALIGNMENT_32BIT_REQUIRED macros for word access in crypto/include/integers.h, but these are never used anywhere. Instead the srtp_*protect() routines say they require 32bit-aligned data in the commentary.

As a quick fix for the Debian arm variants, I've made the minimal change (patch attached), simply aligning the test character arrays used in the test program, which solves the problem.

A more robust solution would be to lift the alignment requirement by using the GET_32 and PUT_32 macros and enabling ALIGNMENT_32BIT_REQUIRED in the header #ifdef __arm__ - that way other people's unaligned code using these functions that seems to work for them would not break mysteriously on arm.

Discussion

  • Tengo
    Tengo
    2011-03-22

    http://gcc.gnu.org/onlinedocs/gcc/Variable-Attributes.html
    aligned (alignment)
    This attribute specifies a minimum alignment for the variable or structure field, measured in bytes.
    So alignment of 4 bytes should be enough, amirite?
    --- a/test/srtp_driver.c 2010-05-27 19:23:05.000000000 +0000
    +++ b/test/srtp_driver.c 2011-03-22 13:55:08.621142729 +0000
    @@ -1195,7 +1195,6 @@
    * These packets were made with the default SRTP policy.
    */

    -
    err_status_t
    srtp_validate() {
    uint8_t srtp_plaintext_ref[28] = {
    @@ -1204,14 +1203,14 @@
    0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab,
    0xab, 0xab, 0xab, 0xab
    };
    - uint8_t srtp_plaintext[38] = {
    + uint8_t srtp_plaintext[38] __attribute__((aligned(4))) = {
    0x80, 0x0f, 0x12, 0x34, 0xde, 0xca, 0xfb, 0xad,
    0xca, 0xfe, 0xba, 0xbe, 0xab, 0xab, 0xab, 0xab,
    0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab,
    0xab, 0xab, 0xab, 0xab, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00
    };
    - uint8_t srtp_ciphertext[38] = {
    + uint8_t srtp_ciphertext[38] __attribute__((aligned(4))) = {
    0x80, 0x0f, 0x12, 0x34, 0xde, 0xca, 0xfb, 0xad,
    0xca, 0xfe, 0xba, 0xbe, 0x4e, 0x55, 0xdc, 0x4c,
    0xe7, 0x99, 0x78, 0xd8, 0x8c, 0xa4, 0xd2, 0x15,