📄 intstub.cpp
字号:
// intstub.cc// purpose is to generate intstub.asm// copyright SafeTP Development Group, Inc., 2000 Terms of use are as specified in license.txt// integer.cpp - written and placed in the public domain by Wei Dai//#include "pch.h"#include "integer.h"#include "modarith.h"#include "nbtheory.h"#include "asn.h"#include "words.h"#ifdef SAFETP# include "iostream.h"# include <string.h> // strlen#else# include "iostream" USING_NAMESPACE(std)#endif // !SAFETP#include "algebra.cc"#include "eprecomp.cc"#define MAKE_DWORD(lowWord, highWord) ((dword(highWord)<<WORD_BITS) | (lowWord))#if defined(_MSC_VER) && defined(_M_IX86) && (_M_IX86<=500)// Add() and Subtract() are coded in Pentium assembly for a speed increase// of about 10-20 percent for a RSA signaturestatic /*__declspec(naked)*/ word __fastcall Add(word *C, const word *A, const word *B, unsigned int N){ __asm { push ebp push ebx push esi push edi mov esi, [esp+24] mov ebx, [esp+20] sub ecx, edx xor eax, eax sub eax, esi lea ebx, [ebx+4*esi] sar eax, 1 // clears the carry flag jz loopend} loopstart: __asm { mov esi,[edx] mov ebp,[edx+4] mov edi,[ebx+8*eax] lea edx,[edx+8] adc esi,edi mov edi,[ebx+8*eax+4] adc ebp,edi inc eax mov [edx+ecx-8],esi mov [edx+ecx-4],ebp jnz loopstart} loopend: __asm { adc eax, 0 pop edi pop esi pop ebx pop ebp ret 8 }}static /*__declspec(naked)*/ word __fastcall Subtract(word *C, const word *A, const word *B, unsigned int N){ __asm { push ebp push ebx push esi push edi mov esi, [esp+24] mov ebx, [esp+20] sub ecx, edx xor eax, eax sub eax, esi lea ebx, [ebx+4*esi] sar eax, 1 // clears the carry flag jz loopend} loopstart: __asm { mov esi,[edx] mov ebp,[edx+4] mov edi,[ebx+8*eax] lea edx,[edx+8] sbb esi,edi mov edi,[ebx+8*eax+4] sbb ebp,edi inc eax mov [edx+ecx-8],esi mov [edx+ecx-4],ebp jnz loopstart} loopend: __asm { adc eax, 0 pop edi pop esi pop ebx pop ebp ret 8 }}#elif defined(__BORLANDC__)word foo(word const*);word foo2(unsigned int N);// will use separately linked moduleextern "C" {word __fastcall Add(word *C, const word *A, const word *B, unsigned int N);word __fastcall Subtract(word *C, const word *A, const word *B, unsigned int N);};word __fastcall Add(word *C, const word *A, const word *B, unsigned int N){ foo(C); foo(A); foo(B); return foo2(N);}word __fastcall Subtract(word *C, const word *A, const word *B, unsigned int N){ foo(C); foo(A); foo(B); return foo2(N);}#else // defined(_MSC_VER) && defined(_M_IX86) && (_M_IX86<=500)static word Add(word *C, const word *A, const word *B, unsigned int N){ assert (N%2 == 0); word carry=0; for (unsigned i = 0; i < N; i+=2) { dword u = (dword) carry + A[i] + B[i]; C[i] = LOW_WORD(u); u = (dword) HIGH_WORD(u) + A[i+1] + B[i+1]; C[i+1] = LOW_WORD(u); carry = HIGH_WORD(u); } return carry;}static word Subtract(word *C, const word *A, const word *B, unsigned int N){ assert (N%2 == 0); word borrow=0; for (unsigned i = 0; i < N; i+=2) { dword u = (dword) A[i] - B[i] - borrow; C[i] = LOW_WORD(u); u = (dword) A[i+1] - B[i+1] - (word)(0-HIGH_WORD(u)); C[i+1] = LOW_WORD(u); borrow = 0-HIGH_WORD(u); } return borrow;}#endif // defined(_MSC_VER) && defined(_M_IX86) && (_M_IX86<=500)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -