{"id":304,"date":"2009-07-03T09:14:25","date_gmt":"2009-07-03T13:14:25","guid":{"rendered":"http:\/\/www.willhackforsushi.com\/?p=304"},"modified":"2009-07-03T09:14:25","modified_gmt":"2009-07-03T13:14:25","slug":"cowpatty-46-with-less-teh-suck","status":"publish","type":"post","link":"https:\/\/www.willhackforsushi.com\/?p=304","title":{"rendered":"Cowpatty 4.6 (with less teh suck)"},"content":{"rendered":"<p>As it turns out, there was a pretty significant bug in cowpatty 4.5 and earlier when built on systems with a more modern version of OpenSSL than what I was testing against:<\/p>\n<pre lang=\"c\">\r\n        typedef struct {\r\n            unsigned char k_ipad[65];\r\n            unsigned char k_opad[65];\r\n            unsigned char k_ipad_set;\r\n            unsigned char k_opad_set;\r\n        } SHA1_CACHE;\r\n\r\n        struct SHA1_CACHE cached;\r\n        SHA1_CTX context;\r\n\r\n        \/* ... *\/\r\n\r\n        if (usecached) {\r\n            \/* Cache the context value *\/\r\n            memcpy(&cached.k_ipad, &context, sizeof(context));\r\n            cached.k_ipad_set = 1;\r\n        }\r\n<\/pre>\n<p>When I looked at this I realized what the problem was right away: I was stupid when I wrote this code.<\/p>\n<p>One of the ways we can accelerate WPA2-PSK cracking is to cache values that are computed each time during SHA1 rounds; namely the inner and outer pad hashes (ipad, opad).   I implemented this in cowpatty and created a data structure SHA1_CACHE to store the hashed value with a field to indicate if it was currently cached or not.<\/p>\n<p>At the time, OpenSSL&#8217;s SHA1_CACHE structure was 64 bytes; I created my structure members at 65 bytes (why not 64 bytes? Because I was stupid when I wrote this code).  Perfect!<\/p>\n<p>All worked well until I recently discovered that the SHA1_CTX structure is now 96 bytes, which did not fit so well in my 65 byte data structure.<\/p>\n<p>The lesson here: don&#8217;t try to recreate the wheel.  This is how I fixed the problem, and how I should have done it back in 2005:<\/p>\n<pre lang=\"c\">\r\n        typedef struct {\r\n            SHA1_CTX k_ipad;\r\n            SHA1_CTX k_opad;\r\n            unsigned char k_ipad_set;\r\n            unsigned char k_opad_set;\r\n        } SHA1_CACHE;\r\n<\/pre>\n<p>Instead of relying on a static byte length that once characterized the size of SHA1_CTX, I should have just used the real thing.  I&#8217;ll remember this lesson in the future, and hopefully you won&#8217;t make the same mistake I did.<\/p>\n<p>You can snag <a href=\"http:\/\/www.willhackforsushi.com\/?page_id=50\">the latest version of cowpatty here<\/a>.  Special thanks to Kevin Kestinggolrer, Philipp Schroedel, Max Moser and Nathan Grennan, Jason Franks and Michal Knobel for hitting me with their various clue-sticks.<\/p>\n<p>-Josh<\/p>\n","protected":false},"excerpt":{"rendered":"<p>As it turns out, there was a pretty significant bug in cowpatty 4.5 and earlier when built on systems with a more modern version of OpenSSL than what I was testing against: typedef struct { unsigned char k_ipad[65]; unsigned char &hellip; <a href=\"https:\/\/www.willhackforsushi.com\/?p=304\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,25,7,10],"tags":[],"class_list":["post-304","post","type-post","status-publish","format-standard","hentry","category-4","category-code","category-security","category-tool"],"_links":{"self":[{"href":"https:\/\/www.willhackforsushi.com\/index.php?rest_route=\/wp\/v2\/posts\/304","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.willhackforsushi.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.willhackforsushi.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.willhackforsushi.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.willhackforsushi.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=304"}],"version-history":[{"count":10,"href":"https:\/\/www.willhackforsushi.com\/index.php?rest_route=\/wp\/v2\/posts\/304\/revisions"}],"predecessor-version":[{"id":314,"href":"https:\/\/www.willhackforsushi.com\/index.php?rest_route=\/wp\/v2\/posts\/304\/revisions\/314"}],"wp:attachment":[{"href":"https:\/\/www.willhackforsushi.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=304"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.willhackforsushi.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=304"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.willhackforsushi.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=304"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}