diff options
Diffstat (limited to 'modules')
46 files changed, 315 insertions, 152 deletions
diff --git a/modules/alg_amd64/modinfo.txt b/modules/alg_amd64/modinfo.txt index f9023b273..313d9ea03 100644 --- a/modules/alg_amd64/modinfo.txt +++ b/modules/alg_amd64/modinfo.txt @@ -2,7 +2,7 @@ realname "Algorithm x86-64 Assembler" mp_bits 64 -load_on: asm_ok +load_on asm_ok <replace> sha160.cpp diff --git a/modules/alg_amd64/sha160.cpp b/modules/alg_amd64/sha160.cpp index 0c9b3b7dc..76937a577 100644 --- a/modules/alg_amd64/sha160.cpp +++ b/modules/alg_amd64/sha160.cpp @@ -4,7 +4,7 @@ *************************************************/ #include <botan/sha160.h> -#include <botan/bit_ops.h> +#include <botan/loadstor.h> namespace Botan { diff --git a/modules/alg_ia32/md4.cpp b/modules/alg_ia32/md4.cpp index 4c1fca4c3..497c6dbe7 100644 --- a/modules/alg_ia32/md4.cpp +++ b/modules/alg_ia32/md4.cpp @@ -4,7 +4,7 @@ *************************************************/ #include <botan/md4.h> -#include <botan/bit_ops.h> +#include <botan/loadstor.h> namespace Botan { diff --git a/modules/alg_ia32/md5.cpp b/modules/alg_ia32/md5.cpp index 1f5c0c05b..5f2e7061e 100644 --- a/modules/alg_ia32/md5.cpp +++ b/modules/alg_ia32/md5.cpp @@ -4,7 +4,7 @@ *************************************************/ #include <botan/md5.h> -#include <botan/bit_ops.h> +#include <botan/loadstor.h> namespace Botan { diff --git a/modules/alg_ia32/modinfo.txt b/modules/alg_ia32/modinfo.txt index fdd955d11..33d30e8bf 100644 --- a/modules/alg_ia32/modinfo.txt +++ b/modules/alg_ia32/modinfo.txt @@ -2,7 +2,7 @@ realname "Algorithm x86 Assembler" mp_bits 32 -load_on: asm_ok +load_on asm_ok <replace> md4.cpp diff --git a/modules/alg_ia32/serpent.cpp b/modules/alg_ia32/serpent.cpp index 3cb5c6305..bf13772e6 100644 --- a/modules/alg_ia32/serpent.cpp +++ b/modules/alg_ia32/serpent.cpp @@ -4,7 +4,7 @@ *************************************************/ #include <botan/serpent.h> -#include <botan/bit_ops.h> +#include <botan/loadstor.h> namespace Botan { diff --git a/modules/alg_ia32/sha160.cpp b/modules/alg_ia32/sha160.cpp index ffa88e080..11cd5dadb 100644 --- a/modules/alg_ia32/sha160.cpp +++ b/modules/alg_ia32/sha160.cpp @@ -4,7 +4,7 @@ *************************************************/ #include <botan/sha160.h> -#include <botan/bit_ops.h> +#include <botan/loadstor.h> namespace Botan { diff --git a/modules/alloc_mmap/mmap_mem.cpp b/modules/alloc_mmap/mmap_mem.cpp index 2ca73b4b7..b40d24ca0 100644 --- a/modules/alloc_mmap/mmap_mem.cpp +++ b/modules/alloc_mmap/mmap_mem.cpp @@ -59,15 +59,15 @@ void* MemoryMapping_Allocator::alloc_block(u32bit n) filepath = new char[path.length() + 1]; std::strcpy(filepath, path.c_str()); - mode_t old_umask = umask(077); - fd = mkstemp(filepath); - umask(old_umask); + mode_t old_umask = ::umask(077); + fd = ::mkstemp(filepath); + ::umask(old_umask); } ~TemporaryFile() { delete[] filepath; - if(fd != -1 && close(fd) == -1) + if(fd != -1 && ::close(fd) == -1) throw MemoryMapping_Failed("Could not close file"); } private: @@ -80,15 +80,15 @@ void* MemoryMapping_Allocator::alloc_block(u32bit n) if(file.get_fd() == -1) throw MemoryMapping_Failed("Could not create file"); - if(unlink(file.path().c_str())) - throw MemoryMapping_Failed("Could not unlink file " + file.path()); + if(::unlink(file.path().c_str())) + throw MemoryMapping_Failed("Could not unlink file '" + file.path() + "'"); - lseek(file.get_fd(), n-1, SEEK_SET); - if(write(file.get_fd(), "\0", 1) != 1) + ::lseek(file.get_fd(), n-1, SEEK_SET); + if(::write(file.get_fd(), "\0", 1) != 1) throw MemoryMapping_Failed("Could not write to file"); - void* ptr = mmap(0, n, PROT_READ | PROT_WRITE, MAP_SHARED, - file.get_fd(), 0); + void* ptr = ::mmap(0, n, PROT_READ | PROT_WRITE, MAP_SHARED, + file.get_fd(), 0); if(ptr == static_cast<void*>(MAP_FAILED)) throw MemoryMapping_Failed("Could not map file"); @@ -101,23 +101,21 @@ void* MemoryMapping_Allocator::alloc_block(u32bit n) *************************************************/ void MemoryMapping_Allocator::dealloc_block(void* ptr, u32bit n) { - if(ptr == 0) return; + if(ptr == 0) + return; - const u32bit OVERWRITE_PASSES = 12; const byte PATTERNS[] = { 0x00, 0xFF, 0xAA, 0x55, 0x73, 0x8C, 0x5F, 0xA0, - 0x6E, 0x91, 0x30, 0xCF, 0xD3, 0x2C, 0xAC, 0x53 }; + 0x6E, 0x91, 0x30, 0xCF, 0xD3, 0x2C, 0xAC, 0x00 }; - for(u32bit j = 0; j != OVERWRITE_PASSES; j++) + for(u32bit j = 0; j != sizeof(PATTERNS); j++) { - std::memset(ptr, PATTERNS[j % sizeof(PATTERNS)], n); - if(msync(ptr, n, MS_SYNC)) + std::memset(ptr, PATTERNS[j], n); + + if(::msync(ptr, n, MS_SYNC)) throw MemoryMapping_Failed("Sync operation failed"); } - std::memset(ptr, 0, n); - if(msync(ptr, n, MS_SYNC)) - throw MemoryMapping_Failed("Sync operation failed"); - if(munmap(ptr, n)) + if(::munmap(ptr, n)) throw MemoryMapping_Failed("Could not unmap file"); } diff --git a/modules/alloc_mmap/modinfo.txt b/modules/alloc_mmap/modinfo.txt index 6426bdf24..8cc2b206e 100644 --- a/modules/alloc_mmap/modinfo.txt +++ b/modules/alloc_mmap/modinfo.txt @@ -1,8 +1,9 @@ realname "Disk Based Allocation System" define ALLOC_MMAP +modset unix -load_on: auto +load_on auto <add> mmap_mem.cpp diff --git a/modules/comp_bzip2/modinfo.txt b/modules/comp_bzip2/modinfo.txt index 92ffb2085..efedc097f 100644 --- a/modules/comp_bzip2/modinfo.txt +++ b/modules/comp_bzip2/modinfo.txt @@ -3,8 +3,9 @@ realname "Bzip2 Compressor" define COMPRESSOR_BZIP2 +modset compression -load_on: request +load_on request <add> bzip2.h diff --git a/modules/comp_zlib/modinfo.txt b/modules/comp_zlib/modinfo.txt index 1687ad312..c1f1f998c 100644 --- a/modules/comp_zlib/modinfo.txt +++ b/modules/comp_zlib/modinfo.txt @@ -4,7 +4,8 @@ realname "Zlib Compressor" define COMPRESSOR_ZLIB #define COMPRESSOR_ZLIB,COMPRESSOR_GZIP -load_on: request +load_on request +modset compression <add> zlib.h diff --git a/modules/comp_zlib/zlib.cpp b/modules/comp_zlib/zlib.cpp index 4bb014b69..59f8e88c4 100644 --- a/modules/comp_zlib/zlib.cpp +++ b/modules/comp_zlib/zlib.cpp @@ -97,12 +97,12 @@ void Zlib_Compression::start_msg() *************************************************/ void Zlib_Compression::write(const byte input[], u32bit length) { - zlib->stream.next_in = (Bytef*)input; + zlib->stream.next_in = static_cast<Bytef*>(input); zlib->stream.avail_in = length; while(zlib->stream.avail_in != 0) { - zlib->stream.next_out = (Bytef*)buffer.begin(); + zlib->stream.next_out = static_cast<Bytef*>(buffer.begin()); zlib->stream.avail_out = buffer.size(); deflate(&(zlib->stream), Z_NO_FLUSH); send(buffer.begin(), buffer.size() - zlib->stream.avail_out); @@ -120,7 +120,7 @@ void Zlib_Compression::end_msg() int rc = Z_OK; while(rc != Z_STREAM_END) { - zlib->stream.next_out = (Bytef*)buffer.begin(); + zlib->stream.next_out = static_cast<Bytef*>(buffer.begin()); zlib->stream.avail_out = buffer.size(); rc = deflate(&(zlib->stream), Z_FINISH); send(buffer.begin(), buffer.size() - zlib->stream.avail_out); @@ -138,7 +138,7 @@ void Zlib_Compression::flush() while(true) { - zlib->stream.next_out = (Bytef*)buffer.begin(); + zlib->stream.next_out = static_cast<Bytef*>(buffer.begin()); zlib->stream.avail_out = buffer.size(); deflate(&(zlib->stream), Z_FULL_FLUSH); send(buffer.begin(), buffer.size() - zlib->stream.avail_out); @@ -188,12 +188,12 @@ void Zlib_Decompression::write(const byte input[], u32bit length) { if(length) no_writes = false; - zlib->stream.next_in = (Bytef*)input; + zlib->stream.next_in = static_cast<Bytef*>(input; zlib->stream.avail_in = length; while(zlib->stream.avail_in != 0) { - zlib->stream.next_out = (Bytef*)buffer.begin(); + zlib->stream.next_out = static_cast<Bytef*>(buffer.begin(); zlib->stream.avail_out = buffer.size(); int rc = inflate(&(zlib->stream), Z_SYNC_FLUSH); @@ -213,7 +213,7 @@ void Zlib_Decompression::write(const byte input[], u32bit length) { u32bit read_from_block = length - zlib->stream.avail_in; start_msg(); - zlib->stream.next_in = (Bytef*)input + read_from_block; + zlib->stream.next_in = static_cast<Bytef*>(input + read_from_block; zlib->stream.avail_in = length - read_from_block; input += read_from_block; length -= read_from_block; @@ -233,7 +233,7 @@ void Zlib_Decompression::end_msg() int rc = Z_OK; while(rc != Z_STREAM_END) { - zlib->stream.next_out = (Bytef*)buffer.begin(); + zlib->stream.next_out = static_cast<Bytef*>(buffer.begin(); zlib->stream.avail_out = buffer.size(); rc = inflate(&(zlib->stream), Z_SYNC_FLUSH); if(rc != Z_OK && rc != Z_STREAM_END) diff --git a/modules/eng_aep/modinfo.txt b/modules/eng_aep/modinfo.txt index 1ffdb81d5..497a0c89f 100644 --- a/modules/eng_aep/modinfo.txt +++ b/modules/eng_aep/modinfo.txt @@ -2,7 +2,7 @@ realname "AEP Engine" define ENGINE_AEP,ENTROPY_SRC_AEP -load_on: request +load_on request <add> eng_aep.cpp diff --git a/modules/eng_gmp/modinfo.txt b/modules/eng_gmp/modinfo.txt index bc44986de..e65e411fd 100644 --- a/modules/eng_gmp/modinfo.txt +++ b/modules/eng_gmp/modinfo.txt @@ -2,7 +2,7 @@ realname "GMP Engine" define ENGINE_GNU_MP -load_on: request +load_on request <add> eng_gmp.cpp diff --git a/modules/eng_ossl/modinfo.txt b/modules/eng_ossl/modinfo.txt index 3378a9158..7892e8e90 100644 --- a/modules/eng_ossl/modinfo.txt +++ b/modules/eng_ossl/modinfo.txt @@ -2,7 +2,7 @@ realname "OpenSSL Engine" define ENGINE_OPENSSL -load_on: request +load_on request <add> eng_ossl.cpp diff --git a/modules/es_beos/modinfo.txt b/modules/es_beos/modinfo.txt index 292f7832d..a7e62cfb3 100644 --- a/modules/es_beos/modinfo.txt +++ b/modules/es_beos/modinfo.txt @@ -1,8 +1,9 @@ realname "BeOS Entropy Source" define ENTROPY_SRC_BEOS +modset beos -load_on: auto +load_on auto <add> es_beos.h diff --git a/modules/es_capi/modinfo.txt b/modules/es_capi/modinfo.txt index 8a0f3041c..40104664b 100644 --- a/modules/es_capi/modinfo.txt +++ b/modules/es_capi/modinfo.txt @@ -1,8 +1,8 @@ realname "Win32 CryptoAPI Entropy Source" define ENTROPY_SRC_CAPI - -load_on: auto +load_on auto +modset win32 <add> es_capi.h diff --git a/modules/es_dev/es_dev.cpp b/modules/es_dev/es_dev.cpp new file mode 100644 index 000000000..61127388a --- /dev/null +++ b/modules/es_dev/es_dev.cpp @@ -0,0 +1,118 @@ +/************************************************* +* Device EntropySource Source File * +* (C) 1999-2007 The Botan Project * +*************************************************/ + +#include <botan/es_dev.h> +#include <botan/config.h> +#include <sys/select.h> +#include <sys/stat.h> +#include <sys/types.h> +#include <sys/fcntl.h> +#include <unistd.h> + +namespace Botan { + +namespace { + +/************************************************* +* A class handling reading from a device * +*************************************************/ +class Device_Reader + { + public: + typedef int fd_type; + + Device_Reader(fd_type device_fd) : fd(device_fd) {} + ~Device_Reader() { ::close(fd); } + u32bit get(byte out[], u32bit length); + + static fd_type open(const std::string& pathname); + private: + fd_type fd; + }; + +/************************************************* +* Read from a device file * +*************************************************/ +u32bit Device_Reader::get(byte out[], u32bit length) + { + if(fd < 0) + return 0; + + if(fd >= FD_SETSIZE) + return 0; + + const u32bit READ_WAIT_MS = 10; + + fd_set read_set; + FD_ZERO(&read_set); + FD_SET(fd, &read_set); + + struct ::timeval timeout; + timeout.tv_sec = 0; + timeout.tv_usec = READ_WAIT_MS * 1000; + + if(::select(fd + 1, &read_set, 0, 0, &timeout) < 0) + return 0; + + if(!(FD_ISSET(fd, &read_set))) + return 0; + + const ssize_t got = ::read(fd, out, length); + if(got <= 0) + return 0; + + const u32bit ret = static_cast<u32bit>(got); + + if(ret > length) + return 0; + + return ret; + } + +/************************************************* +* Attempt to open a device * +*************************************************/ +int Device_Reader::open(const std::string& pathname) + { +#ifndef O_NONBLOCK + #define O_NONBLOCK 0 +#endif + +#ifndef O_NOCTTY + #define O_NOCTTY 0 +#endif + + const int flags = O_RDONLY | O_NONBLOCK | O_NOCTTY; + return ::open(pathname.c_str(), flags); + } + +} + +/************************************************* +* Gather entropy from a RNG device * +*************************************************/ +u32bit Device_EntropySource::slow_poll(byte output[], u32bit length) + { + std::vector<std::string> sources = + global_config().option_as_list("rng/es_files"); + + u32bit read = 0; + + for(size_t j = 0; j != sources.size(); ++j) + { + const std::string source = sources[j]; + + Device_Reader reader(Device_Reader::open(source)); + + read += reader.get(output + read, length - read); + + if(read == length) + break; + } + + return read; + } + +} diff --git a/modules/es_dev/es_dev.h b/modules/es_dev/es_dev.h new file mode 100644 index 000000000..d491a7b18 --- /dev/null +++ b/modules/es_dev/es_dev.h @@ -0,0 +1,24 @@ +/************************************************* +* Device EntropySource Header File * +* (C) 1999-2007 The Botan Project * +*************************************************/ + +#ifndef BOTAN_ENTROPY_SRC_DEVICE_H__ +#define BOTAN_ENTROPY_SRC_DEVICE_H__ + +#include <botan/base.h> + +namespace Botan { + +/************************************************* +* Device Based Entropy Source * +*************************************************/ +class Device_EntropySource : public EntropySource + { + public: + u32bit slow_poll(byte[], u32bit); + }; + +} + +#endif diff --git a/modules/es_dev/modinfo.txt b/modules/es_dev/modinfo.txt new file mode 100644 index 000000000..3a766013d --- /dev/null +++ b/modules/es_dev/modinfo.txt @@ -0,0 +1,11 @@ +realname "RNG Device Reader" + +define ENTROPY_SRC_DEVICE + +load_on auto +modset unix + +<add> +es_dev.h +es_dev.cpp +</add> diff --git a/modules/es_egd/es_egd.cpp b/modules/es_egd/es_egd.cpp index 0ff19a90b..2fbd03598 100644 --- a/modules/es_egd/es_egd.cpp +++ b/modules/es_egd/es_egd.cpp @@ -52,25 +52,25 @@ u32bit EGD_EntropySource::do_poll(byte output[], u32bit length, throw Exception("EGD_EntropySource: Socket path is too long"); std::strcpy(addr.sun_path, path.c_str()); - int fd = socket(addr.sun_family, SOCK_STREAM, 0); + int fd = ::socket(addr.sun_family, SOCK_STREAM, 0); if(fd == -1) return 0; int len = sizeof(addr.sun_family) + std::strlen(addr.sun_path) + 1; - if(connect(fd, (struct sockaddr*)&addr, len)) - { close(fd); return 0; } + if(::connect(fd, reinterpret_cast<struct ::sockaddr*>(&addr), len)) + { ::close(fd); return 0; } byte buffer[2]; buffer[0] = 1; buffer[1] = static_cast<byte>(length); - if(write(fd, buffer, 2) != 2) { close(fd); return 0; } - if(read(fd, buffer, 1) != 1) { close(fd); return 0; } + if(::write(fd, buffer, 2) != 2) { ::close(fd); return 0; } + if(::read(fd, buffer, 1) != 1) { ::close(fd); return 0; } - ssize_t count = read(fd, output, buffer[0]); + ssize_t count = ::read(fd, output, buffer[0]); if(count == -1) { close(fd); return 0; } - close(fd); + ::close(fd); return count; } diff --git a/modules/es_egd/modinfo.txt b/modules/es_egd/modinfo.txt index 06261862c..6b34f395c 100644 --- a/modules/es_egd/modinfo.txt +++ b/modules/es_egd/modinfo.txt @@ -2,7 +2,8 @@ realname "EGD Entropy Source" define ENTROPY_SRC_EGD -load_on: auto +load_on auto +modset unix <add> es_egd.h diff --git a/modules/es_ftw/es_ftw.cpp b/modules/es_ftw/es_ftw.cpp index 412a95f57..63531eb53 100644 --- a/modules/es_ftw/es_ftw.cpp +++ b/modules/es_ftw/es_ftw.cpp @@ -56,32 +56,32 @@ void FTW_EntropySource::gather_from_dir(const std::string& dirname) if(dirname == "" || files_read >= max_read) return; - DIR* dir = opendir(dirname.c_str()); + DIR* dir = ::opendir(dirname.c_str()); if(dir == 0) return; std::vector<std::string> subdirs; - dirent* entry = readdir(dir); + dirent* entry = ::readdir(dir); while(entry && (files_read < max_read)) { if((std::strcmp(entry->d_name, ".") == 0) || (std::strcmp(entry->d_name, "..") == 0)) - { entry = readdir(dir); continue; } + { entry = ::readdir(dir); continue; } const std::string filename = dirname + '/' + entry->d_name; - struct stat stat_buf; - if(lstat(filename.c_str(), &stat_buf) == -1) - { entry = readdir(dir); continue; } + struct ::stat stat_buf; + if(::lstat(filename.c_str(), &stat_buf) == -1) + { entry = ::readdir(dir); continue; } if(S_ISREG(stat_buf.st_mode)) gather_from_file(filename); else if(S_ISDIR(stat_buf.st_mode)) subdirs.push_back(filename); - entry = readdir(dir); + entry = ::readdir(dir); } - closedir(dir); + ::closedir(dir); for(u32bit j = 0; j != subdirs.size(); j++) gather_from_dir(subdirs[j]); @@ -98,7 +98,7 @@ void FTW_EntropySource::gather_from_file(const std::string& filename) SecureVector<byte> read_buf(1024); ssize_t got = ::read(fd, read_buf.begin(), read_buf.size()); - close(fd); + ::close(fd); if(got > 0) { diff --git a/modules/es_ftw/modinfo.txt b/modules/es_ftw/modinfo.txt index d3e93db69..d932523fd 100644 --- a/modules/es_ftw/modinfo.txt +++ b/modules/es_ftw/modinfo.txt @@ -2,7 +2,8 @@ realname "File Tree Walking Entropy Source" define ENTROPY_SRC_FTW -load_on: auto +load_on auto +modset unix <add> es_ftw.h diff --git a/modules/es_unix/es_unix.cpp b/modules/es_unix/es_unix.cpp index 243ba9164..40be78e22 100644 --- a/modules/es_unix/es_unix.cpp +++ b/modules/es_unix/es_unix.cpp @@ -8,6 +8,10 @@ #include <botan/parsing.h> #include <botan/config.h> #include <algorithm> +#include <sys/time.h> +#include <sys/stat.h> +#include <sys/resource.h> +#include <unistd.h> namespace Botan { @@ -43,7 +47,35 @@ void Unix_EntropySource::add_sources(const Unix_Program srcs[], u32bit count) *************************************************/ void Unix_EntropySource::do_fast_poll() { - gather(2*1024); + const char* STAT_TARGETS[] = { "/", "/tmp", ".", "..", 0 }; + + for(u32bit j = 0; STAT_TARGETS[j]; j++) + { + struct ::stat statbuf; + clear_mem(&statbuf, 1); + ::stat(STAT_TARGETS[j], &statbuf); + add_bytes(&statbuf, sizeof(statbuf)); + } + + add_bytes(::getpid()); + add_bytes(::getppid()); + + add_bytes(::getuid()); + add_bytes(::getgid()); + add_bytes(::geteuid()); + add_bytes(::getegid()); + + add_bytes(::getpgrp()); + add_bytes(::getsid(0)); + + struct ::rusage usage; + + clear_mem(&usage, 1); + ::getrusage(RUSAGE_SELF, &usage); + add_bytes(&usage, sizeof(usage)); + + ::getrusage(RUSAGE_CHILDREN, &usage); + add_bytes(&usage, sizeof(usage)); } /************************************************* @@ -51,56 +83,34 @@ void Unix_EntropySource::do_fast_poll() *************************************************/ void Unix_EntropySource::do_slow_poll() { - gather(16*1024); - } - -/************************************************* -* Gather Entropy From Several Unix_Programs * -*************************************************/ -void Unix_EntropySource::gather(u32bit target_amount) - { + const u32bit TRY_TO_GET = 16 * 1024; const u32bit MINIMAL_WORKING = 32; + const std::string PATH = global_config().option("rng/unix_path"); + u32bit got = 0; for(u32bit j = 0; j != sources.size(); j++) { add_timestamp(); - got += gather_from(sources[j]); - sources[j].working = (got >= MINIMAL_WORKING) ? true : false; + DataSource_Command pipe(sources[j].name_and_args, PATH); + SecureVector<byte> buffer(DEFAULT_BUFFERSIZE); - if(got >= target_amount) - break; - } - } + u32bit got_from_src = 0; -/************************************************* -* Gather entropy from a Unix program * -*************************************************/ -u32bit Unix_EntropySource::gather_from(const Unix_Program& prog) - { - const std::string BASE_PATH = "/bin:/sbin:/usr/bin:/usr/sbin"; - const std::string EXTRA_PATH = global_config().option("rng/unix_path"); + while(!pipe.end_of_data()) + { + u32bit this_loop = pipe.read(buffer, buffer.size()); + add_bytes(buffer, this_loop); + got_from_src += this_loop; + } - std::string PATH = BASE_PATH; - if(EXTRA_PATH != "") - PATH += ':' + EXTRA_PATH; + sources[j].working = (got_from_src >= MINIMAL_WORKING) ? true : false; + got += got_from_src; - DataSource_Command pipe(prog.name_and_args, PATH); - if(pipe.end_of_data()) - return 0; - - u32bit got = 0; - SecureVector<byte> buffer(DEFAULT_BUFFERSIZE); - - while(!pipe.end_of_data()) - { - u32bit this_loop = pipe.read(buffer, buffer.size()); - add_bytes(buffer, this_loop); - got += this_loop; + if(got >= TRY_TO_GET) + break; } - - return got; } } diff --git a/modules/es_unix/es_unix.h b/modules/es_unix/es_unix.h index 167bafc89..149e6f395 100644 --- a/modules/es_unix/es_unix.h +++ b/modules/es_unix/es_unix.h @@ -21,11 +21,10 @@ class Unix_EntropySource : public Buffered_EntropySource void add_sources(const Unix_Program[], u32bit); Unix_EntropySource(); private: + static void add_default_sources(std::vector<Unix_Program>&); + void do_fast_poll(); void do_slow_poll(); - void gather(u32bit); - u32bit gather_from(const Unix_Program&); - static void add_default_sources(std::vector<Unix_Program>&); std::vector<Unix_Program> sources; }; diff --git a/modules/es_unix/modinfo.txt b/modules/es_unix/modinfo.txt index ccb499b82..f16e21289 100644 --- a/modules/es_unix/modinfo.txt +++ b/modules/es_unix/modinfo.txt @@ -1,8 +1,9 @@ realname "Generic Unix Entropy Source" define ENTROPY_SRC_UNIX +modset unix,beos -load_on: auto +load_on auto <add> es_unix.cpp diff --git a/modules/es_unix/unix_cmd.cpp b/modules/es_unix/unix_cmd.cpp index dbefc7e3e..65def8c74 100644 --- a/modules/es_unix/unix_cmd.cpp +++ b/modules/es_unix/unix_cmd.cpp @@ -41,7 +41,7 @@ void do_exec(const std::vector<std::string>& arg_list, { const std::string full_path = paths[j] + "/" + arg_list[0]; const char* fsname = full_path.c_str(); - execl(fsname, fsname, arg1, arg2, arg3, arg4, 0); + ::execl(fsname, fsname, arg1, arg2, arg3, arg4, 0); } } @@ -69,12 +69,12 @@ u32bit DataSource_Command::read(byte buf[], u32bit length) FD_ZERO(&set); FD_SET(pipe->fd, &set); - struct timeval tv; + struct ::timeval tv; tv.tv_sec = 0; tv.tv_usec = MAX_BLOCK_USECS; ssize_t got = 0; - if(select(pipe->fd + 1, &set, 0, 0, &tv) == 1) + if(::select(pipe->fd + 1, &set, 0, 0, &tv) == 1) { if(FD_ISSET(pipe->fd, &set)) got = ::read(pipe->fd, buf, length); @@ -136,7 +136,7 @@ void DataSource_Command::create_pipe(const std::string& path) for(u32bit j = 0; j != paths.size(); j++) { const std::string full_path = paths[j] + "/" + arg_list[0]; - if(access(full_path.c_str(), X_OK) == 0) + if(::access(full_path.c_str(), X_OK) == 0) { found_something = true; break; @@ -149,31 +149,31 @@ void DataSource_Command::create_pipe(const std::string& path) if(::pipe(pipe_fd) != 0) return; - pid_t pid = fork(); + pid_t pid = ::fork(); if(pid == -1) { - close(pipe_fd[0]); - close(pipe_fd[1]); + ::close(pipe_fd[0]); + ::close(pipe_fd[1]); } else if(pid > 0) { pipe = new pipe_wrapper; pipe->fd = pipe_fd[0]; pipe->pid = pid; - close(pipe_fd[1]); + ::close(pipe_fd[1]); } else { if(dup2(pipe_fd[1], STDOUT_FILENO) == -1) - exit(127); + ::exit(127); if(close(pipe_fd[0]) != 0 || close(pipe_fd[1]) != 0) - exit(127); + ::exit(127); if(close(STDERR_FILENO) != 0) - exit(127); + ::exit(127); do_exec(arg_list, paths); - exit(127); + ::exit(127); } } @@ -190,23 +190,23 @@ void DataSource_Command::shutdown_pipe() { kill(pipe->pid, SIGTERM); - struct timeval tv; + struct ::timeval tv; tv.tv_sec = 0; tv.tv_usec = KILL_WAIT; select(0, 0, 0, 0, &tv); - reaped = waitpid(pipe->pid, 0, WNOHANG); + reaped = ::waitpid(pipe->pid, 0, WNOHANG); if(reaped == 0) { - kill(pipe->pid, SIGKILL); + ::kill(pipe->pid, SIGKILL); do - reaped = waitpid(pipe->pid, 0, 0); + reaped = ::waitpid(pipe->pid, 0, 0); while(reaped == -1); } } - close(pipe->fd); + ::close(pipe->fd); delete pipe; pipe = 0; } diff --git a/modules/es_win32/modinfo.txt b/modules/es_win32/modinfo.txt index cc8a525bc..931760979 100644 --- a/modules/es_win32/modinfo.txt +++ b/modules/es_win32/modinfo.txt @@ -4,8 +4,9 @@ realname "Win32 Entropy Source" #note "This module will not run under NT4" define ENTROPY_SRC_WIN32 +modset win32 -load_on: auto +load_on auto <add> es_win32.h diff --git a/modules/fd_unix/modinfo.txt b/modules/fd_unix/modinfo.txt index c659f5377..e1f30ea28 100644 --- a/modules/fd_unix/modinfo.txt +++ b/modules/fd_unix/modinfo.txt @@ -1,8 +1,9 @@ realname "Unix I/O support for Pipe" define PIPE_UNIXFD_IO +modset unix,beos -load_on: auto +load_on auto <add> fd_unix.h diff --git a/modules/ml_unix/modinfo.txt b/modules/ml_unix/modinfo.txt index b25468586..201a30ead 100644 --- a/modules/ml_unix/modinfo.txt +++ b/modules/ml_unix/modinfo.txt @@ -1,6 +1,6 @@ realname "Memory Locking for Unix" -load_on: auto +load_on auto <replace> mlock.cpp diff --git a/modules/ml_win32/modinfo.txt b/modules/ml_win32/modinfo.txt index e886c758f..92936e1de 100644 --- a/modules/ml_win32/modinfo.txt +++ b/modules/ml_win32/modinfo.txt @@ -1,6 +1,6 @@ realname "Memory Locking for Win32" -load_on: auto +load_on auto <replace> mlock.cpp diff --git a/modules/mp_amd64/modinfo.txt b/modules/mp_amd64/modinfo.txt index 0e24da0d9..527d9a2c6 100644 --- a/modules/mp_amd64/modinfo.txt +++ b/modules/mp_amd64/modinfo.txt @@ -2,7 +2,7 @@ realname "MPI Assembler Backend for x86-64/AMD64 Systems" mp_bits 64 -load_on: asm_ok +load_on asm_ok <replace> mp_asm.h diff --git a/modules/mp_asm64/modinfo.txt b/modules/mp_asm64/modinfo.txt index 256a439d3..e371c9ede 100644 --- a/modules/mp_asm64/modinfo.txt +++ b/modules/mp_asm64/modinfo.txt @@ -2,16 +2,14 @@ realname "MPI Assembler Backend for 64 bit Systems" mp_bits 64 -load_on: asm_ok +load_on asm_ok <replace> mp_asm.h </replace> -# Disable amd64 since (nominally) the mp_amd64 module has that covered <arch> alpha -# amd64 ia64 mips64 ppc64 diff --git a/modules/mp_asm64/mp_asm.h b/modules/mp_asm64/mp_asm.h index b3a60219d..6abab6166 100644 --- a/modules/mp_asm64/mp_asm.h +++ b/modules/mp_asm64/mp_asm.h @@ -12,14 +12,7 @@ #error The mp_asm64 module requires that BOTAN_MP_WORD_BITS == 64 #endif -#if defined(BOTAN_TARGET_ARCH_IS_AMD64) - -#define BOTAN_WORD_MUL(a,b,z1,z0) do { \ - asm("mulq %3" : "=d" (z0), "=a" (z1) : \ - "a" (a), "rm" (b) : "cc"); \ -} while(0); - -#elif defined(BOTAN_TARGET_ARCH_IS_ALPHA) +#if defined(BOTAN_TARGET_ARCH_IS_ALPHA) #define BOTAN_WORD_MUL(a,b,z1,z0) do { \ asm("umulh %1,%2,%0" : "=r" (z0) : "r" (a), "r" (b)); \ diff --git a/modules/mp_ia32/modinfo.txt b/modules/mp_ia32/modinfo.txt index 805fb656f..2fa8db56e 100644 --- a/modules/mp_ia32/modinfo.txt +++ b/modules/mp_ia32/modinfo.txt @@ -2,7 +2,7 @@ realname "MPI Assembler Backend for x86 Systems" mp_bits 32 -load_on: asm_ok +load_on asm_ok <replace> mp_asm.h diff --git a/modules/mux_pthr/modinfo.txt b/modules/mux_pthr/modinfo.txt index f14137dd5..88de70de0 100644 --- a/modules/mux_pthr/modinfo.txt +++ b/modules/mux_pthr/modinfo.txt @@ -2,7 +2,7 @@ realname "Pthread Mutex" define MUTEX_PTHREAD -load_on: auto +load_on auto <add> mux_pthr.cpp diff --git a/modules/mux_qt/modinfo.txt b/modules/mux_qt/modinfo.txt index 32094eaf4..a21108c79 100644 --- a/modules/mux_qt/modinfo.txt +++ b/modules/mux_qt/modinfo.txt @@ -4,7 +4,7 @@ define MUTEX_QT note "You'll probably have to add -I/-L flags to the Makefile to find Qt" -load_on: request +load_on request <add> mux_qt.cpp diff --git a/modules/mux_win32/modinfo.txt b/modules/mux_win32/modinfo.txt index 320d21b5b..d235ff73c 100644 --- a/modules/mux_win32/modinfo.txt +++ b/modules/mux_win32/modinfo.txt @@ -1,8 +1,9 @@ realname "Win32 Mutex" define MUTEX_WIN32 +modset win32 -load_on: auto +load_on auto <add> mux_win32.cpp diff --git a/modules/tm_hard/modinfo.txt b/modules/tm_hard/modinfo.txt index 35f13dd91..5c928cf83 100644 --- a/modules/tm_hard/modinfo.txt +++ b/modules/tm_hard/modinfo.txt @@ -2,7 +2,7 @@ realname "Hardware Timer" define TIMER_HARDWARE -load_on: asm_ok +load_on asm_ok <add> tm_hard.cpp diff --git a/modules/tm_hard/tm_hard.cpp b/modules/tm_hard/tm_hard.cpp index da9aa3fd2..251fc9cfd 100644 --- a/modules/tm_hard/tm_hard.cpp +++ b/modules/tm_hard/tm_hard.cpp @@ -18,11 +18,11 @@ u64bit Hardware_Timer::clock() const #if defined(BOTAN_TARGET_ARCH_IS_IA32) || defined(BOTAN_TARGET_ARCH_IS_AMD64) u32bit rtc_low = 0, rtc_high = 0; asm volatile("rdtsc" : "=d" (rtc_high), "=a" (rtc_low)); - rtc = ((u64bit)rtc_high << 32) | rtc_low; + rtc = (static_cast<u64bit>(rtc_high) << 32) | rtc_low; #elif defined(BOTAN_TARGET_ARCH_IS_PPC) || defined(BOTAN_TARGET_ARCH_IS_PPC64) u32bit rtc_low = 0, rtc_high = 0; asm volatile("mftbu %0; mftb %1" : "=r" (rtc_high), "=r" (rtc_low)); - rtc = ((u64bit)rtc_high << 32) | rtc_low; + rtc = (static_cast<u64bit>(rtc_high) << 32) | rtc_low; #elif defined(BOTAN_TARGET_ARCH_IS_ALPHA) asm volatile("rpcc %0" : "=r" (rtc)); #elif defined(BOTAN_TARGET_ARCH_IS_SPARC64) diff --git a/modules/tm_posix/modinfo.txt b/modules/tm_posix/modinfo.txt index b6c1d6916..e9298a81c 100644 --- a/modules/tm_posix/modinfo.txt +++ b/modules/tm_posix/modinfo.txt @@ -2,7 +2,7 @@ realname "POSIX Timer" define TIMER_POSIX -load_on: auto +load_on auto <add> tm_posix.cpp diff --git a/modules/tm_posix/tm_posix.cpp b/modules/tm_posix/tm_posix.cpp index 7a6b667c4..e5e1f3f93 100644 --- a/modules/tm_posix/tm_posix.cpp +++ b/modules/tm_posix/tm_posix.cpp @@ -23,8 +23,8 @@ namespace Botan { *************************************************/ u64bit POSIX_Timer::clock() const { - struct timespec tv; - clock_gettime(CLOCK_REALTIME, &tv); + struct ::timespec tv; + ::clock_gettime(CLOCK_REALTIME, &tv); return combine_timers(tv.tv_sec, tv.tv_nsec, 1000000000); } diff --git a/modules/tm_unix/modinfo.txt b/modules/tm_unix/modinfo.txt index 405e341c4..495914589 100644 --- a/modules/tm_unix/modinfo.txt +++ b/modules/tm_unix/modinfo.txt @@ -2,7 +2,8 @@ realname "Unix Timer" define TIMER_UNIX -load_on: auto +load_on auto +modset unix,beos <add> tm_unix.cpp diff --git a/modules/tm_unix/tm_unix.cpp b/modules/tm_unix/tm_unix.cpp index cb9a8431f..51224a7d2 100644 --- a/modules/tm_unix/tm_unix.cpp +++ b/modules/tm_unix/tm_unix.cpp @@ -14,8 +14,8 @@ namespace Botan { *************************************************/ u64bit Unix_Timer::clock() const { - struct timeval tv; - gettimeofday(&tv, 0); + struct ::timeval tv; + ::gettimeofday(&tv, 0); return combine_timers(tv.tv_sec, tv.tv_usec, 1000000); } diff --git a/modules/tm_win32/modinfo.txt b/modules/tm_win32/modinfo.txt index cc5f06197..74c4a59ea 100644 --- a/modules/tm_win32/modinfo.txt +++ b/modules/tm_win32/modinfo.txt @@ -1,8 +1,9 @@ realname "Win32 Timer" define TIMER_WIN32 +modset win32 -load_on: auto +load_on auto <add> tm_win32.cpp |