From 7e61aa79ea0851163ebde3f0b0181adee8444f4b Mon Sep 17 00:00:00 2001 From: Yunus Kurt Date: Thu, 5 Dec 2024 15:10:30 +0100 Subject: [PATCH] Remove reset_gop_hash and update_gop_hash APIs These APIs are no longer needed as recursive hash is not used. --- lib/src/signed_video_h26x_auth.c | 4 ++-- lib/src/signed_video_h26x_common.c | 35 ++-------------------------- lib/src/signed_video_h26x_internal.h | 3 --- lib/src/signed_video_h26x_sign.c | 6 ++--- lib/src/signed_video_internal.h | 4 ---- 5 files changed, 7 insertions(+), 45 deletions(-) diff --git a/lib/src/signed_video_h26x_auth.c b/lib/src/signed_video_h26x_auth.c index 1616b5a..2ec97ff 100644 --- a/lib/src/signed_video_h26x_auth.c +++ b/lib/src/signed_video_h26x_auth.c @@ -29,9 +29,9 @@ #include "legacy_validation.h" #include "signed_video_authenticity.h" // create_local_authenticity_report_if_needed() #include "signed_video_defines.h" // svrc_t -#include "signed_video_h26x_internal.h" // gop_state_*(), update_gop_hash(), update_validation_flags() +#include "signed_video_h26x_internal.h" // gop_state_*() , update_validation_flags() #include "signed_video_h26x_nalu_list.h" // h26x_nalu_list_append() -#include "signed_video_internal.h" // gop_info_t, gop_state_t, reset_gop_hash() +#include "signed_video_internal.h" // gop_info_t, gop_state_t #include "signed_video_openssl_internal.h" // openssl_{verify_hash, public_key_malloc}() #include "signed_video_tlv.h" // tlv_find_tag() diff --git a/lib/src/signed_video_h26x_common.c b/lib/src/signed_video_h26x_common.c index e166804..a68dad2 100644 --- a/lib/src/signed_video_h26x_common.c +++ b/lib/src/signed_video_h26x_common.c @@ -271,18 +271,6 @@ set_hash_list_size(gop_info_t *gop_info, size_t hash_list_size) return SV_OK; } -svrc_t -reset_gop_hash(signed_video_t *self) -{ - if (!self) return SV_INVALID_PARAMETER; - - gop_info_t *gop_info = self->gop_info; - assert(gop_info); - - gop_info->num_nalus_in_gop_hash = 0; - return openssl_hash_data(self->crypto_handle, &gop_info->gop_hash_init, 1, gop_info->gop_hash); -} - /** * Checks a pointer to member in struct if it's allocated, and correct size, then copies over the * data to that member. @@ -837,23 +825,6 @@ update_num_nalus_in_gop_hash(signed_video_t *self, const h26x_nalu_t *nalu) } } -svrc_t -update_gop_hash(void *crypto_handle, gop_info_t *gop_info) -{ - if (!gop_info) return SV_INVALID_PARAMETER; - - size_t hash_size = openssl_get_hash_size(crypto_handle); - svrc_t status = SV_UNKNOWN_FAILURE; - SV_TRY() - // Update the gop_hash, that is, hash the memory (both hashes) in hashes = [gop_hash, latest - // nalu_hash] and replace the gop_hash part with the new hash. - SV_THROW(openssl_hash_data(crypto_handle, gop_info->hashes, 2 * hash_size, gop_info->gop_hash)); - SV_CATCH() - SV_DONE(status) - - return status; -} - /* Initializes and updates the GOP hash regardless of available space. If there is enough * room, copies the |hash| and updates |list_idx|. Otherwise, sets |list_idx| to -1. */ @@ -1070,7 +1041,6 @@ hash_and_add(signed_video_t *self, const h26x_nalu_t *nalu) if (nalu->is_last_nalu_part) { // The end of the NALU has been reached. Update hash list and GOP hash. check_and_copy_hash_to_hash_list(self, nalu_hash, hash_size); - SV_THROW(update_gop_hash(self->crypto_handle, gop_info)); update_num_nalus_in_gop_hash(self, nalu); } SV_CATCH() @@ -1171,8 +1141,7 @@ signed_video_create(SignedVideoCodec codec) self->gop_info = gop_info_create(); SV_THROW_IF_WITH_MSG(!self->gop_info, SV_MEMORY, "Could not allocate gop_info"); - SV_THROW_WITH_MSG(reset_gop_hash(self), "Could not reset gop_hash"); - + self->gop_info->num_nalus_in_gop_hash = 0; // Setup vendor handle. #ifdef SV_VENDOR_AXIS_COMMUNICATIONS self->vendor_handle = sv_vendor_axis_communications_setup(); @@ -1250,7 +1219,7 @@ signed_video_reset(signed_video_t *self) self->last_nalu->is_last_nalu_part = true; SV_THROW(openssl_init_hash(self->crypto_handle, false)); - SV_THROW(reset_gop_hash(self)); + self->gop_info->num_nalus_in_gop_hash = 0; SV_CATCH() SV_DONE(status) diff --git a/lib/src/signed_video_h26x_internal.h b/lib/src/signed_video_h26x_internal.h index 9bf34dd..a4a2a90 100644 --- a/lib/src/signed_video_h26x_internal.h +++ b/lib/src/signed_video_h26x_internal.h @@ -171,9 +171,6 @@ gop_state_reset(gop_state_t *gop_state); void update_num_nalus_in_gop_hash(signed_video_t *signed_video, const h26x_nalu_t *nalu); -svrc_t -update_gop_hash(void *crypto_handle, gop_info_t *gop_info); - void check_and_copy_hash_to_hash_list(signed_video_t *signed_video, const uint8_t *hash, diff --git a/lib/src/signed_video_h26x_sign.c b/lib/src/signed_video_h26x_sign.c index 6b68ec7..9987cf0 100644 --- a/lib/src/signed_video_h26x_sign.c +++ b/lib/src/signed_video_h26x_sign.c @@ -29,7 +29,7 @@ #include "signed_video_authenticity.h" // allocate_memory_and_copy_string #include "signed_video_defines.h" // svrc_t, sv_tlv_tag_t #include "signed_video_h26x_internal.h" // parse_nalu_info() -#include "signed_video_internal.h" // gop_info_t, reset_gop_hash() +#include "signed_video_internal.h" // gop_info_t #include "signed_video_openssl_internal.h" #include "signed_video_tlv.h" // tlv_list_encode_or_get_size() @@ -354,8 +354,8 @@ generate_sei_nalu(signed_video_t *self, uint8_t **payload, uint8_t **payload_sig memcpy(sign_data->hash, gop_info->gop_hash, hash_size); } - // Reset the gop_hash since we start a new GOP. - SV_THROW(reset_gop_hash(self)); + // Reset the |num_nalus_in_gop_hash| since we start a new GOP. + self->gop_info->num_nalus_in_gop_hash = 0; // Reset the |hash_list| by rewinding the |list_idx| since we start a new GOP. gop_info->list_idx = 0; diff --git a/lib/src/signed_video_internal.h b/lib/src/signed_video_internal.h index f3347a1..6531f19 100644 --- a/lib/src/signed_video_internal.h +++ b/lib/src/signed_video_internal.h @@ -269,10 +269,6 @@ struct_member_memory_allocated_and_copy(void **member_ptr, svrc_t set_hash_list_size(gop_info_t *gop_info, size_t hash_list_size); -/* Resets the gop_hash. */ -svrc_t -reset_gop_hash(signed_video_t *signed_video); - void product_info_free_members(signed_video_product_info_t *product_info);