📄 mp_core2.cpp
字号:
/************************************************** 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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -