JP4293665B2 - Remainder multiplier - Google Patents

Remainder multiplier Download PDF

Info

Publication number
JP4293665B2
JP4293665B2 JP05480399A JP5480399A JP4293665B2 JP 4293665 B2 JP4293665 B2 JP 4293665B2 JP 05480399 A JP05480399 A JP 05480399A JP 5480399 A JP5480399 A JP 5480399A JP 4293665 B2 JP4293665 B2 JP 4293665B2
Authority
JP
Japan
Prior art keywords
value
bits
partial
remainder
intermediate number
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Expired - Fee Related
Application number
JP05480399A
Other languages
Japanese (ja)
Other versions
JPH11316544A (en
Inventor
貴敏 小野
なつめ 松崎
浩 柏
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Panasonic Corp
Panasonic Holdings Corp
Original Assignee
Panasonic Corp
Matsushita Electric Industrial Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Panasonic Corp, Matsushita Electric Industrial Co Ltd filed Critical Panasonic Corp
Priority to JP05480399A priority Critical patent/JP4293665B2/en
Publication of JPH11316544A publication Critical patent/JPH11316544A/en
Application granted granted Critical
Publication of JP4293665B2 publication Critical patent/JP4293665B2/en
Anticipated expiration legal-status Critical
Expired - Fee Related legal-status Critical Current

Links

Images

Description

【0001】
【発明の属する技術分野】
本発明は、高速かつ小回路規模の構成により剰余乗算を行う剰余乗算装置に関する。
【0002】
【従来の技術】
近年、通信分野における暗号化技術の発達に伴って、暗号化の際に利用される各種演算装置の需要が高まっている。
例えば、楕円暗号方式においては剰余乗算を行うための剰余乗算装置が利用される。ここで剰余乗算とは、3つの整数a、b及びpにおいて(a*b)modpの演算を施すことである。ここにおいてaは被乗数、bは乗数、pは法という。
【0003】
図17は、従来の剰余乗算装置の構成を示す。
なお、同図の剰余乗算装置1においてa、b、pは、説明を簡単にするため4ビットで表わされるような小さい値を用いるものとする。
剰余乗算装置1は、積算出部2、剰余算出部3、制御部4から構成される。
積算出部2は、被乗数レジスタ5(4ビット)、加算器6(4ビット)、積レジスタ7(9ビット)から構成され、制御部4の制御によって被乗数aと乗数bとの積a*bを算出する。
【0004】
積算出部2に対する制御部4の処理手順を以下に示す。
ステップ1:初期設定として、被乗数レジスタ5に被乗数aを保持させ、積レジスタ7(8ビット)の下位4ビットに乗数bを保持させ、積レジスタ7の上位5ビットに0を保持させる。
ステップ2:積レジスタ7の最下位ビットが0であるか1であるかを判定し、1と判定した場合には、加算器6において積レジスタ7の上位5ビットのうち最上位ビットを除く4ビットに保持される値と被乗数レジスタ7に保持される被乗数aとを加算させ、加算値を積レジスタ7の上位4ビットに保持させる。
【0005】
ステップ3:積レジスタ7を右1ビットシフトさせる。
ステップ4:ステップ2〜3の処理を4回繰り返す。
以上のようにしてステップ2〜3のループ処理を4回繰り返すと積レジスタ7には積a*bが保持されることになる。
剰余算出部3は、法レジスタ8(4ビット)、加算器9(5ビット)、剰余レジスタ10(13ビット)から構成され、制御部4の制御によって手書きの筆算と同等な要領により積a*bの法pによる剰余(a*b)modpの算出を行う。なお、剰余算出部3により算出される剰余は符号付きの5ビット値である。
【0006】
剰余算出部3に対する制御部4の処理手順を以下に示す。
ステップ5:初期設定として法レジスタ8に法pを保持させ、剰余レジスタ10の下位8ビットに積レジスタ7に保持される積a*bを保持させ、上位5ビットに0を保持させる。
ステップ6:剰余レジスタ10に左1ビットシフトさせる。
【0007】
ステップ7:加算器9において剰余レジスタ10の上位5ビットに保持される値から法レジスタ8に保持される法pを減算させ、剰余レジスタ10の上位5ビットに保持させる。
ステップ8:剰余レジスタ10の上位5ビットの正負を最上位ビットの値から判定し、負(最上位ビットが1)と判定した場合は、加算器9において剰余レジスタ10の上位5ビットと法レジスタ8の法pとを加算させることによって剰余レジスタ10の値を元に戻す(つまり、ステップ7において減算される前の値に戻す)。
【0008】
ステップ9:ステップ6〜8の処理を8回繰り返す。
以上のようにしてステップ6〜8のループ処理を8回繰り返すと、剰余レジスタ10の上位5ビットに剰余(a*b)modpが保持されることになる。
このように剰余乗算装置1は、積算出部2においては、被乗数aと乗数bの各ビットとの部分積を、bの下位側から被乗数aに対応させて算出し、算出される部分積を順次に累算することによって積a*bを算出する。そして剰余算出部3においては、積算出部2において算出された積a*bをシフトさせて法pの桁を積a*bの上位桁から下位桁へと桁を合わせつつa*bから法pを減算することにより剰余(a*b)modpを算出する。
【0009】
【発明が解決しようとする課題】
上記従来技術における剰余乗算装置1においては、a、b、pが4ビットという小さな値であるので、加算器6及び加算器9は4ビットの加算が行えればよく、またループ処理の回数も積算出部2においては4回、剰余算出部3においては8回と少ない。それに対して実際の楕円暗号に用いられるa、b、pは例えば160ビットとかなり大きな値である。よって従来の剰余乗算装置1を160ビットのa、b、pを用いた演算に対応させた場合、加算器6及び加算器9は160ビットの加算を行う必要があり、回路規模が大きくなるという問題があった。またループ処理の回数は、積算出部2においては160回、剰余算出部3においては320回繰り返されることとなり、演算時間がかかるという問題があった。
【0010】
このようにして従来技術の剰余乗算装置1をあらゆる値を用いた演算に対応させるとすると、値のビット数が大きくなればなるほど、加算器で行われる加算のビット数が大きくなるので加算器の回路規模が大きくなり、ループ処理の回数が増えるので演算時間が長くなるという問題があった。
上記剰余乗算装置1の演算時間の問題を解消する他の従来技術として「United States Patent 5,144,574 Modular multiplication method and the system for processing data」に記載の剰余乗算方法がある。
【0011】
この剰余乗算方法は、乗数bの上位側から2ビットずつ順次に被乗数aに対応させて、被乗数aと乗数bの2ビットずつとの部分積を算出し、算出される度にその部分積から法pの整数倍を減算することによって部分積の法pによる部分剰余を算出し、その部分剰余を累算することによって(a*b)modpを算出する方法である。
【0012】
このような剰余乗算方法を用いた装置においては、剰余乗算装置1が乗数bの1ビットずつを被乗数aに対応させて部分積を算出していたのに対して、被乗数aと乗数bの2ビットずつとの部分積を算出するので、部分積の算出にかかるループ処理の回数が少なくなり演算時間が短縮される。
このように剰余乗算方法は、主に、被乗数aと乗数bの2ビットずつとを対応させた部分積の算出によって演算時間を短縮しようとするものである。ただしこの剰余乗算方法においては、部分積を算出する際に被乗数aに対応させる乗数bのビット数はたかだか2ビットと少なく、a、b、pが大きな値である場合には、さほど演算時間の短縮の効果は得られない。
【0013】
上記問題に鑑みて本発明は、回路規模を抑えながら高速に演算を行う剰余乗算装置を提供することを目的とする。
【0014】
【課題を解決するための手段】
上記問題を解決するため本発明の剰余乗算装置は、被乗数aと乗数b(bはkbビットのデータ)との積に対して、法p(pはkビットデータ)による剰余と合同な値を次式の累算値として算出する剰余乗算装置であって、
累算値 = Σ C(i)*b[s*i+s-1:s*i]
(ここでΣはi=0〜[[kb/s]]までの累算を示す。 [[kb/s]]は商kb/sの整数部分であり、iは0から[[k/s]]までの整数であり、C(i)は漸化式で表わされi=0のときC(i)=a、i>=1のときC(i)≡(C(i-1)*2s) mod pであり(≡は両辺の値が法pにおいて合同であることを示す))
b[s*i+s-1:s*i]は、kビットの乗数bのうち2s*i+s-1の位から2s*iの位までのsビットの部分乗数であり、前記剰余乗算装置は、m(mはs以上の整数)ビットにより表現される各値について、その値の2k倍に対する法pによる剰余を予め記憶するテーブル手段と、初回(i=0)では被乗数aを中間数C(0)として出力し、
2回目以降(i>0)では、前回出力された中間数C(i-1)をsビット桁上げし、桁上げ後の中間数の下位kビットを除く上位のmビットについての前記剰余をテーブル手段から読み出し、読み出した剰余と下位kビットとを加算することにより新たな中間数(i)を算出する中間数算出手段とを備え、算出された各中間数C(i)と、それに対応する部分乗数b[s*i+s-1:s*i]との部分積C(i)*b[s*i+s-1:s*i]を順次累算することによって前記累算値を算出するよう構成される。
【0015】
また前記中間数算出手段は、中間数を保持する第1保持手段と、部分乗数b[s*i+s-1:s*i]に対応して、第1保持手段に保持された中間数をsビット桁上げする桁上げ手段と、桁上げ後の中間数を、桁上げ後の中間数における下位kビットよりも上位のmビットの部分である上位データと下位kビットの部分である下位データとに分割する分割手段と、分割手段による上位データに対する法pによる剰余を前テーブル手段から読み出す読み出し手段と、テーブル手段から読み出された剰余と、分割手段による下位データとを加算することにより新たな中間数を得る加算手段とを備え、前記第1保持手段は、加算手段において新たな中間数が得られる度にその保持内容を新たな中間数に更新し、前記初回では被乗数を中間数として出力し、前記2回目以降では更新後の新たな中間数を出力するよう構成される。
【0016】
また前記剰余乗算装置は、さらに、前記分割手段、読み出し手段、加算手段を利用することにより、前記累算値の法pによる剰余を求める後処理手段を備える。
また、前記テーブル手段は、mビットにより表現される各値に対応するアドレスが入力され、そのアドレスが指す記憶領域に当該アドレスに対応するmビットの値の2k倍に対する法pによる剰余を予め記憶するメモリ素子を有する。
【0017】
また前記mビットは下位m1ビットと上位m2ビット(m=m1+m2)とに分割され、前記mビットにより表現される各値は、m1ビットにより表現される値とm2ビットにより表現される値との組み合わせに対応し、前記テーブル手段は、m1ビットにより表現される各値について、その値の2k倍に対する法pによる剰余を予め記憶する第1部分テーブル手段と、m2ビットにより表現される各値について、その値の2k+m1倍に対する法pによる剰余を予め記憶する第2部分テーブル手段とを備え、前記加算手段は、第1、第2部分テーブルからの読み出されたそれぞれの剰余と、前記下位データとを加算することにより新たなっ中間数を得るよう構成される。
また前記mビットは下位側からt(3≦t≦m)個の部分ビットm1、…、mtに分割され、前記mビットにより表現される各値は、各mi(iは1からtまで整数)ビットにより表現される値(t個)を組み合わせたものに対応し、前記テーブル手段は、部分ビットmiビットにより表現される各値について、その値の2k+x倍(ここでx=m1+…+m(i-1)である)に対する法pによる剰余を予め記憶するt個の部分テーブル手段Tiを備え、前記加算手段は、t個の部分テーブル手段Tiからの読み出されたt個の剰余と、前記下位データとを加算することにより新たな中間数を得るよう構成される。
【0018】
また前記剰余乗算装置は、さらに累算手段と補正手段とを備え、前記累算手段は、初期値として0を保持する第3レジスタと、部分積C(i)*b[s*i+s-1:s*i]と第3レジスタに保持された累算値とを加算し、加算結果を新たな累算値として第3レジスタに出力して保持させる加算器とを備え、前記補正手段は、pの整数倍の値をもつ補正値を保持する補正値保持手段と、前記第3レジスタに保持された累算値が所定の値以上であれば、補正値保持手段に保持された補正値を、前記加算器に減算させる補正制御手段とを備える。
【0019】
また前記第3レジスタは符号ビットを有し、前記補正制御手段は、第3レジスタの累算値が正であれば、前記加算器に対して累算値と部分積との加算と同時に前記補正値を減算させ、前記補正値は、pの整数倍であってその絶対値が前記部分積の最大値(t+1)(2 s -1)p以下の値であることを特徴とする。
また前記法pはp=2k−αの関係を満たし、各部分テーブル手段Tiは、前記剰余をk3ビットのデータとして記憶する、ここで、k3はt*2m*αのビット数であり、前記αは、k3がkより小さくなるように定められた定数であることを特徴とする。
【0020】
また各部分テーブル手段Tiは、miビットにより表現される0から(2mi-1)までの値に対応する2mi個のエントリを有し、j(jは0から2miまで)番目のエントリは、j*2m1++m(i-1) *αを格納していることを特徴とする。
本発明の剰余乗算装置は、被乗数と乗数との積に対する法p(pはkビットデータ)による剰余と合同な数を算出する剰余乗算装置であって、乗数をs(sは2以上の整数)ビットずつに分けて得られるsビットの部分乗数を下位側から順に出力する出力手段と、各部分乗数の位に応じて、被乗数を桁上げし、桁上げ後の被乗数に対して、法pによる剰余と合同な数(以下中間数と呼ぶ)を算出する第1算出手段と、出力手段により出力された部分乗数と、当該部分乗数に対応して第1算出手段により算出された前記中間数との積を部分積として算出する第2算出手段と、第2算出手段に算出された部分積を累算する累算手段と、累算手段に累算された累算値にpの整数倍の値を加減算することにより、累算値を所定のビット数を越えないように補正する補正手段と、出力手段により全ての部分乗数が出力されるまで、第1算出手段による中間数の算出と、第2算出手段による部分積の算出と、累算手段による累算と、補正手段による補正とを繰り返し行わせる制御手段とを備え、前記第1算出手段は、m(mはs以上の整数)ビットにより表現される各値について、その値の2k倍に対する法pによる剰余を予め記憶し、制御手段による繰り返しのうち初回では被乗数を中間数として出力し、2回目以降では、前回出力された中間数をsビット桁上げし、桁上げ後の中間数の下位kビットより上位のmビットについてテーブル手段を読み出し、読み出した数と下位kビットとを加算することにより新たな中間数を算出するよう構成される。
【0021】
また前記制御手段は、第1〜第3ステージを含むパイプライン処理を制御する、第1ステージでは出力手段に部分乗数を出力させるとともに第1算出手段に中間数を出力させ、第2ステージでは第2算出手段に部分積を算出させ、第3ステージでは累算手段に累算させるともに補正手段に補正させるよう構成される。
また前記出力手段は、最初に乗数を保持し、保持している値の下位sビットを部分乗数として出力する乗数保持手段と、乗数保持手段に保持されている値をsビット下位側にシフトさせ、シフト後の値を乗数保持手段に出力して保持させるシフト手段とを備える。
【0022】
また前記第2生成手段は、第i(iは1から(s−1)の整数)のシフト手段は、第1算出手段により算出された前記中間数をiビット左シフトにより桁上げする第1から第(s−1)のシフト手段を備え、前記第1生成手段は、第1算出手段により算出された前記中間数をsビット左シフトにより桁上げする第sのシフト手段と、前記中間数の1の補数を生成する補数生成手段と、定数1を出力する定数出力手段とを備え、前記第2加算手段は、全ビットが1であると判定された場合に、第sのシフト手段の出力と、補数生成手段に生成された1の補数と、定数1を選択し、全ビットが1であると判定されなかった場合に、部分乗数の20の位が”1”であれば前記中間数を選択し、部分乗数の2iの位が”1”であれば、第iのシフト手段の桁上げ結果を選択する選択手段と、選択手段の選択結果を加算することにより前記部分積を算出する加算器とを備える。
【0023】
【発明の実施の形態】
<第1実施形態>
以下に本実施形態における剰余乗算装置ついて図面を用いて説明する。
本実施形態における剰余乗算装置は、楕円曲線暗号の演算等に用いられる装置で、被乗数A(160ビット)と乗数B(160ビット)とが入力されると、(式1)に示す積A*Bの法P(160ビットの素数)による剰余R(=A*BmodP)又は剰余Rと剰余体上において同値の値を算出する。ここにおいて法Pは、αを54ビット以下の値とするときP=2160−αを満たす値である。
【0024】
本剰余乗算装置は、(式1)を変形させた(式2)に基づいて構成されている。なお、念のため(式1)から(式2)への変形過程の詳細を発明の実施の形態の末尾に示す。
【0025】
【数3】

Figure 0004293665
【0026】
【数4】
Figure 0004293665
【0027】
<演算式の説明>
(式2)においてR1は、Rと法Pの剰余体において同値の値である。ここでRとR1とが法Pの剰余体において同値であるとは、R1とRとの差がPの整数倍であるということを示す。
R1は、i=1からk/sまでの間、C(i)*b(i)を累算することによって算出される。ここでkは乗数Bのビット数である。sは、乗数Bを数ビットずつの部分乗数に分割したときの各部分乗数のビット数である。つまりk/sは、部分乗数の個数と同じ値である。ここにおいてkとsとは、kがsで割り切れる関係になるように定められる。
【0028】
b(i)=b[s*i−1:s*i−s)]は、乗数Bを下位からsビットずつに分割した部分乗数を示す。i=1のときb(1)=b[s−1:0]、i=2のときb(2)=b[2s−1:s]、i=3のときb(3)=[3s−1:2s]、...となる。ここでkビットの乗数Bを2進数表記した場合、bk−1bk−2...b2b1b0と表わすものとする。またb[x:y]は、乗数Bの下位からx+1ビット目からy+1ビット目(ただしx>y)までのビット列を指すものとする。よって例えばb[15:8]は、乗数Bの下位16ビット目から9ビット目までの部分乗数を指し、2進数表記によりb15b14b13b12b11b10b9b8と表わされる。
【0029】
C(i)は、i=1のときC(1)=A(Aは被乗数)、2<=i<=k/sのときC(i)≡C(i−1)*2smodPという漸化式で表わされる。つまりC(i)は、C(1)=A(被乗数)、C(2)≡A*2smodP、C(3)≡(A*2smodP)*2smodP、...というように漸化的に変化する。この漸化式において2sは、sビットの部分乗数b(i)の桁上げに相当する。C(i)は、1つ前の値であるC(i−1)をsビット桁上げした値の法Pによる剰余である。以下、C(i)を以後中間数と呼ぶこととする。
【0030】
このように(式2)においてR1は、i=1〜k/sの間、被乗数Aについて、sビット桁上げした値の法Pによる剰余を中間数C(i)として漸化的に算出し、また乗数Bを下位からsビットずつの部分乗数b(i)に分割し、それらの部分積C(i)*b(i)を求めて累算することを繰り返しk/s回行うことによって求められる。以下、R1を算出するために演算をk/s回繰り返すことを繰り返し処理と呼ぶ。
<剰余乗算装置の構成>
図1は、本実施形態における剰余乗算装置100の概略構成を示すブロック図である。
【0031】
同図において剰余乗算装置100は、乗数分割部11、剰余算出部12、部分積算出部13、累算部14、補正部15、制御部16から構成される。この剰余乗算装置100は、k=160、s=8としたときの(式2)に基づいて構成されている。
乗数分割部11は、8ビットずつの部分乗数b(i)=b[8i−1:8i−8](i=1,...,19,20)を乗数Bの下位側から順次出力する。
【0032】
剰余算出部12は、中間数C(i)(i=1,...19,20)を漸化的に算出する。つまり剰余算出部12は、初回(i=1)は被乗数Aを中間数C(1)として出力する。2回目以降(i=2,3,...,20)は前回の中間数C(i−1)を8ビット桁上げして、その桁上げ値C(i−1)*28の法Pによる剰余を中間数C(i)(i=2,3,...,20)として算出する。より具体的には、剰余算出部12は、初回はA、2回目はA*28modP、3回目は(A*28modP)*28modP、4回目は((A*28modP)*28modP)*28modP、...を中間数C(i)として算出する。ここで剰余算出部12が算出するC(i)は、桁上げ値C(i−1)*28と合同な値であって、Pよりも大きい値である場合もある。
【0033】
剰余の算出が高速に行われるようにするため剰余算出部12は、ROMテーブル308、ROMテーブル309を有する。これらのROMは、後に詳しく説明するが、桁上げ値C(i−1)*28から下位160ビットを除いた部分、つまり桁上げによって160ビットを越えた部分に対応する法Pによる剰余を予め記憶する。剰余算出部12は、桁上げ値C(i−1)*28の160ビットを越える部分について、これらのROMを参照し、ROMより得られる160ビットを越える部分に対応する剰余と、桁上げ値C(i−1)*28の下位160ビットの部分とを加算することにより中間数C(i)を算出する。
【0034】
部分積算出部13は、剰余算出部12より出力される中間数C(i)と乗数分割部11より出力される部分乗数b(i)との部分積C(i)*b(i)を出力する。
累算部14は、部分積算出部13より出力される部分積C(i)*b(i)を累算する。
【0035】
補正部15は、累算部14による累算結果に応じて累算値にPの整数倍の値を加減算することによって累算値を補正し、それによって累算部14における累算値の桁あふれを防ぐ。
制御部16は、剰余算出部12、部分積算出部13、累算部14、補正部15においてi=1〜20の20回行われる演算の繰り返し処理を制御する。また制御部16は、剰余算出部12による中間数の算出と乗数分割部11による部分乗数の算出とを第1段階、部分積算出部13による部分積の算出を第2段階、累算部14による累算値の算出と補正部15による累算値の補正とを第3段階としてパイプライン制御を行う。さらに制御部16は、20回繰り返し動作させた後、累算部14における最終的な累算値がPより大きい場合には、その累算値を剰余算出部12に入力して累算値のPによる剰余を算出させる。
【0036】
図2は、剰余算出部12のより詳細な構成図を示す。
同図において剰余算出部12は、セレクタ301、レジスタA302、シフタ303、セレクタ304、剰余演算部311から構成される。
セレクタ301は、制御部16の制御により、まず初期設定(i=1)として外部より入力される被乗数AをレジスタA302に出力し、初期設定後(2<=i<=20)は剰余演算部311より入力される中間数C(i)をレジスタA302に出力するセレクタである。
【0037】
レジスタA302は、161ビットのレジスタであり、初期設定(i=1)として外部よりセレクタ301を介して入力される被乗数A(=C(1))を保持し、初期設定後(2<=i<=20)は加算器310からセレクタ301を介して入力される中間数C(i)を保持する。レジスタA302は、出力側が部分積算出部13とシフタ303とに接続されており、制御部16の指示に応じて保持している中間数を新たに入力される中間数に更新し、部分積算出部13とシフタ303とに出力する。
【0038】
シフタ303は、入力を8ビット左シフトする169ビット幅のシフタであり、レジスタA302より入力される161ビットの中間数C(i−1)を8ビット左シフトして169ビットの桁上げ値C(i−1)*28を出力する。このようにシフタ303は、8ビットの左シフトを行うことによって中間数C(i−1)に対して8ビットの桁上げを行う。
【0039】
セレクタ304は、繰り返し処理の間、シフタ303より入力される桁上げ値C(i−1)*28を剰余演算部311に出力し、繰り返し処理の後、累算部14より入力される累算値を剰余演算部311に出力する。
剰余演算部311は、ROMテーブル308、ROMテーブル309、加算器310から構成され、シフタ303よりセレクタ304を介して入力される桁上げ値C(i−1)*28又は累算部14より入力される累算値の法Pによる剰余又は合同な値を出力する。この剰余または合同な値は161ビットである。
【0040】
また剰余演算部311は、セレクタ304から入力される169ビットの値の下位160ビットを加算器310に入力するバス305と、161〜165ビット目をROMテーブル308に入力するバス306と、166〜169ビット目をROMテーブル309に入力するバス307とを備える。これらのバスは、桁上げ値C(i−1)*28または累算値を下位側から160ビットの部分(以下下位部分と呼ぶ)と5ビットの部分(以下5ビット部分と呼ぶ)と4ビットの部分(以下4ビット部分と呼ぶ)とに分割してそれぞれ加算器310とROMテーブル308とROMテーブル309とに入力する。
【0041】
図3(a)(b)は、ROMテーブル309及びROMテーブル308の記憶内容を示す。
同図(b)は、ROMテーブル308の記憶内容を示す。ROMテーブル308は、5ビットで表現される値(00000)2〜(11111)2を入力値とし、それら各値を2160倍した値に対する法Pによる剰余を出力値として対応付けて記憶する。同図(b)においてαは、P=2160−αの関係を満たすことからα=2160modPである。よって同図(b)の出力値0、1*α、2*α、...31*αは、入力値(5ビット部分)を2160倍した値の法Pによる剰余である。ここでαは54ビット以下の値で入力値は5ビットであるのでROMテーブル308の出力は最大でも59ビットである。ROMテーブル308は、制御部16よりread信号が入力されたときバス306より入力される5ビット部分に対応する剰余を読み出して出力する。
【0042】
同図(a)は、ROMテーブル309の記憶内容を示す。ROMテーブル309は、4ビットで表現される値(0000)2〜(1111)2を入力値とし、それら各値を2165倍した値に対する法Pによる剰余を出力値として対応付けて記憶する。ここでα=2160modPであるので、どう図(a)の出力値0、▲1▼*32*α、2*32*α、...15*32*αは入力値(4ビット)を2165倍した値の法Pによる剰余である。αは54ビット以下の値で、入力値は4ビット、32は5ビットであるのでROMテーブル309の出力は最大でも63ビットである。ROMテーブル309は、制御部16よりread信号が入力されたときバス307より入力される4ビット部分に対応する剰余を読み出して出力する。
【0043】
このように剰余演算部311においては桁上げによって160ビットを越えた部分についてROMテーブル308、ROMテーブル309を用いて剰余を求めるので、従来のように減算によって剰余を求める構成よりも高速になる。また、ROMテーブル308、ROMテーブル309の2つのROMに分けたことにより入力値の個数がROMテーブル308は25個、ROMテーブル309は24個と少なくなる。これによりROMテーブル308、ROMテーブル309は、5ビット部分、4ビット部分それぞれに対応する入力値の検索がより速くなり、剰余の算出を高速にしている。
【0044】
加算器310は、160ビットの下位部分とROMテーブル308より出力される5ビット部分の剰余(59ビット)とROMテーブル309より出力される4ビット部分の剰余(63ビット)とを加えることによってC(i−1)*28modP又は合同な値を出力する。
と法Pの剰余体上同値の値を出力する。加算器310が出力する値は、161ビットである。
【0045】
図4は、乗数分割部11のより詳細な構成を示す。
同図において乗数分割部11は、シフタ503、セレクタ501、レジスタB502から構成される。
セレクタ501は、制御部16の制御により、初期設定(i=1)として、外部より入力される乗数BをレジスタB502へ出力し、初期設定後(2<=i)は、シフタ503より入力される値をレジスタB502へ出力する。
【0046】
レジスタB502は、160ビットのレジスタであり、初期設定として外部よりセレクタ501を介して入力される乗数Bを保持し、初期設定後は、シフタ503よりセレクタ501を介して入力される値を保持する。レジスタB502は、出力側がシフタ503に接続されており、また下位8ビットの部分が部分積算出部13に接続されている。乗数分割部11は、制御部16の制御により保持している値を、シフタ503よりセレクタ501を介して新たに入力される値に更新する。レジスタB502に保持されている値は、シフタ503に出力されるとともに下位8ビットが部分積算出部13へ出力される。
【0047】
シフタ503は、レジスタB502より入力される値を8ビット右シフトして出力する160ビットのシフタである。
このような構成によって乗数分割部11は、乗数Bの下位から8ビットずつの部分乗数b(i)=b[8i−1:8i−8](i=1,...19,20)を順次に部分積算出部13に出力する。
【0048】
図5は、部分積算出部13のより詳細な構成を示す。
同図において部分積算出部13は、シフタ部512、セレクタ部513、加算器522、加算器523、レジスタCa524、レジスタCb525から構成される。
部分積算出部13における演算を式によって表わすと(式3)のようになる。
【0049】
【数5】
Figure 0004293665
【0050】
なお同式においては便宜上、乗数分割部11より入力される部分乗数b(i)の2進表記をbi7bi6bi5bi4bi3bi2bi1bi0としている。
同式に示すように、部分積算出部13は、まず剰余算出部12より入力される中間数C(i)に対して部分乗数b(i)の各ビットに応じた0〜7ビットの桁上げを行い(同式▲1▼)、次に桁上げされた各値に部分乗数b(i)の各ビットを乗じ(同式▲2▼)、最後にそれらを加算する(同式▲3▼、▲4▼)
シフタ部512は、バス504と、入力される値に対してそれぞれ1〜7ビット左シフトを行うシフタ505〜511とを備え、同式▲1▼に相当する演算を行う。
【0051】
すなわちシフタ部512は、剰余算出部12より入力される中間数C(i)を部分乗数b(i)の各ビットの重みに応じた桁上げを行ってセレクタ部513に出力する。シフタ505〜511は、入力されるC(i)に対してそれぞれ1〜7ビットの左シフトを行うシフタである。つまりシフタ505〜511は、入力されるC(i)に対して、それぞれC(i)*21〜C(i)*27を出力する。バス504は、中間数C(i)をそのままセレクタ部513に出力する。
【0052】
セレクタ部513は、セレクタ514〜521を備え、同式▲2▼に相当する演算を行う。セレクタ514〜521は、それぞれシフタ部512よりC(i)*20〜C(i)*27が入力され、乗数分割部11よりb(i)の各ビットbi0〜bi7が入力される。セレクタ514〜521は、それぞれに入力される部分乗数b(i)の各ビットbi0〜bi7の値に応じて、それぞれに入力されるC(i)*20〜C(i)*27か0かのどちらかを選択して出力する。すなわちセレクタ514〜521は、入力されるbin(n=0,1,...,7)の値が1の場合はC(i)*2n(n=0,1,...,7)を出力し、binの値が0の場合は0を出力する。
【0053】
加算器522は、▲3▼に相当する演算を行う加算器であり、セレクタ514〜517より入力される4つの値を加算した値(以下部分積aという)をレジスタCa524へ出力する。
加算器523は、▲4▼に相当する演算を行う加算器であり、セレクタ518〜521より入力される4つの値を加算した値(以下部分積bという)をレジスタCb525へ出力する。
【0054】
レジスタCa524、レジスタCb525は、それぞれ部分積a、部分積bを保持し、制御部16の制御により保持している部分積a、部分積bを新しく入力された値に更新する。レジスタCa524及びレジスタCb525の出力側は、累算部14に接続されており、レジスタCa524及びレジスタCb525は、保持している部分積a、bを累算部14に出力する。
【0055】
この部分積aと部分積bとを加え合わせた値が部分積C(i)*b(i)に相当する。
図6は、累算部14及び補正部15の詳細な構成を示す。
累算部14は、加算器601及びレジスタS602から構成される。
レジスタS602は、累算値を保持する170ビットのレジスタであり、制御部16の制御により、保持している累算値を、加算器601から入力される新しい累算値に更新する。ここでレジスタS602の最上位ビットは、累算値の正負を表わす符合ビットとなる。
【0056】
加算器601は、レジスタS602に保持される累算値とレジスタCa524及びレジスタCb525に保持される部分積aと部分積bと補正部15より入力される補正値とを加算してレジスタS602に出力する。
補正部15は、レジスタE603、インバータ606、セレクタ604、セレクタ605から構成される。
【0057】
レジスタE603は、部分積a及び部分積bを合わせた値の最大値となり得る値より大きく、かつ最も近い値を保持する。
インバータ606は、レジスタE603に保持される510*Pの反転値(以下、¬510*Pと表記する)を出力する。
セレクタ604は、制御部16の制御に従って、0と510*Pと¬510*Pのうちからいずれかを補正値として選択して加算器601に供給する。
【0058】
セレクタ605は、制御部16の制御に従って、0または1を加算器601に供給する。
ここで制御部16は、レジスタS602に保持される累算値の正負に応じてセレクタ604に補正値を選択させ、またセレクタ605に0または1を選択させて加算器601に供給させる。
【0059】
詳しくは制御部16は、レジスタS602の最上位ビットが0であれば、セレクタ604に¬510*Pを選択させ、セレクタ605に1を選択させる。これによってレジスタS602に保持される累算値が正(最上位ビットが0)である場合には、レジスタE603からインバータ606、セレクタ604を介して¬510*Pが、またセレクタ605を介して1が加算器601に供給される。これのおかげで加算器601の次の加算においては510*Pが減算されることになり、加算器601及びレジスタS602における桁あふれが予防される。
【0060】
制御部16は、レジスタS602に保持される累算値が負(最上位ビットが1)である場合には、セレクタ604に0を選択させ、またセレクタ605に0を選択させる。
また制御部16は、i=1〜20の繰り返し処理が終わり、レジスタS602の保持する値が最終的な累算値に更新された場合、その累算値の最上位ビットが1か0かを判定し、1(負を示す)である場合には、セレクタ604に510*Pを、セレクタ605に0を選択させ、加算器601においてレジスタS602に保持される累算値に510*Pを加える補正を行わせる。これによって制御部16は、最終的な累算値が正になるよう補正させる。また制御部16は、最終的な累算値の最上位ビットが0(正を示す)場合には、セレクタ604に0を、セレクタ605に0を選択させ、累算値の補正が行われないようにする。
<第2実施形態>
以下に第2実施形態における剰余乗算装置について以下に図面を用いて説明する。
【0061】
本実施形態における剰余乗算装置は、被乗数A(160ビット)と乗数B(161ビット)とが入力されると、積A*Bの法P(160ビット)による剰余R(=A*BmodP)又は剰余Rと剰余体上において同値の値を算出する。ここにおいて法Pは、αを54ビット以下の値とするときP=2160−αを満たす値である。
【0062】
本実施形態の剰余乗算装置も、第1実施形態と同様(式2)に基づいて構成されている。ただし第1実施形態においてはs=8であったのに対して第2実施形態においてはs=9とする。またk/sの部分は、実際に計算するとk/s=161/9と割り切れないので、本実施形態においてはk/sの部分は18と置き換えるものとする。
【0063】
図7は、第2実施形態における剰余乗算装置200の概略構成を示すブロック図である。
同図において剰余乗算装置200は、乗数分割部81、剰余算出部82、部分積算出部83、累算部84、補正部85、制御部86から構成される。
同図の剰余乗算装置200において剰余算出部82は、1つしかROMテーブルを有していない点が剰余算出部12と異なる。また図11において詳細に説明するが、部分積算出部83は部分積算出部13に対して、その内部の加算器に入力される入力数を減らして加算器の回路規模がより小さくなるように構成されている。さらに剰余乗算装置100において桁挙げ値C(i−1)*28の算出は剰余算出部12が行っていたが、剰余乗算装置200において桁上げ値C(i−1)*29の算出は、剰余算出部82ではなく部分積算出部83が行う。
【0064】
その他、乗数分割部81、累算部84、補正部85、制御部86は、乗数Bが161ビット、sが9ビットと第1実施形態とビット数が異なっている点から各構成要素における入出力のビット数やレジスタ等のビット数が異なってはいるものの、その点を除けば第1実施形態と同様の構成である
乗数分割部81は、9ビットずつの部分乗数b(i)=b[9i−1:9i−9](i=1,...,17,18)を乗数Bの下位側から順次出力する。
【0065】
剰余算出部82は、中間数C(i)(i=1,...17,18)を漸化的に算出する。つまり剰余算出部82は、初回(i=1)は、被乗数Aを中間数C(i)として出力する。2回目以降(i=2,...17,18)は前回の中間数C(i−1)の9ビット桁上げされた桁上げ値C(i−1)*29の法Pによる剰余C(i−1)*29modPを中間数C(i)として算出する。より具体的には、剰余算出部82は、初回はA、2回目はA*29modP、3回目は(A*29modP)*29modP、4回目は、((A*29modP)*29modP)*29modP、...を中間数C(i)として算出する。ただし、剰余算出部82は、中間数C(i−1)に対する9ビットの桁上げを行わず、部分積算出部83において算出される桁上げ値C(i−1)*29を利用してその法Pによる剰余C(i−1)*29modPを算出する。
【0066】
剰余の算出が高速に行われるようにするため剰余算出部82は、ROMテーブル904を有する。ROMテーブル904は、桁上げ値C(i−1)*29から下位160ビットを除いた部分、つまり桁上げによって160ビットを越えた部分に対応する法Pによる剰余を予め記憶する。剰余算出部82は、桁上げ値C(i−1)*29の160ビットを越える部分についてROMテーブル904を参照し、当該ROMにより得られる160ビットを越える部分に対応する剰余と、桁上げ値C(i−1)*29の下位160ビットの部分とを算出することにより中間数C(i)を算出する。
【0067】
部分積算出部83は、剰余算出部82より出力される中間数C(i)と乗数分割部81より出力される部分乗数b(i)との部分積C(i)*b(i)を出力する。また部分積算出部83は、剰余算出部82より出力される中間数C(i−1)の9ビットの桁上げ値を算出して剰余算出部82に出力する。
累算部84は、部分積算出部83により出力される部分積C(i)*b(i)を累算する。
【0068】
補正部85は、累算部84による累算結果に応じて累算値にPの整数倍の値を加減算することによって累算値を補正し、それによって累算部84における累算値の桁あふれを防ぐ。
制御部86は、乗数分割部81、剰余算出部82、部分積算出部83、累算部84、補正部85においてi=1〜18の18回行われる演算の繰り返し処理を制御する。また制御部86は、剰余算出部82による中間数の算出と乗数分割部81による部分乗数の算出とを第1段階、部分積算出部83による部分積の算出を第2段階、累算部84による累算値の算出と補正部85による累算値の補正とを第3段階としてパイプライン制御を行う。制御部86は、18回の繰り返し動作の後、累算部84における最終的な累算値がPより大きい場合には、その累算値を剰余算出部82に入力して累算値のPによる剰余を算出させる。
【0069】
図8は、剰余算出部82のより詳細な構成を示す。
同図において剰余算出部82は、セレクタ901、レジスタA906、セレクタ902、剰余演算部907から構成される。
セレクタ901は、制御部86の制御により、まず初期設定(i=1)として外部より入力される被乗数AをレジスタA906に出力し、初期設定後(i=2,...17,18)は剰余演算部907より入力される中間数C(i)をセレクタ901に出力するセレクタである。
【0070】
レジスタA906は、161ビットのレジスタであり、初期設定(i=1)として外部よりセレクタ901を介して入力される被乗数A(=C(1))を保持し、初期設定後(i=2,...17,18)は、加算器905からセレクタ901を介して入力される中間数C(i)を保持する。レジスタA906は、出力側が部分積算出部83に接続されており、制御部86の指示に応じて保持している中間数を新たに入力される中間数に更新し、部分積算出部83に出力する。レジスタA906は、最終的には剰余乗算値Rを保持する。
【0071】
セレクタ902は、繰り返し処理の間、部分積算出部83より入力される桁上げ値C(i−1)*29を剰余演算部907に出力し、繰り返し処理の後、累算部84より入力される累算値を剰余演算部907に出力する。
剰余演算部907は、ROMテーブル904と加算器905から構成され、部分積算出部83よりセレクタ902を介して入力される170ビットの桁上げ値C(i−1)*29又は累算部84より入力される170ビットの累算値の法Pによる剰余又は合同な値を出力する。この剰余または合同な値は161ビットである。
【0072】
剰余演算部907は、セレクタ902から入力される170ビットの値の下位160ビットを加算器905に出力するバス908と、下位160ビットを除く上位10ビット(161〜170ビット目)をROMテーブル904に出力するバス909とを備える。これらバス908及びバス909は、170ビットの値を下位160ビット(以下下位部分と呼ぶ)と上位10ビット(以下上位部分と呼ぶ)とに分割して、下位部分と上位部分とをそれぞれ加算器905とROMテーブル904とに入力する。
【0073】
図9は、ROMテーブル904の記憶内容を示す。
同図においてROMテーブル904は、10ビットで表現される各値(0000000000)2〜(1111111111)2を入力値とし、それら各値を2160倍した値に対する法Pによる剰余を出力値として対応付けて記憶する。ROMテーブル904は、制御部86よりread信号が入力されたときバス909より入力される上位部分に対応する剰余を読み出して出力する。
【0074】
加算器905は、ROMテーブル904より出力される上位部分に対する剰余と下位部分とを加えることによって161ビットのC(i−1)*29modP又はそれと合同な値を出力する。
このように剰余演算部907においては9ビットの桁上げによって160ビットを越えた部分についてROMテーブル904を用いて剰余を求め、その剰余と下位160ビットとを加算することによって桁上げ値C(i−1)*2の剰余又は合同な値を求める。
【0075】
この剰余演算部907の内部の構成を従来技術における剰余算出部3と似た構成にした場合、剰余演算部907は従来技術に示したようなループ処理(ステップ6〜8)を複数回行わなければならず、剰余の算出に時間がかかる。これに対して本実施形態の剰余演算部907は、ROMテーブル904における1回の読出しと加算器905における1回の加算とを行うだけで剰余を算出するので従来の構成よりも高速になる。
【0076】
図10は、乗数分割部81のより詳細な構成を示す。
同図において乗数分割部81は、セレクタ801、レジスタB802、シフタ803から構成される。
セレクタ801は、制御部86の制御により、初期設定(i=1)として、外部より入力される乗数BをレジスタB802へ出力し、初期設定後(i=2,...17,18)は、シフタ803より入力される値をレジスタB802へ出力する。
【0077】
レジスタB802は、161ビットのレジスタであり、初期設定として外部よりセレクタ801を介して入力される乗数Bを保持し、初期設定後は、シフタ803よりセレクタ801を介して入力される値を保持する。レジスタB802は、出力側がシフタ803に接続されており、また下位9ビットの部分が部分積算出部83に接続されている。レジスタB802は、制御部16の制御により保持している値を、シフタ803よりセレクタ801を介して新たに入力される値に更新する。レジスタB802に保持されている値は、シフタ803に出力されるとともに下位9ビットが部分積算出部83へ出力される。
【0078】
シフタ803は、レジスタB802より入力される値を9ビット右シフトして出力する161ビットのシフタである。
このような構成によって剰余算出部82は、乗数Bの下位から9ビットずつの部分乗数b(i)=b[9i−1:9i−9](i=1,...17,18)を順次に部分積算出部83に出力する。
<部分積算出方法>
ここで部分積算出部83の詳細な構成を説明する前に、部分積算出部83の構成の基礎となっている2つの積算出方法について説明する。
【0079】
被乗数Xと3ビットの乗数Y(=y2y1y0)との積は、(式4)のように展開される。
【0080】
【数6】
Figure 0004293665
【0081】
つまり(式4)において積X*Yは、被乗数Xと乗数Yの各桁の重み(22,21,20)と各桁の値(y2,y1,y0)とを乗じて得られる値(X*22*y2,X*21*y1,X*20*y0、以下ビット積と呼ぶ)を加算することにより算出される。
具体的には例えば、Y=101のとき(式4)はX*Y=X*22*y2+X*20*y0であり、X*Yは2つの値(以下ビット積と呼ぶ)の加算によって算出される。Y=110のとき(式4)はX*Y=X*22*y2+X*21*y1であり、X*Yは2つのビット積の加算によって算出される。Y=111のとき(式4)はX*Y=X*22*y2+X*21*y1+X*20*y0であり、X*Yは3つのビット積の加算によって算出される。
【0082】
このように被乗数に対して乗数の各桁の重みと各桁の値とを乗じて得られるビット積を加算することにより積を算出する方法を一般算出方法と呼ぶこととする。第1実施形態における剰余算出部12も、この方法に基づいて構成されている。
ところで111=23−1である。よってY=111のとき積X*Yは、被乗数Xに111を乗じる代わりに23−1を乗じることによっても算出することができる。被乗数Xと23−1と積は次のように展開される。
【0083】
【数7】
Figure 0004293665
【0084】
つまり(式5)においてY=111のとき積X*Yは、被乗数Xに23を乗じた値から被乗数Xを減算することにより算出される。
またY’=111000のとき、Y’=Y*23であるから積X*Y’は被乗数Xに111000を乗じる代わりに26−23を乗じることによっても算出することができる。
【0085】
以上により乗数において2pの位(下位からp+1ビット目)から2q(下位からq+1ビット目)の位(ただしp>q)が全て1であるとき、その部分における積は被乗数に2p+1を乗じた値(以下被減数ともいう)から被乗数に2q(以下減数ともいう)を乗じた値を減ずることによって算出することができる。この方法を特別算出方法と呼ぶこととする。
【0086】
ところで加算器においてsとtとの減算値s−tは、sとtの反転値(1の補数)と定数1との加算に置きかえられて算出される。よって乗数において2pの位(下位からp+1ビット目)から2q(下位からq+1ビット目)の位(ただしp>q)が全て1である場合、その部分について特別算出方法によって積を算出するとすれば、加算器は被乗数の2p+1倍と被乗数の2q倍の反転値(以下単に反転値ともいう)と定数1との加算を行うだけでよい。しかも定数1の加算は加算器の下位ビットのキャリーインを利用して実現することができる。つまり特別算出方法によって積を算出する場合、加算器は2つの加算とキャリーインとを行うだけでよい。
【0087】
これに対してnビットの乗数の全ビットが1である場合、一般算出方法によって積を算出するとすれば、加算器はn個のビット積の加算を行う必要がある。
以上のことから乗数中1が3以上連続して並ぶ場合、その部分については、一般算出方法によるよりも特別算出方法によって積を算出するほうが加算器における加算の数を減らすことができるので、加算器の規模の縮小と加算量の負荷軽減とを実現できる。
部分積算出部83は、上記2つの方法に基づいて部分積C(i)*b(i)を算出するよう構成される。
【0088】
部分積算出部83は、部分乗数b(i)のビット列において1が連続している部分に特別算出方法を適用し、それ以外の部分については一般算出方法を適用する。より具体的には、部分積算出部83は、9ビットの部分乗数b(i)が111111111である場合と、部分乗数b(i)の上位6ビット又は下位6ビットが111111である場合と、上位3ビット又は中位3ビット又は下位3ビットが111である場合にその部分について特別算出方法を適用し、それ以外は一般算出方法を適用する。
【0089】
例えば、部分乗数b(i)が111111011である場合、部分積算出部83は、上位6ビットの111111の部分に特別算出方法を適用し、下位3ビットの010の部分に一般算出方法を適用して積C(i)*b(i)する。ただしこのとき、上位6ビットの111111は、下位から3ビット桁上げされた値(23倍した値)であるので、部分積算出部83は、特別算出方法を適用する際には上位6ビットの部分に対して23の桁上げを行わなければならない。
【0090】
具体的には(式6)のように展開される。
【0091】
【数8】
Figure 0004293665
【0092】
(式6)に示すように上位6ビットの111111については特別算出方法の適用と23の桁上げとにより同式▲1▼のように展開される。すなわち部分積算出部83は、中間数C(i)を9ビット桁上げした値と中間数C(i)を3ビット桁上げした値と定数1との加算によって上位6ビットの111111の部分における積を算出する。また下位3ビットの011については一般算出方法の適用により同式▲2▼のように展開される。すなわち部分積算出部83は、下位3ビットの011の値に応じて、中間数C(i)を1ビット桁上げした値と中間数C(i)との加算によって下位3ビットの011の部分における積を算出する。
【0093】
図11は、部分積算出部83のより詳細な構成を示す。
同図において部分積算出部83は、シフタ部51、選択部52、OR回路513、加算器A701、加算器B702、レジスタCa844、レジスタCb845から構成される。
シフタ部51は、バス830とシフタ831〜839とを有する。バス830は、入力される161ビットの中間数C(i)をそのまま選択部52へ出力する。シフタ831〜839は、それぞれ入力される中間数C(i)を左に1〜9ビットシフトさせることにより中間数C(i)を1〜9ビット桁上げしてC(i)*2、C(i)*22、C(i)*23、C(i)*24、C(i)*25、C(i)*26、C(i)*27、C(i)*28、C(i)*29を生成して選択部52に出力する。またシフタ839は、中間数C(i)を左に9ビットシフトさせて選択部52に出力すると同時に、その値を桁上げ値C(i−1)*29として剰余算出部82に出力する。
【0094】
シフタ部51において、バス830とシフタ831〜838の出力、すなわちC(i)、C(i)*21C、...、C(i)*28は一般算出方法による算出の際のビット積の候補となる値である。シフタ833、836、839の出力、すなわちC(i)*23、C(i−1)*26、C(i−1)*29は、特別算出方法による算出の際の被減数の候補となる値である。またバス830、シフタ833、836の出力、すなわちC(i)、C(i)*23、C(i−1)*26は、特別算出方法による算出の際、減数の候補となる値である。以下これらの候補となる値を候補値と呼ぶこととする。
【0095】
選択部52は、シフタ部51より0〜9ビット桁上げされた値と乗数分割部81からの部分乗数b(i)とが入力されると、9ビットの部分乗数b(i)が111111111であるか否か、部分乗数b(i)の上位6ビット又は下位6ビットが111111であるか否か、上位3ビット又は中位3ビット又は下位3ビットが111であるか否かを判定する。次に選択部52は、その判定に応じてシフタ部51から入力される候補値のうちのいくつかを選択する。より詳しくは、選択部52は、肯定的に判定された部分については、候補値の中からその部分に対応する被減数と減数とを選択する。選択部52は、否定的に判定された部分については、候補値の中からその部分に対応するビット積を選択する。選択部52は、選択された候補値のうち、被減数とビット積についてはそのまま加算器A701又は加算器B702に出力する。選択部52は、選択された候補値のうち、減数については、その値を反転させた反転値と定数1とを生成して、生成した値を加算器A701又は加算器B702に出力する。
【0096】
選択部52は、演算値選択器840、841、842を備える。
図12は、演算値選択器840、841、842の詳細な構成を示す。
演算値選択器840は、インバータ1301、セレクタ1302、1303、制御回路1304を備える。また演算値選択器840は、入力端子S、Z、I0、I1、I2、I3、出力端子F、O0、O1を備える。
【0097】
インバータ1301は、入力端子I0より候補値C(i)が減数として入力されると、その減数を反転させた反転値をセレクタ1303に出力する。
セレクタ1303は、インバータ1301より入力端子¬I0を介して候補値C(i)の反転値が、入力端子Zより0が、入力端子I0より候補値C(i)が、入力端子I1より候補値C(i)*21が入力されると、制御回路1304の入出力論理に従ってこれらの入力端子のうちから1つを選択し、選択した入力端子より入力される値を出力端子O0より出力する。
【0098】
セレクタ1302は、入力端子Zより0が、入力端子I1より候補値C(i)*21が、入力端子I2より候補値C(i)*22が、入力端子I3より候補値C(i)*23が入力されると、制御回路1304の入出力論理に従ってこれらの入力端子のうちから1つを選択し、選択した入力端子より入力される値を出力端子O1より出力する。
【0099】
制御回路1304は、入力端子Sより部分乗数b(i)が入力されると、図13(c)に示す入出力論理に基づいてセレクタ1302及び1303に入力端子の1つを選択させて、その入力端子から入力される値を出力端子O1、O0より出力させる。また制御回路1304は、セレクタ1303に入力端子¬I0を選択させたとき、出力端子Fより1を出力する。それ以外のとき、制御回路1304は、出力端子Fより0を出力する。
【0100】
図13(c)は、制御回路1304に入力される部分乗数b(i)と入出力論理を示す。
同図(c)の1列目は、入力端子Sより入力される部分乗数b(i)を示す。“−”は、1か0かの任意の値を示し、“###”は、“111”以外の任意の値を示す。2列目は、セレクタ1302に選択させる入力端子を示す。3列目は、セレクタ1303に選択させる入力端子を示す。4列目は、制御回路1304が出力端子Fより出力する値で、1のとき定数1を示す。
【0101】
例えば、制御回路1304は、部分乗数b(i)の下位6ビットすべてが1であると判定した場合は、出力端子O1より0を、出力端子O0よりC(i)の反転値を出力させ、出力端子Fより定数1を出力する。下位6ビットすべてが1であると判定しなかった場合であって、下位3ビットすべてが1であると判定した場合は、制御回路1304は、出力端子O1よりC(i)*23を出力させ、出力端子O0よりC(i)を出力させ、出力端子Fより定数1を選択する。その他の場合、制御回路1304は、部分乗数b(i)の下位3ビットの値に応じて出力端子O1、O0よりC(i)*22、C(i)*21、C(i)、0のうちのいずれか2つの値を出力させる。
【0102】
演算値選択器841は、インバータ1301、セレクタ1302、1303、制御回路1305を備える。また演算値選択器841は、入力端子S、Z、I0、I1、I2、I3、出力端子F、O0、O1を備える。演算値選択器841は、演算値選択器840に対して制御回路1304の代わりに制御回路1305を備える点が異なっている。制御回路1305は、入力端子Sより部分乗数b(i)が入力されると、図13(b)に示す入出力論理に基づいてセレクタ1302及び1303に入力端子の1つを選択させて、その入力端子から入力される値を出力端子O1、O0より出力させる。その他の構成要素は、演算値選択器840と同様であるので説明を省略する。
【0103】
演算値選択器842は、インバータ1301、セレクタ1302、1303、制御回路1306を備える。また演算値選択器842は、入力端子S、Z、I0、I1、I2、I3、出力端子F、O0、O1を備える。演算値選択器842は、演算値選択器840に対して制御回路1304の代わりに制御回路1306を備える点が異なっている。制御回路1306は、入力端子Sより部分乗数b(i)が入力されると、図13(a)に示す入出力論理に基づいてセレクタ1302及び1303に入力端子の1つを選択させて、その入力端子から入力される値を出力端子O1、O0より出力させる。その他の構成要素は、演算値選択器840と同様であるので説明を省略する。
【0104】
OR回路513は、演算値選択器840及び841それぞれの出力端子Fの出力値の論理和をとる。図13(b)(c)からわかるように、演算値選択器840及び841において、出力端子Fの一方の出力が定数1であるときは必ず他方の出力は0である。よってOR回路513は、論理和をとることによって2つの値を1つにまとめ、これにより選択器52の出力数を減らしている。
【0105】
加算器A701は、演算値選択器842の出力端子O1、O0、Fの出力値と演算値選択器841の出力端子O1の出力値とを加算して、結果の部分積cをレジスタCa844に出力する。
加算器B702は、演算値選択器841の出力端子O0の出力値と演算値選択器840の出力端子O1、O0の出力値とOR回路513の出力値とを加算しての出力値とを加算して、結果の部分積dをレジスタCa845に出力する。
【0106】
ここにおいて部分積cと部分積dとを加え合わせた値が部分積C(i)*b(i)である。
レジスタCa844レジスタCb845は、それぞれ部分積c及び部分積dを保持し、制御部86の制御により保持している部分積c及び部分積dを新しく入力される値に更新する。レジスタCa844レジスタCb845の出力側は、累算部84に接続されており、レジスタCa844レジスタCb845は、保持している部分積c及び部分積dを累算部84に出力する。
【0107】
図14は、累算部84及び補正部85のより詳細な構成を示す。
同図において累算部84は、加算器705及びレジスタS707から構成される。
レジスタS707は、累算値を保持する171ビットのレジスタであり、制御部86の制御により、保持している累算値を、セレクタ706から入力される新しい累算値に更新する。ここでレジスタS707の最上位ビットは、累算値の正負を表わす符号ビットとなる。
【0108】
加算器705は、レジスタS707に保持される累算値とレジスタCa844及びレジスタCb845に保持される部分積cと部分積dと補正部85より入力される補正値とを加算してレジスタS707に出力する。
補正部85は、レジスタE703、インバータ708、セレクタ704、セレクタ706から構成される。
【0109】
レジスタE703は、部分積c及び部分積dを合わせた値の最大値と成り得る値より大きく、かつ最も近い値を保持する。具体的にはレジスタE703は、122*Pを保持する。
インバータ708は、レジスタE703に保持される1022*Pの反転値(以下、¬1022*Pと表記する)を出力する。
【0110】
セレクタ704は、制御部86の制御に従って、0と1022*Pと¬1022*Pのうちからいずれかを補正値として選択してセレクタ706に供給する。セレクタ706は、制御部86の制御に従って、0または1をセレクタ706に供給する。ここで制御部86は、レジスタS707に保持される累算値の正負に応じてセレクタ704に補正値を選択させ、またセレクタ706に0または1を選択させて加算器705に供給させる。
【0111】
詳しくは制御部86は、レジスタS707の最上位ビットが0であれば、セレクタ704に¬1022*Pを選択させ、セレクタ706に1を選択させる。これによってレジスタS707に保持される累算値が正(最上位ビットが0)である場合には、レジスタE703からインバータ708、セレクタ704を介して¬1022*Pが、またセレクタ706を介して1が加算器705に供給される。これのおかげで加算器705の次の加算においては1022*Pが減算されることになり、加算器705及びレジスタS707における桁あふれが予防される。
【0112】
制御部86は、レジスタS707に保持される累算値が負(最上位ビットが1)である場合には、セレクタ704に0を選択させ、またセレクタ706に0を選択させる。
また制御部86は、i=1〜18の繰り返し処理が終わり、レジスタS707の保持する値が最終的な累算値に更新された場合、その累算値の最上位ビットが1か0かを判定し、1(負を示す)である場合には、セレクタ704に1022*Pを、セレクタ706に0を選択させ、加算器705においてレジスタS707に保持される累算値に1022*Pを加えるという補正を行わせる。これによって制御部86は、最終的な累算値が正になるよう補正させる。また制御部86は、最終的な累算値の最上位ビットが0(正を示す)の場合には、セレクタ704に0を、セレクタ706に0を選択させ、累算値の補正が行われないようにする。
【0113】
なお部分積算出部83は、図15のように構成してもよい。
同図は、図11に対して、シフタ847及びシフタ846を備える点と、演算値選択器840、841、842の代わりに演算値選択器850、851、852を備える点が異なっている。
シフタ847は、部分乗数b(i)を右に3ビットシフトして出力する。
【0114】
シフタ846は、部分乗数b(i)を左に3ビットシフトして出力する。
図16は、演算値選択器850、851、852に共通の制御回路の入出力論理を示す。このように図16に示す部分積算出部83は、シフタ847及びシフタ846を備えることによって、右に3ビットシフトさせた部分乗数b(i)と、部分乗数b(i)そのものと、左に3ビットシフトさせた部分乗数b(i)とを選択器52に入力させる。こうすることにより演算値選択器850、851、852は、同じ入出力論理を適用することができる。また演算値選択器850、851、852がいずれも同じ入出力論理を適用できるので、制御回路を1つにしても良い。
【0115】
また実施形態1において剰余算出部12が有するROMテーブルは2つ、実施形態2において剰余算出部82が有するROMテーブルは1つであったが、3つ以上のROMテーブルを備えるようにしてもよい。
<式の展開>
実施形態1における(式1)から(式2)の変形過程を以下に示しておく。
【0116】
【数9】
Figure 0004293665
【0117】
【発明の効果】
本発明の剰余乗算装置は、被乗数aと乗数b(bはkbビットのデータ)との積に対して、法p(pはkビットデータ)による剰余と合同な値を次式の累算値として算出する剰余乗算装置であって、
累算値 = Σ C(i)*b[s*i+s-1:s*i]
(ここでΣはi=0〜[[kb/s]]までの累算を示す。[[kb/s]]は商kb/sの整数部分であり、iは0から[[k/s]]までの整数であり、C(i)は漸化式で表わされi=0のときC(i)=a、i>=1のときC(i)≡(C(i-1)*2s) mod pであり(≡は両辺の値が法pにおいて合同であることを示す))
b[s*i+s-1:s*i]は、kビットの乗数bのうち2s*i+s-1の位から2s*iの位までのsビットの部分乗数であり、前記剰余乗算装置は、m(mはs以上の整数)ビットにより表現される各値について、その値の2k倍に対する法pによる剰余を予め記憶するテーブル手段と、初回(i=0)では被乗数aを中間数C(0)として出力し、2回目以降(i>0)では、前回出力された中間数C(i-1)をsビット桁上げし、桁上げ後の中間数の下位kビットを除く上位のmビットについての前記剰余をテーブル手段から読み出し、読み出した剰余と下位kビットとを加算することにより新たな中間数(i)を算出する中間数算出手段とを備え、算出された各中間数C(i)と、それに対応する部分乗数b[s*i+s-1:s*i]との部分積C(i)*b[s*i+s-1:s*i]を順次累算することによって前記累算値を算出するよう構成される。
【0118】
この構成によれば、テーブル手段はmビットにより表現される各値、つまり0から2m−1に相当する各値について、それらの値の2K倍に対する法pによる剰余を予め記憶する。中間数算出手段は、i>=1のとき、まず桁上げ後の中間数の下位kビットを除く上位mビットについての剰余、つまり上位mビットの2k倍に対する法pによる剰余をテーブル手段から読み出す。次に中間数算出手段は、テーブル手段より読み出した剰余と下位kビットとを加算することにより桁上げ後の中間数の法pによる剰余又は合同な値を算出する。
【0119】
ここで桁上げ後の中間数の下位kビットは、法pによる剰余そのものの値であるか、又は法pによる剰余と合同な値である。この合同な値は、剰余より大きくかつ剰余により近い値である。よって桁上げ後の中間数について法pによる剰余又は合同な値であって剰余により近い値を得るには、中間数算出手段は、上位mビットについて剰余を得て、これと下位kビットとを加え合わせればよい。中間数算出手段は、上位mビットの剰余をテーブル手段から読み出すことによって、桁上げ後の中間数の法pによる剰余又は合同な値をより短時間で算出する。
【0120】
仮に、従来技術の剰余乗算装置1の剰余算出部3における剰余算出の手順と同様な手順を用いて桁上げ後の中間数の法pによる剰余を求めるとすれば、中間数算出部は、ステップ6〜8のループ処理を複数回繰り返さなければならない。より詳しくは、このループ処理の回数は、桁上げ後の中間数のビット数に相当する。これに対し本発明における中間数算出部は、テーブル部の1回の読み出しと、1回の加算によって桁上げ後の中間数の法pによる剰余又は合同な値を算出することができ高速な剰余演算を実現できる。
【0121】
また中間数算出手段は、漸化的に前回の中間数を桁上げした値の剰余を中間数として算出し、これによって中間数算出手段は、算出する中間数のビット数の増大を防止している。この防止により、中間数を用いて算出される部分積のビット数の増大を防止する。この結果、部分積の累算においてはビット数の抑えられた部分積を用いて加算を行えばよいので、加算器の回路規模を抑えることができる。
【0122】
また前記中間数算出手段は、中間数を保持する第1保持手段と、部分乗数b[s*i+s-1:s*i]に対応して、第1保持手段に保持された中間数をsビット桁上げする桁上げ手段と、桁上げ後の中間数を、桁上げ後の中間数における下位kビットよりも上位のmビットの部分である上位データと下位kビットの部分である下位データとに分割する分割手段と、分割手段による上位データに対する法pによる剰余を前テーブル手段から読み出す読み出し手段と、テーブル手段から読み出された剰余と、分割手段による下位データとを加算することにより新たな中間数を得る加算手段とを備え、前記第1保持手段は、加算手段において新たな中間数が得られる度にその保持内容を新たな中間数に更新し、前記初回では被乗数を中間数として出力し、前記2回目以降では更新後の新たな中間数を出力するよう構成される。
【0123】
この構成によれば、中間数算出手段内部の各構成要素は、汎用のハードウェア素子を用いて簡単に構成することができる。つまり第1保持手段はレジスタ、桁上げ手段はシフタ、分割手段は前記シフタの上位mビット部分と下位kビット部分に接続されたmビットのバスとkビットのバス、加算手段は加算器を用いて構成でき、これらの構成要素によって中間数算出手段は、中間数C(i)を漸化的に算出する。
【0124】
また前記剰余乗算装置は、さらに、前記分割手段、読み出し手段、加算手段を利用することにより、前記累算値の法pによる剰余を求める後処理手段を備える。
この構成によれば、後処理手段が最後の累算値の法pによる剰余を求めることにより、最後の累算値をpよりも小さい値にすることができる。
【0125】
また前記テーブル手段は、mビットにより表現される各値に対応するアドレスが入力され、そのアドレスが指す記憶領域に当該アドレスに対応するmビットの値の2k倍に対する法pによる剰余を予め記憶するメモリ素子を有する。
この構成によれば、テーブル手段はメモリ素子1個で実現することができる。メモリ素子は、mビットにより表現される各値、つまり10進数の0から2m−1に相当する各値について、その2k倍の法pによる剰余を予め記憶する。これら剰余の記憶領域を指し示すアドレスは、各値と同じ値である。メモリ素子は、読み出し手段から上位mビットが入力されると、その値をアドレスとして、そのアドレスが示す記憶領域の剰余が読み出し手段によって読み出される。これによって中間数算出手段は、メモリ素子からの1回の読出しを行うだけで、上位mビットに対応する剰余を短時間で得ることができる。
【0126】
また前記mビットは下位m1ビットと上位m2ビット(m=m1+m2)とに分割され、前記mビットにより表現される各値は、m1ビットにより表現される値とm2ビットにより表現される値との組み合わせに対応し、前記テーブル手段は、m1ビットにより表現される各値について、その値の2k倍に対する法pによる剰余を予め記憶する第1部分テーブル手段と、m2ビットにより表現される各値について、その値の2k+m1倍に対する法pによる剰余を予め記憶する第2部分テーブル手段とを備え、前記加算手段は、第1、第2部分テーブルからの読み出されたそれぞれの剰余と、前記下位データとを加算することにより新たなっ中間数を得るよう構成される。
【0127】
この構成によれば、テーブル手段は、mビットのうち上位側のm1ビットに対応する第1部分テーブル手段と、下位側のm2ビットに対応する第2部分テーブル手段とを有する。第1部分テーブル手段は、上位側m1ビットに対応する剰余を2m1個記憶し、第2部分テーブル手段は、下位側m2ビットに対応する剰余を2m2個記憶する。この個数からわかるように、第1及び第2部分テーブル手段とを合わせた剰余の記憶個数は、メモリ素子1個の場合に比べて、さらに少なくなる。これによりテーブル手段は、記憶容量の小さい2つのメモリ素子によって構成することができる。
【0128】
また前記mビットは下位側からt(3≦t≦m)個の部分ビットm1、…、mtに分割され、前記mビットにより表現される各値は、各mi(iは1からtまで整数)ビットにより表現される値(t個)を組み合わせたものに対応し、前記テーブル手段は、部分ビットmiビットにより表現される各値について、その値の2k+x倍(ここでx=m1+…+m(i-1)である)に対する法pによる剰余を予め記憶するt個の部分テーブル手段Tiを備え、前記加算手段は、t個の部分テーブル手段Tiからの読み出されたt個の剰余と、前記下位データとを加算することにより新たな中間数を得るよう構成される。
【0129】
このようにテーブル手段は、mビットを分割したt個の部分ビットの各値に対応するt個の部分テーブル手段Tiを有する。このようにテーブル手段は、複数の部分テーブル手段Tiを有することにより各部分テーブル手段Tiにおける剰余の記憶個数を少なくしている。
前記剰余乗算装置は、さらに累算手段と補正手段とを備え、前記累算手段は、初期値として0を保持する第3レジスタと、部分積C(i)*b[s*i+s-1:s*i]と第3レジスタに保持された累算値とを加算し、加算結果を新たな累算値として第3レジスタに出力して保持させる加算器とを備え、前記補正手段は、pの整数倍の値をもつ補正値を保持する補正値保持手段と、前記第3レジスタに保持された累算値が所定の値以上であれば、補正値保持手段に保持された補正値を、前記加算器に減算させる補正制御手段とを備える。
【0130】
この構成によれば補正制御手段は、累算値が所定の値以上であれば、加算器に累算値から補正値を減算させるので、第3レジスタにおける桁あふれが防止される。
また前記第3レジスタは符号ビットを有し、前記補正制御手段は、第3レジスタの累算値が正であれば、前記加算器に対して累算値と部分積との加算と同時に前記補正値を減算させ、前記補正値は、pの整数倍であってその絶対値が前記部分積の最大値(t+1)(2 s -1)p以下の値であることを特徴とする。
【0131】
この構成によれば、補正制御手段は第3レジスタに保持される累算値の符号ビットが1(累算値が正を示す)であるとき、加算器に累算値から補正値を減算させるので、第3レジスタにおける桁あふれが防止される。また補正値は、pの整数倍であって前記部分積の最大値(t+1)(2s-1)p以下の値であるので、累算値の最終的な値がpより小さい値か又はpに近い値にする。
【0132】
また前記法pはp=2k−αの関係を満たし、各部分テーブル手段Tiは、前記剰余をk3ビットのデータとして記憶する、ここで、k3はt*2m*αのビット数であり、前記αは、k3がkより小さくなるように定められた定数であることを特徴とする。
この構成によればp=2k−αの関係を満たし、αはk3がkより小さくなるように上限を定められた定数である。これらによって部分テーブル手段Tiに記憶される剰余はk3ビットまでに制限することができ、部分テーブルからの出力ビット数を少なくすることができる。部分テーブル手段Tiから出力される剰余のビット数がk3ビット以下であるので、それに合わせて加算部のビット幅も制限することができる。
【0133】
また各部分テーブル手段Tiは、miビットにより表現される0から(2mi-1)までの値に対応する2mi個のエントリを有し、j(jは0から2miまで)番目のエントリは、j*2m1++m(i-1) *αを格納していることを特徴とする。
この構成において、部分テーブル手段Tiは、記憶するエントリの個数を2mi−1と制限することができ、部分テーブルの規模を小さくすることができる。
【0134】
また、αが仮にuビットであるとすると、j番目のエントリであるj*2m1++m(i-1)*αのビット数は、最大でもjのビット数にm1+m2+...+m(i−1)とuビットとを加え合わせた値に制限することができる。部分テーブル手段Tiより出力される剰余を加算する加算手段は、ビット幅を制限することができる。
【0135】
本発明の剰余乗算装置は、被乗数と乗数との積に対する法p(pはkビットデータ)による剰余と合同な数を算出する剰余乗算装置であって、乗数をs(sは2以上の整数)ビットずつに分けて得られるsビットの部分乗数を下位側から順に出力する出力手段と、各部分乗数の位に応じて、被乗数を桁上げし、桁上げ後の被乗数に対して、法pによる剰余と合同な数(以下中間数と呼ぶ)を算出する第1算出手段と、出力手段により出力された部分乗数と、当該部分乗数に対応して第1算出手段により算出された前記中間数との積を部分積として算出する第2算出手段と、第2算出手段に算出された部分積を累算する累算手段と、累算手段に累算された累算値にpの整数倍の値を加減算することにより、累算値を所定のビット数を越えないように補正する補正手段と、出力手段により全ての部分乗数が出力されるまで、第1算出手段による中間数の算出と、第2算出手段による部分積の算出と、累算手段による累算と、補正手段による補正とを繰り返し行わせる制御手段とを備え、前記第1算出手段は、m(mはs以上の整数)ビットにより表現される各値について、その値の2k倍に対する法pによる剰余を予め記憶し、制御手段による繰り返しのうち初回では被乗数を中間数として出力し、2回目以降では、前回出力された中間数をsビット桁上げし、桁上げ後の中間数の下位kビットより上位のmビットについてテーブル手段を読み出し、読み出した数と下位kビットとを加算することにより新たな中間数を算出するよう構成される。
【0136】
この構成によれば第1算出手段は、制御手段により繰り返しのうち2回目以降では、sビット桁上げされた桁上げ後の中間数の下位kビットを除く上位もmビットについてテーブル手段より対応する剰余を読出し、その剰余と下位kビットとを加算することにより、桁上げ後の中間数の法pによる剰余又は合同な値を中間数として算出する。これによって第1算出手段は、剰余の算出を高速に行う。
【0137】
また第2算出手段は、sビットの部分乗数毎に部分乗数と中間数との部分積を算出する。このように複数桁の部分乗数ずつ部分積を算出するので、部分乗数の個数分だけ部分積の算出を行えばよく、第2算出手段における繰り返しの回数が減り、従来技術の積算出部2に比べて高速になる。
また前記制御手段は、第1〜第3ステージを含むパイプライン処理を制御する、第1ステージでは出力手段に部分乗数を出力させるとともに第1算出手段に中間数を出力させ、第2ステージでは第2算出手段に部分積を算出させ、第3ステージでは累算手段に累算させるともに補正手段に補正させるよう構成される。
【0138】
この構成によれば剰余乗算装置は、パイプライン処理を行うので、各構成要素における処理が効率良く行われ、演算の処理速度がより高速になる。
また前記出力手段は、最初に乗数を保持し、保持している値の下位sビットを部分乗数として出力する乗数保持手段と、乗数保持手段に保持されている値をsビット下位側にシフトさせ、シフト後の値を乗数保持手段に出力して保持させるシフト手段とを備える。
【0139】
この構成によれば、出力手段は、乗数を保持するレジスタと、保持された乗数をsビット下位側にシフトさせるシフタによって簡単に構成することができる。
また前記第2生成手段は、第i(iは1から(s−1)の整数)のシフト手段は、第1算出手段により算出された前記中間数をiビット左シフトにより桁上げする第1から第(s−1)のシフト手段を備え、前記第1生成手段は、第1算出手段により算出された前記中間数をsビット左シフトにより桁上げする第sのシフト手段と、前記中間数の1の補数を生成する補数生成手段と、定数1を出力する定数出力手段とを備え、前記第2加算手段は、全ビットが1であると判定された場合に、第sのシフト手段の出力と、補数生成手段に生成された1の補数と、定数1を選択し、全ビットが1であると判定されなかった場合に、部分乗数の20の位が”1”であれば前記中間数を選択し、部分乗数の2iの位が”1”であれば、第iのシフト手段の桁上げ結果を選択する選択手段と、選択手段の選択結果を加算することにより前記部分積を算出する加算器とを備える。
【0140】
この構成によれば、第1から第(s−1)のシフト手段は、1〜(s−1)ビット左シフトを行うシフタによって実現される。第sのシフト手段は、sビット左シフトを行うシフタによって実現される。補数生成手段は、インバータにより実現される。このように第1生成手段及び第2生成手段は、汎用的なハードウェア素子によって構成することができる。これらの構成要素は、加算手段に加算させるべき候補の値を前もって生成する。選択手段は、部分乗数の値に応じて候補の値から加算手段に加算させるべき値を選択する。加算手段は、選択された候補の値を加算することによって部分積を算出する。このような構成によって第2算出手段は、複数桁の中間数と部分乗数との部分積を高速に算出することができる。
【図面の簡単な説明】
【図1】第1実施形態における剰余乗算装置100の概略構成を示すブロック図である。
【図2】剰余算出部12のより詳細な構成図を示す。
【図3】(a)ROMテーブル309の記憶内容を示す。
(b)ROMテーブル308の記憶内容を示す。
【図4】乗数分割部11のより詳細な構成を示す。
【図5】部分積算出部13のより詳細な構成を示す。
【図6】累算部14及び補正部15の詳細な構成を示す。
【図7】第2実施形態における剰余乗算装置200の概略構成を示すブロック図である。
【図8】剰余算出部82のより詳細な構成を示す。
【図9】ROMテーブル904の記憶内容を示す。
【図10】乗数分割部81のより詳細な構成を示す。
【図11】部分積算出部83のより詳細な構成を示す。
【図12】演算値選択器840、841、842の詳細な構成を示す。
【図13】(a)は、制御回路1306に入力される部分乗数b(i)と制御回路1306の入出力論理との対応を示す。
(b)は、制御回路1305に入力される部分乗数b(i)と制御回路1305の入出力論理との対応を示す。
(c)は、制御回路1304に入力される部分乗数b(i)と制御回路1304の入出力論理との対応を示す。
【図14】累算部84及び補正部85のより詳細な構成を示す。
【図15】部分積算出部83は、図15のように構成してもよい。
【図16】演算値選択器850、851、852に共通の制御回路の入出力論理を示す。
【図17】従来の剰余乗算装置の構成を示す。
【符号の説明】
100 剰余乗算装置
11 乗数分割部
12 剰余算出部
13 部分積算出部
14 累算部
15 補正部
16 制御部
308 ROMテーブル
309 ROMテーブル
301 セレクタ
302 レジスタA
303 シフタ
304 セレクタ
310 加算器
311 剰余演算部[0001]
BACKGROUND OF THE INVENTION
The present invention relates to a modular multiplication apparatus that performs modular multiplication with a high-speed and small-circuit configuration.
[0002]
[Prior art]
In recent years, with the development of encryption technology in the communication field, there is an increasing demand for various arithmetic units used for encryption.
For example, in the elliptic cryptosystem, a modular multiplication device for performing modular multiplication is used. Here, the remainder multiplication is to perform (a * b) modp operation on the three integers a, b and p. Here, a is a multiplicand, b is a multiplier, and p is a modulus.
[0003]
FIG. 17 shows a configuration of a conventional modular multiplication apparatus.
In the remainder multiplication apparatus 1 shown in FIG. 2, a, b, and p are small values as represented by 4 bits for the sake of simplicity.
The remainder multiplication apparatus 1 includes a product calculation unit 2, a remainder calculation unit 3, and a control unit 4.
The product calculation unit 2 includes a multiplicand register 5 (4 bits), an adder 6 (4 bits), and a product register 7 (9 bits). The product a * b of the multiplicand a and the multiplier b is controlled by the control unit 4. Is calculated.
[0004]
The processing procedure of the control unit 4 for the product calculation unit 2 is shown below.
Step 1: As an initial setting, the multiplicand a is held in the multiplicand register 5, the multiplier b is held in the lower 4 bits of the product register 7 (8 bits), and 0 is held in the upper 5 bits of the product register 7.
Step 2: It is determined whether the least significant bit of the product register 7 is 0 or 1. If it is determined to be 1, the adder 6 removes the most significant bit from the upper 5 bits of the product register 7 4 The value held in the bit and the multiplicand a held in the multiplicand register 7 are added, and the added value is held in the upper 4 bits of the product register 7.
[0005]
Step 3: Shift product register 7 right by 1 bit.
Step 4: The process of steps 2-3 is repeated four times.
As described above, when the loop processing in steps 2 to 3 is repeated four times, the product a * b is held in the product register 7.
The remainder calculation unit 3 includes a modulus register 8 (4 bits), an adder 9 (5 bits), and a remainder register 10 (13 bits), and is controlled by the control unit 4 in the same manner as handwritten writing. The remainder (a * b) modp is calculated by the modulus p of b. The remainder calculated by the remainder calculation unit 3 is a signed 5-bit value.
[0006]
The processing procedure of the control unit 4 for the remainder calculation unit 3 is shown below.
Step 5: As an initial setting, the modulus p is held in the modulus register 8, the product a * b held in the product register 7 is held in the lower 8 bits of the remainder register 10, and 0 is held in the upper 5 bits.
Step 6: Shift the left register 1 bit by 1 bit.
[0007]
Step 7: The adder 9 subtracts the modulus p held in the modulus register 8 from the value held in the upper 5 bits of the remainder register 10, and holds it in the upper 5 bits of the remainder register 10.
Step 8: The sign of the upper 5 bits of the remainder register 10 is determined from the value of the most significant bit, and if it is determined to be negative (the most significant bit is 1), the adder 9 uses the upper 5 bits of the remainder register 10 and the modulus register. The value of the remainder register 10 is restored by adding the modulus p of 8 (that is, the value before being subtracted in step 7).
[0008]
Step 9: The process of steps 6-8 is repeated 8 times.
As described above, when the loop process of steps 6 to 8 is repeated eight times, the remainder (a * b) modp is held in the upper 5 bits of the remainder register 10.
In this way, the remainder multiplying apparatus 1 calculates the partial product of the multiplicand a and each bit of the multiplier b in the product calculation unit 2 in correspondence with the multiplicand a from the lower side of b, and calculates the calculated partial product. The product a * b is calculated by sequentially accumulating. Then, the remainder calculating unit 3 shifts the product a * b calculated by the product calculating unit 2 and adjusts the digit of the modulus p from the a * b to the modulus a while aligning the digit from the upper digit to the lower digit of the product a * b. The remainder (a * b) modp is calculated by subtracting p.
[0009]
[Problems to be solved by the invention]
In the remainder multiplication apparatus 1 in the above prior art, since a, b, and p are as small as 4 bits, the adder 6 and the adder 9 only need to be able to add 4 bits, and the number of loop processes is also sufficient. The number is 4 times in the product calculation unit 2 and 8 times in the remainder calculation unit 3. On the other hand, a, b, and p used for actual elliptic encryption are considerably large values such as 160 bits. Therefore, when the conventional remainder multiplication apparatus 1 is made to correspond to an operation using 160 bits a, b, and p, the adder 6 and the adder 9 need to perform 160 bits addition, which increases the circuit scale. There was a problem. In addition, the number of loop processes is repeated 160 times in the product calculation unit 2 and 320 times in the remainder calculation unit 3, and there is a problem that it takes a calculation time.
[0010]
Assuming that the remainder multiplication apparatus 1 according to the prior art is adapted to an operation using any value in this way, the larger the number of bits of the value, the larger the number of bits added in the adder. There is a problem in that the circuit scale becomes large and the number of loop processes increases, resulting in a long calculation time.
As another conventional technique for solving the calculation time problem of the remainder multiplication apparatus 1, there is a remainder multiplication method described in “United States Patent 5,144,574 Modular multiplication method and the system for processing data”.
[0011]
This remainder multiplication method calculates a partial product of 2 bits each of a multiplicand a and a multiplier b in order corresponding to the multiplicand a by 2 bits sequentially from the higher-order side of the multiplier b, and from each partial product, it is calculated. This is a method of calculating a partial remainder by subtracting an integral multiple of the modulus p and calculating the partial residue by the partial product method p, and accumulating the partial residue.
[0012]
In an apparatus using such a modular multiplication method, the modular multiplication apparatus 1 calculates a partial product by associating each bit of the multiplier b with the multiplicand a, whereas the multiplicand a and the multiplier b 2 Since the partial product for each bit is calculated, the number of loop processes for calculating the partial product is reduced, and the calculation time is shortened.
As described above, the remainder multiplication method is intended to shorten the calculation time mainly by calculating a partial product in which the multiplicand a and the multiplier b are associated with each two bits. However, in this remainder multiplication method, the number of bits of the multiplier b corresponding to the multiplicand a when calculating the partial product is as few as 2 bits, and when a, b, and p are large values, the calculation time is much longer. The shortening effect cannot be obtained.
[0013]
In view of the above problems, an object of the present invention is to provide a modular multiplication apparatus that performs high-speed computation while suppressing the circuit scale.
[0014]
[Means for Solving the Problems]
In order to solve the above problem, the remainder multiplication apparatus of the present invention obtains a congruent value with the remainder by the modulus p (p is k-bit data) for the product of the multiplicand a and the multiplier b (b is kb-bit data). A modular multiplication device that calculates the accumulated value of the following equation,
Accumulated value = ΣC (i) * b [s * i + s-1: s * i]
(Where Σ is an accumulation from i = 0 to [[kb / s]]. [[Kb / s]] is the integer part of the quotient kb / s, and i ranges from 0 to [[k / s ]], And C (i) is expressed by a recurrence formula. When i = 0, C (i) = a, and when i> = 1, C (i) ≡ (C (i-1) * 2 s ) mod p (≡ indicates that the values on both sides are congruent in modulus p))
b [s * i + s-1: s * i] is 2 out of the k-bit multiplier b s * i + s-1 2 from the place of s * i S-bit partial multipliers up to k Table means for preliminarily storing the remainder by the modulus p for the multiplication, and in the first time (i = 0), the multiplicand a is output as an intermediate number C (0);
From the second time on (i> 0), the intermediate number C (i-1) output last time is carried out by s bits, and the remainder for the upper m bits excluding the lower k bits of the intermediate number after the carry. Intermediate number calculation means for calculating a new intermediate number (i) by reading from the table means and adding the read remainder and the lower k bits, and corresponding to each calculated intermediate number C (i) The partial product C (i) * b [s * i + s-1: s * i] with the partial multiplier b [s * i + s-1: s * i] It is configured to calculate a value.
[0015]
The intermediate number calculating means includes a first holding means for holding the intermediate number and an intermediate number held in the first holding means corresponding to the partial multiplier b [s * i + s−1: s * i]. And a carry means for carrying s bits, and an intermediate number after the carry, the upper data which is the upper m bits of the lower k bits and the lower k which is the lower k bits of the intermediate number after the carry A dividing unit that divides the data into data, a reading unit that reads the remainder of the higher-order data by the dividing unit by the method p from the previous table unit, a remainder read from the table unit, and the lower data by the dividing unit Adding means for obtaining a new intermediate number, and the first holding means updates the held content to a new intermediate number each time a new intermediate number is obtained by the adding means, and the multiplicand is changed to the intermediate number at the first time. Output as the second time Descending in is configured to output a new intermediate number of updated.
[0016]
The remainder multiplication device further includes post-processing means for obtaining a remainder by the modulus p of the accumulated value by using the dividing means, the reading means, and the adding means.
The table means receives an address corresponding to each value represented by m bits, and stores the m-bit value 2 corresponding to the address in the storage area indicated by the address. k It has a memory element for preliminarily storing a remainder by the modulus p for the multiplication.
[0017]
The m bits are divided into lower m1 bits and upper m2 bits (m = m1 + m2), and each value represented by the m bits is a value represented by the m1 bit and a value represented by the m2 bit. The table means, for each value represented by m1 bits, 2 k A first partial table means for preliminarily storing a remainder by a modulus p for a multiplication factor, and for each value represented by m2 bits, 2 of the value k + m1 Second partial table means for preliminarily storing a remainder obtained by modulus p with respect to multiplication, wherein the adding means adds the respective remainders read from the first and second partial tables and the lower order data To obtain a new intermediate number.
The m bits are divided into t (3 ≦ t ≦ m) partial bits m1,..., Mt from the lower side, and each value represented by the m bits is each mi (i is an integer from 1 to t). ) Corresponding to a combination of values (t) expressed by bits, the table means for each value expressed by partial bits mi bits, k + x T partial table means Ti for preliminarily storing a remainder by modulus p for a multiple (here, x = m1 +... + M (i-1)), and the adding means includes t partial table means Ti A new intermediate number is obtained by adding the read t remainders and the lower order data.
[0018]
The remainder multiplication apparatus further includes an accumulation unit and a correction unit, and the accumulation unit includes a third register that holds 0 as an initial value, and a partial product C (i) * b [s * i + s. -1: s * i] and the accumulated value held in the third register are added, and the addition means outputs the added result to the third register as a new accumulated value and holds it. Is a correction value holding means for holding a correction value having an integer multiple of p, and a correction value held in the correction value holding means if the accumulated value held in the third register is equal to or greater than a predetermined value. Correction control means for causing the adder to subtract a value.
[0019]
The third register has a sign bit, and the correction control means corrects the correction simultaneously with the addition of the accumulated value and the partial product to the adder if the accumulated value of the third register is positive. The correction value is an integer multiple of p, and its absolute value is the maximum value (t + 1) (2 s -1) The value is less than or equal to p.
The method p is p = 2. k Each partial table means Ti stores the remainder as k3 bit data, where k3 is t * 2 m * The number of bits of α, wherein α is a constant determined such that k3 is smaller than k.
[0020]
Each partial table means Ti is represented by 0 to (2 mi 2 for values up to -1) mi J (j is 0 to 2) mi The second entry is j * 2 m1 + ... + m (i-1) * α is stored.
A remainder multiplication apparatus according to the present invention is a remainder multiplication apparatus that calculates a number congruent with a remainder by a modulus p (p is k-bit data) for a product of a multiplicand and a multiplier, and the multiplier is s (s is an integer of 2 or more) ) Output means for outputting partial multipliers of s bits obtained by dividing each bit in order from the lower side, and the multiplicand is carried according to the position of each partial multiplier, and the modulus p is applied to the multiplicand after the carry. A first calculation means for calculating a number congruent with the remainder by the above (hereinafter referred to as an intermediate number), a partial multiplier output by the output means, and the intermediate number calculated by the first calculation means corresponding to the partial multiplier A second calculating means for calculating the product of the two as a partial product, an accumulating means for accumulating the partial product calculated by the second calculating means, and an integral multiple of p to the accumulated value accumulated by the accumulating means By adding or subtracting the value, the accumulated value does not exceed the specified number of bits. Until all partial multipliers are output by the output means, the intermediate number by the first calculation means, the partial product by the second calculation means, the accumulation by the accumulation means, Control means for repeatedly performing correction by the correction means, wherein the first calculation means is configured to calculate 2 for each value represented by m (m is an integer equal to or greater than s) bits. k The remainder by the modulus p for the multiplication is stored in advance, and the multiplicand is output as an intermediate number in the first iteration among the repetitions by the control means. The table means is read for m bits higher than the lower k bits of the number, and a new intermediate number is calculated by adding the read number and the lower k bits.
[0021]
The control means controls pipeline processing including the first to third stages. In the first stage, the output means outputs a partial multiplier and the first calculation means outputs an intermediate number, and the second stage outputs the intermediate number. 2 The partial product is calculated by the calculating means, and in the third stage, the accumulating means is accumulated and the correcting means is corrected.
The output means holds the multiplier first, and outputs the lower s bits of the held value as a partial multiplier, and shifts the value held in the multiplier holding means to the lower side of the s bits. Shift means for outputting and holding the shifted value to the multiplier holding means.
[0022]
The second generation means is a first shift means for shifting the intermediate number calculated by the first calculation means by i-bit left shift. The i-th shift means (i is an integer from 1 to (s-1)). To (s-1) th shift means, wherein the first generation means carries the intermediate number calculated by the first calculation means by s-bit left shift, and the intermediate number Complement generating means for generating a 1's complement, and constant output means for outputting a constant 1, wherein the second adding means is configured to output the sth shift means when all bits are determined to be 1. When the output, the one's complement generated by the complement generation means, and the constant 1 are selected and it is not determined that all bits are 1, the partial multiplier is 2 0 If the place is “1”, the intermediate number is selected and the partial multiplier is 2 i If the place is “1”, there are provided selection means for selecting the carry result of the i-th shift means and an adder for calculating the partial product by adding the selection results of the selection means.
[0023]
DETAILED DESCRIPTION OF THE INVENTION
<First Embodiment>
The remainder multiplication apparatus in this embodiment will be described below with reference to the drawings.
The remainder multiplication apparatus according to the present embodiment is an apparatus used for computation of elliptic curve cryptography. When a multiplicand A (160 bits) and a multiplier B (160 bits) are input, the product A * shown in (Expression 1). The remainder R (= A * BmodP) or the remainder R in the modulus P (160-bit prime number) of B is calculated on the remainder field. Here, the modulus P is P = 2 when α is a value of 54 bits or less. 160 It is a value satisfying −α.
[0024]
This modular multiplication apparatus is configured based on (Expression 2) obtained by modifying (Expression 1). Note that the details of the transformation process from (Formula 1) to (Formula 2) are shown at the end of the embodiment of the invention just in case.
[0025]
[Equation 3]
Figure 0004293665
[0026]
[Expression 4]
Figure 0004293665
[0027]
<Explanation of arithmetic expression>
In (Formula 2), R1 is the same value in the remainder field of R and modulus P. Here, the fact that R and R1 are the same in the remainder field of the modulus P indicates that the difference between R1 and R is an integral multiple of P.
R1 is calculated by accumulating C (i) * b (i) from i = 1 to k / s. Here, k is the number of bits of the multiplier B. s is the number of bits of each partial multiplier when the multiplier B is divided into partial multipliers of several bits. That is, k / s is the same value as the number of partial multipliers. Here, k and s are determined so that k is divisible by s.
[0028]
b (i) = b [s * i−1: s * i−s)] represents a partial multiplier obtained by dividing the multiplier B into s bits from the lower order. b (1) = b [s-1: 0] when i = 1, b (2) = b [2s-1: s] when i = 2, b (3) = [3s when i = 3 −1: 2s],. . . It becomes. Here, when the k-bit multiplier B is expressed in binary, bk-1bk-2. . . It shall be expressed as b2b1b0. Also, b [x: y] indicates a bit string from the lower x + 1 bit to the y + 1th bit (where x> y) of the multiplier B. Therefore, for example, b [15: 8] indicates a partial multiplier from the lower 16th bit to the 9th bit of the multiplier B, and is expressed as b15b14b13b12b11b10b9b8 in binary notation.
[0029]
C (i) is C (1) = A (A is a multiplicand) when i = 1, and C (i) ≡C (i-1) * 2 when 2 <= i <= k / s. s It is expressed by a recurrence formula called modP. That is, C (i) is C (1) = A (multiplicand), C (2) ≡A * 2 s modP, C (3) ≡ (A * 2 s modP) * 2 s ModP, ... changes gradually. In this recurrence formula, 2 s Corresponds to a carry of the partial multiplier b (i) of s bits. C (i) is a remainder in modulus P of a value obtained by carrying s bits of C (i−1), which is the previous value. Hereinafter, C (i) is hereinafter referred to as an intermediate number.
[0030]
Thus, in (Equation 2), R1 is recursively calculated as the intermediate number C (i) with the remainder of the value raised by s bits for the multiplicand A in the range of i = 1 to k / s. In addition, by dividing the multiplier B into partial multipliers b (i) of s bits from the lower order, and obtaining and accumulating those partial products C (i) * b (i) by repeating k / s times Desired. Hereinafter, repeating the operation k / s times to calculate R1 is referred to as an iterative process.
<Configuration of Remainder Multiplier>
FIG. 1 is a block diagram illustrating a schematic configuration of a remainder multiplication apparatus 100 according to the present embodiment.
[0031]
In FIG. 1, the remainder multiplication apparatus 100 includes a multiplier division unit 11, a remainder calculation unit 12, a partial product calculation unit 13, an accumulation unit 14, a correction unit 15, and a control unit 16. The remainder multiplication apparatus 100 is configured based on (Expression 2) when k = 160 and s = 8.
The multiplier division unit 11 sequentially outputs 8-bit partial multipliers b (i) = b [8i-1: 8i-8] (i = 1,..., 19, 20) from the lower order side of the multiplier B. .
[0032]
The remainder calculation unit 12 recursively calculates the intermediate number C (i) (i = 1,..., 19, 20). That is, the remainder calculation unit 12 outputs the multiplicand A as the intermediate number C (1) for the first time (i = 1). For the second and subsequent times (i = 2, 3,..., 20), the previous intermediate number C (i−1) is carried by 8 bits, and the carry value C (i−1) * 2 8 Is calculated as an intermediate number C (i) (i = 2, 3,..., 20). More specifically, the remainder calculation unit 12 determines that the first time is A and the second time is A * 2. 8 modP, the third time (A * 2 8 modP) * 2 8 modP, 4th ((A * 2 8 modP) * 2 8 modP) * 2 8 modP,. . . Is calculated as an intermediate number C (i). Here, C (i) calculated by the remainder calculation unit 12 is a carry value C (i−1) * 2. 8 And may be a value greater than P.
[0033]
The remainder calculation unit 12 includes a ROM table 308 and a ROM table 309 so that the remainder is calculated at high speed. These ROMs will be described in detail later, but carry value C (i-1) * 2 8 The remainder of the modulus P corresponding to the part excluding the lower 160 bits from the part, that is, the part exceeding 160 bits by carry is stored in advance. The remainder calculation unit 12 carries the carry value C (i−1) * 2. 8 Referring to these ROMs for the portion exceeding 160 bits, the remainder corresponding to the portion exceeding 160 bits obtained from the ROM and the carry value C (i−1) * 2 8 The intermediate number C (i) is calculated by adding the lower 160 bits.
[0034]
The partial product calculation unit 13 calculates a partial product C (i) * b (i) between the intermediate number C (i) output from the remainder calculation unit 12 and the partial multiplier b (i) output from the multiplier division unit 11. Output.
The accumulation unit 14 accumulates the partial product C (i) * b (i) output from the partial product calculation unit 13.
[0035]
The correction unit 15 corrects the accumulated value by adding or subtracting an integer multiple of P to the accumulated value according to the accumulation result by the accumulating unit 14, and thereby the digit of the accumulated value in the accumulating unit 14. Prevent overflow.
The control unit 16 controls the repetitive processing of the calculation performed 20 times with i = 1 to 20 in the remainder calculation unit 12, the partial product calculation unit 13, the accumulation unit 14, and the correction unit 15. The control unit 16 calculates the intermediate number by the remainder calculating unit 12 and the partial multiplier by the multiplier dividing unit 11 in the first stage, and calculates the partial product by the partial product calculating unit 13 in the second stage. The pipeline control is performed in the third stage of the calculation of the accumulated value by and the correction of the accumulated value by the correction unit 15. Further, after the control unit 16 repeatedly operates 20 times, if the final accumulated value in the accumulating unit 14 is larger than P, the accumulated value is input to the remainder calculating unit 12 to calculate the accumulated value. The remainder by P is calculated.
[0036]
FIG. 2 shows a more detailed configuration diagram of the remainder calculation unit 12.
In the figure, the remainder calculation unit 12 includes a selector 301, a register A 302, a shifter 303, a selector 304, and a remainder calculation unit 311.
Under the control of the control unit 16, the selector 301 first outputs a multiplicand A input from the outside as an initial setting (i = 1) to the register A302, and after the initial setting (2 <= i <= 20), a remainder calculation unit. This selector outputs the intermediate number C (i) input from 311 to the register A302.
[0037]
The register A302 is a 161-bit register, holds the multiplicand A (= C (1)) input from the outside via the selector 301 as an initial setting (i = 1), and after the initial setting (2 <= i <= 20) holds the intermediate number C (i) input from the adder 310 via the selector 301. The register A302 is connected to the partial product calculation unit 13 and the shifter 303 on the output side, and updates the intermediate number held in response to an instruction from the control unit 16 to the newly input intermediate number, thereby calculating the partial product Output to the unit 13 and the shifter 303.
[0038]
The shifter 303 is a 169-bit wide shifter that shifts the input by 8 bits to the left. The 161-bit intermediate number C (i−1) input from the register A302 is shifted by 8 bits to the left, and a 169-bit carry value C (I-1) * 2 8 Is output. Thus, the shifter 303 performs an 8-bit carry on the intermediate number C (i−1) by performing an 8-bit left shift.
[0039]
The selector 304 carries the carry value C (i−1) * 2 input from the shifter 303 during the repetitive processing. 8 Is output to the residue calculation unit 311, and after the iterative processing, the accumulated value input from the accumulation unit 14 is output to the residue calculation unit 311.
The remainder calculation unit 311 includes a ROM table 308, a ROM table 309, and an adder 310, and a carry value C (i−1) * 2 input from the shifter 303 via the selector 304. 8 Alternatively, a remainder or congruent value according to the modulus P of the accumulated value input from the accumulation unit 14 is output. This remainder or congruent value is 161 bits.
[0040]
The remainder calculation unit 311 also inputs a bus 305 that inputs the lower 160 bits of the 169-bit value input from the selector 304 to the adder 310, a bus 306 that inputs the 161st to 165th bits to the ROM table 308, and 166 to And a bus 307 for inputting the 169th bit to the ROM table 309. These buses carry carry value C (i-1) * 2. 8 Alternatively, the accumulated value is divided into a 160-bit portion (hereinafter referred to as the lower portion), a 5-bit portion (hereinafter referred to as the 5-bit portion), and a 4-bit portion (hereinafter referred to as the 4-bit portion) from the lower side. The data are input to the adder 310, the ROM table 308, and the ROM table 309, respectively.
[0041]
3A and 3B show the storage contents of the ROM table 309 and the ROM table 308. FIG.
FIG. 4B shows the stored contents of the ROM table 308. The ROM table 308 is a value represented by 5 bits (00000). 2 ~ (11111) 2 Is the input value and each of those values is 2 160 The remainder by the modulus P for the doubled value is stored in association with the output value. In FIG. 5B, α is P = 2. 160 Since α satisfies the relationship α = 2 160 modP. Therefore, the output values 0, 1 * α, 2 * α,... 31 * α in FIG. 160 This is a remainder by the modulus P of the doubled value. Here, α is a value of 54 bits or less and the input value is 5 bits, so the output of the ROM table 308 is 59 bits at the maximum. The ROM table 308 reads and outputs the remainder corresponding to the 5-bit portion input from the bus 306 when the read signal is input from the control unit 16.
[0042]
FIG. 4A shows the stored contents of the ROM table 309. The ROM table 309 is a 4-bit value (0000) 2 ~ (1111) 2 Is the input value and each of those values is 2 165 The remainder by the modulus P for the doubled value is stored in association with the output value. Where α = 2 160 Since it is modP, the output value 0, (1) * 32 * α, 2 * 32 * α,... 15 * 32 * α in FIG. 165 This is a remainder by the modulus P of the doubled value. Since α is a value of 54 bits or less, the input value is 4 bits, and 32 is 5 bits, the output of the ROM table 309 is 63 bits at the maximum. The ROM table 309 reads and outputs the remainder corresponding to the 4-bit portion input from the bus 307 when the read signal is input from the control unit 16.
[0043]
As described above, the remainder calculation unit 311 obtains the remainder using the ROM table 308 and the ROM table 309 for the part exceeding 160 bits due to the carry, and thus the speed is higher than the conventional construction for obtaining the remainder by subtraction. Further, since the ROM table 308 and the ROM table 309 are divided into two ROMs, the number of input values is 2 in the ROM table 308. Five ROM table 309 is 2 Four It becomes fewer with pieces. As a result, the ROM table 308 and the ROM table 309 search for input values corresponding to the 5-bit part and the 4-bit part, respectively, and speed up the calculation of the remainder.
[0044]
The adder 310 adds the lower part of 160 bits, the remainder (59 bits) of the 5-bit part output from the ROM table 308, and the remainder (63 bits) of the 4-bit part output from the ROM table 309. (I-1) * 2 8 ModP or congruent value is output.
And modulo P output the same value over the remainder field. The value output from the adder 310 is 161 bits.
[0045]
FIG. 4 shows a more detailed configuration of the multiplier dividing unit 11.
In the same figure, the multiplier dividing unit 11 includes a shifter 503, a selector 501, and a register B502.
Under the control of the control unit 16, the selector 501 outputs the multiplier B input from the outside to the register B 502 as an initial setting (i = 1). After the initial setting (2 <= i), the selector 501 inputs the shifter 503. Is output to the register B502.
[0046]
A register B502 is a 160-bit register that holds a multiplier B input from the outside via the selector 501 as an initial setting, and holds a value input from the shifter 503 via the selector 501 after the initial setting. . The output side of the register B502 is connected to the shifter 503, and the lower 8 bits are connected to the partial product calculation unit 13. The multiplier dividing unit 11 updates the value held by the control of the control unit 16 to a value newly input from the shifter 503 via the selector 501. The value held in the register B 502 is output to the shifter 503 and the lower 8 bits are output to the partial product calculation unit 13.
[0047]
The shifter 503 is a 160-bit shifter that shifts the value input from the register B502 to the right by 8 bits and outputs the result.
With such a configuration, the multiplier dividing unit 11 calculates the partial multipliers b (i) = b [8i−1: 8i−8] (i = 1,..., 19, 20) of 8 bits from the lower order of the multiplier B. The data are sequentially output to the partial product calculation unit 13.
[0048]
FIG. 5 shows a more detailed configuration of the partial product calculation unit 13.
In the figure, the partial product calculation unit 13 includes a shifter unit 512, a selector unit 513, an adder 522, an adder 523, a register Ca 524, and a register Cb 525.
When the calculation in the partial product calculation unit 13 is expressed by an equation, it is expressed as (Equation 3).
[0049]
[Equation 5]
Figure 0004293665
[0050]
In the equation, for convenience, the binary notation of the partial multiplier b (i) input from the multiplier dividing unit 11 is bi7bi6bi5bi4bi3bi2bi1bi0.
As shown in the equation, the partial product calculation unit 13 first calculates a digit of 0 to 7 bits corresponding to each bit of the partial multiplier b (i) with respect to the intermediate number C (i) input from the remainder calculation unit 12. Next, multiply each value carried by each bit of the partial multiplier b (i) (formula (2)), and finally add them (form (3)) ▼, ▲ 4 ▼)
The shifter unit 512 includes a bus 504 and shifters 505 to 511 that respectively shift the input values by 1 to 7 bits to the left, and performs an operation corresponding to the equation (1).
[0051]
That is, the shifter unit 512 carries the intermediate number C (i) input from the remainder calculation unit 12 according to the weight of each bit of the partial multiplier b (i) and outputs the result to the selector unit 513. The shifters 505 to 511 are shifters that perform 1 to 7-bit left shift on input C (i). That is, the shifters 505 to 511 each receive C (i) * 2 for C (i) input. 1 ~ C (i) * 2 7 Is output. The bus 504 outputs the intermediate number C (i) to the selector unit 513 as it is.
[0052]
The selector unit 513 includes selectors 514 to 521 and performs an operation corresponding to the equation (2). The selectors 514 to 521 receive C (i) * 2 from the shifter unit 512, respectively. 0 ~ C (i) * 2 7 Are input, and the bits bi0 to bi7 of b (i) are input from the multiplier dividing unit 11. The selectors 514 to 521 respectively input C (i) * 2 according to the values of the respective bits bi0 to bi7 of the partial multiplier b (i) input thereto. 0 ~ C (i) * 2 7 Select either 0 or 0 and output. That is, when the value of bin (n = 0, 1,..., 7) input is 1, the selectors 514 to 521 have C (i) * 2 n (N = 0, 1,..., 7) is output. If the value of bin is 0, 0 is output.
[0053]
The adder 522 is an adder that performs an operation corresponding to (3), and outputs a value obtained by adding the four values input from the selectors 514 to 517 (hereinafter referred to as a partial product a) to the register Ca 524.
The adder 523 is an adder that performs an operation corresponding to (4), and outputs a value obtained by adding the four values input from the selectors 518 to 521 (hereinafter referred to as a partial product b) to the register Cb525.
[0054]
The register Ca 524 and the register Cb 525 hold the partial product a and the partial product b, respectively, and update the partial product a and the partial product b held by the control unit 16 to newly input values. The output sides of the register Ca 524 and the register Cb 525 are connected to the accumulation unit 14, and the register Ca 524 and the register Cb 525 output the partial products a and b that are held to the accumulation unit 14.
[0055]
A value obtained by adding the partial product a and the partial product b corresponds to the partial product C (i) * b (i).
FIG. 6 shows a detailed configuration of the accumulating unit 14 and the correcting unit 15.
The accumulating unit 14 includes an adder 601 and a register S602.
The register S <b> 602 is a 170-bit register that holds an accumulated value, and updates the held accumulated value to a new accumulated value input from the adder 601 under the control of the control unit 16. Here, the most significant bit of the register S602 is a sign bit representing the sign of the accumulated value.
[0056]
The adder 601 adds the accumulated value held in the register S602, the partial product a and the partial product b held in the register Ca524 and the register Cb525, and the correction value input from the correction unit 15, and outputs the result to the register S602. To do.
The correction unit 15 includes a register E603, an inverter 606, a selector 604, and a selector 605.
[0057]
The register E603 holds a value that is larger and closest to a value that can be the maximum value of the sum of the partial product a and the partial product b.
The inverter 606 outputs the inverted value of 510 * P (hereinafter referred to as ¬510 * P) held in the register E603.
The selector 604 selects one of 0, 510 * P, and ˜510 * P as a correction value according to the control of the control unit 16 and supplies it to the adder 601.
[0058]
The selector 605 supplies 0 or 1 to the adder 601 under the control of the control unit 16.
Here, the control unit 16 causes the selector 604 to select a correction value according to whether the accumulated value held in the register S602 is positive or negative, and causes the selector 605 to select 0 or 1 and supply it to the adder 601.
[0059]
Specifically, if the most significant bit of the register S602 is 0, the control unit 16 causes the selector 604 to select 510 * P and causes the selector 605 to select 1. As a result, when the accumulated value held in the register S602 is positive (the most significant bit is 0), 511 * P is transferred from the register E603 via the inverter 606 and the selector 604, and 1 through the selector 605. Is supplied to the adder 601. Thanks to this, 510 * P is subtracted in the next addition of the adder 601, and overflow in the adder 601 and the register S602 is prevented.
[0060]
When the accumulated value held in the register S602 is negative (the most significant bit is 1), the control unit 16 causes the selector 604 to select 0 and the selector 605 to select 0.
Further, when the iterative process of i = 1 to 20 is completed and the value held in the register S602 is updated to the final accumulated value, the control unit 16 determines whether the most significant bit of the accumulated value is 1 or 0. If it is 1 (indicating negative), the selector 604 selects 510 * P, the selector 605 selects 0, and the adder 601 adds 510 * P to the accumulated value held in the register S602. Make corrections. As a result, the control unit 16 corrects the final accumulated value to be positive. When the most significant bit of the final accumulated value is 0 (indicating positive), the control unit 16 causes the selector 604 to select 0 and the selector 605 to select 0, and the accumulated value is not corrected. Like that.
Second Embodiment
The remainder multiplication apparatus in 2nd Embodiment is demonstrated below using drawing below.
[0061]
When the multiplicand A (160 bits) and the multiplier B (161 bits) are input to the remainder multiplication apparatus in this embodiment, the remainder R (= A * BmodP) by the modulus P (160 bits) of the product A * B or The same value is calculated on the remainder R and the remainder field. Here, the modulus P is P = 2 when α is a value of 54 bits or less. 160 It is a value satisfying −α.
[0062]
The remainder multiplication apparatus of this embodiment is also configured based on (Equation 2) as in the first embodiment. However, s = 8 in the first embodiment, whereas s = 9 in the second embodiment. In addition, since the k / s portion is not divisible by k / s = 161/9 when actually calculated, the k / s portion is replaced with 18 in this embodiment.
[0063]
FIG. 7 is a block diagram showing a schematic configuration of the remainder multiplication apparatus 200 in the second embodiment.
In the figure, the remainder multiplication apparatus 200 includes a multiplier division unit 81, a remainder calculation unit 82, a partial product calculation unit 83, an accumulation unit 84, a correction unit 85, and a control unit 86.
In the remainder multiplication apparatus 200 of the figure, the remainder calculation unit 82 is different from the remainder calculation unit 12 in that it has only one ROM table. In addition, as will be described in detail in FIG. 11, the partial product calculation unit 83 reduces the number of inputs input to the adder inside the partial product calculation unit 13 so that the circuit scale of the adder becomes smaller. It is configured. Further, the digit multiplication value C (i−1) * 2 in the remainder multiplication apparatus 100. 8 Is calculated by the remainder calculation unit 12, but the carry multiplication apparatus 200 carries the carry value C (i−1) * 2. 9 Is calculated not by the remainder calculation unit 82 but by the partial product calculation unit 83.
[0064]
In addition, the multiplier dividing unit 81, the accumulating unit 84, the correcting unit 85, and the control unit 86 are different from those in the first embodiment in that the multiplier B is 161 bits and s is 9 bits. Although the number of output bits and the number of bits in the register are different, the configuration is the same as in the first embodiment except for this point.
The multiplier dividing unit 81 sequentially outputs the partial multipliers b (i) = b [9i-1: 9i-9] (i = 1,..., 17, 18) of 9 bits from the lower side of the multiplier B. .
[0065]
The remainder calculating unit 82 recursively calculates the intermediate number C (i) (i = 1,..., 17, 18). That is, the remainder calculation unit 82 outputs the multiplicand A as the intermediate number C (i) for the first time (i = 1). After the second time (i = 2,..., 17, 18), the carry value C (i−1) * 2 obtained by carrying the 9-bit carry of the previous intermediate number C (i−1). 9 Remainder C (i-1) * 2 by modulo P 9 ModP is calculated as an intermediate number C (i). More specifically, the remainder calculation unit 82 determines that the first time is A and the second time is A * 2. 9 modP, the third time (A * 2 9 modP) * 2 9 modP, the fourth is ((A * 2 9 modP) * 2 9 modP) * 2 9 ModP,... is calculated as an intermediate number C (i). However, the remainder calculation unit 82 does not carry 9-bit carry over the intermediate number C (i−1), and the carry value C (i−1) * 2 calculated by the partial product calculation unit 83. 9 And the remainder C (i-1) * 2 by the modulus P 9 modP is calculated.
[0066]
The remainder calculation unit 82 includes a ROM table 904 so that the remainder is calculated at high speed. ROM table 904 stores carry value C (i-1) * 2. 9 The remainder of the modulus P corresponding to the part excluding the lower 160 bits from the part, that is, the part exceeding 160 bits by carry is stored in advance. The remainder calculation unit 82 carries the carry value C (i−1) * 2. 9 The ROM table 904 is referred to for a portion exceeding 160 bits, and the remainder corresponding to the portion exceeding 160 bits obtained by the ROM and the carry value C (i−1) * 2 9 To calculate the intermediate number C (i).
[0067]
The partial product calculation unit 83 calculates a partial product C (i) * b (i) between the intermediate number C (i) output from the remainder calculation unit 82 and the partial multiplier b (i) output from the multiplier division unit 81. Output. The partial product calculation unit 83 calculates a 9-bit carry value of the intermediate number C (i−1) output from the residue calculation unit 82 and outputs the calculated value to the residue calculation unit 82.
The accumulation unit 84 accumulates the partial product C (i) * b (i) output from the partial product calculation unit 83.
[0068]
The correction unit 85 corrects the accumulated value by adding or subtracting a value that is an integral multiple of P to the accumulated value according to the accumulated result by the accumulating unit 84, and thereby the digit of the accumulated value in the accumulating unit 84. Prevent overflow.
The control unit 86 controls an iterative process of 18 operations of i = 1 to 18 in the multiplier division unit 81, the remainder calculation unit 82, the partial product calculation unit 83, the accumulation unit 84, and the correction unit 85. The control unit 86 calculates the intermediate number by the remainder calculating unit 82 and the partial multiplier by the multiplier dividing unit 81 in the first stage, and calculates the partial product by the partial product calculating unit 83 in the second stage, and the accumulating unit 84. The pipeline control is performed in the third stage of the calculation of the accumulated value by and the correction of the accumulated value by the correction unit 85. When the final accumulated value in the accumulating unit 84 is larger than P after 18 repetitive operations, the control unit 86 inputs the accumulated value to the remainder calculating unit 82 and outputs the accumulated value P To calculate the remainder.
[0069]
FIG. 8 shows a more detailed configuration of the remainder calculation unit 82.
In the figure, the remainder calculation unit 82 includes a selector 901, a register A 906, a selector 902, and a remainder calculation unit 907.
Under the control of the control unit 86, the selector 901 first outputs the multiplicand A input from the outside to the register A 906 as an initial setting (i = 1), and after the initial setting (i = 2,..., 17, 18). This is a selector that outputs the intermediate number C (i) input from the remainder calculation unit 907 to the selector 901.
[0070]
The register A 906 is a 161-bit register, holds a multiplicand A (= C (1)) input from the outside via the selector 901 as an initial setting (i = 1), and after initial setting (i = 2, .., 17) hold the intermediate number C (i) input from the adder 905 via the selector 901. The register A 906 has an output side connected to the partial product calculation unit 83, updates the intermediate number held in accordance with an instruction from the control unit 86 to the newly input intermediate number, and outputs it to the partial product calculation unit 83. To do. The register A906 finally holds the remainder multiplication value R.
[0071]
The selector 902 carries the carry value C (i−1) * 2 input from the partial product calculation unit 83 during the iterative process. 9 Is output to the residue calculation unit 907, and after the iterative processing, the accumulated value input from the accumulation unit 84 is output to the residue calculation unit 907.
The remainder calculation unit 907 includes a ROM table 904 and an adder 905, and a 170-bit carry value C (i−1) * 2 input from the partial product calculation unit 83 via the selector 902. 9 Alternatively, a remainder or congruent value by the modulus P of the 170-bit accumulated value input from the accumulation unit 84 is output. This remainder or congruent value is 161 bits.
[0072]
The remainder calculating unit 907 outputs the lower 160 bits of the 170-bit value input from the selector 902 to the adder 905 and the upper 10 bits (161th to 170th bits) excluding the lower 160 bits in the ROM table 904. And a bus 909 for outputting to the network. These buses 908 and 909 divide the 170-bit value into lower 160 bits (hereinafter referred to as the lower part) and upper 10 bits (hereinafter referred to as the upper part), and add the lower part and the upper part to the adders. 905 and the ROM table 904 are input.
[0073]
FIG. 9 shows the stored contents of the ROM table 904.
In the figure, the ROM table 904 is a value (0000000000000) expressed by 10 bits. 2 ~ (1111111111) 2 Is the input value and each of those values is 2 160 The remainder by the modulus P for the doubled value is stored in association with the output value. The ROM table 904 reads and outputs the remainder corresponding to the upper part input from the bus 909 when the read signal is input from the control unit 86.
[0074]
The adder 905 adds a remainder and a lower part for the upper part output from the ROM table 904 to provide 161 bits of C (i−1) * 2. 9 modP or a congruent value is output.
In this way, the remainder calculation unit 907 obtains a remainder using the ROM table 904 for a part exceeding 160 bits by 9-bit carry, and adds the remainder and the lower 160 bits to carry value C (i -1) Find the remainder or congruent value of * 2.
[0075]
When the internal configuration of the remainder calculation unit 907 is similar to that of the remainder calculation unit 3 in the prior art, the remainder calculation unit 907 must perform the loop processing (steps 6 to 8) as shown in the prior art a plurality of times. It takes time to calculate the remainder. On the other hand, the remainder calculation unit 907 according to the present embodiment calculates the remainder only by performing one reading in the ROM table 904 and one addition in the adder 905, so that the speed is higher than that of the conventional configuration.
[0076]
FIG. 10 shows a more detailed configuration of the multiplier division unit 81.
In the figure, the multiplier division unit 81 includes a selector 801, a register B 802, and a shifter 803.
Under the control of the control unit 86, the selector 801 outputs the multiplier B input from the outside to the register B 802 as the initial setting (i = 1), and after the initial setting (i = 2,..., 17, 18). The value input from the shifter 803 is output to the register B 802.
[0077]
The register B 802 is a 161-bit register that holds a multiplier B input from the outside via the selector 801 as an initial setting, and holds a value input from the shifter 803 via the selector 801 after the initial setting. . In the register B 802, the output side is connected to the shifter 803, and the lower 9 bits are connected to the partial product calculation unit 83. The register B 802 updates the value held by the control of the control unit 16 to a value newly input from the shifter 803 via the selector 801. The value held in the register B 802 is output to the shifter 803 and the lower 9 bits are output to the partial product calculation unit 83.
[0078]
The shifter 803 is a 161-bit shifter that shifts the value input from the register B 802 to the right by 9 bits and outputs the result.
With such a configuration, the remainder calculation unit 82 calculates a partial multiplier b (i) = b [9i−1: 9i-9] (i = 1,..., 17, 18) of 9 bits from the lower order of the multiplier B. The data are sequentially output to the partial product calculation unit 83.
<Partial product calculation method>
Before describing the detailed configuration of the partial product calculation unit 83, two product calculation methods that form the basis of the configuration of the partial product calculation unit 83 will be described.
[0079]
The product of the multiplicand X and the 3-bit multiplier Y (= y2y1y0) is expanded as shown in (Expression 4).
[0080]
[Formula 6]
Figure 0004293665
[0081]
That is, in (Expression 4), the product X * Y is the weight of each digit of the multiplicand X and the multiplier Y (2 2 , 2 1 , 2 0 ) And each digit value (y2, y1, y0) (X * 2) 2 * Y2, X * 2 1 * Y1, X * 2 0 * Y0, hereinafter referred to as bit product).
Specifically, for example, when Y = 101 (formula 4), X * Y = X * 2. 2 * Y2 + X * 2 0 * Y0, and X * Y is calculated by adding two values (hereinafter referred to as bit product). When Y = 110 (Formula 4), X * Y = X * 2 2 * Y2 + X * 2 1 * Y1, and X * Y is calculated by adding two bit products. When Y = 111 (Formula 4), X * Y = X * 2 2 * Y2 + X * 2 1 * Y1 + X * 2 0 * Y0, and X * Y is calculated by adding three bit products.
[0082]
A method of calculating a product by adding a bit product obtained by multiplying the multiplicand by the weight of each digit of the multiplier and the value of each digit is referred to as a general calculation method. The remainder calculation unit 12 in the first embodiment is also configured based on this method.
By the way, 111 = 2 Three -1. Therefore, when Y = 111, the product X * Y is 2 instead of multiplying the multiplicand X by 111. Three It can also be calculated by multiplying by -1. Multiplicand X and 2 Three The product of -1 is expanded as follows:
[0083]
[Expression 7]
Figure 0004293665
[0084]
In other words, in (Equation 5), when Y = 111, the product X * Y is 2 to the multiplicand X. Three This is calculated by subtracting the multiplicand X from the value multiplied by.
When Y ′ = 111000, Y ′ = Y * 2 Three So the product X * Y 'is 2 instead of multiplying the multiplicand X by 111000 6 -2 Three It can also be calculated by multiplying.
[0085]
2 in the multiplier p 2 from the place (p + 1 bit from the bottom) q When the order (q + 1 bit from the lower order) (where p> q) is all 1, the product in that part is 2 in the multiplicand p + 1 2 to the multiplicand from the value obtained by multiplying q It can be calculated by subtracting a value multiplied by (hereinafter also referred to as a subtraction). This method is called a special calculation method.
[0086]
In the adder, the subtracted value s-t between s and t is calculated by replacing the inverted value of s and t (1's complement) with the constant 1. So 2 in the multiplier p 2 from the place (p + 1 bit from the bottom) q If the order (q + 1 bit from the least significant) (where p> q) is all 1, if the product is calculated by a special calculation method for that part, the adder is 2 p + 1 Double and multiplicand 2 q It is only necessary to add a double inverted value (hereinafter also simply referred to as an inverted value) and a constant 1. Moreover, the addition of the constant 1 can be realized by using the carry-in of the lower bits of the adder. That is, when the product is calculated by the special calculation method, the adder only needs to perform two additions and carry-in.
[0087]
On the other hand, when all the bits of the n-bit multiplier are 1, if the product is calculated by the general calculation method, the adder needs to add n bit products.
From the above, when 1 or more of the multipliers are continuously arranged, it is possible to reduce the number of additions in the adder by calculating the product by the special calculation method rather than by the general calculation method. The scale of the vessel can be reduced and the load of the addition amount can be reduced.
The partial product calculation unit 83 is configured to calculate the partial product C (i) * b (i) based on the above two methods.
[0088]
The partial product calculation unit 83 applies the special calculation method to the portion where 1 is continuous in the bit string of the partial multiplier b (i), and applies the general calculation method to the other portions. More specifically, the partial product calculation unit 83 has a case where the 9-bit partial multiplier b (i) is 111111111, a case where the upper 6 bits or the lower 6 bits of the partial multiplier b (i) are 111111, When the upper 3 bits, the middle 3 bits, or the lower 3 bits are 111, the special calculation method is applied to that portion, and the general calculation method is applied otherwise.
[0089]
For example, when the partial multiplier b (i) is 1111111011, the partial product calculation unit 83 applies the special calculation method to the 111111 portion of the upper 6 bits and applies the general calculation method to the 010 portion of the lower 3 bits. Product C (i) * b (i). However, at this time, the upper 6 bits 111111 are values obtained by carrying 3 bits from the lower order (2 Three Therefore, the partial product calculation unit 83 applies 2 to the upper 6 bits when applying the special calculation method. Three Must carry a carry.
[0090]
Specifically, it is expanded as shown in (Expression 6).
[0091]
[Equation 8]
Figure 0004293665
[0092]
As shown in (Expression 6), for the upper 6 bits 111111, the special calculation method is applied and 2 Three Is expanded as shown in equation (1). That is, the partial product calculation unit 83 adds the value obtained by carrying the intermediate number C (i) by 9 bits, the value obtained by carrying the intermediate number C (i) by 3 bits, and the constant 1 to the upper 6 bits 111111. Calculate the product. The lower 3 bits 011 are expanded as shown in the equation (2) by applying the general calculation method. That is, the partial product calculation unit 83 adds the value obtained by raising the intermediate number C (i) by 1 bit and the intermediate number C (i) according to the value of 011 of the lower 3 bits and the portion of 011 of the lower 3 bits. Calculate the product at.
[0093]
FIG. 11 shows a more detailed configuration of the partial product calculation unit 83.
In the figure, the partial product calculation unit 83 includes a shifter unit 51, a selection unit 52, an OR circuit 513, an adder A701, an adder B702, a register Ca844, and a register Cb845.
The shifter unit 51 includes a bus 830 and shifters 831 to 839. The bus 830 outputs the input 161-bit intermediate number C (i) to the selection unit 52 as it is. The shifters 831 to 839 shift the input intermediate number C (i) to the left by 1 to 9 bits to carry the intermediate number C (i) by 1 to 9 bits to obtain C (i) * 2, C (I) * 2 2 , C (i) * 2 Three , C (i) * 2 Four , C (i) * 2 Five , C (i) * 2 6 , C (i) * 2 7 , C (i) * 2 8 , C (i) * 2 9 Is generated and output to the selection unit 52. The shifter 839 shifts the intermediate number C (i) by 9 bits to the left and outputs it to the selection unit 52, and at the same time, carries the value into the carry value C (i-1) * 2. 9 To the remainder calculation unit 82.
[0094]
In the shifter unit 51, the outputs of the bus 830 and the shifters 831 to 838, that is, C (i), C (i) * 2 1 C,. . . , C (i) * 2 8 Is a value that is a candidate for the bit product in the calculation by the general calculation method. Outputs of the shifters 833, 836, 839, that is, C (i) * 2 Three , C (i-1) * 2 6 , C (i-1) * 2 9 Is a value that is a candidate for the divisor in the calculation by the special calculation method. The output of the bus 830 and shifters 833 and 836, that is, C (i), C (i) * 2 Three , C (i-1) * 2 6 Is a value that is a candidate for reduction in the calculation by the special calculation method. Hereinafter, these candidate values will be referred to as candidate values.
[0095]
When the value obtained by carrying 0 to 9 bits from the shifter unit 51 and the partial multiplier b (i) from the multiplier dividing unit 81 are input to the selection unit 52, the 9-bit partial multiplier b (i) is 111111111. It is determined whether there is 111, whether the upper 6 bits or the lower 6 bits of the partial multiplier b (i) is 111111, and whether the upper 3 bits, the middle 3 bits, or the lower 3 bits are 111. Next, the selection unit 52 selects some of the candidate values input from the shifter unit 51 according to the determination. More specifically, the selection unit 52 selects a subtracted number and a reduced number corresponding to the part from the candidate values for the part that has been positively determined. For the part determined negatively, the selection unit 52 selects a bit product corresponding to the part from the candidate values. The selection unit 52 outputs the attenuator and the bit product of the selected candidate values as they are to the adder A701 or the adder B702. The selection unit 52 generates an inverted value obtained by inverting the value of the selected candidate value and a constant 1, and outputs the generated value to the adder A701 or the adder B702.
[0096]
The selection unit 52 includes operation value selectors 840, 841, and 842.
FIG. 12 shows a detailed configuration of the calculation value selectors 840, 841, and 842.
The calculation value selector 840 includes an inverter 1301, selectors 1302 and 1303, and a control circuit 1304. The calculation value selector 840 includes input terminals S, Z, I0, I1, I2, I3, and output terminals F, O0, O1.
[0097]
When the candidate value C (i) is input as a reduction number from the input terminal I0, the inverter 1301 outputs an inverted value obtained by inverting the reduction number to the selector 1303.
The selector 1303 receives an inverted value of the candidate value C (i) from the inverter 1301 via the input terminal ¬I0, 0 from the input terminal Z, candidate value C (i) from the input terminal I0, and candidate value from the input terminal I1. C (i) * 2 1 Is selected, one of these input terminals is selected according to the input / output logic of the control circuit 1304, and the value input from the selected input terminal is output from the output terminal O0.
[0098]
The selector 1302 is 0 from the input terminal Z, and the candidate value C (i) * 2 from the input terminal I1. 1 Is a candidate value C (i) * 2 from the input terminal I2. 2 Is a candidate value C (i) * 2 from the input terminal I3. Three Is input, one of these input terminals is selected according to the input / output logic of the control circuit 1304, and the value input from the selected input terminal is output from the output terminal O1.
[0099]
When the partial multiplier b (i) is input from the input terminal S, the control circuit 1304 causes the selectors 1302 and 1303 to select one of the input terminals based on the input / output logic shown in FIG. Values input from the input terminals are output from the output terminals O1 and O0. The control circuit 1304 outputs 1 from the output terminal F when the selector 1303 selects the input terminal ¬I0. At other times, the control circuit 1304 outputs 0 from the output terminal F.
[0100]
FIG. 13C shows the partial multiplier b (i) input to the control circuit 1304 and the input / output logic.
The first column of FIG. 10C shows the partial multiplier b (i) input from the input terminal S. “−” Represents an arbitrary value of 1 or 0, and “####” represents an arbitrary value other than “111”. The second column shows input terminals to be selected by the selector 1302. The third column shows input terminals to be selected by the selector 1303. The fourth column is a value output from the output terminal F by the control circuit 1304 and indicates a constant of 1 when 1.
[0101]
For example, if the control circuit 1304 determines that all the lower 6 bits of the partial multiplier b (i) are 1, the control circuit 1304 outputs 0 from the output terminal O1 and the inverted value of C (i) from the output terminal O0. The constant 1 is output from the output terminal F. When it is determined that all the lower 6 bits are not 1 and all the lower 3 bits are 1, the control circuit 1304 receives C (i) * 2 from the output terminal O1. Three , C (i) is output from the output terminal O 0, and the constant 1 is selected from the output terminal F. In other cases, the control circuit 1304 uses C (i) * 2 from the output terminals O1 and O0 according to the value of the lower 3 bits of the partial multiplier b (i). 2 , C (i) * 2 1 , C (i), and any two values of 0 are output.
[0102]
The calculation value selector 841 includes an inverter 1301, selectors 1302 and 1303, and a control circuit 1305. The calculation value selector 841 includes input terminals S, Z, I0, I1, I2, I3, and output terminals F, O0, O1. The calculation value selector 841 is different from the calculation value selector 840 in that a control circuit 1305 is provided instead of the control circuit 1304. When the partial multiplier b (i) is input from the input terminal S, the control circuit 1305 causes the selectors 1302 and 1303 to select one of the input terminals based on the input / output logic shown in FIG. Values input from the input terminals are output from the output terminals O1 and O0. Since other components are the same as those of the calculation value selector 840, description thereof is omitted.
[0103]
The calculation value selector 842 includes an inverter 1301, selectors 1302 and 1303, and a control circuit 1306. The calculation value selector 842 includes input terminals S, Z, I0, I1, I2, I3, and output terminals F, O0, O1. The calculation value selector 842 is different from the calculation value selector 840 in that a control circuit 1306 is provided instead of the control circuit 1304. When the partial multiplier b (i) is input from the input terminal S, the control circuit 1306 causes the selectors 1302 and 1303 to select one of the input terminals based on the input / output logic shown in FIG. Values input from the input terminals are output from the output terminals O1 and O0. Since other components are the same as those of the calculation value selector 840, description thereof is omitted.
[0104]
The OR circuit 513 calculates the logical sum of the output values of the output terminals F of the operation value selectors 840 and 841. As can be seen from FIGS. 13B and 13C, in the operation value selectors 840 and 841, when one output of the output terminal F is a constant 1, the other output is always 0. Therefore, the OR circuit 513 combines the two values into one by taking the logical sum, thereby reducing the number of outputs of the selector 52.
[0105]
Adder A701 adds the output values of output terminals O1, O0, and F of operation value selector 842 and the output value of output terminal O1 of operation value selector 841, and outputs the resulting partial product c to register Ca844. To do.
Adder B 702 adds the output value of output terminal O 0 of operation value selector 841, the output value of output terminals O 1 and O 0 of operation value selector 840, and the output value of OR circuit 513. Then, the resulting partial product d is output to the register Ca845.
[0106]
Here, a value obtained by adding the partial product c and the partial product d is the partial product C (i) * b (i).
The register Ca844 register Cb845 holds the partial product c and the partial product d, respectively, and updates the partial product c and the partial product d held under the control of the control unit 86 to newly input values. The output side of the register Ca844 register Cb845 is connected to the accumulation unit 84, and the register Ca844 register Cb845 outputs the partial product c and the partial product d that are held to the accumulation unit 84.
[0107]
FIG. 14 shows a more detailed configuration of the accumulation unit 84 and the correction unit 85.
In the figure, the accumulating unit 84 includes an adder 705 and a register S707.
The register S707 is a 171-bit register that holds the accumulated value, and updates the held accumulated value to a new accumulated value input from the selector 706 under the control of the control unit 86. Here, the most significant bit of the register S707 is a sign bit representing the sign of the accumulated value.
[0108]
The adder 705 adds the accumulated value held in the register S707, the partial product c and the partial product d held in the register Ca844 and the register Cb845, and the correction value input from the correction unit 85, and outputs the result to the register S707. To do.
The correction unit 85 includes a register E 703, an inverter 708, a selector 704, and a selector 706.
[0109]
The register E703 holds a value that is greater than and closest to a value that can be the maximum value of the sum of the partial product c and the partial product d. Specifically, the register E703 holds 122 * P.
The inverter 708 outputs the inverted value of 1022 * P held in the register E703 (hereinafter referred to as ˜1022 * P).
[0110]
The selector 704 selects one of 0, 1022 * P, and ˜1022 * P as a correction value according to the control of the control unit 86 and supplies it to the selector 706. The selector 706 supplies 0 or 1 to the selector 706 under the control of the control unit 86. Here, the control unit 86 causes the selector 704 to select a correction value in accordance with the sign of the accumulated value held in the register S707, and causes the selector 706 to select 0 or 1 and supply it to the adder 705.
[0111]
Specifically, if the most significant bit of the register S707 is 0, the control unit 86 causes the selector 704 to select 1022 * P and causes the selector 706 to select 1. As a result, when the accumulated value held in the register S707 is positive (the most significant bit is 0), -1022 * P from the register E703 via the inverter 708 and the selector 704 and 1 through the selector 706 are set. Is supplied to the adder 705. Thanks to this, in the next addition of the adder 705, 1022 * P is subtracted, and overflow in the adder 705 and the register S707 is prevented.
[0112]
When the accumulated value held in the register S707 is negative (the most significant bit is 1), the control unit 86 causes the selector 704 to select 0 and the selector 706 to select 0.
In addition, when the iterative process of i = 1 to 18 ends and the value held in the register S707 is updated to the final accumulated value, the control unit 86 determines whether the most significant bit of the accumulated value is 1 or 0. If it is 1 (indicating negative), the selector 704 selects 1022 * P, the selector 706 selects 0, and the adder 705 adds 1022 * P to the accumulated value held in the register S707. Make corrections. As a result, the control unit 86 corrects the final accumulated value to be positive. When the most significant bit of the final accumulated value is 0 (indicating positive), the control unit 86 causes the selector 704 to select 0 and the selector 706 to select 0 to correct the accumulated value. Do not.
[0113]
The partial product calculation unit 83 may be configured as shown in FIG.
11 differs from FIG. 11 in that shifters 847 and 846 are provided, and calculation value selectors 850, 851, and 852 are provided instead of calculation value selectors 840, 841, and 842.
Shifter 847 shifts partial multiplier b (i) to the right by 3 bits and outputs the result.
[0114]
Shifter 846 shifts partial multiplier b (i) to the left by 3 bits and outputs the result.
FIG. 16 shows the input / output logic of the control circuit common to the operation value selectors 850, 851, and 852. As described above, the partial product calculation unit 83 shown in FIG. 16 includes the shifter 847 and the shifter 846, so that the partial multiplier b (i) shifted by 3 bits to the right, the partial multiplier b (i) itself, and the left The partial multiplier b (i) shifted by 3 bits is input to the selector 52. By doing so, the operation value selectors 850, 851, and 852 can apply the same input / output logic. Further, since the same input / output logic can be applied to all the operation value selectors 850, 851, and 852, one control circuit may be provided.
[0115]
In the first embodiment, the remainder calculation unit 12 has two ROM tables. In the second embodiment, the remainder calculation unit 82 has one ROM table. However, the remainder calculation unit 82 may have three or more ROM tables. .
<Development of expression>
The deformation process from (Equation 1) to (Equation 2) in the first embodiment will be described below.
[0116]
[Equation 9]
Figure 0004293665
[0117]
【The invention's effect】
The remainder multiplication apparatus according to the present invention calculates, for the product of the multiplicand a and the multiplier b (b is data of kb bits), a value congruent with the remainder by the modulus p (p is k-bit data) and an accumulated value of the following equation: A remainder multiplication device that calculates as
Accumulated value = ΣC (i) * b [s * i + s-1: s * i]
(Here, Σ represents an accumulation from i = 0 to [[kb / s]]. [[Kb / s]] is an integer part of the quotient kb / s, and i ranges from 0 to [[k / s]. ]], And C (i) is expressed by a recurrence formula. When i = 0, C (i) = a, and when i> = 1, C (i) ≡ (C (i-1) * 2 s ) mod p (≡ indicates that the values on both sides are congruent in modulus p))
b [s * i + s-1: s * i] is 2 out of the k-bit multiplier b s * i + s-1 2 from the place of s * i S-bit partial multipliers up to k Table means for preliminarily storing the remainder by the modulus p for the multiplication and the first time (i = 0), the multiplicand a is output as an intermediate number C (0), and the second and subsequent times (i> 0), the intermediate number output last time C (i-1) is carried by s bits, the remainder for the upper m bits excluding the lower k bits of the intermediate number after the carry is read from the table means, and the read remainder and the lower k bits are added. Intermediate number calculation means for calculating a new intermediate number (i), and each calculated intermediate number C (i) and the corresponding partial multiplier b [s * i + s-1: s * i ] And the partial product C (i) * b [s * i + s-1: s * i] are sequentially accumulated to calculate the accumulated value.
[0118]
According to this configuration, the table means has each value represented by m bits, that is, 0 to 2 m For each value corresponding to -1, 2 of those values K The remainder by the modulus p for the multiplication is stored in advance. When i> = 1, the intermediate number calculation means first calculates the remainder for the upper m bits excluding the lower k bits of the intermediate number after carry, that is, the upper m bits of 2 k The remainder from the modulus p for the double is read from the table means. Next, the intermediate number calculation means calculates the remainder or congruent value by the modulus p of the intermediate number after the carry by adding the remainder read from the table means and the lower k bits.
[0119]
Here, the lower-order k bits of the intermediate number after the carry are the value of the remainder itself by the modulus p or the congruent value with the remainder by the modulus p. This congruent value is larger than the remainder and closer to the remainder. Therefore, in order to obtain a remainder or congruent value by the modulus p for the intermediate number after the carry, and a value closer to the remainder, the intermediate number calculation means obtains the remainder for the upper m bits, and obtains this and the lower k bits. Add them together. The intermediate number calculation means calculates the remainder or congruent value of the intermediate number after the carry by the modulus p by reading the remainder of the upper m bits from the table means.
[0120]
If the remainder of the intermediate number after carry is calculated by using the same procedure as the remainder calculation procedure in the remainder calculation section 3 of the remainder multiplication apparatus 1 of the prior art, the intermediate number calculation section The loop process of 6-8 must be repeated several times. More specifically, the number of loop processes corresponds to the intermediate number of bits after the carry. On the other hand, the intermediate number calculation unit according to the present invention can calculate a remainder or a congruent value of the intermediate number after carry by a single reading and a single addition of the table part, and a high-speed remainder. Arithmetic can be realized.
[0121]
Further, the intermediate number calculation means calculates the remainder of the value obtained by incrementally raising the previous intermediate number as an intermediate number, thereby preventing the intermediate number calculation means from increasing the number of bits of the intermediate number to be calculated. Yes. This prevention prevents an increase in the number of bits of the partial product calculated using the intermediate number. As a result, in the accumulation of partial products, addition may be performed using partial products with a reduced number of bits, so that the circuit scale of the adder can be reduced.
[0122]
The intermediate number calculating means includes a first holding means for holding the intermediate number and an intermediate number held in the first holding means corresponding to the partial multiplier b [s * i + s−1: s * i]. And a carry means for carrying s bits, and an intermediate number after the carry, the upper data which is the upper m bits of the lower k bits and the lower k which is the lower k bits of the intermediate number after the carry A dividing unit that divides the data into data, a reading unit that reads the remainder of the higher-order data by the dividing unit by the method p from the previous table unit, a remainder read from the table unit, and the lower data by the dividing unit Adding means for obtaining a new intermediate number, and the first holding means updates the held content to a new intermediate number each time a new intermediate number is obtained by the adding means, and the multiplicand is changed to the intermediate number at the first time. Output as the second time Descending in is configured to output a new intermediate number of updated.
[0123]
According to this configuration, each component in the intermediate number calculation means can be easily configured using a general-purpose hardware element. That is, the first holding means uses a register, the carry means uses a shifter, the dividing means uses an m-bit bus and a k-bit bus connected to the upper m-bit part and the lower k-bit part of the shifter, and the adding means uses an adder. With these components, the intermediate number calculation means calculates the intermediate number C (i) incrementally.
[0124]
The remainder multiplication device further includes post-processing means for obtaining a remainder by the modulus p of the accumulated value by using the dividing means, the reading means, and the adding means.
According to this configuration, the post-processing means obtains the remainder by the modulus p of the last accumulated value, so that the last accumulated value can be made smaller than p.
[0125]
The table means receives an address corresponding to each value represented by m bits, and stores the m-bit value 2 corresponding to the address in the storage area indicated by the address. k It has a memory element for preliminarily storing a remainder by the modulus p for the multiplication.
According to this configuration, the table means can be realized by one memory element. The memory element has each value represented by m bits, that is, a decimal number from 0 to 2. m 2 for each value corresponding to -1. k The remainder by the modulo p is stored in advance. The address indicating the storage area of the remainder is the same value as each value. When the upper m bits are input from the reading means, the memory element reads the remainder of the storage area indicated by the address as the address by the reading means. As a result, the intermediate number calculation means can obtain the remainder corresponding to the upper m bits in a short time by only performing one reading from the memory element.
[0126]
The m bits are divided into lower m1 bits and upper m2 bits (m = m1 + m2), and each value represented by the m bits is a value represented by the m1 bit and a value represented by the m2 bit. The table means, for each value represented by m1 bits, 2 k A first partial table means for preliminarily storing a remainder by a modulus p for a multiplication factor, and for each value represented by m2 bits, 2 of the value k + m1 Second partial table means for preliminarily storing a remainder obtained by modulus p with respect to multiplication, wherein the adding means adds the respective remainders read from the first and second partial tables and the lower order data To obtain a new intermediate number.
[0127]
According to this configuration, the table means includes the first partial table means corresponding to the upper m1 bits of the m bits and the second partial table means corresponding to the lower m2 bits. The first partial table means sets the remainder corresponding to the upper m1 bit to 2 m1 The second partial table means stores the remainder corresponding to the lower-order m2 bits as 2 m2 Remember me. As can be seen from this number, the combined number of the remainders of the first and second partial table means is further reduced as compared with the case of one memory element. Thus, the table means can be constituted by two memory elements having a small storage capacity.
[0128]
The m bits are divided into t (3 ≦ t ≦ m) partial bits m1,..., Mt from the lower side, and each value represented by the m bits is each mi (i is an integer from 1 to t). ) Corresponding to a combination of values (t) expressed by bits, the table means for each value expressed by partial bits mi bits, k + x T partial table means Ti for preliminarily storing a remainder by modulus p for a multiple (here, x = m1 +... + M (i-1)), and the adding means includes t partial table means Ti A new intermediate number is obtained by adding the read t remainders and the lower order data.
[0129]
Thus, the table means has t partial table means Ti corresponding to each value of t partial bits obtained by dividing m bits. Thus, the table means has a plurality of partial table means Ti, thereby reducing the number of stored surpluses in each partial table means Ti.
The remainder multiplication device further includes an accumulation unit and a correction unit, and the accumulation unit includes a third register that holds 0 as an initial value, a partial product C (i) * b [s * i + s− 1: s * i] and the accumulated value held in the third register are added, and an adder that outputs and holds the addition result as a new accumulated value in the third register is provided. , Correction value holding means for holding a correction value having an integer multiple of p, and a correction value held in the correction value holding means if the accumulated value held in the third register is equal to or greater than a predetermined value And a correction control means for causing the adder to subtract.
[0130]
According to this configuration, the correction control means causes the adder to subtract the correction value from the accumulated value if the accumulated value is equal to or greater than a predetermined value, thereby preventing overflow in the third register.
The third register has a sign bit, and the correction control means corrects the correction simultaneously with the addition of the accumulated value and the partial product to the adder if the accumulated value of the third register is positive. The correction value is an integer multiple of p, and its absolute value is the maximum value (t + 1) (2 s -1) The value is less than or equal to p.
[0131]
According to this configuration, the correction control means causes the adder to subtract the correction value from the accumulated value when the sign bit of the accumulated value held in the third register is 1 (the accumulated value indicates positive). Therefore, overflow in the third register is prevented. Since the correction value is an integer multiple of p and is equal to or less than the maximum value (t + 1) (2s-1) p of the partial product, is the final value of the accumulated value smaller than p? Or a value close to p.
[0132]
The method p is p = 2. k Each partial table means Ti stores the remainder as k3 bit data, where k3 is t * 2 m * The number of bits of α, wherein α is a constant determined such that k3 is smaller than k.
According to this configuration, p = 2 k -Α is satisfied, and α is a constant whose upper limit is set so that k3 becomes smaller than k. As a result, the remainder stored in the partial table means Ti can be limited to k3 bits, and the number of output bits from the partial table can be reduced. Since the number of surplus bits output from the partial table means Ti is k3 bits or less, the bit width of the adder can be limited accordingly.
[0133]
Each partial table means Ti is represented by 0 to (2 mi 2 for values up to -1) mi J (j is 0 to 2) mi The second entry is j * 2 m1 + ... + m (i-1) * α is stored.
In this configuration, the partial table means Ti sets the number of entries to be stored to 2 mi −1, and the scale of the partial table can be reduced.
[0134]
Also, if α is u bits, j * 2 which is the jth entry m1 + ... + m (i-1) * The number of bits of α can be limited to a value obtained by adding m1 + m2 +... + M (i−1) and u bits to the number of bits of j at the maximum. The adding means for adding the remainder output from the partial table means Ti can limit the bit width.
[0135]
A remainder multiplication apparatus according to the present invention is a remainder multiplication apparatus that calculates a number congruent with a remainder by a modulus p (p is k-bit data) for a product of a multiplicand and a multiplier, and the multiplier is s (s is an integer of 2 or more) ) Output means for outputting partial multipliers of s bits obtained by dividing each bit in order from the lower side, and the multiplicand is carried according to the position of each partial multiplier, and the modulus p is applied to the multiplicand after the carry. A first calculation means for calculating a number congruent with the remainder by the above (hereinafter referred to as an intermediate number), a partial multiplier output by the output means, and the intermediate number calculated by the first calculation means corresponding to the partial multiplier A second calculating means for calculating the product of the two as a partial product, an accumulating means for accumulating the partial product calculated by the second calculating means, and an integral multiple of p to the accumulated value accumulated by the accumulating means By adding or subtracting the value, the accumulated value does not exceed the specified number of bits. Until all partial multipliers are output by the output means, the intermediate number by the first calculation means, the partial product by the second calculation means, the accumulation by the accumulation means, Control means for repeatedly performing correction by the correction means, wherein the first calculation means is configured to calculate 2 for each value represented by m (m is an integer equal to or greater than s) bits. k The remainder by the modulus p for the multiplication is stored in advance, and the multiplicand is output as an intermediate number in the first iteration among the repetitions by the control means. The table means is read for m bits higher than the lower k bits of the number, and a new intermediate number is calculated by adding the read number and the lower k bits.
[0136]
According to this configuration, in the second and subsequent iterations of the first calculation means by the control means, the upper part excluding the lower k bits of the intermediate number after the carry carried by s bits also corresponds to the m bits from the table means. By reading the remainder and adding the remainder and the lower-order k bits, a remainder or congruent value according to the modulus p of the intermediate number after the carry is calculated as the intermediate number. Thereby, the first calculation means calculates the remainder at high speed.
[0137]
The second calculating means calculates a partial product of the partial multiplier and the intermediate number for each s-bit partial multiplier. Since partial products are calculated for each partial multiplier of multiple digits in this way, partial products need only be calculated for the number of partial multipliers, and the number of iterations in the second calculation means is reduced, and the prior art product calculation unit 2 is Compared to faster.
The control means controls pipeline processing including the first to third stages. In the first stage, the output means outputs a partial multiplier and the first calculation means outputs an intermediate number, and the second stage outputs the intermediate number. 2 The partial product is calculated by the calculating means, and in the third stage, the accumulating means is accumulated and the correcting means is corrected.
[0138]
According to this configuration, the remainder multiplication apparatus performs pipeline processing, so that the processing in each component is efficiently performed, and the processing speed of the operation is further increased.
The output means holds the multiplier first, and outputs the lower s bits of the held value as a partial multiplier, and shifts the value held in the multiplier holding means to the lower side of the s bits. Shift means for outputting and holding the shifted value to the multiplier holding means.
[0139]
According to this configuration, the output unit can be easily configured by the register that holds the multiplier and the shifter that shifts the held multiplier to the lower side of s bits.
The second generation means is a first shift means for shifting the intermediate number calculated by the first calculation means by i-bit left shift. The i-th shift means (i is an integer from 1 to (s-1)). To (s-1) th shift means, wherein the first generation means carries the intermediate number calculated by the first calculation means by s-bit left shift, and the intermediate number Complement generating means for generating a 1's complement, and constant output means for outputting a constant 1, wherein the second adding means is configured to output the sth shift means when all bits are determined to be 1. When the output, the one's complement generated by the complement generation means, and the constant 1 are selected and it is not determined that all bits are 1, the partial multiplier is 2 0 If the place is “1”, the intermediate number is selected and the partial multiplier is 2 i If the place is “1”, there are provided selection means for selecting the carry result of the i-th shift means and an adder for calculating the partial product by adding the selection results of the selection means.
[0140]
According to this configuration, the first to (s−1) th shift means are realized by a shifter that performs 1 to (s−1) bit left shift. The s-th shift means is realized by a shifter that performs s-bit left shift. The complement generation means is realized by an inverter. As described above, the first generation unit and the second generation unit can be configured by general-purpose hardware elements. These components generate in advance candidate values to be added by the adding means. The selecting means selects a value to be added to the adding means from the candidate values according to the value of the partial multiplier. The adding means calculates a partial product by adding the values of the selected candidates. With such a configuration, the second calculating means can calculate a partial product of a multi-digit intermediate number and a partial multiplier at high speed.
[Brief description of the drawings]
FIG. 1 is a block diagram illustrating a schematic configuration of a remainder multiplication apparatus 100 according to a first embodiment.
FIG. 2 shows a more detailed configuration diagram of the remainder calculation unit 12;
FIG. 3A shows the storage contents of a ROM table 309;
(B) The stored contents of the ROM table 308 are shown.
FIG. 4 shows a more detailed configuration of the multiplier dividing unit 11;
FIG. 5 shows a more detailed configuration of the partial product calculation unit 13;
6 shows a detailed configuration of an accumulation unit 14 and a correction unit 15. FIG.
FIG. 7 is a block diagram showing a schematic configuration of a remainder multiplication apparatus 200 in the second embodiment.
FIG. 8 shows a more detailed configuration of the remainder calculation unit 82.
FIG. 9 shows the storage contents of a ROM table 904;
10 shows a more detailed configuration of the multiplier division unit 81. FIG.
11 shows a more detailed configuration of the partial product calculation unit 83. FIG.
12 shows a detailed configuration of the calculation value selectors 840, 841, and 842. FIG.
13A shows the correspondence between the partial multiplier b (i) input to the control circuit 1306 and the input / output logic of the control circuit 1306. FIG.
(B) shows the correspondence between the partial multiplier b (i) input to the control circuit 1305 and the input / output logic of the control circuit 1305.
(C) shows the correspondence between the partial multiplier b (i) input to the control circuit 1304 and the input / output logic of the control circuit 1304.
14 shows a more detailed configuration of the accumulating unit 84 and the correcting unit 85. FIG.
15 may be configured as shown in FIG.
FIG. 16 shows the input / output logic of a control circuit common to the operation value selectors 850, 851, and 852;
FIG. 17 shows a configuration of a conventional modular multiplication apparatus.
[Explanation of symbols]
100 Remainder multiplier
11 multiplier divider
12 Remainder calculation part
13 Partial product calculator
14 Accumulation part
15 Correction unit
16 Control unit
308 ROM table
309 ROM table
301 selector
302 Register A
303 Shifter
304 selector
310 Adder
311 Remainder calculation part

Claims (31)

被乗数aと乗数b(bはkbビットのデータ)との積に対して、法p(pはkビットデータ)による剰余と合同な値を次式の累算値として算出する剰余乗算装置であって、
Figure 0004293665
ここで[[kb/s]]は商kb/sの整数部分であり、
iは0から[[k/s]]までの整数であり、
C(i)は漸化式で表わされi=0のときC(i)=a、i>=1のときC(i)≡(C(i-1)*2s) modpであり(≡は両辺の値が法pにおいて合同であることを示す)、
b[s*i+s-1:s*i]は、kビットの乗数bのうち2s*i+s-1の位から2s*iの位までのsビットの部分乗数であり、
前記剰余乗算装置は、
m(mはs以上の整数)ビットにより表現される各値について、その値の2k倍に対する法pによる剰余を予め記憶するテーブル手段と、
初回(i=0)では被乗数aを中間数C(0)として出力し、
2回目以降(i>0)では、前回出力された中間数C(i-1)をsビット桁上げし、桁上げ後の中間数の下位kビットを除く上位のmビットについての前記剰余をテーブル手段から読み出し、読み出した剰余と下位kビットとを加算することにより新たな中間数(i)を算出する中間数算出手段と
を備え、
算出された各中間数C(i)と、それに対応する部分乗数b[s*i+s-1:s*i]との部分積C(i)*b[s*i+s-1:s*i]を順次累算することによって前記累算値を算出すること
を特徴とする剰余乗算装置。
This is a remainder multiplication device that calculates a congruent value as a cumulative value of the following equation for a product of a multiplicand a and a multiplier b (b is kb bit data) and a modulus p (p is k bit data). And
Figure 0004293665
Where [[kb / s]] is the integer part of the quotient kb / s,
i is an integer from 0 to [[k / s]]
C (i) is expressed by a recurrence formula. When i = 0, C (i) = a, and when i> = 1, C (i) ≡ (C (i-1) * 2 s ) modp ( ≡ indicates that the values on both sides are congruent in the modulus p),
b [s * i + s-1: s * i] is a partial multiplier of s bits from the 2 s * i + s-1 to the 2 s * i of the k-bit multiplier b,
The remainder multiplication device includes:
table means for storing in advance, for each value represented by m (m is an integer greater than or equal to s) bits, a modulus p with respect to 2 k times that value;
At the first time (i = 0), multiplicand a is output as intermediate number C (0),
From the second time on (i> 0), the intermediate number C (i-1) output last time is carried out by s bits, and the remainder for the upper m bits excluding the lower k bits of the intermediate number after the carry. An intermediate number calculating means for calculating a new intermediate number (i) by reading from the table means and adding the read remainder and the lower k bits;
Partial product C (i) * b [s * i + s-1: between each calculated intermediate number C (i) and the corresponding partial multiplier b [s * i + s-1: s * i] s * i] is sequentially accumulated to calculate the accumulated value.
前記中間数算出手段は、
中間数を保持する第1保持手段と、
部分乗数b[s*i+s-1:s*i]に対応して、第1保持手段に保持された中間数をsビット桁上げする桁上げ手段と、
桁上げ後の中間数を、桁上げ後の中間数における下位kビットよりも上位のmビットの部分である上位データと下位kビットの部分である下位データとに分割する分割手段と、
分割手段による上位データに対する法pによる剰余を前テーブル手段から読み出す読み出し手段と、
テーブル手段から読み出された剰余と、分割手段による下位データとを加算することにより新たな中間数を得る加算手段と
を備え、
前記第1保持手段は、加算手段において新たな中間数が得られる度にその保持内容を新たな中間数に更新し、前記初回では被乗数を中間数として出力し、前記2回目以降では更新後の新たな中間数を出力すること
を特徴とする請求項1記載の剰余乗算装置。
The intermediate number calculating means includes
First holding means for holding an intermediate number;
Carrying means for carrying the intermediate number held in the first holding means by s bits corresponding to the partial multiplier b [s * i + s-1: s * i];
A dividing unit that divides the intermediate number after the carry into upper data that is a portion of m bits higher than the lower k bits in the intermediate number after the carry and lower data that is a portion of the lower k bits;
A reading means for reading out the remainder by the modulus p for the upper data by the dividing means from the previous table means;
Adding means for obtaining a new intermediate number by adding the remainder read from the table means and the lower data by the dividing means;
The first holding means updates the held content to a new intermediate number every time a new intermediate number is obtained in the adding means, outputs the multiplicand as the intermediate number in the first time, and after the second time after the update 2. The remainder multiplication apparatus according to claim 1, wherein a new intermediate number is output.
前記剰余乗算装置は、さらに、
前記分割手段、読み出し手段、加算手段を利用することにより、前記累算値の法pによる剰余を求める後処理手段
を備えることを特徴とする請求項2記載の剰余乗算装置。
The remainder multiplication device further includes:
3. The remainder multiplication apparatus according to claim 2, further comprising post-processing means for obtaining a remainder of the accumulated value by a modulus p by using the dividing means, the reading means, and the adding means.
前記テーブル手段は、
mビットにより表現される各値に対応するアドレスが入力され、そのアドレスが指す記憶領域に当該アドレスに対応するmビットの値の2k倍に対する法pによる剰余を予め記憶するメモリ素子を有すること
を特徴とする請求項2及び3記載の剰余乗算装置。
The table means includes
An address corresponding to each value represented by m bits is input, and a memory element that stores in advance a remainder obtained by modulus p with respect to 2 k times the m-bit value corresponding to the address is stored in the storage area indicated by the address. The modular multiplication apparatus according to claim 2 or 3, wherein
前記mビットは下位m1ビットと上位m2ビット(m=m1+m2)とに分割され、
前記mビットにより表現される各値は、m1ビットにより表現される値とm2ビットにより表現される値との組み合わせに対応し、
前記テーブル手段は、
m1ビットにより表現される各値について、その値の2k倍に対する法pによる剰余を予め記憶する第1部分テーブル手段と、
m2ビットにより表現される各値について、その値の2k+m1倍に対する法pによる剰余を予め記憶する第2部分テーブル手段と
を備え、
前記加算手段は、第1、第2部分テーブルからの読み出されたそれぞれの剰余と、前記下位データとを加算することにより新たなっ中間数を得る
ことを特徴とする請求項2及び3記載の剰余乗算装置。
The m bits are divided into lower m1 bits and upper m2 bits (m = m1 + m2),
Each value represented by the m bits corresponds to a combination of a value represented by the m1 bit and a value represented by the m2 bit,
The table means includes
first partial table means for preliminarily storing, for each value represented by m1 bits, a modulus p for 2 k times that value;
for each value represented by m2 bits, a second partial table means for preliminarily storing a remainder in modulus p for 2 k + m1 times that value;
4. The addition means according to claim 2, wherein a new intermediate number is obtained by adding each of the remainders read from the first and second partial tables and the lower order data. Remainder multiplier.
前記mビットは下位側からt(3≦t≦m)個の部分ビットm1、…、mtに分割され、
前記mビットにより表現される各値は、各mi(iは1からtまで整数)ビットにより表現される値(t個)を組み合わせたものに対応し、
前記テーブル手段は、
部分ビットmiビットにより表現される各値について、その値の2k+x倍(ここでx=m1+…+m(i-1)である)に対する法pによる剰余を予め記憶するt個の部分テーブル手段Tiを備え、
前記加算手段は、t個の部分テーブル手段Tiからの読み出されたt個の剰余と、前記下位データとを加算することにより新たな中間数を得る
ことを特徴とする請求項2及び3記載の剰余乗算装置。
The m bits are divided into t (3 ≦ t ≦ m) partial bits m1, ..., mt from the lower side,
Each value represented by the m bits corresponds to a combination of values (t) represented by each mi (i is an integer from 1 to t) bits,
The table means includes
For each value represented by the partial bits mi bits, t partial tables for storing in advance a remainder by the modulus p for 2 k + x times the value (where x = m1 +... + M (i−1)). Means Ti,
4. The adding means obtains a new intermediate number by adding t remainders read out from t partial table means Ti and the lower order data. Remainder multiplication device.
前記mビットは下位側からt(2≦t≦m)個の部分ビットm1、…、mtに分割され、
前記テーブル手段は、
xが次式で表わされるとき、各部分テーブル手段Tiは、部分ビットmiビットにより表現される各値について、その値の2k+x倍に対する法pによる剰余を予め記憶するt個の部分テーブル手段Ti(iは1からtの整数)を備え、
ここでxは次式によって表わされるものとする
Figure 0004293665
前記加算手段は、t個の部分テーブル手段Tiから読み出されたt個の剰余と前記下位データとを加算することにより新たな中間数を得る
ことを特徴とする請求項2及び3記載の剰余乗算装置。
The m bits are divided into t (2 ≦ t ≦ m) partial bits m1, ..., mt from the lower side,
The table means includes
When x is expressed by the following equation, each partial table means Ti stores, for each value represented by the partial bit mi bit, t partial tables for storing in advance a remainder obtained by modulus p for 2 k + x times that value. Means Ti (i is an integer from 1 to t),
Where x is represented by the following equation:
Figure 0004293665
4. The remainder according to claim 2, wherein the adding means obtains a new intermediate number by adding t remainders read from t partial table means Ti and the lower order data. Multiplier device.
各部分テーブル手段Tiは、前記剰余をkビットのデータとして記憶すること
を特徴とする請求項7記載の剰余乗算装置。
8. The remainder multiplication apparatus according to claim 7, wherein each partial table means Ti stores the remainder as k-bit data.
前記剰余乗算装置は、さらに累算手段と補正手段とを備え、
前記累算手段は、
初期値として0を保持する第3レジスタと、
部分積C(i)*b[s*i+s-1:s*i]と第3レジスタに保持された累算値とを加算し、加算結果を新たな累算値として第3レジスタに出力して保持させる加算器と
を備え、
前記補正手段は、
pの整数倍の値をもつ補正値を保持する補正値保持手段と、
前記第3レジスタに保持された累算値が所定の値以上であれば、補正値保持手段に保持された補正値を、前記加算器に減算させる補正制御手段と
を備えることを特徴とする請求項8記載の剰余乗算装置。
The remainder multiplication device further includes an accumulation unit and a correction unit,
The accumulation means includes
A third register holding 0 as an initial value;
The partial product C (i) * b [s * i + s-1: s * i] is added to the accumulated value held in the third register, and the addition result is added to the third register as a new accumulated value. And an adder for outputting and holding,
The correction means includes
correction value holding means for holding a correction value having a value that is an integer multiple of p;
And a correction control means for causing the adder to subtract the correction value held in the correction value holding means when the accumulated value held in the third register is equal to or greater than a predetermined value. Item 9. A modular multiplication apparatus according to item 8.
前記第3レジスタは符号ビットを有し、
前記補正制御手段は、第3レジスタの累算値が正であれば、前記加算器に対して累算値と部分積との加算と同時に前記補正値を減算させ、
前記補正値は、pの整数倍であってその絶対値が前記部分積の最大値(t+1)(2 s -1)p以下の値であること
を特徴とする請求項9記載の剰余乗算装置。
The third register has a sign bit;
If the accumulated value of the third register is positive, the correction control means causes the adder to subtract the correction value simultaneously with the addition of the accumulated value and the partial product,
The correction value is an integral multiple of p, and its absolute value is the maximum value (t + 1) (2 10. The modular multiplication apparatus according to claim 9, wherein s -1) is a value equal to or less than p.
前記法pはp=2k−αの関係を満たし、
各部分テーブル手段Tiは、前記剰余をk3ビットのデータとして記憶する、
ここで、k3はt*2m*αのビット数であり、
前記αは、k3がkより小さくなるように定められた定数であることを
特徴とする請求項7記載の剰余乗算装置。
The modulus p satisfies the relationship p = 2 k −α,
Each partial table means Ti stores the remainder as k3 bit data.
Where k3 is the number of bits of t * 2 m * α,
8. The modular multiplication apparatus according to claim 7, wherein α is a constant determined so that k3 is smaller than k.
各部分テーブル手段Tiは、miビットにより表現される0から(2mi-1)までの値に対応する2mi個のエントリを有し、
j(jは0から2miまで)番目のエントリは、j*2m1++m(i-1) *αを格納していることを特徴とする請求項11記載の剰余乗算装置。
Each partial table means Ti has 2 mi entries corresponding to values from 0 to (2 mi -1) represented by mi bits,
12. The modular multiplication apparatus according to claim 11, wherein the j-th entry (j is from 0 to 2 mi ) stores j * 2 m1 + ... + m (i−1) * α.
前記剰余乗算装置は、さらに累算手段と補正手段とを備え、
前記累算手段は、
初期値として0を保持する第3レジスタと、
部分積C(i)*b[s*i+s-1:s*i]と第3レジスタに保持された累算値とを加算し、加算結果を新たな累算値として第3レジスタに出力して保持させる加算器と
を備え、
前記補正手段は、
pの整数倍の値をもつ補正値を保持する補正値保持手段と、
前記第3レジスタに保持された累算値が所定の値以上であれば、補正値保持手段に保持された補正値を、前記加算器に減算させる補正制御手段と、
を備えることを特徴とする請求項12記載の剰余乗算装置。
The remainder multiplication device further includes an accumulation unit and a correction unit,
The accumulation means includes
A third register holding 0 as an initial value;
The partial product C (i) * b [s * i + s-1: s * i] is added to the accumulated value held in the third register, and the addition result is added to the third register as a new accumulated value. And an adder for outputting and holding,
The correction means includes
correction value holding means for holding a correction value having a value that is an integer multiple of p;
If the accumulated value held in the third register is equal to or greater than a predetermined value, correction control means for causing the adder to subtract the correction value held in the correction value holding means;
The modular multiplication apparatus according to claim 12, comprising:
前記第3レジスタは符号ビットを有し、
前記補正制御手段は、第3レジスタの累算値が正であれば、前記加算器に対して累算値と部分積との加算と同時に前記補正値を減算させ、
前記補正値は、pの整数倍であって前記部分積の最大値(2s+1-2)p以下の値であること
を特徴とする請求項13記載の剰余乗算装置。
The third register has a sign bit;
If the accumulated value of the third register is positive, the correction control means causes the adder to subtract the correction value simultaneously with the addition of the accumulated value and the partial product,
14. The modular multiplication apparatus according to claim 13, wherein the correction value is an integral multiple of p and is equal to or less than a maximum value (2 s + 1 −2) p of the partial product.
被乗数と乗数との積に対する法p(pはkビットデータ)による剰余と合同な数を算出する剰余乗算装置において、
乗数をs(sは2以上の整数)ビットずつに分けて得られるsビットの部分乗数を下位側から順に出力する出力手段と、
各部分乗数の位に応じて、被乗数を桁上げし、桁上げ後の被乗数に対して、法pによる剰余と合同な数(以下中間数と呼ぶ)を算出する第1算出手段と、
出力手段により出力された部分乗数と、当該部分乗数に対応して第1算出手段により算出された前記中間数との積を部分積として算出する第2算出手段と、
第2算出手段に算出された部分積を累算する累算手段と、
累算手段に累算された累算値にpの整数倍の値を加減算することにより、累算値を所定のビット数を越えないように補正する補正手段と、
出力手段により全ての部分乗数が出力されるまで、第1算出手段による中間数の算出と、第2算出手段による部分積の算出と、累算手段による累算と、補正手段による補正とを繰り返し行わせる制御手段と
を備え、
前記第1算出手段は、m(mはs以上の整数)ビットにより表現される各値について、その値の2k倍に対する法pによる剰余を予め記憶し、
制御手段による繰り返しのうち初回では被乗数を中間数として出力し、2回目以降では、前回出力された中間数をsビット桁上げし、桁上げ後の中間数の下位kビットより上位のmビットについてテーブル手段を読み出し、読み出した数と下位kビットとを加算することにより新たな中間数を算出すること
を特徴とする剰余乗算装置。
In a remainder multiplication device that calculates a number congruent with a remainder by a modulus p (p is k-bit data) for a product of a multiplicand and a multiplier,
Output means for sequentially outputting s-bit partial multipliers obtained by dividing the multiplier into s (s is an integer of 2 or more) bits, in order from the lower order;
First calculating means for carrying the multiplicand according to the position of each partial multiplier and calculating a number congruent to the remainder by the modulus p (hereinafter referred to as an intermediate number) with respect to the multiplicand after the carry;
Second calculation means for calculating as a partial product a product of the partial multiplier output by the output means and the intermediate number calculated by the first calculation means corresponding to the partial multiplier;
Accumulating means for accumulating the partial products calculated by the second calculating means;
Correction means for correcting the accumulated value so as not to exceed a predetermined number of bits by adding or subtracting an integer multiple of p to the accumulated value accumulated by the accumulating means;
Until all the partial multipliers are output by the output means, the calculation of the intermediate number by the first calculation means, the calculation of the partial product by the second calculation means, the accumulation by the accumulation means, and the correction by the correction means are repeated. Control means to perform,
The first calculation means stores in advance, for each value represented by m (m is an integer equal to or greater than s) bits, a modulus p with respect to 2 k times that value,
Of the repetitions by the control means, the multiplicand is output as an intermediate number at the first time, and the second and subsequent times carry out the previous output intermediate number by s bits, and m bits higher than the lower k bits of the intermediate number after the carry. A remainder multiplication device characterized in that a new intermediate number is calculated by reading the table means and adding the read number and the lower k bits.
前記第1算出手段は、
被乗数を保持する第1保持手段と、
出力手段から2回目以降に出力される部分乗数に対応して、第1保持手段に保持された中間数をsビット桁上げする桁上げ手段と、
桁上げ後の中間数を桁上げ後の中間数における下位kビットよりも上位のmビットの部分である上位データと下位kビットの部分である下位データとに分割する分割手段と、
分割手段による上位データに対する法pによる剰余を前記テーブル手段から読み出す読み出し手段と、
テーブル手段から読み出された剰余と、分割手段による下位データとを加算することにより新たな中間数を得る加算手段と、
を備え、
前記第1保持手段は、前記加算手段により新たな中間数が得られる度にその保持内容を新たな中間数に更新し、前記初回では被乗数を中間数として出力し、前記2回目以降では更新後の新たな中間数を出力し、
前記第2算出手段は、第1保持手段の保持内容を中間数として前記部分積を算出すること
を特徴とする請求項15記載の剰余乗算装置。
The first calculation means includes
First holding means for holding a multiplicand;
Carrying means for carrying the intermediate number held in the first holding means by s bits corresponding to the partial multiplier output from the output means for the second time or later,
A dividing unit that divides the intermediate number after the carry into upper data that is a portion of m bits higher than the lower k bits in the intermediate number after the carry and lower data that is a portion of the lower k bits;
A reading means for reading out the remainder by the modulus p for the upper data by the dividing means from the table means;
An adding means for obtaining a new intermediate number by adding the remainder read from the table means and the lower data by the dividing means;
With
The first holding means updates the held contents to a new intermediate number every time a new intermediate number is obtained by the adding means, outputs the multiplicand as the intermediate number in the first time, and after the second time after the update Output a new intermediate number of
16. The modular multiplication apparatus according to claim 15, wherein the second calculation unit calculates the partial product using the content held by the first holding unit as an intermediate number.
前記制御手段は、第1〜第3ステージを含むパイプライン処理を制御する、第1ステージでは出力手段に部分乗数を出力させるとともに第1算出手段に中間数を出力させ、第2ステージでは第2算出手段に部分積を算出させ、第3ステージでは累算手段に累算させるともに補正手段に補正させること
を特徴とする請求項16記載の剰余乗算装置。
The control means controls pipeline processing including the first to third stages. In the first stage, the output means outputs a partial multiplier and the first calculation means outputs an intermediate number, and the second stage outputs a second number. 17. The modular multiplication apparatus according to claim 16, wherein the calculating means causes the partial product to be calculated, and in the third stage, the accumulating means causes the correction means to correct and the correction means to correct.
前記出力手段は、
最初に乗数を保持し、保持している値の下位sビットを部分乗数として出力する乗数保持手段と、
乗数保持手段に保持されている値をsビット下位側にシフトさせ、シフト後の値を乗数保持手段に出力して保持させるシフト手段と
を備えることを特徴とする請求項17記載の剰余乗算装置。
The output means includes
Multiplier holding means for initially holding a multiplier and outputting the lower s bits of the held value as a partial multiplier;
18. The modular multiplication apparatus according to claim 17, further comprising shift means for shifting the value held in the multiplier holding means to the lower side of s bits and outputting and holding the shifted value to the multiplier holding means. .
前記第2算出手段は、
第1保持手段に保持された中間数と乗数保持手段から出力された部分乗数とから前記部分積を算出する乗算手段と、
乗算手段に算出された部分積を保持する第2保持手段と
を備えることを特徴とする請求項18記載の剰余乗算装置。
The second calculation means includes
Multiplication means for calculating the partial product from the intermediate number held in the first holding means and the partial multiplier output from the multiplier holding means;
19. The modular multiplication apparatus according to claim 18, further comprising second holding means for holding the calculated partial product in the multiplication means.
前記累算手段は、
前記累算値を保持する第3保持手段と、
第2保持手段に保持された部分積と、第3保持手段に保持された累算値とを加算する加算器と
を備え、
前記第3保持手段は加算結果を新たな累算値として保持すること
を特徴とする請求項19記載の剰余乗算装置。
The accumulation means includes
Third holding means for holding the accumulated value;
An adder for adding the partial product held in the second holding means and the accumulated value held in the third holding means;
20. The modular multiplication apparatus according to claim 19, wherein the third holding unit holds the addition result as a new accumulated value.
前記補正手段は、
pの整数倍の値をもつ補正値を保持する補正値保持手段と、
前記第3保持手段に保持された累算値の有効ビット数が所定のビット数以上になったとき、補正値保持手段に保持された補正値を、部分積と累算値の加算と同時に前記加算器に加減算させる補正制御手段と
を備えることを特徴とする請求項20記載の剰余乗算装置。
The correction means includes
correction value holding means for holding a correction value having a value that is an integer multiple of p;
When the number of effective bits of the accumulated value held in the third holding means is equal to or greater than a predetermined number of bits, the correction value held in the correction value holding means is simultaneously added to the partial product and the accumulated value. 21. The modular multiplication apparatus according to claim 20, further comprising correction control means for adding and subtracting the adder.
前記制御部は、第1保持手段及び乗数保持手段を第1から第2ステージへのパイプラインラッチとし、第2保持手段を第2から第3ステージへのパイプラインラッチとしてパイプライン処理を制御すること
を特徴とする請求項21記載の剰余乗算装置。
The control unit controls the pipeline processing by using the first holding means and the multiplier holding means as a pipeline latch from the first to the second stage and using the second holding means as the pipeline latch from the second to the third stage. 22. The modular multiplication apparatus according to claim 21, wherein
前記テーブル手段は、
mビットにより表現される各値に対応するアドレスが入力され、そのアドレスが指す記憶領域に当該アドレスに対応するmビットの値の2k倍に対する法pによる剰余を予め記憶するメモリ素子を有すること
を特徴とする請求項17記載の剰余乗算装置。
The table means includes
An address corresponding to each value represented by m bits is input, and a memory element that stores in advance a remainder obtained by modulus p with respect to 2 k times the m-bit value corresponding to the address is stored in the storage area indicated by the address. 18. The modular multiplication apparatus according to claim 17, wherein
前記mビットは下位m1ビットと上位m2ビット(m=m1+m2)とに分割され、
前記mビットにより表現される各値は、m1ビットにより表現される値とm2ビットにより表現される値との組み合わせに対応し、
前記テーブル手段は、
m1ビットにより表現される各値について、その値の2k倍に対する法pによる剰余を予め記憶する第1部分テーブル手段と、
m2ビットにより表現される各値について、その値の2k+m1倍に対する法pによる剰余を予め記憶する第2部分テーブル手段と
を備え、
前記加算手段は、第1、第2部分テーブルからの読み出されたそれぞれの剰余と、前記下位データとを加算すること
を特徴とする請求項17記載の剰余乗算装置。
The m bits are divided into lower m1 bits and upper m2 bits (m = m1 + m2),
Each value represented by the m bits corresponds to a combination of a value represented by the m1 bit and a value represented by the m2 bit,
The table means includes
first partial table means for preliminarily storing, for each value represented by m1 bits, a modulus p for 2 k times that value;
for each value represented by m2 bits, a second partial table means for preliminarily storing a remainder in modulus p for 2 k + m1 times that value;
18. The remainder multiplying apparatus according to claim 17, wherein the adding means adds the remainders read from the first and second partial tables and the lower order data.
前記mビットは下位側からt(3≦t≦m)個の部分ビットm1、…、mtに分割され、
前記mビットにより表現される各値は、各mi(iは1からtまで整数)ビットにより表現される値(t個)を組み合わせたものに対応し、
前記テーブル手段は、
部分ビットmiビットにより表現される各値について、その値の2k+x倍(ここでx=m1+…+m(i-1))に対する法pによる剰余を予め記憶するt個の部分テーブル手段Tiを備え、
前記加算手段は、t個の部分テーブル手段Tiからの読み出されたt個の剰余と、前記下位データとを加算すること
を特徴とする請求項17記載の剰余乗算装置。
The m bits are divided into t (3 ≦ t ≦ m) partial bits m1, ..., mt from the lower side,
Each value represented by the m bits corresponds to a combination of values (t) represented by each mi (i is an integer from 1 to t) bits,
The table means includes
For each value represented by the partial bits mi bits, t partial table means Ti for storing in advance the remainder by the modulus p for 2 k + x times the value (here, x = m1 +... + M (i-1)). With
18. The remainder multiplication apparatus according to claim 17, wherein the adding means adds t remainders read from t partial table means Ti and the lower order data.
前記第2算出手段は、
出力手段から出力されたsビットの部分乗数の全ビットが1であるか否かを判定する判定手段と、
第1算出手段により算出された前記中間数を2のs乗倍した値と、当該被乗数の負の値とを生成する第1生成手段と、
部分乗数の各ビットについて、部分乗数におけるビット重みと前記中間数との積を生成する、この積は中間数をビット重みだけ桁上げした数である第2生成手段と、
全ビットが1であると判定された場合、第1生成手段に生成された各値を加算し、全ビットが1であると判定されなかった場合、第2生成手段に生成された積のうち、部分乗数中の”1”のビットに対応するものを加算する第2加算手段と
を備えることを特徴とする請求項16記載の剰余乗算装置。
The second calculation means includes
Determining means for determining whether or not all bits of the partial multiplier of s bits output from the output means are 1,
First generation means for generating a value obtained by multiplying the intermediate number calculated by the first calculation means by the power of 2 and a negative value of the multiplicand;
For each bit of the partial multiplier, a product of a bit weight in the partial multiplier and the intermediate number is generated, and the product is a second generation means that is a number obtained by raising the intermediate number by the bit weight;
When it is determined that all the bits are 1, each value generated by the first generation unit is added. When all the bits are not determined to be 1, among the products generated by the second generation unit 17. The modular multiplication apparatus according to claim 16, further comprising second addition means for adding a bit corresponding to a bit of “1” in the partial multiplier.
前記第2生成手段は、
第i(iは1から(s−1)の整数)のシフト手段は、第1算出手段により算出された前記中間数をiビット左シフトにより桁上げする第1から第(s−1)のシフト手段
を備え、
前記第1生成手段は、
第1算出手段により算出された前記中間数をsビット左シフトにより桁上げする第sのシフト手段と、
前記中間数の1の補数を生成する補数生成手段と、
定数1を出力する定数出力手段と
を備え、
前記第2加算手段は、
全ビットが1であると判定された場合に、第sのシフト手段の出力と、補数生成手段に生成された1の補数と、定数1を選択し、全ビットが1であると判定されなかった場合に、部分乗数の20の位が”1”であれば前記中間数を選択し、部分乗数の2iの位が”1”であれば、第iのシフト手段の桁上げ結果を選択する選択手段と、
選択手段の選択結果を加算することにより前記部分積を算出する加算器と
を備えることを特徴とする請求項26記載の剰余乗算装置。
The second generation means includes
The i-th (i is an integer from 1 to (s-1)) shift means shifts the intermediate number calculated by the first calculation means by i-bit left shift from the first to (s-1) -th Provided with shifting means,
The first generation means includes
S-th shift means for carrying the intermediate number calculated by the first calculation means by s-bit left shift;
A complement generation means for generating the one's complement of the intermediate number;
Constant output means for outputting constant 1;
The second adding means includes
When it is determined that all bits are 1, the output of the s-th shift means, the 1's complement generated by the complement generation means, and the constant 1 are selected, and it is not determined that all bits are 1. If the, if 2 0 digit of partial multiplier is "1" to select the intermediate speed, if the position of the 2 i of portions multiplier "1", the carry resulting from the shift means of the i A selection means to select;
27. The modular multiplication apparatus according to claim 26, further comprising: an adder that calculates the partial product by adding selection results of the selection means.
前記sは3の倍数(3n)ビットであり、
前記部分乗数は、3ビットずつ区切ったn個の3ビットデータsn,…,s1で表され、
前記第2算出手段は、
第j(jは1からnの整数)の判定手段は、前記3ビットデータsjが"111"であるか否かを判定する第1から第nの判定手段と、
第jの判定手段により"111"であると判定された場合に、前記中間数に”1000”と3ビットデータsjの位23(j-1)とを乗じた値と、被乗数の負の値に3ビットデータsjの位23(j-1)を乗じた値とを生成する第1から第nの特別生成手段と、
第jの判定手段により"111"でないと判定された場合には、3ビットデータsjの各ビットについて、当該ビットの論理値と、sビット部分乗数における各ビットの重みと、前記中間数との積を生成する第1から第nの一般生成手段と、
"111"であると判定されたsjに対応する特別生成手段により生成された値と、"111"でないと判定されたsjに対応する一般生成手段により生成された積とを加算する加算手段と
を備えることを特徴とする請求項16記載の剰余乗算装置。
S is a multiple of 3 (3n) bits;
The partial multiplier is represented by n pieces of 3-bit data sn,.
The second calculation means includes
J-th (j is an integer from 1 to n) determination means; first to n-th determination means for determining whether or not the 3-bit data sj is "111";
When it is determined by the jth determination means that the value is “111”, a value obtained by multiplying the intermediate number by “1000” and the position 2 3 (j−1) of the 3-bit data sj, and a negative multiplicand First to n-th special generation means for generating a value obtained by multiplying the value by the position 2 3 (j-1) of the 3-bit data sj;
When it is determined by the j-th determining means that it is not “111”, for each bit of the 3-bit data sj, the logical value of the bit, the weight of each bit in the s-bit partial multiplier, and the intermediate number First to nth general generating means for generating a product;
Adding means for adding the value generated by the special generating means corresponding to sj determined to be “111” and the product generated by the general generating means corresponding to sj determined not to be “111”; 17. The modular multiplication apparatus according to claim 16, further comprising:
前記第2算出手段は、
第i(iは1からsの整数)のシフト手段は、前記中間数をiビット左シフトにより桁上げする第1から第sのシフト手段を備え、
前記第1の一般生成手段は、第1及び第2シフト手段によるシフト結果を利用し、
前記第1を除く第jの一般生成手段は、第(3j−3)、第(3j−2)、第(3j−1)のシフト手段によるシフト結果を利用し、
前記第jの特別生成手段は、第(3j)のシフト手段によるシフト結果を利用し、
第jの特別生成手段と第(j+1)の一般生成手段とは、第(3j)のシフト手段を共用する
ことを特徴とする請求項28記載の剰余乗算装置。
The second calculation means includes
The i-th (i is an integer from 1 to s) shift means includes first to s-th shift means for carrying the intermediate number by i-bit left shift,
The first general generation means uses a shift result by the first and second shift means,
The j-th general generation means excluding the first uses a shift result by the (3j-3) th, (3j-2), and (3j-1) th shift means,
The jth special generation means uses the shift result obtained by the (3j) th shift means,
29. The modular multiplication apparatus according to claim 28, wherein the jth special generating means and the (j + 1) th general generating means share the (3j) shift means.
前記第jの特別生成手段は、
前記中間数又は第(3j−3)のシフト手段によるシフト結果の1の補数を生成する補数生成手段と、
定数1を出力する定数出力手段と
を備え、
前記加算手段は、
sjが”111”であると判定された場合に、第(3j)のシフト手段の出力と、第jの特別生成手段中の補数生成手段により生成された1の補数と、第jの特別生成手段中の定数出力手段により出力された定数1とを選択し、
s1が”111”であると判定されなかった場合に、中間数と第(3j−2)、第(3j−1)のシフト手段の出力とを選択し、
s1を除くsjが”111”であると判定されなかった場合に、第(3j−3)、第(3j−2)、第(3j−3)のシフト手段の出力を選択する選択手段と、
選択手段の選択結果を加算することにより前記部分積を算出する加算器と
を備えることを特徴とする請求項29記載の剰余乗算装置。
The jth special generation means includes:
A complement generation means for generating a one's complement of the intermediate number or a shift result by the (3j-3) th shift means;
Constant output means for outputting constant 1;
The adding means includes
When it is determined that sj is “111”, the output of the (3j) th shift means, the one's complement generated by the complement generation means in the jth special generation means, and the jth special generation Select the constant 1 output by the constant output means in the means,
If it is not determined that s1 is “111”, the intermediate number and the output of the (3j−2) th and (3j−1) th shift means are selected,
selection means for selecting the output of the (3j-3) th, (3j-2) th, and (3j-3) th shift means when sj excluding s1 is not determined to be "111";
30. The modular multiplication apparatus according to claim 29, further comprising an adder that calculates the partial product by adding the selection results of the selection means.
前記分割手段、読み出し手段、加算手段を利用することにより、補正手段に補正された最後の累算値の法pによる剰余を求める後処理手段
を備えることを特徴とする請求項16記載の剰余乗算装置。
17. The modular multiplication according to claim 16, further comprising: a post-processing unit that obtains a remainder of the last accumulated value corrected by the modulus p by using the dividing unit, the reading unit, and the adding unit. apparatus.
JP05480399A 1998-03-02 1999-03-02 Remainder multiplier Expired - Fee Related JP4293665B2 (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
JP05480399A JP4293665B2 (en) 1998-03-02 1999-03-02 Remainder multiplier

Applications Claiming Priority (3)

Application Number Priority Date Filing Date Title
JP10-49152 1998-03-02
JP4915298 1998-03-02
JP05480399A JP4293665B2 (en) 1998-03-02 1999-03-02 Remainder multiplier

Publications (2)

Publication Number Publication Date
JPH11316544A JPH11316544A (en) 1999-11-16
JP4293665B2 true JP4293665B2 (en) 2009-07-08

Family

ID=26389512

Family Applications (1)

Application Number Title Priority Date Filing Date
JP05480399A Expired - Fee Related JP4293665B2 (en) 1998-03-02 1999-03-02 Remainder multiplier

Country Status (1)

Country Link
JP (1) JP4293665B2 (en)

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
AU2003252789B2 (en) * 1999-09-29 2006-02-23 Hitachi, Ltd. Processing apparatus, program, or system of secret information
JP5294787B2 (en) * 2008-10-10 2013-09-18 ルネサスエレクトロニクス株式会社 Data processing apparatus and data processing method

Also Published As

Publication number Publication date
JPH11316544A (en) 1999-11-16

Similar Documents

Publication Publication Date Title
US6049815A (en) Method and apparatus for finite field multiplication
JP3238128B2 (en) Reed-Solomon encoding apparatus and method
US6366940B1 (en) High-speed modular multiplication apparatus achieved in small circuit
JPH05216627A (en) Multiplier and multiplying method
US20010054053A1 (en) Method and apparatus for finite field multiplication
JP4293665B2 (en) Remainder multiplier
JP3660075B2 (en) Dividing device
EP1573510A2 (en) Multiplier with look up tables
JP2000503146A (en) Modular arithmetic coprocessor with integer division circuit
JP4177125B2 (en) Arithmetic device and arithmetic method of arithmetic device
CN111615700B (en) Arithmetic circuit
JPH0326114A (en) Multiplication remainder computing element
KR100506470B1 (en) Method and hardware for computing reciprocal square root and a storage medium
US20050125479A1 (en) Hardware for performing an arithmetic function
JPH11237973A (en) Multiplier
JP2790327B2 (en) Remainder multiplication circuit and remainder multiplication method
JP2803442B2 (en) Square root device
JP3197186B2 (en) Multiplication device using semiconductor memory
JP3851025B2 (en) Division circuit
KR100196426B1 (en) Divider circuit and method of driving the same
JP3261600B2 (en) Remainder multiplier
CN112732219A (en) Multiplication circuit and method in SSD (solid State disk) master control chip
CN114610269A (en) Method, system equipment and medium for generating finite field multiplication circuit
JPH11203110A (en) Divider
JPH1124893A (en) Inverse square root arithmetic unit

Legal Events

Date Code Title Description
A621 Written request for application examination

Free format text: JAPANESE INTERMEDIATE CODE: A621

Effective date: 20051130

TRDD Decision of grant or rejection written
A01 Written decision to grant a patent or to grant a registration (utility model)

Free format text: JAPANESE INTERMEDIATE CODE: A01

Effective date: 20090310

A01 Written decision to grant a patent or to grant a registration (utility model)

Free format text: JAPANESE INTERMEDIATE CODE: A01

A61 First payment of annual fees (during grant procedure)

Free format text: JAPANESE INTERMEDIATE CODE: A61

Effective date: 20090407

FPAY Renewal fee payment (event date is renewal date of database)

Free format text: PAYMENT UNTIL: 20120417

Year of fee payment: 3

R150 Certificate of patent or registration of utility model

Free format text: JAPANESE INTERMEDIATE CODE: R150

LAPS Cancellation because of no payment of annual fees