>> 3) The test program core dumps when run with the v option.
>> Testing MessageDigest algorithm SHA-384.
>> ..signal BUS (invalid address alignment) in CryptoPP::SHA512::Transform at
>> line 27 in file "sha.cpp"
>>    27   #define blk0(i) (W[i] = data[i])
>> (dbx) print data
>> data = 0xffffffff7fffc1ec
>> (dbx) print i
>> dbx: "i" is not defined in the scope
>> `cryptest.exe`sha.cpp`CryptoPP::SHA512::Transform(unsigned long long*,const
>> unsigned long long*)`
>> dbx: see `help scope' for details
>> (dbx) where
>> =>[1] CryptoPP::SHA512::Transform(state = 0x1010f1980, data =
>> 0xffffffff7fffc1ec) (optimized), at 0x1006041a8 (line ~27) in "sha.cpp"
>>   [2] CryptoPP::IteratedHashWithStaticTransform<unsigned long
>> long,CryptoPP::EnumToType<CryptoPP::ByteOrder,1>,128U,64U,CryptoPP::SHA384,48U,false>::HashEndianCorrectedBlock(this
>> = 0x1010f18d0, data = 0xffffffff7fffc1ec) (optimized), at 0x1004b30b8 (line
>> ~89) in "iterhash.h"
>>   [3] CryptoPP::IteratedHashBase<unsigned long
>> long,CryptoPP::HashTransformation>::HashMultipleBlocks(this = 0x1010f18d0,
>> input = 0xffffffff7fffc1ec, length = <value unavailable>) (optimized), at
>> 0x1005cff6c (line ~91) in "iterhash.cpp"
>
> OK, this is good stuff here. I can't duplicate in my modest test
> environment, but its obvious 'data = 0xffffffff7fffc1ec' is only
> aligned to 2-bytes, while you likely need 8-byte or 16-byte alignment
> due to SSE2.
> ...

Here's more of the back story...

> That should isolate it to the known undefined behavior we are
> [currently] carrying around. If it fixes the issue, then problem
> solved until we can make config.recommend the default (Crypto++ 5.7
> when it arrives).

We wanted to cut-over to config.recommend for regular users; but
withhold the cut-over for distros like Debian and Ubuntu. I inquired
how to detect a package build so we could supply the different
configuration on one of the Debian mailing lists. I got scolded by the
Debian admin for wanting to do such a thing.

So everyone gets the backwards compatible configuration, and users who
want to avoid undefined behavior (like the unaligned data accesses you
are witnessing) must do something special. That has never sat well
with me, but we can't risk breaking millions of distro users.

> The hairier result is, it does not fix the problem. In this case, we
> will need to investigate why the caller is not using
> OptimalDataAlignment(). Also see
> https://www.cryptopp.com/docs/ref/class_s_h_a3.html.

If you want to trace what's going on, then OptimalDataAlignment()
eventually references this piece of goodness
(http://github.com/weidai11/cryptopp/blob/master/misc.h#L871):

template <class T>
inline unsigned int GetAlignmentOf(T *dummy=NULL) // VC60 workaround
{
    // GCC 4.6 (circa 2008) and above aggressively uses vectorization.
    #if defined(CRYPTOPP_ALLOW_UNALIGNED_DATA_ACCESS)
        if (sizeof(T) < 16)
            return 1;
    #endif
    CRYPTOPP_UNUSED(dummy);
    #if defined(CRYPTOPP_CXX11_ALIGNOF)
        return alignof(T);
    #elif (_MSC_VER >= 1300)
        return __alignof(T);
    #elif defined(__GNUC__)
        return __alignof__(T);
    #elif CRYPTOPP_BOOL_SLOW_WORD64
        return UnsignedMin(4U, sizeof(T));
    #else
        return sizeof(T);
    #endif
}

One of the things config.recommend does is squash
CRYPTOPP_ALLOW_UNALIGNED_DATA_ACCESS.

GetAlignmentOf coupled with CRYPTOPP_ALLOW_UNALIGNED_DATA_ACCESS used
to cause me so much aggravation... its the cause of the failure, but
it never shows up in the back traces. The damage was done long before
the faulting function gets fingered in a bask trace.

Now I can spot the troubles it causes from a mile away. I've
experienced them on nearly every platform, from i686 and x86_64 to
MIPS and ARM. As soon as I see a SIGBUS or alignment issue, I jump
over to config.recommend to isolate it.

Jeff

-- 
-- 
You received this message because you are subscribed to the "Crypto++ Users" 
Google Group.
To unsubscribe, send an email to [email protected].
More information about Crypto++ and this group is available at 
http://www.cryptopp.com.
--- 
You received this message because you are subscribed to the Google Groups 
"Crypto++ Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to