\doxysection{gprs\+\_\+cipher.\+h}
\label{gprs__cipher_8h_source}\index{include/osmocom/crypt/gprs\_cipher.h@{include/osmocom/crypt/gprs\_cipher.h}}
\textbf{ Go to the documentation of this file.}
\begin{DoxyCode}{0}
\DoxyCodeLine{1 }
\DoxyCodeLine{3 \textcolor{preprocessor}{\#pragma once}}
\DoxyCodeLine{4 }
\DoxyCodeLine{5 \textcolor{preprocessor}{\#include <osmocom/core/linuxlist.h>}}
\DoxyCodeLine{6 \textcolor{preprocessor}{\#include <osmocom/core/utils.h>}}
\DoxyCodeLine{7 }
\DoxyCodeLine{8 \textcolor{preprocessor}{\#include <stdint.h>}}
\DoxyCodeLine{9 }
\DoxyCodeLine{10 \textcolor{preprocessor}{\#define GSM0464\_CIPH\_MAX\_BLOCK  1523}}
\DoxyCodeLine{11 }
\DoxyCodeLine{12 \textcolor{comment}{/* 3GPP TS 24.008 § 10.5.5.3 */}}
\DoxyCodeLine{13 \textcolor{keyword}{enum} gprs\_ciph\_algo \{}
\DoxyCodeLine{14         GPRS\_ALGO\_GEA0 = 0,}
\DoxyCodeLine{15         GPRS\_ALGO\_GEA1 = 1,}
\DoxyCodeLine{16         GPRS\_ALGO\_GEA2 = 2,}
\DoxyCodeLine{17         GPRS\_ALGO\_GEA3 = 3,}
\DoxyCodeLine{18         GPRS\_ALGO\_GEA4 = 4,}
\DoxyCodeLine{19         \_GPRS\_ALGO\_NUM}
\DoxyCodeLine{20 \};}
\DoxyCodeLine{21 }
\DoxyCodeLine{22 \textcolor{comment}{/* 3GPP TS 04.64 Table A.1: */}}
\DoxyCodeLine{23 \textcolor{keyword}{enum} gprs\_cipher\_direction \{}
\DoxyCodeLine{24         GPRS\_CIPH\_MS2SGSN = 0,}
\DoxyCodeLine{25         GPRS\_CIPH\_SGSN2MS = 1,}
\DoxyCodeLine{26 \};}
\DoxyCodeLine{27 }
\DoxyCodeLine{28 \textcolor{keyword}{extern} \textcolor{keyword}{const} \textcolor{keyword}{struct }value\_string gprs\_cipher\_names[];}
\DoxyCodeLine{29 }
\DoxyCodeLine{30 \textcolor{comment}{/* An implementation of a GPRS cipher */}}
\DoxyCodeLine{31 \textcolor{keyword}{struct }gprs\_cipher\_impl \{}
\DoxyCodeLine{32         \textcolor{keyword}{struct }llist\_head list;}
\DoxyCodeLine{33         \textcolor{keyword}{enum} gprs\_ciph\_algo algo;}
\DoxyCodeLine{34         \textcolor{keyword}{const} \textcolor{keywordtype}{char} *name;}
\DoxyCodeLine{35         \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} priority;}
\DoxyCodeLine{36 }
\DoxyCodeLine{37         \textcolor{comment}{/* As specified in 04.64 Annex A.  Uses Kc, IV and direction}}
\DoxyCodeLine{38 \textcolor{comment}{         * to generate the 1523 bytes cipher stream that need to be}}
\DoxyCodeLine{39 \textcolor{comment}{         * XORed wit the plaintext for encrypt / ciphertext for decrypt */}}
\DoxyCodeLine{40         int (*run)(uint8\_t *out, uint16\_t len, uint8\_t *kc, uint32\_t iv,}
\DoxyCodeLine{41                    \textcolor{keyword}{enum} gprs\_cipher\_direction direction);}
\DoxyCodeLine{42 \};}
\DoxyCodeLine{43 }
\DoxyCodeLine{44 \textcolor{comment}{/* register a cipher with the core (from a plugin) */}}
\DoxyCodeLine{45 \textcolor{keywordtype}{int} gprs\_cipher\_register(\textcolor{keyword}{struct} gprs\_cipher\_impl *ciph);}
\DoxyCodeLine{46 }
\DoxyCodeLine{47 \textcolor{comment}{/* load all available GPRS cipher plugins */}}
\DoxyCodeLine{48 \textcolor{keywordtype}{int} gprs\_cipher\_load(\textcolor{keyword}{const} \textcolor{keywordtype}{char} *path);}
\DoxyCodeLine{49 }
\DoxyCodeLine{50 \textcolor{comment}{/* function to be called by core code */}}
\DoxyCodeLine{51 \textcolor{keywordtype}{int} gprs\_cipher\_run(uint8\_t *out, uint16\_t len, \textcolor{keyword}{enum} gprs\_ciph\_algo algo,}
\DoxyCodeLine{52                     uint8\_t *kc, uint32\_t iv, \textcolor{keyword}{enum} gprs\_cipher\_direction dir);}
\DoxyCodeLine{53 }
\DoxyCodeLine{54 \textcolor{comment}{/* Do we have an implementation for this cipher? */}}
\DoxyCodeLine{55 \textcolor{keywordtype}{int} gprs\_cipher\_supported(\textcolor{keyword}{enum} gprs\_ciph\_algo algo);}
\DoxyCodeLine{56 }
\DoxyCodeLine{57 \textcolor{comment}{/* Return key length for supported cipher, in bytes */}}
\DoxyCodeLine{58 \textcolor{keywordtype}{unsigned} gprs\_cipher\_key\_length(\textcolor{keyword}{enum} gprs\_ciph\_algo algo);}
\DoxyCodeLine{59 }
\DoxyCodeLine{60 \textcolor{comment}{/* GSM TS 04.64 / Section A.2.1 : Generation of 'input' */}}
\DoxyCodeLine{61 uint32\_t gprs\_cipher\_gen\_input\_ui(uint32\_t iov\_ui, uint8\_t sapi, uint32\_t lfn, uint32\_t oc);}
\DoxyCodeLine{62 }
\DoxyCodeLine{63 \textcolor{comment}{/* GSM TS 04.64 / Section A.2.1 : Generation of 'input' */}}
\DoxyCodeLine{64 uint32\_t gprs\_cipher\_gen\_input\_i(uint32\_t iov\_i, uint32\_t lfn, uint32\_t oc);}

\end{DoxyCode}
