Debian Codegraph @

src/core/tsi/alts/frame_protector/alts_counter.h

raw
1 /*
2 *
3 * Copyright 2018 gRPC authors.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 */
18
19 #ifndef GRPC_CORE_TSI_ALTS_FRAME_PROTECTOR_ALTS_COUNTER_H
20 #define GRPC_CORE_TSI_ALTS_FRAME_PROTECTOR_ALTS_COUNTER_H
21
22 #include <grpc/support/port_platform.h>
23
24 #include <stdbool.h>
25 #include <stdlib.h>
26
27 #include <grpc/grpc.h>
28
29 /* Main struct for a crypter counter managed within seal/unseal operations. */
30 typedef struct alts_counter {
31 size_t size;
32 size_t overflow_size;
33 unsigned char* counter;
34 } alts_counter;
35
36 /**
37 * This method creates and initializes an alts_counter instance.
38 *
39 * - is_client: a flag indicating if the alts_counter instance will be used
40 * at client (is_client = true) or server (is_client = false) side.
41 * - counter_size: size of buffer holding the counter value.
42 * - overflow_size: overflow size in bytes. The counter instance can be used
43 * to produce at most 2^(overflow_size*8) frames.
44 * - crypter_counter: an alts_counter instance to be returned from the method.
45 * - error_details: a buffer containing an error message if the method does not
46 * function correctly. It is legal to pass nullptr into error_details and
47 * otherwise, the parameter should be freed with gpr_free.
48 *
49 * On success, the method returns GRPC_STATUS_OK. Otherwise,
50 * it returns an error status code along with its details specified in
51 * error_details (if error_details is not nullptr).
52 */
53 grpc_status_code alts_counter_create(bool is_client, size_t counter_size,
54 size_t overflow_size,
55 alts_counter** crypter_counter,
56 char** error_details);
57
58 /**
59 * This method increments the internal counter.
60 *
61 * - crypter_counter: an alts_counter instance.
62 * - is_overflow: after incrementing the internal counter, if an overflow
63 * occurs, is_overflow is set to true, and no further calls to
64 * alts_counter_increment() should be made. Otherwise, is_overflow is set to
65 * false.
66 * - error_details: a buffer containing an error message if the method does not
67 * function correctly. It is legal to pass nullptr into error_details and
68 * otherwise, the parameter should be freed with gpr_free.
69 *
70 * On success, the method returns GRPC_STATUS_OK. Otherwise,
71 * it returns an error status code along with its details specified in
72 * error_details (if error_details is not nullptr).
73 */
74 grpc_status_code alts_counter_increment(alts_counter* crypter_counter,
75 bool* is_overflow,
76 char** error_details);
77
78 /**
79 * This method returns the size of counter buffer.
80 *
81 * - crypter_counter: an alts_counter instance.
82 */
83 size_t alts_counter_get_size(alts_counter* crypter_counter);
84
85 /**
86 * This method returns the counter buffer.
87 *
88 * - crypter_counter: an alts_counter instance.
89 */
90 unsigned char* alts_counter_get_counter(alts_counter* crypter_counter);
91
92 /**
93 * This method de-allocates all memory allocated to an alts_coutner instance.
94 * - crypter_counter: an alts_counter instance.
95 */
96 void alts_counter_destroy(alts_counter* crypter_counter);
97
98 #endif /* GRPC_CORE_TSI_ALTS_FRAME_PROTECTOR_ALTS_COUNTER_H */