LCOV - code coverage report
Current view: top level - crypto - s2n_cipher.c (source / functions) Hit Total Coverage
Test: unit_test_coverage.info Lines: 12 12 100.0 %
Date: 2025-08-15 07:28:39 Functions: 2 2 100.0 %
Branches: 3 10 30.0 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
       3                 :            :  *
       4                 :            :  * Licensed under the Apache License, Version 2.0 (the "License").
       5                 :            :  * You may not use this file except in compliance with the License.
       6                 :            :  * A copy of the License is located at
       7                 :            :  *
       8                 :            :  *  http://aws.amazon.com/apache2.0
       9                 :            :  *
      10                 :            :  * or in the "license" file accompanying this file. This file is distributed
      11                 :            :  * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
      12                 :            :  * express or implied. See the License for the specific language governing
      13                 :            :  * permissions and limitations under the License.
      14                 :            :  */
      15                 :            : 
      16                 :            : #include <openssl/evp.h>
      17                 :            : #if defined(OPENSSL_IS_BORINGSSL) || defined(OPENSSL_IS_AWSLC)
      18                 :            :     #include <openssl/mem.h>
      19                 :            : #endif
      20                 :            : 
      21                 :            : #include "crypto/s2n_cipher.h"
      22                 :            : #include "utils/s2n_safety.h"
      23                 :            : 
      24                 :            : int s2n_session_key_alloc(struct s2n_session_key *key)
      25                 :     503098 : {
      26 [ -  + ][ #  # ]:     503098 :     POSIX_ENSURE_EQ(key->evp_cipher_ctx, NULL);
      27 [ -  + ][ #  # ]:     503098 :     POSIX_ENSURE_REF(key->evp_cipher_ctx = EVP_CIPHER_CTX_new());
      28                 :            : #if defined(S2N_CIPHER_AEAD_API_AVAILABLE)
      29                 :            :     POSIX_ENSURE_EQ(key->evp_aead_ctx, NULL);
      30                 :            :     key->evp_aead_ctx = OPENSSL_malloc(sizeof(EVP_AEAD_CTX));
      31                 :            :     if (key->evp_aead_ctx == NULL) {
      32                 :            :         EVP_CIPHER_CTX_free(key->evp_cipher_ctx);
      33                 :            :         S2N_ERROR_PRESERVE_ERRNO();
      34                 :            :     }
      35                 :            :     EVP_AEAD_CTX_zero(key->evp_aead_ctx);
      36                 :            : #endif
      37                 :            : 
      38                 :     503098 :     return 0;
      39                 :     503098 : }
      40                 :            : 
      41                 :            : int s2n_session_key_free(struct s2n_session_key *key)
      42                 :     503098 : {
      43         [ +  - ]:     503098 :     if (key->evp_cipher_ctx != NULL) {
      44                 :     503098 :         EVP_CIPHER_CTX_free(key->evp_cipher_ctx);
      45                 :     503098 :         key->evp_cipher_ctx = NULL;
      46                 :     503098 :     }
      47                 :            : #if defined(S2N_CIPHER_AEAD_API_AVAILABLE)
      48                 :            :     if (key->evp_aead_ctx != NULL) {
      49                 :            :         EVP_AEAD_CTX_free(key->evp_aead_ctx);
      50                 :            :         key->evp_aead_ctx = NULL;
      51                 :            :     }
      52                 :            : #endif
      53                 :            : 
      54                 :     503098 :     return 0;
      55                 :     503098 : }

Generated by: LCOV version 1.14