3 * Copyright 2018 gRPC authors.
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #ifndef GRPC_CORE_TSI_ALTS_ZERO_COPY_FRAME_PROTECTOR_ALTS_GRPC_RECORD_PROTOCOL_COMMON_H
20 #define GRPC_CORE_TSI_ALTS_ZERO_COPY_FRAME_PROTECTOR_ALTS_GRPC_RECORD_PROTOCOL_COMMON_H
23 * this file contains alts_grpc_record_protocol internals and internal-only
24 * helper functions. The public functions of alts_grpc_record_protocol are
25 * defined in the alts_grpc_record_protocol.h.
28 #include <grpc/support/port_platform.h>
30 #include "src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol.h"
31 #include "src/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol.h"
33 /* V-table for alts_grpc_record_protocol implementations. */
35 tsi_result (*protect)(alts_grpc_record_protocol* self,
36 grpc_slice_buffer* unprotected_slices,
37 grpc_slice_buffer* protected_slices);
38 tsi_result (*unprotect)(alts_grpc_record_protocol* self,
39 grpc_slice_buffer* protected_slices,
40 grpc_slice_buffer* unprotected_slices);
41 void (*destruct)(alts_grpc_record_protocol* self);
42 } alts_grpc_record_protocol_vtable;
44 /* Main struct for alts_grpc_record_protocol implementation, shared by both
45 * integrity-only record protocol and privacy-integrity record protocol.
46 * Integrity-only record protocol has additional data elements.
47 * Privacy-integrity record protocol uses this struct directly. */
48 struct alts_grpc_record_protocol {
49 const alts_grpc_record_protocol_vtable* vtable;
50 alts_iovec_record_protocol* iovec_rp;
51 grpc_slice_buffer header_sb;
52 unsigned char* header_buf;
56 size_t iovec_buf_length;
60 * Converts the slices of input sb into iovec_t's and puts the result into
61 * rp->iovec_buf. Note that the actual data are not copied, only
62 * pointers and lengths are copied.
64 void alts_grpc_record_protocol_convert_slice_buffer_to_iovec(
65 alts_grpc_record_protocol* rp, const grpc_slice_buffer* sb);
68 * Copies bytes from slice buffer to destination buffer. Caller is responsible
69 * for allocating enough memory of destination buffer. This method is used for
70 * copying frame header and tag in case they are stored in multiple slices.
72 void alts_grpc_record_protocol_copy_slice_buffer(const grpc_slice_buffer* src,
76 * This method returns an iovec object pointing to the frame header stored in
77 * rp->header_sb. If the frame header is stored in multiple slices,
78 * this method will copy the bytes in rp->header_sb to
79 * rp->header_buf, and return an iovec object pointing to
82 iovec_t alts_grpc_record_protocol_get_header_iovec(
83 alts_grpc_record_protocol* rp);
86 * Initializes an alts_grpc_record_protocol object, given a gsec_aead_crypter
87 * instance, the overflow size of the counter in bytes, a flag indicating if the
88 * object is used for client or server side, a flag indicating if it is used for
89 * integrity-only or privacy-integrity mode, and a flag indicating if it is for
90 * protect or unprotect. The ownership of gsec_aead_crypter object is
91 * transferred to the alts_grpc_record_protocol object.
93 tsi_result alts_grpc_record_protocol_init(alts_grpc_record_protocol* rp,
94 gsec_aead_crypter* crypter,
95 size_t overflow_size, bool is_client,
96 bool is_integrity_only,
99 #endif /* GRPC_CORE_TSI_ALTS_ZERO_COPY_FRAME_PROTECTOR_ALTS_GRPC_RECORD_PROTOCOL_COMMON_H \