aboutsummaryrefslogtreecommitdiff
path: root/doc/doxyout/hcrypto/html/example_evp_cipher_8c-example.html
diff options
context:
space:
mode:
Diffstat (limited to 'doc/doxyout/hcrypto/html/example_evp_cipher_8c-example.html')
-rw-r--r--doc/doxyout/hcrypto/html/example_evp_cipher_8c-example.html2
1 files changed, 1 insertions, 1 deletions
diff --git a/doc/doxyout/hcrypto/html/example_evp_cipher_8c-example.html b/doc/doxyout/hcrypto/html/example_evp_cipher_8c-example.html
index 33d7824e6b61..0d96ac2cc42f 100644
--- a/doc/doxyout/hcrypto/html/example_evp_cipher_8c-example.html
+++ b/doc/doxyout/hcrypto/html/example_evp_cipher_8c-example.html
@@ -26,6 +26,6 @@ $(function() {
<p>This is an example how to use <a class="el" href="group__hcrypto__evp.html#ga98da5a5c1aa25d9cb2e4717fa11314bd">EVP_CipherInit_ex()</a>, <a class="el" href="group__hcrypto__evp.html#ga863349e1001b36cfd6c4afedddd12862">EVP_CipherUpdate()</a> and <a class="el" href="group__hcrypto__evp.html#ga714eef7d737fd68171d852043a4995de">EVP_CipherFinal_ex()</a>.</p>
<div class="fragment"><div class="line"><span class="comment">/*</span></div><div class="line"><span class="comment"> * Copyright (c) 2008 Kungliga Tekniska Högskolan</span></div><div class="line"><span class="comment"> * (Royal Institute of Technology, Stockholm, Sweden).</span></div><div class="line"><span class="comment"> * All rights reserved.</span></div><div class="line"><span class="comment"> *</span></div><div class="line"><span class="comment"> * Redistribution and use in source and binary forms, with or without</span></div><div class="line"><span class="comment"> * modification, are permitted provided that the following conditions</span></div><div class="line"><span class="comment"> * are met:</span></div><div class="line"><span class="comment"> *</span></div><div class="line"><span class="comment"> * 1. Redistributions of source code must retain the above copyright</span></div><div class="line"><span class="comment"> * notice, this list of conditions and the following disclaimer.</span></div><div class="line"><span class="comment"> *</span></div><div class="line"><span class="comment"> * 2. Redistributions in binary form must reproduce the above copyright</span></div><div class="line"><span class="comment"> * notice, this list of conditions and the following disclaimer in the</span></div><div class="line"><span class="comment"> * documentation and/or other materials provided with the distribution.</span></div><div class="line"><span class="comment"> *</span></div><div class="line"><span class="comment"> * 3. Neither the name of the Institute nor the names of its contributors</span></div><div class="line"><span class="comment"> * may be used to endorse or promote products derived from this software</span></div><div class="line"><span class="comment"> * without specific prior written permission.</span></div><div class="line"><span class="comment"> *</span></div><div class="line"><span class="comment"> * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS&#39;&#39; AND</span></div><div class="line"><span class="comment"> * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE</span></div><div class="line"><span class="comment"> * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE</span></div><div class="line"><span class="comment"> * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE</span></div><div class="line"><span class="comment"> * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL</span></div><div class="line"><span class="comment"> * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS</span></div><div class="line"><span class="comment"> * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)</span></div><div class="line"><span class="comment"> * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT</span></div><div class="line"><span class="comment"> * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY</span></div><div class="line"><span class="comment"> * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF</span></div><div class="line"><span class="comment"> * SUCH DAMAGE.</span></div><div class="line"><span class="comment"> */</span></div><div class="line"></div><div class="line"><span class="preprocessor">#include &lt;config.h&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;roken.h&gt;</span></div><div class="line"></div><div class="line"><span class="preprocessor">#include &lt;krb5-types.h&gt;</span> <span class="comment">/* should really be stdint.h */</span></div><div class="line"><span class="preprocessor">#include &lt;hcrypto/evp.h&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;hcrypto/evp-pkcs11.h&gt;</span></div><div class="line"><span class="preprocessor">#ifdef __APPLE__</span></div><div class="line"><span class="preprocessor">#include &lt;hcrypto/evp-cc.h&gt;</span></div><div class="line"><span class="preprocessor">#endif</span></div><div class="line"><span class="preprocessor">#ifdef _WIN32</span></div><div class="line"><span class="preprocessor">#include &lt;hcrypto/evp-w32.h&gt;</span></div><div class="line"><span class="preprocessor">#endif</span></div><div class="line"></div><div class="line"><span class="preprocessor">#include &lt;err.h&gt;</span></div><div class="line"><span class="preprocessor">#include &lt;assert.h&gt;</span></div><div class="line"></div><div class="line"><span class="comment">/* key and initial vector */</span></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">char</span> key[16] =</div><div class="line"> <span class="stringliteral">&quot;\xaa\xbb\x45\xd4\xaa\xbb\x45\xd4&quot;</span></div><div class="line"> <span class="stringliteral">&quot;\xaa\xbb\x45\xd4\xaa\xbb\x45\xd4&quot;</span>;</div><div class="line"><span class="keyword">static</span> <span class="keywordtype">char</span> ivec[16] =</div><div class="line"> <span class="stringliteral">&quot;\xaa\xbb\x45\xd4\xaa\xbb\x45\xd4&quot;</span></div><div class="line"> <span class="stringliteral">&quot;\xaa\xbb\x45\xd4\xaa\xbb\x45\xd4&quot;</span>;</div><div class="line"></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">void</span></div><div class="line">usage(<span class="keywordtype">int</span> exit_code) __attribute__((noreturn));</div><div class="line"></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">void</span></div><div class="line">usage(<span class="keywordtype">int</span> exit_code)</div><div class="line">{</div><div class="line"> printf(<span class="stringliteral">&quot;usage: %s in out [pkcs11 | cc | w32]\n&quot;</span>, getprogname());</div><div class="line"> exit(exit_code);</div><div class="line">}</div><div class="line"></div><div class="line"></div><div class="line"><span class="keywordtype">int</span></div><div class="line">main(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> **argv)</div><div class="line">{</div><div class="line"> <span class="keywordtype">int</span> encryptp = 1;</div><div class="line"> <span class="keyword">const</span> <span class="keywordtype">char</span> *ifn = NULL, *ofn = NULL;</div><div class="line"> FILE *in, *out;</div><div class="line"> <span class="keywordtype">void</span> *ibuf, *obuf;</div><div class="line"> <span class="keywordtype">int</span> ilen, olen;</div><div class="line"> <span class="keywordtype">size_t</span> block_size = 0;</div><div class="line"> <span class="keyword">const</span> EVP_CIPHER *c = <a name="a0"></a><a class="code" href="group__hcrypto__evp.html#ga2747bac943db15c97167ac37fdc2af43">EVP_aes_128_cbc</a>();</div><div class="line"> EVP_CIPHER_CTX ctx;</div><div class="line"> <span class="keywordtype">int</span> ret;</div><div class="line"></div><div class="line"> setprogname(argv[0]);</div><div class="line"></div><div class="line"> <span class="keywordflow">if</span> (argc == 2) {</div><div class="line"> <span class="keywordflow">if</span> (strcmp(argv[1], <span class="stringliteral">&quot;--version&quot;</span>) == 0) {</div><div class="line"> printf(<span class="stringliteral">&quot;version&quot;</span>);</div><div class="line"> exit(0);</div><div class="line"> }</div><div class="line"> <span class="keywordflow">if</span> (strcmp(argv[1], <span class="stringliteral">&quot;--help&quot;</span>) == 0)</div><div class="line"> usage(0);</div><div class="line"> usage(1);</div><div class="line"> } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (argc == 4 || argc == 5) {</div><div class="line"> block_size = atoi(argv[1]);</div><div class="line"> <span class="keywordflow">if</span> (block_size == 0)</div><div class="line"> errx(1, <span class="stringliteral">&quot;invalid blocksize %s&quot;</span>, argv[1]);</div><div class="line"> ifn = argv[2];</div><div class="line"> ofn = argv[3];</div><div class="line"> <span class="keywordflow">if</span> (argc == 5) {</div><div class="line"> <span class="keywordflow">if</span> (strcmp(argv[4], <span class="stringliteral">&quot;pkcs11&quot;</span>) == 0)</div><div class="line"> c = hc_EVP_pkcs11_aes_128_cbc();</div><div class="line"><span class="preprocessor">#ifdef __APPLE__</span></div><div class="line"> <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strcmp(argv[4], <span class="stringliteral">&quot;cc&quot;</span>) == 0)</div><div class="line"> c = hc_EVP_cc_aes_128_cbc();</div><div class="line"><span class="preprocessor">#endif</span></div><div class="line"><span class="preprocessor">#ifdef _WIN32</span></div><div class="line"> <span class="keywordflow">else</span> <span class="keywordflow">if</span> (strcmp(argv[4], <span class="stringliteral">&quot;w32&quot;</span>) == 0)</div><div class="line"> c = hc_EVP_w32crypto_aes_128_cbc();</div><div class="line"><span class="preprocessor">#endif</span></div><div class="line"> <span class="keywordflow">else</span></div><div class="line"> usage(1);</div><div class="line"> }</div><div class="line"> } <span class="keywordflow">else</span></div><div class="line"> usage(1);</div><div class="line"></div><div class="line"> in = fopen(ifn, <span class="stringliteral">&quot;r&quot;</span>);</div><div class="line"> <span class="keywordflow">if</span> (in == NULL)</div><div class="line"> errx(1, <span class="stringliteral">&quot;failed to open input file&quot;</span>);</div><div class="line"> out = fopen(ofn, <span class="stringliteral">&quot;w+&quot;</span>);</div><div class="line"> <span class="keywordflow">if</span> (out == NULL)</div><div class="line"> errx(1, <span class="stringliteral">&quot;failed to open output file&quot;</span>);</div><div class="line"></div><div class="line"> <span class="comment">/* Check that key and ivec are long enough */</span></div><div class="line"> assert(<a name="a1"></a><a class="code" href="group__hcrypto__evp.html#ga4793a9e130da86ac42c497b19395b748">EVP_CIPHER_key_length</a>(c) &lt;= <span class="keyword">sizeof</span>(key));</div><div class="line"> assert(<a name="a2"></a><a class="code" href="group__hcrypto__evp.html#ga7edebe76d19dee11686a6698d24f19f5">EVP_CIPHER_iv_length</a>(c) &lt;= <span class="keyword">sizeof</span>(ivec));</div><div class="line"></div><div class="line"> <span class="comment">/*</span></div><div class="line"><span class="comment"> * Allocate buffer, the output buffer is at least</span></div><div class="line"><span class="comment"> * EVP_CIPHER_block_size() longer</span></div><div class="line"><span class="comment"> */</span></div><div class="line"> ibuf = malloc(block_size);</div><div class="line"> obuf = malloc(block_size + <a name="a3"></a><a class="code" href="group__hcrypto__evp.html#ga3123ff4b426783dd972538249b9e9d4d">EVP_CIPHER_block_size</a>(c));</div><div class="line"></div><div class="line"> <span class="comment">/*</span></div><div class="line"><span class="comment"> * Init the memory used for EVP_CIPHER_CTX and set the key and</span></div><div class="line"><span class="comment"> * ivec.</span></div><div class="line"><span class="comment"> */</span></div><div class="line"> <a name="a4"></a><a class="code" href="group__hcrypto__evp.html#ga13d0ff0e87312566cb6b3591157f9754">EVP_CIPHER_CTX_init</a>(&amp;ctx);</div><div class="line"> <a name="a5"></a><a class="code" href="group__hcrypto__evp.html#ga98da5a5c1aa25d9cb2e4717fa11314bd">EVP_CipherInit_ex</a>(&amp;ctx, c, NULL, key, ivec, encryptp);</div><div class="line"></div><div class="line"> <span class="comment">/* read in buffer */</span></div><div class="line"> <span class="keywordflow">while</span> ((ilen = fread(ibuf, 1, block_size, in)) &gt; 0) {</div><div class="line"> <span class="comment">/* encrypto/decrypt */</span></div><div class="line"> ret = <a name="a6"></a><a class="code" href="group__hcrypto__evp.html#ga863349e1001b36cfd6c4afedddd12862">EVP_CipherUpdate</a>(&amp;ctx, obuf, &amp;olen, ibuf, ilen);</div><div class="line"> <span class="keywordflow">if</span> (ret != 1) {</div><div class="line"> <a name="a7"></a><a class="code" href="group__hcrypto__evp.html#gac16dd3987cd90c8bcdbad5290c558359">EVP_CIPHER_CTX_cleanup</a>(&amp;ctx);</div><div class="line"> errx(1, <span class="stringliteral">&quot;EVP_CipherUpdate failed&quot;</span>);</div><div class="line"> }</div><div class="line"> <span class="comment">/* write out to output file */</span></div><div class="line"> fwrite(obuf, 1, olen, out);</div><div class="line"> }</div><div class="line"> <span class="comment">/* done reading */</span></div><div class="line"> fclose(in);</div><div class="line"></div><div class="line"> <span class="comment">/* clear up any last bytes left in the output buffer */</span></div><div class="line"> ret = <a name="a8"></a><a class="code" href="group__hcrypto__evp.html#ga714eef7d737fd68171d852043a4995de">EVP_CipherFinal_ex</a>(&amp;ctx, obuf, &amp;olen);</div><div class="line"> <a class="code" href="group__hcrypto__evp.html#gac16dd3987cd90c8bcdbad5290c558359">EVP_CIPHER_CTX_cleanup</a>(&amp;ctx);</div><div class="line"> <span class="keywordflow">if</span> (ret != 1)</div><div class="line"> errx(1, <span class="stringliteral">&quot;EVP_CipherFinal_ex failed&quot;</span>);</div><div class="line"></div><div class="line"> <span class="comment">/* write the last bytes out and close */</span></div><div class="line"> fwrite(obuf, 1, olen, out);</div><div class="line"> fclose(out);</div><div class="line"></div><div class="line"> <span class="keywordflow">return</span> 0;</div><div class="line">}</div></div><!-- fragment --> </div><!-- contents -->
<hr size="1"><address style="text-align: right;"><small>
-Generated on Fri Dec 8 2017 03:49:01 for Heimdal crypto library by&nbsp;<a href="http://www.doxygen.org/index.html"><img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.8.13</small></address>
+Generated on Fri Jun 7 2019 02:49:57 for Heimdal crypto library by&nbsp;<a href="http://www.doxygen.org/index.html"><img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.8.13</small></address>
</body>
</html>