Unify checking for ctx and ctx->cipher_ctx (assertions) in encrypt 24/262924/3
authorLukasz Pawelczyk <l.pawelczyk@samsung.com>
Mon, 23 Aug 2021 17:09:47 +0000 (19:09 +0200)
committerTomasz Swierczek <t.swierczek@samsung.com>
Mon, 30 Aug 2021 06:20:51 +0000 (06:20 +0000)
Change-Id: I8440869307b9b48b76e21f95d7e727951516b108

src/encrypt.c

index f0ef959..556eb3f 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright (c) 2016-2020 Samsung Electronics Co., Ltd All Rights Reserved
+ *  Copyright (c) 2016-2021 Samsung Electronics Co., Ltd All Rights Reserved
  *
  *  Contact: Krzysztof Jackiewicz <k.jackiewicz@samsung.com>
  *
@@ -843,13 +843,13 @@ static int get_encrypt_property(const yaca_context_h ctx, yaca_property_e proper
        int ret;
        void *tag = NULL;
        struct yaca_encrypt_context_s *c = get_encrypt_context(ctx);
-       int mode;
+       assert(c != NULL);
+       assert(c->cipher_ctx != NULL);
 
-       if (c == NULL || value == NULL)
+       if (value == NULL)
                return YACA_ERROR_INVALID_PARAMETER;
-       assert(c->cipher_ctx != NULL);
 
-       mode = EVP_CIPHER_CTX_mode(c->cipher_ctx);
+       int mode = EVP_CIPHER_CTX_mode(c->cipher_ctx);
 
        switch (property) {
        case YACA_PROPERTY_GCM_TAG:
@@ -1057,6 +1057,8 @@ int encrypt_update(yaca_context_h ctx,
        if (c == NULL || input_len == 0 || output_len == NULL || op_type != c->op_type)
                return YACA_ERROR_INVALID_PARAMETER;
 
+       assert(c->cipher_ctx != NULL);
+
        int mode = EVP_CIPHER_CTX_mode(c->cipher_ctx);
        int nid = EVP_CIPHER_CTX_nid(c->cipher_ctx);
 
@@ -1138,6 +1140,8 @@ int encrypt_finalize(yaca_context_h ctx,
        if (c == NULL || output == NULL || output_len == NULL || op_type != c->op_type)
                return YACA_ERROR_INVALID_PARAMETER;
 
+       assert(c->cipher_ctx != NULL);
+
        if (!verify_state_change(c, ENC_CTX_FINALIZED))
                return YACA_ERROR_INVALID_PARAMETER;