{"id":790,"date":"2009-12-01T17:34:06","date_gmt":"2009-12-01T17:34:06","guid":{"rendered":"http:\/\/pchero21.com\/?p=790"},"modified":"2009-12-01T17:34:06","modified_gmt":"2009-12-01T17:34:06","slug":"openssl-%ed%82%a4%ec%99%80-iv-%ec%83%9d%ec%84%b1-%ed%94%84%eb%a1%9c%ea%b7%b8%eb%9e%a8","status":"publish","type":"post","link":"http:\/\/pchero21.com\/?p=790","title":{"rendered":"OpenSSL- \ud0a4\uc640 IV \uc0dd\uc131 \ud504\ub85c\uadf8\ub7a8"},"content":{"rendered":"<p><P>&nbsp;<\/P><br \/>\n<P>&nbsp;<\/P><br \/>\n<P>#include &lt;stdio.h&gt;<\/P><br \/>\n<P>#include &lt;stdio.h&gt;<br \/>#include &lt;string.h&gt;<br \/>#include &lt;openssl\/evp.h&gt;<br \/>#include &lt;openssl\/objects.h&gt;<br \/>#include &lt;openssl\/rand.h&gt;<\/P><br \/>\n<P>&nbsp;<\/P><br \/>\n<P>int main(int argc, char* argv[])<br \/>{<br \/>&nbsp; &nbsp; &nbsp; &nbsp; int i;<\/P><br \/>\n<P>&nbsp;<\/P><br \/>\n<P>&nbsp; &nbsp; &nbsp; &nbsp; \/\/ salt bufer length = 8<br \/>&nbsp; &nbsp; &nbsp; &nbsp; unsigned char salt[8];<br \/>&nbsp; &nbsp; &nbsp; &nbsp; \/\/ EVP_CIPHER = Cipher structure<br \/>&nbsp; &nbsp; &nbsp; &nbsp; const EVP_CIPHER *cipher = NULL;<br \/>&nbsp; &nbsp; &nbsp; &nbsp; \/\/ password pointer. password = &#8220;aaaa&#8221;<br \/>&nbsp; &nbsp; &nbsp; &nbsp; char *password = &#8220;aaaa&#8221;;<br \/><\/P><br \/>\n<P>&nbsp; &nbsp; &nbsp; &nbsp; \/\/ \ud0a4\uc640 IV\uac00 \uc800\uc7a5\ub420 \ubcc0\uc218\ub97c \uc815\uc758\ud558\uace0 \uae38\uc774\ub294 OpenSSL\uc5d0\uc11c \uc54c\uc544\uc11c \uc815\ud574\uc900\ub2e4.<br \/>&nbsp; &nbsp; &nbsp; &nbsp; unsigned char key[EVP_MAX_KEY_LENGTH], iv[EVP_MAX_IV_LENGTH];<\/P><br \/>\n<P>&nbsp;<\/P><br \/>\n<P>&nbsp; &nbsp; &nbsp; &nbsp; int ret = 0;<\/P><br \/>\n<P>&nbsp; &nbsp; &nbsp; &nbsp; \/\/ PRNG\ub97c \ud1b5\ud574 \ub79c\ub364 \uc218\ub97c \ub9cc\ub4e4\uace0 \uadf8 \uac12\uc744 Salt\uc5d0 \uc800\uc7a5\ud55c\ub2e4. \uae38\uc774\ub294 8<br \/>&nbsp; &nbsp; &nbsp; &nbsp; ret = RAND_pseudo_bytes(salt, 8);<br \/><\/P><br \/>\n<P>&nbsp; &nbsp; &nbsp; &nbsp; \/\/ PRNG\uc5d0\uc11c \uc5d0\ub7ec\uac00 \ubc1c\uc0dd\ud560 \uacbd\uc6b0 \uc5d0\ub7ec \uba54\uc2dc\uc9c0\ub97c \ucd9c\ub825\ud558\uace0 \ud504\ub85c\uadf8\ub7a8\uc744 \uc885\ub8cc\ud55c\ub2e4.<br \/>&nbsp; &nbsp; &nbsp; &nbsp; if(ret &lt; 0) {<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf(&#8220;Can&#8217;t generate random number.n&#8221;);<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return 0;<br \/>&nbsp; &nbsp; &nbsp; &nbsp; }<\/P><br \/>\n<P>&nbsp;<\/P><br \/>\n<P>&nbsp; &nbsp; &nbsp; &nbsp; \/\/ \uc554\ud638\ud654 \uad6c\uc870\uccb4\uc758 \uc778\uc2a4\ud134\uc2a4\ub97c \uc0dd\uc131. \uc5ec\uae30\uc11c\ub294 DES\uc758 ECB \ubaa8\ub4dc\uc758 \uc554\ud638\ud654 \uad6c\uc870\uccb4 \uc0dd\uc131<br \/>&nbsp; &nbsp; &nbsp; &nbsp; cipher = EVP_des_ecb();<\/P><br \/>\n<P>&nbsp;<\/P><br \/>\n<P>&nbsp; &nbsp; &nbsp; &nbsp; \/\/ \ud0a4\uc640 IV\ub97c \uc0dd\uc131\ud568. \uc778\uc790\ub294 \uc554\ud638\ud654 \uad6c\uc870\uccb4, \ub2e4\uc774\uc81c\uc2a4\ud2b8 \uad6c\uc870\uccb4, salt \uac12, \ud328\uc2a4\uc6cc\ub4dc<\/P><br \/>\n<P>&nbsp; &nbsp; &nbsp; &nbsp; \/\/ \uce74\uc6b4\ud2b8\ub294 \uc0dd\uc131\ub420 \ud0a4\uc640 IV\ub97c \uc800\uc7a5\ud560 \ubcc0\uc218<\/P><br \/>\n<P>&nbsp; &nbsp; &nbsp; &nbsp; \/\/ \ub2e4\uc774\uc81c\uc2a4\ud2b8 \uad6c\uc870\uccb4\ub294 EVP_md5() \ud568\uc218\ub97c \ud1b5\ud574 \uc0dd\uc131. \uce74\uc6b4\ud2b8\ub294 \ud55c\ubc88<br \/>&nbsp; &nbsp; &nbsp; &nbsp; EVP_BytesToKey(cipher, EVP_md5(), salt, (unsigned char *)password, strlen(password), 1, key, iv);<\/P><br \/>\n<P>&nbsp; &nbsp; &nbsp; &nbsp; \/\/ display salt<br \/>&nbsp; &nbsp; &nbsp; &nbsp; for(i = 0; i &lt; sizeof(salt); i++) {<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf(&#8220;%02X&#8221;, salt[i]);<br \/>&nbsp; &nbsp; &nbsp; &nbsp; }<\/P><br \/>\n<P>&nbsp; &nbsp; &nbsp; &nbsp; \/\/ Display key<br \/>&nbsp; &nbsp; &nbsp; &nbsp; if(cipher-&gt;key_len &gt; 0) {<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for(i = 0; i &lt; cipher-&gt;key_len; i++) {<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf(&#8220;%02X&#8221;, key[i]);<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br \/>&nbsp; &nbsp; &nbsp; &nbsp; }<\/P><br \/>\n<P>&nbsp;<\/P><br \/>\n<P>&nbsp; &nbsp; &nbsp; &nbsp; \/\/ Display IV<br \/>&nbsp; &nbsp; &nbsp; &nbsp; if(cipher-&gt;iv_len &gt; 0) {<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for(i = 0; i &lt; cipher-&gt;iv_len; i++) {<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf(&#8220;%02X&#8221;, iv[i]);<br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br \/>&nbsp; &nbsp; &nbsp; &nbsp; }<\/P><br \/>\n<P>&nbsp;<\/P><br \/>\n<P>&nbsp; &nbsp; &nbsp; &nbsp; return 0;<br \/>}<br \/><\/P><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; &nbsp; #include &lt;stdio.h&gt; #include &lt;stdio.h&gt;#include &lt;string.h&gt;#include &lt;openssl\/evp.h&gt;#include &lt;openssl\/objects.h&gt;#include &lt;openssl\/rand.h&gt; &nbsp; int main(int argc, char* argv[]){&nbsp; &nbsp; &nbsp; &nbsp; int i; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \/\/ salt bufer length = 8&nbsp; &nbsp; &nbsp; &nbsp; unsigned char salt[8];&nbsp; &nbsp; &nbsp; &hellip; <a href=\"http:\/\/pchero21.com\/?p=790\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[53],"tags":[297,362],"_links":{"self":[{"href":"http:\/\/pchero21.com\/index.php?rest_route=\/wp\/v2\/posts\/790"}],"collection":[{"href":"http:\/\/pchero21.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/pchero21.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/pchero21.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/pchero21.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=790"}],"version-history":[{"count":0,"href":"http:\/\/pchero21.com\/index.php?rest_route=\/wp\/v2\/posts\/790\/revisions"}],"wp:attachment":[{"href":"http:\/\/pchero21.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=790"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/pchero21.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=790"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/pchero21.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=790"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}