How to handle HC 128 ( stream cipher ) for start encryption from middle bytes to end of a stream content?

839 views Asked by At

My situation: I have a video streaming service that allows users to pause / resume their videos and also watch multiple parts of them in parallel (like IDM) each of them can be paused and resumed. Performance is a significat issue here, so we chose HC-128 which is the best in performance according to this comparsion.

In HC as in most stream ciphers one of the security techniques is to set a counter when starting the algorithm and increasing that counter as more data gets encrypted.

My solutions works fine when the stream is downloaded in full (from index 0 to content.length()) but fails when I want to resume at a given location (say at byte 10000).

I use the default HC initialization process which sets the counter to 0. I tried to read the code of HC but couldn't come up with a solution.

How can I initialize HC-128 with a given counter position?

I also have a decryption APP to decrypt my stream but this is worked if counter incremented with incoming bytes.

There is a sample of HC 128 copied from bouncy castle library that works fine

You can run this code online here In main method "Hello World" is the input

0

There are 0 answers