xref: /aosp_15_r20/external/boringssl/src/crypto/ec_extra/internal.h (revision 8fb009dc861624b67b6cdb62ea21f0f22d0c584b)
1 /* Copyright (c) 2020, Google Inc.
2  *
3  * Permission to use, copy, modify, and/or distribute this software for any
4  * purpose with or without fee is hereby granted, provided that the above
5  * copyright notice and this permission notice appear in all copies.
6  *
7  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
10  * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
12  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
13  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
14 
15 #ifndef OPENSSL_HEADER_EC_EXTRA_INTERNAL_H
16 #define OPENSSL_HEADER_EC_EXTRA_INTERNAL_H
17 
18 #include <openssl/ec.h>
19 
20 #include "../fipsmodule/ec/internal.h"
21 
22 #if defined(__cplusplus)
23 extern "C" {
24 #endif
25 
26 
27 // Hash-to-curve.
28 //
29 // Internal |EC_JACOBIAN| versions of the corresponding public APIs.
30 
31 // ec_hash_to_curve_p256_xmd_sha256_sswu hashes |msg| to a point on |group| and
32 // writes the result to |out|, implementing the P256_XMD:SHA-256_SSWU_RO_ suite
33 // from RFC 9380. It returns one on success and zero on error.
34 OPENSSL_EXPORT int ec_hash_to_curve_p256_xmd_sha256_sswu(
35     const EC_GROUP *group, EC_JACOBIAN *out, const uint8_t *dst, size_t dst_len,
36     const uint8_t *msg, size_t msg_len);
37 
38 // ec_hash_to_curve_p384_xmd_sha384_sswu hashes |msg| to a point on |group| and
39 // writes the result to |out|, implementing the P384_XMD:SHA-384_SSWU_RO_ suite
40 // from RFC 9380. It returns one on success and zero on error.
41 OPENSSL_EXPORT int ec_hash_to_curve_p384_xmd_sha384_sswu(
42     const EC_GROUP *group, EC_JACOBIAN *out, const uint8_t *dst, size_t dst_len,
43     const uint8_t *msg, size_t msg_len);
44 
45 // ec_hash_to_scalar_p384_xmd_sha384 hashes |msg| to a scalar on |group|
46 // and writes the result to |out|, using the hash_to_field operation from the
47 // P384_XMD:SHA-384_SSWU_RO_ suite from RFC 9380, but generating a value modulo
48 // the group order rather than a field element.
49 OPENSSL_EXPORT int ec_hash_to_scalar_p384_xmd_sha384(
50     const EC_GROUP *group, EC_SCALAR *out, const uint8_t *dst, size_t dst_len,
51     const uint8_t *msg, size_t msg_len);
52 
53 // ec_hash_to_curve_p384_xmd_sha512_sswu_draft07 hashes |msg| to a point on
54 // |group| and writes the result to |out|, implementing the
55 // P384_XMD:SHA-512_SSWU_RO_ suite from draft-irtf-cfrg-hash-to-curve-07. It
56 // returns one on success and zero on error.
57 //
58 // TODO(https://crbug.com/1414562): Migrate this to the final version.
59 OPENSSL_EXPORT int ec_hash_to_curve_p384_xmd_sha512_sswu_draft07(
60     const EC_GROUP *group, EC_JACOBIAN *out, const uint8_t *dst, size_t dst_len,
61     const uint8_t *msg, size_t msg_len);
62 
63 // ec_hash_to_scalar_p384_xmd_sha512_draft07 hashes |msg| to a scalar on |group|
64 // and writes the result to |out|, using the hash_to_field operation from the
65 // P384_XMD:SHA-512_SSWU_RO_ suite from draft-irtf-cfrg-hash-to-curve-07, but
66 // generating a value modulo the group order rather than a field element.
67 //
68 // TODO(https://crbug.com/1414562): Migrate this to the final version.
69 OPENSSL_EXPORT int ec_hash_to_scalar_p384_xmd_sha512_draft07(
70     const EC_GROUP *group, EC_SCALAR *out, const uint8_t *dst, size_t dst_len,
71     const uint8_t *msg, size_t msg_len);
72 
73 
74 #if defined(__cplusplus)
75 }  // extern C
76 #endif
77 
78 #endif  // OPENSSL_HEADER_EC_EXTRA_INTERNAL_H
79