elliptic curve crypto

Zeung-il Kim
1 min readMar 21, 2019

--

전기차 충전 및 앞으로 계속 나올 IoT장비들에는 PKI기반 보안 기술이 들어가게 된다. 
그 중에서 나름 최신 암호화 suite인 ECC방식에 대해 간단한 예로 알아 보자.
openssl을 활용하여 ECC(Elliptic curve crypto)로 데이터 암호화 하기kim과 park이 서로 개인키를 각자 생성하고 이로 부터 공개키를 추출한다. 1. 개인키 생성
openssl ecparam -name secp256k1 -genkey -noout -out kim_priv_key.pem
2. 개인키로 부터 공개키 추출
openssl ec -in kim_priv_key.pem -pubout -out kim_pub_key.pem
#park도 위의 1,2과정을 통해 키를 생성한다. ECC에서는 바로 데이터를 암호화 하거나 복호화 하지 않고 DH(Diffie-Hellman) Key exchange 방식을 사용해서 shard secret을 만들고 이를 이용해서 암호화 통신을 한다.
이것을 ECDH (ECC + DH)라고 함.
3. 자신의 개인키와 상대방의 공개키를 활용해서 shared secret을 만들어 보자. openssl pkeyutl -derive -inkey kim_priv_key.pem -peerkey park_pub_key.pem -out kim_shared_secret.binopenssl pkeyutl -derive -inkey park_priv_key.pem -peerkey kim_pub_key.pem -out park_shared_secret.binbase64 kim_shared_secret.bin
base64 park_shard_secret.bin 이 두값을 보면 똑같다는 것을 알 수 있음.
이제 이 정보를 이용해서 대칭키암호화 통신을 할 수 있다. 예를 들면echo 'Hello crypto world!' > plain.txt
openssl enc -aes256 -base64 -k $(base64 kim_shared_secret.bin) -e -in plain.txt -out cipher.txt
openssl end -aes256 -base64 -k $(base64 park_shared_secret.bin) -d -in cipher.txt -out plain_again.txt
이제 개인키로 서명하고 공개키로 검증을 해보자
메시지 자체에 서명하는 것이 아니라 hash값에 서명 한다. openssl dgst -sha256 -sign kim_priv_key.pem plain.txt > plain_signature.der (DER포맷의 메시지 서명값 생성)hex로 뜨고자 하면
openssl dgst -sha256 -hex -sign kim_priv_key.pem plain.txt
hexdump plain_signature.der
이제 검증해 보자
openssl dgst -sha256 -verify kim_pub_key.pem -signature plain_signature.der plain.txt>> Verified OK

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

No responses yet

Write a response