{"id":793,"date":"2009-12-03T12:10:44","date_gmt":"2009-12-03T12:10:44","guid":{"rendered":"http:\/\/pchero21.com\/?p=793"},"modified":"2009-12-03T12:10:44","modified_gmt":"2009-12-03T12:10:44","slug":"openlssl-%eb%8d%b0%ec%9d%b4%ed%84%b0-%eb%b3%b5%ed%98%b8%ed%99%94","status":"publish","type":"post","link":"http:\/\/pchero21.com\/?p=793","title":{"rendered":"OpenlSSL &#8211; \ub370\uc774\ud130 \ubcf5\ud638\ud654"},"content":{"rendered":"<p>\/\/ &nbsp; &nbsp;&nbsp; dec_evp.c<br \/>\/\/ &nbsp; &nbsp; &nbsp;<br \/>\/\/ &nbsp; &nbsp;&nbsp; Copyright 2009 Kim Sung-tae &lt;pchero21@gmail.com&gt;<br \/>\/\/ &nbsp; &nbsp; &nbsp;<br \/>\/\/ &nbsp; &nbsp;&nbsp; This program is free software; you can redistribute it and\/or modify<br \/>\/\/ &nbsp; &nbsp;&nbsp; it under the terms of the GNU General Public License as published by<br \/>\/\/ &nbsp; &nbsp;&nbsp; the Free Software Foundation; either version 2 of the License, or<br \/>\/\/ &nbsp; &nbsp;&nbsp; (at your option) any later version.<br \/>\/\/ &nbsp; &nbsp; &nbsp;<br \/>\/\/ &nbsp; &nbsp;&nbsp; This program is distributed in the hope that it will be useful,<br \/>\/\/ &nbsp; &nbsp;&nbsp; but WITHOUT ANY WARRANTY; without even the implied warranty of<br \/>\/\/ &nbsp; &nbsp;&nbsp; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.&nbsp; See the<br \/>\/\/ &nbsp; &nbsp;&nbsp; GNU General Public License for more details.<br \/>\/\/ &nbsp; &nbsp; &nbsp;<br \/>\/\/ &nbsp; &nbsp;&nbsp; You should have received a copy of the GNU General Public License<br \/>\/\/ &nbsp; &nbsp;&nbsp; along with this program; if not, write to the Free Software<br \/>\/\/ &nbsp; &nbsp;&nbsp; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,<br \/>\/\/ &nbsp; &nbsp;&nbsp; MA 02110-1301, USA.<\/p>\n<p>#include &lt;stdio.h&gt;<br \/>#include &lt;openssl\/bio.h&gt;<br \/>#include &lt;openssl\/err.h&gt;<br \/>#include &lt;openssl\/bn.h&gt;<br \/>#include &lt;openssl\/dh.h&gt;<br \/>#include &lt;openssl\/x509.h&gt;<br \/>#include &lt;openssl\/rand.h&gt;<br \/>#include &lt;openssl\/pem.h&gt;<\/p>\n<p>#define IN_FILE &#8220;encrypt.txt&#8221;<br \/>#define OUT_FILE &#8220;decrypt.txt&#8221;<\/p>\n<p>unsigned char* readFile(char *file, int *readLen);<br \/>unsigned char* readFileBio(BIO *fileBIO, int *readLen);<br \/>unsigned char* addString(unsigned char *destString, int destLen, const unsigned char *addString, int addLen);<\/p>\n<p>int main(int argc, char** argv)<br \/>{<br \/>&nbsp;&nbsp; &nbsp;<br \/>&nbsp;&nbsp; &nbsp;\/\/ \ud0a4\uc640 IV \uac12\uc740 \uc9c1\uc811 \ub9cc\ub4e0<br \/>&nbsp;&nbsp; &nbsp;unsigned char key[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};<br \/>&nbsp;&nbsp; &nbsp;unsigned char iv[] = {1, 2, 3, 4, 5, 6, 7, 8};<br \/>&nbsp;&nbsp; &nbsp;<br \/>&nbsp;&nbsp; &nbsp;unsigned char* outbuf; &nbsp; &nbsp;\/\/ \ubcf5\ud638\ubb38\uc774 \uc800\uc7a5\ub420 \ubc84\ud37c<br \/>&nbsp;&nbsp; &nbsp;int outlen, tmplen;<br \/>&nbsp;&nbsp; &nbsp;<br \/>&nbsp;&nbsp; &nbsp;BIO *errBIO = NULL;<br \/>&nbsp;&nbsp; &nbsp;BIO *outBIO = NULL;<br \/>&nbsp;&nbsp; &nbsp;<br \/>&nbsp;&nbsp; &nbsp;\/\/ \uc5d0\ub7ec \ubc1c\uc0dd\uc758 \uacbd\uc6b0 \ud574\ub2f9 \uc5d0\ub7ec \uc2a4\ud2b8\ub9c1 \ucd9c\ub825\uc744 \uc704\ud574 \ubbf8\ub9ac \uc5d0\ub7ec \uc2a4\ud2b8\ub9c1\ub4e4\uc744 \ub85c\ub529.<br \/>&nbsp;&nbsp; &nbsp;ERR_load_crypto_strings();<br \/>&nbsp;&nbsp; &nbsp;<br \/>&nbsp;&nbsp; &nbsp;\/\/ \ud45c\ub454 \ud654\uba74 \ucd9c\ub825 BIO \uc0dd\uc131<br \/>&nbsp;&nbsp; &nbsp;if((errBIO = BIO_new(BIO_s_file())) != NULL)<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;BIO_set_fp(errBIO, stderr, BIO_NOCLOSE | BIO_FP_TEXT);<br \/>&nbsp;&nbsp; &nbsp;<br \/>&nbsp;&nbsp; &nbsp;\/\/ \ud30c\uc77c \ucd9c\ub825 BIO \uc0dd\uc131<br \/>&nbsp;&nbsp; &nbsp;outBIO = BIO_new_file(OUT_FILE, &#8220;wb&#8221;);<br \/>&nbsp;&nbsp; &nbsp;<br \/>&nbsp;&nbsp; &nbsp;if(!outBIO) { &nbsp; &nbsp;\/\/ \uc5d0\ub7ec\uac00 \ubc1c\uc0dd\ud55c \uacbd\uc6b0<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;BIO_printf(errBIO, &#8220;\ud30c\uc77c [%s]\uc744 \uc0dd\uc131\ud558\ub294\ub370 \uc5d0\ub7ec\uac00 \ubc1c\uc0dd \ud588\uc2b5\ub2c8\ub2e4.&#8221;, OUT_FILE);<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;ERR_print_errors(errBIO);<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;exit(1);<br \/>&nbsp;&nbsp; &nbsp;}<br \/>&nbsp;&nbsp; &nbsp;<br \/>&nbsp;&nbsp; &nbsp;\/\/ \ud30c\uc77c\uc5d0\uc11c \uc77d\uc5b4\uc624\uae30<br \/>&nbsp;&nbsp; &nbsp;int len;<br \/>&nbsp;&nbsp; &nbsp;unsigned char* readBuffer = readFile(IN_FILE, &amp;len);<br \/>&nbsp;&nbsp; &nbsp;<br \/>&nbsp;&nbsp; &nbsp;\/\/ \uc554\ud638\ud654 \ucee8\ud14d\uc2a4\ud2b8 EVP_CIPHER_CTX \uc0dd\uc131, \ucd08\uae30\ud654<br \/>&nbsp;&nbsp; &nbsp;EVP_CIPHER_CTX ctx;<br \/>&nbsp;&nbsp; &nbsp;EVP_CIPHER_CTX_init(&amp;ctx);<br \/>&nbsp;&nbsp; &nbsp;<br \/>&nbsp;&nbsp; &nbsp;\/\/ \ucd08\uae30\ud654<br \/>&nbsp;&nbsp; &nbsp;EVP_DecryptInit_ex(&amp;ctx, EVP_bf_cbc(), NULL, key, iv);<br \/>&nbsp;&nbsp; &nbsp;<br \/>&nbsp;&nbsp; &nbsp;\/\/ \ucd08\uae30\ud654\uac00 \ub05d\ub09c\ud6c4\uc5d0 \ud574\uc57c \ud55c\ub2e4. \ubcf5\ud638\ubb38 \uc800\uc7a5\ud560 \ubc84\ud37c \uc0dd\uc131<br \/>&nbsp;&nbsp; &nbsp;outbuf = (unsigned char*)malloc(sizeof(unsigned char) * len);<br \/>&nbsp;&nbsp; &nbsp;<br \/>&nbsp;&nbsp; &nbsp;\/\/ \uc5c5\ub370\uc774\ud2b8, \ub9c8\uc9c0\ub9c9 \ube14\ub85d\uc744 \uc81c\uc678\ud558\uace0 \ubaa8\ub450 \ubcf5\ud638\ud654<br \/>&nbsp;&nbsp; &nbsp;if(!EVP_DecryptUpdate(&amp;ctx, outbuf, &amp;outlen, readBuffer, len)) {<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;return 0;<br \/>&nbsp;&nbsp; &nbsp;}<br \/>&nbsp;&nbsp; &nbsp;<br \/>&nbsp;&nbsp; &nbsp;\/\/ \uc885\ub8cc. \ub9c8\uc9c0\ub9c9 \ube14\ub85d\uc744 \ubcf5\ud638\ud654<br \/>&nbsp;&nbsp; &nbsp;if(!EVP_DecryptFinal_ex(&amp;ctx, outbuf + outlen, &amp;tmplen)) {<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;return 0;<br \/>&nbsp;&nbsp; &nbsp;}<br \/>&nbsp;&nbsp; &nbsp;<br \/>&nbsp;&nbsp; &nbsp;\/\/ \ubcf5\ud638\ubb38 \uae38\uc774\ub294 \uc5c5\ub370\uc774\ud2b8, \uc885\ub8cc \uacfc\uc815\uc5d0\uc11c \ub098\uc628 \uacb0\uacfc\uc758 \ud569<br \/>&nbsp;&nbsp; &nbsp;outlen += tmplen;<br \/>&nbsp;&nbsp; &nbsp;EVP_CIPHER_CTX_cleanup(&amp;ctx);<br \/>&nbsp;&nbsp; &nbsp;<br \/>&nbsp;&nbsp; &nbsp;BIO_printf(errBIO, &#8220;\ubcf5\ud638\ud654\uac00 \uc644\ub8cc\ub418\uc5c8\uc2b5\ub2c8\ub2e4. \ubcf5\ud638\ubb38\uc740 \ub2e4\uc74c\uacfc \uac19\uc2b5\ub2c8\ub2e4.nn&#8221;);<br \/>&nbsp;&nbsp; &nbsp;outbuf[outlen] = 0;<br \/>&nbsp;&nbsp; &nbsp;printf(&#8220;%s&#8221;, outbuf);<br \/>&nbsp;&nbsp; &nbsp;<br \/>&nbsp;&nbsp; &nbsp;\/\/ \ud30c\uc77c\uc5d0 \uac19\uc740 \ub0b4\uc6a9\uc744 \ucd9c\ub825\ud55c\ub2e4.<br \/>&nbsp;&nbsp; &nbsp;BIO_write(outBIO, outbuf, outlen);<\/p>\n<p>&nbsp;&nbsp; &nbsp;\/\/ \uac1d\uccb4 \uc81c\uac70<br \/>&nbsp;&nbsp; &nbsp;BIO_free(outBIO);<br \/>&nbsp;&nbsp; &nbsp;<br \/>&nbsp;&nbsp; &nbsp;return 0;<br \/>}<\/p>\n<p>unsigned char* readFile(char *file, int *readLen)<br \/>{<br \/>&nbsp;&nbsp; &nbsp;unsigned char *retBuffer = NULL;<br \/>&nbsp;&nbsp; &nbsp;unsigned char *buffer = NULL;<br \/>&nbsp;&nbsp; &nbsp;int length = 0;<br \/>&nbsp;&nbsp; &nbsp;<br \/>&nbsp;&nbsp; &nbsp;\/\/ \ud30c\uc77c BIO \uc815\uc758<br \/>&nbsp;&nbsp; &nbsp;BIO *fileBIO = NULL;<br \/>&nbsp;&nbsp; &nbsp;<br \/>&nbsp;&nbsp; &nbsp;\/\/ \uc778\uc790\ub85c \ub118\uc5b4\uc628 \ud30c\uc77c\uc744 \uc5f4\uace0, \ud30c\uc77c BIO \uc0dd\uc131<br \/>&nbsp;&nbsp; &nbsp;fileBIO = BIO_new_file(file, &#8220;rb&#8221;);<br \/>&nbsp;&nbsp; &nbsp;<br \/>&nbsp;&nbsp; &nbsp;if(!fileBIO) { &nbsp; &nbsp;\/\/ \ud30c\uc77c\uc744 \uc5ec\ub294\ub370 \uc5d0\ub7ec\uac00 \ubc1c\uc0dd\ud55c \uacbd\uc6b0<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;printf(&#8220;\uc785\ub825 \ud30c\uc77c [%s] \uc744 \uc5ec\ub294\ub370 \uc5d0\ub7ec\uac00 \ubc1c\uc0dd \ud588\uc2b5\ub2c8\ub2e4.n&#8221;, file);<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;exit(1);<br \/>&nbsp;&nbsp; &nbsp;}<br \/>&nbsp;&nbsp; &nbsp;<br \/>&nbsp;&nbsp; &nbsp;\/\/ \uc784\uc2dc\ub85c 1000 \ubc14\uc774\ud2b8 \ub9cc\ud07c\uc758 \uc77d\uc740 \ub370\uc774\ud130\ub97c \uc800\uc7a5\ud560 \ubc84\ud37c \uc0dd\uc131<br \/>&nbsp;&nbsp; &nbsp;buffer = (unsigned char*)malloc(1001);<br \/>&nbsp;&nbsp; &nbsp;*readLen = 0;<br \/>&nbsp;&nbsp; &nbsp;<br \/>&nbsp;&nbsp; &nbsp;while(1) {<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;\/\/ \ud30c\uc77c BIO\uc5d0\uc11c 1000 \ubc14\uc774\ud2b8 \ub9cc\ud07c \uc77d\uc5b4\uc11c buffer\uc5d0 \uc800\uc7a5\ud55c\ub2e4.<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;length = BIO_read(fileBIO, buffer, 1000);<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;\/\/ \uc548\uc804\uc744 \uc704\ud574 \ubc84\ud37c\uc758 \ub05d\uc740 NULL\ub85c \ucc44\uc6b4\ub2e4.<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;buffer[length] = 0;<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;\/\/ \uc784\uc2dc\ub85c \uc77d\uc740 1000\ubc14\uc774\ud2b8\uc758 \ub370\uc774\ud130\ub97c \ub9ac\ud134 \ubc84\ud37c\uc5d0 \ub354\ud55c\ub2e4.<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;retBuffer = addString(retBuffer, *readLen, buffer, length);<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;\/\/ \uc9c0\uae08\uae4c\uc9c0 \uc77d\uc740 \ub370\uc774\ud130\uc758 \uae38\uc774\ub97c \ub354\ud55c\ub2e4.<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;*readLen = *readLen + length;<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;\/\/ \ub9cc\uc57d \uc9c0\uae08 \ud30c\uc77c\uc5d0\uc11c \uc77d\uc740 \ub370\uc774\ud130\uc758 \uae38\uc774\uac00 \uaf2d 1000 \ubc14\uc774\ud2b8\ub77c\uba74 \uc55e\uc73c\ub85c \ub354 \uc77d\uc744<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;\/\/ \ub370\uc774\ud130\uac00 \uc5c6\uc744 \uac83\uc774\ub2e4. \ud558\uc9c0\ub9cc 1000 \ubc14\uc774\ud2b8\ubcf4\ub2e4 \uc791\ub2e4\uba74 \ub354 \uc774\uc0c1 \uc77d\uc744 \ub370\uc774\ud130\uac00<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;\/\/ \uc5c6\uc744 \uac83\uc774\ubbc0\ub85c \uc885\ub8cc\ud55c\ub2e4.<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;if(length == 1000)<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\/\/ \ud30c\uc77c \ud3ec\uc778\ud130\ub97c 1000 \ubc14\uc774\ud2b8 \ub4a4\ub85c \uc62e\uae34\ub2e4.<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;BIO_seek(fileBIO, 1000);<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;else<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;break;<br \/>&nbsp;&nbsp; &nbsp;}<br \/>&nbsp;&nbsp; &nbsp;<br \/>&nbsp;&nbsp; &nbsp;\/\/ \uac1d\uccb4 \uc0ad\uc81c<br \/>&nbsp;&nbsp; &nbsp;BIO_free(fileBIO);<br \/>&nbsp;&nbsp; &nbsp;free(buffer);<br \/>&nbsp;&nbsp; &nbsp;<br \/>&nbsp;&nbsp; &nbsp;return retBuffer;<br \/>&nbsp;&nbsp; &nbsp;<br \/>}<\/p>\n<p>unsigned char* readFileBio(BIO *fileBIO, int *readLen)<br \/>{<br \/>&nbsp;&nbsp; &nbsp;unsigned char* retBuffer = NULL;<br \/>&nbsp;&nbsp; &nbsp;\/\/ \uc784\uc2dc\ub85c 1000\ubc14\uc774\ud2b8 \ub9cc\ud07c\uc758 \uc77d\uc740 \ub370\uc774\ud130\ub97c \uc800\uc7a5\ud560 \ubc84\ud37c \uc0dd\uc131<br \/>&nbsp;&nbsp; &nbsp;unsigned char* buffer = (unsigned char*)malloc(1001);<br \/>&nbsp;&nbsp; &nbsp;int length = 0;<br \/>&nbsp;&nbsp; &nbsp;<br \/>&nbsp;&nbsp; &nbsp;*readLen = 0;<br \/>&nbsp;&nbsp; &nbsp;<br \/>&nbsp;&nbsp; &nbsp;while(1) {<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;\/\/ \ud30c\uc77c BIO\uc5d0\uc11c 1000\ubc14\uc774\ud2b8 \ub9cc\ud07c \uc77d\uc5b4\uc11c buffer\uc5d0 \uc800\uc7a5\ud55c\ub2e4.<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;length = BIO_read(fileBIO, buffer, 1000);<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;\/\/ \uc548\uc804\uc744 \uc704\ud574 \ubc84\ud37c\uc758 \ub05d\uc740 NULL\ub85c \ucc44\uc6b4\ub2e4<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;buffer[length] = 0;<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;\/\/ \uc784\uc2dc\ub85c \uc77d\uc740 1000\ubc14\uc774\ud2b8\uc758 \ub370\uc774\ud130 \ub9ac\ud134 \ubc84\ud37c\uc5d0 \ub354\ud55c\ub2e4.<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;retBuffer = addString(retBuffer, *readLen, buffer, length);<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;\/\/ \uc9c0\uae08\uae4c\uc9c0 \uc77d\uc740 \ub370\uc774\ud130\uc758 \uae38\uc774\ub97c \ub354\ud55c\ub2e4.<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;*readLen = *readLen + length;<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;\/\/ \ub9cc\uc57d \uc9c0\uae08 \ud30c\uc77c\uc5d0\uc11c \uc77d\uc740 \ub370\uc774\ud130\uc758 \uae38\uc774\uac00 \uaf2d 1000 \ubc14\uc774\ud2b8\ub77c\uba74 \uc55e\uc73c\ub85c \ub354 \uc77d\uc744<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;\/\/ \ub370\uc774\ud130\uac00 \uc788\uc744 \uac83\uc774\ub2e4. \ud558\uc9c0\ub9cc 1000 \ubc14\uc774\ud2b8\ubcf4\ub2e4 \uc791\ub2e4\uba74 \ub354 \uc774\uc0c1 \uc77d\uc744 \ub370\uc774\ud130\uac00<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;\/\/ \uc5c6\uc744 \uac83\uc774\ubbc0\ub85c \uc885\ub8cc \ud55c\ub2e4.<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;if(length == 1000)<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\/\/ \ud30c\uc77c \ud3ec\uc778\ud130\ub97c 1000\ubc14\uc774\ud2b8 \ub4a4\ub85c \uc62e\uae34\ub2e4.<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;BIO_seek(fileBIO, 1000);<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;else<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;break;<br \/>&nbsp;&nbsp; &nbsp;}<br \/>&nbsp;&nbsp; &nbsp;<br \/>&nbsp;&nbsp; &nbsp;return retBuffer;<br \/>}<\/p>\n<p>unsigned char* addString(unsigned char *destString, int destLen, const unsigned char *addString, int addLen)<br \/>{<br \/>&nbsp;&nbsp; &nbsp;\/\/ \ub9ac\ud134 \ud560 \ubc84\ud37c \uc815\uc758<br \/>&nbsp;&nbsp; &nbsp;unsigned char *retString;<br \/>&nbsp;&nbsp; &nbsp;<br \/>&nbsp;&nbsp; &nbsp;int i;<br \/>&nbsp;&nbsp; &nbsp;<br \/>&nbsp;&nbsp; &nbsp;\/\/ \ub9cc\uc57d \ub367\ubd99\uc77c \ub300\uc0c1 \ubc84\ud37c\uac00 NULL, \uc774\uac70\ub098 \uae38\uc774\uac00 0\uc774\uba74 \ub367\ubd99\uc77c \ub300\uc0c1\ubc84\ud37c\uac00 \uc5c6\ub294 \uacbd\uc6b0<br \/>&nbsp;&nbsp; &nbsp;\/\/ \uc774\ubbc0\ub85c \uc0c8\ub85c \uc0dd\uc131\ud558\uace0, \ub367\ubd99\uc77c \ubc84\ud37c\uc758 \ub0b4\uc6a9\uc744 \ubcf5\uc0ac\ud55c\ub2e4.<br \/>&nbsp;&nbsp; &nbsp;if((destString == NULL) || (destLen == 0)) {<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;\/\/ \ub367\ubd99\uc77c \ubc84\ud37c\uc758 \uae38\uc774 \ub9cc\ud07c\uc758 \ubc84\ud37c \uc0dd\uc131<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;retString = (unsigned char*)malloc(sizeof(unsigned char) * (addLen + 1));<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;\/\/ \ub367\ubd99\uc77c \ubc84\ud37c\uc758 \ub0b4\uc6a9\uc744 \uc0c8\ub85c\uc6b4 \ubc84\ud37c\uc5d0 \ubcf5\uc0ac<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;for(i = 0; i &lt; addLen; i++) {<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;retString[i] = addString[i];<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;}<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;\/\/ \uc548\uc804\uc744 \uc704\ud574 \ubc84\ud37c\uc758 \ub9c8\uc9c0\ub9c9\uc5d0 NULL \ubc14\uc774\ud2b8\ub97c \ubd99\uc778\ub2e4.<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;retString[i] = NULL;<br \/>&nbsp;&nbsp; &nbsp;}<br \/>&nbsp;&nbsp; &nbsp;else { &nbsp; &nbsp;\/\/ \ub367\ubd99\uc77c \ub300\uc0c1 \ubc84\ud37c\uac00 \uc788\ub294 \uacbd\uc6b0 \uc774\ubbc0\ub85c \ub300\uc0c1 \ubc84\ud37c\uc758 \uae38\uc774\uc640 \ub367\ubd99\uc77c \ubc84\ud37c\uc758 \uae38\uc774\ub97c<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\/\/ \ub354\ud55c \ub9cc\ud07c\uc758 \ubc84\ud37c\ub97c \uc0c8\ub85c \uc0dd\uc131\ud558\uace0, \ub450 \ubc84\ud37c\uc758 \ub0b4\uc6a9\uc744 \uc0c8\ub85c\uc6b4 \ubc84\ud130\uc5d0 \ubcf5\uc0ac\ud55c\ub2e4.<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;retString = (unsigned char*)malloc(sizeof(unsigned char) * (destLen + addLen + 1));<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;\/\/ \ub367\ubd99\uc77c \ub300\uc0c1 \ubc84\ud37c \ub0b4\uc6a9\uc744 \uc0c8\ub85c\uc6b4 \ubc84\ud37c\uc5d0 \ubcf5\uc0ac<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;for(i = 0; i &lt; destLen; i++) {<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;retString[i] = destString[i];<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;}<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;\/\/ \ub367\ubd99\uc77c \ubc84\ud37c\uc758 \ub0b4\uc6a9\uc744 \uc0c8\ub85c\uc6b4 \ubc84\ud37c\uc5d0 \ubcf5\uc0ac<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;for(i = 0; i &lt; addLen; i++) {<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;retString[i + destLen] = addString[i];<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;}<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;\/\/ \uc548\uc804\uc744 \uc704\ud574 \ubc84\ud37c\uc758 \ub9c8\uc9c0\ub9c9\uc5d0 NULL \ubc14\uc774\ud2b8\ub97c \ubd99\uc778\ub2e4.<br \/>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;retString[i + destLen] = NULL;<br \/>&nbsp;&nbsp; &nbsp;}<br \/>&nbsp;&nbsp; &nbsp;<br \/>&nbsp;&nbsp; &nbsp;\/\/ \uba54\ubaa8\ub9ac\uc5d0\uc11c \uc0ad\uc81c<br \/>&nbsp;&nbsp; &nbsp;free(destString);<br \/>&nbsp;&nbsp; &nbsp;<br \/>&nbsp;&nbsp; &nbsp;return retString;<br \/>}<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\/\/ &nbsp; &nbsp;&nbsp; dec_evp.c\/\/ &nbsp; &nbsp; &nbsp;\/\/ &nbsp; &nbsp;&nbsp; Copyright 2009 Kim Sung-tae &lt;pchero21@gmail.com&gt;\/\/ &nbsp; &nbsp; &nbsp;\/\/ &nbsp; &nbsp;&nbsp; This program is free software; you can redistribute it and\/or modify\/\/ &nbsp; &nbsp;&nbsp; it under the terms of the GNU General &hellip; <a href=\"http:\/\/pchero21.com\/?p=793\">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,364],"_links":{"self":[{"href":"http:\/\/pchero21.com\/index.php?rest_route=\/wp\/v2\/posts\/793"}],"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=793"}],"version-history":[{"count":0,"href":"http:\/\/pchero21.com\/index.php?rest_route=\/wp\/v2\/posts\/793\/revisions"}],"wp:attachment":[{"href":"http:\/\/pchero21.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=793"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/pchero21.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=793"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/pchero21.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=793"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}