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

📄 mp_kmul.cpp

📁 含有多种公开密钥算法、多种块加密、多种数据流加密、多种HASH函数、多种CheckSum校验、多种MAC校验等几十种加密算法的程序
💻 CPP
字号:
/************************************************** Karatsuba Multiplication Source File           ** (C) 1999-2002 The Botan Project                **************************************************/#include <botan/mp_core.h>#include <botan/util.h>#include <botan/exceptn.h>namespace Botan {#define KARATSUBA_CORE(N1, N2, INNER_MUL, x0, x1, y0, y1, z0, z1)   \   {                                                                \   const s32bit cmp0 = bigint_cmp(x0, N2, x1, N2);                  \   const s32bit cmp1 = bigint_cmp(y1, N2, y0, N2);                  \                                                                    \   bool positive = (cmp0 == cmp1) || (cmp0 == 0) || (cmp1 == 0);    \                                                                    \   word temp[N1+N1+1] = { 0 };                                      \   word* middle = temp + N1;                                        \                                                                    \   if(cmp0 && cmp1)                                                 \      {                                                             \      if(cmp0 == 1)                                                 \         bigint_sub3(middle, x0, N2, x1, N2);                       \      else                                                          \         bigint_sub3(middle, x1, N2, x0, N2);                       \                                                                    \      if(cmp1 == 1)                                                 \         bigint_sub3(z, y1, N2, y0, N2);                            \      else                                                          \         bigint_sub3(z, y0, N2, y1, N2);                            \                                                                    \      INNER_MUL(temp, middle, z);                                   \      }                                                             \                                                                    \   INNER_MUL(z0, x0, y0);                                           \   INNER_MUL(z1, x1, y1);                                           \                                                                    \   bigint_add3(middle, z0, N1, z1, N1);                             \                                                                    \   if(positive)                                                     \      bigint_add2(middle, N1+1, temp, N1);                          \   else                                                             \      {                                                             \      const s32bit scmp = bigint_cmp(middle, N1+1, temp, N1);       \                                                                    \      if(scmp < 0)                                                  \         throw Internal_Error("bigint_karat" + to_string(N1) +      \                              ": scmp < 0");                        \                                                                    \      if(scmp > 0)                                                  \         bigint_sub2(middle, N1+1, temp, N1);                       \      else if(scmp == 0)                                            \         clear_mem(middle, N1+1);                                   \      }                                                             \                                                                    \   bigint_add2(z + N2, 2*N1-N2, middle, N1+1);                      \   }/************************************************** Karatsuba 16x16 Multiplication                 **************************************************/void bigint_karat16(word z[32], const word x[16], const word y[16])   {   KARATSUBA_CORE(16, 8, bigint_comba8,                  x, x + 8, y, y + 8, z, z + 16);   }/************************************************** Karatsuba 32x32 Multiplication                 **************************************************/void bigint_karat32(word z[64], const word x[32], const word y[32])   {   KARATSUBA_CORE(32, 16, bigint_karat16,                  x, x + 16, y, y + 16, z, z + 32);   }/************************************************** Karatsuba 64x64 Multiplication                 **************************************************/void bigint_karat64(word z[128], const word x[64], const word y[64])   {   KARATSUBA_CORE(64, 32, bigint_karat32,                  x, x + 32, y, y + 32, z, z + 64);   }/************************************************** Karatsuba 128x128 Multiplication               **************************************************/void bigint_karat128(word z[256], const word x[128], const word y[128])   {   KARATSUBA_CORE(128, 64, bigint_karat64,                  x, x + 64, y, y + 64, z, z + 128);   }}

⌨️ 快捷键说明

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