crypto.h (6700B)
1 /* 2 * 3 * Wireless daemon for Linux 4 * 5 * Copyright (C) 2013-2019 Intel Corporation. All rights reserved. 6 * 7 * This library is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU Lesser General Public 9 * License as published by the Free Software Foundation; either 10 * version 2.1 of the License, or (at your option) any later version. 11 * 12 * This library is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * Lesser General Public License for more details. 16 * 17 * You should have received a copy of the GNU Lesser General Public 18 * License along with this library; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 * 21 */ 22 23 #include <stddef.h> 24 #include <stdbool.h> 25 26 struct l_ecc_point; 27 28 enum crypto_cipher { 29 CRYPTO_CIPHER_WEP40 = 0x000fac01, 30 CRYPTO_CIPHER_WEP104 = 0x000fac05, 31 CRYPTO_CIPHER_TKIP = 0x000fac02, 32 CRYPTO_CIPHER_CCMP = 0x000fac04, 33 CRYPTO_CIPHER_BIP_CMAC = 0x000fac06, 34 CRYPTO_CIPHER_GCMP = 0x000fac08, 35 CRYPTO_CIPHER_GCMP_256 = 0x000fac09, 36 CRYPTO_CIPHER_CCMP_256 = 0x000fac0a, 37 CRYPTO_CIPHER_BIP_GMAC = 0x000fac0b, 38 CRYPTO_CIPHER_BIP_GMAC_256 = 0x000fac0c, 39 CRYPTO_CIPHER_BIP_CMAC_256 = 0x000fac0d, 40 }; 41 42 enum crypto_akm { 43 CRYPTO_AKM_8021X = 0x000fac01, 44 CRYPTO_AKM_PSK = 0x000fac02, 45 CRYPTO_AKM_FT_OVER_8021X = 0x000fac03, 46 CRYPTO_AKM_FT_USING_PSK = 0x000fac04, 47 CRYPTO_AKM_8021X_SHA256 = 0x000fac05, 48 CRYPTO_AKM_PSK_SHA256 = 0x000fac06, 49 CRYPTO_AKM_TDLS = 0x000fac07, 50 CRYPTO_AKM_SAE_SHA256 = 0x000fac08, 51 CRYPTO_AKM_FT_OVER_SAE_SHA256 = 0x000fac09, 52 CRYPTO_AKM_AP_PEER_KEY_SHA256 = 0x000fac0a, 53 CRYPTO_AKM_8021X_SUITE_B_SHA256 = 0x000fac0b, 54 CRYPTO_AKM_8021X_SUITE_B_SHA384 = 0x000fac0c, 55 CRYPTO_AKM_FT_OVER_8021X_SHA384 = 0x000fac0d, 56 CRYPTO_AKM_FILS_SHA256 = 0x000fac0e, 57 CRYPTO_AKM_FILS_SHA384 = 0x000fac0f, 58 CRYPTO_AKM_FT_OVER_FILS_SHA256 = 0x000fac10, 59 CRYPTO_AKM_FT_OVER_FILS_SHA384 = 0x000fac11, 60 CRYPTO_AKM_OWE = 0x000fac12, 61 CRYPTO_AKM_OSEN = 0x506f9a01, 62 }; 63 64 /* Min & Max reported by crypto_cipher_key_len when ignoring WEP */ 65 #define CRYPTO_MIN_GTK_LEN 16 66 #define CRYPTO_MAX_GTK_LEN 32 67 #define CRYPTO_MIN_IGTK_LEN 16 68 #define CRYPTO_MAX_IGTK_LEN 32 69 70 extern const unsigned char crypto_dh5_prime[]; 71 extern size_t crypto_dh5_prime_size; 72 extern const unsigned char crypto_dh5_generator[]; 73 extern size_t crypto_dh5_generator_size; 74 75 bool hmac_md5(const void *key, size_t key_len, 76 const void *data, size_t data_len, void *output, size_t size); 77 bool hmac_sha1(const void *key, size_t key_len, 78 const void *data, size_t data_len, void *output, size_t size); 79 bool hmac_sha256(const void *key, size_t key_len, 80 const void *data, size_t data_len, void *output, size_t size); 81 bool hmac_sha384(const void *key, size_t key_len, 82 const void *data, size_t data_len, void *output, size_t size); 83 bool cmac_aes(const void *key, size_t key_len, 84 const void *data, size_t data_len, void *output, size_t size); 85 86 bool aes_unwrap(const uint8_t *kek, size_t kek_len, const uint8_t *in, size_t len, 87 uint8_t *out); 88 bool aes_wrap(const uint8_t *kek, const uint8_t *in, size_t len, uint8_t *out); 89 bool arc4_skip(const uint8_t *key, size_t key_len, size_t skip, 90 const uint8_t *in, size_t len, uint8_t *out); 91 92 bool aes_siv_encrypt(const void *key, size_t key_len, const void *in, 93 size_t in_len, struct iovec *ad, size_t num_ad, 94 void *out); 95 bool aes_siv_decrypt(const void *key, size_t key_len, const void *in, 96 size_t in_len, struct iovec *ad, size_t num_ad, 97 void *out); 98 99 int crypto_cipher_key_len(enum crypto_cipher cipher); 100 int crypto_cipher_tk_bits(enum crypto_cipher cipher); 101 102 bool crypto_passphrase_is_valid(const char *passphrase); 103 104 int crypto_psk_from_passphrase(const char *passphrase, 105 const unsigned char *ssid, size_t ssid_len, 106 unsigned char *out_psk); 107 108 bool crypto_kdf(enum l_checksum_type type, const void *key, size_t key_len, 109 const void *prefix, size_t prefix_len, 110 const void *data, size_t data_len, void *output, size_t size); 111 bool kdf_sha256(const void *key, size_t key_len, 112 const void *prefix, size_t prefix_len, 113 const void *data, size_t data_len, void *output, size_t size); 114 bool kdf_sha384(const void *key, size_t key_len, 115 const void *prefix, size_t prefix_len, 116 const void *data, size_t data_len, void *output, size_t size); 117 bool prf_sha1(const void *key, size_t key_len, 118 const void *prefix, size_t prefix_len, 119 const void *data, size_t data_len, void *output, size_t size); 120 bool prf_plus_sha1(const void *key, size_t key_len, 121 const void *prefix, size_t prefix_len, 122 const void *data, size_t data_len, void *output, size_t size); 123 124 bool prf_plus(enum l_checksum_type type, const void *key, size_t key_len, 125 void *out, size_t out_len, 126 size_t n_extra, ...); 127 128 bool hkdf_extract(enum l_checksum_type type, const void *key, size_t key_len, 129 uint8_t num_args, void *out, ...); 130 131 bool hkdf_expand(enum l_checksum_type type, const void *key, size_t key_len, 132 const char *info, void *out, size_t out_len); 133 134 bool crypto_derive_pairwise_ptk(const uint8_t *pmk, size_t pmk_len, 135 const uint8_t *addr1, const uint8_t *addr2, 136 const uint8_t *nonce1, const uint8_t *nonce2, 137 uint8_t *out_ptk, size_t ptk_len, 138 enum l_checksum_type type); 139 140 bool crypto_derive_pmk_r0(const uint8_t *xxkey, size_t xxkey_len, 141 const uint8_t *ssid, size_t ssid_len, 142 uint16_t mdid, 143 const uint8_t *r0khid, size_t r0kh_len, 144 const uint8_t *s0khid, bool sha384, 145 uint8_t *out_pmk_r0, uint8_t *out_pmk_r0_name); 146 bool crypto_derive_pmk_r1(const uint8_t *pmk_r0, 147 const uint8_t *r1khid, const uint8_t *s1khid, 148 const uint8_t *pmk_r0_name, bool sha384, 149 uint8_t *out_pmk_r1, 150 uint8_t *out_pmk_r1_name); 151 bool crypto_derive_ft_ptk(const uint8_t *pmk_r1, const uint8_t *pmk_r1_name, 152 const uint8_t *addr1, const uint8_t *addr2, 153 const uint8_t *nonce1, const uint8_t *nonce2, 154 bool sha384, uint8_t *out_ptk, size_t ptk_len, 155 uint8_t *out_ptk_name); 156 157 bool crypto_derive_pmkid(const uint8_t *pmk, size_t key_len, 158 const uint8_t *addr1, const uint8_t *addr2, 159 uint8_t *out_pmkid, 160 enum l_checksum_type checksum); 161 162 enum crypto_sae { 163 CRYPTO_SAE_LOOPING, 164 CRYPTO_SAE_HASH_TO_ELEMENT, 165 }; 166 167 enum l_checksum_type crypto_sae_hash_from_ecc_prime_len(enum crypto_sae type, 168 size_t prime_len); 169 struct l_ecc_point *crypto_derive_sae_pt_ecc(unsigned int group, 170 const char *ssid, 171 const char *password, 172 const char *identifier); 173 struct l_ecc_point *crypto_derive_sae_pwe_from_pt_ecc(const uint8_t *mac1, 174 const uint8_t *mac2, 175 const struct l_ecc_point *pt);