wpa_supplicant / hostapd  2.5
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
crypto.h
Go to the documentation of this file.
1 
17 #ifndef CRYPTO_H
18 #define CRYPTO_H
19 
28 int md4_vector(size_t num_elem, const u8 *addr[], const size_t *len, u8 *mac);
29 
38 int md5_vector(size_t num_elem, const u8 *addr[], const size_t *len, u8 *mac);
39 
40 
49 int sha1_vector(size_t num_elem, const u8 *addr[], const size_t *len,
50  u8 *mac);
51 
64 int __must_check fips186_2_prf(const u8 *seed, size_t seed_len, u8 *x,
65  size_t xlen);
66 
75 int sha256_vector(size_t num_elem, const u8 *addr[], const size_t *len,
76  u8 *mac);
77 
84 void des_encrypt(const u8 *clear, const u8 *key, u8 *cypher);
85 
92 void * aes_encrypt_init(const u8 *key, size_t len);
93 
100 void aes_encrypt(void *ctx, const u8 *plain, u8 *crypt);
101 
106 void aes_encrypt_deinit(void *ctx);
107 
114 void * aes_decrypt_init(const u8 *key, size_t len);
115 
122 void aes_decrypt(void *ctx, const u8 *crypt, u8 *plain);
123 
128 void aes_decrypt_deinit(void *ctx);
129 
130 
131 enum crypto_hash_alg {
132  CRYPTO_HASH_ALG_MD5, CRYPTO_HASH_ALG_SHA1,
133  CRYPTO_HASH_ALG_HMAC_MD5, CRYPTO_HASH_ALG_HMAC_SHA1,
134  CRYPTO_HASH_ALG_SHA256, CRYPTO_HASH_ALG_HMAC_SHA256
135 };
136 
137 struct crypto_hash;
138 
151 struct crypto_hash * crypto_hash_init(enum crypto_hash_alg alg, const u8 *key,
152  size_t key_len);
153 
164 void crypto_hash_update(struct crypto_hash *ctx, const u8 *data, size_t len);
165 
183 int crypto_hash_finish(struct crypto_hash *ctx, u8 *hash, size_t *len);
184 
185 
186 enum crypto_cipher_alg {
187  CRYPTO_CIPHER_NULL = 0, CRYPTO_CIPHER_ALG_AES, CRYPTO_CIPHER_ALG_3DES,
188  CRYPTO_CIPHER_ALG_DES, CRYPTO_CIPHER_ALG_RC2, CRYPTO_CIPHER_ALG_RC4
189 };
190 
191 struct crypto_cipher;
192 
206 struct crypto_cipher * crypto_cipher_init(enum crypto_cipher_alg alg,
207  const u8 *iv, const u8 *key,
208  size_t key_len);
209 
222 int __must_check crypto_cipher_encrypt(struct crypto_cipher *ctx,
223  const u8 *plain, u8 *crypt, size_t len);
224 
237 int __must_check crypto_cipher_decrypt(struct crypto_cipher *ctx,
238  const u8 *crypt, u8 *plain, size_t len);
239 
248 void crypto_cipher_deinit(struct crypto_cipher *ctx);
249 
250 
251 struct crypto_public_key;
252 struct crypto_private_key;
253 
268 struct crypto_public_key * crypto_public_key_import(const u8 *key, size_t len);
269 
270 struct crypto_public_key *
271 crypto_public_key_import_parts(const u8 *n, size_t n_len,
272  const u8 *e, size_t e_len);
273 
285 struct crypto_private_key * crypto_private_key_import(const u8 *key,
286  size_t len,
287  const char *passwd);
288 
303 struct crypto_public_key * crypto_public_key_from_cert(const u8 *buf,
304  size_t len);
305 
319 int __must_check crypto_public_key_encrypt_pkcs1_v15(
320  struct crypto_public_key *key, const u8 *in, size_t inlen,
321  u8 *out, size_t *outlen);
322 
336 int __must_check crypto_private_key_decrypt_pkcs1_v15(
337  struct crypto_private_key *key, const u8 *in, size_t inlen,
338  u8 *out, size_t *outlen);
339 
353 int __must_check crypto_private_key_sign_pkcs1(struct crypto_private_key *key,
354  const u8 *in, size_t inlen,
355  u8 *out, size_t *outlen);
356 
365 void crypto_public_key_free(struct crypto_public_key *key);
366 
376 
386 int __must_check crypto_public_key_decrypt_pkcs1(
387  struct crypto_public_key *key, const u8 *crypt, size_t crypt_len,
388  u8 *plain, size_t *plain_len);
389 
398 int __must_check crypto_global_init(void);
399 
408 void crypto_global_deinit(void);
409 
430 int __must_check crypto_mod_exp(const u8 *base, size_t base_len,
431  const u8 *power, size_t power_len,
432  const u8 *modulus, size_t modulus_len,
433  u8 *result, size_t *result_len);
434 
448 int rc4_skip(const u8 *key, size_t keylen, size_t skip,
449  u8 *data, size_t data_len);
450 
460 int crypto_get_random(void *buf, size_t len);
461 
462 
470 struct crypto_bignum;
471 
476 struct crypto_bignum * crypto_bignum_init(void);
477 
484 struct crypto_bignum * crypto_bignum_init_set(const u8 *buf, size_t len);
485 
491 void crypto_bignum_deinit(struct crypto_bignum *n, int clear);
492 
501 int crypto_bignum_to_bin(const struct crypto_bignum *a,
502  u8 *buf, size_t buflen, size_t padlen);
503 
511 int crypto_bignum_add(const struct crypto_bignum *a,
512  const struct crypto_bignum *b,
513  struct crypto_bignum *c);
514 
522 int crypto_bignum_mod(const struct crypto_bignum *a,
523  const struct crypto_bignum *b,
524  struct crypto_bignum *c);
525 
534 int crypto_bignum_exptmod(const struct crypto_bignum *a,
535  const struct crypto_bignum *b,
536  const struct crypto_bignum *c,
537  struct crypto_bignum *d);
538 
546 int crypto_bignum_inverse(const struct crypto_bignum *a,
547  const struct crypto_bignum *b,
548  struct crypto_bignum *c);
549 
557 int crypto_bignum_sub(const struct crypto_bignum *a,
558  const struct crypto_bignum *b,
559  struct crypto_bignum *c);
560 
568 int crypto_bignum_div(const struct crypto_bignum *a,
569  const struct crypto_bignum *b,
570  struct crypto_bignum *c);
571 
580 int crypto_bignum_mulmod(const struct crypto_bignum *a,
581  const struct crypto_bignum *b,
582  const struct crypto_bignum *c,
583  struct crypto_bignum *d);
584 
591 int crypto_bignum_cmp(const struct crypto_bignum *a,
592  const struct crypto_bignum *b);
593 
599 int crypto_bignum_bits(const struct crypto_bignum *a);
600 
606 int crypto_bignum_is_zero(const struct crypto_bignum *a);
607 
613 int crypto_bignum_is_one(const struct crypto_bignum *a);
614 
621 int crypto_bignum_legendre(const struct crypto_bignum *a,
622  const struct crypto_bignum *p);
623 
631 struct crypto_ec;
632 
639 struct crypto_ec * crypto_ec_init(int group);
640 
645 void crypto_ec_deinit(struct crypto_ec *e);
646 
652 size_t crypto_ec_prime_len(struct crypto_ec *e);
653 
659 size_t crypto_ec_prime_len_bits(struct crypto_ec *e);
660 
666 const struct crypto_bignum * crypto_ec_get_prime(struct crypto_ec *e);
667 
673 const struct crypto_bignum * crypto_ec_get_order(struct crypto_ec *e);
674 
682 struct crypto_ec_point;
683 
689 struct crypto_ec_point * crypto_ec_point_init(struct crypto_ec *e);
690 
696 void crypto_ec_point_deinit(struct crypto_ec_point *p, int clear);
697 
710 int crypto_ec_point_to_bin(struct crypto_ec *e,
711  const struct crypto_ec_point *point, u8 *x, u8 *y);
712 
723 struct crypto_ec_point * crypto_ec_point_from_bin(struct crypto_ec *e,
724  const u8 *val);
725 
734 int crypto_ec_point_add(struct crypto_ec *e, const struct crypto_ec_point *a,
735  const struct crypto_ec_point *b,
736  struct crypto_ec_point *c);
737 
746 int crypto_ec_point_mul(struct crypto_ec *e, const struct crypto_ec_point *p,
747  const struct crypto_bignum *b,
748  struct crypto_ec_point *res);
749 
756 int crypto_ec_point_invert(struct crypto_ec *e, struct crypto_ec_point *p);
757 
766 int crypto_ec_point_solve_y_coord(struct crypto_ec *e,
767  struct crypto_ec_point *p,
768  const struct crypto_bignum *x, int y_bit);
769 
776 struct crypto_bignum *
777 crypto_ec_point_compute_y_sqr(struct crypto_ec *e,
778  const struct crypto_bignum *x);
779 
787 int crypto_ec_point_is_at_infinity(struct crypto_ec *e,
788  const struct crypto_ec_point *p);
789 
796 int crypto_ec_point_is_on_curve(struct crypto_ec *e,
797  const struct crypto_ec_point *p);
798 
806 int crypto_ec_point_cmp(const struct crypto_ec *e,
807  const struct crypto_ec_point *a,
808  const struct crypto_ec_point *b);
809 
810 #endif /* CRYPTO_H */
struct crypto_ec_point * crypto_ec_point_from_bin(struct crypto_ec *e, const u8 *val)
Create EC point from binary data.
int crypto_ec_point_invert(struct crypto_ec *e, struct crypto_ec_point *p)
Compute inverse of an EC point.
size_t crypto_ec_prime_len(struct crypto_ec *e)
Get length of the prime in octets.
void crypto_cipher_deinit(struct crypto_cipher *ctx)
Free cipher context.
Definition: crypto_gnutls.c:290
int crypto_bignum_sub(const struct crypto_bignum *a, const struct crypto_bignum *b, struct crypto_bignum *c)
c = a - b
Definition: crypto_openssl.c:1047
Definition: crypto_libtomcrypt.c:403
struct crypto_public_key * crypto_public_key_from_cert(const u8 *buf, size_t len)
Import an RSA public key from a certificate.
Definition: crypto_internal-rsa.c:60
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)
Modular exponentiation of large integers.
Definition: crypto_gnutls.c:150
int __must_check fips186_2_prf(const u8 *seed, size_t seed_len, u8 *x, size_t xlen)
NIST FIPS Publication 186-2 change notice 1 PRF.
Definition: fips_prf_internal.c:13
int crypto_ec_point_solve_y_coord(struct crypto_ec *e, struct crypto_ec_point *p, const struct crypto_bignum *x, int y_bit)
Solve y coordinate for an x coordinate.
int sha256_vector(size_t num_elem, const u8 *addr[], const size_t *len, u8 *mac)
SHA256 hash for data vector.
Definition: crypto_openssl.c:175
struct crypto_public_key * crypto_public_key_import(const u8 *key, size_t len)
Import an RSA public key.
Definition: crypto_internal-rsa.c:18
int sha1_vector(size_t num_elem, const u8 *addr[], const size_t *len, u8 *mac)
SHA-1 hash for data vector.
Definition: crypto_gnutls.c:69
size_t crypto_ec_prime_len_bits(struct crypto_ec *e)
Get length of the prime in bits.
int crypto_get_random(void *buf, size_t len)
Generate cryptographically strong pseudy-random bytes.
Definition: crypto_openssl.c:875
int crypto_ec_point_add(struct crypto_ec *e, const struct crypto_ec_point *a, const struct crypto_ec_point *b, struct crypto_ec_point *c)
c = a + b
void crypto_bignum_deinit(struct crypto_bignum *n, int clear)
Free bignum.
Definition: crypto_openssl.c:951
int rc4_skip(const u8 *key, size_t keylen, size_t skip, u8 *data, size_t data_len)
XOR RC4 stream to given data with skip-stream-start.
Definition: crypto_openssl.c:122
int __must_check crypto_cipher_decrypt(struct crypto_cipher *ctx, const u8 *crypt, u8 *plain, size_t len)
Cipher decrypt.
Definition: crypto_gnutls.c:280
struct crypto_bignum * crypto_bignum_init(void)
Allocate memory for bignum.
Definition: crypto_openssl.c:938
struct crypto_bignum * crypto_ec_point_compute_y_sqr(struct crypto_ec *e, const struct crypto_bignum *x)
Compute y^2 = x^3 + ax + b.
Definition: crypto_gnutls.c:185
void aes_decrypt_deinit(void *ctx)
Deinitialize AES decryption.
Definition: aes-internal-dec.c:153
void aes_encrypt(void *ctx, const u8 *plain, u8 *crypt)
Encrypt one AES block.
Definition: aes-internal-enc.c:111
struct crypto_ec * crypto_ec_init(int group)
Initialize elliptic curve context.
void aes_decrypt(void *ctx, const u8 *crypt, u8 *plain)
Decrypt one AES block.
Definition: aes-internal-dec.c:146
void crypto_ec_point_deinit(struct crypto_ec_point *p, int clear)
Deinitialize EC point data.
void crypto_ec_deinit(struct crypto_ec *e)
Deinitialize elliptic curve context.
void crypto_hash_update(struct crypto_hash *ctx, const u8 *data, size_t len)
Add data to hash calculation.
Definition: crypto_internal.c:121
int crypto_bignum_inverse(const struct crypto_bignum *a, const struct crypto_bignum *b, struct crypto_bignum *c)
Inverse a bignum so that a * c = 1 (mod b)
Definition: crypto_openssl.c:1029
int __must_check crypto_cipher_encrypt(struct crypto_cipher *ctx, const u8 *plain, u8 *crypt, size_t len)
Cipher encrypt.
Definition: crypto_gnutls.c:270
int crypto_bignum_add(const struct crypto_bignum *a, const struct crypto_bignum *b, struct crypto_bignum *c)
c = a + b
Definition: crypto_openssl.c:983
int crypto_hash_finish(struct crypto_hash *ctx, u8 *hash, size_t *len)
Complete hash calculation.
Definition: crypto_internal.c:147
int crypto_bignum_bits(const struct crypto_bignum *a)
Get size of a bignum in bits.
Definition: crypto_openssl.c:1102
int crypto_bignum_is_one(const struct crypto_bignum *a)
Is the given bignum one.
Definition: crypto_openssl.c:1114
struct crypto_hash * crypto_hash_init(enum crypto_hash_alg alg, const u8 *key, size_t key_len)
Initialize hash/HMAC function.
Definition: crypto_internal.c:27
void * aes_decrypt_init(const u8 *key, size_t len)
Initialize AES for decryption.
Definition: aes-internal-dec.c:55
int crypto_ec_point_is_at_infinity(struct crypto_ec *e, const struct crypto_ec_point *p)
Check whether EC point is neutral element.
int crypto_bignum_exptmod(const struct crypto_bignum *a, const struct crypto_bignum *b, const struct crypto_bignum *c, struct crypto_bignum *d)
Modular exponentiation: d = a^b (mod c)
Definition: crypto_openssl.c:1010
int crypto_ec_point_cmp(const struct crypto_ec *e, const struct crypto_ec_point *a, const struct crypto_ec_point *b)
Compare two EC points.
void crypto_private_key_free(struct crypto_private_key *key)
Free private key.
Definition: crypto_internal-rsa.c:101
struct crypto_bignum * crypto_bignum_init_set(const u8 *buf, size_t len)
Allocate memory for bignum and set the value.
Definition: crypto_openssl.c:944
int crypto_bignum_cmp(const struct crypto_bignum *a, const struct crypto_bignum *b)
Compare two bignums.
Definition: crypto_openssl.c:1095
int crypto_bignum_mod(const struct crypto_bignum *a, const struct crypto_bignum *b, struct crypto_bignum *c)
c = a % b
Definition: crypto_openssl.c:992
int crypto_bignum_is_zero(const struct crypto_bignum *a)
Is the given bignum zero.
Definition: crypto_openssl.c:1108
struct crypto_private_key * crypto_private_key_import(const u8 *key, size_t len, const char *passwd)
Import an RSA private key.
Definition: crypto_internal-rsa.c:34
void crypto_global_deinit(void)
Deinitialize crypto wrapper.
Definition: crypto_internal.c:269
int crypto_bignum_div(const struct crypto_bignum *a, const struct crypto_bignum *b, struct crypto_bignum *c)
c = a / b
Definition: crypto_openssl.c:1056
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)
Private key decryption (PKCS #1 v1.5)
Definition: crypto_internal-rsa.c:77
void * aes_encrypt_init(const u8 *key, size_t len)
Initialize AES for encryption.
Definition: aes-internal-enc.c:94
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)
Decrypt PKCS #1 signature.
Definition: crypto_internal-rsa.c:107
int __must_check crypto_private_key_sign_pkcs1(struct crypto_private_key *key, const u8 *in, size_t inlen, u8 *out, size_t *outlen)
Sign with private key (PKCS #1)
Definition: crypto_internal-rsa.c:86
void crypto_public_key_free(struct crypto_public_key *key)
Free public key.
Definition: crypto_internal-rsa.c:95
int md4_vector(size_t num_elem, const u8 *addr[], const size_t *len, u8 *mac)
MD4 hash for data vector.
Definition: crypto_gnutls.c:11
int crypto_ec_point_mul(struct crypto_ec *e, const struct crypto_ec_point *p, const struct crypto_bignum *b, struct crypto_ec_point *res)
res = b * p
const struct crypto_bignum * crypto_ec_get_prime(struct crypto_ec *e)
Get prime defining an EC group.
int md5_vector(size_t num_elem, const u8 *addr[], const size_t *len, u8 *mac)
MD5 hash for data vector.
Definition: crypto_gnutls.c:51
struct crypto_cipher * crypto_cipher_init(enum crypto_cipher_alg alg, const u8 *iv, const u8 *key, size_t key_len)
Initialize block/stream cipher function.
Definition: crypto_gnutls.c:191
Definition: crypto_internal.c:13
int __must_check crypto_global_init(void)
Initialize crypto wrapper.
Definition: crypto_internal.c:263
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)
Public key encryption (PKCS #1 v1.5)
Definition: crypto_internal-rsa.c:68
struct crypto_ec_point * crypto_ec_point_init(struct crypto_ec *e)
Initialize data for an EC point.
int crypto_ec_point_is_on_curve(struct crypto_ec *e, const struct crypto_ec_point *p)
Check whether EC point is on curve.
int crypto_bignum_mulmod(const struct crypto_bignum *a, const struct crypto_bignum *b, const struct crypto_bignum *c, struct crypto_bignum *d)
d = a * b (mod c)
Definition: crypto_openssl.c:1075
const struct crypto_bignum * crypto_ec_get_order(struct crypto_ec *e)
Get order of an EC group.
void aes_encrypt_deinit(void *ctx)
Deinitialize AES encryption.
Definition: aes-internal-enc.c:118
Definition: crypto_libtomcrypt.c:407
int crypto_ec_point_to_bin(struct crypto_ec *e, const struct crypto_ec_point *point, u8 *x, u8 *y)
Write EC point value as binary data.
int crypto_bignum_legendre(const struct crypto_bignum *a, const struct crypto_bignum *p)
Compute the Legendre symbol (a/p)
Definition: crypto_openssl.c:1120
int crypto_bignum_to_bin(const struct crypto_bignum *a, u8 *buf, size_t buflen, size_t padlen)
Set binary buffer to unsigned bignum.
Definition: crypto_openssl.c:960
void des_encrypt(const u8 *clear, const u8 *key, u8 *cypher)
Encrypt one block with DES.
Definition: crypto_gnutls.c:29