1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
|
<!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"/>
<title>WiredTiger: nop_encrypt.c</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="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
$(document).ready(initResizable);
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="wiredtiger.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="projectlogo"><a href="http://wiredtiger.com/"><img alt="Logo" src="LogoFinal-header.png" alt="WiredTiger" /></a></td>
<td style="padding-left: 0.5em;">
<div id="projectname">
 <span id="projectnumber">Version 3.2.1</span>
</div>
<div id="projectbrief"><!-- 3.2.1 --></div>
</td>
</tr>
</tbody>
</table>
</div>
<div class="banner">
<a href="https://github.com/wiredtiger/wiredtiger">Fork me on GitHub</a>
<a class="last" href="http://groups.google.com/group/wiredtiger-users">Join my user group</a>
</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><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
<div id="nav-tree">
<div id="nav-tree-contents">
<div id="nav-sync" class="sync"></div>
</div>
</div>
<div id="splitbar" style="-moz-user-select:none;"
class="ui-resizable-handle">
</div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('nop_encrypt_8c-example.html','');});
</script>
<div id="doc-content">
<div class="header">
<div class="headertitle">
<div class="title">nop_encrypt.c</div> </div>
</div><!--header-->
<div class="contents">
<p>Shows the basic framework for building an encryptor as a plug in library.</p>
<div class="fragment"><div class="line"><span class="comment">/*-</span></div><div class="line"><span class="comment"> * Public Domain 2014-2019 MongoDB, Inc.</span></div><div class="line"><span class="comment"> * Public Domain 2008-2014 WiredTiger, Inc.</span></div><div class="line"><span class="comment"> *</span></div><div class="line"><span class="comment"> * This is free and unencumbered software released into the public domain.</span></div><div class="line"><span class="comment"> *</span></div><div class="line"><span class="comment"> * Anyone is free to copy, modify, publish, use, compile, sell, or</span></div><div class="line"><span class="comment"> * distribute this software, either in source code form or as a compiled</span></div><div class="line"><span class="comment"> * binary, for any purpose, commercial or non-commercial, and by any</span></div><div class="line"><span class="comment"> * means.</span></div><div class="line"><span class="comment"> *</span></div><div class="line"><span class="comment"> * In jurisdictions that recognize copyright laws, the author or authors</span></div><div class="line"><span class="comment"> * of this software dedicate any and all copyright interest in the</span></div><div class="line"><span class="comment"> * software to the public domain. We make this dedication for the benefit</span></div><div class="line"><span class="comment"> * of the public at large and to the detriment of our heirs and</span></div><div class="line"><span class="comment"> * successors. We intend this dedication to be an overt act of</span></div><div class="line"><span class="comment"> * relinquishment in perpetuity of all present and future rights to this</span></div><div class="line"><span class="comment"> * software under copyright law.</span></div><div class="line"><span class="comment"> *</span></div><div class="line"><span class="comment"> * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,</span></div><div class="line"><span class="comment"> * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF</span></div><div class="line"><span class="comment"> * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.</span></div><div class="line"><span class="comment"> * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR</span></div><div class="line"><span class="comment"> * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,</span></div><div class="line"><span class="comment"> * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR</span></div><div class="line"><span class="comment"> * OTHER DEALINGS IN THE SOFTWARE.</span></div><div class="line"><span class="comment"> */</span></div><div class="line"></div><div class="line"><span class="preprocessor">#include <errno.h></span></div><div class="line"><span class="preprocessor">#include <stdlib.h></span></div><div class="line"><span class="preprocessor">#include <string.h></span></div><div class="line"></div><div class="line"><span class="preprocessor">#include <wiredtiger.h></span></div><div class="line"><span class="preprocessor">#include <wiredtiger_ext.h></span></div><div class="line"></div><div class="line"><span class="comment">/* Local encryptor structure. */</span></div><div class="line"><span class="keyword">typedef</span> <span class="keyword">struct </span>{</div><div class="line"> <a name="_a0"></a><a class="code" href="struct_w_t___e_n_c_r_y_p_t_o_r.html">WT_ENCRYPTOR</a> encryptor; <span class="comment">/* Must come first */</span></div><div class="line"></div><div class="line"> <a name="_a1"></a><a class="code" href="struct_w_t___e_x_t_e_n_s_i_o_n___a_p_i.html">WT_EXTENSION_API</a> *wt_api; <span class="comment">/* Extension API */</span></div><div class="line"></div><div class="line"> <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> nop_calls; <span class="comment">/* Count of calls */</span></div><div class="line"></div><div class="line">} NOP_ENCRYPTOR;</div><div class="line"><span class="comment">/*</span></div><div class="line"><span class="comment"> * nop_error --</span></div><div class="line"><span class="comment"> * Display an error from this module in a standard way.</span></div><div class="line"><span class="comment"> */</span></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">int</span></div><div class="line">nop_error(NOP_ENCRYPTOR *encryptor, <a name="_a2"></a><a class="code" href="struct_w_t___s_e_s_s_i_o_n.html">WT_SESSION</a> *session, <span class="keywordtype">int</span> err, <span class="keyword">const</span> <span class="keywordtype">char</span> *msg)</div><div class="line">{</div><div class="line"> <a class="code" href="struct_w_t___e_x_t_e_n_s_i_o_n___a_p_i.html">WT_EXTENSION_API</a> *wt_api;</div><div class="line"></div><div class="line"> wt_api = encryptor->wt_api;</div><div class="line"> (void)wt_api-><a name="a3"></a><a class="code" href="struct_w_t___e_x_t_e_n_s_i_o_n___a_p_i.html#a6d58298e356dbf58ac854c3d1af99678">err_printf</a>(</div><div class="line"> wt_api, session, <span class="stringliteral">"nop encryption: %s: %s"</span>, msg, wt_api-><a name="a4"></a><a class="code" href="struct_w_t___e_x_t_e_n_s_i_o_n___a_p_i.html#a3fd4b5255e2f82139a846d66d67be565">strerror</a>(wt_api, NULL, err));</div><div class="line"> <span class="keywordflow">return</span> (err);</div><div class="line">}</div><div class="line"></div><div class="line"><span class="comment">/*</span></div><div class="line"><span class="comment"> * nop_encrypt --</span></div><div class="line"><span class="comment"> * A simple encryption example that passes data through unchanged.</span></div><div class="line"><span class="comment"> */</span></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">int</span></div><div class="line">nop_encrypt(<a class="code" href="struct_w_t___e_n_c_r_y_p_t_o_r.html">WT_ENCRYPTOR</a> *encryptor, <a class="code" href="struct_w_t___s_e_s_s_i_o_n.html">WT_SESSION</a> *session, uint8_t *src, <span class="keywordtype">size_t</span> src_len,</div><div class="line"> uint8_t *dst, <span class="keywordtype">size_t</span> dst_len, <span class="keywordtype">size_t</span> *result_lenp)</div><div class="line">{</div><div class="line"> NOP_ENCRYPTOR *nop_encryptor = (NOP_ENCRYPTOR *)encryptor;</div><div class="line"></div><div class="line"> (void)session; <span class="comment">/* Unused parameters */</span></div><div class="line"></div><div class="line"> ++nop_encryptor->nop_calls; <span class="comment">/* Call count */</span></div><div class="line"></div><div class="line"> <span class="keywordflow">if</span> (dst_len < src_len)</div><div class="line"> <span class="keywordflow">return</span> (nop_error(nop_encryptor, session, ENOMEM, <span class="stringliteral">"encrypt buffer not big enough"</span>));</div><div class="line"></div><div class="line"> memcpy(dst, src, src_len);</div><div class="line"> *result_lenp = src_len;</div><div class="line"></div><div class="line"> <span class="keywordflow">return</span> (0);</div><div class="line">}</div><div class="line"><span class="comment">/*</span></div><div class="line"><span class="comment"> * nop_decrypt --</span></div><div class="line"><span class="comment"> * A simple decryption example that passes data through unchanged.</span></div><div class="line"><span class="comment"> */</span></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">int</span></div><div class="line">nop_decrypt(<a class="code" href="struct_w_t___e_n_c_r_y_p_t_o_r.html">WT_ENCRYPTOR</a> *encryptor, <a class="code" href="struct_w_t___s_e_s_s_i_o_n.html">WT_SESSION</a> *session, uint8_t *src, <span class="keywordtype">size_t</span> src_len,</div><div class="line"> uint8_t *dst, <span class="keywordtype">size_t</span> dst_len, <span class="keywordtype">size_t</span> *result_lenp)</div><div class="line">{</div><div class="line"> NOP_ENCRYPTOR *nop_encryptor = (NOP_ENCRYPTOR *)encryptor;</div><div class="line"></div><div class="line"> (void)session; <span class="comment">/* Unused parameters */</span></div><div class="line"> (void)src_len;</div><div class="line"></div><div class="line"> ++nop_encryptor->nop_calls; <span class="comment">/* Call count */</span></div><div class="line"></div><div class="line"> <span class="comment">/*</span></div><div class="line"><span class="comment"> * The destination length is the number of unencrypted bytes we're expected to return.</span></div><div class="line"><span class="comment"> */</span></div><div class="line"> memcpy(dst, src, dst_len);</div><div class="line"> *result_lenp = dst_len;</div><div class="line"> <span class="keywordflow">return</span> (0);</div><div class="line">}</div><div class="line"><span class="comment">/*</span></div><div class="line"><span class="comment"> * nop_sizing --</span></div><div class="line"><span class="comment"> * A simple sizing example that tells wiredtiger that the encrypted buffer is always the same as</span></div><div class="line"><span class="comment"> * the source buffer.</span></div><div class="line"><span class="comment"> */</span></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">int</span></div><div class="line">nop_sizing(<a class="code" href="struct_w_t___e_n_c_r_y_p_t_o_r.html">WT_ENCRYPTOR</a> *encryptor, <a class="code" href="struct_w_t___s_e_s_s_i_o_n.html">WT_SESSION</a> *session, <span class="keywordtype">size_t</span> *expansion_constantp)</div><div class="line">{</div><div class="line"> NOP_ENCRYPTOR *nop_encryptor = (NOP_ENCRYPTOR *)encryptor;</div><div class="line"></div><div class="line"> (void)session; <span class="comment">/* Unused parameters */</span></div><div class="line"></div><div class="line"> ++nop_encryptor->nop_calls; <span class="comment">/* Call count */</span></div><div class="line"></div><div class="line"> *expansion_constantp = 0;</div><div class="line"> <span class="keywordflow">return</span> (0);</div><div class="line">}</div><div class="line"><span class="comment">/*</span></div><div class="line"><span class="comment"> * nop_terminate --</span></div><div class="line"><span class="comment"> * WiredTiger no-op encryption termination.</span></div><div class="line"><span class="comment"> */</span></div><div class="line"><span class="keyword">static</span> <span class="keywordtype">int</span></div><div class="line">nop_terminate(<a class="code" href="struct_w_t___e_n_c_r_y_p_t_o_r.html">WT_ENCRYPTOR</a> *encryptor, <a class="code" href="struct_w_t___s_e_s_s_i_o_n.html">WT_SESSION</a> *session)</div><div class="line">{</div><div class="line"> NOP_ENCRYPTOR *nop_encryptor = (NOP_ENCRYPTOR *)encryptor;</div><div class="line"></div><div class="line"> (void)session; <span class="comment">/* Unused parameters */</span></div><div class="line"></div><div class="line"> ++nop_encryptor->nop_calls; <span class="comment">/* Call count */</span></div><div class="line"></div><div class="line"> <span class="comment">/* Free the allocated memory. */</span></div><div class="line"> free(encryptor);</div><div class="line"></div><div class="line"> <span class="keywordflow">return</span> (0);</div><div class="line">}</div><div class="line"><span class="comment">/*</span></div><div class="line"><span class="comment"> * wiredtiger_extension_init --</span></div><div class="line"><span class="comment"> * A simple shared library encryption example.</span></div><div class="line"><span class="comment"> */</span></div><div class="line"><span class="keywordtype">int</span></div><div class="line"><a name="a5"></a><a class="code" href="group__wt__ext.html#ga5ed14c916d5dcfe0e81aea9d9ccb7fe3">wiredtiger_extension_init</a>(<a name="_a6"></a><a class="code" href="struct_w_t___c_o_n_n_e_c_t_i_o_n.html">WT_CONNECTION</a> *connection, <a class="code" href="group__wt__ext.html#ga6fa5797cf581d18dc843e07333a497e4">WT_CONFIG_ARG</a> *config)</div><div class="line">{</div><div class="line"> NOP_ENCRYPTOR *nop_encryptor;</div><div class="line"> <span class="keywordtype">int</span> ret;</div><div class="line"></div><div class="line"> (void)config; <span class="comment">/* Unused parameters */</span></div><div class="line"></div><div class="line"> <span class="keywordflow">if</span> ((nop_encryptor = calloc(1, <span class="keyword">sizeof</span>(NOP_ENCRYPTOR))) == NULL)</div><div class="line"> <span class="keywordflow">return</span> (errno);</div><div class="line"></div><div class="line"> <span class="comment">/*</span></div><div class="line"><span class="comment"> * Allocate a local encryptor structure, with a WT_ENCRYPTOR structure</span></div><div class="line"><span class="comment"> * as the first field, allowing us to treat references to either type of</span></div><div class="line"><span class="comment"> * structure as a reference to the other type.</span></div><div class="line"><span class="comment"> *</span></div><div class="line"><span class="comment"> * Heap memory (not static), because it can support multiple databases.</span></div><div class="line"><span class="comment"> */</span></div><div class="line"> nop_encryptor->encryptor.encrypt = nop_encrypt;</div><div class="line"> nop_encryptor->encryptor.decrypt = nop_decrypt;</div><div class="line"> nop_encryptor->encryptor.sizing = nop_sizing;</div><div class="line"> nop_encryptor->encryptor.terminate = nop_terminate;</div><div class="line"></div><div class="line"> nop_encryptor->wt_api = connection-><a name="a7"></a><a class="code" href="struct_w_t___c_o_n_n_e_c_t_i_o_n.html#a99df5b3a17564eb5b3e4ec076590133d">get_extension_api</a>(connection);</div><div class="line"></div><div class="line"> <span class="comment">/* Load the encryptor */</span></div><div class="line"> <span class="keywordflow">if</span> ((ret = connection-><a name="a8"></a><a class="code" href="struct_w_t___c_o_n_n_e_c_t_i_o_n.html#a59d203f4474780ca34bd3e07b8064949">add_encryptor</a>(connection, <span class="stringliteral">"nop"</span>, (<a class="code" href="struct_w_t___e_n_c_r_y_p_t_o_r.html">WT_ENCRYPTOR</a> *)nop_encryptor, NULL)) ==</div><div class="line"> 0)</div><div class="line"> <span class="keywordflow">return</span> (0);</div><div class="line"></div><div class="line"> free(nop_encryptor);</div><div class="line"> <span class="keywordflow">return</span> (ret);</div><div class="line">}</div></div><!-- fragment --> </div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
<ul>
<li class="footer">Copyright (c) 2008-2019 MongoDB, Inc. All rights reserved. Contact <a href="mailto:info@wiredtiger.com">info@wiredtiger.com</a> for more information.</li>
</ul>
</div>
</body>
</html>
|