Skip to content

Commit

Permalink
Do not allow the gop hash to span multiple GOPs (#249)
Browse files Browse the repository at this point in the history
Breaks at first I-frame if NAL Units have already been added to the
GOP hash.

Co-authored-by: bjornvolcker <[email protected]>
  • Loading branch information
bjornvolcker and bjornvolcker authored Nov 4, 2024
1 parent f000f6d commit 9cb2b25
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/src/signed_video_h26x_auth.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ prepare_for_link_and_gop_hash_verification(signed_video_t *self, h26x_nalu_list_
const size_t hash_size = self->verify_data->hash_size;
h26x_nalu_list_item_t *item = NULL;
const uint8_t *hash_to_add = NULL;
int num_nalus_in_gop = 0;
assert(nalu_list);

h26x_nalu_list_print(nalu_list);
Expand All @@ -207,6 +208,11 @@ prepare_for_link_and_gop_hash_verification(signed_video_t *self, h26x_nalu_list_
if (num_i_frames > 1) break; // Break if encountered second I frame.
// Ensure that only non-missing NALUs (which have non-null pointers) are processed.
assert(item->nalu);
// Break at I-frame if NAL Units have been added to GOP hash, since a GOP hash cannot span
// across multiple GOPs.
if (item->nalu->is_first_nalu_in_gop && (num_nalus_in_gop > 0)) {
break;
}

// Skip GOP SEI items as they do not contribute to the GOP hash.
if (item == sei) {
Expand All @@ -216,6 +222,7 @@ prepare_for_link_and_gop_hash_verification(signed_video_t *self, h26x_nalu_list_
// Since the GOP hash is initialized, it can be updated with each incoming NALU hash.
SV_THROW(openssl_update_hash(self->crypto_handle, hash_to_add, hash_size, true));
item->used_in_gop_hash = true; // Mark the item as used in the GOP hash
num_nalus_in_gop++;

item = item->next;
}
Expand Down

0 comments on commit 9cb2b25

Please sign in to comment.