<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 12pt;
font-family:Calibri
}
--></style></head>
<body class='hmmessage'><div dir='ltr'>Hello,<div><br></div><div>I'm running server and client and they communicate using DTLS over UDP and cipher suite in use is AES-GCM-SHA384.</div><div><br></div><div>What i want to do here is to decrypt the packets which are sent by the client but i keep failing to do so.</div><div><br></div><div>To do this i obviously need the clients write key, nonce, the actual encrypted data and the additional data like it's specified here <a href="https://tools.ietf.org/html/rfc5246" target="_blank" style="font-size: 12pt;">https://tools.ietf.org/html/rfc5246</a> in section 6.2.3.3.</div><div><br></div><div>The key is the easy part, that i can get from the client. </div><div><br></div><div>Next part is the nonce, which to my understanding and according to this <a href="https://tools.ietf.org/html/rfc5116" target="_blank" style="font-size: 12pt;">https://tools.ietf.org/html/rfc5116</a> document is built from 2 parts, the explicit part which is the first 8 bytes after the UDP header just before the ciphertext and the 4 byte salt which is negotiated during the handshake, those two are then concatenated (salt + 8bytes of data) and this is then used as a 12 byte initialization vector.</div><div><br></div><div>Then there is the additional data which according to this <a href="https://tools.ietf.org/html/rfc5246" target="_blank" style="font-size: 12pt;">https://tools.ietf.org/html/rfc5246</a> (section 6.2.3.3) is:</div><div><span style="font-size: 13.3333px;">seq_num + TLSCompressed.type + </span><span style="font-size: 13.3333px;">TLSCompressed.version + TLSCompressed.length</span></div><div><span style="font-size: 13.3333px;"><br></span></div><div>Now, what i would like to do is to use <a href="https://raw.githubusercontent.com/openssl/openssl/master/demos/evp/aesgcm.c" target="_blank" style="font-size: 12pt;">https://raw.githubusercontent.com/openssl/openssl/master/demos/evp/aesgcm.c</a> this as a template and decrypt the data that's in the packet but when i plug in the encrypted data, key, aad and IV it just fails.</div><div><br></div><div>The only problem here is with the tag which is used in the example after the data is decrypted and before the <span style="font-size: 12pt;">EVP_DecryptFinal_ex function is called. I assume that it is appended to the data before encryption and i have to get it after the data is decrypted, is this correct?</span></div><div><br></div><div>So question is, what im doing wrong? Do i derive the IV and additional data correctly?</div>                                           </div></body>
</html>