<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/> <meta http-equiv="X-UA-Compatible" content="IE=9"/> <meta name="generator" content="Doxygen 1.8.13"/> <meta name="viewport" content="width=device-width, initial-scale=1"/> <title>mbed TLS v2.6.0: blowfish.h Source File</title> <link href="tabs.css" rel="stylesheet" type="text/css"/> <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript" src="dynsections.js"></script> <link href="doxygen.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="top"><!-- do not remove this div, it is closed by doxygen! --> <div id="titlearea"> <table cellspacing="0" cellpadding="0"> <tbody> <tr style="height: 56px;"> <td id="projectalign" style="padding-left: 0.5em;"> <div id="projectname">mbed TLS v2.6.0 </div> </td> </tr> </tbody> </table> </div> <!-- end header part --> <!-- Generated by Doxygen 1.8.13 --> <script type="text/javascript" src="menudata.js"></script> <script type="text/javascript" src="menu.js"></script> <script type="text/javascript"> $(function() { initMenu('',false,false,'search.php','Search'); }); </script> <div id="main-nav"></div> <div id="nav-path" class="navpath"> <ul> <li class="navelem"><a class="el" href="dir_d44c64559bbebec7f509842c48db8b23.html">include</a></li><li class="navelem"><a class="el" href="dir_b4d146e9a6d8dd56ed4afb2480a97fd3.html">mbedtls</a></li> </ul> </div> </div><!-- top --> <div class="header"> <div class="headertitle"> <div class="title">blowfish.h</div> </div> </div><!--header--> <div class="contents"> <a href="blowfish_8h.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno"> 1</span> </div><div class="line"><a name="l00023"></a><span class="lineno"> 23</span> <span class="preprocessor">#ifndef MBEDTLS_BLOWFISH_H</span></div><div class="line"><a name="l00024"></a><span class="lineno"> 24</span> <span class="preprocessor">#define MBEDTLS_BLOWFISH_H</span></div><div class="line"><a name="l00025"></a><span class="lineno"> 25</span> </div><div class="line"><a name="l00026"></a><span class="lineno"> 26</span> <span class="preprocessor">#if !defined(MBEDTLS_CONFIG_FILE)</span></div><div class="line"><a name="l00027"></a><span class="lineno"> 27</span> <span class="preprocessor">#include "<a class="code" href="config_8h.html">config.h</a>"</span></div><div class="line"><a name="l00028"></a><span class="lineno"> 28</span> <span class="preprocessor">#else</span></div><div class="line"><a name="l00029"></a><span class="lineno"> 29</span> <span class="preprocessor">#include MBEDTLS_CONFIG_FILE</span></div><div class="line"><a name="l00030"></a><span class="lineno"> 30</span> <span class="preprocessor">#endif</span></div><div class="line"><a name="l00031"></a><span class="lineno"> 31</span> </div><div class="line"><a name="l00032"></a><span class="lineno"> 32</span> <span class="preprocessor">#include <stddef.h></span></div><div class="line"><a name="l00033"></a><span class="lineno"> 33</span> <span class="preprocessor">#include <stdint.h></span></div><div class="line"><a name="l00034"></a><span class="lineno"> 34</span> </div><div class="line"><a name="l00035"></a><span class="lineno"><a class="line" href="blowfish_8h.html#a34aab9bd2b3ee93f1b8d4d61ecca1813"> 35</a></span> <span class="preprocessor">#define MBEDTLS_BLOWFISH_ENCRYPT 1</span></div><div class="line"><a name="l00036"></a><span class="lineno"><a class="line" href="blowfish_8h.html#a6086a94330e2715de55709b211b74660"> 36</a></span> <span class="preprocessor">#define MBEDTLS_BLOWFISH_DECRYPT 0</span></div><div class="line"><a name="l00037"></a><span class="lineno"><a class="line" href="blowfish_8h.html#ab9ee76bc99b79ca87442dc0e46c232f5"> 37</a></span> <span class="preprocessor">#define MBEDTLS_BLOWFISH_MAX_KEY_BITS 448</span></div><div class="line"><a name="l00038"></a><span class="lineno"><a class="line" href="blowfish_8h.html#ab0c941b14f54f62f35565d96d4c9d592"> 38</a></span> <span class="preprocessor">#define MBEDTLS_BLOWFISH_MIN_KEY_BITS 32</span></div><div class="line"><a name="l00039"></a><span class="lineno"><a class="line" href="blowfish_8h.html#a9a9858208f44ea332105fcb68ef93f06"> 39</a></span> <span class="preprocessor">#define MBEDTLS_BLOWFISH_ROUNDS 16 </span></div><div class="line"><a name="l00040"></a><span class="lineno"><a class="line" href="blowfish_8h.html#aeb0e924c896432e403795a34863219db"> 40</a></span> <span class="preprocessor">#define MBEDTLS_BLOWFISH_BLOCKSIZE 8 </span><span class="comment">/* Blowfish uses 64 bit blocks */</span><span class="preprocessor"></span></div><div class="line"><a name="l00041"></a><span class="lineno"> 41</span> </div><div class="line"><a name="l00042"></a><span class="lineno"><a class="line" href="blowfish_8h.html#ada258472bd81338e8dc2d3361487a51b"> 42</a></span> <span class="preprocessor">#define MBEDTLS_ERR_BLOWFISH_INVALID_KEY_LENGTH -0x0016 </span></div><div class="line"><a name="l00043"></a><span class="lineno"><a class="line" href="blowfish_8h.html#a279c1b5f0ab064fc6591a3ca324f3830"> 43</a></span> <span class="preprocessor">#define MBEDTLS_ERR_BLOWFISH_INVALID_INPUT_LENGTH -0x0018 </span></div><div class="line"><a name="l00045"></a><span class="lineno"> 45</span> <span class="preprocessor">#if !defined(MBEDTLS_BLOWFISH_ALT)</span></div><div class="line"><a name="l00046"></a><span class="lineno"> 46</span> <span class="comment">// Regular implementation</span></div><div class="line"><a name="l00047"></a><span class="lineno"> 47</span> <span class="comment">//</span></div><div class="line"><a name="l00048"></a><span class="lineno"> 48</span> </div><div class="line"><a name="l00049"></a><span class="lineno"> 49</span> <span class="preprocessor">#ifdef __cplusplus</span></div><div class="line"><a name="l00050"></a><span class="lineno"> 50</span> <span class="keyword">extern</span> <span class="stringliteral">"C"</span> {</div><div class="line"><a name="l00051"></a><span class="lineno"> 51</span> <span class="preprocessor">#endif</span></div><div class="line"><a name="l00052"></a><span class="lineno"> 52</span> </div><div class="line"><a name="l00056"></a><span class="lineno"><a class="line" href="structmbedtls__blowfish__context.html"> 56</a></span> <span class="keyword">typedef</span> <span class="keyword">struct</span></div><div class="line"><a name="l00057"></a><span class="lineno"> 57</span> {</div><div class="line"><a name="l00058"></a><span class="lineno"><a class="line" href="structmbedtls__blowfish__context.html#a6797f919a5b195cef17647d3d63ec13f"> 58</a></span>  uint32_t P[<a class="code" href="blowfish_8h.html#a9a9858208f44ea332105fcb68ef93f06">MBEDTLS_BLOWFISH_ROUNDS</a> + 2]; </div><div class="line"><a name="l00059"></a><span class="lineno"><a class="line" href="structmbedtls__blowfish__context.html#ab366ec526d9d5303483ed9c5bbb6a049"> 59</a></span>  uint32_t S[4][256]; </div><div class="line"><a name="l00060"></a><span class="lineno"> 60</span> }</div><div class="line"><a name="l00061"></a><span class="lineno"> 61</span> <a class="code" href="structmbedtls__blowfish__context.html">mbedtls_blowfish_context</a>;</div><div class="line"><a name="l00062"></a><span class="lineno"> 62</span> </div><div class="line"><a name="l00068"></a><span class="lineno"> 68</span> <span class="keywordtype">void</span> <a class="code" href="blowfish_8h.html#ab3f9ff267483076e9c834df5b362ecff">mbedtls_blowfish_init</a>( <a class="code" href="structmbedtls__blowfish__context.html">mbedtls_blowfish_context</a> *ctx );</div><div class="line"><a name="l00069"></a><span class="lineno"> 69</span> </div><div class="line"><a name="l00075"></a><span class="lineno"> 75</span> <span class="keywordtype">void</span> <a class="code" href="blowfish_8h.html#ac249a721d4a718295311305471d9d80b">mbedtls_blowfish_free</a>( <a class="code" href="structmbedtls__blowfish__context.html">mbedtls_blowfish_context</a> *ctx );</div><div class="line"><a name="l00076"></a><span class="lineno"> 76</span> </div><div class="line"><a name="l00086"></a><span class="lineno"> 86</span> <span class="keywordtype">int</span> <a class="code" href="blowfish_8h.html#a272e6906daa7083c8020f3311da7fb12">mbedtls_blowfish_setkey</a>( <a class="code" href="structmbedtls__blowfish__context.html">mbedtls_blowfish_context</a> *ctx, <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> *key,</div><div class="line"><a name="l00087"></a><span class="lineno"> 87</span>  <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> keybits );</div><div class="line"><a name="l00088"></a><span class="lineno"> 88</span> </div><div class="line"><a name="l00099"></a><span class="lineno"> 99</span> <span class="keywordtype">int</span> <a class="code" href="blowfish_8h.html#afe15cef6820aa39a999e7268bf6f4c29">mbedtls_blowfish_crypt_ecb</a>( <a class="code" href="structmbedtls__blowfish__context.html">mbedtls_blowfish_context</a> *ctx,</div><div class="line"><a name="l00100"></a><span class="lineno"> 100</span>  <span class="keywordtype">int</span> mode,</div><div class="line"><a name="l00101"></a><span class="lineno"> 101</span>  <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> input[<a class="code" href="blowfish_8h.html#aeb0e924c896432e403795a34863219db">MBEDTLS_BLOWFISH_BLOCKSIZE</a>],</div><div class="line"><a name="l00102"></a><span class="lineno"> 102</span>  <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> output[MBEDTLS_BLOWFISH_BLOCKSIZE] );</div><div class="line"><a name="l00103"></a><span class="lineno"> 103</span> </div><div class="line"><a name="l00104"></a><span class="lineno"> 104</span> <span class="preprocessor">#if defined(MBEDTLS_CIPHER_MODE_CBC)</span></div><div class="line"><a name="l00105"></a><span class="lineno"> 105</span> </div><div class="line"><a name="l00128"></a><span class="lineno"> 128</span> <span class="keywordtype">int</span> <a class="code" href="blowfish_8h.html#a24f95511214b38914090036938cbc045">mbedtls_blowfish_crypt_cbc</a>( <a class="code" href="structmbedtls__blowfish__context.html">mbedtls_blowfish_context</a> *ctx,</div><div class="line"><a name="l00129"></a><span class="lineno"> 129</span>  <span class="keywordtype">int</span> mode,</div><div class="line"><a name="l00130"></a><span class="lineno"> 130</span>  <span class="keywordtype">size_t</span> length,</div><div class="line"><a name="l00131"></a><span class="lineno"> 131</span>  <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> iv[<a class="code" href="blowfish_8h.html#aeb0e924c896432e403795a34863219db">MBEDTLS_BLOWFISH_BLOCKSIZE</a>],</div><div class="line"><a name="l00132"></a><span class="lineno"> 132</span>  <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> *input,</div><div class="line"><a name="l00133"></a><span class="lineno"> 133</span>  <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> *output );</div><div class="line"><a name="l00134"></a><span class="lineno"> 134</span> <span class="preprocessor">#endif </span><span class="comment">/* MBEDTLS_CIPHER_MODE_CBC */</span><span class="preprocessor"></span></div><div class="line"><a name="l00135"></a><span class="lineno"> 135</span> </div><div class="line"><a name="l00136"></a><span class="lineno"> 136</span> <span class="preprocessor">#if defined(MBEDTLS_CIPHER_MODE_CFB)</span></div><div class="line"><a name="l00137"></a><span class="lineno"> 137</span> </div><div class="line"><a name="l00158"></a><span class="lineno"> 158</span> <span class="keywordtype">int</span> <a class="code" href="blowfish_8h.html#af3996e5bb50864497b0c7349819ffd12">mbedtls_blowfish_crypt_cfb64</a>( <a class="code" href="structmbedtls__blowfish__context.html">mbedtls_blowfish_context</a> *ctx,</div><div class="line"><a name="l00159"></a><span class="lineno"> 159</span>  <span class="keywordtype">int</span> mode,</div><div class="line"><a name="l00160"></a><span class="lineno"> 160</span>  <span class="keywordtype">size_t</span> length,</div><div class="line"><a name="l00161"></a><span class="lineno"> 161</span>  <span class="keywordtype">size_t</span> *iv_off,</div><div class="line"><a name="l00162"></a><span class="lineno"> 162</span>  <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> iv[<a class="code" href="blowfish_8h.html#aeb0e924c896432e403795a34863219db">MBEDTLS_BLOWFISH_BLOCKSIZE</a>],</div><div class="line"><a name="l00163"></a><span class="lineno"> 163</span>  <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> *input,</div><div class="line"><a name="l00164"></a><span class="lineno"> 164</span>  <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> *output );</div><div class="line"><a name="l00165"></a><span class="lineno"> 165</span> <span class="preprocessor">#endif </span><span class="comment">/*MBEDTLS_CIPHER_MODE_CFB */</span><span class="preprocessor"></span></div><div class="line"><a name="l00166"></a><span class="lineno"> 166</span> </div><div class="line"><a name="l00167"></a><span class="lineno"> 167</span> <span class="preprocessor">#if defined(MBEDTLS_CIPHER_MODE_CTR)</span></div><div class="line"><a name="l00168"></a><span class="lineno"> 168</span> </div><div class="line"><a name="l00186"></a><span class="lineno"> 186</span> <span class="keywordtype">int</span> <a class="code" href="blowfish_8h.html#a7d1688bf5fb906fdbad101e08bc8bf85">mbedtls_blowfish_crypt_ctr</a>( <a class="code" href="structmbedtls__blowfish__context.html">mbedtls_blowfish_context</a> *ctx,</div><div class="line"><a name="l00187"></a><span class="lineno"> 187</span>  <span class="keywordtype">size_t</span> length,</div><div class="line"><a name="l00188"></a><span class="lineno"> 188</span>  <span class="keywordtype">size_t</span> *nc_off,</div><div class="line"><a name="l00189"></a><span class="lineno"> 189</span>  <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> nonce_counter[<a class="code" href="blowfish_8h.html#aeb0e924c896432e403795a34863219db">MBEDTLS_BLOWFISH_BLOCKSIZE</a>],</div><div class="line"><a name="l00190"></a><span class="lineno"> 190</span>  <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> stream_block[MBEDTLS_BLOWFISH_BLOCKSIZE],</div><div class="line"><a name="l00191"></a><span class="lineno"> 191</span>  <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> *input,</div><div class="line"><a name="l00192"></a><span class="lineno"> 192</span>  <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> *output );</div><div class="line"><a name="l00193"></a><span class="lineno"> 193</span> <span class="preprocessor">#endif </span><span class="comment">/* MBEDTLS_CIPHER_MODE_CTR */</span><span class="preprocessor"></span></div><div class="line"><a name="l00194"></a><span class="lineno"> 194</span> </div><div class="line"><a name="l00195"></a><span class="lineno"> 195</span> <span class="preprocessor">#ifdef __cplusplus</span></div><div class="line"><a name="l00196"></a><span class="lineno"> 196</span> }</div><div class="line"><a name="l00197"></a><span class="lineno"> 197</span> <span class="preprocessor">#endif</span></div><div class="line"><a name="l00198"></a><span class="lineno"> 198</span> </div><div class="line"><a name="l00199"></a><span class="lineno"> 199</span> <span class="preprocessor">#else </span><span class="comment">/* MBEDTLS_BLOWFISH_ALT */</span><span class="preprocessor"></span></div><div class="line"><a name="l00200"></a><span class="lineno"> 200</span> <span class="preprocessor">#include "blowfish_alt.h"</span></div><div class="line"><a name="l00201"></a><span class="lineno"> 201</span> <span class="preprocessor">#endif </span><span class="comment">/* MBEDTLS_BLOWFISH_ALT */</span><span class="preprocessor"></span></div><div class="line"><a name="l00202"></a><span class="lineno"> 202</span> </div><div class="line"><a name="l00203"></a><span class="lineno"> 203</span> <span class="preprocessor">#endif </span><span class="comment">/* blowfish.h */</span><span class="preprocessor"></span></div><div class="ttc" id="blowfish_8h_html_aeb0e924c896432e403795a34863219db"><div class="ttname"><a href="blowfish_8h.html#aeb0e924c896432e403795a34863219db">MBEDTLS_BLOWFISH_BLOCKSIZE</a></div><div class="ttdeci">#define MBEDTLS_BLOWFISH_BLOCKSIZE</div><div class="ttdef"><b>Definition:</b> <a href="blowfish_8h_source.html#l00040">blowfish.h:40</a></div></div> <div class="ttc" id="blowfish_8h_html_a7d1688bf5fb906fdbad101e08bc8bf85"><div class="ttname"><a href="blowfish_8h.html#a7d1688bf5fb906fdbad101e08bc8bf85">mbedtls_blowfish_crypt_ctr</a></div><div class="ttdeci">int mbedtls_blowfish_crypt_ctr(mbedtls_blowfish_context *ctx, size_t length, size_t *nc_off, unsigned char nonce_counter[MBEDTLS_BLOWFISH_BLOCKSIZE], unsigned char stream_block[MBEDTLS_BLOWFISH_BLOCKSIZE], const unsigned char *input, unsigned char *output)</div><div class="ttdoc">Blowfish-CTR buffer encryption/decryption. </div></div> <div class="ttc" id="config_8h_html"><div class="ttname"><a href="config_8h.html">config.h</a></div><div class="ttdoc">Configuration options (set of defines) </div></div> <div class="ttc" id="structmbedtls__blowfish__context_html"><div class="ttname"><a href="structmbedtls__blowfish__context.html">mbedtls_blowfish_context</a></div><div class="ttdoc">Blowfish context structure. </div><div class="ttdef"><b>Definition:</b> <a href="blowfish_8h_source.html#l00056">blowfish.h:56</a></div></div> <div class="ttc" id="blowfish_8h_html_ab3f9ff267483076e9c834df5b362ecff"><div class="ttname"><a href="blowfish_8h.html#ab3f9ff267483076e9c834df5b362ecff">mbedtls_blowfish_init</a></div><div class="ttdeci">void mbedtls_blowfish_init(mbedtls_blowfish_context *ctx)</div><div class="ttdoc">Initialize Blowfish context. </div></div> <div class="ttc" id="blowfish_8h_html_af3996e5bb50864497b0c7349819ffd12"><div class="ttname"><a href="blowfish_8h.html#af3996e5bb50864497b0c7349819ffd12">mbedtls_blowfish_crypt_cfb64</a></div><div class="ttdeci">int mbedtls_blowfish_crypt_cfb64(mbedtls_blowfish_context *ctx, int mode, size_t length, size_t *iv_off, unsigned char iv[MBEDTLS_BLOWFISH_BLOCKSIZE], const unsigned char *input, unsigned char *output)</div><div class="ttdoc">Blowfish CFB buffer encryption/decryption. </div></div> <div class="ttc" id="blowfish_8h_html_a24f95511214b38914090036938cbc045"><div class="ttname"><a href="blowfish_8h.html#a24f95511214b38914090036938cbc045">mbedtls_blowfish_crypt_cbc</a></div><div class="ttdeci">int mbedtls_blowfish_crypt_cbc(mbedtls_blowfish_context *ctx, int mode, size_t length, unsigned char iv[MBEDTLS_BLOWFISH_BLOCKSIZE], const unsigned char *input, unsigned char *output)</div><div class="ttdoc">Blowfish-CBC buffer encryption/decryption Length should be a multiple of the block size (8 bytes) ...</div></div> <div class="ttc" id="blowfish_8h_html_afe15cef6820aa39a999e7268bf6f4c29"><div class="ttname"><a href="blowfish_8h.html#afe15cef6820aa39a999e7268bf6f4c29">mbedtls_blowfish_crypt_ecb</a></div><div class="ttdeci">int mbedtls_blowfish_crypt_ecb(mbedtls_blowfish_context *ctx, int mode, const unsigned char input[MBEDTLS_BLOWFISH_BLOCKSIZE], unsigned char output[MBEDTLS_BLOWFISH_BLOCKSIZE])</div><div class="ttdoc">Blowfish-ECB block encryption/decryption. </div></div> <div class="ttc" id="blowfish_8h_html_a272e6906daa7083c8020f3311da7fb12"><div class="ttname"><a href="blowfish_8h.html#a272e6906daa7083c8020f3311da7fb12">mbedtls_blowfish_setkey</a></div><div class="ttdeci">int mbedtls_blowfish_setkey(mbedtls_blowfish_context *ctx, const unsigned char *key, unsigned int keybits)</div><div class="ttdoc">Blowfish key schedule. </div></div> <div class="ttc" id="blowfish_8h_html_a9a9858208f44ea332105fcb68ef93f06"><div class="ttname"><a href="blowfish_8h.html#a9a9858208f44ea332105fcb68ef93f06">MBEDTLS_BLOWFISH_ROUNDS</a></div><div class="ttdeci">#define MBEDTLS_BLOWFISH_ROUNDS</div><div class="ttdoc">Rounds to use. </div><div class="ttdef"><b>Definition:</b> <a href="blowfish_8h_source.html#l00039">blowfish.h:39</a></div></div> <div class="ttc" id="blowfish_8h_html_ac249a721d4a718295311305471d9d80b"><div class="ttname"><a href="blowfish_8h.html#ac249a721d4a718295311305471d9d80b">mbedtls_blowfish_free</a></div><div class="ttdeci">void mbedtls_blowfish_free(mbedtls_blowfish_context *ctx)</div><div class="ttdoc">Clear Blowfish context. </div></div> </div><!-- fragment --></div><!-- contents --> <!-- start footer part --> <hr class="footer"/><address class="footer"><small> Generated on Thu Dec 28 2017 18:33:29 for mbed TLS v2.6.0 by  <a href="http://www.doxygen.org/index.html"> <img class="footer" src="doxygen.png" alt="doxygen"/> </a> 1.8.13 </small></address> </body> </html>