<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-2029893803605764663</id><updated>2012-02-16T17:51:11.553-08:00</updated><title type='text'>Tony Blog</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://incog-izick.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2029893803605764663/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://incog-izick.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Tony</name><uri>http://www.blogger.com/profile/10806058598964897702</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>1</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-2029893803605764663.post-6385746906324048470</id><published>2011-08-31T11:44:00.000-07:00</published><updated>2011-08-31T14:50:22.540-07:00</updated><title type='text'>Using OpenSSL AES GCM</title><content type='html'>While I've been doing work on crypto for many years, I hadn't needed to use OpenSSL's EVP functions much at all. &amp;nbsp;Much of my life was PKCS#11 were mechanism parameters are passed with the Init functions. &amp;nbsp;Using GCM with from the Aug 15th 2011 OpenSSL gate was my encounter with passing parameters OpenSSL style. &amp;nbsp; Something I couldn't find documentation when searching.&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;The easy one to figure out what using EVP_CIPHER_CTX_ctrl functions to get the authentication tag in and out of the operation. &amp;nbsp;It was obvious that some function had to do it, and it was pretty easy to find while looking through the code. &amp;nbsp;After getting that setup, I was doing encrypt operations fine, but decrypt would fail during the EVP_DecryptFinal. Looking through the code it was the tag checking that was failing, but why? &amp;nbsp;I did not have any additional authentication data (AAD), so a simple decrypt should work for which it just encrypted. &amp;nbsp;After thinking it was a bug for quite a while I finally came across the FIPS POST code and saw the answer.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;EVP requires that the app after doing EVP_*Init() must provide the AAD in the form of an EVP_*Update(). &amp;nbsp;For example in pseudo code:&lt;/div&gt;&lt;div&gt;&lt;pre&gt;&lt;br /&gt;    EVP_EncryptInit(ctx, algorithm, key, iv);&lt;br /&gt;    EVP_EncryptUpdate(ctx, NULL, &amp;amp;len, aad, aad_len);&lt;br /&gt;    EVP_EncryptUpdate(ctx, ct, &amp;amp;len, pt, pt_len);&lt;br /&gt;    EVP_EncryptFinal(ctx, ct + ct_len, &amp;amp;len);&lt;br /&gt;    EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_GET_TAG, 16, ct + ct_len)&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;It has been my observation that even if you are not using an AAD, you must send a zero length buffer to the EVP_EncryptUpdate() for the TAG to be correct during decrypt.  If you do not, the TAG will be random.&lt;br /&gt;&lt;br /&gt;This is as of the Aug 15th 2011 code in the gate of OpenSSL.  A binary release of this is probably headed for OpenSSL 1.0.1&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2029893803605764663-6385746906324048470?l=incog-izick.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://incog-izick.blogspot.com/feeds/6385746906324048470/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://incog-izick.blogspot.com/2011/08/using-openssl-aes-gcm.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2029893803605764663/posts/default/6385746906324048470'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2029893803605764663/posts/default/6385746906324048470'/><link rel='alternate' type='text/html' href='http://incog-izick.blogspot.com/2011/08/using-openssl-aes-gcm.html' title='Using OpenSSL AES GCM'/><author><name>Tony</name><uri>http://www.blogger.com/profile/10806058598964897702</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry></feed>
