2 * Wrapper functions for crypto libraries
3 * Copyright (c) 2004-2013, Jouni Malinen <j@w1.fi>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
8 * This file defines the cryptographic functions that need to be implemented
9 * for wpa_supplicant and hostapd. When TLS is not used, internal
10 * implementation of MD5, SHA1, and AES is used and no external libraries are
11 * required. When TLS is enabled (e.g., by enabling EAP-TLS or EAP-PEAP), the
12 * crypto library used by the TLS implementation is expected to be used for
13 * non-TLS needs, too, in order to save space by not implementing these
16 * Wrapper code for using each crypto library is in its own file (crypto*.c)
17 * and one of these files is build and linked in to provide the functions
30 * md4_vector - MD4 hash for data vector
31 * @num_elem: Number of elements in the data vector
32 * @addr: Pointers to the data areas
33 * @len: Lengths of the data blocks
34 * @mac: Buffer for the hash
35 * Returns: 0 on success, -1 on failure
37 int md4_vector(size_t num_elem, const u8 *addr[], const size_t *len, u8 *mac);
40 * md5_vector - MD5 hash for data vector
41 * @num_elem: Number of elements in the data vector
42 * @addr: Pointers to the data areas
43 * @len: Lengths of the data blocks
44 * @mac: Buffer for the hash
45 * Returns: 0 on success, -1 on failure
47 int md5_vector(size_t num_elem, const u8 *addr[], const size_t *len, u8 *mac);
51 * sha1_vector - SHA-1 hash for data vector
52 * @num_elem: Number of elements in the data vector
53 * @addr: Pointers to the data areas
54 * @len: Lengths of the data blocks
55 * @mac: Buffer for the hash
56 * Returns: 0 on success, -1 on failure
58 int sha1_vector(size_t num_elem, const u8 *addr[], const size_t *len,
62 * fips186_2-prf - NIST FIPS Publication 186-2 change notice 1 PRF
63 * @seed: Seed/key for the PRF
64 * @seed_len: Seed length in bytes
65 * @x: Buffer for PRF output
66 * @xlen: Output length in bytes
67 * Returns: 0 on success, -1 on failure
69 * This function implements random number generation specified in NIST FIPS
70 * Publication 186-2 for EAP-SIM. This PRF uses a function that is similar to
71 * SHA-1, but has different message padding.
73 int __must_check fips186_2_prf(const u8 *seed, size_t seed_len, u8 *x,
77 * sha256_vector - SHA256 hash for data vector
78 * @num_elem: Number of elements in the data vector
79 * @addr: Pointers to the data areas
80 * @len: Lengths of the data blocks
81 * @mac: Buffer for the hash
82 * Returns: 0 on success, -1 on failure
84 int sha256_vector(size_t num_elem, const u8 *addr[], const size_t *len,
88 * des_encrypt - Encrypt one block with DES
89 * @clear: 8 octets (in)
90 * @key: 7 octets (in) (no parity bits included)
91 * @cypher: 8 octets (out)
93 void des_encrypt(const u8 *clear, const u8 *key, u8 *cypher);
96 * aes_encrypt_init - Initialize AES for encryption
97 * @key: Encryption key
98 * @len: Key length in bytes (usually 16, i.e., 128 bits)
99 * Returns: Pointer to context data or %NULL on failure
101 void * aes_encrypt_init(const u8 *key, size_t len);
104 * aes_encrypt - Encrypt one AES block
105 * @ctx: Context pointer from aes_encrypt_init()
106 * @plain: Plaintext data to be encrypted (16 bytes)
107 * @crypt: Buffer for the encrypted data (16 bytes)
109 void aes_encrypt(void *ctx, const u8 *plain, u8 *crypt);
112 * aes_encrypt_deinit - Deinitialize AES encryption
113 * @ctx: Context pointer from aes_encrypt_init()
115 void aes_encrypt_deinit(void *ctx);
118 * aes_decrypt_init - Initialize AES for decryption
119 * @key: Decryption key
120 * @len: Key length in bytes (usually 16, i.e., 128 bits)
121 * Returns: Pointer to context data or %NULL on failure
123 void * aes_decrypt_init(const u8 *key, size_t len);
126 * aes_decrypt - Decrypt one AES block
127 * @ctx: Context pointer from aes_encrypt_init()
128 * @crypt: Encrypted data (16 bytes)
129 * @plain: Buffer for the decrypted data (16 bytes)
131 void aes_decrypt(void *ctx, const u8 *crypt, u8 *plain);
134 * aes_decrypt_deinit - Deinitialize AES decryption
135 * @ctx: Context pointer from aes_encrypt_init()
137 void aes_decrypt_deinit(void *ctx);
140 enum crypto_hash_alg {
141 CRYPTO_HASH_ALG_MD5, CRYPTO_HASH_ALG_SHA1,
142 CRYPTO_HASH_ALG_HMAC_MD5, CRYPTO_HASH_ALG_HMAC_SHA1,
143 CRYPTO_HASH_ALG_SHA256, CRYPTO_HASH_ALG_HMAC_SHA256
149 * crypto_hash_init - Initialize hash/HMAC function
150 * @alg: Hash algorithm
151 * @key: Key for keyed hash (e.g., HMAC) or %NULL if not needed
152 * @key_len: Length of the key in bytes
153 * Returns: Pointer to hash context to use with other hash functions or %NULL
156 * This function is only used with internal TLSv1 implementation
157 * (CONFIG_TLS=internal). If that is not used, the crypto wrapper does not need
160 struct crypto_hash * crypto_hash_init(enum crypto_hash_alg alg, const u8 *key,
164 * crypto_hash_update - Add data to hash calculation
165 * @ctx: Context pointer from crypto_hash_init()
166 * @data: Data buffer to add
167 * @len: Length of the buffer
169 * This function is only used with internal TLSv1 implementation
170 * (CONFIG_TLS=internal). If that is not used, the crypto wrapper does not need
173 void crypto_hash_update(struct crypto_hash *ctx, const u8 *data, size_t len);
176 * crypto_hash_finish - Complete hash calculation
177 * @ctx: Context pointer from crypto_hash_init()
178 * @hash: Buffer for hash value or %NULL if caller is just freeing the hash
180 * @len: Pointer to length of the buffer or %NULL if caller is just freeing the
181 * hash context; on return, this is set to the actual length of the hash value
182 * Returns: 0 on success, -1 if buffer is too small (len set to needed length),
183 * or -2 on other failures (including failed crypto_hash_update() operations)
185 * This function calculates the hash value and frees the context buffer that
186 * was used for hash calculation.
188 * This function is only used with internal TLSv1 implementation
189 * (CONFIG_TLS=internal). If that is not used, the crypto wrapper does not need
192 int crypto_hash_finish(struct crypto_hash *ctx, u8 *hash, size_t *len);
195 enum crypto_cipher_alg {
196 CRYPTO_CIPHER_NULL = 0, CRYPTO_CIPHER_ALG_AES, CRYPTO_CIPHER_ALG_3DES,
197 CRYPTO_CIPHER_ALG_DES, CRYPTO_CIPHER_ALG_RC2, CRYPTO_CIPHER_ALG_RC4
200 struct crypto_cipher;
203 * crypto_cipher_init - Initialize block/stream cipher function
204 * @alg: Cipher algorithm
205 * @iv: Initialization vector for block ciphers or %NULL for stream ciphers
207 * @key_len: Length of key in bytes
208 * Returns: Pointer to cipher context to use with other cipher functions or
211 * This function is only used with internal TLSv1 implementation
212 * (CONFIG_TLS=internal). If that is not used, the crypto wrapper does not need
215 struct crypto_cipher * crypto_cipher_init(enum crypto_cipher_alg alg,
216 const u8 *iv, const u8 *key,
220 * crypto_cipher_encrypt - Cipher encrypt
221 * @ctx: Context pointer from crypto_cipher_init()
222 * @plain: Plaintext to cipher
223 * @crypt: Resulting ciphertext
224 * @len: Length of the plaintext
225 * Returns: 0 on success, -1 on failure
227 * This function is only used with internal TLSv1 implementation
228 * (CONFIG_TLS=internal). If that is not used, the crypto wrapper does not need
231 int __must_check crypto_cipher_encrypt(struct crypto_cipher *ctx,
232 const u8 *plain, u8 *crypt, size_t len);
235 * crypto_cipher_decrypt - Cipher decrypt
236 * @ctx: Context pointer from crypto_cipher_init()
237 * @crypt: Ciphertext to decrypt
238 * @plain: Resulting plaintext
239 * @len: Length of the cipher text
240 * Returns: 0 on success, -1 on failure
242 * This function is only used with internal TLSv1 implementation
243 * (CONFIG_TLS=internal). If that is not used, the crypto wrapper does not need
246 int __must_check crypto_cipher_decrypt(struct crypto_cipher *ctx,
247 const u8 *crypt, u8 *plain, size_t len);
250 * crypto_cipher_decrypt - Free cipher context
251 * @ctx: Context pointer from crypto_cipher_init()
253 * This function is only used with internal TLSv1 implementation
254 * (CONFIG_TLS=internal). If that is not used, the crypto wrapper does not need
257 void crypto_cipher_deinit(struct crypto_cipher *ctx);
260 struct crypto_public_key;
261 struct crypto_private_key;
264 * crypto_public_key_import - Import an RSA public key
265 * @key: Key buffer (DER encoded RSA public key)
266 * @len: Key buffer length in bytes
267 * Returns: Pointer to the public key or %NULL on failure
269 * This function can just return %NULL if the crypto library supports X.509
270 * parsing. In that case, crypto_public_key_from_cert() is used to import the
271 * public key from a certificate.
273 * This function is only used with internal TLSv1 implementation
274 * (CONFIG_TLS=internal). If that is not used, the crypto wrapper does not need
277 struct crypto_public_key * crypto_public_key_import(const u8 *key, size_t len);
279 struct crypto_public_key *
280 crypto_public_key_import_parts(const u8 *n, size_t n_len,
281 const u8 *e, size_t e_len);
284 * crypto_private_key_import - Import an RSA private key
285 * @key: Key buffer (DER encoded RSA private key)
286 * @len: Key buffer length in bytes
287 * @passwd: Key encryption password or %NULL if key is not encrypted
288 * Returns: Pointer to the private key or %NULL on failure
290 * This function is only used with internal TLSv1 implementation
291 * (CONFIG_TLS=internal). If that is not used, the crypto wrapper does not need
294 struct crypto_private_key * crypto_private_key_import(const u8 *key,
299 * crypto_public_key_from_cert - Import an RSA public key from a certificate
300 * @buf: DER encoded X.509 certificate
301 * @len: Certificate buffer length in bytes
302 * Returns: Pointer to public key or %NULL on failure
304 * This function can just return %NULL if the crypto library does not support
305 * X.509 parsing. In that case, internal code will be used to parse the
306 * certificate and public key is imported using crypto_public_key_import().
308 * This function is only used with internal TLSv1 implementation
309 * (CONFIG_TLS=internal). If that is not used, the crypto wrapper does not need
312 struct crypto_public_key * crypto_public_key_from_cert(const u8 *buf,
316 * crypto_public_key_encrypt_pkcs1_v15 - Public key encryption (PKCS #1 v1.5)
318 * @in: Plaintext buffer
319 * @inlen: Length of plaintext buffer in bytes
320 * @out: Output buffer for encrypted data
321 * @outlen: Length of output buffer in bytes; set to used length on success
322 * Returns: 0 on success, -1 on failure
324 * This function is only used with internal TLSv1 implementation
325 * (CONFIG_TLS=internal). If that is not used, the crypto wrapper does not need
328 int __must_check crypto_public_key_encrypt_pkcs1_v15(
329 struct crypto_public_key *key, const u8 *in, size_t inlen,
330 u8 *out, size_t *outlen);
333 * crypto_private_key_decrypt_pkcs1_v15 - Private key decryption (PKCS #1 v1.5)
335 * @in: Encrypted buffer
336 * @inlen: Length of encrypted buffer in bytes
337 * @out: Output buffer for encrypted data
338 * @outlen: Length of output buffer in bytes; set to used length on success
339 * Returns: 0 on success, -1 on failure
341 * This function is only used with internal TLSv1 implementation
342 * (CONFIG_TLS=internal). If that is not used, the crypto wrapper does not need
345 int __must_check crypto_private_key_decrypt_pkcs1_v15(
346 struct crypto_private_key *key, const u8 *in, size_t inlen,
347 u8 *out, size_t *outlen);
350 * crypto_private_key_sign_pkcs1 - Sign with private key (PKCS #1)
351 * @key: Private key from crypto_private_key_import()
352 * @in: Plaintext buffer
353 * @inlen: Length of plaintext buffer in bytes
354 * @out: Output buffer for encrypted (signed) data
355 * @outlen: Length of output buffer in bytes; set to used length on success
356 * Returns: 0 on success, -1 on failure
358 * This function is only used with internal TLSv1 implementation
359 * (CONFIG_TLS=internal). If that is not used, the crypto wrapper does not need
362 int __must_check crypto_private_key_sign_pkcs1(struct crypto_private_key *key,
363 const u8 *in, size_t inlen,
364 u8 *out, size_t *outlen);
367 * crypto_public_key_free - Free public key
370 * This function is only used with internal TLSv1 implementation
371 * (CONFIG_TLS=internal). If that is not used, the crypto wrapper does not need
374 void crypto_public_key_free(struct crypto_public_key *key);
377 * crypto_private_key_free - Free private key
378 * @key: Private key from crypto_private_key_import()
380 * This function is only used with internal TLSv1 implementation
381 * (CONFIG_TLS=internal). If that is not used, the crypto wrapper does not need
384 void crypto_private_key_free(struct crypto_private_key *key);
387 * crypto_public_key_decrypt_pkcs1 - Decrypt PKCS #1 signature
389 * @crypt: Encrypted signature data (using the private key)
390 * @crypt_len: Encrypted signature data length
391 * @plain: Buffer for plaintext (at least crypt_len bytes)
392 * @plain_len: Plaintext length (max buffer size on input, real len on output);
393 * Returns: 0 on success, -1 on failure
395 int __must_check crypto_public_key_decrypt_pkcs1(
396 struct crypto_public_key *key, const u8 *crypt, size_t crypt_len,
397 u8 *plain, size_t *plain_len);
400 * crypto_global_init - Initialize crypto wrapper
402 * This function is only used with internal TLSv1 implementation
403 * (CONFIG_TLS=internal). If that is not used, the crypto wrapper does not need
406 int __must_check crypto_global_init(void);
409 * crypto_global_deinit - Deinitialize crypto wrapper
411 * This function is only used with internal TLSv1 implementation
412 * (CONFIG_TLS=internal). If that is not used, the crypto wrapper does not need
415 void crypto_global_deinit(void);
418 * crypto_mod_exp - Modular exponentiation of large integers
419 * @base: Base integer (big endian byte array)
420 * @base_len: Length of base integer in bytes
421 * @power: Power integer (big endian byte array)
422 * @power_len: Length of power integer in bytes
423 * @modulus: Modulus integer (big endian byte array)
424 * @modulus_len: Length of modulus integer in bytes
425 * @result: Buffer for the result
426 * @result_len: Result length (max buffer size on input, real len on output)
427 * Returns: 0 on success, -1 on failure
429 * This function calculates result = base ^ power mod modulus. modules_len is
430 * used as the maximum size of modulus buffer. It is set to the used size on
433 * This function is only used with internal TLSv1 implementation
434 * (CONFIG_TLS=internal). If that is not used, the crypto wrapper does not need
437 int __must_check crypto_mod_exp(const u8 *base, size_t base_len,
438 const u8 *power, size_t power_len,
439 const u8 *modulus, size_t modulus_len,
440 u8 *result, size_t *result_len);
443 * rc4_skip - XOR RC4 stream to given data with skip-stream-start
445 * @keylen: RC4 key length
446 * @skip: number of bytes to skip from the beginning of the RC4 stream
447 * @data: data to be XOR'ed with RC4 stream
448 * @data_len: buf length
449 * Returns: 0 on success, -1 on failure
451 * Generate RC4 pseudo random stream for the given key, skip beginning of the
452 * stream, and XOR the end result with the data buffer to perform RC4
453 * encryption/decryption.
455 int rc4_skip(const u8 *key, size_t keylen, size_t skip,
456 u8 *data, size_t data_len);
459 * crypto_get_random - Generate cryptographically strong pseudy-random bytes
460 * @buf: Buffer for data
461 * @len: Number of bytes to generate
462 * Returns: 0 on success, -1 on failure
464 * If the PRNG does not have enough entropy to ensure unpredictable byte
465 * sequence, this functions must return -1.
467 int crypto_get_random(void *buf, size_t len);
471 * struct crypto_bignum - bignum
473 * Internal data structure for bignum implementation. The contents is specific
474 * to the used crypto library.
476 struct crypto_bignum;
479 * crypto_bignum_init - Allocate memory for bignum
480 * Returns: Pointer to allocated bignum or %NULL on failure
482 struct crypto_bignum * crypto_bignum_init(void);
485 * crypto_bignum_init_set - Allocate memory for bignum and set the value
486 * @buf: Buffer with unsigned binary value
487 * @len: Length of buf in octets
488 * Returns: Pointer to allocated bignum or %NULL on failure
490 struct crypto_bignum * crypto_bignum_init_set(const u8 *buf, size_t len);
493 * crypto_bignum_deinit - Free bignum
494 * @n: Bignum from crypto_bignum_init() or crypto_bignum_init_set()
495 * @clear: Whether to clear the value from memory
497 void crypto_bignum_deinit(struct crypto_bignum *n, int clear);
500 * crypto_bignum_to_bin - Set binary buffer to unsigned bignum
502 * @buf: Buffer for the binary number
503 * @len: Length of @buf in octets
504 * @padlen: Length in octets to pad the result to or 0 to indicate no padding
505 * Returns: Number of octets written on success, -1 on failure
507 int crypto_bignum_to_bin(const struct crypto_bignum *a,
508 u8 *buf, size_t buflen, size_t padlen);
511 * crypto_bignum_add - c = a + b
514 * @c: Bignum; used to store the result of a + b
515 * Returns: 0 on success, -1 on failure
517 int crypto_bignum_add(const struct crypto_bignum *a,
518 const struct crypto_bignum *b,
519 struct crypto_bignum *c);
522 * crypto_bignum_mod - c = a % b
525 * @c: Bignum; used to store the result of a % b
526 * Returns: 0 on success, -1 on failure
528 int crypto_bignum_mod(const struct crypto_bignum *a,
529 const struct crypto_bignum *b,
530 struct crypto_bignum *c);
533 * crypto_bignum_exptmod - Modular exponentiation: d = a^b (mod c)
535 * @b: Bignum; exponent
536 * @c: Bignum; modulus
537 * @d: Bignum; used to store the result of a^b (mod c)
538 * Returns: 0 on success, -1 on failure
540 int crypto_bignum_exptmod(const struct crypto_bignum *a,
541 const struct crypto_bignum *b,
542 const struct crypto_bignum *c,
543 struct crypto_bignum *d);
546 * crypto_bignum_inverse - Inverse a bignum so that a * c = 1 (mod b)
549 * @c: Bignum; used to store the result
550 * Returns: 0 on success, -1 on failure
552 int crypto_bignum_inverse(const struct crypto_bignum *a,
553 const struct crypto_bignum *b,
554 struct crypto_bignum *c);
557 * crypto_bignum_sub - c = a - b
560 * @c: Bignum; used to store the result of a - b
561 * Returns: 0 on success, -1 on failure
563 int crypto_bignum_sub(const struct crypto_bignum *a,
564 const struct crypto_bignum *b,
565 struct crypto_bignum *c);
568 * crypto_bignum_div - c = a / b
571 * @c: Bignum; used to store the result of a / b
572 * Returns: 0 on success, -1 on failure
574 int crypto_bignum_div(const struct crypto_bignum *a,
575 const struct crypto_bignum *b,
576 struct crypto_bignum *c);
579 * crypto_bignum_mulmod - d = a * b (mod c)
583 * @d: Bignum; used to store the result of (a * b) % c
584 * Returns: 0 on success, -1 on failure
586 int crypto_bignum_mulmod(const struct crypto_bignum *a,
587 const struct crypto_bignum *b,
588 const struct crypto_bignum *c,
589 struct crypto_bignum *d);
592 * crypto_bignum_cmp - Compare two bignums
595 * Returns: -1 if a < b, 0 if a == b, or 1 if a > b
597 int crypto_bignum_cmp(const struct crypto_bignum *a,
598 const struct crypto_bignum *b);
601 * crypto_bignum_bits - Get size of a bignum in bits
603 * Returns: Number of bits in the bignum
605 int crypto_bignum_bits(const struct crypto_bignum *a);
608 * crypto_bignum_is_zero - Is the given bignum zero
610 * Returns: 1 if @a is zero or 0 if not
612 int crypto_bignum_is_zero(const struct crypto_bignum *a);
615 * crypto_bignum_is_one - Is the given bignum one
617 * Returns: 1 if @a is one or 0 if not
619 int crypto_bignum_is_one(const struct crypto_bignum *a);
622 * crypto_bignum_legendre - Compute the Legendre symbol (a/p)
625 * Returns: Legendre symbol -1,0,1 on success; -2 on calculation failure
627 int crypto_bignum_legendre(const struct crypto_bignum *a,
628 const struct crypto_bignum *p);
631 * struct crypto_ec - Elliptic curve context
633 * Internal data structure for EC implementation. The contents is specific
634 * to the used crypto library.
639 * crypto_ec_init - Initialize elliptic curve context
640 * @group: Identifying number for the ECC group (IANA "Group Description"
641 * attribute registrty for RFC 2409)
642 * Returns: Pointer to EC context or %NULL on failure
644 struct crypto_ec * crypto_ec_init(int group);
647 * crypto_ec_deinit - Deinitialize elliptic curve context
648 * @e: EC context from crypto_ec_init()
650 void crypto_ec_deinit(struct crypto_ec *e);
653 * crypto_ec_prime_len - Get length of the prime in octets
654 * @e: EC context from crypto_ec_init()
655 * Returns: Length of the prime defining the group
657 size_t crypto_ec_prime_len(struct crypto_ec *e);
660 * crypto_ec_prime_len_bits - Get length of the prime in bits
661 * @e: EC context from crypto_ec_init()
662 * Returns: Length of the prime defining the group in bits
664 size_t crypto_ec_prime_len_bits(struct crypto_ec *e);
667 * crypto_ec_get_prime - Get prime defining an EC group
668 * @e: EC context from crypto_ec_init()
669 * Returns: Prime (bignum) defining the group
671 const struct crypto_bignum * crypto_ec_get_prime(struct crypto_ec *e);
674 * crypto_ec_get_order - Get order of an EC group
675 * @e: EC context from crypto_ec_init()
676 * Returns: Order (bignum) of the group
678 const struct crypto_bignum * crypto_ec_get_order(struct crypto_ec *e);
681 * struct crypto_ec_point - Elliptic curve point
683 * Internal data structure for EC implementation to represent a point. The
684 * contents is specific to the used crypto library.
686 struct crypto_ec_point;
689 * crypto_ec_point_init - Initialize data for an EC point
690 * @e: EC context from crypto_ec_init()
691 * Returns: Pointer to EC point data or %NULL on failure
693 struct crypto_ec_point * crypto_ec_point_init(struct crypto_ec *e);
696 * crypto_ec_point_deinit - Deinitialize EC point data
697 * @p: EC point data from crypto_ec_point_init()
698 * @clear: Whether to clear the EC point value from memory
700 void crypto_ec_point_deinit(struct crypto_ec_point *p, int clear);
703 * crypto_ec_point_to_bin - Write EC point value as binary data
704 * @e: EC context from crypto_ec_init()
705 * @p: EC point data from crypto_ec_point_init()
706 * @x: Buffer for writing the binary data for x coordinate or %NULL if not used
707 * @y: Buffer for writing the binary data for y coordinate or %NULL if not used
708 * Returns: 0 on success, -1 on failure
710 * This function can be used to write an EC point as binary data in a format
711 * that has the x and y coordinates in big endian byte order fields padded to
712 * the length of the prime defining the group.
714 int crypto_ec_point_to_bin(struct crypto_ec *e,
715 const struct crypto_ec_point *point, u8 *x, u8 *y);
718 * crypto_ec_point_from_bin - Create EC point from binary data
719 * @e: EC context from crypto_ec_init()
720 * @val: Binary data to read the EC point from
721 * Returns: Pointer to EC point data or %NULL on failure
723 * This function readers x and y coordinates of the EC point from the provided
724 * buffer assuming the values are in big endian byte order with fields padded to
725 * the length of the prime defining the group.
727 struct crypto_ec_point * crypto_ec_point_from_bin(struct crypto_ec *e,
731 * crypto_bignum_add - c = a + b
732 * @e: EC context from crypto_ec_init()
735 * @c: Bignum; used to store the result of a + b
736 * Returns: 0 on success, -1 on failure
738 int crypto_ec_point_add(struct crypto_ec *e, const struct crypto_ec_point *a,
739 const struct crypto_ec_point *b,
740 struct crypto_ec_point *c);
743 * crypto_bignum_mul - res = b * p
744 * @e: EC context from crypto_ec_init()
747 * @res: EC point; used to store the result of b * p
748 * Returns: 0 on success, -1 on failure
750 int crypto_ec_point_mul(struct crypto_ec *e, const struct crypto_ec_point *p,
751 const struct crypto_bignum *b,
752 struct crypto_ec_point *res);
755 * crypto_ec_point_invert - Compute inverse of an EC point
756 * @e: EC context from crypto_ec_init()
757 * @p: EC point to invert (and result of the operation)
758 * Returns: 0 on success, -1 on failure
760 int crypto_ec_point_invert(struct crypto_ec *e, struct crypto_ec_point *p);
763 * crypto_ec_point_solve_y_coord - Solve y coordinate for an x coordinate
764 * @e: EC context from crypto_ec_init()
765 * @p: EC point to use for the returning the result
767 * @y_bit: y-bit (0 or 1) for selecting the y value to use
768 * Returns: 0 on success, -1 on failure
770 int crypto_ec_point_solve_y_coord(struct crypto_ec *e,
771 struct crypto_ec_point *p,
772 const struct crypto_bignum *x, int y_bit);
775 * crypto_ec_point_compute_y_sqr - Compute y^2 = x^3 + ax + b
776 * @e: EC context from crypto_ec_init()
778 * Returns: y^2 on success, %NULL failure
780 struct crypto_bignum *
781 crypto_ec_point_compute_y_sqr(struct crypto_ec *e,
782 const struct crypto_bignum *x);
785 * crypto_ec_point_is_at_infinity - Check whether EC point is neutral element
786 * @e: EC context from crypto_ec_init()
788 * Returns: 1 if the specified EC point is the neutral element of the group or
791 int crypto_ec_point_is_at_infinity(struct crypto_ec *e,
792 const struct crypto_ec_point *p);
795 * crypto_ec_point_is_on_curve - Check whether EC point is on curve
796 * @e: EC context from crypto_ec_init()
798 * Returns: 1 if the specified EC point is on the curve or 0 if not
800 int crypto_ec_point_is_on_curve(struct crypto_ec *e,
801 const struct crypto_ec_point *p);
804 * crypto_ec_point_cmp - Compare two EC points
805 * @e: EC context from crypto_ec_init()
808 * Returns: 0 on equal, non-zero otherwise
810 int crypto_ec_point_cmp(const struct crypto_ec *e,
811 const struct crypto_ec_point *a,
812 const struct crypto_ec_point *b);
819 #endif /* CRYPTO_H */