\doxysection{crypto.\+h}
\label{kdf_2crypto_8h_source}\index{src/gsm/kdf/crypto.h@{src/gsm/kdf/crypto.h}}
\textbf{ Go to the documentation of this file.}
\begin{DoxyCode}{0}
\DoxyCodeLine{1 \textcolor{comment}{/*}}
\DoxyCodeLine{2 \textcolor{comment}{ * WPA Supplicant / wrapper functions for crypto libraries}}
\DoxyCodeLine{3 \textcolor{comment}{ * Copyright (c) 2004-\/2009, Jouni Malinen <j@w1.fi>}}
\DoxyCodeLine{4 \textcolor{comment}{ *}}
\DoxyCodeLine{5 \textcolor{comment}{ * This program is free software; you can redistribute it and/or modify}}
\DoxyCodeLine{6 \textcolor{comment}{ * it under the terms of the GNU General Public License version 2 as}}
\DoxyCodeLine{7 \textcolor{comment}{ * published by the Free Software Foundation.}}
\DoxyCodeLine{8 \textcolor{comment}{ *}}
\DoxyCodeLine{9 \textcolor{comment}{ * Alternatively, this software may be distributed under the terms of BSD}}
\DoxyCodeLine{10 \textcolor{comment}{ * license.}}
\DoxyCodeLine{11 \textcolor{comment}{ *}}
\DoxyCodeLine{12 \textcolor{comment}{ * See README and COPYING for more details.}}
\DoxyCodeLine{13 \textcolor{comment}{ *}}
\DoxyCodeLine{14 \textcolor{comment}{ * This file defines the cryptographic functions that need to be implemented}}
\DoxyCodeLine{15 \textcolor{comment}{ * for wpa\_supplicant and hostapd. When TLS is not used, internal}}
\DoxyCodeLine{16 \textcolor{comment}{ * implementation of MD5, SHA1, and AES is used and no external libraries are}}
\DoxyCodeLine{17 \textcolor{comment}{ * required. When TLS is enabled (e.g., by enabling EAP-\/TLS or EAP-\/PEAP), the}}
\DoxyCodeLine{18 \textcolor{comment}{ * crypto library used by the TLS implementation is expected to be used for}}
\DoxyCodeLine{19 \textcolor{comment}{ * non-\/TLS needs, too, in order to save space by not implementing these}}
\DoxyCodeLine{20 \textcolor{comment}{ * functions twice.}}
\DoxyCodeLine{21 \textcolor{comment}{ *}}
\DoxyCodeLine{22 \textcolor{comment}{ * Wrapper code for using each crypto library is in its own file (crypto*.c)}}
\DoxyCodeLine{23 \textcolor{comment}{ * and one of these files is build and linked in to provide the functions}}
\DoxyCodeLine{24 \textcolor{comment}{ * defined here.}}
\DoxyCodeLine{25 \textcolor{comment}{ */}}
\DoxyCodeLine{26 }
\DoxyCodeLine{27 \textcolor{preprocessor}{\#ifndef CRYPTO\_H}}
\DoxyCodeLine{28 \textcolor{preprocessor}{\#define CRYPTO\_H}}
\DoxyCodeLine{29 }
\DoxyCodeLine{38 \textcolor{keywordtype}{int} md4\_vector(\textcolor{keywordtype}{size\_t} num\_elem, \textcolor{keyword}{const} u8 *addr[], \textcolor{keyword}{const} \textcolor{keywordtype}{size\_t} *len, u8 *mac);}
\DoxyCodeLine{39 }
\DoxyCodeLine{48 \textcolor{keywordtype}{int} md5\_vector(\textcolor{keywordtype}{size\_t} num\_elem, \textcolor{keyword}{const} u8 *addr[], \textcolor{keyword}{const} \textcolor{keywordtype}{size\_t} *len, u8 *mac);}
\DoxyCodeLine{49 }
\DoxyCodeLine{50 \textcolor{preprocessor}{\#ifdef CONFIG\_FIPS}}
\DoxyCodeLine{59 \textcolor{keywordtype}{int} md5\_vector\_non\_fips\_allow(\textcolor{keywordtype}{size\_t} num\_elem, \textcolor{keyword}{const} u8 *addr[],}
\DoxyCodeLine{60                               \textcolor{keyword}{const} \textcolor{keywordtype}{size\_t} *len, u8 *mac);}
\DoxyCodeLine{61 \textcolor{preprocessor}{\#else }\textcolor{comment}{/* CONFIG\_FIPS */}\textcolor{preprocessor}{}}
\DoxyCodeLine{62 \textcolor{preprocessor}{\#define md5\_vector\_non\_fips\_allow md5\_vector}}
\DoxyCodeLine{63 \textcolor{preprocessor}{\#endif }\textcolor{comment}{/* CONFIG\_FIPS */}\textcolor{preprocessor}{}}
\DoxyCodeLine{64 }
\DoxyCodeLine{65 }
\DoxyCodeLine{74 \textcolor{keywordtype}{int} sha1\_vector(\textcolor{keywordtype}{size\_t} num\_elem, \textcolor{keyword}{const} u8 *addr[], \textcolor{keyword}{const} \textcolor{keywordtype}{size\_t} *len,}
\DoxyCodeLine{75                 u8 *mac);}
\DoxyCodeLine{76 }
\DoxyCodeLine{89 \textcolor{keywordtype}{int} \_\_must\_check fips186\_2\_prf(\textcolor{keyword}{const} u8 *seed, \textcolor{keywordtype}{size\_t} seed\_len, u8 *x,}
\DoxyCodeLine{90                                \textcolor{keywordtype}{size\_t} xlen);}
\DoxyCodeLine{91 }
\DoxyCodeLine{100 \textcolor{keywordtype}{int} sha256\_vector(\textcolor{keywordtype}{size\_t} num\_elem, \textcolor{keyword}{const} u8 *addr[], \textcolor{keyword}{const} \textcolor{keywordtype}{size\_t} *len,}
\DoxyCodeLine{101                   u8 *mac);}
\DoxyCodeLine{102 }
\DoxyCodeLine{109 \textcolor{keywordtype}{void} des\_encrypt(\textcolor{keyword}{const} u8 *clear, \textcolor{keyword}{const} u8 *key, u8 *cypher);}
\DoxyCodeLine{110 }
\DoxyCodeLine{117 \textcolor{keywordtype}{void} * aes\_encrypt\_init(\textcolor{keyword}{const} u8 *key, \textcolor{keywordtype}{size\_t} len);}
\DoxyCodeLine{118 }
\DoxyCodeLine{125 \textcolor{keywordtype}{void} aes\_encrypt(\textcolor{keywordtype}{void} *ctx, \textcolor{keyword}{const} u8 *plain, u8 *crypt);}
\DoxyCodeLine{126 }
\DoxyCodeLine{131 \textcolor{keywordtype}{void} aes\_encrypt\_deinit(\textcolor{keywordtype}{void} *ctx);}
\DoxyCodeLine{132 }
\DoxyCodeLine{139 \textcolor{keywordtype}{void} * aes\_decrypt\_init(\textcolor{keyword}{const} u8 *key, \textcolor{keywordtype}{size\_t} len);}
\DoxyCodeLine{140 }
\DoxyCodeLine{147 \textcolor{keywordtype}{void} aes\_decrypt(\textcolor{keywordtype}{void} *ctx, \textcolor{keyword}{const} u8 *crypt, u8 *plain);}
\DoxyCodeLine{148 }
\DoxyCodeLine{153 \textcolor{keywordtype}{void} aes\_decrypt\_deinit(\textcolor{keywordtype}{void} *ctx);}
\DoxyCodeLine{154 }
\DoxyCodeLine{155 }
\DoxyCodeLine{156 \textcolor{keyword}{enum} crypto\_hash\_alg \{}
\DoxyCodeLine{157         CRYPTO\_HASH\_ALG\_MD5, CRYPTO\_HASH\_ALG\_SHA1,}
\DoxyCodeLine{158         CRYPTO\_HASH\_ALG\_HMAC\_MD5, CRYPTO\_HASH\_ALG\_HMAC\_SHA1,}
\DoxyCodeLine{159         CRYPTO\_HASH\_ALG\_SHA256, CRYPTO\_HASH\_ALG\_HMAC\_SHA256}
\DoxyCodeLine{160 \};}
\DoxyCodeLine{161 }
\DoxyCodeLine{162 \textcolor{keyword}{struct }crypto\_hash;}
\DoxyCodeLine{163 }
\DoxyCodeLine{176 \textcolor{keyword}{struct }crypto\_hash * crypto\_hash\_init(\textcolor{keyword}{enum} crypto\_hash\_alg alg, \textcolor{keyword}{const} u8 *key,}
\DoxyCodeLine{177                                       \textcolor{keywordtype}{size\_t} key\_len);}
\DoxyCodeLine{178 }
\DoxyCodeLine{189 \textcolor{keywordtype}{void} crypto\_hash\_update(\textcolor{keyword}{struct} crypto\_hash *ctx, \textcolor{keyword}{const} u8 *data, \textcolor{keywordtype}{size\_t} len);}
\DoxyCodeLine{190 }
\DoxyCodeLine{208 \textcolor{keywordtype}{int} crypto\_hash\_finish(\textcolor{keyword}{struct} crypto\_hash *ctx, u8 *hash, \textcolor{keywordtype}{size\_t} *len);}
\DoxyCodeLine{209 }
\DoxyCodeLine{210 }
\DoxyCodeLine{211 \textcolor{keyword}{enum} crypto\_cipher\_alg \{}
\DoxyCodeLine{212         CRYPTO\_CIPHER\_NULL = 0, CRYPTO\_CIPHER\_ALG\_AES, CRYPTO\_CIPHER\_ALG\_3DES,}
\DoxyCodeLine{213         CRYPTO\_CIPHER\_ALG\_DES, CRYPTO\_CIPHER\_ALG\_RC2, CRYPTO\_CIPHER\_ALG\_RC4}
\DoxyCodeLine{214 \};}
\DoxyCodeLine{215 }
\DoxyCodeLine{216 \textcolor{keyword}{struct }crypto\_cipher;}
\DoxyCodeLine{217 }
\DoxyCodeLine{231 \textcolor{keyword}{struct }crypto\_cipher * crypto\_cipher\_init(\textcolor{keyword}{enum} crypto\_cipher\_alg alg,}
\DoxyCodeLine{232                                           \textcolor{keyword}{const} u8 *iv, \textcolor{keyword}{const} u8 *key,}
\DoxyCodeLine{233                                           \textcolor{keywordtype}{size\_t} key\_len);}
\DoxyCodeLine{234 }
\DoxyCodeLine{247 \textcolor{keywordtype}{int} \_\_must\_check crypto\_cipher\_encrypt(\textcolor{keyword}{struct} crypto\_cipher *ctx,}
\DoxyCodeLine{248                                        \textcolor{keyword}{const} u8 *plain, u8 *crypt, \textcolor{keywordtype}{size\_t} len);}
\DoxyCodeLine{249 }
\DoxyCodeLine{262 \textcolor{keywordtype}{int} \_\_must\_check crypto\_cipher\_decrypt(\textcolor{keyword}{struct} crypto\_cipher *ctx,}
\DoxyCodeLine{263                                        \textcolor{keyword}{const} u8 *crypt, u8 *plain, \textcolor{keywordtype}{size\_t} len);}
\DoxyCodeLine{264 }
\DoxyCodeLine{273 \textcolor{keywordtype}{void} crypto\_cipher\_deinit(\textcolor{keyword}{struct} crypto\_cipher *ctx);}
\DoxyCodeLine{274 }
\DoxyCodeLine{275 }
\DoxyCodeLine{276 \textcolor{keyword}{struct }crypto\_public\_key;}
\DoxyCodeLine{277 \textcolor{keyword}{struct }crypto\_private\_key;}
\DoxyCodeLine{278 }
\DoxyCodeLine{293 \textcolor{keyword}{struct }crypto\_public\_key * crypto\_public\_key\_import(\textcolor{keyword}{const} u8 *key, \textcolor{keywordtype}{size\_t} len);}
\DoxyCodeLine{294 }
\DoxyCodeLine{306 \textcolor{keyword}{struct }crypto\_private\_key * crypto\_private\_key\_import(\textcolor{keyword}{const} u8 *key,}
\DoxyCodeLine{307                                                       \textcolor{keywordtype}{size\_t} len,}
\DoxyCodeLine{308                                                       \textcolor{keyword}{const} \textcolor{keywordtype}{char} *passwd);}
\DoxyCodeLine{309 }
\DoxyCodeLine{324 \textcolor{keyword}{struct }crypto\_public\_key * crypto\_public\_key\_from\_cert(\textcolor{keyword}{const} u8 *buf,}
\DoxyCodeLine{325                                                        \textcolor{keywordtype}{size\_t} len);}
\DoxyCodeLine{326 }
\DoxyCodeLine{340 \textcolor{keywordtype}{int} \_\_must\_check crypto\_public\_key\_encrypt\_pkcs1\_v15(}
\DoxyCodeLine{341         \textcolor{keyword}{struct} crypto\_public\_key *key, \textcolor{keyword}{const} u8 *in, \textcolor{keywordtype}{size\_t} inlen,}
\DoxyCodeLine{342         u8 *out, \textcolor{keywordtype}{size\_t} *outlen);}
\DoxyCodeLine{343 }
\DoxyCodeLine{357 \textcolor{keywordtype}{int} \_\_must\_check crypto\_private\_key\_decrypt\_pkcs1\_v15(}
\DoxyCodeLine{358         \textcolor{keyword}{struct} crypto\_private\_key *key, \textcolor{keyword}{const} u8 *in, \textcolor{keywordtype}{size\_t} inlen,}
\DoxyCodeLine{359         u8 *out, \textcolor{keywordtype}{size\_t} *outlen);}
\DoxyCodeLine{360 }
\DoxyCodeLine{374 \textcolor{keywordtype}{int} \_\_must\_check crypto\_private\_key\_sign\_pkcs1(\textcolor{keyword}{struct} crypto\_private\_key *key,}
\DoxyCodeLine{375                                                \textcolor{keyword}{const} u8 *in, \textcolor{keywordtype}{size\_t} inlen,}
\DoxyCodeLine{376                                                u8 *out, \textcolor{keywordtype}{size\_t} *outlen);}
\DoxyCodeLine{377 }
\DoxyCodeLine{386 \textcolor{keywordtype}{void} crypto\_public\_key\_free(\textcolor{keyword}{struct} crypto\_public\_key *key);}
\DoxyCodeLine{387 }
\DoxyCodeLine{396 \textcolor{keywordtype}{void} crypto\_private\_key\_free(\textcolor{keyword}{struct} crypto\_private\_key *key);}
\DoxyCodeLine{397 }
\DoxyCodeLine{407 \textcolor{keywordtype}{int} \_\_must\_check crypto\_public\_key\_decrypt\_pkcs1(}
\DoxyCodeLine{408         \textcolor{keyword}{struct} crypto\_public\_key *key, \textcolor{keyword}{const} u8 *crypt, \textcolor{keywordtype}{size\_t} crypt\_len,}
\DoxyCodeLine{409         u8 *plain, \textcolor{keywordtype}{size\_t} *plain\_len);}
\DoxyCodeLine{410 }
\DoxyCodeLine{418 \textcolor{keywordtype}{int} \_\_must\_check crypto\_global\_init(\textcolor{keywordtype}{void});}
\DoxyCodeLine{419 }
\DoxyCodeLine{427 \textcolor{keywordtype}{void} crypto\_global\_deinit(\textcolor{keywordtype}{void});}
\DoxyCodeLine{428 }
\DoxyCodeLine{449 \textcolor{keywordtype}{int} \_\_must\_check crypto\_mod\_exp(\textcolor{keyword}{const} u8 *base, \textcolor{keywordtype}{size\_t} base\_len,}
\DoxyCodeLine{450                                 \textcolor{keyword}{const} u8 *power, \textcolor{keywordtype}{size\_t} power\_len,}
\DoxyCodeLine{451                                 \textcolor{keyword}{const} u8 *modulus, \textcolor{keywordtype}{size\_t} modulus\_len,}
\DoxyCodeLine{452                                 u8 *result, \textcolor{keywordtype}{size\_t} *result\_len);}
\DoxyCodeLine{453 }
\DoxyCodeLine{467 \textcolor{keywordtype}{int} rc4\_skip(\textcolor{keyword}{const} u8 *key, \textcolor{keywordtype}{size\_t} keylen, \textcolor{keywordtype}{size\_t} skip,}
\DoxyCodeLine{468              u8 *data, \textcolor{keywordtype}{size\_t} data\_len);}
\DoxyCodeLine{469 }
\DoxyCodeLine{470 \textcolor{preprocessor}{\#endif }\textcolor{comment}{/* CRYPTO\_H */}\textcolor{preprocessor}{}}

\end{DoxyCode}
