Classes | Functions | Variables
aes_gcm.cc File Reference
#include <grpc/support/port_platform.h>
#include <string.h>
#include <openssl/bio.h>
#include <openssl/buffer.h>
#include <openssl/err.h>
#include <openssl/evp.h>
#include <openssl/hmac.h>
#include <grpc/support/alloc.h>
#include "src/core/tsi/alts/crypt/gsec.h"
Include dependency graph for aes_gcm.cc:

Go to the source code of this file.

Classes

struct  gsec_aes_gcm_aead_crypter
 
struct  gsec_aes_gcm_aead_rekey_data
 

Functions

static grpc_status_code aes_gcm_derive_aead_key (uint8_t *dst, const uint8_t *kdf_key, const uint8_t *kdf_counter)
 
static void aes_gcm_format_errors (const char *error_msg, char **error_details)
 
static char * aes_gcm_get_openssl_errors ()
 
static void aes_gcm_mask_nonce (uint8_t *dst, const uint8_t *nonce, const uint8_t *mask)
 
static grpc_status_code aes_gcm_new_evp_cipher_ctx (gsec_aes_gcm_aead_crypter *aes_gcm_crypter, char **error_details)
 
static grpc_status_code aes_gcm_rekey_if_required (gsec_aes_gcm_aead_crypter *aes_gcm_crypter, const uint8_t *nonce, char **error_details)
 
grpc_status_code gsec_aes_gcm_aead_crypter_create (const uint8_t *key, size_t key_length, size_t nonce_length, size_t tag_length, bool rekey, gsec_aead_crypter **crypter, char **error_details)
 
static grpc_status_code gsec_aes_gcm_aead_crypter_decrypt_iovec (gsec_aead_crypter *crypter, const uint8_t *nonce, size_t nonce_length, const struct iovec *aad_vec, size_t aad_vec_length, const struct iovec *ciphertext_vec, size_t ciphertext_vec_length, struct iovec plaintext_vec, size_t *plaintext_bytes_written, char **error_details)
 
static void gsec_aes_gcm_aead_crypter_destroy (gsec_aead_crypter *crypter)
 
static grpc_status_code gsec_aes_gcm_aead_crypter_encrypt_iovec (gsec_aead_crypter *crypter, const uint8_t *nonce, size_t nonce_length, const struct iovec *aad_vec, size_t aad_vec_length, const struct iovec *plaintext_vec, size_t plaintext_vec_length, struct iovec ciphertext_vec, size_t *ciphertext_bytes_written, char **error_details)
 
static grpc_status_code gsec_aes_gcm_aead_crypter_key_length (const gsec_aead_crypter *crypter, size_t *key_length, char **error_details)
 
static grpc_status_code gsec_aes_gcm_aead_crypter_max_ciphertext_and_tag_length (const gsec_aead_crypter *crypter, size_t plaintext_length, size_t *max_ciphertext_and_tag_length, char **error_details)
 
static grpc_status_code gsec_aes_gcm_aead_crypter_max_plaintext_length (const gsec_aead_crypter *crypter, size_t ciphertext_and_tag_length, size_t *max_plaintext_length, char **error_details)
 
static grpc_status_code gsec_aes_gcm_aead_crypter_nonce_length (const gsec_aead_crypter *crypter, size_t *nonce_length, char **error_details)
 
static grpc_status_code gsec_aes_gcm_aead_crypter_tag_length (const gsec_aead_crypter *crypter, size_t *tag_length, char **error_details)
 

Variables

constexpr size_t kKdfCounterLen = 6
 
constexpr size_t kKdfCounterOffset = 2
 
constexpr size_t kKdfKeyLen = 32
 
constexpr size_t kRekeyAeadKeyLen = kAes128GcmKeyLength
 
static const gsec_aead_crypter_vtable vtable
 

Function Documentation

◆ aes_gcm_derive_aead_key()

static grpc_status_code aes_gcm_derive_aead_key ( uint8_t dst,
const uint8_t kdf_key,
const uint8_t kdf_counter 
)
static

Definition at line 184 of file aes_gcm.cc.

◆ aes_gcm_format_errors()

static void aes_gcm_format_errors ( const char *  error_msg,
char **  error_details 
)
static

Definition at line 70 of file aes_gcm.cc.

◆ aes_gcm_get_openssl_errors()

static char* aes_gcm_get_openssl_errors ( )
static

Definition at line 55 of file aes_gcm.cc.

◆ aes_gcm_mask_nonce()

static void aes_gcm_mask_nonce ( uint8_t dst,
const uint8_t nonce,
const uint8_t mask 
)
static

Definition at line 168 of file aes_gcm.cc.

◆ aes_gcm_new_evp_cipher_ctx()

static grpc_status_code aes_gcm_new_evp_cipher_ctx ( gsec_aes_gcm_aead_crypter aes_gcm_crypter,
char **  error_details 
)
static

Definition at line 596 of file aes_gcm.cc.

◆ aes_gcm_rekey_if_required()

static grpc_status_code aes_gcm_rekey_if_required ( gsec_aes_gcm_aead_crypter aes_gcm_crypter,
const uint8_t nonce,
char **  error_details 
)
static

Definition at line 216 of file aes_gcm.cc.

◆ gsec_aes_gcm_aead_crypter_create()

grpc_status_code gsec_aes_gcm_aead_crypter_create ( const uint8_t key,
size_t  key_length,
size_t  nonce_length,
size_t  tag_length,
bool  rekey,
gsec_aead_crypter **  crypter,
char **  error_details 
)

This method creates an AEAD crypter instance of AES-GCM encryption scheme which supports 16 and 32 bytes long keys, 12 and 16 bytes long nonces, and 16 bytes long tags. It should be noted that once the lengths of key, nonce, and tag are determined at construction time, they cannot be modified later.

  • key: buffer containing a key which is binded with AEAD crypter instance.
  • key_length: length of a key in bytes, which should be 44 if rekeying is enabled and 16 or 32 otherwise.
  • nonce_length: length of a nonce in bytes, which should be either 12 or 16.
  • tag_length: length of a tag in bytes, which should be always 16.
  • rekey: enable nonce-based rekeying and nonce-masking.
  • crypter: address of AES_GCM crypter instance returned from the method.
  • error_details: a buffer containing an error message if the method does not function correctly. It is legal to pass nullptr into error_details, and otherwise, the parameter should be freed with gpr_free.

On success of instance creation, it stores the address of instance at crypter. Otherwise, it returns an error status code together with its details specified in error_details.

Definition at line 633 of file aes_gcm.cc.

◆ gsec_aes_gcm_aead_crypter_decrypt_iovec()

static grpc_status_code gsec_aes_gcm_aead_crypter_decrypt_iovec ( gsec_aead_crypter crypter,
const uint8_t nonce,
size_t  nonce_length,
const struct iovec aad_vec,
size_t  aad_vec_length,
const struct iovec ciphertext_vec,
size_t  ciphertext_vec_length,
struct iovec  plaintext_vec,
size_t *  plaintext_bytes_written,
char **  error_details 
)
static

Definition at line 383 of file aes_gcm.cc.

◆ gsec_aes_gcm_aead_crypter_destroy()

static void gsec_aes_gcm_aead_crypter_destroy ( gsec_aead_crypter crypter)
static

Definition at line 577 of file aes_gcm.cc.

◆ gsec_aes_gcm_aead_crypter_encrypt_iovec()

static grpc_status_code gsec_aes_gcm_aead_crypter_encrypt_iovec ( gsec_aead_crypter crypter,
const uint8_t nonce,
size_t  nonce_length,
const struct iovec aad_vec,
size_t  aad_vec_length,
const struct iovec plaintext_vec,
size_t  plaintext_vec_length,
struct iovec  ciphertext_vec,
size_t *  ciphertext_bytes_written,
char **  error_details 
)
static

Definition at line 245 of file aes_gcm.cc.

◆ gsec_aes_gcm_aead_crypter_key_length()

static grpc_status_code gsec_aes_gcm_aead_crypter_key_length ( const gsec_aead_crypter crypter,
size_t *  key_length,
char **  error_details 
)
static

Definition at line 140 of file aes_gcm.cc.

◆ gsec_aes_gcm_aead_crypter_max_ciphertext_and_tag_length()

static grpc_status_code gsec_aes_gcm_aead_crypter_max_ciphertext_and_tag_length ( const gsec_aead_crypter crypter,
size_t  plaintext_length,
size_t *  max_ciphertext_and_tag_length,
char **  error_details 
)
static

Definition at line 89 of file aes_gcm.cc.

◆ gsec_aes_gcm_aead_crypter_max_plaintext_length()

static grpc_status_code gsec_aes_gcm_aead_crypter_max_plaintext_length ( const gsec_aead_crypter crypter,
size_t  ciphertext_and_tag_length,
size_t *  max_plaintext_length,
char **  error_details 
)
static

Definition at line 105 of file aes_gcm.cc.

◆ gsec_aes_gcm_aead_crypter_nonce_length()

static grpc_status_code gsec_aes_gcm_aead_crypter_nonce_length ( const gsec_aead_crypter crypter,
size_t *  nonce_length,
char **  error_details 
)
static

Definition at line 126 of file aes_gcm.cc.

◆ gsec_aes_gcm_aead_crypter_tag_length()

static grpc_status_code gsec_aes_gcm_aead_crypter_tag_length ( const gsec_aead_crypter crypter,
size_t *  tag_length,
char **  error_details 
)
static

Definition at line 154 of file aes_gcm.cc.

Variable Documentation

◆ kKdfCounterLen

constexpr size_t kKdfCounterLen = 6
constexpr

Definition at line 34 of file aes_gcm.cc.

◆ kKdfCounterOffset

constexpr size_t kKdfCounterOffset = 2
constexpr

Definition at line 35 of file aes_gcm.cc.

◆ kKdfKeyLen

constexpr size_t kKdfKeyLen = 32
constexpr

Definition at line 33 of file aes_gcm.cc.

◆ kRekeyAeadKeyLen

constexpr size_t kRekeyAeadKeyLen = kAes128GcmKeyLength
constexpr

Definition at line 36 of file aes_gcm.cc.

◆ vtable

gsec_aes_gcm_aead_crypter_nonce_length
static grpc_status_code gsec_aes_gcm_aead_crypter_nonce_length(const gsec_aead_crypter *crypter, size_t *nonce_length, char **error_details)
Definition: aes_gcm.cc:126
gsec_aes_gcm_aead_crypter_max_ciphertext_and_tag_length
static grpc_status_code gsec_aes_gcm_aead_crypter_max_ciphertext_and_tag_length(const gsec_aead_crypter *crypter, size_t plaintext_length, size_t *max_ciphertext_and_tag_length, char **error_details)
Definition: aes_gcm.cc:89
gsec_aes_gcm_aead_crypter_destroy
static void gsec_aes_gcm_aead_crypter_destroy(gsec_aead_crypter *crypter)
Definition: aes_gcm.cc:577
gsec_aes_gcm_aead_crypter_key_length
static grpc_status_code gsec_aes_gcm_aead_crypter_key_length(const gsec_aead_crypter *crypter, size_t *key_length, char **error_details)
Definition: aes_gcm.cc:140
gsec_aes_gcm_aead_crypter_max_plaintext_length
static grpc_status_code gsec_aes_gcm_aead_crypter_max_plaintext_length(const gsec_aead_crypter *crypter, size_t ciphertext_and_tag_length, size_t *max_plaintext_length, char **error_details)
Definition: aes_gcm.cc:105
gsec_aes_gcm_aead_crypter_encrypt_iovec
static grpc_status_code gsec_aes_gcm_aead_crypter_encrypt_iovec(gsec_aead_crypter *crypter, const uint8_t *nonce, size_t nonce_length, const struct iovec *aad_vec, size_t aad_vec_length, const struct iovec *plaintext_vec, size_t plaintext_vec_length, struct iovec ciphertext_vec, size_t *ciphertext_bytes_written, char **error_details)
Definition: aes_gcm.cc:245
gsec_aes_gcm_aead_crypter_decrypt_iovec
static grpc_status_code gsec_aes_gcm_aead_crypter_decrypt_iovec(gsec_aead_crypter *crypter, const uint8_t *nonce, size_t nonce_length, const struct iovec *aad_vec, size_t aad_vec_length, const struct iovec *ciphertext_vec, size_t ciphertext_vec_length, struct iovec plaintext_vec, size_t *plaintext_bytes_written, char **error_details)
Definition: aes_gcm.cc:383
gsec_aes_gcm_aead_crypter_tag_length
static grpc_status_code gsec_aes_gcm_aead_crypter_tag_length(const gsec_aead_crypter *crypter, size_t *tag_length, char **error_details)
Definition: aes_gcm.cc:154


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