JP3137599B2 - Circuit for calculating the remainder of B raised to the power of C modulo n - Google Patents

Circuit for calculating the remainder of B raised to the power of C modulo n

Info

Publication number
JP3137599B2
JP3137599B2 JP09245113A JP24511397A JP3137599B2 JP 3137599 B2 JP3137599 B2 JP 3137599B2 JP 09245113 A JP09245113 A JP 09245113A JP 24511397 A JP24511397 A JP 24511397A JP 3137599 B2 JP3137599 B2 JP 3137599B2
Authority
JP
Japan
Prior art keywords
circuit
value
register
output
modulo
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
JP09245113A
Other languages
Japanese (ja)
Other versions
JPH10260818A (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.)
International Business Machines Corp
Original Assignee
International Business Machines Corp
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 International Business Machines Corp filed Critical International Business Machines Corp
Priority to JP09245113A priority Critical patent/JP3137599B2/en
Publication of JPH10260818A publication Critical patent/JPH10260818A/en
Priority to US09/219,942 priority patent/US6317769B1/en
Application granted granted Critical
Publication of JP3137599B2 publication Critical patent/JP3137599B2/en
Anticipated expiration legal-status Critical
Expired - Fee Related legal-status Critical Current

Links

Description

【発明の詳細な説明】DETAILED DESCRIPTION OF THE INVENTION

【0001】[0001]

【発明の属する技術分野】本願発明は、RSA(Rives
t, Shamir and Adelman)暗号系を高速に処理するため
の装置に関し、より詳しくは、RSA暗号系において必
要とされるBCのnを法とする剰余を高速に計算する装
置に関する。
TECHNICAL FIELD The present invention relates to an RSA (Rives
The present invention relates to an apparatus for processing a t (Shamir and Adelman) encryption system at a high speed, and more particularly to an apparatus for calculating a modulo n modulo B C required in an RSA encryption system at a high speed.

【0002】[0002]

【従来の技術】RSA暗号系を処理するためには、51
2から1024ビット程度の以下の3つの数値n,B,
Cについて BC(mod n) (1) という計算が必要となる。この(1)式の値はnがBよ
り大きい素数で、Cが(n−1)に等しい時に1とな
る。また、Cがnの時にBになる。すなわち、以下のよ
うになる。 Bn-1≡1(mod n) Bn ≡B (mod n) これらは、フェルマーの小定理として知られている。
2. Description of the Related Art To process an RSA encryption system, 51
The following three numbers n, B, about 2 to 1024 bits
For C, a calculation of B C (mod n) (1) is required. The value of equation (1) is a prime number where n is greater than B and becomes 1 when C is equal to (n-1). Also, when C is n, it becomes B. That is, it becomes as follows. B n-1 ≡1 (mod n) B n ≡B (mod n) These are known as Fermat's little theorem.

【0003】nが2つの素数p,qの積の場合に、
(1)式は、Bが(p−1),(q−1)と互いに素で
あり、Cが(p−1)・(q−1)に等しい時に1にな
る。また、(p−1)・(q−1)で割った余りが1とな
る時、(1)式の値は元の値Bに等しくなる。すなわ
ち、n=p・qというように2つの素数に因数分解で
き、(B,k)=1(注:最大公約数が1)ならば、k
=(p−1)・(q−1)なるkについて、 Bk≡1 (mod n) Bk+1≡B (mod n) が成立する。これをオイラーの定理という。フェルマー
の小定理はオイラーの定理の一部である。
When n is the product of two prime numbers p and q,
Equation (1) becomes 1 when B is relatively prime to (p-1) and (q-1) and C is equal to (p-1). (Q-1). When the remainder after dividing by (p-1). (Q-1) becomes 1, the value of the expression (1) becomes equal to the original value B. That is, it can be factorized into two prime numbers such that n = p · q, and if (B, k) = 1 (note: the greatest common divisor is 1), k
For k = (p−1) · (q−1), B k ≡1 (mod n) B k + 1 ≡B (mod n) holds. This is called Euler's theorem. Fermat's little theorem is part of Euler's theorem.

【0004】ここで次のようなe,dが存在すれば、 e・d≡1 (mod k) eを暗号化、dを復号化のキーとして用いることができ
る。すなわち、eで暗号化したものをdで解読すること
ができるということである。また反対にdで暗号化した
ものをeで解読することも可能であるため、特定の二者
間で相手の確認をしながら通信を行うことができる。
Here, if the following e and d exist, ed ・ 1 (mod k) e can be used as a key for encryption and d as a key for decryption. That is, what is encrypted with e can be decrypted with d. Conversely, it is also possible to decrypt the data encrypted with d with e, so that communication can be performed between the specific two parties while confirming the other party.

【0005】例えば、Bを暗号化して送る時には、 Be≡M (mod n) を計算し、Mを送信する。そして、受信側では、 Md≡Bed≡B (mod n) が計算され、Bが解読できたことになる。但し、(B,
e)=1,(B,d)=1である。
[0005] For example, when sending encrypted is a B, B e ≡M a (mod n) is calculated, and transmits the M. Then, on the receiving side, M d ≡B ed ≡B (mod n) is calculated, and B is decoded. However, (B,
e) = 1, (B, d) = 1.

【0006】また、相手を確認する認証という処理の場
合には、両者が既知のXを、送信側が Xd≡N を計算して、Nを送信する。そして、受信側ではNe
計算して、 Ne≡Xed≡X からXが導き出せれば、正しい相手と通信していること
が確認できる。但し、(B,e)=1,(B,d)=1
である。
In the process of authentication for confirming the other party, both parties calculate a known X, and the transmitting side calculates X d ≡N and transmits N. Then, the receiving side calculates N e, and if X can be derived from N e ≡X ed ≡X, it can be confirmed that communication is being performed with the correct partner. However, (B, e) = 1, (B, d) = 1
It is.

【0007】このようなeとdの組が1つ見つかると、
各々をn乗したものも新しいキーの組となる。このよう
なキー(em,dm)の組は、(p−1)・(q−1)程度
存在し、この数は十分に大きいので、通信路に1:1で
(em,dm)の組を割り振ることができる。ここで、n
の値が決まれば、(p−1)・(q−1)=kを法とした
(em,dm)の組を同じハードウエアで作り出すことが
できる。すなわち、 em≡em (mod k) dm≡dm (mod k) である。
When one such pair of e and d is found,
Each raised to the nth power is also a new key set. Such a pair of keys (em, dm) exists in the order of (p−1) · (q−1), and the number is sufficiently large. Can be allocated. Where n
Is determined, a set of (em, dm) modulo (p-1). (Q-1) = k can be created with the same hardware. That is, e m ≡em (mod k) d m ≡dm (mod k).

【0008】RSA暗号系は暗号化と復号化が同じハー
ドウエアでできること、可逆性があること、暗号がキー
を知らない人にとって解きにくいことから広く使われて
いる。
[0008] The RSA encryption system is widely used because encryption and decryption can be performed by the same hardware, reversibility is high, and encryption is difficult to decrypt for those who do not know the key.

【0009】このような原理を用いて実際に計算を実行
する装置の一例を、特公平7−86822号公報が開示
している。ここで、以下の説明の準備を行っておく。例
えば、8×9の7を法とする剰余は、2であることはす
ぐに分かる。この計算を二進数表現すると、1000×
1001の0111を法とする剰余ということになる。
これを単純に計算する場合、最初に掛け算を図5のよう
に行う。このような計算を行うと、4ビット同士の掛け
算に7ビットのレジスタを必要とするので、より多数の
ビットの計算をハードウエアで実施する際には負担が大
きい。そこで、図6のように、step1で1000
(8)を取ってきて0111のmodを取り(0111
の2の補数1001を加算)、0001を得る。そし
て、step2で0001をシフトして(2倍して)0
010とし、0010の法0111を計算する。ここで
は、0010は0111より小さいので、そのまま00
10が結果となる。step3で0010をシフトして
0100とし、0100の法0111を計算する。ここ
では、0100は0111より小さいので、そのまま0
100が結果となる。step4で0100をシフトし
て1000とし、1000の法0111を計算し、結果
として0001を得る。そして、1001(9)のう
ち"1"が存在するLSBに対応するstep1の結果0
001と、同じく"1"が存在するMSBに対応するst
ep4の結果0001を加算すると、0010(2)を
得ることができ、先に示した計算は常に4ビット(ケタ
上がりを含めると5ビット)のレジスタを使用して行う
ことができる。なお、1001(9)のうち"1"が存在
するビット位置に対応するシフト及びMod計算の結果
を加算したが、先に1001(9)の7を法とする剰余
を求め(ここでは0010)、その剰余のうち"1"が存
在するビット位置に対応するシフト及びMod計算の結
果(ここではstep2の結果)を加算したものとして
も、結果が同じである(ここでは0010)。
Japanese Patent Publication No. 7-86822 discloses an example of an apparatus for actually executing a calculation using such a principle. Here, the following description is prepared. For example, it is immediately apparent that the remainder modulo 8 × 9 is 2. When this calculation is expressed in binary, 1000 ×
This means that the remainder is modulo 0111 of 1001.
When this is simply calculated, first multiplication is performed as shown in FIG. When such a calculation is performed, a 7-bit register is required for multiplication of 4 bits, so that the calculation of a larger number of bits requires a large burden when performed by hardware. Therefore, as shown in FIG.
Take (8) and take the mod of 0111 (0111
Of the two's complement 1001) to obtain 0001. Then, in step 2, 0001 is shifted (doubled) to 0.
010, and the modulo 0111 of 0010 is calculated. Here, since 0010 is smaller than 0111, 00 is used as it is.
10 is the result. In step 3, 0010 is shifted to 0100, and the modulus 0111 of 0100 is calculated. Here, 0100 is smaller than 0111, so 0
100 is the result. In step 4, 0100 is shifted to 1000, a modulo 0111 of 1000 is calculated, and 0001 is obtained as a result. Then, the result 0 of step 1 corresponding to the LSB in which “1” exists in 1001 (9)
001 and the st corresponding to the MSB in which “1” also exists
By adding the result 0001 of ep4, 0010 (2) can be obtained, and the above-described calculation can always be performed using a register of 4 bits (5 bits including an increase in digit). In addition, the result of the shift and the Mod calculation corresponding to the bit position where “1” exists in 1001 (9) is added, but the remainder modulo 7 of 1001 (9) is first obtained (here, 0010). The result is the same (here, 0010) even if the result of the shift and the Mod calculation (here, the result of step 2) corresponding to the bit position where “1” exists in the remainder is added.

【0010】以上の点を踏まえて、特公平7−8682
2号公報の装置を図7を用いて説明する。ここではMe
(mod n)=Cを計算するとしているのでそれに従うこと
にする。Mは数値入力から入力され、被乗数レジスタ1
に入力される。このレジスタ1の出力は、剰余演算器3
に入力され、ここで先に示したシフト及びMod計算が
行われる。Modを計算するために、除数レジスタ2に
除数入力としてnが入力されている。但し、引算を行う
ので、nの2の補数を入力する。そして、剰余演算器3
の結果は被乗数セレクタ11を介して被乗数レジスタ1
に入力される。この処理をMのビット数だけ繰り返す。
[0010] Based on the above points, Japanese Patent Publication No. 7-8682
The apparatus disclosed in Japanese Patent Publication No. 2 will be described with reference to FIG. Here Me
Since (mod n) = C is calculated, it will be followed. M is input from the numerical input, and the multiplicand register 1
Is input to The output of this register 1 is
, Where the shift and mod calculations described above are performed. In order to calculate Mod, n is input to the divisor register 2 as a divisor input. However, since subtraction is performed, the 2's complement of n is input. And the remainder arithmetic unit 3
Is output to the multiplicand register 1 via the multiplicand selector 11.
Is input to This process is repeated by the number of M bits.

【0011】また、Mは入力レジスタ7、置数レジスタ
8、及び乗数セレクタ9を介して乗数レジスタ10にセ
ットされ、このMのうちLSBから"1"が存在するビッ
トに対応する剰余演算器3の結果を剰余レジスタ12を
介して累算剰余演算器4に入力する。この累算剰余演算
器4では、累算剰余レジスタ5の結果と加算し、nの剰
余を計算し、結果を累算剰余レジスタに格納する。これ
は先に示した8×9(mod 7)の例の最後に述べた加算
処理に対応する。以上の処理をMのビット分だけ計算す
ると、M×M(mod n)が計算されたことになり、結果
が累算剰余レジスタ5に出力される。もし、M2が望み
の計算であれば、出力レジスタ13に結果を入力して処
理を終了させる。
M is set in a multiplier register 10 via an input register 7, a number register 8, and a multiplier selector 9, and the remainder arithmetic unit 3 corresponding to a bit in which "1" exists from the LSB of M is set. Is input to the accumulated remainder arithmetic unit 4 via the remainder register 12. The accumulated remainder calculator 4 adds the result of the accumulated remainder register 5 to calculate the remainder of n, and stores the result in the accumulated remainder register. This corresponds to the addition processing described at the end of the 8 × 9 (mod 7) example described above. When the above processing is performed for M bits, M × M (mod n) is calculated, and the result is output to the accumulation remainder register 5. If M 2 is the desired calculation, the result is input to the output register 13 and the process is terminated.

【0012】しかし、通常は指数レジスタ6に入力され
た指数eのビットに従って計算される。よって、べき乗
演算のために、乗数セレクタ9が指数レジスタ6の最上
位ビット(MSB)から最下位ビット(LSB)に至る
各ビット出力に順次応答してその論理値が"0"の時に
は、累乗剰余レジスタ5に格納されている前回の累乗剰
余値S(これは被乗数レジスタ1に格納される)を乗数
レジスタ10に設定する。その結果、S×S (mod n)
の処理が実行される。また、論理値が"1"の時には、ま
ず前回の累算剰余値Sを乗数レジスタに設定してS×S
(mod n)を求め、次いで入力レジスタ7の内容である
数値Mを乗数レジスタに設定して、{S×S (mod n)
×M}(mod n)を求める。
However, the calculation is normally performed according to the bit of the exponent e input to the exponent register 6. Therefore, for the exponentiation operation, the multiplier selector 9 sequentially responds to each bit output from the most significant bit (MSB) to the least significant bit (LSB) of the exponent register 6 and when its logical value is "0", the exponentiation is performed. The previous power residue value S stored in the remainder register 5 (which is stored in the multiplicand register 1) is set in the multiplier register 10. As a result, S × S (mod n)
Is performed. When the logical value is “1”, first, the previous accumulated remainder value S is set in the multiplier register and S × S
(mod n) is obtained, and then the value M, which is the content of the input register 7, is set in the multiplier register, and ΔS × S (mod n)
× M} (mod n) is obtained.

【0013】このような装置においては、一応の処理の
高速化が図れるが、前段落において述べたように、指数
eのMSBから計算し、その計算が"0"と"1"とでは異
なるため、この処理における動作を解析すると、キーが
暴露されてしまうおそれがあるという欠点があった。
In such a device, the processing can be speeded up for the time being. However, as described in the previous paragraph, the calculation is performed from the MSB of the index e, and the calculation is different between "0" and "1". However, when the operation in this processing is analyzed, there is a disadvantage that the key may be exposed.

【0014】[0014]

【発明が解決しようとする課題】よって、本願発明の目
的は、キーの安全性を確保しつつ、最小限のハードウエ
ア資源を用いて高速にBのC乗のnを法とする剰余を計
算する装置を提供することにある。
SUMMARY OF THE INVENTION Accordingly, an object of the present invention is to calculate a remainder modulo B raised to the power of C at a high speed using minimum hardware resources while ensuring the security of a key. It is an object of the present invention to provide a device that performs

【0015】さらに、消費電力を低減させることも目的
である。
Another object is to reduce power consumption.

【0016】[0016]

【課題を解決するための手段】以上の目的を達成するた
めに、本願発明は、Bのnを法とした剰余を計算し且つ
当該計算結果B1を保持する処理を実行し、保持する値
をシフトし且つnを法として合同となる値を計算し且つ
当該計算結果を保持する処理を繰り返す第1回路と、初
期値としてB1を格納する第1レジスタと、第1レジス
タの所定位置のビットの値が1である場合、第1回路の
計算結果を累積する第2回路と、初期値として1を格納
する第2レジスタと、Cを出力するC出力回路と、C出
力回路の出力値が1であって、第2レジスタの所定位置
のビットの値が1である場合、第1回路の計算結果を累
積する第3回路とを有する。そして、第1レジスタ及び
前記第2レジスタの所定位置のビットは、格納した値の
LSBからMSB方向にシフトし、第1レジスタが格納
した値のMSBについての処理が終了した場合には、
(a)第2回路の累積結果のnを法として合同となる値
を第1回路における保持する値とし且つ第1レジスタに
格納し、(b)C出力回路の出力は、CのLSBからM
SB方向にシフトした値に変化し、(c)C出力回路の
出力値が1であれば第3回路の累積結果のnを法として
合同な値を第2レジスタに格納する。このようにする
と、第2回路で、B2,B4,B8,..が計算される。
また、第3回路によって必要なべき乗計算がなされ、C
出力回路が出力する全てのCのビットに対する処理を行
えば第2レジスタに最終結果が格納されている。
In order to achieve the above object, the present invention calculates the remainder of B modulo n, executes processing for holding the calculation result B1, and calculates the value to be held. A first circuit that repeats a process of calculating a congruent value by modulating n and holding the calculation result, a first register that stores B1 as an initial value, and a bit of a bit at a predetermined position of the first register. When the value is 1, the second circuit that accumulates the calculation result of the first circuit, the second register that stores 1 as an initial value, the C output circuit that outputs C, and the output value of the C output circuit is 1 And a third circuit for accumulating the calculation result of the first circuit when the value of the bit at the predetermined position of the second register is 1. Then, the bits at predetermined positions of the first register and the second register are shifted in the MSB direction from the LSB of the stored value, and when the processing for the MSB of the value stored in the first register is completed,
(A) A value congruent modulo n of the accumulated result of the second circuit is set as a value to be held in the first circuit and stored in the first register. (B) The output of the C output circuit is obtained from the LSB of C to M
(C) If the output value of the C output circuit is 1, a congruent value is stored in the second register by modulating n of the accumulation result of the third circuit. In this way, the second circuit generates B 2 , B 4 , B 8 ,. . Is calculated.
Further, the required exponentiation calculation is performed by the third circuit, and C
If processing is performed on all the C bits output from the output circuit, the final result is stored in the second register.

【0017】先の第1レジスタ、第2レジスタ、C出力
回路が、それぞれシフトレジスタであるようにしてもよ
いし、通常のレジスタでポインタの位置を移動させるよ
うにしてもよい。特にC出力回路はLFSR(Linear F
eedback Shift Register)等でもよい。
The first register, the second register, and the C output circuit may be shift registers, or the position of the pointer may be moved by a normal register. In particular, the C output circuit is LFSR (Linear F
eedback Shift Register).

【0018】また、先の第2回路が、第1回路の計算結
果を累積するごとに、当該累積値のnを法とする剰余を
計算する回路を含むようにすることもできる。第3回路
についても同様である。
Further, the second circuit may include a circuit for calculating a remainder modulo n of the accumulated value every time the calculation result of the first circuit is accumulated. The same applies to the third circuit.

【0019】但し、第1レジスタの所定位置のビットの
値が0であって、第2回路の累積値が正の値である場
合、第2回路は、累積値からxn(xは正の整数)引算
し、第1レジスタに格納された値のMSBが処理された
場合、第2回路の累積値が正の値か否か判断し、正であ
ると判断された場合には、累積値が負になるまでxn引
算し、負であると判断された場合には、正になるまでy
n(yは正の整数)を足し算するようにしてもよい。こ
のようにすると、Mod計算の回数を減少させることが
できる。これらは、1の加算回路にて加算する値を変更
することによって同等の機能を果たすことができる。
However, if the value of the bit at the predetermined position of the first register is 0 and the cumulative value of the second circuit is a positive value, the second circuit calculates xn (x is a positive integer) from the cumulative value. If the subtraction is performed and the MSB of the value stored in the first register is processed, it is determined whether or not the cumulative value of the second circuit is a positive value. If it is determined that the cumulative value is positive, the cumulative value is determined. Is subtracted xn until becomes negative, and if it is determined to be negative, y is subtracted until it becomes positive
Alternatively, n (y is a positive integer) may be added. By doing so, the number of mod calculations can be reduced. These can perform the same function by changing the value to be added by one adding circuit.

【0020】第3回路についても、C出力回路の出力値
が1であって且つ第2レジスタの所定位置のビットの値
が0であって、第3回路の累積値が正の値である場合、
累積値からxn(xは正の整数)引算し、C出力回路の
出力値が1であって、第2レジスタに格納された値のM
SBについての処理が終了した場合、第3回路の累積値
が正の値か否か判断し、正であると判断された場合に
は、累積値が負になるまでxn引算し、負であると判断
された場合には、正になるまでyn(yは正の整数)を
足し算するようにすることもできる。
Also in the case of the third circuit, when the output value of the C output circuit is 1, the value of a bit at a predetermined position of the second register is 0, and the cumulative value of the third circuit is a positive value ,
Xn (x is a positive integer) is subtracted from the accumulated value, and the output value of the C output circuit is 1 and M of the value stored in the second register is obtained.
When the process for SB is completed, it is determined whether or not the cumulative value of the third circuit is a positive value. If it is determined that the cumulative value is positive, xn is subtracted until the cumulative value becomes negative. If it is determined that there is, yn (y is a positive integer) may be added until it becomes positive.

【0021】また、nを格納するn用レジスタをさらに
含み、Bのnを法とした剰余を計算し且つ当該計算結果
B1を保持する処理において、n用レジスタは、nをM
SBからみて最初に1となるビットがMSBとなるよう
に、nをMSB方向にシフトさせ、次いで当該シフトさ
せた値をLSB方向にBと同一となるまで1ビットずつ
シフトさせ、各シフトさせた値を順に第1回路に出力
し、第1回路は、Bからn用レジスタから得た各シフト
させた値を引算できれば引算するようにして求めること
ができる。このようにすると、Bのnを法とした剰余を
同一のハードウエア内の加算回路に入力する値を変える
ことによって計算できるという利点がある。
Further, in the processing for calculating the remainder of B modulo n and holding the calculation result B 1, the n register stores n as M
N is shifted in the MSB direction so that the first bit that becomes 1 when viewed from the SB becomes the MSB, and then the shifted value is shifted one bit at a time until the value becomes the same as B in the LSB direction. The values can be sequentially output to the first circuit, and the first circuit can obtain the values by subtracting the shifted values obtained from the registers for B to n if they can be subtracted. This has the advantage that the remainder of B modulo n can be calculated by changing the value input to the adder circuit in the same hardware.

【0022】さらに第1回路についても様々な変形が考
えられる。例えば、第1回路の保持する値が正である場
合には、当該保持する値をシフトし且つp・n(pは正
の整数)を減じる計算を実行し、保持する値が負である
場合には、当該保持する値をシフトし且つq・n(qは
正の整数)を加算する計算を実行するようにすることも
考えられる。このように、第1回路の保持する値を正の
値のみではなく、負の値を許すことにより、第2及び第
3回路の構成を簡単にするという効果を奏する。
Further, various modifications can be considered for the first circuit. For example, when the value held by the first circuit is positive, a calculation is performed in which the value held is shifted and pn (p is a positive integer) is reduced, and the value held is negative. It is also conceivable to execute a calculation for shifting the held value and adding q · n (q is a positive integer). As described above, by allowing the first circuit to hold not only a positive value but also a negative value, there is an effect that the configuration of the second and third circuits is simplified.

【0023】また、第1回路が、第1レジスタ及び第2
レジスタの所定位置のビットの値及びC出力回路の出力
値が、第2回路及び第3回路が累積を実施しないような
値である場合には、保持する値をrビット分(rは正の
整数)シフトし且つnを法として合同な値を計算するよ
うにすることも考えられる。第2及び第3回路は第1及
び第2レジスタ及びC出力回路の値によっては動作不要
な期間があるので、その期間をスキップするために、第
1回路におけるシフトするビット数を変化させ、それに
応じて減じる値(加える値)も変化させることにより、
回路全体の処理を高速化できる。
The first circuit includes a first register and a second register.
If the value of the bit at the predetermined position of the register and the output value of the C output circuit are such that the second circuit and the third circuit do not perform accumulation, the value to be held is r bits (r is a positive value). It is also conceivable to calculate a congruent value modulo n). The second and third circuits have periods in which operation is unnecessary depending on the values of the first and second registers and the C output circuit. In order to skip these periods, the number of bits to be shifted in the first circuit is changed, and By changing the value to be subtracted (added value) accordingly,
The processing speed of the entire circuit can be increased.

【0024】さらに、rが2であって、第1回路が、保
持する値が正である場合には、当該保持する値を4倍し
且つ保持する値及びnの値に基づきn又は2n又は3n
を減じる計算を実行し、保持する値が負である場合に
は、当該保持する値を4倍し且つ保持する値及びnの値
に基づきn又は2n又は3nを加算する計算を実行する
ようにすることも考えられる。このようにすると、不要
な期間に2ビット・シフトすることにより処理を高速化
することができる。但し、3nを生成する必要がある。
Further, when r is 2 and the value held by the first circuit is positive, the value held is multiplied by 4 and based on the value held and the value of n, n or 2n or 3n
When the value to be held is negative, the calculation to multiply the held value by 4 and add n or 2n or 3n based on the value to be held and the value of n is performed. It is also possible to do. By doing so, the processing can be speeded up by shifting by 2 bits during an unnecessary period. However, it is necessary to generate 3n.

【0025】さらにrが1であって、第1回路は、保持
する値が正である場合には、当該保持する値を2倍し且
つnを減じる計算を実行し、この計算結果に基づき当該
計算結果をさらに2倍するか否か決定し、保持する値が
負である場合には、当該保持する値を2倍し且つnを加
算する計算を実行し、この計算結果に基づき当該計算結
果をさらに2倍する否か決定するようにしてもよい。こ
のようにすると、3nを生成する必要がなくなるが、処
理速度の向上という効果は減ぜられる。
Further, when r is 1, and the value to be held is positive, the first circuit executes a calculation of doubling the value to be held and subtracting n, and based on the calculation result, It is determined whether or not to further double the calculation result. If the value to be held is negative, a calculation to double the value to be held and add n is performed, and based on the calculation result, the calculation result is calculated. May be determined to be further doubled. This eliminates the need to generate 3n, but reduces the effect of improving the processing speed.

【0026】以上述べたような変形の他、多数の変形が
以下に述べる本発明の実施例から導き出される。
In addition to the modifications described above, numerous modifications can be derived from the embodiments of the present invention described below.

【0027】[0027]

【発明の実施の形態】まず、本願発明の計算の基本的ポ
リシーを説明する。BC (mod n)のCを二進数表現し、
各ビットを(c(m-1)....,c4,c3,c2,c1,c0)と書くこと
にする。すなわち、CのLSBからMSBへ、順に0か
ら順番に番号を振るのである。このようにすると、BC
(mod n)は以下のように分解することができる。すなわ
ち、 BC (mod n)=(B(..,0,0,0,c0) (mod n)×B
(..,0,0,c1,0) (mod n)×B(..,0,c2,0,0) (mod n)×
(..,0,c3,0,0,0) (mod n)×B(..,0,c4,0,0,0,0) (m
od n)×.......)(mod n)
DESCRIPTION OF THE PREFERRED EMBODIMENTS First, the basic policy of calculation of the present invention will be described. C of B C (mod n) is represented by a binary number,
Let each bit be written as (c (m-1) ...., c4, c3, c2, c1, c0). That is, numbers are sequentially assigned from 0 to the MSB from the LSB of C. In this case, B C
(mod n) can be decomposed as follows. That is, B C (mod n) = (B (.., 0,0,0, c0) (mod n) × B
(.., 0,0, c1,0) (mod n) × B (.., 0, c2,0,0) (mod n) ×
B (.., 0, c3,0,0,0) (mod n) × B (.., 0, c4,0,0,0,0) (m
od n) × .......) (mod n)

【0028】よって、まずB(..,0,0,0,1) (mod n),B
(..,0,0,1,0) (mod n),B(..,0,1, 0,0) (mod n),B
(..,0,1,0,0,0) (mod n),B(..,0,1,0,0,0,0) (mod
n),....を順に生成する。これを二乗計算という。
そして、cx=1(xは0以上、Cのビット数以下の整
数)となっているxに対応するビットのみ、先のBの累
乗の計算結果を掛け算する。これをべき乗計算という。
Therefore, first, B (.., 0,0,0,1) (mod n), B
(.., 0,0,1,0) (mod n), B (.., 0,1, 0,0) (mod n), B
(.., 0,1,0,0,0) (mod n), B (.., 0,1,0,0,0,0) (mod
n),. . . . Are generated in order. This is called a square calculation.
Then, only the bits corresponding to x in which cx = 1 (x is an integer of 0 or more and the number of bits of C or less) are multiplied by the calculation result of the power of B. This is called exponentiation calculation.

【0029】例えば、B(1101001) (mod n)を計算する
ならば、B(0000001) (mod n),B( 0000010) (mod n),
(0000100) (mod n),B(0001000) (mod n),B
(0010000)(mod n),B(0100000) (mod n),B(1000000)
(mod n)を順番に生成する。そして、B(0000001) (mod
n)とB(0001000) (mod n)が生成されたところでそれら
の掛け算を行い、その掛け算の結果のnを法とする剰余
を計算する。この結果をS1とする。そして、B
(0100000) (mod n)が生成されたところで、S1と掛け算
を行い、その掛け算の結果のnを法とする剰余を計算す
る。この結果をS2とする。さらに、B(1000000) (mod
n)が生成されたところで、S2と掛け算を行い、その掛
け算の結果のnを法とする剰余を計算する。このように
すれば、B(1101001 ) (mod n)を計算することができ
る。
For example, if B (1101001) (mod n) is calculated, B (0000001) (mod n), B ( 0000010) (mod n),
B (0000100) (mod n), B (0001000) (mod n), B
(0010000) (mod n), B (0100000) (mod n), B (1000000)
(mod n) in order. And B (0000001) (mod
When n) and B (0001000) (mod n) are generated, they are multiplied, and a remainder modulo n of the result of the multiplication is calculated. This result is defined as S1. And B
(0100000) When (mod n) is generated, multiplication with S1 is performed, and a remainder modulo n of the result of the multiplication is calculated. This result is defined as S2. Furthermore, B (1000000) (mod
When n) is generated, multiplication with S2 is performed, and a remainder modulo n of the result of the multiplication is calculated. In this way, B (1101001 ) (mod n) can be calculated.

【0030】但し、各二乗計算及びべき乗計算には、従
来技術の欄にて説明したシフト及びMod計算、そして
加算及びMod計算にて実施する。すなわち、被乗数を
被乗数のビット数m回(従来技術の欄の例にて説明した
ように、正確にはm−1回)、シフト(2倍)してその
nを法とする剰余計算する。そして、乗数のビットのう
ち"1"であるビットをLSBから数えた時の順番に対応
するシフト及びMod計算の結果を、順次加算して、そ
の結果のnを法とする剰余を計算する。
However, each square calculation and exponentiation calculation is performed by the shift and mod calculations, and the addition and mod calculations described in the section of the prior art. That is, the multiplicand is shifted (doubled) m times the number of bits of the multiplicand (exactly m-1 times as described in the example of the related art), and the remainder is calculated modulo n. Then, the shift and Mod calculation results corresponding to the order in which the bits of the multiplier that are “1” are counted from the LSB are sequentially added, and the remainder modulo n of the result is calculated.

【0031】本願発明の構成を図1を参照して説明す
る。SHIFT&MOD回路100は、第1ADD&M
OD回路110に接続される。このSHIFT&MOD
回路100は、暗号化の対象たるB又は当該第1ADD
&MOD回路110からの出力を入力としている。ま
た、SHIFT&MOD回路100はMod計算に用い
るnを得るために、n用レジスタ130に接続されてい
る。第1ADD&MOD回路110は、シフトレジスタ
である第1レジスタ120に接続されており、第1レジ
スタ120のLSB120aを入力として受け取るよう
になっている。Mod計算を行うため、第1ADD&M
OD回路110は、n用レジスタ130に接続されてい
る。
The configuration of the present invention will be described with reference to FIG. The SHIFT & MOD circuit 100 includes a first ADD & M
Connected to OD circuit 110. This SHIFT & MOD
The circuit 100 includes the B to be encrypted or the first ADD.
The output from the & MOD circuit 110 is input. The SHIFT & MOD circuit 100 is connected to an n register 130 in order to obtain n used for Mod calculation. The first ADD & MOD circuit 110 is connected to a first register 120 that is a shift register, and receives the LSB 120a of the first register 120 as an input. First ADD & M to perform Mod calculation
The OD circuit 110 is connected to the register 130 for n.

【0032】また、SHIFT&MOD回路100は、
第2ADD&MOD回路150に接続されている。第2
ADD&MOD回路150は、シフトレジスタであるC
用レジスタ140からLSBを受け取るようになってい
る。また、回路150はMod計算のためにn用レジス
タ130に接続されている。この第2ADD&MOD回
路150の出力は、シフトレジスタである第2レジスタ
160に入力されるようになっており、逆に第2レジス
タ160のLSB160aは第2ADD&MOD回路1
50に出力されるようになっている。この第2レジスタ
160の初期値は1である。
The SHIFT & MOD circuit 100
The second ADD & MOD circuit 150 is connected. Second
The ADD & MOD circuit 150 includes a shift register C
The LSB is received from the register 140. The circuit 150 is connected to the register 130 for n for mod calculation. The output of the second ADD & MOD circuit 150 is input to a second register 160 which is a shift register. On the contrary, the LSB 160 a of the second register 160 is connected to the second ADD & MOD circuit 1.
50. The initial value of the second register 160 is 1.

【0033】次に、この図1に示された回路の動作を説
明する。最初に、暗号化の対象たるBがSHIFT&M
OD回路100に入力されると、SHIFT&MOD回
路100は、n用レジスタ130からnを受け取り、B
のnを法とする剰余を計算する。この結果をB11とす
る。ここで注意されたいのは、最初のステップではシフ
ト動作を行わないということである。このB11を第1A
DD&MOD回路110を介して第1レジスタ120に
出力する。
Next, the operation of the circuit shown in FIG. 1 will be described. First, B to be encrypted is SHIFT & M
When input to the OD circuit 100, the SHIFT & MOD circuit 100 receives n from the n register
Is calculated modulo n. This result is designated as B11. It should be noted that no shift operation is performed in the first step. This B11 is the first A
The data is output to the first register 120 via the DD & MOD circuit 110.

【0034】B11は、第1ADD&MOD回路110を
介して第1レジスタ120に入力される。第1ADD&
MOD回路110はその際B11のLSBを受け取って保
持しておく。そして、B11からLSBを除いたビットを
第1レジスタ120に入力する。このようにすると、第
1レジスタ120のビット数を減らすことができる。但
し、そのままB11を第1レジスタ120に入力するよう
にしてもよい。また、従来技術の欄で少し述べたが、B
そのものを第1レジスタ120に入力するようにしても
よい。
B11 is input to the first register 120 via the first ADD & MOD circuit 110. 1st ADD &
At this time, the MOD circuit 110 receives and holds the LSB of B11. Then, a bit obtained by removing the LSB from B11 is input to the first register 120. By doing so, the number of bits of the first register 120 can be reduced. However, B11 may be directly input to the first register 120. Also, as described briefly in the section of the prior art, B
This may be input to the first register 120.

【0035】先に述べたように、このSHIFT&MO
D回路100の第1回目の計算結果B11は、SHIFT
&MOD回路100に保持されるとともに、第1ADD
&MOD回路110に出力される。第1ADD&MOD
回路110は、SHIFT&MOD回路100から又は
第1レジスタ120から、まずB11のLSBを受け取
る。このLSBが"1"であれば、SHIFT&MOD回
路100の計算結果B11を第1ADD&MOD回路11
0にロードする。すなわち、この計算結果B11を単に保
持する。通常は加算及びnを法とする剰余を計算する
が、最初にLSB(LSB120aからの出力の場合も
ある)が"1"となった時は0との加算であり且つSHI
FT&MOD回路100にてnを法とする剰余も計算し
ているので、ロードするのみでよい。但し、加算及びn
を法とする剰余の計算を行っても解は変わらない。ま
た、B11のLSBが"0"であれば、SHIFT&MOD
回路100からの入力を無視する。nを法とする剰余の
計算については、SHIFT&MOD回路100と同様
に、n用レジスタ130からの出力を用いる。
As described above, this SHIFT & MO
The first calculation result B11 of the D circuit 100 is SHIFT
& MOD circuit 100, and the first ADD
& MOD circuit 110. 1st ADD & MOD
The circuit 110 first receives the LSB of B11 from the SHIFT & MOD circuit 100 or from the first register 120. If this LSB is "1", the calculation result B11 of the SHIFT & MOD circuit 100 is transferred to the first ADD & MOD circuit 11
Load to 0. That is, the calculation result B11 is simply held. Normally, the addition and the remainder modulo n are calculated, but when the LSB (which may be the output from the LSB 120a) first becomes "1", it is an addition with 0 and the SHI
Since the FT & MOD circuit 100 also calculates the remainder modulo n, it is only necessary to load the remainder. However, addition and n
The solution does not change even if the remainder is calculated modulo. If the LSB of B11 is "0", SHIFT & MOD
The input from the circuit 100 is ignored. For the calculation of the remainder modulo n, the output from the register 130 for n is used, as in the SHIFT & MOD circuit 100.

【0036】次に、SHIFT&MOD回路100は、
先の計算結果B11をシフト処理(2倍)し、その結果の
nを法とする剰余を計算する。この計算結果をB12とす
る。このB12は、SHIFT&MOD回路100に保持
されるとともに、第1ADD&MOD回路110に出力
される。第1ADD&MOD回路110は、第1レジス
タ120のLSB120aの値を参照する。第1レジス
タ120は、B11のLSBが除かれて入力された場合に
は、LSB120aに存在するビットを出力し、B11自
身が入力された場合には、1ビットシフトさせて、シフ
トによりLSB120aに入ったそのビット値を出力す
る。シフト方向はMSBからLSBの方向である。も
し、第1レジスタ120のLSB120aの値が"1"で
ある場合には、B12と第1ADD&MOD回路110に
保持された値とを加算する。すなわち、B11のLSB
が"1"であれば計算結果B11とB12の加算を行い、B11
のLSBが"0"であれば0とB12と加算する。先に述べ
たように最初にLSB120aの出力が"1"となった際
には単にロードするだけでもよい。そして、その加算結
果のnを法とする剰余を計算し、この値を保持する。ま
た、LSB120aの値が"0"である場合には、何もし
ない。
Next, the SHIFT & MOD circuit 100
The previous calculation result B11 is shifted (doubled), and the remainder modulo n of the result is calculated. This calculation result is defined as B12. This B12 is held in the SHIFT & MOD circuit 100 and output to the first ADD & MOD circuit 110. The first ADD & MOD circuit 110 refers to the value of the LSB 120a of the first register 120. The first register 120 outputs the bit present in the LSB 120a when the LSB of B11 is removed and is input, and shifts one bit when the B11 itself is input and enters the LSB 120a by the shift. Outputs the bit value. The shift direction is a direction from the MSB to the LSB. If the value of the LSB 120a of the first register 120 is "1", B12 is added to the value held in the first ADD & MOD circuit 110. That is, the LSB of B11
Is "1", the calculation results B11 and B12 are added, and B11
If the LSB of is "0", 0 and B12 are added. As described above, when the output of the LSB 120a first becomes "1", it may be simply loaded. Then, a remainder modulo n of the addition result is calculated, and this value is held. If the value of the LSB 120a is "0", nothing is performed.

【0037】そして、SHIFT&MOD回路100
は、先の計算結果B12をシフト処理(2倍)し、その結
果のnを法とする剰余を計算する。この計算結果をB13
とする。このB13は、SHIFT&MOD回路100に
保持されるとともに、第1ADD&MOD回路110に
出力される。第1ADD&MOD回路110は、第1レ
ジスタ120のLSB120aの値を参照する。第1レ
ジスタ120は、先の処理から1ビットシフトさせて、
シフトによりLSB120aに入ったそのビット値を出
力する。もし、LSB120aの値が"1"であるなら
ば、第1ADD&MOD回路110に保持されている値
とB13を加算し、nを法とする剰余を計算する。"0"で
あるならば何もしない。
Then, the SHIFT & MOD circuit 100
Shifts (doubles) the previous calculation result B12 and calculates the remainder of the result modulo n. This calculation result is B13
And This B13 is held in the SHIFT & MOD circuit 100 and output to the first ADD & MOD circuit 110. The first ADD & MOD circuit 110 refers to the value of the LSB 120a of the first register 120. The first register 120 shifts one bit from the previous processing,
The bit value input to the LSB 120a by the shift is output. If the value of the LSB 120a is "1", the value held in the first ADD & MOD circuit 110 is added to B13 to calculate a remainder modulo n. If it is "0", do nothing.

【0038】以上の処理を、B1m(mはBのビット数)
が第1ADD&MOD回路にて処理されるまで繰り返
す。B1mの処理を第1ADD&MOD回路110が行う
と、B2 (mod n)が生成されたことになる。B2 (mod
n)は、SHIFT&MOD回路100に出力され、第
1レジスタ120にも出力される。これは、B4 (mod
n)を計算するためである。但し、先にも述べたよう
に、第1レジスタ120のビット数を減らす場合には、
2 (mod n)のLSBを第1ADD&MOD回路110
に保持し、B2 (mod n)からそのLSBを除いたビット
を第1レジスタ120に出力する。また、そのままB2
(mod n)を第1レジスタ120に出力して、保持するよ
うにしてもよい。
The above processing is performed using B1m (m is the number of bits of B)
Is repeated by the first ADD & MOD circuit. When the processing of B1m is first 1ADD & MOD circuit 110 performs, B 2 (mod n) is thus generated. B 2 (mod
n) is output to the SHIFT & MOD circuit 100 and is also output to the first register 120. This is B 4 (mod
n). However, as described above, when reducing the number of bits of the first register 120,
The LSB of B 2 (mod n) is added to the first ADD & MOD circuit 110
And outputs the bit obtained by removing the LSB from B 2 (mod n) to the first register 120. In addition, B 2
(mod n) may be output to the first register 120 and held.

【0039】B2 (mod n)を受け取ったSHIFT&M
OD回路100は、その値を保持する。これは既にnを
法とする剰余は計算されているためである。そして、第
1ADD&MOD回路110は、第1レジスタ120の
LSB120aの値又は保持していたB2 (mod n)のL
SBの値を参照し、B2 (mod n)を保持するか("1"の
場合)、B2 (mod n)をクリアし0を保持する("0"の
場合)。このステップは、0との加算を行うだけであっ
て、nを法とする剰余も既に計算されているので、B2
(mod n)を保持するか否かを決めるだけでよい。B2 (m
od n)をB21とする。
SHIFT & M receiving B 2 (mod n)
The OD circuit 100 holds the value. This is because the remainder modulo n has already been calculated. Then, the first ADD & MOD circuit 110 outputs the value of the LSB 120 a of the first register 120 or the L of the stored B 2 (mod n).
Referring to the value of SB, B 2 (mod n) is held (in the case of “1”), or B 2 (mod n) is cleared and held in 0 (in the case of “0”). This step is merely performing addition with 0, since modulo n have also been calculated, B 2
You only need to decide whether to keep (mod n) or not. B 2 (m
od n) is B21.

【0040】次に、SHIFT&MOD回路100は、
保持したB21を1ビットシフトし(2倍し)、nを法と
する剰余を計算する。この計算結果B22は、第1ADD
&MOD回路110に出力される。第1ADD&MOD
回路110は、第1レジスタ120のLSB120aの
値(B2 (mod n)をそのまま保持している場合には、1
ビットシフト動作を実施した後の値)が"1"である場
合、第1ADD&MOD回路110が保持している値と
加算し、nを法とする剰余を計算する。そして、その結
果を保持する。"0"である場合には、何もせず、SHI
FT&MOD回路100の出力を無視する。
Next, the SHIFT & MOD circuit 100
The stored B21 is shifted by one bit (doubled), and the remainder modulo n is calculated. This calculation result B22 is the first ADD
& MOD circuit 110. 1st ADD & MOD
If the circuit 110 holds the value of the LSB 120a of the first register 120 (B 2 (mod n) as it is,
If the value after performing the bit shift operation is “1”, the value is added to the value held by the first ADD & MOD circuit 110, and the remainder modulo n is calculated. Then, the result is held. If "0", do nothing and SHI
The output of the FT & MOD circuit 100 is ignored.

【0041】以下、B4 (mod n)が生成されるまで、す
なわち、B2mが生成され処理されるまで(無視する場合
も、無視する処理を行うということとする)繰り返す。
そして、B8 (mod n),B16 (mod n),...を次々に
生成していく。
Thereafter, the process is repeated until B 4 (mod n) is generated, that is, until B 2m is generated and processed (when ignored, the process of ignoring is performed).
Then, B 8 (mod n), B 16 (mod n),. . . Are generated one after another.

【0042】では、SHIFT&MOD回路100と第
2ADD&MOD回路150の協働を説明する。初期値
として、第2レジスタ160には1が入力されている。
また、第2ADD&MOD回路150は、C用レジスタ
140に格納された、BC (mod n)の指数CをLSBか
ら入力として受け取り、動作を切り換える。第2レジス
タ160も同様にLSBからビットを出力するようにな
っており、第2ADD&MOD回路150は、その値に
応じて動作を切り換える。上記2つのレジスタはシフト
レジスタであって、MSBからLSBへビットをシフト
させる。
Now, the cooperation between the SHIFT & MOD circuit 100 and the second ADD & MOD circuit 150 will be described. 1 is input to the second register 160 as an initial value.
The second ADD & MOD circuit 150 receives the exponent C of B C (mod n) stored in the C register 140 as an input from the LSB, and switches the operation. Similarly, the second register 160 outputs a bit from the LSB, and the second ADD & MOD circuit 150 switches the operation according to the value. The above two registers are shift registers and shift bits from the MSB to the LSB.

【0043】まず、第2ADD&MOD回路150は、
C用レジスタ140からCのLSBを受け取り、これか
らm回のSHIFT&MOD回路100からの出力を受
け取って処理を行うかを判断する。すなわち、CのLS
Bが"1"であれば、これからm回の出力を受け取って処
理を行い、"0"であれば、これからm回の出力を受け取
らない。そして、CのLSBが"1"である場合、次に第
2レジスタ160のLSB160aの出力を参照する。
もし、この第2レジスタ160のLSB160aの出力
が"1"であれば、第2ADD&MOD回路150は、S
HIFT&MOD回路100からの出力と保持している
値(初期値は0)とを加算し、nを法とする剰余を計算
する。そして、計算結果を保持する。第2レジスタ16
0のLSB160aの出力が"0"であれば、何もしな
い。これを第2レジスタのビット数分(Bのビット数と
同じ)繰り返す。繰り返す際には、繰り返しごとに第2
レジスタ160を1ビットずつシフトさせる。但し、最
初にC用レジスタ140のLSBの出力が"1"となった
場合には、第2レジスタ160にはLSBにのみ"1"が
保持されているので、最初のSHIFT&MOD回路1
00の出力のみは、加算及びnを法とする剰余を計算せ
ずに単にロードする。このような処理は、Cのビットが
LSBから数えて最初に"1"となったところの累乗の値
を第2レジスタ160が保持するために行われる。例え
ば、B(1101001) (mod n)を計算する場合には、B
(0000001) (mod n)を第2レジスタ160に入力するた
めに行われる。
First, the second ADD & MOD circuit 150
The C LSB is received from the C register 140, and it is determined whether the output from the SHIFT & MOD circuit 100 is to be received and processed m times. That is, the LS of C
If B is "1", m outputs will be received and processed, and if "0", m outputs will not be received. Then, when the LSB of C is “1”, the output of the LSB 160 a of the second register 160 is referred to next.
If the output of the LSB 160a of the second register 160 is "1", the second ADD & MOD circuit 150
The output from the HIFT & MOD circuit 100 is added to the held value (the initial value is 0), and the remainder modulo n is calculated. Then, the calculation result is held. Second register 16
If the output of the 0 LSB 160a is "0", nothing is done. This is repeated for the number of bits of the second register (same as the number of bits of B). When repeating, a second
The register 160 is shifted one bit at a time. However, when the output of the LSB of the C register 140 first becomes “1”, since the second register 160 holds “1” only in the LSB, the first SHIFT & MOD circuit 1
Only the output of 00 simply loads without calculating the addition and the remainder modulo n. Such processing is performed because the second register 160 holds the value of the power at which the bit of C first becomes “1” counted from the LSB. For example, when calculating B (1101001) (mod n), B
This is performed to input (0000001) (mod n) to the second register 160.

【0044】m回SHIFT&MOD回路100の出力
が第2ADD&MOD回路150にて処理されると(受
け取らない場合も含む)、C用レジスタ140は格納さ
れているビットを1ビットLSB側へシフトさせる。そ
して、第2ADD&MOD回路150は、計算結果を第
2レジスタ160に出力した後に、自身が保持している
値をクリアする。その後、第2ADD&MOD回路15
0は、C用レジスタ140のLSBを参照して、そのビ
ットが"1"であるか"0"であるかを判断する。もし、"
1"であるならば、今後m回のSHIFT&MOD回路
100の出力を受け取り、加算及びnを法とする剰余の
計算を行う可能性を有するようになる。一方、"0"であ
るならば、今後m回のSHIFT&MOD回路100の
出力を受け取らず、無視する。
When the output of the SHIFT & MOD circuit 100 is processed by the second ADD & MOD circuit 150 m times (including the case where the output is not received), the C register 140 shifts the stored bit to the 1-bit LSB side. Then, the second ADD & MOD circuit 150 clears the value held by itself after outputting the calculation result to the second register 160. Then, the second ADD & MOD circuit 15
The value “0” refers to the LSB of the C register 140 to determine whether the bit is “1” or “0”. if,"
If it is "1", the output of the SHIFT & MOD circuit 100 will be received m times from now on, and there will be a possibility of performing addition and calculating the remainder modulo n. The output of the SHIFT & MOD circuit 100 times is not received and ignored.

【0045】C用レジスタ140の出力が"1"であれ
ば、次に第2ADD&MOD回路150は、第2レジス
タ160のLSB160aを参照して、その値が"1"で
あれば、加算を行い、nを法とする剰余を計算する。そ
して、結果を保持する。但し、最初の処理は、先に述べ
たように、0との加算であり、SHIFT&MOD回路
100でnを法とする剰余の計算も行われているので、
何もせずに値を単に保持するようにしてもよい。第2レ
ジスタ160のLSB160aが"0"であれば、第2A
DD&MOD回路150は何もしない。これを、第2レ
ジスタ160のビット分(m回)繰り返す。その際、第
2レジスタ150は、各SHIFT&MOD回路100
の入力ごとに1ビットずつLSB側へシフトさせる。
If the output of the C register 140 is "1", then the second ADD & MOD circuit 150 refers to the LSB 160a of the second register 160, and if the value is "1", performs addition. Calculate the remainder modulo n. Then, the result is held. However, the first process is, as described above, an addition with 0, and the calculation of the remainder modulo n is also performed in the SHIFT & MOD circuit 100.
The value may simply be retained without doing anything. If the LSB 160a of the second register 160 is "0", the second A
The DD & MOD circuit 150 does nothing. This is repeated for the bits of the second register 160 (m times). At this time, the second register 150 stores each SHIFT & MOD circuit 100
Is shifted to the LSB side by 1 bit for each input.

【0046】B(1101001) (mod n)を計算する際には、
(0000001) (mod n)を第2レジスタ160に格納した
後に、2m回SHIFT&MOD回路100の出力を受
け取らず無視した後、次のm回SHIFT&MOD回路
100からの出力を受け取り、B(0000001) (mod n)を
格納した第2レジスタ160のLSB160a(各処理
ごとにシフト動作をしているので常に同じビットを見て
いる訳でない)を参照して、加算及びnを法とする剰余
の計算を行うか、又は何もしない、ということを繰り返
す。そして、m回目のSHIFT&MOD回路100か
らの出力を受け取り、加算及びnを法とする剰余の計算
を行うか、又は何もしないか、の処理の後、第2ADD
&MOD回路150が保持している値を、第2レジスタ
160に入力する。そして、第2ADD&MOD回路1
50の保持している値をクリアする。
When calculating B (1101001) (mod n),
After storing B (0000001) (mod n) in the second register 160, the output of the SHIFT & MOD circuit 100 is ignored for 2m times and then the output of the next m times SHIFT & MOD circuit 100 is received, and B (0000001) ( With reference to the LSB 160a of the second register 160 (mod n) (which does not always look at the same bit because a shift operation is performed for each process), the addition and the calculation of the remainder modulo n are performed. Do or do nothing. Then, after receiving the output from the m-th SHIFT & MOD circuit 100 and performing the addition and calculating the remainder modulo n or doing nothing, the second ADD
The value held by & MOD circuit 150 is input to second register 160. Then, the second ADD & MOD circuit 1
Clear the value held by 50.

【0047】以下、同様にシフト動作後のC用レジスタ
140のLSBの値を参照し、第2レジスタ160のL
SB160aの値に応じて、加算及びnを法とする剰余
の計算を行うか、又は何もしない、ということを繰り返
す。そして、m回第2ADD&MOD回路150がSH
IFT&MOD回路100から出力を受け取って処理を
行った時に、保持している値を第2レジスタ160に入
力し、保持している値をクリアする。例えば、B
(1101001) (mod n)を計算する場合には、先に説明した
部分の後に、m回SHIFT&MOD回路100からの
出力を受け取らず、次のm回は受け取って、第2レジス
タ160のLSB160aの値に従い処理を行い、結果
を再度第2レジスタ160に格納する。そして次のm回
もSHIFT&MOD回路100からの出力を受け取
り、第2レジスタのLSB160aの値に従い処理を行
い、結果を第2レジスタ160に入力する。この計算の
ための処理は、これで終了する。最終結果は第2レジス
タ160に格納されている。すなわち、C用レジスタ1
40に格納された値が、シフト動作によって無くなるま
で上記動作を繰り返せば、最終結果を第2レジスタ16
0内に得ることができる。
Hereinafter, the LSB value of the second register 160 is similarly referred by referring to the value of the LSB of the C register 140 after the shift operation.
Depending on the value of SB 160a, addition and calculation of the remainder modulo n are performed or nothing is repeated. Then, the m-th second ADD & MOD circuit 150 sets SH
When the output is received from the IFT & MOD circuit 100 and processing is performed, the held value is input to the second register 160, and the held value is cleared. For example, B
(1101001) When calculating (mod n), after the part described above, the output from the SHIFT & MOD circuit 100 is not received m times, the next m times are received, and the value of the LSB 160a of the second register 160 is received. And the result is stored in the second register 160 again. The output from the SHIFT & MOD circuit 100 is received next m times, the processing is performed according to the value of the LSB 160 a of the second register, and the result is input to the second register 160. The processing for this calculation ends here. The final result is stored in the second register 160. That is, the C register 1
If the above operation is repeated until the value stored in 40 is lost by the shift operation, the final result is stored in the second register 16.
Can be obtained within zero.

【0048】では、SHIFT&MOD回路100の詳
細を図2に示す。初期の入力Bは、レジスタ200に入
力されるようになっており、レジスタ200は第1AD
D&MOD回路110及び加算回路210に接続されて
いる。この加算回路210にはn用レジスタ130から
入力がなされており、出力はレジスタ200に戻され
る。また、先に説明したように、第1ADD&MOD回
路110がm回処理を実行した後(SHIFT&MOD
回路100の出力を無視するという処理も含む)の第1
ADD&MOD回路110の出力は、レジスタ200に
入力されるようになっている。
FIG. 2 shows the details of the SHIFT & MOD circuit 100. The initial input B is to be input to the register 200, and the register 200
It is connected to the D & MOD circuit 110 and the addition circuit 210. The input to this adder circuit 210 is made from the register for n 130, and the output is returned to the register 200. Further, as described above, after the first ADD & MOD circuit 110 executes the processing m times (SHIFT & MOD circuit).
(Including the process of ignoring the output of the circuit 100)
The output of the ADD & MOD circuit 110 is input to the register 200.

【0049】次にSHIFT&MOD回路100の動作
を説明する。初期の入力Bは、入力されるとレジスタ2
00に一旦保持され、シフト動作を行わずに加算回路2
10に出力される。この初期の入力Bを処理する時の
み、n用レジスタ130は、保持しているビットのMS
Bを検査し、"0"であれば1ビットLSBからMSBへ
シフトさせる。このシフト動作の後に、再度MSBを検
査し、"0"であれば、再度1ビットMSBへシフトさせ
る。このように、nのうちMSBから最初に"1"が現れ
るビット位置の前のビットまでの"0"を取り除く。この
値をn1とする。そして、n用レジスタ130は、この
n1を加算回路210に出力する。加算回路210は、
nを法とする剰余を計算するための回路である。nを法
とする剰余を計算するためには、nの2の補数を加算す
る。よって、n用レジスタ130からn1を受け取る
と、加算回路210は、n1の各ビットを反転(NOT処
理)させ、この反転結果と1とBとを加算する。この加
算の結果、キャリーが生じれば加算は成功、すなわち引
算が成功したことになり、引算結果b1をレジスタ20
0に入力する。もし、キャリーが生じなければ、引算は
失敗、すなわちn1>Bであるから、Bをそのままレジ
スタ200に保持しておく。
Next, the operation of the SHIFT & MOD circuit 100 will be described. The initial input B is input to register 2
00, and the addition circuit 2
It is output to 10. Only when this initial input B is processed, the register for n 130 stores the MS of the held bit.
B is checked, and if "0", 1 bit LSB is shifted from MSB. After this shift operation, the MSB is checked again, and if it is "0", it is shifted to the 1-bit MSB again. In this way, “0” from the MSB to the bit before the bit position where “1” first appears in n is removed. This value is defined as n1. Then, the register for n 130 outputs this n1 to the adding circuit 210. The addition circuit 210
This is a circuit for calculating the remainder modulo n. To calculate the remainder modulo n, add the two's complement of n. Therefore, upon receiving n1 from the register 130 for n, the adding circuit 210 inverts (NOT processing) each bit of n1 and adds 1 and B to the inverted result. As a result of the addition, if a carry occurs, the addition has succeeded, that is, the subtraction has succeeded, and the subtraction result b1 is stored in the register 20.
Enter 0. If no carry occurs, the subtraction fails, that is, n1> B, so B is held in the register 200 as it is.

【0050】次に、n用レジスタ130は、n1をLS
B側に1ビットシフトさせ、その結果を加算回路210
に出力する。この値をn2とする。加算回路210は、
レジスタ200からそれが保持している値を受け取り、
その値(b1又はB)とn2の各ビットを反転させた値と
1とを加算する。この加算の結果、キャリーが生じれば
引算は成功であり、引算の結果b2をレジスタ200に
格納する。引算が失敗であれば、レジスタ200に記憶
してあった値を保持する。
Next, the register for n 130 sets n1 to LS.
B is shifted by one bit, and the result is added to an adder 210
Output to This value is defined as n2. The addition circuit 210
Receives the value it holds from register 200,
The value (b1 or B), the value obtained by inverting each bit of n2, and 1 are added. If a carry occurs as a result of the addition, the subtraction is successful, and the result b2 of the subtraction is stored in the register 200. If the subtraction fails, the value stored in the register 200 is held.

【0051】このような処理を、nx(xは正の整数)
=nとなり、このnが加算回路210にて処理されるま
で繰り返す。このようにすると、B (mod n)を少ない
ハードウエアにて実行することができようになる。
Such processing is performed by nx (x is a positive integer)
= N, and this is repeated until this n is processed by the adding circuit 210. In this way, B (mod n) can be executed with a small amount of hardware.

【0052】上記の処理の例を説明する。B=1000
1,n=00111とすると、nを法とする剰余は00
011である。まず、nをMSB側にシフトさせると、
n1=11100となる。11100の各ビットを反転
した値は、00011である。よって、00011と0
0001(=1)と10001とを加算すると、キャリ
ーが生成されないので、レジスタ200はB=1000
1を保持する。次に、n1=11100を1ビットLS
B側にシフトさせ、n2=01110を得る。0111
0の各ビットを反転した値は10001である。よっ
て、10001と00001とレジスタ200からの1
0001を加算すると、キャリーが生じて、00011
を得ることができる。よって、この値をレジスタ200
に格納する。次に、n2=01110を1ビットLSB
側にシフトさせ、n3=00111を得る。このn3はn
と同じであるから、このn3の処理が終われば、Bのn
を法とする剰余は計算されたことになる。00111の
各ビットを反転された値は11000であり、0000
1とレジスタ200に格納された00011とを加算す
ると、キャリーが発生しない。よって、レジスタ200
に格納された値を保持する。これにて処理は終了である
から、00011がBのnを法とする剰余となり、最初
に示した値と一致しており、上記の処理にて問題ないこ
とが分かった。
An example of the above processing will be described. B = 1000
1, n = 00111, the remainder modulo n is 00
011. First, when n is shifted to the MSB side,
n1 = 1100. The value obtained by inverting each bit of 11100 is 00011. Therefore, 00011 and 0
When 0001 (= 1) and 10001 are added, no carry is generated, so the register 200 stores B = 1000
Hold 1 Next, n1 = 11100 is converted to 1-bit LS
Shift to the B side to obtain n2 = 01110. 0111
The value obtained by inverting each bit of 0 is 10001. Therefore, 10001 and 00001 and 1 from the register 200
When 0001 is added, carry occurs, and 00011
Can be obtained. Therefore, this value is stored in register 200
To be stored. Next, n2 = 0110 is converted to 1-bit LSB.
To obtain n3 = 00111. This n3 is n
When the processing of n3 is completed, n of B
The remainder modulo is calculated. The value obtained by inverting each bit of 00111 is 11000, and 0000 is obtained.
When 1 is added to 00011 stored in the register 200, no carry occurs. Therefore, register 200
Holds the value stored in. Since the process is now completed, 00011 is the remainder of B modulo n, which is consistent with the value shown first, indicating that there is no problem in the above process.

【0053】Bのnを法とする剰余の値はB11である。
このB11は、第1ADD&MOD回路110及び第2A
DD&MOD回路150へ出力される。次に実施される
処理は、このB11をMSB側に1ビットシフトさせ(す
なわち2倍し)、その結果を加算回路210に入力する
ことである。そして加算回路210は、n用レジスタ1
30からnを得て、nの各ビットを反転させた値と1と
B11をシフトさせた値とを加算する。キャリーが発生す
れば、引算成功で、その引算結果をレジスタ200に格
納する。キャリーが発生しなければ、B11をシフトさせ
た値をレジスタ200に格納する。レジスタ200に格
納された値はB12である。このB12は、第1及び第2A
DD&MOD回路に出力される。このシフト動作は、レ
ジスタ200がシフトレジスタとして動作してもよい
し、加算回路210が1ビットシフトした形でレジスタ
200の値を受け取るようにしてもよい。
The remainder of B modulo n is B11.
This B11 is composed of the first ADD & MOD circuit 110 and the second A
Output to DD & MOD circuit 150. The processing to be performed next is to shift B11 by one bit to the MSB side (that is, double it) and input the result to the addition circuit 210. Then, the adder circuit 210 outputs the n register 1
N is obtained from 30 and the value obtained by inverting each bit of n and the value obtained by shifting 1 and B11 are added. If a carry occurs, the subtraction is successful and the result of the subtraction is stored in the register 200. If no carry occurs, the value obtained by shifting B11 is stored in the register 200. The value stored in the register 200 is B12. This B12 is the first and second A
Output to DD & MOD circuit. In this shift operation, the register 200 may operate as a shift register, or the addition circuit 210 may receive the value of the register 200 in a form shifted by one bit.

【0054】以上のような処理をB1mが生成されるまで
繰り返す。B1mの第1ADD&MOD回路110におけ
る処理が終了すると、レジスタ200には処理の結果が
入力される。レジスタ200は、その処理結果を保持
し、第2ADD&MOD回路150に出力する。この処
理結果はB21である。第1ADD&MOD回路110
は、B21を有しており、処理しないでもよい。そして、
先に示したように、B21を1ビットMSB側にシフトさ
せ、加算回路210にて、シフト結果と1とnの各ビッ
トを反転させた値とを加算する。加算においてキャリー
が生じれば、加算結果をレジスタ200に格納し、キャ
リーが生じなければ、シフト結果をレジスタ200に格
納する。この値がB22である。このB22は、第1及び第
2ADD&MOD回路に出力する。以上のような処理を
B2m、そしてBmmが生成されるまで繰り返す。
The above processing is repeated until B1m is generated. When the processing of B1m in the first ADD & MOD circuit 110 is completed, the result of the processing is input to the register 200. The register 200 holds the processing result and outputs the result to the second ADD & MOD circuit 150. This processing result is B21. First ADD & MOD circuit 110
Has B21 and may not be processed. And
As described above, B21 is shifted to the MSB side by one bit, and the adder 210 adds the shift result and a value obtained by inverting each bit of 1 and n. If a carry occurs in the addition, the result of the addition is stored in the register 200, and if no carry occurs, the result of the shift is stored in the register 200. This value is B22. This B22 is output to the first and second ADD & MOD circuits. The above processing is repeated until B2m and Bmm are generated.

【0055】次に第1ADD&MOD回路110の詳細
を図3に示す。第1ADD&MOD回路110は、アキ
ュムレータ250と切換回路260とにより構成され
る。アキュムレータ250は、加算回路250aと加算
の結果が格納されるレジスタを含んでいる。第1ADD
&MOD回路110は、加算計算及びMod計算を行う
ので、加算回路250aには、SHIFT&MOD回路
100及びn用レジスタ130の双方からの入力があ
る。切換回路260は、加算回路250aに接続されて
いる。アキュムレータ250の出力は、第1レジスタ1
20及びSHIFT&MOD回路100の双方に接続さ
れている。
Next, the details of the first ADD & MOD circuit 110 are shown in FIG. The first ADD & MOD circuit 110 includes an accumulator 250 and a switching circuit 260. Accumulator 250 includes an adder circuit 250a and a register in which the result of the addition is stored. 1st ADD
Since the & MOD circuit 110 performs addition calculation and Mod calculation, the addition circuit 250a has inputs from both the SHIFT & MOD circuit 100 and the register 130 for n. The switching circuit 260 is connected to the adding circuit 250a. The output of the accumulator 250 is the first register 1
20 and the SHIFT & MOD circuit 100.

【0056】この回路の動作を次に説明する。最初にS
HIFT&MOD回路から初期の入力B11を受け取る。
このB11は、先に説明したようにLSBを削った形で第
1レジスタ120に出力するようにしても、そのまま出
力するようにしてもよい。B11のLSBの値が1であっ
た場合には、加算回路250aはB11とレジスタ(図示
せず)の値(ここでは0)とを加算する。B11のLSB
の値が0であった場合には、加算回路250aは動作し
ない。通常は、この切換を切換回路260が指示する。
但し、B11のLSBを削った形で第1レジスタ120に
出力する場合には、このLSBの値を切換回路260の
出力として用いる。そうでない場合には、LSB120
aを介して入力される値に従って、切換回路260は動
作を切り換る。
Next, the operation of this circuit will be described. First S
An initial input B11 is received from the HIFT & MOD circuit.
This B11 may be output to the first register 120 with the LSB removed as described above, or may be output as it is. When the value of the LSB of B11 is 1, the adding circuit 250a adds B11 to the value (here, 0) of a register (not shown). LSB of B11
Is zero, the adding circuit 250a does not operate. Usually, this switching is instructed by switching circuit 260.
However, when the LSB of B11 is output to the first register 120 with the LSB removed, the value of this LSB is used as the output of the switching circuit 260. Otherwise, LSB 120
The switching circuit 260 switches the operation according to the value input via a.

【0057】また、アキュムレータ250内のレジスタ
に0が格納されている場合には、SHIFT&MOD回
路100からの入力は既にnを法とする剰余も計算され
ているので、加算回路を何等動作させずにアキュムレー
タ250内のレジスタに受信した値を格納するように切
換回路260は命令することも出来る(B11のLSB又
はLSB120aの値が1の場合)。
When 0 is stored in the register in the accumulator 250, the input from the SHIFT & MOD circuit 100 has already calculated the remainder modulo n, so that the addition circuit is not operated at all. The switching circuit 260 can also instruct the register in the accumulator 250 to store the received value (when the value of the LSB or LSB 120a of B11 is 1).

【0058】B11のLSB又はLSB120aの値が1
であるならば、次に、切換回路260は加算回路250
aにn用レジスタ130からの値を用いるように命令す
る。このnを法とする剰余の計算は、先に説明したよう
に、nの2の補数の加算であり、加算回路250aは、
nの各ビットを反転させた値と1とアキュムレータ25
0内のレジスタに保持された値とを加算する。加算した
結果、キャリーが発生すれば加算結果をアキュムレータ
250内のレジスタに格納し、そうでなければ、アキュ
ムレータ250内のレジスタの値を保持する。
When the value of the LSB or LSB 120a of B11 is 1
, Then, the switching circuit 260
a is instructed to use the value from the register 130 for n. The calculation of the remainder modulo n is the addition of two's complement of n as described above, and the addition circuit 250a
n and the value obtained by inverting each bit of n, 1 and the accumulator 25
The value held in the register within 0 is added. As a result of the addition, if a carry occurs, the addition result is stored in a register in accumulator 250; otherwise, the value of the register in accumulator 250 is held.

【0059】さらに、B12が入力された場合、切換回路
260はLSB120aの値を参照し、アキュムレータ
250をホールドさせるか否か判断する。LSB120
aの値が1であれば、切換回路260はB12を受け取る
ように命じ、加算回路250aにて、アキュムレータ2
50内のレジスタと加算する。加算の後に、切換回路2
60は、nを法とする剰余を計算するために、n用レジ
スタ130から出力を受け取るように命じる。以下、動
作は同様である。
Further, when B12 is input, the switching circuit 260 refers to the value of the LSB 120a and determines whether or not to hold the accumulator 250. LSB120
If the value of a is 1, the switching circuit 260 instructs to receive B12, and the accumulator 2
Add to the register in 50. After the addition, the switching circuit 2
60 instructs to receive the output from the register for n 130 to calculate the remainder modulo n. Hereinafter, the operation is the same.

【0060】B1mが入力され、切換回路260にて加算
及びnを法とする剰余の計算を実行するか、保持してい
る値をホールドするかを命じられ、その通り処理した後
にアキュムレータ250内のレジスタに保持されている
値は、第1レジスタ120及びSHIFT&MOD回路
100に出力される。この際に、B11が入力された時と
同様にLSBを削った形で第1レジスタ120に出力す
ることも、そのまま出力することもできる。いずれにし
ても、B1mが処理されるとB2 (mod n)が計算されたこ
ととなるので、このB2 (mod n)のLSBの値が1であ
れば、アキュムレータ250内のレジスタに保持された
値をクリアしないで保持しておく。一方、B2 (mod n)
のLSBが0である場合には、アキュムレータ250内
のレジスタの値をクリアする。これにて、B21に対する
処理が終了したことになる。
B1m is input, and the switching circuit 260 is instructed to execute addition and calculation of the remainder modulo n or to hold the held value. The value held in the register is output to the first register 120 and the SHIFT & MOD circuit 100. At this time, the LSB can be output to the first register 120 in the same manner as when B11 is input, or can be output as it is. Anyway, since the B1m is processed B 2 (mod n) is the calculated, if the value of the LSB is 1 the B 2 (mod n), held in the register in the accumulator 250 The value is kept without clearing. On the other hand, B 2 (mod n)
, The value of the register in the accumulator 250 is cleared. This completes the process for B21.

【0061】そして、Bmmに対する処理までこのような
処理を繰り返す。以上の構成は一例であって、n用レジ
スタ130からの入力は加算回路250aに入力される
前に処理が必要であるから、切換回路260その他にて
処理をして入力するようにしてもよい。また、切換回路
260が、LSB120aの出力が0を示している時
は、アキュムレータ250にクロックを入力しないよう
に、又はクロックをスキップするように命じることもで
きる。このようにすると、消費電力を抑えることができ
る。
Then, such processing is repeated until the processing for Bmm. The above configuration is an example, and the input from the register for n 130 needs to be processed before being input to the addition circuit 250a. Therefore, the input may be processed and input by the switching circuit 260 and the like. . When the output of the LSB 120a indicates 0, the switching circuit 260 can also instruct the accumulator 250 not to input the clock or to skip the clock. In this way, power consumption can be reduced.

【0062】また、加算するごとにMod計算を実施す
ると動作が遅くなる。そこで、nを法とする剰余のため
の計算をまとめて実施するように変形することができ
る。これは、LSB120aの値が0の場合アキュムレ
ータ250は動作しないので、この時間を利用するもの
である。まず、切換回路260は、LSB120aの値
が0であることを確認し、さらにアキュムレータ250
内のレジスタに格納された値が正の値であるか検査す
る。そして両条件とも満たされた場合には、例えば4n
を引算するように命じる。この4nの引算は、n用レジ
スタ130から取り出した値を4倍し(2ビットMSB
側にシフトし)、この値の各ビットを反転させ、反転に
より生じた値と1とアキュムレータ250内のレジスタ
の値とを加算することにより得られる。4という数字は
任意であり、一般的には正の整数倍することができる
が、nをシフト処理することにより得られるようにすれ
ば簡単であるから、2、4、8、16...倍するとよ
い。但し、余りに大きい値を引算すると、その分アキュ
ムレータ内のレジスタのビット数が増加する。また、余
り小さい値を引算すると、当該処理を何回も行わなけれ
ばならなくなるので、消費電力が増加する。よって、B
のビット数等を勘案して大きさを決めるべきである。ま
た、LSB120aの出力が1の時に行ってもよいが、
加算の後に行われるため、処理時間は"0"の時に実施す
るよりも少し増加する。
If the Mod calculation is performed every time the addition is performed, the operation becomes slow. Therefore, a modification can be made so that calculations for the remainder modulo n are collectively performed. Since the accumulator 250 does not operate when the value of the LSB 120a is 0, this time is used. First, the switching circuit 260 confirms that the value of the LSB 120a is 0, and further checks the accumulator 250
Check that the value stored in the register inside is positive. If both conditions are satisfied, for example, 4n
Command to subtract. This subtraction of 4n multiplies the value taken out from the register 130 for n by 4 (2-bit MSB).
Side), inverting each bit of this value, and adding the value resulting from the inversion to 1 and the value of the register in the accumulator 250. The number 4 is arbitrary and can generally be multiplied by a positive integer. However, it is simple if n can be obtained by performing a shift process, so that 2, 4, 8, 16,. . . You should double it. However, if an excessively large value is subtracted, the number of bits of the register in the accumulator increases accordingly. In addition, if a value that is too small is subtracted, the processing must be performed many times, so that power consumption increases. Therefore, B
The size should be determined in consideration of the number of bits and the like. Also, this may be performed when the output of the LSB 120a is 1,
Since the processing is performed after the addition, the processing time is slightly increased as compared with the case where the processing is performed at "0".

【0063】このように4nを引いた後は、次にLSB
120aの値が0であって、アキュムレータ250内の
レジスタの値が正になるまで、単にSHIFT&MOD
回路100からの出力を加算すればよい(LSB120
aの値が1である場合)。よって、切換回路260は、
一旦4nの引算を行った場合には、先の条件を再度満た
すまで、nを法とする剰余の計算のための処理に動作を
切り換えることは命じない。そして、B1m,B2m,B3
m...が入力されて、その処理をアキュムレータ25
0が行った(何もしないということも処理とする)場合
には、切換回路260はアキュムレータ250内のレジ
スタに格納されている値を確認する。すなわち、アキュ
ムレータ250内のレジスタに格納されている値が負の
値であれば、当該値が正になるまで、切換回路260は
加算回路250aにn用レジスタ130からのnをレジ
スタの値を加算するように命ずる。また、正である場合
には、切換回路260は、アキュムレータ250内のレ
ジスタに格納されている値から4nを引算するように命
じる。また、引算の結果が負でなければ、負になるまで
4nを引算する。そして、負になった後は、先と同様で
あって、切換回路260は、正になるまでnを加算する
ように加算回路250aに命ずる。この加算する値は、
nではなくyn(yは正の整数)であってもよい。
After subtracting 4n in this manner, the next LSB
Until the value of the register 120a is 0 and the value of the register in the accumulator 250 becomes positive, only SHIFT & MOD
The output from the circuit 100 may be added (LSB 120
when the value of a is 1). Therefore, the switching circuit 260
Once the subtraction of 4n is performed, it is not instructed to switch the operation to the processing for calculating the remainder modulo n until the above condition is satisfied again. And B1m, B2m, B3
m. . . Is input, and the processing is performed by the accumulator 25.
If 0 is performed (it is also assumed that no processing is performed), the switching circuit 260 checks the value stored in the register in the accumulator 250. That is, if the value stored in the register in the accumulator 250 is a negative value, the switching circuit 260 adds the value of the register from the register for n 130 to the adding circuit 250a until the value becomes positive. Order to do so. If it is positive, the switching circuit 260 commands the subtraction of 4n from the value stored in the register in the accumulator 250. If the result of the subtraction is not negative, 4n is subtracted until the result becomes negative. After becoming negative, the switching circuit 260 instructs the adding circuit 250a to add n until it becomes positive. The value to be added is
Instead of n, it may be yn (y is a positive integer).

【0064】処理は少々複雑になるが、このようにする
とnを法とする剰余を計算する回数は減るので、結果的
に全体の処理速度が早くなり、且つ消費電力も少なくて
済む。また、最後に不規則な修正動作を行うので、キー
を盗みにくくできる。但し、アキュムレータ250内の
レジスタのビット数は多少多くなる。
Although the processing becomes slightly complicated, this reduces the number of times of calculating the remainder modulo n, so that the overall processing speed is increased and the power consumption is reduced. In addition, since an irregular correction operation is performed at the end, it is difficult to steal a key. However, the number of bits of the register in the accumulator 250 is slightly increased.

【0065】消費電力軽減という観点から、第1レジス
タ120にも工夫を施すことができる。先の説明では、
第1レジスタ120はシフトレジスタで、第1ADD&
MOD回路110にSHIFT&MOD回路100の出
力が入力されるごとにシフトさせていたが、シフトさせ
るレジスタのビット数が多くなると、消費電力が多くな
ってしまう。そこで、例えばLSBから8ビットだけは
1ビットずつシフトさせ、この8ビットが全てシフトさ
れてしまった場合には、残りのビットをすべて8ビット
シフトさせる。そして、またLSBから8ビットだけを
1ビットづつシフトさせ、8ビットすべてシフトさせて
しまった場合に、さらに残りのビットをすべて8ビット
シフトさせる、といった処理を繰り返すと、消費電力を
軽減することができる。なお、第2レジスタ160及び
C用レジスタ140も同様な構成にすることができる。
なお、8ビットというのは任意であって、一般的には2
以上の整数ビットである。但し、あまり小さい値である
と効果が減ぜられる。
From the viewpoint of reducing power consumption, the first register 120 can be devised. In the description above,
The first register 120 is a shift register, and the first ADD &
The shift is performed every time the output of the SHIFT & MOD circuit 100 is input to the MOD circuit 110. However, if the number of bits of the register to be shifted increases, the power consumption increases. Therefore, for example, only 8 bits from the LSB are shifted one bit at a time, and if all these 8 bits have been shifted, the remaining bits are all shifted by 8 bits. Further, when only the 8 bits are shifted from the LSB by one bit at a time and all the 8 bits are shifted, the remaining bits are all shifted by 8 bits, so that the power consumption can be reduced. it can. Note that the second register 160 and the C register 140 can have the same configuration.
Note that 8 bits is arbitrary and generally 2 bits
These are the above integer bits. However, if the value is too small, the effect is reduced.

【0066】次に、第2ADD&MOD回路150の詳
細を図4に示す。基本的な構成は、第1ADD&MOD
回路110と同様であるが、切換回路310にはC用レ
ジスタ140からCのLSBが入力されるようになって
いる。先に述べたように、第2ADD&MOD回路15
0は、C用レジスタ140からのCのLSBに応じて処
理を切り換えるからである。すなわち、CのLSB(シ
フトされてLSBになったものを含む)が0であれば、
SHIFT&MOD回路100からの第2ADD&MO
D回路150への入力をm回処理しないことになり、1
であれば、SHIFT&MOD回路100からの入力を
m回処理するようになる。その後に、LSB160aの
値に応じて実際に加算及びMod計算を実施するか判断
する。
Next, the details of the second ADD & MOD circuit 150 are shown in FIG. Basic configuration is 1st ADD & MOD
The circuit is similar to the circuit 110 except that the LSB of C is input from the C register 140 to the switching circuit 310. As described above, the second ADD & MOD circuit 15
This is because “0” switches the processing according to the LSB of C from the C register 140. That is, if the LSB (including the shifted LSB) of C is 0,
Second ADD & MO from SHIFT & MOD circuit 100
The input to the D circuit 150 is not processed m times, and 1
Then, the input from the SHIFT & MOD circuit 100 is processed m times. After that, it is determined whether the addition and the Mod calculation are actually performed according to the value of the LSB 160a.

【0067】また、第1ADD&MOD回路110のよ
うにB1m,B2m,B3m,..の処理結果をSHIFT&
MOD回路100にフィードバックすることはない。さ
らに、B1m,B2m,B3m,..の処理を行って、その処
理結果を第2レジスタ160に出力した後は、必ずアキ
ュムレータ300内のレジスタ(図示せず)の値はクリ
アされる。また、初期値B11を第2レジスタ160に入
力することもない。これは、第2レジスタ160に既に
初期値が与えられているからである。後の動作は、第1
及び第2ADD&MOD回路にて差はない。
Also, as in the first ADD & MOD circuit 110, B1m, B2m, B3m,. . SHIFT &
There is no feedback to the MOD circuit 100. Further, B1m, B2m, B3m,. . After outputting the processing result to the second register 160, the value of the register (not shown) in the accumulator 300 is always cleared. Further, the initial value B11 is not input to the second register 160. This is because the initial value has already been given to the second register 160. Subsequent operation is the first
And the second ADD & MOD circuit does not differ.

【0068】ここではC用レジスタ140のLSBの値
によりアキュムレータ300は全く動作しないようにな
るので、そのような場合には、切換回路310が、アキ
ュムレータ300に入力されるクロックを停止すること
により余分な電力を消費しないようにすることができ
る。
Here, accumulator 300 does not operate at all according to the value of LSB of register 140 for C. In such a case, switching circuit 310 stops the clock input to accumulator 300 to save extra time. Power consumption can be prevented.

【0069】なお、SHIFT&MOD回路100の変
形も考えられる。上で述べた例では、通常のサイクルで
は、1ビット・シフトの後にnを減じて(−nを足し
て)、その値が正であれば、nを減じた後の値を格納
し、負であれば、1ビット・シフトの結果を格納してい
た。この処理を簡単な擬似コードで表現すると以下のよ
うになる。但し、DBはレジスタ200の値である。 なお、RSA演算におけるnは奇数なので、DB=0と
なることはなく、実際のDBの範囲は0<DB<nであ
る。
The SHIFT & MOD circuit 100 may be modified. In the example described above, in a normal cycle, n is subtracted (added by -n) after one bit shift, and if the value is positive, the value after n is stored and negative is stored. If so, the result of the 1-bit shift has been stored. This processing is represented by simple pseudo code as follows. Here, DB is the value of the register 200. Since n in the RSA operation is an odd number, DB = 0 does not hold, and the actual DB range is 0 <DB <n.

【0070】これに対しここでは、DBに正負の値を許
し、−n≦DB<nの範囲に収めることとする。すなわ
ち、以下のような擬似コードで表される計算をSHIF
T&MOD回路100が実行するよう変形する。 但し、nは奇数なので、実際には−n<DB<nであ
る。
On the other hand, in this case, positive and negative values are allowed for DB, and the value is within the range of -n ≦ DB <n. That is, the calculation represented by the following pseudo code is performed by SHIF
The T & MOD circuit 100 is modified to execute. However, since n is an odd number, actually -n <DB <n.

【0071】このようにすると上で述べた実施例のよう
に2DB−nの結果を判断して2DB−n又は2DBを
レジスタ200に格納するというような制御を行う必要
がなくなり、DBの正負によって事前に加算か減算かを
決定することができる。よって、処理が高速化される。
さらに、上の実施例では第1及び第2ADD&MOD回
路にて一方的に正の数(DB)を加えていくので、加算
するごとにnを減じたり、適宜4nを減じる等の補正を
行う必要があった。これに対しこの変形ではDBは正又
は負の値を行き来するので、そのまま補正を行わずとも
演算終了後にほぼ所望の値近くになっている。よって、
途中で補正演算を行わなくとも済むようになり、消費電
力の低減及び第1及び第2ADD&MOD回路の処理高
速化がなされる。
This eliminates the need to determine the result of 2DB-n and store 2DB-n or 2DB in the register 200 as in the above-described embodiment. The addition or the subtraction can be determined in advance. Therefore, the processing speed is increased.
Further, in the above embodiment, the first and second ADD & MOD circuits unilaterally add a positive number (DB). Therefore, it is necessary to perform a correction such as reducing n each time the addition is performed or appropriately reducing 4n. there were. On the other hand, in this modification, the DB alternates between a positive value and a negative value. Therefore, even if the correction is not performed as it is, the value is almost close to a desired value after the calculation is completed. Therefore,
This eliminates the need for performing a correction operation on the way, thereby reducing power consumption and increasing the processing speed of the first and second ADD & MOD circuits.

【0072】なお、−4nの補正を行う場合にはnの2
ビット・シフト配線が必要となるが、この配線が不要と
なり、加算回路の構成が簡単になるという効果も奏す
る。さらに回路レイアウトによっては寄生容量も削減で
きるので、それによる高速化も見込める。
When the correction of -4n is performed, 2 of n is used.
Although bit shift wiring is required, this wiring is not required, and the effect of simplifying the configuration of the adder circuit is also achieved. In addition, since the parasitic capacitance can be reduced depending on the circuit layout, a higher speed can be expected.

【0073】さらに上の実施例でSHIFT&MOD回
路100は、必ず2DB (mod n)計算を実施してい
た。しかし、第1ADD&MOD回路110は第1レジ
スタ120のLSB120aが1の場合のみ2DB(mo
d n)を加算し、第2ADD&MOD回路150はC用
レジスタ140のLSBが1であって第2レジスタ16
0のLSB160aが1の場合のみ2DB(mod n)を
加算するので、第1及び第2ADD&MOD回路の両方
が加算を行わない場合も生じる。よって、このように加
算を行わない場合には、2DB(mod n)を計算する必
要はなく、この計算をスキップして4DB(mod n)を
計算するようにすると、計算に必要なクロック数を減ら
すことができる。SHIFT&MOD回路100が4D
B(mod n)を計算してもよい条件を以下に記す。 (1)C用レジスタ140のLSBが0であって、第1
レジスタ120のLSB120aが0である場合。 (2)C用レジスタ140のLSBが1であるが、第1
レジスタ120のLSB120aが0で且つ第2レジス
タ160のLSB160aも0である場合。このような
条件が発生する確率はおよそ30%であり、その分処理
が高速化される。
In the above embodiment, the SHIFT & MOD circuit 100 always performs 2DB (mod n) calculation. However, the first ADD & MOD circuit 110 outputs 2DB (mo) only when the LSB 120a of the first register 120 is 1.
dn), and the second ADD & MOD circuit 150 determines that the LSB of the C register 140 is 1 and the second register 16
Since 2DB (mod n) is added only when the LSB 160a of 0 is 1, there is also a case where both the first and second ADD & MOD circuits do not add. Therefore, when the addition is not performed in this way, it is not necessary to calculate 2DB (mod n). If this calculation is skipped and 4DB (mod n) is calculated, the number of clocks required for the calculation is reduced. Can be reduced. SHIFT & MOD circuit 100 is 4D
The conditions under which B (mod n) may be calculated are described below. (1) When the LSB of the C register 140 is 0,
When the LSB 120a of the register 120 is 0. (2) Although the LSB of the C register 140 is 1, the first
The case where the LSB 120a of the register 120 is 0 and the LSB 160a of the second register 160 is also 0. The probability that such a condition will occur is about 30%, and the processing speeds up accordingly.

【0074】では、4DB(mod n)を計算する際のS
HIFT&MOD回路100の処理について説明する。
なお、DBの範囲は−n≦DB<nとする。また、DB
は符号付の2進数になるので、先頭の符号ビットが0で
あれば正又は0の数、1であれば負の数となる。nは正
の値しかとらないので、符号ビットはない。よって、S
HIFT&MOD回路100は以下のような表に示され
た計算を実行する。
Then, when calculating 4DB (mod n), S
The processing of the HIFT & MOD circuit 100 will be described.
Note that the range of DB is -n ≦ DB <n. Also, DB
Is a signed binary number, so if the leading sign bit is 0, it is a positive or 0 number, and if it is 1, it is a negative number. Since n can only take a positive value, there is no sign bit. Therefore, S
The HIFT & MOD circuit 100 performs the calculations shown in the table below.

【表1】 (a)はDBが正又は0の場合、(b)はDBが負の場
合を示している。表1のDBの行はDBの先頭4ビット
(符号ビットを含む)の値の場合分けを示しており、n
は先頭の2ビットの値の場合分けをしている(実質的に
は2ビット目の値による場合分け)。また表1中xは0
又は1ということを示している。
[Table 1] (A) shows the case where DB is positive or 0, and (b) shows the case where DB is negative. The row of DB in Table 1 shows the case of the value of the first 4 bits (including the sign bit) of DB, and n
Indicates the case of the value of the first two bits (substantially the case of the value of the second bit). In Table 1, x is 0
Or 1.

【0075】このような処理を実施することにより、D
Bは−n≦DB<nの範囲に収まり、且つ第1及び第2
ADD&MOD回路が動作しない期間を省略することが
できる。なお、これまではB、C及びnが例えば102
4ビットで各種レジスタもそれに合わせたビット数であ
る場合を示してきた。しかし、入力データのビット数が
レジスタ長に満たないと通常LSB側から詰めてレジス
タに格納するので、表1のようにMSBから数ビット検
査して演算の種類を決定することができなくなる。よっ
て、このような場合にはデータをMSB側から詰めてい
き、余ったLSB側には0を詰める。この詰めた0の個
数をqとすると、このようなレジスタへの値の詰め方は
q倍した法の上で演算を行うことを意味する。この場
合、最後に2qで割れば結果は変わらない。例えば8 (m
od 3)=2であるが、800 (mod300)=200で、1
00分の1すれば2となり、この論理が正しいことが分
かる。
By performing such processing, D
B is in the range of -n ≦ DB <n, and the first and second
A period during which the ADD & MOD circuit does not operate can be omitted. Heretofore, B, C and n are, for example, 102
It has been shown that each register has 4 bits and the number of bits corresponding to each register. However, if the number of bits of the input data is less than the register length, the data is usually packed from the LSB side and stored in the register, so that it is not possible to determine the type of operation by inspecting several bits from the MSB as shown in Table 1. Therefore, in such a case, the data is packed from the MSB side, and 0 is filled in the surplus LSB side. Assuming that the number of the padded zeros is q, such a method of padding the value into the register means that the operation is performed on a method multiplied by 2q . In this case, dividing by 2q at the end does not change the result. For example, 8 (m
od 3) = 2, but 800 (mod 300) = 200 and 1
If it is 1/100, it becomes 2 and it can be seen that this logic is correct.

【0076】LSB側から詰めてレジスタに格納する場
合、DBの符合は正と負を行き来するので、それに伴い
MSB側の余ったビットが'000...'と'111...'の
反転を繰り返す。これに対し、MSB側からレジスタに
詰めて格納する場合、LSB側の余ったビットは'...0
00'から反転せず、消費電力の低減につながる。以上
のようにすると、DBの先頭4ビットとnの先頭から2
ビット目の計5ビットを参照することにより、演算内容
を決定することができる。
When the data is stored in the register from the LSB side, the sign of the DB is switched between positive and negative, so that the extra bits on the MSB side are inverted from '000 ...' and '111 ...'. repeat. On the other hand, when the data is packed and stored in the register from the MSB side, the extra bits on the LSB side are '... 0
It does not reverse from 00 ', which leads to a reduction in power consumption. As described above, the first 4 bits of the DB and 2 from the top of n
The operation content can be determined by referring to the five bits in total.

【0077】場合によっては、4DBの計算ではなく6
DB(3ビット・シフト)及び8DB(4ビット・シフ
ト)を計算するようにすることも可能な場合があるが、
2ビット・シフトを行う場合に3nが必要になったよう
に、5n,6n,7n,8n,9n,10n等が必要に
なるので、あまり現実的でない。
In some cases, instead of calculating 4DB, 6
While it may be possible to calculate DB (3 bit shift) and 8DB (4 bit shift),
Just as 3n is required when performing a 2-bit shift, 5n, 6n, 7n, 8n, 9n, 10n, etc. are required, which is not very practical.

【0078】さらに表1の演算方法を変形する事も可能
である。表1では3nが必要となるので、これを用いな
いような変形である。すなわち、以下の擬似コードで示
される処理をSHIFT&MOD回路100が実施する
ようにする。 なお、'000xxx' 又は'111xxx'は計算結果の上位3ビッ
トを検査するということを意味する。なお、この条件は
最終的にレジスタ200に格納される値が[−n,n)
の範囲に入るか否かの条件である。この範囲に入れば、
さらに2倍することができ、そうでない場合には2倍す
ることができず、2DB−nを格納することになる。こ
のような処理を実施して効果があるのは10%程度と考
えられている。
Further, it is possible to modify the calculation method of Table 1. In Table 1, since 3n is required, the modification is not used. That is, the processing indicated by the following pseudo code is performed by the SHIFT & MOD circuit 100. '000xxx' or '111xxx' means that the upper 3 bits of the calculation result are checked. In this condition, the value finally stored in the register 200 is [-n, n).
Is the condition of whether or not it falls within the range. If you enter this range,
It can be further doubled, otherwise it cannot be doubled and 2DB-n is stored. It is considered that the effect of performing such processing is about 10%.

【0079】なお、本発明で使用する加算回路は高速で
長いビット長を扱う。フルアダーを例えば1024段つ
なぐと、ゲートディレイだけで1μsec程度かかり、動
作速度は1MHzに制限される。加算される2つの値を
1、2、3、4、,,,,44、45というように区切
り、区切られた中で加算を済ませてから1インクリメン
タで正しい値に補正すると、フルアダーを並べる回路に
比べて2倍強の回路サイズで、1024ビットであれば
20倍程度の動作速度を得ることができる。トータルの
ビット数は1...Nを加算した値になるので、0.5
N(N+1)>1024なるNまで分割していけばN段
のゲートディレイでアダーを組む事ができる。すなわ
ち、512ビットの場合はアダーで32段ディレイと1
インクリメンタで2ディレイで34段ディレイ、102
4ビットの場合には45段ディレイ、2048ビットの
場合には66段ディレイである。なお、この技術は例え
ば、情報処理第37巻第1号p80−85,情報処理学
会発行、1996年1月に記載されている。
The addition circuit used in the present invention handles a long bit length at high speed. When connecting 1024 stages of full adders, for example, it takes about 1 μsec only by the gate delay, and the operation speed is limited to 1 MHz. When the two values to be added are separated as 1, 2, 3, 4,..., 44, 45, and the addition is completed in the separated sections, and then corrected by 1 incrementer to the correct value, the full adders are arranged. With a circuit size slightly more than twice as large as that of the circuit, an operating speed of about 20 times can be obtained with 1024 bits. The total number of bits is 1. . . N is added, so 0.5
If N (N + 1)> 1024 is divided, an adder can be formed with N stages of gate delays. That is, in the case of 512 bits, the adder has 32 stages of delay and 1
34 steps delay with 2 delays by incrementer, 102
In the case of 4 bits, there is a 45-stage delay, and in the case of 2048 bits, there is a 66-stage delay. This technique is described, for example, in Information Processing Vol. 37, No. 1, p80-85, published by the Information Processing Society of Japan, January 1996.

【0080】以上のようにすると簡単で且つ高速なBC
(mod n)を計算する回路を構成することができる。但
し、秘密キーが盗み出されないようにしなければならな
い。このためには、回路を実装したチップが解剖された
場合には破壊されるような構成にするとともに、ABI
ST(Automatic Built In Self Test)を用いてテスタ
ビリティが高く、読まれにくい回路にしたり、ダイナミ
ックラッチを用いて動作周波数を下げて解析する際に回
路の動作を不安定にする等の処置をとるべきである。ま
た、LSFR等にて秘密キーをスクランブルしておくと
より効果がある。この場合、CはC用レジスタに記憶さ
れる代わりに、生成するための回路(LFSR)が必要
となる。
In this way, a simple and fast B C
A circuit for calculating (mod n) can be configured. However, you must ensure that your secret key is not stolen. For this purpose, the chip on which the circuit is mounted is destroyed when dissected, and the ABI
Use ST (Automatic Built In Self Test) to make the circuit highly testable and difficult to read, or take measures such as making the operation of the circuit unstable when analyzing by lowering the operating frequency using a dynamic latch. Should. Further, it is more effective to scramble the secret key by LSFR or the like. In this case, a circuit (LFSR) for generating C is required instead of being stored in the register for C.

【0081】以上説明した回路は、従来技術の欄で説明
したように暗号システムの一部として利用される。例え
ば、図7のようにネットワーク1000に暗号化装置1
100及び解読装置1200が接続されているようなシ
ステムが簡単に構築できる。このネットワーク1000
には他の暗号化/解読装置が接続されていてもよい。R
SA暗号方式に従うのであれば、暗号化装置1100に
おいて、解読装置1200の公開キーeで、メッセージ
Mは、C=Me (mod n)に変換される。この処理に上で
述べた回路は非常に役に立つ。そして暗号化装置110
0はCを解読装置1200にネットワーク1000を介
して送信する。解読装置1200では、解読装置120
0の秘密キーdで、M=Cd (mod n)が計算される。こ
の処理にも上で述べた回路は非常に役に立つ。なお、暗
号方式はRSAに限定されるものではなく、例えばEl
Gamalの方式など、多くの公開鍵暗号方式で用いる
ことができる。さらに、電子署名などにもBC (mond n)
の計算は必要とされる場合があり、その場合にもこの回
路は役に立つ。
The circuit described above is used as a part of an encryption system as described in the section of the prior art. For example, as shown in FIG.
100 and the decoding device 1200 can be easily constructed. This network 1000
May be connected to another encryption / decryption device. R
According to the SA encryption method, in the encryption device 1100, the message M is converted into C = Me (mod n) using the public key e of the decryption device 1200. The circuit described above is very useful for this process. And the encryption device 110
0 transmits C to the decryption device 1200 via the network 1000. In the decryption device 1200, the decryption device 120
With a secret key d of 0, M = C d (mod n) is calculated. The circuit described above is also very useful in this process. Note that the encryption method is not limited to RSA.
It can be used in many public key cryptosystems such as the Gamal system. Furthermore, B C (mond n) is also used for electronic signatures.
May be required and the circuit is still useful.

【0082】[0082]

【効果】以上のように、キーの安全性を確保しつつ、最
小限のハードウエア資源を用いて高速にBのC乗のnの
剰余を計算する装置を提供することができた。
As described above, it is possible to provide a device for calculating the remainder of B raised to the power of C at a high speed with minimum hardware resources while ensuring the security of the key.

【図面の簡単な説明】[Brief description of the drawings]

【図1】本発明のブロック図である。FIG. 1 is a block diagram of the present invention.

【図2】SHIFT&MOD回路100の詳細を示すブ
ロック図である。
FIG. 2 is a block diagram showing details of a SHIFT & MOD circuit 100;

【図3】第1ADD&MDO回路110の詳細を示すブ
ロック図である。
FIG. 3 is a block diagram showing details of a first ADD & MDO circuit 110;

【図4】第2ADD&MOD回路150の詳細を示すブ
ロック図である。
FIG. 4 is a block diagram showing details of a second ADD & MOD circuit 150;

【図5】2進数の掛け算の説明のための図である。FIG. 5 is a diagram for explaining multiplication of binary numbers.

【図6】2進数の掛け算の説明のための図である。FIG. 6 is a diagram for explaining binary multiplication;

【図7】暗号システムのブロック図である。FIG. 7 is a block diagram of a cryptographic system.

【図8】従来技術の説明のための図である。FIG. 8 is a diagram for explaining a conventional technique.

【符号の説明】[Explanation of symbols]

100 SHIFT&MOD回路 110 第1ADD&MOD回路 120 第1レジスタ 130 n用レジスタ 140 C用レジスタ 150 第2ADD&MOD回路 160 第2レジスタ 1000 ネットワーク 1100 暗号化装置 1200 解読装置 REFERENCE SIGNS LIST 100 SHIFT & MOD circuit 110 First ADD & MOD circuit 120 First register 130 Register for n 140 Register for C 150 Second ADD & MOD circuit 160 Second register 1000 Network 1100 Encryption device 1200 Decryption device

───────────────────────────────────────────────────── フロントページの続き (72)発明者 佐藤 証 神奈川県大和市下鶴間1623番地14 日本 アイ・ビー・エム株式会社 東京基礎研 究所内 (72)発明者 新島 秀人 神奈川県大和市下鶴間1623番地14 日本 アイ・ビー・エム株式会社 東京基礎研 究所内 (56)参考文献 特開 平2−12290(JP,A) 特開 平1−302288(JP,A) 特開 昭56−42852(JP,A) (58)調査した分野(Int.Cl.7,DB名) G06F 7/72 G09C 1/00 620 G09C 1/00 650 ──────────────────────────────────────────────────の Continued on the front page (72) Inventor Satoru Sato 1623-14 Shimotsuruma, Yamato-shi, Kanagawa Prefecture IBM Japan, Ltd.Tokyo Basic Research Laboratory (72) Inventor Hideto Niijima Shimotsuruma, Yamato-shi, Kanagawa 1623-14 IBM Japan, Ltd. Tokyo Research Laboratory (56) References JP-A-2-12290 (JP, A) JP-A-1-302288 (JP, A) JP-A-56-42852 ( JP, A) (58) Fields investigated (Int. Cl. 7 , DB name) G06F 7/72 G09C 1/00 620 G09C 1/00 650

Claims (17)

(57)【特許請求の範囲】(57) [Claims] 【請求項1】BのC乗のnを法とする剰余を計算する回
路であって、 Bのnを法とした剰余を計算し且つ当該計算結果B1を
保持する処理を実行し、保持する値をシフトし且つnを
法として合同となる値を計算し且つ当該計算結果を保持
する処理を繰り返す第1回路と、 初期値としてB1を格納する第1レジスタと、 前記第1レジスタの所定位置のビットの値が1である場
合、前記第1回路の計算結果を累積する第2回路と、 初期値として1を格納する第2レジスタと、 Cを出力するC出力回路と、 前記C出力回路の出力値が1であって、前記第2レジス
タの所定位置のビットの値が1である場合、前記第1回
路の計算結果を累積する第3回路とを有し、 前記第1レジスタ及び前記第2レジスタの所定位置のビ
ットは、格納した値のLSBからMSB方向にシフト
し、 前記第1レジスタが格納した値のMSBについての処理
が終了した場合には、(a)前記第2回路の累積結果の
nを法として合同となる値を前記第1回路における前記
保持する値とし且つ前記第1レジスタに格納し、(b)
前記C出力回路の出力は、CのLSBからMSB方向に
シフトした値に変化し、(c)前記C出力回路の出力値
が1であれば前記第3回路の累積結果のnを法として合
同な値を前記第2レジスタに格納することを特徴とする
BのC乗のnを法とする剰余を計算する回路。
1. A circuit for calculating a remainder of B raised to the power of C modulo n, performing a process of calculating the remainder of B raised to n modulo and holding the calculation result B1. A first circuit for repeating a process of shifting a value and calculating a congruent value modulo n and holding the calculation result; a first register for storing B1 as an initial value; and a predetermined position of the first register A second circuit for accumulating the calculation result of the first circuit; a second register for storing 1 as an initial value; a C output circuit for outputting C; A third circuit that accumulates the calculation result of the first circuit when an output value of the first register is 1 and a value of a bit at a predetermined position of the second register is 1. The bit at the predetermined position of the second register is the LSB of the stored value. In the MSB direction, and when the processing for the MSB of the value stored in the first register is completed, (a) a value which is congruent modulo n of the accumulation result of the second circuit is set to the first value. Storing in the first register the value to be held in the circuit, and (b)
The output of the C output circuit changes from the LSB of C to a value shifted in the MSB direction. (C) If the output value of the C output circuit is 1, the output of the C output circuit is combined modulo n of the cumulative result of the third circuit. A circuit for calculating a remainder modulo n of B raised to the power of C, wherein the remainder is stored in the second register.
【請求項2】前記第1レジスタがシフトレジスタである
ことを特徴とする請求項1記載のBのC乗のnを法とす
る剰余を計算する回路。
2. The circuit according to claim 1, wherein said first register is a shift register.
【請求項3】前記第2レジスタがシフトレジスタである
ことを特徴とする請求項1記載のBのC乗のnを法とす
る剰余を計算する回路。
3. The circuit according to claim 1, wherein said second register is a shift register.
【請求項4】前記C出力回路がシフトレジスタであるこ
とを特徴とする請求項1記載のBのC乗のnを法とする
剰余を計算する回路。
4. The circuit according to claim 1, wherein said C output circuit is a shift register.
【請求項5】前記第2回路が、前記第1回路の計算結果
を累積するごとに、当該累積値のnを法とする剰余を計
算する回路を含む請求項1記載のBのC乗のnを法とす
る剰余を計算する回路。
5. The circuit according to claim 1, wherein said second circuit includes a circuit for calculating a remainder modulo n each time the calculation result of said first circuit is accumulated. A circuit for calculating the remainder modulo n.
【請求項6】前記第3回路が、前記第1回路の計算結果
を累積するごとに、当該累積値のnを法とする剰余を計
算する回路を含む請求項1記載のBのC乗のnを法とす
る剰余を計算する回路。
6. The C-th power of B according to claim 1, wherein said third circuit includes a circuit for calculating a remainder modulo n each time the calculation result of said first circuit is accumulated. A circuit for calculating the remainder modulo n.
【請求項7】前記第2回路が、前記第1レジスタの所定
位置のビットの値が0であって、前記第2回路の累積値
が正の値である場合、前記累積値からxn(xは正の整
数)引算することを特徴とする請求項1記載のBのC乗
のnを法とする剰余を計算する回路。
7. When the value of a bit at a predetermined position of the first register is 0 and the cumulative value of the second circuit is a positive value, the second circuit calculates xn (x 2. The circuit for calculating a remainder modulo n of B raised to the power of C according to claim 1, wherein subtraction is performed.
【請求項8】前記第2回路が、 前記第1レジスタに格納された値のMSBについて処理
が終了した場合、前記第2回路の累積値が正の値か否か
判断し、 正であると判断された場合には、前記累積値が負になる
までxn引算し、 負であると判断された場合には、正になるまでyn(y
は正の整数)を足し算することを特徴とする請求項7記
載のBのC乗のnを法とする剰余を計算する回路。
8. When the second circuit finishes processing on the MSB of the value stored in the first register, the second circuit determines whether or not the accumulated value of the second circuit is a positive value. If it is determined, xn is subtracted until the accumulated value becomes negative. If it is determined that the accumulated value is negative, yn (y
8. The circuit for calculating a remainder modulo n of B raised to the power of C according to claim 7, wherein the sum is a positive integer.
【請求項9】前記第3回路が、前記C出力回路の出力値
が1であって且つ前記第2レジスタの所定位置のビット
の値が0であって、前記第3回路の累積値が正の値であ
る場合、前記累積値からxn(xは正の整数)引算する
ことを特徴とする請求項1記載のBのC乗のnを法とす
る剰余を計算する回路。
9. The third circuit, wherein the output value of the C output circuit is 1, the value of a bit at a predetermined position of the second register is 0, and the accumulated value of the third circuit is positive. 2. The circuit according to claim 1, wherein xn (x is a positive integer) is subtracted from the accumulated value if the value is the value of (b).
【請求項10】前記第3回路が、 前記C出力回路の出力が1であって、前記第2レジスタ
に格納された値のMSBについての処理が終了した場
合、前記第3回路の累積値が正の値か否か判断し、 正であると判断された場合には、前記累積値が負になる
までxn引算する回路と、 負であると判断された場合には、正になるまでyn(y
は正の整数)を足し算することを特徴とする請求項9記
載のBのC乗のnを法とする剰余を計算する回路。
10. When the output of the C output circuit is 1 and the process for the MSB of the value stored in the second register is completed, the third circuit calculates the accumulated value of the third circuit. It is determined whether or not the value is a positive value. If the value is determined to be positive, a circuit for subtracting xn until the accumulated value becomes negative. yn (y
10. The circuit for calculating a remainder modulo n of B raised to the power of C according to claim 9, wherein n is a positive integer.
【請求項11】nを格納するn用レジスタをさらに含
み、 前記Bのnを法とした剰余を計算し且つ当該計算結果B
1を保持する処理において、 前記n用レジスタは、nをMSBからみて最初に1とな
るビットがMSBとなるように、nをMSB方向にシフ
トさせ、次いで当該シフトさせた値をLSB方向にBと
同一となるまで1ビットずつシフトさせ、各シフトさせ
た値を順に前記第1回路に出力し、 前記第1回路は、Bから前記n用レジスタから得た各シ
フトさせた値を引算できれば引算することを特徴とする
請求項1記載のBのC乗のnを法とする剰余を計算する
回路。
11. An n-register for storing n, wherein a remainder of said B modulo n is calculated, and said calculation result B
In the process of holding 1, the register for n shifts n in the MSB direction so that the first bit that becomes 1 when viewed from the MSB is the MSB, and then shifts the shifted value in the LSB direction. Is shifted one bit at a time until it becomes the same as above, and each shifted value is sequentially output to the first circuit. If the first circuit can subtract each shifted value obtained from B from the n register, 2. The circuit for calculating a remainder modulo n of B raised to the power C according to claim 1, wherein the subtraction is performed.
【請求項12】前記第1回路が、 前記保持する値が正である場合には、当該保持する値を
シフトし且つp・n(pは正の整数)を減じる計算を実
行し、 前記保持する値が負である場合には、当該保持する値を
シフトし且つq・n(qは正の整数)を加算する計算を
実行することを特徴とする請求項1記載のBのC乗のn
を法とする剰余を計算する回路。
12. The first circuit, if the value to be held is positive, shifts the value to be held and performs a calculation to reduce pn (p is a positive integer), 2. The method according to claim 1, further comprising, when the value to be calculated is negative, performing a calculation of shifting the held value and adding q · n (q is a positive integer). n
A circuit that calculates the remainder modulo.
【請求項13】前記第1回路が、 前記第1レジスタ及び前記第2レジスタの所定位置のビ
ットの値及び前記C出力回路の出力値が、前記第2回路
及び前記第3回路が累積を実施しないような値である場
合には、前記保持する値をrビット分(rは正の整数)
シフトし且つnを法として合同な値を計算することを特
徴とする請求項1記載のBのC乗のnを法とする剰余を
計算する回路。
13. The first circuit, the second circuit and the third circuit accumulate a value of a bit at a predetermined position of the first register and the second register and an output value of the C output circuit. If the value is not to be stored, the value to be held is r bits (r is a positive integer)
2. The circuit for calculating the remainder of a B raised to the power of C modulo n according to claim 1, wherein congruent values are calculated modulo n.
【請求項14】前記rは2であって、前記第1回路が、 前記保持する値が正である場合には、当該保持する値を
4倍し且つ前記保持する値及びnの値に基づきn又は2
n又は3nを減じる計算を実行し、 前記保持する値が負である場合には、当該保持する値を
4倍し且つ前記保持する値及びnの値に基づきn又は2
n又は3nを加算する計算を実行する、 ことを特徴とする請求項13記載のBのC乗のnを法と
する剰余を計算する回路。
14. The r is 2, and when the value held by the first circuit is positive, the value held by the first circuit is multiplied by 4 and based on the value of the held value and the value of n. n or 2
When the value to be retained is negative, the value to be retained is multiplied by 4 and n or 2 is calculated based on the value to be retained and the value of n.
The circuit for calculating a remainder of modulating B to the power of C according to claim 13, wherein the circuit performs a calculation for adding n or 3n.
【請求項15】前記rは1であって、前記第1回路は、 前記保持する値が正である場合には、当該保持する値を
2倍し且つnを減じる計算を実行し、この計算結果に基
づき当該計算結果をさらに2倍するか否か決定し、 前記保持する値が負である場合には、当該保持する値を
2倍し且つnを加算する計算を実行し、この計算結果に
基づき当該計算結果をさらに2倍する否か決定すること
を特徴とする請求項13記載のBのC乗のnを法とする
剰余を計算する回路。
15. The r is 1, and the first circuit executes, when the held value is positive, a calculation of doubling the held value and subtracting n. Based on the result, it is determined whether or not the calculation result is further doubled. If the held value is negative, the calculation is performed by doubling the held value and adding n. 14. The circuit for calculating the remainder of modulating B to the power of C according to claim 13, wherein it is determined whether or not the calculation result is further doubled based on the following equation.
【請求項16】暗号装置であって、 Bのnを法とした剰余を計算し且つ当該計算結果B1を
保持する処理を実行し、保持する値をシフトし且つnを
法として合同となる値を計算し且つ当該計算結果を保持
する処理を繰り返す第1回路と、 初期値としてB1を格納する第1レジスタと、 前記第1レジスタの所定位置のビットの値が1である場
合、前記第1回路の計算結果を累積する第2回路と、 初期値として1を格納する第2レジスタと、 Cを出力するC出力回路と、 前記C出力回路の出力値が1であって、前記第2レジス
タの所定位置のビットの値が1である場合、前記第1回
路の計算結果を累積する第3回路とを有し、 前記第1レジスタ及び前記第2レジスタの所定位置のビ
ットは、格納した値のLSBからMSB方向にシフト
し、 前記第1レジスタが格納した値のMSBについての処理
が終了した場合には、(a)前記第2回路の累積結果の
nを法として合同となる値を前記第1回路における前記
保持する値とし且つ前記第1レジスタに格納し、(b)
前記C出力回路の出力は、CのLSBからMSB方向に
シフトした値に変化し、(c)前記C出力回路の出力値
が1であれば前記第3回路の累積結果のnを法として合
同な値を前記第2レジスタに格納するBのC乗のnを法
とする剰余を計算する回路を有する暗号装置。
16. A cryptographic device, comprising: calculating a remainder of B modulo n, executing a process of retaining the computation result B1, shifting a retained value, and congruent modulo n. A first circuit that repeats a process of calculating the value and holding a result of the calculation, a first register that stores B1 as an initial value, and a first register that stores a value of 1 at a predetermined position of the first register. A second circuit for accumulating a calculation result of the circuit, a second register for storing 1 as an initial value, a C output circuit for outputting C, and an output value of the C output circuit being 1, wherein the second register A third circuit for accumulating the calculation result of the first circuit when a value of a bit at a predetermined position of the first register is 1, and a bit at a predetermined position of the first register and the second register is a stored value. From the LSB to the MSB direction, When the processing for the MSB of the value stored in the first register is completed, (a) a value which is congruent modulo n of the accumulation result of the second circuit is set as the value to be held in the first circuit; Storing in the first register, (b)
The output of the C output circuit changes from the LSB of C to a value shifted in the MSB direction. (C) If the output value of the C output circuit is 1, the output of the C output circuit is combined modulo n of the cumulative result of the third circuit. A cryptographic apparatus having a circuit for calculating a remainder modulo n of B raised to the power of C, which stores a proper value in the second register.
【請求項17】暗号装置及び解読装置を含むネットワー
ク・システムであって、 前記暗号装置及び解読装置のうち少なくとも1つが、 Bのnを法とした剰余を計算し且つ当該計算結果B1を
保持する処理を実行し、保持する値をシフトし且つnを
法として合同となる値を計算し且つ当該計算結果を保持
する処理を繰り返す第1回路と、 初期値としてB1を格納する第1レジスタと、 前記第1レジスタの所定位置のビットの値が1である場
合、前記第1回路の計算結果を累積する第2回路と、 初期値として1を格納する第2レジスタと、 Cを出力するC出力回路と、 前記C出力回路の出力値が1であって、前記第2レジス
タの所定位置のビットの値が1である場合、前記第1回
路の計算結果を累積する第3回路とを有し、 前記第1レジスタ及び前記第2レジスタの所定位置のビ
ットは、格納した値のLSBからMSB方向にシフト
し、 前記第1レジスタが格納した値のMSBについての処理
が終了した場合には、(a)前記第2回路の累積結果の
nを法として合同となる値を前記第1回路における前記
保持する値とし且つ前記第1レジスタに格納し、(b)
前記C出力回路の出力は、CのLSBからMSB方向に
シフトした値に変化し、(c)前記C出力回路の出力値
が1であれば前記第3回路の累積結果のnを法として合
同な値を前記第2レジスタに格納するBのC乗のnを法
とする剰余を計算する回路を含むことを特徴とするネッ
トワーク・システム。
17. A network system including an encryption device and a decryption device, wherein at least one of the encryption device and the decryption device calculates a remainder of B modulo n and holds the calculation result B1. A first circuit for executing processing, shifting a value to be held, calculating a congruent value modulo n, and repeating the process of holding the calculation result; a first register for storing B1 as an initial value; When the value of a bit at a predetermined position of the first register is 1, a second circuit that accumulates the calculation result of the first circuit, a second register that stores 1 as an initial value, and a C output that outputs C And a third circuit that accumulates a calculation result of the first circuit when an output value of the C output circuit is 1 and a value of a bit at a predetermined position of the second register is 1. The first register and And the bit at a predetermined position of the second register is shifted in the MSB direction from the LSB of the stored value, and when the processing for the MSB of the value stored in the first register is completed, (a) the second (B) storing a value that is congruent modulo n of the accumulated result of the circuit as the held value in the first circuit and in the first register;
The output of the C output circuit changes from the LSB of C to a value shifted in the MSB direction. (C) If the output value of the C output circuit is 1, the output of the C output circuit is combined modulo n of the cumulative result of the third circuit. A network for calculating a remainder modulo n of B raised to the power of C, storing the value in the second register.
JP09245113A 1996-09-18 1997-09-10 Circuit for calculating the remainder of B raised to the power of C modulo n Expired - Fee Related JP3137599B2 (en)

Priority Applications (2)

Application Number Priority Date Filing Date Title
JP09245113A JP3137599B2 (en) 1996-09-18 1997-09-10 Circuit for calculating the remainder of B raised to the power of C modulo n
US09/219,942 US6317769B1 (en) 1996-09-18 1998-12-23 Apparatus for calculating of Bc (mod n) with repeatedly shifting a holding value

Applications Claiming Priority (3)

Application Number Priority Date Filing Date Title
JP24625096 1996-09-18
JP8-246250 1996-09-18
JP09245113A JP3137599B2 (en) 1996-09-18 1997-09-10 Circuit for calculating the remainder of B raised to the power of C modulo n

Publications (2)

Publication Number Publication Date
JPH10260818A JPH10260818A (en) 1998-09-29
JP3137599B2 true JP3137599B2 (en) 2001-02-26

Family

ID=26537047

Family Applications (1)

Application Number Title Priority Date Filing Date
JP09245113A Expired - Fee Related JP3137599B2 (en) 1996-09-18 1997-09-10 Circuit for calculating the remainder of B raised to the power of C modulo n

Country Status (1)

Country Link
JP (1) JP3137599B2 (en)

Also Published As

Publication number Publication date
JPH10260818A (en) 1998-09-29

Similar Documents

Publication Publication Date Title
US7277540B1 (en) Arithmetic method and apparatus and crypto processing apparatus for performing multiple types of cryptography
EP0801345B1 (en) Circuit for modulo multiplication and exponentiation arithmetic
JP4955182B2 (en) Integer calculation field range extension
Kim et al. Asynchronous implementation of 1024-bit modular processor for RSA cryptosystem
US7831650B2 (en) Method for modular multiplication
JPH11305996A (en) Method and device for increasing data processing speed of calculation device using multiplication
KR20050088506A (en) Scalable montgomery modular multiplier supporting multiple precision
KR100442218B1 (en) Power-residue calculating unit using montgomery algorithm
JP4180024B2 (en) Multiplication remainder calculator and information processing apparatus
US20090089350A1 (en) Modular reduction operator
KR20040060445A (en) Montgomery modular multiplier by 4 to 2 compressor and multiplication method thereof
JP3302043B2 (en) Encryption communication method and system
JP2004258141A (en) Arithmetic unit for multiple length arithmetic of montgomery multiplication residues
JP4170267B2 (en) Multiplication remainder calculator and information processing apparatus
US5928315A (en) Apparatus and method for calculating Bc (mod n)
JP2010139544A (en) Apparatus and method for calculating remainder
US6317769B1 (en) Apparatus for calculating of Bc (mod n) with repeatedly shifting a holding value
JP3137599B2 (en) Circuit for calculating the remainder of B raised to the power of C modulo n
JP2000207387A (en) Arithmetic unit and cipher processor
US20020114449A1 (en) Modular multiplier and an encryption/decryption processor using the modular multiplier
JP3904421B2 (en) Remainder multiplication arithmetic unit
GB2318892A (en) Co-processor for performing modular multiplication
KR100836737B1 (en) Apparatus and method for modular multiplication using chhinese remainder theorem and carry save adder
KR100297110B1 (en) Modular multiplier
KR100946256B1 (en) Scalable Dual-Field Montgomery Multiplier On Dual Field Using Multi-Precision Carry Save Adder

Legal Events

Date Code Title Description
LAPS Cancellation because of no payment of annual fees