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 * sha384_vector - SHA384 hash for data vector
89 * @num_elem: Number of elements in the data vector
90 * @addr: Pointers to the data areas
91 * @len: Lengths of the data blocks
92 * @mac: Buffer for the hash
93 * Returns: 0 on success, -1 on failure
95 int sha384_vector(size_t num_elem, const u8 *addr[], const size_t *len,
99 * sha512_vector - SHA512 hash for data vector
100 * @num_elem: Number of elements in the data vector
101 * @addr: Pointers to the data areas
102 * @len: Lengths of the data blocks
103 * @mac: Buffer for the hash
104 * Returns: 0 on success, -1 on failure
106 int sha512_vector(size_t num_elem, const u8 *addr[], const size_t *len,
110 * des_encrypt - Encrypt one block with DES
111 * @clear: 8 octets (in)
112 * @key: 7 octets (in) (no parity bits included)
113 * @cypher: 8 octets (out)
115 void des_encrypt(const u8 *clear, const u8 *key, u8 *cypher);
118 * aes_encrypt_init - Initialize AES for encryption
119 * @key: Encryption 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_encrypt_init(const u8 *key, size_t len);
126 * aes_encrypt - Encrypt one AES block
127 * @ctx: Context pointer from aes_encrypt_init()
128 * @plain: Plaintext data to be encrypted (16 bytes)
129 * @crypt: Buffer for the encrypted data (16 bytes)
131 void aes_encrypt(void *ctx, const u8 *plain, u8 *crypt);
134 * aes_encrypt_deinit - Deinitialize AES encryption
135 * @ctx: Context pointer from aes_encrypt_init()
137 void aes_encrypt_deinit(void *ctx);
140 * aes_decrypt_init - Initialize AES for decryption
141 * @key: Decryption key
142 * @len: Key length in bytes (usually 16, i.e., 128 bits)
143 * Returns: Pointer to context data or %NULL on failure
145 void * aes_decrypt_init(const u8 *key, size_t len);
148 * aes_decrypt - Decrypt one AES block
149 * @ctx: Context pointer from aes_encrypt_init()
150 * @crypt: Encrypted data (16 bytes)
151 * @plain: Buffer for the decrypted data (16 bytes)
153 void aes_decrypt(void *ctx, const u8 *crypt, u8 *plain);
156 * aes_decrypt_deinit - Deinitialize AES decryption
157 * @ctx: Context pointer from aes_encrypt_init()
159 void aes_decrypt_deinit(void *ctx);
162 enum crypto_hash_alg {
163 CRYPTO_HASH_ALG_MD5, CRYPTO_HASH_ALG_SHA1,
164 CRYPTO_HASH_ALG_HMAC_MD5, CRYPTO_HASH_ALG_HMAC_SHA1,
165 CRYPTO_HASH_ALG_SHA256, CRYPTO_HASH_ALG_HMAC_SHA256,
166 CRYPTO_HASH_ALG_SHA384, CRYPTO_HASH_ALG_SHA512
172 * crypto_hash_init - Initialize hash/HMAC function
173 * @alg: Hash algorithm
174 * @key: Key for keyed hash (e.g., HMAC) or %NULL if not needed
175 * @key_len: Length of the key in bytes
176 * Returns: Pointer to hash context to use with other hash functions or %NULL
179 * This function is only used with internal TLSv1 implementation
180 * (CONFIG_TLS=internal). If that is not used, the crypto wrapper does not need
183 struct crypto_hash * crypto_hash_init(enum crypto_hash_alg alg, const u8 *key,
187 * crypto_hash_update - Add data to hash calculation
188 * @ctx: Context pointer from crypto_hash_init()
189 * @data: Data buffer to add
190 * @len: Length of the buffer
192 * This function is only used with internal TLSv1 implementation
193 * (CONFIG_TLS=internal). If that is not used, the crypto wrapper does not need
196 void crypto_hash_update(struct crypto_hash *ctx, const u8 *data, size_t len);
199 * crypto_hash_finish - Complete hash calculation
200 * @ctx: Context pointer from crypto_hash_init()
201 * @hash: Buffer for hash value or %NULL if caller is just freeing the hash
203 * @len: Pointer to length of the buffer or %NULL if caller is just freeing the
204 * hash context; on return, this is set to the actual length of the hash value
205 * Returns: 0 on success, -1 if buffer is too small (len set to needed length),
206 * or -2 on other failures (including failed crypto_hash_update() operations)
208 * This function calculates the hash value and frees the context buffer that
209 * was used for hash calculation.
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 int crypto_hash_finish(struct crypto_hash *ctx, u8 *hash, size_t *len);
218 enum crypto_cipher_alg {
219 CRYPTO_CIPHER_NULL = 0, CRYPTO_CIPHER_ALG_AES, CRYPTO_CIPHER_ALG_3DES,
220 CRYPTO_CIPHER_ALG_DES, CRYPTO_CIPHER_ALG_RC2, CRYPTO_CIPHER_ALG_RC4
223 struct crypto_cipher;
226 * crypto_cipher_init - Initialize block/stream cipher function
227 * @alg: Cipher algorithm
228 * @iv: Initialization vector for block ciphers or %NULL for stream ciphers
230 * @key_len: Length of key in bytes
231 * Returns: Pointer to cipher context to use with other cipher functions or
234 * This function is only used with internal TLSv1 implementation
235 * (CONFIG_TLS=internal). If that is not used, the crypto wrapper does not need
238 struct crypto_cipher * crypto_cipher_init(enum crypto_cipher_alg alg,
239 const u8 *iv, const u8 *key,
243 * crypto_cipher_encrypt - Cipher encrypt
244 * @ctx: Context pointer from crypto_cipher_init()
245 * @plain: Plaintext to cipher
246 * @crypt: Resulting ciphertext
247 * @len: Length of the plaintext
248 * Returns: 0 on success, -1 on failure
250 * This function is only used with internal TLSv1 implementation
251 * (CONFIG_TLS=internal). If that is not used, the crypto wrapper does not need
254 int __must_check crypto_cipher_encrypt(struct crypto_cipher *ctx,
255 const u8 *plain, u8 *crypt, size_t len);
258 * crypto_cipher_decrypt - Cipher decrypt
259 * @ctx: Context pointer from crypto_cipher_init()
260 * @crypt: Ciphertext to decrypt
261 * @plain: Resulting plaintext
262 * @len: Length of the cipher text
263 * Returns: 0 on success, -1 on failure
265 * This function is only used with internal TLSv1 implementation
266 * (CONFIG_TLS=internal). If that is not used, the crypto wrapper does not need
269 int __must_check crypto_cipher_decrypt(struct crypto_cipher *ctx,
270 const u8 *crypt, u8 *plain, size_t len);
273 * crypto_cipher_decrypt - Free cipher context
274 * @ctx: Context pointer from crypto_cipher_init()
276 * This function is only used with internal TLSv1 implementation
277 * (CONFIG_TLS=internal). If that is not used, the crypto wrapper does not need
280 void crypto_cipher_deinit(struct crypto_cipher *ctx);
283 struct crypto_public_key;
284 struct crypto_private_key;
287 * crypto_public_key_import - Import an RSA public key
288 * @key: Key buffer (DER encoded RSA public key)
289 * @len: Key buffer length in bytes
290 * Returns: Pointer to the public key or %NULL on failure
292 * This function can just return %NULL if the crypto library supports X.509
293 * parsing. In that case, crypto_public_key_from_cert() is used to import the
294 * public key from a certificate.
296 * This function is only used with internal TLSv1 implementation
297 * (CONFIG_TLS=internal). If that is not used, the crypto wrapper does not need
300 struct crypto_public_key * crypto_public_key_import(const u8 *key, size_t len);
302 struct crypto_public_key *
303 crypto_public_key_import_parts(const u8 *n, size_t n_len,
304 const u8 *e, size_t e_len);
307 * crypto_private_key_import - Import an RSA private key
308 * @key: Key buffer (DER encoded RSA private key)
309 * @len: Key buffer length in bytes
310 * @passwd: Key encryption password or %NULL if key is not encrypted
311 * Returns: Pointer to the private key or %NULL on failure
313 * This function is only used with internal TLSv1 implementation
314 * (CONFIG_TLS=internal). If that is not used, the crypto wrapper does not need
317 struct crypto_private_key * crypto_private_key_import(const u8 *key,
322 * crypto_public_key_from_cert - Import an RSA public key from a certificate
323 * @buf: DER encoded X.509 certificate
324 * @len: Certificate buffer length in bytes
325 * Returns: Pointer to public key or %NULL on failure
327 * This function can just return %NULL if the crypto library does not support
328 * X.509 parsing. In that case, internal code will be used to parse the
329 * certificate and public key is imported using crypto_public_key_import().
331 * This function is only used with internal TLSv1 implementation
332 * (CONFIG_TLS=internal). If that is not used, the crypto wrapper does not need
335 struct crypto_public_key * crypto_public_key_from_cert(const u8 *buf,
339 * crypto_public_key_encrypt_pkcs1_v15 - Public key encryption (PKCS #1 v1.5)
341 * @in: Plaintext buffer
342 * @inlen: Length of plaintext buffer in bytes
343 * @out: Output buffer for encrypted data
344 * @outlen: Length of output buffer in bytes; set to used length on success
345 * Returns: 0 on success, -1 on failure
347 * This function is only used with internal TLSv1 implementation
348 * (CONFIG_TLS=internal). If that is not used, the crypto wrapper does not need
351 int __must_check crypto_public_key_encrypt_pkcs1_v15(
352 struct crypto_public_key *key, const u8 *in, size_t inlen,
353 u8 *out, size_t *outlen);
356 * crypto_private_key_decrypt_pkcs1_v15 - Private key decryption (PKCS #1 v1.5)
358 * @in: Encrypted buffer
359 * @inlen: Length of encrypted buffer in bytes
360 * @out: Output buffer for encrypted data
361 * @outlen: Length of output buffer in bytes; set to used length on success
362 * Returns: 0 on success, -1 on failure
364 * This function is only used with internal TLSv1 implementation
365 * (CONFIG_TLS=internal). If that is not used, the crypto wrapper does not need
368 int __must_check crypto_private_key_decrypt_pkcs1_v15(
369 struct crypto_private_key *key, const u8 *in, size_t inlen,
370 u8 *out, size_t *outlen);
373 * crypto_private_key_sign_pkcs1 - Sign with private key (PKCS #1)
374 * @key: Private key from crypto_private_key_import()
375 * @in: Plaintext buffer
376 * @inlen: Length of plaintext buffer in bytes
377 * @out: Output buffer for encrypted (signed) data
378 * @outlen: Length of output buffer in bytes; set to used length on success
379 * Returns: 0 on success, -1 on failure
381 * This function is only used with internal TLSv1 implementation
382 * (CONFIG_TLS=internal). If that is not used, the crypto wrapper does not need
385 int __must_check crypto_private_key_sign_pkcs1(struct crypto_private_key *key,
386 const u8 *in, size_t inlen,
387 u8 *out, size_t *outlen);
390 * crypto_public_key_free - Free public key
393 * This function is only used with internal TLSv1 implementation
394 * (CONFIG_TLS=internal). If that is not used, the crypto wrapper does not need
397 void crypto_public_key_free(struct crypto_public_key *key);
400 * crypto_private_key_free - Free private key
401 * @key: Private key from crypto_private_key_import()
403 * This function is only used with internal TLSv1 implementation
404 * (CONFIG_TLS=internal). If that is not used, the crypto wrapper does not need
407 void crypto_private_key_free(struct crypto_private_key *key);
410 * crypto_public_key_decrypt_pkcs1 - Decrypt PKCS #1 signature
412 * @crypt: Encrypted signature data (using the private key)
413 * @crypt_len: Encrypted signature data length
414 * @plain: Buffer for plaintext (at least crypt_len bytes)
415 * @plain_len: Plaintext length (max buffer size on input, real len on output);
416 * Returns: 0 on success, -1 on failure
418 int __must_check crypto_public_key_decrypt_pkcs1(
419 struct crypto_public_key *key, const u8 *crypt, size_t crypt_len,
420 u8 *plain, size_t *plain_len);
423 * crypto_global_init - Initialize crypto wrapper
425 * This function is only used with internal TLSv1 implementation
426 * (CONFIG_TLS=internal). If that is not used, the crypto wrapper does not need
429 int __must_check crypto_global_init(void);
432 * crypto_global_deinit - Deinitialize crypto wrapper
434 * This function is only used with internal TLSv1 implementation
435 * (CONFIG_TLS=internal). If that is not used, the crypto wrapper does not need
438 void crypto_global_deinit(void);
441 * crypto_mod_exp - Modular exponentiation of large integers
442 * @base: Base integer (big endian byte array)
443 * @base_len: Length of base integer in bytes
444 * @power: Power integer (big endian byte array)
445 * @power_len: Length of power integer in bytes
446 * @modulus: Modulus integer (big endian byte array)
447 * @modulus_len: Length of modulus integer in bytes
448 * @result: Buffer for the result
449 * @result_len: Result length (max buffer size on input, real len on output)
450 * Returns: 0 on success, -1 on failure
452 * This function calculates result = base ^ power mod modulus. modules_len is
453 * used as the maximum size of modulus buffer. It is set to the used size on
456 * This function is only used with internal TLSv1 implementation
457 * (CONFIG_TLS=internal). If that is not used, the crypto wrapper does not need
460 int __must_check crypto_mod_exp(const u8 *base, size_t base_len,
461 const u8 *power, size_t power_len,
462 const u8 *modulus, size_t modulus_len,
463 u8 *result, size_t *result_len);
466 * rc4_skip - XOR RC4 stream to given data with skip-stream-start
468 * @keylen: RC4 key length
469 * @skip: number of bytes to skip from the beginning of the RC4 stream
470 * @data: data to be XOR'ed with RC4 stream
471 * @data_len: buf length
472 * Returns: 0 on success, -1 on failure
474 * Generate RC4 pseudo random stream for the given key, skip beginning of the
475 * stream, and XOR the end result with the data buffer to perform RC4
476 * encryption/decryption.
478 int rc4_skip(const u8 *key, size_t keylen, size_t skip,
479 u8 *data, size_t data_len);
482 * crypto_get_random - Generate cryptographically strong pseudy-random bytes
483 * @buf: Buffer for data
484 * @len: Number of bytes to generate
485 * Returns: 0 on success, -1 on failure
487 * If the PRNG does not have enough entropy to ensure unpredictable byte
488 * sequence, this functions must return -1.
490 int crypto_get_random(void *buf, size_t len);
494 * struct crypto_bignum - bignum
496 * Internal data structure for bignum implementation. The contents is specific
497 * to the used crypto library.
499 struct crypto_bignum;
502 * crypto_bignum_init - Allocate memory for bignum
503 * Returns: Pointer to allocated bignum or %NULL on failure
505 struct crypto_bignum * crypto_bignum_init(void);
508 * crypto_bignum_init_set - Allocate memory for bignum and set the value
509 * @buf: Buffer with unsigned binary value
510 * @len: Length of buf in octets
511 * Returns: Pointer to allocated bignum or %NULL on failure
513 struct crypto_bignum * crypto_bignum_init_set(const u8 *buf, size_t len);
516 * crypto_bignum_deinit - Free bignum
517 * @n: Bignum from crypto_bignum_init() or crypto_bignum_init_set()
518 * @clear: Whether to clear the value from memory
520 void crypto_bignum_deinit(struct crypto_bignum *n, int clear);
523 * crypto_bignum_to_bin - Set binary buffer to unsigned bignum
525 * @buf: Buffer for the binary number
526 * @len: Length of @buf in octets
527 * @padlen: Length in octets to pad the result to or 0 to indicate no padding
528 * Returns: Number of octets written on success, -1 on failure
530 int crypto_bignum_to_bin(const struct crypto_bignum *a,
531 u8 *buf, size_t buflen, size_t padlen);
534 * crypto_bignum_add - c = a + b
537 * @c: Bignum; used to store the result of a + b
538 * Returns: 0 on success, -1 on failure
540 int crypto_bignum_add(const struct crypto_bignum *a,
541 const struct crypto_bignum *b,
542 struct crypto_bignum *c);
545 * crypto_bignum_mod - c = a % b
548 * @c: Bignum; used to store the result of a % b
549 * Returns: 0 on success, -1 on failure
551 int crypto_bignum_mod(const struct crypto_bignum *a,
552 const struct crypto_bignum *b,
553 struct crypto_bignum *c);
556 * crypto_bignum_exptmod - Modular exponentiation: d = a^b (mod c)
558 * @b: Bignum; exponent
559 * @c: Bignum; modulus
560 * @d: Bignum; used to store the result of a^b (mod c)
561 * Returns: 0 on success, -1 on failure
563 int crypto_bignum_exptmod(const struct crypto_bignum *a,
564 const struct crypto_bignum *b,
565 const struct crypto_bignum *c,
566 struct crypto_bignum *d);
569 * crypto_bignum_inverse - Inverse a bignum so that a * c = 1 (mod b)
572 * @c: Bignum; used to store the result
573 * Returns: 0 on success, -1 on failure
575 int crypto_bignum_inverse(const struct crypto_bignum *a,
576 const struct crypto_bignum *b,
577 struct crypto_bignum *c);
580 * crypto_bignum_sub - c = a - b
583 * @c: Bignum; used to store the result of a - b
584 * Returns: 0 on success, -1 on failure
586 int crypto_bignum_sub(const struct crypto_bignum *a,
587 const struct crypto_bignum *b,
588 struct crypto_bignum *c);
591 * crypto_bignum_div - c = a / b
594 * @c: Bignum; used to store the result of a / b
595 * Returns: 0 on success, -1 on failure
597 int crypto_bignum_div(const struct crypto_bignum *a,
598 const struct crypto_bignum *b,
599 struct crypto_bignum *c);
602 * crypto_bignum_mulmod - d = a * b (mod c)
606 * @d: Bignum; used to store the result of (a * b) % c
607 * Returns: 0 on success, -1 on failure
609 int crypto_bignum_mulmod(const struct crypto_bignum *a,
610 const struct crypto_bignum *b,
611 const struct crypto_bignum *c,
612 struct crypto_bignum *d);
615 * crypto_bignum_cmp - Compare two bignums
618 * Returns: -1 if a < b, 0 if a == b, or 1 if a > b
620 int crypto_bignum_cmp(const struct crypto_bignum *a,
621 const struct crypto_bignum *b);
624 * crypto_bignum_bits - Get size of a bignum in bits
626 * Returns: Number of bits in the bignum
628 int crypto_bignum_bits(const struct crypto_bignum *a);
631 * crypto_bignum_is_zero - Is the given bignum zero
633 * Returns: 1 if @a is zero or 0 if not
635 int crypto_bignum_is_zero(const struct crypto_bignum *a);
638 * crypto_bignum_is_one - Is the given bignum one
640 * Returns: 1 if @a is one or 0 if not
642 int crypto_bignum_is_one(const struct crypto_bignum *a);
645 * crypto_bignum_legendre - Compute the Legendre symbol (a/p)
648 * Returns: Legendre symbol -1,0,1 on success; -2 on calculation failure
650 int crypto_bignum_legendre(const struct crypto_bignum *a,
651 const struct crypto_bignum *p);
654 * struct crypto_ec - Elliptic curve context
656 * Internal data structure for EC implementation. The contents is specific
657 * to the used crypto library.
662 * crypto_ec_init - Initialize elliptic curve context
663 * @group: Identifying number for the ECC group (IANA "Group Description"
664 * attribute registrty for RFC 2409)
665 * Returns: Pointer to EC context or %NULL on failure
667 struct crypto_ec * crypto_ec_init(int group);
670 * crypto_ec_deinit - Deinitialize elliptic curve context
671 * @e: EC context from crypto_ec_init()
673 void crypto_ec_deinit(struct crypto_ec *e);
676 * crypto_ec_prime_len - Get length of the prime in octets
677 * @e: EC context from crypto_ec_init()
678 * Returns: Length of the prime defining the group
680 size_t crypto_ec_prime_len(struct crypto_ec *e);
683 * crypto_ec_prime_len_bits - Get length of the prime in bits
684 * @e: EC context from crypto_ec_init()
685 * Returns: Length of the prime defining the group in bits
687 size_t crypto_ec_prime_len_bits(struct crypto_ec *e);
690 * crypto_ec_get_prime - Get prime defining an EC group
691 * @e: EC context from crypto_ec_init()
692 * Returns: Prime (bignum) defining the group
694 const struct crypto_bignum * crypto_ec_get_prime(struct crypto_ec *e);
697 * crypto_ec_get_order - Get order of an EC group
698 * @e: EC context from crypto_ec_init()
699 * Returns: Order (bignum) of the group
701 const struct crypto_bignum * crypto_ec_get_order(struct crypto_ec *e);
704 * struct crypto_ec_point - Elliptic curve point
706 * Internal data structure for EC implementation to represent a point. The
707 * contents is specific to the used crypto library.
709 struct crypto_ec_point;
712 * crypto_ec_point_init - Initialize data for an EC point
713 * @e: EC context from crypto_ec_init()
714 * Returns: Pointer to EC point data or %NULL on failure
716 struct crypto_ec_point * crypto_ec_point_init(struct crypto_ec *e);
719 * crypto_ec_point_deinit - Deinitialize EC point data
720 * @p: EC point data from crypto_ec_point_init()
721 * @clear: Whether to clear the EC point value from memory
723 void crypto_ec_point_deinit(struct crypto_ec_point *p, int clear);
726 * crypto_ec_point_to_bin - Write EC point value as binary data
727 * @e: EC context from crypto_ec_init()
728 * @p: EC point data from crypto_ec_point_init()
729 * @x: Buffer for writing the binary data for x coordinate or %NULL if not used
730 * @y: Buffer for writing the binary data for y coordinate or %NULL if not used
731 * Returns: 0 on success, -1 on failure
733 * This function can be used to write an EC point as binary data in a format
734 * that has the x and y coordinates in big endian byte order fields padded to
735 * the length of the prime defining the group.
737 int crypto_ec_point_to_bin(struct crypto_ec *e,
738 const struct crypto_ec_point *point, u8 *x, u8 *y);
741 * crypto_ec_point_from_bin - Create EC point from binary data
742 * @e: EC context from crypto_ec_init()
743 * @val: Binary data to read the EC point from
744 * Returns: Pointer to EC point data or %NULL on failure
746 * This function readers x and y coordinates of the EC point from the provided
747 * buffer assuming the values are in big endian byte order with fields padded to
748 * the length of the prime defining the group.
750 struct crypto_ec_point * crypto_ec_point_from_bin(struct crypto_ec *e,
754 * crypto_bignum_add - c = a + b
755 * @e: EC context from crypto_ec_init()
758 * @c: Bignum; used to store the result of a + b
759 * Returns: 0 on success, -1 on failure
761 int crypto_ec_point_add(struct crypto_ec *e, const struct crypto_ec_point *a,
762 const struct crypto_ec_point *b,
763 struct crypto_ec_point *c);
766 * crypto_bignum_mul - res = b * p
767 * @e: EC context from crypto_ec_init()
770 * @res: EC point; used to store the result of b * p
771 * Returns: 0 on success, -1 on failure
773 int crypto_ec_point_mul(struct crypto_ec *e, const struct crypto_ec_point *p,
774 const struct crypto_bignum *b,
775 struct crypto_ec_point *res);
778 * crypto_ec_point_invert - Compute inverse of an EC point
779 * @e: EC context from crypto_ec_init()
780 * @p: EC point to invert (and result of the operation)
781 * Returns: 0 on success, -1 on failure
783 int crypto_ec_point_invert(struct crypto_ec *e, struct crypto_ec_point *p);
786 * crypto_ec_point_solve_y_coord - Solve y coordinate for an x coordinate
787 * @e: EC context from crypto_ec_init()
788 * @p: EC point to use for the returning the result
790 * @y_bit: y-bit (0 or 1) for selecting the y value to use
791 * Returns: 0 on success, -1 on failure
793 int crypto_ec_point_solve_y_coord(struct crypto_ec *e,
794 struct crypto_ec_point *p,
795 const struct crypto_bignum *x, int y_bit);
798 * crypto_ec_point_compute_y_sqr - Compute y^2 = x^3 + ax + b
799 * @e: EC context from crypto_ec_init()
801 * Returns: y^2 on success, %NULL failure
803 struct crypto_bignum *
804 crypto_ec_point_compute_y_sqr(struct crypto_ec *e,
805 const struct crypto_bignum *x);
808 * crypto_ec_point_is_at_infinity - Check whether EC point is neutral element
809 * @e: EC context from crypto_ec_init()
811 * Returns: 1 if the specified EC point is the neutral element of the group or
814 int crypto_ec_point_is_at_infinity(struct crypto_ec *e,
815 const struct crypto_ec_point *p);
818 * crypto_ec_point_is_on_curve - Check whether EC point is on curve
819 * @e: EC context from crypto_ec_init()
821 * Returns: 1 if the specified EC point is on the curve or 0 if not
823 int crypto_ec_point_is_on_curve(struct crypto_ec *e,
824 const struct crypto_ec_point *p);
827 * crypto_ec_point_cmp - Compare two EC points
828 * @e: EC context from crypto_ec_init()
831 * Returns: 0 on equal, non-zero otherwise
833 int crypto_ec_point_cmp(const struct crypto_ec *e,
834 const struct crypto_ec_point *a,
835 const struct crypto_ec_point *b);
842 #endif /* CRYPTO_H */