GRPC Core  9.0.0
Functions | Variables
alts_grpc_record_protocol_common.cc File Reference
#include <grpc/support/port_platform.h>
#include "src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_common.h"
#include <string.h>
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include "src/core/lib/gpr/useful.h"
#include "src/core/lib/iomgr/exec_ctx.h"
#include "src/core/lib/slice/slice_internal.h"

Functions

void alts_grpc_record_protocol_convert_slice_buffer_to_iovec (alts_grpc_record_protocol *rp, const grpc_slice_buffer *sb)
 Converts the slices of input sb into iovec_t's and puts the result into rp->iovec_buf. More...
 
void alts_grpc_record_protocol_copy_slice_buffer (const grpc_slice_buffer *src, unsigned char *dst)
 Copies bytes from slice buffer to destination buffer. More...
 
iovec_t alts_grpc_record_protocol_get_header_iovec (alts_grpc_record_protocol *rp)
 This method returns an iovec object pointing to the frame header stored in rp->header_sb. More...
 
tsi_result alts_grpc_record_protocol_init (alts_grpc_record_protocol *rp, gsec_aead_crypter *crypter, size_t overflow_size, bool is_client, bool is_integrity_only, bool is_protect)
 Initializes an alts_grpc_record_protocol object, given a gsec_aead_crypter instance, the overflow size of the counter in bytes, a flag indicating if the object is used for client or server side, a flag indicating if it is used for integrity-only or privacy-integrity mode, and a flag indicating if it is for protect or unprotect. More...
 
tsi_result alts_grpc_record_protocol_protect (alts_grpc_record_protocol *self, grpc_slice_buffer *unprotected_slices, grpc_slice_buffer *protected_slices)
 This methods performs protect operation on unprotected data and appends the protected frame to protected_slices. More...
 
tsi_result alts_grpc_record_protocol_unprotect (alts_grpc_record_protocol *self, grpc_slice_buffer *protected_slices, grpc_slice_buffer *unprotected_slices)
 This methods performs unprotect operation on a full frame of protected data and appends unprotected data to unprotected_slices. More...
 
void alts_grpc_record_protocol_destroy (alts_grpc_record_protocol *self)
 This method destroys an alts_grpc_record_protocol instance by de-allocating all of its occupied memory. More...
 
size_t alts_grpc_record_protocol_max_unprotected_data_size (const alts_grpc_record_protocol *self, size_t max_protected_frame_size)
 This method returns maximum allowed unprotected data size, given maximum protected frame size. More...
 

Variables

const size_t kInitialIovecBufferSize = 8
 

Function Documentation

◆ alts_grpc_record_protocol_convert_slice_buffer_to_iovec()

void alts_grpc_record_protocol_convert_slice_buffer_to_iovec ( alts_grpc_record_protocol rp,
const grpc_slice_buffer sb 
)

Converts the slices of input sb into iovec_t's and puts the result into rp->iovec_buf.

Note that the actual data are not copied, only pointers and lengths are copied.

◆ alts_grpc_record_protocol_copy_slice_buffer()

void alts_grpc_record_protocol_copy_slice_buffer ( const grpc_slice_buffer src,
unsigned char *  dst 
)

Copies bytes from slice buffer to destination buffer.

Caller is responsible for allocating enough memory of destination buffer. This method is used for copying frame header and tag in case they are stored in multiple slices.

◆ alts_grpc_record_protocol_destroy()

void alts_grpc_record_protocol_destroy ( alts_grpc_record_protocol self)

This method destroys an alts_grpc_record_protocol instance by de-allocating all of its occupied memory.

◆ alts_grpc_record_protocol_get_header_iovec()

iovec_t alts_grpc_record_protocol_get_header_iovec ( alts_grpc_record_protocol rp)

This method returns an iovec object pointing to the frame header stored in rp->header_sb.

If the frame header is stored in multiple slices, this method will copy the bytes in rp->header_sb to rp->header_buf, and return an iovec object pointing to rp->header_buf.

◆ alts_grpc_record_protocol_init()

tsi_result alts_grpc_record_protocol_init ( alts_grpc_record_protocol rp,
gsec_aead_crypter crypter,
size_t  overflow_size,
bool  is_client,
bool  is_integrity_only,
bool  is_protect 
)

Initializes an alts_grpc_record_protocol object, given a gsec_aead_crypter instance, the overflow size of the counter in bytes, a flag indicating if the object is used for client or server side, a flag indicating if it is used for integrity-only or privacy-integrity mode, and a flag indicating if it is for protect or unprotect.

The ownership of gsec_aead_crypter object is transferred to the alts_grpc_record_protocol object.

◆ alts_grpc_record_protocol_max_unprotected_data_size()

size_t alts_grpc_record_protocol_max_unprotected_data_size ( const alts_grpc_record_protocol self,
size_t  max_protected_frame_size 
)

This method returns maximum allowed unprotected data size, given maximum protected frame size.

On success, the method returns the maximum allowed unprotected data size. Otherwise, it returns zero.

◆ alts_grpc_record_protocol_protect()

tsi_result alts_grpc_record_protocol_protect ( alts_grpc_record_protocol self,
grpc_slice_buffer unprotected_slices,
grpc_slice_buffer protected_slices 
)

This methods performs protect operation on unprotected data and appends the protected frame to protected_slices.

The caller needs to ensure the length of unprotected data plus the frame overhead is less than or equal to the maximum frame length. The input unprotected data slice buffer will be cleared, although the actual unprotected data bytes are not modified.

  • self: an alts_grpc_record_protocol instance.
  • unprotected_slices: the unprotected data to be protected.
  • protected_slices: slice buffer where the protected frame is appended.

This method returns TSI_OK in case of success or a specific error code in case of failure.

◆ alts_grpc_record_protocol_unprotect()

tsi_result alts_grpc_record_protocol_unprotect ( alts_grpc_record_protocol self,
grpc_slice_buffer protected_slices,
grpc_slice_buffer unprotected_slices 
)

This methods performs unprotect operation on a full frame of protected data and appends unprotected data to unprotected_slices.

It is the caller's responsibility to prepare a full frame of data before calling this method. The input protected frame slice buffer will be cleared, although the actual protected data bytes are not modified.

  • self: an alts_grpc_record_protocol instance.
  • protected_slices: a full frame of protected data in grpc slices.
  • unprotected_slices: slice buffer where unprotected data is appended.

This method returns TSI_OK in case of success or a specific error code in case of failure.

Variable Documentation

◆ kInitialIovecBufferSize

const size_t kInitialIovecBufferSize = 8