\doxysection{src/gsm/kdf/sha256-\/internal.c File Reference}
\label{sha256-internal_8c}\index{src/gsm/kdf/sha256-\/internal.c@{src/gsm/kdf/sha256-\/internal.c}}
{\ttfamily \#include \char`\"{}common.\+h\char`\"{}}\newline
{\ttfamily \#include \char`\"{}sha256.\+h\char`\"{}}\newline
{\ttfamily \#include \char`\"{}sha256\+\_\+i.\+h\char`\"{}}\newline
{\ttfamily \#include \char`\"{}crypto.\+h\char`\"{}}\newline
\doxysubsection*{Macros}
\begin{DoxyCompactItemize}
\item 
\#define \textbf{ RORc}(\textbf{ x},  y)
\item 
\#define \textbf{ Ch}(\textbf{ x},  y,  z)~(z $^\wedge$ (\textbf{ x} \& (y $^\wedge$ z)))
\item 
\#define \textbf{ Maj}(\textbf{ x},  y,  z)~(((\textbf{ x} $\vert$ y) \& z) $\vert$ (\textbf{ x} \& y))
\item 
\#define \textbf{ S}(\textbf{ x},  \textbf{ n})~\textbf{ RORc}((\textbf{ x}), (\textbf{ n}))
\item 
\#define \textbf{ R}(\textbf{ x},  \textbf{ n})~(((\textbf{ x})\&0x\+FFFFFFFFUL)$>$$>$(\textbf{ n}))
\item 
\#define \textbf{ Sigma0}(\textbf{ x})~(\textbf{ S}(\textbf{ x}, 2) $^\wedge$ \textbf{ S}(\textbf{ x}, 13) $^\wedge$ \textbf{ S}(\textbf{ x}, 22))
\item 
\#define \textbf{ Sigma1}(\textbf{ x})~(\textbf{ S}(\textbf{ x}, 6) $^\wedge$ \textbf{ S}(\textbf{ x}, 11) $^\wedge$ \textbf{ S}(\textbf{ x}, 25))
\item 
\#define \textbf{ Gamma0}(\textbf{ x})~(\textbf{ S}(\textbf{ x}, 7) $^\wedge$ \textbf{ S}(\textbf{ x}, 18) $^\wedge$ \textbf{ R}(\textbf{ x}, 3))
\item 
\#define \textbf{ Gamma1}(\textbf{ x})~(\textbf{ S}(\textbf{ x}, 17) $^\wedge$ \textbf{ S}(\textbf{ x}, 19) $^\wedge$ \textbf{ R}(\textbf{ x}, 10))
\item 
\#define \textbf{ MIN}(\textbf{ x},  y)~(((\textbf{ x}) $<$ (y)) ? (\textbf{ x}) \+: (y))
\item 
\#define \textbf{ RND}(a,  b,  \textbf{ c},  d,  e,  f,  \textbf{ g},  \textbf{ h},  i)
\end{DoxyCompactItemize}
\doxysubsection*{Functions}
\begin{DoxyCompactItemize}
\item 
int \textbf{ sha256\+\_\+vector} (size\+\_\+t num\+\_\+elem, const \textbf{ u8} $\ast$addr[$\,$], const size\+\_\+t $\ast$\textbf{ len}, \textbf{ u8} $\ast$mac)
\begin{DoxyCompactList}\small\item\em sha256\+\_\+vector -\/ SHA256 hash for data vector @num\+\_\+elem\+: Number of elements in the data vector @addr\+: Pointers to the data areas @len\+: Lengths of the data blocks @mac\+: Buffer for the hash Returns\+: 0 on success, -\/1 of failure \end{DoxyCompactList}\item 
static int \textbf{ sha256\+\_\+compress} (struct \textbf{ sha256\+\_\+state} $\ast$md, unsigned char $\ast$buf)
\item 
void \textbf{ sha256\+\_\+init} (struct \textbf{ sha256\+\_\+state} $\ast$md)
\item 
int \textbf{ sha256\+\_\+process} (struct \textbf{ sha256\+\_\+state} $\ast$md, const unsigned char $\ast$in, unsigned long inlen)
\begin{DoxyCompactList}\small\item\em Process a block of memory though the hash. \end{DoxyCompactList}\item 
int \textbf{ sha256\+\_\+done} (struct \textbf{ sha256\+\_\+state} $\ast$md, unsigned char $\ast$out)
\begin{DoxyCompactList}\small\item\em Terminate the hash to get the digest. \end{DoxyCompactList}\end{DoxyCompactItemize}
\doxysubsection*{Variables}
\begin{DoxyCompactItemize}
\item 
static const unsigned long \textbf{ K} [64]
\end{DoxyCompactItemize}


\doxysubsection{Macro Definition Documentation}
\mbox{\label{sha256-internal_8c_ab0a0d1ad13c7e4d3cb38c89f7127c85a}} 
\index{sha256-\/internal.c@{sha256-\/internal.c}!Ch@{Ch}}
\index{Ch@{Ch}!sha256-\/internal.c@{sha256-\/internal.c}}
\doxysubsubsection{Ch}
{\footnotesize\ttfamily \#define Ch(\begin{DoxyParamCaption}\item[{}]{\textbf{ x},  }\item[{}]{y,  }\item[{}]{z }\end{DoxyParamCaption})~(z $^\wedge$ (\textbf{ x} \& (y $^\wedge$ z)))}

\mbox{\label{sha256-internal_8c_aab39e163b484c43a39b10beda3f6b35f}} 
\index{sha256-\/internal.c@{sha256-\/internal.c}!Gamma0@{Gamma0}}
\index{Gamma0@{Gamma0}!sha256-\/internal.c@{sha256-\/internal.c}}
\doxysubsubsection{Gamma0}
{\footnotesize\ttfamily \#define Gamma0(\begin{DoxyParamCaption}\item[{}]{\textbf{ x} }\end{DoxyParamCaption})~(\textbf{ S}(\textbf{ x}, 7) $^\wedge$ \textbf{ S}(\textbf{ x}, 18) $^\wedge$ \textbf{ R}(\textbf{ x}, 3))}

\mbox{\label{sha256-internal_8c_acd7a8e9e37c472f0a570c8c3e7d553ca}} 
\index{sha256-\/internal.c@{sha256-\/internal.c}!Gamma1@{Gamma1}}
\index{Gamma1@{Gamma1}!sha256-\/internal.c@{sha256-\/internal.c}}
\doxysubsubsection{Gamma1}
{\footnotesize\ttfamily \#define Gamma1(\begin{DoxyParamCaption}\item[{}]{\textbf{ x} }\end{DoxyParamCaption})~(\textbf{ S}(\textbf{ x}, 17) $^\wedge$ \textbf{ S}(\textbf{ x}, 19) $^\wedge$ \textbf{ R}(\textbf{ x}, 10))}

\mbox{\label{sha256-internal_8c_a447cd1d7fb703b62666400976be24bf3}} 
\index{sha256-\/internal.c@{sha256-\/internal.c}!Maj@{Maj}}
\index{Maj@{Maj}!sha256-\/internal.c@{sha256-\/internal.c}}
\doxysubsubsection{Maj}
{\footnotesize\ttfamily \#define Maj(\begin{DoxyParamCaption}\item[{}]{\textbf{ x},  }\item[{}]{y,  }\item[{}]{z }\end{DoxyParamCaption})~(((\textbf{ x} $\vert$ y) \& z) $\vert$ (\textbf{ x} \& y))}

\mbox{\label{sha256-internal_8c_a74e75242132eaabbc1c512488a135926}} 
\index{sha256-\/internal.c@{sha256-\/internal.c}!MIN@{MIN}}
\index{MIN@{MIN}!sha256-\/internal.c@{sha256-\/internal.c}}
\doxysubsubsection{MIN}
{\footnotesize\ttfamily \#define MIN(\begin{DoxyParamCaption}\item[{}]{\textbf{ x},  }\item[{}]{y }\end{DoxyParamCaption})~(((\textbf{ x}) $<$ (y)) ? (\textbf{ x}) \+: (y))}

\mbox{\label{sha256-internal_8c_a8fb1dfc3ad6dd07bc99c1962e6583087}} 
\index{sha256-\/internal.c@{sha256-\/internal.c}!R@{R}}
\index{R@{R}!sha256-\/internal.c@{sha256-\/internal.c}}
\doxysubsubsection{R}
{\footnotesize\ttfamily \#define R(\begin{DoxyParamCaption}\item[{}]{\textbf{ x},  }\item[{}]{\textbf{ n} }\end{DoxyParamCaption})~(((\textbf{ x})\&0x\+FFFFFFFFUL)$>$$>$(\textbf{ n}))}

\mbox{\label{sha256-internal_8c_a14b75d9ce98c82d21041eba16021cba7}} 
\index{sha256-\/internal.c@{sha256-\/internal.c}!RND@{RND}}
\index{RND@{RND}!sha256-\/internal.c@{sha256-\/internal.c}}
\doxysubsubsection{RND}
{\footnotesize\ttfamily \#define RND(\begin{DoxyParamCaption}\item[{}]{a,  }\item[{}]{b,  }\item[{}]{\textbf{ c},  }\item[{}]{d,  }\item[{}]{e,  }\item[{}]{f,  }\item[{}]{\textbf{ g},  }\item[{}]{\textbf{ h},  }\item[{}]{i }\end{DoxyParamCaption})}

{\bfseries Value\+:}
\begin{DoxyCode}{0}
\DoxyCodeLine{        t0 = h + Sigma1(e) + Ch(e, f, g) + K[i] + W[i];      \(\backslash\)}
\DoxyCodeLine{        t1 = Sigma0(a) + Maj(a, b, c);                        \(\backslash\)}
\DoxyCodeLine{        d += t0;                                        \(\backslash\)}
\DoxyCodeLine{        h  = t0 + t1;}

\end{DoxyCode}
\mbox{\label{sha256-internal_8c_adb04fb3f7c1736d29125ad0f179b1068}} 
\index{sha256-\/internal.c@{sha256-\/internal.c}!RORc@{RORc}}
\index{RORc@{RORc}!sha256-\/internal.c@{sha256-\/internal.c}}
\doxysubsubsection{RORc}
{\footnotesize\ttfamily \#define RORc(\begin{DoxyParamCaption}\item[{}]{\textbf{ x},  }\item[{}]{y }\end{DoxyParamCaption})}

{\bfseries Value\+:}
\begin{DoxyCode}{0}
\DoxyCodeLine{( ((((\textcolor{keywordtype}{unsigned} long) (x) \& 0xFFFFFFFFUL) >> (\textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{long}) ((y) \& 31)) | \(\backslash\)}
\DoxyCodeLine{   ((\textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{long}) (x) << (\textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{long}) (32 -\/ ((y) \& 31)))) \& 0xFFFFFFFFUL)}

\end{DoxyCode}
\mbox{\label{sha256-internal_8c_a5a9675d71aad8449f8e4112ce611fd93}} 
\index{sha256-\/internal.c@{sha256-\/internal.c}!S@{S}}
\index{S@{S}!sha256-\/internal.c@{sha256-\/internal.c}}
\doxysubsubsection{S}
{\footnotesize\ttfamily \#define S(\begin{DoxyParamCaption}\item[{}]{\textbf{ x},  }\item[{}]{\textbf{ n} }\end{DoxyParamCaption})~\textbf{ RORc}((\textbf{ x}), (\textbf{ n}))}

\mbox{\label{sha256-internal_8c_a613f88ad88919b6ed21ff223070f9a21}} 
\index{sha256-\/internal.c@{sha256-\/internal.c}!Sigma0@{Sigma0}}
\index{Sigma0@{Sigma0}!sha256-\/internal.c@{sha256-\/internal.c}}
\doxysubsubsection{Sigma0}
{\footnotesize\ttfamily \#define Sigma0(\begin{DoxyParamCaption}\item[{}]{\textbf{ x} }\end{DoxyParamCaption})~(\textbf{ S}(\textbf{ x}, 2) $^\wedge$ \textbf{ S}(\textbf{ x}, 13) $^\wedge$ \textbf{ S}(\textbf{ x}, 22))}

\mbox{\label{sha256-internal_8c_a6d34508d6d962274083fcd992fb4e340}} 
\index{sha256-\/internal.c@{sha256-\/internal.c}!Sigma1@{Sigma1}}
\index{Sigma1@{Sigma1}!sha256-\/internal.c@{sha256-\/internal.c}}
\doxysubsubsection{Sigma1}
{\footnotesize\ttfamily \#define Sigma1(\begin{DoxyParamCaption}\item[{}]{\textbf{ x} }\end{DoxyParamCaption})~(\textbf{ S}(\textbf{ x}, 6) $^\wedge$ \textbf{ S}(\textbf{ x}, 11) $^\wedge$ \textbf{ S}(\textbf{ x}, 25))}



\doxysubsection{Function Documentation}
\mbox{\label{sha256-internal_8c_acbd2b3c13cc2d0f5141340d9f75bc86f}} 
\index{sha256-\/internal.c@{sha256-\/internal.c}!sha256\_compress@{sha256\_compress}}
\index{sha256\_compress@{sha256\_compress}!sha256-\/internal.c@{sha256-\/internal.c}}
\doxysubsubsection{sha256\_compress()}
{\footnotesize\ttfamily static int sha256\+\_\+compress (\begin{DoxyParamCaption}\item[{struct \textbf{ sha256\+\_\+state} $\ast$}]{md,  }\item[{unsigned char $\ast$}]{buf }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [static]}}



References \textbf{ sha256\+\_\+state\+::buf}, \textbf{ Gamma0}, \textbf{ Gamma1}, \textbf{ RND}, \textbf{ S}, \textbf{ sha256\+\_\+state\+::state}, and \textbf{ WPA\+\_\+\+GET\+\_\+\+BE32}.



Referenced by \textbf{ sha256\+\_\+done()}, and \textbf{ sha256\+\_\+process()}.

\mbox{\label{sha256-internal_8c_a1939416ef1730d4692944ec46da5c396}} 
\index{sha256-\/internal.c@{sha256-\/internal.c}!sha256\_done@{sha256\_done}}
\index{sha256\_done@{sha256\_done}!sha256-\/internal.c@{sha256-\/internal.c}}
\doxysubsubsection{sha256\_done()}
{\footnotesize\ttfamily int sha256\+\_\+done (\begin{DoxyParamCaption}\item[{struct \textbf{ sha256\+\_\+state} $\ast$}]{md,  }\item[{unsigned char $\ast$}]{out }\end{DoxyParamCaption})}



Terminate the hash to get the digest. 


\begin{DoxyParams}{Parameters}
{\em md} & The hash state \\
\hline
{\em out} & [out] The destination of the hash (32 bytes) \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
CRYPT\+\_\+\+OK if successful 
\end{DoxyReturn}


References \textbf{ sha256\+\_\+state\+::buf}, \textbf{ sha256\+\_\+state\+::curlen}, \textbf{ sha256\+\_\+state\+::length}, \textbf{ SHA256\+\_\+\+BLOCK\+\_\+\+SIZE}, \textbf{ sha256\+\_\+compress()}, \textbf{ sha256\+\_\+state\+::state}, \textbf{ WPA\+\_\+\+PUT\+\_\+\+BE32}, and \textbf{ WPA\+\_\+\+PUT\+\_\+\+BE64}.



Referenced by \textbf{ sha256\+\_\+vector()}.

\mbox{\label{sha256-internal_8c_abbad427a9bd58421c2dd49112d8c0410}} 
\index{sha256-\/internal.c@{sha256-\/internal.c}!sha256\_init@{sha256\_init}}
\index{sha256\_init@{sha256\_init}!sha256-\/internal.c@{sha256-\/internal.c}}
\doxysubsubsection{sha256\_init()}
{\footnotesize\ttfamily void sha256\+\_\+init (\begin{DoxyParamCaption}\item[{struct \textbf{ sha256\+\_\+state} $\ast$}]{md }\end{DoxyParamCaption})}



References \textbf{ sha256\+\_\+state\+::curlen}, \textbf{ sha256\+\_\+state\+::length}, and \textbf{ sha256\+\_\+state\+::state}.



Referenced by \textbf{ sha256\+\_\+vector()}.

\mbox{\label{sha256-internal_8c_ae7561631dd1f7860a4f0b300b9b465b7}} 
\index{sha256-\/internal.c@{sha256-\/internal.c}!sha256\_process@{sha256\_process}}
\index{sha256\_process@{sha256\_process}!sha256-\/internal.c@{sha256-\/internal.c}}
\doxysubsubsection{sha256\_process()}
{\footnotesize\ttfamily int sha256\+\_\+process (\begin{DoxyParamCaption}\item[{struct \textbf{ sha256\+\_\+state} $\ast$}]{md,  }\item[{const unsigned char $\ast$}]{in,  }\item[{unsigned long}]{inlen }\end{DoxyParamCaption})}



Process a block of memory though the hash. 


\begin{DoxyParams}{Parameters}
{\em md} & The hash state \\
\hline
{\em in} & The data to hash \\
\hline
{\em inlen} & The length of the data (octets) \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
CRYPT\+\_\+\+OK if successful 
\end{DoxyReturn}


References \textbf{ sha256\+\_\+state\+::buf}, \textbf{ sha256\+\_\+state\+::curlen}, \textbf{ sha256\+\_\+state\+::length}, \textbf{ MIN}, \textbf{ n}, \textbf{ os\+\_\+memcpy}, \textbf{ SHA256\+\_\+\+BLOCK\+\_\+\+SIZE}, and \textbf{ sha256\+\_\+compress()}.



Referenced by \textbf{ sha256\+\_\+vector()}.

\mbox{\label{sha256-internal_8c_a194c5aeed625c760d10e3d1d34cd8a10}} 
\index{sha256-\/internal.c@{sha256-\/internal.c}!sha256\_vector@{sha256\_vector}}
\index{sha256\_vector@{sha256\_vector}!sha256-\/internal.c@{sha256-\/internal.c}}
\doxysubsubsection{sha256\_vector()}
{\footnotesize\ttfamily int sha256\+\_\+vector (\begin{DoxyParamCaption}\item[{size\+\_\+t}]{num\+\_\+elem,  }\item[{const \textbf{ u8} $\ast$}]{addr[$\,$],  }\item[{const size\+\_\+t $\ast$}]{len,  }\item[{\textbf{ u8} $\ast$}]{mac }\end{DoxyParamCaption})}



sha256\+\_\+vector -\/ SHA256 hash for data vector @num\+\_\+elem\+: Number of elements in the data vector @addr\+: Pointers to the data areas @len\+: Lengths of the data blocks @mac\+: Buffer for the hash Returns\+: 0 on success, -\/1 of failure 

sha256\+\_\+vector -\/ SHA256 hash for data vector @num\+\_\+elem\+: Number of elements in the data vector @addr\+: Pointers to the data areas @len\+: Lengths of the data blocks @mac\+: Buffer for the hash Returns\+: 0 on success, -\/1 on failure 

References \textbf{ len}, \textbf{ sha256\+\_\+done()}, \textbf{ sha256\+\_\+init()}, and \textbf{ sha256\+\_\+process()}.



Referenced by \textbf{ hmac\+\_\+sha256\+\_\+vector()}.



\doxysubsection{Variable Documentation}
\mbox{\label{sha256-internal_8c_abb2cc8d3454ac3b0a2c264a1c7ed6db8}} 
\index{sha256-\/internal.c@{sha256-\/internal.c}!K@{K}}
\index{K@{K}!sha256-\/internal.c@{sha256-\/internal.c}}
\doxysubsubsection{K}
{\footnotesize\ttfamily const unsigned long K[64]\hspace{0.3cm}{\ttfamily [static]}}

{\bfseries Initial value\+:}
\begin{DoxyCode}{0}
\DoxyCodeLine{= \{}
\DoxyCodeLine{        0x428a2f98UL, 0x71374491UL, 0xb5c0fbcfUL, 0xe9b5dba5UL, 0x3956c25bUL,}
\DoxyCodeLine{        0x59f111f1UL, 0x923f82a4UL, 0xab1c5ed5UL, 0xd807aa98UL, 0x12835b01UL,}
\DoxyCodeLine{        0x243185beUL, 0x550c7dc3UL, 0x72be5d74UL, 0x80deb1feUL, 0x9bdc06a7UL,}
\DoxyCodeLine{        0xc19bf174UL, 0xe49b69c1UL, 0xefbe4786UL, 0x0fc19dc6UL, 0x240ca1ccUL,}
\DoxyCodeLine{        0x2de92c6fUL, 0x4a7484aaUL, 0x5cb0a9dcUL, 0x76f988daUL, 0x983e5152UL,}
\DoxyCodeLine{        0xa831c66dUL, 0xb00327c8UL, 0xbf597fc7UL, 0xc6e00bf3UL, 0xd5a79147UL,}
\DoxyCodeLine{        0x06ca6351UL, 0x14292967UL, 0x27b70a85UL, 0x2e1b2138UL, 0x4d2c6dfcUL,}
\DoxyCodeLine{        0x53380d13UL, 0x650a7354UL, 0x766a0abbUL, 0x81c2c92eUL, 0x92722c85UL,}
\DoxyCodeLine{        0xa2bfe8a1UL, 0xa81a664bUL, 0xc24b8b70UL, 0xc76c51a3UL, 0xd192e819UL,}
\DoxyCodeLine{        0xd6990624UL, 0xf40e3585UL, 0x106aa070UL, 0x19a4c116UL, 0x1e376c08UL,}
\DoxyCodeLine{        0x2748774cUL, 0x34b0bcb5UL, 0x391c0cb3UL, 0x4ed8aa4aUL, 0x5b9cca4fUL,}
\DoxyCodeLine{        0x682e6ff3UL, 0x748f82eeUL, 0x78a5636fUL, 0x84c87814UL, 0x8cc70208UL,}
\DoxyCodeLine{        0x90befffaUL, 0xa4506cebUL, 0xbef9a3f7UL, 0xc67178f2UL}
\DoxyCodeLine{\}}

\end{DoxyCode}
