\hypertarget{g__eli__hmac_8c_source}{}\doxysection{g\+\_\+eli\+\_\+hmac.\+c}
\label{g__eli__hmac_8c_source}\index{geom/eli/g\_eli\_hmac.c@{geom/eli/g\_eli\_hmac.c}}
\mbox{\hyperlink{g__eli__hmac_8c}{Go to the documentation of this file.}}
\begin{DoxyCode}{0}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00001}00001 \textcolor{comment}{/*-\/}}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00002}00002 \textcolor{comment}{ * Copyright (c) 2005-\/2010 Pawel Jakub Dawidek <pjd@FreeBSD.org>}}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00003}00003 \textcolor{comment}{ * All rights reserved.}}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00004}00004 \textcolor{comment}{ *}}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00005}00005 \textcolor{comment}{ * Redistribution and use in source and binary forms, with or without}}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00006}00006 \textcolor{comment}{ * modification, are permitted provided that the following conditions}}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00007}00007 \textcolor{comment}{ * are met:}}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00008}00008 \textcolor{comment}{ * 1. Redistributions of source code must retain the above copyright}}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00009}00009 \textcolor{comment}{ *    notice, this list of conditions and the following disclaimer.}}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00010}00010 \textcolor{comment}{ * 2. Redistributions in binary form must reproduce the above copyright}}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00011}00011 \textcolor{comment}{ *    notice, this list of conditions and the following disclaimer in the}}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00012}00012 \textcolor{comment}{ *    documentation and/or other materials provided with the distribution.}}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00013}00013 \textcolor{comment}{ *}}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00014}00014 \textcolor{comment}{ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND}}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00015}00015 \textcolor{comment}{ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE}}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00016}00016 \textcolor{comment}{ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE}}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00017}00017 \textcolor{comment}{ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE}}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00018}00018 \textcolor{comment}{ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL}}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00019}00019 \textcolor{comment}{ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS}}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00020}00020 \textcolor{comment}{ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)}}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00021}00021 \textcolor{comment}{ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT}}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00022}00022 \textcolor{comment}{ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY}}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00023}00023 \textcolor{comment}{ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF}}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00024}00024 \textcolor{comment}{ * SUCH DAMAGE.}}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00025}00025 \textcolor{comment}{ */}}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00026}00026 }
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00027}00027 \textcolor{preprocessor}{\#include <sys/cdefs.h>}}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00028}\mbox{\hyperlink{g__eli__hmac_8c_a8c3ef283470a68cd30afe9b8a72cb60f}{00028}} \mbox{\hyperlink{g__eli__hmac_8c_a8c3ef283470a68cd30afe9b8a72cb60f}{\_\_FBSDID}}(\textcolor{stringliteral}{"{}\$FreeBSD\$"{}});}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00029}00029 }
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00030}00030 \textcolor{preprocessor}{\#include <sys/param.h>}}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00031}00031 \textcolor{preprocessor}{\#ifdef \_KERNEL}}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00032}00032 \textcolor{preprocessor}{\#include <sys/systm.h>}}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00033}00033 \textcolor{preprocessor}{\#include <sys/kernel.h>}}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00034}00034 \textcolor{preprocessor}{\#include <sys/malloc.h>}}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00035}00035 \textcolor{preprocessor}{\#elif defined(\_STANDALONE)}}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00036}00036 \textcolor{preprocessor}{\#include "{}stand.h"{}}}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00037}00037 \textcolor{preprocessor}{\#else}}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00038}00038 \textcolor{preprocessor}{\#include <stdint.h>}}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00039}00039 \textcolor{preprocessor}{\#include <string.h>}}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00040}00040 \textcolor{preprocessor}{\#include <strings.h>}}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00041}00041 \textcolor{preprocessor}{\#include <errno.h>}}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00042}00042 \textcolor{preprocessor}{\#include <assert.h>}}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00043}00043 \textcolor{preprocessor}{\#include <openssl/evp.h>}}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00044}00044 \textcolor{preprocessor}{\#define \_OpenSSL\_}}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00045}00045 \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00046}00046 \textcolor{preprocessor}{\#include <\mbox{\hyperlink{g__eli_8h}{geom/eli/g\_eli.h}}>}}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00047}00047 }
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00048}00048 \textcolor{keywordtype}{void}}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00049}\mbox{\hyperlink{g__eli_8h_a043228f1ea776ea3cb70412a7c5cee76}{00049}} \mbox{\hyperlink{g__eli__hmac_8c_a043228f1ea776ea3cb70412a7c5cee76}{g\_eli\_crypto\_hmac\_init}}(\textcolor{keyword}{struct} \mbox{\hyperlink{structhmac__ctx}{hmac\_ctx}} *ctx, \textcolor{keyword}{const} \textcolor{keywordtype}{char} *hkey,}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00050}00050     \textcolor{keywordtype}{size\_t} hkeylen)}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00051}00051 \{}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00052}00052         u\_char k\_ipad[128], k\_opad[128], key[128];}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00053}00053         SHA512\_CTX lctx;}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00054}00054         u\_int i;}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00055}00055 }
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00056}00056         bzero(key, \textcolor{keyword}{sizeof}(key));}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00057}00057         \textcolor{keywordflow}{if} (hkeylen == 0)}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00058}00058                 ; \textcolor{comment}{/* do nothing */}}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00059}00059         \textcolor{keywordflow}{else} \textcolor{keywordflow}{if} (hkeylen <= 128)}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00060}00060                 bcopy(hkey, key, hkeylen);}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00061}00061         \textcolor{keywordflow}{else} \{}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00062}00062                 \textcolor{comment}{/* If key is longer than 128 bytes reset it to key = SHA512(key). */}}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00063}00063                 SHA512\_Init(\&lctx);}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00064}00064                 SHA512\_Update(\&lctx, hkey, hkeylen);}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00065}00065                 SHA512\_Final(key, \&lctx);}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00066}00066         \}}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00067}00067 }
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00068}00068         \textcolor{comment}{/* XOR key with ipad and opad values. */}}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00069}00069         \textcolor{keywordflow}{for} (i = 0; i < \textcolor{keyword}{sizeof}(key); i++) \{}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00070}00070                 k\_ipad[i] = key[i] \string^ 0x36;}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00071}00071                 k\_opad[i] = key[i] \string^ 0x5c;}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00072}00072         \}}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00073}00073         explicit\_bzero(key, \textcolor{keyword}{sizeof}(key));}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00074}00074         \textcolor{comment}{/* Start inner SHA512. */}}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00075}00075         SHA512\_Init(\&ctx-\/>\mbox{\hyperlink{structhmac__ctx_af09486ab180913e073cc10e4118c0c1d}{innerctx}});}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00076}00076         SHA512\_Update(\&ctx-\/>\mbox{\hyperlink{structhmac__ctx_af09486ab180913e073cc10e4118c0c1d}{innerctx}}, k\_ipad, \textcolor{keyword}{sizeof}(k\_ipad));}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00077}00077         explicit\_bzero(k\_ipad, \textcolor{keyword}{sizeof}(k\_ipad));}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00078}00078         \textcolor{comment}{/* Start outer SHA512. */}}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00079}00079         SHA512\_Init(\&ctx-\/>\mbox{\hyperlink{structhmac__ctx_ab766aac4d8826a0d607117e0513ebc4e}{outerctx}});}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00080}00080         SHA512\_Update(\&ctx-\/>\mbox{\hyperlink{structhmac__ctx_ab766aac4d8826a0d607117e0513ebc4e}{outerctx}}, k\_opad, \textcolor{keyword}{sizeof}(k\_opad));}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00081}00081         explicit\_bzero(k\_opad, \textcolor{keyword}{sizeof}(k\_opad));}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00082}00082 \}}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00083}00083 }
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00084}00084 \textcolor{keywordtype}{void}}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00085}\mbox{\hyperlink{g__eli_8h_a30bc80ea7c5963579dd5083e15a78176}{00085}} \mbox{\hyperlink{g__eli__hmac_8c_a30bc80ea7c5963579dd5083e15a78176}{g\_eli\_crypto\_hmac\_update}}(\textcolor{keyword}{struct} \mbox{\hyperlink{structhmac__ctx}{hmac\_ctx}} *ctx, \textcolor{keyword}{const} \mbox{\hyperlink{binstream_8h_ab077fa1127453be2bd9d4c3c8a768fa7}{uint8\_t}} *\mbox{\hyperlink{g__part__if_8m_a735984d41155bc1032e09bece8f8d66d}{data}},}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00086}00086     \textcolor{keywordtype}{size\_t} datasize)}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00087}00087 \{}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00088}00088 }
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00089}00089         SHA512\_Update(\&ctx-\/>\mbox{\hyperlink{structhmac__ctx_af09486ab180913e073cc10e4118c0c1d}{innerctx}}, \mbox{\hyperlink{g__part__if_8m_a735984d41155bc1032e09bece8f8d66d}{data}}, datasize);}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00090}00090 \}}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00091}00091 }
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00092}00092 \textcolor{keywordtype}{void}}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00093}\mbox{\hyperlink{g__eli_8h_abc72d045d3fee2a84c89f1168191207a}{00093}} \mbox{\hyperlink{g__eli__hmac_8c_abc72d045d3fee2a84c89f1168191207a}{g\_eli\_crypto\_hmac\_final}}(\textcolor{keyword}{struct} \mbox{\hyperlink{structhmac__ctx}{hmac\_ctx}} *ctx, \mbox{\hyperlink{binstream_8h_ab077fa1127453be2bd9d4c3c8a768fa7}{uint8\_t}} *md, \textcolor{keywordtype}{size\_t} mdsize)}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00094}00094 \{}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00095}00095         u\_char digest[\mbox{\hyperlink{g__eli_8h_a54d6e8690a9994410675db19dea8dacb}{SHA512\_MDLEN}}];}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00096}00096 }
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00097}00097         \textcolor{comment}{/* Complete inner hash */}}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00098}00098         SHA512\_Final(digest, \&ctx-\/>\mbox{\hyperlink{structhmac__ctx_af09486ab180913e073cc10e4118c0c1d}{innerctx}});}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00099}00099 }
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00100}00100         \textcolor{comment}{/* Complete outer hash */}}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00101}00101         SHA512\_Update(\&ctx-\/>\mbox{\hyperlink{structhmac__ctx_ab766aac4d8826a0d607117e0513ebc4e}{outerctx}}, digest, \textcolor{keyword}{sizeof}(digest));}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00102}00102         SHA512\_Final(digest, \&ctx-\/>\mbox{\hyperlink{structhmac__ctx_ab766aac4d8826a0d607117e0513ebc4e}{outerctx}});}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00103}00103 }
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00104}00104         explicit\_bzero(ctx, \textcolor{keyword}{sizeof}(*ctx));}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00105}00105         \textcolor{comment}{/* mdsize == 0 means "{}Give me the whole hash!"{} */}}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00106}00106         \textcolor{keywordflow}{if} (mdsize == 0)}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00107}00107                 mdsize = \mbox{\hyperlink{g__eli_8h_a54d6e8690a9994410675db19dea8dacb}{SHA512\_MDLEN}};}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00108}00108         bcopy(digest, md, mdsize);}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00109}00109         explicit\_bzero(digest, \textcolor{keyword}{sizeof}(digest));}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00110}00110 \}}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00111}00111 }
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00112}00112 \textcolor{keywordtype}{void}}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00113}\mbox{\hyperlink{g__eli_8h_a7568712ca711b91d055948e2bed38865}{00113}} \mbox{\hyperlink{g__eli__hmac_8c_a7568712ca711b91d055948e2bed38865}{g\_eli\_crypto\_hmac}}(\textcolor{keyword}{const} \textcolor{keywordtype}{char} *hkey, \textcolor{keywordtype}{size\_t} hkeysize, \textcolor{keyword}{const} \mbox{\hyperlink{binstream_8h_ab077fa1127453be2bd9d4c3c8a768fa7}{uint8\_t}} *\mbox{\hyperlink{g__part__if_8m_a735984d41155bc1032e09bece8f8d66d}{data}},}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00114}00114     \textcolor{keywordtype}{size\_t} datasize, \mbox{\hyperlink{binstream_8h_ab077fa1127453be2bd9d4c3c8a768fa7}{uint8\_t}} *md, \textcolor{keywordtype}{size\_t} mdsize)}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00115}00115 \{}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00116}00116         \textcolor{keyword}{struct }\mbox{\hyperlink{structhmac__ctx}{hmac\_ctx}} ctx;}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00117}00117 }
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00118}00118         \mbox{\hyperlink{g__eli__hmac_8c_a043228f1ea776ea3cb70412a7c5cee76}{g\_eli\_crypto\_hmac\_init}}(\&ctx, hkey, hkeysize);}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00119}00119         \mbox{\hyperlink{g__eli__hmac_8c_a30bc80ea7c5963579dd5083e15a78176}{g\_eli\_crypto\_hmac\_update}}(\&ctx, \mbox{\hyperlink{g__part__if_8m_a735984d41155bc1032e09bece8f8d66d}{data}}, datasize);}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00120}00120         \mbox{\hyperlink{g__eli__hmac_8c_abc72d045d3fee2a84c89f1168191207a}{g\_eli\_crypto\_hmac\_final}}(\&ctx, md, mdsize);}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00121}00121 \}}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00122}00122 }
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00123}00123 \textcolor{comment}{/*}}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00124}00124 \textcolor{comment}{ * Here we generate IV. It is unique for every sector.}}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00125}00125 \textcolor{comment}{ */}}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00126}00126 \textcolor{keywordtype}{void}}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00127}\mbox{\hyperlink{g__eli_8h_ab07921ca3b88d093ec9b2b33a0d8d226}{00127}} \mbox{\hyperlink{g__eli__hmac_8c_ab07921ca3b88d093ec9b2b33a0d8d226}{g\_eli\_crypto\_ivgen}}(\textcolor{keyword}{struct} \mbox{\hyperlink{structg__eli__softc}{g\_eli\_softc}} *sc, off\_t \mbox{\hyperlink{g__raid__tr__if_8m_ad5f0842c40c7e46344fd8df70187fa0f}{offset}}, u\_char *iv,}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00128}00128     \textcolor{keywordtype}{size\_t} size)}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00129}00129 \{}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00130}00130         \mbox{\hyperlink{binstream_8h_ab077fa1127453be2bd9d4c3c8a768fa7}{uint8\_t}} off[8];}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00131}00131 }
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00132}00132         \textcolor{keywordflow}{if} ((sc-\/>\mbox{\hyperlink{structg__eli__softc_a94876b8cf2ed7da3eb3a3e1858171ef2}{sc\_flags}} \& \mbox{\hyperlink{g__eli_8h_aadf5b5c7223ca0c58183c6b87de8acd0}{G\_ELI\_FLAG\_NATIVE\_BYTE\_ORDER}}) != 0)}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00133}00133                 bcopy(\&\mbox{\hyperlink{g__raid__tr__if_8m_ad5f0842c40c7e46344fd8df70187fa0f}{offset}}, off, \textcolor{keyword}{sizeof}(off));}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00134}00134         \textcolor{keywordflow}{else}}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00135}00135                 le64enc(off, (uint64\_t)\mbox{\hyperlink{g__raid__tr__if_8m_ad5f0842c40c7e46344fd8df70187fa0f}{offset}});}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00136}00136 }
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00137}00137         \textcolor{keywordflow}{switch} (sc-\/>\mbox{\hyperlink{structg__eli__softc_aecc6e7e7b1b2e05b9ded85a9ab763d74}{sc\_ealgo}}) \{}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00138}00138         \textcolor{keywordflow}{case} CRYPTO\_AES\_XTS:}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00139}00139                 bcopy(off, iv, \textcolor{keyword}{sizeof}(off));}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00140}00140                 bzero(iv + \textcolor{keyword}{sizeof}(off), size -\/ \textcolor{keyword}{sizeof}(off));}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00141}00141                 \textcolor{keywordflow}{break};}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00142}00142         \textcolor{keywordflow}{default}:}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00143}00143             \{}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00144}00144                 u\_char hash[SHA256\_DIGEST\_LENGTH];}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00145}00145                 SHA256\_CTX ctx;}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00146}00146 }
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00147}00147                 \textcolor{comment}{/* Copy precalculated SHA256 context for IV-\/Key. */}}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00148}00148                 bcopy(\&sc-\/>\mbox{\hyperlink{structg__eli__softc_a7e01f366939fc752d121f7a6bc352675}{sc\_ivctx}}, \&ctx, \textcolor{keyword}{sizeof}(ctx));}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00149}00149                 SHA256\_Update(\&ctx, off, \textcolor{keyword}{sizeof}(off));}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00150}00150                 SHA256\_Final(hash, \&ctx);}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00151}00151                 bcopy(hash, iv, MIN(\textcolor{keyword}{sizeof}(hash), size));}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00152}00152                 \textcolor{keywordflow}{break};}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00153}00153             \}}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00154}00154         \}}
\DoxyCodeLine{\Hypertarget{g__eli__hmac_8c_source_l00155}00155 \}}

\end{DoxyCode}
