Manual/BerEditor

[BerEditor] ํฐ์ˆ˜(Big Num) ๊ณ„์‚ฐ๊ธฐ๋กœ RSA ํ‚ค์Œ ๋ฐ ์•”๋ณตํ˜ธํ™” ์—ฐ์‚ฐ

JayKim๐Ÿ™‚ 2024. 6. 27. 17:51

[์ด ๊ธฐ๋Šฅ์€ ๋ผ์ด์„ ์Šค ๋ฒ„์ „ ๊ธฐ๋Šฅ์ž…๋‹ˆ๋‹ค]
๋ผ์ด์„ ์Šค๊ฐ€ ํ•„์š”ํ•œ ๋ถ„์€ [ํ”„๋กœ๊ทธ๋žจ ํ‚ค ๋ฐœ๊ธ‰] ํŽ˜์ด์ง€์—์„œ 30์ผ ๋ผ์ด์„ ์Šค ๋ฐœ๊ธ‰ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค

RSA ๊ธฐ์ˆ ์—์„œ ์•”ํ˜ธํ™” ์—ฐ์‚ฐ์—๋Š” ์•„์ฃผ ํฐ ์ˆซ์ž ์—ฐ์‚ฐ ๋ฐ ๋ชจ๋“ˆ๋ผ ์—ฐ์‚ฐ์ด ์ฃผ๋กœ ์‚ฌ์šฉ๋œ๋‹ค.
์ด ์—ฐ์‚ฐ์„ ํ•˜๊ธฐ ์œ„ํ•ด์„œ BerEditor ๋ฉ”๋‰ด์—์„œ BN Calculator ๋ฅผ ์ด์šฉํ•˜๋ฉด ๋œ๋‹ค.

๊ณ„์‚ฐ๊ธฐ์—์„œ ์ง€์› ํ•˜๋Š” Base Group ์—์„œ ์—ฐ์‚ฐ ๋ฐฉ์‹์€ 3๊ฐ€์ง€ ์ด๋‹ค.

- Number : ์ผ๋ฐ˜ ์ •์ˆ˜ ์—ฐ์‚ฐ
- Modular : ๋ชจ๋“ˆ๋ผ๋ฅผ ์ด์šฉํ•œ ์—ฐ์‚ฐ
- GF2m : ๊ฐˆ๋ฃจ์•„ ํ•„๋“œ๋ฅผ ์ด์šฉํ•œ GF(2^m) ์—ฐ์‚ฐ

์ด๋ ‡๊ฒŒ 3๊ฐ€์ง€ ๋ฉ”๋‰ด๊ฐ€ ์žˆ๋‹ค.
์—ฌ๊ธฐ์„œ RSA ํ‚ค์ƒ์„ ๋งŒ๋“œ๋Š”๊ฒƒ์€ Number์™€ Modular ๋ฐฉ์‹์„ ์‚ฌ์šฉํ•œ๋‹ค.
๊ทธ๋ฆฌ๊ณ  ํ…Œ์ŠคํŠธ๋กœ ์‚ฌ์šฉํ•˜๋Š” ์ˆซ์ž ๊ฐ’์€ ํ—ฅ์‚ฌ ํ‘œ๊ธฐ์ด๋‹ค.

๊ณ„์‚ฐ๊ธฐ์—์„œ ์ž…๋ ฅ๊ฐ’์˜ ๊ธธ์ด(์˜ค๋ฅธ์ชฝ ์ฝ๊ธฐ ํ‘œ์‹œ)๋Š” ๋‹จ์ˆœ ๋ฌธ์ž์˜ ๊ฐœ์ˆ˜์ด๋‹ค.

๋ณดํ†ต RSA ํ‚ค ์Œ์€ ๋‘๊ฐœ์˜ ํฐ ์†Œ์ˆ˜ P์™€ Q ๋ฅผ ๋งŒ๋“ค๊ณ  ์ด ๊ฐ’์„ ๊ฐ€์ง€๊ณ  ๊ฐœ์ธํ‚ค์™€ ๊ณต๊ฐœํ‚ค๋ฅผ ์–ป์„ ์ˆ˜ ์žˆ๋‹ค.
์ฆ‰ ํฐ ์†Œ์ˆ˜ P ์™€ Q๋ฅผ ๋…ธ์ถœ์€ ๊ณง ๊ฐœ์ธํ‚ค๋ฅผ ๋…ธ์ถœ๋˜๋Š” ๊ฒƒ์œผ๋กœ ๋ณด๋ฉด ๋˜๋‹ค.
๊ทธ๋ฆฌ๊ณ  ๊ณต๊ฐœ๋กœ PublicExponent ๋Š” e = 010001 ( 10์ง„์ˆ˜ 65537) ์„ ์‚ฌ์šฉํ•œ๋‹ค.

์—ฌ๊ธฐ ์˜ˆ์ œ์—์„œ๋Š” ์ดํ•ด๋ฅผ ์œ„ํ•ด ์งง์€ ํ‚ค ๊ธธ์ด P์™€Q 256 ๋น„ํŠธ๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค.
์ฆ‰ P์™€Q๊ฐ€ 256 ๋น„ํŠธ๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค๋Š” ๊ฒƒ์€ P*Q ์˜ ๊ฒฐ๊ณผ์ธ N์ด 512๋น„ํŠธ๊ฐ€ ๋˜์–ด์„œ RSA 512 ๋น„ํŠธ ํ‚ค๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด๋‹ค.

ํฐ ์†Œ์ˆ˜ P์™€ Q ์ƒ์„ฑ ๋ฐ ๊ณต๊ฐœํ‚ค ๊ตฌํ•˜๊ธฐ

  • A : P ์†Œ์ˆ˜ ์ƒ์„ฑ ๊ฐ’
  • B : Q ์†Œ์ˆ˜ ์ƒ์„ฑ ๊ฐ’
  • A x B ๋ฒ„ํŠผ : N๊ฐ’ ๊ตฌํ•˜๊ธฐ

๊ทธ๋Ÿผ N ๊ฐ’์„ ๋งŒ๋“ค๊ธฐ ์œ„ํ•ด์„œ๋Š” P * Q ์ด๋ฏ€๋กœ A * B ๋ฒ„ํŠผ์„ ๋ˆŒ๋Ÿฌ ์ฃผ์ž
์ƒ์„ฑ๋œ ๊ฐ’

P (A ๊ฐ’) = D957E9E5E313B9E6EF0A112875037F227015BF81D235C61316E0F1CA10E5DFFD

Q (B ๊ฐ’) = C5C989AF683037D7D8D40BD1C47D2DAB5BFBF5B55CC5423E73804AC036C4B65B

N ( Result ๊ฐ’ ) = A7EBC1E984F70A21D8C3B8298D67B56CF10B796531FDBC8C096A0E97EFB33893FCF08CAFC79A3389B010F68447AC8A86D55BFB211FB5E28A90C827D64AA87CEF

์—ฌ๊ธฐ์„œ ๊ณ„์‚ฐ๋œ ( e, N ) ๊ฐ’์ด RSA ๊ณต๊ฐœํ‚ค ๊ฐ’์ด ๋œ๋‹ค.
๋งŒ์•ฝ ์ด๋ฏธ ๋งŒ๋“ค์–ด์ง€ P์™€ Q๊ฐ’์„ ์ด์šฉ์‹œ๋Š” A์™€ B์˜์—ญ์— ๋ณต์‚ฌํ•ด์„œ ๋„ฃ์–ด ์ฃผ์–ด๋„ ๋œ๋‹ค.

RSA ๊ฐœ์ธํ‚ค๋ฅผ ๊ตฌํ•ด ๋ณด์ž

๊ฐœ์ธํ‚ค๋ฅผ ๊ตฌํ•˜๋Š” ๊ณต์‹์€ ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค
$$ d ≡e^{-1} \, mod \, ๐œ™(n) $$
๋จผ์ € ๊ฐœ์ธํ‚ค๋ฅผ ๊ตฌํ•˜๊ธฐ ์œ„ํ•ด์„œ ฯ•(n)=(p−1)×(q−1) ๊ฐ’์„ ๊ตฌํ•˜์ž

์ฐธ๊ณ ๋กœ ์‹ค์ œ 2048 Bits ์ด์ƒ์˜ ๊ฐœ์ธํ‚ค๋ฅผ ๊ตฌํ•˜๋Š” ๊ณต์‹์€ FIPS-186-4 ์—์„œ๋Š” ์•„๋ž˜ ๊ณต์‹์„ ์‚ฌ์šฉํ•ด์•ผ ํ•œ๋‹ค.
$$  d ≡e^{-1} \, mod \, LCM(p-1, q-1) $$

LCM ๊ตฌํ•˜๊ธฐ ์ฐธ๊ณ 

์—ฌ๊ธฐ์„œ๋Š” ์˜ˆ์ œ๋กœ ์œ„์˜ ๋ฐฉ์‹์„ ์‚ฌ์šฉํ•˜์˜€๋‹ค.

  • A ๊ฐ’์—์„œ -1 ๋ฒ„ํŠผ ์„ ๋ˆ„๋ฅด๋ฉด (p-1) ๊ณ„์‚ฐ
  • B ๊ฐ’์—์„œ -1 ๋ฒ„ํŠผ ๋ˆ„๋ฅธ๋ฉด (q-1) ๊ณ„์‚ฐ
  • A x B ํด๋ฆญ : ฯ•(n) ๊ฐ’์„ ๊ตฌํ•˜๊ฒŒ ๋œ๋‹ค.
(P-1) = D957E9E5E313B9E6EF0A112875037F227015BF81D235C61316E0F1CA10E5DFFC

(Q-1) = C5C989AF683037D7D8D40BD1C47D2DAB5BFBF5B55CC5423E73804AC036C4B65A

ฯ•(n) ๊ฒฐ๊ณผ๊ฐ’ = A7EBC1E984F70A21D8C3B8298D67B56CF10B796531FDBC8C096A0E97EFB338925DCF191A7C5641CAE832D98A0E2BDDB9094A45E9F0BADA390666EB4C02FDE698

๊ฐœ์ธํ‚ค d ๊ฐ’์„ ๊ตฌํ•˜๊ธฐ

์œ„ ฯ•(n) ๊ฐ’์„ M์— ์ž…๋ ฅ ๊ทธ๋ฆฌ๊ณ  A ์—๋Š” e๊ฐ’์ธ 010001 ์ž…๋ ฅํ›„ A^-1 Mod M ๋ฒ„ํŠผ์„ ํด๋ฆญ ํ•˜๋ฉด ๊ฐœ์ธํ‚ค d ๊ฐ’์ด ๋‚˜์˜จ๋‹ค.

E (A๊ฐ’) = 010001 ( 10์ง„์ˆ˜ 65537 )

ฯ•(n) (M๊ฐ’) = A7EBC1E984F70A21D8C3B8298D67B56CF10B796531FDBC8C096A0E97EFB338925DCF191A7C5641CAE832D98A0E2BDDB9094A45E9F0BADA390666EB4C02FDE698

d (๊ฒฐ๊ณผ๊ฐ’) = 030E869C22A0809DB71D70F7C8AC2FA0490F0569B32C444764507AED871E83141F030B18F1547CA41DEFF707CD543D18063444EB8A474C7BA7432E5B56DE9A59

RSA ์•”ํ˜ธํ™”

์•”ํ˜ธํ™” ๊ณต์‹์€ C = M^e mod N ์ด๋‹ค.
RSA ์•”ํ˜ธํ™”๋Š” ๊ณต๊ฐœํ‚ค ๊ฐ’๋งŒ์œผ๋กœ ๋งŒ๋“œ๋Š” ๊ฐ’์ด๋‹ค. ์ผ๋ฐ˜์ ์œผ๋กœ ์ˆ˜์‹ ์ž์˜ ๊ณต๊ฐœํ‚ค๋ฅผ ์ด์šฉํ•ด ์•”ํ˜ธํ™” ํ•œ๋‹ค.
์˜ˆ์ œ๋กœ ์‚ฌ์šฉํ•˜๋Š” ๋ฉ”์„ธ์ง€๋กœ ํ—ฅ์‚ฌ ๊ฐ’ 12345678 ์„ ์‚ฌ์šฉํ•ด์„œ ์•”ํ˜ธํ™” ํ•ด ๋ณด์ž

Message (A๊ฐ’) = 12345678  
e (B๊ฐ’) = 010001  
N ๊ฐ’ (M๊ฐ’) = A7EBC1E984F70A21D8C3B8298D67B56CF10B796531FDBC8C096A0E97EFB33893FCF08CAFC79A3389B010F68447AC8A86D55BFB211FB5E28A90C827D64AA87CEF

Cipher๊ฐ’ (Result๊ฐ’) = 50325882778093FD69C8A37D1B1FFCD8D60099D2DCEFBC3A6EADFF0EBD7B27320CAF505E81F8660C9534A49E2ECED3EC2EE928A7AC446FE5AA237CAEA0360F55 

RSA ๋ณตํ˜ธํ™”

๋ณตํ˜ธํ™” ๊ณต์‹์€ M = C^d mod N ์ด๋‹ค.
RSA ๋ณตํ˜ธํ™”๋Š” ๊ฐœ์ธํ‚ค๋ฅผ ์ด์šฉํ•ด ๋ณตํ˜ธํ™” ํ•˜๊ฒŒ ๋œ๋‹ค.
๊ทธ๋Ÿผ ์•”ํ˜ธ๋ฌธ์„ ๊ฐ€์ง€๊ณ  ์›๋ฌธ์„ ๊ตฌํ•ด ๋ณด์ž.

Cipher (A๊ฐ’) =50325882778093FD69C8A37D1B1FFCD8D60099D2DCEFBC3A6EADFF0EBD7B27320CAF505E81F8660C9534A49E2ECED3EC2EE928A7AC446FE5AA237CAEA0360F55

d (B๊ฐ’) = 030E869C22A0809DB71D70F7C8AC2FA0490F0569B32C444764507AED871E83141F030B18F1547CA41DEFF707CD543D18063444EB8A474C7BA7432E5B56DE9A59

N ( M๊ฐ’) = A7EBC1E984F70A21D8C3B8298D67B56CF10B796531FDBC8C096A0E97EFB33893FCF08CAFC79A3389B010F68447AC8A86D55BFB211FB5E28A90C827D64AA87CEF

Plain (๊ฒฐ๊ณผ๊ฐ’) = 12345678

์œ„ ๊ณต์‹๋Œ€๋กœ ๊ฐ’์„ ๊ณ„์‚ฐํ•˜๊ฒŒ ๋˜๋ฉด ๊ฒฐ๊ณผ์ธ ์›๋ฌธ 12345678 ์„ ๊ตฌํ•  ์ˆ˜ ์žˆ๋‹ค.

๋งˆ๋ฌด๋ฆฌ

๋น…๋„˜ ์—ฐ์‚ฐ๊ธฐ๋ฅผ ์ด์šฉํ•˜์—ฌ ๊ฐ„๋‹จํžˆ RSA ํ‚ค ์Œ์„ ๋งŒ๋“ค์–ด ๋ณด์•˜๋‹ค.
์ด๋ ‡๊ฒŒ ํฐ ์†Œ์ˆ˜ P ์™€ Q๋ฅผ ๊ฐ’์„ ์•Œ๊ฒŒ ๋˜๋ฉด ๊ฐœ์ธํ‚ค์™€ ๊ณต๊ฐœํ‚ค๋ฅผ ๊ตฌํ•ด์ง€๋ฏ€๋กœ p์™€ q๊ฐ’์€ ๊ฐœ์ธํ‚ค์™€ ๊ฐ™์€ ๋…ธ์ถœ ๋˜์–ด์„œ๋Š” ์•ˆ๋˜๋Š” ๊ฐ’์ด ๋œ๋‹ค.
์—ฌ๊ธฐ์„œ๋Š” ์„ค๋ช…์„ ์œ„ํ•ด 512 ๋น„ํŠธ์˜ ์งง์€ ๊ธธ์ด๋ฅผ ์‚ฌ์šฉ ํ•˜์˜€์ง€๋งŒ ์‹ค์ œ์—์„œ๋Š” 2048 ๋น„ํŠธ๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค.
2048 ๋น„ํŠธ๋กœ ํ…Œ์ŠคํŠธ ํ• ๋ ค๋ฉด ์œ„ ์„ค๋ช…์—์„œ ์†Œ์ˆ˜๊ฐ’ P์™€ Q์ƒ์„ฑ ์‹œ 1024 ๋น„ํŠธ๋ฅผ ์„ ํƒ ํ•˜์—ฌ์„œ ๋˜‘๊ฐ™์ด ํ•˜๋ฉด๋œ๋‹ค.