mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-01-29 15:43:52 +00:00
Make Makefile for Mac use clang options instead of old GCC options, and fix a nasty but obvious bug I introduced into Utils::getSecureRandom.
This commit is contained in:
parent
12b297a712
commit
7015017686
@ -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
|
||||
|
@ -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();
|
||||
|
12
selftest.cpp
12
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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user