<div dir="ltr"><div class="gmail_signature"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div style="">Hi Guys,</div><div style=""><br></div><div style="">           I'm trying for hardware encryption for my streaming data for that i'm using</div><div style="">openssl with libsrtp. Below are the things i have noted.</div><div style=""><br></div><div style=""><span style="color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,'Segoe UI',Arial,freesans,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:14px;line-height:22px">Our CAAM (Cryptographic Acceleration and Assurance Module) driver does not support AES-GCM. We are using an iMX6 SOC and it has a hardware accelerator called CAAM to do encryption/decryption. So, we are stuck with AES-CTR mode to do hardware encryption with libsrtp. We are using a Gstreamer bad plugin (srtpenc) which relies on libsrtp to do real time encryption of live RTP video packets.</span><br></div><div style=""><span style="color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,'Segoe UI',Arial,freesans,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:14px;line-height:22px"><br></span></div><div style=""><span style="color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,'Segoe UI',Arial,freesans,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:14px;line-height:22px">I modified the encrypt function in aes_icm_openssl.c(libsrtp-1.5.3) to give a different buffer for input and output.</span><span style="color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,'Segoe UI',Arial,freesans,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:14px;line-height:22px"><br></span></div><div style=""><span style="color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,'Segoe UI',Arial,freesans,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:14px;line-height:22px"><br></span></div><div style=""><span style="color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,'Segoe UI',Arial,freesans,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:14px;line-height:22px">In the original code, the encryption was done in place. This change was done because of a segmentation fault thrown from the EVP_EncryptUpdate() call.</span><span style="color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,'Segoe UI',Arial,freesans,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:14px;line-height:22px"><br></span></div><div style=""><span style="color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,'Segoe UI',Arial,freesans,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:14px;line-height:22px"><br></span></div><div style=""><span style="color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,'Segoe UI',Arial,freesans,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:14px;line-height:22px">I debugged this and couldn't find anything strange in the cryptodev as well as openssl code (buffer overflows, memory leaks or out of bound array access) except for the in place computation.</span><span style="color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,'Segoe UI',Arial,freesans,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:14px;line-height:22px"><br></span></div><div style=""><span style="color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,'Segoe UI',Arial,freesans,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:14px;line-height:22px"><br></span></div><div style=""><span style="color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,'Segoe UI',Arial,freesans,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:14px;line-height:22px">So, I declared a global buffer for 1 KB (out_buf) and gave this as the output argument to EVP_EncryptUpdate() and now, the encryption and decryption succeeded, except that the input had to be padded to a multiple of 16 so that the decryption could succeed, later. This was a workaround/hack I did to get basic hardware encryption with AES-CTR, working.</span><span style="color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,'Segoe UI',Arial,freesans,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:14px;line-height:22px"><br></span></div><div style=""><span style="color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,'Segoe UI',Arial,freesans,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:14px;line-height:22px"><br></span></div><div style=""><span style="color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,'Segoe UI',Arial,freesans,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:14px;line-height:22px">The 1 KB size was arbitrary and chosen to make the srtp driver tests work. To encrypt video, I had to increase the buffer size and so, I chose a maximum size of 1 MB (I didn't want to allocate dynamic memory to keep things simple) to hold the video packets. </span><span style="color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,'Segoe UI',Arial,freesans,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:14px;line-height:22px"><br></span></div><div style=""><span style="color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,'Segoe UI',Arial,freesans,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:14px;line-height:22px"><br></span></div><div style=""><span style="color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,'Segoe UI',Arial,freesans,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:14px;line-height:22px">Please note that encryption/decryption works fine without crypto engine support. i.e. if we pass NULL as the 3rd argument to EVP_EncryptInit_ex(), there's no need for a separate input/output buffer, and encryption and decryption work fine with large buffers too (video can be encrypted/decrypted).</span><span style="color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,'Segoe UI',Arial,freesans,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:14px;line-height:22px"><br></span></div><div style=""><span style="color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,'Segoe UI',Arial,freesans,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:14px;line-height:22px"><br></span></div><div style=""><span style="color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,'Segoe UI',Arial,freesans,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:14px;line-height:22px">Coming to hardware encryption, i have increase the size of buffer to 1MB, streaming works fine but for maximum of 10 seconds, i have decrease the size of buffer at different size. After 10 seconds, the streaming application closes and it throws segmentation fault.</span></div><div style=""><span style="color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,'Segoe UI',Arial,freesans,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:14px;line-height:22px"><br></span></div><div style=""><span style="color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,'Segoe UI',Arial,freesans,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:14px;line-height:22px">Can anyone tell me how do i solve this problem and my encryption of streaming video should be continuous.</span></div><div style=""><br></div><div style=""><br></div><div>Ganesh Biradar,</div><div>e-mail - id : <a href="mailto:grbesd1@gmail.com" target="_blank">grbesd1@gmail.com</a></div><div><br></div></div></div></div></div>
</div>