mp_core2.cpp
来自「含有多种公开密钥算法、多种块加密、多种数据流加密、多种HASH函数、多种Chec」· C++ 代码 · 共 84 行
CPP
84 行
/************************************************** Two Operand MP Algorithms Source File ** (C) 1999-2002 The Botan Project **************************************************/#include <botan/mp_core.h>extern "C" {/************************************************** Two Operand Addition Without Carry **************************************************/word bigint_add2_nc(word* const x, u32bit x_size, const word* y, u32bit y_size) { word carry = 0; for(u32bit j = 0; j != y_size; j++) { dword sum = ((dword)x[j] + y[j]) + carry; x[j] = MP_LOW_WORD(sum); carry = MP_HIGH_WORD(sum); } if(!carry) return 0; for(u32bit j = y_size; j != x_size; j++) { x[j]++; if(x[j]) return 0; } return 1; }/************************************************** Two Operand Addition **************************************************/void bigint_add2(word* const x, u32bit x_size, const word* y, u32bit y_size) { x[x_size] += bigint_add2_nc(x, x_size, y, y_size); }/************************************************** Two Operand Subtraction **************************************************/void bigint_sub2(word* const x, u32bit x_size, const word* y, u32bit y_size) { word borrow = 0; for(u32bit j = 0; j != y_size; j++) { dword temp = ((MP_RADIX + x[j]) - y[j]) - borrow; borrow = ((temp < MP_RADIX) ? 1 : 0); x[j] = (word)(temp - MP_RADIX); } for(u32bit j = y_size; j != x_size; j++) { if(borrow == 0) break; dword temp = (MP_RADIX + x[j]) - borrow; borrow = ((temp < MP_RADIX) ? 1 : 0); x[j] = (word)(temp - MP_RADIX); } }/************************************************** Two Operand Linear Multiply **************************************************/void bigint_linmul2(word* const x, u32bit x_size, word y) { word carry = 0; for(u32bit j = 0; j != x_size; j++) { dword product = (dword)x[j] * y + carry; x[j] = MP_LOW_WORD(product); carry = MP_HIGH_WORD(product); } x[x_size] = carry; }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?