aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/python/cryptography/_cffi_src/hazmat_src/padding.c
diff options
context:
space:
mode:
authorolegts <olegts@yandex-team.ru>2022-02-10 16:48:23 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:48:23 +0300
commit5eefa17021221fd267f1dd5f9d63d2493d131a8a (patch)
tree5d5cb817648f650d76cf1076100726fd9b8448e8 /contrib/python/cryptography/_cffi_src/hazmat_src/padding.c
parent30983fb2586f6904aaf6a5d6ef2b445cbaec1f44 (diff)
downloadydb-5eefa17021221fd267f1dd5f9d63d2493d131a8a.tar.gz
Restoring authorship annotation for <olegts@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'contrib/python/cryptography/_cffi_src/hazmat_src/padding.c')
-rw-r--r--contrib/python/cryptography/_cffi_src/hazmat_src/padding.c128
1 files changed, 64 insertions, 64 deletions
diff --git a/contrib/python/cryptography/_cffi_src/hazmat_src/padding.c b/contrib/python/cryptography/_cffi_src/hazmat_src/padding.c
index db677c7ed6..a6e05dee1e 100644
--- a/contrib/python/cryptography/_cffi_src/hazmat_src/padding.c
+++ b/contrib/python/cryptography/_cffi_src/hazmat_src/padding.c
@@ -1,65 +1,65 @@
-// 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.
+// 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 uint16_t Cryptography_DUPLICATE_MSB_TO_ALL(uint16_t a) {
- return (1 - (a >> (sizeof(uint16_t) * 8 - 1))) - 1;
-}
-
-/* This returns 0xFFFF if a < b else 0x0000, but does so in a constant time
- fashion */
-static uint16_t Cryptography_constant_time_lt(uint16_t a, uint16_t b) {
- a -= b;
- return Cryptography_DUPLICATE_MSB_TO_ALL(a);
-}
-
-uint8_t Cryptography_check_pkcs7_padding(const uint8_t *data,
- uint16_t block_len) {
- uint16_t i;
- uint16_t pad_size = data[block_len - 1];
- uint16_t mismatch = 0;
- for (i = 0; i < block_len; i++) {
- unsigned int mask = Cryptography_constant_time_lt(i, pad_size);
- uint16_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 >> 8;
- mismatch |= mismatch >> 4;
- mismatch |= mismatch >> 2;
- mismatch |= mismatch >> 1;
- /* Now check the low bit to see if it's set */
- return (mismatch & 1) == 0;
-}
-
-uint8_t Cryptography_check_ansix923_padding(const uint8_t *data,
- uint16_t block_len) {
- uint16_t i;
- uint16_t pad_size = data[block_len - 1];
- uint16_t mismatch = 0;
- /* Skip the first one with the pad size */
- for (i = 1; i < block_len; i++) {
- unsigned int mask = Cryptography_constant_time_lt(i, pad_size);
- uint16_t b = data[block_len - 1 - i];
- mismatch |= (mask & 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 >> 8;
- mismatch |= mismatch >> 4;
- mismatch |= mismatch >> 2;
- mismatch |= mismatch >> 1;
- /* Now check the low bit to see if it's set */
- return (mismatch & 1) == 0;
-}
+/* Returns the value of the input with the most-significant-bit copied to all
+ of the bits. */
+static uint16_t Cryptography_DUPLICATE_MSB_TO_ALL(uint16_t a) {
+ return (1 - (a >> (sizeof(uint16_t) * 8 - 1))) - 1;
+}
+
+/* This returns 0xFFFF if a < b else 0x0000, but does so in a constant time
+ fashion */
+static uint16_t Cryptography_constant_time_lt(uint16_t a, uint16_t b) {
+ a -= b;
+ return Cryptography_DUPLICATE_MSB_TO_ALL(a);
+}
+
+uint8_t Cryptography_check_pkcs7_padding(const uint8_t *data,
+ uint16_t block_len) {
+ uint16_t i;
+ uint16_t pad_size = data[block_len - 1];
+ uint16_t mismatch = 0;
+ for (i = 0; i < block_len; i++) {
+ unsigned int mask = Cryptography_constant_time_lt(i, pad_size);
+ uint16_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 >> 8;
+ mismatch |= mismatch >> 4;
+ mismatch |= mismatch >> 2;
+ mismatch |= mismatch >> 1;
+ /* Now check the low bit to see if it's set */
+ return (mismatch & 1) == 0;
+}
+
+uint8_t Cryptography_check_ansix923_padding(const uint8_t *data,
+ uint16_t block_len) {
+ uint16_t i;
+ uint16_t pad_size = data[block_len - 1];
+ uint16_t mismatch = 0;
+ /* Skip the first one with the pad size */
+ for (i = 1; i < block_len; i++) {
+ unsigned int mask = Cryptography_constant_time_lt(i, pad_size);
+ uint16_t b = data[block_len - 1 - i];
+ mismatch |= (mask & 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 >> 8;
+ mismatch |= mismatch >> 4;
+ mismatch |= mismatch >> 2;
+ mismatch |= mismatch >> 1;
+ /* Now check the low bit to see if it's set */
+ return (mismatch & 1) == 0;
+}