\hypertarget{g__eli__key__cache_8c_source}{}\doxysection{g\+\_\+eli\+\_\+key\+\_\+cache.\+c}
\label{g__eli__key__cache_8c_source}\index{geom/eli/g\_eli\_key\_cache.c@{geom/eli/g\_eli\_key\_cache.c}}
\mbox{\hyperlink{g__eli__key__cache_8c}{Go to the documentation of this file.}}
\begin{DoxyCode}{0}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00001}00001 \textcolor{comment}{/*-\/}}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00002}00002 \textcolor{comment}{ * SPDX-\/License-\/Identifier: BSD-\/2-\/Clause-\/FreeBSD}}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00003}00003 \textcolor{comment}{ *}}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00004}00004 \textcolor{comment}{ * Copyright (c) 2011-\/2019 Pawel Jakub Dawidek <pawel@dawidek.net>}}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00005}00005 \textcolor{comment}{ * All rights reserved.}}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00006}00006 \textcolor{comment}{ *}}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00007}00007 \textcolor{comment}{ * Redistribution and use in source and binary forms, with or without}}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00008}00008 \textcolor{comment}{ * modification, are permitted provided that the following conditions}}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00009}00009 \textcolor{comment}{ * are met:}}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00010}00010 \textcolor{comment}{ * 1. Redistributions of source code must retain the above copyright}}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00011}00011 \textcolor{comment}{ *    notice, this list of conditions and the following disclaimer.}}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00012}00012 \textcolor{comment}{ * 2. Redistributions in binary form must reproduce the above copyright}}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00013}00013 \textcolor{comment}{ *    notice, this list of conditions and the following disclaimer in the}}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00014}00014 \textcolor{comment}{ *    documentation and/or other materials provided with the distribution.}}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00015}00015 \textcolor{comment}{ *}}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00016}00016 \textcolor{comment}{ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND}}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00017}00017 \textcolor{comment}{ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE}}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00018}00018 \textcolor{comment}{ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE}}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00019}00019 \textcolor{comment}{ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE}}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00020}00020 \textcolor{comment}{ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL}}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00021}00021 \textcolor{comment}{ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS}}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00022}00022 \textcolor{comment}{ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)}}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00023}00023 \textcolor{comment}{ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT}}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00024}00024 \textcolor{comment}{ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY}}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00025}00025 \textcolor{comment}{ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF}}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00026}00026 \textcolor{comment}{ * SUCH DAMAGE.}}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00027}00027 \textcolor{comment}{ */}}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00028}00028 }
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00029}00029 \textcolor{preprocessor}{\#include <sys/cdefs.h>}}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00030}\mbox{\hyperlink{g__eli__key__cache_8c_a8c3ef283470a68cd30afe9b8a72cb60f}{00030}} \mbox{\hyperlink{g__eli__key__cache_8c_a8c3ef283470a68cd30afe9b8a72cb60f}{\_\_FBSDID}}(\textcolor{stringliteral}{"{}\$FreeBSD\$"{}});}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00031}00031 }
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00032}00032 \textcolor{preprocessor}{\#include <sys/param.h>}}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00033}00033 \textcolor{preprocessor}{\#ifdef \_KERNEL}}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00034}00034 \textcolor{preprocessor}{\#include <sys/kernel.h>}}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00035}00035 \textcolor{preprocessor}{\#include <sys/malloc.h>}}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00036}00036 \textcolor{preprocessor}{\#include <sys/sysctl.h>}}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00037}00037 \textcolor{preprocessor}{\#include <sys/systm.h>}}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00038}00038 \textcolor{preprocessor}{\#endif }\textcolor{comment}{/* \_KERNEL */}\textcolor{preprocessor}{}}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00039}00039 \textcolor{preprocessor}{\#include <sys/queue.h>}}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00040}00040 \textcolor{preprocessor}{\#include <sys/tree.h>}}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00041}00041 }
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00042}00042 \textcolor{preprocessor}{\#include <\mbox{\hyperlink{geom_8h}{geom/geom.h}}>}}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00043}00043 }
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00044}00044 \textcolor{preprocessor}{\#include <\mbox{\hyperlink{g__eli_8h}{geom/eli/g\_eli.h}}>}}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00045}00045 }
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00046}00046 \textcolor{preprocessor}{\#ifdef \_KERNEL}}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00047}\mbox{\hyperlink{g__eli__key__cache_8c_a06a072b20b0a62f2ced24ac2600f4a2c}{00047}} \mbox{\hyperlink{g__eli__key__cache_8c_a06a072b20b0a62f2ced24ac2600f4a2c}{MALLOC\_DECLARE}}(M\_ELI);}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00048}00048 }
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00049}\mbox{\hyperlink{g__eli__key__cache_8c_ab22b61ed7af24355117430bad247c616}{00049}} \mbox{\hyperlink{g__eli__key__cache_8c_ab22b61ed7af24355117430bad247c616}{SYSCTL\_DECL}}(\_kern\_geom\_eli);}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00050}00050 \textcolor{comment}{/*}}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00051}00051 \textcolor{comment}{ * The default limit (8192 keys) will allow to cache all keys for 4TB}}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00052}00052 \textcolor{comment}{ * provider with 512 bytes sectors and will take around 1MB of memory.}}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00053}00053 \textcolor{comment}{ */}}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00054}\mbox{\hyperlink{g__eli__key__cache_8c_a4fd8867a72aa80bb0459a2ad5eeb3589}{00054}} \textcolor{keyword}{static} u\_int \mbox{\hyperlink{g__eli__key__cache_8c_a4fd8867a72aa80bb0459a2ad5eeb3589}{g\_eli\_key\_cache\_limit}} = 8192;}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00055}\mbox{\hyperlink{g__eli__key__cache_8c_ae85a4fd8d63df862e411b2abee15b98e}{00055}} \mbox{\hyperlink{g__eli__key__cache_8c_ae85a4fd8d63df862e411b2abee15b98e}{SYSCTL\_UINT}}(\_kern\_geom\_eli, OID\_AUTO, key\_cache\_limit, CTLFLAG\_RDTUN,}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00056}00056     \&\mbox{\hyperlink{g__eli__key__cache_8c_a4fd8867a72aa80bb0459a2ad5eeb3589}{g\_eli\_key\_cache\_limit}}, 0, \textcolor{stringliteral}{"{}Maximum number of encryption keys to cache"{}});}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00057}\mbox{\hyperlink{g__eli__key__cache_8c_a955b8bacccfd2540de45dde8d4b6aff2}{00057}} \textcolor{keyword}{static} uint64\_t \mbox{\hyperlink{g__eli__key__cache_8c_a955b8bacccfd2540de45dde8d4b6aff2}{g\_eli\_key\_cache\_hits}};}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00058}\mbox{\hyperlink{g__eli__key__cache_8c_a36883a10b365befae7697b6200bde8a7}{00058}} \mbox{\hyperlink{g__eli__key__cache_8c_a36883a10b365befae7697b6200bde8a7}{SYSCTL\_UQUAD}}(\_kern\_geom\_eli, OID\_AUTO, key\_cache\_hits, CTLFLAG\_RW,}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00059}00059     \&\mbox{\hyperlink{g__eli__key__cache_8c_a955b8bacccfd2540de45dde8d4b6aff2}{g\_eli\_key\_cache\_hits}}, 0, \textcolor{stringliteral}{"{}Key cache hits"{}});}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00060}\mbox{\hyperlink{g__eli__key__cache_8c_af43c729be7ab7bf3f9b34c9fe1465658}{00060}} \textcolor{keyword}{static} uint64\_t \mbox{\hyperlink{g__eli__key__cache_8c_af43c729be7ab7bf3f9b34c9fe1465658}{g\_eli\_key\_cache\_misses}};}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00061}\mbox{\hyperlink{g__eli__key__cache_8c_a57f56411950ae77cb75f10158edbd413}{00061}} \mbox{\hyperlink{g__eli__key__cache_8c_a36883a10b365befae7697b6200bde8a7}{SYSCTL\_UQUAD}}(\_kern\_geom\_eli, OID\_AUTO, key\_cache\_misses, CTLFLAG\_RW,}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00062}00062     \&\mbox{\hyperlink{g__eli__key__cache_8c_af43c729be7ab7bf3f9b34c9fe1465658}{g\_eli\_key\_cache\_misses}}, 0, \textcolor{stringliteral}{"{}Key cache misses"{}});}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00063}00063 }
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00064}00064 \textcolor{keyword}{static} \textcolor{keywordtype}{int}}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00065}\mbox{\hyperlink{g__eli__key__cache_8c_aee2fff7815847debf76044bf467fd958}{00065}} \mbox{\hyperlink{g__eli__key__cache_8c_aee2fff7815847debf76044bf467fd958}{g\_eli\_key\_cmp}}(\textcolor{keyword}{const} \textcolor{keyword}{struct} \mbox{\hyperlink{structg__eli__key}{g\_eli\_key}} *a, \textcolor{keyword}{const} \textcolor{keyword}{struct} \mbox{\hyperlink{structg__eli__key}{g\_eli\_key}} *b)}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00066}00066 \{}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00067}00067 }
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00068}00068         \textcolor{keywordflow}{if} (a-\/>\mbox{\hyperlink{structg__eli__key_a52688902d6e7306fc4f468ac3c9e9334}{gek\_keyno}} > b-\/>\mbox{\hyperlink{structg__eli__key_a52688902d6e7306fc4f468ac3c9e9334}{gek\_keyno}})}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00069}00069                 \textcolor{keywordflow}{return} (1);}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00070}00070         \textcolor{keywordflow}{else} \textcolor{keywordflow}{if} (a-\/>\mbox{\hyperlink{structg__eli__key_a52688902d6e7306fc4f468ac3c9e9334}{gek\_keyno}} < b-\/>\mbox{\hyperlink{structg__eli__key_a52688902d6e7306fc4f468ac3c9e9334}{gek\_keyno}})}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00071}00071                 \textcolor{keywordflow}{return} (-\/1);}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00072}00072         \textcolor{keywordflow}{return} (0);}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00073}00073 \}}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00074}00074 \textcolor{preprocessor}{\#endif }\textcolor{comment}{/* \_KERNEL */}\textcolor{preprocessor}{}}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00075}00075 }
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00076}00076 \textcolor{keywordtype}{void}}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00077}\mbox{\hyperlink{g__eli_8h_ab71dc07a76bd6365d076e51f1dd36c70}{00077}} \mbox{\hyperlink{g__eli__key__cache_8c_ab71dc07a76bd6365d076e51f1dd36c70}{g\_eli\_key\_fill}}(\textcolor{keyword}{struct} \mbox{\hyperlink{structg__eli__softc}{g\_eli\_softc}} *sc, \textcolor{keyword}{struct} \mbox{\hyperlink{structg__eli__key}{g\_eli\_key}} *key, uint64\_t keyno)}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00078}00078 \{}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00079}00079         \textcolor{keyword}{const} \mbox{\hyperlink{binstream_8h_ab077fa1127453be2bd9d4c3c8a768fa7}{uint8\_t}} *ekey;}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00080}00080         \textcolor{keyword}{struct }\{}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00081}00081                 \textcolor{keywordtype}{char} magic[4];}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00082}00082                 \mbox{\hyperlink{binstream_8h_ab077fa1127453be2bd9d4c3c8a768fa7}{uint8\_t}} keyno[8];}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00083}00083         \} \mbox{\hyperlink{g__eli_8h_a9da00a1c85e29640b43e72e814ff687a}{\_\_packed}} hmacdata;}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00084}00084 }
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00085}00085         \textcolor{keywordflow}{if} ((sc-\/>\mbox{\hyperlink{structg__eli__softc_a94876b8cf2ed7da3eb3a3e1858171ef2}{sc\_flags}} \& \mbox{\hyperlink{g__eli_8h_adb32d9869b3bb0f00fa1cc7bb85990b1}{G\_ELI\_FLAG\_ENC\_IVKEY}}) != 0)}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00086}00086                 ekey = sc-\/>\mbox{\hyperlink{structg__eli__softc_a8581b85c073273bcbb556b18d5932b10}{sc\_mkey}};}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00087}00087         \textcolor{keywordflow}{else}}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00088}00088                 ekey = sc-\/>\mbox{\hyperlink{structg__eli__softc_a23352840c391565e85bd18ca4a72320e}{sc\_ekey}};}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00089}00089 }
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00090}00090         bcopy(\textcolor{stringliteral}{"{}ekey"{}}, hmacdata.magic, 4);}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00091}00091         le64enc(hmacdata.keyno, keyno);}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00092}00092         \mbox{\hyperlink{g__eli_8h_a7568712ca711b91d055948e2bed38865}{g\_eli\_crypto\_hmac}}(ekey, \mbox{\hyperlink{g__eli_8h_aec1ec73171d7f9f52740b5890ee2615e}{G\_ELI\_MAXKEYLEN}}, (\mbox{\hyperlink{binstream_8h_ab077fa1127453be2bd9d4c3c8a768fa7}{uint8\_t}} *)\&hmacdata,}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00093}00093             \textcolor{keyword}{sizeof}(hmacdata), key-\/>\mbox{\hyperlink{structg__eli__key_ab17ea58ccc262b9c8b90f785f63ecae6}{gek\_key}}, 0);}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00094}00094         key-\/>\mbox{\hyperlink{structg__eli__key_a52688902d6e7306fc4f468ac3c9e9334}{gek\_keyno}} = keyno;}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00095}00095         key-\/>\mbox{\hyperlink{structg__eli__key_a9812b097be2b483ad61eb367e80ef8e3}{gek\_count}} = 0;}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00096}00096         key-\/>\mbox{\hyperlink{structg__eli__key_a0cc9445fd08397ecc1a902c065a86631}{gek\_magic}} = \mbox{\hyperlink{g__eli_8h_a8016668c3138460b2912154d099e1c43}{G\_ELI\_KEY\_MAGIC}};}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00097}00097 \}}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00098}00098 }
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00099}00099 \textcolor{preprocessor}{\#ifdef \_KERNEL}}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00100}\mbox{\hyperlink{g__eli__key__cache_8c_af83b4114cb08c2d15ab7ff3fa6168897}{00100}} \mbox{\hyperlink{g__eli__key__cache_8c_af83b4114cb08c2d15ab7ff3fa6168897}{RB\_PROTOTYPE}}(g\_eli\_key\_tree, \mbox{\hyperlink{structg__eli__key}{g\_eli\_key}}, gek\_link, \mbox{\hyperlink{g__eli__key__cache_8c_aee2fff7815847debf76044bf467fd958}{g\_eli\_key\_cmp}});}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00101}\mbox{\hyperlink{g__eli__key__cache_8c_a1242fb8523d88174514e42fdd29d6f8a}{00101}} \mbox{\hyperlink{g__eli__key__cache_8c_a1242fb8523d88174514e42fdd29d6f8a}{RB\_GENERATE}}(g\_eli\_key\_tree, \mbox{\hyperlink{structg__eli__key}{g\_eli\_key}}, gek\_link, \mbox{\hyperlink{g__eli__key__cache_8c_aee2fff7815847debf76044bf467fd958}{g\_eli\_key\_cmp}});}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00102}00102 }
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00103}00103 \textcolor{keyword}{static} \textcolor{keyword}{struct }\mbox{\hyperlink{structg__eli__key}{g\_eli\_key}} *}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00104}\mbox{\hyperlink{g__eli__key__cache_8c_a6e49116ae542d1da934b59e32d5cd216}{00104}} \mbox{\hyperlink{g__eli__key__cache_8c_a6e49116ae542d1da934b59e32d5cd216}{g\_eli\_key\_allocate}}(\textcolor{keyword}{struct} \mbox{\hyperlink{structg__eli__softc}{g\_eli\_softc}} *sc, uint64\_t keyno)}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00105}00105 \{}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00106}00106         \textcolor{keyword}{struct }\mbox{\hyperlink{structg__eli__key}{g\_eli\_key}} *key, *ekey, keysearch;}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00107}00107 }
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00108}00108         mtx\_assert(\&sc-\/>\mbox{\hyperlink{structg__eli__softc_aeaed9e283a3ee539995fcfa127e67bed}{sc\_ekeys\_lock}}, MA\_OWNED);}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00109}00109         mtx\_unlock(\&sc-\/>\mbox{\hyperlink{structg__eli__softc_aeaed9e283a3ee539995fcfa127e67bed}{sc\_ekeys\_lock}});}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00110}00110 }
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00111}00111         key = malloc(\textcolor{keyword}{sizeof}(*key), M\_ELI, M\_WAITOK);}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00112}00112         \mbox{\hyperlink{g__eli__key__cache_8c_ab71dc07a76bd6365d076e51f1dd36c70}{g\_eli\_key\_fill}}(sc, key, keyno);}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00113}00113 }
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00114}00114         mtx\_lock(\&sc-\/>\mbox{\hyperlink{structg__eli__softc_aeaed9e283a3ee539995fcfa127e67bed}{sc\_ekeys\_lock}});}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00115}00115         \textcolor{comment}{/*}}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00116}00116 \textcolor{comment}{         * Recheck if the key wasn't added while we weren't holding the lock.}}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00117}00117 \textcolor{comment}{         */}}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00118}00118         keysearch.\mbox{\hyperlink{structg__eli__key_a52688902d6e7306fc4f468ac3c9e9334}{gek\_keyno}} = keyno;}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00119}00119         ekey = RB\_FIND(g\_eli\_key\_tree, \&sc-\/>sc\_ekeys\_tree, \&keysearch);}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00120}00120         \textcolor{keywordflow}{if} (ekey != NULL) \{}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00121}00121                 zfree(key, M\_ELI);}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00122}00122                 key = ekey;}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00123}00123                 TAILQ\_REMOVE(\&sc-\/>sc\_ekeys\_queue, key, gek\_next);}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00124}00124         \} \textcolor{keywordflow}{else} \{}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00125}00125                 RB\_INSERT(g\_eli\_key\_tree, \&sc-\/>sc\_ekeys\_tree, key);}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00126}00126                 sc-\/>\mbox{\hyperlink{structg__eli__softc_a79fd16c488c0d5c510b56c944364218d}{sc\_ekeys\_allocated}}++;}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00127}00127         \}}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00128}00128         TAILQ\_INSERT\_TAIL(\&sc-\/>sc\_ekeys\_queue, key, gek\_next);}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00129}00129 }
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00130}00130         \textcolor{keywordflow}{return} (key);}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00131}00131 \}}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00132}00132 }
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00133}00133 \textcolor{keyword}{static} \textcolor{keyword}{struct }\mbox{\hyperlink{structg__eli__key}{g\_eli\_key}} *}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00134}\mbox{\hyperlink{g__eli__key__cache_8c_a6d67454a8a0893446f20952385cb9788}{00134}} \mbox{\hyperlink{g__eli__key__cache_8c_a6d67454a8a0893446f20952385cb9788}{g\_eli\_key\_find\_last}}(\textcolor{keyword}{struct} \mbox{\hyperlink{structg__eli__softc}{g\_eli\_softc}} *sc)}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00135}00135 \{}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00136}00136         \textcolor{keyword}{struct }\mbox{\hyperlink{structg__eli__key}{g\_eli\_key}} *key;}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00137}00137 }
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00138}00138         mtx\_assert(\&sc-\/>\mbox{\hyperlink{structg__eli__softc_aeaed9e283a3ee539995fcfa127e67bed}{sc\_ekeys\_lock}}, MA\_OWNED);}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00139}00139 }
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00140}00140         TAILQ\_FOREACH(key, \&sc-\/>sc\_ekeys\_queue, gek\_next) \{}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00141}00141                 \textcolor{keywordflow}{if} (key-\/>\mbox{\hyperlink{structg__eli__key_a9812b097be2b483ad61eb367e80ef8e3}{gek\_count}} == 0)}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00142}00142                         \textcolor{keywordflow}{break};}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00143}00143         \}}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00144}00144 }
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00145}00145         \textcolor{keywordflow}{return} (key);}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00146}00146 \}}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00147}00147 }
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00148}00148 \textcolor{keyword}{static} \textcolor{keywordtype}{void}}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00149}\mbox{\hyperlink{g__eli__key__cache_8c_ab552e15d96c547c624223bdbe99d96d6}{00149}} \mbox{\hyperlink{g__eli__key__cache_8c_ab552e15d96c547c624223bdbe99d96d6}{g\_eli\_key\_replace}}(\textcolor{keyword}{struct} \mbox{\hyperlink{structg__eli__softc}{g\_eli\_softc}} *sc, \textcolor{keyword}{struct} \mbox{\hyperlink{structg__eli__key}{g\_eli\_key}} *key, uint64\_t keyno)}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00150}00150 \{}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00151}00151 }
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00152}00152         mtx\_assert(\&sc-\/>\mbox{\hyperlink{structg__eli__softc_aeaed9e283a3ee539995fcfa127e67bed}{sc\_ekeys\_lock}}, MA\_OWNED);}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00153}00153         KASSERT(key-\/>\mbox{\hyperlink{structg__eli__key_a0cc9445fd08397ecc1a902c065a86631}{gek\_magic}} == \mbox{\hyperlink{g__eli_8h_a8016668c3138460b2912154d099e1c43}{G\_ELI\_KEY\_MAGIC}}, (\textcolor{stringliteral}{"{}Invalid magic."{}}));}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00154}00154 }
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00155}00155         RB\_REMOVE(g\_eli\_key\_tree, \&sc-\/>sc\_ekeys\_tree, key);}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00156}00156         TAILQ\_REMOVE(\&sc-\/>sc\_ekeys\_queue, key, gek\_next);}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00157}00157 }
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00158}00158         KASSERT(key-\/>\mbox{\hyperlink{structg__eli__key_a9812b097be2b483ad61eb367e80ef8e3}{gek\_count}} == 0, (\textcolor{stringliteral}{"{}gek\_count=\%d"{}}, key-\/>\mbox{\hyperlink{structg__eli__key_a9812b097be2b483ad61eb367e80ef8e3}{gek\_count}}));}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00159}00159 }
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00160}00160         \mbox{\hyperlink{g__eli__key__cache_8c_ab71dc07a76bd6365d076e51f1dd36c70}{g\_eli\_key\_fill}}(sc, key, keyno);}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00161}00161 }
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00162}00162         RB\_INSERT(g\_eli\_key\_tree, \&sc-\/>sc\_ekeys\_tree, key);}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00163}00163         TAILQ\_INSERT\_TAIL(\&sc-\/>sc\_ekeys\_queue, key, gek\_next);}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00164}00164 \}}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00165}00165 }
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00166}00166 \textcolor{keyword}{static} \textcolor{keywordtype}{void}}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00167}\mbox{\hyperlink{g__eli__key__cache_8c_a78798e879ad9727d2b755f9adb421b94}{00167}} \mbox{\hyperlink{g__eli__key__cache_8c_a78798e879ad9727d2b755f9adb421b94}{g\_eli\_key\_remove}}(\textcolor{keyword}{struct} \mbox{\hyperlink{structg__eli__softc}{g\_eli\_softc}} *sc, \textcolor{keyword}{struct} \mbox{\hyperlink{structg__eli__key}{g\_eli\_key}} *key)}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00168}00168 \{}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00169}00169 }
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00170}00170         mtx\_assert(\&sc-\/>\mbox{\hyperlink{structg__eli__softc_aeaed9e283a3ee539995fcfa127e67bed}{sc\_ekeys\_lock}}, MA\_OWNED);}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00171}00171         KASSERT(key-\/>\mbox{\hyperlink{structg__eli__key_a0cc9445fd08397ecc1a902c065a86631}{gek\_magic}} == \mbox{\hyperlink{g__eli_8h_a8016668c3138460b2912154d099e1c43}{G\_ELI\_KEY\_MAGIC}}, (\textcolor{stringliteral}{"{}Invalid magic."{}}));}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00172}00172         KASSERT(key-\/>\mbox{\hyperlink{structg__eli__key_a9812b097be2b483ad61eb367e80ef8e3}{gek\_count}} == 0, (\textcolor{stringliteral}{"{}gek\_count=\%d"{}}, key-\/>\mbox{\hyperlink{structg__eli__key_a9812b097be2b483ad61eb367e80ef8e3}{gek\_count}}));}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00173}00173 }
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00174}00174         RB\_REMOVE(g\_eli\_key\_tree, \&sc-\/>sc\_ekeys\_tree, key);}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00175}00175         TAILQ\_REMOVE(\&sc-\/>sc\_ekeys\_queue, key, gek\_next);}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00176}00176         sc-\/>\mbox{\hyperlink{structg__eli__softc_a79fd16c488c0d5c510b56c944364218d}{sc\_ekeys\_allocated}}-\/-\/;}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00177}00177         zfree(key, M\_ELI);}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00178}00178 \}}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00179}00179 }
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00180}00180 \textcolor{keywordtype}{void}}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00181}\mbox{\hyperlink{g__eli_8h_a8b7574ca318f8b8d499f7fcc35468313}{00181}} \mbox{\hyperlink{g__eli__key__cache_8c_a8b7574ca318f8b8d499f7fcc35468313}{g\_eli\_key\_init}}(\textcolor{keyword}{struct} \mbox{\hyperlink{structg__eli__softc}{g\_eli\_softc}} *sc)}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00182}00182 \{}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00183}00183         \mbox{\hyperlink{binstream_8h_ab077fa1127453be2bd9d4c3c8a768fa7}{uint8\_t}} *mkey;}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00184}00184 }
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00185}00185         mtx\_lock(\&sc-\/>\mbox{\hyperlink{structg__eli__softc_aeaed9e283a3ee539995fcfa127e67bed}{sc\_ekeys\_lock}});}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00186}00186 }
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00187}00187         mkey = sc-\/>\mbox{\hyperlink{structg__eli__softc_a8581b85c073273bcbb556b18d5932b10}{sc\_mkey}} + \textcolor{keyword}{sizeof}(sc-\/>\mbox{\hyperlink{structg__eli__softc_a35a1d558d42d78a52715771803ee042e}{sc\_ivkey}});}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00188}00188         \textcolor{keywordflow}{if} ((sc-\/>\mbox{\hyperlink{structg__eli__softc_a94876b8cf2ed7da3eb3a3e1858171ef2}{sc\_flags}} \& \mbox{\hyperlink{g__eli_8h_a723b90905e6c7f8485c4723967759d84}{G\_ELI\_FLAG\_AUTH}}) == 0)}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00189}00189                 bcopy(mkey, sc-\/>\mbox{\hyperlink{structg__eli__softc_a23352840c391565e85bd18ca4a72320e}{sc\_ekey}}, \mbox{\hyperlink{g__eli_8h_a7732e68e5347389c8b740583a43a7b08}{G\_ELI\_DATAKEYLEN}});}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00190}00190         \textcolor{keywordflow}{else} \{}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00191}00191                 \textcolor{comment}{/*}}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00192}00192 \textcolor{comment}{                 * The encryption key is: ekey = HMAC\_SHA512(Data-\/Key, 0x10)}}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00193}00193 \textcolor{comment}{                 */}}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00194}00194                 \mbox{\hyperlink{g__eli_8h_a7568712ca711b91d055948e2bed38865}{g\_eli\_crypto\_hmac}}(mkey, \mbox{\hyperlink{g__eli_8h_aec1ec73171d7f9f52740b5890ee2615e}{G\_ELI\_MAXKEYLEN}}, \textcolor{stringliteral}{"{}\(\backslash\)x10"{}}, 1,}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00195}00195                     sc-\/>\mbox{\hyperlink{structg__eli__softc_a23352840c391565e85bd18ca4a72320e}{sc\_ekey}}, 0);}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00196}00196         \}}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00197}00197 }
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00198}00198         \textcolor{keywordflow}{if} ((sc-\/>\mbox{\hyperlink{structg__eli__softc_a94876b8cf2ed7da3eb3a3e1858171ef2}{sc\_flags}} \& \mbox{\hyperlink{g__eli_8h_a0440d24008eaa5fe7620843804fecc7a}{G\_ELI\_FLAG\_SINGLE\_KEY}}) != 0) \{}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00199}00199                 sc-\/>\mbox{\hyperlink{structg__eli__softc_addf43ecb1aadd3f61593aa388b4742a4}{sc\_ekeys\_total}} = 1;}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00200}00200                 sc-\/>\mbox{\hyperlink{structg__eli__softc_a79fd16c488c0d5c510b56c944364218d}{sc\_ekeys\_allocated}} = 0;}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00201}00201         \} \textcolor{keywordflow}{else} \{}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00202}00202                 off\_t mediasize;}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00203}00203                 \textcolor{keywordtype}{size\_t} blocksize;}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00204}00204 }
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00205}00205                 \textcolor{keywordflow}{if} ((sc-\/>\mbox{\hyperlink{structg__eli__softc_a94876b8cf2ed7da3eb3a3e1858171ef2}{sc\_flags}} \& \mbox{\hyperlink{g__eli_8h_a723b90905e6c7f8485c4723967759d84}{G\_ELI\_FLAG\_AUTH}}) != 0) \{}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00206}00206                         \textcolor{keyword}{struct }\mbox{\hyperlink{structg__provider}{g\_provider}} *\mbox{\hyperlink{g__part__if_8m_a9bc7638f295763b77465c5ebebbd3442}{pp}};}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00207}00207 }
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00208}00208                         \mbox{\hyperlink{g__part__if_8m_a9bc7638f295763b77465c5ebebbd3442}{pp}} = LIST\_FIRST(\&sc-\/>\mbox{\hyperlink{structg__eli__softc_a899949202205997147c78c52b32b9843}{sc\_geom}}-\/>consumer)-\/>provider;}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00209}00209                         \mbox{\hyperlink{structg__provider_a8f47c464c78aa91fa4ca5143ed3cd15e}{mediasize}} = \mbox{\hyperlink{g__part__if_8m_a9bc7638f295763b77465c5ebebbd3442}{pp}}-\/>\mbox{\hyperlink{structg__provider_a8f47c464c78aa91fa4ca5143ed3cd15e}{mediasize}};}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00210}00210                         blocksize = \mbox{\hyperlink{g__part__if_8m_a9bc7638f295763b77465c5ebebbd3442}{pp}}-\/>\mbox{\hyperlink{structg__provider_aea3cd43d41461790b8d0afcd8c49a355}{sectorsize}};}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00211}00211                 \} \textcolor{keywordflow}{else} \{}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00212}00212                         \mbox{\hyperlink{structg__provider_a8f47c464c78aa91fa4ca5143ed3cd15e}{mediasize}} = sc-\/>\mbox{\hyperlink{structg__eli__softc_a886bea13cc2ca3e3e7b459d97d2459f5}{sc\_mediasize}};}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00213}00213                         blocksize = sc-\/>\mbox{\hyperlink{structg__eli__softc_a98f6d4510dc5541540fbb45883782c9f}{sc\_sectorsize}};}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00214}00214                 \}}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00215}00215                 sc-\/>\mbox{\hyperlink{structg__eli__softc_addf43ecb1aadd3f61593aa388b4742a4}{sc\_ekeys\_total}} =}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00216}00216                     ((\mbox{\hyperlink{structg__provider_a8f47c464c78aa91fa4ca5143ed3cd15e}{mediasize}} -\/ 1) >> \mbox{\hyperlink{g__eli_8h_ab8cfe0383780aeb7d7f5ea6c9d2b1cea}{G\_ELI\_KEY\_SHIFT}}) / blocksize + 1;}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00217}00217                 sc-\/>\mbox{\hyperlink{structg__eli__softc_a79fd16c488c0d5c510b56c944364218d}{sc\_ekeys\_allocated}} = 0;}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00218}00218                 TAILQ\_INIT(\&sc-\/>sc\_ekeys\_queue);}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00219}00219                 RB\_INIT(\&sc-\/>sc\_ekeys\_tree);}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00220}00220                 \textcolor{keywordflow}{if} (sc-\/>\mbox{\hyperlink{structg__eli__softc_addf43ecb1aadd3f61593aa388b4742a4}{sc\_ekeys\_total}} <= \mbox{\hyperlink{g__eli__key__cache_8c_a4fd8867a72aa80bb0459a2ad5eeb3589}{g\_eli\_key\_cache\_limit}}) \{}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00221}00221                         uint64\_t keyno;}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00222}00222 }
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00223}00223                         \textcolor{keywordflow}{for} (keyno = 0; keyno < sc-\/>\mbox{\hyperlink{structg__eli__softc_addf43ecb1aadd3f61593aa388b4742a4}{sc\_ekeys\_total}}; keyno++)}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00224}00224                                 (\textcolor{keywordtype}{void})\mbox{\hyperlink{g__eli__key__cache_8c_a6e49116ae542d1da934b59e32d5cd216}{g\_eli\_key\_allocate}}(sc, keyno);}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00225}00225                         KASSERT(sc-\/>\mbox{\hyperlink{structg__eli__softc_addf43ecb1aadd3f61593aa388b4742a4}{sc\_ekeys\_total}} == sc-\/>\mbox{\hyperlink{structg__eli__softc_a79fd16c488c0d5c510b56c944364218d}{sc\_ekeys\_allocated}},}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00226}00226                             (\textcolor{stringliteral}{"{}sc\_ekeys\_total=\%ju != sc\_ekeys\_allocated=\%ju"{}},}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00227}00227                             (uintmax\_t)sc-\/>\mbox{\hyperlink{structg__eli__softc_addf43ecb1aadd3f61593aa388b4742a4}{sc\_ekeys\_total}},}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00228}00228                             (uintmax\_t)sc-\/>\mbox{\hyperlink{structg__eli__softc_a79fd16c488c0d5c510b56c944364218d}{sc\_ekeys\_allocated}}));}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00229}00229                 \}}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00230}00230         \}}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00231}00231 }
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00232}00232         mtx\_unlock(\&sc-\/>\mbox{\hyperlink{structg__eli__softc_aeaed9e283a3ee539995fcfa127e67bed}{sc\_ekeys\_lock}});}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00233}00233 \}}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00234}00234 }
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00235}00235 \textcolor{keywordtype}{void}}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00236}\mbox{\hyperlink{g__eli_8h_abecc31857c0153fd28236eae25d1e8d7}{00236}} \mbox{\hyperlink{g__eli__key__cache_8c_abecc31857c0153fd28236eae25d1e8d7}{g\_eli\_key\_destroy}}(\textcolor{keyword}{struct} \mbox{\hyperlink{structg__eli__softc}{g\_eli\_softc}} *sc)}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00237}00237 \{}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00238}00238 }
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00239}00239         mtx\_lock(\&sc-\/>\mbox{\hyperlink{structg__eli__softc_aeaed9e283a3ee539995fcfa127e67bed}{sc\_ekeys\_lock}});}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00240}00240         \textcolor{keywordflow}{if} ((sc-\/>\mbox{\hyperlink{structg__eli__softc_a94876b8cf2ed7da3eb3a3e1858171ef2}{sc\_flags}} \& \mbox{\hyperlink{g__eli_8h_a0440d24008eaa5fe7620843804fecc7a}{G\_ELI\_FLAG\_SINGLE\_KEY}}) != 0) \{}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00241}00241                 explicit\_bzero(sc-\/>\mbox{\hyperlink{structg__eli__softc_a23352840c391565e85bd18ca4a72320e}{sc\_ekey}}, \textcolor{keyword}{sizeof}(sc-\/>\mbox{\hyperlink{structg__eli__softc_a23352840c391565e85bd18ca4a72320e}{sc\_ekey}}));}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00242}00242         \} \textcolor{keywordflow}{else} \{}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00243}00243                 \textcolor{keyword}{struct }\mbox{\hyperlink{structg__eli__key}{g\_eli\_key}} *key;}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00244}00244 }
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00245}00245                 \textcolor{keywordflow}{while} ((key = TAILQ\_FIRST(\&sc-\/>sc\_ekeys\_queue)) != NULL)}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00246}00246                         \mbox{\hyperlink{g__eli__key__cache_8c_a78798e879ad9727d2b755f9adb421b94}{g\_eli\_key\_remove}}(sc, key);}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00247}00247                 TAILQ\_INIT(\&sc-\/>sc\_ekeys\_queue);}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00248}00248                 RB\_INIT(\&sc-\/>sc\_ekeys\_tree);}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00249}00249         \}}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00250}00250         mtx\_unlock(\&sc-\/>\mbox{\hyperlink{structg__eli__softc_aeaed9e283a3ee539995fcfa127e67bed}{sc\_ekeys\_lock}});}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00251}00251 \}}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00252}00252 }
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00253}00253 \textcolor{keywordtype}{void}}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00254}\mbox{\hyperlink{g__eli_8h_a7d9df773c5f36c14e39bbd1e30e5dfc5}{00254}} \mbox{\hyperlink{g__eli__key__cache_8c_a7d9df773c5f36c14e39bbd1e30e5dfc5}{g\_eli\_key\_resize}}(\textcolor{keyword}{struct} \mbox{\hyperlink{structg__eli__softc}{g\_eli\_softc}} *sc)}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00255}00255 \{}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00256}00256         uint64\_t new\_ekeys\_total;}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00257}00257         off\_t mediasize;}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00258}00258         \textcolor{keywordtype}{size\_t} blocksize;}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00259}00259 }
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00260}00260         \textcolor{keywordflow}{if} ((sc-\/>\mbox{\hyperlink{structg__eli__softc_a94876b8cf2ed7da3eb3a3e1858171ef2}{sc\_flags}} \& \mbox{\hyperlink{g__eli_8h_a0440d24008eaa5fe7620843804fecc7a}{G\_ELI\_FLAG\_SINGLE\_KEY}}) != 0) \{}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00261}00261                 \textcolor{keywordflow}{return};}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00262}00262         \}}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00263}00263 }
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00264}00264         mtx\_lock(\&sc-\/>\mbox{\hyperlink{structg__eli__softc_aeaed9e283a3ee539995fcfa127e67bed}{sc\_ekeys\_lock}});}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00265}00265 }
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00266}00266         \textcolor{keywordflow}{if} ((sc-\/>\mbox{\hyperlink{structg__eli__softc_a94876b8cf2ed7da3eb3a3e1858171ef2}{sc\_flags}} \& \mbox{\hyperlink{g__eli_8h_a723b90905e6c7f8485c4723967759d84}{G\_ELI\_FLAG\_AUTH}}) != 0) \{}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00267}00267                 \textcolor{keyword}{struct }\mbox{\hyperlink{structg__provider}{g\_provider}} *\mbox{\hyperlink{g__part__if_8m_a9bc7638f295763b77465c5ebebbd3442}{pp}};}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00268}00268 }
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00269}00269                 \mbox{\hyperlink{g__part__if_8m_a9bc7638f295763b77465c5ebebbd3442}{pp}} = LIST\_FIRST(\&sc-\/>\mbox{\hyperlink{structg__eli__softc_a899949202205997147c78c52b32b9843}{sc\_geom}}-\/>consumer)-\/>provider;}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00270}00270                 \mbox{\hyperlink{structg__provider_a8f47c464c78aa91fa4ca5143ed3cd15e}{mediasize}} = \mbox{\hyperlink{g__part__if_8m_a9bc7638f295763b77465c5ebebbd3442}{pp}}-\/>\mbox{\hyperlink{structg__provider_a8f47c464c78aa91fa4ca5143ed3cd15e}{mediasize}};}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00271}00271                 blocksize = \mbox{\hyperlink{g__part__if_8m_a9bc7638f295763b77465c5ebebbd3442}{pp}}-\/>\mbox{\hyperlink{structg__provider_aea3cd43d41461790b8d0afcd8c49a355}{sectorsize}};}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00272}00272         \} \textcolor{keywordflow}{else} \{}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00273}00273                 \mbox{\hyperlink{structg__provider_a8f47c464c78aa91fa4ca5143ed3cd15e}{mediasize}} = sc-\/>\mbox{\hyperlink{structg__eli__softc_a886bea13cc2ca3e3e7b459d97d2459f5}{sc\_mediasize}};}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00274}00274                 blocksize = sc-\/>\mbox{\hyperlink{structg__eli__softc_a98f6d4510dc5541540fbb45883782c9f}{sc\_sectorsize}};}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00275}00275         \}}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00276}00276         new\_ekeys\_total = ((\mbox{\hyperlink{structg__provider_a8f47c464c78aa91fa4ca5143ed3cd15e}{mediasize}} -\/ 1) >> \mbox{\hyperlink{g__eli_8h_ab8cfe0383780aeb7d7f5ea6c9d2b1cea}{G\_ELI\_KEY\_SHIFT}}) / blocksize + 1;}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00277}00277         \textcolor{comment}{/* We only allow to grow. */}}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00278}00278         KASSERT(new\_ekeys\_total >= sc-\/>\mbox{\hyperlink{structg__eli__softc_addf43ecb1aadd3f61593aa388b4742a4}{sc\_ekeys\_total}},}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00279}00279             (\textcolor{stringliteral}{"{}new\_ekeys\_total=\%ju < sc\_ekeys\_total=\%ju"{}},}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00280}00280             (uintmax\_t)new\_ekeys\_total, (uintmax\_t)sc-\/>\mbox{\hyperlink{structg__eli__softc_addf43ecb1aadd3f61593aa388b4742a4}{sc\_ekeys\_total}}));}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00281}00281         \textcolor{keywordflow}{if} (new\_ekeys\_total <= \mbox{\hyperlink{g__eli__key__cache_8c_a4fd8867a72aa80bb0459a2ad5eeb3589}{g\_eli\_key\_cache\_limit}}) \{}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00282}00282                 uint64\_t keyno;}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00283}00283 }
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00284}00284                 \textcolor{keywordflow}{for} (keyno = sc-\/>\mbox{\hyperlink{structg__eli__softc_addf43ecb1aadd3f61593aa388b4742a4}{sc\_ekeys\_total}}; keyno < new\_ekeys\_total;}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00285}00285                     keyno++) \{}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00286}00286                         (void)\mbox{\hyperlink{g__eli__key__cache_8c_a6e49116ae542d1da934b59e32d5cd216}{g\_eli\_key\_allocate}}(sc, keyno);}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00287}00287                 \}}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00288}00288                 KASSERT(new\_ekeys\_total == sc-\/>\mbox{\hyperlink{structg__eli__softc_a79fd16c488c0d5c510b56c944364218d}{sc\_ekeys\_allocated}},}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00289}00289                     (\textcolor{stringliteral}{"{}new\_ekeys\_total=\%ju != sc\_ekeys\_allocated=\%ju"{}},}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00290}00290                     (uintmax\_t)new\_ekeys\_total,}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00291}00291                     (uintmax\_t)sc-\/>\mbox{\hyperlink{structg__eli__softc_a79fd16c488c0d5c510b56c944364218d}{sc\_ekeys\_allocated}}));}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00292}00292         \}}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00293}00293 }
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00294}00294         sc-\/>\mbox{\hyperlink{structg__eli__softc_addf43ecb1aadd3f61593aa388b4742a4}{sc\_ekeys\_total}} = new\_ekeys\_total;}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00295}00295 }
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00296}00296         mtx\_unlock(\&sc-\/>\mbox{\hyperlink{structg__eli__softc_aeaed9e283a3ee539995fcfa127e67bed}{sc\_ekeys\_lock}});}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00297}00297 \}}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00298}00298 }
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00299}00299 \textcolor{comment}{/*}}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00300}00300 \textcolor{comment}{ * Select encryption key. If G\_ELI\_FLAG\_SINGLE\_KEY is present we only have one}}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00301}00301 \textcolor{comment}{ * key available for all the data. If the flag is not present select the key}}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00302}00302 \textcolor{comment}{ * based on data offset.}}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00303}00303 \textcolor{comment}{ */}}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00304}00304 \mbox{\hyperlink{binstream_8h_ab077fa1127453be2bd9d4c3c8a768fa7}{uint8\_t}} *}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00305}\mbox{\hyperlink{g__eli_8h_a0271575799ad05ec5fb7adc0b414e137}{00305}} \mbox{\hyperlink{g__eli__key__cache_8c_a0271575799ad05ec5fb7adc0b414e137}{g\_eli\_key\_hold}}(\textcolor{keyword}{struct} \mbox{\hyperlink{structg__eli__softc}{g\_eli\_softc}} *sc, off\_t \mbox{\hyperlink{g__raid__tr__if_8m_ad5f0842c40c7e46344fd8df70187fa0f}{offset}}, \textcolor{keywordtype}{size\_t} blocksize)}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00306}00306 \{}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00307}00307         \textcolor{keyword}{struct }\mbox{\hyperlink{structg__eli__key}{g\_eli\_key}} *key, keysearch;}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00308}00308         uint64\_t keyno;}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00309}00309 }
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00310}00310         \textcolor{keywordflow}{if} ((sc-\/>\mbox{\hyperlink{structg__eli__softc_a94876b8cf2ed7da3eb3a3e1858171ef2}{sc\_flags}} \& \mbox{\hyperlink{g__eli_8h_a0440d24008eaa5fe7620843804fecc7a}{G\_ELI\_FLAG\_SINGLE\_KEY}}) != 0)}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00311}00311                 \textcolor{keywordflow}{return} (sc-\/>\mbox{\hyperlink{structg__eli__softc_a23352840c391565e85bd18ca4a72320e}{sc\_ekey}});}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00312}00312 }
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00313}00313         \textcolor{comment}{/* We switch key every 2\string^G\_ELI\_KEY\_SHIFT blocks. */}}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00314}00314         keyno = (\mbox{\hyperlink{g__raid__tr__if_8m_ad5f0842c40c7e46344fd8df70187fa0f}{offset}} >> \mbox{\hyperlink{g__eli_8h_ab8cfe0383780aeb7d7f5ea6c9d2b1cea}{G\_ELI\_KEY\_SHIFT}}) / blocksize;}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00315}00315 }
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00316}00316         KASSERT(keyno < sc-\/>sc\_ekeys\_total,}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00317}00317             (\textcolor{stringliteral}{"{}\%s: keyno=\%ju >= sc\_ekeys\_total=\%ju"{}},}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00318}00318             \_\_func\_\_, (uintmax\_t)keyno, (uintmax\_t)sc-\/>\mbox{\hyperlink{structg__eli__softc_addf43ecb1aadd3f61593aa388b4742a4}{sc\_ekeys\_total}}));}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00319}00319 }
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00320}00320         keysearch.\mbox{\hyperlink{structg__eli__key_a52688902d6e7306fc4f468ac3c9e9334}{gek\_keyno}} = keyno;}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00321}00321 }
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00322}00322         \textcolor{keywordflow}{if} (sc-\/>\mbox{\hyperlink{structg__eli__softc_addf43ecb1aadd3f61593aa388b4742a4}{sc\_ekeys\_total}} == sc-\/>\mbox{\hyperlink{structg__eli__softc_a79fd16c488c0d5c510b56c944364218d}{sc\_ekeys\_allocated}}) \{}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00323}00323                 \textcolor{comment}{/* We have all the keys, so avoid some overhead. */}}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00324}00324                 key = RB\_FIND(g\_eli\_key\_tree, \&sc-\/>sc\_ekeys\_tree, \&keysearch);}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00325}00325                 KASSERT(key != NULL, (\textcolor{stringliteral}{"{}No key \%ju found."{}}, (uintmax\_t)keyno));}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00326}00326                 KASSERT(key-\/>\mbox{\hyperlink{structg__eli__key_a0cc9445fd08397ecc1a902c065a86631}{gek\_magic}} == \mbox{\hyperlink{g__eli_8h_a8016668c3138460b2912154d099e1c43}{G\_ELI\_KEY\_MAGIC}},}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00327}00327                     (\textcolor{stringliteral}{"{}Invalid key magic."{}}));}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00328}00328                 \textcolor{keywordflow}{return} (key-\/>\mbox{\hyperlink{structg__eli__key_ab17ea58ccc262b9c8b90f785f63ecae6}{gek\_key}});}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00329}00329         \}}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00330}00330 }
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00331}00331         mtx\_lock(\&sc-\/>\mbox{\hyperlink{structg__eli__softc_aeaed9e283a3ee539995fcfa127e67bed}{sc\_ekeys\_lock}});}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00332}00332         key = RB\_FIND(g\_eli\_key\_tree, \&sc-\/>sc\_ekeys\_tree, \&keysearch);}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00333}00333         \textcolor{keywordflow}{if} (key != NULL) \{}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00334}00334                 \mbox{\hyperlink{g__eli__key__cache_8c_a955b8bacccfd2540de45dde8d4b6aff2}{g\_eli\_key\_cache\_hits}}++;}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00335}00335                 TAILQ\_REMOVE(\&sc-\/>sc\_ekeys\_queue, key, gek\_next);}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00336}00336                 TAILQ\_INSERT\_TAIL(\&sc-\/>sc\_ekeys\_queue, key, gek\_next);}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00337}00337         \} \textcolor{keywordflow}{else} \{}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00338}00338                 \textcolor{comment}{/*}}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00339}00339 \textcolor{comment}{                 * No key in cache, find the least recently unreferenced key}}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00340}00340 \textcolor{comment}{                 * or allocate one if we haven't reached our limit yet.}}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00341}00341 \textcolor{comment}{                 */}}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00342}00342                 \textcolor{keywordflow}{if} (sc-\/>\mbox{\hyperlink{structg__eli__softc_a79fd16c488c0d5c510b56c944364218d}{sc\_ekeys\_allocated}} < \mbox{\hyperlink{g__eli__key__cache_8c_a4fd8867a72aa80bb0459a2ad5eeb3589}{g\_eli\_key\_cache\_limit}}) \{}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00343}00343                         key = \mbox{\hyperlink{g__eli__key__cache_8c_a6e49116ae542d1da934b59e32d5cd216}{g\_eli\_key\_allocate}}(sc, keyno);}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00344}00344                 \} \textcolor{keywordflow}{else} \{}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00345}00345                         \mbox{\hyperlink{g__eli__key__cache_8c_af43c729be7ab7bf3f9b34c9fe1465658}{g\_eli\_key\_cache\_misses}}++;}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00346}00346                         key = \mbox{\hyperlink{g__eli__key__cache_8c_a6d67454a8a0893446f20952385cb9788}{g\_eli\_key\_find\_last}}(sc);}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00347}00347                         \textcolor{keywordflow}{if} (key != NULL) \{}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00348}00348                                 \mbox{\hyperlink{g__eli__key__cache_8c_ab552e15d96c547c624223bdbe99d96d6}{g\_eli\_key\_replace}}(sc, key, keyno);}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00349}00349                         \} \textcolor{keywordflow}{else} \{}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00350}00350                                 \textcolor{comment}{/* All keys are referenced? Allocate one. */}}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00351}00351                                 key = \mbox{\hyperlink{g__eli__key__cache_8c_a6e49116ae542d1da934b59e32d5cd216}{g\_eli\_key\_allocate}}(sc, keyno);}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00352}00352                         \}}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00353}00353                 \}}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00354}00354         \}}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00355}00355         key-\/>\mbox{\hyperlink{structg__eli__key_a9812b097be2b483ad61eb367e80ef8e3}{gek\_count}}++;}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00356}00356         mtx\_unlock(\&sc-\/>\mbox{\hyperlink{structg__eli__softc_aeaed9e283a3ee539995fcfa127e67bed}{sc\_ekeys\_lock}});}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00357}00357 }
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00358}00358         KASSERT(key-\/>\mbox{\hyperlink{structg__eli__key_a0cc9445fd08397ecc1a902c065a86631}{gek\_magic}} == \mbox{\hyperlink{g__eli_8h_a8016668c3138460b2912154d099e1c43}{G\_ELI\_KEY\_MAGIC}}, (\textcolor{stringliteral}{"{}Invalid key magic."{}}));}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00359}00359 }
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00360}00360         \textcolor{keywordflow}{return} (key-\/>\mbox{\hyperlink{structg__eli__key_ab17ea58ccc262b9c8b90f785f63ecae6}{gek\_key}});}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00361}00361 \}}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00362}00362 }
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00363}00363 \textcolor{keywordtype}{void}}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00364}\mbox{\hyperlink{g__eli_8h_a6f8aafc6ae8883d71c46a348b8856b28}{00364}} \mbox{\hyperlink{g__eli__key__cache_8c_a6f8aafc6ae8883d71c46a348b8856b28}{g\_eli\_key\_drop}}(\textcolor{keyword}{struct} \mbox{\hyperlink{structg__eli__softc}{g\_eli\_softc}} *sc, \mbox{\hyperlink{binstream_8h_ab077fa1127453be2bd9d4c3c8a768fa7}{uint8\_t}} *rawkey)}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00365}00365 \{}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00366}00366         \textcolor{keyword}{struct }\mbox{\hyperlink{structg__eli__key}{g\_eli\_key}} *key = (\textcolor{keyword}{struct }\mbox{\hyperlink{structg__eli__key}{g\_eli\_key}} *)rawkey;}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00367}00367 }
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00368}00368         \textcolor{keywordflow}{if} ((sc-\/>\mbox{\hyperlink{structg__eli__softc_a94876b8cf2ed7da3eb3a3e1858171ef2}{sc\_flags}} \& \mbox{\hyperlink{g__eli_8h_a0440d24008eaa5fe7620843804fecc7a}{G\_ELI\_FLAG\_SINGLE\_KEY}}) != 0)}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00369}00369                 \textcolor{keywordflow}{return};}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00370}00370 }
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00371}00371         KASSERT(key-\/>\mbox{\hyperlink{structg__eli__key_a0cc9445fd08397ecc1a902c065a86631}{gek\_magic}} == \mbox{\hyperlink{g__eli_8h_a8016668c3138460b2912154d099e1c43}{G\_ELI\_KEY\_MAGIC}}, (\textcolor{stringliteral}{"{}Invalid key magic."{}}));}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00372}00372 }
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00373}00373         \textcolor{keywordflow}{if} (sc-\/>\mbox{\hyperlink{structg__eli__softc_addf43ecb1aadd3f61593aa388b4742a4}{sc\_ekeys\_total}} == sc-\/>\mbox{\hyperlink{structg__eli__softc_a79fd16c488c0d5c510b56c944364218d}{sc\_ekeys\_allocated}})}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00374}00374                 \textcolor{keywordflow}{return};}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00375}00375 }
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00376}00376         mtx\_lock(\&sc-\/>\mbox{\hyperlink{structg__eli__softc_aeaed9e283a3ee539995fcfa127e67bed}{sc\_ekeys\_lock}});}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00377}00377         KASSERT(key-\/>\mbox{\hyperlink{structg__eli__key_a9812b097be2b483ad61eb367e80ef8e3}{gek\_count}} > 0, (\textcolor{stringliteral}{"{}key-\/>gek\_count=\%d"{}}, key-\/>\mbox{\hyperlink{structg__eli__key_a9812b097be2b483ad61eb367e80ef8e3}{gek\_count}}));}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00378}00378         key-\/>\mbox{\hyperlink{structg__eli__key_a9812b097be2b483ad61eb367e80ef8e3}{gek\_count}}-\/-\/;}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00379}00379         \textcolor{keywordflow}{while} (sc-\/>\mbox{\hyperlink{structg__eli__softc_a79fd16c488c0d5c510b56c944364218d}{sc\_ekeys\_allocated}} > \mbox{\hyperlink{g__eli__key__cache_8c_a4fd8867a72aa80bb0459a2ad5eeb3589}{g\_eli\_key\_cache\_limit}}) \{}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00380}00380                 key = \mbox{\hyperlink{g__eli__key__cache_8c_a6d67454a8a0893446f20952385cb9788}{g\_eli\_key\_find\_last}}(sc);}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00381}00381                 \textcolor{keywordflow}{if} (key == NULL)}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00382}00382                         \textcolor{keywordflow}{break};}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00383}00383                 \mbox{\hyperlink{g__eli__key__cache_8c_a78798e879ad9727d2b755f9adb421b94}{g\_eli\_key\_remove}}(sc, key);}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00384}00384         \}}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00385}00385         mtx\_unlock(\&sc-\/>\mbox{\hyperlink{structg__eli__softc_aeaed9e283a3ee539995fcfa127e67bed}{sc\_ekeys\_lock}});}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00386}00386 \}}
\DoxyCodeLine{\Hypertarget{g__eli__key__cache_8c_source_l00387}00387 \textcolor{preprocessor}{\#endif }\textcolor{comment}{/* \_KERNEL */}\textcolor{preprocessor}{}}

\end{DoxyCode}
