Skip to content

Commit

Permalink
Remove reset_gop_hash and update_gop_hash APIs
Browse files Browse the repository at this point in the history
These APIs are no longer needed as recursive hash is not used.
  • Loading branch information
mithydolphin committed Dec 5, 2024
1 parent e255e19 commit 7e61aa7
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 45 deletions.
4 changes: 2 additions & 2 deletions lib/src/signed_video_h26x_auth.c
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
35 changes: 2 additions & 33 deletions lib/src/signed_video_h26x_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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)

Expand Down
3 changes: 0 additions & 3 deletions lib/src/signed_video_h26x_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions lib/src/signed_video_h26x_sign.c
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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;

Expand Down
4 changes: 0 additions & 4 deletions lib/src/signed_video_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 7e61aa7

Please sign in to comment.