Adi Shamir(アディ・シャミア) Leonard Max Adleman(レオナルド・エーデルマン) の原語表記の頭文字をつなげてこのように呼ばれる。当時、ディフィーとヘルマンに よって発表されたばかりの公開鍵暗号という新しい概念に対し、秘匿や認証を実現でき る具体的なアルゴリズムを与えた。 この暗号はフェルマーの小定理に基づいている。 5
Blog https://www.sejuku.net/blog/74038 「試し割り法」のプログラム例 import math number = 123 def trial_division(target): dest = int(math.sqrt(target)) for i in range(2, dest): if target % i == 0: print(str(target) + 'は合成数!') return print(str(target) + 'は素数!') trial_division(number)
if (i * l + 1) % e == 0: d = (i * l + 1) // e break i += 1 整数Dを求めるプログラム例1 # 秘密鍵で使用するdを算出する for D in range(2, L): if (E * D) % L == 1: break 鍵長 左側の処理 (プログラム例1) 右側の処理 (プログラム例2) 鍵長23ビット(100回繰り返し) (p = 1879, q = 2531, n = 4755749, e = 7) Python3: 5.841[s] Golang: 0.564[s] Python3: 0.057[s] Golang: 0.051[s] 鍵長2048ビット(100回繰り返し) (e = 65537) Python3: 計測断念 Golang: 未計測 Python3: 1.625[s] Golang: 未計測 数式 ==1での比較ではなく、 数式 == 0 で比較した方が、 圧倒的に処理が速い。
version Version, modulus INTEGER, -- n publicExponent INTEGER, -- e privateExponent INTEGER, -- d prime1 INTEGER, -- p prime2 INTEGER, -- q exponent1 INTEGER, -- d mod (p-1) exponent2 INTEGER, -- d mod (q-1) coefficient INTEGER, -- (inverse of q) mod p otherPrimeInfos OtherPrimeInfos OPTIONAL } 22 出典) Information technology – ASN.1 encoding rules: Specification of Basic Encoding Rules (BER), Canonical Encoding Rules (CER) and Distinguished Encoding Rules (DER) https://www.itu.int/ITU-T/studygroups/com17/languages/X.690-0207.pdf
get_random_bytes from Crypto.Cipher import AES, PKCS1_OAEP data = “I met aliens in UFO. Here is the map.”.encode(“utf-8”) # 元の文字列 file_out = open(“encrypted_data.bin”, “wb”) # 暗号化データの出力ファイル recipient_key = RSA.import_key(open(“receiver.pem”).read()) # 公開鍵を読み込む session_key = get_random_bytes(16) # 共通鍵を生成 # Encrypt the session key with the public RSA key cipher_rsa = PKCS1_OAEP.new(recipient_key) # RSA処理用のインスタンス生成 enc_session_key = cipher_rsa.encrypt(session_key) # 共通鍵を公開鍵で暗号化 # Encrypt the data with the AES session key cipher_aes = AES.new(session_key, AES.MODE_EAX) # AES処理用のインスタンス生成 ciphertext, tag = cipher_aes.encrypt_and_digest(data) # 元の文字列を共通鍵で暗号化 [ file_out.write(x) for x in (enc_session_key, cipher_aes.nonce, tag, ciphertext) ] # 鍵情報と暗号化データをファイルへ出力 25 PyCryptodome Examples https://www.pycryptodome.org/en/latest/src/examples.html