\hypertarget{cbc__mac_8c_source}{}\doxysection{cbc\+\_\+mac.\+c}
\label{cbc__mac_8c_source}\index{opencrypto/cbc\_mac.c@{opencrypto/cbc\_mac.c}}
\mbox{\hyperlink{cbc__mac_8c}{Go to the documentation of this file.}}
\begin{DoxyCode}{0}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00001}00001 \textcolor{comment}{/*}}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00002}00002 \textcolor{comment}{ * Copyright (c) 2018-\/2019 iXsystems Inc.  All rights reserved.}}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00003}00003 \textcolor{comment}{ *}}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00004}00004 \textcolor{comment}{ * Redistribution and use in source and binary forms, with or without}}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00005}00005 \textcolor{comment}{ * modification, are permitted provided that the following conditions}}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00006}00006 \textcolor{comment}{ * are met:}}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00007}00007 \textcolor{comment}{ * 1. Redistributions of source code must retain the above copyright}}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00008}00008 \textcolor{comment}{ *    notice, this list of conditions and the following disclaimer.}}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00009}00009 \textcolor{comment}{ * 2. Redistributions in binary form must reproduce the above copyright}}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00010}00010 \textcolor{comment}{ *    notice, this list of conditions and the following disclaimer in the}}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00011}00011 \textcolor{comment}{ *    documentation and/or other materials provided with the distribution.}}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00012}00012 \textcolor{comment}{ *}}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00013}00013 \textcolor{comment}{ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR}}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00014}00014 \textcolor{comment}{ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES}}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00015}00015 \textcolor{comment}{ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.}}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00016}00016 \textcolor{comment}{ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,}}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00017}00017 \textcolor{comment}{ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT}}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00018}00018 \textcolor{comment}{ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,}}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00019}00019 \textcolor{comment}{ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY}}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00020}00020 \textcolor{comment}{ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT}}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00021}00021 \textcolor{comment}{ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF}}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00022}00022 \textcolor{comment}{ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.}}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00023}00023 \textcolor{comment}{ */}}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00024}00024 }
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00025}00025 \textcolor{preprocessor}{\#include <sys/cdefs.h>}}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00026}\mbox{\hyperlink{cbc__mac_8c_a8c3ef283470a68cd30afe9b8a72cb60f}{00026}} \mbox{\hyperlink{cbc__mac_8c_a8c3ef283470a68cd30afe9b8a72cb60f}{\_\_FBSDID}}(\textcolor{stringliteral}{"{}\$FreeBSD\$"{}});}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00027}00027 }
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00028}00028 \textcolor{preprocessor}{\#include <sys/types.h>}}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00029}00029 \textcolor{preprocessor}{\#include <sys/systm.h>}}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00030}00030 \textcolor{preprocessor}{\#include <sys/param.h>}}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00031}00031 \textcolor{preprocessor}{\#include <sys/endian.h>}}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00032}00032 \textcolor{preprocessor}{\#include <\mbox{\hyperlink{cbc__mac_8h}{opencrypto/cbc\_mac.h}}>}}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00033}00033 \textcolor{preprocessor}{\#include <\mbox{\hyperlink{xform__auth_8h}{opencrypto/xform\_auth.h}}>}}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00034}00034 }
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00035}00035 \textcolor{comment}{/*}}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00036}00036 \textcolor{comment}{ * Given two CCM\_CBC\_BLOCK\_LEN blocks, xor}}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00037}00037 \textcolor{comment}{ * them into dst, and then encrypt dst.}}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00038}00038 \textcolor{comment}{ */}}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00039}00039 \textcolor{keyword}{static} \textcolor{keywordtype}{void}}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00040}\mbox{\hyperlink{cbc__mac_8c_ab6f3fc035687f7feefbdd6a4b5bcd92a}{00040}} \mbox{\hyperlink{cbc__mac_8c_ab6f3fc035687f7feefbdd6a4b5bcd92a}{xor\_and\_encrypt}}(\textcolor{keyword}{struct} \mbox{\hyperlink{structaes__cbc__mac__ctx}{aes\_cbc\_mac\_ctx}} *ctx,}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00041}00041                 \textcolor{keyword}{const} uint8\_t *src, uint8\_t *dst)}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00042}00042 \{}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00043}00043         \textcolor{keyword}{const} uint64\_t *b1;}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00044}00044         uint64\_t *b2;}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00045}00045         uint64\_t temp\_block[\mbox{\hyperlink{cbc__mac_8h_a93cc12cc210e8f3e682726362cba4573}{CCM\_CBC\_BLOCK\_LEN}}/\textcolor{keyword}{sizeof}(uint64\_t)];}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00046}00046 }
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00047}00047         b1 = (\textcolor{keyword}{const} uint64\_t*)src;}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00048}00048         b2 = (uint64\_t*)dst;}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00049}00049 }
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00050}00050         \textcolor{keywordflow}{for} (\textcolor{keywordtype}{size\_t} count = 0;}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00051}00051              count < \mbox{\hyperlink{cbc__mac_8h_a93cc12cc210e8f3e682726362cba4573}{CCM\_CBC\_BLOCK\_LEN}}/\textcolor{keyword}{sizeof}(uint64\_t);}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00052}00052              count++) \{}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00053}00053                 temp\_block[count] = b1[count] \string^ b2[count];}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00054}00054         \}}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00055}00055         rijndaelEncrypt(ctx-\/>\mbox{\hyperlink{structaes__cbc__mac__ctx_a134a2b899c7bed15794dffbc37bc436f}{keysched}}, ctx-\/>\mbox{\hyperlink{structaes__cbc__mac__ctx_ab35eacc1a7c5ebf06a061c32c13ae485}{rounds}}, (\textcolor{keywordtype}{void}*)temp\_block, dst);}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00056}00056 \}}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00057}00057 }
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00058}00058 \textcolor{keywordtype}{void}}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00059}\mbox{\hyperlink{cbc__mac_8c_a26138253e492657b41158ae678120f2c}{00059}} \mbox{\hyperlink{cbc__mac_8c_a26138253e492657b41158ae678120f2c}{AES\_CBC\_MAC\_Init}}(\textcolor{keywordtype}{void} *vctx)}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00060}00060 \{}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00061}00061         \textcolor{keyword}{struct }\mbox{\hyperlink{structaes__cbc__mac__ctx}{aes\_cbc\_mac\_ctx}} *ctx;}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00062}00062 }
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00063}00063         ctx = vctx;}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00064}00064         bzero(ctx, \textcolor{keyword}{sizeof}(*ctx));}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00065}00065 \}}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00066}00066 }
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00067}00067 \textcolor{keywordtype}{void}}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00068}\mbox{\hyperlink{cbc__mac_8c_ad0f14ca2614599eb4cfc1c2e831d875a}{00068}} \mbox{\hyperlink{cbc__mac_8c_ad0f14ca2614599eb4cfc1c2e831d875a}{AES\_CBC\_MAC\_Setkey}}(\textcolor{keywordtype}{void} *vctx, \textcolor{keyword}{const} uint8\_t *key, u\_int klen)}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00069}00069 \{}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00070}00070         \textcolor{keyword}{struct }\mbox{\hyperlink{structaes__cbc__mac__ctx}{aes\_cbc\_mac\_ctx}} *ctx;}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00071}00071 }
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00072}00072         ctx = vctx;}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00073}00073         ctx-\/>\mbox{\hyperlink{structaes__cbc__mac__ctx_ab35eacc1a7c5ebf06a061c32c13ae485}{rounds}} = rijndaelKeySetupEnc(ctx-\/>\mbox{\hyperlink{structaes__cbc__mac__ctx_a134a2b899c7bed15794dffbc37bc436f}{keysched}}, key, klen * 8);}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00074}00074 \}}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00075}00075 }
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00076}00076 \textcolor{comment}{/*}}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00077}00077 \textcolor{comment}{ * This is called to set the nonce, aka IV.}}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00078}00078 \textcolor{comment}{ *}}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00079}00079 \textcolor{comment}{ * Note that the caller is responsible for constructing b0 as well}}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00080}00080 \textcolor{comment}{ * as the length and padding around the AAD and passing that data}}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00081}00081 \textcolor{comment}{ * to \_Update.}}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00082}00082 \textcolor{comment}{ */}}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00083}00083 \textcolor{keywordtype}{void}}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00084}\mbox{\hyperlink{cbc__mac_8c_a085ab60b250c6a35e0767d645ac05796}{00084}} \mbox{\hyperlink{cbc__mac_8c_a085ab60b250c6a35e0767d645ac05796}{AES\_CBC\_MAC\_Reinit}}(\textcolor{keywordtype}{void} *vctx, \textcolor{keyword}{const} uint8\_t *\mbox{\hyperlink{structaes__cbc__mac__ctx_a5154c0f097df9184a446a1c25d7ec63a}{nonce}}, u\_int nonceLen)}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00085}00085 \{}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00086}00086         \textcolor{keyword}{struct }\mbox{\hyperlink{structaes__cbc__mac__ctx}{aes\_cbc\_mac\_ctx}} *ctx = vctx;}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00087}00087 }
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00088}00088         ctx-\/>\mbox{\hyperlink{structaes__cbc__mac__ctx_a5154c0f097df9184a446a1c25d7ec63a}{nonce}} = \mbox{\hyperlink{structaes__cbc__mac__ctx_a5154c0f097df9184a446a1c25d7ec63a}{nonce}};}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00089}00089         ctx-\/>\mbox{\hyperlink{structaes__cbc__mac__ctx_a2a05a43ca920c9a10d81a8cef44d240c}{nonceLength}} = nonceLen;}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00090}00090 }
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00091}00091         ctx-\/>\mbox{\hyperlink{structaes__cbc__mac__ctx_aca9b789e8120db44db240c29ac5cb8e2}{blockIndex}} = 0;}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00092}00092 }
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00093}00093         \textcolor{comment}{/* XOR b0 with all 0's on first call to \_Update. */}}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00094}00094         memset(ctx-\/>\mbox{\hyperlink{structaes__cbc__mac__ctx_af4daf4fbd6aac9888269ac54e7958bc4}{block}}, 0, \mbox{\hyperlink{cbc__mac_8h_a93cc12cc210e8f3e682726362cba4573}{CCM\_CBC\_BLOCK\_LEN}});}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00095}00095 \}}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00096}00096 }
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00097}00097 \textcolor{keywordtype}{int}}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00098}\mbox{\hyperlink{cbc__mac_8c_a2a953b91b1c32f6ea2e96b52b96096af}{00098}} \mbox{\hyperlink{cbc__mac_8c_a2a953b91b1c32f6ea2e96b52b96096af}{AES\_CBC\_MAC\_Update}}(\textcolor{keywordtype}{void} *vctx, \textcolor{keyword}{const} \textcolor{keywordtype}{void} *vdata, u\_int length)}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00099}00099 \{}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00100}00100         \textcolor{keyword}{struct }\mbox{\hyperlink{structaes__cbc__mac__ctx}{aes\_cbc\_mac\_ctx}} *ctx;}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00101}00101         \textcolor{keyword}{const} uint8\_t *data;}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00102}00102         \textcolor{keywordtype}{size\_t} copy\_amt;}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00103}00103         }
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00104}00104         ctx = vctx;}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00105}00105         data = vdata;}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00106}00106 }
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00107}00107         \textcolor{comment}{/*}}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00108}00108 \textcolor{comment}{         * \_Update can be called with non-\/aligned update lengths.  Use}}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00109}00109 \textcolor{comment}{         * the staging block when necessary.}}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00110}00110 \textcolor{comment}{         */}}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00111}00111         \textcolor{keywordflow}{while} (length != 0) \{}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00112}00112                 uint8\_t *ptr;}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00113}00113 }
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00114}00114                 \textcolor{comment}{/*}}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00115}00115 \textcolor{comment}{                 * If there is no partial block and the length is at}}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00116}00116 \textcolor{comment}{                 * least a full block, encrypt the full block without}}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00117}00117 \textcolor{comment}{                 * copying to the staging block.}}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00118}00118 \textcolor{comment}{                 */}}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00119}00119                 \textcolor{keywordflow}{if} (ctx-\/>\mbox{\hyperlink{structaes__cbc__mac__ctx_aca9b789e8120db44db240c29ac5cb8e2}{blockIndex}} == 0 \&\& length >= \mbox{\hyperlink{cbc__mac_8h_a93cc12cc210e8f3e682726362cba4573}{CCM\_CBC\_BLOCK\_LEN}}) \{}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00120}00120                         \mbox{\hyperlink{cbc__mac_8c_ab6f3fc035687f7feefbdd6a4b5bcd92a}{xor\_and\_encrypt}}(ctx, data, ctx-\/>\mbox{\hyperlink{structaes__cbc__mac__ctx_af4daf4fbd6aac9888269ac54e7958bc4}{block}});}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00121}00121                         length -\/= \mbox{\hyperlink{cbc__mac_8h_a93cc12cc210e8f3e682726362cba4573}{CCM\_CBC\_BLOCK\_LEN}};}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00122}00122                         data += \mbox{\hyperlink{cbc__mac_8h_a93cc12cc210e8f3e682726362cba4573}{CCM\_CBC\_BLOCK\_LEN}};}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00123}00123                         \textcolor{keywordflow}{continue};}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00124}00124                 \}}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00125}00125 }
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00126}00126                 copy\_amt = MIN(\textcolor{keyword}{sizeof}(ctx-\/>\mbox{\hyperlink{structaes__cbc__mac__ctx_aaa5f06890323184375d275053d6ac2c8}{staging\_block}}) -\/ ctx-\/>\mbox{\hyperlink{structaes__cbc__mac__ctx_aca9b789e8120db44db240c29ac5cb8e2}{blockIndex}},}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00127}00127                     length);}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00128}00128                 ptr = ctx-\/>\mbox{\hyperlink{structaes__cbc__mac__ctx_aaa5f06890323184375d275053d6ac2c8}{staging\_block}} + ctx-\/>\mbox{\hyperlink{structaes__cbc__mac__ctx_aca9b789e8120db44db240c29ac5cb8e2}{blockIndex}};}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00129}00129                 bcopy(data, ptr, copy\_amt);}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00130}00130                 data += copy\_amt;}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00131}00131                 ctx-\/>\mbox{\hyperlink{structaes__cbc__mac__ctx_aca9b789e8120db44db240c29ac5cb8e2}{blockIndex}} += copy\_amt;}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00132}00132                 length -\/= copy\_amt;}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00133}00133                 \textcolor{keywordflow}{if} (ctx-\/>\mbox{\hyperlink{structaes__cbc__mac__ctx_aca9b789e8120db44db240c29ac5cb8e2}{blockIndex}} == \textcolor{keyword}{sizeof}(ctx-\/>\mbox{\hyperlink{structaes__cbc__mac__ctx_aaa5f06890323184375d275053d6ac2c8}{staging\_block}})) \{}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00134}00134                         \textcolor{comment}{/* We've got a full block */}}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00135}00135                         \mbox{\hyperlink{cbc__mac_8c_ab6f3fc035687f7feefbdd6a4b5bcd92a}{xor\_and\_encrypt}}(ctx, ctx-\/>\mbox{\hyperlink{structaes__cbc__mac__ctx_aaa5f06890323184375d275053d6ac2c8}{staging\_block}}, ctx-\/>\mbox{\hyperlink{structaes__cbc__mac__ctx_af4daf4fbd6aac9888269ac54e7958bc4}{block}});}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00136}00136                         ctx-\/>\mbox{\hyperlink{structaes__cbc__mac__ctx_aca9b789e8120db44db240c29ac5cb8e2}{blockIndex}} = 0;}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00137}00137                 \}}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00138}00138         \}}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00139}00139         \textcolor{keywordflow}{return} (0);}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00140}00140 \}}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00141}00141 }
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00142}00142 \textcolor{keywordtype}{void}}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00143}\mbox{\hyperlink{cbc__mac_8c_a2e3529780c92bbf81d9229f95f5c0e13}{00143}} \mbox{\hyperlink{cbc__mac_8c_a2e3529780c92bbf81d9229f95f5c0e13}{AES\_CBC\_MAC\_Final}}(uint8\_t *buf, \textcolor{keywordtype}{void} *vctx)}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00144}00144 \{}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00145}00145         \textcolor{keyword}{struct }\mbox{\hyperlink{structaes__cbc__mac__ctx}{aes\_cbc\_mac\_ctx}} *ctx;}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00146}00146         uint8\_t s0[\mbox{\hyperlink{cbc__mac_8h_a93cc12cc210e8f3e682726362cba4573}{CCM\_CBC\_BLOCK\_LEN}}];}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00147}00147 }
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00148}00148         ctx = vctx;}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00149}00149 }
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00150}00150         \textcolor{comment}{/*}}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00151}00151 \textcolor{comment}{         * We first need to check to see if we've got any data}}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00152}00152 \textcolor{comment}{         * left over to encrypt.}}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00153}00153 \textcolor{comment}{         */}}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00154}00154         \textcolor{keywordflow}{if} (ctx-\/>\mbox{\hyperlink{structaes__cbc__mac__ctx_aca9b789e8120db44db240c29ac5cb8e2}{blockIndex}} != 0) \{}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00155}00155                 memset(ctx-\/>\mbox{\hyperlink{structaes__cbc__mac__ctx_aaa5f06890323184375d275053d6ac2c8}{staging\_block}} + ctx-\/>\mbox{\hyperlink{structaes__cbc__mac__ctx_aca9b789e8120db44db240c29ac5cb8e2}{blockIndex}}, 0,}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00156}00156                     \mbox{\hyperlink{cbc__mac_8h_a93cc12cc210e8f3e682726362cba4573}{CCM\_CBC\_BLOCK\_LEN}} -\/ ctx-\/>\mbox{\hyperlink{structaes__cbc__mac__ctx_aca9b789e8120db44db240c29ac5cb8e2}{blockIndex}});}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00157}00157                 \mbox{\hyperlink{cbc__mac_8c_ab6f3fc035687f7feefbdd6a4b5bcd92a}{xor\_and\_encrypt}}(ctx, ctx-\/>\mbox{\hyperlink{structaes__cbc__mac__ctx_aaa5f06890323184375d275053d6ac2c8}{staging\_block}}, ctx-\/>\mbox{\hyperlink{structaes__cbc__mac__ctx_af4daf4fbd6aac9888269ac54e7958bc4}{block}});}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00158}00158         \}}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00159}00159         explicit\_bzero(ctx-\/>\mbox{\hyperlink{structaes__cbc__mac__ctx_aaa5f06890323184375d275053d6ac2c8}{staging\_block}}, \textcolor{keyword}{sizeof}(ctx-\/>\mbox{\hyperlink{structaes__cbc__mac__ctx_aaa5f06890323184375d275053d6ac2c8}{staging\_block}}));}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00160}00160 }
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00161}00161         bzero(s0, \textcolor{keyword}{sizeof}(s0));}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00162}00162         s0[0] = (15 -\/ ctx-\/>\mbox{\hyperlink{structaes__cbc__mac__ctx_a2a05a43ca920c9a10d81a8cef44d240c}{nonceLength}}) -\/ 1;}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00163}00163         bcopy(ctx-\/>\mbox{\hyperlink{structaes__cbc__mac__ctx_a5154c0f097df9184a446a1c25d7ec63a}{nonce}}, s0 + 1, ctx-\/>\mbox{\hyperlink{structaes__cbc__mac__ctx_a2a05a43ca920c9a10d81a8cef44d240c}{nonceLength}});}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00164}00164         rijndaelEncrypt(ctx-\/>\mbox{\hyperlink{structaes__cbc__mac__ctx_a134a2b899c7bed15794dffbc37bc436f}{keysched}}, ctx-\/>\mbox{\hyperlink{structaes__cbc__mac__ctx_ab35eacc1a7c5ebf06a061c32c13ae485}{rounds}}, s0, s0);}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00165}00165         \textcolor{keywordflow}{for} (\textcolor{keywordtype}{size\_t} indx = 0; indx < \mbox{\hyperlink{cryptodev_8h_ac2ae88aad7e64defa5f4f33f9befcbe8}{AES\_CBC\_MAC\_HASH\_LEN}}; indx++)}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00166}00166                 buf[indx] = ctx-\/>\mbox{\hyperlink{structaes__cbc__mac__ctx_af4daf4fbd6aac9888269ac54e7958bc4}{block}}[indx] \string^ s0[indx];}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00167}00167         explicit\_bzero(s0, \textcolor{keyword}{sizeof}(s0));}
\DoxyCodeLine{\Hypertarget{cbc__mac_8c_source_l00168}00168 \}}

\end{DoxyCode}
