\doxysection{auth.\+h}
\label{auth_8h_source}\index{include/osmocom/crypt/auth.h@{include/osmocom/crypt/auth.h}}
\textbf{ Go to the documentation of this file.}
\begin{DoxyCode}{0}
\DoxyCodeLine{1 \textcolor{preprocessor}{\#pragma once}}
\DoxyCodeLine{2 }
\DoxyCodeLine{7 \textcolor{preprocessor}{\#include <stdint.h>}}
\DoxyCodeLine{8 }
\DoxyCodeLine{9 \textcolor{preprocessor}{\#include <osmocom/core/linuxlist.h>}}
\DoxyCodeLine{10 \textcolor{preprocessor}{\#include <osmocom/core/utils.h>}}
\DoxyCodeLine{11 }
\DoxyCodeLine{12 \textcolor{preprocessor}{\#define OSMO\_A5\_MAX\_KEY\_LEN\_BYTES (128/8)}}
\DoxyCodeLine{13 \textcolor{preprocessor}{\#define OSMO\_MILENAGE\_IND\_BITLEN\_MAX 28}}
\DoxyCodeLine{14 }
\DoxyCodeLine{16 \textcolor{keyword}{enum} osmo\_sub\_auth\_type \{}
\DoxyCodeLine{17         OSMO\_AUTH\_TYPE\_NONE  = 0x00,}
\DoxyCodeLine{18         OSMO\_AUTH\_TYPE\_GSM    = 0x01,}
\DoxyCodeLine{19         OSMO\_AUTH\_TYPE\_UMTS  = 0x02,}
\DoxyCodeLine{20 \};}
\DoxyCodeLine{21 }
\DoxyCodeLine{22 \textcolor{keyword}{extern} \textcolor{keyword}{const} \textcolor{keyword}{struct }value\_string osmo\_sub\_auth\_type\_names[];}
\DoxyCodeLine{23 \textcolor{keyword}{static} \textcolor{keyword}{inline} \textcolor{keyword}{const} \textcolor{keywordtype}{char} *osmo\_sub\_auth\_type\_name(\textcolor{keyword}{enum} osmo\_sub\_auth\_type val)}
\DoxyCodeLine{24 \{ \textcolor{keywordflow}{return} get\_value\_string(osmo\_sub\_auth\_type\_names, val); \}}
\DoxyCodeLine{25 }
\DoxyCodeLine{28 \textcolor{keyword}{enum} osmo\_auth\_algo \{}
\DoxyCodeLine{29         OSMO\_AUTH\_ALG\_NONE,}
\DoxyCodeLine{30         OSMO\_AUTH\_ALG\_COMP128v1,}
\DoxyCodeLine{31         OSMO\_AUTH\_ALG\_COMP128v2,}
\DoxyCodeLine{32         OSMO\_AUTH\_ALG\_COMP128v3,}
\DoxyCodeLine{33         OSMO\_AUTH\_ALG\_XOR\_3G,}
\DoxyCodeLine{34         OSMO\_AUTH\_ALG\_MILENAGE,}
\DoxyCodeLine{35         OSMO\_AUTH\_ALG\_XOR\_2G,}
\DoxyCodeLine{36         OSMO\_AUTH\_ALG\_TUAK,}
\DoxyCodeLine{37         \_OSMO\_AUTH\_ALG\_NUM,}
\DoxyCodeLine{38 \};}
\DoxyCodeLine{39 \textcolor{comment}{/* Backwards-\/compatibility. We used to call XOR-\/3G just "{}XOR"{} which became ambiguous when}}
\DoxyCodeLine{40 \textcolor{comment}{ * we started to add XOR-\/2G support. */}}
\DoxyCodeLine{41 \textcolor{preprocessor}{\#define OSMO\_AUTH\_ALG\_XOR OSMO\_AUTH\_ALG\_XOR\_3G}}
\DoxyCodeLine{42 }
\DoxyCodeLine{44 \textcolor{keyword}{struct }osmo\_sub\_auth\_data2 \{}
\DoxyCodeLine{45         \textcolor{keyword}{enum} osmo\_sub\_auth\_type type;}
\DoxyCodeLine{46         \textcolor{keyword}{enum} osmo\_auth\_algo algo;}
\DoxyCodeLine{47         \textcolor{keyword}{union }\{}
\DoxyCodeLine{48                 \textcolor{keyword}{struct }\{}
\DoxyCodeLine{49                         \textcolor{comment}{/* See 3GPP TS 33.102 Section 9.3.7 Length of authentication parameters */}}
\DoxyCodeLine{50                         uint8\_t opc[32]; }
\DoxyCodeLine{51                         uint8\_t opc\_len; }
\DoxyCodeLine{52                         uint8\_t k[32]; }
\DoxyCodeLine{53                         uint8\_t k\_len;     }
\DoxyCodeLine{54                         uint8\_t amf[2];}
\DoxyCodeLine{55                         uint64\_t sqn;        }
\DoxyCodeLine{56                         \textcolor{keywordtype}{int} opc\_is\_op; }
\DoxyCodeLine{57                         \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} ind\_bitlen; }
\DoxyCodeLine{58                         \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} ind; }
\DoxyCodeLine{59                         uint64\_t sqn\_ms; }
\DoxyCodeLine{60                 \} umts;}
\DoxyCodeLine{61                 \textcolor{keyword}{struct }\{}
\DoxyCodeLine{62                         uint8\_t ki[OSMO\_A5\_MAX\_KEY\_LEN\_BYTES];       }
\DoxyCodeLine{63                 \} gsm;}
\DoxyCodeLine{64         \} u;}
\DoxyCodeLine{65 \};}
\DoxyCodeLine{66 }
\DoxyCodeLine{67 \textcolor{comment}{/* deprecated older structure without support for 32-\/byte K/OP[c] */}}
\DoxyCodeLine{68 \textcolor{keyword}{struct }osmo\_sub\_auth\_data \{}
\DoxyCodeLine{69         \textcolor{keyword}{enum} osmo\_sub\_auth\_type type;}
\DoxyCodeLine{70         \textcolor{keyword}{enum} osmo\_auth\_algo algo;}
\DoxyCodeLine{71         \textcolor{keyword}{union }\{}
\DoxyCodeLine{72                 \textcolor{keyword}{struct }\{}
\DoxyCodeLine{73                         uint8\_t opc[16]; }
\DoxyCodeLine{74                         uint8\_t k[OSMO\_A5\_MAX\_KEY\_LEN\_BYTES]; }
\DoxyCodeLine{75                         uint8\_t amf[2];}
\DoxyCodeLine{76                         uint64\_t sqn;        }
\DoxyCodeLine{77                         \textcolor{keywordtype}{int} opc\_is\_op; }
\DoxyCodeLine{78                         \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} ind\_bitlen; }
\DoxyCodeLine{79                         \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} ind; }
\DoxyCodeLine{80                         uint64\_t sqn\_ms; }
\DoxyCodeLine{81                 \} umts;}
\DoxyCodeLine{82                 \textcolor{keyword}{struct }\{}
\DoxyCodeLine{83                         uint8\_t ki[OSMO\_A5\_MAX\_KEY\_LEN\_BYTES];       }
\DoxyCodeLine{84                 \} gsm;}
\DoxyCodeLine{85         \} u;}
\DoxyCodeLine{86 \};}
\DoxyCodeLine{87 }
\DoxyCodeLine{88 \textcolor{comment}{/* data structure describing a computed auth vector, generated by AuC */}}
\DoxyCodeLine{89 \textcolor{keyword}{struct }osmo\_auth\_vector \{}
\DoxyCodeLine{90         uint8\_t rand[16];   }
\DoxyCodeLine{91         uint8\_t autn[16];   }
\DoxyCodeLine{92         uint8\_t ck[OSMO\_A5\_MAX\_KEY\_LEN\_BYTES];               }
\DoxyCodeLine{93         uint8\_t ik[OSMO\_A5\_MAX\_KEY\_LEN\_BYTES];               }
\DoxyCodeLine{94         uint8\_t res[16];     }
\DoxyCodeLine{95         uint8\_t res\_len; }
\DoxyCodeLine{96         uint8\_t kc[8];                }
\DoxyCodeLine{97         uint8\_t sres[4];    }
\DoxyCodeLine{98         uint32\_t auth\_types;  }
\DoxyCodeLine{99 \};}
\DoxyCodeLine{100 }
\DoxyCodeLine{101 \textcolor{comment}{/* An implementation of an authentication algorithm */}}
\DoxyCodeLine{102 \textcolor{keyword}{struct }osmo\_auth\_impl \{}
\DoxyCodeLine{103         \textcolor{keyword}{struct }llist\_head list;}
\DoxyCodeLine{104         \textcolor{keyword}{enum} osmo\_auth\_algo algo; }
\DoxyCodeLine{105         \textcolor{keyword}{const} \textcolor{keywordtype}{char} *name;   }
\DoxyCodeLine{106         \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} priority;  }
\DoxyCodeLine{109         int (*gen\_vec)(\textcolor{keyword}{struct }osmo\_auth\_vector *vec,}
\DoxyCodeLine{110                         \textcolor{keyword}{struct }osmo\_sub\_auth\_data2 *aud,}
\DoxyCodeLine{111                         \textcolor{keyword}{const} uint8\_t *\_rand);}
\DoxyCodeLine{112 }
\DoxyCodeLine{114         int (*gen\_vec\_auts)(\textcolor{keyword}{struct }osmo\_auth\_vector *vec,}
\DoxyCodeLine{115                             \textcolor{keyword}{struct }osmo\_sub\_auth\_data2 *aud,}
\DoxyCodeLine{116                             \textcolor{keyword}{const} uint8\_t *auts, \textcolor{keyword}{const} uint8\_t *rand\_auts,}
\DoxyCodeLine{117                             \textcolor{keyword}{const} uint8\_t *\_rand);}
\DoxyCodeLine{118 \};}
\DoxyCodeLine{119 }
\DoxyCodeLine{120 \textcolor{keywordtype}{int} osmo\_auth\_gen\_vec(\textcolor{keyword}{struct} osmo\_auth\_vector *vec,}
\DoxyCodeLine{121                       \textcolor{keyword}{struct} osmo\_sub\_auth\_data *aud, \textcolor{keyword}{const} uint8\_t *\_rand)}
\DoxyCodeLine{122         OSMO\_DEPRECATED\_OUTSIDE(\textcolor{stringliteral}{"{}Use osmo\_auth\_gen\_vec2 instead"{}});}
\DoxyCodeLine{123 }
\DoxyCodeLine{124 \textcolor{keywordtype}{int} osmo\_auth\_gen\_vec2(\textcolor{keyword}{struct} osmo\_auth\_vector *vec,}
\DoxyCodeLine{125                        \textcolor{keyword}{struct} osmo\_sub\_auth\_data2 *aud, \textcolor{keyword}{const} uint8\_t *\_rand);}
\DoxyCodeLine{126 }
\DoxyCodeLine{127 \textcolor{keywordtype}{int} osmo\_auth\_gen\_vec\_auts(\textcolor{keyword}{struct} osmo\_auth\_vector *vec,}
\DoxyCodeLine{128                            \textcolor{keyword}{struct} osmo\_sub\_auth\_data *aud,}
\DoxyCodeLine{129                            \textcolor{keyword}{const} uint8\_t *auts, \textcolor{keyword}{const} uint8\_t *rand\_auts,}
\DoxyCodeLine{130                            \textcolor{keyword}{const} uint8\_t *\_rand)}
\DoxyCodeLine{131         OSMO\_DEPRECATED\_OUTSIDE(\textcolor{stringliteral}{"{}Use osmo\_auth\_gen\_vec\_auts2 instead"{}});}
\DoxyCodeLine{132 }
\DoxyCodeLine{133 \textcolor{keywordtype}{int} osmo\_auth\_gen\_vec\_auts2(\textcolor{keyword}{struct} osmo\_auth\_vector *vec,}
\DoxyCodeLine{134                            \textcolor{keyword}{struct} osmo\_sub\_auth\_data2 *aud,}
\DoxyCodeLine{135                            \textcolor{keyword}{const} uint8\_t *auts, \textcolor{keyword}{const} uint8\_t *rand\_auts,}
\DoxyCodeLine{136                            \textcolor{keyword}{const} uint8\_t *\_rand);}
\DoxyCodeLine{137 }
\DoxyCodeLine{138 \textcolor{keywordtype}{int} osmo\_auth\_register(\textcolor{keyword}{struct} osmo\_auth\_impl *impl);}
\DoxyCodeLine{139 }
\DoxyCodeLine{140 \textcolor{keywordtype}{int} osmo\_auth\_load(\textcolor{keyword}{const} \textcolor{keywordtype}{char} *path);}
\DoxyCodeLine{141 }
\DoxyCodeLine{142 \textcolor{keywordtype}{int} osmo\_auth\_supported(\textcolor{keyword}{enum} osmo\_auth\_algo algo);}
\DoxyCodeLine{143 \textcolor{keywordtype}{void} osmo\_c4(uint8\_t *ck, \textcolor{keyword}{const} uint8\_t *kc);}
\DoxyCodeLine{144 \textcolor{keyword}{const} \textcolor{keywordtype}{char} *osmo\_auth\_alg\_name(\textcolor{keyword}{enum} osmo\_auth\_algo alg);}
\DoxyCodeLine{145 \textcolor{keyword}{enum} osmo\_auth\_algo osmo\_auth\_alg\_parse(\textcolor{keyword}{const} \textcolor{keywordtype}{char} *name);}
\DoxyCodeLine{146 }
\DoxyCodeLine{147 \textcolor{keywordtype}{void} osmo\_auth\_c3(uint8\_t kc[], \textcolor{keyword}{const} uint8\_t ck[], \textcolor{keyword}{const} uint8\_t ik[]);}
\DoxyCodeLine{148 \textcolor{keywordtype}{void} osmo\_auth\_c2(uint8\_t sres[4], \textcolor{keyword}{const} uint8\_t *res, \textcolor{keywordtype}{size\_t} res\_len, uint8\_t sres\_deriv\_func);}
\DoxyCodeLine{149 }
\DoxyCodeLine{150 \textcolor{comment}{/* @\} */}}

\end{DoxyCode}
