keygeneration on ios using clang(libc++) never terminates

42 views
Skip to first unread message

thwang

unread,
Oct 29, 2012, 9:08:18 AM10/29/12
to cryptop...@googlegroups.com

Hi all

I have recently change compiler, from gcc(libstdc++) to clang(libc++) on
iOS. After the change the generation of key, using the following snib, never
terminates.
...
CryptoPP::RSAES< CryptoPP::OAEP <CryptoPP::SHA1> >::PrivateKey
privateSessionKey;
CryptoPP::AutoSeededX917RNG<CryptoPP::AES> rng;
privateSessionKey.GenerateRandomWithKeySize(rng, 2048);
...

I haunted it dow to be related to the use of vector<bool> in
nbtheory.cpp(line 310) which seems to give unexpected values when using the
clang(and libc++).
..
308 bool PrimeSieve::NextCandidate(Integer &c)
309 {
310 bool safe = SafeConvert(std::find(m_sieve.begin()+m_next,
m_sieve.end(), false) - m_sieve.begin(), m_next);
311 assert(safe);
312 if (m_next == m_sieve.size())
..

I isolated the issue to the following example:
std::vector<bool> my_vector;
my_vector.push_back(true);
my_vector.push_back(false);
my_vector.push_back(true);
my_vector.push_back(true);
my_vector.push_back(true);
my_vector.push_back(false);
my_vector.push_back(true);
long idx = std::find(my_vector.begin()+2, my_vector.end(), false) -
my_vector.begin();
std::cout << "idx:" << idx << std::endl;

which returns
idx:0
when using clang (and libc++) and
idx:5
when using gcc (and libstdc++) as expected.

Can anybody confirm this issue?

Does anybody know if vector<bool> is used extensive in Crypto++ ?

regards - thwang

--
View this message in context: http://old.nabble.com/keygeneration-on-ios-using-clang%28libc%2B%2B%29-never-terminates-tp34614981p34614981.html
Sent from the Crypto++ Users mailing list archive at Nabble.com.

Marshall Clow

unread,
Oct 29, 2012, 10:39:05 AM10/29/12
to cryptop...@googlegroups.com
Nice catch! - thanks for the simple test case.

I can confirm that this issue is present in the shipping libc++ (tested with Xcode 4.5.1)
I can also confirm that this issue has been fixed in the libc++ source repository at:
https://llvm.org/svn/llvm-project/libcxx/trunk

A short term fix would be to replace just the file "__bit_reference" in your Xcode installation (after backing up, of course) with the one from the libc++ source repo.
On my system, that's in:
/Applications/Xcode.app/Contents/Developer/Toolchain/XcodeDefault.xctoolchain/usr/lib/c++/v1/__bit_reference

-- Marshall

Marshall Clow Idio Software <mailto:mclow...@gmail.com>

A.D. 1517: Martin Luther nails his 95 Theses to the church door and is promptly moderated down to (-1, Flamebait).
-- Yu Suzuki

Fraser Hutchison

unread,
Oct 29, 2012, 4:41:10 PM10/29/12
to Marshall Clow, cryptop...@googlegroups.com
Hi there,

I reported this a while back:
http://sourceforge.net/apps/trac/cryptopp/ticket/17

It looks like there's not much activity in the bug tracker - should I
have reported this elsewhere?

Thanks,
Fraser.

Reply all
Reply to author
Forward
0 new messages