xref: /aosp_15_r20/external/tink/cc/subtle/ec_util.h (revision e7b1675dde1b92d52ec075b0a92829627f2c52a5)
1 // Copyright 2017 Google Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 //
15 ///////////////////////////////////////////////////////////////////////////////
16 
17 #ifndef TINK_SUBTLE_EC_UTIL_H_
18 #define TINK_SUBTLE_EC_UTIL_H_
19 
20 #include "absl/base/macros.h"
21 #include "tink/internal/ec_util.h"
22 #include "tink/subtle/common_enums.h"
23 #include "tink/util/status.h"
24 #include "tink/util/statusor.h"
25 
26 namespace crypto {
27 namespace tink {
28 namespace subtle {
29 
30 class EcUtil {
31  public:
32   // Returns the encoding size of a point on the specified elliptic curve
33   // when the given 'point_format' is used.
34   ABSL_DEPRECATED("Use of this function is dicouraged outside Tink.")
EncodingSizeInBytes(EllipticCurveType curve_type,EcPointFormat point_format)35   static inline crypto::tink::util::StatusOr<uint32_t> EncodingSizeInBytes(
36       EllipticCurveType curve_type, EcPointFormat point_format) {
37     return internal::EcPointEncodingSizeInBytes(curve_type, point_format);
38   }
39 
40   // Returns the size (in bytes) of an element of the field over which
41   // the curve is defined.
42   ABSL_DEPRECATED("Use of this function is dicouraged outside Tink.")
FieldSizeInBytes(EllipticCurveType curve_type)43   static inline uint32_t FieldSizeInBytes(EllipticCurveType curve_type) {
44     util::StatusOr<int32_t> size = internal::EcFieldSizeInBytes(curve_type);
45     if (!size.ok()) {
46       return 0;
47     }
48     return *size;
49   }
50 };
51 
52 }  // namespace subtle
53 }  // namespace tink
54 }  // namespace crypto
55 
56 #endif  // TINK_SUBTLE_EC_UTIL_H_
57