⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 init.cpp

📁 含有多种公开密钥算法、多种块加密、多种数据流加密、多种HASH函数、多种CheckSum校验、多种MAC校验等几十种加密算法的程序
💻 CPP
字号:
/************************************************** Initalization Function Source File             ** (C) 1999-2002 The Botan Project                **************************************************/#include <botan/init.h>#include <botan/allocate.h>#include <botan/rng.h>#include <botan/mutex.h>#include <botan/timers.h>#include <botan/randpool.h>#include <botan/x917_rng.h>#include <botan/look_add.h>#include <map>#if defined(BOTAN_EXT_MUTEX_PTHREAD)  #include <botan/mux_pthr.h>#endif#if defined(BOTAN_EXT_ALLOC_MMAP)  #include <botan/mmap_mem.h>#endif#if defined(BOTAN_EXT_ALLOC_MLOCK)  #include <botan/lock_mem.h>#endif#if defined(BOTAN_EXT_TIMER_HARDWARE)  #include <botan/tm_hard.h>#elif defined(BOTAN_EXT_TIMER_POSIX)  #include <botan/tm_posix.h>#elif defined(BOTAN_EXT_TIMER_UNIX)  #include <botan/tm_unix.h>#endifnamespace Botan {namespace {/************************************************** Parse the option string                        **************************************************/std::map<std::string, std::string> parse_args(const std::string& flags)   {   std::string opt_string = flags + " ";   std::map<std::string, std::string> options;   std::string::size_type start = 0, end = opt_string.find(" ");   while(end != std::string::npos)      {      std::string option = opt_string.substr(start, end-start);      start = end+1;      end = opt_string.find(" ", start);      if(option == "")         continue;      if(option.find("=") == std::string::npos)         options[option] = "";      else         {         std::string::size_type split = option.find("=");         std::string opt_name = option.substr(0, split);         std::string arg = option.substr(split + 1, option.length());         if(opt_name == "")            continue;         options[opt_name] = arg;         }      }   return options;   }/************************************************** Check if an option is set in the argument      **************************************************/bool arg_set(const std::map<std::string, std::string>& args,             const std::string& option)   {   if(args.find(option) != args.end())      return true;   return false;   }/************************************************** Register a mutex type, if possible             **************************************************/bool set_mutex()   {#if defined(BOTAN_EXT_MUTEX_PTHREAD)   set_mutex_type(new Pthread_Mutex);   return true;#else   return false;#endif   }/************************************************** Register a high resolution timer, if possible  **************************************************/void set_timer()   {#if defined(BOTAN_EXT_TIMER_HARDWARE)   set_timer_type(new Hardware_Timer);#elif defined(BOTAN_EXT_TIMER_POSIX)   set_timer_type(new POSIX_Timer);#elif defined(BOTAN_EXT_TIMER_UNIX)   set_timer_type(new Unix_Timer);#endif   }/************************************************** Register a more secure allocator, if possible  **************************************************/void set_safe_allocator()   {#if defined(BOTAN_EXT_ALLOC_MLOCK)   add_allocator_type("mlock", new MemoryLocking_Allocator);   set_default_allocator("mlock");#endif#if defined(BOTAN_EXT_ALLOC_MMAP)   add_allocator_type("mmap", new MemoryMapping_Allocator);   set_default_allocator("mmap");#endif   }}/************************************************** Internal startup/shutdown functions            **************************************************/extern void initalize_memory_subsystem();extern void shutdown_memory_subsystem();extern void create_global_bigints();extern void delete_global_bigints();extern void init_lookup_tables();extern void destroy_lookup_tables();extern void load_algorithms_list();/************************************************** Libary Initalization                           **************************************************/LibraryInitializer::LibraryInitializer(const std::string& arg_string)   {   std::map<std::string, std::string> args = parse_args(arg_string);   if(arg_set(args, "thread_safe"))      if(!set_mutex())         throw Exception("LibraryInitializer: thread safety impossible");   initalize_memory_subsystem();   create_global_bigints();   init_lookup_tables();   load_algorithms_list();   if(arg_set(args, "secure_memory"))      set_safe_allocator();   if(!arg_set(args, "no_timers"))      set_timer();   if(arg_set(args, "fast_rng"))      set_global_rng(new ANSI_X917_RNG);   else      set_global_rng(new Randpool);   u32bit seeding_level = 0;   if(arg_set(args, "egd_path")) seeding_level = 1;   if(arg_set(args, "seed_rng")) seeding_level = 2;   if(arg_set(args, "egd_path"))      Global_RNG::seed(seeding_level, args["egd_path"]);   else      Global_RNG::seed(seeding_level);   }/************************************************** Libary Deinitialization                        **************************************************/LibraryInitializer::~LibraryInitializer()   {   set_global_rng(0);   destroy_lookup_tables();   delete_global_bigints();   set_timer_type(0);   set_mutex_type(0);   shutdown_memory_subsystem();   }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -