Loading...
Searching...
No Matches
crypto.h
Go to the documentation of this file.
/*
* WPA Supplicant / wrapper functions for crypto libraries
* Copyright (c) 2004-2009, Jouni Malinen <j@w1.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* Alternatively, this software may be distributed under the terms of BSD
* license.
*
* See README and COPYING for more details.
*
* This file defines the cryptographic functions that need to be implemented
* for wpa_supplicant and hostapd. When TLS is not used, internal
* implementation of MD5, SHA1, and AES is used and no external libraries are
* required. When TLS is enabled (e.g., by enabling EAP-TLS or EAP-PEAP), the
* crypto library used by the TLS implementation is expected to be used for
* non-TLS needs, too, in order to save space by not implementing these
* functions twice.
*
* Wrapper code for using each crypto library is in its own file (crypto*.c)
* and one of these files is build and linked in to provide the functions
* defined here.
*/
#ifndef CRYPTO_H
#define CRYPTO_H
int md4_vector(size_t num_elem, const u8 *addr[], const size_t *len, u8 *mac);
int md5_vector(size_t num_elem, const u8 *addr[], const size_t *len, u8 *mac);
#ifdef CONFIG_FIPS
int md5_vector_non_fips_allow(size_t num_elem, const u8 *addr[],
const size_t *len, u8 *mac);
#else /* CONFIG_FIPS */
#define md5_vector_non_fips_allow md5_vector
#endif /* CONFIG_FIPS */
int sha1_vector(size_t num_elem, const u8 *addr[], const size_t *len,
u8 *mac);
int __must_check fips186_2_prf(const u8 *seed, size_t seed_len, u8 *x,
size_t xlen);
int sha256_vector(size_t num_elem, const u8 *addr[], const size_t *len,
u8 *mac);
void des_encrypt(const u8 *clear, const u8 *key, u8 *cypher);
void * aes_encrypt_init(const u8 *key, size_t len);
void aes_encrypt(void *ctx, const u8 *plain, u8 *crypt);
void aes_encrypt_deinit(void *ctx);
void * aes_decrypt_init(const u8 *key, size_t len);
void aes_decrypt(void *ctx, const u8 *crypt, u8 *plain);
void aes_decrypt_deinit(void *ctx);
enum crypto_hash_alg {
CRYPTO_HASH_ALG_MD5, CRYPTO_HASH_ALG_SHA1,
CRYPTO_HASH_ALG_HMAC_MD5, CRYPTO_HASH_ALG_HMAC_SHA1,
CRYPTO_HASH_ALG_SHA256, CRYPTO_HASH_ALG_HMAC_SHA256
};
struct crypto_hash;
struct crypto_hash * crypto_hash_init(enum crypto_hash_alg alg, const u8 *key,
size_t key_len);
void crypto_hash_update(struct crypto_hash *ctx, const u8 *data, size_t len);
int crypto_hash_finish(struct crypto_hash *ctx, u8 *hash, size_t *len);
enum crypto_cipher_alg {
CRYPTO_CIPHER_NULL = 0, CRYPTO_CIPHER_ALG_AES, CRYPTO_CIPHER_ALG_3DES,
CRYPTO_CIPHER_ALG_DES, CRYPTO_CIPHER_ALG_RC2, CRYPTO_CIPHER_ALG_RC4
};
struct crypto_cipher;
struct crypto_cipher * crypto_cipher_init(enum crypto_cipher_alg alg,
const u8 *iv, const u8 *key,
size_t key_len);
int __must_check crypto_cipher_encrypt(struct crypto_cipher *ctx,
const u8 *plain, u8 *crypt, size_t len);
int __must_check crypto_cipher_decrypt(struct crypto_cipher *ctx,
const u8 *crypt, u8 *plain, size_t len);
void crypto_cipher_deinit(struct crypto_cipher *ctx);
struct crypto_public_key;
struct crypto_private_key;
struct crypto_public_key * crypto_public_key_import(const u8 *key, size_t len);
struct crypto_private_key * crypto_private_key_import(const u8 *key,
size_t len,
const char *passwd);
struct crypto_public_key * crypto_public_key_from_cert(const u8 *buf,
size_t len);
int __must_check crypto_public_key_encrypt_pkcs1_v15(
struct crypto_public_key *key, const u8 *in, size_t inlen,
u8 *out, size_t *outlen);
int __must_check crypto_private_key_decrypt_pkcs1_v15(
struct crypto_private_key *key, const u8 *in, size_t inlen,
u8 *out, size_t *outlen);
int __must_check crypto_private_key_sign_pkcs1(struct crypto_private_key *key,
const u8 *in, size_t inlen,
u8 *out, size_t *outlen);
void crypto_public_key_free(struct crypto_public_key *key);
void crypto_private_key_free(struct crypto_private_key *key);
int __must_check crypto_public_key_decrypt_pkcs1(
struct crypto_public_key *key, const u8 *crypt, size_t crypt_len,
u8 *plain, size_t *plain_len);
int __must_check crypto_global_init(void);
void crypto_global_deinit(void);
int __must_check crypto_mod_exp(const u8 *base, size_t base_len,
const u8 *power, size_t power_len,
const u8 *modulus, size_t modulus_len,
u8 *result, size_t *result_len);
int rc4_skip(const u8 *key, size_t keylen, size_t skip,
u8 *data, size_t data_len);
#endif /* CRYPTO_H */
len
uint8_t len
Definition gsm_04_11.h:0
u8
uint8_t u8
Definition common.h:27
__must_check
#define __must_check
Definition common.h:101
crypto_hash_finish
int crypto_hash_finish(struct crypto_hash *ctx, u8 *hash, size_t *len)
crypto_hash_finish - Complete hash calculation @ctx: Context pointer from crypto_hash_init() @hash: B...
crypto_mod_exp
int __must_check crypto_mod_exp(const u8 *base, size_t base_len, const u8 *power, size_t power_len, const u8 *modulus, size_t modulus_len, u8 *result, size_t *result_len)
crypto_mod_exp - Modular exponentiation of large integers @base: Base integer (big endian byte array)...
crypto_global_deinit
void crypto_global_deinit(void)
crypto_global_deinit - Deinitialize crypto wrapper
crypto_hash_update
void crypto_hash_update(struct crypto_hash *ctx, const u8 *data, size_t len)
crypto_hash_update - Add data to hash calculation @ctx: Context pointer from crypto_hash_init() @data...
sha256_vector
int sha256_vector(size_t num_elem, const u8 *addr[], const size_t *len, u8 *mac)
sha256_vector - SHA256 hash for data vector @num_elem: Number of elements in the data vector @addr: P...
Definition sha256-internal.c:30
crypto_cipher_deinit
void crypto_cipher_deinit(struct crypto_cipher *ctx)
crypto_cipher_decrypt - Free cipher context @ctx: Context pointer from crypto_cipher_init()
crypto_private_key_decrypt_pkcs1_v15
int __must_check crypto_private_key_decrypt_pkcs1_v15(struct crypto_private_key *key, const u8 *in, size_t inlen, u8 *out, size_t *outlen)
crypto_private_key_decrypt_pkcs1_v15 - Private key decryption (PKCS #1 v1.5) @key: Private key @in: E...
md4_vector
int md4_vector(size_t num_elem, const u8 *addr[], const size_t *len, u8 *mac)
md4_vector - MD4 hash for data vector @num_elem: Number of elements in the data vector @addr: Pointer...
aes_encrypt_init
void * aes_encrypt_init(const u8 *key, size_t len)
aes_encrypt_init - Initialize AES for encryption @key: Encryption key @len: Key length in bytes (usua...
Definition aes-internal-enc.c:101
aes_encrypt_deinit
void aes_encrypt_deinit(void *ctx)
aes_encrypt_deinit - Deinitialize AES encryption @ctx: Context pointer from aes_encrypt_init()
Definition aes-internal-enc.c:120
crypto_hash_alg
crypto_hash_alg
Definition crypto.h:156
CRYPTO_HASH_ALG_HMAC_SHA256
@ CRYPTO_HASH_ALG_HMAC_SHA256
Definition crypto.h:159
CRYPTO_HASH_ALG_SHA1
@ CRYPTO_HASH_ALG_SHA1
Definition crypto.h:157
CRYPTO_HASH_ALG_SHA256
@ CRYPTO_HASH_ALG_SHA256
Definition crypto.h:159
CRYPTO_HASH_ALG_HMAC_MD5
@ CRYPTO_HASH_ALG_HMAC_MD5
Definition crypto.h:158
CRYPTO_HASH_ALG_MD5
@ CRYPTO_HASH_ALG_MD5
Definition crypto.h:157
CRYPTO_HASH_ALG_HMAC_SHA1
@ CRYPTO_HASH_ALG_HMAC_SHA1
Definition crypto.h:158
md5_vector
int md5_vector(size_t num_elem, const u8 *addr[], const size_t *len, u8 *mac)
md5_vector - MD5 hash for data vector @num_elem: Number of elements in the data vector @addr: Pointer...
crypto_global_init
int __must_check crypto_global_init(void)
crypto_global_init - Initialize crypto wrapper
crypto_cipher_alg
crypto_cipher_alg
Definition crypto.h:211
CRYPTO_CIPHER_ALG_RC2
@ CRYPTO_CIPHER_ALG_RC2
Definition crypto.h:213
CRYPTO_CIPHER_ALG_DES
@ CRYPTO_CIPHER_ALG_DES
Definition crypto.h:213
CRYPTO_CIPHER_ALG_AES
@ CRYPTO_CIPHER_ALG_AES
Definition crypto.h:212
CRYPTO_CIPHER_ALG_3DES
@ CRYPTO_CIPHER_ALG_3DES
Definition crypto.h:212
CRYPTO_CIPHER_ALG_RC4
@ CRYPTO_CIPHER_ALG_RC4
Definition crypto.h:213
CRYPTO_CIPHER_NULL
@ CRYPTO_CIPHER_NULL
Definition crypto.h:212
rc4_skip
int rc4_skip(const u8 *key, size_t keylen, size_t skip, u8 *data, size_t data_len)
rc4_skip - XOR RC4 stream to given data with skip-stream-start @key: RC4 key @keylen: RC4 key length ...
crypto_cipher_init
struct crypto_cipher * crypto_cipher_init(enum crypto_cipher_alg alg, const u8 *iv, const u8 *key, size_t key_len)
crypto_cipher_init - Initialize block/stream cipher function @alg: Cipher algorithm @iv: Initializati...
crypto_public_key_from_cert
struct crypto_public_key * crypto_public_key_from_cert(const u8 *buf, size_t len)
crypto_public_key_from_cert - Import an RSA public key from a certificate @buf: DER encoded X....
md5_vector_non_fips_allow
#define md5_vector_non_fips_allow
Definition crypto.h:62
crypto_public_key_free
void crypto_public_key_free(struct crypto_public_key *key)
crypto_public_key_free - Free public key @key: Public key
crypto_cipher_decrypt
int __must_check crypto_cipher_decrypt(struct crypto_cipher *ctx, const u8 *crypt, u8 *plain, size_t len)
crypto_cipher_decrypt - Cipher decrypt @ctx: Context pointer from crypto_cipher_init() @crypt: Cipher...
des_encrypt
void des_encrypt(const u8 *clear, const u8 *key, u8 *cypher)
des_encrypt - Encrypt one block with DES @clear: 8 octets (in) @key: 7 octets (in) (no parity bits in...
crypto_private_key_sign_pkcs1
int __must_check crypto_private_key_sign_pkcs1(struct crypto_private_key *key, const u8 *in, size_t inlen, u8 *out, size_t *outlen)
crypto_private_key_sign_pkcs1 - Sign with private key (PKCS #1) @key: Private key from crypto_private...
aes_encrypt
void aes_encrypt(void *ctx, const u8 *plain, u8 *crypt)
aes_encrypt - Encrypt one AES block @ctx: Context pointer from aes_encrypt_init() @plain: Plaintext d...
Definition aes-internal-enc.c:114
crypto_private_key_free
void crypto_private_key_free(struct crypto_private_key *key)
crypto_private_key_free - Free private key @key: Private key from crypto_private_key_import()
sha1_vector
int sha1_vector(size_t num_elem, const u8 *addr[], const size_t *len, u8 *mac)
sha1_vector - SHA-1 hash for data vector @num_elem: Number of elements in the data vector @addr: Poin...
Definition sha1-internal.c:35
crypto_public_key_decrypt_pkcs1
int __must_check crypto_public_key_decrypt_pkcs1(struct crypto_public_key *key, const u8 *crypt, size_t crypt_len, u8 *plain, size_t *plain_len)
crypto_public_key_decrypt_pkcs1 - Decrypt PKCS #1 signature @key: Public key @crypt: Encrypted signat...
aes_decrypt_deinit
void aes_decrypt_deinit(void *ctx)
aes_decrypt_deinit - Deinitialize AES decryption @ctx: Context pointer from aes_encrypt_init()
crypto_public_key_encrypt_pkcs1_v15
int __must_check crypto_public_key_encrypt_pkcs1_v15(struct crypto_public_key *key, const u8 *in, size_t inlen, u8 *out, size_t *outlen)
crypto_public_key_encrypt_pkcs1_v15 - Public key encryption (PKCS #1 v1.5) @key: Public key @in: Plai...
crypto_public_key_import
struct crypto_public_key * crypto_public_key_import(const u8 *key, size_t len)
crypto_public_key_import - Import an RSA public key @key: Key buffer (DER encoded RSA public key) @le...
crypto_hash_init
struct crypto_hash * crypto_hash_init(enum crypto_hash_alg alg, const u8 *key, size_t key_len)
crypto_hash_init - Initialize hash/HMAC function @alg: Hash algorithm @key: Key for keyed hash (e....
fips186_2_prf
int __must_check fips186_2_prf(const u8 *seed, size_t seed_len, u8 *x, size_t xlen)
fips186_2-prf - NIST FIPS Publication 186-2 change notice 1 PRF @seed: Seed/key for the PRF @seed_len...
aes_decrypt
void aes_decrypt(void *ctx, const u8 *crypt, u8 *plain)
aes_decrypt - Decrypt one AES block @ctx: Context pointer from aes_encrypt_init() @crypt: Encrypted d...
crypto_private_key_import
struct crypto_private_key * crypto_private_key_import(const u8 *key, size_t len, const char *passwd)
crypto_private_key_import - Import an RSA private key @key: Key buffer (DER encoded RSA private key) ...
crypto_cipher_encrypt
int __must_check crypto_cipher_encrypt(struct crypto_cipher *ctx, const u8 *plain, u8 *crypt, size_t len)
crypto_cipher_encrypt - Cipher encrypt @ctx: Context pointer from crypto_cipher_init() @plain: Plaint...
aes_decrypt_init
void * aes_decrypt_init(const u8 *key, size_t len)
aes_decrypt_init - Initialize AES for decryption @key: Decryption key @len: Key length in bytes (usua...