> With my 64bit Window7 machine, > I can build Crypto++ static library in X86 in visual studio 2017, and use > it without any issue, > > so I built Crypto++ static library in X64 within visual studio 2017, and > tried to use it with 64bit application, > It always crashed on the line m_k[i] = a+b with error message : > System.AccessViolationException: 'Attempted to read or write protected > memory. This is often an indication that other memory is corrupt.' > > Below is the section of codes when crashed, the Crypto++ is the latest > source.2016. > > void Twofish::Base::UncheckedSetKey(const byte *userKey, unsigned int > keylength, const NameValuePairs &) > { > AssertValidKeyLength(keylength); > > unsigned int len = (keylength <= 16 ? 2 : (keylength <= 24 ? 3 : 4)); > SecBlock<word32> key(len*2); > GetUserKey(LITTLE_ENDIAN_ORDER, key.begin(), len*2, userKey, keylength); > > unsigned int i; > for (i=0; i<40; i+=2) > { > word32 a = h(i, key, len); > word32 b = rotlFixed(h(i+1, key+1, len), 8); > m_k[i] = a+b; > m_k[i+1] = rotlFixed(a+2*b, 9); > } >
That code is unchanged for ages. See, for example, Crypto++ 5.5 from 2007 at https://github.com/weidai11/cryptopp/blob/0f71ab33118145a6185221715129190193aed1b5/twofish.cpp#L52 . > Did I miss any setting? > The problem is likely in the code that is using Twofish. We need to see the userland code around setting the key. Some_Mode<Twofish>::Encryption (and decryption) calls UncheckedSetKey to set the key. If the calling code looks OK, then please check Master for the problem. I don't recall a problem that would affect the 5.6.5 ZIP but not affect Master. However, I could be wrong. You can verify the library is OK by running the self tests. Build and run the self tests from Visual Studio or from the command line according to https://www.cryptopp.com/wiki/MSBuild_(Command_Line). Jeff -- -- You received this message because you are subscribed to the "Crypto++ Users" Google Group. To unsubscribe, send an email to cryptopp-users-unsubscr...@googlegroups.com. 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 cryptopp-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.