Classes | Typedefs | Functions | Variables
alts_zero_copy_grpc_protector.cc File Reference
#include <grpc/support/port_platform.h>
#include "src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.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"
#include "src/core/tsi/alts/crypt/gsec.h"
#include "src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_integrity_only_record_protocol.h"
#include "src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_privacy_integrity_record_protocol.h"
#include "src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol.h"
#include "src/core/tsi/alts/zero_copy_frame_protector/alts_iovec_record_protocol.h"
#include "src/core/tsi/transport_security_grpc.h"
Include dependency graph for alts_zero_copy_grpc_protector.cc:

Go to the source code of this file.

Classes

struct  alts_zero_copy_grpc_protector
 

Typedefs

typedef struct alts_zero_copy_grpc_protector alts_zero_copy_grpc_protector
 

Functions

tsi_result alts_zero_copy_grpc_protector_create (const uint8_t *key, size_t key_size, bool is_rekey, bool is_client, bool is_integrity_only, bool enable_extra_copy, size_t *max_protected_frame_size, tsi_zero_copy_grpc_protector **protector)
 
static void alts_zero_copy_grpc_protector_destroy (tsi_zero_copy_grpc_protector *self)
 
static tsi_result alts_zero_copy_grpc_protector_max_frame_size (tsi_zero_copy_grpc_protector *self, size_t *max_frame_size)
 
static tsi_result alts_zero_copy_grpc_protector_protect (tsi_zero_copy_grpc_protector *self, grpc_slice_buffer *unprotected_slices, grpc_slice_buffer *protected_slices)
 
static tsi_result alts_zero_copy_grpc_protector_unprotect (tsi_zero_copy_grpc_protector *self, grpc_slice_buffer *protected_slices, grpc_slice_buffer *unprotected_slices, int *min_progress_size)
 
static tsi_result create_alts_grpc_record_protocol (const uint8_t *key, size_t key_size, bool is_rekey, bool is_client, bool is_integrity_only, bool is_protect, bool enable_extra_copy, alts_grpc_record_protocol **record_protocol)
 
static bool read_frame_size (const grpc_slice_buffer *sb, uint32_t *total_frame_size)
 

Variables

static const tsi_zero_copy_grpc_protector_vtable alts_zero_copy_grpc_protector_vtable
 
constexpr size_t kDefaultFrameLength = 16 * 1024
 
constexpr size_t kMaxFrameLength = 16 * 1024 * 1024
 
constexpr size_t kMinFrameLength = 1024
 

Typedef Documentation

◆ alts_zero_copy_grpc_protector

Main struct for alts_zero_copy_grpc_protector. We choose to have two alts_grpc_record_protocol objects and two sets of slice buffers: one for protect and the other for unprotect, so that protect and unprotect can be executed in parallel. Implementations of this object must be thread compatible.

Function Documentation

◆ alts_zero_copy_grpc_protector_create()

tsi_result alts_zero_copy_grpc_protector_create ( const uint8_t key,
size_t  key_size,
bool  is_rekey,
bool  is_client,
bool  is_integrity_only,
bool  enable_extra_copy,
size_t *  max_protected_frame_size,
tsi_zero_copy_grpc_protector **  protector 
)

This method creates an ALTS zero-copy grpc protector.

  • key: a symmetric key used to seal/unseal frames.
  • key_size: the size of symmetric key.
  • is_rekey: use rekeying AEAD crypter.
  • is_client: a flag indicating if the protector will be used at client or server side.
  • is_integrity_only: a flag indicating if the protector instance will be used for integrity-only or privacy-integrity mode.
  • enable_extra_copy: a flag indicating if the protector instance does one extra memory copy during the protect operation for integrity_only mode. For the unprotect operation, it is still zero-copy. If application intends to modify the data buffer after the protect operation, we can turn on this mode to avoid integrity check failure.
  • max_protected_frame_size: an in/out parameter indicating max frame size to be used by the protector. If it is nullptr, the default frame size will be used. Otherwise, the provided frame size will be adjusted (if not falling into a valid frame range) and used.
  • protector: a pointer to the zero-copy protector returned from the method.

This method returns TSI_OK on success or a specific error code otherwise.

Definition at line 260 of file alts_zero_copy_grpc_protector.cc.

◆ alts_zero_copy_grpc_protector_destroy()

static void alts_zero_copy_grpc_protector_destroy ( tsi_zero_copy_grpc_protector self)
static

Definition at line 229 of file alts_zero_copy_grpc_protector.cc.

◆ alts_zero_copy_grpc_protector_max_frame_size()

static tsi_result alts_zero_copy_grpc_protector_max_frame_size ( tsi_zero_copy_grpc_protector self,
size_t *  max_frame_size 
)
static

Definition at line 244 of file alts_zero_copy_grpc_protector.cc.

◆ alts_zero_copy_grpc_protector_protect()

static tsi_result alts_zero_copy_grpc_protector_protect ( tsi_zero_copy_grpc_protector self,
grpc_slice_buffer unprotected_slices,
grpc_slice_buffer protected_slices 
)
static

Definition at line 149 of file alts_zero_copy_grpc_protector.cc.

◆ alts_zero_copy_grpc_protector_unprotect()

static tsi_result alts_zero_copy_grpc_protector_unprotect ( tsi_zero_copy_grpc_protector self,
grpc_slice_buffer protected_slices,
grpc_slice_buffer unprotected_slices,
int min_progress_size 
)
static

Definition at line 175 of file alts_zero_copy_grpc_protector.cc.

◆ create_alts_grpc_record_protocol()

static tsi_result create_alts_grpc_record_protocol ( const uint8_t key,
size_t  key_size,
bool  is_rekey,
bool  is_client,
bool  is_integrity_only,
bool  is_protect,
bool  enable_extra_copy,
alts_grpc_record_protocol **  record_protocol 
)
static

Creates an alts_grpc_record_protocol object, given key, key size, and flags to indicate whether the record_protocol object uses the rekeying AEAD, whether the object is for client or server, whether the object is for integrity-only or privacy-integrity mode, and whether the object is used for protect or unprotect.

Definition at line 111 of file alts_zero_copy_grpc_protector.cc.

◆ read_frame_size()

static bool read_frame_size ( const grpc_slice_buffer sb,
uint32_t total_frame_size 
)
static

Given a slice buffer, parses the first 4 bytes little-endian unsigned frame size and returns the total frame size including the frame field. Caller needs to make sure the input slice buffer has at least 4 bytes. Returns true on success and false on failure.

Definition at line 67 of file alts_zero_copy_grpc_protector.cc.

Variable Documentation

◆ alts_zero_copy_grpc_protector_vtable

const tsi_zero_copy_grpc_protector_vtable alts_zero_copy_grpc_protector_vtable
static

◆ kDefaultFrameLength

constexpr size_t kDefaultFrameLength = 16 * 1024
constexpr

Definition at line 39 of file alts_zero_copy_grpc_protector.cc.

◆ kMaxFrameLength

constexpr size_t kMaxFrameLength = 16 * 1024 * 1024
constexpr

Definition at line 40 of file alts_zero_copy_grpc_protector.cc.

◆ kMinFrameLength

constexpr size_t kMinFrameLength = 1024
constexpr

Definition at line 38 of file alts_zero_copy_grpc_protector.cc.

alts_zero_copy_grpc_protector_max_frame_size
static tsi_result alts_zero_copy_grpc_protector_max_frame_size(tsi_zero_copy_grpc_protector *self, size_t *max_frame_size)
Definition: alts_zero_copy_grpc_protector.cc:244
alts_zero_copy_grpc_protector_destroy
static void alts_zero_copy_grpc_protector_destroy(tsi_zero_copy_grpc_protector *self)
Definition: alts_zero_copy_grpc_protector.cc:229
alts_zero_copy_grpc_protector_protect
static tsi_result alts_zero_copy_grpc_protector_protect(tsi_zero_copy_grpc_protector *self, grpc_slice_buffer *unprotected_slices, grpc_slice_buffer *protected_slices)
Definition: alts_zero_copy_grpc_protector.cc:149
alts_zero_copy_grpc_protector_unprotect
static tsi_result alts_zero_copy_grpc_protector_unprotect(tsi_zero_copy_grpc_protector *self, grpc_slice_buffer *protected_slices, grpc_slice_buffer *unprotected_slices, int *min_progress_size)
Definition: alts_zero_copy_grpc_protector.cc:175


grpc
Author(s):
autogenerated on Fri May 16 2025 03:01:02