diff options
author | Adam Ierymenko <adam.ierymenko@gmail.com> | 2013-10-28 15:53:40 -0400 |
---|---|---|
committer | Adam Ierymenko <adam.ierymenko@gmail.com> | 2013-10-28 15:53:40 -0400 |
commit | 7015017686e8cd70421fc366e6c6848156c24197 (patch) | |
tree | afc8a147b19d9e6f3a38daf4d579432975af6bd8 | |
parent | 12b297a7127a752c1ffb51d768072572f035e8da (diff) | |
download | infinitytier-7015017686e8cd70421fc366e6c6848156c24197.tar.gz infinitytier-7015017686e8cd70421fc366e6c6848156c24197.zip |
Make Makefile for Mac use clang options instead of old GCC options, and fix a nasty but obvious bug I introduced into Utils::getSecureRandom.
-rw-r--r-- | Makefile.mac | 6 | ||||
-rw-r--r-- | node/Utils.cpp | 1 | ||||
-rw-r--r-- | selftest.cpp | 12 |
3 files changed, 15 insertions, 4 deletions
diff --git a/Makefile.mac b/Makefile.mac index 6955710e..841ea6cb 100644 --- a/Makefile.mac +++ b/Makefile.mac @@ -1,12 +1,12 @@ -CC=gcc -CXX=g++ +CC=clang +CXX=clang++ INCLUDES= DEFS= LIBS=-lm # Uncomment for a release optimized universal binary build -CFLAGS=-arch i386 -arch x86_64 -Wall -O3 -ftree-vectorize -fstack-protector -pthread -mmacosx-version-min=10.6 -DNDEBUG $(INCLUDES) $(DEFS) +CFLAGS=-arch i386 -arch x86_64 -Wall -O4 -pthread -mmacosx-version-min=10.6 -DNDEBUG $(INCLUDES) $(DEFS) STRIP=strip # Uncomment for a debug build diff --git a/node/Utils.cpp b/node/Utils.cpp index 7e82df2a..c565d8c4 100644 --- a/node/Utils.cpp +++ b/node/Utils.cpp @@ -196,6 +196,7 @@ void Utils::getSecureRandom(void *buf,unsigned int bytes) // A Salsa20 instance is used to mangle whatever our base // random source happens to be. if (!randInitialized) { + randInitialized = true; memset(randbuf,0,sizeof(randbuf)); char s20key[33]; uint64_t s20iv = now(); diff --git a/selftest.cpp b/selftest.cpp index 59b23b02..ba362bd3 100644 --- a/selftest.cpp +++ b/selftest.cpp @@ -68,6 +68,11 @@ static int testCrypto() unsigned char buf1[16384]; unsigned char buf2[sizeof(buf1)],buf3[sizeof(buf1)]; + for(int i=0;i<3;++i) { + Utils::getSecureRandom(buf1,64); + std::cout << "[crypto] getSecureRandom: " << Utils::hex(buf1,64) << std::endl; + } + std::cout << "[crypto] Testing SHA-512... "; std::cout.flush(); SHA512::hash(buf1,sha512TV0Input,strlen(sha512TV0Input)); if (memcmp(buf1,sha512TV0Digest,64)) { @@ -120,17 +125,22 @@ static int testCrypto() std::cout << "PASS" << std::endl; std::cout << "[crypto] Testing C25519 ECC key agreement... "; std::cout.flush(); - for(unsigned int i=0;i<50;++i) { + for(unsigned int i=0;i<100;++i) { + memset(buf1,64,sizeof(buf1)); + memset(buf2,64,sizeof(buf2)); + memset(buf3,64,sizeof(buf3)); C25519::Pair p1 = C25519::generate(); C25519::Pair p2 = C25519::generate(); C25519::Pair p3 = C25519::generate(); C25519::agree(p1,p2.pub,buf1,64); C25519::agree(p2,p1.pub,buf2,64); C25519::agree(p3,p1.pub,buf3,64); + // p1<>p2 should equal p1<>p2 if (memcmp(buf1,buf2,64)) { std::cout << "FAIL (1)" << std::endl; return -1; } + // p2<>p1 should not equal p3<>p1 if (!memcmp(buf2,buf3,64)) { std::cout << "FAIL (2)" << std::endl; return -1; |