\doxysection{GSM A5 ciphering algorithm}
\label{group__a5}\index{GSM A5 ciphering algorithm@{GSM A5 ciphering algorithm}}


Osmocom GSM ciphering algorithm implementation.  


\doxysubsection*{Files}
\begin{DoxyCompactItemize}
\item 
file \textbf{ a5.\+h}
\end{DoxyCompactItemize}
\doxysubsection*{Macros}
\begin{DoxyCompactItemize}
\item 
\#define \textbf{ ENOTSUP}~EINVAL
\item 
\#define \textbf{ A5\+\_\+\+R1\+\_\+\+LEN}~19
\item 
\#define \textbf{ A5\+\_\+\+R2\+\_\+\+LEN}~22
\item 
\#define \textbf{ A5\+\_\+\+R3\+\_\+\+LEN}~23
\item 
\#define \textbf{ A5\+\_\+\+R4\+\_\+\+LEN}~17 /$\ast$ A5/2 only $\ast$/
\item 
\#define \textbf{ A5\+\_\+\+R1\+\_\+\+MASK}~((1$<$$<$\textbf{ A5\+\_\+\+R1\+\_\+\+LEN})-\/1)
\item 
\#define \textbf{ A5\+\_\+\+R2\+\_\+\+MASK}~((1$<$$<$\textbf{ A5\+\_\+\+R2\+\_\+\+LEN})-\/1)
\item 
\#define \textbf{ A5\+\_\+\+R3\+\_\+\+MASK}~((1$<$$<$\textbf{ A5\+\_\+\+R3\+\_\+\+LEN})-\/1)
\item 
\#define \textbf{ A5\+\_\+\+R4\+\_\+\+MASK}~((1$<$$<$\textbf{ A5\+\_\+\+R4\+\_\+\+LEN})-\/1)
\item 
\#define \textbf{ A5\+\_\+\+R1\+\_\+\+TAPS}~0x072000 /$\ast$ x$^\wedge$19 + x$^\wedge$18 + x$^\wedge$17 + x$^\wedge$14 + 1 $\ast$/
\item 
\#define \textbf{ A5\+\_\+\+R2\+\_\+\+TAPS}~0x300000 /$\ast$ x$^\wedge$22 + x$^\wedge$21 + 1 $\ast$/
\item 
\#define \textbf{ A5\+\_\+\+R3\+\_\+\+TAPS}~0x700080 /$\ast$ x$^\wedge$23 + x$^\wedge$22 + x$^\wedge$21 + x$^\wedge$8 + 1 $\ast$/
\item 
\#define \textbf{ A5\+\_\+\+R4\+\_\+\+TAPS}~0x010800 /$\ast$ x$^\wedge$17 + x$^\wedge$12 + 1 $\ast$/
\item 
\#define \textbf{ A51\+\_\+\+R1\+\_\+\+CLKBIT}~0x000100
\item 
\#define \textbf{ A51\+\_\+\+R2\+\_\+\+CLKBIT}~0x000400
\item 
\#define \textbf{ A51\+\_\+\+R3\+\_\+\+CLKBIT}~0x000400
\item 
\#define \textbf{ A52\+\_\+\+R4\+\_\+\+CLKBIT0}~0x000400
\item 
\#define \textbf{ A52\+\_\+\+R4\+\_\+\+CLKBIT1}~0x000008
\item 
\#define \textbf{ A52\+\_\+\+R4\+\_\+\+CLKBIT2}~0x000080
\end{DoxyCompactItemize}
\doxysubsection*{Functions}
\begin{DoxyCompactItemize}
\item 
static uint32\+\_\+t \textbf{ osmo\+\_\+a5\+\_\+fn\+\_\+count} (uint32\+\_\+t fn)
\begin{DoxyCompactList}\small\item\em Converts a frame number into the 22 bit number used in A5/x. \end{DoxyCompactList}\item 
int \textbf{ osmo\+\_\+a5} (int \textbf{ n}, const uint8\+\_\+t $\ast$key, uint32\+\_\+t fn, \textbf{ ubit\+\_\+t} $\ast$dl, \textbf{ ubit\+\_\+t} $\ast$ul)
\begin{DoxyCompactList}\small\item\em Main method to generate a A5/x cipher stream. \end{DoxyCompactList}\item 
void \textbf{ osmo\+\_\+a5\+\_\+1} (const uint8\+\_\+t $\ast$key, uint32\+\_\+t fn, \textbf{ ubit\+\_\+t} $\ast$dl, \textbf{ ubit\+\_\+t} $\ast$ul) \textbf{ OSMO\+\_\+\+DEPRECATED}(\char`\"{}Use generic \textbf{ osmo\+\_\+a5}() \textbf{ instead}\char`\"{})
\item 
void \textbf{ osmo\+\_\+a5\+\_\+2} (const uint8\+\_\+t $\ast$key, uint32\+\_\+t fn, \textbf{ ubit\+\_\+t} $\ast$dl, \textbf{ ubit\+\_\+t} $\ast$ul) \textbf{ OSMO\+\_\+\+DEPRECATED}(\char`\"{}Use generic \textbf{ osmo\+\_\+a5}() \textbf{ instead}\char`\"{})
\item 
void \textbf{ \+\_\+a5\+\_\+4} (const uint8\+\_\+t $\ast$ck, uint32\+\_\+t fn, \textbf{ ubit\+\_\+t} $\ast$dl, \textbf{ ubit\+\_\+t} $\ast$ul, bool fn\+\_\+correct)
\begin{DoxyCompactList}\small\item\em Generate a GSM A5/4 cipher stream. \end{DoxyCompactList}\item 
void \textbf{ \+\_\+a5\+\_\+3} (const uint8\+\_\+t $\ast$key, uint32\+\_\+t fn, \textbf{ ubit\+\_\+t} $\ast$dl, \textbf{ ubit\+\_\+t} $\ast$ul, bool fn\+\_\+correct)
\begin{DoxyCompactList}\small\item\em Generate a GSM A5/3 cipher stream. \end{DoxyCompactList}\item 
static uint32\+\_\+t \textbf{ \+\_\+a5\+\_\+12\+\_\+parity} (uint32\+\_\+t x)
\begin{DoxyCompactList}\small\item\em Computes parity of a 32-\/bit word. \end{DoxyCompactList}\item 
static uint32\+\_\+t \textbf{ \+\_\+a5\+\_\+12\+\_\+majority} (uint32\+\_\+t v1, uint32\+\_\+t v2, uint32\+\_\+t v3)
\begin{DoxyCompactList}\small\item\em Compute majority bit from 3 taps. \end{DoxyCompactList}\item 
static uint32\+\_\+t \textbf{ \+\_\+a5\+\_\+12\+\_\+clock} (uint32\+\_\+t r, uint32\+\_\+t mask, uint32\+\_\+t taps)
\begin{DoxyCompactList}\small\item\em Compute the next LFSR state. \end{DoxyCompactList}\item 
static void \textbf{ \+\_\+a5\+\_\+1\+\_\+clock} (uint32\+\_\+t r[$\,$], int force)
\begin{DoxyCompactList}\small\item\em GSM A5/1 Clocking function. \end{DoxyCompactList}\item 
static uint8\+\_\+t \textbf{ \+\_\+a5\+\_\+1\+\_\+get\+\_\+output} (uint32\+\_\+t r[$\,$])
\begin{DoxyCompactList}\small\item\em GSM A5/1 Output function. \end{DoxyCompactList}\item 
void \textbf{ \+\_\+a5\+\_\+1} (const uint8\+\_\+t $\ast$key, uint32\+\_\+t fn, \textbf{ ubit\+\_\+t} $\ast$dl, \textbf{ ubit\+\_\+t} $\ast$ul)
\begin{DoxyCompactList}\small\item\em Generate a GSM A5/1 cipher stream. \end{DoxyCompactList}\item 
static void \textbf{ \+\_\+a5\+\_\+2\+\_\+clock} (uint32\+\_\+t r[$\,$], int force)
\begin{DoxyCompactList}\small\item\em GSM A5/2 Clocking function. \end{DoxyCompactList}\item 
static uint8\+\_\+t \textbf{ \+\_\+a5\+\_\+2\+\_\+get\+\_\+output} (uint32\+\_\+t r[$\,$])
\begin{DoxyCompactList}\small\item\em GSM A5/2 Output function. \end{DoxyCompactList}\item 
void \textbf{ \+\_\+a5\+\_\+2} (const uint8\+\_\+t $\ast$key, uint32\+\_\+t fn, \textbf{ ubit\+\_\+t} $\ast$dl, \textbf{ ubit\+\_\+t} $\ast$ul)
\begin{DoxyCompactList}\small\item\em Generate a GSM A5/1 cipher stream. \end{DoxyCompactList}\end{DoxyCompactItemize}


\doxysubsection{Detailed Description}
Osmocom GSM ciphering algorithm implementation. 

Full reimplementation of A5/1,2,3,4 (split and threadsafe).

The logic behind the algorithm is taken from \char`\"{}\+A pedagogical implementation of the GSM A5/1 and A5/2 \char`\"{}voice privacy\char`\"{} encryption algorithms.\char`\"{} by Marc Briceno, Ian Goldberg, and David Wagner. 

\doxysubsection{Macro Definition Documentation}
\mbox{\label{group__a5_ga9c7f4f2fdbd277855006b6df0af83f46}} 
\index{GSM A5 ciphering algorithm@{GSM A5 ciphering algorithm}!A51\_R1\_CLKBIT@{A51\_R1\_CLKBIT}}
\index{A51\_R1\_CLKBIT@{A51\_R1\_CLKBIT}!GSM A5 ciphering algorithm@{GSM A5 ciphering algorithm}}
\doxysubsubsection{A51\_R1\_CLKBIT}
{\footnotesize\ttfamily \#define A51\+\_\+\+R1\+\_\+\+CLKBIT~0x000100}

\mbox{\label{group__a5_ga67e1de46368a11a176edd0fd6be99f42}} 
\index{GSM A5 ciphering algorithm@{GSM A5 ciphering algorithm}!A51\_R2\_CLKBIT@{A51\_R2\_CLKBIT}}
\index{A51\_R2\_CLKBIT@{A51\_R2\_CLKBIT}!GSM A5 ciphering algorithm@{GSM A5 ciphering algorithm}}
\doxysubsubsection{A51\_R2\_CLKBIT}
{\footnotesize\ttfamily \#define A51\+\_\+\+R2\+\_\+\+CLKBIT~0x000400}

\mbox{\label{group__a5_ga1f331f4829ed93ad89f2865a754ae85c}} 
\index{GSM A5 ciphering algorithm@{GSM A5 ciphering algorithm}!A51\_R3\_CLKBIT@{A51\_R3\_CLKBIT}}
\index{A51\_R3\_CLKBIT@{A51\_R3\_CLKBIT}!GSM A5 ciphering algorithm@{GSM A5 ciphering algorithm}}
\doxysubsubsection{A51\_R3\_CLKBIT}
{\footnotesize\ttfamily \#define A51\+\_\+\+R3\+\_\+\+CLKBIT~0x000400}

\mbox{\label{group__a5_gaad85feeb6789e1520d4ed2afabd2cdcc}} 
\index{GSM A5 ciphering algorithm@{GSM A5 ciphering algorithm}!A52\_R4\_CLKBIT0@{A52\_R4\_CLKBIT0}}
\index{A52\_R4\_CLKBIT0@{A52\_R4\_CLKBIT0}!GSM A5 ciphering algorithm@{GSM A5 ciphering algorithm}}
\doxysubsubsection{A52\_R4\_CLKBIT0}
{\footnotesize\ttfamily \#define A52\+\_\+\+R4\+\_\+\+CLKBIT0~0x000400}

\mbox{\label{group__a5_ga6a23a2d40db1e29918e2295f55c6535e}} 
\index{GSM A5 ciphering algorithm@{GSM A5 ciphering algorithm}!A52\_R4\_CLKBIT1@{A52\_R4\_CLKBIT1}}
\index{A52\_R4\_CLKBIT1@{A52\_R4\_CLKBIT1}!GSM A5 ciphering algorithm@{GSM A5 ciphering algorithm}}
\doxysubsubsection{A52\_R4\_CLKBIT1}
{\footnotesize\ttfamily \#define A52\+\_\+\+R4\+\_\+\+CLKBIT1~0x000008}

\mbox{\label{group__a5_gaf73f036a0f44f997cd3ca9305718959a}} 
\index{GSM A5 ciphering algorithm@{GSM A5 ciphering algorithm}!A52\_R4\_CLKBIT2@{A52\_R4\_CLKBIT2}}
\index{A52\_R4\_CLKBIT2@{A52\_R4\_CLKBIT2}!GSM A5 ciphering algorithm@{GSM A5 ciphering algorithm}}
\doxysubsubsection{A52\_R4\_CLKBIT2}
{\footnotesize\ttfamily \#define A52\+\_\+\+R4\+\_\+\+CLKBIT2~0x000080}

\mbox{\label{group__a5_gadb6d00269adbd486aafd769188c5028d}} 
\index{GSM A5 ciphering algorithm@{GSM A5 ciphering algorithm}!A5\_R1\_LEN@{A5\_R1\_LEN}}
\index{A5\_R1\_LEN@{A5\_R1\_LEN}!GSM A5 ciphering algorithm@{GSM A5 ciphering algorithm}}
\doxysubsubsection{A5\_R1\_LEN}
{\footnotesize\ttfamily \#define A5\+\_\+\+R1\+\_\+\+LEN~19}

\mbox{\label{group__a5_ga2e6ce330ec39c7298200dee67cd7ab80}} 
\index{GSM A5 ciphering algorithm@{GSM A5 ciphering algorithm}!A5\_R1\_MASK@{A5\_R1\_MASK}}
\index{A5\_R1\_MASK@{A5\_R1\_MASK}!GSM A5 ciphering algorithm@{GSM A5 ciphering algorithm}}
\doxysubsubsection{A5\_R1\_MASK}
{\footnotesize\ttfamily \#define A5\+\_\+\+R1\+\_\+\+MASK~((1$<$$<$\textbf{ A5\+\_\+\+R1\+\_\+\+LEN})-\/1)}

\mbox{\label{group__a5_ga54cd8f895e6dcf1c579b590bca416fef}} 
\index{GSM A5 ciphering algorithm@{GSM A5 ciphering algorithm}!A5\_R1\_TAPS@{A5\_R1\_TAPS}}
\index{A5\_R1\_TAPS@{A5\_R1\_TAPS}!GSM A5 ciphering algorithm@{GSM A5 ciphering algorithm}}
\doxysubsubsection{A5\_R1\_TAPS}
{\footnotesize\ttfamily \#define A5\+\_\+\+R1\+\_\+\+TAPS~0x072000 /$\ast$ x$^\wedge$19 + x$^\wedge$18 + x$^\wedge$17 + x$^\wedge$14 + 1 $\ast$/}

\mbox{\label{group__a5_gad6c0ca79e9c6bcaa1984af1408c87f4e}} 
\index{GSM A5 ciphering algorithm@{GSM A5 ciphering algorithm}!A5\_R2\_LEN@{A5\_R2\_LEN}}
\index{A5\_R2\_LEN@{A5\_R2\_LEN}!GSM A5 ciphering algorithm@{GSM A5 ciphering algorithm}}
\doxysubsubsection{A5\_R2\_LEN}
{\footnotesize\ttfamily \#define A5\+\_\+\+R2\+\_\+\+LEN~22}

\mbox{\label{group__a5_gaf7ad4468322253449bca053f5dfdd675}} 
\index{GSM A5 ciphering algorithm@{GSM A5 ciphering algorithm}!A5\_R2\_MASK@{A5\_R2\_MASK}}
\index{A5\_R2\_MASK@{A5\_R2\_MASK}!GSM A5 ciphering algorithm@{GSM A5 ciphering algorithm}}
\doxysubsubsection{A5\_R2\_MASK}
{\footnotesize\ttfamily \#define A5\+\_\+\+R2\+\_\+\+MASK~((1$<$$<$\textbf{ A5\+\_\+\+R2\+\_\+\+LEN})-\/1)}

\mbox{\label{group__a5_gad035040318cb713b3b4ccc8aab4f4d93}} 
\index{GSM A5 ciphering algorithm@{GSM A5 ciphering algorithm}!A5\_R2\_TAPS@{A5\_R2\_TAPS}}
\index{A5\_R2\_TAPS@{A5\_R2\_TAPS}!GSM A5 ciphering algorithm@{GSM A5 ciphering algorithm}}
\doxysubsubsection{A5\_R2\_TAPS}
{\footnotesize\ttfamily \#define A5\+\_\+\+R2\+\_\+\+TAPS~0x300000 /$\ast$ x$^\wedge$22 + x$^\wedge$21 + 1 $\ast$/}

\mbox{\label{group__a5_ga034965c5e9599b493f7f7b5d7077800e}} 
\index{GSM A5 ciphering algorithm@{GSM A5 ciphering algorithm}!A5\_R3\_LEN@{A5\_R3\_LEN}}
\index{A5\_R3\_LEN@{A5\_R3\_LEN}!GSM A5 ciphering algorithm@{GSM A5 ciphering algorithm}}
\doxysubsubsection{A5\_R3\_LEN}
{\footnotesize\ttfamily \#define A5\+\_\+\+R3\+\_\+\+LEN~23}

\mbox{\label{group__a5_ga7465a3442936aff5481993b9d28e7238}} 
\index{GSM A5 ciphering algorithm@{GSM A5 ciphering algorithm}!A5\_R3\_MASK@{A5\_R3\_MASK}}
\index{A5\_R3\_MASK@{A5\_R3\_MASK}!GSM A5 ciphering algorithm@{GSM A5 ciphering algorithm}}
\doxysubsubsection{A5\_R3\_MASK}
{\footnotesize\ttfamily \#define A5\+\_\+\+R3\+\_\+\+MASK~((1$<$$<$\textbf{ A5\+\_\+\+R3\+\_\+\+LEN})-\/1)}

\mbox{\label{group__a5_gac88656395ea81cdada3a5eabf073314a}} 
\index{GSM A5 ciphering algorithm@{GSM A5 ciphering algorithm}!A5\_R3\_TAPS@{A5\_R3\_TAPS}}
\index{A5\_R3\_TAPS@{A5\_R3\_TAPS}!GSM A5 ciphering algorithm@{GSM A5 ciphering algorithm}}
\doxysubsubsection{A5\_R3\_TAPS}
{\footnotesize\ttfamily \#define A5\+\_\+\+R3\+\_\+\+TAPS~0x700080 /$\ast$ x$^\wedge$23 + x$^\wedge$22 + x$^\wedge$21 + x$^\wedge$8 + 1 $\ast$/}

\mbox{\label{group__a5_ga89cf4178358eb1f1abd1a905fab1fb65}} 
\index{GSM A5 ciphering algorithm@{GSM A5 ciphering algorithm}!A5\_R4\_LEN@{A5\_R4\_LEN}}
\index{A5\_R4\_LEN@{A5\_R4\_LEN}!GSM A5 ciphering algorithm@{GSM A5 ciphering algorithm}}
\doxysubsubsection{A5\_R4\_LEN}
{\footnotesize\ttfamily \#define A5\+\_\+\+R4\+\_\+\+LEN~17 /$\ast$ A5/2 only $\ast$/}

\mbox{\label{group__a5_ga380c7c90ad62eba2c3e4273a9f2aeb18}} 
\index{GSM A5 ciphering algorithm@{GSM A5 ciphering algorithm}!A5\_R4\_MASK@{A5\_R4\_MASK}}
\index{A5\_R4\_MASK@{A5\_R4\_MASK}!GSM A5 ciphering algorithm@{GSM A5 ciphering algorithm}}
\doxysubsubsection{A5\_R4\_MASK}
{\footnotesize\ttfamily \#define A5\+\_\+\+R4\+\_\+\+MASK~((1$<$$<$\textbf{ A5\+\_\+\+R4\+\_\+\+LEN})-\/1)}

\mbox{\label{group__a5_ga934a373597a8f373a78d244f0728b562}} 
\index{GSM A5 ciphering algorithm@{GSM A5 ciphering algorithm}!A5\_R4\_TAPS@{A5\_R4\_TAPS}}
\index{A5\_R4\_TAPS@{A5\_R4\_TAPS}!GSM A5 ciphering algorithm@{GSM A5 ciphering algorithm}}
\doxysubsubsection{A5\_R4\_TAPS}
{\footnotesize\ttfamily \#define A5\+\_\+\+R4\+\_\+\+TAPS~0x010800 /$\ast$ x$^\wedge$17 + x$^\wedge$12 + 1 $\ast$/}

\mbox{\label{group__a5_ga91457bbf35f0f1085619a99423bb1f33}} 
\index{GSM A5 ciphering algorithm@{GSM A5 ciphering algorithm}!ENOTSUP@{ENOTSUP}}
\index{ENOTSUP@{ENOTSUP}!GSM A5 ciphering algorithm@{GSM A5 ciphering algorithm}}
\doxysubsubsection{ENOTSUP}
{\footnotesize\ttfamily \#define ENOTSUP~EINVAL}



\doxysubsection{Function Documentation}
\mbox{\label{group__a5_ga1fa3ceb5aa7339737aeab03db7ae74db}} 
\index{GSM A5 ciphering algorithm@{GSM A5 ciphering algorithm}!\_a5\_1@{\_a5\_1}}
\index{\_a5\_1@{\_a5\_1}!GSM A5 ciphering algorithm@{GSM A5 ciphering algorithm}}
\doxysubsubsection{\_a5\_1()}
{\footnotesize\ttfamily void \+\_\+a5\+\_\+1 (\begin{DoxyParamCaption}\item[{const uint8\+\_\+t $\ast$}]{key,  }\item[{uint32\+\_\+t}]{fn,  }\item[{\textbf{ ubit\+\_\+t} $\ast$}]{dl,  }\item[{\textbf{ ubit\+\_\+t} $\ast$}]{ul }\end{DoxyParamCaption})}



Generate a GSM A5/1 cipher stream. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em key} & 8 byte array for the key (as received from the SIM) \\
\hline
\mbox{\texttt{ in}}  & {\em fn} & Frame number \\
\hline
\mbox{\texttt{ out}}  & {\em dl} & Pointer to array of ubits to return Downlink cipher stream \\
\hline
\mbox{\texttt{ out}}  & {\em ul} & Pointer to array of ubits to return Uplink cipher stream\\
\hline
\end{DoxyParams}
Either (or both) of dl/ul can be NULL if not needed. 

References \textbf{ \+\_\+a5\+\_\+1\+\_\+clock()}, \textbf{ \+\_\+a5\+\_\+1\+\_\+get\+\_\+output()}, and \textbf{ osmo\+\_\+a5\+\_\+fn\+\_\+count()}.



Referenced by \textbf{ osmo\+\_\+a5()}.

\mbox{\label{group__a5_ga79fe3aa16d75aa56c9e9f24f95a1491d}} 
\index{GSM A5 ciphering algorithm@{GSM A5 ciphering algorithm}!\_a5\_12\_clock@{\_a5\_12\_clock}}
\index{\_a5\_12\_clock@{\_a5\_12\_clock}!GSM A5 ciphering algorithm@{GSM A5 ciphering algorithm}}
\doxysubsubsection{\_a5\_12\_clock()}
{\footnotesize\ttfamily static uint32\+\_\+t \+\_\+a5\+\_\+12\+\_\+clock (\begin{DoxyParamCaption}\item[{uint32\+\_\+t}]{r,  }\item[{uint32\+\_\+t}]{mask,  }\item[{uint32\+\_\+t}]{taps }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [inline]}, {\ttfamily [static]}}



Compute the next LFSR state. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em r} & Current state \\
\hline
\mbox{\texttt{ in}}  & {\em mask} & LFSR mask \\
\hline
\mbox{\texttt{ in}}  & {\em taps} & LFSR taps \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
Next state 
\end{DoxyReturn}


References \textbf{ \+\_\+a5\+\_\+12\+\_\+parity()}.



Referenced by \textbf{ \+\_\+a5\+\_\+1\+\_\+clock()}, and \textbf{ \+\_\+a5\+\_\+2\+\_\+clock()}.

\mbox{\label{group__a5_ga92520572bdf7231dbc717c3a959509b3}} 
\index{GSM A5 ciphering algorithm@{GSM A5 ciphering algorithm}!\_a5\_12\_majority@{\_a5\_12\_majority}}
\index{\_a5\_12\_majority@{\_a5\_12\_majority}!GSM A5 ciphering algorithm@{GSM A5 ciphering algorithm}}
\doxysubsubsection{\_a5\_12\_majority()}
{\footnotesize\ttfamily static uint32\+\_\+t \+\_\+a5\+\_\+12\+\_\+majority (\begin{DoxyParamCaption}\item[{uint32\+\_\+t}]{v1,  }\item[{uint32\+\_\+t}]{v2,  }\item[{uint32\+\_\+t}]{v3 }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [inline]}, {\ttfamily [static]}}



Compute majority bit from 3 taps. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em v1} & LFSR state ANDed with tap-\/bit \\
\hline
\mbox{\texttt{ in}}  & {\em v2} & LFSR state ANDed with tap-\/bit \\
\hline
\mbox{\texttt{ in}}  & {\em v3} & LFSR state ANDed with tap-\/bit \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
The majority bit (0 or 1) 
\end{DoxyReturn}


Referenced by \textbf{ \+\_\+a5\+\_\+1\+\_\+clock()}, and \textbf{ \+\_\+a5\+\_\+2\+\_\+get\+\_\+output()}.

\mbox{\label{group__a5_ga5b05652d125561e04459f3506dd81550}} 
\index{GSM A5 ciphering algorithm@{GSM A5 ciphering algorithm}!\_a5\_12\_parity@{\_a5\_12\_parity}}
\index{\_a5\_12\_parity@{\_a5\_12\_parity}!GSM A5 ciphering algorithm@{GSM A5 ciphering algorithm}}
\doxysubsubsection{\_a5\_12\_parity()}
{\footnotesize\ttfamily static uint32\+\_\+t \+\_\+a5\+\_\+12\+\_\+parity (\begin{DoxyParamCaption}\item[{uint32\+\_\+t}]{x }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [inline]}, {\ttfamily [static]}}



Computes parity of a 32-\/bit word. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em x} & 32 bit word \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
Parity bit (xor of all bits) as 0 or 1 
\end{DoxyReturn}


Referenced by \textbf{ \+\_\+a5\+\_\+12\+\_\+clock()}.

\mbox{\label{group__a5_gad6d2841c782f2e65ca458af55e72295f}} 
\index{GSM A5 ciphering algorithm@{GSM A5 ciphering algorithm}!\_a5\_1\_clock@{\_a5\_1\_clock}}
\index{\_a5\_1\_clock@{\_a5\_1\_clock}!GSM A5 ciphering algorithm@{GSM A5 ciphering algorithm}}
\doxysubsubsection{\_a5\_1\_clock()}
{\footnotesize\ttfamily static void \+\_\+a5\+\_\+1\+\_\+clock (\begin{DoxyParamCaption}\item[{uint32\+\_\+t}]{r[$\,$],  }\item[{int}]{force }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [inline]}, {\ttfamily [static]}}



GSM A5/1 Clocking function. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em r} & Register state \\
\hline
\mbox{\texttt{ in}}  & {\em force} & Non-\/zero value disable conditional clocking \\
\hline
\end{DoxyParams}


References \textbf{ \+\_\+a5\+\_\+12\+\_\+clock()}, \textbf{ \+\_\+a5\+\_\+12\+\_\+majority()}, \textbf{ A51\+\_\+\+R1\+\_\+\+CLKBIT}, \textbf{ A51\+\_\+\+R2\+\_\+\+CLKBIT}, \textbf{ A51\+\_\+\+R3\+\_\+\+CLKBIT}, \textbf{ A5\+\_\+\+R1\+\_\+\+MASK}, \textbf{ A5\+\_\+\+R1\+\_\+\+TAPS}, \textbf{ A5\+\_\+\+R2\+\_\+\+MASK}, \textbf{ A5\+\_\+\+R2\+\_\+\+TAPS}, \textbf{ A5\+\_\+\+R3\+\_\+\+MASK}, and \textbf{ A5\+\_\+\+R3\+\_\+\+TAPS}.



Referenced by \textbf{ \+\_\+a5\+\_\+1()}.

\mbox{\label{group__a5_gad57df36050292bace67390ea375f590a}} 
\index{GSM A5 ciphering algorithm@{GSM A5 ciphering algorithm}!\_a5\_1\_get\_output@{\_a5\_1\_get\_output}}
\index{\_a5\_1\_get\_output@{\_a5\_1\_get\_output}!GSM A5 ciphering algorithm@{GSM A5 ciphering algorithm}}
\doxysubsubsection{\_a5\_1\_get\_output()}
{\footnotesize\ttfamily static uint8\+\_\+t \+\_\+a5\+\_\+1\+\_\+get\+\_\+output (\begin{DoxyParamCaption}\item[{uint32\+\_\+t}]{r[$\,$] }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [inline]}, {\ttfamily [static]}}



GSM A5/1 Output function. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em r} & Register state \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
The A5/1 output function bit 
\end{DoxyReturn}


References \textbf{ A5\+\_\+\+R1\+\_\+\+LEN}, \textbf{ A5\+\_\+\+R2\+\_\+\+LEN}, and \textbf{ A5\+\_\+\+R3\+\_\+\+LEN}.



Referenced by \textbf{ \+\_\+a5\+\_\+1()}.

\mbox{\label{group__a5_ga94a85029362c86ab7349115231535c0e}} 
\index{GSM A5 ciphering algorithm@{GSM A5 ciphering algorithm}!\_a5\_2@{\_a5\_2}}
\index{\_a5\_2@{\_a5\_2}!GSM A5 ciphering algorithm@{GSM A5 ciphering algorithm}}
\doxysubsubsection{\_a5\_2()}
{\footnotesize\ttfamily void \+\_\+a5\+\_\+2 (\begin{DoxyParamCaption}\item[{const uint8\+\_\+t $\ast$}]{key,  }\item[{uint32\+\_\+t}]{fn,  }\item[{\textbf{ ubit\+\_\+t} $\ast$}]{dl,  }\item[{\textbf{ ubit\+\_\+t} $\ast$}]{ul }\end{DoxyParamCaption})}



Generate a GSM A5/1 cipher stream. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em key} & 8 byte array for the key (as received from the SIM) \\
\hline
\mbox{\texttt{ in}}  & {\em fn} & Frame number \\
\hline
\mbox{\texttt{ out}}  & {\em dl} & Pointer to array of ubits to return Downlink cipher stream \\
\hline
\mbox{\texttt{ out}}  & {\em ul} & Pointer to array of ubits to return Uplink cipher stream\\
\hline
\end{DoxyParams}
Either (or both) of dl/ul can be NULL if not needed. 

References \textbf{ \+\_\+a5\+\_\+2\+\_\+clock()}, \textbf{ \+\_\+a5\+\_\+2\+\_\+get\+\_\+output()}, and \textbf{ osmo\+\_\+a5\+\_\+fn\+\_\+count()}.



Referenced by \textbf{ osmo\+\_\+a5()}.

\mbox{\label{group__a5_gad1de17c20e9ad87f42e775e87e2fe44b}} 
\index{GSM A5 ciphering algorithm@{GSM A5 ciphering algorithm}!\_a5\_2\_clock@{\_a5\_2\_clock}}
\index{\_a5\_2\_clock@{\_a5\_2\_clock}!GSM A5 ciphering algorithm@{GSM A5 ciphering algorithm}}
\doxysubsubsection{\_a5\_2\_clock()}
{\footnotesize\ttfamily static void \+\_\+a5\+\_\+2\+\_\+clock (\begin{DoxyParamCaption}\item[{uint32\+\_\+t}]{r[$\,$],  }\item[{int}]{force }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [inline]}, {\ttfamily [static]}}



GSM A5/2 Clocking function. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em r} & Register state \\
\hline
\mbox{\texttt{ in}}  & {\em force} & Non-\/zero value disable conditional clocking \\
\hline
\end{DoxyParams}


References \textbf{ \+\_\+a5\+\_\+12\+\_\+clock()}, \textbf{ A52\+\_\+\+R4\+\_\+\+CLKBIT0}, \textbf{ A52\+\_\+\+R4\+\_\+\+CLKBIT1}, \textbf{ A52\+\_\+\+R4\+\_\+\+CLKBIT2}, \textbf{ A5\+\_\+\+R1\+\_\+\+MASK}, \textbf{ A5\+\_\+\+R1\+\_\+\+TAPS}, \textbf{ A5\+\_\+\+R2\+\_\+\+MASK}, \textbf{ A5\+\_\+\+R2\+\_\+\+TAPS}, \textbf{ A5\+\_\+\+R3\+\_\+\+MASK}, \textbf{ A5\+\_\+\+R3\+\_\+\+TAPS}, \textbf{ A5\+\_\+\+R4\+\_\+\+MASK}, and \textbf{ A5\+\_\+\+R4\+\_\+\+TAPS}.



Referenced by \textbf{ \+\_\+a5\+\_\+2()}.

\mbox{\label{group__a5_ga1e1c4c9935674be0b595cfe2f83dcb94}} 
\index{GSM A5 ciphering algorithm@{GSM A5 ciphering algorithm}!\_a5\_2\_get\_output@{\_a5\_2\_get\_output}}
\index{\_a5\_2\_get\_output@{\_a5\_2\_get\_output}!GSM A5 ciphering algorithm@{GSM A5 ciphering algorithm}}
\doxysubsubsection{\_a5\_2\_get\_output()}
{\footnotesize\ttfamily static uint8\+\_\+t \+\_\+a5\+\_\+2\+\_\+get\+\_\+output (\begin{DoxyParamCaption}\item[{uint32\+\_\+t}]{r[$\,$] }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [inline]}, {\ttfamily [static]}}



GSM A5/2 Output function. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em r} & Register state \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
The A5/2 output function bit 
\end{DoxyReturn}


References \textbf{ \+\_\+a5\+\_\+12\+\_\+majority()}, \textbf{ A5\+\_\+\+R1\+\_\+\+LEN}, \textbf{ A5\+\_\+\+R2\+\_\+\+LEN}, and \textbf{ A5\+\_\+\+R3\+\_\+\+LEN}.



Referenced by \textbf{ \+\_\+a5\+\_\+2()}.

\mbox{\label{group__a5_ga387cf457e69dcd880b446c39114da0ac}} 
\index{GSM A5 ciphering algorithm@{GSM A5 ciphering algorithm}!\_a5\_3@{\_a5\_3}}
\index{\_a5\_3@{\_a5\_3}!GSM A5 ciphering algorithm@{GSM A5 ciphering algorithm}}
\doxysubsubsection{\_a5\_3()}
{\footnotesize\ttfamily void \+\_\+a5\+\_\+3 (\begin{DoxyParamCaption}\item[{const uint8\+\_\+t $\ast$}]{key,  }\item[{uint32\+\_\+t}]{fn,  }\item[{\textbf{ ubit\+\_\+t} $\ast$}]{dl,  }\item[{\textbf{ ubit\+\_\+t} $\ast$}]{ul,  }\item[{bool}]{fn\+\_\+correct }\end{DoxyParamCaption})}



Generate a GSM A5/3 cipher stream. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em key} & 8 byte array for the key (as received from the SIM) \\
\hline
\mbox{\texttt{ in}}  & {\em fn} & Frame number \\
\hline
\mbox{\texttt{ out}}  & {\em dl} & Pointer to array of ubits to return Downlink cipher stream \\
\hline
\mbox{\texttt{ out}}  & {\em ul} & Pointer to array of ubits to return Uplink cipher stream \\
\hline
\mbox{\texttt{ in}}  & {\em fn\+\_\+correct} & true if fn is a real GSM frame number and thus requires internal conversion\\
\hline
\end{DoxyParams}
Either (or both) of dl/ul should be NULL if not needed.

Implementation based on specifications from 3GPP TS 55.\+216, 3GPP TR 55.\+919 and ETSI TS 135 202 with slight simplifications (CE hardcoded to 0). 

References \textbf{ \+\_\+a5\+\_\+4()}, and \textbf{ osmo\+\_\+c4()}.



Referenced by \textbf{ osmo\+\_\+a5()}.

\mbox{\label{group__a5_gaa444cf116b2f6842d8cf935ec3c56657}} 
\index{GSM A5 ciphering algorithm@{GSM A5 ciphering algorithm}!\_a5\_4@{\_a5\_4}}
\index{\_a5\_4@{\_a5\_4}!GSM A5 ciphering algorithm@{GSM A5 ciphering algorithm}}
\doxysubsubsection{\_a5\_4()}
{\footnotesize\ttfamily void \+\_\+a5\+\_\+4 (\begin{DoxyParamCaption}\item[{const uint8\+\_\+t $\ast$}]{ck,  }\item[{uint32\+\_\+t}]{fn,  }\item[{\textbf{ ubit\+\_\+t} $\ast$}]{dl,  }\item[{\textbf{ ubit\+\_\+t} $\ast$}]{ul,  }\item[{bool}]{fn\+\_\+correct }\end{DoxyParamCaption})}



Generate a GSM A5/4 cipher stream. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em key} & 16 byte array for the key (as received from the SIM) \\
\hline
\mbox{\texttt{ in}}  & {\em fn} & Frame number \\
\hline
\mbox{\texttt{ out}}  & {\em dl} & Pointer to array of ubits to return Downlink cipher stream \\
\hline
\mbox{\texttt{ out}}  & {\em ul} & Pointer to array of ubits to return Uplink cipher stream \\
\hline
\mbox{\texttt{ in}}  & {\em fn\+\_\+correct} & true if fn is a real GSM frame number and thus requires internal conversion\\
\hline
\end{DoxyParams}
Either (or both) of dl/ul should be NULL if not needed.

Implementation based on specifications from 3GPP TS 55.\+216, 3GPP TR 55.\+919 and ETSI TS 135 202 with slight simplifications (CE hardcoded to 0). 

References \textbf{ \+\_\+kasumi\+\_\+kgcore()}, \textbf{ osmo\+\_\+a5\+\_\+fn\+\_\+count()}, and \textbf{ osmo\+\_\+pbit2ubit()}.



Referenced by \textbf{ \+\_\+a5\+\_\+3()}, and \textbf{ osmo\+\_\+a5()}.

\mbox{\label{group__a5_ga5720846e796d9c9ac89af3ad6dd16249}} 
\index{GSM A5 ciphering algorithm@{GSM A5 ciphering algorithm}!osmo\_a5@{osmo\_a5}}
\index{osmo\_a5@{osmo\_a5}!GSM A5 ciphering algorithm@{GSM A5 ciphering algorithm}}
\doxysubsubsection{osmo\_a5()}
{\footnotesize\ttfamily int osmo\+\_\+a5 (\begin{DoxyParamCaption}\item[{int}]{n,  }\item[{const uint8\+\_\+t $\ast$}]{key,  }\item[{uint32\+\_\+t}]{fn,  }\item[{\textbf{ ubit\+\_\+t} $\ast$}]{dl,  }\item[{\textbf{ ubit\+\_\+t} $\ast$}]{ul }\end{DoxyParamCaption})}



Main method to generate a A5/x cipher stream. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em n} & Which A5/x method to use \\
\hline
\mbox{\texttt{ in}}  & {\em key} & 8 or 16 (for a5/4) byte array for the key (as received from the SIM) \\
\hline
\mbox{\texttt{ in}}  & {\em fn} & Frame number \\
\hline
\mbox{\texttt{ out}}  & {\em dl} & Pointer to array of ubits to return Downlink cipher stream \\
\hline
\mbox{\texttt{ out}}  & {\em ul} & Pointer to array of ubits to return Uplink cipher stream \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
0 for success, -\/ENOTSUP for invalid cipher selection.
\end{DoxyReturn}
Currently A5/[0-\/4] are supported. Either (or both) of dl/ul can be NULL if not needed. 

References \textbf{ \+\_\+a5\+\_\+1()}, \textbf{ \+\_\+a5\+\_\+2()}, \textbf{ \+\_\+a5\+\_\+3()}, \textbf{ \+\_\+a5\+\_\+4()}, \textbf{ ENOTSUP}, and \textbf{ n}.



Referenced by \textbf{ osmo\+\_\+a5\+\_\+1()}, and \textbf{ osmo\+\_\+a5\+\_\+2()}.

\mbox{\label{group__a5_gab9196e735908d289c77990973d926462}} 
\index{GSM A5 ciphering algorithm@{GSM A5 ciphering algorithm}!osmo\_a5\_1@{osmo\_a5\_1}}
\index{osmo\_a5\_1@{osmo\_a5\_1}!GSM A5 ciphering algorithm@{GSM A5 ciphering algorithm}}
\doxysubsubsection{osmo\_a5\_1()}
{\footnotesize\ttfamily void osmo\+\_\+a5\+\_\+1 (\begin{DoxyParamCaption}\item[{const uint8\+\_\+t $\ast$}]{key,  }\item[{uint32\+\_\+t}]{fn,  }\item[{\textbf{ ubit\+\_\+t} $\ast$}]{dl,  }\item[{\textbf{ ubit\+\_\+t} $\ast$}]{ul }\end{DoxyParamCaption})}



References \textbf{ osmo\+\_\+a5()}.

\mbox{\label{group__a5_ga3eaf81ac494f21f7a70ba829ca5a3f87}} 
\index{GSM A5 ciphering algorithm@{GSM A5 ciphering algorithm}!osmo\_a5\_2@{osmo\_a5\_2}}
\index{osmo\_a5\_2@{osmo\_a5\_2}!GSM A5 ciphering algorithm@{GSM A5 ciphering algorithm}}
\doxysubsubsection{osmo\_a5\_2()}
{\footnotesize\ttfamily void osmo\+\_\+a5\+\_\+2 (\begin{DoxyParamCaption}\item[{const uint8\+\_\+t $\ast$}]{key,  }\item[{uint32\+\_\+t}]{fn,  }\item[{\textbf{ ubit\+\_\+t} $\ast$}]{dl,  }\item[{\textbf{ ubit\+\_\+t} $\ast$}]{ul }\end{DoxyParamCaption})}



References \textbf{ osmo\+\_\+a5()}.

\mbox{\label{group__a5_ga301d2e0806c5237dedee181dbf54bf2f}} 
\index{GSM A5 ciphering algorithm@{GSM A5 ciphering algorithm}!osmo\_a5\_fn\_count@{osmo\_a5\_fn\_count}}
\index{osmo\_a5\_fn\_count@{osmo\_a5\_fn\_count}!GSM A5 ciphering algorithm@{GSM A5 ciphering algorithm}}
\doxysubsubsection{osmo\_a5\_fn\_count()}
{\footnotesize\ttfamily static uint32\+\_\+t osmo\+\_\+a5\+\_\+fn\+\_\+count (\begin{DoxyParamCaption}\item[{uint32\+\_\+t}]{fn }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [inline]}, {\ttfamily [static]}}



Converts a frame number into the 22 bit number used in A5/x. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em fn} & The true framenumber \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
22 bit word 
\end{DoxyReturn}


Referenced by \textbf{ \+\_\+a5\+\_\+1()}, \textbf{ \+\_\+a5\+\_\+2()}, and \textbf{ \+\_\+a5\+\_\+4()}.

