// This file is dual licensed under the terms of the Apache License, Version
// 2.0, and the BSD License. See the LICENSE file in the root of this
// repository for complete details.

/* Returns the value of the input with the most-significant-bit copied to all
   of the bits. */
static uint8_t Cryptography_DUPLICATE_MSB_TO_ALL(uint8_t a) {
    return (1 - (a >> (sizeof(uint8_t) * 8 - 1))) - 1;
}

/* This returns 0xFF if a < b else 0x00, but does so in a constant time
   fashion */
static uint8_t Cryptography_constant_time_lt(uint8_t a, uint8_t b) {
    a -= b;
    return Cryptography_DUPLICATE_MSB_TO_ALL(a);
}

uint8_t Cryptography_check_pkcs7_padding(const uint8_t *data,
                                         uint8_t block_len) {
    uint8_t i;
    uint8_t pad_size = data[block_len - 1];
    uint8_t mismatch = 0;
    for (i = 0; i < block_len; i++) {
        unsigned int mask = Cryptography_constant_time_lt(i, pad_size);
        uint8_t b = data[block_len - 1 - i];
        mismatch |= (mask & (pad_size ^ b));
    }

    /* Check to make sure the pad_size was within the valid range. */
    mismatch |= ~Cryptography_constant_time_lt(0, pad_size);
    mismatch |= Cryptography_constant_time_lt(block_len, pad_size);

    /* Make sure any bits set are copied to the lowest bit */
    mismatch |= mismatch >> 4;
    mismatch |= mismatch >> 2;
    mismatch |= mismatch >> 1;
    /* Now check the low bit to see if it's set */
    return (mismatch & 1) == 0;
}
itmproxy/refs/?id=786cd214d64ed67668e89033576dc75f3e80169a'>refs</a><a href='/cgit/cloud-email/mitmproxy/log/web/src/js/components/ContentView/ContentViewOptions.jsx'>log</a><a class='active' href='/cgit/cloud-email/mitmproxy/tree/web/src/js/components/ContentView/ContentViewOptions.jsx?id=786cd214d64ed67668e89033576dc75f3e80169a'>tree</a><a href='/cgit/cloud-email/mitmproxy/commit/web/src/js/components/ContentView/ContentViewOptions.jsx?id=786cd214d64ed67668e89033576dc75f3e80169a'>commit</a><a href='/cgit/cloud-email/mitmproxy/diff/web/src/js/components/ContentView/ContentViewOptions.jsx?id=786cd214d64ed67668e89033576dc75f3e80169a'>diff</a><a href='/cgit/cloud-email/mitmproxy/stats/web/src/js/components/ContentView/ContentViewOptions.jsx'>stats</a></td><td class='form'><form class='right' method='get' action='/cgit/cloud-email/mitmproxy/log/web/src/js/components/ContentView/ContentViewOptions.jsx'>
<input type='hidden' name='id' value='786cd214d64ed67668e89033576dc75f3e80169a'/><select name='qt'>
<option value='grep'>log msg</option>
<option value='author'>author</option>
<option value='committer'>committer</option>
<option value='range'>range</option>
</select>
<input class='txt' type='search' size='10' name='q' value=''/>
<input type='submit' value='search'/>
</form>
</td></tr></table>
<div class='path'>path: <a href='/cgit/cloud-email/mitmproxy/tree/?id=786cd214d64ed67668e89033576dc75f3e80169a'>root</a>/<a href='/cgit/cloud-email/mitmproxy/tree/web?id=786cd214d64ed67668e89033576dc75f3e80169a'>web</a>/<a href='/cgit/cloud-email/mitmproxy/tree/web/src?id=786cd214d64ed67668e89033576dc75f3e80169a'>src</a>/<a href='/cgit/cloud-email/mitmproxy/tree/web/src/js?id=786cd214d64ed67668e89033576dc75f3e80169a'>js</a>/<a href='/cgit/cloud-email/mitmproxy/tree/web/src/js/components?id=786cd214d64ed67668e89033576dc75f3e80169a'>components</a>/<a href='/cgit/cloud-email/mitmproxy/tree/web/src/js/components/ContentView?id=786cd214d64ed67668e89033576dc75f3e80169a'>ContentView</a>/<a href='/cgit/cloud-email/mitmproxy/tree/web/src/js/components/ContentView/ContentViewOptions.jsx?id=786cd214d64ed67668e89033576dc75f3e80169a'>ContentViewOptions.jsx</a></div><div class='content'>blob: 1ec9013e7c35335de6219c15b4976940da393de2 (<a href='/cgit/cloud-email/mitmproxy/plain/web/src/js/components/ContentView/ContentViewOptions.jsx?id=786cd214d64ed67668e89033576dc75f3e80169a'>plain</a>)
<table summary='blob content' class='blob'>
<tr><td class='linenumbers'><pre><a id='n1' href='#n1'>1</a>
<a id='n2' href='#n2'>2</a>
<a id='n3' href='#n3'>3</a>
<a id='n4' href='#n4'>4</a>
<a id='n5' href='#n5'>5</a>
<a id='n6' href='#n6'>6</a>
<a id='n7' href='#n7'>7</a>
<a id='n8' href='#n8'>8</a>
<a id='n9' href='#n9'>9</a>
<a id='n10' href='#n10'>10</a>
<a id='n11' href='#n11'>11</a>
<a id='n12' href='#n12'>12</a>
<a id='n13' href='#n13'>13</a>
<a id='n14' href='#n14'>14</a>
<a id='n15' href='#n15'>15</a>
<a id='n16' href='#n16'>16</a>
<a id='n17' href='#n17'>17</a>
<a id='n18' href='#n18'>18</a>
<a id='n19' href='#n19'>19</a>
<a id='n20' href='#n20'>20</a>
<a id='n21' href='#n21'>21</a>
<a id='n22' href='#n22'>22</a>
<a id='n23' href='#n23'>23</a>
<a id='n24' href='#n24'>24</a>
<a id='n25' href='#n25'>25</a>
<a id='n26' href='#n26'>26</a>
<a id='n27' href='#n27'>27</a>
<a id='n28' href='#n28'>28</a>
<a id='n29' href='#n29'>29</a>
<a id='n30' href='#n30'>30</a>
<a id='n31' href='#n31'>31</a>
</pre></td>
<td class='lines'><pre><code></code></pre></td></tr></table>
</div> <!-- class=content -->
<div class='footer'>generated by <a href='https://git.zx2c4.com/cgit/about/'>cgit v1.2.3</a> (<a href='https://git-scm.com/'>git 2.25.1</a>) at 2025-06-02 19:31:30 +0000</div>
</div> <!-- id=cgit -->
</body>
</html>
