[erlang-questions] crypto:block_decrypt doesn't return ivec

Sverker Eriksson <>
Thu Jun 5 17:15:52 CEST 2014


On 05/09/2014 04:48 PM, Max Lapshin wrote:
> I'm implementing Apple HLS SAMPLE-AES decryption and according to their
> spec, it is required to decrypt different blocks independently.
>
> But specs are written for fun, so it is required to take ivec from decrypt
> process and use it in next decrypt.
>
> crypto:block_decrypt(aes_cbc128,....) returns only decrypted text and
> looses ivec:
>
>      ret_ptr = enif_make_new_binary(env, data_bin.size, &ret);
>      memcpy(ivec, ivec_bin.data, 16); /* writable copy */
>      AES_cbc_encrypt(data_bin.data, ret_ptr, data_bin.size, &aes_key, ivec,
> i);
>      CONSUME_REDS(env,data_bin);
>      return ret;
>
>
> modified ivec is lost. So I cannot reuse it and I need to cut all parts for
> decrypting, glue them together and then split back.
>
> Why modified ivec is ignored? Is it possible to modify api in some way that
> it would be possible to fix it and return ivec also?
>
>
There is an api for this that could be amended with more cipher modes:

crypto:stream_init/2/3
crypto:stream_encrypt/2
crypto:stream_decrypt/2


/Sverker, Erlang/OTP



More information about the erlang-questions mailing list