{"id":5609,"date":"2024-09-15T08:59:56","date_gmt":"2024-09-15T06:59:56","guid":{"rendered":"https:\/\/cyber-fi.net\/?p=5609"},"modified":"2024-09-15T08:59:58","modified_gmt":"2024-09-15T06:59:58","slug":"when-a-block-cipher-is-not-a-block-cipher","status":"publish","type":"post","link":"https:\/\/cyber-fi.net\/index.php\/2024\/09\/15\/when-a-block-cipher-is-not-a-block-cipher\/","title":{"rendered":"When a Block Cipher is not a Block Cipher"},"content":{"rendered":"\n<p>Well, of course a Block cipher is always a Block cipher. But sometimes it might not be used as expected and this can cause some misunderstanding of how things work.<\/p>\n\n\n\n<p>If you implement IPsec VPNs, you likely know ESP, the Encapsulating Security Payload and it&#8217;s packet format:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code> 0                   1                   2                   3\n 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1\n+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ ----\n|               Security Parameters Index (SPI)                 | ^Int.\n+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |Cov-\n|                      Sequence Number                          | |ered\n+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ----\n|                    Payload Data* (variable)                   | |   ^\n~                                                               ~ |   |\n|                                                               | |Conf.\n+               +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |Cov-\n|               |     Padding (0-255 bytes)                     | |ered*\n+-+-+-+-+-+-+-+-+               +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |   |\n|                               |  Pad Length   | Next Header   | v   v\n+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ ------\n|         Integrity Check Value-ICV   (variable)                |\n~                                                               ~\n|                                                               |\n+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n<\/code><\/pre>\n\n\n\n<p class=\"has-text-align-center\"><a href=\"https:\/\/datatracker.ietf.org\/doc\/html\/rfc4303#section-2\" target=\"_blank\" rel=\"noreferrer noopener\">The Encapsulating Security Payload Packet Format from RFC 4303<\/a><\/p>\n\n\n\n<p>The interesting part is the Padding. When AES is used, we have the block size of 128 bits, and the encryption always uses chunks of this size. when the payload is less than the blocksize, the data gets padded to reach the blocksize.<\/p>\n\n\n\n<p>We can visualize this with a series of pings where the payload increases by 1 Byte with every ping:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"565\" src=\"https:\/\/cyber-fi.net\/wp-content\/uploads\/2024\/09\/ESP-1024x565.jpg\" alt=\"\" class=\"wp-image-5619\" srcset=\"https:\/\/cyber-fi.net\/wp-content\/uploads\/2024\/09\/ESP-1024x565.jpg 1024w, https:\/\/cyber-fi.net\/wp-content\/uploads\/2024\/09\/ESP-300x166.jpg 300w, https:\/\/cyber-fi.net\/wp-content\/uploads\/2024\/09\/ESP-768x424.jpg 768w, https:\/\/cyber-fi.net\/wp-content\/uploads\/2024\/09\/ESP-1536x848.jpg 1536w, https:\/\/cyber-fi.net\/wp-content\/uploads\/2024\/09\/ESP-2048x1131.jpg 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\">Screenshot<\/figcaption><\/figure>\n\n\n\n<p>The y-axis has the IP-packet length, the x-axis is the packet number. There are always 16 packet of the same size and then the size increases by 16 Bytes.<\/p>\n\n\n\n<p>But if we do the same test in a wireless LAN this can not be observed. Although CCMP also uses AES as the encryption algorithm, the packet size increases by 1 Byte per packet:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"560\" src=\"https:\/\/cyber-fi.net\/wp-content\/uploads\/2024\/09\/CCMP-1024x560.jpg\" alt=\"\" class=\"wp-image-5620\" srcset=\"https:\/\/cyber-fi.net\/wp-content\/uploads\/2024\/09\/CCMP-1024x560.jpg 1024w, https:\/\/cyber-fi.net\/wp-content\/uploads\/2024\/09\/CCMP-300x164.jpg 300w, https:\/\/cyber-fi.net\/wp-content\/uploads\/2024\/09\/CCMP-768x420.jpg 768w, https:\/\/cyber-fi.net\/wp-content\/uploads\/2024\/09\/CCMP-1536x839.jpg 1536w, https:\/\/cyber-fi.net\/wp-content\/uploads\/2024\/09\/CCMP-2048x1119.jpg 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\">Screenshot<\/figcaption><\/figure>\n\n\n\n<p>Obviously, no padding is needed when AES is used on a WLAN. But why? Let&#8217;s first look at the MPDU format of a CCMP-encapsulated wireless frame, which is used if we configure the WLAN with WPA2 and AES:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"357\" src=\"https:\/\/cyber-fi.net\/wp-content\/uploads\/2024\/09\/CleanShot-2024-09-07-at-18.09.18@2x-1024x357.jpg\" alt=\"\" class=\"wp-image-5613\" srcset=\"https:\/\/cyber-fi.net\/wp-content\/uploads\/2024\/09\/CleanShot-2024-09-07-at-18.09.18@2x-1024x357.jpg 1024w, https:\/\/cyber-fi.net\/wp-content\/uploads\/2024\/09\/CleanShot-2024-09-07-at-18.09.18@2x-300x104.jpg 300w, https:\/\/cyber-fi.net\/wp-content\/uploads\/2024\/09\/CleanShot-2024-09-07-at-18.09.18@2x-768x267.jpg 768w, https:\/\/cyber-fi.net\/wp-content\/uploads\/2024\/09\/CleanShot-2024-09-07-at-18.09.18@2x-1536x535.jpg 1536w, https:\/\/cyber-fi.net\/wp-content\/uploads\/2024\/09\/CleanShot-2024-09-07-at-18.09.18@2x-2048x713.jpg 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\">CCMP MPDU from IEEE 802.11-2020<\/figcaption><\/figure>\n<\/div>\n\n\n<p>The field &#8220;Data (PDU)&#8221; is defined as 1 Byte or more, and the frame doesn&#8217;t have a Padding Field as seen on the ESP packet format. The whole encryption process with AES has to be done in a completely different way than with IPsec\/ESP.<\/p>\n\n\n\n<p>The 802.11 standard has no details about the encryption process but references <a href=\"https:\/\/datatracker.ietf.org\/doc\/html\/rfc3610\" target=\"_blank\" rel=\"noreferrer noopener\">RFC 3610 Counter with CBC-MAC (CCM)<\/a>.<\/p>\n\n\n\n<p>The most important piece of information here is the &#8220;Counter&#8221; (CTR). CCMP is a variant of the Counter Mode, that was already developed by Whitfield Diffie and Martin Hellman in 1979. Counter mode uses the Block Cipher to generate a key stream, which is then XORed with the data. Effectively, with Counter Mode, we use a block cipher like AES in a way similar to how a stream cipher works.<\/p>\n\n\n\n<p>Paragraph 2.3 of RFC 3610 has the details:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>To encrypt the message data we use Counter (CTR) mode.  We first<br>   define the key stream blocks by:<br><br>      S_i := E( K, A_i )   for i=0, 1, 2, ...<br><br>...<br><br>The message is encrypted by XORing the octets of message m with the<br>   first l(m) octets of the concatenation of S_1, S_2, S_3, ... .<\/strong><\/pre>\n\n\n\n<p>In this process, we always have a key stream with sizes in increments of the block size. But with the XOR operation, we are not limited to encrypting only data of the block size.<\/p>\n\n\n\n<p>Are there other benefits of using CCMP compared to the implementation in IPsec?<\/p>\n\n\n\n<p>When used as a block cipher, the encryption and decryption processes are different. However, in CCMP, only the AES encryption operation is used to generate the key stream for the data&#8217;s encryption and decryption, which can reduce the complexity of the code.<\/p>\n\n\n\n<p>This process is perfectly visualized in the <a href=\"https:\/\/en.wikipedia.org\/wiki\/Block_cipher_mode_of_operation#Counter_(CTR)\" target=\"_blank\" rel=\"noreferrer noopener\">Wikipedia article describing the different modes of operations<\/a>:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"413\" src=\"https:\/\/cyber-fi.net\/wp-content\/uploads\/2024\/09\/image-1024x413.png\" alt=\"\" class=\"wp-image-5626\" srcset=\"https:\/\/cyber-fi.net\/wp-content\/uploads\/2024\/09\/image-1024x413.png 1024w, https:\/\/cyber-fi.net\/wp-content\/uploads\/2024\/09\/image-300x121.png 300w, https:\/\/cyber-fi.net\/wp-content\/uploads\/2024\/09\/image-768x310.png 768w, https:\/\/cyber-fi.net\/wp-content\/uploads\/2024\/09\/image-1536x619.png 1536w, https:\/\/cyber-fi.net\/wp-content\/uploads\/2024\/09\/image.png 1920w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n<\/div>\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"413\" src=\"https:\/\/cyber-fi.net\/wp-content\/uploads\/2024\/09\/image-1-1024x413.png\" alt=\"\" class=\"wp-image-5627\" srcset=\"https:\/\/cyber-fi.net\/wp-content\/uploads\/2024\/09\/image-1-1024x413.png 1024w, https:\/\/cyber-fi.net\/wp-content\/uploads\/2024\/09\/image-1-300x121.png 300w, https:\/\/cyber-fi.net\/wp-content\/uploads\/2024\/09\/image-1-768x310.png 768w, https:\/\/cyber-fi.net\/wp-content\/uploads\/2024\/09\/image-1-1536x619.png 1536w, https:\/\/cyber-fi.net\/wp-content\/uploads\/2024\/09\/image-1.png 1920w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\">By Gwenda (PNG version), WhiteTimberwolf (SVG version) &#8211; PNG version, Public Domain, https:\/\/commons.wikimedia.org\/w\/index.php?curid=26434105<\/figcaption><\/figure>\n<\/div>\n\n\n<p>Happy WLAN encryption!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Well, of course a Block cipher is always a Block cipher. But sometimes it might not be used as expected and this can cause some misunderstanding of how things work. If you implement IPsec VPNs, you likely know ESP, the Encapsulating Security Payload and it&#8217;s packet format: The Encapsulating Security Payload Packet Format from RFC <\/p>\n<div class=\"read-more-text\"><a href=\"https:\/\/cyber-fi.net\/index.php\/2024\/09\/15\/when-a-block-cipher-is-not-a-block-cipher\/\" class=\"read-more\">continue reading<\/a><\/div>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"twitterCardType":"","cardImageID":0,"cardImage":"","cardTitle":"","cardDesc":"","cardImageAlt":"","cardPlayer":"","cardPlayerWidth":0,"cardPlayerHeight":0,"cardPlayerStream":"","cardPlayerCodec":"","footnotes":""},"categories":[706,717],"tags":[49,739,743,711,740,741,317,742,744],"class_list":["post-5609","post","type-post","status-publish","format-standard","hentry","category-cwnp","category-wireless","tag-aes","tag-ccmp","tag-ctr","tag-cwsp","tag-esp","tag-ieee-802-11","tag-ipsec","tag-rfc-3610","tag-rfc-4303"],"_links":{"self":[{"href":"https:\/\/cyber-fi.net\/index.php\/wp-json\/wp\/v2\/posts\/5609","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cyber-fi.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cyber-fi.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cyber-fi.net\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/cyber-fi.net\/index.php\/wp-json\/wp\/v2\/comments?post=5609"}],"version-history":[{"count":11,"href":"https:\/\/cyber-fi.net\/index.php\/wp-json\/wp\/v2\/posts\/5609\/revisions"}],"predecessor-version":[{"id":5632,"href":"https:\/\/cyber-fi.net\/index.php\/wp-json\/wp\/v2\/posts\/5609\/revisions\/5632"}],"wp:attachment":[{"href":"https:\/\/cyber-fi.net\/index.php\/wp-json\/wp\/v2\/media?parent=5609"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cyber-fi.net\/index.php\/wp-json\/wp\/v2\/categories?post=5609"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cyber-fi.net\/index.php\/wp-json\/wp\/v2\/tags?post=5609"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}