diff options
author | unril <unril@yandex-team.ru> | 2022-02-10 16:46:05 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:46:05 +0300 |
commit | 3b241dd57cf58f20bbbd63fa6a0a758dbec09b68 (patch) | |
tree | 1a2c5ffcf89eb53ecd79dbc9bc0a195c27404d0c /contrib/restricted/aws | |
parent | 11ae9eca250d0188b7962459cbc6706719e7dca9 (diff) | |
download | ydb-3b241dd57cf58f20bbbd63fa6a0a758dbec09b68.tar.gz |
Restoring authorship annotation for <unril@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'contrib/restricted/aws')
77 files changed, 12365 insertions, 12365 deletions
diff --git a/contrib/restricted/aws/aws-c-common/LICENSE b/contrib/restricted/aws/aws-c-common/LICENSE index c0fd617439..d645695673 100644 --- a/contrib/restricted/aws/aws-c-common/LICENSE +++ b/contrib/restricted/aws/aws-c-common/LICENSE @@ -1,202 +1,202 @@ - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/contrib/restricted/aws/aws-c-common/README.md b/contrib/restricted/aws/aws-c-common/README.md index 2b1b7d6fad..054c918735 100644 --- a/contrib/restricted/aws/aws-c-common/README.md +++ b/contrib/restricted/aws/aws-c-common/README.md @@ -1,118 +1,118 @@ -## AWS C Common - - +## AWS C Common + + [![GitHub](https://img.shields.io/github/license/awslabs/aws-c-common.svg)](https://github.com/awslabs/aws-c-common/blob/main/LICENSE) -[![Language grade: C/C++](https://img.shields.io/lgtm/grade/cpp/g/awslabs/aws-c-common.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/awslabs/aws-c-common/context:cpp) -[![Total alerts](https://img.shields.io/lgtm/alerts/g/awslabs/aws-c-common.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/awslabs/aws-c-common/alerts/) - -Core c99 package for AWS SDK for C. Includes cross-platform primitives, configuration, data structures, and error handling. - -## License - -This library is licensed under the Apache 2.0 License. - -## Usage -### Building -aws-c-common uses CMake for setting up build environments. This library has no non-kernel dependencies so the build is quite -simple. - -For example: - - git clone git@github.com:awslabs/aws-c-common.git aws-c-common - mkdir aws-c-common-build - cd aws-c-common-build - cmake ../aws-c-common - make -j 12 - make test - sudo make install - -Keep in mind that CMake supports multiple build systems, so for each platform you can pass your own build system -as the `-G` option. For example: - - cmake -GNinja ../aws-c-common - ninja build - ninja test - sudo ninja install - -Or on windows, - - cmake -G "Visual Studio 14 2015 Win64" ../aws-c-common - msbuild.exe ALL_BUILD.vcproj - -### CMake Options -* -DCMAKE_CLANG_TIDY=/path/to/clang-tidy (or just clang-tidy or clang-tidy-7.0 if it is in your PATH) - Runs clang-tidy as part of your build. -* -DENABLE_SANITIZERS=ON - Enables gcc/clang sanitizers, by default this adds -fsanitizer=address,undefined to the compile flags for projects that call aws_add_sanitizers. -* -DENABLE_FUZZ_TESTS=ON - Includes fuzz tests in the unit test suite. Off by default, because fuzz tests can take a long time. Set -DFUZZ_TESTS_MAX_TIME=N to determine how long to run each fuzz test (default 60s). -* -DCMAKE_INSTALL_PREFIX=/path/to/install - Standard way of installing to a user defined path. If specified when configuring aws-c-common, ensure the same prefix is specified when configuring other aws-c-* SDKs. +[![Language grade: C/C++](https://img.shields.io/lgtm/grade/cpp/g/awslabs/aws-c-common.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/awslabs/aws-c-common/context:cpp) +[![Total alerts](https://img.shields.io/lgtm/alerts/g/awslabs/aws-c-common.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/awslabs/aws-c-common/alerts/) + +Core c99 package for AWS SDK for C. Includes cross-platform primitives, configuration, data structures, and error handling. + +## License + +This library is licensed under the Apache 2.0 License. + +## Usage +### Building +aws-c-common uses CMake for setting up build environments. This library has no non-kernel dependencies so the build is quite +simple. + +For example: + + git clone git@github.com:awslabs/aws-c-common.git aws-c-common + mkdir aws-c-common-build + cd aws-c-common-build + cmake ../aws-c-common + make -j 12 + make test + sudo make install + +Keep in mind that CMake supports multiple build systems, so for each platform you can pass your own build system +as the `-G` option. For example: + + cmake -GNinja ../aws-c-common + ninja build + ninja test + sudo ninja install + +Or on windows, + + cmake -G "Visual Studio 14 2015 Win64" ../aws-c-common + msbuild.exe ALL_BUILD.vcproj + +### CMake Options +* -DCMAKE_CLANG_TIDY=/path/to/clang-tidy (or just clang-tidy or clang-tidy-7.0 if it is in your PATH) - Runs clang-tidy as part of your build. +* -DENABLE_SANITIZERS=ON - Enables gcc/clang sanitizers, by default this adds -fsanitizer=address,undefined to the compile flags for projects that call aws_add_sanitizers. +* -DENABLE_FUZZ_TESTS=ON - Includes fuzz tests in the unit test suite. Off by default, because fuzz tests can take a long time. Set -DFUZZ_TESTS_MAX_TIME=N to determine how long to run each fuzz test (default 60s). +* -DCMAKE_INSTALL_PREFIX=/path/to/install - Standard way of installing to a user defined path. If specified when configuring aws-c-common, ensure the same prefix is specified when configuring other aws-c-* SDKs. * -DSTATIC_CRT=ON - On MSVC, use /MT(d) to link MSVCRT - -### API style and conventions -Every API has a specific set of styles and conventions. We'll outline them here. These conventions are followed in every -library in the AWS C SDK ecosystem. - -#### Error handling -Every function that returns an `int` type, returns `AWS_OP_SUCCESS` ( 0 ) or `AWS_OP_ERR` (-1) on failure. To retrieve -the error code, use the function `aws_last_error()`. Each error code also has a corresponding error string that can be -accessed via the `aws_error_str()` function. - -In addition, you can install both a global and a thread local error handler by using the `aws_set_global_error_handler_fn()` -and `aws_set_thread_local_error_handler_fn()` functions. - -All error functions are in the `include/aws/common/error.h` header file. - -#### Naming + +### API style and conventions +Every API has a specific set of styles and conventions. We'll outline them here. These conventions are followed in every +library in the AWS C SDK ecosystem. + +#### Error handling +Every function that returns an `int` type, returns `AWS_OP_SUCCESS` ( 0 ) or `AWS_OP_ERR` (-1) on failure. To retrieve +the error code, use the function `aws_last_error()`. Each error code also has a corresponding error string that can be +accessed via the `aws_error_str()` function. + +In addition, you can install both a global and a thread local error handler by using the `aws_set_global_error_handler_fn()` +and `aws_set_thread_local_error_handler_fn()` functions. + +All error functions are in the `include/aws/common/error.h` header file. + +#### Naming Any function that allocates and initializes an object will be suffixed with `new` (e.g. `aws_myobj_new()`). Similarly, these objects will always -have a corresponding function with a `destroy` suffix. The `new` functions will return the allocated object -on success and `NULL` on failure. To respond to the error, call `aws_last_error()`. If several `new` or `destroy` +have a corresponding function with a `destroy` suffix. The `new` functions will return the allocated object +on success and `NULL` on failure. To respond to the error, call `aws_last_error()`. If several `new` or `destroy` functions are available, the variants should be named like `new_x` or `destroy_x` (e.g. `aws_myobj_new_copy()` or `aws_myobj_destroy_secure()`). - + Any function that initializes an existing object will be suffixed with `init` (e.g. `aws_myobj_init()`. These objects will have a corresponding -`clean_up` function if necessary. In these cases, you are responsible for making the decisions for how your object is -allocated. The `init` functions return `AWS_OP_SUCCESS` ( 0 ) or `AWS_OP_ERR` (-1) on failure. If several `init` or +`clean_up` function if necessary. In these cases, you are responsible for making the decisions for how your object is +allocated. The `init` functions return `AWS_OP_SUCCESS` ( 0 ) or `AWS_OP_ERR` (-1) on failure. If several `init` or `clean_up` functions are available, they should be named like `init_x` or `clean_up_x` (e.g. `aws_myobj_init_static()` or `aws_myobj_clean_up_secure()`). - -## Contributing - -If you are contributing to this code-base, first off, THANK YOU!. There are a few things to keep in mind to minimize the -pull request turn around time. - -### Coding "guidelines" -These "guidelines" are followed in every library in the AWS C SDK ecosystem. - -#### Memory Management -* All APIs that need to be able to allocate memory, must take an instance of `aws_allocator` and use that. No `malloc()` or -`free()` calls should be made directly. -* If an API does not allocate the memory, it does not free it. All allocations and deallocations should take place at the same level. -For example, if a user allocates memory, the user is responsible for freeing it. There will inevitably be a few exceptions to this -rule, but they will need significant justification to make it through the code-review. -* All functions that allocate memory must raise an `AWS_ERROR_OOM` error code upon allocation failures. If it is a `new()` function -it should return NULL. If it is an `init()` function, it should return `AWS_OP_ERR`. - -#### Threading -* Occasionally a thread is necessary. In those cases, prefer for memory not to be shared between threads. If memory must cross -a thread barrier it should be a complete ownership hand-off. Bias towards, "if I need a mutex, I'm doing it wrong". -* Do not sleep or block .... ever .... under any circumstances, in non-test-code. -* Do not expose blocking APIs. - -### Error Handling -* For APIs returning an `int` error code. The only acceptable return types are `AWS_OP_SUCCESS` and `AWS_OP_ERR`. Before -returning control to the caller, if you have an error to raise, use the `aws_raise_error()` function. -* For APIs returning an allocated instance of an object, return the memory on success, and `NULL` on failure. Before -returning control to the caller, if you have an error to raise, use the `aws_raise_error()` function. - -#### Log Subjects & Error Codes -The logging & error handling infrastructure is designed to support multiple libraries. For this to work, AWS maintained libraries + +## Contributing + +If you are contributing to this code-base, first off, THANK YOU!. There are a few things to keep in mind to minimize the +pull request turn around time. + +### Coding "guidelines" +These "guidelines" are followed in every library in the AWS C SDK ecosystem. + +#### Memory Management +* All APIs that need to be able to allocate memory, must take an instance of `aws_allocator` and use that. No `malloc()` or +`free()` calls should be made directly. +* If an API does not allocate the memory, it does not free it. All allocations and deallocations should take place at the same level. +For example, if a user allocates memory, the user is responsible for freeing it. There will inevitably be a few exceptions to this +rule, but they will need significant justification to make it through the code-review. +* All functions that allocate memory must raise an `AWS_ERROR_OOM` error code upon allocation failures. If it is a `new()` function +it should return NULL. If it is an `init()` function, it should return `AWS_OP_ERR`. + +#### Threading +* Occasionally a thread is necessary. In those cases, prefer for memory not to be shared between threads. If memory must cross +a thread barrier it should be a complete ownership hand-off. Bias towards, "if I need a mutex, I'm doing it wrong". +* Do not sleep or block .... ever .... under any circumstances, in non-test-code. +* Do not expose blocking APIs. + +### Error Handling +* For APIs returning an `int` error code. The only acceptable return types are `AWS_OP_SUCCESS` and `AWS_OP_ERR`. Before +returning control to the caller, if you have an error to raise, use the `aws_raise_error()` function. +* For APIs returning an allocated instance of an object, return the memory on success, and `NULL` on failure. Before +returning control to the caller, if you have an error to raise, use the `aws_raise_error()` function. + +#### Log Subjects & Error Codes +The logging & error handling infrastructure is designed to support multiple libraries. For this to work, AWS maintained libraries have pre-slotted log subjects & error codes for each library. The currently allocated ranges are: - -| Range | Library Name | -| --- | --- | -| [0x0000, 0x0400) | aws-c-common | -| [0x0400, 0x0800) | aws-c-io | -| [0x0800, 0x0C00) | aws-c-http | -| [0x0C00, 0x1000) | aws-c-compression | -| [0x1000, 0x1400) | aws-c-eventstream | -| [0x1400, 0x1800) | aws-c-mqtt | + +| Range | Library Name | +| --- | --- | +| [0x0000, 0x0400) | aws-c-common | +| [0x0400, 0x0800) | aws-c-io | +| [0x0800, 0x0C00) | aws-c-http | +| [0x0C00, 0x1000) | aws-c-compression | +| [0x1000, 0x1400) | aws-c-eventstream | +| [0x1400, 0x1800) | aws-c-mqtt | | [0x1800, 0x1C00) | aws-c-auth | | [0x1C00, 0x2000) | aws-c-cal | | [0x2000, 0x2400) | aws-crt-cpp | @@ -121,127 +121,127 @@ have pre-slotted log subjects & error codes for each library. The currently allo | [0x2C00, 0x3000) | aws-crt-nodejs | | [0x3000, 0x3400) | aws-crt-dotnet | | [0x3400, 0x3800) | aws-c-iot | -| [0x3800, 0x3C00) | (reserved for future project) | -| [0x3C00, 0x4000) | (reserved for future project) | +| [0x3800, 0x3C00) | (reserved for future project) | +| [0x3C00, 0x4000) | (reserved for future project) | | [0x4000, 0x4400) | (reserved for future project) | | [0x4400, 0x4800) | (reserved for future project) | - + Each library should begin its error and log subject values at the beginning of its range and follow in sequence (don't skip codes). Upon adding an AWS maintained library, a new enum range must be approved and added to the above table. - -### Testing -We have a high bar for test coverage, and PRs fixing bugs or introducing new functionality need to have tests before -they will be accepted. A couple of tips: - -#### Aws Test Harness -We provide a test harness for writing unit tests. This includes an allocator that will fail your test if you have any -memory leaks, as well as some `ASSERT` macros. To write a test: - -* Create a *.c test file in the tests directory of the project. -* Implement one or more tests with the signature `int test_case_name(struct aws_allocator *, void *ctx)` -* Use the `AWS_TEST_CASE` macro to declare the test. -* Include your test in the `tests/main.c` file. + +### Testing +We have a high bar for test coverage, and PRs fixing bugs or introducing new functionality need to have tests before +they will be accepted. A couple of tips: + +#### Aws Test Harness +We provide a test harness for writing unit tests. This includes an allocator that will fail your test if you have any +memory leaks, as well as some `ASSERT` macros. To write a test: + +* Create a *.c test file in the tests directory of the project. +* Implement one or more tests with the signature `int test_case_name(struct aws_allocator *, void *ctx)` +* Use the `AWS_TEST_CASE` macro to declare the test. +* Include your test in the `tests/main.c` file. * Include your test in the `tests/CMakeLists.txt` file. - -### Coding Style -* No Tabs. -* Indent is 4 spaces. -* K & R style for braces. -* Space after if, before the `(`. -* `else` and `else if` stay on the same line as the closing brace. - -Example: - - if (condition) { - do_something(); - } else { - do_something_else(); - } -* Avoid C99 features in header files. For some types such as bool, uint32_t etc..., these are defined if not available for the language -standard being used in `aws/common/common.h`, so feel free to use them. -* For C++ compatibility, don't put const members in structs. -* Avoid C++ style comments e.g. `//`. -* All public API functions need C++ guards and Windows dll semantics. -* Use Unix line endings. -* Where implementation hiding is desired for either ABI or runtime polymorphism reasons, use the `void *impl` pattern. v-tables - should be the last member in the struct. -* For #ifdef, put a # as the first character on the line and then indent the compilation branches. - -Example: - - - #ifdef FOO - do_something(); - - # ifdef BAR - do_something_else(); - # endif - #endif - - -* For all error code names with the exception of aws-c-common, use `AWS_ERROR_<lib name>_<error name>`. -* All error strings should be written using correct English grammar. -* SNAKE_UPPER_CASE constants, macros, and enum members. -* snake_lower_case everything else. -* `static` (local file scope) variables that are not `const` are prefixed by `s_` and lower snake case. -* Global variables not prefixed as `const` are prefixed by `g_` and lower snake case. -* Thread local variables are prefixed as `tl_` and lower snake case. -* Macros and `const` variables are upper snake case. -* For constants, prefer anonymous enums. -* Don't typedef structs. It breaks forward declaration ability. -* Don't typedef enums. It breaks forward declaration ability. -* typedef function definitions for use as function pointers as values and suffixed with _fn. - -Example: - - typedef int(fn_name_fn)(void *); - -Not: - - typedef int(*fn_name_fn)(void *); - -* Every source and header file must have a copyright header (The standard AWS one for apache 2). -* Use standard include guards (e.g. #IFNDEF HEADER_NAME #define HEADER_NAME etc...). -* Include order should be: - the header for the translation unit for the .c file - newline - header files in a directory in alphabetical order - newline - header files not in a directory (system and stdlib headers) -* Platform specifics should be handled in c files and partitioned by directory. -* Do not use `extern inline`. It's too unpredictable between compiler versions and language standards. -* Namespace all definitions in header files with `aws_<libname>?_<api>_<what it does>`. Lib name is -not always required if a conflict is not likely and it provides better ergonomics. -* `init`, `clean_up`, `new`, `destroy` are suffixed to the function names for their object. - -Example: - - AWS_COMMON_API - int aws_module_init(aws_module_t *module); - AWS_COMMON_API - void aws_module_clean_up(aws_module_t *module); - AWS_COMMON_API - aws_module_t *aws_module_new(aws_allocator_t *allocator); - AWS_COMMON_API - void aws_module_destroy(aws_module_t *module); - -* Avoid c-strings, and don't write code that depends on `NULL` terminators. Expose `struct aws_byte_buf` APIs -and let the user figure it out. -* There is only one valid character encoding-- UTF-8. Try not to ever need to care about character encodings, but -where you do, the working assumption should always be UTF-8 unless it's something we don't get a choice in (e.g. a protocol -explicitly mandates a character set). -* If you are adding/using a compiler specific keyword, macro, or intrinsic, hide it behind a platform independent macro -definition. This mainly applies to header files. Obviously, if you are writing a file that will only be built on a certain -platform, you have more liberty on this. + +### Coding Style +* No Tabs. +* Indent is 4 spaces. +* K & R style for braces. +* Space after if, before the `(`. +* `else` and `else if` stay on the same line as the closing brace. + +Example: + + if (condition) { + do_something(); + } else { + do_something_else(); + } +* Avoid C99 features in header files. For some types such as bool, uint32_t etc..., these are defined if not available for the language +standard being used in `aws/common/common.h`, so feel free to use them. +* For C++ compatibility, don't put const members in structs. +* Avoid C++ style comments e.g. `//`. +* All public API functions need C++ guards and Windows dll semantics. +* Use Unix line endings. +* Where implementation hiding is desired for either ABI or runtime polymorphism reasons, use the `void *impl` pattern. v-tables + should be the last member in the struct. +* For #ifdef, put a # as the first character on the line and then indent the compilation branches. + +Example: + + + #ifdef FOO + do_something(); + + # ifdef BAR + do_something_else(); + # endif + #endif + + +* For all error code names with the exception of aws-c-common, use `AWS_ERROR_<lib name>_<error name>`. +* All error strings should be written using correct English grammar. +* SNAKE_UPPER_CASE constants, macros, and enum members. +* snake_lower_case everything else. +* `static` (local file scope) variables that are not `const` are prefixed by `s_` and lower snake case. +* Global variables not prefixed as `const` are prefixed by `g_` and lower snake case. +* Thread local variables are prefixed as `tl_` and lower snake case. +* Macros and `const` variables are upper snake case. +* For constants, prefer anonymous enums. +* Don't typedef structs. It breaks forward declaration ability. +* Don't typedef enums. It breaks forward declaration ability. +* typedef function definitions for use as function pointers as values and suffixed with _fn. + +Example: + + typedef int(fn_name_fn)(void *); + +Not: + + typedef int(*fn_name_fn)(void *); + +* Every source and header file must have a copyright header (The standard AWS one for apache 2). +* Use standard include guards (e.g. #IFNDEF HEADER_NAME #define HEADER_NAME etc...). +* Include order should be: + the header for the translation unit for the .c file + newline + header files in a directory in alphabetical order + newline + header files not in a directory (system and stdlib headers) +* Platform specifics should be handled in c files and partitioned by directory. +* Do not use `extern inline`. It's too unpredictable between compiler versions and language standards. +* Namespace all definitions in header files with `aws_<libname>?_<api>_<what it does>`. Lib name is +not always required if a conflict is not likely and it provides better ergonomics. +* `init`, `clean_up`, `new`, `destroy` are suffixed to the function names for their object. + +Example: + + AWS_COMMON_API + int aws_module_init(aws_module_t *module); + AWS_COMMON_API + void aws_module_clean_up(aws_module_t *module); + AWS_COMMON_API + aws_module_t *aws_module_new(aws_allocator_t *allocator); + AWS_COMMON_API + void aws_module_destroy(aws_module_t *module); + +* Avoid c-strings, and don't write code that depends on `NULL` terminators. Expose `struct aws_byte_buf` APIs +and let the user figure it out. +* There is only one valid character encoding-- UTF-8. Try not to ever need to care about character encodings, but +where you do, the working assumption should always be UTF-8 unless it's something we don't get a choice in (e.g. a protocol +explicitly mandates a character set). +* If you are adding/using a compiler specific keyword, macro, or intrinsic, hide it behind a platform independent macro +definition. This mainly applies to header files. Obviously, if you are writing a file that will only be built on a certain +platform, you have more liberty on this. * When checking more than one error condition, check and log each condition separately with a unique message. - + Example: - + if (options->callback == NULL) { AWS_LOGF_ERROR(AWS_LS_SOME_SUBJECT, "Invalid options - callback is null"); return aws_raise_error(AWS_ERROR_INVALID_ARGUMENT); } - + if (options->allocator == NULL) { AWS_LOGF_ERROR(AWS_LS_SOME_SUBJECT, "Invalid options - allocator is null"); return aws_raise_error(AWS_ERROR_INVALID_ARGUMENT); diff --git a/contrib/restricted/aws/aws-c-common/generated/include/aws/common/config.h b/contrib/restricted/aws/aws-c-common/generated/include/aws/common/config.h index d2a9049b30..decbdf88f0 100644 --- a/contrib/restricted/aws/aws-c-common/generated/include/aws/common/config.h +++ b/contrib/restricted/aws/aws-c-common/generated/include/aws/common/config.h @@ -1,20 +1,20 @@ -#ifndef AWS_COMMON_CONFIG_H -#define AWS_COMMON_CONFIG_H - +#ifndef AWS_COMMON_CONFIG_H +#define AWS_COMMON_CONFIG_H + /** * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. - */ - -/* - * This header exposes compiler feature test results determined during cmake - * configure time to inline function implementations. The macros defined here - * should be considered to be an implementation detail, and can change at any - * time. - */ -#define AWS_HAVE_GCC_OVERFLOW_MATH_EXTENSIONS -#define AWS_HAVE_GCC_INLINE_ASM -/* #undef AWS_HAVE_MSVC_MULX */ -/* #undef AWS_HAVE_EXECINFO */ - -#endif + */ + +/* + * This header exposes compiler feature test results determined during cmake + * configure time to inline function implementations. The macros defined here + * should be considered to be an implementation detail, and can change at any + * time. + */ +#define AWS_HAVE_GCC_OVERFLOW_MATH_EXTENSIONS +#define AWS_HAVE_GCC_INLINE_ASM +/* #undef AWS_HAVE_MSVC_MULX */ +/* #undef AWS_HAVE_EXECINFO */ + +#endif diff --git a/contrib/restricted/aws/aws-c-common/include/aws/common/array_list.h b/contrib/restricted/aws/aws-c-common/include/aws/common/array_list.h index 895362863b..1eb7f773cf 100644 --- a/contrib/restricted/aws/aws-c-common/include/aws/common/array_list.h +++ b/contrib/restricted/aws/aws-c-common/include/aws/common/array_list.h @@ -1,110 +1,110 @@ -#ifndef AWS_COMMON_ARRAY_LIST_H -#define AWS_COMMON_ARRAY_LIST_H - +#ifndef AWS_COMMON_ARRAY_LIST_H +#define AWS_COMMON_ARRAY_LIST_H + /** * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. - */ -#include <aws/common/common.h> -#include <aws/common/math.h> - -#include <stdlib.h> - -#define AWS_ARRAY_LIST_DEBUG_FILL 0xDD - -struct aws_array_list { - struct aws_allocator *alloc; - size_t current_size; - size_t length; - size_t item_size; - void *data; -}; - -/** - * Prototype for a comparator function for sorting elements. - * - * a and b should be cast to pointers to the element type held in the list - * before being dereferenced. The function should compare the elements and - * return a positive number if a > b, zero if a = b, and a negative number - * if a < b. - */ -typedef int(aws_array_list_comparator_fn)(const void *a, const void *b); - -AWS_EXTERN_C_BEGIN - -/** - * Initializes an array list with an array of size initial_item_allocation * item_size. In this mode, the array size - * will grow by a factor of 2 upon insertion if space is not available. initial_item_allocation is the number of - * elements you want space allocated for. item_size is the size of each element in bytes. Mixing items types is not - * supported by this API. - */ -AWS_STATIC_IMPL -int aws_array_list_init_dynamic( - struct aws_array_list *AWS_RESTRICT list, - struct aws_allocator *alloc, - size_t initial_item_allocation, - size_t item_size); - -/** - * Initializes an array list with a preallocated array of void *. item_count is the number of elements in the array, - * and item_size is the size in bytes of each element. Mixing items types is not supported - * by this API. Once this list is full, new items will be rejected. - */ -AWS_STATIC_IMPL -void aws_array_list_init_static( - struct aws_array_list *AWS_RESTRICT list, - void *raw_array, - size_t item_count, - size_t item_size); - -/** - * Set of properties of a valid aws_array_list. - */ -AWS_STATIC_IMPL -bool aws_array_list_is_valid(const struct aws_array_list *AWS_RESTRICT list); - -/** - * Deallocates any memory that was allocated for this list, and resets list for reuse or deletion. - */ -AWS_STATIC_IMPL -void aws_array_list_clean_up(struct aws_array_list *AWS_RESTRICT list); - -/** + */ +#include <aws/common/common.h> +#include <aws/common/math.h> + +#include <stdlib.h> + +#define AWS_ARRAY_LIST_DEBUG_FILL 0xDD + +struct aws_array_list { + struct aws_allocator *alloc; + size_t current_size; + size_t length; + size_t item_size; + void *data; +}; + +/** + * Prototype for a comparator function for sorting elements. + * + * a and b should be cast to pointers to the element type held in the list + * before being dereferenced. The function should compare the elements and + * return a positive number if a > b, zero if a = b, and a negative number + * if a < b. + */ +typedef int(aws_array_list_comparator_fn)(const void *a, const void *b); + +AWS_EXTERN_C_BEGIN + +/** + * Initializes an array list with an array of size initial_item_allocation * item_size. In this mode, the array size + * will grow by a factor of 2 upon insertion if space is not available. initial_item_allocation is the number of + * elements you want space allocated for. item_size is the size of each element in bytes. Mixing items types is not + * supported by this API. + */ +AWS_STATIC_IMPL +int aws_array_list_init_dynamic( + struct aws_array_list *AWS_RESTRICT list, + struct aws_allocator *alloc, + size_t initial_item_allocation, + size_t item_size); + +/** + * Initializes an array list with a preallocated array of void *. item_count is the number of elements in the array, + * and item_size is the size in bytes of each element. Mixing items types is not supported + * by this API. Once this list is full, new items will be rejected. + */ +AWS_STATIC_IMPL +void aws_array_list_init_static( + struct aws_array_list *AWS_RESTRICT list, + void *raw_array, + size_t item_count, + size_t item_size); + +/** + * Set of properties of a valid aws_array_list. + */ +AWS_STATIC_IMPL +bool aws_array_list_is_valid(const struct aws_array_list *AWS_RESTRICT list); + +/** + * Deallocates any memory that was allocated for this list, and resets list for reuse or deletion. + */ +AWS_STATIC_IMPL +void aws_array_list_clean_up(struct aws_array_list *AWS_RESTRICT list); + +/** * Erases and then deallocates any memory that was allocated for this list, and resets list for reuse or deletion. */ AWS_STATIC_IMPL void aws_array_list_clean_up_secure(struct aws_array_list *AWS_RESTRICT list); /** - * Pushes the memory pointed to by val onto the end of internal list - */ -AWS_STATIC_IMPL -int aws_array_list_push_back(struct aws_array_list *AWS_RESTRICT list, const void *val); - -/** - * Copies the element at the front of the list if it exists. If list is empty, AWS_ERROR_LIST_EMPTY will be raised - */ -AWS_STATIC_IMPL -int aws_array_list_front(const struct aws_array_list *AWS_RESTRICT list, void *val); - -/** - * Deletes the element at the front of the list if it exists. If list is empty, AWS_ERROR_LIST_EMPTY will be raised. - * This call results in shifting all of the elements at the end of the array to the front. Avoid this call unless that - * is intended behavior. - */ -AWS_STATIC_IMPL -int aws_array_list_pop_front(struct aws_array_list *AWS_RESTRICT list); - -/** - * Delete N elements from the front of the list. - * Remaining elements are shifted to the front of the list. - * If the list has less than N elements, the list is cleared. - * This call is more efficient than calling aws_array_list_pop_front() N times. - */ -AWS_STATIC_IMPL -void aws_array_list_pop_front_n(struct aws_array_list *AWS_RESTRICT list, size_t n); - -/** + * Pushes the memory pointed to by val onto the end of internal list + */ +AWS_STATIC_IMPL +int aws_array_list_push_back(struct aws_array_list *AWS_RESTRICT list, const void *val); + +/** + * Copies the element at the front of the list if it exists. If list is empty, AWS_ERROR_LIST_EMPTY will be raised + */ +AWS_STATIC_IMPL +int aws_array_list_front(const struct aws_array_list *AWS_RESTRICT list, void *val); + +/** + * Deletes the element at the front of the list if it exists. If list is empty, AWS_ERROR_LIST_EMPTY will be raised. + * This call results in shifting all of the elements at the end of the array to the front. Avoid this call unless that + * is intended behavior. + */ +AWS_STATIC_IMPL +int aws_array_list_pop_front(struct aws_array_list *AWS_RESTRICT list); + +/** + * Delete N elements from the front of the list. + * Remaining elements are shifted to the front of the list. + * If the list has less than N elements, the list is cleared. + * This call is more efficient than calling aws_array_list_pop_front() N times. + */ +AWS_STATIC_IMPL +void aws_array_list_pop_front_n(struct aws_array_list *AWS_RESTRICT list, size_t n); + +/** * Deletes the element this index in the list if it exists. * If element does not exist, AWS_ERROR_INVALID_INDEX will be raised. * This call results in shifting all remaining elements towards the front. @@ -114,102 +114,102 @@ AWS_STATIC_IMPL int aws_array_list_erase(struct aws_array_list *AWS_RESTRICT list, size_t index); /** - * Copies the element at the end of the list if it exists. If list is empty, AWS_ERROR_LIST_EMPTY will be raised. - */ -AWS_STATIC_IMPL -int aws_array_list_back(const struct aws_array_list *AWS_RESTRICT list, void *val); - -/** - * Deletes the element at the end of the list if it exists. If list is empty, AWS_ERROR_LIST_EMPTY will be raised. - */ -AWS_STATIC_IMPL -int aws_array_list_pop_back(struct aws_array_list *AWS_RESTRICT list); - -/** - * Clears all elements in the array and resets length to zero. Size does not change in this operation. - */ -AWS_STATIC_IMPL -void aws_array_list_clear(struct aws_array_list *AWS_RESTRICT list); - -/** - * If in dynamic mode, shrinks the allocated array size to the minimum amount necessary to store its elements. - */ -AWS_COMMON_API -int aws_array_list_shrink_to_fit(struct aws_array_list *AWS_RESTRICT list); - -/** - * Copies the elements from from to to. If to is in static mode, it must at least be the same length as from. Any data - * in to will be overwritten in this copy. - */ -AWS_COMMON_API -int aws_array_list_copy(const struct aws_array_list *AWS_RESTRICT from, struct aws_array_list *AWS_RESTRICT to); - -/** - * Swap contents between two dynamic lists. Both lists must use the same allocator. - */ -AWS_STATIC_IMPL -void aws_array_list_swap_contents( - struct aws_array_list *AWS_RESTRICT list_a, - struct aws_array_list *AWS_RESTRICT list_b); - -/** - * Returns the number of elements that can fit in the internal array. If list is initialized in dynamic mode, - * the capacity changes over time. - */ -AWS_STATIC_IMPL -size_t aws_array_list_capacity(const struct aws_array_list *AWS_RESTRICT list); - -/** - * Returns the number of elements in the internal array. - */ -AWS_STATIC_IMPL -size_t aws_array_list_length(const struct aws_array_list *AWS_RESTRICT list); - -/** - * Copies the memory at index to val. If element does not exist, AWS_ERROR_INVALID_INDEX will be raised. - */ -AWS_STATIC_IMPL -int aws_array_list_get_at(const struct aws_array_list *AWS_RESTRICT list, void *val, size_t index); - -/** - * Copies the memory address of the element at index to *val. If element does not exist, AWS_ERROR_INVALID_INDEX will be - * raised. - */ -AWS_STATIC_IMPL -int aws_array_list_get_at_ptr(const struct aws_array_list *AWS_RESTRICT list, void **val, size_t index); - -/** - * Ensures that the array list has enough capacity to store a value at the specified index. If there is not already - * enough capacity, and the list is in dynamic mode, this function will attempt to allocate more memory, expanding the - * list. In static mode, if 'index' is beyond the maximum index, AWS_ERROR_INVALID_INDEX will be raised. - */ -AWS_COMMON_API -int aws_array_list_ensure_capacity(struct aws_array_list *AWS_RESTRICT list, size_t index); - -/** - * Copies the the memory pointed to by val into the array at index. If in dynamic mode, the size will grow by a factor - * of two when the array is full. In static mode, AWS_ERROR_INVALID_INDEX will be raised if the index is past the bounds - * of the array. - */ -AWS_STATIC_IMPL -int aws_array_list_set_at(struct aws_array_list *AWS_RESTRICT list, const void *val, size_t index); - -/** - * Swap elements at the specified indices, which must be within the bounds of the array. - */ -AWS_COMMON_API -void aws_array_list_swap(struct aws_array_list *AWS_RESTRICT list, size_t a, size_t b); - -/** - * Sort elements in the list in-place according to the comparator function. - */ -AWS_STATIC_IMPL -void aws_array_list_sort(struct aws_array_list *AWS_RESTRICT list, aws_array_list_comparator_fn *compare_fn); - + * Copies the element at the end of the list if it exists. If list is empty, AWS_ERROR_LIST_EMPTY will be raised. + */ +AWS_STATIC_IMPL +int aws_array_list_back(const struct aws_array_list *AWS_RESTRICT list, void *val); + +/** + * Deletes the element at the end of the list if it exists. If list is empty, AWS_ERROR_LIST_EMPTY will be raised. + */ +AWS_STATIC_IMPL +int aws_array_list_pop_back(struct aws_array_list *AWS_RESTRICT list); + +/** + * Clears all elements in the array and resets length to zero. Size does not change in this operation. + */ +AWS_STATIC_IMPL +void aws_array_list_clear(struct aws_array_list *AWS_RESTRICT list); + +/** + * If in dynamic mode, shrinks the allocated array size to the minimum amount necessary to store its elements. + */ +AWS_COMMON_API +int aws_array_list_shrink_to_fit(struct aws_array_list *AWS_RESTRICT list); + +/** + * Copies the elements from from to to. If to is in static mode, it must at least be the same length as from. Any data + * in to will be overwritten in this copy. + */ +AWS_COMMON_API +int aws_array_list_copy(const struct aws_array_list *AWS_RESTRICT from, struct aws_array_list *AWS_RESTRICT to); + +/** + * Swap contents between two dynamic lists. Both lists must use the same allocator. + */ +AWS_STATIC_IMPL +void aws_array_list_swap_contents( + struct aws_array_list *AWS_RESTRICT list_a, + struct aws_array_list *AWS_RESTRICT list_b); + +/** + * Returns the number of elements that can fit in the internal array. If list is initialized in dynamic mode, + * the capacity changes over time. + */ +AWS_STATIC_IMPL +size_t aws_array_list_capacity(const struct aws_array_list *AWS_RESTRICT list); + +/** + * Returns the number of elements in the internal array. + */ +AWS_STATIC_IMPL +size_t aws_array_list_length(const struct aws_array_list *AWS_RESTRICT list); + +/** + * Copies the memory at index to val. If element does not exist, AWS_ERROR_INVALID_INDEX will be raised. + */ +AWS_STATIC_IMPL +int aws_array_list_get_at(const struct aws_array_list *AWS_RESTRICT list, void *val, size_t index); + +/** + * Copies the memory address of the element at index to *val. If element does not exist, AWS_ERROR_INVALID_INDEX will be + * raised. + */ +AWS_STATIC_IMPL +int aws_array_list_get_at_ptr(const struct aws_array_list *AWS_RESTRICT list, void **val, size_t index); + +/** + * Ensures that the array list has enough capacity to store a value at the specified index. If there is not already + * enough capacity, and the list is in dynamic mode, this function will attempt to allocate more memory, expanding the + * list. In static mode, if 'index' is beyond the maximum index, AWS_ERROR_INVALID_INDEX will be raised. + */ +AWS_COMMON_API +int aws_array_list_ensure_capacity(struct aws_array_list *AWS_RESTRICT list, size_t index); + +/** + * Copies the the memory pointed to by val into the array at index. If in dynamic mode, the size will grow by a factor + * of two when the array is full. In static mode, AWS_ERROR_INVALID_INDEX will be raised if the index is past the bounds + * of the array. + */ +AWS_STATIC_IMPL +int aws_array_list_set_at(struct aws_array_list *AWS_RESTRICT list, const void *val, size_t index); + +/** + * Swap elements at the specified indices, which must be within the bounds of the array. + */ +AWS_COMMON_API +void aws_array_list_swap(struct aws_array_list *AWS_RESTRICT list, size_t a, size_t b); + +/** + * Sort elements in the list in-place according to the comparator function. + */ +AWS_STATIC_IMPL +void aws_array_list_sort(struct aws_array_list *AWS_RESTRICT list, aws_array_list_comparator_fn *compare_fn); + #ifndef AWS_NO_STATIC_IMPL # include <aws/common/array_list.inl> #endif /* AWS_NO_STATIC_IMPL */ - -AWS_EXTERN_C_END - -#endif /* AWS_COMMON_ARRAY_LIST_H */ + +AWS_EXTERN_C_END + +#endif /* AWS_COMMON_ARRAY_LIST_H */ diff --git a/contrib/restricted/aws/aws-c-common/include/aws/common/array_list.inl b/contrib/restricted/aws/aws-c-common/include/aws/common/array_list.inl index d50028c528..d3ca30ecda 100644 --- a/contrib/restricted/aws/aws-c-common/include/aws/common/array_list.inl +++ b/contrib/restricted/aws/aws-c-common/include/aws/common/array_list.inl @@ -4,96 +4,96 @@ /** * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. - */ - -/* This is implicitly included, but helps with editor highlighting */ -#include <aws/common/array_list.h> -/* - * Do not add system headers here; add them to array_list.h. This file is included under extern "C" guards, - * which might break system headers. - */ + */ + +/* This is implicitly included, but helps with editor highlighting */ +#include <aws/common/array_list.h> +/* + * Do not add system headers here; add them to array_list.h. This file is included under extern "C" guards, + * which might break system headers. + */ AWS_EXTERN_C_BEGIN - -AWS_STATIC_IMPL -int aws_array_list_init_dynamic( - struct aws_array_list *AWS_RESTRICT list, - struct aws_allocator *alloc, - size_t initial_item_allocation, - size_t item_size) { - + +AWS_STATIC_IMPL +int aws_array_list_init_dynamic( + struct aws_array_list *AWS_RESTRICT list, + struct aws_allocator *alloc, + size_t initial_item_allocation, + size_t item_size) { + AWS_FATAL_PRECONDITION(list != NULL); AWS_FATAL_PRECONDITION(alloc != NULL); AWS_FATAL_PRECONDITION(item_size > 0); AWS_ZERO_STRUCT(*list); - size_t allocation_size; - if (aws_mul_size_checked(initial_item_allocation, item_size, &allocation_size)) { + size_t allocation_size; + if (aws_mul_size_checked(initial_item_allocation, item_size, &allocation_size)) { goto error; - } - - if (allocation_size > 0) { + } + + if (allocation_size > 0) { list->data = aws_mem_acquire(alloc, allocation_size); - if (!list->data) { + if (!list->data) { goto error; - } -#ifdef DEBUG_BUILD - memset(list->data, AWS_ARRAY_LIST_DEBUG_FILL, allocation_size); + } +#ifdef DEBUG_BUILD + memset(list->data, AWS_ARRAY_LIST_DEBUG_FILL, allocation_size); -#endif - list->current_size = allocation_size; - } +#endif + list->current_size = allocation_size; + } list->item_size = item_size; list->alloc = alloc; - + AWS_FATAL_POSTCONDITION(list->current_size == 0 || list->data); - AWS_POSTCONDITION(aws_array_list_is_valid(list)); - return AWS_OP_SUCCESS; + AWS_POSTCONDITION(aws_array_list_is_valid(list)); + return AWS_OP_SUCCESS; error: AWS_POSTCONDITION(AWS_IS_ZEROED(*list)); return AWS_OP_ERR; -} - -AWS_STATIC_IMPL -void aws_array_list_init_static( - struct aws_array_list *AWS_RESTRICT list, - void *raw_array, - size_t item_count, - size_t item_size) { - +} + +AWS_STATIC_IMPL +void aws_array_list_init_static( + struct aws_array_list *AWS_RESTRICT list, + void *raw_array, + size_t item_count, + size_t item_size) { + AWS_FATAL_PRECONDITION(list != NULL); AWS_FATAL_PRECONDITION(raw_array != NULL); AWS_FATAL_PRECONDITION(item_count > 0); AWS_FATAL_PRECONDITION(item_size > 0); - list->alloc = NULL; - - int no_overflow = !aws_mul_size_checked(item_count, item_size, &list->current_size); + list->alloc = NULL; + + int no_overflow = !aws_mul_size_checked(item_count, item_size, &list->current_size); AWS_FATAL_PRECONDITION(no_overflow); - - list->item_size = item_size; - list->length = 0; - list->data = raw_array; - AWS_POSTCONDITION(aws_array_list_is_valid(list)); -} - -AWS_STATIC_IMPL -bool aws_array_list_is_valid(const struct aws_array_list *AWS_RESTRICT list) { + + list->item_size = item_size; + list->length = 0; + list->data = raw_array; + AWS_POSTCONDITION(aws_array_list_is_valid(list)); +} + +AWS_STATIC_IMPL +bool aws_array_list_is_valid(const struct aws_array_list *AWS_RESTRICT list) { if (!list) { - return false; - } - size_t required_size = 0; + return false; + } + size_t required_size = 0; bool required_size_is_valid = (aws_mul_size_checked(list->length, list->item_size, &required_size) == AWS_OP_SUCCESS); - bool current_size_is_valid = (list->current_size >= required_size); + bool current_size_is_valid = (list->current_size >= required_size); bool data_is_valid = AWS_IMPLIES(list->current_size == 0, list->data == NULL) && AWS_IMPLIES(list->current_size != 0, AWS_MEM_IS_WRITABLE(list->data, list->current_size)); bool item_size_is_valid = (list->item_size != 0); return required_size_is_valid && current_size_is_valid && data_is_valid && item_size_is_valid; -} - -AWS_STATIC_IMPL +} + +AWS_STATIC_IMPL void aws_array_list_debug_print(const struct aws_array_list *list) { printf( "arraylist %p. Alloc %p. current_size %zu. length %zu. item_size %zu. data %p\n", @@ -106,16 +106,16 @@ void aws_array_list_debug_print(const struct aws_array_list *list) { } AWS_STATIC_IMPL -void aws_array_list_clean_up(struct aws_array_list *AWS_RESTRICT list) { +void aws_array_list_clean_up(struct aws_array_list *AWS_RESTRICT list) { AWS_PRECONDITION(AWS_IS_ZEROED(*list) || aws_array_list_is_valid(list)); - if (list->alloc && list->data) { - aws_mem_release(list->alloc, list->data); - } - + if (list->alloc && list->data) { + aws_mem_release(list->alloc, list->data); + } + AWS_ZERO_STRUCT(*list); -} - -AWS_STATIC_IMPL +} + +AWS_STATIC_IMPL void aws_array_list_clean_up_secure(struct aws_array_list *AWS_RESTRICT list) { AWS_PRECONDITION(AWS_IS_ZEROED(*list) || aws_array_list_is_valid(list)); if (list->alloc && list->data) { @@ -127,75 +127,75 @@ void aws_array_list_clean_up_secure(struct aws_array_list *AWS_RESTRICT list) { } AWS_STATIC_IMPL -int aws_array_list_push_back(struct aws_array_list *AWS_RESTRICT list, const void *val) { - AWS_PRECONDITION(aws_array_list_is_valid(list)); +int aws_array_list_push_back(struct aws_array_list *AWS_RESTRICT list, const void *val) { + AWS_PRECONDITION(aws_array_list_is_valid(list)); AWS_PRECONDITION( val && AWS_MEM_IS_READABLE(val, list->item_size), "Input pointer [val] must point writable memory of [list->item_size] bytes."); - int err_code = aws_array_list_set_at(list, val, aws_array_list_length(list)); - - if (err_code && aws_last_error() == AWS_ERROR_INVALID_INDEX && !list->alloc) { - AWS_POSTCONDITION(aws_array_list_is_valid(list)); - return aws_raise_error(AWS_ERROR_LIST_EXCEEDS_MAX_SIZE); - } - - AWS_POSTCONDITION(aws_array_list_is_valid(list)); - return err_code; -} - -AWS_STATIC_IMPL -int aws_array_list_front(const struct aws_array_list *AWS_RESTRICT list, void *val) { - AWS_PRECONDITION(aws_array_list_is_valid(list)); + int err_code = aws_array_list_set_at(list, val, aws_array_list_length(list)); + + if (err_code && aws_last_error() == AWS_ERROR_INVALID_INDEX && !list->alloc) { + AWS_POSTCONDITION(aws_array_list_is_valid(list)); + return aws_raise_error(AWS_ERROR_LIST_EXCEEDS_MAX_SIZE); + } + + AWS_POSTCONDITION(aws_array_list_is_valid(list)); + return err_code; +} + +AWS_STATIC_IMPL +int aws_array_list_front(const struct aws_array_list *AWS_RESTRICT list, void *val) { + AWS_PRECONDITION(aws_array_list_is_valid(list)); AWS_PRECONDITION( val && AWS_MEM_IS_WRITABLE(val, list->item_size), "Input pointer [val] must point writable memory of [list->item_size] bytes."); - if (aws_array_list_length(list) > 0) { - memcpy(val, list->data, list->item_size); + if (aws_array_list_length(list) > 0) { + memcpy(val, list->data, list->item_size); AWS_POSTCONDITION(AWS_BYTES_EQ(val, list->data, list->item_size)); - AWS_POSTCONDITION(aws_array_list_is_valid(list)); - return AWS_OP_SUCCESS; - } - - AWS_POSTCONDITION(aws_array_list_is_valid(list)); - return aws_raise_error(AWS_ERROR_LIST_EMPTY); -} - -AWS_STATIC_IMPL -int aws_array_list_pop_front(struct aws_array_list *AWS_RESTRICT list) { - AWS_PRECONDITION(aws_array_list_is_valid(list)); - if (aws_array_list_length(list) > 0) { - aws_array_list_pop_front_n(list, 1); - AWS_POSTCONDITION(aws_array_list_is_valid(list)); - return AWS_OP_SUCCESS; - } - - AWS_POSTCONDITION(aws_array_list_is_valid(list)); - return aws_raise_error(AWS_ERROR_LIST_EMPTY); -} - -AWS_STATIC_IMPL -void aws_array_list_pop_front_n(struct aws_array_list *AWS_RESTRICT list, size_t n) { - AWS_PRECONDITION(aws_array_list_is_valid(list)); - if (n >= aws_array_list_length(list)) { - aws_array_list_clear(list); - AWS_POSTCONDITION(aws_array_list_is_valid(list)); - return; - } - - if (n > 0) { - size_t popping_bytes = list->item_size * n; - size_t remaining_items = aws_array_list_length(list) - n; - size_t remaining_bytes = remaining_items * list->item_size; - memmove(list->data, (uint8_t *)list->data + popping_bytes, remaining_bytes); - list->length = remaining_items; -#ifdef DEBUG_BUILD - memset((uint8_t *)list->data + remaining_bytes, AWS_ARRAY_LIST_DEBUG_FILL, popping_bytes); -#endif - } - AWS_POSTCONDITION(aws_array_list_is_valid(list)); -} - + AWS_POSTCONDITION(aws_array_list_is_valid(list)); + return AWS_OP_SUCCESS; + } + + AWS_POSTCONDITION(aws_array_list_is_valid(list)); + return aws_raise_error(AWS_ERROR_LIST_EMPTY); +} + +AWS_STATIC_IMPL +int aws_array_list_pop_front(struct aws_array_list *AWS_RESTRICT list) { + AWS_PRECONDITION(aws_array_list_is_valid(list)); + if (aws_array_list_length(list) > 0) { + aws_array_list_pop_front_n(list, 1); + AWS_POSTCONDITION(aws_array_list_is_valid(list)); + return AWS_OP_SUCCESS; + } + + AWS_POSTCONDITION(aws_array_list_is_valid(list)); + return aws_raise_error(AWS_ERROR_LIST_EMPTY); +} + +AWS_STATIC_IMPL +void aws_array_list_pop_front_n(struct aws_array_list *AWS_RESTRICT list, size_t n) { + AWS_PRECONDITION(aws_array_list_is_valid(list)); + if (n >= aws_array_list_length(list)) { + aws_array_list_clear(list); + AWS_POSTCONDITION(aws_array_list_is_valid(list)); + return; + } + + if (n > 0) { + size_t popping_bytes = list->item_size * n; + size_t remaining_items = aws_array_list_length(list) - n; + size_t remaining_bytes = remaining_items * list->item_size; + memmove(list->data, (uint8_t *)list->data + popping_bytes, remaining_bytes); + list->length = remaining_items; +#ifdef DEBUG_BUILD + memset((uint8_t *)list->data + remaining_bytes, AWS_ARRAY_LIST_DEBUG_FILL, popping_bytes); +#endif + } + AWS_POSTCONDITION(aws_array_list_is_valid(list)); +} + int aws_array_list_erase(struct aws_array_list *AWS_RESTRICT list, size_t index) { AWS_PRECONDITION(aws_array_list_is_valid(list)); @@ -227,162 +227,162 @@ int aws_array_list_erase(struct aws_array_list *AWS_RESTRICT list, size_t index) return AWS_OP_SUCCESS; } -AWS_STATIC_IMPL -int aws_array_list_back(const struct aws_array_list *AWS_RESTRICT list, void *val) { - AWS_PRECONDITION(aws_array_list_is_valid(list)); +AWS_STATIC_IMPL +int aws_array_list_back(const struct aws_array_list *AWS_RESTRICT list, void *val) { + AWS_PRECONDITION(aws_array_list_is_valid(list)); AWS_PRECONDITION( val && AWS_MEM_IS_WRITABLE(val, list->item_size), "Input pointer [val] must point writable memory of [list->item_size] bytes."); - if (aws_array_list_length(list) > 0) { - size_t last_item_offset = list->item_size * (aws_array_list_length(list) - 1); - - memcpy(val, (void *)((uint8_t *)list->data + last_item_offset), list->item_size); - AWS_POSTCONDITION(aws_array_list_is_valid(list)); - return AWS_OP_SUCCESS; - } - - AWS_POSTCONDITION(aws_array_list_is_valid(list)); - return aws_raise_error(AWS_ERROR_LIST_EMPTY); -} - -AWS_STATIC_IMPL -int aws_array_list_pop_back(struct aws_array_list *AWS_RESTRICT list) { - AWS_PRECONDITION(aws_array_list_is_valid(list)); - if (aws_array_list_length(list) > 0) { - + if (aws_array_list_length(list) > 0) { + size_t last_item_offset = list->item_size * (aws_array_list_length(list) - 1); + + memcpy(val, (void *)((uint8_t *)list->data + last_item_offset), list->item_size); + AWS_POSTCONDITION(aws_array_list_is_valid(list)); + return AWS_OP_SUCCESS; + } + + AWS_POSTCONDITION(aws_array_list_is_valid(list)); + return aws_raise_error(AWS_ERROR_LIST_EMPTY); +} + +AWS_STATIC_IMPL +int aws_array_list_pop_back(struct aws_array_list *AWS_RESTRICT list) { + AWS_PRECONDITION(aws_array_list_is_valid(list)); + if (aws_array_list_length(list) > 0) { + AWS_FATAL_PRECONDITION(list->data); - - size_t last_item_offset = list->item_size * (aws_array_list_length(list) - 1); - - memset((void *)((uint8_t *)list->data + last_item_offset), 0, list->item_size); - list->length--; - AWS_POSTCONDITION(aws_array_list_is_valid(list)); - return AWS_OP_SUCCESS; - } - - AWS_POSTCONDITION(aws_array_list_is_valid(list)); - return aws_raise_error(AWS_ERROR_LIST_EMPTY); -} - -AWS_STATIC_IMPL -void aws_array_list_clear(struct aws_array_list *AWS_RESTRICT list) { - AWS_PRECONDITION(aws_array_list_is_valid(list)); - if (list->data) { -#ifdef DEBUG_BUILD - memset(list->data, AWS_ARRAY_LIST_DEBUG_FILL, list->current_size); -#endif - list->length = 0; - } - AWS_POSTCONDITION(aws_array_list_is_valid(list)); -} - -AWS_STATIC_IMPL -void aws_array_list_swap_contents( - struct aws_array_list *AWS_RESTRICT list_a, - struct aws_array_list *AWS_RESTRICT list_b) { + + size_t last_item_offset = list->item_size * (aws_array_list_length(list) - 1); + + memset((void *)((uint8_t *)list->data + last_item_offset), 0, list->item_size); + list->length--; + AWS_POSTCONDITION(aws_array_list_is_valid(list)); + return AWS_OP_SUCCESS; + } + + AWS_POSTCONDITION(aws_array_list_is_valid(list)); + return aws_raise_error(AWS_ERROR_LIST_EMPTY); +} + +AWS_STATIC_IMPL +void aws_array_list_clear(struct aws_array_list *AWS_RESTRICT list) { + AWS_PRECONDITION(aws_array_list_is_valid(list)); + if (list->data) { +#ifdef DEBUG_BUILD + memset(list->data, AWS_ARRAY_LIST_DEBUG_FILL, list->current_size); +#endif + list->length = 0; + } + AWS_POSTCONDITION(aws_array_list_is_valid(list)); +} + +AWS_STATIC_IMPL +void aws_array_list_swap_contents( + struct aws_array_list *AWS_RESTRICT list_a, + struct aws_array_list *AWS_RESTRICT list_b) { AWS_FATAL_PRECONDITION(list_a->alloc); AWS_FATAL_PRECONDITION(list_a->alloc == list_b->alloc); AWS_FATAL_PRECONDITION(list_a->item_size == list_b->item_size); AWS_FATAL_PRECONDITION(list_a != list_b); - AWS_PRECONDITION(aws_array_list_is_valid(list_a)); - AWS_PRECONDITION(aws_array_list_is_valid(list_b)); - - struct aws_array_list tmp = *list_a; - *list_a = *list_b; - *list_b = tmp; - AWS_POSTCONDITION(aws_array_list_is_valid(list_a)); - AWS_POSTCONDITION(aws_array_list_is_valid(list_b)); -} - -AWS_STATIC_IMPL -size_t aws_array_list_capacity(const struct aws_array_list *AWS_RESTRICT list) { + AWS_PRECONDITION(aws_array_list_is_valid(list_a)); + AWS_PRECONDITION(aws_array_list_is_valid(list_b)); + + struct aws_array_list tmp = *list_a; + *list_a = *list_b; + *list_b = tmp; + AWS_POSTCONDITION(aws_array_list_is_valid(list_a)); + AWS_POSTCONDITION(aws_array_list_is_valid(list_b)); +} + +AWS_STATIC_IMPL +size_t aws_array_list_capacity(const struct aws_array_list *AWS_RESTRICT list) { AWS_FATAL_PRECONDITION(list->item_size); - AWS_PRECONDITION(aws_array_list_is_valid(list)); - size_t capacity = list->current_size / list->item_size; - AWS_POSTCONDITION(aws_array_list_is_valid(list)); - return capacity; -} - -AWS_STATIC_IMPL -size_t aws_array_list_length(const struct aws_array_list *AWS_RESTRICT list) { - /* - * This assert teaches clang-tidy and friends that list->data cannot be null in a non-empty - * list. - */ + AWS_PRECONDITION(aws_array_list_is_valid(list)); + size_t capacity = list->current_size / list->item_size; + AWS_POSTCONDITION(aws_array_list_is_valid(list)); + return capacity; +} + +AWS_STATIC_IMPL +size_t aws_array_list_length(const struct aws_array_list *AWS_RESTRICT list) { + /* + * This assert teaches clang-tidy and friends that list->data cannot be null in a non-empty + * list. + */ AWS_FATAL_PRECONDITION(!list->length || list->data); - AWS_PRECONDITION(aws_array_list_is_valid(list)); - size_t len = list->length; - AWS_POSTCONDITION(aws_array_list_is_valid(list)); - return len; -} - -AWS_STATIC_IMPL -int aws_array_list_get_at(const struct aws_array_list *AWS_RESTRICT list, void *val, size_t index) { - AWS_PRECONDITION(aws_array_list_is_valid(list)); + AWS_PRECONDITION(aws_array_list_is_valid(list)); + size_t len = list->length; + AWS_POSTCONDITION(aws_array_list_is_valid(list)); + return len; +} + +AWS_STATIC_IMPL +int aws_array_list_get_at(const struct aws_array_list *AWS_RESTRICT list, void *val, size_t index) { + AWS_PRECONDITION(aws_array_list_is_valid(list)); AWS_PRECONDITION( val && AWS_MEM_IS_WRITABLE(val, list->item_size), "Input pointer [val] must point writable memory of [list->item_size] bytes."); - if (aws_array_list_length(list) > index) { - memcpy(val, (void *)((uint8_t *)list->data + (list->item_size * index)), list->item_size); - AWS_POSTCONDITION(aws_array_list_is_valid(list)); - return AWS_OP_SUCCESS; - } - AWS_POSTCONDITION(aws_array_list_is_valid(list)); - return aws_raise_error(AWS_ERROR_INVALID_INDEX); -} - -AWS_STATIC_IMPL -int aws_array_list_get_at_ptr(const struct aws_array_list *AWS_RESTRICT list, void **val, size_t index) { - AWS_PRECONDITION(aws_array_list_is_valid(list)); + if (aws_array_list_length(list) > index) { + memcpy(val, (void *)((uint8_t *)list->data + (list->item_size * index)), list->item_size); + AWS_POSTCONDITION(aws_array_list_is_valid(list)); + return AWS_OP_SUCCESS; + } + AWS_POSTCONDITION(aws_array_list_is_valid(list)); + return aws_raise_error(AWS_ERROR_INVALID_INDEX); +} + +AWS_STATIC_IMPL +int aws_array_list_get_at_ptr(const struct aws_array_list *AWS_RESTRICT list, void **val, size_t index) { + AWS_PRECONDITION(aws_array_list_is_valid(list)); AWS_PRECONDITION(val != NULL); - if (aws_array_list_length(list) > index) { - *val = (void *)((uint8_t *)list->data + (list->item_size * index)); - AWS_POSTCONDITION(aws_array_list_is_valid(list)); - return AWS_OP_SUCCESS; - } - AWS_POSTCONDITION(aws_array_list_is_valid(list)); - return aws_raise_error(AWS_ERROR_INVALID_INDEX); -} - -AWS_STATIC_IMPL + if (aws_array_list_length(list) > index) { + *val = (void *)((uint8_t *)list->data + (list->item_size * index)); + AWS_POSTCONDITION(aws_array_list_is_valid(list)); + return AWS_OP_SUCCESS; + } + AWS_POSTCONDITION(aws_array_list_is_valid(list)); + return aws_raise_error(AWS_ERROR_INVALID_INDEX); +} + +AWS_STATIC_IMPL int aws_array_list_set_at(struct aws_array_list *AWS_RESTRICT list, const void *val, size_t index) { - AWS_PRECONDITION(aws_array_list_is_valid(list)); + AWS_PRECONDITION(aws_array_list_is_valid(list)); AWS_PRECONDITION( val && AWS_MEM_IS_READABLE(val, list->item_size), "Input pointer [val] must point readable memory of [list->item_size] bytes."); - + if (aws_array_list_ensure_capacity(list, index)) { - AWS_POSTCONDITION(aws_array_list_is_valid(list)); - return AWS_OP_ERR; - } - + AWS_POSTCONDITION(aws_array_list_is_valid(list)); + return AWS_OP_ERR; + } + AWS_FATAL_PRECONDITION(list->data); - - memcpy((void *)((uint8_t *)list->data + (list->item_size * index)), val, list->item_size); - - /* - * This isn't perfect, but its the best I can come up with for detecting - * length changes. - */ - if (index >= aws_array_list_length(list)) { - if (aws_add_size_checked(index, 1, &list->length)) { - AWS_POSTCONDITION(aws_array_list_is_valid(list)); - return AWS_OP_ERR; - } - } - - AWS_POSTCONDITION(aws_array_list_is_valid(list)); - return AWS_OP_SUCCESS; -} - -AWS_STATIC_IMPL -void aws_array_list_sort(struct aws_array_list *AWS_RESTRICT list, aws_array_list_comparator_fn *compare_fn) { - AWS_PRECONDITION(aws_array_list_is_valid(list)); - if (list->data) { - qsort(list->data, aws_array_list_length(list), list->item_size, compare_fn); - } - AWS_POSTCONDITION(aws_array_list_is_valid(list)); -} + + memcpy((void *)((uint8_t *)list->data + (list->item_size * index)), val, list->item_size); + + /* + * This isn't perfect, but its the best I can come up with for detecting + * length changes. + */ + if (index >= aws_array_list_length(list)) { + if (aws_add_size_checked(index, 1, &list->length)) { + AWS_POSTCONDITION(aws_array_list_is_valid(list)); + return AWS_OP_ERR; + } + } + + AWS_POSTCONDITION(aws_array_list_is_valid(list)); + return AWS_OP_SUCCESS; +} + +AWS_STATIC_IMPL +void aws_array_list_sort(struct aws_array_list *AWS_RESTRICT list, aws_array_list_comparator_fn *compare_fn) { + AWS_PRECONDITION(aws_array_list_is_valid(list)); + if (list->data) { + qsort(list->data, aws_array_list_length(list), list->item_size, compare_fn); + } + AWS_POSTCONDITION(aws_array_list_is_valid(list)); +} AWS_EXTERN_C_END diff --git a/contrib/restricted/aws/aws-c-common/include/aws/common/atomics.h b/contrib/restricted/aws/aws-c-common/include/aws/common/atomics.h index fd204764ed..e2ee8df95a 100644 --- a/contrib/restricted/aws/aws-c-common/include/aws/common/atomics.h +++ b/contrib/restricted/aws/aws-c-common/include/aws/common/atomics.h @@ -1,327 +1,327 @@ -#ifndef AWS_COMMON_ATOMICS_H -#define AWS_COMMON_ATOMICS_H - -#include <aws/common/common.h> - +#ifndef AWS_COMMON_ATOMICS_H +#define AWS_COMMON_ATOMICS_H + +#include <aws/common/common.h> + /** * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. - */ - -/** - * struct aws_atomic_var represents an atomic variable - a value which can hold an integer or pointer - * that can be manipulated atomically. struct aws_atomic_vars should normally only be manipulated - * with atomics methods defined in this header. - */ -struct aws_atomic_var { - void *value; -}; -/* Helpers for extracting the integer and pointer values from aws_atomic_var. */ + */ + +/** + * struct aws_atomic_var represents an atomic variable - a value which can hold an integer or pointer + * that can be manipulated atomically. struct aws_atomic_vars should normally only be manipulated + * with atomics methods defined in this header. + */ +struct aws_atomic_var { + void *value; +}; +/* Helpers for extracting the integer and pointer values from aws_atomic_var. */ #define AWS_ATOMIC_VAR_PTRVAL(var) ((var)->value) #define AWS_ATOMIC_VAR_INTVAL(var) (*(aws_atomic_impl_int_t *)(var)) - -/* - * This enumeration specifies the memory ordering properties requested for a particular - * atomic operation. The atomic operation may provide stricter ordering than requested. - * Note that, within a single thread, all operations are still sequenced (that is, a thread - * sees its own atomic writes and reads happening in program order, but other threads may - * disagree on this ordering). - * - * The behavior of these memory orderings are the same as in the C11 atomics API; however, - * we only implement a subset that can be portably implemented on the compilers we target. - */ - -enum aws_memory_order { - /** - * No particular ordering constraints are guaranteed relative to other - * operations at all; we merely ensure that the operation itself is atomic. - */ - aws_memory_order_relaxed = 0, - /* aws_memory_order_consume - not currently implemented */ - - /** - * Specifies acquire ordering. No reads or writes on the current thread can be - * reordered to happen before this operation. This is typically paired with a release - * ordering; any writes that happened on the releasing operation will be visible - * after the paired acquire operation. - * - * Acquire ordering is only meaningful on load or load-store operations. - */ - aws_memory_order_acquire = 2, /* leave a spot for consume if we ever add it */ - - /** - * Specifies release order. No reads or writes can be reordered to come after this - * operation. Typically paired with an acquire operation. - * - * Release ordering is only meaningful on store or load-store operations. - */ - aws_memory_order_release, - - /** - * Specifies acquire-release order; if this operation acts as a load, it acts as an - * acquire operation; if it acts as a store, it acts as a release operation; if it's - * a load-store, it does both. - */ - aws_memory_order_acq_rel, - - /* - * Specifies sequentially consistent order. This behaves as acq_rel, but in addition, - * all seq_cst operations appear to occur in some globally consistent order. - * - * TODO: Figure out how to correctly implement this in MSVC. It appears that interlocked - * functions provide only acq_rel ordering. - */ - aws_memory_order_seq_cst -}; - -/** - * Statically initializes an aws_atomic_var to a given size_t value. - */ -#define AWS_ATOMIC_INIT_INT(x) \ - { .value = (void *)(uintptr_t)(x) } - -/** - * Statically initializes an aws_atomic_var to a given void * value. - */ -#define AWS_ATOMIC_INIT_PTR(x) \ - { .value = (void *)(x) } - + +/* + * This enumeration specifies the memory ordering properties requested for a particular + * atomic operation. The atomic operation may provide stricter ordering than requested. + * Note that, within a single thread, all operations are still sequenced (that is, a thread + * sees its own atomic writes and reads happening in program order, but other threads may + * disagree on this ordering). + * + * The behavior of these memory orderings are the same as in the C11 atomics API; however, + * we only implement a subset that can be portably implemented on the compilers we target. + */ + +enum aws_memory_order { + /** + * No particular ordering constraints are guaranteed relative to other + * operations at all; we merely ensure that the operation itself is atomic. + */ + aws_memory_order_relaxed = 0, + /* aws_memory_order_consume - not currently implemented */ + + /** + * Specifies acquire ordering. No reads or writes on the current thread can be + * reordered to happen before this operation. This is typically paired with a release + * ordering; any writes that happened on the releasing operation will be visible + * after the paired acquire operation. + * + * Acquire ordering is only meaningful on load or load-store operations. + */ + aws_memory_order_acquire = 2, /* leave a spot for consume if we ever add it */ + + /** + * Specifies release order. No reads or writes can be reordered to come after this + * operation. Typically paired with an acquire operation. + * + * Release ordering is only meaningful on store or load-store operations. + */ + aws_memory_order_release, + + /** + * Specifies acquire-release order; if this operation acts as a load, it acts as an + * acquire operation; if it acts as a store, it acts as a release operation; if it's + * a load-store, it does both. + */ + aws_memory_order_acq_rel, + + /* + * Specifies sequentially consistent order. This behaves as acq_rel, but in addition, + * all seq_cst operations appear to occur in some globally consistent order. + * + * TODO: Figure out how to correctly implement this in MSVC. It appears that interlocked + * functions provide only acq_rel ordering. + */ + aws_memory_order_seq_cst +}; + +/** + * Statically initializes an aws_atomic_var to a given size_t value. + */ +#define AWS_ATOMIC_INIT_INT(x) \ + { .value = (void *)(uintptr_t)(x) } + +/** + * Statically initializes an aws_atomic_var to a given void * value. + */ +#define AWS_ATOMIC_INIT_PTR(x) \ + { .value = (void *)(x) } + AWS_EXTERN_C_BEGIN -/* - * Note: We do not use the C11 atomics API; this is because we want to make sure the representation - * (and behavior) of atomic values is consistent, regardless of what --std= flag you pass to your compiler. - * Since C11 atomics can silently introduce locks, we run the risk of creating such ABI inconsistencies - * if we decide based on compiler features which atomics API to use, and in practice we expect to have - * either the GNU or MSVC atomics anyway. - * - * As future work, we could test to see if the C11 atomics API on this platform behaves consistently - * with the other APIs and use it if it does. - */ - -/** - * Initializes an atomic variable with an integer value. This operation should be done before any - * other operations on this atomic variable, and must be done before attempting any parallel operations. - * - * This operation does not imply a barrier. Ensure that you use an acquire-release barrier (or stronger) - * when communicating the fact that initialization is complete to the other thread. Launching the thread - * implies a sufficiently strong barrier. - */ -AWS_STATIC_IMPL -void aws_atomic_init_int(volatile struct aws_atomic_var *var, size_t n); - -/** - * Initializes an atomic variable with a pointer value. This operation should be done before any - * other operations on this atomic variable, and must be done before attempting any parallel operations. - * - * This operation does not imply a barrier. Ensure that you use an acquire-release barrier (or stronger) - * when communicating the fact that initialization is complete to the other thread. Launching the thread - * implies a sufficiently strong barrier. - */ -AWS_STATIC_IMPL -void aws_atomic_init_ptr(volatile struct aws_atomic_var *var, void *p); - -/** - * Reads an atomic var as an integer, using the specified ordering, and returns the result. - */ -AWS_STATIC_IMPL -size_t aws_atomic_load_int_explicit(volatile const struct aws_atomic_var *var, enum aws_memory_order memory_order); - -/** - * Reads an atomic var as an integer, using sequentially consistent ordering, and returns the result. - */ -AWS_STATIC_IMPL +/* + * Note: We do not use the C11 atomics API; this is because we want to make sure the representation + * (and behavior) of atomic values is consistent, regardless of what --std= flag you pass to your compiler. + * Since C11 atomics can silently introduce locks, we run the risk of creating such ABI inconsistencies + * if we decide based on compiler features which atomics API to use, and in practice we expect to have + * either the GNU or MSVC atomics anyway. + * + * As future work, we could test to see if the C11 atomics API on this platform behaves consistently + * with the other APIs and use it if it does. + */ + +/** + * Initializes an atomic variable with an integer value. This operation should be done before any + * other operations on this atomic variable, and must be done before attempting any parallel operations. + * + * This operation does not imply a barrier. Ensure that you use an acquire-release barrier (or stronger) + * when communicating the fact that initialization is complete to the other thread. Launching the thread + * implies a sufficiently strong barrier. + */ +AWS_STATIC_IMPL +void aws_atomic_init_int(volatile struct aws_atomic_var *var, size_t n); + +/** + * Initializes an atomic variable with a pointer value. This operation should be done before any + * other operations on this atomic variable, and must be done before attempting any parallel operations. + * + * This operation does not imply a barrier. Ensure that you use an acquire-release barrier (or stronger) + * when communicating the fact that initialization is complete to the other thread. Launching the thread + * implies a sufficiently strong barrier. + */ +AWS_STATIC_IMPL +void aws_atomic_init_ptr(volatile struct aws_atomic_var *var, void *p); + +/** + * Reads an atomic var as an integer, using the specified ordering, and returns the result. + */ +AWS_STATIC_IMPL +size_t aws_atomic_load_int_explicit(volatile const struct aws_atomic_var *var, enum aws_memory_order memory_order); + +/** + * Reads an atomic var as an integer, using sequentially consistent ordering, and returns the result. + */ +AWS_STATIC_IMPL size_t aws_atomic_load_int(volatile const struct aws_atomic_var *var); -/** - * Reads an atomic var as a pointer, using the specified ordering, and returns the result. - */ -AWS_STATIC_IMPL -void *aws_atomic_load_ptr_explicit(volatile const struct aws_atomic_var *var, enum aws_memory_order memory_order); - -/** - * Reads an atomic var as a pointer, using sequentially consistent ordering, and returns the result. - */ -AWS_STATIC_IMPL +/** + * Reads an atomic var as a pointer, using the specified ordering, and returns the result. + */ +AWS_STATIC_IMPL +void *aws_atomic_load_ptr_explicit(volatile const struct aws_atomic_var *var, enum aws_memory_order memory_order); + +/** + * Reads an atomic var as a pointer, using sequentially consistent ordering, and returns the result. + */ +AWS_STATIC_IMPL void *aws_atomic_load_ptr(volatile const struct aws_atomic_var *var); - -/** - * Stores an integer into an atomic var, using the specified ordering. - */ -AWS_STATIC_IMPL -void aws_atomic_store_int_explicit(volatile struct aws_atomic_var *var, size_t n, enum aws_memory_order memory_order); - -/** - * Stores an integer into an atomic var, using sequentially consistent ordering. - */ -AWS_STATIC_IMPL + +/** + * Stores an integer into an atomic var, using the specified ordering. + */ +AWS_STATIC_IMPL +void aws_atomic_store_int_explicit(volatile struct aws_atomic_var *var, size_t n, enum aws_memory_order memory_order); + +/** + * Stores an integer into an atomic var, using sequentially consistent ordering. + */ +AWS_STATIC_IMPL void aws_atomic_store_int(volatile struct aws_atomic_var *var, size_t n); - -/** - * Stores a pointer into an atomic var, using the specified ordering. - */ -AWS_STATIC_IMPL -void aws_atomic_store_ptr_explicit(volatile struct aws_atomic_var *var, void *p, enum aws_memory_order memory_order); - -/** - * Stores a pointer into an atomic var, using sequentially consistent ordering. - */ -AWS_STATIC_IMPL + +/** + * Stores a pointer into an atomic var, using the specified ordering. + */ +AWS_STATIC_IMPL +void aws_atomic_store_ptr_explicit(volatile struct aws_atomic_var *var, void *p, enum aws_memory_order memory_order); + +/** + * Stores a pointer into an atomic var, using sequentially consistent ordering. + */ +AWS_STATIC_IMPL void aws_atomic_store_ptr(volatile struct aws_atomic_var *var, void *p); - -/** - * Exchanges an integer with the value in an atomic_var, using the specified ordering. - * Returns the value that was previously in the atomic_var. - */ -AWS_STATIC_IMPL -size_t aws_atomic_exchange_int_explicit( - volatile struct aws_atomic_var *var, - size_t n, - enum aws_memory_order memory_order); - -/** - * Exchanges an integer with the value in an atomic_var, using sequentially consistent ordering. - * Returns the value that was previously in the atomic_var. - */ -AWS_STATIC_IMPL + +/** + * Exchanges an integer with the value in an atomic_var, using the specified ordering. + * Returns the value that was previously in the atomic_var. + */ +AWS_STATIC_IMPL +size_t aws_atomic_exchange_int_explicit( + volatile struct aws_atomic_var *var, + size_t n, + enum aws_memory_order memory_order); + +/** + * Exchanges an integer with the value in an atomic_var, using sequentially consistent ordering. + * Returns the value that was previously in the atomic_var. + */ +AWS_STATIC_IMPL size_t aws_atomic_exchange_int(volatile struct aws_atomic_var *var, size_t n); - -/** - * Exchanges a pointer with the value in an atomic_var, using the specified ordering. - * Returns the value that was previously in the atomic_var. - */ -AWS_STATIC_IMPL -void *aws_atomic_exchange_ptr_explicit( - volatile struct aws_atomic_var *var, - void *p, - enum aws_memory_order memory_order); - -/** - * Exchanges an integer with the value in an atomic_var, using sequentially consistent ordering. - * Returns the value that was previously in the atomic_var. - */ -AWS_STATIC_IMPL + +/** + * Exchanges a pointer with the value in an atomic_var, using the specified ordering. + * Returns the value that was previously in the atomic_var. + */ +AWS_STATIC_IMPL +void *aws_atomic_exchange_ptr_explicit( + volatile struct aws_atomic_var *var, + void *p, + enum aws_memory_order memory_order); + +/** + * Exchanges an integer with the value in an atomic_var, using sequentially consistent ordering. + * Returns the value that was previously in the atomic_var. + */ +AWS_STATIC_IMPL void *aws_atomic_exchange_ptr(volatile struct aws_atomic_var *var, void *p); - -/** - * Atomically compares *var to *expected; if they are equal, atomically sets *var = desired. Otherwise, *expected is set - * to the value in *var. On success, the memory ordering used was order_success; otherwise, it was order_failure. - * order_failure must be no stronger than order_success, and must not be release or acq_rel. - * Returns true if the compare was successful and the variable updated to desired. - */ -AWS_STATIC_IMPL -bool aws_atomic_compare_exchange_int_explicit( - volatile struct aws_atomic_var *var, - size_t *expected, - size_t desired, - enum aws_memory_order order_success, - enum aws_memory_order order_failure); - -/** - * Atomically compares *var to *expected; if they are equal, atomically sets *var = desired. Otherwise, *expected is set - * to the value in *var. Uses sequentially consistent memory ordering, regardless of success or failure. - * Returns true if the compare was successful and the variable updated to desired. - */ -AWS_STATIC_IMPL + +/** + * Atomically compares *var to *expected; if they are equal, atomically sets *var = desired. Otherwise, *expected is set + * to the value in *var. On success, the memory ordering used was order_success; otherwise, it was order_failure. + * order_failure must be no stronger than order_success, and must not be release or acq_rel. + * Returns true if the compare was successful and the variable updated to desired. + */ +AWS_STATIC_IMPL +bool aws_atomic_compare_exchange_int_explicit( + volatile struct aws_atomic_var *var, + size_t *expected, + size_t desired, + enum aws_memory_order order_success, + enum aws_memory_order order_failure); + +/** + * Atomically compares *var to *expected; if they are equal, atomically sets *var = desired. Otherwise, *expected is set + * to the value in *var. Uses sequentially consistent memory ordering, regardless of success or failure. + * Returns true if the compare was successful and the variable updated to desired. + */ +AWS_STATIC_IMPL bool aws_atomic_compare_exchange_int(volatile struct aws_atomic_var *var, size_t *expected, size_t desired); - -/** - * Atomically compares *var to *expected; if they are equal, atomically sets *var = desired. Otherwise, *expected is set - * to the value in *var. On success, the memory ordering used was order_success; otherwise, it was order_failure. - * order_failure must be no stronger than order_success, and must not be release or acq_rel. - * Returns true if the compare was successful and the variable updated to desired. - */ -AWS_STATIC_IMPL -bool aws_atomic_compare_exchange_ptr_explicit( - volatile struct aws_atomic_var *var, - void **expected, - void *desired, - enum aws_memory_order order_success, - enum aws_memory_order order_failure); - -/** - * Atomically compares *var to *expected; if they are equal, atomically sets *var = desired. Otherwise, *expected is set - * to the value in *var. Uses sequentially consistent memory ordering, regardless of success or failure. - * Returns true if the compare was successful and the variable updated to desired. - */ -AWS_STATIC_IMPL + +/** + * Atomically compares *var to *expected; if they are equal, atomically sets *var = desired. Otherwise, *expected is set + * to the value in *var. On success, the memory ordering used was order_success; otherwise, it was order_failure. + * order_failure must be no stronger than order_success, and must not be release or acq_rel. + * Returns true if the compare was successful and the variable updated to desired. + */ +AWS_STATIC_IMPL +bool aws_atomic_compare_exchange_ptr_explicit( + volatile struct aws_atomic_var *var, + void **expected, + void *desired, + enum aws_memory_order order_success, + enum aws_memory_order order_failure); + +/** + * Atomically compares *var to *expected; if they are equal, atomically sets *var = desired. Otherwise, *expected is set + * to the value in *var. Uses sequentially consistent memory ordering, regardless of success or failure. + * Returns true if the compare was successful and the variable updated to desired. + */ +AWS_STATIC_IMPL bool aws_atomic_compare_exchange_ptr(volatile struct aws_atomic_var *var, void **expected, void *desired); - -/** - * Atomically adds n to *var, and returns the previous value of *var. - */ -AWS_STATIC_IMPL -size_t aws_atomic_fetch_add_explicit(volatile struct aws_atomic_var *var, size_t n, enum aws_memory_order order); - -/** - * Atomically subtracts n from *var, and returns the previous value of *var. - */ -AWS_STATIC_IMPL -size_t aws_atomic_fetch_sub_explicit(volatile struct aws_atomic_var *var, size_t n, enum aws_memory_order order); - -/** - * Atomically ORs n with *var, and returns the previous value of *var. - */ -AWS_STATIC_IMPL -size_t aws_atomic_fetch_or_explicit(volatile struct aws_atomic_var *var, size_t n, enum aws_memory_order order); - -/** - * Atomically ANDs n with *var, and returns the previous value of *var. - */ -AWS_STATIC_IMPL -size_t aws_atomic_fetch_and_explicit(volatile struct aws_atomic_var *var, size_t n, enum aws_memory_order order); - -/** - * Atomically XORs n with *var, and returns the previous value of *var. - */ -AWS_STATIC_IMPL -size_t aws_atomic_fetch_xor_explicit(volatile struct aws_atomic_var *var, size_t n, enum aws_memory_order order); - -/** - * Atomically adds n to *var, and returns the previous value of *var. - * Uses sequentially consistent ordering. - */ -AWS_STATIC_IMPL + +/** + * Atomically adds n to *var, and returns the previous value of *var. + */ +AWS_STATIC_IMPL +size_t aws_atomic_fetch_add_explicit(volatile struct aws_atomic_var *var, size_t n, enum aws_memory_order order); + +/** + * Atomically subtracts n from *var, and returns the previous value of *var. + */ +AWS_STATIC_IMPL +size_t aws_atomic_fetch_sub_explicit(volatile struct aws_atomic_var *var, size_t n, enum aws_memory_order order); + +/** + * Atomically ORs n with *var, and returns the previous value of *var. + */ +AWS_STATIC_IMPL +size_t aws_atomic_fetch_or_explicit(volatile struct aws_atomic_var *var, size_t n, enum aws_memory_order order); + +/** + * Atomically ANDs n with *var, and returns the previous value of *var. + */ +AWS_STATIC_IMPL +size_t aws_atomic_fetch_and_explicit(volatile struct aws_atomic_var *var, size_t n, enum aws_memory_order order); + +/** + * Atomically XORs n with *var, and returns the previous value of *var. + */ +AWS_STATIC_IMPL +size_t aws_atomic_fetch_xor_explicit(volatile struct aws_atomic_var *var, size_t n, enum aws_memory_order order); + +/** + * Atomically adds n to *var, and returns the previous value of *var. + * Uses sequentially consistent ordering. + */ +AWS_STATIC_IMPL size_t aws_atomic_fetch_add(volatile struct aws_atomic_var *var, size_t n); - -/** - * Atomically subtracts n from *var, and returns the previous value of *var. - * Uses sequentially consistent ordering. - */ -AWS_STATIC_IMPL + +/** + * Atomically subtracts n from *var, and returns the previous value of *var. + * Uses sequentially consistent ordering. + */ +AWS_STATIC_IMPL size_t aws_atomic_fetch_sub(volatile struct aws_atomic_var *var, size_t n); - -/** - * Atomically ands n into *var, and returns the previous value of *var. - * Uses sequentially consistent ordering. - */ -AWS_STATIC_IMPL + +/** + * Atomically ands n into *var, and returns the previous value of *var. + * Uses sequentially consistent ordering. + */ +AWS_STATIC_IMPL size_t aws_atomic_fetch_and(volatile struct aws_atomic_var *var, size_t n); - -/** - * Atomically ors n into *var, and returns the previous value of *var. - * Uses sequentially consistent ordering. - */ -AWS_STATIC_IMPL + +/** + * Atomically ors n into *var, and returns the previous value of *var. + * Uses sequentially consistent ordering. + */ +AWS_STATIC_IMPL size_t aws_atomic_fetch_or(volatile struct aws_atomic_var *var, size_t n); - -/** - * Atomically xors n into *var, and returns the previous value of *var. - * Uses sequentially consistent ordering. - */ -AWS_STATIC_IMPL + +/** + * Atomically xors n into *var, and returns the previous value of *var. + * Uses sequentially consistent ordering. + */ +AWS_STATIC_IMPL size_t aws_atomic_fetch_xor(volatile struct aws_atomic_var *var, size_t n); - -/** - * Provides the same reordering guarantees as an atomic operation with the specified memory order, without - * needing to actually perform an atomic operation. - */ -AWS_STATIC_IMPL -void aws_atomic_thread_fence(enum aws_memory_order order); - + +/** + * Provides the same reordering guarantees as an atomic operation with the specified memory order, without + * needing to actually perform an atomic operation. + */ +AWS_STATIC_IMPL +void aws_atomic_thread_fence(enum aws_memory_order order); + #ifndef AWS_NO_STATIC_IMPL # include <aws/common/atomics.inl> #endif /* AWS_NO_STATIC_IMPL */ - + AWS_EXTERN_C_END -#endif +#endif diff --git a/contrib/restricted/aws/aws-c-common/include/aws/common/atomics_fallback.inl b/contrib/restricted/aws/aws-c-common/include/aws/common/atomics_fallback.inl index e51252b4bc..e0c52d80cc 100644 --- a/contrib/restricted/aws/aws-c-common/include/aws/common/atomics_fallback.inl +++ b/contrib/restricted/aws/aws-c-common/include/aws/common/atomics_fallback.inl @@ -4,20 +4,20 @@ /** * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. - */ - + */ + AWS_EXTERN_C_BEGIN -#ifndef AWS_ATOMICS_HAVE_THREAD_FENCE - -void aws_atomic_thread_fence(enum aws_memory_order order) { - struct aws_atomic_var var; - aws_atomic_int_t expected = 0; - - aws_atomic_store_int(&var, expected, aws_memory_order_relaxed); - aws_atomic_compare_exchange_int(&var, &expected, 1, order, aws_memory_order_relaxed); -} - +#ifndef AWS_ATOMICS_HAVE_THREAD_FENCE + +void aws_atomic_thread_fence(enum aws_memory_order order) { + struct aws_atomic_var var; + aws_atomic_int_t expected = 0; + + aws_atomic_store_int(&var, expected, aws_memory_order_relaxed); + aws_atomic_compare_exchange_int(&var, &expected, 1, order, aws_memory_order_relaxed); +} + #endif /* AWS_ATOMICS_HAVE_THREAD_FENCE */ AWS_EXTERN_C_END diff --git a/contrib/restricted/aws/aws-c-common/include/aws/common/atomics_gnu.inl b/contrib/restricted/aws/aws-c-common/include/aws/common/atomics_gnu.inl index dc72543762..711b7795d6 100644 --- a/contrib/restricted/aws/aws-c-common/include/aws/common/atomics_gnu.inl +++ b/contrib/restricted/aws/aws-c-common/include/aws/common/atomics_gnu.inl @@ -4,215 +4,215 @@ /** * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. - */ - -/* These are implicitly included, but help with editor highlighting */ -#include <aws/common/atomics.h> -#include <aws/common/common.h> - -#include <stdint.h> -#include <stdlib.h> - + */ + +/* These are implicitly included, but help with editor highlighting */ +#include <aws/common/atomics.h> +#include <aws/common/common.h> + +#include <stdint.h> +#include <stdlib.h> + AWS_EXTERN_C_BEGIN -#ifdef __clang__ -# pragma clang diagnostic push -# pragma clang diagnostic ignored "-Wc11-extensions" -#else -# pragma GCC diagnostic push -# pragma GCC diagnostic ignored "-Wpedantic" -#endif - -typedef size_t aws_atomic_impl_int_t; - -static inline int aws_atomic_priv_xlate_order(enum aws_memory_order order) { - switch (order) { - case aws_memory_order_relaxed: - return __ATOMIC_RELAXED; - case aws_memory_order_acquire: - return __ATOMIC_ACQUIRE; - case aws_memory_order_release: - return __ATOMIC_RELEASE; - case aws_memory_order_acq_rel: - return __ATOMIC_ACQ_REL; - case aws_memory_order_seq_cst: - return __ATOMIC_SEQ_CST; - default: /* Unknown memory order */ - abort(); - } -} - -/** - * Initializes an atomic variable with an integer value. This operation should be done before any - * other operations on this atomic variable, and must be done before attempting any parallel operations. - */ -AWS_STATIC_IMPL -void aws_atomic_init_int(volatile struct aws_atomic_var *var, size_t n) { - AWS_ATOMIC_VAR_INTVAL(var) = n; -} - -/** - * Initializes an atomic variable with a pointer value. This operation should be done before any - * other operations on this atomic variable, and must be done before attempting any parallel operations. - */ -AWS_STATIC_IMPL -void aws_atomic_init_ptr(volatile struct aws_atomic_var *var, void *p) { - AWS_ATOMIC_VAR_PTRVAL(var) = p; -} - -/** - * Reads an atomic var as an integer, using the specified ordering, and returns the result. - */ -AWS_STATIC_IMPL -size_t aws_atomic_load_int_explicit(volatile const struct aws_atomic_var *var, enum aws_memory_order memory_order) { - return __atomic_load_n(&AWS_ATOMIC_VAR_INTVAL(var), aws_atomic_priv_xlate_order(memory_order)); -} - -/** +#ifdef __clang__ +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wc11-extensions" +#else +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wpedantic" +#endif + +typedef size_t aws_atomic_impl_int_t; + +static inline int aws_atomic_priv_xlate_order(enum aws_memory_order order) { + switch (order) { + case aws_memory_order_relaxed: + return __ATOMIC_RELAXED; + case aws_memory_order_acquire: + return __ATOMIC_ACQUIRE; + case aws_memory_order_release: + return __ATOMIC_RELEASE; + case aws_memory_order_acq_rel: + return __ATOMIC_ACQ_REL; + case aws_memory_order_seq_cst: + return __ATOMIC_SEQ_CST; + default: /* Unknown memory order */ + abort(); + } +} + +/** + * Initializes an atomic variable with an integer value. This operation should be done before any + * other operations on this atomic variable, and must be done before attempting any parallel operations. + */ +AWS_STATIC_IMPL +void aws_atomic_init_int(volatile struct aws_atomic_var *var, size_t n) { + AWS_ATOMIC_VAR_INTVAL(var) = n; +} + +/** + * Initializes an atomic variable with a pointer value. This operation should be done before any + * other operations on this atomic variable, and must be done before attempting any parallel operations. + */ +AWS_STATIC_IMPL +void aws_atomic_init_ptr(volatile struct aws_atomic_var *var, void *p) { + AWS_ATOMIC_VAR_PTRVAL(var) = p; +} + +/** + * Reads an atomic var as an integer, using the specified ordering, and returns the result. + */ +AWS_STATIC_IMPL +size_t aws_atomic_load_int_explicit(volatile const struct aws_atomic_var *var, enum aws_memory_order memory_order) { + return __atomic_load_n(&AWS_ATOMIC_VAR_INTVAL(var), aws_atomic_priv_xlate_order(memory_order)); +} + +/** * Reads an atomic var as a pointer, using the specified ordering, and returns the result. - */ -AWS_STATIC_IMPL -void *aws_atomic_load_ptr_explicit(volatile const struct aws_atomic_var *var, enum aws_memory_order memory_order) { - return __atomic_load_n(&AWS_ATOMIC_VAR_PTRVAL(var), aws_atomic_priv_xlate_order(memory_order)); -} - -/** - * Stores an integer into an atomic var, using the specified ordering. - */ -AWS_STATIC_IMPL -void aws_atomic_store_int_explicit(volatile struct aws_atomic_var *var, size_t n, enum aws_memory_order memory_order) { - __atomic_store_n(&AWS_ATOMIC_VAR_INTVAL(var), n, aws_atomic_priv_xlate_order(memory_order)); -} - -/** - * Stores an pointer into an atomic var, using the specified ordering. - */ -AWS_STATIC_IMPL -void aws_atomic_store_ptr_explicit(volatile struct aws_atomic_var *var, void *p, enum aws_memory_order memory_order) { - __atomic_store_n(&AWS_ATOMIC_VAR_PTRVAL(var), p, aws_atomic_priv_xlate_order(memory_order)); -} - -/** - * Exchanges an integer with the value in an atomic_var, using the specified ordering. - * Returns the value that was previously in the atomic_var. - */ -AWS_STATIC_IMPL -size_t aws_atomic_exchange_int_explicit( - volatile struct aws_atomic_var *var, - size_t n, - enum aws_memory_order memory_order) { - return __atomic_exchange_n(&AWS_ATOMIC_VAR_INTVAL(var), n, aws_atomic_priv_xlate_order(memory_order)); -} - -/** - * Exchanges a pointer with the value in an atomic_var, using the specified ordering. - * Returns the value that was previously in the atomic_var. - */ -AWS_STATIC_IMPL -void *aws_atomic_exchange_ptr_explicit( - volatile struct aws_atomic_var *var, - void *p, - enum aws_memory_order memory_order) { - return __atomic_exchange_n(&AWS_ATOMIC_VAR_PTRVAL(var), p, aws_atomic_priv_xlate_order(memory_order)); -} - -/** - * Atomically compares *var to *expected; if they are equal, atomically sets *var = desired. Otherwise, *expected is set - * to the value in *var. On success, the memory ordering used was order_success; otherwise, it was order_failure. - * order_failure must be no stronger than order_success, and must not be release or acq_rel. - */ -AWS_STATIC_IMPL -bool aws_atomic_compare_exchange_int_explicit( - volatile struct aws_atomic_var *var, - size_t *expected, - size_t desired, - enum aws_memory_order order_success, - enum aws_memory_order order_failure) { - return __atomic_compare_exchange_n( - &AWS_ATOMIC_VAR_INTVAL(var), - expected, - desired, - false, - aws_atomic_priv_xlate_order(order_success), - aws_atomic_priv_xlate_order(order_failure)); -} - -/** - * Atomically compares *var to *expected; if they are equal, atomically sets *var = desired. Otherwise, *expected is set - * to the value in *var. On success, the memory ordering used was order_success; otherwise, it was order_failure. - * order_failure must be no stronger than order_success, and must not be release or acq_rel. - */ -AWS_STATIC_IMPL -bool aws_atomic_compare_exchange_ptr_explicit( - volatile struct aws_atomic_var *var, - void **expected, - void *desired, - enum aws_memory_order order_success, - enum aws_memory_order order_failure) { - return __atomic_compare_exchange_n( - &AWS_ATOMIC_VAR_PTRVAL(var), - expected, - desired, - false, - aws_atomic_priv_xlate_order(order_success), - aws_atomic_priv_xlate_order(order_failure)); -} - -/** - * Atomically adds n to *var, and returns the previous value of *var. - */ -AWS_STATIC_IMPL -size_t aws_atomic_fetch_add_explicit(volatile struct aws_atomic_var *var, size_t n, enum aws_memory_order order) { - return __atomic_fetch_add(&AWS_ATOMIC_VAR_INTVAL(var), n, aws_atomic_priv_xlate_order(order)); -} - -/** - * Atomically subtracts n from *var, and returns the previous value of *var. - */ -AWS_STATIC_IMPL -size_t aws_atomic_fetch_sub_explicit(volatile struct aws_atomic_var *var, size_t n, enum aws_memory_order order) { - return __atomic_fetch_sub(&AWS_ATOMIC_VAR_INTVAL(var), n, aws_atomic_priv_xlate_order(order)); -} - -/** - * Atomically ORs n with *var, and returns the previous value of *var. - */ -AWS_STATIC_IMPL -size_t aws_atomic_fetch_or_explicit(volatile struct aws_atomic_var *var, size_t n, enum aws_memory_order order) { - return __atomic_fetch_or(&AWS_ATOMIC_VAR_INTVAL(var), n, aws_atomic_priv_xlate_order(order)); -} - -/** - * Atomically ANDs n with *var, and returns the previous value of *var. - */ -AWS_STATIC_IMPL -size_t aws_atomic_fetch_and_explicit(volatile struct aws_atomic_var *var, size_t n, enum aws_memory_order order) { - return __atomic_fetch_and(&AWS_ATOMIC_VAR_INTVAL(var), n, aws_atomic_priv_xlate_order(order)); -} - -/** - * Atomically XORs n with *var, and returns the previous value of *var. - */ -AWS_STATIC_IMPL -size_t aws_atomic_fetch_xor_explicit(volatile struct aws_atomic_var *var, size_t n, enum aws_memory_order order) { - return __atomic_fetch_xor(&AWS_ATOMIC_VAR_INTVAL(var), n, aws_atomic_priv_xlate_order(order)); -} - -/** - * Provides the same reordering guarantees as an atomic operation with the specified memory order, without - * needing to actually perform an atomic operation. - */ -AWS_STATIC_IMPL -void aws_atomic_thread_fence(enum aws_memory_order order) { - __atomic_thread_fence(order); -} - -#ifdef __clang__ -# pragma clang diagnostic pop -#else -# pragma GCC diagnostic pop -#endif - -#define AWS_ATOMICS_HAVE_THREAD_FENCE + */ +AWS_STATIC_IMPL +void *aws_atomic_load_ptr_explicit(volatile const struct aws_atomic_var *var, enum aws_memory_order memory_order) { + return __atomic_load_n(&AWS_ATOMIC_VAR_PTRVAL(var), aws_atomic_priv_xlate_order(memory_order)); +} + +/** + * Stores an integer into an atomic var, using the specified ordering. + */ +AWS_STATIC_IMPL +void aws_atomic_store_int_explicit(volatile struct aws_atomic_var *var, size_t n, enum aws_memory_order memory_order) { + __atomic_store_n(&AWS_ATOMIC_VAR_INTVAL(var), n, aws_atomic_priv_xlate_order(memory_order)); +} + +/** + * Stores an pointer into an atomic var, using the specified ordering. + */ +AWS_STATIC_IMPL +void aws_atomic_store_ptr_explicit(volatile struct aws_atomic_var *var, void *p, enum aws_memory_order memory_order) { + __atomic_store_n(&AWS_ATOMIC_VAR_PTRVAL(var), p, aws_atomic_priv_xlate_order(memory_order)); +} + +/** + * Exchanges an integer with the value in an atomic_var, using the specified ordering. + * Returns the value that was previously in the atomic_var. + */ +AWS_STATIC_IMPL +size_t aws_atomic_exchange_int_explicit( + volatile struct aws_atomic_var *var, + size_t n, + enum aws_memory_order memory_order) { + return __atomic_exchange_n(&AWS_ATOMIC_VAR_INTVAL(var), n, aws_atomic_priv_xlate_order(memory_order)); +} + +/** + * Exchanges a pointer with the value in an atomic_var, using the specified ordering. + * Returns the value that was previously in the atomic_var. + */ +AWS_STATIC_IMPL +void *aws_atomic_exchange_ptr_explicit( + volatile struct aws_atomic_var *var, + void *p, + enum aws_memory_order memory_order) { + return __atomic_exchange_n(&AWS_ATOMIC_VAR_PTRVAL(var), p, aws_atomic_priv_xlate_order(memory_order)); +} + +/** + * Atomically compares *var to *expected; if they are equal, atomically sets *var = desired. Otherwise, *expected is set + * to the value in *var. On success, the memory ordering used was order_success; otherwise, it was order_failure. + * order_failure must be no stronger than order_success, and must not be release or acq_rel. + */ +AWS_STATIC_IMPL +bool aws_atomic_compare_exchange_int_explicit( + volatile struct aws_atomic_var *var, + size_t *expected, + size_t desired, + enum aws_memory_order order_success, + enum aws_memory_order order_failure) { + return __atomic_compare_exchange_n( + &AWS_ATOMIC_VAR_INTVAL(var), + expected, + desired, + false, + aws_atomic_priv_xlate_order(order_success), + aws_atomic_priv_xlate_order(order_failure)); +} + +/** + * Atomically compares *var to *expected; if they are equal, atomically sets *var = desired. Otherwise, *expected is set + * to the value in *var. On success, the memory ordering used was order_success; otherwise, it was order_failure. + * order_failure must be no stronger than order_success, and must not be release or acq_rel. + */ +AWS_STATIC_IMPL +bool aws_atomic_compare_exchange_ptr_explicit( + volatile struct aws_atomic_var *var, + void **expected, + void *desired, + enum aws_memory_order order_success, + enum aws_memory_order order_failure) { + return __atomic_compare_exchange_n( + &AWS_ATOMIC_VAR_PTRVAL(var), + expected, + desired, + false, + aws_atomic_priv_xlate_order(order_success), + aws_atomic_priv_xlate_order(order_failure)); +} + +/** + * Atomically adds n to *var, and returns the previous value of *var. + */ +AWS_STATIC_IMPL +size_t aws_atomic_fetch_add_explicit(volatile struct aws_atomic_var *var, size_t n, enum aws_memory_order order) { + return __atomic_fetch_add(&AWS_ATOMIC_VAR_INTVAL(var), n, aws_atomic_priv_xlate_order(order)); +} + +/** + * Atomically subtracts n from *var, and returns the previous value of *var. + */ +AWS_STATIC_IMPL +size_t aws_atomic_fetch_sub_explicit(volatile struct aws_atomic_var *var, size_t n, enum aws_memory_order order) { + return __atomic_fetch_sub(&AWS_ATOMIC_VAR_INTVAL(var), n, aws_atomic_priv_xlate_order(order)); +} + +/** + * Atomically ORs n with *var, and returns the previous value of *var. + */ +AWS_STATIC_IMPL +size_t aws_atomic_fetch_or_explicit(volatile struct aws_atomic_var *var, size_t n, enum aws_memory_order order) { + return __atomic_fetch_or(&AWS_ATOMIC_VAR_INTVAL(var), n, aws_atomic_priv_xlate_order(order)); +} + +/** + * Atomically ANDs n with *var, and returns the previous value of *var. + */ +AWS_STATIC_IMPL +size_t aws_atomic_fetch_and_explicit(volatile struct aws_atomic_var *var, size_t n, enum aws_memory_order order) { + return __atomic_fetch_and(&AWS_ATOMIC_VAR_INTVAL(var), n, aws_atomic_priv_xlate_order(order)); +} + +/** + * Atomically XORs n with *var, and returns the previous value of *var. + */ +AWS_STATIC_IMPL +size_t aws_atomic_fetch_xor_explicit(volatile struct aws_atomic_var *var, size_t n, enum aws_memory_order order) { + return __atomic_fetch_xor(&AWS_ATOMIC_VAR_INTVAL(var), n, aws_atomic_priv_xlate_order(order)); +} + +/** + * Provides the same reordering guarantees as an atomic operation with the specified memory order, without + * needing to actually perform an atomic operation. + */ +AWS_STATIC_IMPL +void aws_atomic_thread_fence(enum aws_memory_order order) { + __atomic_thread_fence(order); +} + +#ifdef __clang__ +# pragma clang diagnostic pop +#else +# pragma GCC diagnostic pop +#endif + +#define AWS_ATOMICS_HAVE_THREAD_FENCE AWS_EXTERN_C_END #endif /* AWS_COMMON_ATOMICS_GNU_INL */ diff --git a/contrib/restricted/aws/aws-c-common/include/aws/common/byte_buf.h b/contrib/restricted/aws/aws-c-common/include/aws/common/byte_buf.h index 12915b829d..8e79a93b27 100644 --- a/contrib/restricted/aws/aws-c-common/include/aws/common/byte_buf.h +++ b/contrib/restricted/aws/aws-c-common/include/aws/common/byte_buf.h @@ -1,157 +1,157 @@ -#ifndef AWS_COMMON_BYTE_BUF_H -#define AWS_COMMON_BYTE_BUF_H +#ifndef AWS_COMMON_BYTE_BUF_H +#define AWS_COMMON_BYTE_BUF_H /** * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. - */ - -#include <aws/common/array_list.h> -#include <aws/common/byte_order.h> -#include <aws/common/common.h> - -#include <string.h> - -/** - * Represents a length-delimited binary string or buffer. If byte buffer points - * to constant memory or memory that should otherwise not be freed by this - * struct, set allocator to NULL and free function will be a no-op. - * - * This structure used to define the output for all functions that write to a buffer. - * - * Note that this structure allocates memory at the buffer pointer only. The - * struct itself does not get dynamically allocated and must be either - * maintained or copied to avoid losing access to the memory. - */ -struct aws_byte_buf { - /* do not reorder this, this struct lines up nicely with windows buffer structures--saving us allocations.*/ - size_t len; - uint8_t *buffer; - size_t capacity; - struct aws_allocator *allocator; -}; - -/** - * Represents a movable pointer within a larger binary string or buffer. - * - * This structure is used to define buffers for reading. - */ -struct aws_byte_cursor { - /* do not reorder this, this struct lines up nicely with windows buffer structures--saving us allocations */ - size_t len; - uint8_t *ptr; -}; - -/** - * Helper macro for passing aws_byte_cursor to the printf family of functions. - * Intended for use with the PRInSTR format macro. - * Ex: printf(PRInSTR "\n", AWS_BYTE_CURSOR_PRI(my_cursor)); - */ -#define AWS_BYTE_CURSOR_PRI(C) ((int)(C).len < 0 ? 0 : (int)(C).len), (const char *)(C).ptr - -/** - * Helper macro for passing aws_byte_buf to the printf family of functions. - * Intended for use with the PRInSTR format macro. - * Ex: printf(PRInSTR "\n", AWS_BYTE_BUF_PRI(my_buf)); - */ -#define AWS_BYTE_BUF_PRI(B) ((int)(B).len < 0 ? 0 : (int)(B).len), (const char *)(B).buffer - -/** + */ + +#include <aws/common/array_list.h> +#include <aws/common/byte_order.h> +#include <aws/common/common.h> + +#include <string.h> + +/** + * Represents a length-delimited binary string or buffer. If byte buffer points + * to constant memory or memory that should otherwise not be freed by this + * struct, set allocator to NULL and free function will be a no-op. + * + * This structure used to define the output for all functions that write to a buffer. + * + * Note that this structure allocates memory at the buffer pointer only. The + * struct itself does not get dynamically allocated and must be either + * maintained or copied to avoid losing access to the memory. + */ +struct aws_byte_buf { + /* do not reorder this, this struct lines up nicely with windows buffer structures--saving us allocations.*/ + size_t len; + uint8_t *buffer; + size_t capacity; + struct aws_allocator *allocator; +}; + +/** + * Represents a movable pointer within a larger binary string or buffer. + * + * This structure is used to define buffers for reading. + */ +struct aws_byte_cursor { + /* do not reorder this, this struct lines up nicely with windows buffer structures--saving us allocations */ + size_t len; + uint8_t *ptr; +}; + +/** + * Helper macro for passing aws_byte_cursor to the printf family of functions. + * Intended for use with the PRInSTR format macro. + * Ex: printf(PRInSTR "\n", AWS_BYTE_CURSOR_PRI(my_cursor)); + */ +#define AWS_BYTE_CURSOR_PRI(C) ((int)(C).len < 0 ? 0 : (int)(C).len), (const char *)(C).ptr + +/** + * Helper macro for passing aws_byte_buf to the printf family of functions. + * Intended for use with the PRInSTR format macro. + * Ex: printf(PRInSTR "\n", AWS_BYTE_BUF_PRI(my_buf)); + */ +#define AWS_BYTE_BUF_PRI(B) ((int)(B).len < 0 ? 0 : (int)(B).len), (const char *)(B).buffer + +/** * Helper Macro for inititilizing a byte cursor from a string literal */ #define AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL(literal) \ { .ptr = (uint8_t *)(const char *)(literal), .len = sizeof(literal) - 1 } /** - * Signature for function argument to trim APIs - */ -typedef bool(aws_byte_predicate_fn)(uint8_t value); - -AWS_EXTERN_C_BEGIN - -/** - * Compare two arrays. - * Return whether their contents are equivalent. - * NULL may be passed as the array pointer if its length is declared to be 0. - */ -AWS_COMMON_API + * Signature for function argument to trim APIs + */ +typedef bool(aws_byte_predicate_fn)(uint8_t value); + +AWS_EXTERN_C_BEGIN + +/** + * Compare two arrays. + * Return whether their contents are equivalent. + * NULL may be passed as the array pointer if its length is declared to be 0. + */ +AWS_COMMON_API bool aws_array_eq(const void *const array_a, const size_t len_a, const void *array_b, const size_t len_b); - -/** - * Perform a case-insensitive string comparison of two arrays. - * Return whether their contents are equivalent. - * NULL may be passed as the array pointer if its length is declared to be 0. - * The "C" locale is used for comparing upper and lowercase letters. - * Data is assumed to be ASCII text, UTF-8 will work fine too. - */ -AWS_COMMON_API + +/** + * Perform a case-insensitive string comparison of two arrays. + * Return whether their contents are equivalent. + * NULL may be passed as the array pointer if its length is declared to be 0. + * The "C" locale is used for comparing upper and lowercase letters. + * Data is assumed to be ASCII text, UTF-8 will work fine too. + */ +AWS_COMMON_API bool aws_array_eq_ignore_case( const void *const array_a, const size_t len_a, const void *const array_b, const size_t len_b); - -/** - * Compare an array and a null-terminated string. - * Returns true if their contents are equivalent. - * The array should NOT contain a null-terminator, or the comparison will always return false. - * NULL may be passed as the array pointer if its length is declared to be 0. - */ -AWS_COMMON_API + +/** + * Compare an array and a null-terminated string. + * Returns true if their contents are equivalent. + * The array should NOT contain a null-terminator, or the comparison will always return false. + * NULL may be passed as the array pointer if its length is declared to be 0. + */ +AWS_COMMON_API bool aws_array_eq_c_str(const void *const array, const size_t array_len, const char *const c_str); - -/** - * Perform a case-insensitive string comparison of an array and a null-terminated string. - * Return whether their contents are equivalent. - * The array should NOT contain a null-terminator, or the comparison will always return false. - * NULL may be passed as the array pointer if its length is declared to be 0. - * The "C" locale is used for comparing upper and lowercase letters. - * Data is assumed to be ASCII text, UTF-8 will work fine too. - */ -AWS_COMMON_API + +/** + * Perform a case-insensitive string comparison of an array and a null-terminated string. + * Return whether their contents are equivalent. + * The array should NOT contain a null-terminator, or the comparison will always return false. + * NULL may be passed as the array pointer if its length is declared to be 0. + * The "C" locale is used for comparing upper and lowercase letters. + * Data is assumed to be ASCII text, UTF-8 will work fine too. + */ +AWS_COMMON_API bool aws_array_eq_c_str_ignore_case(const void *const array, const size_t array_len, const char *const c_str); - -AWS_COMMON_API -int aws_byte_buf_init(struct aws_byte_buf *buf, struct aws_allocator *allocator, size_t capacity); - -/** - * Initializes an aws_byte_buf structure base on another valid one. - * Requires: *src and *allocator are valid objects. - * Ensures: *dest is a valid aws_byte_buf with a new backing array dest->buffer - * which is a copy of the elements from src->buffer. - */ -AWS_COMMON_API int aws_byte_buf_init_copy( - struct aws_byte_buf *dest, - struct aws_allocator *allocator, - const struct aws_byte_buf *src); - -/** - * Evaluates the set of properties that define the shape of all valid aws_byte_buf structures. - * It is also a cheap check, in the sense it run in constant time (i.e., no loops or recursion). - */ -AWS_COMMON_API -bool aws_byte_buf_is_valid(const struct aws_byte_buf *const buf); - -/** - * Evaluates the set of properties that define the shape of all valid aws_byte_cursor structures. - * It is also a cheap check, in the sense it runs in constant time (i.e., no loops or recursion). - */ -AWS_COMMON_API -bool aws_byte_cursor_is_valid(const struct aws_byte_cursor *cursor); - -/** - * Copies src buffer into dest and sets the correct len and capacity. - * A new memory zone is allocated for dest->buffer. When dest is no longer needed it will have to be cleaned-up using - * aws_byte_buf_clean_up(dest). - * Dest capacity and len will be equal to the src len. Allocator of the dest will be identical with parameter allocator. - * If src buffer is null the dest will have a null buffer with a len and a capacity of 0 - * Returns AWS_OP_SUCCESS in case of success or AWS_OP_ERR when memory can't be allocated. - */ -AWS_COMMON_API -int aws_byte_buf_init_copy_from_cursor( - struct aws_byte_buf *dest, - struct aws_allocator *allocator, - struct aws_byte_cursor src); - + +AWS_COMMON_API +int aws_byte_buf_init(struct aws_byte_buf *buf, struct aws_allocator *allocator, size_t capacity); + +/** + * Initializes an aws_byte_buf structure base on another valid one. + * Requires: *src and *allocator are valid objects. + * Ensures: *dest is a valid aws_byte_buf with a new backing array dest->buffer + * which is a copy of the elements from src->buffer. + */ +AWS_COMMON_API int aws_byte_buf_init_copy( + struct aws_byte_buf *dest, + struct aws_allocator *allocator, + const struct aws_byte_buf *src); + +/** + * Evaluates the set of properties that define the shape of all valid aws_byte_buf structures. + * It is also a cheap check, in the sense it run in constant time (i.e., no loops or recursion). + */ +AWS_COMMON_API +bool aws_byte_buf_is_valid(const struct aws_byte_buf *const buf); + +/** + * Evaluates the set of properties that define the shape of all valid aws_byte_cursor structures. + * It is also a cheap check, in the sense it runs in constant time (i.e., no loops or recursion). + */ +AWS_COMMON_API +bool aws_byte_cursor_is_valid(const struct aws_byte_cursor *cursor); + +/** + * Copies src buffer into dest and sets the correct len and capacity. + * A new memory zone is allocated for dest->buffer. When dest is no longer needed it will have to be cleaned-up using + * aws_byte_buf_clean_up(dest). + * Dest capacity and len will be equal to the src len. Allocator of the dest will be identical with parameter allocator. + * If src buffer is null the dest will have a null buffer with a len and a capacity of 0 + * Returns AWS_OP_SUCCESS in case of success or AWS_OP_ERR when memory can't be allocated. + */ +AWS_COMMON_API +int aws_byte_buf_init_copy_from_cursor( + struct aws_byte_buf *dest, + struct aws_allocator *allocator, + struct aws_byte_cursor src); + /** * Init buffer with contents of multiple cursors, and update cursors to reference the memory stored in the buffer. * Each cursor arg must be an `struct aws_byte_cursor *`. NULL must be passed as the final arg. @@ -159,20 +159,20 @@ int aws_byte_buf_init_copy_from_cursor( * Returns AWS_OP_SUCCESS in case of success. * AWS_OP_ERR is returned if memory can't be allocated or the total cursor length exceeds SIZE_MAX. */ -AWS_COMMON_API +AWS_COMMON_API int aws_byte_buf_init_cache_and_update_cursors(struct aws_byte_buf *dest, struct aws_allocator *allocator, ...); AWS_COMMON_API -void aws_byte_buf_clean_up(struct aws_byte_buf *buf); - -/** - * Equivalent to calling aws_byte_buf_secure_zero and then aws_byte_buf_clean_up - * on the buffer. - */ -AWS_COMMON_API -void aws_byte_buf_clean_up_secure(struct aws_byte_buf *buf); - -/** +void aws_byte_buf_clean_up(struct aws_byte_buf *buf); + +/** + * Equivalent to calling aws_byte_buf_secure_zero and then aws_byte_buf_clean_up + * on the buffer. + */ +AWS_COMMON_API +void aws_byte_buf_clean_up_secure(struct aws_byte_buf *buf); + +/** * Resets the len of the buffer to 0, but does not free the memory. The buffer can then be reused. * Optionally zeroes the contents, if the "zero_contents" flag is true. */ @@ -180,119 +180,119 @@ AWS_COMMON_API void aws_byte_buf_reset(struct aws_byte_buf *buf, bool zero_contents); /** - * Sets all bytes of buffer to zero and resets len to zero. - */ -AWS_COMMON_API -void aws_byte_buf_secure_zero(struct aws_byte_buf *buf); - -/** - * Compare two aws_byte_buf structures. - * Return whether their contents are equivalent. - */ -AWS_COMMON_API + * Sets all bytes of buffer to zero and resets len to zero. + */ +AWS_COMMON_API +void aws_byte_buf_secure_zero(struct aws_byte_buf *buf); + +/** + * Compare two aws_byte_buf structures. + * Return whether their contents are equivalent. + */ +AWS_COMMON_API bool aws_byte_buf_eq(const struct aws_byte_buf *const a, const struct aws_byte_buf *const b); - -/** - * Perform a case-insensitive string comparison of two aws_byte_buf structures. - * Return whether their contents are equivalent. - * The "C" locale is used for comparing upper and lowercase letters. - * Data is assumed to be ASCII text, UTF-8 will work fine too. - */ -AWS_COMMON_API + +/** + * Perform a case-insensitive string comparison of two aws_byte_buf structures. + * Return whether their contents are equivalent. + * The "C" locale is used for comparing upper and lowercase letters. + * Data is assumed to be ASCII text, UTF-8 will work fine too. + */ +AWS_COMMON_API bool aws_byte_buf_eq_ignore_case(const struct aws_byte_buf *const a, const struct aws_byte_buf *const b); - -/** - * Compare an aws_byte_buf and a null-terminated string. - * Returns true if their contents are equivalent. - * The buffer should NOT contain a null-terminator, or the comparison will always return false. - */ -AWS_COMMON_API + +/** + * Compare an aws_byte_buf and a null-terminated string. + * Returns true if their contents are equivalent. + * The buffer should NOT contain a null-terminator, or the comparison will always return false. + */ +AWS_COMMON_API bool aws_byte_buf_eq_c_str(const struct aws_byte_buf *const buf, const char *const c_str); - -/** - * Perform a case-insensitive string comparison of an aws_byte_buf and a null-terminated string. - * Return whether their contents are equivalent. - * The buffer should NOT contain a null-terminator, or the comparison will always return false. - * The "C" locale is used for comparing upper and lowercase letters. - * Data is assumed to be ASCII text, UTF-8 will work fine too. - */ -AWS_COMMON_API + +/** + * Perform a case-insensitive string comparison of an aws_byte_buf and a null-terminated string. + * Return whether their contents are equivalent. + * The buffer should NOT contain a null-terminator, or the comparison will always return false. + * The "C" locale is used for comparing upper and lowercase letters. + * Data is assumed to be ASCII text, UTF-8 will work fine too. + */ +AWS_COMMON_API bool aws_byte_buf_eq_c_str_ignore_case(const struct aws_byte_buf *const buf, const char *const c_str); - -/** - * No copies, no buffer allocations. Iterates over input_str, and returns the next substring between split_on instances. - * - * Edge case rules are as follows: + +/** + * No copies, no buffer allocations. Iterates over input_str, and returns the next substring between split_on instances. + * + * Edge case rules are as follows: * If the input is an empty string, an empty cursor will be the one entry returned. - * If the input begins with split_on, an empty cursor will be the first entry returned. - * If the input has two adjacent split_on tokens, an empty cursor will be returned. - * If the input ends with split_on, an empty cursor will be returned last. - * + * If the input begins with split_on, an empty cursor will be the first entry returned. + * If the input has two adjacent split_on tokens, an empty cursor will be returned. + * If the input ends with split_on, an empty cursor will be returned last. + * * It is the user's responsibility zero-initialize substr before the first call. - * - * It is the user's responsibility to make sure the input buffer stays in memory - * long enough to use the results. - */ -AWS_COMMON_API -bool aws_byte_cursor_next_split( - const struct aws_byte_cursor *AWS_RESTRICT input_str, - char split_on, - struct aws_byte_cursor *AWS_RESTRICT substr); - -/** - * No copies, no buffer allocations. Fills in output with a list of - * aws_byte_cursor instances where buffer is an offset into the input_str and - * len is the length of that string in the original buffer. - * - * Edge case rules are as follows: - * if the input begins with split_on, an empty cursor will be the first entry in - * output. if the input has two adjacent split_on tokens, an empty cursor will - * be inserted into the output. if the input ends with split_on, an empty cursor - * will be appended to the output. - * - * It is the user's responsibility to properly initialize output. Recommended number of preallocated elements from - * output is your most likely guess for the upper bound of the number of elements resulting from the split. - * - * The type that will be stored in output is struct aws_byte_cursor (you'll need - * this for the item size param). - * - * It is the user's responsibility to make sure the input buffer stays in memory - * long enough to use the results. - */ -AWS_COMMON_API -int aws_byte_cursor_split_on_char( - const struct aws_byte_cursor *AWS_RESTRICT input_str, - char split_on, - struct aws_array_list *AWS_RESTRICT output); - -/** - * No copies, no buffer allocations. Fills in output with a list of aws_byte_cursor instances where buffer is - * an offset into the input_str and len is the length of that string in the original buffer. N is the max number of - * splits, if this value is zero, it will add all splits to the output. - * - * Edge case rules are as follows: - * if the input begins with split_on, an empty cursor will be the first entry in output - * if the input has two adjacent split_on tokens, an empty cursor will be inserted into the output. - * if the input ends with split_on, an empty cursor will be appended to the output. - * - * It is the user's responsibility to properly initialize output. Recommended number of preallocated elements from - * output is your most likely guess for the upper bound of the number of elements resulting from the split. - * - * If the output array is not large enough, input_str will be updated to point to the first character after the last - * processed split_on instance. - * - * The type that will be stored in output is struct aws_byte_cursor (you'll need this for the item size param). - * - * It is the user's responsibility to make sure the input buffer stays in memory long enough to use the results. - */ -AWS_COMMON_API -int aws_byte_cursor_split_on_char_n( - const struct aws_byte_cursor *AWS_RESTRICT input_str, - char split_on, - size_t n, - struct aws_array_list *AWS_RESTRICT output); - -/** + * + * It is the user's responsibility to make sure the input buffer stays in memory + * long enough to use the results. + */ +AWS_COMMON_API +bool aws_byte_cursor_next_split( + const struct aws_byte_cursor *AWS_RESTRICT input_str, + char split_on, + struct aws_byte_cursor *AWS_RESTRICT substr); + +/** + * No copies, no buffer allocations. Fills in output with a list of + * aws_byte_cursor instances where buffer is an offset into the input_str and + * len is the length of that string in the original buffer. + * + * Edge case rules are as follows: + * if the input begins with split_on, an empty cursor will be the first entry in + * output. if the input has two adjacent split_on tokens, an empty cursor will + * be inserted into the output. if the input ends with split_on, an empty cursor + * will be appended to the output. + * + * It is the user's responsibility to properly initialize output. Recommended number of preallocated elements from + * output is your most likely guess for the upper bound of the number of elements resulting from the split. + * + * The type that will be stored in output is struct aws_byte_cursor (you'll need + * this for the item size param). + * + * It is the user's responsibility to make sure the input buffer stays in memory + * long enough to use the results. + */ +AWS_COMMON_API +int aws_byte_cursor_split_on_char( + const struct aws_byte_cursor *AWS_RESTRICT input_str, + char split_on, + struct aws_array_list *AWS_RESTRICT output); + +/** + * No copies, no buffer allocations. Fills in output with a list of aws_byte_cursor instances where buffer is + * an offset into the input_str and len is the length of that string in the original buffer. N is the max number of + * splits, if this value is zero, it will add all splits to the output. + * + * Edge case rules are as follows: + * if the input begins with split_on, an empty cursor will be the first entry in output + * if the input has two adjacent split_on tokens, an empty cursor will be inserted into the output. + * if the input ends with split_on, an empty cursor will be appended to the output. + * + * It is the user's responsibility to properly initialize output. Recommended number of preallocated elements from + * output is your most likely guess for the upper bound of the number of elements resulting from the split. + * + * If the output array is not large enough, input_str will be updated to point to the first character after the last + * processed split_on instance. + * + * The type that will be stored in output is struct aws_byte_cursor (you'll need this for the item size param). + * + * It is the user's responsibility to make sure the input buffer stays in memory long enough to use the results. + */ +AWS_COMMON_API +int aws_byte_cursor_split_on_char_n( + const struct aws_byte_cursor *AWS_RESTRICT input_str, + char split_on, + size_t n, + struct aws_array_list *AWS_RESTRICT output); + +/** * Search for an exact byte match inside a cursor. The first match will be returned. Returns AWS_OP_SUCCESS * on successful match and first_find will be set to the offset in input_str, and length will be the remaining length * from input_str past the returned offset. If the match was not found, AWS_OP_ERR will be returned and @@ -305,71 +305,71 @@ int aws_byte_cursor_find_exact( struct aws_byte_cursor *first_find); /** - * - * Shrinks a byte cursor from the right for as long as the supplied predicate is true - */ -AWS_COMMON_API -struct aws_byte_cursor aws_byte_cursor_right_trim_pred( - const struct aws_byte_cursor *source, - aws_byte_predicate_fn *predicate); - -/** - * Shrinks a byte cursor from the left for as long as the supplied predicate is true - */ -AWS_COMMON_API -struct aws_byte_cursor aws_byte_cursor_left_trim_pred( - const struct aws_byte_cursor *source, - aws_byte_predicate_fn *predicate); - -/** - * Shrinks a byte cursor from both sides for as long as the supplied predicate is true - */ -AWS_COMMON_API -struct aws_byte_cursor aws_byte_cursor_trim_pred( - const struct aws_byte_cursor *source, - aws_byte_predicate_fn *predicate); - -/** - * Returns true if the byte cursor's range of bytes all satisfy the predicate - */ -AWS_COMMON_API -bool aws_byte_cursor_satisfies_pred(const struct aws_byte_cursor *source, aws_byte_predicate_fn *predicate); - -/** - * Copies from to to. If to is too small, AWS_ERROR_DEST_COPY_TOO_SMALL will be - * returned. dest->len will contain the amount of data actually copied to dest. - * - * from and to may be the same buffer, permitting copying a buffer into itself. - */ -AWS_COMMON_API -int aws_byte_buf_append(struct aws_byte_buf *to, const struct aws_byte_cursor *from); - -/** - * Copies from to to while converting bytes via the passed in lookup table. - * If to is too small, AWS_ERROR_DEST_COPY_TOO_SMALL will be - * returned. to->len will contain its original size plus the amount of data actually copied to to. - * - * from and to should not be the same buffer (overlap is not handled) - * lookup_table must be at least 256 bytes - */ -AWS_COMMON_API -int aws_byte_buf_append_with_lookup( - struct aws_byte_buf *AWS_RESTRICT to, - const struct aws_byte_cursor *AWS_RESTRICT from, - const uint8_t *lookup_table); - -/** - * Copies from to to. If to is too small, the buffer will be grown appropriately and - * the old contents copied to, before the new contents are appended. - * - * If the grow fails (overflow or OOM), then an error will be returned. - * - * from and to may be the same buffer, permitting copying a buffer into itself. - */ -AWS_COMMON_API -int aws_byte_buf_append_dynamic(struct aws_byte_buf *to, const struct aws_byte_cursor *from); - -/** + * + * Shrinks a byte cursor from the right for as long as the supplied predicate is true + */ +AWS_COMMON_API +struct aws_byte_cursor aws_byte_cursor_right_trim_pred( + const struct aws_byte_cursor *source, + aws_byte_predicate_fn *predicate); + +/** + * Shrinks a byte cursor from the left for as long as the supplied predicate is true + */ +AWS_COMMON_API +struct aws_byte_cursor aws_byte_cursor_left_trim_pred( + const struct aws_byte_cursor *source, + aws_byte_predicate_fn *predicate); + +/** + * Shrinks a byte cursor from both sides for as long as the supplied predicate is true + */ +AWS_COMMON_API +struct aws_byte_cursor aws_byte_cursor_trim_pred( + const struct aws_byte_cursor *source, + aws_byte_predicate_fn *predicate); + +/** + * Returns true if the byte cursor's range of bytes all satisfy the predicate + */ +AWS_COMMON_API +bool aws_byte_cursor_satisfies_pred(const struct aws_byte_cursor *source, aws_byte_predicate_fn *predicate); + +/** + * Copies from to to. If to is too small, AWS_ERROR_DEST_COPY_TOO_SMALL will be + * returned. dest->len will contain the amount of data actually copied to dest. + * + * from and to may be the same buffer, permitting copying a buffer into itself. + */ +AWS_COMMON_API +int aws_byte_buf_append(struct aws_byte_buf *to, const struct aws_byte_cursor *from); + +/** + * Copies from to to while converting bytes via the passed in lookup table. + * If to is too small, AWS_ERROR_DEST_COPY_TOO_SMALL will be + * returned. to->len will contain its original size plus the amount of data actually copied to to. + * + * from and to should not be the same buffer (overlap is not handled) + * lookup_table must be at least 256 bytes + */ +AWS_COMMON_API +int aws_byte_buf_append_with_lookup( + struct aws_byte_buf *AWS_RESTRICT to, + const struct aws_byte_cursor *AWS_RESTRICT from, + const uint8_t *lookup_table); + +/** + * Copies from to to. If to is too small, the buffer will be grown appropriately and + * the old contents copied to, before the new contents are appended. + * + * If the grow fails (overflow or OOM), then an error will be returned. + * + * from and to may be the same buffer, permitting copying a buffer into itself. + */ +AWS_COMMON_API +int aws_byte_buf_append_dynamic(struct aws_byte_buf *to, const struct aws_byte_cursor *from); + +/** * Copies `from` to `to`. If `to` is too small, the buffer will be grown appropriately and * the old contents copied over, before the new contents are appended. * @@ -418,104 +418,104 @@ AWS_COMMON_API int aws_byte_buf_append_null_terminator(struct aws_byte_buf *buf); /** - * Attempts to increase the capacity of a buffer to the requested capacity - * - * If the the buffer's capacity is currently larger than the request capacity, the - * function does nothing (no shrink is performed). - */ -AWS_COMMON_API -int aws_byte_buf_reserve(struct aws_byte_buf *buffer, size_t requested_capacity); - -/** - * Convenience function that attempts to increase the capacity of a buffer relative to the current - * length. - * - * aws_byte_buf_reserve_relative(buf, x) ~~ aws_byte_buf_reserve(buf, buf->len + x) - * - */ -AWS_COMMON_API -int aws_byte_buf_reserve_relative(struct aws_byte_buf *buffer, size_t additional_length); - -/** - * Concatenates a variable number of struct aws_byte_buf * into destination. - * Number of args must be greater than 1. If dest is too small, - * AWS_ERROR_DEST_COPY_TOO_SMALL will be returned. dest->len will contain the - * amount of data actually copied to dest. - */ -AWS_COMMON_API -int aws_byte_buf_cat(struct aws_byte_buf *dest, size_t number_of_args, ...); - -/** - * Compare two aws_byte_cursor structures. - * Return whether their contents are equivalent. - */ -AWS_COMMON_API -bool aws_byte_cursor_eq(const struct aws_byte_cursor *a, const struct aws_byte_cursor *b); - -/** - * Perform a case-insensitive string comparison of two aws_byte_cursor structures. - * Return whether their contents are equivalent. - * The "C" locale is used for comparing upper and lowercase letters. - * Data is assumed to be ASCII text, UTF-8 will work fine too. - */ -AWS_COMMON_API -bool aws_byte_cursor_eq_ignore_case(const struct aws_byte_cursor *a, const struct aws_byte_cursor *b); - -/** - * Compare an aws_byte_cursor and an aws_byte_buf. - * Return whether their contents are equivalent. - */ -AWS_COMMON_API + * Attempts to increase the capacity of a buffer to the requested capacity + * + * If the the buffer's capacity is currently larger than the request capacity, the + * function does nothing (no shrink is performed). + */ +AWS_COMMON_API +int aws_byte_buf_reserve(struct aws_byte_buf *buffer, size_t requested_capacity); + +/** + * Convenience function that attempts to increase the capacity of a buffer relative to the current + * length. + * + * aws_byte_buf_reserve_relative(buf, x) ~~ aws_byte_buf_reserve(buf, buf->len + x) + * + */ +AWS_COMMON_API +int aws_byte_buf_reserve_relative(struct aws_byte_buf *buffer, size_t additional_length); + +/** + * Concatenates a variable number of struct aws_byte_buf * into destination. + * Number of args must be greater than 1. If dest is too small, + * AWS_ERROR_DEST_COPY_TOO_SMALL will be returned. dest->len will contain the + * amount of data actually copied to dest. + */ +AWS_COMMON_API +int aws_byte_buf_cat(struct aws_byte_buf *dest, size_t number_of_args, ...); + +/** + * Compare two aws_byte_cursor structures. + * Return whether their contents are equivalent. + */ +AWS_COMMON_API +bool aws_byte_cursor_eq(const struct aws_byte_cursor *a, const struct aws_byte_cursor *b); + +/** + * Perform a case-insensitive string comparison of two aws_byte_cursor structures. + * Return whether their contents are equivalent. + * The "C" locale is used for comparing upper and lowercase letters. + * Data is assumed to be ASCII text, UTF-8 will work fine too. + */ +AWS_COMMON_API +bool aws_byte_cursor_eq_ignore_case(const struct aws_byte_cursor *a, const struct aws_byte_cursor *b); + +/** + * Compare an aws_byte_cursor and an aws_byte_buf. + * Return whether their contents are equivalent. + */ +AWS_COMMON_API bool aws_byte_cursor_eq_byte_buf(const struct aws_byte_cursor *const a, const struct aws_byte_buf *const b); - -/** - * Perform a case-insensitive string comparison of an aws_byte_cursor and an aws_byte_buf. - * Return whether their contents are equivalent. - * The "C" locale is used for comparing upper and lowercase letters. - * Data is assumed to be ASCII text, UTF-8 will work fine too. - */ -AWS_COMMON_API + +/** + * Perform a case-insensitive string comparison of an aws_byte_cursor and an aws_byte_buf. + * Return whether their contents are equivalent. + * The "C" locale is used for comparing upper and lowercase letters. + * Data is assumed to be ASCII text, UTF-8 will work fine too. + */ +AWS_COMMON_API bool aws_byte_cursor_eq_byte_buf_ignore_case(const struct aws_byte_cursor *const a, const struct aws_byte_buf *const b); - -/** - * Compare an aws_byte_cursor and a null-terminated string. - * Returns true if their contents are equivalent. - * The cursor should NOT contain a null-terminator, or the comparison will always return false. - */ -AWS_COMMON_API + +/** + * Compare an aws_byte_cursor and a null-terminated string. + * Returns true if their contents are equivalent. + * The cursor should NOT contain a null-terminator, or the comparison will always return false. + */ +AWS_COMMON_API bool aws_byte_cursor_eq_c_str(const struct aws_byte_cursor *const cursor, const char *const c_str); - -/** - * Perform a case-insensitive string comparison of an aws_byte_cursor and a null-terminated string. - * Return whether their contents are equivalent. - * The cursor should NOT contain a null-terminator, or the comparison will always return false. - * The "C" locale is used for comparing upper and lowercase letters. - * Data is assumed to be ASCII text, UTF-8 will work fine too. - */ -AWS_COMMON_API + +/** + * Perform a case-insensitive string comparison of an aws_byte_cursor and a null-terminated string. + * Return whether their contents are equivalent. + * The cursor should NOT contain a null-terminator, or the comparison will always return false. + * The "C" locale is used for comparing upper and lowercase letters. + * Data is assumed to be ASCII text, UTF-8 will work fine too. + */ +AWS_COMMON_API bool aws_byte_cursor_eq_c_str_ignore_case(const struct aws_byte_cursor *const cursor, const char *const c_str); - -/** - * Case-insensitive hash function for array containing ASCII or UTF-8 text. - */ -AWS_COMMON_API + +/** + * Case-insensitive hash function for array containing ASCII or UTF-8 text. + */ +AWS_COMMON_API uint64_t aws_hash_array_ignore_case(const void *array, const size_t len); - -/** - * Case-insensitive hash function for aws_byte_cursors stored in an aws_hash_table. - * For case-sensitive hashing, use aws_hash_byte_cursor_ptr(). - */ -AWS_COMMON_API -uint64_t aws_hash_byte_cursor_ptr_ignore_case(const void *item); - -/** - * Returns a lookup table for bytes that is the identity transformation with the exception - * of uppercase ascii characters getting replaced with lowercase characters. Used in - * caseless comparisons. - */ -AWS_COMMON_API -const uint8_t *aws_lookup_table_to_lower_get(void); - + +/** + * Case-insensitive hash function for aws_byte_cursors stored in an aws_hash_table. + * For case-sensitive hashing, use aws_hash_byte_cursor_ptr(). + */ +AWS_COMMON_API +uint64_t aws_hash_byte_cursor_ptr_ignore_case(const void *item); + +/** + * Returns a lookup table for bytes that is the identity transformation with the exception + * of uppercase ascii characters getting replaced with lowercase characters. Used in + * caseless comparisons. + */ +AWS_COMMON_API +const uint8_t *aws_lookup_table_to_lower_get(void); + /** * Returns lookup table to go from ASCII/UTF-8 hex character to a number (0-15). * Non-hex characters map to 255. @@ -546,88 +546,88 @@ int aws_byte_cursor_compare_lookup( const struct aws_byte_cursor *rhs, const uint8_t *lookup_table); -/** - * For creating a byte buffer from a null-terminated string literal. - */ +/** + * For creating a byte buffer from a null-terminated string literal. + */ AWS_COMMON_API struct aws_byte_buf aws_byte_buf_from_c_str(const char *c_str); - + AWS_COMMON_API struct aws_byte_buf aws_byte_buf_from_array(const void *bytes, size_t len); - + AWS_COMMON_API struct aws_byte_buf aws_byte_buf_from_empty_array(const void *bytes, size_t capacity); - + AWS_COMMON_API struct aws_byte_cursor aws_byte_cursor_from_buf(const struct aws_byte_buf *const buf); - + AWS_COMMON_API struct aws_byte_cursor aws_byte_cursor_from_c_str(const char *c_str); - + AWS_COMMON_API struct aws_byte_cursor aws_byte_cursor_from_array(const void *const bytes, const size_t len); - -/** - * Tests if the given aws_byte_cursor has at least len bytes remaining. If so, - * *buf is advanced by len bytes (incrementing ->ptr and decrementing ->len), - * and an aws_byte_cursor referring to the first len bytes of the original *buf - * is returned. Otherwise, an aws_byte_cursor with ->ptr = NULL, ->len = 0 is - * returned. - * - * Note that if len is above (SIZE_MAX / 2), this function will also treat it as - * a buffer overflow, and return NULL without changing *buf. - */ + +/** + * Tests if the given aws_byte_cursor has at least len bytes remaining. If so, + * *buf is advanced by len bytes (incrementing ->ptr and decrementing ->len), + * and an aws_byte_cursor referring to the first len bytes of the original *buf + * is returned. Otherwise, an aws_byte_cursor with ->ptr = NULL, ->len = 0 is + * returned. + * + * Note that if len is above (SIZE_MAX / 2), this function will also treat it as + * a buffer overflow, and return NULL without changing *buf. + */ AWS_COMMON_API struct aws_byte_cursor aws_byte_cursor_advance(struct aws_byte_cursor *const cursor, const size_t len); - -/** - * Behaves identically to aws_byte_cursor_advance, but avoids speculative - * execution potentially reading out-of-bounds pointers (by returning an - * empty ptr in such speculated paths). - * - * This should generally be done when using an untrusted or - * data-dependent value for 'len', to avoid speculating into a path where - * cursor->ptr points outside the true ptr length. - */ - + +/** + * Behaves identically to aws_byte_cursor_advance, but avoids speculative + * execution potentially reading out-of-bounds pointers (by returning an + * empty ptr in such speculated paths). + * + * This should generally be done when using an untrusted or + * data-dependent value for 'len', to avoid speculating into a path where + * cursor->ptr points outside the true ptr length. + */ + AWS_COMMON_API struct aws_byte_cursor aws_byte_cursor_advance_nospec(struct aws_byte_cursor *const cursor, size_t len); - -/** - * Reads specified length of data from byte cursor and copies it to the - * destination array. - * - * On success, returns true and updates the cursor pointer/length accordingly. - * If there is insufficient space in the cursor, returns false, leaving the - * cursor unchanged. - */ + +/** + * Reads specified length of data from byte cursor and copies it to the + * destination array. + * + * On success, returns true and updates the cursor pointer/length accordingly. + * If there is insufficient space in the cursor, returns false, leaving the + * cursor unchanged. + */ AWS_COMMON_API bool aws_byte_cursor_read( - struct aws_byte_cursor *AWS_RESTRICT cur, - void *AWS_RESTRICT dest, + struct aws_byte_cursor *AWS_RESTRICT cur, + void *AWS_RESTRICT dest, const size_t len); - -/** - * Reads as many bytes from cursor as size of buffer, and copies them to buffer. - * - * On success, returns true and updates the cursor pointer/length accordingly. - * If there is insufficient space in the cursor, returns false, leaving the - * cursor unchanged. - */ + +/** + * Reads as many bytes from cursor as size of buffer, and copies them to buffer. + * + * On success, returns true and updates the cursor pointer/length accordingly. + * If there is insufficient space in the cursor, returns false, leaving the + * cursor unchanged. + */ AWS_COMMON_API bool aws_byte_cursor_read_and_fill_buffer( - struct aws_byte_cursor *AWS_RESTRICT cur, + struct aws_byte_cursor *AWS_RESTRICT cur, struct aws_byte_buf *AWS_RESTRICT dest); - -/** - * Reads a single byte from cursor, placing it in *var. - * - * On success, returns true and updates the cursor pointer/length accordingly. - * If there is insufficient space in the cursor, returns false, leaving the - * cursor unchanged. - */ + +/** + * Reads a single byte from cursor, placing it in *var. + * + * On success, returns true and updates the cursor pointer/length accordingly. + * If there is insufficient space in the cursor, returns false, leaving the + * cursor unchanged. + */ AWS_COMMON_API bool aws_byte_cursor_read_u8(struct aws_byte_cursor *AWS_RESTRICT cur, uint8_t *AWS_RESTRICT var); - -/** - * Reads a 16-bit value in network byte order from cur, and places it in host - * byte order into var. - * - * On success, returns true and updates the cursor pointer/length accordingly. - * If there is insufficient space in the cursor, returns false, leaving the - * cursor unchanged. - */ + +/** + * Reads a 16-bit value in network byte order from cur, and places it in host + * byte order into var. + * + * On success, returns true and updates the cursor pointer/length accordingly. + * If there is insufficient space in the cursor, returns false, leaving the + * cursor unchanged. + */ AWS_COMMON_API bool aws_byte_cursor_read_be16(struct aws_byte_cursor *cur, uint16_t *var); - + /** * Reads an unsigned 24-bit value (3 bytes) in network byte order from cur, * and places it in host byte order into 32-bit var. @@ -638,17 +638,17 @@ AWS_COMMON_API bool aws_byte_cursor_read_be16(struct aws_byte_cursor *cur, uint1 * cursor unchanged. */ AWS_COMMON_API bool aws_byte_cursor_read_be24(struct aws_byte_cursor *cur, uint32_t *var); - -/** - * Reads a 32-bit value in network byte order from cur, and places it in host - * byte order into var. - * - * On success, returns true and updates the cursor pointer/length accordingly. - * If there is insufficient space in the cursor, returns false, leaving the - * cursor unchanged. - */ + +/** + * Reads a 32-bit value in network byte order from cur, and places it in host + * byte order into var. + * + * On success, returns true and updates the cursor pointer/length accordingly. + * If there is insufficient space in the cursor, returns false, leaving the + * cursor unchanged. + */ AWS_COMMON_API bool aws_byte_cursor_read_be32(struct aws_byte_cursor *cur, uint32_t *var); - + /** * Reads a 64-bit value in network byte order from cur, and places it in host * byte order into var. @@ -658,7 +658,7 @@ AWS_COMMON_API bool aws_byte_cursor_read_be32(struct aws_byte_cursor *cur, uint3 * cursor unchanged. */ AWS_COMMON_API bool aws_byte_cursor_read_be64(struct aws_byte_cursor *cur, uint64_t *var); - + /** * Reads a 32-bit value in network byte order from cur, and places it in host * byte order into var. @@ -668,17 +668,17 @@ AWS_COMMON_API bool aws_byte_cursor_read_be64(struct aws_byte_cursor *cur, uint6 * cursor unchanged. */ AWS_COMMON_API bool aws_byte_cursor_read_float_be32(struct aws_byte_cursor *cur, float *var); - -/** - * Reads a 64-bit value in network byte order from cur, and places it in host - * byte order into var. - * - * On success, returns true and updates the cursor pointer/length accordingly. - * If there is insufficient space in the cursor, returns false, leaving the - * cursor unchanged. - */ + +/** + * Reads a 64-bit value in network byte order from cur, and places it in host + * byte order into var. + * + * On success, returns true and updates the cursor pointer/length accordingly. + * If there is insufficient space in the cursor, returns false, leaving the + * cursor unchanged. + */ AWS_COMMON_API bool aws_byte_cursor_read_float_be64(struct aws_byte_cursor *cur, double *var); - + /** * Reads 2 hex characters from ASCII/UTF-8 text to produce an 8-bit number. * Accepts both lowercase 'a'-'f' and uppercase 'A'-'F'. @@ -689,58 +689,58 @@ AWS_COMMON_API bool aws_byte_cursor_read_float_be64(struct aws_byte_cursor *cur, * is encountered, returns false, leaving the cursor unchanged. */ AWS_COMMON_API bool aws_byte_cursor_read_hex_u8(struct aws_byte_cursor *cur, uint8_t *var); - -/** - * Appends a sub-buffer to the specified buffer. - * - * If the buffer has at least `len' bytes remaining (buffer->capacity - buffer->len >= len), - * then buffer->len is incremented by len, and an aws_byte_buf is assigned to *output corresponding - * to the last len bytes of the input buffer. The aws_byte_buf at *output will have a null - * allocator, a zero initial length, and a capacity of 'len'. The function then returns true. - * - * If there is insufficient space, then this function nulls all fields in *output and returns - * false. - */ + +/** + * Appends a sub-buffer to the specified buffer. + * + * If the buffer has at least `len' bytes remaining (buffer->capacity - buffer->len >= len), + * then buffer->len is incremented by len, and an aws_byte_buf is assigned to *output corresponding + * to the last len bytes of the input buffer. The aws_byte_buf at *output will have a null + * allocator, a zero initial length, and a capacity of 'len'. The function then returns true. + * + * If there is insufficient space, then this function nulls all fields in *output and returns + * false. + */ AWS_COMMON_API bool aws_byte_buf_advance( struct aws_byte_buf *const AWS_RESTRICT buffer, struct aws_byte_buf *const AWS_RESTRICT output, const size_t len); - -/** - * Write specified number of bytes from array to byte buffer. - * - * On success, returns true and updates the buffer length accordingly. - * If there is insufficient space in the buffer, returns false, leaving the - * buffer unchanged. - */ + +/** + * Write specified number of bytes from array to byte buffer. + * + * On success, returns true and updates the buffer length accordingly. + * If there is insufficient space in the buffer, returns false, leaving the + * buffer unchanged. + */ AWS_COMMON_API bool aws_byte_buf_write( - struct aws_byte_buf *AWS_RESTRICT buf, - const uint8_t *AWS_RESTRICT src, + struct aws_byte_buf *AWS_RESTRICT buf, + const uint8_t *AWS_RESTRICT src, size_t len); - -/** - * Copies all bytes from buffer to buffer. - * - * On success, returns true and updates the buffer /length accordingly. - * If there is insufficient space in the buffer, returns false, leaving the - * buffer unchanged. - */ + +/** + * Copies all bytes from buffer to buffer. + * + * On success, returns true and updates the buffer /length accordingly. + * If there is insufficient space in the buffer, returns false, leaving the + * buffer unchanged. + */ AWS_COMMON_API bool aws_byte_buf_write_from_whole_buffer( - struct aws_byte_buf *AWS_RESTRICT buf, + struct aws_byte_buf *AWS_RESTRICT buf, struct aws_byte_buf src); - -/** - * Copies all bytes from buffer to buffer. - * - * On success, returns true and updates the buffer /length accordingly. - * If there is insufficient space in the buffer, returns false, leaving the - * buffer unchanged. - */ + +/** + * Copies all bytes from buffer to buffer. + * + * On success, returns true and updates the buffer /length accordingly. + * If there is insufficient space in the buffer, returns false, leaving the + * buffer unchanged. + */ AWS_COMMON_API bool aws_byte_buf_write_from_whole_cursor( - struct aws_byte_buf *AWS_RESTRICT buf, + struct aws_byte_buf *AWS_RESTRICT buf, struct aws_byte_cursor src); - -/** + +/** * Without increasing buf's capacity, write as much as possible from advancing_cursor into buf. * * buf's len is updated accordingly. @@ -760,34 +760,34 @@ AWS_COMMON_API struct aws_byte_cursor aws_byte_buf_write_to_capacity( struct aws_byte_cursor *advancing_cursor); /** - * Copies one byte to buffer. - * - * On success, returns true and updates the cursor /length - accordingly. + * Copies one byte to buffer. + * + * On success, returns true and updates the cursor /length + accordingly. * * If there is insufficient space in the buffer, returns false, leaving the * buffer unchanged. */ AWS_COMMON_API bool aws_byte_buf_write_u8(struct aws_byte_buf *AWS_RESTRICT buf, uint8_t c); - + /** * Writes one byte repeatedly to buffer (like memset) * * If there is insufficient space in the buffer, returns false, leaving the * buffer unchanged. - */ + */ AWS_COMMON_API bool aws_byte_buf_write_u8_n(struct aws_byte_buf *buf, uint8_t c, size_t count); - -/** - * Writes a 16-bit integer in network byte order (big endian) to buffer. - * + +/** + * Writes a 16-bit integer in network byte order (big endian) to buffer. + * * On success, returns true and updates the buffer /length accordingly. * If there is insufficient space in the buffer, returns false, leaving the * buffer unchanged. - */ + */ AWS_COMMON_API bool aws_byte_buf_write_be16(struct aws_byte_buf *buf, uint16_t x); - -/** + +/** * Writes low 24-bits (3 bytes) of an unsigned integer in network byte order (big endian) to buffer. * Ex: If x is 0x00AABBCC then {0xAA, 0xBB, 0xCC} is written to buffer. * @@ -798,15 +798,15 @@ AWS_COMMON_API bool aws_byte_buf_write_be16(struct aws_byte_buf *buf, uint16_t x AWS_COMMON_API bool aws_byte_buf_write_be24(struct aws_byte_buf *buf, uint32_t x); /** - * Writes a 32-bit integer in network byte order (big endian) to buffer. - * + * Writes a 32-bit integer in network byte order (big endian) to buffer. + * * On success, returns true and updates the buffer /length accordingly. * If there is insufficient space in the buffer, returns false, leaving the * buffer unchanged. - */ + */ AWS_COMMON_API bool aws_byte_buf_write_be32(struct aws_byte_buf *buf, uint32_t x); - -/** + +/** * Writes a 32-bit float in network byte order (big endian) to buffer. * * On success, returns true and updates the buffer /length accordingly. @@ -816,14 +816,14 @@ AWS_COMMON_API bool aws_byte_buf_write_be32(struct aws_byte_buf *buf, uint32_t x AWS_COMMON_API bool aws_byte_buf_write_float_be32(struct aws_byte_buf *buf, float x); /** - * Writes a 64-bit integer in network byte order (big endian) to buffer. - * + * Writes a 64-bit integer in network byte order (big endian) to buffer. + * * On success, returns true and updates the buffer /length accordingly. * If there is insufficient space in the buffer, returns false, leaving the * buffer unchanged. - */ + */ AWS_COMMON_API bool aws_byte_buf_write_be64(struct aws_byte_buf *buf, uint64_t x); - + /** * Writes a 64-bit float in network byte order (big endian) to buffer. * @@ -875,4 +875,4 @@ AWS_COMMON_API bool aws_isspace(uint8_t ch); AWS_EXTERN_C_END -#endif /* AWS_COMMON_BYTE_BUF_H */ +#endif /* AWS_COMMON_BYTE_BUF_H */ diff --git a/contrib/restricted/aws/aws-c-common/include/aws/common/byte_order.h b/contrib/restricted/aws/aws-c-common/include/aws/common/byte_order.h index efd16b1915..efd59d60be 100644 --- a/contrib/restricted/aws/aws-c-common/include/aws/common/byte_order.h +++ b/contrib/restricted/aws/aws-c-common/include/aws/common/byte_order.h @@ -1,37 +1,37 @@ -#ifndef AWS_COMMON_BYTE_ORDER_H -#define AWS_COMMON_BYTE_ORDER_H - +#ifndef AWS_COMMON_BYTE_ORDER_H +#define AWS_COMMON_BYTE_ORDER_H + /** * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. - */ - -#include <aws/common/common.h> - + */ + +#include <aws/common/common.h> + AWS_EXTERN_C_BEGIN - -/** - * Returns 1 if machine is big endian, 0 if little endian. - * If you compile with even -O1 optimization, this check is completely optimized - * out at compile time and code which calls "if (aws_is_big_endian())" will do - * the right thing without branching. - */ + +/** + * Returns 1 if machine is big endian, 0 if little endian. + * If you compile with even -O1 optimization, this check is completely optimized + * out at compile time and code which calls "if (aws_is_big_endian())" will do + * the right thing without branching. + */ AWS_STATIC_IMPL int aws_is_big_endian(void); -/** - * Convert 64 bit integer from host to network byte order. - */ +/** + * Convert 64 bit integer from host to network byte order. + */ AWS_STATIC_IMPL uint64_t aws_hton64(uint64_t x); -/** - * Convert 64 bit integer from network to host byte order. - */ +/** + * Convert 64 bit integer from network to host byte order. + */ AWS_STATIC_IMPL uint64_t aws_ntoh64(uint64_t x); - -/** - * Convert 32 bit integer from host to network byte order. - */ + +/** + * Convert 32 bit integer from host to network byte order. + */ AWS_STATIC_IMPL uint32_t aws_hton32(uint32_t x); - -/** + +/** * Convert 32 bit float from host to network byte order. */ AWS_STATIC_IMPL float aws_htonf32(float x); @@ -42,11 +42,11 @@ AWS_STATIC_IMPL float aws_htonf32(float x); AWS_STATIC_IMPL double aws_htonf64(double x); /** - * Convert 32 bit integer from network to host byte order. - */ + * Convert 32 bit integer from network to host byte order. + */ AWS_STATIC_IMPL uint32_t aws_ntoh32(uint32_t x); - -/** + +/** * Convert 32 bit float from network to host byte order. */ AWS_STATIC_IMPL float aws_ntohf32(float x); @@ -56,19 +56,19 @@ AWS_STATIC_IMPL float aws_ntohf32(float x); AWS_STATIC_IMPL double aws_ntohf64(double x); /** - * Convert 16 bit integer from host to network byte order. - */ + * Convert 16 bit integer from host to network byte order. + */ AWS_STATIC_IMPL uint16_t aws_hton16(uint16_t x); - -/** - * Convert 16 bit integer from network to host byte order. - */ + +/** + * Convert 16 bit integer from network to host byte order. + */ AWS_STATIC_IMPL uint16_t aws_ntoh16(uint16_t x); - + #ifndef AWS_NO_STATIC_IMPL # include <aws/common/byte_order.inl> #endif /* AWS_NO_STATIC_IMPL */ AWS_EXTERN_C_END -#endif /* AWS_COMMON_BYTE_ORDER_H */ +#endif /* AWS_COMMON_BYTE_ORDER_H */ diff --git a/contrib/restricted/aws/aws-c-common/include/aws/common/clock.h b/contrib/restricted/aws/aws-c-common/include/aws/common/clock.h index 1a90a1f7b7..489a5f19a1 100644 --- a/contrib/restricted/aws/aws-c-common/include/aws/common/clock.h +++ b/contrib/restricted/aws/aws-c-common/include/aws/common/clock.h @@ -1,55 +1,55 @@ -#ifndef AWS_COMMON_CLOCK_H -#define AWS_COMMON_CLOCK_H - +#ifndef AWS_COMMON_CLOCK_H +#define AWS_COMMON_CLOCK_H + /** * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. - */ - -#include <aws/common/common.h> -#include <aws/common/math.h> - -enum aws_timestamp_unit { - AWS_TIMESTAMP_SECS = 1, - AWS_TIMESTAMP_MILLIS = 1000, - AWS_TIMESTAMP_MICROS = 1000000, - AWS_TIMESTAMP_NANOS = 1000000000, -}; - + */ + +#include <aws/common/common.h> +#include <aws/common/math.h> + +enum aws_timestamp_unit { + AWS_TIMESTAMP_SECS = 1, + AWS_TIMESTAMP_MILLIS = 1000, + AWS_TIMESTAMP_MICROS = 1000000, + AWS_TIMESTAMP_NANOS = 1000000000, +}; + AWS_EXTERN_C_BEGIN -/** - * Converts 'timestamp' from unit 'convert_from' to unit 'convert_to', if the units are the same then 'timestamp' is - * returned. If 'remainder' is NOT NULL, it will be set to the remainder if convert_from is a more precise unit than - * convert_to. To avoid unnecessary branching, 'remainder' is not zero initialized in this function, be sure to set it - * to 0 first if you care about that kind of thing. If conversion would lead to integer overflow, the timestamp - * returned will be the highest possible time that is representable, i.e. UINT64_MAX. - */ -AWS_STATIC_IMPL uint64_t aws_timestamp_convert( - uint64_t timestamp, - enum aws_timestamp_unit convert_from, - enum aws_timestamp_unit convert_to, +/** + * Converts 'timestamp' from unit 'convert_from' to unit 'convert_to', if the units are the same then 'timestamp' is + * returned. If 'remainder' is NOT NULL, it will be set to the remainder if convert_from is a more precise unit than + * convert_to. To avoid unnecessary branching, 'remainder' is not zero initialized in this function, be sure to set it + * to 0 first if you care about that kind of thing. If conversion would lead to integer overflow, the timestamp + * returned will be the highest possible time that is representable, i.e. UINT64_MAX. + */ +AWS_STATIC_IMPL uint64_t aws_timestamp_convert( + uint64_t timestamp, + enum aws_timestamp_unit convert_from, + enum aws_timestamp_unit convert_to, uint64_t *remainder); - -/** - * Get ticks in nanoseconds (usually 100 nanosecond precision) on the high resolution clock (most-likely TSC). This - * clock has no bearing on the actual system time. On success, timestamp will be set. - */ -AWS_COMMON_API -int aws_high_res_clock_get_ticks(uint64_t *timestamp); - -/** - * Get ticks in nanoseconds (usually 100 nanosecond precision) on the system clock. Reflects actual system time via - * nanoseconds since unix epoch. Use with care since an inaccurately set clock will probably cause bugs. On success, - * timestamp will be set. - */ -AWS_COMMON_API -int aws_sys_clock_get_ticks(uint64_t *timestamp); - + +/** + * Get ticks in nanoseconds (usually 100 nanosecond precision) on the high resolution clock (most-likely TSC). This + * clock has no bearing on the actual system time. On success, timestamp will be set. + */ +AWS_COMMON_API +int aws_high_res_clock_get_ticks(uint64_t *timestamp); + +/** + * Get ticks in nanoseconds (usually 100 nanosecond precision) on the system clock. Reflects actual system time via + * nanoseconds since unix epoch. Use with care since an inaccurately set clock will probably cause bugs. On success, + * timestamp will be set. + */ +AWS_COMMON_API +int aws_sys_clock_get_ticks(uint64_t *timestamp); + #ifndef AWS_NO_STATIC_IMPL # include <aws/common/clock.inl> #endif /* AWS_NO_STATIC_IMPL */ -AWS_EXTERN_C_END - -#endif /* AWS_COMMON_CLOCK_H */ +AWS_EXTERN_C_END + +#endif /* AWS_COMMON_CLOCK_H */ diff --git a/contrib/restricted/aws/aws-c-common/include/aws/common/command_line_parser.h b/contrib/restricted/aws/aws-c-common/include/aws/common/command_line_parser.h index 266e15abe9..8b31ae98ef 100644 --- a/contrib/restricted/aws/aws-c-common/include/aws/common/command_line_parser.h +++ b/contrib/restricted/aws/aws-c-common/include/aws/common/command_line_parser.h @@ -3,56 +3,56 @@ /** * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. - */ -#include <aws/common/common.h> - -enum aws_cli_options_has_arg { - AWS_CLI_OPTIONS_NO_ARGUMENT = 0, - AWS_CLI_OPTIONS_REQUIRED_ARGUMENT = 1, - AWS_CLI_OPTIONS_OPTIONAL_ARGUMENT = 2, -}; - + */ +#include <aws/common/common.h> + +enum aws_cli_options_has_arg { + AWS_CLI_OPTIONS_NO_ARGUMENT = 0, + AWS_CLI_OPTIONS_REQUIRED_ARGUMENT = 1, + AWS_CLI_OPTIONS_OPTIONAL_ARGUMENT = 2, +}; + /* Ignoring padding since we're trying to maintain getopt.h compatibility */ /* NOLINTNEXTLINE(clang-analyzer-optin.performance.Padding) */ -struct aws_cli_option { - const char *name; - enum aws_cli_options_has_arg has_arg; - int *flag; - int val; -}; - +struct aws_cli_option { + const char *name; + enum aws_cli_options_has_arg has_arg; + int *flag; + int val; +}; + AWS_EXTERN_C_BEGIN -/** - * Initialized to 1 (for where the first argument would be). As arguments are parsed, this number is the index - * of the next argument to parse. Reset this to 1 to parse another set of arguments, or to rerun the parser. - */ -AWS_COMMON_API extern int aws_cli_optind; - -/** - * If an option has an argument, when the option is encountered, this will be set to the argument portion. - */ -AWS_COMMON_API extern const char *aws_cli_optarg; - -/** - * A mostly compliant implementation of posix getopt_long(). Parses command-line arguments. argc is the number of - * command line arguments passed in argv. optstring contains the legitimate option characters. The option characters - * coorespond to aws_cli_option::val. If the character is followed by a :, the option requires an argument. If it is - * followed by '::', the argument is optional (not implemented yet). - * - * longopts, is an array of struct aws_cli_option. These are the allowed options for the program. - * The last member of the array must be zero initialized. - * - * If longindex is non-null, it will be set to the index in longopts, for the found option. - * - * Returns option val if it was found, '?' if an option was encountered that was not specified in the option string, - * returns -1 when all arguments that can be parsed have been parsed. - */ -AWS_COMMON_API int aws_cli_getopt_long( - int argc, - char *const argv[], - const char *optstring, - const struct aws_cli_option *longopts, - int *longindex); -AWS_EXTERN_C_END - +/** + * Initialized to 1 (for where the first argument would be). As arguments are parsed, this number is the index + * of the next argument to parse. Reset this to 1 to parse another set of arguments, or to rerun the parser. + */ +AWS_COMMON_API extern int aws_cli_optind; + +/** + * If an option has an argument, when the option is encountered, this will be set to the argument portion. + */ +AWS_COMMON_API extern const char *aws_cli_optarg; + +/** + * A mostly compliant implementation of posix getopt_long(). Parses command-line arguments. argc is the number of + * command line arguments passed in argv. optstring contains the legitimate option characters. The option characters + * coorespond to aws_cli_option::val. If the character is followed by a :, the option requires an argument. If it is + * followed by '::', the argument is optional (not implemented yet). + * + * longopts, is an array of struct aws_cli_option. These are the allowed options for the program. + * The last member of the array must be zero initialized. + * + * If longindex is non-null, it will be set to the index in longopts, for the found option. + * + * Returns option val if it was found, '?' if an option was encountered that was not specified in the option string, + * returns -1 when all arguments that can be parsed have been parsed. + */ +AWS_COMMON_API int aws_cli_getopt_long( + int argc, + char *const argv[], + const char *optstring, + const struct aws_cli_option *longopts, + int *longindex); +AWS_EXTERN_C_END + #endif /* AWS_COMMON_COMMAND_LINE_PARSER_H */ diff --git a/contrib/restricted/aws/aws-c-common/include/aws/common/common.h b/contrib/restricted/aws/aws-c-common/include/aws/common/common.h index e9bbf536da..7968a5e009 100644 --- a/contrib/restricted/aws/aws-c-common/include/aws/common/common.h +++ b/contrib/restricted/aws/aws-c-common/include/aws/common/common.h @@ -1,14 +1,14 @@ -#ifndef AWS_COMMON_COMMON_H -#define AWS_COMMON_COMMON_H - +#ifndef AWS_COMMON_COMMON_H +#define AWS_COMMON_COMMON_H + /** * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. - */ - + */ + #include <aws/common/config.h> -#include <aws/common/exports.h> - +#include <aws/common/exports.h> + #include <aws/common/allocator.h> #include <aws/common/assert.h> #include <aws/common/error.h> @@ -18,29 +18,29 @@ #include <aws/common/stdbool.h> #include <aws/common/stdint.h> #include <aws/common/zero.h> -#include <stddef.h> -#include <stdio.h> +#include <stddef.h> +#include <stdio.h> #include <stdlib.h> /* for abort() */ -#include <string.h> - -AWS_EXTERN_C_BEGIN - -/** +#include <string.h> + +AWS_EXTERN_C_BEGIN + +/** * Initializes internal datastructures used by aws-c-common. * Must be called before using any functionality in aws-c-common. - */ -AWS_COMMON_API + */ +AWS_COMMON_API void aws_common_library_init(struct aws_allocator *allocator); - -/** + +/** * Shuts down the internal datastructures used by aws-c-common. - */ -AWS_COMMON_API + */ +AWS_COMMON_API void aws_common_library_clean_up(void); - -AWS_COMMON_API + +AWS_COMMON_API void aws_common_fatal_assert_library_initialized(void); - -AWS_EXTERN_C_END - -#endif /* AWS_COMMON_COMMON_H */ + +AWS_EXTERN_C_END + +#endif /* AWS_COMMON_COMMON_H */ diff --git a/contrib/restricted/aws/aws-c-common/include/aws/common/condition_variable.h b/contrib/restricted/aws/aws-c-common/include/aws/common/condition_variable.h index 485bcc9368..e78ceea160 100644 --- a/contrib/restricted/aws/aws-c-common/include/aws/common/condition_variable.h +++ b/contrib/restricted/aws/aws-c-common/include/aws/common/condition_variable.h @@ -1,111 +1,111 @@ -#ifndef AWS_COMMON_CONDITION_VARIABLE_H -#define AWS_COMMON_CONDITION_VARIABLE_H - +#ifndef AWS_COMMON_CONDITION_VARIABLE_H +#define AWS_COMMON_CONDITION_VARIABLE_H + /** * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. - */ - -#include <aws/common/common.h> -#ifndef _WIN32 -# include <pthread.h> -#endif - -struct aws_mutex; - -struct aws_condition_variable; - -typedef bool(aws_condition_predicate_fn)(void *); - -struct aws_condition_variable { -#ifdef _WIN32 - void *condition_handle; -#else - pthread_cond_t condition_handle; -#endif + */ + +#include <aws/common/common.h> +#ifndef _WIN32 +# include <pthread.h> +#endif + +struct aws_mutex; + +struct aws_condition_variable; + +typedef bool(aws_condition_predicate_fn)(void *); + +struct aws_condition_variable { +#ifdef _WIN32 + void *condition_handle; +#else + pthread_cond_t condition_handle; +#endif bool initialized; -}; - -/** - * Static initializer for condition variable. - * You can do something like struct aws_condition_variable var = - * AWS_CONDITION_VARIABLE_INIT; - * - * If on Windows and you get an error about AWS_CONDITION_VARIABLE_INIT being undefined, please include Windows.h to get - * CONDITION_VARIABLE_INIT. - */ -#ifdef _WIN32 -# define AWS_CONDITION_VARIABLE_INIT \ +}; + +/** + * Static initializer for condition variable. + * You can do something like struct aws_condition_variable var = + * AWS_CONDITION_VARIABLE_INIT; + * + * If on Windows and you get an error about AWS_CONDITION_VARIABLE_INIT being undefined, please include Windows.h to get + * CONDITION_VARIABLE_INIT. + */ +#ifdef _WIN32 +# define AWS_CONDITION_VARIABLE_INIT \ { .condition_handle = NULL, .initialized = true } -#else -# define AWS_CONDITION_VARIABLE_INIT \ +#else +# define AWS_CONDITION_VARIABLE_INIT \ { .condition_handle = PTHREAD_COND_INITIALIZER, .initialized = true } -#endif - -AWS_EXTERN_C_BEGIN - -/** - * Initializes a condition variable. - */ -AWS_COMMON_API -int aws_condition_variable_init(struct aws_condition_variable *condition_variable); - -/** - * Cleans up a condition variable. - */ -AWS_COMMON_API -void aws_condition_variable_clean_up(struct aws_condition_variable *condition_variable); - -/** - * Notifies/Wakes one waiting thread - */ -AWS_COMMON_API -int aws_condition_variable_notify_one(struct aws_condition_variable *condition_variable); - -/** - * Notifies/Wakes all waiting threads. - */ -AWS_COMMON_API -int aws_condition_variable_notify_all(struct aws_condition_variable *condition_variable); - -/** - * Waits the calling thread on a notification from another thread. - */ -AWS_COMMON_API -int aws_condition_variable_wait(struct aws_condition_variable *condition_variable, struct aws_mutex *mutex); - -/** - * Waits the calling thread on a notification from another thread. If predicate returns false, the wait is reentered, - * otherwise control returns to the caller. - */ -AWS_COMMON_API -int aws_condition_variable_wait_pred( - struct aws_condition_variable *condition_variable, - struct aws_mutex *mutex, - aws_condition_predicate_fn *pred, - void *pred_ctx); - -/** - * Waits the calling thread on a notification from another thread. Times out after time_to_wait. time_to_wait is in - * nanoseconds. - */ -AWS_COMMON_API -int aws_condition_variable_wait_for( - struct aws_condition_variable *condition_variable, - struct aws_mutex *mutex, - int64_t time_to_wait); - -/** - * Waits the calling thread on a notification from another thread. Times out after time_to_wait. time_to_wait is in - * nanoseconds. If predicate returns false, the wait is reentered, otherwise control returns to the caller. - */ -AWS_COMMON_API -int aws_condition_variable_wait_for_pred( - struct aws_condition_variable *condition_variable, - struct aws_mutex *mutex, - int64_t time_to_wait, - aws_condition_predicate_fn *pred, - void *pred_ctx); - -AWS_EXTERN_C_END -#endif /* AWS_COMMON_CONDITION_VARIABLE_H */ +#endif + +AWS_EXTERN_C_BEGIN + +/** + * Initializes a condition variable. + */ +AWS_COMMON_API +int aws_condition_variable_init(struct aws_condition_variable *condition_variable); + +/** + * Cleans up a condition variable. + */ +AWS_COMMON_API +void aws_condition_variable_clean_up(struct aws_condition_variable *condition_variable); + +/** + * Notifies/Wakes one waiting thread + */ +AWS_COMMON_API +int aws_condition_variable_notify_one(struct aws_condition_variable *condition_variable); + +/** + * Notifies/Wakes all waiting threads. + */ +AWS_COMMON_API +int aws_condition_variable_notify_all(struct aws_condition_variable *condition_variable); + +/** + * Waits the calling thread on a notification from another thread. + */ +AWS_COMMON_API +int aws_condition_variable_wait(struct aws_condition_variable *condition_variable, struct aws_mutex *mutex); + +/** + * Waits the calling thread on a notification from another thread. If predicate returns false, the wait is reentered, + * otherwise control returns to the caller. + */ +AWS_COMMON_API +int aws_condition_variable_wait_pred( + struct aws_condition_variable *condition_variable, + struct aws_mutex *mutex, + aws_condition_predicate_fn *pred, + void *pred_ctx); + +/** + * Waits the calling thread on a notification from another thread. Times out after time_to_wait. time_to_wait is in + * nanoseconds. + */ +AWS_COMMON_API +int aws_condition_variable_wait_for( + struct aws_condition_variable *condition_variable, + struct aws_mutex *mutex, + int64_t time_to_wait); + +/** + * Waits the calling thread on a notification from another thread. Times out after time_to_wait. time_to_wait is in + * nanoseconds. If predicate returns false, the wait is reentered, otherwise control returns to the caller. + */ +AWS_COMMON_API +int aws_condition_variable_wait_for_pred( + struct aws_condition_variable *condition_variable, + struct aws_mutex *mutex, + int64_t time_to_wait, + aws_condition_predicate_fn *pred, + void *pred_ctx); + +AWS_EXTERN_C_END +#endif /* AWS_COMMON_CONDITION_VARIABLE_H */ diff --git a/contrib/restricted/aws/aws-c-common/include/aws/common/date_time.h b/contrib/restricted/aws/aws-c-common/include/aws/common/date_time.h index 14860c5d21..5522c4fae5 100644 --- a/contrib/restricted/aws/aws-c-common/include/aws/common/date_time.h +++ b/contrib/restricted/aws/aws-c-common/include/aws/common/date_time.h @@ -1,158 +1,158 @@ -#ifndef AWS_COMMON_DATE_TIME_H -#define AWS_COMMON_DATE_TIME_H +#ifndef AWS_COMMON_DATE_TIME_H +#define AWS_COMMON_DATE_TIME_H /** * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. - */ -#include <aws/common/common.h> - -#include <time.h> - -#define AWS_DATE_TIME_STR_MAX_LEN 100 -#define AWS_DATE_TIME_STR_MAX_BASIC_LEN 20 - -struct aws_byte_buf; -struct aws_byte_cursor; - -enum aws_date_format { - AWS_DATE_FORMAT_RFC822, - AWS_DATE_FORMAT_ISO_8601, - AWS_DATE_FORMAT_ISO_8601_BASIC, - AWS_DATE_FORMAT_AUTO_DETECT, -}; - -enum aws_date_month { - AWS_DATE_MONTH_JANUARY = 0, - AWS_DATE_MONTH_FEBRUARY, - AWS_DATE_MONTH_MARCH, - AWS_DATE_MONTH_APRIL, - AWS_DATE_MONTH_MAY, - AWS_DATE_MONTH_JUNE, - AWS_DATE_MONTH_JULY, - AWS_DATE_MONTH_AUGUST, - AWS_DATE_MONTH_SEPTEMBER, - AWS_DATE_MONTH_OCTOBER, - AWS_DATE_MONTH_NOVEMBER, - AWS_DATE_MONTH_DECEMBER, -}; - -enum aws_date_day_of_week { - AWS_DATE_DAY_OF_WEEK_SUNDAY = 0, - AWS_DATE_DAY_OF_WEEK_MONDAY, - AWS_DATE_DAY_OF_WEEK_TUESDAY, - AWS_DATE_DAY_OF_WEEK_WEDNESDAY, - AWS_DATE_DAY_OF_WEEK_THURSDAY, - AWS_DATE_DAY_OF_WEEK_FRIDAY, - AWS_DATE_DAY_OF_WEEK_SATURDAY, -}; - -struct aws_date_time { - time_t timestamp; - char tz[6]; - struct tm gmt_time; - struct tm local_time; - bool utc_assumed; -}; - -AWS_EXTERN_C_BEGIN - -/** - * Initializes dt to be the current system time. - */ -AWS_COMMON_API void aws_date_time_init_now(struct aws_date_time *dt); - -/** - * Initializes dt to be the time represented in milliseconds since unix epoch. - */ -AWS_COMMON_API void aws_date_time_init_epoch_millis(struct aws_date_time *dt, uint64_t ms_since_epoch); - -/** - * Initializes dt to be the time represented in seconds.millis since unix epoch. - */ -AWS_COMMON_API void aws_date_time_init_epoch_secs(struct aws_date_time *dt, double sec_ms); - -/** - * Initializes dt to be the time represented by date_str in format 'fmt'. Returns AWS_OP_SUCCESS if the - * string was successfully parsed, returns AWS_OP_ERR if parsing failed. - * - * Notes for AWS_DATE_FORMAT_RFC822: - * If no time zone information is provided, it is assumed to be local time (please don't do this). - * - * If the time zone is something other than something indicating Universal Time (e.g. Z, UT, UTC, or GMT) or an offset - * from UTC (e.g. +0100, -0700), parsing will fail. - * - * Really, it's just better if you always use Universal Time. - */ -AWS_COMMON_API int aws_date_time_init_from_str( - struct aws_date_time *dt, - const struct aws_byte_buf *date_str, - enum aws_date_format fmt); - -/** - * aws_date_time_init variant that takes a byte_cursor rather than a byte_buf - */ -AWS_COMMON_API int aws_date_time_init_from_str_cursor( - struct aws_date_time *dt, - const struct aws_byte_cursor *date_str_cursor, - enum aws_date_format fmt); - -/** - * Copies the current time as a formatted date string in local time into output_buf. If buffer is too small, it will - * return AWS_OP_ERR. A good size suggestion is AWS_DATE_TIME_STR_MAX_LEN bytes. AWS_DATE_FORMAT_AUTO_DETECT is not - * allowed. - */ -AWS_COMMON_API int aws_date_time_to_local_time_str( - const struct aws_date_time *dt, - enum aws_date_format fmt, - struct aws_byte_buf *output_buf); - -/** - * Copies the current time as a formatted date string in utc time into output_buf. If buffer is too small, it will - * return AWS_OP_ERR. A good size suggestion is AWS_DATE_TIME_STR_MAX_LEN bytes. AWS_DATE_FORMAT_AUTO_DETECT is not - * allowed. - */ -AWS_COMMON_API int aws_date_time_to_utc_time_str( - const struct aws_date_time *dt, - enum aws_date_format fmt, - struct aws_byte_buf *output_buf); - -/** - * Copies the current time as a formatted short date string in local time into output_buf. If buffer is too small, it - * will return AWS_OP_ERR. A good size suggestion is AWS_DATE_TIME_STR_MAX_LEN bytes. AWS_DATE_FORMAT_AUTO_DETECT is not - * allowed. - */ -AWS_COMMON_API int aws_date_time_to_local_time_short_str( - const struct aws_date_time *dt, - enum aws_date_format fmt, - struct aws_byte_buf *output_buf); - -/** - * Copies the current time as a formatted short date string in utc time into output_buf. If buffer is too small, it will - * return AWS_OP_ERR. A good size suggestion is AWS_DATE_TIME_STR_MAX_LEN bytes. AWS_DATE_FORMAT_AUTO_DETECT is not - * allowed. - */ -AWS_COMMON_API int aws_date_time_to_utc_time_short_str( - const struct aws_date_time *dt, - enum aws_date_format fmt, - struct aws_byte_buf *output_buf); - -AWS_COMMON_API double aws_date_time_as_epoch_secs(const struct aws_date_time *dt); -AWS_COMMON_API uint64_t aws_date_time_as_nanos(const struct aws_date_time *dt); -AWS_COMMON_API uint64_t aws_date_time_as_millis(const struct aws_date_time *dt); -AWS_COMMON_API uint16_t aws_date_time_year(const struct aws_date_time *dt, bool local_time); -AWS_COMMON_API enum aws_date_month aws_date_time_month(const struct aws_date_time *dt, bool local_time); -AWS_COMMON_API uint8_t aws_date_time_month_day(const struct aws_date_time *dt, bool local_time); -AWS_COMMON_API enum aws_date_day_of_week aws_date_time_day_of_week(const struct aws_date_time *dt, bool local_time); -AWS_COMMON_API uint8_t aws_date_time_hour(const struct aws_date_time *dt, bool local_time); -AWS_COMMON_API uint8_t aws_date_time_minute(const struct aws_date_time *dt, bool local_time); -AWS_COMMON_API uint8_t aws_date_time_second(const struct aws_date_time *dt, bool local_time); -AWS_COMMON_API bool aws_date_time_dst(const struct aws_date_time *dt, bool local_time); - -/** - * returns the difference of a and b (a - b) in seconds. - */ -AWS_COMMON_API time_t aws_date_time_diff(const struct aws_date_time *a, const struct aws_date_time *b); - -AWS_EXTERN_C_END - -#endif /* AWS_COMMON_DATE_TIME_H */ + */ +#include <aws/common/common.h> + +#include <time.h> + +#define AWS_DATE_TIME_STR_MAX_LEN 100 +#define AWS_DATE_TIME_STR_MAX_BASIC_LEN 20 + +struct aws_byte_buf; +struct aws_byte_cursor; + +enum aws_date_format { + AWS_DATE_FORMAT_RFC822, + AWS_DATE_FORMAT_ISO_8601, + AWS_DATE_FORMAT_ISO_8601_BASIC, + AWS_DATE_FORMAT_AUTO_DETECT, +}; + +enum aws_date_month { + AWS_DATE_MONTH_JANUARY = 0, + AWS_DATE_MONTH_FEBRUARY, + AWS_DATE_MONTH_MARCH, + AWS_DATE_MONTH_APRIL, + AWS_DATE_MONTH_MAY, + AWS_DATE_MONTH_JUNE, + AWS_DATE_MONTH_JULY, + AWS_DATE_MONTH_AUGUST, + AWS_DATE_MONTH_SEPTEMBER, + AWS_DATE_MONTH_OCTOBER, + AWS_DATE_MONTH_NOVEMBER, + AWS_DATE_MONTH_DECEMBER, +}; + +enum aws_date_day_of_week { + AWS_DATE_DAY_OF_WEEK_SUNDAY = 0, + AWS_DATE_DAY_OF_WEEK_MONDAY, + AWS_DATE_DAY_OF_WEEK_TUESDAY, + AWS_DATE_DAY_OF_WEEK_WEDNESDAY, + AWS_DATE_DAY_OF_WEEK_THURSDAY, + AWS_DATE_DAY_OF_WEEK_FRIDAY, + AWS_DATE_DAY_OF_WEEK_SATURDAY, +}; + +struct aws_date_time { + time_t timestamp; + char tz[6]; + struct tm gmt_time; + struct tm local_time; + bool utc_assumed; +}; + +AWS_EXTERN_C_BEGIN + +/** + * Initializes dt to be the current system time. + */ +AWS_COMMON_API void aws_date_time_init_now(struct aws_date_time *dt); + +/** + * Initializes dt to be the time represented in milliseconds since unix epoch. + */ +AWS_COMMON_API void aws_date_time_init_epoch_millis(struct aws_date_time *dt, uint64_t ms_since_epoch); + +/** + * Initializes dt to be the time represented in seconds.millis since unix epoch. + */ +AWS_COMMON_API void aws_date_time_init_epoch_secs(struct aws_date_time *dt, double sec_ms); + +/** + * Initializes dt to be the time represented by date_str in format 'fmt'. Returns AWS_OP_SUCCESS if the + * string was successfully parsed, returns AWS_OP_ERR if parsing failed. + * + * Notes for AWS_DATE_FORMAT_RFC822: + * If no time zone information is provided, it is assumed to be local time (please don't do this). + * + * If the time zone is something other than something indicating Universal Time (e.g. Z, UT, UTC, or GMT) or an offset + * from UTC (e.g. +0100, -0700), parsing will fail. + * + * Really, it's just better if you always use Universal Time. + */ +AWS_COMMON_API int aws_date_time_init_from_str( + struct aws_date_time *dt, + const struct aws_byte_buf *date_str, + enum aws_date_format fmt); + +/** + * aws_date_time_init variant that takes a byte_cursor rather than a byte_buf + */ +AWS_COMMON_API int aws_date_time_init_from_str_cursor( + struct aws_date_time *dt, + const struct aws_byte_cursor *date_str_cursor, + enum aws_date_format fmt); + +/** + * Copies the current time as a formatted date string in local time into output_buf. If buffer is too small, it will + * return AWS_OP_ERR. A good size suggestion is AWS_DATE_TIME_STR_MAX_LEN bytes. AWS_DATE_FORMAT_AUTO_DETECT is not + * allowed. + */ +AWS_COMMON_API int aws_date_time_to_local_time_str( + const struct aws_date_time *dt, + enum aws_date_format fmt, + struct aws_byte_buf *output_buf); + +/** + * Copies the current time as a formatted date string in utc time into output_buf. If buffer is too small, it will + * return AWS_OP_ERR. A good size suggestion is AWS_DATE_TIME_STR_MAX_LEN bytes. AWS_DATE_FORMAT_AUTO_DETECT is not + * allowed. + */ +AWS_COMMON_API int aws_date_time_to_utc_time_str( + const struct aws_date_time *dt, + enum aws_date_format fmt, + struct aws_byte_buf *output_buf); + +/** + * Copies the current time as a formatted short date string in local time into output_buf. If buffer is too small, it + * will return AWS_OP_ERR. A good size suggestion is AWS_DATE_TIME_STR_MAX_LEN bytes. AWS_DATE_FORMAT_AUTO_DETECT is not + * allowed. + */ +AWS_COMMON_API int aws_date_time_to_local_time_short_str( + const struct aws_date_time *dt, + enum aws_date_format fmt, + struct aws_byte_buf *output_buf); + +/** + * Copies the current time as a formatted short date string in utc time into output_buf. If buffer is too small, it will + * return AWS_OP_ERR. A good size suggestion is AWS_DATE_TIME_STR_MAX_LEN bytes. AWS_DATE_FORMAT_AUTO_DETECT is not + * allowed. + */ +AWS_COMMON_API int aws_date_time_to_utc_time_short_str( + const struct aws_date_time *dt, + enum aws_date_format fmt, + struct aws_byte_buf *output_buf); + +AWS_COMMON_API double aws_date_time_as_epoch_secs(const struct aws_date_time *dt); +AWS_COMMON_API uint64_t aws_date_time_as_nanos(const struct aws_date_time *dt); +AWS_COMMON_API uint64_t aws_date_time_as_millis(const struct aws_date_time *dt); +AWS_COMMON_API uint16_t aws_date_time_year(const struct aws_date_time *dt, bool local_time); +AWS_COMMON_API enum aws_date_month aws_date_time_month(const struct aws_date_time *dt, bool local_time); +AWS_COMMON_API uint8_t aws_date_time_month_day(const struct aws_date_time *dt, bool local_time); +AWS_COMMON_API enum aws_date_day_of_week aws_date_time_day_of_week(const struct aws_date_time *dt, bool local_time); +AWS_COMMON_API uint8_t aws_date_time_hour(const struct aws_date_time *dt, bool local_time); +AWS_COMMON_API uint8_t aws_date_time_minute(const struct aws_date_time *dt, bool local_time); +AWS_COMMON_API uint8_t aws_date_time_second(const struct aws_date_time *dt, bool local_time); +AWS_COMMON_API bool aws_date_time_dst(const struct aws_date_time *dt, bool local_time); + +/** + * returns the difference of a and b (a - b) in seconds. + */ +AWS_COMMON_API time_t aws_date_time_diff(const struct aws_date_time *a, const struct aws_date_time *b); + +AWS_EXTERN_C_END + +#endif /* AWS_COMMON_DATE_TIME_H */ diff --git a/contrib/restricted/aws/aws-c-common/include/aws/common/device_random.h b/contrib/restricted/aws/aws-c-common/include/aws/common/device_random.h index c1fc2405c9..ae79f7578d 100644 --- a/contrib/restricted/aws/aws-c-common/include/aws/common/device_random.h +++ b/contrib/restricted/aws/aws-c-common/include/aws/common/device_random.h @@ -1,40 +1,40 @@ -#ifndef AWS_COMMON_DEVICE_RANDOM_H -#define AWS_COMMON_DEVICE_RANDOM_H +#ifndef AWS_COMMON_DEVICE_RANDOM_H +#define AWS_COMMON_DEVICE_RANDOM_H /** * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. - */ -#include <aws/common/common.h> - -struct aws_byte_buf; - -AWS_EXTERN_C_BEGIN - -/** - * Get an unpredictably random 64bit number, suitable for cryptographic use. - */ -AWS_COMMON_API int aws_device_random_u64(uint64_t *output); - -/** - * Get an unpredictably random 32bit number, suitable for cryptographic use. - */ -AWS_COMMON_API int aws_device_random_u32(uint32_t *output); - -/** - * Get an unpredictably random 16bit number, suitable for cryptographic use. - */ -AWS_COMMON_API int aws_device_random_u16(uint16_t *output); - -/** - * Get an unpredictably random 8bit number, suitable for cryptographic use. - */ -AWS_COMMON_API int aws_device_random_u8(uint8_t *output); - -/** - * Fill a buffer with unpredictably random bytes, suitable for cryptographic use. - */ -AWS_COMMON_API int aws_device_random_buffer(struct aws_byte_buf *output); - -AWS_EXTERN_C_END - -#endif /* AWS_COMMON_DEVICE_RANDOM_H */ + */ +#include <aws/common/common.h> + +struct aws_byte_buf; + +AWS_EXTERN_C_BEGIN + +/** + * Get an unpredictably random 64bit number, suitable for cryptographic use. + */ +AWS_COMMON_API int aws_device_random_u64(uint64_t *output); + +/** + * Get an unpredictably random 32bit number, suitable for cryptographic use. + */ +AWS_COMMON_API int aws_device_random_u32(uint32_t *output); + +/** + * Get an unpredictably random 16bit number, suitable for cryptographic use. + */ +AWS_COMMON_API int aws_device_random_u16(uint16_t *output); + +/** + * Get an unpredictably random 8bit number, suitable for cryptographic use. + */ +AWS_COMMON_API int aws_device_random_u8(uint8_t *output); + +/** + * Fill a buffer with unpredictably random bytes, suitable for cryptographic use. + */ +AWS_COMMON_API int aws_device_random_buffer(struct aws_byte_buf *output); + +AWS_EXTERN_C_END + +#endif /* AWS_COMMON_DEVICE_RANDOM_H */ diff --git a/contrib/restricted/aws/aws-c-common/include/aws/common/encoding.h b/contrib/restricted/aws/aws-c-common/include/aws/common/encoding.h index 3739ac60b0..a90b72ef0b 100644 --- a/contrib/restricted/aws/aws-c-common/include/aws/common/encoding.h +++ b/contrib/restricted/aws/aws-c-common/include/aws/common/encoding.h @@ -1,135 +1,135 @@ -#ifndef AWS_COMMON_ENCODING_H -#define AWS_COMMON_ENCODING_H - +#ifndef AWS_COMMON_ENCODING_H +#define AWS_COMMON_ENCODING_H + /** * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. - */ - -#include <aws/common/byte_buf.h> -#include <aws/common/byte_order.h> -#include <aws/common/common.h> - -#include <memory.h> - -AWS_EXTERN_C_BEGIN - -/* - * computes the length necessary to store the result of aws_hex_encode(). - * returns -1 on failure, and 0 on success. encoded_length will be set on - * success. - */ -AWS_COMMON_API -int aws_hex_compute_encoded_len(size_t to_encode_len, size_t *encoded_length); - -/* - * Base 16 (hex) encodes the contents of to_encode and stores the result in - * output. 0 terminates the result. Assumes the buffer is empty and does not resize on - * insufficient capacity. - */ -AWS_COMMON_API -int aws_hex_encode(const struct aws_byte_cursor *AWS_RESTRICT to_encode, struct aws_byte_buf *AWS_RESTRICT output); - -/* - * Base 16 (hex) encodes the contents of to_encode and appends the result in - * output. Does not 0-terminate. Grows the destination buffer dynamically if necessary. - */ -AWS_COMMON_API -int aws_hex_encode_append_dynamic( - const struct aws_byte_cursor *AWS_RESTRICT to_encode, - struct aws_byte_buf *AWS_RESTRICT output); - -/* - * computes the length necessary to store the result of aws_hex_decode(). - * returns -1 on failure, and 0 on success. decoded_len will be set on success. - */ -AWS_COMMON_API -int aws_hex_compute_decoded_len(size_t to_decode_len, size_t *decoded_len); - -/* - * Base 16 (hex) decodes the contents of to_decode and stores the result in - * output. If output is NULL, output_size will be set to what the output_size - * should be. - */ -AWS_COMMON_API -int aws_hex_decode(const struct aws_byte_cursor *AWS_RESTRICT to_decode, struct aws_byte_buf *AWS_RESTRICT output); - -/* - * Computes the length necessary to store the output of aws_base64_encode call. - * returns -1 on failure, and 0 on success. encoded_length will be set on - * success. - */ -AWS_COMMON_API -int aws_base64_compute_encoded_len(size_t to_encode_len, size_t *encoded_len); - -/* - * Base 64 encodes the contents of to_encode and stores the result in output. - */ -AWS_COMMON_API -int aws_base64_encode(const struct aws_byte_cursor *AWS_RESTRICT to_encode, struct aws_byte_buf *AWS_RESTRICT output); - -/* - * Computes the length necessary to store the output of aws_base64_decode call. - * returns -1 on failure, and 0 on success. decoded_len will be set on success. - */ -AWS_COMMON_API -int aws_base64_compute_decoded_len(const struct aws_byte_cursor *AWS_RESTRICT to_decode, size_t *decoded_len); - -/* - * Base 64 decodes the contents of to_decode and stores the result in output. - */ -AWS_COMMON_API -int aws_base64_decode(const struct aws_byte_cursor *AWS_RESTRICT to_decode, struct aws_byte_buf *AWS_RESTRICT output); - -/* Add a 64 bit unsigned integer to the buffer, ensuring network - byte order - * Assumes the buffer size is at least 8 bytes. - */ + */ + +#include <aws/common/byte_buf.h> +#include <aws/common/byte_order.h> +#include <aws/common/common.h> + +#include <memory.h> + +AWS_EXTERN_C_BEGIN + +/* + * computes the length necessary to store the result of aws_hex_encode(). + * returns -1 on failure, and 0 on success. encoded_length will be set on + * success. + */ +AWS_COMMON_API +int aws_hex_compute_encoded_len(size_t to_encode_len, size_t *encoded_length); + +/* + * Base 16 (hex) encodes the contents of to_encode and stores the result in + * output. 0 terminates the result. Assumes the buffer is empty and does not resize on + * insufficient capacity. + */ +AWS_COMMON_API +int aws_hex_encode(const struct aws_byte_cursor *AWS_RESTRICT to_encode, struct aws_byte_buf *AWS_RESTRICT output); + +/* + * Base 16 (hex) encodes the contents of to_encode and appends the result in + * output. Does not 0-terminate. Grows the destination buffer dynamically if necessary. + */ +AWS_COMMON_API +int aws_hex_encode_append_dynamic( + const struct aws_byte_cursor *AWS_RESTRICT to_encode, + struct aws_byte_buf *AWS_RESTRICT output); + +/* + * computes the length necessary to store the result of aws_hex_decode(). + * returns -1 on failure, and 0 on success. decoded_len will be set on success. + */ +AWS_COMMON_API +int aws_hex_compute_decoded_len(size_t to_decode_len, size_t *decoded_len); + +/* + * Base 16 (hex) decodes the contents of to_decode and stores the result in + * output. If output is NULL, output_size will be set to what the output_size + * should be. + */ +AWS_COMMON_API +int aws_hex_decode(const struct aws_byte_cursor *AWS_RESTRICT to_decode, struct aws_byte_buf *AWS_RESTRICT output); + +/* + * Computes the length necessary to store the output of aws_base64_encode call. + * returns -1 on failure, and 0 on success. encoded_length will be set on + * success. + */ +AWS_COMMON_API +int aws_base64_compute_encoded_len(size_t to_encode_len, size_t *encoded_len); + +/* + * Base 64 encodes the contents of to_encode and stores the result in output. + */ +AWS_COMMON_API +int aws_base64_encode(const struct aws_byte_cursor *AWS_RESTRICT to_encode, struct aws_byte_buf *AWS_RESTRICT output); + +/* + * Computes the length necessary to store the output of aws_base64_decode call. + * returns -1 on failure, and 0 on success. decoded_len will be set on success. + */ +AWS_COMMON_API +int aws_base64_compute_decoded_len(const struct aws_byte_cursor *AWS_RESTRICT to_decode, size_t *decoded_len); + +/* + * Base 64 decodes the contents of to_decode and stores the result in output. + */ +AWS_COMMON_API +int aws_base64_decode(const struct aws_byte_cursor *AWS_RESTRICT to_decode, struct aws_byte_buf *AWS_RESTRICT output); + +/* Add a 64 bit unsigned integer to the buffer, ensuring network - byte order + * Assumes the buffer size is at least 8 bytes. + */ AWS_STATIC_IMPL void aws_write_u64(uint64_t value, uint8_t *buffer); - -/* - * Extracts a 64 bit unsigned integer from buffer. Ensures conversion from - * network byte order to host byte order. Assumes buffer size is at least 8 - * bytes. - */ + +/* + * Extracts a 64 bit unsigned integer from buffer. Ensures conversion from + * network byte order to host byte order. Assumes buffer size is at least 8 + * bytes. + */ AWS_STATIC_IMPL uint64_t aws_read_u64(const uint8_t *buffer); - -/* Add a 32 bit unsigned integer to the buffer, ensuring network - byte order - * Assumes the buffer size is at least 4 bytes. - */ + +/* Add a 32 bit unsigned integer to the buffer, ensuring network - byte order + * Assumes the buffer size is at least 4 bytes. + */ AWS_STATIC_IMPL void aws_write_u32(uint32_t value, uint8_t *buffer); - -/* - * Extracts a 32 bit unsigned integer from buffer. Ensures conversion from - * network byte order to host byte order. Assumes the buffer size is at least 4 - * bytes. - */ + +/* + * Extracts a 32 bit unsigned integer from buffer. Ensures conversion from + * network byte order to host byte order. Assumes the buffer size is at least 4 + * bytes. + */ AWS_STATIC_IMPL uint32_t aws_read_u32(const uint8_t *buffer); - -/* Add a 24 bit unsigned integer to the buffer, ensuring network - byte order - * return the new position in the buffer for the next operation. - * Note, since this uses uint32_t for storage, the 3 least significant bytes - * will be used. Assumes buffer is at least 3 bytes long. - */ + +/* Add a 24 bit unsigned integer to the buffer, ensuring network - byte order + * return the new position in the buffer for the next operation. + * Note, since this uses uint32_t for storage, the 3 least significant bytes + * will be used. Assumes buffer is at least 3 bytes long. + */ AWS_STATIC_IMPL void aws_write_u24(uint32_t value, uint8_t *buffer); -/* - * Extracts a 24 bit unsigned integer from buffer. Ensures conversion from - * network byte order to host byte order. Assumes buffer is at least 3 bytes - * long. - */ +/* + * Extracts a 24 bit unsigned integer from buffer. Ensures conversion from + * network byte order to host byte order. Assumes buffer is at least 3 bytes + * long. + */ AWS_STATIC_IMPL uint32_t aws_read_u24(const uint8_t *buffer); - -/* Add a 16 bit unsigned integer to the buffer, ensuring network-byte order - * return the new position in the buffer for the next operation. - * Assumes buffer is at least 2 bytes long. - */ + +/* Add a 16 bit unsigned integer to the buffer, ensuring network-byte order + * return the new position in the buffer for the next operation. + * Assumes buffer is at least 2 bytes long. + */ AWS_STATIC_IMPL void aws_write_u16(uint16_t value, uint8_t *buffer); -/* - * Extracts a 16 bit unsigned integer from buffer. Ensures conversion from - * network byte order to host byte order. Assumes buffer is at least 2 bytes - * long. - */ +/* + * Extracts a 16 bit unsigned integer from buffer. Ensures conversion from + * network byte order to host byte order. Assumes buffer is at least 2 bytes + * long. + */ AWS_STATIC_IMPL uint16_t aws_read_u16(const uint8_t *buffer); - + enum aws_text_encoding { AWS_TEXT_UNKNOWN, AWS_TEXT_UTF8, @@ -137,7 +137,7 @@ enum aws_text_encoding { AWS_TEXT_UTF32, AWS_TEXT_ASCII, }; - + /* Checks the BOM in the buffer to see if encoding can be determined. If there is no BOM or * it is unrecognizable, then AWS_TEXT_UNKNOWN will be returned. */ @@ -154,4 +154,4 @@ AWS_STATIC_IMPL bool aws_text_is_utf8(const uint8_t *bytes, size_t size); AWS_EXTERN_C_END -#endif /* AWS_COMMON_ENCODING_H */ +#endif /* AWS_COMMON_ENCODING_H */ diff --git a/contrib/restricted/aws/aws-c-common/include/aws/common/environment.h b/contrib/restricted/aws/aws-c-common/include/aws/common/environment.h index 154b9faa71..c11bac3ad0 100644 --- a/contrib/restricted/aws/aws-c-common/include/aws/common/environment.h +++ b/contrib/restricted/aws/aws-c-common/include/aws/common/environment.h @@ -1,46 +1,46 @@ -#ifndef AWS_COMMON_ENVIRONMENT_H -#define AWS_COMMON_ENVIRONMENT_H - +#ifndef AWS_COMMON_ENVIRONMENT_H +#define AWS_COMMON_ENVIRONMENT_H + /** * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. - */ - -#include <aws/common/common.h> - -struct aws_string; - -/* - * Simple shims to the appropriate platform calls for environment variable manipulation. - * - * Not thread safe to use set/unset unsynced with get. Set/unset only used in unit tests. - */ -AWS_EXTERN_C_BEGIN - -/* - * Get the value of an environment variable. If the variable is not set, the output string will be set to NULL. - * Not thread-safe - */ -AWS_COMMON_API -int aws_get_environment_value( - struct aws_allocator *allocator, - const struct aws_string *variable_name, - struct aws_string **value_out); - -/* - * Set the value of an environment variable. On Windows, setting a variable to the empty string will actually unset it. - * Not thread-safe - */ -AWS_COMMON_API -int aws_set_environment_value(const struct aws_string *variable_name, const struct aws_string *value); - -/* - * Unset an environment variable. - * Not thread-safe - */ -AWS_COMMON_API -int aws_unset_environment_value(const struct aws_string *variable_name); - -AWS_EXTERN_C_END - -#endif /* AWS_COMMON_ENVIRONMENT_H */ + */ + +#include <aws/common/common.h> + +struct aws_string; + +/* + * Simple shims to the appropriate platform calls for environment variable manipulation. + * + * Not thread safe to use set/unset unsynced with get. Set/unset only used in unit tests. + */ +AWS_EXTERN_C_BEGIN + +/* + * Get the value of an environment variable. If the variable is not set, the output string will be set to NULL. + * Not thread-safe + */ +AWS_COMMON_API +int aws_get_environment_value( + struct aws_allocator *allocator, + const struct aws_string *variable_name, + struct aws_string **value_out); + +/* + * Set the value of an environment variable. On Windows, setting a variable to the empty string will actually unset it. + * Not thread-safe + */ +AWS_COMMON_API +int aws_set_environment_value(const struct aws_string *variable_name, const struct aws_string *value); + +/* + * Unset an environment variable. + * Not thread-safe + */ +AWS_COMMON_API +int aws_unset_environment_value(const struct aws_string *variable_name); + +AWS_EXTERN_C_END + +#endif /* AWS_COMMON_ENVIRONMENT_H */ diff --git a/contrib/restricted/aws/aws-c-common/include/aws/common/error.h b/contrib/restricted/aws/aws-c-common/include/aws/common/error.h index 7be3e616e9..200de33146 100644 --- a/contrib/restricted/aws/aws-c-common/include/aws/common/error.h +++ b/contrib/restricted/aws/aws-c-common/include/aws/common/error.h @@ -1,17 +1,17 @@ -#ifndef AWS_COMMON_ERROR_H -#define AWS_COMMON_ERROR_H - +#ifndef AWS_COMMON_ERROR_H +#define AWS_COMMON_ERROR_H + /** * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. - */ - + */ + #include <aws/common/assert.h> -#include <aws/common/exports.h> +#include <aws/common/exports.h> #include <aws/common/macros.h> #include <aws/common/package.h> #include <aws/common/stdint.h> - + #define AWS_OP_SUCCESS (0) #define AWS_OP_ERR (-1) @@ -21,110 +21,110 @@ #define AWS_ERROR_ENUM_BEGIN_RANGE(x) ((x)*AWS_ERROR_ENUM_STRIDE) #define AWS_ERROR_ENUM_END_RANGE(x) (((x) + 1) * AWS_ERROR_ENUM_STRIDE - 1) -struct aws_error_info { - int error_code; - const char *literal_name; - const char *error_str; - const char *lib_name; - const char *formatted_name; -}; - -struct aws_error_info_list { - const struct aws_error_info *error_list; - uint16_t count; -}; - -#define AWS_DEFINE_ERROR_INFO(C, ES, LN) \ - { \ - .literal_name = #C, .error_code = (C), .error_str = (ES), .lib_name = (LN), \ - .formatted_name = LN ": " #C ", " ES, \ - } - -typedef void(aws_error_handler_fn)(int err, void *ctx); - -AWS_EXTERN_C_BEGIN - -/* - * Returns the latest error code on the current thread, or 0 if none have - * occurred. - */ -AWS_COMMON_API -int aws_last_error(void); - -/* - * Returns the error str corresponding to `err`. - */ -AWS_COMMON_API -const char *aws_error_str(int err); - -/* - * Returns the enum name corresponding to `err`. - */ -AWS_COMMON_API -const char *aws_error_name(int err); - -/* - * Returns the error lib name corresponding to `err`. - */ -AWS_COMMON_API -const char *aws_error_lib_name(int err); - -/* - * Returns libname concatenated with error string. - */ -AWS_COMMON_API -const char *aws_error_debug_str(int err); - -/* - * Internal implementation detail. - */ -AWS_COMMON_API -void aws_raise_error_private(int err); - -/* - * Raises `err` to the installed callbacks, and sets the thread's error. - */ -AWS_STATIC_IMPL +struct aws_error_info { + int error_code; + const char *literal_name; + const char *error_str; + const char *lib_name; + const char *formatted_name; +}; + +struct aws_error_info_list { + const struct aws_error_info *error_list; + uint16_t count; +}; + +#define AWS_DEFINE_ERROR_INFO(C, ES, LN) \ + { \ + .literal_name = #C, .error_code = (C), .error_str = (ES), .lib_name = (LN), \ + .formatted_name = LN ": " #C ", " ES, \ + } + +typedef void(aws_error_handler_fn)(int err, void *ctx); + +AWS_EXTERN_C_BEGIN + +/* + * Returns the latest error code on the current thread, or 0 if none have + * occurred. + */ +AWS_COMMON_API +int aws_last_error(void); + +/* + * Returns the error str corresponding to `err`. + */ +AWS_COMMON_API +const char *aws_error_str(int err); + +/* + * Returns the enum name corresponding to `err`. + */ +AWS_COMMON_API +const char *aws_error_name(int err); + +/* + * Returns the error lib name corresponding to `err`. + */ +AWS_COMMON_API +const char *aws_error_lib_name(int err); + +/* + * Returns libname concatenated with error string. + */ +AWS_COMMON_API +const char *aws_error_debug_str(int err); + +/* + * Internal implementation detail. + */ +AWS_COMMON_API +void aws_raise_error_private(int err); + +/* + * Raises `err` to the installed callbacks, and sets the thread's error. + */ +AWS_STATIC_IMPL int aws_raise_error(int err); - -/* - * Resets the `err` back to defaults - */ -AWS_COMMON_API -void aws_reset_error(void); -/* - * Sets `err` to the latest error. Does not invoke callbacks. - */ -AWS_COMMON_API -void aws_restore_error(int err); - -/* - * Sets an application wide error handler function. This will be overridden by - * the thread local handler. The previous handler is returned, this can be used - * for restoring an error handler if it needs to be overridden temporarily. - * Setting this to NULL will turn off this error callback after it has been - * enabled. - */ -AWS_COMMON_API -aws_error_handler_fn *aws_set_global_error_handler_fn(aws_error_handler_fn *handler, void *ctx); - -/* - * Sets a thread-local error handler function. This will override the global - * handler. The previous handler is returned, this can be used for restoring an - * error handler if it needs to be overridden temporarily. Setting this to NULL - * will turn off this error callback after it has been enabled. - */ -AWS_COMMON_API -aws_error_handler_fn *aws_set_thread_local_error_handler_fn(aws_error_handler_fn *handler, void *ctx); - -/** TODO: this needs to be a private function (wait till we have the cmake story - * better before moving it though). It should be external for the purpose of - * other libs we own, but customers should not be able to hit it without going - * out of their way to do so. - */ -AWS_COMMON_API -void aws_register_error_info(const struct aws_error_info_list *error_info); - + +/* + * Resets the `err` back to defaults + */ +AWS_COMMON_API +void aws_reset_error(void); +/* + * Sets `err` to the latest error. Does not invoke callbacks. + */ +AWS_COMMON_API +void aws_restore_error(int err); + +/* + * Sets an application wide error handler function. This will be overridden by + * the thread local handler. The previous handler is returned, this can be used + * for restoring an error handler if it needs to be overridden temporarily. + * Setting this to NULL will turn off this error callback after it has been + * enabled. + */ +AWS_COMMON_API +aws_error_handler_fn *aws_set_global_error_handler_fn(aws_error_handler_fn *handler, void *ctx); + +/* + * Sets a thread-local error handler function. This will override the global + * handler. The previous handler is returned, this can be used for restoring an + * error handler if it needs to be overridden temporarily. Setting this to NULL + * will turn off this error callback after it has been enabled. + */ +AWS_COMMON_API +aws_error_handler_fn *aws_set_thread_local_error_handler_fn(aws_error_handler_fn *handler, void *ctx); + +/** TODO: this needs to be a private function (wait till we have the cmake story + * better before moving it though). It should be external for the purpose of + * other libs we own, but customers should not be able to hit it without going + * out of their way to do so. + */ +AWS_COMMON_API +void aws_register_error_info(const struct aws_error_info_list *error_info); + AWS_COMMON_API void aws_unregister_error_info(const struct aws_error_info_list *error_info); @@ -138,8 +138,8 @@ int aws_translate_and_raise_io_error(int error_no); # include <aws/common/error.inl> #endif /* AWS_NO_STATIC_IMPL */ -AWS_EXTERN_C_END - +AWS_EXTERN_C_END + enum aws_common_error { AWS_ERROR_SUCCESS = AWS_ERROR_ENUM_BEGIN_RANGE(AWS_C_COMMON_PACKAGE_ID), AWS_ERROR_OOM, @@ -194,4 +194,4 @@ enum aws_common_error { AWS_ERROR_END_COMMON_RANGE = AWS_ERROR_ENUM_END_RANGE(AWS_C_COMMON_PACKAGE_ID) }; -#endif /* AWS_COMMON_ERROR_H */ +#endif /* AWS_COMMON_ERROR_H */ diff --git a/contrib/restricted/aws/aws-c-common/include/aws/common/exports.h b/contrib/restricted/aws/aws-c-common/include/aws/common/exports.h index ba07e743ce..017a5f04ef 100644 --- a/contrib/restricted/aws/aws-c-common/include/aws/common/exports.h +++ b/contrib/restricted/aws/aws-c-common/include/aws/common/exports.h @@ -1,30 +1,30 @@ -#ifndef AWS_COMMON_EXPORTS_H -#define AWS_COMMON_EXPORTS_H +#ifndef AWS_COMMON_EXPORTS_H +#define AWS_COMMON_EXPORTS_H /** * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. - */ + */ #if defined(AWS_C_RT_USE_WINDOWS_DLL_SEMANTICS) || defined(_WIN32) -# ifdef AWS_COMMON_USE_IMPORT_EXPORT -# ifdef AWS_COMMON_EXPORTS -# define AWS_COMMON_API __declspec(dllexport) -# else -# define AWS_COMMON_API __declspec(dllimport) -# endif /* AWS_COMMON_EXPORTS */ -# else -# define AWS_COMMON_API -# endif /* AWS_COMMON_USE_IMPORT_EXPORT */ - +# ifdef AWS_COMMON_USE_IMPORT_EXPORT +# ifdef AWS_COMMON_EXPORTS +# define AWS_COMMON_API __declspec(dllexport) +# else +# define AWS_COMMON_API __declspec(dllimport) +# endif /* AWS_COMMON_EXPORTS */ +# else +# define AWS_COMMON_API +# endif /* AWS_COMMON_USE_IMPORT_EXPORT */ + #else /* defined (AWS_C_RT_USE_WINDOWS_DLL_SEMANTICS) || defined (_WIN32) */ - -# if ((__GNUC__ >= 4) || defined(__clang__)) && defined(AWS_COMMON_USE_IMPORT_EXPORT) && defined(AWS_COMMON_EXPORTS) -# define AWS_COMMON_API __attribute__((visibility("default"))) -# else -# define AWS_COMMON_API -# endif /* __GNUC__ >= 4 || defined(__clang__) */ - + +# if ((__GNUC__ >= 4) || defined(__clang__)) && defined(AWS_COMMON_USE_IMPORT_EXPORT) && defined(AWS_COMMON_EXPORTS) +# define AWS_COMMON_API __attribute__((visibility("default"))) +# else +# define AWS_COMMON_API +# endif /* __GNUC__ >= 4 || defined(__clang__) */ + #endif /* defined (AWS_C_RT_USE_WINDOWS_DLL_SEMANTICS) || defined (_WIN32) */ - + #ifdef AWS_NO_STATIC_IMPL # define AWS_STATIC_IMPL AWS_COMMON_API #endif @@ -37,4 +37,4 @@ # define AWS_STATIC_IMPL static inline #endif -#endif /* AWS_COMMON_EXPORTS_H */ +#endif /* AWS_COMMON_EXPORTS_H */ diff --git a/contrib/restricted/aws/aws-c-common/include/aws/common/hash_table.h b/contrib/restricted/aws/aws-c-common/include/aws/common/hash_table.h index 648266266b..c4ac55cb64 100644 --- a/contrib/restricted/aws/aws-c-common/include/aws/common/hash_table.h +++ b/contrib/restricted/aws/aws-c-common/include/aws/common/hash_table.h @@ -1,298 +1,298 @@ -#ifndef AWS_COMMON_HASH_TABLE_H -#define AWS_COMMON_HASH_TABLE_H - +#ifndef AWS_COMMON_HASH_TABLE_H +#define AWS_COMMON_HASH_TABLE_H + /** * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. - */ - -#include <aws/common/common.h> - -#include <stddef.h> - -#define AWS_COMMON_HASH_TABLE_ITER_CONTINUE (1 << 0) -#define AWS_COMMON_HASH_TABLE_ITER_DELETE (1 << 1) - -/** - * Hash table data structure. This module provides an automatically resizing - * hash table implementation for general purpose use. The hash table stores a - * mapping between void * keys and values; it is expected that in most cases, - * these will point to a structure elsewhere in the heap, instead of inlining a - * key or value into the hash table element itself. - * - * Currently, this hash table implements a variant of robin hood hashing, but - * we do not guarantee that this won't change in the future. - * - * Associated with each hash function are four callbacks: - * - * hash_fn - A hash function from the keys to a uint64_t. It is critical that - * the hash function for a key does not change while the key is in the hash - * table; violating this results in undefined behavior. Collisions are - * tolerated, though naturally with reduced performance. - * - * equals_fn - An equality comparison function. This function must be - * reflexive and consistent with hash_fn. - * - * destroy_key_fn, destroy_value_fn - Optional callbacks invoked when the - * table is cleared or cleaned up and at the caller's option when an element - * is removed from the table. Either or both may be set to NULL, which - * has the same effect as a no-op destroy function. - * - * This datastructure can be safely moved between threads, subject to the - * requirements of the underlying allocator. It is also safe to invoke - * non-mutating operations on the hash table from multiple threads. A suitable - * memory barrier must be used when transitioning from single-threaded mutating - * usage to multithreaded usage. - */ -struct hash_table_state; /* Opaque pointer */ -struct aws_hash_table { - struct hash_table_state *p_impl; -}; - -/** - * Represents an element in the hash table. Various operations on the hash - * table may provide pointers to elements stored within the hash table; - * generally, calling code may alter value, but must not alter key (or any - * information used to compute key's hash code). - * - * Pointers to elements within the hash are invalidated whenever an operation - * which may change the number of elements in the hash is invoked (i.e. put, - * delete, clear, and clean_up), regardless of whether the number of elements - * actually changes. - */ -struct aws_hash_element { - const void *key; - void *value; -}; - -enum aws_hash_iter_status { - AWS_HASH_ITER_STATUS_DONE, - AWS_HASH_ITER_STATUS_DELETE_CALLED, - AWS_HASH_ITER_STATUS_READY_FOR_USE, -}; - -struct aws_hash_iter { - const struct aws_hash_table *map; - struct aws_hash_element element; - size_t slot; - size_t limit; - enum aws_hash_iter_status status; - /* - * Reserving extra fields for binary compatibility with future expansion of - * iterator in case hash table implementation changes. - */ - int unused_0; - void *unused_1; - void *unused_2; -}; - -/** - * Prototype for a key hashing function pointer. - */ -typedef uint64_t(aws_hash_fn)(const void *key); - -/** - * Prototype for a hash table equality check function pointer. - * - * This type is usually used for a function that compares two hash table - * keys, but note that the same type is used for a function that compares - * two hash table values in aws_hash_table_eq. - * - * Equality functions used in a hash table must be reflexive (i.e., a == b if - * and only if b == a), and must be consistent with the hash function in use. - */ -typedef bool(aws_hash_callback_eq_fn)(const void *a, const void *b); - -/** - * Prototype for a hash table key or value destructor function pointer. - * - * This function is used to destroy elements in the hash table when the - * table is cleared or cleaned up. - * - * Note that functions which remove individual elements from the hash - * table provide options of whether or not to invoke the destructors - * on the key and value of a removed element. - */ -typedef void(aws_hash_callback_destroy_fn)(void *key_or_value); - -AWS_EXTERN_C_BEGIN - -/** - * Initializes a hash map with initial capacity for 'size' elements - * without resizing. Uses hash_fn to compute the hash of each element. - * equals_fn to compute equality of two keys. Whenever an element is - * removed without being returned, destroy_key_fn is run on the pointer - * to the key and destroy_value_fn is run on the pointer to the value. - * Either or both may be NULL if a callback is not desired in this case. - */ -AWS_COMMON_API -int aws_hash_table_init( - struct aws_hash_table *map, - struct aws_allocator *alloc, - size_t size, - aws_hash_fn *hash_fn, - aws_hash_callback_eq_fn *equals_fn, - aws_hash_callback_destroy_fn *destroy_key_fn, - aws_hash_callback_destroy_fn *destroy_value_fn); - -/** - * Deletes every element from map and frees all associated memory. - * destroy_fn will be called for each element. aws_hash_table_init - * must be called before reusing the hash table. - * - * This method is idempotent. - */ -AWS_COMMON_API -void aws_hash_table_clean_up(struct aws_hash_table *map); - -/** - * Safely swaps two hash tables. Note that we swap the entirety of the hash - * table, including which allocator is associated. - * - * Neither hash table is required to be initialized; if one or both is - * uninitialized, then the uninitialized state is also swapped. - */ -AWS_COMMON_API -void aws_hash_table_swap(struct aws_hash_table *AWS_RESTRICT a, struct aws_hash_table *AWS_RESTRICT b); - -/** - * Moves the hash table in 'from' to 'to'. After this move, 'from' will - * be identical to the state of the original 'to' hash table, and 'to' - * will be in the same state as if it had been passed to aws_hash_table_clean_up - * (that is, it will have no memory allocated, and it will be safe to - * either discard it or call aws_hash_table_clean_up again). - * - * Note that 'to' will not be cleaned up. You should make sure that 'to' - * is either uninitialized or cleaned up before moving a hashtable into - * it. - */ -AWS_COMMON_API -void aws_hash_table_move(struct aws_hash_table *AWS_RESTRICT to, struct aws_hash_table *AWS_RESTRICT from); - -/** - * Returns the current number of entries in the table. - */ -AWS_COMMON_API -size_t aws_hash_table_get_entry_count(const struct aws_hash_table *map); - -/** - * Returns an iterator to be used for iterating through a hash table. - * Iterator will already point to the first element of the table it finds, - * which can be accessed as iter.element. - * - * This function cannot fail, but if there are no elements in the table, - * the returned iterator will return true for aws_hash_iter_done(&iter). - */ -AWS_COMMON_API -struct aws_hash_iter aws_hash_iter_begin(const struct aws_hash_table *map); - -/** - * Returns true if iterator is done iterating through table, false otherwise. - * If this is true, the iterator will not include an element of the table. - */ -AWS_COMMON_API -bool aws_hash_iter_done(const struct aws_hash_iter *iter); - -/** - * Updates iterator so that it points to next element of hash table. - * - * This and the two previous functions are designed to be used together with - * the following idiom: - * - * for (struct aws_hash_iter iter = aws_hash_iter_begin(&map); - * !aws_hash_iter_done(&iter); aws_hash_iter_next(&iter)) { - * const key_type key = *(const key_type *)iter.element.key; - * value_type value = *(value_type *)iter.element.value; - * // etc. - * } - * - * Note that calling this on an iter which is "done" is idempotent: - * i.e. it will return another iter which is "done". - */ -AWS_COMMON_API -void aws_hash_iter_next(struct aws_hash_iter *iter); - -/** - * Deletes the element currently pointed-to by the hash iterator. - * After calling this method, the element member of the iterator - * should not be accessed until the next call to aws_hash_iter_next. - * - * @param destroy_contents If true, the destructors for the key and value - * will be called. - */ -AWS_COMMON_API -void aws_hash_iter_delete(struct aws_hash_iter *iter, bool destroy_contents); - -/** - * Attempts to locate an element at key. If the element is found, a - * pointer to the value is placed in *p_elem; if it is not found, - * *pElem is set to NULL. Either way, AWS_OP_SUCCESS is returned. - * - * This method does not change the state of the hash table. Therefore, it - * is safe to call _find from multiple threads on the same hash table, - * provided no mutating operations happen in parallel. - * - * Calling code may update the value in the hash table by modifying **pElem - * after a successful find. However, this pointer is not guaranteed to - * remain usable after a subsequent call to _put, _delete, _clear, or - * _clean_up. - */ - -AWS_COMMON_API -int aws_hash_table_find(const struct aws_hash_table *map, const void *key, struct aws_hash_element **p_elem); - -/** - * Attempts to locate an element at key. If no such element was found, - * creates a new element, with value initialized to NULL. In either case, a - * pointer to the element is placed in *p_elem. - * - * If was_created is non-NULL, *was_created is set to 0 if an existing - * element was found, or 1 is a new element was created. - * - * Returns AWS_OP_SUCCESS if an item was found or created. - * Raises AWS_ERROR_OOM if hash table expansion was required and memory - * allocation failed. - */ -AWS_COMMON_API -int aws_hash_table_create( - struct aws_hash_table *map, - const void *key, - struct aws_hash_element **p_elem, - int *was_created); - -/** - * Inserts a new element at key, with the given value. If another element - * exists at that key, the old element will be overwritten; both old key and - * value objects will be destroyed. - * - * If was_created is non-NULL, *was_created is set to 0 if an existing - * element was found, or 1 is a new element was created. - * - * Returns AWS_OP_SUCCESS if an item was found or created. - * Raises AWS_ERROR_OOM if hash table expansion was required and memory - */ -AWS_COMMON_API -int aws_hash_table_put(struct aws_hash_table *map, const void *key, void *value, int *was_created); - -/** - * Removes element at key. Always returns AWS_OP_SUCCESS. - * - * If pValue is non-NULL, the existing value (if any) is moved into - * (*value) before removing from the table, and destroy_fn is _not_ - * invoked. If pValue is NULL, then (if the element existed) destroy_fn - * will be invoked on the element being removed. - * - * If was_present is non-NULL, it is set to 0 if the element was - * not present, or 1 if it was present (and is now removed). - */ -AWS_COMMON_API -int aws_hash_table_remove( - struct aws_hash_table *map, - const void *key, - struct aws_hash_element *p_value, - int *was_present); - -/** + */ + +#include <aws/common/common.h> + +#include <stddef.h> + +#define AWS_COMMON_HASH_TABLE_ITER_CONTINUE (1 << 0) +#define AWS_COMMON_HASH_TABLE_ITER_DELETE (1 << 1) + +/** + * Hash table data structure. This module provides an automatically resizing + * hash table implementation for general purpose use. The hash table stores a + * mapping between void * keys and values; it is expected that in most cases, + * these will point to a structure elsewhere in the heap, instead of inlining a + * key or value into the hash table element itself. + * + * Currently, this hash table implements a variant of robin hood hashing, but + * we do not guarantee that this won't change in the future. + * + * Associated with each hash function are four callbacks: + * + * hash_fn - A hash function from the keys to a uint64_t. It is critical that + * the hash function for a key does not change while the key is in the hash + * table; violating this results in undefined behavior. Collisions are + * tolerated, though naturally with reduced performance. + * + * equals_fn - An equality comparison function. This function must be + * reflexive and consistent with hash_fn. + * + * destroy_key_fn, destroy_value_fn - Optional callbacks invoked when the + * table is cleared or cleaned up and at the caller's option when an element + * is removed from the table. Either or both may be set to NULL, which + * has the same effect as a no-op destroy function. + * + * This datastructure can be safely moved between threads, subject to the + * requirements of the underlying allocator. It is also safe to invoke + * non-mutating operations on the hash table from multiple threads. A suitable + * memory barrier must be used when transitioning from single-threaded mutating + * usage to multithreaded usage. + */ +struct hash_table_state; /* Opaque pointer */ +struct aws_hash_table { + struct hash_table_state *p_impl; +}; + +/** + * Represents an element in the hash table. Various operations on the hash + * table may provide pointers to elements stored within the hash table; + * generally, calling code may alter value, but must not alter key (or any + * information used to compute key's hash code). + * + * Pointers to elements within the hash are invalidated whenever an operation + * which may change the number of elements in the hash is invoked (i.e. put, + * delete, clear, and clean_up), regardless of whether the number of elements + * actually changes. + */ +struct aws_hash_element { + const void *key; + void *value; +}; + +enum aws_hash_iter_status { + AWS_HASH_ITER_STATUS_DONE, + AWS_HASH_ITER_STATUS_DELETE_CALLED, + AWS_HASH_ITER_STATUS_READY_FOR_USE, +}; + +struct aws_hash_iter { + const struct aws_hash_table *map; + struct aws_hash_element element; + size_t slot; + size_t limit; + enum aws_hash_iter_status status; + /* + * Reserving extra fields for binary compatibility with future expansion of + * iterator in case hash table implementation changes. + */ + int unused_0; + void *unused_1; + void *unused_2; +}; + +/** + * Prototype for a key hashing function pointer. + */ +typedef uint64_t(aws_hash_fn)(const void *key); + +/** + * Prototype for a hash table equality check function pointer. + * + * This type is usually used for a function that compares two hash table + * keys, but note that the same type is used for a function that compares + * two hash table values in aws_hash_table_eq. + * + * Equality functions used in a hash table must be reflexive (i.e., a == b if + * and only if b == a), and must be consistent with the hash function in use. + */ +typedef bool(aws_hash_callback_eq_fn)(const void *a, const void *b); + +/** + * Prototype for a hash table key or value destructor function pointer. + * + * This function is used to destroy elements in the hash table when the + * table is cleared or cleaned up. + * + * Note that functions which remove individual elements from the hash + * table provide options of whether or not to invoke the destructors + * on the key and value of a removed element. + */ +typedef void(aws_hash_callback_destroy_fn)(void *key_or_value); + +AWS_EXTERN_C_BEGIN + +/** + * Initializes a hash map with initial capacity for 'size' elements + * without resizing. Uses hash_fn to compute the hash of each element. + * equals_fn to compute equality of two keys. Whenever an element is + * removed without being returned, destroy_key_fn is run on the pointer + * to the key and destroy_value_fn is run on the pointer to the value. + * Either or both may be NULL if a callback is not desired in this case. + */ +AWS_COMMON_API +int aws_hash_table_init( + struct aws_hash_table *map, + struct aws_allocator *alloc, + size_t size, + aws_hash_fn *hash_fn, + aws_hash_callback_eq_fn *equals_fn, + aws_hash_callback_destroy_fn *destroy_key_fn, + aws_hash_callback_destroy_fn *destroy_value_fn); + +/** + * Deletes every element from map and frees all associated memory. + * destroy_fn will be called for each element. aws_hash_table_init + * must be called before reusing the hash table. + * + * This method is idempotent. + */ +AWS_COMMON_API +void aws_hash_table_clean_up(struct aws_hash_table *map); + +/** + * Safely swaps two hash tables. Note that we swap the entirety of the hash + * table, including which allocator is associated. + * + * Neither hash table is required to be initialized; if one or both is + * uninitialized, then the uninitialized state is also swapped. + */ +AWS_COMMON_API +void aws_hash_table_swap(struct aws_hash_table *AWS_RESTRICT a, struct aws_hash_table *AWS_RESTRICT b); + +/** + * Moves the hash table in 'from' to 'to'. After this move, 'from' will + * be identical to the state of the original 'to' hash table, and 'to' + * will be in the same state as if it had been passed to aws_hash_table_clean_up + * (that is, it will have no memory allocated, and it will be safe to + * either discard it or call aws_hash_table_clean_up again). + * + * Note that 'to' will not be cleaned up. You should make sure that 'to' + * is either uninitialized or cleaned up before moving a hashtable into + * it. + */ +AWS_COMMON_API +void aws_hash_table_move(struct aws_hash_table *AWS_RESTRICT to, struct aws_hash_table *AWS_RESTRICT from); + +/** + * Returns the current number of entries in the table. + */ +AWS_COMMON_API +size_t aws_hash_table_get_entry_count(const struct aws_hash_table *map); + +/** + * Returns an iterator to be used for iterating through a hash table. + * Iterator will already point to the first element of the table it finds, + * which can be accessed as iter.element. + * + * This function cannot fail, but if there are no elements in the table, + * the returned iterator will return true for aws_hash_iter_done(&iter). + */ +AWS_COMMON_API +struct aws_hash_iter aws_hash_iter_begin(const struct aws_hash_table *map); + +/** + * Returns true if iterator is done iterating through table, false otherwise. + * If this is true, the iterator will not include an element of the table. + */ +AWS_COMMON_API +bool aws_hash_iter_done(const struct aws_hash_iter *iter); + +/** + * Updates iterator so that it points to next element of hash table. + * + * This and the two previous functions are designed to be used together with + * the following idiom: + * + * for (struct aws_hash_iter iter = aws_hash_iter_begin(&map); + * !aws_hash_iter_done(&iter); aws_hash_iter_next(&iter)) { + * const key_type key = *(const key_type *)iter.element.key; + * value_type value = *(value_type *)iter.element.value; + * // etc. + * } + * + * Note that calling this on an iter which is "done" is idempotent: + * i.e. it will return another iter which is "done". + */ +AWS_COMMON_API +void aws_hash_iter_next(struct aws_hash_iter *iter); + +/** + * Deletes the element currently pointed-to by the hash iterator. + * After calling this method, the element member of the iterator + * should not be accessed until the next call to aws_hash_iter_next. + * + * @param destroy_contents If true, the destructors for the key and value + * will be called. + */ +AWS_COMMON_API +void aws_hash_iter_delete(struct aws_hash_iter *iter, bool destroy_contents); + +/** + * Attempts to locate an element at key. If the element is found, a + * pointer to the value is placed in *p_elem; if it is not found, + * *pElem is set to NULL. Either way, AWS_OP_SUCCESS is returned. + * + * This method does not change the state of the hash table. Therefore, it + * is safe to call _find from multiple threads on the same hash table, + * provided no mutating operations happen in parallel. + * + * Calling code may update the value in the hash table by modifying **pElem + * after a successful find. However, this pointer is not guaranteed to + * remain usable after a subsequent call to _put, _delete, _clear, or + * _clean_up. + */ + +AWS_COMMON_API +int aws_hash_table_find(const struct aws_hash_table *map, const void *key, struct aws_hash_element **p_elem); + +/** + * Attempts to locate an element at key. If no such element was found, + * creates a new element, with value initialized to NULL. In either case, a + * pointer to the element is placed in *p_elem. + * + * If was_created is non-NULL, *was_created is set to 0 if an existing + * element was found, or 1 is a new element was created. + * + * Returns AWS_OP_SUCCESS if an item was found or created. + * Raises AWS_ERROR_OOM if hash table expansion was required and memory + * allocation failed. + */ +AWS_COMMON_API +int aws_hash_table_create( + struct aws_hash_table *map, + const void *key, + struct aws_hash_element **p_elem, + int *was_created); + +/** + * Inserts a new element at key, with the given value. If another element + * exists at that key, the old element will be overwritten; both old key and + * value objects will be destroyed. + * + * If was_created is non-NULL, *was_created is set to 0 if an existing + * element was found, or 1 is a new element was created. + * + * Returns AWS_OP_SUCCESS if an item was found or created. + * Raises AWS_ERROR_OOM if hash table expansion was required and memory + */ +AWS_COMMON_API +int aws_hash_table_put(struct aws_hash_table *map, const void *key, void *value, int *was_created); + +/** + * Removes element at key. Always returns AWS_OP_SUCCESS. + * + * If pValue is non-NULL, the existing value (if any) is moved into + * (*value) before removing from the table, and destroy_fn is _not_ + * invoked. If pValue is NULL, then (if the element existed) destroy_fn + * will be invoked on the element being removed. + * + * If was_present is non-NULL, it is set to 0 if the element was + * not present, or 1 if it was present (and is now removed). + */ +AWS_COMMON_API +int aws_hash_table_remove( + struct aws_hash_table *map, + const void *key, + struct aws_hash_element *p_value, + int *was_present); + +/** * Removes element already known (typically by find()). * * p_value should point to a valid element returned by create() or find(). @@ -304,113 +304,113 @@ AWS_COMMON_API int aws_hash_table_remove_element(struct aws_hash_table *map, struct aws_hash_element *p_value); /** - * Iterates through every element in the map and invokes the callback on - * that item. Iteration is performed in an arbitrary, implementation-defined - * order, and is not guaranteed to be consistent across invocations. - * - * The callback may change the value associated with the key by overwriting - * the value pointed-to by value. In this case, the on_element_removed - * callback will not be invoked, unless the callback invokes - * AWS_COMMON_HASH_TABLE_ITER_DELETE (in which case the on_element_removed - * is given the updated value). - * - * The callback must return a bitmask of zero or more of the following values - * ORed together: - * - * # AWS_COMMON_HASH_TABLE_ITER_CONTINUE - Continues iteration to the next - * element (if not set, iteration stops) - * # AWS_COMMON_HASH_TABLE_ITER_DELETE - Deletes the current value and - * continues iteration. destroy_fn will NOT be invoked. - * - * Invoking any method which may change the contents of the hashtable - * during iteration results in undefined behavior. However, you may safely - * invoke non-mutating operations during an iteration. - * - * This operation is mutating only if AWS_COMMON_HASH_TABLE_ITER_DELETE - * is returned at some point during iteration. Otherwise, it is non-mutating - * and is safe to invoke in parallel with other non-mutating operations. - */ - -AWS_COMMON_API -int aws_hash_table_foreach( - struct aws_hash_table *map, - int (*callback)(void *context, struct aws_hash_element *p_element), - void *context); - -/** - * Compares two hash tables for equality. Both hash tables must have equivalent - * key comparators; values will be compared using the comparator passed into this - * function. The key hash function does not need to be equivalent between the - * two hash tables. - */ -AWS_COMMON_API -bool aws_hash_table_eq( - const struct aws_hash_table *a, - const struct aws_hash_table *b, - aws_hash_callback_eq_fn *value_eq); - -/** - * Removes every element from the hash map. destroy_fn will be called for - * each element. - */ -AWS_COMMON_API -void aws_hash_table_clear(struct aws_hash_table *map); - -/** - * Convenience hash function for NULL-terminated C-strings - */ -AWS_COMMON_API -uint64_t aws_hash_c_string(const void *item); - -/** - * Convenience hash function for struct aws_strings. - * Hash is same as used on the string bytes by aws_hash_c_string. - */ -AWS_COMMON_API -uint64_t aws_hash_string(const void *item); - -/** - * Convenience hash function for struct aws_byte_cursor. - * Hash is same as used on the string bytes by aws_hash_c_string. - */ -AWS_COMMON_API -uint64_t aws_hash_byte_cursor_ptr(const void *item); - -/** - * Convenience hash function which hashes the pointer value directly, - * without dereferencing. This can be used in cases where pointer identity - * is desired, or where a uintptr_t is encoded into a const void *. - */ -AWS_COMMON_API -uint64_t aws_hash_ptr(const void *item); - + * Iterates through every element in the map and invokes the callback on + * that item. Iteration is performed in an arbitrary, implementation-defined + * order, and is not guaranteed to be consistent across invocations. + * + * The callback may change the value associated with the key by overwriting + * the value pointed-to by value. In this case, the on_element_removed + * callback will not be invoked, unless the callback invokes + * AWS_COMMON_HASH_TABLE_ITER_DELETE (in which case the on_element_removed + * is given the updated value). + * + * The callback must return a bitmask of zero or more of the following values + * ORed together: + * + * # AWS_COMMON_HASH_TABLE_ITER_CONTINUE - Continues iteration to the next + * element (if not set, iteration stops) + * # AWS_COMMON_HASH_TABLE_ITER_DELETE - Deletes the current value and + * continues iteration. destroy_fn will NOT be invoked. + * + * Invoking any method which may change the contents of the hashtable + * during iteration results in undefined behavior. However, you may safely + * invoke non-mutating operations during an iteration. + * + * This operation is mutating only if AWS_COMMON_HASH_TABLE_ITER_DELETE + * is returned at some point during iteration. Otherwise, it is non-mutating + * and is safe to invoke in parallel with other non-mutating operations. + */ + +AWS_COMMON_API +int aws_hash_table_foreach( + struct aws_hash_table *map, + int (*callback)(void *context, struct aws_hash_element *p_element), + void *context); + +/** + * Compares two hash tables for equality. Both hash tables must have equivalent + * key comparators; values will be compared using the comparator passed into this + * function. The key hash function does not need to be equivalent between the + * two hash tables. + */ +AWS_COMMON_API +bool aws_hash_table_eq( + const struct aws_hash_table *a, + const struct aws_hash_table *b, + aws_hash_callback_eq_fn *value_eq); + +/** + * Removes every element from the hash map. destroy_fn will be called for + * each element. + */ +AWS_COMMON_API +void aws_hash_table_clear(struct aws_hash_table *map); + +/** + * Convenience hash function for NULL-terminated C-strings + */ +AWS_COMMON_API +uint64_t aws_hash_c_string(const void *item); + +/** + * Convenience hash function for struct aws_strings. + * Hash is same as used on the string bytes by aws_hash_c_string. + */ +AWS_COMMON_API +uint64_t aws_hash_string(const void *item); + +/** + * Convenience hash function for struct aws_byte_cursor. + * Hash is same as used on the string bytes by aws_hash_c_string. + */ +AWS_COMMON_API +uint64_t aws_hash_byte_cursor_ptr(const void *item); + +/** + * Convenience hash function which hashes the pointer value directly, + * without dereferencing. This can be used in cases where pointer identity + * is desired, or where a uintptr_t is encoded into a const void *. + */ +AWS_COMMON_API +uint64_t aws_hash_ptr(const void *item); + AWS_COMMON_API uint64_t aws_hash_combine(uint64_t item1, uint64_t item2); -/** - * Convenience eq callback for NULL-terminated C-strings - */ -AWS_COMMON_API -bool aws_hash_callback_c_str_eq(const void *a, const void *b); - -/** - * Convenience eq callback for AWS strings - */ -AWS_COMMON_API -bool aws_hash_callback_string_eq(const void *a, const void *b); - -/** - * Convenience destroy callback for AWS strings - */ -AWS_COMMON_API -void aws_hash_callback_string_destroy(void *a); - -/** - * Equality function which compares pointer equality. - */ -AWS_COMMON_API -bool aws_ptr_eq(const void *a, const void *b); - +/** + * Convenience eq callback for NULL-terminated C-strings + */ +AWS_COMMON_API +bool aws_hash_callback_c_str_eq(const void *a, const void *b); + +/** + * Convenience eq callback for AWS strings + */ +AWS_COMMON_API +bool aws_hash_callback_string_eq(const void *a, const void *b); + +/** + * Convenience destroy callback for AWS strings + */ +AWS_COMMON_API +void aws_hash_callback_string_destroy(void *a); + +/** + * Equality function which compares pointer equality. + */ +AWS_COMMON_API +bool aws_ptr_eq(const void *a, const void *b); + /** * Best-effort check of hash_table_state data-structure invariants */ @@ -423,6 +423,6 @@ bool aws_hash_table_is_valid(const struct aws_hash_table *map); AWS_COMMON_API bool aws_hash_iter_is_valid(const struct aws_hash_iter *iter); -AWS_EXTERN_C_END - -#endif /* AWS_COMMON_HASH_TABLE_H */ +AWS_EXTERN_C_END + +#endif /* AWS_COMMON_HASH_TABLE_H */ diff --git a/contrib/restricted/aws/aws-c-common/include/aws/common/linked_list.h b/contrib/restricted/aws/aws-c-common/include/aws/common/linked_list.h index 5d578adbf0..e4c3be9637 100644 --- a/contrib/restricted/aws/aws-c-common/include/aws/common/linked_list.h +++ b/contrib/restricted/aws/aws-c-common/include/aws/common/linked_list.h @@ -1,28 +1,28 @@ -#ifndef AWS_COMMON_LINKED_LIST_H -#define AWS_COMMON_LINKED_LIST_H - +#ifndef AWS_COMMON_LINKED_LIST_H +#define AWS_COMMON_LINKED_LIST_H + /** * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. - */ - -#include <aws/common/common.h> - -#include <stddef.h> - -struct aws_linked_list_node { - struct aws_linked_list_node *next; - struct aws_linked_list_node *prev; -}; - -struct aws_linked_list { - struct aws_linked_list_node head; - struct aws_linked_list_node tail; -}; - + */ + +#include <aws/common/common.h> + +#include <stddef.h> + +struct aws_linked_list_node { + struct aws_linked_list_node *next; + struct aws_linked_list_node *prev; +}; + +struct aws_linked_list { + struct aws_linked_list_node head; + struct aws_linked_list_node tail; +}; + AWS_EXTERN_C_BEGIN -/** +/** * Set node's next and prev pointers to NULL. */ AWS_STATIC_IMPL void aws_linked_list_node_reset(struct aws_linked_list_node *node); @@ -69,99 +69,99 @@ AWS_STATIC_IMPL bool aws_linked_list_node_prev_is_valid(const struct aws_linked_ AWS_STATIC_IMPL bool aws_linked_list_is_valid_deep(const struct aws_linked_list *list); /** - * Initializes the list. List will be empty after this call. - */ + * Initializes the list. List will be empty after this call. + */ AWS_STATIC_IMPL void aws_linked_list_init(struct aws_linked_list *list); - -/** - * Returns an iteration pointer for the first element in the list. - */ + +/** + * Returns an iteration pointer for the first element in the list. + */ AWS_STATIC_IMPL struct aws_linked_list_node *aws_linked_list_begin(const struct aws_linked_list *list); - -/** - * Returns an iteration pointer for one past the last element in the list. - */ + +/** + * Returns an iteration pointer for one past the last element in the list. + */ AWS_STATIC_IMPL const struct aws_linked_list_node *aws_linked_list_end(const struct aws_linked_list *list); - -/** - * Returns a pointer for the last element in the list. - * Used to begin iterating the list in reverse. Ex: - * for (i = aws_linked_list_rbegin(list); i != aws_linked_list_rend(list); i = aws_linked_list_prev(i)) {...} - */ + +/** + * Returns a pointer for the last element in the list. + * Used to begin iterating the list in reverse. Ex: + * for (i = aws_linked_list_rbegin(list); i != aws_linked_list_rend(list); i = aws_linked_list_prev(i)) {...} + */ AWS_STATIC_IMPL struct aws_linked_list_node *aws_linked_list_rbegin(const struct aws_linked_list *list); - -/** - * Returns the pointer to one before the first element in the list. - * Used to end iterating the list in reverse. - */ + +/** + * Returns the pointer to one before the first element in the list. + * Used to end iterating the list in reverse. + */ AWS_STATIC_IMPL const struct aws_linked_list_node *aws_linked_list_rend(const struct aws_linked_list *list); - -/** - * Returns the next element in the list. - */ + +/** + * Returns the next element in the list. + */ AWS_STATIC_IMPL struct aws_linked_list_node *aws_linked_list_next(const struct aws_linked_list_node *node); - -/** - * Returns the previous element in the list. - */ + +/** + * Returns the previous element in the list. + */ AWS_STATIC_IMPL struct aws_linked_list_node *aws_linked_list_prev(const struct aws_linked_list_node *node); - -/** - * Inserts to_add immediately after after. - */ -AWS_STATIC_IMPL void aws_linked_list_insert_after( - struct aws_linked_list_node *after, + +/** + * Inserts to_add immediately after after. + */ +AWS_STATIC_IMPL void aws_linked_list_insert_after( + struct aws_linked_list_node *after, struct aws_linked_list_node *to_add); /** * Swaps the order two nodes in the linked list. */ AWS_STATIC_IMPL void aws_linked_list_swap_nodes(struct aws_linked_list_node *a, struct aws_linked_list_node *b); - -/** - * Inserts to_add immediately before before. - */ -AWS_STATIC_IMPL void aws_linked_list_insert_before( - struct aws_linked_list_node *before, + +/** + * Inserts to_add immediately before before. + */ +AWS_STATIC_IMPL void aws_linked_list_insert_before( + struct aws_linked_list_node *before, struct aws_linked_list_node *to_add); - -/** - * Removes the specified node from the list (prev/next point to each other) and - * returns the next node in the list. - */ + +/** + * Removes the specified node from the list (prev/next point to each other) and + * returns the next node in the list. + */ AWS_STATIC_IMPL void aws_linked_list_remove(struct aws_linked_list_node *node); - -/** - * Append new_node. - */ + +/** + * Append new_node. + */ AWS_STATIC_IMPL void aws_linked_list_push_back(struct aws_linked_list *list, struct aws_linked_list_node *node); - -/** - * Returns the element in the back of the list. - */ + +/** + * Returns the element in the back of the list. + */ AWS_STATIC_IMPL struct aws_linked_list_node *aws_linked_list_back(const struct aws_linked_list *list); - -/** - * Returns the element in the back of the list and removes it - */ + +/** + * Returns the element in the back of the list and removes it + */ AWS_STATIC_IMPL struct aws_linked_list_node *aws_linked_list_pop_back(struct aws_linked_list *list); - -/** - * Prepend new_node. - */ + +/** + * Prepend new_node. + */ AWS_STATIC_IMPL void aws_linked_list_push_front(struct aws_linked_list *list, struct aws_linked_list_node *node); -/** - * Returns the element in the front of the list. - */ +/** + * Returns the element in the front of the list. + */ AWS_STATIC_IMPL struct aws_linked_list_node *aws_linked_list_front(const struct aws_linked_list *list); -/** - * Returns the element in the front of the list and removes it - */ +/** + * Returns the element in the front of the list and removes it + */ AWS_STATIC_IMPL struct aws_linked_list_node *aws_linked_list_pop_front(struct aws_linked_list *list); - + AWS_STATIC_IMPL void aws_linked_list_swap_contents( struct aws_linked_list *AWS_RESTRICT a, struct aws_linked_list *AWS_RESTRICT b); - + /** * Remove all nodes from one list, and add them to the back of another. * @@ -170,7 +170,7 @@ AWS_STATIC_IMPL void aws_linked_list_swap_contents( AWS_STATIC_IMPL void aws_linked_list_move_all_back( struct aws_linked_list *AWS_RESTRICT dst, struct aws_linked_list *AWS_RESTRICT src); - + /** * Remove all nodes from one list, and add them to the front of another. * @@ -179,10 +179,10 @@ AWS_STATIC_IMPL void aws_linked_list_move_all_back( AWS_STATIC_IMPL void aws_linked_list_move_all_front( struct aws_linked_list *AWS_RESTRICT dst, struct aws_linked_list *AWS_RESTRICT src); - + #ifndef AWS_NO_STATIC_IMPL # include <aws/common/linked_list.inl> #endif /* AWS_NO_STATIC_IMPL */ AWS_EXTERN_C_END -#endif /* AWS_COMMON_LINKED_LIST_H */ +#endif /* AWS_COMMON_LINKED_LIST_H */ diff --git a/contrib/restricted/aws/aws-c-common/include/aws/common/lru_cache.h b/contrib/restricted/aws/aws-c-common/include/aws/common/lru_cache.h index 0aa7162ecf..37eff525f5 100644 --- a/contrib/restricted/aws/aws-c-common/include/aws/common/lru_cache.h +++ b/contrib/restricted/aws/aws-c-common/include/aws/common/lru_cache.h @@ -1,42 +1,42 @@ -#ifndef AWS_COMMON_LRU_CACHE_H -#define AWS_COMMON_LRU_CACHE_H +#ifndef AWS_COMMON_LRU_CACHE_H +#define AWS_COMMON_LRU_CACHE_H /** * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. - */ - + */ + #include <aws/common/cache.h> - -AWS_EXTERN_C_BEGIN - -/** + +AWS_EXTERN_C_BEGIN + +/** * Initializes the Least-recently-used cache. Sets up the underlying linked hash table. * Once `max_items` elements have been added, the least recently used item will be removed. For the other parameters, * see aws/common/hash_table.h. Hash table semantics of these arguments are preserved.(Yes the one that was the answer * to that interview question that one time). - */ -AWS_COMMON_API + */ +AWS_COMMON_API struct aws_cache *aws_cache_new_lru( - struct aws_allocator *allocator, - aws_hash_fn *hash_fn, - aws_hash_callback_eq_fn *equals_fn, - aws_hash_callback_destroy_fn *destroy_key_fn, - aws_hash_callback_destroy_fn *destroy_value_fn, - size_t max_items); - -/** - * Accesses the least-recently-used element, sets it to most-recently-used - * element, and returns the value. - */ -AWS_COMMON_API + struct aws_allocator *allocator, + aws_hash_fn *hash_fn, + aws_hash_callback_eq_fn *equals_fn, + aws_hash_callback_destroy_fn *destroy_key_fn, + aws_hash_callback_destroy_fn *destroy_value_fn, + size_t max_items); + +/** + * Accesses the least-recently-used element, sets it to most-recently-used + * element, and returns the value. + */ +AWS_COMMON_API void *aws_lru_cache_use_lru_element(struct aws_cache *cache); - -/** - * Accesses the most-recently-used element and returns its value. - */ -AWS_COMMON_API + +/** + * Accesses the most-recently-used element and returns its value. + */ +AWS_COMMON_API void *aws_lru_cache_get_mru_element(const struct aws_cache *cache); - -AWS_EXTERN_C_END - -#endif /* AWS_COMMON_LRU_CACHE_H */ + +AWS_EXTERN_C_END + +#endif /* AWS_COMMON_LRU_CACHE_H */ diff --git a/contrib/restricted/aws/aws-c-common/include/aws/common/math.gcc_overflow.inl b/contrib/restricted/aws/aws-c-common/include/aws/common/math.gcc_overflow.inl index d0cfec872e..24ce3f0e00 100644 --- a/contrib/restricted/aws/aws-c-common/include/aws/common/math.gcc_overflow.inl +++ b/contrib/restricted/aws/aws-c-common/include/aws/common/math.gcc_overflow.inl @@ -4,111 +4,111 @@ /** * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. - */ - -/* - * This header is already included, but include it again to make editor - * highlighting happier. - */ -#include <aws/common/common.h> + */ + +/* + * This header is already included, but include it again to make editor + * highlighting happier. + */ +#include <aws/common/common.h> #include <aws/common/math.h> - + AWS_EXTERN_C_BEGIN -/** - * Multiplies a * b. If the result overflows, returns 2^64 - 1. - */ -AWS_STATIC_IMPL uint64_t aws_mul_u64_saturating(uint64_t a, uint64_t b) { - uint64_t res; - - if (__builtin_mul_overflow(a, b, &res)) { - res = UINT64_MAX; - } - - return res; -} - -/** - * If a * b overflows, returns AWS_OP_ERR; otherwise multiplies - * a * b, returns the result in *r, and returns AWS_OP_SUCCESS. - */ -AWS_STATIC_IMPL int aws_mul_u64_checked(uint64_t a, uint64_t b, uint64_t *r) { - if (__builtin_mul_overflow(a, b, r)) { - return aws_raise_error(AWS_ERROR_OVERFLOW_DETECTED); - } - return AWS_OP_SUCCESS; -} - -/** - * Multiplies a * b. If the result overflows, returns 2^32 - 1. - */ -AWS_STATIC_IMPL uint32_t aws_mul_u32_saturating(uint32_t a, uint32_t b) { - uint32_t res; - - if (__builtin_mul_overflow(a, b, &res)) { - res = UINT32_MAX; - } - - return res; -} - -/** - * If a * b overflows, returns AWS_OP_ERR; otherwise multiplies - * a * b, returns the result in *r, and returns AWS_OP_SUCCESS. - */ -AWS_STATIC_IMPL int aws_mul_u32_checked(uint32_t a, uint32_t b, uint32_t *r) { - if (__builtin_mul_overflow(a, b, r)) { - return aws_raise_error(AWS_ERROR_OVERFLOW_DETECTED); - } - return AWS_OP_SUCCESS; -} - -/** - * If a + b overflows, returns AWS_OP_ERR; otherwise adds - * a + b, returns the result in *r, and returns AWS_OP_SUCCESS. - */ -AWS_STATIC_IMPL int aws_add_u64_checked(uint64_t a, uint64_t b, uint64_t *r) { - if (__builtin_add_overflow(a, b, r)) { - return aws_raise_error(AWS_ERROR_OVERFLOW_DETECTED); - } - return AWS_OP_SUCCESS; -} - -/** - * Adds a + b. If the result overflows, returns 2^64 - 1. - */ -AWS_STATIC_IMPL uint64_t aws_add_u64_saturating(uint64_t a, uint64_t b) { - uint64_t res; - - if (__builtin_add_overflow(a, b, &res)) { - res = UINT64_MAX; - } - - return res; -} - -/** - * If a + b overflows, returns AWS_OP_ERR; otherwise adds - * a + b, returns the result in *r, and returns AWS_OP_SUCCESS. - */ -AWS_STATIC_IMPL int aws_add_u32_checked(uint32_t a, uint32_t b, uint32_t *r) { - if (__builtin_add_overflow(a, b, r)) { - return aws_raise_error(AWS_ERROR_OVERFLOW_DETECTED); - } - return AWS_OP_SUCCESS; -} - -/** - * Adds a + b. If the result overflows, returns 2^32 - 1. - */ +/** + * Multiplies a * b. If the result overflows, returns 2^64 - 1. + */ +AWS_STATIC_IMPL uint64_t aws_mul_u64_saturating(uint64_t a, uint64_t b) { + uint64_t res; + + if (__builtin_mul_overflow(a, b, &res)) { + res = UINT64_MAX; + } + + return res; +} + +/** + * If a * b overflows, returns AWS_OP_ERR; otherwise multiplies + * a * b, returns the result in *r, and returns AWS_OP_SUCCESS. + */ +AWS_STATIC_IMPL int aws_mul_u64_checked(uint64_t a, uint64_t b, uint64_t *r) { + if (__builtin_mul_overflow(a, b, r)) { + return aws_raise_error(AWS_ERROR_OVERFLOW_DETECTED); + } + return AWS_OP_SUCCESS; +} + +/** + * Multiplies a * b. If the result overflows, returns 2^32 - 1. + */ +AWS_STATIC_IMPL uint32_t aws_mul_u32_saturating(uint32_t a, uint32_t b) { + uint32_t res; + + if (__builtin_mul_overflow(a, b, &res)) { + res = UINT32_MAX; + } + + return res; +} + +/** + * If a * b overflows, returns AWS_OP_ERR; otherwise multiplies + * a * b, returns the result in *r, and returns AWS_OP_SUCCESS. + */ +AWS_STATIC_IMPL int aws_mul_u32_checked(uint32_t a, uint32_t b, uint32_t *r) { + if (__builtin_mul_overflow(a, b, r)) { + return aws_raise_error(AWS_ERROR_OVERFLOW_DETECTED); + } + return AWS_OP_SUCCESS; +} + +/** + * If a + b overflows, returns AWS_OP_ERR; otherwise adds + * a + b, returns the result in *r, and returns AWS_OP_SUCCESS. + */ +AWS_STATIC_IMPL int aws_add_u64_checked(uint64_t a, uint64_t b, uint64_t *r) { + if (__builtin_add_overflow(a, b, r)) { + return aws_raise_error(AWS_ERROR_OVERFLOW_DETECTED); + } + return AWS_OP_SUCCESS; +} + +/** + * Adds a + b. If the result overflows, returns 2^64 - 1. + */ +AWS_STATIC_IMPL uint64_t aws_add_u64_saturating(uint64_t a, uint64_t b) { + uint64_t res; + + if (__builtin_add_overflow(a, b, &res)) { + res = UINT64_MAX; + } + + return res; +} + +/** + * If a + b overflows, returns AWS_OP_ERR; otherwise adds + * a + b, returns the result in *r, and returns AWS_OP_SUCCESS. + */ +AWS_STATIC_IMPL int aws_add_u32_checked(uint32_t a, uint32_t b, uint32_t *r) { + if (__builtin_add_overflow(a, b, r)) { + return aws_raise_error(AWS_ERROR_OVERFLOW_DETECTED); + } + return AWS_OP_SUCCESS; +} + +/** + * Adds a + b. If the result overflows, returns 2^32 - 1. + */ AWS_STATIC_IMPL uint32_t aws_add_u32_saturating(uint32_t a, uint32_t b) { - uint32_t res; - - if (__builtin_add_overflow(a, b, &res)) { - res = UINT32_MAX; - } - - return res; -} + uint32_t res; + + if (__builtin_add_overflow(a, b, &res)) { + res = UINT32_MAX; + } + + return res; +} AWS_EXTERN_C_END diff --git a/contrib/restricted/aws/aws-c-common/include/aws/common/math.h b/contrib/restricted/aws/aws-c-common/include/aws/common/math.h index 027d0ff502..108e983639 100644 --- a/contrib/restricted/aws/aws-c-common/include/aws/common/math.h +++ b/contrib/restricted/aws/aws-c-common/include/aws/common/math.h @@ -1,101 +1,101 @@ -#ifndef AWS_COMMON_MATH_H -#define AWS_COMMON_MATH_H - +#ifndef AWS_COMMON_MATH_H +#define AWS_COMMON_MATH_H + /** * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. - */ - -#include <aws/common/common.h> -#include <aws/common/config.h> - -#include <limits.h> -#include <stdlib.h> - -/* The number of bits in a size_t variable */ -#if SIZE_MAX == UINT32_MAX -# define SIZE_BITS 32 -#elif SIZE_MAX == UINT64_MAX -# define SIZE_BITS 64 -#else -# error "Target not supported" -#endif - -/* The largest power of two that can be stored in a size_t */ -#define SIZE_MAX_POWER_OF_TWO (((size_t)1) << (SIZE_BITS - 1)) - + */ + +#include <aws/common/common.h> +#include <aws/common/config.h> + +#include <limits.h> +#include <stdlib.h> + +/* The number of bits in a size_t variable */ +#if SIZE_MAX == UINT32_MAX +# define SIZE_BITS 32 +#elif SIZE_MAX == UINT64_MAX +# define SIZE_BITS 64 +#else +# error "Target not supported" +#endif + +/* The largest power of two that can be stored in a size_t */ +#define SIZE_MAX_POWER_OF_TWO (((size_t)1) << (SIZE_BITS - 1)) + AWS_EXTERN_C_BEGIN - + #if defined(AWS_HAVE_GCC_OVERFLOW_MATH_EXTENSIONS) && (defined(__clang__) || !defined(__cplusplus)) || \ (defined(__x86_64__) || defined(__aarch64__)) && defined(AWS_HAVE_GCC_INLINE_ASM) || \ defined(AWS_HAVE_MSVC_MULX) || defined(CBMC) || !defined(AWS_HAVE_GCC_OVERFLOW_MATH_EXTENSIONS) /* In all these cases, we can use fast static inline versions of this code */ # define AWS_COMMON_MATH_API AWS_STATIC_IMPL -#else -/* - * We got here because we are building in C++ mode but we only support overflow extensions - * in C mode. Because the fallback is _slow_ (involving a division), we'd prefer to make a - * non-inline call to the fast C intrinsics. - */ +#else +/* + * We got here because we are building in C++ mode but we only support overflow extensions + * in C mode. Because the fallback is _slow_ (involving a division), we'd prefer to make a + * non-inline call to the fast C intrinsics. + */ # define AWS_COMMON_MATH_API AWS_COMMON_API #endif - -/** - * Multiplies a * b. If the result overflows, returns 2^64 - 1. - */ + +/** + * Multiplies a * b. If the result overflows, returns 2^64 - 1. + */ AWS_COMMON_MATH_API uint64_t aws_mul_u64_saturating(uint64_t a, uint64_t b); - -/** - * If a * b overflows, returns AWS_OP_ERR; otherwise multiplies - * a * b, returns the result in *r, and returns AWS_OP_SUCCESS. - */ + +/** + * If a * b overflows, returns AWS_OP_ERR; otherwise multiplies + * a * b, returns the result in *r, and returns AWS_OP_SUCCESS. + */ AWS_COMMON_MATH_API int aws_mul_u64_checked(uint64_t a, uint64_t b, uint64_t *r); - -/** - * Multiplies a * b. If the result overflows, returns 2^32 - 1. - */ + +/** + * Multiplies a * b. If the result overflows, returns 2^32 - 1. + */ AWS_COMMON_MATH_API uint32_t aws_mul_u32_saturating(uint32_t a, uint32_t b); - -/** - * If a * b overflows, returns AWS_OP_ERR; otherwise multiplies - * a * b, returns the result in *r, and returns AWS_OP_SUCCESS. - */ + +/** + * If a * b overflows, returns AWS_OP_ERR; otherwise multiplies + * a * b, returns the result in *r, and returns AWS_OP_SUCCESS. + */ AWS_COMMON_MATH_API int aws_mul_u32_checked(uint32_t a, uint32_t b, uint32_t *r); - -/** - * Adds a + b. If the result overflows returns 2^64 - 1. - */ + +/** + * Adds a + b. If the result overflows returns 2^64 - 1. + */ AWS_COMMON_MATH_API uint64_t aws_add_u64_saturating(uint64_t a, uint64_t b); - -/** - * If a + b overflows, returns AWS_OP_ERR; otherwise adds - * a + b, returns the result in *r, and returns AWS_OP_SUCCESS. - */ + +/** + * If a + b overflows, returns AWS_OP_ERR; otherwise adds + * a + b, returns the result in *r, and returns AWS_OP_SUCCESS. + */ AWS_COMMON_MATH_API int aws_add_u64_checked(uint64_t a, uint64_t b, uint64_t *r); - -/** - * Adds a + b. If the result overflows returns 2^32 - 1. - */ + +/** + * Adds a + b. If the result overflows returns 2^32 - 1. + */ AWS_COMMON_MATH_API uint32_t aws_add_u32_saturating(uint32_t a, uint32_t b); - -/** - * If a + b overflows, returns AWS_OP_ERR; otherwise adds - * a + b, returns the result in *r, and returns AWS_OP_SUCCESS. - */ + +/** + * If a + b overflows, returns AWS_OP_ERR; otherwise adds + * a + b, returns the result in *r, and returns AWS_OP_SUCCESS. + */ AWS_COMMON_MATH_API int aws_add_u32_checked(uint32_t a, uint32_t b, uint32_t *r); - + /** * Subtracts a - b. If the result overflows returns 0. */ AWS_STATIC_IMPL uint64_t aws_sub_u64_saturating(uint64_t a, uint64_t b); - + /** * If a - b overflows, returns AWS_OP_ERR; otherwise subtracts * a - b, returns the result in *r, and returns AWS_OP_SUCCESS. */ AWS_STATIC_IMPL int aws_sub_u64_checked(uint64_t a, uint64_t b, uint64_t *r); - -/** + +/** * Subtracts a - b. If the result overflows returns 0. */ AWS_STATIC_IMPL uint32_t aws_sub_u32_saturating(uint32_t a, uint32_t b); @@ -107,39 +107,39 @@ AWS_STATIC_IMPL uint32_t aws_sub_u32_saturating(uint32_t a, uint32_t b); AWS_STATIC_IMPL int aws_sub_u32_checked(uint32_t a, uint32_t b, uint32_t *r); /** - * Multiplies a * b. If the result overflows, returns SIZE_MAX. - */ + * Multiplies a * b. If the result overflows, returns SIZE_MAX. + */ AWS_STATIC_IMPL size_t aws_mul_size_saturating(size_t a, size_t b); - -/** - * Multiplies a * b and returns the result in *r. If the result - * overflows, returns AWS_OP_ERR; otherwise returns AWS_OP_SUCCESS. - */ + +/** + * Multiplies a * b and returns the result in *r. If the result + * overflows, returns AWS_OP_ERR; otherwise returns AWS_OP_SUCCESS. + */ AWS_STATIC_IMPL int aws_mul_size_checked(size_t a, size_t b, size_t *r); - -/** - * Adds a + b. If the result overflows returns SIZE_MAX. - */ + +/** + * Adds a + b. If the result overflows returns SIZE_MAX. + */ AWS_STATIC_IMPL size_t aws_add_size_saturating(size_t a, size_t b); - -/** - * Adds a + b and returns the result in *r. If the result - * overflows, returns AWS_OP_ERR; otherwise returns AWS_OP_SUCCESS. - */ + +/** + * Adds a + b and returns the result in *r. If the result + * overflows, returns AWS_OP_ERR; otherwise returns AWS_OP_SUCCESS. + */ AWS_STATIC_IMPL int aws_add_size_checked(size_t a, size_t b, size_t *r); - + /** * Adds [num] arguments (expected to be of size_t), and returns the result in *r. * If the result overflows, returns AWS_OP_ERR; otherwise returns AWS_OP_SUCCESS. */ AWS_COMMON_API int aws_add_size_checked_varargs(size_t num, size_t *r, ...); - -/** + +/** * Subtracts a - b. If the result overflows returns 0. - */ + */ AWS_STATIC_IMPL size_t aws_sub_size_saturating(size_t a, size_t b); - -/** + +/** * If a - b overflows, returns AWS_OP_ERR; otherwise subtracts * a - b, returns the result in *r, and returns AWS_OP_SUCCESS. */ @@ -150,11 +150,11 @@ AWS_STATIC_IMPL int aws_sub_size_checked(size_t a, size_t b, size_t *r); */ AWS_STATIC_IMPL bool aws_is_power_of_two(const size_t x); /** - * Function to find the smallest result that is power of 2 >= n. Returns AWS_OP_ERR if this cannot - * be done without overflow - */ + * Function to find the smallest result that is power of 2 >= n. Returns AWS_OP_ERR if this cannot + * be done without overflow + */ AWS_STATIC_IMPL int aws_round_up_to_power_of_two(size_t n, size_t *result); - + /** * Counts the number of leading 0 bits in an integer */ @@ -163,7 +163,7 @@ AWS_STATIC_IMPL size_t aws_clz_i32(int32_t n); AWS_STATIC_IMPL size_t aws_clz_u64(uint64_t n); AWS_STATIC_IMPL size_t aws_clz_i64(int64_t n); AWS_STATIC_IMPL size_t aws_clz_size(size_t n); - + /** * Counts the number of trailing 0 bits in an integer */ @@ -172,7 +172,7 @@ AWS_STATIC_IMPL size_t aws_ctz_i32(int32_t n); AWS_STATIC_IMPL size_t aws_ctz_u64(uint64_t n); AWS_STATIC_IMPL size_t aws_ctz_i64(int64_t n); AWS_STATIC_IMPL size_t aws_ctz_size(size_t n); - + AWS_STATIC_IMPL uint8_t aws_min_u8(uint8_t a, uint8_t b); AWS_STATIC_IMPL uint8_t aws_max_u8(uint8_t a, uint8_t b); AWS_STATIC_IMPL int8_t aws_min_i8(int8_t a, int8_t b); @@ -197,11 +197,11 @@ AWS_STATIC_IMPL float aws_min_float(float a, float b); AWS_STATIC_IMPL float aws_max_float(float a, float b); AWS_STATIC_IMPL double aws_min_double(double a, double b); AWS_STATIC_IMPL double aws_max_double(double a, double b); - + #ifndef AWS_NO_STATIC_IMPL # include <aws/common/math.inl> #endif /* AWS_NO_STATIC_IMPL */ AWS_EXTERN_C_END -#endif /* AWS_COMMON_MATH_H */ +#endif /* AWS_COMMON_MATH_H */ diff --git a/contrib/restricted/aws/aws-c-common/include/aws/common/mutex.h b/contrib/restricted/aws/aws-c-common/include/aws/common/mutex.h index 5a4bb635c6..73c2ecfa55 100644 --- a/contrib/restricted/aws/aws-c-common/include/aws/common/mutex.h +++ b/contrib/restricted/aws/aws-c-common/include/aws/common/mutex.h @@ -1,72 +1,72 @@ -#ifndef AWS_COMMON_MUTEX_H -#define AWS_COMMON_MUTEX_H - +#ifndef AWS_COMMON_MUTEX_H +#define AWS_COMMON_MUTEX_H + /** * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. - */ - -#include <aws/common/common.h> -#ifdef _WIN32 -/* NOTE: Do not use this macro before including Windows.h */ + */ + +#include <aws/common/common.h> +#ifdef _WIN32 +/* NOTE: Do not use this macro before including Windows.h */ # define AWSMUTEX_TO_WINDOWS(pMutex) (PSRWLOCK) & (pMutex)->mutex_handle -#else -# include <pthread.h> -#endif - -struct aws_mutex { -#ifdef _WIN32 - void *mutex_handle; -#else - pthread_mutex_t mutex_handle; -#endif +#else +# include <pthread.h> +#endif + +struct aws_mutex { +#ifdef _WIN32 + void *mutex_handle; +#else + pthread_mutex_t mutex_handle; +#endif bool initialized; -}; - -#ifdef _WIN32 -# define AWS_MUTEX_INIT \ +}; + +#ifdef _WIN32 +# define AWS_MUTEX_INIT \ { .mutex_handle = NULL, .initialized = true } -#else -# define AWS_MUTEX_INIT \ +#else +# define AWS_MUTEX_INIT \ { .mutex_handle = PTHREAD_MUTEX_INITIALIZER, .initialized = true } -#endif - -AWS_EXTERN_C_BEGIN - -/** - * Initializes a new platform instance of mutex. - */ -AWS_COMMON_API -int aws_mutex_init(struct aws_mutex *mutex); - -/** - * Cleans up internal resources. - */ -AWS_COMMON_API -void aws_mutex_clean_up(struct aws_mutex *mutex); - -/** - * Blocks until it acquires the lock. While on some platforms such as Windows, - * this may behave as a reentrant mutex, you should not treat it like one. On - * platforms it is possible for it to be non-reentrant, it will be. - */ -AWS_COMMON_API -int aws_mutex_lock(struct aws_mutex *mutex); - -/** - * Attempts to acquire the lock but returns immediately if it can not. - * While on some platforms such as Windows, this may behave as a reentrant mutex, - * you should not treat it like one. On platforms it is possible for it to be non-reentrant, it will be. - */ -AWS_COMMON_API -int aws_mutex_try_lock(struct aws_mutex *mutex); - -/** - * Releases the lock. - */ -AWS_COMMON_API -int aws_mutex_unlock(struct aws_mutex *mutex); - -AWS_EXTERN_C_END - -#endif /* AWS_COMMON_MUTEX_H */ +#endif + +AWS_EXTERN_C_BEGIN + +/** + * Initializes a new platform instance of mutex. + */ +AWS_COMMON_API +int aws_mutex_init(struct aws_mutex *mutex); + +/** + * Cleans up internal resources. + */ +AWS_COMMON_API +void aws_mutex_clean_up(struct aws_mutex *mutex); + +/** + * Blocks until it acquires the lock. While on some platforms such as Windows, + * this may behave as a reentrant mutex, you should not treat it like one. On + * platforms it is possible for it to be non-reentrant, it will be. + */ +AWS_COMMON_API +int aws_mutex_lock(struct aws_mutex *mutex); + +/** + * Attempts to acquire the lock but returns immediately if it can not. + * While on some platforms such as Windows, this may behave as a reentrant mutex, + * you should not treat it like one. On platforms it is possible for it to be non-reentrant, it will be. + */ +AWS_COMMON_API +int aws_mutex_try_lock(struct aws_mutex *mutex); + +/** + * Releases the lock. + */ +AWS_COMMON_API +int aws_mutex_unlock(struct aws_mutex *mutex); + +AWS_EXTERN_C_END + +#endif /* AWS_COMMON_MUTEX_H */ diff --git a/contrib/restricted/aws/aws-c-common/include/aws/common/posix/common.inl b/contrib/restricted/aws/aws-c-common/include/aws/common/posix/common.inl index 4a6e0a1b6a..ebf34efbcd 100644 --- a/contrib/restricted/aws/aws-c-common/include/aws/common/posix/common.inl +++ b/contrib/restricted/aws/aws-c-common/include/aws/common/posix/common.inl @@ -1,36 +1,36 @@ /** * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. - */ - -#ifndef AWS_COMMON_POSIX_COMMON_INL -#define AWS_COMMON_POSIX_COMMON_INL - -#include <aws/common/common.h> - -#include <errno.h> - -AWS_EXTERN_C_BEGIN - -static inline int aws_private_convert_and_raise_error_code(int error_code) { - switch (error_code) { - case 0: - return AWS_OP_SUCCESS; - case EINVAL: - return aws_raise_error(AWS_ERROR_MUTEX_NOT_INIT); - case EBUSY: - return aws_raise_error(AWS_ERROR_MUTEX_TIMEOUT); - case EPERM: - return aws_raise_error(AWS_ERROR_MUTEX_CALLER_NOT_OWNER); - case ENOMEM: - return aws_raise_error(AWS_ERROR_OOM); - case EDEADLK: - return aws_raise_error(AWS_ERROR_THREAD_DEADLOCK_DETECTED); - default: - return aws_raise_error(AWS_ERROR_MUTEX_FAILED); - } -} - -AWS_EXTERN_C_END - -#endif /* AWS_COMMON_POSIX_COMMON_INL */ + */ + +#ifndef AWS_COMMON_POSIX_COMMON_INL +#define AWS_COMMON_POSIX_COMMON_INL + +#include <aws/common/common.h> + +#include <errno.h> + +AWS_EXTERN_C_BEGIN + +static inline int aws_private_convert_and_raise_error_code(int error_code) { + switch (error_code) { + case 0: + return AWS_OP_SUCCESS; + case EINVAL: + return aws_raise_error(AWS_ERROR_MUTEX_NOT_INIT); + case EBUSY: + return aws_raise_error(AWS_ERROR_MUTEX_TIMEOUT); + case EPERM: + return aws_raise_error(AWS_ERROR_MUTEX_CALLER_NOT_OWNER); + case ENOMEM: + return aws_raise_error(AWS_ERROR_OOM); + case EDEADLK: + return aws_raise_error(AWS_ERROR_THREAD_DEADLOCK_DETECTED); + default: + return aws_raise_error(AWS_ERROR_MUTEX_FAILED); + } +} + +AWS_EXTERN_C_END + +#endif /* AWS_COMMON_POSIX_COMMON_INL */ diff --git a/contrib/restricted/aws/aws-c-common/include/aws/common/priority_queue.h b/contrib/restricted/aws/aws-c-common/include/aws/common/priority_queue.h index 392c934d8e..8859729346 100644 --- a/contrib/restricted/aws/aws-c-common/include/aws/common/priority_queue.h +++ b/contrib/restricted/aws/aws-c-common/include/aws/common/priority_queue.h @@ -1,87 +1,87 @@ -#ifndef AWS_COMMON_PRIORITY_QUEUE_H -#define AWS_COMMON_PRIORITY_QUEUE_H +#ifndef AWS_COMMON_PRIORITY_QUEUE_H +#define AWS_COMMON_PRIORITY_QUEUE_H /** * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. - */ - -#include <aws/common/array_list.h> -#include <aws/common/common.h> - -/* The comparator should return a positive value if the second argument has a - * higher priority than the first; Otherwise, it should return a negative value - * or zero. NOTE: priority_queue pops its highest priority element first. For - * example: int cmp(const void *a, const void *b) { return a < b; } would result - * in a max heap, while: int cmp(const void *a, const void *b) { return a > b; } - * would result in a min heap. - */ -typedef int(aws_priority_queue_compare_fn)(const void *a, const void *b); - -struct aws_priority_queue { - /** - * predicate that determines the priority of the elements in the queue. - */ - aws_priority_queue_compare_fn *pred; - - /** - * The underlying container storing the queue elements. - */ - struct aws_array_list container; - - /** - * An array of pointers to backpointer elements. This array is initialized when - * the first call to aws_priority_queue_push_bp is made, and is subsequently maintained - * through any heap node manipulations. - * - * Each element is a struct aws_priority_queue_node *, pointing to a backpointer field - * owned by the calling code, or a NULL. The backpointer field is continually updated - * with information needed to locate and remove a specific node later on. - */ - struct aws_array_list backpointers; -}; - -struct aws_priority_queue_node { - /** The current index of the node in queuesion, or SIZE_MAX if the node has been removed. */ - size_t current_index; -}; - -AWS_EXTERN_C_BEGIN - -/** - * Initializes a priority queue struct for use. This mode will grow memory automatically (exponential model) - * Default size is the inital size of the queue - * item_size is the size of each element in bytes. Mixing items types is not supported by this API. - * pred is the function that will be used to determine priority. - */ -AWS_COMMON_API -int aws_priority_queue_init_dynamic( - struct aws_priority_queue *queue, - struct aws_allocator *alloc, - size_t default_size, - size_t item_size, - aws_priority_queue_compare_fn *pred); - -/** - * Initializes a priority queue struct for use. This mode will not allocate any additional memory. When the heap fills - * new enqueue operations will fail with AWS_ERROR_PRIORITY_QUEUE_FULL. - * - * Heaps initialized using this call do not support the aws_priority_queue_push_ref call with a non-NULL backpointer - * parameter. - * - * heap is the raw memory allocated for this priority_queue - * item_count is the maximum number of elements the raw heap can contain - * item_size is the size of each element in bytes. Mixing items types is not supported by this API. - * pred is the function that will be used to determine priority. - */ -AWS_COMMON_API -void aws_priority_queue_init_static( - struct aws_priority_queue *queue, - void *heap, - size_t item_count, - size_t item_size, - aws_priority_queue_compare_fn *pred); - -/** + */ + +#include <aws/common/array_list.h> +#include <aws/common/common.h> + +/* The comparator should return a positive value if the second argument has a + * higher priority than the first; Otherwise, it should return a negative value + * or zero. NOTE: priority_queue pops its highest priority element first. For + * example: int cmp(const void *a, const void *b) { return a < b; } would result + * in a max heap, while: int cmp(const void *a, const void *b) { return a > b; } + * would result in a min heap. + */ +typedef int(aws_priority_queue_compare_fn)(const void *a, const void *b); + +struct aws_priority_queue { + /** + * predicate that determines the priority of the elements in the queue. + */ + aws_priority_queue_compare_fn *pred; + + /** + * The underlying container storing the queue elements. + */ + struct aws_array_list container; + + /** + * An array of pointers to backpointer elements. This array is initialized when + * the first call to aws_priority_queue_push_bp is made, and is subsequently maintained + * through any heap node manipulations. + * + * Each element is a struct aws_priority_queue_node *, pointing to a backpointer field + * owned by the calling code, or a NULL. The backpointer field is continually updated + * with information needed to locate and remove a specific node later on. + */ + struct aws_array_list backpointers; +}; + +struct aws_priority_queue_node { + /** The current index of the node in queuesion, or SIZE_MAX if the node has been removed. */ + size_t current_index; +}; + +AWS_EXTERN_C_BEGIN + +/** + * Initializes a priority queue struct for use. This mode will grow memory automatically (exponential model) + * Default size is the inital size of the queue + * item_size is the size of each element in bytes. Mixing items types is not supported by this API. + * pred is the function that will be used to determine priority. + */ +AWS_COMMON_API +int aws_priority_queue_init_dynamic( + struct aws_priority_queue *queue, + struct aws_allocator *alloc, + size_t default_size, + size_t item_size, + aws_priority_queue_compare_fn *pred); + +/** + * Initializes a priority queue struct for use. This mode will not allocate any additional memory. When the heap fills + * new enqueue operations will fail with AWS_ERROR_PRIORITY_QUEUE_FULL. + * + * Heaps initialized using this call do not support the aws_priority_queue_push_ref call with a non-NULL backpointer + * parameter. + * + * heap is the raw memory allocated for this priority_queue + * item_count is the maximum number of elements the raw heap can contain + * item_size is the size of each element in bytes. Mixing items types is not supported by this API. + * pred is the function that will be used to determine priority. + */ +AWS_COMMON_API +void aws_priority_queue_init_static( + struct aws_priority_queue *queue, + void *heap, + size_t item_count, + size_t item_size, + aws_priority_queue_compare_fn *pred); + +/** * Checks that the backpointer at a specific index of the queue is * NULL or points to a correctly allocated aws_priority_queue_node. */ @@ -102,77 +102,77 @@ bool aws_priority_queue_backpointers_valid_deep(const struct aws_priority_queue bool aws_priority_queue_backpointers_valid(const struct aws_priority_queue *const queue); /** - * Set of properties of a valid aws_priority_queue. - */ -AWS_COMMON_API -bool aws_priority_queue_is_valid(const struct aws_priority_queue *const queue); - -/** - * Cleans up any internally allocated memory and resets the struct for reuse or deletion. - */ -AWS_COMMON_API -void aws_priority_queue_clean_up(struct aws_priority_queue *queue); - -/** - * Copies item into the queue and places it in the proper priority order. Complexity: O(log(n)). - */ -AWS_COMMON_API -int aws_priority_queue_push(struct aws_priority_queue *queue, void *item); - -/** - * Copies item into the queue and places it in the proper priority order. Complexity: O(log(n)). - * - * If the backpointer parameter is non-null, the heap will continually update the pointed-to field - * with information needed to remove the node later on. *backpointer must remain valid until the node - * is removed from the heap, and may be updated on any mutating operation on the priority queue. - * - * If the node is removed, the backpointer will be set to a sentinel value that indicates that the - * node has already been removed. It is safe (and a no-op) to call aws_priority_queue_remove with - * such a sentinel value. - */ -AWS_COMMON_API -int aws_priority_queue_push_ref( - struct aws_priority_queue *queue, - void *item, - struct aws_priority_queue_node *backpointer); - -/** - * Copies the element of the highest priority, and removes it from the queue.. Complexity: O(log(n)). - * If queue is empty, AWS_ERROR_PRIORITY_QUEUE_EMPTY will be raised. - */ -AWS_COMMON_API -int aws_priority_queue_pop(struct aws_priority_queue *queue, void *item); - -/** - * Removes a specific node from the priority queue. Complexity: O(log(n)) - * After removing a node (using either _remove or _pop), the backpointer set at push_ref time is set - * to a sentinel value. If this sentinel value is passed to aws_priority_queue_remove, - * AWS_ERROR_PRIORITY_QUEUE_BAD_NODE will be raised. Note, however, that passing uninitialized - * aws_priority_queue_nodes, or ones from different priority queues, results in undefined behavior. - */ -AWS_COMMON_API -int aws_priority_queue_remove(struct aws_priority_queue *queue, void *item, const struct aws_priority_queue_node *node); - -/** - * Obtains a pointer to the element of the highest priority. Complexity: constant time. - * If queue is empty, AWS_ERROR_PRIORITY_QUEUE_EMPTY will be raised. - */ -AWS_COMMON_API -int aws_priority_queue_top(const struct aws_priority_queue *queue, void **item); - -/** - * Current number of elements in the queue - */ -AWS_COMMON_API -size_t aws_priority_queue_size(const struct aws_priority_queue *queue); - -/** - * Current allocated capacity for the queue, in dynamic mode this grows over time, in static mode, this will never - * change. - */ -AWS_COMMON_API -size_t aws_priority_queue_capacity(const struct aws_priority_queue *queue); - -AWS_EXTERN_C_END - -#endif /* AWS_COMMON_PRIORITY_QUEUE_H */ + * Set of properties of a valid aws_priority_queue. + */ +AWS_COMMON_API +bool aws_priority_queue_is_valid(const struct aws_priority_queue *const queue); + +/** + * Cleans up any internally allocated memory and resets the struct for reuse or deletion. + */ +AWS_COMMON_API +void aws_priority_queue_clean_up(struct aws_priority_queue *queue); + +/** + * Copies item into the queue and places it in the proper priority order. Complexity: O(log(n)). + */ +AWS_COMMON_API +int aws_priority_queue_push(struct aws_priority_queue *queue, void *item); + +/** + * Copies item into the queue and places it in the proper priority order. Complexity: O(log(n)). + * + * If the backpointer parameter is non-null, the heap will continually update the pointed-to field + * with information needed to remove the node later on. *backpointer must remain valid until the node + * is removed from the heap, and may be updated on any mutating operation on the priority queue. + * + * If the node is removed, the backpointer will be set to a sentinel value that indicates that the + * node has already been removed. It is safe (and a no-op) to call aws_priority_queue_remove with + * such a sentinel value. + */ +AWS_COMMON_API +int aws_priority_queue_push_ref( + struct aws_priority_queue *queue, + void *item, + struct aws_priority_queue_node *backpointer); + +/** + * Copies the element of the highest priority, and removes it from the queue.. Complexity: O(log(n)). + * If queue is empty, AWS_ERROR_PRIORITY_QUEUE_EMPTY will be raised. + */ +AWS_COMMON_API +int aws_priority_queue_pop(struct aws_priority_queue *queue, void *item); + +/** + * Removes a specific node from the priority queue. Complexity: O(log(n)) + * After removing a node (using either _remove or _pop), the backpointer set at push_ref time is set + * to a sentinel value. If this sentinel value is passed to aws_priority_queue_remove, + * AWS_ERROR_PRIORITY_QUEUE_BAD_NODE will be raised. Note, however, that passing uninitialized + * aws_priority_queue_nodes, or ones from different priority queues, results in undefined behavior. + */ +AWS_COMMON_API +int aws_priority_queue_remove(struct aws_priority_queue *queue, void *item, const struct aws_priority_queue_node *node); + +/** + * Obtains a pointer to the element of the highest priority. Complexity: constant time. + * If queue is empty, AWS_ERROR_PRIORITY_QUEUE_EMPTY will be raised. + */ +AWS_COMMON_API +int aws_priority_queue_top(const struct aws_priority_queue *queue, void **item); + +/** + * Current number of elements in the queue + */ +AWS_COMMON_API +size_t aws_priority_queue_size(const struct aws_priority_queue *queue); + +/** + * Current allocated capacity for the queue, in dynamic mode this grows over time, in static mode, this will never + * change. + */ +AWS_COMMON_API +size_t aws_priority_queue_capacity(const struct aws_priority_queue *queue); + +AWS_EXTERN_C_END + +#endif /* AWS_COMMON_PRIORITY_QUEUE_H */ diff --git a/contrib/restricted/aws/aws-c-common/include/aws/common/private/hash_table_impl.h b/contrib/restricted/aws/aws-c-common/include/aws/common/private/hash_table_impl.h index 137a5c5466..86ffb1401f 100644 --- a/contrib/restricted/aws/aws-c-common/include/aws/common/private/hash_table_impl.h +++ b/contrib/restricted/aws/aws-c-common/include/aws/common/private/hash_table_impl.h @@ -1,62 +1,62 @@ -#ifndef AWS_COMMON_PRIVATE_HASH_TABLE_IMPL_H -#define AWS_COMMON_PRIVATE_HASH_TABLE_IMPL_H - +#ifndef AWS_COMMON_PRIVATE_HASH_TABLE_IMPL_H +#define AWS_COMMON_PRIVATE_HASH_TABLE_IMPL_H + /** * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. - */ - -#include <aws/common/common.h> -#include <aws/common/hash_table.h> -#include <aws/common/math.h> - -struct hash_table_entry { - struct aws_hash_element element; - uint64_t hash_code; /* hash code (0 signals empty) */ -}; - -/* Using a flexible array member is the C99 compliant way to have the hash_table_entries - * immediatly follow the struct. - * - * MSVC doesn't know this for some reason so we need to use a pragma to make - * it happy. - */ -#ifdef _MSC_VER -# pragma warning(push) -# pragma warning(disable : 4200) -#endif -struct hash_table_state { - aws_hash_fn *hash_fn; - aws_hash_callback_eq_fn *equals_fn; - aws_hash_callback_destroy_fn *destroy_key_fn; - aws_hash_callback_destroy_fn *destroy_value_fn; - struct aws_allocator *alloc; - - size_t size, entry_count; - size_t max_load; - /* We AND a hash value with mask to get the slot index */ - size_t mask; - double max_load_factor; - /* actually variable length */ - struct hash_table_entry slots[]; -}; -#ifdef _MSC_VER -# pragma warning(pop) -#endif - -/** + */ + +#include <aws/common/common.h> +#include <aws/common/hash_table.h> +#include <aws/common/math.h> + +struct hash_table_entry { + struct aws_hash_element element; + uint64_t hash_code; /* hash code (0 signals empty) */ +}; + +/* Using a flexible array member is the C99 compliant way to have the hash_table_entries + * immediatly follow the struct. + * + * MSVC doesn't know this for some reason so we need to use a pragma to make + * it happy. + */ +#ifdef _MSC_VER +# pragma warning(push) +# pragma warning(disable : 4200) +#endif +struct hash_table_state { + aws_hash_fn *hash_fn; + aws_hash_callback_eq_fn *equals_fn; + aws_hash_callback_destroy_fn *destroy_key_fn; + aws_hash_callback_destroy_fn *destroy_value_fn; + struct aws_allocator *alloc; + + size_t size, entry_count; + size_t max_load; + /* We AND a hash value with mask to get the slot index */ + size_t mask; + double max_load_factor; + /* actually variable length */ + struct hash_table_entry slots[]; +}; +#ifdef _MSC_VER +# pragma warning(pop) +#endif + +/** * Best-effort check of hash_table_state data-structure invariants * Some invariants, such as that the number of entries is actually the - * same as the entry_count field, would require a loop to check - */ + * same as the entry_count field, would require a loop to check + */ bool hash_table_state_is_valid(const struct hash_table_state *map); - -/** - * Determine the total number of bytes needed for a hash-table with - * "size" slots. If the result would overflow a size_t, return - * AWS_OP_ERR; otherwise, return AWS_OP_SUCCESS with the result in - * "required_bytes". - */ + +/** + * Determine the total number of bytes needed for a hash-table with + * "size" slots. If the result would overflow a size_t, return + * AWS_OP_ERR; otherwise, return AWS_OP_SUCCESS with the result in + * "required_bytes". + */ int hash_table_state_required_bytes(size_t size, size_t *required_bytes); - -#endif /* AWS_COMMON_PRIVATE_HASH_TABLE_IMPL_H */ + +#endif /* AWS_COMMON_PRIVATE_HASH_TABLE_IMPL_H */ diff --git a/contrib/restricted/aws/aws-c-common/include/aws/common/rw_lock.h b/contrib/restricted/aws/aws-c-common/include/aws/common/rw_lock.h index f3f551179e..64863d2c28 100644 --- a/contrib/restricted/aws/aws-c-common/include/aws/common/rw_lock.h +++ b/contrib/restricted/aws/aws-c-common/include/aws/common/rw_lock.h @@ -1,69 +1,69 @@ -#ifndef AWS_COMMON_RW_LOCK_H -#define AWS_COMMON_RW_LOCK_H - +#ifndef AWS_COMMON_RW_LOCK_H +#define AWS_COMMON_RW_LOCK_H + /** * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. - */ - -#include <aws/common/common.h> -#ifdef _WIN32 -/* NOTE: Do not use this macro before including Windows.h */ -# define AWSSRW_TO_WINDOWS(pCV) (PSRWLOCK) pCV -#else -# include <pthread.h> -#endif - -struct aws_rw_lock { -#ifdef _WIN32 - void *lock_handle; -#else - pthread_rwlock_t lock_handle; -#endif -}; - -#ifdef _WIN32 -# define AWS_RW_LOCK_INIT \ - { .lock_handle = NULL } -#else -# define AWS_RW_LOCK_INIT \ - { .lock_handle = PTHREAD_RWLOCK_INITIALIZER } -#endif - -AWS_EXTERN_C_BEGIN - -/** - * Initializes a new platform instance of mutex. - */ -AWS_COMMON_API int aws_rw_lock_init(struct aws_rw_lock *lock); - -/** - * Cleans up internal resources. - */ -AWS_COMMON_API void aws_rw_lock_clean_up(struct aws_rw_lock *lock); - -/** - * Blocks until it acquires the lock. While on some platforms such as Windows, - * this may behave as a reentrant mutex, you should not treat it like one. On - * platforms it is possible for it to be non-reentrant, it will be. - */ -AWS_COMMON_API int aws_rw_lock_rlock(struct aws_rw_lock *lock); -AWS_COMMON_API int aws_rw_lock_wlock(struct aws_rw_lock *lock); - -/** - * Attempts to acquire the lock but returns immediately if it can not. - * While on some platforms such as Windows, this may behave as a reentrant mutex, - * you should not treat it like one. On platforms it is possible for it to be non-reentrant, it will be. - */ -AWS_COMMON_API int aws_rw_lock_try_rlock(struct aws_rw_lock *lock); -AWS_COMMON_API int aws_rw_lock_try_wlock(struct aws_rw_lock *lock); - -/** - * Releases the lock. - */ -AWS_COMMON_API int aws_rw_lock_runlock(struct aws_rw_lock *lock); -AWS_COMMON_API int aws_rw_lock_wunlock(struct aws_rw_lock *lock); - -AWS_EXTERN_C_END - -#endif /* AWS_COMMON_RW_LOCK_H */ + */ + +#include <aws/common/common.h> +#ifdef _WIN32 +/* NOTE: Do not use this macro before including Windows.h */ +# define AWSSRW_TO_WINDOWS(pCV) (PSRWLOCK) pCV +#else +# include <pthread.h> +#endif + +struct aws_rw_lock { +#ifdef _WIN32 + void *lock_handle; +#else + pthread_rwlock_t lock_handle; +#endif +}; + +#ifdef _WIN32 +# define AWS_RW_LOCK_INIT \ + { .lock_handle = NULL } +#else +# define AWS_RW_LOCK_INIT \ + { .lock_handle = PTHREAD_RWLOCK_INITIALIZER } +#endif + +AWS_EXTERN_C_BEGIN + +/** + * Initializes a new platform instance of mutex. + */ +AWS_COMMON_API int aws_rw_lock_init(struct aws_rw_lock *lock); + +/** + * Cleans up internal resources. + */ +AWS_COMMON_API void aws_rw_lock_clean_up(struct aws_rw_lock *lock); + +/** + * Blocks until it acquires the lock. While on some platforms such as Windows, + * this may behave as a reentrant mutex, you should not treat it like one. On + * platforms it is possible for it to be non-reentrant, it will be. + */ +AWS_COMMON_API int aws_rw_lock_rlock(struct aws_rw_lock *lock); +AWS_COMMON_API int aws_rw_lock_wlock(struct aws_rw_lock *lock); + +/** + * Attempts to acquire the lock but returns immediately if it can not. + * While on some platforms such as Windows, this may behave as a reentrant mutex, + * you should not treat it like one. On platforms it is possible for it to be non-reentrant, it will be. + */ +AWS_COMMON_API int aws_rw_lock_try_rlock(struct aws_rw_lock *lock); +AWS_COMMON_API int aws_rw_lock_try_wlock(struct aws_rw_lock *lock); + +/** + * Releases the lock. + */ +AWS_COMMON_API int aws_rw_lock_runlock(struct aws_rw_lock *lock); +AWS_COMMON_API int aws_rw_lock_wunlock(struct aws_rw_lock *lock); + +AWS_EXTERN_C_END + +#endif /* AWS_COMMON_RW_LOCK_H */ diff --git a/contrib/restricted/aws/aws-c-common/include/aws/common/string.h b/contrib/restricted/aws/aws-c-common/include/aws/common/string.h index 9e1bb262e1..58eba5baf7 100644 --- a/contrib/restricted/aws/aws-c-common/include/aws/common/string.h +++ b/contrib/restricted/aws/aws-c-common/include/aws/common/string.h @@ -1,119 +1,119 @@ -#ifndef AWS_COMMON_STRING_H -#define AWS_COMMON_STRING_H +#ifndef AWS_COMMON_STRING_H +#define AWS_COMMON_STRING_H /** * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. - */ -#include <aws/common/byte_buf.h> -#include <aws/common/common.h> - -/** - * Represents an immutable string holding either text or binary data. If the - * string is in constant memory or memory that should otherwise not be freed by - * this struct, set allocator to NULL and destroy function will be a no-op. - * - * This is for use cases where the entire struct and the data bytes themselves - * need to be held in dynamic memory, such as when held by a struct - * aws_hash_table. The data bytes themselves are always held in contiguous - * memory immediately after the end of the struct aws_string, and the memory for - * both the header and the data bytes is allocated together. - * - * Use the aws_string_bytes function to access the data bytes. A null byte is - * always included immediately after the data but not counted in the length, so - * that the output of aws_string_bytes can be treated as a C-string in cases - * where none of the the data bytes are null. - * - * Note that the fields of this structure are const; this ensures not only that - * they cannot be modified, but also that you can't assign the structure using - * the = operator accidentally. - */ - -/* Using a flexible array member is the C99 compliant way to have the bytes of - * the string immediately follow the header. - * - * MSVC doesn't know this for some reason so we need to use a pragma to make - * it happy. - */ -#ifdef _MSC_VER -# pragma warning(push) -# pragma warning(disable : 4200) -#endif -struct aws_string { - struct aws_allocator *const allocator; - const size_t len; + */ +#include <aws/common/byte_buf.h> +#include <aws/common/common.h> + +/** + * Represents an immutable string holding either text or binary data. If the + * string is in constant memory or memory that should otherwise not be freed by + * this struct, set allocator to NULL and destroy function will be a no-op. + * + * This is for use cases where the entire struct and the data bytes themselves + * need to be held in dynamic memory, such as when held by a struct + * aws_hash_table. The data bytes themselves are always held in contiguous + * memory immediately after the end of the struct aws_string, and the memory for + * both the header and the data bytes is allocated together. + * + * Use the aws_string_bytes function to access the data bytes. A null byte is + * always included immediately after the data but not counted in the length, so + * that the output of aws_string_bytes can be treated as a C-string in cases + * where none of the the data bytes are null. + * + * Note that the fields of this structure are const; this ensures not only that + * they cannot be modified, but also that you can't assign the structure using + * the = operator accidentally. + */ + +/* Using a flexible array member is the C99 compliant way to have the bytes of + * the string immediately follow the header. + * + * MSVC doesn't know this for some reason so we need to use a pragma to make + * it happy. + */ +#ifdef _MSC_VER +# pragma warning(push) +# pragma warning(disable : 4200) +#endif +struct aws_string { + struct aws_allocator *const allocator; + const size_t len; /* give this a storage specifier for C++ purposes. It will likely be larger after init. */ const uint8_t bytes[1]; -}; -#ifdef _MSC_VER -# pragma warning(pop) -#endif - +}; +#ifdef _MSC_VER +# pragma warning(pop) +#endif + AWS_EXTERN_C_BEGIN - -/** - * Returns true if bytes of string are the same, false otherwise. - */ + +/** + * Returns true if bytes of string are the same, false otherwise. + */ AWS_COMMON_API bool aws_string_eq(const struct aws_string *a, const struct aws_string *b); - -/** - * Returns true if bytes of string are equivalent, using a case-insensitive comparison. - */ + +/** + * Returns true if bytes of string are equivalent, using a case-insensitive comparison. + */ AWS_COMMON_API bool aws_string_eq_ignore_case(const struct aws_string *a, const struct aws_string *b); - -/** - * Returns true if bytes of string and cursor are the same, false otherwise. - */ + +/** + * Returns true if bytes of string and cursor are the same, false otherwise. + */ AWS_COMMON_API bool aws_string_eq_byte_cursor(const struct aws_string *str, const struct aws_byte_cursor *cur); - -/** - * Returns true if bytes of string and cursor are equivalent, using a case-insensitive comparison. - */ + +/** + * Returns true if bytes of string and cursor are equivalent, using a case-insensitive comparison. + */ AWS_COMMON_API bool aws_string_eq_byte_cursor_ignore_case(const struct aws_string *str, const struct aws_byte_cursor *cur); - -/** - * Returns true if bytes of string and buffer are the same, false otherwise. - */ + +/** + * Returns true if bytes of string and buffer are the same, false otherwise. + */ AWS_COMMON_API bool aws_string_eq_byte_buf(const struct aws_string *str, const struct aws_byte_buf *buf); - -/** - * Returns true if bytes of string and buffer are equivalent, using a case-insensitive comparison. - */ + +/** + * Returns true if bytes of string and buffer are equivalent, using a case-insensitive comparison. + */ AWS_COMMON_API bool aws_string_eq_byte_buf_ignore_case(const struct aws_string *str, const struct aws_byte_buf *buf); - + AWS_COMMON_API bool aws_string_eq_c_str(const struct aws_string *str, const char *c_str); - -/** - * Returns true if bytes of strings are equivalent, using a case-insensitive comparison. - */ + +/** + * Returns true if bytes of strings are equivalent, using a case-insensitive comparison. + */ AWS_COMMON_API bool aws_string_eq_c_str_ignore_case(const struct aws_string *str, const char *c_str); - -/** - * Constructor functions which copy data from null-terminated C-string or array of bytes. - */ -AWS_COMMON_API -struct aws_string *aws_string_new_from_c_str(struct aws_allocator *allocator, const char *c_str); + +/** + * Constructor functions which copy data from null-terminated C-string or array of bytes. + */ +AWS_COMMON_API +struct aws_string *aws_string_new_from_c_str(struct aws_allocator *allocator, const char *c_str); /** * Allocate a new string with the same contents as array. */ -AWS_COMMON_API -struct aws_string *aws_string_new_from_array(struct aws_allocator *allocator, const uint8_t *bytes, size_t len); - -/** +AWS_COMMON_API +struct aws_string *aws_string_new_from_array(struct aws_allocator *allocator, const uint8_t *bytes, size_t len); + +/** * Allocate a new string with the same contents as another string. - */ -AWS_COMMON_API -struct aws_string *aws_string_new_from_string(struct aws_allocator *allocator, const struct aws_string *str); - -/** + */ +AWS_COMMON_API +struct aws_string *aws_string_new_from_string(struct aws_allocator *allocator, const struct aws_string *str); + +/** * Allocate a new string with the same contents as cursor. */ AWS_COMMON_API @@ -126,110 +126,110 @@ AWS_COMMON_API struct aws_string *aws_string_new_from_buf(struct aws_allocator *allocator, const struct aws_byte_buf *buf); /** - * Deallocate string. - */ -AWS_COMMON_API -void aws_string_destroy(struct aws_string *str); - -/** - * Zeroes out the data bytes of string and then deallocates the memory. - * Not safe to run on a string created with AWS_STATIC_STRING_FROM_LITERAL. - */ -AWS_COMMON_API -void aws_string_destroy_secure(struct aws_string *str); - -/** - * Compares lexicographical ordering of two strings. This is a binary - * byte-by-byte comparison, treating bytes as unsigned integers. It is suitable - * for either textual or binary data and is unaware of unicode or any other byte - * encoding. If both strings are identical in the bytes of the shorter string, - * then the longer string is lexicographically after the shorter. - * - * Returns a positive number if string a > string b. (i.e., string a is - * lexicographically after string b.) Returns zero if string a = string b. - * Returns negative number if string a < string b. - */ -AWS_COMMON_API -int aws_string_compare(const struct aws_string *a, const struct aws_string *b); - -/** - * A convenience function for sorting lists of (const struct aws_string *) elements. This can be used as a - * comparator for aws_array_list_sort. It is just a simple wrapper around aws_string_compare. - */ -AWS_COMMON_API -int aws_array_list_comparator_string(const void *a, const void *b); - -/** - * Defines a (static const struct aws_string *) with name specified in first - * argument that points to constant memory and has data bytes containing the - * string literal in the second argument. - * - * GCC allows direct initilization of structs with variable length final fields - * However, this might not be portable, so we can do this instead - * This will have to be updated whenever the aws_string structure changes - */ -#define AWS_STATIC_STRING_FROM_LITERAL(name, literal) \ - static const struct { \ - struct aws_allocator *const allocator; \ - const size_t len; \ - const uint8_t bytes[sizeof(literal)]; \ - } name##_s = {NULL, sizeof(literal) - 1, literal}; \ - static const struct aws_string *(name) = (struct aws_string *)(&name##_s) - -/* - * A related macro that declares the string pointer without static, allowing it to be externed as a global constant - */ -#define AWS_STRING_FROM_LITERAL(name, literal) \ - static const struct { \ - struct aws_allocator *const allocator; \ - const size_t len; \ - const uint8_t bytes[sizeof(literal)]; \ - } name##_s = {NULL, sizeof(literal) - 1, literal}; \ - const struct aws_string *(name) = (struct aws_string *)(&name##_s) - -/** - * Copies all bytes from string to buf. - * - * On success, returns true and updates the buf pointer/length - * accordingly. If there is insufficient space in the buf, returns - * false, leaving the buf unchanged. - */ + * Deallocate string. + */ +AWS_COMMON_API +void aws_string_destroy(struct aws_string *str); + +/** + * Zeroes out the data bytes of string and then deallocates the memory. + * Not safe to run on a string created with AWS_STATIC_STRING_FROM_LITERAL. + */ +AWS_COMMON_API +void aws_string_destroy_secure(struct aws_string *str); + +/** + * Compares lexicographical ordering of two strings. This is a binary + * byte-by-byte comparison, treating bytes as unsigned integers. It is suitable + * for either textual or binary data and is unaware of unicode or any other byte + * encoding. If both strings are identical in the bytes of the shorter string, + * then the longer string is lexicographically after the shorter. + * + * Returns a positive number if string a > string b. (i.e., string a is + * lexicographically after string b.) Returns zero if string a = string b. + * Returns negative number if string a < string b. + */ +AWS_COMMON_API +int aws_string_compare(const struct aws_string *a, const struct aws_string *b); + +/** + * A convenience function for sorting lists of (const struct aws_string *) elements. This can be used as a + * comparator for aws_array_list_sort. It is just a simple wrapper around aws_string_compare. + */ +AWS_COMMON_API +int aws_array_list_comparator_string(const void *a, const void *b); + +/** + * Defines a (static const struct aws_string *) with name specified in first + * argument that points to constant memory and has data bytes containing the + * string literal in the second argument. + * + * GCC allows direct initilization of structs with variable length final fields + * However, this might not be portable, so we can do this instead + * This will have to be updated whenever the aws_string structure changes + */ +#define AWS_STATIC_STRING_FROM_LITERAL(name, literal) \ + static const struct { \ + struct aws_allocator *const allocator; \ + const size_t len; \ + const uint8_t bytes[sizeof(literal)]; \ + } name##_s = {NULL, sizeof(literal) - 1, literal}; \ + static const struct aws_string *(name) = (struct aws_string *)(&name##_s) + +/* + * A related macro that declares the string pointer without static, allowing it to be externed as a global constant + */ +#define AWS_STRING_FROM_LITERAL(name, literal) \ + static const struct { \ + struct aws_allocator *const allocator; \ + const size_t len; \ + const uint8_t bytes[sizeof(literal)]; \ + } name##_s = {NULL, sizeof(literal) - 1, literal}; \ + const struct aws_string *(name) = (struct aws_string *)(&name##_s) + +/** + * Copies all bytes from string to buf. + * + * On success, returns true and updates the buf pointer/length + * accordingly. If there is insufficient space in the buf, returns + * false, leaving the buf unchanged. + */ AWS_COMMON_API bool aws_byte_buf_write_from_whole_string( - struct aws_byte_buf *AWS_RESTRICT buf, + struct aws_byte_buf *AWS_RESTRICT buf, const struct aws_string *AWS_RESTRICT src); - -/** - * Creates an aws_byte_cursor from an existing string. - */ + +/** + * Creates an aws_byte_cursor from an existing string. + */ AWS_COMMON_API struct aws_byte_cursor aws_byte_cursor_from_string(const struct aws_string *src); - + /** * If the string was dynamically allocated, clones it. If the string was statically allocated (i.e. has no allocator), * returns the original string. */ AWS_COMMON_API struct aws_string *aws_string_clone_or_reuse(struct aws_allocator *allocator, const struct aws_string *str); - + /* Computes the length of a c string in bytes assuming the character set is either ASCII or UTF-8. If no NULL character * is found within max_read_len of str, AWS_ERROR_C_STRING_BUFFER_NOT_NULL_TERMINATED is raised. Otherwise, str_len * will contain the string length minus the NULL character, and AWS_OP_SUCCESS will be returned. */ AWS_COMMON_API int aws_secure_strlen(const char *str, size_t max_read_len, size_t *str_len); -/** +/** * Equivalent to str->bytes. - */ + */ AWS_STATIC_IMPL const uint8_t *aws_string_bytes(const struct aws_string *str); - -/** + +/** * Equivalent to `(const char *)str->bytes`. - */ + */ AWS_STATIC_IMPL const char *aws_string_c_str(const struct aws_string *str); - + /** * Evaluates the set of properties that define the shape of all valid aws_string structures. * It is also a cheap check, in the sense it run in constant time (i.e., no loops or recursion). @@ -255,4 +255,4 @@ bool aws_char_is_space(uint8_t c); AWS_EXTERN_C_END -#endif /* AWS_COMMON_STRING_H */ +#endif /* AWS_COMMON_STRING_H */ diff --git a/contrib/restricted/aws/aws-c-common/include/aws/common/system_info.h b/contrib/restricted/aws/aws-c-common/include/aws/common/system_info.h index 7ac9be5cf3..4143fed56b 100644 --- a/contrib/restricted/aws/aws-c-common/include/aws/common/system_info.h +++ b/contrib/restricted/aws/aws-c-common/include/aws/common/system_info.h @@ -1,29 +1,29 @@ -#ifndef AWS_COMMON_SYSTEM_INFO_H -#define AWS_COMMON_SYSTEM_INFO_H - +#ifndef AWS_COMMON_SYSTEM_INFO_H +#define AWS_COMMON_SYSTEM_INFO_H + /** * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. - */ - -#include <aws/common/common.h> - + */ + +#include <aws/common/common.h> + enum aws_platform_os { AWS_PLATFORM_OS_WINDOWS, AWS_PLATFORM_OS_MAC, AWS_PLATFORM_OS_UNIX, }; -AWS_EXTERN_C_BEGIN - +AWS_EXTERN_C_BEGIN + /* Returns the OS this was built under */ AWS_COMMON_API enum aws_platform_os aws_get_platform_build_os(void); -/* Returns the number of online processors available for usage. */ -AWS_COMMON_API -size_t aws_system_info_processor_count(void); - +/* Returns the number of online processors available for usage. */ +AWS_COMMON_API +size_t aws_system_info_processor_count(void); + /* Returns true if a debugger is currently attached to the process. */ AWS_COMMON_API bool aws_is_debugger_present(void); @@ -76,6 +76,6 @@ void aws_backtrace_print(FILE *fp, void *call_site_data); AWS_COMMON_API void aws_backtrace_log(void); -AWS_EXTERN_C_END - -#endif /* AWS_COMMON_SYSTEM_INFO_H */ +AWS_EXTERN_C_END + +#endif /* AWS_COMMON_SYSTEM_INFO_H */ diff --git a/contrib/restricted/aws/aws-c-common/include/aws/common/task_scheduler.h b/contrib/restricted/aws/aws-c-common/include/aws/common/task_scheduler.h index 60a9091209..1c78fd3e51 100644 --- a/contrib/restricted/aws/aws-c-common/include/aws/common/task_scheduler.h +++ b/contrib/restricted/aws/aws-c-common/include/aws/common/task_scheduler.h @@ -1,51 +1,51 @@ -#ifndef AWS_COMMON_TASK_SCHEDULER_H -#define AWS_COMMON_TASK_SCHEDULER_H - +#ifndef AWS_COMMON_TASK_SCHEDULER_H +#define AWS_COMMON_TASK_SCHEDULER_H + /** * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. - */ - -#include <aws/common/common.h> -#include <aws/common/linked_list.h> -#include <aws/common/priority_queue.h> - -struct aws_task; - -typedef enum aws_task_status { - AWS_TASK_STATUS_RUN_READY, - AWS_TASK_STATUS_CANCELED, -} aws_task_status; - -/** - * A scheduled function. - */ -typedef void(aws_task_fn)(struct aws_task *task, void *arg, enum aws_task_status); - -/* - * A task object. - * Once added to the scheduler, a task must remain in memory until its function is executed. - */ -struct aws_task { - aws_task_fn *fn; - void *arg; - uint64_t timestamp; - struct aws_linked_list_node node; - struct aws_priority_queue_node priority_queue_node; + */ + +#include <aws/common/common.h> +#include <aws/common/linked_list.h> +#include <aws/common/priority_queue.h> + +struct aws_task; + +typedef enum aws_task_status { + AWS_TASK_STATUS_RUN_READY, + AWS_TASK_STATUS_CANCELED, +} aws_task_status; + +/** + * A scheduled function. + */ +typedef void(aws_task_fn)(struct aws_task *task, void *arg, enum aws_task_status); + +/* + * A task object. + * Once added to the scheduler, a task must remain in memory until its function is executed. + */ +struct aws_task { + aws_task_fn *fn; + void *arg; + uint64_t timestamp; + struct aws_linked_list_node node; + struct aws_priority_queue_node priority_queue_node; const char *type_tag; - size_t reserved; -}; - -struct aws_task_scheduler { - struct aws_allocator *alloc; - struct aws_priority_queue timed_queue; /* Tasks scheduled to run at specific times */ - struct aws_linked_list timed_list; /* If timed_queue runs out of memory, further timed tests are stored here */ - struct aws_linked_list asap_list; /* Tasks scheduled to run as soon as possible */ -}; - -AWS_EXTERN_C_BEGIN - -/** + size_t reserved; +}; + +struct aws_task_scheduler { + struct aws_allocator *alloc; + struct aws_priority_queue timed_queue; /* Tasks scheduled to run at specific times */ + struct aws_linked_list timed_list; /* If timed_queue runs out of memory, further timed tests are stored here */ + struct aws_linked_list asap_list; /* Tasks scheduled to run as soon as possible */ +}; + +AWS_EXTERN_C_BEGIN + +/** * Init an aws_task */ AWS_COMMON_API @@ -58,67 +58,67 @@ AWS_COMMON_API void aws_task_run(struct aws_task *task, enum aws_task_status status); /** - * Initializes a task scheduler instance. - */ -AWS_COMMON_API -int aws_task_scheduler_init(struct aws_task_scheduler *scheduler, struct aws_allocator *alloc); - -/** - * Empties and executes all queued tasks, passing the AWS_TASK_STATUS_CANCELED status to the task function. - * Cleans up any memory allocated, and prepares the instance for reuse or deletion. - */ -AWS_COMMON_API -void aws_task_scheduler_clean_up(struct aws_task_scheduler *scheduler); - + * Initializes a task scheduler instance. + */ +AWS_COMMON_API +int aws_task_scheduler_init(struct aws_task_scheduler *scheduler, struct aws_allocator *alloc); + +/** + * Empties and executes all queued tasks, passing the AWS_TASK_STATUS_CANCELED status to the task function. + * Cleans up any memory allocated, and prepares the instance for reuse or deletion. + */ +AWS_COMMON_API +void aws_task_scheduler_clean_up(struct aws_task_scheduler *scheduler); + AWS_COMMON_API bool aws_task_scheduler_is_valid(const struct aws_task_scheduler *scheduler); -/** - * Returns whether the scheduler has any scheduled tasks. - * next_task_time (optional) will be set to time of the next task, note that 0 will be set if tasks were - * added via aws_task_scheduler_schedule_now() and UINT64_MAX will be set if no tasks are scheduled at all. - */ -AWS_COMMON_API -bool aws_task_scheduler_has_tasks(const struct aws_task_scheduler *scheduler, uint64_t *next_task_time); - -/** - * Schedules a task to run immediately. - * The task should not be cleaned up or modified until its function is executed. - */ -AWS_COMMON_API -void aws_task_scheduler_schedule_now(struct aws_task_scheduler *scheduler, struct aws_task *task); - -/** - * Schedules a task to run at time_to_run. - * The task should not be cleaned up or modified until its function is executed. - */ -AWS_COMMON_API -void aws_task_scheduler_schedule_future( - struct aws_task_scheduler *scheduler, - struct aws_task *task, - uint64_t time_to_run); - -/** - * Removes task from the scheduler and invokes the task with the AWS_TASK_STATUS_CANCELED status. - */ -AWS_COMMON_API -void aws_task_scheduler_cancel_task(struct aws_task_scheduler *scheduler, struct aws_task *task); - -/** - * Sequentially execute all tasks scheduled to run at, or before current_time. - * AWS_TASK_STATUS_RUN_READY will be passed to the task function as the task status. - * - * If a task schedules another task, the new task will not be executed until the next call to this function. - */ -AWS_COMMON_API -void aws_task_scheduler_run_all(struct aws_task_scheduler *scheduler, uint64_t current_time); - +/** + * Returns whether the scheduler has any scheduled tasks. + * next_task_time (optional) will be set to time of the next task, note that 0 will be set if tasks were + * added via aws_task_scheduler_schedule_now() and UINT64_MAX will be set if no tasks are scheduled at all. + */ +AWS_COMMON_API +bool aws_task_scheduler_has_tasks(const struct aws_task_scheduler *scheduler, uint64_t *next_task_time); + +/** + * Schedules a task to run immediately. + * The task should not be cleaned up or modified until its function is executed. + */ +AWS_COMMON_API +void aws_task_scheduler_schedule_now(struct aws_task_scheduler *scheduler, struct aws_task *task); + +/** + * Schedules a task to run at time_to_run. + * The task should not be cleaned up or modified until its function is executed. + */ +AWS_COMMON_API +void aws_task_scheduler_schedule_future( + struct aws_task_scheduler *scheduler, + struct aws_task *task, + uint64_t time_to_run); + +/** + * Removes task from the scheduler and invokes the task with the AWS_TASK_STATUS_CANCELED status. + */ +AWS_COMMON_API +void aws_task_scheduler_cancel_task(struct aws_task_scheduler *scheduler, struct aws_task *task); + +/** + * Sequentially execute all tasks scheduled to run at, or before current_time. + * AWS_TASK_STATUS_RUN_READY will be passed to the task function as the task status. + * + * If a task schedules another task, the new task will not be executed until the next call to this function. + */ +AWS_COMMON_API +void aws_task_scheduler_run_all(struct aws_task_scheduler *scheduler, uint64_t current_time); + /** * Convert a status value to a c-string suitable for logging */ AWS_COMMON_API const char *aws_task_status_to_c_str(enum aws_task_status status); -AWS_EXTERN_C_END - -#endif /* AWS_COMMON_TASK_SCHEDULER_H */ +AWS_EXTERN_C_END + +#endif /* AWS_COMMON_TASK_SCHEDULER_H */ diff --git a/contrib/restricted/aws/aws-c-common/include/aws/common/thread.h b/contrib/restricted/aws/aws-c-common/include/aws/common/thread.h index bbc965d37c..e7abd79f7e 100644 --- a/contrib/restricted/aws/aws-c-common/include/aws/common/thread.h +++ b/contrib/restricted/aws/aws-c-common/include/aws/common/thread.h @@ -1,24 +1,24 @@ -#ifndef AWS_COMMON_THREAD_H -#define AWS_COMMON_THREAD_H - +#ifndef AWS_COMMON_THREAD_H +#define AWS_COMMON_THREAD_H + /** * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. - */ -#include <aws/common/common.h> - -#ifndef _WIN32 -# include <pthread.h> -#endif - -enum aws_thread_detach_state { - AWS_THREAD_NOT_CREATED = 1, - AWS_THREAD_JOINABLE, - AWS_THREAD_JOIN_COMPLETED, -}; - -struct aws_thread_options { - size_t stack_size; + */ +#include <aws/common/common.h> + +#ifndef _WIN32 +# include <pthread.h> +#endif + +enum aws_thread_detach_state { + AWS_THREAD_NOT_CREATED = 1, + AWS_THREAD_JOINABLE, + AWS_THREAD_JOIN_COMPLETED, +}; + +struct aws_thread_options { + size_t stack_size; /* default is -1. If you set this to anything >= 0, and the platform supports it, the thread will be pinned to * that cpu. Also, we assume you're doing this for memory throughput purposes. On unix systems, * If libnuma.so is available, upon the thread launching, the memory policy for that thread will be set to @@ -30,21 +30,21 @@ struct aws_thread_options { * On Apple and Android platforms, this setting doesn't do anything at all. */ int32_t cpu_id; -}; - -#ifdef _WIN32 -typedef union { - void *ptr; -} aws_thread_once; -# define AWS_THREAD_ONCE_STATIC_INIT \ - { NULL } +}; + +#ifdef _WIN32 +typedef union { + void *ptr; +} aws_thread_once; +# define AWS_THREAD_ONCE_STATIC_INIT \ + { NULL } typedef unsigned long aws_thread_id_t; -#else -typedef pthread_once_t aws_thread_once; -# define AWS_THREAD_ONCE_STATIC_INIT PTHREAD_ONCE_INIT +#else +typedef pthread_once_t aws_thread_once; +# define AWS_THREAD_ONCE_STATIC_INIT PTHREAD_ONCE_INIT typedef pthread_t aws_thread_id_t; -#endif - +#endif + /* * Buffer size needed to represent aws_thread_id_t as a string (2 hex chars per byte * plus '\0' terminator). Needed for portable printing because pthread_t is @@ -52,89 +52,89 @@ typedef pthread_t aws_thread_id_t; */ #define AWS_THREAD_ID_T_REPR_BUFSZ (sizeof(aws_thread_id_t) * 2 + 1) -struct aws_thread { - struct aws_allocator *allocator; - enum aws_thread_detach_state detach_state; -#ifdef _WIN32 - void *thread_handle; -#endif +struct aws_thread { + struct aws_allocator *allocator; + enum aws_thread_detach_state detach_state; +#ifdef _WIN32 + void *thread_handle; +#endif aws_thread_id_t thread_id; -}; - -AWS_EXTERN_C_BEGIN - -/** - * Returns an instance of system default thread options. - */ -AWS_COMMON_API -const struct aws_thread_options *aws_default_thread_options(void); - +}; + +AWS_EXTERN_C_BEGIN + +/** + * Returns an instance of system default thread options. + */ +AWS_COMMON_API +const struct aws_thread_options *aws_default_thread_options(void); + AWS_COMMON_API void aws_thread_call_once(aws_thread_once *flag, void (*call_once)(void *), void *user_data); - -/** - * Initializes a new platform specific thread object struct (not the os-level - * thread itself). - */ -AWS_COMMON_API -int aws_thread_init(struct aws_thread *thread, struct aws_allocator *allocator); - -/** - * Creates an OS level thread and associates it with func. context will be passed to func when it is executed. - * options will be applied to the thread if they are applicable for the platform. - * You must either call join or detach after creating the thread and before calling clean_up. - */ -AWS_COMMON_API -int aws_thread_launch( - struct aws_thread *thread, - void (*func)(void *arg), - void *arg, - const struct aws_thread_options *options); - -/** - * Gets the id of thread - */ -AWS_COMMON_API + +/** + * Initializes a new platform specific thread object struct (not the os-level + * thread itself). + */ +AWS_COMMON_API +int aws_thread_init(struct aws_thread *thread, struct aws_allocator *allocator); + +/** + * Creates an OS level thread and associates it with func. context will be passed to func when it is executed. + * options will be applied to the thread if they are applicable for the platform. + * You must either call join or detach after creating the thread and before calling clean_up. + */ +AWS_COMMON_API +int aws_thread_launch( + struct aws_thread *thread, + void (*func)(void *arg), + void *arg, + const struct aws_thread_options *options); + +/** + * Gets the id of thread + */ +AWS_COMMON_API aws_thread_id_t aws_thread_get_id(struct aws_thread *thread); - -/** - * Gets the detach state of the thread. For example, is it safe to call join on - * this thread? Has it been detached()? - */ -AWS_COMMON_API -enum aws_thread_detach_state aws_thread_get_detach_state(struct aws_thread *thread); - -/** - * Joins the calling thread to a thread instance. Returns when thread is - * finished. - */ -AWS_COMMON_API -int aws_thread_join(struct aws_thread *thread); - -/** - * Cleans up the thread handle. Either detach or join must be called - * before calling this function. - */ -AWS_COMMON_API -void aws_thread_clean_up(struct aws_thread *thread); - -/** + +/** + * Gets the detach state of the thread. For example, is it safe to call join on + * this thread? Has it been detached()? + */ +AWS_COMMON_API +enum aws_thread_detach_state aws_thread_get_detach_state(struct aws_thread *thread); + +/** + * Joins the calling thread to a thread instance. Returns when thread is + * finished. + */ +AWS_COMMON_API +int aws_thread_join(struct aws_thread *thread); + +/** + * Cleans up the thread handle. Either detach or join must be called + * before calling this function. + */ +AWS_COMMON_API +void aws_thread_clean_up(struct aws_thread *thread); + +/** * Returns the thread id of the calling thread. - */ -AWS_COMMON_API + */ +AWS_COMMON_API aws_thread_id_t aws_thread_current_thread_id(void); - -/** + +/** * Compare thread ids. */ AWS_COMMON_API bool aws_thread_thread_id_equal(aws_thread_id_t t1, aws_thread_id_t t2); /** - * Sleeps the current thread by nanos. - */ -AWS_COMMON_API -void aws_thread_current_sleep(uint64_t nanos); - + * Sleeps the current thread by nanos. + */ +AWS_COMMON_API +void aws_thread_current_sleep(uint64_t nanos); + typedef void(aws_thread_atexit_fn)(void *user_data); /** @@ -146,6 +146,6 @@ typedef void(aws_thread_atexit_fn)(void *user_data); AWS_COMMON_API int aws_thread_current_at_exit(aws_thread_atexit_fn *callback, void *user_data); -AWS_EXTERN_C_END - -#endif /* AWS_COMMON_THREAD_H */ +AWS_EXTERN_C_END + +#endif /* AWS_COMMON_THREAD_H */ diff --git a/contrib/restricted/aws/aws-c-common/include/aws/common/time.h b/contrib/restricted/aws/aws-c-common/include/aws/common/time.h index d008a2ce80..6ea6c9c757 100644 --- a/contrib/restricted/aws/aws-c-common/include/aws/common/time.h +++ b/contrib/restricted/aws/aws-c-common/include/aws/common/time.h @@ -1,30 +1,30 @@ -#ifndef AWS_COMMON_TIME_H -#define AWS_COMMON_TIME_H +#ifndef AWS_COMMON_TIME_H +#define AWS_COMMON_TIME_H /** * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. - */ -#include <aws/common/common.h> - -#include <time.h> - -AWS_EXTERN_C_BEGIN - -/** - * Cross platform friendly version of timegm - */ -AWS_COMMON_API time_t aws_timegm(struct tm *const t); - -/** - * Cross platform friendly version of localtime_r - */ -AWS_COMMON_API void aws_localtime(time_t time, struct tm *t); - -/** - * Cross platform friendly version of gmtime_r - */ -AWS_COMMON_API void aws_gmtime(time_t time, struct tm *t); - -AWS_EXTERN_C_END - + */ +#include <aws/common/common.h> + +#include <time.h> + +AWS_EXTERN_C_BEGIN + +/** + * Cross platform friendly version of timegm + */ +AWS_COMMON_API time_t aws_timegm(struct tm *const t); + +/** + * Cross platform friendly version of localtime_r + */ +AWS_COMMON_API void aws_localtime(time_t time, struct tm *t); + +/** + * Cross platform friendly version of gmtime_r + */ +AWS_COMMON_API void aws_gmtime(time_t time, struct tm *t); + +AWS_EXTERN_C_END + #endif /* AWS_COMMON_TIME_H */ diff --git a/contrib/restricted/aws/aws-c-common/include/aws/common/uuid.h b/contrib/restricted/aws/aws-c-common/include/aws/common/uuid.h index 83a91457b3..a8677c5814 100644 --- a/contrib/restricted/aws/aws-c-common/include/aws/common/uuid.h +++ b/contrib/restricted/aws/aws-c-common/include/aws/common/uuid.h @@ -1,29 +1,29 @@ -#ifndef AWS_COMMON_UUID_H -#define AWS_COMMON_UUID_H - +#ifndef AWS_COMMON_UUID_H +#define AWS_COMMON_UUID_H + /** * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. - */ -#include <aws/common/common.h> - -struct aws_byte_cursor; -struct aws_byte_buf; - -struct aws_uuid { - uint8_t uuid_data[16]; -}; - -/* 36 bytes for the UUID plus one more for the null terminator. */ -#define AWS_UUID_STR_LEN 37 - -AWS_EXTERN_C_BEGIN - -AWS_COMMON_API int aws_uuid_init(struct aws_uuid *uuid); -AWS_COMMON_API int aws_uuid_init_from_str(struct aws_uuid *uuid, const struct aws_byte_cursor *uuid_str); -AWS_COMMON_API int aws_uuid_to_str(const struct aws_uuid *uuid, struct aws_byte_buf *output); -AWS_COMMON_API bool aws_uuid_equals(const struct aws_uuid *a, const struct aws_uuid *b); - -AWS_EXTERN_C_END - -#endif /* AWS_COMMON_UUID_H */ + */ +#include <aws/common/common.h> + +struct aws_byte_cursor; +struct aws_byte_buf; + +struct aws_uuid { + uint8_t uuid_data[16]; +}; + +/* 36 bytes for the UUID plus one more for the null terminator. */ +#define AWS_UUID_STR_LEN 37 + +AWS_EXTERN_C_BEGIN + +AWS_COMMON_API int aws_uuid_init(struct aws_uuid *uuid); +AWS_COMMON_API int aws_uuid_init_from_str(struct aws_uuid *uuid, const struct aws_byte_cursor *uuid_str); +AWS_COMMON_API int aws_uuid_to_str(const struct aws_uuid *uuid, struct aws_byte_buf *output); +AWS_COMMON_API bool aws_uuid_equals(const struct aws_uuid *a, const struct aws_uuid *b); + +AWS_EXTERN_C_END + +#endif /* AWS_COMMON_UUID_H */ diff --git a/contrib/restricted/aws/aws-c-common/source/array_list.c b/contrib/restricted/aws/aws-c-common/source/array_list.c index cfcd7d2db2..7e05636a75 100644 --- a/contrib/restricted/aws/aws-c-common/source/array_list.c +++ b/contrib/restricted/aws/aws-c-common/source/array_list.c @@ -1,13 +1,13 @@ /** * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. - */ - -#include <aws/common/array_list.h> + */ + +#include <aws/common/array_list.h> #include <aws/common/private/array_list.h> - -#include <stdlib.h> /* qsort */ - + +#include <stdlib.h> /* qsort */ + int aws_array_list_calc_necessary_size(struct aws_array_list *AWS_RESTRICT list, size_t index, size_t *necessary_size) { AWS_PRECONDITION(aws_array_list_is_valid(list)); size_t index_inc; @@ -24,184 +24,184 @@ int aws_array_list_calc_necessary_size(struct aws_array_list *AWS_RESTRICT list, return AWS_OP_SUCCESS; } -int aws_array_list_shrink_to_fit(struct aws_array_list *AWS_RESTRICT list) { - AWS_PRECONDITION(aws_array_list_is_valid(list)); - if (list->alloc) { - size_t ideal_size; - if (aws_mul_size_checked(list->length, list->item_size, &ideal_size)) { - AWS_POSTCONDITION(aws_array_list_is_valid(list)); - return AWS_OP_ERR; - } - - if (ideal_size < list->current_size) { - void *raw_data = NULL; - - if (ideal_size > 0) { - raw_data = aws_mem_acquire(list->alloc, ideal_size); - if (!raw_data) { - AWS_POSTCONDITION(aws_array_list_is_valid(list)); - return AWS_OP_ERR; - } - - memcpy(raw_data, list->data, ideal_size); - aws_mem_release(list->alloc, list->data); - } - list->data = raw_data; - list->current_size = ideal_size; - } - AWS_POSTCONDITION(aws_array_list_is_valid(list)); - return AWS_OP_SUCCESS; - } - - AWS_POSTCONDITION(aws_array_list_is_valid(list)); - return aws_raise_error(AWS_ERROR_LIST_STATIC_MODE_CANT_SHRINK); -} - -int aws_array_list_copy(const struct aws_array_list *AWS_RESTRICT from, struct aws_array_list *AWS_RESTRICT to) { +int aws_array_list_shrink_to_fit(struct aws_array_list *AWS_RESTRICT list) { + AWS_PRECONDITION(aws_array_list_is_valid(list)); + if (list->alloc) { + size_t ideal_size; + if (aws_mul_size_checked(list->length, list->item_size, &ideal_size)) { + AWS_POSTCONDITION(aws_array_list_is_valid(list)); + return AWS_OP_ERR; + } + + if (ideal_size < list->current_size) { + void *raw_data = NULL; + + if (ideal_size > 0) { + raw_data = aws_mem_acquire(list->alloc, ideal_size); + if (!raw_data) { + AWS_POSTCONDITION(aws_array_list_is_valid(list)); + return AWS_OP_ERR; + } + + memcpy(raw_data, list->data, ideal_size); + aws_mem_release(list->alloc, list->data); + } + list->data = raw_data; + list->current_size = ideal_size; + } + AWS_POSTCONDITION(aws_array_list_is_valid(list)); + return AWS_OP_SUCCESS; + } + + AWS_POSTCONDITION(aws_array_list_is_valid(list)); + return aws_raise_error(AWS_ERROR_LIST_STATIC_MODE_CANT_SHRINK); +} + +int aws_array_list_copy(const struct aws_array_list *AWS_RESTRICT from, struct aws_array_list *AWS_RESTRICT to) { AWS_FATAL_PRECONDITION(from->item_size == to->item_size); AWS_FATAL_PRECONDITION(from->data); - AWS_PRECONDITION(aws_array_list_is_valid(from)); - AWS_PRECONDITION(aws_array_list_is_valid(to)); - - size_t copy_size; - if (aws_mul_size_checked(from->length, from->item_size, ©_size)) { - AWS_POSTCONDITION(aws_array_list_is_valid(from)); - AWS_POSTCONDITION(aws_array_list_is_valid(to)); - return AWS_OP_ERR; - } - - if (to->current_size >= copy_size) { - if (copy_size > 0) { - memcpy(to->data, from->data, copy_size); - } - to->length = from->length; - AWS_POSTCONDITION(aws_array_list_is_valid(from)); - AWS_POSTCONDITION(aws_array_list_is_valid(to)); - return AWS_OP_SUCCESS; - } - /* if to is in dynamic mode, we can just reallocate it and copy */ - if (to->alloc != NULL) { - void *tmp = aws_mem_acquire(to->alloc, copy_size); - - if (!tmp) { - AWS_POSTCONDITION(aws_array_list_is_valid(from)); - AWS_POSTCONDITION(aws_array_list_is_valid(to)); - return AWS_OP_ERR; - } - - memcpy(tmp, from->data, copy_size); - if (to->data) { - aws_mem_release(to->alloc, to->data); - } - - to->data = tmp; - to->length = from->length; - to->current_size = copy_size; - AWS_POSTCONDITION(aws_array_list_is_valid(from)); - AWS_POSTCONDITION(aws_array_list_is_valid(to)); - return AWS_OP_SUCCESS; - } - - return aws_raise_error(AWS_ERROR_DEST_COPY_TOO_SMALL); -} - -int aws_array_list_ensure_capacity(struct aws_array_list *AWS_RESTRICT list, size_t index) { - AWS_PRECONDITION(aws_array_list_is_valid(list)); - size_t necessary_size; - if (aws_array_list_calc_necessary_size(list, index, &necessary_size)) { - AWS_POSTCONDITION(aws_array_list_is_valid(list)); - return AWS_OP_ERR; - } - - if (list->current_size < necessary_size) { - if (!list->alloc) { - AWS_POSTCONDITION(aws_array_list_is_valid(list)); - return aws_raise_error(AWS_ERROR_INVALID_INDEX); - } - - /* this will double capacity if the index isn't bigger than what the - * next allocation would be, but allocates the exact requested size if - * it is. This is largely because we don't have a good way to predict - * the usage pattern to make a smart decision about it. However, if the - * user - * is doing this in an iterative fashion, necessary_size will never be - * used.*/ - size_t next_allocation_size = list->current_size << 1; - size_t new_size = next_allocation_size > necessary_size ? next_allocation_size : necessary_size; - - if (new_size < list->current_size) { - /* this means new_size overflowed. The only way this happens is on a - * 32-bit system where size_t is 32 bits, in which case we're out of - * addressable memory anyways, or we're on a 64 bit system and we're - * most certainly out of addressable memory. But since we're simply - * going to fail fast and say, sorry can't do it, we'll just tell - * the user they can't grow the list anymore. */ - AWS_POSTCONDITION(aws_array_list_is_valid(list)); - return aws_raise_error(AWS_ERROR_LIST_EXCEEDS_MAX_SIZE); - } - - void *temp = aws_mem_acquire(list->alloc, new_size); - - if (!temp) { - AWS_POSTCONDITION(aws_array_list_is_valid(list)); - return AWS_OP_ERR; - } - - if (list->data) { - memcpy(temp, list->data, list->current_size); - -#ifdef DEBUG_BUILD - memset( - (void *)((uint8_t *)temp + list->current_size), - AWS_ARRAY_LIST_DEBUG_FILL, - new_size - list->current_size); -#endif - aws_mem_release(list->alloc, list->data); - } - list->data = temp; - list->current_size = new_size; - } - - AWS_POSTCONDITION(aws_array_list_is_valid(list)); - return AWS_OP_SUCCESS; -} - -static void aws_array_list_mem_swap(void *AWS_RESTRICT item1, void *AWS_RESTRICT item2, size_t item_size) { - enum { SLICE = 128 }; - + AWS_PRECONDITION(aws_array_list_is_valid(from)); + AWS_PRECONDITION(aws_array_list_is_valid(to)); + + size_t copy_size; + if (aws_mul_size_checked(from->length, from->item_size, ©_size)) { + AWS_POSTCONDITION(aws_array_list_is_valid(from)); + AWS_POSTCONDITION(aws_array_list_is_valid(to)); + return AWS_OP_ERR; + } + + if (to->current_size >= copy_size) { + if (copy_size > 0) { + memcpy(to->data, from->data, copy_size); + } + to->length = from->length; + AWS_POSTCONDITION(aws_array_list_is_valid(from)); + AWS_POSTCONDITION(aws_array_list_is_valid(to)); + return AWS_OP_SUCCESS; + } + /* if to is in dynamic mode, we can just reallocate it and copy */ + if (to->alloc != NULL) { + void *tmp = aws_mem_acquire(to->alloc, copy_size); + + if (!tmp) { + AWS_POSTCONDITION(aws_array_list_is_valid(from)); + AWS_POSTCONDITION(aws_array_list_is_valid(to)); + return AWS_OP_ERR; + } + + memcpy(tmp, from->data, copy_size); + if (to->data) { + aws_mem_release(to->alloc, to->data); + } + + to->data = tmp; + to->length = from->length; + to->current_size = copy_size; + AWS_POSTCONDITION(aws_array_list_is_valid(from)); + AWS_POSTCONDITION(aws_array_list_is_valid(to)); + return AWS_OP_SUCCESS; + } + + return aws_raise_error(AWS_ERROR_DEST_COPY_TOO_SMALL); +} + +int aws_array_list_ensure_capacity(struct aws_array_list *AWS_RESTRICT list, size_t index) { + AWS_PRECONDITION(aws_array_list_is_valid(list)); + size_t necessary_size; + if (aws_array_list_calc_necessary_size(list, index, &necessary_size)) { + AWS_POSTCONDITION(aws_array_list_is_valid(list)); + return AWS_OP_ERR; + } + + if (list->current_size < necessary_size) { + if (!list->alloc) { + AWS_POSTCONDITION(aws_array_list_is_valid(list)); + return aws_raise_error(AWS_ERROR_INVALID_INDEX); + } + + /* this will double capacity if the index isn't bigger than what the + * next allocation would be, but allocates the exact requested size if + * it is. This is largely because we don't have a good way to predict + * the usage pattern to make a smart decision about it. However, if the + * user + * is doing this in an iterative fashion, necessary_size will never be + * used.*/ + size_t next_allocation_size = list->current_size << 1; + size_t new_size = next_allocation_size > necessary_size ? next_allocation_size : necessary_size; + + if (new_size < list->current_size) { + /* this means new_size overflowed. The only way this happens is on a + * 32-bit system where size_t is 32 bits, in which case we're out of + * addressable memory anyways, or we're on a 64 bit system and we're + * most certainly out of addressable memory. But since we're simply + * going to fail fast and say, sorry can't do it, we'll just tell + * the user they can't grow the list anymore. */ + AWS_POSTCONDITION(aws_array_list_is_valid(list)); + return aws_raise_error(AWS_ERROR_LIST_EXCEEDS_MAX_SIZE); + } + + void *temp = aws_mem_acquire(list->alloc, new_size); + + if (!temp) { + AWS_POSTCONDITION(aws_array_list_is_valid(list)); + return AWS_OP_ERR; + } + + if (list->data) { + memcpy(temp, list->data, list->current_size); + +#ifdef DEBUG_BUILD + memset( + (void *)((uint8_t *)temp + list->current_size), + AWS_ARRAY_LIST_DEBUG_FILL, + new_size - list->current_size); +#endif + aws_mem_release(list->alloc, list->data); + } + list->data = temp; + list->current_size = new_size; + } + + AWS_POSTCONDITION(aws_array_list_is_valid(list)); + return AWS_OP_SUCCESS; +} + +static void aws_array_list_mem_swap(void *AWS_RESTRICT item1, void *AWS_RESTRICT item2, size_t item_size) { + enum { SLICE = 128 }; + AWS_FATAL_PRECONDITION(item1); AWS_FATAL_PRECONDITION(item2); - - /* copy SLICE sized bytes at a time */ - size_t slice_count = item_size / SLICE; - uint8_t temp[SLICE]; - for (size_t i = 0; i < slice_count; i++) { - memcpy((void *)temp, (void *)item1, SLICE); - memcpy((void *)item1, (void *)item2, SLICE); - memcpy((void *)item2, (void *)temp, SLICE); - item1 = (uint8_t *)item1 + SLICE; - item2 = (uint8_t *)item2 + SLICE; - } - - size_t remainder = item_size & (SLICE - 1); /* item_size % SLICE */ - memcpy((void *)temp, (void *)item1, remainder); - memcpy((void *)item1, (void *)item2, remainder); - memcpy((void *)item2, (void *)temp, remainder); -} - -void aws_array_list_swap(struct aws_array_list *AWS_RESTRICT list, size_t a, size_t b) { + + /* copy SLICE sized bytes at a time */ + size_t slice_count = item_size / SLICE; + uint8_t temp[SLICE]; + for (size_t i = 0; i < slice_count; i++) { + memcpy((void *)temp, (void *)item1, SLICE); + memcpy((void *)item1, (void *)item2, SLICE); + memcpy((void *)item2, (void *)temp, SLICE); + item1 = (uint8_t *)item1 + SLICE; + item2 = (uint8_t *)item2 + SLICE; + } + + size_t remainder = item_size & (SLICE - 1); /* item_size % SLICE */ + memcpy((void *)temp, (void *)item1, remainder); + memcpy((void *)item1, (void *)item2, remainder); + memcpy((void *)item2, (void *)temp, remainder); +} + +void aws_array_list_swap(struct aws_array_list *AWS_RESTRICT list, size_t a, size_t b) { AWS_FATAL_PRECONDITION(a < list->length); AWS_FATAL_PRECONDITION(b < list->length); - AWS_PRECONDITION(aws_array_list_is_valid(list)); - - if (a == b) { - AWS_POSTCONDITION(aws_array_list_is_valid(list)); - return; - } - - void *item1 = NULL, *item2 = NULL; - aws_array_list_get_at_ptr(list, &item1, a); - aws_array_list_get_at_ptr(list, &item2, b); - aws_array_list_mem_swap(item1, item2, list->item_size); - AWS_POSTCONDITION(aws_array_list_is_valid(list)); -} + AWS_PRECONDITION(aws_array_list_is_valid(list)); + + if (a == b) { + AWS_POSTCONDITION(aws_array_list_is_valid(list)); + return; + } + + void *item1 = NULL, *item2 = NULL; + aws_array_list_get_at_ptr(list, &item1, a); + aws_array_list_get_at_ptr(list, &item2, b); + aws_array_list_mem_swap(item1, item2, list->item_size); + AWS_POSTCONDITION(aws_array_list_is_valid(list)); +} diff --git a/contrib/restricted/aws/aws-c-common/source/assert.c b/contrib/restricted/aws/aws-c-common/source/assert.c index adfc4c408a..9aaae9a19e 100644 --- a/contrib/restricted/aws/aws-c-common/source/assert.c +++ b/contrib/restricted/aws/aws-c-common/source/assert.c @@ -1,18 +1,18 @@ /** * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. - */ - -#include <aws/common/common.h> - + */ + +#include <aws/common/common.h> + #include <aws/common/system_info.h> -#include <stdio.h> -#include <stdlib.h> - -void aws_fatal_assert(const char *cond_str, const char *file, int line) { - aws_debug_break(); - fprintf(stderr, "Fatal error condition occurred in %s:%d: %s\nExiting Application\n", file, line, cond_str); - aws_backtrace_print(stderr, NULL); - abort(); -} +#include <stdio.h> +#include <stdlib.h> + +void aws_fatal_assert(const char *cond_str, const char *file, int line) { + aws_debug_break(); + fprintf(stderr, "Fatal error condition occurred in %s:%d: %s\nExiting Application\n", file, line, cond_str); + aws_backtrace_print(stderr, NULL); + abort(); +} diff --git a/contrib/restricted/aws/aws-c-common/source/byte_buf.c b/contrib/restricted/aws/aws-c-common/source/byte_buf.c index 4b2cf1d279..ca18f4121b 100644 --- a/contrib/restricted/aws/aws-c-common/source/byte_buf.c +++ b/contrib/restricted/aws/aws-c-common/source/byte_buf.c @@ -1,71 +1,71 @@ /** * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. - */ - -#include <aws/common/byte_buf.h> + */ + +#include <aws/common/byte_buf.h> #include <aws/common/private/byte_buf.h> - -#include <stdarg.h> - -#ifdef _MSC_VER -/* disables warning non const declared initializers for Microsoft compilers */ -# pragma warning(disable : 4204) -# pragma warning(disable : 4706) -#endif - -int aws_byte_buf_init(struct aws_byte_buf *buf, struct aws_allocator *allocator, size_t capacity) { + +#include <stdarg.h> + +#ifdef _MSC_VER +/* disables warning non const declared initializers for Microsoft compilers */ +# pragma warning(disable : 4204) +# pragma warning(disable : 4706) +#endif + +int aws_byte_buf_init(struct aws_byte_buf *buf, struct aws_allocator *allocator, size_t capacity) { AWS_PRECONDITION(buf); AWS_PRECONDITION(allocator); - - buf->buffer = (capacity == 0) ? NULL : aws_mem_acquire(allocator, capacity); - if (capacity != 0 && buf->buffer == NULL) { + + buf->buffer = (capacity == 0) ? NULL : aws_mem_acquire(allocator, capacity); + if (capacity != 0 && buf->buffer == NULL) { AWS_ZERO_STRUCT(*buf); - return AWS_OP_ERR; - } - - buf->len = 0; - buf->capacity = capacity; - buf->allocator = allocator; - AWS_POSTCONDITION(aws_byte_buf_is_valid(buf)); - return AWS_OP_SUCCESS; -} - -int aws_byte_buf_init_copy(struct aws_byte_buf *dest, struct aws_allocator *allocator, const struct aws_byte_buf *src) { + return AWS_OP_ERR; + } + + buf->len = 0; + buf->capacity = capacity; + buf->allocator = allocator; + AWS_POSTCONDITION(aws_byte_buf_is_valid(buf)); + return AWS_OP_SUCCESS; +} + +int aws_byte_buf_init_copy(struct aws_byte_buf *dest, struct aws_allocator *allocator, const struct aws_byte_buf *src) { AWS_PRECONDITION(allocator); AWS_PRECONDITION(dest); AWS_ERROR_PRECONDITION(aws_byte_buf_is_valid(src)); - - if (!src->buffer) { - AWS_ZERO_STRUCT(*dest); - dest->allocator = allocator; - AWS_POSTCONDITION(aws_byte_buf_is_valid(dest)); - return AWS_OP_SUCCESS; - } - - *dest = *src; - dest->allocator = allocator; - dest->buffer = (uint8_t *)aws_mem_acquire(allocator, src->capacity); - if (dest->buffer == NULL) { - AWS_ZERO_STRUCT(*dest); - return AWS_OP_ERR; - } - memcpy(dest->buffer, src->buffer, src->len); - AWS_POSTCONDITION(aws_byte_buf_is_valid(dest)); - return AWS_OP_SUCCESS; -} - -bool aws_byte_buf_is_valid(const struct aws_byte_buf *const buf) { + + if (!src->buffer) { + AWS_ZERO_STRUCT(*dest); + dest->allocator = allocator; + AWS_POSTCONDITION(aws_byte_buf_is_valid(dest)); + return AWS_OP_SUCCESS; + } + + *dest = *src; + dest->allocator = allocator; + dest->buffer = (uint8_t *)aws_mem_acquire(allocator, src->capacity); + if (dest->buffer == NULL) { + AWS_ZERO_STRUCT(*dest); + return AWS_OP_ERR; + } + memcpy(dest->buffer, src->buffer, src->len); + AWS_POSTCONDITION(aws_byte_buf_is_valid(dest)); + return AWS_OP_SUCCESS; +} + +bool aws_byte_buf_is_valid(const struct aws_byte_buf *const buf) { return buf != NULL && ((buf->capacity == 0 && buf->len == 0 && buf->buffer == NULL) || (buf->capacity > 0 && buf->len <= buf->capacity && AWS_MEM_IS_WRITABLE(buf->buffer, buf->capacity))); -} - -bool aws_byte_cursor_is_valid(const struct aws_byte_cursor *cursor) { +} + +bool aws_byte_cursor_is_valid(const struct aws_byte_cursor *cursor) { return cursor != NULL && ((cursor->len == 0) || (cursor->len > 0 && cursor->ptr && AWS_MEM_IS_READABLE(cursor->ptr, cursor->len))); -} - +} + void aws_byte_buf_reset(struct aws_byte_buf *buf, bool zero_contents) { if (zero_contents) { aws_byte_buf_secure_zero(buf); @@ -73,33 +73,33 @@ void aws_byte_buf_reset(struct aws_byte_buf *buf, bool zero_contents) { buf->len = 0; } -void aws_byte_buf_clean_up(struct aws_byte_buf *buf) { - AWS_PRECONDITION(aws_byte_buf_is_valid(buf)); - if (buf->allocator && buf->buffer) { - aws_mem_release(buf->allocator, (void *)buf->buffer); - } - buf->allocator = NULL; - buf->buffer = NULL; - buf->len = 0; - buf->capacity = 0; -} - -void aws_byte_buf_secure_zero(struct aws_byte_buf *buf) { - AWS_PRECONDITION(aws_byte_buf_is_valid(buf)); - if (buf->buffer) { - aws_secure_zero(buf->buffer, buf->capacity); - } - buf->len = 0; - AWS_POSTCONDITION(aws_byte_buf_is_valid(buf)); -} - -void aws_byte_buf_clean_up_secure(struct aws_byte_buf *buf) { +void aws_byte_buf_clean_up(struct aws_byte_buf *buf) { + AWS_PRECONDITION(aws_byte_buf_is_valid(buf)); + if (buf->allocator && buf->buffer) { + aws_mem_release(buf->allocator, (void *)buf->buffer); + } + buf->allocator = NULL; + buf->buffer = NULL; + buf->len = 0; + buf->capacity = 0; +} + +void aws_byte_buf_secure_zero(struct aws_byte_buf *buf) { AWS_PRECONDITION(aws_byte_buf_is_valid(buf)); - aws_byte_buf_secure_zero(buf); - aws_byte_buf_clean_up(buf); + if (buf->buffer) { + aws_secure_zero(buf->buffer, buf->capacity); + } + buf->len = 0; AWS_POSTCONDITION(aws_byte_buf_is_valid(buf)); -} - +} + +void aws_byte_buf_clean_up_secure(struct aws_byte_buf *buf) { + AWS_PRECONDITION(aws_byte_buf_is_valid(buf)); + aws_byte_buf_secure_zero(buf); + aws_byte_buf_clean_up(buf); + AWS_POSTCONDITION(aws_byte_buf_is_valid(buf)); +} + bool aws_byte_buf_eq(const struct aws_byte_buf *const a, const struct aws_byte_buf *const b) { AWS_PRECONDITION(aws_byte_buf_is_valid(a)); AWS_PRECONDITION(aws_byte_buf_is_valid(b)); @@ -107,8 +107,8 @@ bool aws_byte_buf_eq(const struct aws_byte_buf *const a, const struct aws_byte_b AWS_POSTCONDITION(aws_byte_buf_is_valid(a)); AWS_POSTCONDITION(aws_byte_buf_is_valid(b)); return rval; -} - +} + bool aws_byte_buf_eq_ignore_case(const struct aws_byte_buf *const a, const struct aws_byte_buf *const b) { AWS_PRECONDITION(aws_byte_buf_is_valid(a)); AWS_PRECONDITION(aws_byte_buf_is_valid(b)); @@ -116,49 +116,49 @@ bool aws_byte_buf_eq_ignore_case(const struct aws_byte_buf *const a, const struc AWS_POSTCONDITION(aws_byte_buf_is_valid(a)); AWS_POSTCONDITION(aws_byte_buf_is_valid(b)); return rval; -} - +} + bool aws_byte_buf_eq_c_str(const struct aws_byte_buf *const buf, const char *const c_str) { AWS_PRECONDITION(aws_byte_buf_is_valid(buf)); AWS_PRECONDITION(c_str != NULL); bool rval = aws_array_eq_c_str(buf->buffer, buf->len, c_str); AWS_POSTCONDITION(aws_byte_buf_is_valid(buf)); return rval; -} - +} + bool aws_byte_buf_eq_c_str_ignore_case(const struct aws_byte_buf *const buf, const char *const c_str) { AWS_PRECONDITION(aws_byte_buf_is_valid(buf)); AWS_PRECONDITION(c_str != NULL); bool rval = aws_array_eq_c_str_ignore_case(buf->buffer, buf->len, c_str); AWS_POSTCONDITION(aws_byte_buf_is_valid(buf)); return rval; -} - -int aws_byte_buf_init_copy_from_cursor( - struct aws_byte_buf *dest, - struct aws_allocator *allocator, - struct aws_byte_cursor src) { +} + +int aws_byte_buf_init_copy_from_cursor( + struct aws_byte_buf *dest, + struct aws_allocator *allocator, + struct aws_byte_cursor src) { AWS_PRECONDITION(allocator); AWS_PRECONDITION(dest); AWS_ERROR_PRECONDITION(aws_byte_cursor_is_valid(&src)); - - AWS_ZERO_STRUCT(*dest); - - dest->buffer = (src.len > 0) ? (uint8_t *)aws_mem_acquire(allocator, src.len) : NULL; - if (src.len != 0 && dest->buffer == NULL) { - return AWS_OP_ERR; - } - - dest->len = src.len; - dest->capacity = src.len; - dest->allocator = allocator; - if (src.len > 0) { - memcpy(dest->buffer, src.ptr, src.len); - } - AWS_POSTCONDITION(aws_byte_buf_is_valid(dest)); - return AWS_OP_SUCCESS; -} - + + AWS_ZERO_STRUCT(*dest); + + dest->buffer = (src.len > 0) ? (uint8_t *)aws_mem_acquire(allocator, src.len) : NULL; + if (src.len != 0 && dest->buffer == NULL) { + return AWS_OP_ERR; + } + + dest->len = src.len; + dest->capacity = src.len; + dest->allocator = allocator; + if (src.len > 0) { + memcpy(dest->buffer, src.ptr, src.len); + } + AWS_POSTCONDITION(aws_byte_buf_is_valid(dest)); + return AWS_OP_SUCCESS; +} + int aws_byte_buf_init_cache_and_update_cursors(struct aws_byte_buf *dest, struct aws_allocator *allocator, ...) { AWS_PRECONDITION(allocator); AWS_PRECONDITION(dest); @@ -193,16 +193,16 @@ int aws_byte_buf_init_cache_and_update_cursors(struct aws_byte_buf *dest, struct return AWS_OP_SUCCESS; } -bool aws_byte_cursor_next_split( - const struct aws_byte_cursor *AWS_RESTRICT input_str, - char split_on, - struct aws_byte_cursor *AWS_RESTRICT substr) { - +bool aws_byte_cursor_next_split( + const struct aws_byte_cursor *AWS_RESTRICT input_str, + char split_on, + struct aws_byte_cursor *AWS_RESTRICT substr) { + AWS_PRECONDITION(aws_byte_cursor_is_valid(input_str)); - + /* If substr is zeroed-out, then this is the first run. */ const bool first_run = substr->ptr == NULL; - + /* It's legal for input_str to be zeroed out: {.ptr=NULL, .len=0} * Deal with this case separately */ if (AWS_UNLIKELY(input_str->ptr == NULL)) { @@ -212,14 +212,14 @@ bool aws_byte_cursor_next_split( substr->len = 0; return true; } - + /* done */ - AWS_ZERO_STRUCT(*substr); - return false; - } - + AWS_ZERO_STRUCT(*substr); + return false; + } + /* Rest of function deals with non-NULL input_str->ptr */ - + if (first_run) { *substr = *input_str; } else { @@ -235,64 +235,64 @@ bool aws_byte_cursor_next_split( /* done */ AWS_ZERO_STRUCT(*substr); return false; - } + } /* update len to be remainder of the string */ substr->len = input_str->len - (substr->ptr - input_str->ptr); - } - + } + /* substr is now remainder of string, search for next split */ - uint8_t *new_location = memchr(substr->ptr, split_on, substr->len); - if (new_location) { - - /* Character found, update string length. */ - substr->len = new_location - substr->ptr; - } - + uint8_t *new_location = memchr(substr->ptr, split_on, substr->len); + if (new_location) { + + /* Character found, update string length. */ + substr->len = new_location - substr->ptr; + } + AWS_POSTCONDITION(aws_byte_cursor_is_valid(substr)); - return true; -} - -int aws_byte_cursor_split_on_char_n( - const struct aws_byte_cursor *AWS_RESTRICT input_str, - char split_on, - size_t n, - struct aws_array_list *AWS_RESTRICT output) { + return true; +} + +int aws_byte_cursor_split_on_char_n( + const struct aws_byte_cursor *AWS_RESTRICT input_str, + char split_on, + size_t n, + struct aws_array_list *AWS_RESTRICT output) { AWS_ASSERT(aws_byte_cursor_is_valid(input_str)); - AWS_ASSERT(output); - AWS_ASSERT(output->item_size >= sizeof(struct aws_byte_cursor)); - - size_t max_splits = n > 0 ? n : SIZE_MAX; - size_t split_count = 0; - - struct aws_byte_cursor substr; - AWS_ZERO_STRUCT(substr); - - /* Until we run out of substrs or hit the max split count, keep iterating and pushing into the array list. */ - while (split_count <= max_splits && aws_byte_cursor_next_split(input_str, split_on, &substr)) { - - if (split_count == max_splits) { - /* If this is the last split, take the rest of the string. */ - substr.len = input_str->len - (substr.ptr - input_str->ptr); - } - - if (AWS_UNLIKELY(aws_array_list_push_back(output, (const void *)&substr))) { - return AWS_OP_ERR; - } - ++split_count; - } - - return AWS_OP_SUCCESS; -} - -int aws_byte_cursor_split_on_char( - const struct aws_byte_cursor *AWS_RESTRICT input_str, - char split_on, - struct aws_array_list *AWS_RESTRICT output) { - - return aws_byte_cursor_split_on_char_n(input_str, split_on, 0, output); -} - + AWS_ASSERT(output); + AWS_ASSERT(output->item_size >= sizeof(struct aws_byte_cursor)); + + size_t max_splits = n > 0 ? n : SIZE_MAX; + size_t split_count = 0; + + struct aws_byte_cursor substr; + AWS_ZERO_STRUCT(substr); + + /* Until we run out of substrs or hit the max split count, keep iterating and pushing into the array list. */ + while (split_count <= max_splits && aws_byte_cursor_next_split(input_str, split_on, &substr)) { + + if (split_count == max_splits) { + /* If this is the last split, take the rest of the string. */ + substr.len = input_str->len - (substr.ptr - input_str->ptr); + } + + if (AWS_UNLIKELY(aws_array_list_push_back(output, (const void *)&substr))) { + return AWS_OP_ERR; + } + ++split_count; + } + + return AWS_OP_SUCCESS; +} + +int aws_byte_cursor_split_on_char( + const struct aws_byte_cursor *AWS_RESTRICT input_str, + char split_on, + struct aws_array_list *AWS_RESTRICT output) { + + return aws_byte_cursor_split_on_char_n(input_str, split_on, 0, output); +} + int aws_byte_cursor_find_exact( const struct aws_byte_cursor *AWS_RESTRICT input_str, const struct aws_byte_cursor *AWS_RESTRICT to_find, @@ -331,66 +331,66 @@ int aws_byte_cursor_find_exact( return aws_raise_error(AWS_ERROR_STRING_MATCH_NOT_FOUND); } -int aws_byte_buf_cat(struct aws_byte_buf *dest, size_t number_of_args, ...) { +int aws_byte_buf_cat(struct aws_byte_buf *dest, size_t number_of_args, ...) { AWS_PRECONDITION(aws_byte_buf_is_valid(dest)); - - va_list ap; - va_start(ap, number_of_args); - - for (size_t i = 0; i < number_of_args; ++i) { - struct aws_byte_buf *buffer = va_arg(ap, struct aws_byte_buf *); - struct aws_byte_cursor cursor = aws_byte_cursor_from_buf(buffer); - - if (aws_byte_buf_append(dest, &cursor)) { - va_end(ap); + + va_list ap; + va_start(ap, number_of_args); + + for (size_t i = 0; i < number_of_args; ++i) { + struct aws_byte_buf *buffer = va_arg(ap, struct aws_byte_buf *); + struct aws_byte_cursor cursor = aws_byte_cursor_from_buf(buffer); + + if (aws_byte_buf_append(dest, &cursor)) { + va_end(ap); AWS_POSTCONDITION(aws_byte_buf_is_valid(dest)); - return AWS_OP_ERR; - } - } - - va_end(ap); + return AWS_OP_ERR; + } + } + + va_end(ap); AWS_POSTCONDITION(aws_byte_buf_is_valid(dest)); - return AWS_OP_SUCCESS; -} - -bool aws_byte_cursor_eq(const struct aws_byte_cursor *a, const struct aws_byte_cursor *b) { + return AWS_OP_SUCCESS; +} + +bool aws_byte_cursor_eq(const struct aws_byte_cursor *a, const struct aws_byte_cursor *b) { AWS_PRECONDITION(aws_byte_cursor_is_valid(a)); AWS_PRECONDITION(aws_byte_cursor_is_valid(b)); bool rv = aws_array_eq(a->ptr, a->len, b->ptr, b->len); AWS_POSTCONDITION(aws_byte_cursor_is_valid(a)); AWS_POSTCONDITION(aws_byte_cursor_is_valid(b)); return rv; -} - -bool aws_byte_cursor_eq_ignore_case(const struct aws_byte_cursor *a, const struct aws_byte_cursor *b) { +} + +bool aws_byte_cursor_eq_ignore_case(const struct aws_byte_cursor *a, const struct aws_byte_cursor *b) { AWS_PRECONDITION(aws_byte_cursor_is_valid(a)); AWS_PRECONDITION(aws_byte_cursor_is_valid(b)); bool rv = aws_array_eq_ignore_case(a->ptr, a->len, b->ptr, b->len); AWS_POSTCONDITION(aws_byte_cursor_is_valid(a)); AWS_POSTCONDITION(aws_byte_cursor_is_valid(b)); return rv; -} - -/* Every possible uint8_t value, lowercased */ +} + +/* Every possible uint8_t value, lowercased */ static const uint8_t s_tolower_table[] = { - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, - 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, - 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 'a', - 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', - 'x', 'y', 'z', 91, 92, 93, 94, 95, 96, 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', - 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 123, 124, 125, 126, 127, 128, 129, 130, 131, - 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, - 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, - 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, - 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, - 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, - 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255}; + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, + 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, + 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 'a', + 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', + 'x', 'y', 'z', 91, 92, 93, 94, 95, 96, 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', + 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 123, 124, 125, 126, 127, 128, 129, 130, 131, + 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, + 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, + 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, + 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, + 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, + 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255}; AWS_STATIC_ASSERT(AWS_ARRAY_SIZE(s_tolower_table) == 256); - -const uint8_t *aws_lookup_table_to_lower_get(void) { - return s_tolower_table; -} - + +const uint8_t *aws_lookup_table_to_lower_get(void) { + return s_tolower_table; +} + bool aws_array_eq_ignore_case( const void *const array_a, const size_t len_a, @@ -400,128 +400,128 @@ bool aws_array_eq_ignore_case( (len_a == 0) || AWS_MEM_IS_READABLE(array_a, len_a), "Input array [array_a] must be readable up to [len_a]."); AWS_PRECONDITION( (len_b == 0) || AWS_MEM_IS_READABLE(array_b, len_b), "Input array [array_b] must be readable up to [len_b]."); - - if (len_a != len_b) { - return false; - } - - const uint8_t *bytes_a = array_a; - const uint8_t *bytes_b = array_b; - for (size_t i = 0; i < len_a; ++i) { - if (s_tolower_table[bytes_a[i]] != s_tolower_table[bytes_b[i]]) { - return false; - } - } - - return true; -} - + + if (len_a != len_b) { + return false; + } + + const uint8_t *bytes_a = array_a; + const uint8_t *bytes_b = array_b; + for (size_t i = 0; i < len_a; ++i) { + if (s_tolower_table[bytes_a[i]] != s_tolower_table[bytes_b[i]]) { + return false; + } + } + + return true; +} + bool aws_array_eq(const void *const array_a, const size_t len_a, const void *const array_b, const size_t len_b) { AWS_PRECONDITION( (len_a == 0) || AWS_MEM_IS_READABLE(array_a, len_a), "Input array [array_a] must be readable up to [len_a]."); AWS_PRECONDITION( (len_b == 0) || AWS_MEM_IS_READABLE(array_b, len_b), "Input array [array_b] must be readable up to [len_b]."); - - if (len_a != len_b) { - return false; - } - - if (len_a == 0) { - return true; - } - - return !memcmp(array_a, array_b, len_a); -} - + + if (len_a != len_b) { + return false; + } + + if (len_a == 0) { + return true; + } + + return !memcmp(array_a, array_b, len_a); +} + bool aws_array_eq_c_str_ignore_case(const void *const array, const size_t array_len, const char *const c_str) { AWS_PRECONDITION( array || (array_len == 0), "Either input pointer [array_a] mustn't be NULL or input [array_len] mustn't be zero."); AWS_PRECONDITION(c_str != NULL); - - /* Simpler implementation could have been: - * return aws_array_eq_ignore_case(array, array_len, c_str, strlen(c_str)); - * but that would have traversed c_str twice. - * This implementation traverses c_str just once. */ - - const uint8_t *array_bytes = array; - const uint8_t *str_bytes = (const uint8_t *)c_str; - - for (size_t i = 0; i < array_len; ++i) { - uint8_t s = str_bytes[i]; - if (s == '\0') { - return false; - } - - if (s_tolower_table[array_bytes[i]] != s_tolower_table[s]) { - return false; - } - } - - return str_bytes[array_len] == '\0'; -} - + + /* Simpler implementation could have been: + * return aws_array_eq_ignore_case(array, array_len, c_str, strlen(c_str)); + * but that would have traversed c_str twice. + * This implementation traverses c_str just once. */ + + const uint8_t *array_bytes = array; + const uint8_t *str_bytes = (const uint8_t *)c_str; + + for (size_t i = 0; i < array_len; ++i) { + uint8_t s = str_bytes[i]; + if (s == '\0') { + return false; + } + + if (s_tolower_table[array_bytes[i]] != s_tolower_table[s]) { + return false; + } + } + + return str_bytes[array_len] == '\0'; +} + bool aws_array_eq_c_str(const void *const array, const size_t array_len, const char *const c_str) { AWS_PRECONDITION( array || (array_len == 0), "Either input pointer [array_a] mustn't be NULL or input [array_len] mustn't be zero."); AWS_PRECONDITION(c_str != NULL); - - /* Simpler implementation could have been: - * return aws_array_eq(array, array_len, c_str, strlen(c_str)); - * but that would have traversed c_str twice. - * This implementation traverses c_str just once. */ - - const uint8_t *array_bytes = array; - const uint8_t *str_bytes = (const uint8_t *)c_str; - - for (size_t i = 0; i < array_len; ++i) { - uint8_t s = str_bytes[i]; - if (s == '\0') { - return false; - } - - if (array_bytes[i] != s) { - return false; - } - } - - return str_bytes[array_len] == '\0'; -} - + + /* Simpler implementation could have been: + * return aws_array_eq(array, array_len, c_str, strlen(c_str)); + * but that would have traversed c_str twice. + * This implementation traverses c_str just once. */ + + const uint8_t *array_bytes = array; + const uint8_t *str_bytes = (const uint8_t *)c_str; + + for (size_t i = 0; i < array_len; ++i) { + uint8_t s = str_bytes[i]; + if (s == '\0') { + return false; + } + + if (array_bytes[i] != s) { + return false; + } + } + + return str_bytes[array_len] == '\0'; +} + uint64_t aws_hash_array_ignore_case(const void *array, const size_t len) { AWS_PRECONDITION(AWS_MEM_IS_READABLE(array, len)); - /* FNV-1a: https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function */ - const uint64_t fnv_offset_basis = 0xcbf29ce484222325ULL; - const uint64_t fnv_prime = 0x100000001b3ULL; - - const uint8_t *i = array; - const uint8_t *end = i + len; - - uint64_t hash = fnv_offset_basis; - while (i != end) { - const uint8_t lower = s_tolower_table[*i++]; - hash ^= lower; + /* FNV-1a: https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function */ + const uint64_t fnv_offset_basis = 0xcbf29ce484222325ULL; + const uint64_t fnv_prime = 0x100000001b3ULL; + + const uint8_t *i = array; + const uint8_t *end = i + len; + + uint64_t hash = fnv_offset_basis; + while (i != end) { + const uint8_t lower = s_tolower_table[*i++]; + hash ^= lower; #ifdef CBMC # pragma CPROVER check push # pragma CPROVER check disable "unsigned-overflow" #endif - hash *= fnv_prime; + hash *= fnv_prime; #ifdef CBMC # pragma CPROVER check pop #endif - } - return hash; -} - -uint64_t aws_hash_byte_cursor_ptr_ignore_case(const void *item) { + } + return hash; +} + +uint64_t aws_hash_byte_cursor_ptr_ignore_case(const void *item) { AWS_PRECONDITION(aws_byte_cursor_is_valid(item)); const struct aws_byte_cursor *const cursor = item; uint64_t rval = aws_hash_array_ignore_case(cursor->ptr, cursor->len); AWS_POSTCONDITION(aws_byte_cursor_is_valid(item)); return rval; -} - +} + bool aws_byte_cursor_eq_byte_buf(const struct aws_byte_cursor *const a, const struct aws_byte_buf *const b) { AWS_PRECONDITION(aws_byte_cursor_is_valid(a)); AWS_PRECONDITION(aws_byte_buf_is_valid(b)); @@ -529,8 +529,8 @@ bool aws_byte_cursor_eq_byte_buf(const struct aws_byte_cursor *const a, const st AWS_POSTCONDITION(aws_byte_cursor_is_valid(a)); AWS_POSTCONDITION(aws_byte_buf_is_valid(b)); return rv; -} - +} + bool aws_byte_cursor_eq_byte_buf_ignore_case( const struct aws_byte_cursor *const a, const struct aws_byte_buf *const b) { @@ -540,176 +540,176 @@ bool aws_byte_cursor_eq_byte_buf_ignore_case( AWS_POSTCONDITION(aws_byte_cursor_is_valid(a)); AWS_POSTCONDITION(aws_byte_buf_is_valid(b)); return rv; -} - +} + bool aws_byte_cursor_eq_c_str(const struct aws_byte_cursor *const cursor, const char *const c_str) { AWS_PRECONDITION(aws_byte_cursor_is_valid(cursor)); AWS_PRECONDITION(c_str != NULL); bool rv = aws_array_eq_c_str(cursor->ptr, cursor->len, c_str); AWS_POSTCONDITION(aws_byte_cursor_is_valid(cursor)); return rv; -} - +} + bool aws_byte_cursor_eq_c_str_ignore_case(const struct aws_byte_cursor *const cursor, const char *const c_str) { AWS_PRECONDITION(aws_byte_cursor_is_valid(cursor)); AWS_PRECONDITION(c_str != NULL); bool rv = aws_array_eq_c_str_ignore_case(cursor->ptr, cursor->len, c_str); AWS_POSTCONDITION(aws_byte_cursor_is_valid(cursor)); return rv; -} - -int aws_byte_buf_append(struct aws_byte_buf *to, const struct aws_byte_cursor *from) { - AWS_PRECONDITION(aws_byte_buf_is_valid(to)); - AWS_PRECONDITION(aws_byte_cursor_is_valid(from)); - - if (to->capacity - to->len < from->len) { - AWS_POSTCONDITION(aws_byte_buf_is_valid(to)); - AWS_POSTCONDITION(aws_byte_cursor_is_valid(from)); - return aws_raise_error(AWS_ERROR_DEST_COPY_TOO_SMALL); - } - - if (from->len > 0) { - /* This assert teaches clang-tidy that from->ptr and to->buffer cannot be null in a non-empty buffers */ - AWS_ASSERT(from->ptr); - AWS_ASSERT(to->buffer); - memcpy(to->buffer + to->len, from->ptr, from->len); - to->len += from->len; - } - - AWS_POSTCONDITION(aws_byte_buf_is_valid(to)); - AWS_POSTCONDITION(aws_byte_cursor_is_valid(from)); - return AWS_OP_SUCCESS; -} - -int aws_byte_buf_append_with_lookup( - struct aws_byte_buf *AWS_RESTRICT to, - const struct aws_byte_cursor *AWS_RESTRICT from, - const uint8_t *lookup_table) { - AWS_PRECONDITION(aws_byte_buf_is_valid(to)); - AWS_PRECONDITION(aws_byte_cursor_is_valid(from)); +} + +int aws_byte_buf_append(struct aws_byte_buf *to, const struct aws_byte_cursor *from) { + AWS_PRECONDITION(aws_byte_buf_is_valid(to)); + AWS_PRECONDITION(aws_byte_cursor_is_valid(from)); + + if (to->capacity - to->len < from->len) { + AWS_POSTCONDITION(aws_byte_buf_is_valid(to)); + AWS_POSTCONDITION(aws_byte_cursor_is_valid(from)); + return aws_raise_error(AWS_ERROR_DEST_COPY_TOO_SMALL); + } + + if (from->len > 0) { + /* This assert teaches clang-tidy that from->ptr and to->buffer cannot be null in a non-empty buffers */ + AWS_ASSERT(from->ptr); + AWS_ASSERT(to->buffer); + memcpy(to->buffer + to->len, from->ptr, from->len); + to->len += from->len; + } + + AWS_POSTCONDITION(aws_byte_buf_is_valid(to)); + AWS_POSTCONDITION(aws_byte_cursor_is_valid(from)); + return AWS_OP_SUCCESS; +} + +int aws_byte_buf_append_with_lookup( + struct aws_byte_buf *AWS_RESTRICT to, + const struct aws_byte_cursor *AWS_RESTRICT from, + const uint8_t *lookup_table) { + AWS_PRECONDITION(aws_byte_buf_is_valid(to)); + AWS_PRECONDITION(aws_byte_cursor_is_valid(from)); AWS_PRECONDITION( AWS_MEM_IS_READABLE(lookup_table, 256), "Input array [lookup_table] must be at least 256 bytes long."); - - if (to->capacity - to->len < from->len) { - AWS_POSTCONDITION(aws_byte_buf_is_valid(to)); - AWS_POSTCONDITION(aws_byte_cursor_is_valid(from)); - return aws_raise_error(AWS_ERROR_DEST_COPY_TOO_SMALL); - } - - for (size_t i = 0; i < from->len; ++i) { - to->buffer[to->len + i] = lookup_table[from->ptr[i]]; - } - - if (aws_add_size_checked(to->len, from->len, &to->len)) { - return AWS_OP_ERR; - } - - AWS_POSTCONDITION(aws_byte_buf_is_valid(to)); - AWS_POSTCONDITION(aws_byte_cursor_is_valid(from)); - return AWS_OP_SUCCESS; -} - + + if (to->capacity - to->len < from->len) { + AWS_POSTCONDITION(aws_byte_buf_is_valid(to)); + AWS_POSTCONDITION(aws_byte_cursor_is_valid(from)); + return aws_raise_error(AWS_ERROR_DEST_COPY_TOO_SMALL); + } + + for (size_t i = 0; i < from->len; ++i) { + to->buffer[to->len + i] = lookup_table[from->ptr[i]]; + } + + if (aws_add_size_checked(to->len, from->len, &to->len)) { + return AWS_OP_ERR; + } + + AWS_POSTCONDITION(aws_byte_buf_is_valid(to)); + AWS_POSTCONDITION(aws_byte_cursor_is_valid(from)); + return AWS_OP_SUCCESS; +} + static int s_aws_byte_buf_append_dynamic( struct aws_byte_buf *to, const struct aws_byte_cursor *from, bool clear_released_memory) { - AWS_PRECONDITION(aws_byte_buf_is_valid(to)); - AWS_PRECONDITION(aws_byte_cursor_is_valid(from)); + AWS_PRECONDITION(aws_byte_buf_is_valid(to)); + AWS_PRECONDITION(aws_byte_cursor_is_valid(from)); AWS_ERROR_PRECONDITION(to->allocator); - - if (to->capacity - to->len < from->len) { - /* - * NewCapacity = Max(OldCapacity * 2, OldCapacity + MissingCapacity) - */ - size_t missing_capacity = from->len - (to->capacity - to->len); - - size_t required_capacity = 0; - if (aws_add_size_checked(to->capacity, missing_capacity, &required_capacity)) { - AWS_POSTCONDITION(aws_byte_buf_is_valid(to)); - AWS_POSTCONDITION(aws_byte_cursor_is_valid(from)); - return AWS_OP_ERR; - } - - /* - * It's ok if this overflows, just clamp to max possible. - * In theory this lets us still grow a buffer that's larger than 1/2 size_t space - * at least enough to accommodate the append. - */ - size_t growth_capacity = aws_add_size_saturating(to->capacity, to->capacity); - - size_t new_capacity = required_capacity; - if (new_capacity < growth_capacity) { - new_capacity = growth_capacity; - } - - /* - * Attempt to resize - we intentionally do not use reserve() in order to preserve - * the (unlikely) use case of from and to being the same buffer range. - */ - - /* - * Try the max, but if that fails and the required is smaller, try it in fallback - */ - uint8_t *new_buffer = aws_mem_acquire(to->allocator, new_capacity); - if (new_buffer == NULL) { - if (new_capacity > required_capacity) { - new_capacity = required_capacity; - new_buffer = aws_mem_acquire(to->allocator, new_capacity); - if (new_buffer == NULL) { - AWS_POSTCONDITION(aws_byte_buf_is_valid(to)); - AWS_POSTCONDITION(aws_byte_cursor_is_valid(from)); - return AWS_OP_ERR; - } - } else { - AWS_POSTCONDITION(aws_byte_buf_is_valid(to)); - AWS_POSTCONDITION(aws_byte_cursor_is_valid(from)); - return AWS_OP_ERR; - } - } - - /* - * Copy old buffer -> new buffer - */ - if (to->len > 0) { - memcpy(new_buffer, to->buffer, to->len); - } - /* - * Copy what we actually wanted to append in the first place - */ - if (from->len > 0) { - memcpy(new_buffer + to->len, from->ptr, from->len); - } + + if (to->capacity - to->len < from->len) { + /* + * NewCapacity = Max(OldCapacity * 2, OldCapacity + MissingCapacity) + */ + size_t missing_capacity = from->len - (to->capacity - to->len); + + size_t required_capacity = 0; + if (aws_add_size_checked(to->capacity, missing_capacity, &required_capacity)) { + AWS_POSTCONDITION(aws_byte_buf_is_valid(to)); + AWS_POSTCONDITION(aws_byte_cursor_is_valid(from)); + return AWS_OP_ERR; + } + + /* + * It's ok if this overflows, just clamp to max possible. + * In theory this lets us still grow a buffer that's larger than 1/2 size_t space + * at least enough to accommodate the append. + */ + size_t growth_capacity = aws_add_size_saturating(to->capacity, to->capacity); + + size_t new_capacity = required_capacity; + if (new_capacity < growth_capacity) { + new_capacity = growth_capacity; + } + + /* + * Attempt to resize - we intentionally do not use reserve() in order to preserve + * the (unlikely) use case of from and to being the same buffer range. + */ + + /* + * Try the max, but if that fails and the required is smaller, try it in fallback + */ + uint8_t *new_buffer = aws_mem_acquire(to->allocator, new_capacity); + if (new_buffer == NULL) { + if (new_capacity > required_capacity) { + new_capacity = required_capacity; + new_buffer = aws_mem_acquire(to->allocator, new_capacity); + if (new_buffer == NULL) { + AWS_POSTCONDITION(aws_byte_buf_is_valid(to)); + AWS_POSTCONDITION(aws_byte_cursor_is_valid(from)); + return AWS_OP_ERR; + } + } else { + AWS_POSTCONDITION(aws_byte_buf_is_valid(to)); + AWS_POSTCONDITION(aws_byte_cursor_is_valid(from)); + return AWS_OP_ERR; + } + } + + /* + * Copy old buffer -> new buffer + */ + if (to->len > 0) { + memcpy(new_buffer, to->buffer, to->len); + } + /* + * Copy what we actually wanted to append in the first place + */ + if (from->len > 0) { + memcpy(new_buffer + to->len, from->ptr, from->len); + } if (clear_released_memory) { aws_secure_zero(to->buffer, to->capacity); } - /* - * Get rid of the old buffer - */ - aws_mem_release(to->allocator, to->buffer); - - /* - * Switch to the new buffer - */ - to->buffer = new_buffer; - to->capacity = new_capacity; - } else { - if (from->len > 0) { - /* This assert teaches clang-tidy that from->ptr and to->buffer cannot be null in a non-empty buffers */ - AWS_ASSERT(from->ptr); - AWS_ASSERT(to->buffer); - memcpy(to->buffer + to->len, from->ptr, from->len); - } - } - - to->len += from->len; - - AWS_POSTCONDITION(aws_byte_buf_is_valid(to)); - AWS_POSTCONDITION(aws_byte_cursor_is_valid(from)); - return AWS_OP_SUCCESS; -} - + /* + * Get rid of the old buffer + */ + aws_mem_release(to->allocator, to->buffer); + + /* + * Switch to the new buffer + */ + to->buffer = new_buffer; + to->capacity = new_capacity; + } else { + if (from->len > 0) { + /* This assert teaches clang-tidy that from->ptr and to->buffer cannot be null in a non-empty buffers */ + AWS_ASSERT(from->ptr); + AWS_ASSERT(to->buffer); + memcpy(to->buffer + to->len, from->ptr, from->len); + } + } + + to->len += from->len; + + AWS_POSTCONDITION(aws_byte_buf_is_valid(to)); + AWS_POSTCONDITION(aws_byte_cursor_is_valid(from)); + return AWS_OP_SUCCESS; +} + int aws_byte_buf_append_dynamic(struct aws_byte_buf *to, const struct aws_byte_cursor *from) { return s_aws_byte_buf_append_dynamic(to, from, false); } @@ -742,87 +742,87 @@ int aws_byte_buf_append_byte_dynamic_secure(struct aws_byte_buf *buffer, uint8_t return s_aws_byte_buf_append_byte_dynamic(buffer, value, true); } -int aws_byte_buf_reserve(struct aws_byte_buf *buffer, size_t requested_capacity) { +int aws_byte_buf_reserve(struct aws_byte_buf *buffer, size_t requested_capacity) { AWS_ERROR_PRECONDITION(buffer->allocator); AWS_ERROR_PRECONDITION(aws_byte_buf_is_valid(buffer)); - - if (requested_capacity <= buffer->capacity) { - AWS_POSTCONDITION(aws_byte_buf_is_valid(buffer)); - return AWS_OP_SUCCESS; - } - - if (aws_mem_realloc(buffer->allocator, (void **)&buffer->buffer, buffer->capacity, requested_capacity)) { - return AWS_OP_ERR; - } - - buffer->capacity = requested_capacity; - - AWS_POSTCONDITION(aws_byte_buf_is_valid(buffer)); - return AWS_OP_SUCCESS; -} - -int aws_byte_buf_reserve_relative(struct aws_byte_buf *buffer, size_t additional_length) { + + if (requested_capacity <= buffer->capacity) { + AWS_POSTCONDITION(aws_byte_buf_is_valid(buffer)); + return AWS_OP_SUCCESS; + } + + if (aws_mem_realloc(buffer->allocator, (void **)&buffer->buffer, buffer->capacity, requested_capacity)) { + return AWS_OP_ERR; + } + + buffer->capacity = requested_capacity; + + AWS_POSTCONDITION(aws_byte_buf_is_valid(buffer)); + return AWS_OP_SUCCESS; +} + +int aws_byte_buf_reserve_relative(struct aws_byte_buf *buffer, size_t additional_length) { AWS_ERROR_PRECONDITION(buffer->allocator); AWS_ERROR_PRECONDITION(aws_byte_buf_is_valid(buffer)); - - size_t requested_capacity = 0; - if (AWS_UNLIKELY(aws_add_size_checked(buffer->len, additional_length, &requested_capacity))) { - AWS_POSTCONDITION(aws_byte_buf_is_valid(buffer)); - return AWS_OP_ERR; - } - - return aws_byte_buf_reserve(buffer, requested_capacity); -} - -struct aws_byte_cursor aws_byte_cursor_right_trim_pred( - const struct aws_byte_cursor *source, - aws_byte_predicate_fn *predicate) { + + size_t requested_capacity = 0; + if (AWS_UNLIKELY(aws_add_size_checked(buffer->len, additional_length, &requested_capacity))) { + AWS_POSTCONDITION(aws_byte_buf_is_valid(buffer)); + return AWS_OP_ERR; + } + + return aws_byte_buf_reserve(buffer, requested_capacity); +} + +struct aws_byte_cursor aws_byte_cursor_right_trim_pred( + const struct aws_byte_cursor *source, + aws_byte_predicate_fn *predicate) { AWS_PRECONDITION(aws_byte_cursor_is_valid(source)); AWS_PRECONDITION(predicate != NULL); - struct aws_byte_cursor trimmed = *source; - - while (trimmed.len > 0 && predicate(*(trimmed.ptr + trimmed.len - 1))) { - --trimmed.len; - } + struct aws_byte_cursor trimmed = *source; + + while (trimmed.len > 0 && predicate(*(trimmed.ptr + trimmed.len - 1))) { + --trimmed.len; + } AWS_POSTCONDITION(aws_byte_cursor_is_valid(source)); AWS_POSTCONDITION(aws_byte_cursor_is_valid(&trimmed)); - return trimmed; -} - -struct aws_byte_cursor aws_byte_cursor_left_trim_pred( - const struct aws_byte_cursor *source, - aws_byte_predicate_fn *predicate) { + return trimmed; +} + +struct aws_byte_cursor aws_byte_cursor_left_trim_pred( + const struct aws_byte_cursor *source, + aws_byte_predicate_fn *predicate) { AWS_PRECONDITION(aws_byte_cursor_is_valid(source)); AWS_PRECONDITION(predicate != NULL); - struct aws_byte_cursor trimmed = *source; - - while (trimmed.len > 0 && predicate(*(trimmed.ptr))) { - --trimmed.len; - ++trimmed.ptr; - } + struct aws_byte_cursor trimmed = *source; + + while (trimmed.len > 0 && predicate(*(trimmed.ptr))) { + --trimmed.len; + ++trimmed.ptr; + } AWS_POSTCONDITION(aws_byte_cursor_is_valid(source)); AWS_POSTCONDITION(aws_byte_cursor_is_valid(&trimmed)); - return trimmed; -} - -struct aws_byte_cursor aws_byte_cursor_trim_pred( - const struct aws_byte_cursor *source, - aws_byte_predicate_fn *predicate) { + return trimmed; +} + +struct aws_byte_cursor aws_byte_cursor_trim_pred( + const struct aws_byte_cursor *source, + aws_byte_predicate_fn *predicate) { AWS_PRECONDITION(aws_byte_cursor_is_valid(source)); AWS_PRECONDITION(predicate != NULL); - struct aws_byte_cursor left_trimmed = aws_byte_cursor_left_trim_pred(source, predicate); + struct aws_byte_cursor left_trimmed = aws_byte_cursor_left_trim_pred(source, predicate); struct aws_byte_cursor dest = aws_byte_cursor_right_trim_pred(&left_trimmed, predicate); AWS_POSTCONDITION(aws_byte_cursor_is_valid(source)); AWS_POSTCONDITION(aws_byte_cursor_is_valid(&dest)); return dest; -} - -bool aws_byte_cursor_satisfies_pred(const struct aws_byte_cursor *source, aws_byte_predicate_fn *predicate) { - struct aws_byte_cursor trimmed = aws_byte_cursor_left_trim_pred(source, predicate); +} + +bool aws_byte_cursor_satisfies_pred(const struct aws_byte_cursor *source, aws_byte_predicate_fn *predicate) { + struct aws_byte_cursor trimmed = aws_byte_cursor_left_trim_pred(source, predicate); bool rval = (trimmed.len == 0); AWS_POSTCONDITION(aws_byte_cursor_is_valid(source)); return rval; -} +} int aws_byte_cursor_compare_lexical(const struct aws_byte_cursor *lhs, const struct aws_byte_cursor *rhs) { AWS_PRECONDITION(aws_byte_cursor_is_valid(lhs)); diff --git a/contrib/restricted/aws/aws-c-common/source/codegen.c b/contrib/restricted/aws/aws-c-common/source/codegen.c index 1469e63f37..ea6e95d548 100644 --- a/contrib/restricted/aws/aws-c-common/source/codegen.c +++ b/contrib/restricted/aws/aws-c-common/source/codegen.c @@ -1,14 +1,14 @@ /** * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. - */ - -/* - * This file generates exportable implementations for inlineable functions. - */ - -#define AWS_STATIC_IMPL AWS_COMMON_API - + */ + +/* + * This file generates exportable implementations for inlineable functions. + */ + +#define AWS_STATIC_IMPL AWS_COMMON_API + #include <aws/common/array_list.inl> #include <aws/common/atomics.inl> #include <aws/common/byte_order.inl> diff --git a/contrib/restricted/aws/aws-c-common/source/command_line_parser.c b/contrib/restricted/aws/aws-c-common/source/command_line_parser.c index bfb3f9f1aa..ccbe6d1820 100644 --- a/contrib/restricted/aws/aws-c-common/source/command_line_parser.c +++ b/contrib/restricted/aws/aws-c-common/source/command_line_parser.c @@ -1,109 +1,109 @@ /** * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. - */ -#include <aws/common/command_line_parser.h> - -int aws_cli_optind = 1; -int aws_cli_opterr = -1; -int aws_cli_optopt = 0; - -const char *aws_cli_optarg = NULL; - -static const struct aws_cli_option *s_find_option_from_char( - const struct aws_cli_option *longopts, - char search_for, - int *longindex) { - int index = 0; - const struct aws_cli_option *option = &longopts[index]; - - while (option->val != 0 || option->name) { - if (option->val == search_for) { - if (longindex) { - *longindex = index; - } - return option; - } - - option = &longopts[++index]; - } - - return NULL; -} - -static const struct aws_cli_option *s_find_option_from_c_str( - const struct aws_cli_option *longopts, - const char *search_for, - int *longindex) { - int index = 0; - const struct aws_cli_option *option = &longopts[index]; - - while (option->name || option->val != 0) { - if (option->name) { - if (option->name && !strcmp(search_for, option->name)) { - if (longindex) { - *longindex = index; - } - return option; - } - } - - option = &longopts[++index]; - } - - return NULL; -} - -int aws_cli_getopt_long( - int argc, - char *const argv[], - const char *optstring, - const struct aws_cli_option *longopts, - int *longindex) { - aws_cli_optarg = NULL; - - if (aws_cli_optind >= argc) { - return -1; - } - - char first_char = argv[aws_cli_optind][0]; - char second_char = argv[aws_cli_optind][1]; - char *option_start = NULL; - const struct aws_cli_option *option = NULL; - - if (first_char == '-' && second_char != '-') { - option_start = &argv[aws_cli_optind][1]; - option = s_find_option_from_char(longopts, *option_start, longindex); - } else if (first_char == '-' && second_char == '-') { - option_start = &argv[aws_cli_optind][2]; - option = s_find_option_from_c_str(longopts, option_start, longindex); - } else { - return -1; - } - - aws_cli_optind++; - if (option) { - bool has_arg = false; - + */ +#include <aws/common/command_line_parser.h> + +int aws_cli_optind = 1; +int aws_cli_opterr = -1; +int aws_cli_optopt = 0; + +const char *aws_cli_optarg = NULL; + +static const struct aws_cli_option *s_find_option_from_char( + const struct aws_cli_option *longopts, + char search_for, + int *longindex) { + int index = 0; + const struct aws_cli_option *option = &longopts[index]; + + while (option->val != 0 || option->name) { + if (option->val == search_for) { + if (longindex) { + *longindex = index; + } + return option; + } + + option = &longopts[++index]; + } + + return NULL; +} + +static const struct aws_cli_option *s_find_option_from_c_str( + const struct aws_cli_option *longopts, + const char *search_for, + int *longindex) { + int index = 0; + const struct aws_cli_option *option = &longopts[index]; + + while (option->name || option->val != 0) { + if (option->name) { + if (option->name && !strcmp(search_for, option->name)) { + if (longindex) { + *longindex = index; + } + return option; + } + } + + option = &longopts[++index]; + } + + return NULL; +} + +int aws_cli_getopt_long( + int argc, + char *const argv[], + const char *optstring, + const struct aws_cli_option *longopts, + int *longindex) { + aws_cli_optarg = NULL; + + if (aws_cli_optind >= argc) { + return -1; + } + + char first_char = argv[aws_cli_optind][0]; + char second_char = argv[aws_cli_optind][1]; + char *option_start = NULL; + const struct aws_cli_option *option = NULL; + + if (first_char == '-' && second_char != '-') { + option_start = &argv[aws_cli_optind][1]; + option = s_find_option_from_char(longopts, *option_start, longindex); + } else if (first_char == '-' && second_char == '-') { + option_start = &argv[aws_cli_optind][2]; + option = s_find_option_from_c_str(longopts, option_start, longindex); + } else { + return -1; + } + + aws_cli_optind++; + if (option) { + bool has_arg = false; + char *opt_value = memchr(optstring, option->val, strlen(optstring)); if (!opt_value) { return '?'; - } - + } + if (opt_value[1] == ':') { has_arg = true; } - if (has_arg) { + if (has_arg) { if (aws_cli_optind >= argc) { - return '?'; - } - - aws_cli_optarg = argv[aws_cli_optind++]; - } - - return option->val; - } - - return '?'; -} + return '?'; + } + + aws_cli_optarg = argv[aws_cli_optind++]; + } + + return option->val; + } + + return '?'; +} diff --git a/contrib/restricted/aws/aws-c-common/source/common.c b/contrib/restricted/aws/aws-c-common/source/common.c index af5b90cd2a..88c5d262c8 100644 --- a/contrib/restricted/aws/aws-c-common/source/common.c +++ b/contrib/restricted/aws/aws-c-common/source/common.c @@ -1,35 +1,35 @@ /** * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. - */ - -#include <aws/common/common.h> + */ + +#include <aws/common/common.h> #include <aws/common/logging.h> -#include <aws/common/math.h> +#include <aws/common/math.h> #include <aws/common/private/dlloads.h> - -#include <stdarg.h> -#include <stdlib.h> - -#ifdef _WIN32 -# include <Windows.h> + +#include <stdarg.h> +#include <stdlib.h> + +#ifdef _WIN32 +# include <Windows.h> #else # include <dlfcn.h> -#endif - -#ifdef __MACH__ -# include <CoreFoundation/CoreFoundation.h> -#endif - -/* turn off unused named parameter warning on msvc.*/ -#ifdef _MSC_VER -# pragma warning(push) -# pragma warning(disable : 4100) -#endif - +#endif + +#ifdef __MACH__ +# include <CoreFoundation/CoreFoundation.h> +#endif + +/* turn off unused named parameter warning on msvc.*/ +#ifdef _MSC_VER +# pragma warning(push) +# pragma warning(disable : 4100) +#endif + long (*g_set_mempolicy_ptr)(int, const unsigned long *, unsigned long) = NULL; void *g_libnuma_handle = NULL; - + void aws_secure_zero(void *pBuf, size_t bufsize) { #if defined(_WIN32) SecureZeroMemory(pBuf, bufsize); @@ -39,7 +39,7 @@ void aws_secure_zero(void *pBuf, size_t bufsize) { * * We'll try to work around this by using inline asm on GCC-like compilers, * and by exposing the buffer pointer in a volatile local pointer elsewhere. - */ + */ # if defined(__GNUC__) || defined(__clang__) memset(pBuf, 0, bufsize); /* This inline asm serves to convince the compiler that the buffer is (somehow) still @@ -65,143 +65,143 @@ void aws_secure_zero(void *pBuf, size_t bufsize) { memset(pVolBuf, 0, bufsize); # endif // #else not GCC/clang #endif // #else not windows -} - +} + #define AWS_DEFINE_ERROR_INFO_COMMON(C, ES) [(C)-0x0000] = AWS_DEFINE_ERROR_INFO(C, ES, "aws-c-common") -/* clang-format off */ -static struct aws_error_info errors[] = { - AWS_DEFINE_ERROR_INFO_COMMON( - AWS_ERROR_SUCCESS, - "Success."), - AWS_DEFINE_ERROR_INFO_COMMON( - AWS_ERROR_OOM, - "Out of memory."), - AWS_DEFINE_ERROR_INFO_COMMON( - AWS_ERROR_UNKNOWN, - "Unknown error."), - AWS_DEFINE_ERROR_INFO_COMMON( - AWS_ERROR_SHORT_BUFFER, - "Buffer is not large enough to hold result."), - AWS_DEFINE_ERROR_INFO_COMMON( - AWS_ERROR_OVERFLOW_DETECTED, - "Fixed size value overflow was detected."), - AWS_DEFINE_ERROR_INFO_COMMON( - AWS_ERROR_UNSUPPORTED_OPERATION, - "Unsupported operation."), - AWS_DEFINE_ERROR_INFO_COMMON( - AWS_ERROR_INVALID_BUFFER_SIZE, - "Invalid buffer size."), - AWS_DEFINE_ERROR_INFO_COMMON( - AWS_ERROR_INVALID_HEX_STR, - "Invalid hex string."), - AWS_DEFINE_ERROR_INFO_COMMON( - AWS_ERROR_INVALID_BASE64_STR, - "Invalid base64 string."), - AWS_DEFINE_ERROR_INFO_COMMON( - AWS_ERROR_INVALID_INDEX, - "Invalid index for list access."), - AWS_DEFINE_ERROR_INFO_COMMON( - AWS_ERROR_THREAD_INVALID_SETTINGS, - "Invalid thread settings."), - AWS_DEFINE_ERROR_INFO_COMMON( - AWS_ERROR_THREAD_INSUFFICIENT_RESOURCE, - "Insufficent resources for thread."), - AWS_DEFINE_ERROR_INFO_COMMON( - AWS_ERROR_THREAD_NO_PERMISSIONS, - "Insufficient permissions for thread operation."), - AWS_DEFINE_ERROR_INFO_COMMON( - AWS_ERROR_THREAD_NOT_JOINABLE, - "Thread not joinable."), - AWS_DEFINE_ERROR_INFO_COMMON( - AWS_ERROR_THREAD_NO_SUCH_THREAD_ID, - "No such thread ID."), - AWS_DEFINE_ERROR_INFO_COMMON( - AWS_ERROR_THREAD_DEADLOCK_DETECTED, - "Deadlock detected in thread."), - AWS_DEFINE_ERROR_INFO_COMMON( - AWS_ERROR_MUTEX_NOT_INIT, - "Mutex not initialized."), - AWS_DEFINE_ERROR_INFO_COMMON( - AWS_ERROR_MUTEX_TIMEOUT, - "Mutex operation timed out."), - AWS_DEFINE_ERROR_INFO_COMMON( - AWS_ERROR_MUTEX_CALLER_NOT_OWNER, - "The caller of a mutex operation was not the owner."), - AWS_DEFINE_ERROR_INFO_COMMON( - AWS_ERROR_MUTEX_FAILED, - "Mutex operation failed."), - AWS_DEFINE_ERROR_INFO_COMMON( - AWS_ERROR_COND_VARIABLE_INIT_FAILED, - "Condition variable initialization failed."), - AWS_DEFINE_ERROR_INFO_COMMON( - AWS_ERROR_COND_VARIABLE_TIMED_OUT, - "Condition variable wait timed out."), - AWS_DEFINE_ERROR_INFO_COMMON( - AWS_ERROR_COND_VARIABLE_ERROR_UNKNOWN, - "Condition variable unknown error."), - AWS_DEFINE_ERROR_INFO_COMMON( - AWS_ERROR_CLOCK_FAILURE, - "Clock operation failed."), - AWS_DEFINE_ERROR_INFO_COMMON( - AWS_ERROR_LIST_EMPTY, - "Empty list."), - AWS_DEFINE_ERROR_INFO_COMMON( - AWS_ERROR_DEST_COPY_TOO_SMALL, - "Destination of copy is too small."), - AWS_DEFINE_ERROR_INFO_COMMON( - AWS_ERROR_LIST_EXCEEDS_MAX_SIZE, - "A requested operation on a list would exceed it's max size."), - AWS_DEFINE_ERROR_INFO_COMMON( - AWS_ERROR_LIST_STATIC_MODE_CANT_SHRINK, - "Attempt to shrink a list in static mode."), - AWS_DEFINE_ERROR_INFO_COMMON( - AWS_ERROR_PRIORITY_QUEUE_FULL, - "Attempt to add items to a full preallocated queue in static mode."), - AWS_DEFINE_ERROR_INFO_COMMON( - AWS_ERROR_PRIORITY_QUEUE_EMPTY, - "Attempt to pop an item from an empty queue."), - AWS_DEFINE_ERROR_INFO_COMMON( - AWS_ERROR_PRIORITY_QUEUE_BAD_NODE, - "Bad node handle passed to remove."), - AWS_DEFINE_ERROR_INFO_COMMON( - AWS_ERROR_HASHTBL_ITEM_NOT_FOUND, - "Item not found in hash table."), - AWS_DEFINE_ERROR_INFO_COMMON( - AWS_ERROR_INVALID_DATE_STR, - "Date string is invalid and cannot be parsed." - ), - AWS_DEFINE_ERROR_INFO_COMMON( - AWS_ERROR_INVALID_ARGUMENT, - "An invalid argument was passed to a function." - ), - AWS_DEFINE_ERROR_INFO_COMMON( - AWS_ERROR_RANDOM_GEN_FAILED, - "A call to the random number generator failed. Retry later." - ), - AWS_DEFINE_ERROR_INFO_COMMON( - AWS_ERROR_MALFORMED_INPUT_STRING, - "An input string was passed to a parser and the string was incorrectly formatted." - ), - AWS_DEFINE_ERROR_INFO_COMMON( - AWS_ERROR_UNIMPLEMENTED, - "A function was called, but is not implemented." - ), - AWS_DEFINE_ERROR_INFO_COMMON( - AWS_ERROR_INVALID_STATE, - "An invalid state was encountered." - ), - AWS_DEFINE_ERROR_INFO_COMMON( - AWS_ERROR_ENVIRONMENT_GET, - "System call failure when getting an environment variable." - ), - AWS_DEFINE_ERROR_INFO_COMMON( - AWS_ERROR_ENVIRONMENT_SET, - "System call failure when setting an environment variable." - ), - AWS_DEFINE_ERROR_INFO_COMMON( - AWS_ERROR_ENVIRONMENT_UNSET, - "System call failure when unsetting an environment variable." - ), +/* clang-format off */ +static struct aws_error_info errors[] = { + AWS_DEFINE_ERROR_INFO_COMMON( + AWS_ERROR_SUCCESS, + "Success."), + AWS_DEFINE_ERROR_INFO_COMMON( + AWS_ERROR_OOM, + "Out of memory."), + AWS_DEFINE_ERROR_INFO_COMMON( + AWS_ERROR_UNKNOWN, + "Unknown error."), + AWS_DEFINE_ERROR_INFO_COMMON( + AWS_ERROR_SHORT_BUFFER, + "Buffer is not large enough to hold result."), + AWS_DEFINE_ERROR_INFO_COMMON( + AWS_ERROR_OVERFLOW_DETECTED, + "Fixed size value overflow was detected."), + AWS_DEFINE_ERROR_INFO_COMMON( + AWS_ERROR_UNSUPPORTED_OPERATION, + "Unsupported operation."), + AWS_DEFINE_ERROR_INFO_COMMON( + AWS_ERROR_INVALID_BUFFER_SIZE, + "Invalid buffer size."), + AWS_DEFINE_ERROR_INFO_COMMON( + AWS_ERROR_INVALID_HEX_STR, + "Invalid hex string."), + AWS_DEFINE_ERROR_INFO_COMMON( + AWS_ERROR_INVALID_BASE64_STR, + "Invalid base64 string."), + AWS_DEFINE_ERROR_INFO_COMMON( + AWS_ERROR_INVALID_INDEX, + "Invalid index for list access."), + AWS_DEFINE_ERROR_INFO_COMMON( + AWS_ERROR_THREAD_INVALID_SETTINGS, + "Invalid thread settings."), + AWS_DEFINE_ERROR_INFO_COMMON( + AWS_ERROR_THREAD_INSUFFICIENT_RESOURCE, + "Insufficent resources for thread."), + AWS_DEFINE_ERROR_INFO_COMMON( + AWS_ERROR_THREAD_NO_PERMISSIONS, + "Insufficient permissions for thread operation."), + AWS_DEFINE_ERROR_INFO_COMMON( + AWS_ERROR_THREAD_NOT_JOINABLE, + "Thread not joinable."), + AWS_DEFINE_ERROR_INFO_COMMON( + AWS_ERROR_THREAD_NO_SUCH_THREAD_ID, + "No such thread ID."), + AWS_DEFINE_ERROR_INFO_COMMON( + AWS_ERROR_THREAD_DEADLOCK_DETECTED, + "Deadlock detected in thread."), + AWS_DEFINE_ERROR_INFO_COMMON( + AWS_ERROR_MUTEX_NOT_INIT, + "Mutex not initialized."), + AWS_DEFINE_ERROR_INFO_COMMON( + AWS_ERROR_MUTEX_TIMEOUT, + "Mutex operation timed out."), + AWS_DEFINE_ERROR_INFO_COMMON( + AWS_ERROR_MUTEX_CALLER_NOT_OWNER, + "The caller of a mutex operation was not the owner."), + AWS_DEFINE_ERROR_INFO_COMMON( + AWS_ERROR_MUTEX_FAILED, + "Mutex operation failed."), + AWS_DEFINE_ERROR_INFO_COMMON( + AWS_ERROR_COND_VARIABLE_INIT_FAILED, + "Condition variable initialization failed."), + AWS_DEFINE_ERROR_INFO_COMMON( + AWS_ERROR_COND_VARIABLE_TIMED_OUT, + "Condition variable wait timed out."), + AWS_DEFINE_ERROR_INFO_COMMON( + AWS_ERROR_COND_VARIABLE_ERROR_UNKNOWN, + "Condition variable unknown error."), + AWS_DEFINE_ERROR_INFO_COMMON( + AWS_ERROR_CLOCK_FAILURE, + "Clock operation failed."), + AWS_DEFINE_ERROR_INFO_COMMON( + AWS_ERROR_LIST_EMPTY, + "Empty list."), + AWS_DEFINE_ERROR_INFO_COMMON( + AWS_ERROR_DEST_COPY_TOO_SMALL, + "Destination of copy is too small."), + AWS_DEFINE_ERROR_INFO_COMMON( + AWS_ERROR_LIST_EXCEEDS_MAX_SIZE, + "A requested operation on a list would exceed it's max size."), + AWS_DEFINE_ERROR_INFO_COMMON( + AWS_ERROR_LIST_STATIC_MODE_CANT_SHRINK, + "Attempt to shrink a list in static mode."), + AWS_DEFINE_ERROR_INFO_COMMON( + AWS_ERROR_PRIORITY_QUEUE_FULL, + "Attempt to add items to a full preallocated queue in static mode."), + AWS_DEFINE_ERROR_INFO_COMMON( + AWS_ERROR_PRIORITY_QUEUE_EMPTY, + "Attempt to pop an item from an empty queue."), + AWS_DEFINE_ERROR_INFO_COMMON( + AWS_ERROR_PRIORITY_QUEUE_BAD_NODE, + "Bad node handle passed to remove."), + AWS_DEFINE_ERROR_INFO_COMMON( + AWS_ERROR_HASHTBL_ITEM_NOT_FOUND, + "Item not found in hash table."), + AWS_DEFINE_ERROR_INFO_COMMON( + AWS_ERROR_INVALID_DATE_STR, + "Date string is invalid and cannot be parsed." + ), + AWS_DEFINE_ERROR_INFO_COMMON( + AWS_ERROR_INVALID_ARGUMENT, + "An invalid argument was passed to a function." + ), + AWS_DEFINE_ERROR_INFO_COMMON( + AWS_ERROR_RANDOM_GEN_FAILED, + "A call to the random number generator failed. Retry later." + ), + AWS_DEFINE_ERROR_INFO_COMMON( + AWS_ERROR_MALFORMED_INPUT_STRING, + "An input string was passed to a parser and the string was incorrectly formatted." + ), + AWS_DEFINE_ERROR_INFO_COMMON( + AWS_ERROR_UNIMPLEMENTED, + "A function was called, but is not implemented." + ), + AWS_DEFINE_ERROR_INFO_COMMON( + AWS_ERROR_INVALID_STATE, + "An invalid state was encountered." + ), + AWS_DEFINE_ERROR_INFO_COMMON( + AWS_ERROR_ENVIRONMENT_GET, + "System call failure when getting an environment variable." + ), + AWS_DEFINE_ERROR_INFO_COMMON( + AWS_ERROR_ENVIRONMENT_SET, + "System call failure when setting an environment variable." + ), + AWS_DEFINE_ERROR_INFO_COMMON( + AWS_ERROR_ENVIRONMENT_UNSET, + "System call failure when unsetting an environment variable." + ), AWS_DEFINE_ERROR_INFO_COMMON( AWS_ERROR_SYS_CALL_FAILURE, "System call failure"), @@ -226,14 +226,14 @@ static struct aws_error_info errors[] = { AWS_DEFINE_ERROR_INFO_COMMON( AWS_ERROR_DIVIDE_BY_ZERO, "Attempt to divide a number by zero."), -}; -/* clang-format on */ - -static struct aws_error_info_list s_list = { - .error_list = errors, - .count = AWS_ARRAY_SIZE(errors), -}; - +}; +/* clang-format on */ + +static struct aws_error_info_list s_list = { + .error_list = errors, + .count = AWS_ARRAY_SIZE(errors), +}; + static struct aws_log_subject_info s_common_log_subject_infos[] = { DEFINE_LOG_SUBJECT_INFO( AWS_LS_COMMON_GENERAL, @@ -260,7 +260,7 @@ void aws_common_library_init(struct aws_allocator *allocator) { if (!s_common_library_initialized) { s_common_library_initialized = true; - aws_register_error_info(&s_list); + aws_register_error_info(&s_list); aws_register_log_subject_info_list(&s_common_log_subject_list); /* NUMA is funky and we can't rely on libnuma.so being available. We also don't want to take a hard dependency on it, @@ -280,9 +280,9 @@ void aws_common_library_init(struct aws_allocator *allocator) { AWS_LOGF_INFO(AWS_LS_COMMON_GENERAL, "static: libnuma.so failed to load"); } #endif - } -} - + } +} + void aws_common_library_clean_up(void) { if (s_common_library_initialized) { s_common_library_initialized = false; @@ -294,8 +294,8 @@ void aws_common_library_clean_up(void) { } #endif } -} - +} + void aws_common_fatal_assert_library_initialized(void) { if (!s_common_library_initialized) { fprintf( @@ -305,6 +305,6 @@ void aws_common_fatal_assert_library_initialized(void) { } } -#ifdef _MSC_VER -# pragma warning(pop) -#endif +#ifdef _MSC_VER +# pragma warning(pop) +#endif diff --git a/contrib/restricted/aws/aws-c-common/source/condition_variable.c b/contrib/restricted/aws/aws-c-common/source/condition_variable.c index 88b6f501b6..6d67dbbeaa 100644 --- a/contrib/restricted/aws/aws-c-common/source/condition_variable.c +++ b/contrib/restricted/aws/aws-c-common/source/condition_variable.c @@ -1,35 +1,35 @@ /** * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. - */ - -#include <aws/common/condition_variable.h> - -int aws_condition_variable_wait_pred( - struct aws_condition_variable *condition_variable, - struct aws_mutex *mutex, - aws_condition_predicate_fn *pred, - void *pred_ctx) { - - int err_code = 0; - while (!err_code && !pred(pred_ctx)) { - err_code = aws_condition_variable_wait(condition_variable, mutex); - } - - return err_code; -} - -int aws_condition_variable_wait_for_pred( - struct aws_condition_variable *condition_variable, - struct aws_mutex *mutex, - int64_t time_to_wait, - aws_condition_predicate_fn *pred, - void *pred_ctx) { - - int err_code = 0; - while (!err_code && !pred(pred_ctx)) { - err_code = aws_condition_variable_wait_for(condition_variable, mutex, time_to_wait); - } - - return err_code; -} + */ + +#include <aws/common/condition_variable.h> + +int aws_condition_variable_wait_pred( + struct aws_condition_variable *condition_variable, + struct aws_mutex *mutex, + aws_condition_predicate_fn *pred, + void *pred_ctx) { + + int err_code = 0; + while (!err_code && !pred(pred_ctx)) { + err_code = aws_condition_variable_wait(condition_variable, mutex); + } + + return err_code; +} + +int aws_condition_variable_wait_for_pred( + struct aws_condition_variable *condition_variable, + struct aws_mutex *mutex, + int64_t time_to_wait, + aws_condition_predicate_fn *pred, + void *pred_ctx) { + + int err_code = 0; + while (!err_code && !pred(pred_ctx)) { + err_code = aws_condition_variable_wait_for(condition_variable, mutex, time_to_wait); + } + + return err_code; +} diff --git a/contrib/restricted/aws/aws-c-common/source/date_time.c b/contrib/restricted/aws/aws-c-common/source/date_time.c index 40a224490e..8d08e57ad8 100644 --- a/contrib/restricted/aws/aws-c-common/source/date_time.c +++ b/contrib/restricted/aws/aws-c-common/source/date_time.c @@ -1,807 +1,807 @@ /** * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. - */ -#include <aws/common/date_time.h> - -#include <aws/common/array_list.h> -#include <aws/common/byte_buf.h> -#include <aws/common/byte_order.h> -#include <aws/common/clock.h> -#include <aws/common/string.h> -#include <aws/common/time.h> - -#include <ctype.h> - -static const char *RFC822_DATE_FORMAT_STR_MINUS_Z = "%a, %d %b %Y %H:%M:%S GMT"; -static const char *RFC822_DATE_FORMAT_STR_WITH_Z = "%a, %d %b %Y %H:%M:%S %Z"; -static const char *RFC822_SHORT_DATE_FORMAT_STR = "%a, %d %b %Y"; -static const char *ISO_8601_LONG_DATE_FORMAT_STR = "%Y-%m-%dT%H:%M:%SZ"; -static const char *ISO_8601_SHORT_DATE_FORMAT_STR = "%Y-%m-%d"; -static const char *ISO_8601_LONG_BASIC_DATE_FORMAT_STR = "%Y%m%dT%H%M%SZ"; -static const char *ISO_8601_SHORT_BASIC_DATE_FORMAT_STR = "%Y%m%d"; - -#define STR_TRIPLET_TO_INDEX(str) \ - (((uint32_t)(uint8_t)tolower((str)[0]) << 0) | ((uint32_t)(uint8_t)tolower((str)[1]) << 8) | \ - ((uint32_t)(uint8_t)tolower((str)[2]) << 16)) - -static uint32_t s_jan = 0; -static uint32_t s_feb = 0; -static uint32_t s_mar = 0; -static uint32_t s_apr = 0; -static uint32_t s_may = 0; -static uint32_t s_jun = 0; -static uint32_t s_jul = 0; -static uint32_t s_aug = 0; -static uint32_t s_sep = 0; -static uint32_t s_oct = 0; -static uint32_t s_nov = 0; -static uint32_t s_dec = 0; - -static uint32_t s_utc = 0; -static uint32_t s_gmt = 0; - -static void s_check_init_str_to_int(void) { - if (!s_jan) { - s_jan = STR_TRIPLET_TO_INDEX("jan"); - s_feb = STR_TRIPLET_TO_INDEX("feb"); - s_mar = STR_TRIPLET_TO_INDEX("mar"); - s_apr = STR_TRIPLET_TO_INDEX("apr"); - s_may = STR_TRIPLET_TO_INDEX("may"); - s_jun = STR_TRIPLET_TO_INDEX("jun"); - s_jul = STR_TRIPLET_TO_INDEX("jul"); - s_aug = STR_TRIPLET_TO_INDEX("aug"); - s_sep = STR_TRIPLET_TO_INDEX("sep"); - s_oct = STR_TRIPLET_TO_INDEX("oct"); - s_nov = STR_TRIPLET_TO_INDEX("nov"); - s_dec = STR_TRIPLET_TO_INDEX("dec"); - s_utc = STR_TRIPLET_TO_INDEX("utc"); - s_gmt = STR_TRIPLET_TO_INDEX("gmt"); - } -} - -/* Get the 0-11 monthy number from a string representing Month. Case insensitive and will stop on abbreviation*/ -static int get_month_number_from_str(const char *time_string, size_t start_index, size_t stop_index) { - s_check_init_str_to_int(); - - if (stop_index - start_index < 3) { - return -1; - } - - /* This AND forces the string to lowercase (assuming ASCII) */ - uint32_t comp_val = STR_TRIPLET_TO_INDEX(time_string + start_index); - - /* this can't be a switch, because I can't make it a constant expression. */ - if (s_jan == comp_val) { - return 0; - } - - if (s_feb == comp_val) { - return 1; - } - - if (s_mar == comp_val) { - return 2; - } - - if (s_apr == comp_val) { - return 3; - } - - if (s_may == comp_val) { - return 4; - } - - if (s_jun == comp_val) { - return 5; - } - - if (s_jul == comp_val) { - return 6; - } - - if (s_aug == comp_val) { - return 7; - } - - if (s_sep == comp_val) { - return 8; - } - - if (s_oct == comp_val) { - return 9; - } - - if (s_nov == comp_val) { - return 10; - } - - if (s_dec == comp_val) { - return 11; - } - - return -1; -} - -/* Detects whether or not the passed in timezone string is a UTC zone. */ -static bool is_utc_time_zone(const char *str) { - s_check_init_str_to_int(); - - size_t len = strlen(str); - - if (len > 0) { - if (str[0] == 'Z') { - return true; - } - - /* offsets count since their usable */ - if (len == 5 && (str[0] == '+' || str[0] == '-')) { - return true; - } - - if (len == 2) { - return tolower(str[0]) == 'u' && tolower(str[1]) == 't'; - } - - if (len < 3) { - return false; - } - - uint32_t comp_val = STR_TRIPLET_TO_INDEX(str); - - if (comp_val == s_utc || comp_val == s_gmt) { - return true; - } - } - - return false; -} - -struct tm s_get_time_struct(struct aws_date_time *dt, bool local_time) { - struct tm time; - AWS_ZERO_STRUCT(time); - if (local_time) { - aws_localtime(dt->timestamp, &time); - } else { - aws_gmtime(dt->timestamp, &time); - } - - return time; -} - -void aws_date_time_init_now(struct aws_date_time *dt) { - uint64_t current_time = 0; - aws_sys_clock_get_ticks(¤t_time); - dt->timestamp = (time_t)aws_timestamp_convert(current_time, AWS_TIMESTAMP_NANOS, AWS_TIMESTAMP_SECS, NULL); - dt->gmt_time = s_get_time_struct(dt, false); - dt->local_time = s_get_time_struct(dt, true); -} - -void aws_date_time_init_epoch_millis(struct aws_date_time *dt, uint64_t ms_since_epoch) { - dt->timestamp = (time_t)(ms_since_epoch / AWS_TIMESTAMP_MILLIS); - dt->gmt_time = s_get_time_struct(dt, false); - dt->local_time = s_get_time_struct(dt, true); -} - -void aws_date_time_init_epoch_secs(struct aws_date_time *dt, double sec_ms) { - dt->timestamp = (time_t)sec_ms; - dt->gmt_time = s_get_time_struct(dt, false); - dt->local_time = s_get_time_struct(dt, true); -} - -enum parser_state { - ON_WEEKDAY, - ON_SPACE_DELIM, - ON_YEAR, - ON_MONTH, - ON_MONTH_DAY, - ON_HOUR, - ON_MINUTE, - ON_SECOND, - ON_TZ, - FINISHED, -}; - -static int s_parse_iso_8601_basic(const struct aws_byte_cursor *date_str_cursor, struct tm *parsed_time) { - size_t index = 0; - size_t state_start_index = 0; - enum parser_state state = ON_YEAR; - bool error = false; - - AWS_ZERO_STRUCT(*parsed_time); - - while (state < FINISHED && !error && index < date_str_cursor->len) { - char c = date_str_cursor->ptr[index]; - size_t sub_index = index - state_start_index; - switch (state) { - case ON_YEAR: + */ +#include <aws/common/date_time.h> + +#include <aws/common/array_list.h> +#include <aws/common/byte_buf.h> +#include <aws/common/byte_order.h> +#include <aws/common/clock.h> +#include <aws/common/string.h> +#include <aws/common/time.h> + +#include <ctype.h> + +static const char *RFC822_DATE_FORMAT_STR_MINUS_Z = "%a, %d %b %Y %H:%M:%S GMT"; +static const char *RFC822_DATE_FORMAT_STR_WITH_Z = "%a, %d %b %Y %H:%M:%S %Z"; +static const char *RFC822_SHORT_DATE_FORMAT_STR = "%a, %d %b %Y"; +static const char *ISO_8601_LONG_DATE_FORMAT_STR = "%Y-%m-%dT%H:%M:%SZ"; +static const char *ISO_8601_SHORT_DATE_FORMAT_STR = "%Y-%m-%d"; +static const char *ISO_8601_LONG_BASIC_DATE_FORMAT_STR = "%Y%m%dT%H%M%SZ"; +static const char *ISO_8601_SHORT_BASIC_DATE_FORMAT_STR = "%Y%m%d"; + +#define STR_TRIPLET_TO_INDEX(str) \ + (((uint32_t)(uint8_t)tolower((str)[0]) << 0) | ((uint32_t)(uint8_t)tolower((str)[1]) << 8) | \ + ((uint32_t)(uint8_t)tolower((str)[2]) << 16)) + +static uint32_t s_jan = 0; +static uint32_t s_feb = 0; +static uint32_t s_mar = 0; +static uint32_t s_apr = 0; +static uint32_t s_may = 0; +static uint32_t s_jun = 0; +static uint32_t s_jul = 0; +static uint32_t s_aug = 0; +static uint32_t s_sep = 0; +static uint32_t s_oct = 0; +static uint32_t s_nov = 0; +static uint32_t s_dec = 0; + +static uint32_t s_utc = 0; +static uint32_t s_gmt = 0; + +static void s_check_init_str_to_int(void) { + if (!s_jan) { + s_jan = STR_TRIPLET_TO_INDEX("jan"); + s_feb = STR_TRIPLET_TO_INDEX("feb"); + s_mar = STR_TRIPLET_TO_INDEX("mar"); + s_apr = STR_TRIPLET_TO_INDEX("apr"); + s_may = STR_TRIPLET_TO_INDEX("may"); + s_jun = STR_TRIPLET_TO_INDEX("jun"); + s_jul = STR_TRIPLET_TO_INDEX("jul"); + s_aug = STR_TRIPLET_TO_INDEX("aug"); + s_sep = STR_TRIPLET_TO_INDEX("sep"); + s_oct = STR_TRIPLET_TO_INDEX("oct"); + s_nov = STR_TRIPLET_TO_INDEX("nov"); + s_dec = STR_TRIPLET_TO_INDEX("dec"); + s_utc = STR_TRIPLET_TO_INDEX("utc"); + s_gmt = STR_TRIPLET_TO_INDEX("gmt"); + } +} + +/* Get the 0-11 monthy number from a string representing Month. Case insensitive and will stop on abbreviation*/ +static int get_month_number_from_str(const char *time_string, size_t start_index, size_t stop_index) { + s_check_init_str_to_int(); + + if (stop_index - start_index < 3) { + return -1; + } + + /* This AND forces the string to lowercase (assuming ASCII) */ + uint32_t comp_val = STR_TRIPLET_TO_INDEX(time_string + start_index); + + /* this can't be a switch, because I can't make it a constant expression. */ + if (s_jan == comp_val) { + return 0; + } + + if (s_feb == comp_val) { + return 1; + } + + if (s_mar == comp_val) { + return 2; + } + + if (s_apr == comp_val) { + return 3; + } + + if (s_may == comp_val) { + return 4; + } + + if (s_jun == comp_val) { + return 5; + } + + if (s_jul == comp_val) { + return 6; + } + + if (s_aug == comp_val) { + return 7; + } + + if (s_sep == comp_val) { + return 8; + } + + if (s_oct == comp_val) { + return 9; + } + + if (s_nov == comp_val) { + return 10; + } + + if (s_dec == comp_val) { + return 11; + } + + return -1; +} + +/* Detects whether or not the passed in timezone string is a UTC zone. */ +static bool is_utc_time_zone(const char *str) { + s_check_init_str_to_int(); + + size_t len = strlen(str); + + if (len > 0) { + if (str[0] == 'Z') { + return true; + } + + /* offsets count since their usable */ + if (len == 5 && (str[0] == '+' || str[0] == '-')) { + return true; + } + + if (len == 2) { + return tolower(str[0]) == 'u' && tolower(str[1]) == 't'; + } + + if (len < 3) { + return false; + } + + uint32_t comp_val = STR_TRIPLET_TO_INDEX(str); + + if (comp_val == s_utc || comp_val == s_gmt) { + return true; + } + } + + return false; +} + +struct tm s_get_time_struct(struct aws_date_time *dt, bool local_time) { + struct tm time; + AWS_ZERO_STRUCT(time); + if (local_time) { + aws_localtime(dt->timestamp, &time); + } else { + aws_gmtime(dt->timestamp, &time); + } + + return time; +} + +void aws_date_time_init_now(struct aws_date_time *dt) { + uint64_t current_time = 0; + aws_sys_clock_get_ticks(¤t_time); + dt->timestamp = (time_t)aws_timestamp_convert(current_time, AWS_TIMESTAMP_NANOS, AWS_TIMESTAMP_SECS, NULL); + dt->gmt_time = s_get_time_struct(dt, false); + dt->local_time = s_get_time_struct(dt, true); +} + +void aws_date_time_init_epoch_millis(struct aws_date_time *dt, uint64_t ms_since_epoch) { + dt->timestamp = (time_t)(ms_since_epoch / AWS_TIMESTAMP_MILLIS); + dt->gmt_time = s_get_time_struct(dt, false); + dt->local_time = s_get_time_struct(dt, true); +} + +void aws_date_time_init_epoch_secs(struct aws_date_time *dt, double sec_ms) { + dt->timestamp = (time_t)sec_ms; + dt->gmt_time = s_get_time_struct(dt, false); + dt->local_time = s_get_time_struct(dt, true); +} + +enum parser_state { + ON_WEEKDAY, + ON_SPACE_DELIM, + ON_YEAR, + ON_MONTH, + ON_MONTH_DAY, + ON_HOUR, + ON_MINUTE, + ON_SECOND, + ON_TZ, + FINISHED, +}; + +static int s_parse_iso_8601_basic(const struct aws_byte_cursor *date_str_cursor, struct tm *parsed_time) { + size_t index = 0; + size_t state_start_index = 0; + enum parser_state state = ON_YEAR; + bool error = false; + + AWS_ZERO_STRUCT(*parsed_time); + + while (state < FINISHED && !error && index < date_str_cursor->len) { + char c = date_str_cursor->ptr[index]; + size_t sub_index = index - state_start_index; + switch (state) { + case ON_YEAR: if (aws_isdigit(c)) { - parsed_time->tm_year = parsed_time->tm_year * 10 + (c - '0'); - if (sub_index == 3) { - state = ON_MONTH; - state_start_index = index + 1; - parsed_time->tm_year -= 1900; - } - } else { - error = true; - } - break; - - case ON_MONTH: + parsed_time->tm_year = parsed_time->tm_year * 10 + (c - '0'); + if (sub_index == 3) { + state = ON_MONTH; + state_start_index = index + 1; + parsed_time->tm_year -= 1900; + } + } else { + error = true; + } + break; + + case ON_MONTH: if (aws_isdigit(c)) { - parsed_time->tm_mon = parsed_time->tm_mon * 10 + (c - '0'); - if (sub_index == 1) { - state = ON_MONTH_DAY; - state_start_index = index + 1; - parsed_time->tm_mon -= 1; - } - } else { - error = true; - } - break; - - case ON_MONTH_DAY: - if (c == 'T' && sub_index == 2) { - state = ON_HOUR; - state_start_index = index + 1; + parsed_time->tm_mon = parsed_time->tm_mon * 10 + (c - '0'); + if (sub_index == 1) { + state = ON_MONTH_DAY; + state_start_index = index + 1; + parsed_time->tm_mon -= 1; + } + } else { + error = true; + } + break; + + case ON_MONTH_DAY: + if (c == 'T' && sub_index == 2) { + state = ON_HOUR; + state_start_index = index + 1; } else if (aws_isdigit(c)) { - parsed_time->tm_mday = parsed_time->tm_mday * 10 + (c - '0'); - } else { - error = true; - } - break; - - case ON_HOUR: + parsed_time->tm_mday = parsed_time->tm_mday * 10 + (c - '0'); + } else { + error = true; + } + break; + + case ON_HOUR: if (aws_isdigit(c)) { - parsed_time->tm_hour = parsed_time->tm_hour * 10 + (c - '0'); - if (sub_index == 1) { - state = ON_MINUTE; - state_start_index = index + 1; - } - } else { - error = true; - } - break; - - case ON_MINUTE: + parsed_time->tm_hour = parsed_time->tm_hour * 10 + (c - '0'); + if (sub_index == 1) { + state = ON_MINUTE; + state_start_index = index + 1; + } + } else { + error = true; + } + break; + + case ON_MINUTE: if (aws_isdigit(c)) { - parsed_time->tm_min = parsed_time->tm_min * 10 + (c - '0'); - if (sub_index == 1) { - state = ON_SECOND; - state_start_index = index + 1; - } - } else { - error = true; - } - break; - - case ON_SECOND: + parsed_time->tm_min = parsed_time->tm_min * 10 + (c - '0'); + if (sub_index == 1) { + state = ON_SECOND; + state_start_index = index + 1; + } + } else { + error = true; + } + break; + + case ON_SECOND: if (aws_isdigit(c)) { - parsed_time->tm_sec = parsed_time->tm_sec * 10 + (c - '0'); - if (sub_index == 1) { - state = ON_TZ; - state_start_index = index + 1; - } - } else { - error = true; - } - break; - - case ON_TZ: - if (c == 'Z' && (sub_index == 0 || sub_index == 3)) { - state = FINISHED; + parsed_time->tm_sec = parsed_time->tm_sec * 10 + (c - '0'); + if (sub_index == 1) { + state = ON_TZ; + state_start_index = index + 1; + } + } else { + error = true; + } + break; + + case ON_TZ: + if (c == 'Z' && (sub_index == 0 || sub_index == 3)) { + state = FINISHED; } else if (!aws_isdigit(c) || sub_index > 3) { - error = true; - } - break; - - default: - error = true; - break; - } - - index++; - } - - /* ISO8601 supports date only with no time portion. state ==ON_MONTH_DAY catches this case. */ - return (state == FINISHED || state == ON_MONTH_DAY) && !error ? AWS_OP_SUCCESS : AWS_OP_ERR; -} - -static int s_parse_iso_8601(const struct aws_byte_cursor *date_str_cursor, struct tm *parsed_time) { - size_t index = 0; - size_t state_start_index = 0; - enum parser_state state = ON_YEAR; - bool error = false; - bool advance = true; - - AWS_ZERO_STRUCT(*parsed_time); - - while (state < FINISHED && !error && index < date_str_cursor->len) { - char c = date_str_cursor->ptr[index]; - switch (state) { - case ON_YEAR: - if (c == '-' && index - state_start_index == 4) { - state = ON_MONTH; - state_start_index = index + 1; - parsed_time->tm_year -= 1900; + error = true; + } + break; + + default: + error = true; + break; + } + + index++; + } + + /* ISO8601 supports date only with no time portion. state ==ON_MONTH_DAY catches this case. */ + return (state == FINISHED || state == ON_MONTH_DAY) && !error ? AWS_OP_SUCCESS : AWS_OP_ERR; +} + +static int s_parse_iso_8601(const struct aws_byte_cursor *date_str_cursor, struct tm *parsed_time) { + size_t index = 0; + size_t state_start_index = 0; + enum parser_state state = ON_YEAR; + bool error = false; + bool advance = true; + + AWS_ZERO_STRUCT(*parsed_time); + + while (state < FINISHED && !error && index < date_str_cursor->len) { + char c = date_str_cursor->ptr[index]; + switch (state) { + case ON_YEAR: + if (c == '-' && index - state_start_index == 4) { + state = ON_MONTH; + state_start_index = index + 1; + parsed_time->tm_year -= 1900; } else if (aws_isdigit(c)) { - parsed_time->tm_year = parsed_time->tm_year * 10 + (c - '0'); - } else { - error = true; - } - break; - case ON_MONTH: - if (c == '-' && index - state_start_index == 2) { - state = ON_MONTH_DAY; - state_start_index = index + 1; - parsed_time->tm_mon -= 1; + parsed_time->tm_year = parsed_time->tm_year * 10 + (c - '0'); + } else { + error = true; + } + break; + case ON_MONTH: + if (c == '-' && index - state_start_index == 2) { + state = ON_MONTH_DAY; + state_start_index = index + 1; + parsed_time->tm_mon -= 1; } else if (aws_isdigit(c)) { - parsed_time->tm_mon = parsed_time->tm_mon * 10 + (c - '0'); - } else { - error = true; - } - - break; - case ON_MONTH_DAY: - if (c == 'T' && index - state_start_index == 2) { - state = ON_HOUR; - state_start_index = index + 1; + parsed_time->tm_mon = parsed_time->tm_mon * 10 + (c - '0'); + } else { + error = true; + } + + break; + case ON_MONTH_DAY: + if (c == 'T' && index - state_start_index == 2) { + state = ON_HOUR; + state_start_index = index + 1; } else if (aws_isdigit(c)) { - parsed_time->tm_mday = parsed_time->tm_mday * 10 + (c - '0'); - } else { - error = true; - } - break; - /* note: no time portion is spec compliant. */ - case ON_HOUR: - /* time parts can be delimited by ':' or just concatenated together, but must always be 2 digits. */ - if (index - state_start_index == 2) { - state = ON_MINUTE; - state_start_index = index + 1; + parsed_time->tm_mday = parsed_time->tm_mday * 10 + (c - '0'); + } else { + error = true; + } + break; + /* note: no time portion is spec compliant. */ + case ON_HOUR: + /* time parts can be delimited by ':' or just concatenated together, but must always be 2 digits. */ + if (index - state_start_index == 2) { + state = ON_MINUTE; + state_start_index = index + 1; if (aws_isdigit(c)) { - state_start_index = index; - advance = false; - } else if (c != ':') { - error = true; - } + state_start_index = index; + advance = false; + } else if (c != ':') { + error = true; + } } else if (aws_isdigit(c)) { - parsed_time->tm_hour = parsed_time->tm_hour * 10 + (c - '0'); - } else { - error = true; - } - - break; - case ON_MINUTE: - /* time parts can be delimited by ':' or just concatenated together, but must always be 2 digits. */ - if (index - state_start_index == 2) { - state = ON_SECOND; - state_start_index = index + 1; + parsed_time->tm_hour = parsed_time->tm_hour * 10 + (c - '0'); + } else { + error = true; + } + + break; + case ON_MINUTE: + /* time parts can be delimited by ':' or just concatenated together, but must always be 2 digits. */ + if (index - state_start_index == 2) { + state = ON_SECOND; + state_start_index = index + 1; if (aws_isdigit(c)) { - state_start_index = index; - advance = false; - } else if (c != ':') { - error = true; - } + state_start_index = index; + advance = false; + } else if (c != ':') { + error = true; + } } else if (aws_isdigit(c)) { - parsed_time->tm_min = parsed_time->tm_min * 10 + (c - '0'); - } else { - error = true; - } - - break; - case ON_SECOND: - if (c == 'Z' && index - state_start_index == 2) { - state = FINISHED; - state_start_index = index + 1; - } else if (c == '.' && index - state_start_index == 2) { - state = ON_TZ; - state_start_index = index + 1; + parsed_time->tm_min = parsed_time->tm_min * 10 + (c - '0'); + } else { + error = true; + } + + break; + case ON_SECOND: + if (c == 'Z' && index - state_start_index == 2) { + state = FINISHED; + state_start_index = index + 1; + } else if (c == '.' && index - state_start_index == 2) { + state = ON_TZ; + state_start_index = index + 1; } else if (aws_isdigit(c)) { - parsed_time->tm_sec = parsed_time->tm_sec * 10 + (c - '0'); - } else { - error = true; - } - - break; - case ON_TZ: - if (c == 'Z') { - state = FINISHED; - state_start_index = index + 1; + parsed_time->tm_sec = parsed_time->tm_sec * 10 + (c - '0'); + } else { + error = true; + } + + break; + case ON_TZ: + if (c == 'Z') { + state = FINISHED; + state_start_index = index + 1; } else if (!aws_isdigit(c)) { - error = true; - } - break; - default: - error = true; - break; - } - - if (advance) { - index++; - } else { - advance = true; - } - } - - /* ISO8601 supports date only with no time portion. state ==ON_MONTH_DAY catches this case. */ - return (state == FINISHED || state == ON_MONTH_DAY) && !error ? AWS_OP_SUCCESS : AWS_OP_ERR; -} - -static int s_parse_rfc_822( - const struct aws_byte_cursor *date_str_cursor, - struct tm *parsed_time, - struct aws_date_time *dt) { - size_t len = date_str_cursor->len; - - size_t index = 0; - size_t state_start_index = 0; - int state = ON_WEEKDAY; - bool error = false; - - AWS_ZERO_STRUCT(*parsed_time); - - while (!error && index < len) { - char c = date_str_cursor->ptr[index]; - - switch (state) { - /* week day abbr is optional. */ - case ON_WEEKDAY: - if (c == ',') { - state = ON_SPACE_DELIM; - state_start_index = index + 1; + error = true; + } + break; + default: + error = true; + break; + } + + if (advance) { + index++; + } else { + advance = true; + } + } + + /* ISO8601 supports date only with no time portion. state ==ON_MONTH_DAY catches this case. */ + return (state == FINISHED || state == ON_MONTH_DAY) && !error ? AWS_OP_SUCCESS : AWS_OP_ERR; +} + +static int s_parse_rfc_822( + const struct aws_byte_cursor *date_str_cursor, + struct tm *parsed_time, + struct aws_date_time *dt) { + size_t len = date_str_cursor->len; + + size_t index = 0; + size_t state_start_index = 0; + int state = ON_WEEKDAY; + bool error = false; + + AWS_ZERO_STRUCT(*parsed_time); + + while (!error && index < len) { + char c = date_str_cursor->ptr[index]; + + switch (state) { + /* week day abbr is optional. */ + case ON_WEEKDAY: + if (c == ',') { + state = ON_SPACE_DELIM; + state_start_index = index + 1; } else if (aws_isdigit(c)) { - state = ON_MONTH_DAY; + state = ON_MONTH_DAY; } else if (!aws_isalpha(c)) { - error = true; - } - break; - case ON_SPACE_DELIM: + error = true; + } + break; + case ON_SPACE_DELIM: if (aws_isspace(c)) { - state = ON_MONTH_DAY; - state_start_index = index + 1; - } else { - error = true; - } - break; - case ON_MONTH_DAY: + state = ON_MONTH_DAY; + state_start_index = index + 1; + } else { + error = true; + } + break; + case ON_MONTH_DAY: if (aws_isdigit(c)) { - parsed_time->tm_mday = parsed_time->tm_mday * 10 + (c - '0'); + parsed_time->tm_mday = parsed_time->tm_mday * 10 + (c - '0'); } else if (aws_isspace(c)) { - state = ON_MONTH; - state_start_index = index + 1; - } else { - error = true; - } - break; - case ON_MONTH: + state = ON_MONTH; + state_start_index = index + 1; + } else { + error = true; + } + break; + case ON_MONTH: if (aws_isspace(c)) { - int monthNumber = - get_month_number_from_str((const char *)date_str_cursor->ptr, state_start_index, index + 1); - - if (monthNumber > -1) { - state = ON_YEAR; - state_start_index = index + 1; - parsed_time->tm_mon = monthNumber; - } else { - error = true; - } + int monthNumber = + get_month_number_from_str((const char *)date_str_cursor->ptr, state_start_index, index + 1); + + if (monthNumber > -1) { + state = ON_YEAR; + state_start_index = index + 1; + parsed_time->tm_mon = monthNumber; + } else { + error = true; + } } else if (!aws_isalpha(c)) { - error = true; - } - break; - /* year can be 4 or 2 digits. */ - case ON_YEAR: + error = true; + } + break; + /* year can be 4 or 2 digits. */ + case ON_YEAR: if (aws_isspace(c) && index - state_start_index == 4) { - state = ON_HOUR; - state_start_index = index + 1; - parsed_time->tm_year -= 1900; + state = ON_HOUR; + state_start_index = index + 1; + parsed_time->tm_year -= 1900; } else if (aws_isspace(c) && index - state_start_index == 2) { - state = 5; - state_start_index = index + 1; - parsed_time->tm_year += 2000 - 1900; + state = 5; + state_start_index = index + 1; + parsed_time->tm_year += 2000 - 1900; } else if (aws_isdigit(c)) { - parsed_time->tm_year = parsed_time->tm_year * 10 + (c - '0'); - } else { - error = true; - } - break; - case ON_HOUR: - if (c == ':' && index - state_start_index == 2) { - state = ON_MINUTE; - state_start_index = index + 1; + parsed_time->tm_year = parsed_time->tm_year * 10 + (c - '0'); + } else { + error = true; + } + break; + case ON_HOUR: + if (c == ':' && index - state_start_index == 2) { + state = ON_MINUTE; + state_start_index = index + 1; } else if (aws_isdigit(c)) { - parsed_time->tm_hour = parsed_time->tm_hour * 10 + (c - '0'); - } else { - error = true; - } - break; - case ON_MINUTE: - if (c == ':' && index - state_start_index == 2) { - state = ON_SECOND; - state_start_index = index + 1; + parsed_time->tm_hour = parsed_time->tm_hour * 10 + (c - '0'); + } else { + error = true; + } + break; + case ON_MINUTE: + if (c == ':' && index - state_start_index == 2) { + state = ON_SECOND; + state_start_index = index + 1; } else if (aws_isdigit(c)) { - parsed_time->tm_min = parsed_time->tm_min * 10 + (c - '0'); - } else { - error = true; - } - break; - case ON_SECOND: + parsed_time->tm_min = parsed_time->tm_min * 10 + (c - '0'); + } else { + error = true; + } + break; + case ON_SECOND: if (aws_isspace(c) && index - state_start_index == 2) { - state = ON_TZ; - state_start_index = index + 1; + state = ON_TZ; + state_start_index = index + 1; } else if (aws_isdigit(c)) { - parsed_time->tm_sec = parsed_time->tm_sec * 10 + (c - '0'); - } else { - error = true; - } - break; - case ON_TZ: + parsed_time->tm_sec = parsed_time->tm_sec * 10 + (c - '0'); + } else { + error = true; + } + break; + case ON_TZ: if ((aws_isalnum(c) || c == '-' || c == '+') && (index - state_start_index) < 5) { - dt->tz[index - state_start_index] = c; - } else { - error = true; - } - - break; - default: - error = true; - break; - } - - index++; - } - - if (dt->tz[0] != 0) { - if (is_utc_time_zone(dt->tz)) { - dt->utc_assumed = true; - } else { - error = true; - } - } - - return error || state != ON_TZ ? AWS_OP_ERR : AWS_OP_SUCCESS; -} - -int aws_date_time_init_from_str_cursor( - struct aws_date_time *dt, - const struct aws_byte_cursor *date_str_cursor, - enum aws_date_format fmt) { + dt->tz[index - state_start_index] = c; + } else { + error = true; + } + + break; + default: + error = true; + break; + } + + index++; + } + + if (dt->tz[0] != 0) { + if (is_utc_time_zone(dt->tz)) { + dt->utc_assumed = true; + } else { + error = true; + } + } + + return error || state != ON_TZ ? AWS_OP_ERR : AWS_OP_SUCCESS; +} + +int aws_date_time_init_from_str_cursor( + struct aws_date_time *dt, + const struct aws_byte_cursor *date_str_cursor, + enum aws_date_format fmt) { AWS_ERROR_PRECONDITION(date_str_cursor->len <= AWS_DATE_TIME_STR_MAX_LEN, AWS_ERROR_OVERFLOW_DETECTED); - - AWS_ZERO_STRUCT(*dt); - - struct tm parsed_time; - bool successfully_parsed = false; - - time_t seconds_offset = 0; - if (fmt == AWS_DATE_FORMAT_ISO_8601 || fmt == AWS_DATE_FORMAT_AUTO_DETECT) { - if (!s_parse_iso_8601(date_str_cursor, &parsed_time)) { - dt->utc_assumed = true; - successfully_parsed = true; - } - } - - if (fmt == AWS_DATE_FORMAT_ISO_8601_BASIC || (fmt == AWS_DATE_FORMAT_AUTO_DETECT && !successfully_parsed)) { - if (!s_parse_iso_8601_basic(date_str_cursor, &parsed_time)) { - dt->utc_assumed = true; - successfully_parsed = true; - } - } - - if (fmt == AWS_DATE_FORMAT_RFC822 || (fmt == AWS_DATE_FORMAT_AUTO_DETECT && !successfully_parsed)) { - if (!s_parse_rfc_822(date_str_cursor, &parsed_time, dt)) { - successfully_parsed = true; - - if (dt->utc_assumed) { - if (dt->tz[0] == '+' || dt->tz[0] == '-') { - /* in this format, the offset is in format +/-HHMM so convert that to seconds and we'll use - * the offset later. */ - char min_str[3] = {0}; - char hour_str[3] = {0}; - hour_str[0] = dt->tz[1]; - hour_str[1] = dt->tz[2]; - min_str[0] = dt->tz[3]; - min_str[1] = dt->tz[4]; - - long hour = strtol(hour_str, NULL, 10); - long min = strtol(min_str, NULL, 10); - seconds_offset = (time_t)(hour * 3600 + min * 60); - - if (dt->tz[0] == '-') { - seconds_offset = -seconds_offset; - } - } - } - } - } - - if (!successfully_parsed) { - return aws_raise_error(AWS_ERROR_INVALID_DATE_STR); - } - - if (dt->utc_assumed || seconds_offset) { - dt->timestamp = aws_timegm(&parsed_time); - } else { - dt->timestamp = mktime(&parsed_time); - } - - /* negative means we need to move west (increase the timestamp), positive means head east, so decrease the - * timestamp. */ - dt->timestamp -= seconds_offset; - - dt->gmt_time = s_get_time_struct(dt, false); - dt->local_time = s_get_time_struct(dt, true); - - return AWS_OP_SUCCESS; -} - -int aws_date_time_init_from_str( - struct aws_date_time *dt, - const struct aws_byte_buf *date_str, - enum aws_date_format fmt) { + + AWS_ZERO_STRUCT(*dt); + + struct tm parsed_time; + bool successfully_parsed = false; + + time_t seconds_offset = 0; + if (fmt == AWS_DATE_FORMAT_ISO_8601 || fmt == AWS_DATE_FORMAT_AUTO_DETECT) { + if (!s_parse_iso_8601(date_str_cursor, &parsed_time)) { + dt->utc_assumed = true; + successfully_parsed = true; + } + } + + if (fmt == AWS_DATE_FORMAT_ISO_8601_BASIC || (fmt == AWS_DATE_FORMAT_AUTO_DETECT && !successfully_parsed)) { + if (!s_parse_iso_8601_basic(date_str_cursor, &parsed_time)) { + dt->utc_assumed = true; + successfully_parsed = true; + } + } + + if (fmt == AWS_DATE_FORMAT_RFC822 || (fmt == AWS_DATE_FORMAT_AUTO_DETECT && !successfully_parsed)) { + if (!s_parse_rfc_822(date_str_cursor, &parsed_time, dt)) { + successfully_parsed = true; + + if (dt->utc_assumed) { + if (dt->tz[0] == '+' || dt->tz[0] == '-') { + /* in this format, the offset is in format +/-HHMM so convert that to seconds and we'll use + * the offset later. */ + char min_str[3] = {0}; + char hour_str[3] = {0}; + hour_str[0] = dt->tz[1]; + hour_str[1] = dt->tz[2]; + min_str[0] = dt->tz[3]; + min_str[1] = dt->tz[4]; + + long hour = strtol(hour_str, NULL, 10); + long min = strtol(min_str, NULL, 10); + seconds_offset = (time_t)(hour * 3600 + min * 60); + + if (dt->tz[0] == '-') { + seconds_offset = -seconds_offset; + } + } + } + } + } + + if (!successfully_parsed) { + return aws_raise_error(AWS_ERROR_INVALID_DATE_STR); + } + + if (dt->utc_assumed || seconds_offset) { + dt->timestamp = aws_timegm(&parsed_time); + } else { + dt->timestamp = mktime(&parsed_time); + } + + /* negative means we need to move west (increase the timestamp), positive means head east, so decrease the + * timestamp. */ + dt->timestamp -= seconds_offset; + + dt->gmt_time = s_get_time_struct(dt, false); + dt->local_time = s_get_time_struct(dt, true); + + return AWS_OP_SUCCESS; +} + +int aws_date_time_init_from_str( + struct aws_date_time *dt, + const struct aws_byte_buf *date_str, + enum aws_date_format fmt) { AWS_ERROR_PRECONDITION(date_str->len <= AWS_DATE_TIME_STR_MAX_LEN, AWS_ERROR_OVERFLOW_DETECTED); - - struct aws_byte_cursor date_cursor = aws_byte_cursor_from_buf(date_str); - return aws_date_time_init_from_str_cursor(dt, &date_cursor, fmt); -} - -static inline int s_date_to_str(const struct tm *tm, const char *format_str, struct aws_byte_buf *output_buf) { - size_t remaining_space = output_buf->capacity - output_buf->len; - size_t bytes_written = strftime((char *)output_buf->buffer + output_buf->len, remaining_space, format_str, tm); - - if (bytes_written == 0) { - return aws_raise_error(AWS_ERROR_SHORT_BUFFER); - } - - output_buf->len += bytes_written; - - return AWS_OP_SUCCESS; -} - -int aws_date_time_to_local_time_str( - const struct aws_date_time *dt, - enum aws_date_format fmt, - struct aws_byte_buf *output_buf) { - AWS_ASSERT(fmt != AWS_DATE_FORMAT_AUTO_DETECT); - - switch (fmt) { - case AWS_DATE_FORMAT_RFC822: - return s_date_to_str(&dt->local_time, RFC822_DATE_FORMAT_STR_WITH_Z, output_buf); - - case AWS_DATE_FORMAT_ISO_8601: - return s_date_to_str(&dt->local_time, ISO_8601_LONG_DATE_FORMAT_STR, output_buf); - - case AWS_DATE_FORMAT_ISO_8601_BASIC: - return s_date_to_str(&dt->local_time, ISO_8601_LONG_BASIC_DATE_FORMAT_STR, output_buf); - - default: - return aws_raise_error(AWS_ERROR_INVALID_ARGUMENT); - } -} - -int aws_date_time_to_utc_time_str( - const struct aws_date_time *dt, - enum aws_date_format fmt, - struct aws_byte_buf *output_buf) { - AWS_ASSERT(fmt != AWS_DATE_FORMAT_AUTO_DETECT); - - switch (fmt) { - case AWS_DATE_FORMAT_RFC822: - return s_date_to_str(&dt->gmt_time, RFC822_DATE_FORMAT_STR_MINUS_Z, output_buf); - - case AWS_DATE_FORMAT_ISO_8601: - return s_date_to_str(&dt->gmt_time, ISO_8601_LONG_DATE_FORMAT_STR, output_buf); - - case AWS_DATE_FORMAT_ISO_8601_BASIC: - return s_date_to_str(&dt->gmt_time, ISO_8601_LONG_BASIC_DATE_FORMAT_STR, output_buf); - - default: - return aws_raise_error(AWS_ERROR_INVALID_ARGUMENT); - } -} - -int aws_date_time_to_local_time_short_str( - const struct aws_date_time *dt, - enum aws_date_format fmt, - struct aws_byte_buf *output_buf) { - AWS_ASSERT(fmt != AWS_DATE_FORMAT_AUTO_DETECT); - - switch (fmt) { - case AWS_DATE_FORMAT_RFC822: - return s_date_to_str(&dt->local_time, RFC822_SHORT_DATE_FORMAT_STR, output_buf); - - case AWS_DATE_FORMAT_ISO_8601: - return s_date_to_str(&dt->local_time, ISO_8601_SHORT_DATE_FORMAT_STR, output_buf); - - case AWS_DATE_FORMAT_ISO_8601_BASIC: - return s_date_to_str(&dt->local_time, ISO_8601_SHORT_BASIC_DATE_FORMAT_STR, output_buf); - - default: - return aws_raise_error(AWS_ERROR_INVALID_ARGUMENT); - } -} - -int aws_date_time_to_utc_time_short_str( - const struct aws_date_time *dt, - enum aws_date_format fmt, - struct aws_byte_buf *output_buf) { - AWS_ASSERT(fmt != AWS_DATE_FORMAT_AUTO_DETECT); - - switch (fmt) { - case AWS_DATE_FORMAT_RFC822: - return s_date_to_str(&dt->gmt_time, RFC822_SHORT_DATE_FORMAT_STR, output_buf); - - case AWS_DATE_FORMAT_ISO_8601: - return s_date_to_str(&dt->gmt_time, ISO_8601_SHORT_DATE_FORMAT_STR, output_buf); - - case AWS_DATE_FORMAT_ISO_8601_BASIC: - return s_date_to_str(&dt->gmt_time, ISO_8601_SHORT_BASIC_DATE_FORMAT_STR, output_buf); - - default: - return aws_raise_error(AWS_ERROR_INVALID_ARGUMENT); - } -} - -double aws_date_time_as_epoch_secs(const struct aws_date_time *dt) { - return (double)dt->timestamp; -} - -uint64_t aws_date_time_as_nanos(const struct aws_date_time *dt) { - return (uint64_t)dt->timestamp * AWS_TIMESTAMP_NANOS; -} - -uint64_t aws_date_time_as_millis(const struct aws_date_time *dt) { - return (uint64_t)dt->timestamp * AWS_TIMESTAMP_MILLIS; -} - -uint16_t aws_date_time_year(const struct aws_date_time *dt, bool local_time) { - const struct tm *time = local_time ? &dt->local_time : &dt->gmt_time; - - return (uint16_t)(time->tm_year + 1900); -} - -enum aws_date_month aws_date_time_month(const struct aws_date_time *dt, bool local_time) { - const struct tm *time = local_time ? &dt->local_time : &dt->gmt_time; - - return time->tm_mon; -} - -uint8_t aws_date_time_month_day(const struct aws_date_time *dt, bool local_time) { - const struct tm *time = local_time ? &dt->local_time : &dt->gmt_time; - - return (uint8_t)time->tm_mday; -} - -enum aws_date_day_of_week aws_date_time_day_of_week(const struct aws_date_time *dt, bool local_time) { - const struct tm *time = local_time ? &dt->local_time : &dt->gmt_time; - - return time->tm_wday; -} - -uint8_t aws_date_time_hour(const struct aws_date_time *dt, bool local_time) { - const struct tm *time = local_time ? &dt->local_time : &dt->gmt_time; - - return (uint8_t)time->tm_hour; -} - -uint8_t aws_date_time_minute(const struct aws_date_time *dt, bool local_time) { - const struct tm *time = local_time ? &dt->local_time : &dt->gmt_time; - - return (uint8_t)time->tm_min; -} - -uint8_t aws_date_time_second(const struct aws_date_time *dt, bool local_time) { - const struct tm *time = local_time ? &dt->local_time : &dt->gmt_time; - - return (uint8_t)time->tm_sec; -} - -bool aws_date_time_dst(const struct aws_date_time *dt, bool local_time) { - const struct tm *time = local_time ? &dt->local_time : &dt->gmt_time; - - return (bool)time->tm_isdst; -} - -time_t aws_date_time_diff(const struct aws_date_time *a, const struct aws_date_time *b) { - return a->timestamp - b->timestamp; -} + + struct aws_byte_cursor date_cursor = aws_byte_cursor_from_buf(date_str); + return aws_date_time_init_from_str_cursor(dt, &date_cursor, fmt); +} + +static inline int s_date_to_str(const struct tm *tm, const char *format_str, struct aws_byte_buf *output_buf) { + size_t remaining_space = output_buf->capacity - output_buf->len; + size_t bytes_written = strftime((char *)output_buf->buffer + output_buf->len, remaining_space, format_str, tm); + + if (bytes_written == 0) { + return aws_raise_error(AWS_ERROR_SHORT_BUFFER); + } + + output_buf->len += bytes_written; + + return AWS_OP_SUCCESS; +} + +int aws_date_time_to_local_time_str( + const struct aws_date_time *dt, + enum aws_date_format fmt, + struct aws_byte_buf *output_buf) { + AWS_ASSERT(fmt != AWS_DATE_FORMAT_AUTO_DETECT); + + switch (fmt) { + case AWS_DATE_FORMAT_RFC822: + return s_date_to_str(&dt->local_time, RFC822_DATE_FORMAT_STR_WITH_Z, output_buf); + + case AWS_DATE_FORMAT_ISO_8601: + return s_date_to_str(&dt->local_time, ISO_8601_LONG_DATE_FORMAT_STR, output_buf); + + case AWS_DATE_FORMAT_ISO_8601_BASIC: + return s_date_to_str(&dt->local_time, ISO_8601_LONG_BASIC_DATE_FORMAT_STR, output_buf); + + default: + return aws_raise_error(AWS_ERROR_INVALID_ARGUMENT); + } +} + +int aws_date_time_to_utc_time_str( + const struct aws_date_time *dt, + enum aws_date_format fmt, + struct aws_byte_buf *output_buf) { + AWS_ASSERT(fmt != AWS_DATE_FORMAT_AUTO_DETECT); + + switch (fmt) { + case AWS_DATE_FORMAT_RFC822: + return s_date_to_str(&dt->gmt_time, RFC822_DATE_FORMAT_STR_MINUS_Z, output_buf); + + case AWS_DATE_FORMAT_ISO_8601: + return s_date_to_str(&dt->gmt_time, ISO_8601_LONG_DATE_FORMAT_STR, output_buf); + + case AWS_DATE_FORMAT_ISO_8601_BASIC: + return s_date_to_str(&dt->gmt_time, ISO_8601_LONG_BASIC_DATE_FORMAT_STR, output_buf); + + default: + return aws_raise_error(AWS_ERROR_INVALID_ARGUMENT); + } +} + +int aws_date_time_to_local_time_short_str( + const struct aws_date_time *dt, + enum aws_date_format fmt, + struct aws_byte_buf *output_buf) { + AWS_ASSERT(fmt != AWS_DATE_FORMAT_AUTO_DETECT); + + switch (fmt) { + case AWS_DATE_FORMAT_RFC822: + return s_date_to_str(&dt->local_time, RFC822_SHORT_DATE_FORMAT_STR, output_buf); + + case AWS_DATE_FORMAT_ISO_8601: + return s_date_to_str(&dt->local_time, ISO_8601_SHORT_DATE_FORMAT_STR, output_buf); + + case AWS_DATE_FORMAT_ISO_8601_BASIC: + return s_date_to_str(&dt->local_time, ISO_8601_SHORT_BASIC_DATE_FORMAT_STR, output_buf); + + default: + return aws_raise_error(AWS_ERROR_INVALID_ARGUMENT); + } +} + +int aws_date_time_to_utc_time_short_str( + const struct aws_date_time *dt, + enum aws_date_format fmt, + struct aws_byte_buf *output_buf) { + AWS_ASSERT(fmt != AWS_DATE_FORMAT_AUTO_DETECT); + + switch (fmt) { + case AWS_DATE_FORMAT_RFC822: + return s_date_to_str(&dt->gmt_time, RFC822_SHORT_DATE_FORMAT_STR, output_buf); + + case AWS_DATE_FORMAT_ISO_8601: + return s_date_to_str(&dt->gmt_time, ISO_8601_SHORT_DATE_FORMAT_STR, output_buf); + + case AWS_DATE_FORMAT_ISO_8601_BASIC: + return s_date_to_str(&dt->gmt_time, ISO_8601_SHORT_BASIC_DATE_FORMAT_STR, output_buf); + + default: + return aws_raise_error(AWS_ERROR_INVALID_ARGUMENT); + } +} + +double aws_date_time_as_epoch_secs(const struct aws_date_time *dt) { + return (double)dt->timestamp; +} + +uint64_t aws_date_time_as_nanos(const struct aws_date_time *dt) { + return (uint64_t)dt->timestamp * AWS_TIMESTAMP_NANOS; +} + +uint64_t aws_date_time_as_millis(const struct aws_date_time *dt) { + return (uint64_t)dt->timestamp * AWS_TIMESTAMP_MILLIS; +} + +uint16_t aws_date_time_year(const struct aws_date_time *dt, bool local_time) { + const struct tm *time = local_time ? &dt->local_time : &dt->gmt_time; + + return (uint16_t)(time->tm_year + 1900); +} + +enum aws_date_month aws_date_time_month(const struct aws_date_time *dt, bool local_time) { + const struct tm *time = local_time ? &dt->local_time : &dt->gmt_time; + + return time->tm_mon; +} + +uint8_t aws_date_time_month_day(const struct aws_date_time *dt, bool local_time) { + const struct tm *time = local_time ? &dt->local_time : &dt->gmt_time; + + return (uint8_t)time->tm_mday; +} + +enum aws_date_day_of_week aws_date_time_day_of_week(const struct aws_date_time *dt, bool local_time) { + const struct tm *time = local_time ? &dt->local_time : &dt->gmt_time; + + return time->tm_wday; +} + +uint8_t aws_date_time_hour(const struct aws_date_time *dt, bool local_time) { + const struct tm *time = local_time ? &dt->local_time : &dt->gmt_time; + + return (uint8_t)time->tm_hour; +} + +uint8_t aws_date_time_minute(const struct aws_date_time *dt, bool local_time) { + const struct tm *time = local_time ? &dt->local_time : &dt->gmt_time; + + return (uint8_t)time->tm_min; +} + +uint8_t aws_date_time_second(const struct aws_date_time *dt, bool local_time) { + const struct tm *time = local_time ? &dt->local_time : &dt->gmt_time; + + return (uint8_t)time->tm_sec; +} + +bool aws_date_time_dst(const struct aws_date_time *dt, bool local_time) { + const struct tm *time = local_time ? &dt->local_time : &dt->gmt_time; + + return (bool)time->tm_isdst; +} + +time_t aws_date_time_diff(const struct aws_date_time *a, const struct aws_date_time *b) { + return a->timestamp - b->timestamp; +} diff --git a/contrib/restricted/aws/aws-c-common/source/device_random.c b/contrib/restricted/aws/aws-c-common/source/device_random.c index c1731bdb46..3df8a218e7 100644 --- a/contrib/restricted/aws/aws-c-common/source/device_random.c +++ b/contrib/restricted/aws/aws-c-common/source/device_random.c @@ -1,37 +1,37 @@ /** * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. - */ -#include <aws/common/device_random.h> - -#include <aws/common/byte_buf.h> - -#ifdef _MSC_VER -/* disables warning non const declared initializers for Microsoft compilers */ -# pragma warning(disable : 4204) -# pragma warning(disable : 4706) -#endif - -int aws_device_random_u64(uint64_t *output) { - struct aws_byte_buf buf = aws_byte_buf_from_empty_array((uint8_t *)output, sizeof(uint64_t)); - - return aws_device_random_buffer(&buf); -} - -int aws_device_random_u32(uint32_t *output) { - struct aws_byte_buf buf = aws_byte_buf_from_empty_array((uint8_t *)output, sizeof(uint32_t)); - - return aws_device_random_buffer(&buf); -} - -int aws_device_random_u16(uint16_t *output) { - struct aws_byte_buf buf = aws_byte_buf_from_empty_array((uint8_t *)output, sizeof(uint16_t)); - - return aws_device_random_buffer(&buf); -} - -int aws_device_random_u8(uint8_t *output) { - struct aws_byte_buf buf = aws_byte_buf_from_empty_array((uint8_t *)output, sizeof(uint8_t)); - - return aws_device_random_buffer(&buf); -} + */ +#include <aws/common/device_random.h> + +#include <aws/common/byte_buf.h> + +#ifdef _MSC_VER +/* disables warning non const declared initializers for Microsoft compilers */ +# pragma warning(disable : 4204) +# pragma warning(disable : 4706) +#endif + +int aws_device_random_u64(uint64_t *output) { + struct aws_byte_buf buf = aws_byte_buf_from_empty_array((uint8_t *)output, sizeof(uint64_t)); + + return aws_device_random_buffer(&buf); +} + +int aws_device_random_u32(uint32_t *output) { + struct aws_byte_buf buf = aws_byte_buf_from_empty_array((uint8_t *)output, sizeof(uint32_t)); + + return aws_device_random_buffer(&buf); +} + +int aws_device_random_u16(uint16_t *output) { + struct aws_byte_buf buf = aws_byte_buf_from_empty_array((uint8_t *)output, sizeof(uint16_t)); + + return aws_device_random_buffer(&buf); +} + +int aws_device_random_u8(uint8_t *output) { + struct aws_byte_buf buf = aws_byte_buf_from_empty_array((uint8_t *)output, sizeof(uint8_t)); + + return aws_device_random_buffer(&buf); +} diff --git a/contrib/restricted/aws/aws-c-common/source/encoding.c b/contrib/restricted/aws/aws-c-common/source/encoding.c index 384780b46b..26a41fa163 100644 --- a/contrib/restricted/aws/aws-c-common/source/encoding.c +++ b/contrib/restricted/aws/aws-c-common/source/encoding.c @@ -1,289 +1,289 @@ /** * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. - */ - -#include <aws/common/encoding.h> - -#include <ctype.h> -#include <stdlib.h> - -#ifdef USE_SIMD_ENCODING -size_t aws_common_private_base64_decode_sse41(const unsigned char *in, unsigned char *out, size_t len); -void aws_common_private_base64_encode_sse41(const unsigned char *in, unsigned char *out, size_t len); -bool aws_common_private_has_avx2(void); -#else -/* - * When AVX2 compilation is unavailable, we use these stubs to fall back to the pure-C decoder. - * Since we force aws_common_private_has_avx2 to return false, the encode and decode functions should - * not be called - but we must provide them anyway to avoid link errors. - */ -static inline size_t aws_common_private_base64_decode_sse41(const unsigned char *in, unsigned char *out, size_t len) { - (void)in; - (void)out; - (void)len; - AWS_ASSERT(false); - return (size_t)-1; /* unreachable */ -} -static inline void aws_common_private_base64_encode_sse41(const unsigned char *in, unsigned char *out, size_t len) { - (void)in; - (void)out; - (void)len; - AWS_ASSERT(false); -} -static inline bool aws_common_private_has_avx2(void) { - return false; -} -#endif - -static const uint8_t *HEX_CHARS = (const uint8_t *)"0123456789abcdef"; - -static const uint8_t BASE64_SENTIANAL_VALUE = 0xff; -static const uint8_t BASE64_ENCODING_TABLE[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; - -/* in this table, 0xDD is an invalid decoded value, if you have to do byte counting for any reason, there's 16 bytes - * per row. Reformatting is turned off to make sure this stays as 16 bytes per line. */ -/* clang-format off */ -static const uint8_t BASE64_DECODING_TABLE[256] = { - 64, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, - 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, - 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 62, 0xDD, 0xDD, 0xDD, 63, - 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 0xDD, 0xDD, 0xDD, 255, 0xDD, 0xDD, - 0xDD, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, - 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, - 0xDD, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, - 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, - 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, - 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, - 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, - 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, - 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, - 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, - 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, - 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD}; -/* clang-format on */ - -int aws_hex_compute_encoded_len(size_t to_encode_len, size_t *encoded_length) { - AWS_ASSERT(encoded_length); - - size_t temp = (to_encode_len << 1) + 1; - - if (AWS_UNLIKELY(temp < to_encode_len)) { - return aws_raise_error(AWS_ERROR_OVERFLOW_DETECTED); - } - - *encoded_length = temp; - - return AWS_OP_SUCCESS; -} - -int aws_hex_encode(const struct aws_byte_cursor *AWS_RESTRICT to_encode, struct aws_byte_buf *AWS_RESTRICT output) { - AWS_PRECONDITION(aws_byte_cursor_is_valid(to_encode)); - AWS_PRECONDITION(aws_byte_buf_is_valid(output)); - - size_t encoded_len = 0; - - if (AWS_UNLIKELY(aws_hex_compute_encoded_len(to_encode->len, &encoded_len))) { - return AWS_OP_ERR; - } - - if (AWS_UNLIKELY(output->capacity < encoded_len)) { - return aws_raise_error(AWS_ERROR_SHORT_BUFFER); - } - - size_t written = 0; - for (size_t i = 0; i < to_encode->len; ++i) { - - output->buffer[written++] = HEX_CHARS[to_encode->ptr[i] >> 4 & 0x0f]; - output->buffer[written++] = HEX_CHARS[to_encode->ptr[i] & 0x0f]; - } - - output->buffer[written] = '\0'; - output->len = encoded_len; - - return AWS_OP_SUCCESS; -} - -int aws_hex_encode_append_dynamic( - const struct aws_byte_cursor *AWS_RESTRICT to_encode, - struct aws_byte_buf *AWS_RESTRICT output) { - AWS_ASSERT(to_encode->ptr); - AWS_ASSERT(aws_byte_buf_is_valid(output)); - - size_t encoded_len = 0; - if (AWS_UNLIKELY(aws_add_size_checked(to_encode->len, to_encode->len, &encoded_len))) { - return AWS_OP_ERR; - } - - if (AWS_UNLIKELY(aws_byte_buf_reserve_relative(output, encoded_len))) { - return AWS_OP_ERR; - } - - size_t written = output->len; - for (size_t i = 0; i < to_encode->len; ++i) { - - output->buffer[written++] = HEX_CHARS[to_encode->ptr[i] >> 4 & 0x0f]; - output->buffer[written++] = HEX_CHARS[to_encode->ptr[i] & 0x0f]; - } - - output->len += encoded_len; - - return AWS_OP_SUCCESS; -} - -static int s_hex_decode_char_to_int(char character, uint8_t *int_val) { - if (character >= 'a' && character <= 'f') { - *int_val = (uint8_t)(10 + (character - 'a')); - return 0; - } - - if (character >= 'A' && character <= 'F') { - *int_val = (uint8_t)(10 + (character - 'A')); - return 0; - } - - if (character >= '0' && character <= '9') { - *int_val = (uint8_t)(character - '0'); - return 0; - } - - return AWS_OP_ERR; -} - -int aws_hex_compute_decoded_len(size_t to_decode_len, size_t *decoded_len) { - AWS_ASSERT(decoded_len); - - size_t temp = (to_decode_len + 1); - - if (AWS_UNLIKELY(temp < to_decode_len)) { - return aws_raise_error(AWS_ERROR_OVERFLOW_DETECTED); - } - - *decoded_len = temp >> 1; - return AWS_OP_SUCCESS; -} - -int aws_hex_decode(const struct aws_byte_cursor *AWS_RESTRICT to_decode, struct aws_byte_buf *AWS_RESTRICT output) { - AWS_PRECONDITION(aws_byte_cursor_is_valid(to_decode)); - AWS_PRECONDITION(aws_byte_buf_is_valid(output)); - - size_t decoded_length = 0; - - if (AWS_UNLIKELY(aws_hex_compute_decoded_len(to_decode->len, &decoded_length))) { - return aws_raise_error(AWS_ERROR_OVERFLOW_DETECTED); - } - - if (AWS_UNLIKELY(output->capacity < decoded_length)) { - return aws_raise_error(AWS_ERROR_SHORT_BUFFER); - } - - size_t written = 0; - size_t i = 0; - uint8_t high_value = 0; - uint8_t low_value = 0; - - /* if the buffer isn't even, prepend a 0 to the buffer. */ - if (AWS_UNLIKELY(to_decode->len & 0x01)) { - i = 1; - if (s_hex_decode_char_to_int(to_decode->ptr[0], &low_value)) { - return aws_raise_error(AWS_ERROR_INVALID_HEX_STR); - } - - output->buffer[written++] = low_value; - } - - for (; i < to_decode->len; i += 2) { - if (AWS_UNLIKELY( - s_hex_decode_char_to_int(to_decode->ptr[i], &high_value) || - s_hex_decode_char_to_int(to_decode->ptr[i + 1], &low_value))) { - return aws_raise_error(AWS_ERROR_INVALID_HEX_STR); - } - - uint8_t value = (uint8_t)(high_value << 4); - value |= low_value; - output->buffer[written++] = value; - } - - output->len = decoded_length; - - return AWS_OP_SUCCESS; -} - -int aws_base64_compute_encoded_len(size_t to_encode_len, size_t *encoded_len) { - AWS_ASSERT(encoded_len); - - size_t tmp = to_encode_len + 2; - - if (AWS_UNLIKELY(tmp < to_encode_len)) { - return aws_raise_error(AWS_ERROR_OVERFLOW_DETECTED); - } - - tmp /= 3; - size_t overflow_check = tmp; - tmp = 4 * tmp + 1; /* plus one for the NULL terminator */ - - if (AWS_UNLIKELY(tmp < overflow_check)) { - return aws_raise_error(AWS_ERROR_OVERFLOW_DETECTED); - } - - *encoded_len = tmp; - - return AWS_OP_SUCCESS; -} - -int aws_base64_compute_decoded_len(const struct aws_byte_cursor *AWS_RESTRICT to_decode, size_t *decoded_len) { - AWS_ASSERT(to_decode); - AWS_ASSERT(decoded_len); - - const size_t len = to_decode->len; - const uint8_t *input = to_decode->ptr; - - if (len == 0) { - *decoded_len = 0; - return AWS_OP_SUCCESS; - } - - if (AWS_UNLIKELY(len & 0x03)) { - return aws_raise_error(AWS_ERROR_INVALID_BASE64_STR); - } - - size_t tmp = len * 3; - - if (AWS_UNLIKELY(tmp < len)) { - return aws_raise_error(AWS_ERROR_OVERFLOW_DETECTED); - } - - size_t padding = 0; - - if (len >= 2 && input[len - 1] == '=' && input[len - 2] == '=') { /*last two chars are = */ - padding = 2; - } else if (input[len - 1] == '=') { /*last char is = */ - padding = 1; - } - - *decoded_len = (tmp / 4 - padding); - return AWS_OP_SUCCESS; -} - -int aws_base64_encode(const struct aws_byte_cursor *AWS_RESTRICT to_encode, struct aws_byte_buf *AWS_RESTRICT output) { - AWS_ASSERT(to_encode->ptr); - AWS_ASSERT(output->buffer); - + */ + +#include <aws/common/encoding.h> + +#include <ctype.h> +#include <stdlib.h> + +#ifdef USE_SIMD_ENCODING +size_t aws_common_private_base64_decode_sse41(const unsigned char *in, unsigned char *out, size_t len); +void aws_common_private_base64_encode_sse41(const unsigned char *in, unsigned char *out, size_t len); +bool aws_common_private_has_avx2(void); +#else +/* + * When AVX2 compilation is unavailable, we use these stubs to fall back to the pure-C decoder. + * Since we force aws_common_private_has_avx2 to return false, the encode and decode functions should + * not be called - but we must provide them anyway to avoid link errors. + */ +static inline size_t aws_common_private_base64_decode_sse41(const unsigned char *in, unsigned char *out, size_t len) { + (void)in; + (void)out; + (void)len; + AWS_ASSERT(false); + return (size_t)-1; /* unreachable */ +} +static inline void aws_common_private_base64_encode_sse41(const unsigned char *in, unsigned char *out, size_t len) { + (void)in; + (void)out; + (void)len; + AWS_ASSERT(false); +} +static inline bool aws_common_private_has_avx2(void) { + return false; +} +#endif + +static const uint8_t *HEX_CHARS = (const uint8_t *)"0123456789abcdef"; + +static const uint8_t BASE64_SENTIANAL_VALUE = 0xff; +static const uint8_t BASE64_ENCODING_TABLE[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; + +/* in this table, 0xDD is an invalid decoded value, if you have to do byte counting for any reason, there's 16 bytes + * per row. Reformatting is turned off to make sure this stays as 16 bytes per line. */ +/* clang-format off */ +static const uint8_t BASE64_DECODING_TABLE[256] = { + 64, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, + 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, + 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 62, 0xDD, 0xDD, 0xDD, 63, + 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 0xDD, 0xDD, 0xDD, 255, 0xDD, 0xDD, + 0xDD, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, + 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, + 0xDD, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, + 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, + 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, + 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, + 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, + 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, + 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, + 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, + 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, + 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD}; +/* clang-format on */ + +int aws_hex_compute_encoded_len(size_t to_encode_len, size_t *encoded_length) { + AWS_ASSERT(encoded_length); + + size_t temp = (to_encode_len << 1) + 1; + + if (AWS_UNLIKELY(temp < to_encode_len)) { + return aws_raise_error(AWS_ERROR_OVERFLOW_DETECTED); + } + + *encoded_length = temp; + + return AWS_OP_SUCCESS; +} + +int aws_hex_encode(const struct aws_byte_cursor *AWS_RESTRICT to_encode, struct aws_byte_buf *AWS_RESTRICT output) { + AWS_PRECONDITION(aws_byte_cursor_is_valid(to_encode)); + AWS_PRECONDITION(aws_byte_buf_is_valid(output)); + + size_t encoded_len = 0; + + if (AWS_UNLIKELY(aws_hex_compute_encoded_len(to_encode->len, &encoded_len))) { + return AWS_OP_ERR; + } + + if (AWS_UNLIKELY(output->capacity < encoded_len)) { + return aws_raise_error(AWS_ERROR_SHORT_BUFFER); + } + + size_t written = 0; + for (size_t i = 0; i < to_encode->len; ++i) { + + output->buffer[written++] = HEX_CHARS[to_encode->ptr[i] >> 4 & 0x0f]; + output->buffer[written++] = HEX_CHARS[to_encode->ptr[i] & 0x0f]; + } + + output->buffer[written] = '\0'; + output->len = encoded_len; + + return AWS_OP_SUCCESS; +} + +int aws_hex_encode_append_dynamic( + const struct aws_byte_cursor *AWS_RESTRICT to_encode, + struct aws_byte_buf *AWS_RESTRICT output) { + AWS_ASSERT(to_encode->ptr); + AWS_ASSERT(aws_byte_buf_is_valid(output)); + + size_t encoded_len = 0; + if (AWS_UNLIKELY(aws_add_size_checked(to_encode->len, to_encode->len, &encoded_len))) { + return AWS_OP_ERR; + } + + if (AWS_UNLIKELY(aws_byte_buf_reserve_relative(output, encoded_len))) { + return AWS_OP_ERR; + } + + size_t written = output->len; + for (size_t i = 0; i < to_encode->len; ++i) { + + output->buffer[written++] = HEX_CHARS[to_encode->ptr[i] >> 4 & 0x0f]; + output->buffer[written++] = HEX_CHARS[to_encode->ptr[i] & 0x0f]; + } + + output->len += encoded_len; + + return AWS_OP_SUCCESS; +} + +static int s_hex_decode_char_to_int(char character, uint8_t *int_val) { + if (character >= 'a' && character <= 'f') { + *int_val = (uint8_t)(10 + (character - 'a')); + return 0; + } + + if (character >= 'A' && character <= 'F') { + *int_val = (uint8_t)(10 + (character - 'A')); + return 0; + } + + if (character >= '0' && character <= '9') { + *int_val = (uint8_t)(character - '0'); + return 0; + } + + return AWS_OP_ERR; +} + +int aws_hex_compute_decoded_len(size_t to_decode_len, size_t *decoded_len) { + AWS_ASSERT(decoded_len); + + size_t temp = (to_decode_len + 1); + + if (AWS_UNLIKELY(temp < to_decode_len)) { + return aws_raise_error(AWS_ERROR_OVERFLOW_DETECTED); + } + + *decoded_len = temp >> 1; + return AWS_OP_SUCCESS; +} + +int aws_hex_decode(const struct aws_byte_cursor *AWS_RESTRICT to_decode, struct aws_byte_buf *AWS_RESTRICT output) { + AWS_PRECONDITION(aws_byte_cursor_is_valid(to_decode)); + AWS_PRECONDITION(aws_byte_buf_is_valid(output)); + + size_t decoded_length = 0; + + if (AWS_UNLIKELY(aws_hex_compute_decoded_len(to_decode->len, &decoded_length))) { + return aws_raise_error(AWS_ERROR_OVERFLOW_DETECTED); + } + + if (AWS_UNLIKELY(output->capacity < decoded_length)) { + return aws_raise_error(AWS_ERROR_SHORT_BUFFER); + } + + size_t written = 0; + size_t i = 0; + uint8_t high_value = 0; + uint8_t low_value = 0; + + /* if the buffer isn't even, prepend a 0 to the buffer. */ + if (AWS_UNLIKELY(to_decode->len & 0x01)) { + i = 1; + if (s_hex_decode_char_to_int(to_decode->ptr[0], &low_value)) { + return aws_raise_error(AWS_ERROR_INVALID_HEX_STR); + } + + output->buffer[written++] = low_value; + } + + for (; i < to_decode->len; i += 2) { + if (AWS_UNLIKELY( + s_hex_decode_char_to_int(to_decode->ptr[i], &high_value) || + s_hex_decode_char_to_int(to_decode->ptr[i + 1], &low_value))) { + return aws_raise_error(AWS_ERROR_INVALID_HEX_STR); + } + + uint8_t value = (uint8_t)(high_value << 4); + value |= low_value; + output->buffer[written++] = value; + } + + output->len = decoded_length; + + return AWS_OP_SUCCESS; +} + +int aws_base64_compute_encoded_len(size_t to_encode_len, size_t *encoded_len) { + AWS_ASSERT(encoded_len); + + size_t tmp = to_encode_len + 2; + + if (AWS_UNLIKELY(tmp < to_encode_len)) { + return aws_raise_error(AWS_ERROR_OVERFLOW_DETECTED); + } + + tmp /= 3; + size_t overflow_check = tmp; + tmp = 4 * tmp + 1; /* plus one for the NULL terminator */ + + if (AWS_UNLIKELY(tmp < overflow_check)) { + return aws_raise_error(AWS_ERROR_OVERFLOW_DETECTED); + } + + *encoded_len = tmp; + + return AWS_OP_SUCCESS; +} + +int aws_base64_compute_decoded_len(const struct aws_byte_cursor *AWS_RESTRICT to_decode, size_t *decoded_len) { + AWS_ASSERT(to_decode); + AWS_ASSERT(decoded_len); + + const size_t len = to_decode->len; + const uint8_t *input = to_decode->ptr; + + if (len == 0) { + *decoded_len = 0; + return AWS_OP_SUCCESS; + } + + if (AWS_UNLIKELY(len & 0x03)) { + return aws_raise_error(AWS_ERROR_INVALID_BASE64_STR); + } + + size_t tmp = len * 3; + + if (AWS_UNLIKELY(tmp < len)) { + return aws_raise_error(AWS_ERROR_OVERFLOW_DETECTED); + } + + size_t padding = 0; + + if (len >= 2 && input[len - 1] == '=' && input[len - 2] == '=') { /*last two chars are = */ + padding = 2; + } else if (input[len - 1] == '=') { /*last char is = */ + padding = 1; + } + + *decoded_len = (tmp / 4 - padding); + return AWS_OP_SUCCESS; +} + +int aws_base64_encode(const struct aws_byte_cursor *AWS_RESTRICT to_encode, struct aws_byte_buf *AWS_RESTRICT output) { + AWS_ASSERT(to_encode->ptr); + AWS_ASSERT(output->buffer); + size_t terminated_length = 0; - size_t encoded_length = 0; + size_t encoded_length = 0; if (AWS_UNLIKELY(aws_base64_compute_encoded_len(to_encode->len, &terminated_length))) { - return AWS_OP_ERR; - } - + return AWS_OP_ERR; + } + size_t needed_capacity = 0; if (AWS_UNLIKELY(aws_add_size_checked(output->len, terminated_length, &needed_capacity))) { return AWS_OP_ERR; } if (AWS_UNLIKELY(output->capacity < needed_capacity)) { - return aws_raise_error(AWS_ERROR_SHORT_BUFFER); - } - + return aws_raise_error(AWS_ERROR_SHORT_BUFFER); + } + /* * For convenience to standard C functions expecting a null-terminated * string, the output is terminated. As the encoding itself can be used in @@ -291,123 +291,123 @@ int aws_base64_encode(const struct aws_byte_cursor *AWS_RESTRICT to_encode, stru */ encoded_length = (terminated_length - 1); - if (aws_common_private_has_avx2()) { + if (aws_common_private_has_avx2()) { aws_common_private_base64_encode_sse41(to_encode->ptr, output->buffer + output->len, to_encode->len); output->buffer[output->len + encoded_length] = 0; output->len += encoded_length; - return AWS_OP_SUCCESS; - } - - size_t buffer_length = to_encode->len; - size_t block_count = (buffer_length + 2) / 3; - size_t remainder_count = (buffer_length % 3); + return AWS_OP_SUCCESS; + } + + size_t buffer_length = to_encode->len; + size_t block_count = (buffer_length + 2) / 3; + size_t remainder_count = (buffer_length % 3); size_t str_index = output->len; - - for (size_t i = 0; i < to_encode->len; i += 3) { - uint32_t block = to_encode->ptr[i]; - - block <<= 8; - if (AWS_LIKELY(i + 1 < buffer_length)) { - block = block | to_encode->ptr[i + 1]; - } - - block <<= 8; - if (AWS_LIKELY(i + 2 < to_encode->len)) { - block = block | to_encode->ptr[i + 2]; - } - - output->buffer[str_index++] = BASE64_ENCODING_TABLE[(block >> 18) & 0x3F]; - output->buffer[str_index++] = BASE64_ENCODING_TABLE[(block >> 12) & 0x3F]; - output->buffer[str_index++] = BASE64_ENCODING_TABLE[(block >> 6) & 0x3F]; - output->buffer[str_index++] = BASE64_ENCODING_TABLE[block & 0x3F]; - } - - if (remainder_count > 0) { + + for (size_t i = 0; i < to_encode->len; i += 3) { + uint32_t block = to_encode->ptr[i]; + + block <<= 8; + if (AWS_LIKELY(i + 1 < buffer_length)) { + block = block | to_encode->ptr[i + 1]; + } + + block <<= 8; + if (AWS_LIKELY(i + 2 < to_encode->len)) { + block = block | to_encode->ptr[i + 2]; + } + + output->buffer[str_index++] = BASE64_ENCODING_TABLE[(block >> 18) & 0x3F]; + output->buffer[str_index++] = BASE64_ENCODING_TABLE[(block >> 12) & 0x3F]; + output->buffer[str_index++] = BASE64_ENCODING_TABLE[(block >> 6) & 0x3F]; + output->buffer[str_index++] = BASE64_ENCODING_TABLE[block & 0x3F]; + } + + if (remainder_count > 0) { output->buffer[output->len + block_count * 4 - 1] = '='; - if (remainder_count == 1) { + if (remainder_count == 1) { output->buffer[output->len + block_count * 4 - 2] = '='; - } - } - - /* it's a string add the null terminator. */ + } + } + + /* it's a string add the null terminator. */ output->buffer[output->len + encoded_length] = 0; - + output->len += encoded_length; - return AWS_OP_SUCCESS; -} - -static inline int s_base64_get_decoded_value(unsigned char to_decode, uint8_t *value, int8_t allow_sentinal) { - - uint8_t decode_value = BASE64_DECODING_TABLE[(size_t)to_decode]; - if (decode_value != 0xDD && (decode_value != BASE64_SENTIANAL_VALUE || allow_sentinal)) { - *value = decode_value; - return AWS_OP_SUCCESS; - } - - return AWS_OP_ERR; -} - -int aws_base64_decode(const struct aws_byte_cursor *AWS_RESTRICT to_decode, struct aws_byte_buf *AWS_RESTRICT output) { - size_t decoded_length = 0; - - if (AWS_UNLIKELY(aws_base64_compute_decoded_len(to_decode, &decoded_length))) { - return AWS_OP_ERR; - } - - if (output->capacity < decoded_length) { - return aws_raise_error(AWS_ERROR_SHORT_BUFFER); - } - - if (aws_common_private_has_avx2()) { - size_t result = aws_common_private_base64_decode_sse41(to_decode->ptr, output->buffer, to_decode->len); - if (result == -1) { - return aws_raise_error(AWS_ERROR_INVALID_BASE64_STR); - } - - output->len = result; - return AWS_OP_SUCCESS; - } - - int64_t block_count = (int64_t)to_decode->len / 4; - size_t string_index = 0; - uint8_t value1 = 0, value2 = 0, value3 = 0, value4 = 0; - int64_t buffer_index = 0; - - for (int64_t i = 0; i < block_count - 1; ++i) { - if (AWS_UNLIKELY( - s_base64_get_decoded_value(to_decode->ptr[string_index++], &value1, 0) || - s_base64_get_decoded_value(to_decode->ptr[string_index++], &value2, 0) || - s_base64_get_decoded_value(to_decode->ptr[string_index++], &value3, 0) || - s_base64_get_decoded_value(to_decode->ptr[string_index++], &value4, 0))) { - return aws_raise_error(AWS_ERROR_INVALID_BASE64_STR); - } - - buffer_index = i * 3; - output->buffer[buffer_index++] = (uint8_t)((value1 << 2) | ((value2 >> 4) & 0x03)); - output->buffer[buffer_index++] = (uint8_t)(((value2 << 4) & 0xF0) | ((value3 >> 2) & 0x0F)); - output->buffer[buffer_index] = (uint8_t)((value3 & 0x03) << 6 | value4); - } - - buffer_index = (block_count - 1) * 3; - - if (buffer_index >= 0) { - if (s_base64_get_decoded_value(to_decode->ptr[string_index++], &value1, 0) || - s_base64_get_decoded_value(to_decode->ptr[string_index++], &value2, 0) || - s_base64_get_decoded_value(to_decode->ptr[string_index++], &value3, 1) || - s_base64_get_decoded_value(to_decode->ptr[string_index], &value4, 1)) { - return aws_raise_error(AWS_ERROR_INVALID_BASE64_STR); - } - - output->buffer[buffer_index++] = (uint8_t)((value1 << 2) | ((value2 >> 4) & 0x03)); - - if (value3 != BASE64_SENTIANAL_VALUE) { - output->buffer[buffer_index++] = (uint8_t)(((value2 << 4) & 0xF0) | ((value3 >> 2) & 0x0F)); - if (value4 != BASE64_SENTIANAL_VALUE) { - output->buffer[buffer_index] = (uint8_t)((value3 & 0x03) << 6 | value4); - } - } - } - output->len = decoded_length; - return AWS_OP_SUCCESS; -} + return AWS_OP_SUCCESS; +} + +static inline int s_base64_get_decoded_value(unsigned char to_decode, uint8_t *value, int8_t allow_sentinal) { + + uint8_t decode_value = BASE64_DECODING_TABLE[(size_t)to_decode]; + if (decode_value != 0xDD && (decode_value != BASE64_SENTIANAL_VALUE || allow_sentinal)) { + *value = decode_value; + return AWS_OP_SUCCESS; + } + + return AWS_OP_ERR; +} + +int aws_base64_decode(const struct aws_byte_cursor *AWS_RESTRICT to_decode, struct aws_byte_buf *AWS_RESTRICT output) { + size_t decoded_length = 0; + + if (AWS_UNLIKELY(aws_base64_compute_decoded_len(to_decode, &decoded_length))) { + return AWS_OP_ERR; + } + + if (output->capacity < decoded_length) { + return aws_raise_error(AWS_ERROR_SHORT_BUFFER); + } + + if (aws_common_private_has_avx2()) { + size_t result = aws_common_private_base64_decode_sse41(to_decode->ptr, output->buffer, to_decode->len); + if (result == -1) { + return aws_raise_error(AWS_ERROR_INVALID_BASE64_STR); + } + + output->len = result; + return AWS_OP_SUCCESS; + } + + int64_t block_count = (int64_t)to_decode->len / 4; + size_t string_index = 0; + uint8_t value1 = 0, value2 = 0, value3 = 0, value4 = 0; + int64_t buffer_index = 0; + + for (int64_t i = 0; i < block_count - 1; ++i) { + if (AWS_UNLIKELY( + s_base64_get_decoded_value(to_decode->ptr[string_index++], &value1, 0) || + s_base64_get_decoded_value(to_decode->ptr[string_index++], &value2, 0) || + s_base64_get_decoded_value(to_decode->ptr[string_index++], &value3, 0) || + s_base64_get_decoded_value(to_decode->ptr[string_index++], &value4, 0))) { + return aws_raise_error(AWS_ERROR_INVALID_BASE64_STR); + } + + buffer_index = i * 3; + output->buffer[buffer_index++] = (uint8_t)((value1 << 2) | ((value2 >> 4) & 0x03)); + output->buffer[buffer_index++] = (uint8_t)(((value2 << 4) & 0xF0) | ((value3 >> 2) & 0x0F)); + output->buffer[buffer_index] = (uint8_t)((value3 & 0x03) << 6 | value4); + } + + buffer_index = (block_count - 1) * 3; + + if (buffer_index >= 0) { + if (s_base64_get_decoded_value(to_decode->ptr[string_index++], &value1, 0) || + s_base64_get_decoded_value(to_decode->ptr[string_index++], &value2, 0) || + s_base64_get_decoded_value(to_decode->ptr[string_index++], &value3, 1) || + s_base64_get_decoded_value(to_decode->ptr[string_index], &value4, 1)) { + return aws_raise_error(AWS_ERROR_INVALID_BASE64_STR); + } + + output->buffer[buffer_index++] = (uint8_t)((value1 << 2) | ((value2 >> 4) & 0x03)); + + if (value3 != BASE64_SENTIANAL_VALUE) { + output->buffer[buffer_index++] = (uint8_t)(((value2 << 4) & 0xF0) | ((value3 >> 2) & 0x0F)); + if (value4 != BASE64_SENTIANAL_VALUE) { + output->buffer[buffer_index] = (uint8_t)((value3 & 0x03) << 6 | value4); + } + } + } + output->len = decoded_length; + return AWS_OP_SUCCESS; +} diff --git a/contrib/restricted/aws/aws-c-common/source/error.c b/contrib/restricted/aws/aws-c-common/source/error.c index 89fc55629f..60e6c9e799 100644 --- a/contrib/restricted/aws/aws-c-common/source/error.c +++ b/contrib/restricted/aws/aws-c-common/source/error.c @@ -1,149 +1,149 @@ /** * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. - */ - -#include <aws/common/error.h> - -#include <aws/common/common.h> - + */ + +#include <aws/common/error.h> + +#include <aws/common/common.h> + #include <errno.h> -#include <stdio.h> -#include <stdlib.h> - -static AWS_THREAD_LOCAL int tl_last_error = 0; - -static aws_error_handler_fn *s_global_handler = NULL; -static void *s_global_error_context = NULL; - -static AWS_THREAD_LOCAL aws_error_handler_fn *tl_thread_handler = NULL; -AWS_THREAD_LOCAL void *tl_thread_handler_context = NULL; - -/* Since slot size is 00000100 00000000, to divide, we need to shift right by 10 - * bits to find the slot, and to find the modulus, we use a binary and with +#include <stdio.h> +#include <stdlib.h> + +static AWS_THREAD_LOCAL int tl_last_error = 0; + +static aws_error_handler_fn *s_global_handler = NULL; +static void *s_global_error_context = NULL; + +static AWS_THREAD_LOCAL aws_error_handler_fn *tl_thread_handler = NULL; +AWS_THREAD_LOCAL void *tl_thread_handler_context = NULL; + +/* Since slot size is 00000100 00000000, to divide, we need to shift right by 10 + * bits to find the slot, and to find the modulus, we use a binary and with * 00000011 11111111 to find the index in that slot. */ #define SLOT_MASK (AWS_ERROR_ENUM_STRIDE - 1) - + static const int MAX_ERROR_CODE = AWS_ERROR_ENUM_STRIDE * AWS_PACKAGE_SLOTS; - + static const struct aws_error_info_list *volatile ERROR_SLOTS[AWS_PACKAGE_SLOTS] = {0}; - -int aws_last_error(void) { - return tl_last_error; -} - -static const struct aws_error_info *get_error_by_code(int err) { - if (err >= MAX_ERROR_CODE || err < 0) { - return NULL; - } - + +int aws_last_error(void) { + return tl_last_error; +} + +static const struct aws_error_info *get_error_by_code(int err) { + if (err >= MAX_ERROR_CODE || err < 0) { + return NULL; + } + uint32_t slot_index = (uint32_t)err >> AWS_ERROR_ENUM_STRIDE_BITS; uint32_t error_index = (uint32_t)err & SLOT_MASK; - - const struct aws_error_info_list *error_slot = ERROR_SLOTS[slot_index]; - - if (!error_slot || error_index >= error_slot->count) { - return NULL; - } - - return &error_slot->error_list[error_index]; -} - -const char *aws_error_str(int err) { - const struct aws_error_info *error_info = get_error_by_code(err); - - if (error_info) { - return error_info->error_str; - } - - return "Unknown Error Code"; -} - -const char *aws_error_name(int err) { - const struct aws_error_info *error_info = get_error_by_code(err); - - if (error_info) { - return error_info->literal_name; - } - - return "Unknown Error Code"; -} - -const char *aws_error_lib_name(int err) { - const struct aws_error_info *error_info = get_error_by_code(err); - - if (error_info) { - return error_info->lib_name; - } - - return "Unknown Error Code"; -} - -const char *aws_error_debug_str(int err) { - const struct aws_error_info *error_info = get_error_by_code(err); - - if (error_info) { - return error_info->formatted_name; - } - - return "Unknown Error Code"; -} - -void aws_raise_error_private(int err) { - tl_last_error = err; - - if (tl_thread_handler) { - tl_thread_handler(tl_last_error, tl_thread_handler_context); - } else if (s_global_handler) { - s_global_handler(tl_last_error, s_global_error_context); - } -} - -void aws_reset_error(void) { - tl_last_error = 0; -} - -void aws_restore_error(int err) { - tl_last_error = err; -} - -aws_error_handler_fn *aws_set_global_error_handler_fn(aws_error_handler_fn *handler, void *ctx) { - aws_error_handler_fn *old_handler = s_global_handler; - s_global_handler = handler; - s_global_error_context = ctx; - - return old_handler; -} - -aws_error_handler_fn *aws_set_thread_local_error_handler_fn(aws_error_handler_fn *handler, void *ctx) { - aws_error_handler_fn *old_handler = tl_thread_handler; - tl_thread_handler = handler; - tl_thread_handler_context = ctx; - - return old_handler; -} - -void aws_register_error_info(const struct aws_error_info_list *error_info) { - /* - * We're not so worried about these asserts being removed in an NDEBUG build - * - we'll either segfault immediately (for the first two) or for the count - * assert, the registration will be ineffective. - */ + + const struct aws_error_info_list *error_slot = ERROR_SLOTS[slot_index]; + + if (!error_slot || error_index >= error_slot->count) { + return NULL; + } + + return &error_slot->error_list[error_index]; +} + +const char *aws_error_str(int err) { + const struct aws_error_info *error_info = get_error_by_code(err); + + if (error_info) { + return error_info->error_str; + } + + return "Unknown Error Code"; +} + +const char *aws_error_name(int err) { + const struct aws_error_info *error_info = get_error_by_code(err); + + if (error_info) { + return error_info->literal_name; + } + + return "Unknown Error Code"; +} + +const char *aws_error_lib_name(int err) { + const struct aws_error_info *error_info = get_error_by_code(err); + + if (error_info) { + return error_info->lib_name; + } + + return "Unknown Error Code"; +} + +const char *aws_error_debug_str(int err) { + const struct aws_error_info *error_info = get_error_by_code(err); + + if (error_info) { + return error_info->formatted_name; + } + + return "Unknown Error Code"; +} + +void aws_raise_error_private(int err) { + tl_last_error = err; + + if (tl_thread_handler) { + tl_thread_handler(tl_last_error, tl_thread_handler_context); + } else if (s_global_handler) { + s_global_handler(tl_last_error, s_global_error_context); + } +} + +void aws_reset_error(void) { + tl_last_error = 0; +} + +void aws_restore_error(int err) { + tl_last_error = err; +} + +aws_error_handler_fn *aws_set_global_error_handler_fn(aws_error_handler_fn *handler, void *ctx) { + aws_error_handler_fn *old_handler = s_global_handler; + s_global_handler = handler; + s_global_error_context = ctx; + + return old_handler; +} + +aws_error_handler_fn *aws_set_thread_local_error_handler_fn(aws_error_handler_fn *handler, void *ctx) { + aws_error_handler_fn *old_handler = tl_thread_handler; + tl_thread_handler = handler; + tl_thread_handler_context = ctx; + + return old_handler; +} + +void aws_register_error_info(const struct aws_error_info_list *error_info) { + /* + * We're not so worried about these asserts being removed in an NDEBUG build + * - we'll either segfault immediately (for the first two) or for the count + * assert, the registration will be ineffective. + */ AWS_FATAL_ASSERT(error_info); AWS_FATAL_ASSERT(error_info->error_list); AWS_FATAL_ASSERT(error_info->count); - + const int min_range = error_info->error_list[0].error_code; const int slot_index = min_range >> AWS_ERROR_ENUM_STRIDE_BITS; - + if (slot_index >= AWS_PACKAGE_SLOTS || slot_index < 0) { /* This is an NDEBUG build apparently. Kill the process rather than * corrupting heap. */ fprintf(stderr, "Bad error slot index %d\n", slot_index); AWS_FATAL_ASSERT(false); } - + #if DEBUG_BUILD /* Assert that error info entries are in the right order. */ for (int i = 1; i < error_info->count; ++i) { @@ -159,7 +159,7 @@ void aws_register_error_info(const struct aws_error_info_list *error_info) { } } #endif /* DEBUG_BUILD */ - + ERROR_SLOTS[slot_index] = error_info; } @@ -172,14 +172,14 @@ void aws_unregister_error_info(const struct aws_error_info_list *error_info) { const int slot_index = min_range >> AWS_ERROR_ENUM_STRIDE_BITS; if (slot_index >= AWS_PACKAGE_SLOTS || slot_index < 0) { - /* This is an NDEBUG build apparently. Kill the process rather than - * corrupting heap. */ + /* This is an NDEBUG build apparently. Kill the process rather than + * corrupting heap. */ fprintf(stderr, "Bad error slot index %d\n", slot_index); AWS_FATAL_ASSERT(0); - } - + } + ERROR_SLOTS[slot_index] = NULL; -} +} int aws_translate_and_raise_io_error(int error_no) { switch (error_no) { diff --git a/contrib/restricted/aws/aws-c-common/source/hash_table.c b/contrib/restricted/aws/aws-c-common/source/hash_table.c index e59a30db18..a8125a2df1 100644 --- a/contrib/restricted/aws/aws-c-common/source/hash_table.c +++ b/contrib/restricted/aws/aws-c-common/source/hash_table.c @@ -1,57 +1,57 @@ /** * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. - */ - -/* For more information on how the RH hash works and in particular how we do - * deletions, see: - * http://codecapsule.com/2013/11/17/robin-hood-hashing-backward-shift-deletion/ - */ - -#include <aws/common/hash_table.h> -#include <aws/common/math.h> -#include <aws/common/private/hash_table_impl.h> -#include <aws/common/string.h> - -#include <limits.h> -#include <stdio.h> -#include <stdlib.h> - -/* Include lookup3.c so we can (potentially) inline it and make use of the mix() - * macro. */ + */ + +/* For more information on how the RH hash works and in particular how we do + * deletions, see: + * http://codecapsule.com/2013/11/17/robin-hood-hashing-backward-shift-deletion/ + */ + +#include <aws/common/hash_table.h> +#include <aws/common/math.h> +#include <aws/common/private/hash_table_impl.h> +#include <aws/common/string.h> + +#include <limits.h> +#include <stdio.h> +#include <stdlib.h> + +/* Include lookup3.c so we can (potentially) inline it and make use of the mix() + * macro. */ #include <aws/common/private/lookup3.inl> - -static void s_suppress_unused_lookup3_func_warnings(void) { - /* We avoid making changes to lookup3 if we can avoid it, but since it has functions - * we're not using, reference them somewhere to suppress the unused function warning. - */ - (void)hashword; - (void)hashword2; - (void)hashlittle; - (void)hashbig; -} - + +static void s_suppress_unused_lookup3_func_warnings(void) { + /* We avoid making changes to lookup3 if we can avoid it, but since it has functions + * we're not using, reference them somewhere to suppress the unused function warning. + */ + (void)hashword; + (void)hashword2; + (void)hashlittle; + (void)hashbig; +} + /** * Calculate the hash for the given key. * Ensures a reasonable semantics for null keys. * Ensures that no object ever hashes to 0, which is the sentinal value for an empty hash element. */ -static uint64_t s_hash_for(struct hash_table_state *state, const void *key) { +static uint64_t s_hash_for(struct hash_table_state *state, const void *key) { AWS_PRECONDITION(hash_table_state_is_valid(state)); - s_suppress_unused_lookup3_func_warnings(); - + s_suppress_unused_lookup3_func_warnings(); + if (key == NULL) { /* The best answer */ return 42; } - uint64_t hash_code = state->hash_fn(key); - if (!hash_code) { - hash_code = 1; - } + uint64_t hash_code = state->hash_fn(key); + if (!hash_code) { + hash_code = 1; + } AWS_RETURN_WITH_POSTCONDITION(hash_code, hash_code != 0); -} - +} + /** * Check equality of two objects, with a reasonable semantics for null. */ @@ -77,270 +77,270 @@ static bool s_hash_keys_eq(struct hash_table_state *state, const void *a, const AWS_RETURN_WITH_POSTCONDITION(rval, hash_table_state_is_valid(state)); } -static size_t s_index_for(struct hash_table_state *map, struct hash_table_entry *entry) { - AWS_PRECONDITION(hash_table_state_is_valid(map)); - size_t index = entry - map->slots; +static size_t s_index_for(struct hash_table_state *map, struct hash_table_entry *entry) { + AWS_PRECONDITION(hash_table_state_is_valid(map)); + size_t index = entry - map->slots; AWS_RETURN_WITH_POSTCONDITION(index, index < map->size && hash_table_state_is_valid(map)); -} - -#if 0 -/* Useful debugging code for anyone working on this in the future */ -static uint64_t s_distance(struct hash_table_state *state, int index) { - return (index - state->slots[index].hash_code) & state->mask; -} - -void hash_dump(struct aws_hash_table *tbl) { - struct hash_table_state *state = tbl->p_impl; - - printf("Dumping hash table contents:\n"); - - for (int i = 0; i < state->size; i++) { - printf("%7d: ", i); - struct hash_table_entry *e = &state->slots[i]; - if (!e->hash_code) { - printf("EMPTY\n"); - } else { - printf("k: %p v: %p hash_code: %lld displacement: %lld\n", - e->element.key, e->element.value, e->hash_code, - (i - e->hash_code) & state->mask); - } - } -} -#endif - -#if 0 -/* Not currently exposed as an API. Should we have something like this? Useful for benchmarks */ -AWS_COMMON_API -void aws_hash_table_print_stats(struct aws_hash_table *table) { - struct hash_table_state *state = table->p_impl; - uint64_t total_disp = 0; - uint64_t max_disp = 0; - - printf("\n=== Hash table statistics ===\n"); - printf("Table size: %zu/%zu (max load %zu, remaining %zu)\n", state->entry_count, state->size, state->max_load, state->max_load - state->entry_count); - printf("Load factor: %02.2lf%% (max %02.2lf%%)\n", - 100.0 * ((double)state->entry_count / (double)state->size), - state->max_load_factor); - - for (size_t i = 0; i < state->size; i++) { - if (state->slots[i].hash_code) { - int displacement = distance(state, i); - total_disp += displacement; - if (displacement > max_disp) { - max_disp = displacement; - } - } - } - - size_t *disp_counts = calloc(sizeof(*disp_counts), max_disp + 1); - - for (size_t i = 0; i < state->size; i++) { - if (state->slots[i].hash_code) { - disp_counts[distance(state, i)]++; - } - } - - uint64_t median = 0; - uint64_t passed = 0; - for (uint64_t i = 0; i <= max_disp && passed < total_disp / 2; i++) { - median = i; - passed += disp_counts[i]; - } - - printf("Displacement statistics: Avg %02.2lf max %llu median %llu\n", (double)total_disp / (double)state->entry_count, max_disp, median); - for (uint64_t i = 0; i <= max_disp; i++) { - printf("Displacement %2lld: %zu entries\n", i, disp_counts[i]); - } - free(disp_counts); - printf("\n"); -} -#endif - -size_t aws_hash_table_get_entry_count(const struct aws_hash_table *map) { - struct hash_table_state *state = map->p_impl; - return state->entry_count; -} - -/* Given a header template, allocates space for a hash table of the appropriate - * size, and copies the state header into this allocated memory, which is - * returned. - */ -static struct hash_table_state *s_alloc_state(const struct hash_table_state *template) { - size_t required_bytes; - if (hash_table_state_required_bytes(template->size, &required_bytes)) { - return NULL; - } - - /* An empty slot has hashcode 0. So this marks all slots as empty */ - struct hash_table_state *state = aws_mem_calloc(template->alloc, 1, required_bytes); - - if (state == NULL) { - return state; - } - - *state = *template; - return state; -} - -/* Computes the correct size and max_load based on a requested size. */ -static int s_update_template_size(struct hash_table_state *template, size_t expected_elements) { - size_t min_size = expected_elements; - - if (min_size < 2) { - min_size = 2; - } - - /* size is always a power of 2 */ - size_t size; - if (aws_round_up_to_power_of_two(min_size, &size)) { - return AWS_OP_ERR; - } - - /* Update the template once we've calculated everything successfully */ - template->size = size; - template->max_load = (size_t)(template->max_load_factor * (double)template->size); - /* Ensure that there is always at least one empty slot in the hash table */ - if (template->max_load >= size) { - template->max_load = size - 1; - } - - /* Since size is a power of 2: (index & (size - 1)) == (index % size) */ - template->mask = size - 1; - - return AWS_OP_SUCCESS; -} - -int aws_hash_table_init( - struct aws_hash_table *map, - struct aws_allocator *alloc, - size_t size, - aws_hash_fn *hash_fn, - aws_hash_callback_eq_fn *equals_fn, - aws_hash_callback_destroy_fn *destroy_key_fn, - aws_hash_callback_destroy_fn *destroy_value_fn) { +} + +#if 0 +/* Useful debugging code for anyone working on this in the future */ +static uint64_t s_distance(struct hash_table_state *state, int index) { + return (index - state->slots[index].hash_code) & state->mask; +} + +void hash_dump(struct aws_hash_table *tbl) { + struct hash_table_state *state = tbl->p_impl; + + printf("Dumping hash table contents:\n"); + + for (int i = 0; i < state->size; i++) { + printf("%7d: ", i); + struct hash_table_entry *e = &state->slots[i]; + if (!e->hash_code) { + printf("EMPTY\n"); + } else { + printf("k: %p v: %p hash_code: %lld displacement: %lld\n", + e->element.key, e->element.value, e->hash_code, + (i - e->hash_code) & state->mask); + } + } +} +#endif + +#if 0 +/* Not currently exposed as an API. Should we have something like this? Useful for benchmarks */ +AWS_COMMON_API +void aws_hash_table_print_stats(struct aws_hash_table *table) { + struct hash_table_state *state = table->p_impl; + uint64_t total_disp = 0; + uint64_t max_disp = 0; + + printf("\n=== Hash table statistics ===\n"); + printf("Table size: %zu/%zu (max load %zu, remaining %zu)\n", state->entry_count, state->size, state->max_load, state->max_load - state->entry_count); + printf("Load factor: %02.2lf%% (max %02.2lf%%)\n", + 100.0 * ((double)state->entry_count / (double)state->size), + state->max_load_factor); + + for (size_t i = 0; i < state->size; i++) { + if (state->slots[i].hash_code) { + int displacement = distance(state, i); + total_disp += displacement; + if (displacement > max_disp) { + max_disp = displacement; + } + } + } + + size_t *disp_counts = calloc(sizeof(*disp_counts), max_disp + 1); + + for (size_t i = 0; i < state->size; i++) { + if (state->slots[i].hash_code) { + disp_counts[distance(state, i)]++; + } + } + + uint64_t median = 0; + uint64_t passed = 0; + for (uint64_t i = 0; i <= max_disp && passed < total_disp / 2; i++) { + median = i; + passed += disp_counts[i]; + } + + printf("Displacement statistics: Avg %02.2lf max %llu median %llu\n", (double)total_disp / (double)state->entry_count, max_disp, median); + for (uint64_t i = 0; i <= max_disp; i++) { + printf("Displacement %2lld: %zu entries\n", i, disp_counts[i]); + } + free(disp_counts); + printf("\n"); +} +#endif + +size_t aws_hash_table_get_entry_count(const struct aws_hash_table *map) { + struct hash_table_state *state = map->p_impl; + return state->entry_count; +} + +/* Given a header template, allocates space for a hash table of the appropriate + * size, and copies the state header into this allocated memory, which is + * returned. + */ +static struct hash_table_state *s_alloc_state(const struct hash_table_state *template) { + size_t required_bytes; + if (hash_table_state_required_bytes(template->size, &required_bytes)) { + return NULL; + } + + /* An empty slot has hashcode 0. So this marks all slots as empty */ + struct hash_table_state *state = aws_mem_calloc(template->alloc, 1, required_bytes); + + if (state == NULL) { + return state; + } + + *state = *template; + return state; +} + +/* Computes the correct size and max_load based on a requested size. */ +static int s_update_template_size(struct hash_table_state *template, size_t expected_elements) { + size_t min_size = expected_elements; + + if (min_size < 2) { + min_size = 2; + } + + /* size is always a power of 2 */ + size_t size; + if (aws_round_up_to_power_of_two(min_size, &size)) { + return AWS_OP_ERR; + } + + /* Update the template once we've calculated everything successfully */ + template->size = size; + template->max_load = (size_t)(template->max_load_factor * (double)template->size); + /* Ensure that there is always at least one empty slot in the hash table */ + if (template->max_load >= size) { + template->max_load = size - 1; + } + + /* Since size is a power of 2: (index & (size - 1)) == (index % size) */ + template->mask = size - 1; + + return AWS_OP_SUCCESS; +} + +int aws_hash_table_init( + struct aws_hash_table *map, + struct aws_allocator *alloc, + size_t size, + aws_hash_fn *hash_fn, + aws_hash_callback_eq_fn *equals_fn, + aws_hash_callback_destroy_fn *destroy_key_fn, + aws_hash_callback_destroy_fn *destroy_value_fn) { AWS_PRECONDITION(map != NULL); AWS_PRECONDITION(alloc != NULL); AWS_PRECONDITION(hash_fn != NULL); AWS_PRECONDITION(equals_fn != NULL); - - struct hash_table_state template; - template.hash_fn = hash_fn; - template.equals_fn = equals_fn; - template.destroy_key_fn = destroy_key_fn; - template.destroy_value_fn = destroy_value_fn; - template.alloc = alloc; - - template.entry_count = 0; - template.max_load_factor = 0.95; /* TODO - make configurable? */ - - if (s_update_template_size(&template, size)) { - return AWS_OP_ERR; - } - map->p_impl = s_alloc_state(&template); - - if (!map->p_impl) { - return AWS_OP_ERR; - } - + + struct hash_table_state template; + template.hash_fn = hash_fn; + template.equals_fn = equals_fn; + template.destroy_key_fn = destroy_key_fn; + template.destroy_value_fn = destroy_value_fn; + template.alloc = alloc; + + template.entry_count = 0; + template.max_load_factor = 0.95; /* TODO - make configurable? */ + + if (s_update_template_size(&template, size)) { + return AWS_OP_ERR; + } + map->p_impl = s_alloc_state(&template); + + if (!map->p_impl) { + return AWS_OP_ERR; + } + AWS_SUCCEED_WITH_POSTCONDITION(aws_hash_table_is_valid(map)); -} - -void aws_hash_table_clean_up(struct aws_hash_table *map) { +} + +void aws_hash_table_clean_up(struct aws_hash_table *map) { AWS_PRECONDITION(map != NULL); AWS_PRECONDITION( map->p_impl == NULL || aws_hash_table_is_valid(map), "Input aws_hash_table [map] must be valid or hash_table_state pointer [map->p_impl] must be NULL, in case " "aws_hash_table_clean_up was called twice."); - struct hash_table_state *state = map->p_impl; - - /* Ensure that we're idempotent */ - if (!state) { - return; - } - - aws_hash_table_clear(map); + struct hash_table_state *state = map->p_impl; + + /* Ensure that we're idempotent */ + if (!state) { + return; + } + + aws_hash_table_clear(map); aws_mem_release(map->p_impl->alloc, map->p_impl); - - map->p_impl = NULL; + + map->p_impl = NULL; AWS_POSTCONDITION(map->p_impl == NULL); -} - -void aws_hash_table_swap(struct aws_hash_table *AWS_RESTRICT a, struct aws_hash_table *AWS_RESTRICT b) { - AWS_PRECONDITION(a != b); - struct aws_hash_table tmp = *a; - *a = *b; - *b = tmp; -} - -void aws_hash_table_move(struct aws_hash_table *AWS_RESTRICT to, struct aws_hash_table *AWS_RESTRICT from) { +} + +void aws_hash_table_swap(struct aws_hash_table *AWS_RESTRICT a, struct aws_hash_table *AWS_RESTRICT b) { + AWS_PRECONDITION(a != b); + struct aws_hash_table tmp = *a; + *a = *b; + *b = tmp; +} + +void aws_hash_table_move(struct aws_hash_table *AWS_RESTRICT to, struct aws_hash_table *AWS_RESTRICT from) { AWS_PRECONDITION(to != NULL); AWS_PRECONDITION(from != NULL); AWS_PRECONDITION(to != from); AWS_PRECONDITION(aws_hash_table_is_valid(from)); - *to = *from; - AWS_ZERO_STRUCT(*from); - AWS_POSTCONDITION(aws_hash_table_is_valid(to)); -} - -/* Tries to find where the requested key is or where it should go if put. - * Returns AWS_ERROR_SUCCESS if the item existed (leaving it in *entry), - * or AWS_ERROR_HASHTBL_ITEM_NOT_FOUND if it did not (putting its destination - * in *entry). Note that this does not take care of displacing whatever was in - * that entry before. - * - * probe_idx is set to the probe index of the entry found. - */ - -static int s_find_entry1( - struct hash_table_state *state, - uint64_t hash_code, - const void *key, - struct hash_table_entry **p_entry, - size_t *p_probe_idx); - -/* Inlined fast path: Check the first slot, only. */ -/* TODO: Force inlining? */ -static int inline s_find_entry( - struct hash_table_state *state, - uint64_t hash_code, - const void *key, - struct hash_table_entry **p_entry, - size_t *p_probe_idx) { - struct hash_table_entry *entry = &state->slots[hash_code & state->mask]; - - if (entry->hash_code == 0) { - if (p_probe_idx) { - *p_probe_idx = 0; - } - *p_entry = entry; - return AWS_ERROR_HASHTBL_ITEM_NOT_FOUND; - } - + *to = *from; + AWS_ZERO_STRUCT(*from); + AWS_POSTCONDITION(aws_hash_table_is_valid(to)); +} + +/* Tries to find where the requested key is or where it should go if put. + * Returns AWS_ERROR_SUCCESS if the item existed (leaving it in *entry), + * or AWS_ERROR_HASHTBL_ITEM_NOT_FOUND if it did not (putting its destination + * in *entry). Note that this does not take care of displacing whatever was in + * that entry before. + * + * probe_idx is set to the probe index of the entry found. + */ + +static int s_find_entry1( + struct hash_table_state *state, + uint64_t hash_code, + const void *key, + struct hash_table_entry **p_entry, + size_t *p_probe_idx); + +/* Inlined fast path: Check the first slot, only. */ +/* TODO: Force inlining? */ +static int inline s_find_entry( + struct hash_table_state *state, + uint64_t hash_code, + const void *key, + struct hash_table_entry **p_entry, + size_t *p_probe_idx) { + struct hash_table_entry *entry = &state->slots[hash_code & state->mask]; + + if (entry->hash_code == 0) { + if (p_probe_idx) { + *p_probe_idx = 0; + } + *p_entry = entry; + return AWS_ERROR_HASHTBL_ITEM_NOT_FOUND; + } + if (entry->hash_code == hash_code && s_hash_keys_eq(state, key, entry->element.key)) { - if (p_probe_idx) { - *p_probe_idx = 0; - } - *p_entry = entry; - return AWS_OP_SUCCESS; - } - - return s_find_entry1(state, hash_code, key, p_entry, p_probe_idx); -} - -static int s_find_entry1( - struct hash_table_state *state, - uint64_t hash_code, - const void *key, - struct hash_table_entry **p_entry, - size_t *p_probe_idx) { - size_t probe_idx = 1; - /* If we find a deleted entry, we record that index and return it as our probe index (i.e. we'll keep searching to - * see if it already exists, but if not we'll overwrite the deleted entry). - */ - - int rv; - struct hash_table_entry *entry; + if (p_probe_idx) { + *p_probe_idx = 0; + } + *p_entry = entry; + return AWS_OP_SUCCESS; + } + + return s_find_entry1(state, hash_code, key, p_entry, p_probe_idx); +} + +static int s_find_entry1( + struct hash_table_state *state, + uint64_t hash_code, + const void *key, + struct hash_table_entry **p_entry, + size_t *p_probe_idx) { + size_t probe_idx = 1; + /* If we find a deleted entry, we record that index and return it as our probe index (i.e. we'll keep searching to + * see if it already exists, but if not we'll overwrite the deleted entry). + */ + + int rv; + struct hash_table_entry *entry; /* This loop is guaranteed to terminate because entry_probe is bounded above by state->mask (i.e. state->size - 1). * Since probe_idx increments every loop iteration, it will become larger than entry_probe after at most state->size * transitions and the loop will exit (if it hasn't already) @@ -350,82 +350,82 @@ static int s_find_entry1( # pragma CPROVER check push # pragma CPROVER check disable "unsigned-overflow" #endif - uint64_t index = (hash_code + probe_idx) & state->mask; + uint64_t index = (hash_code + probe_idx) & state->mask; #ifdef CBMC # pragma CPROVER check pop #endif - entry = &state->slots[index]; - if (!entry->hash_code) { - rv = AWS_ERROR_HASHTBL_ITEM_NOT_FOUND; - break; - } - + entry = &state->slots[index]; + if (!entry->hash_code) { + rv = AWS_ERROR_HASHTBL_ITEM_NOT_FOUND; + break; + } + if (entry->hash_code == hash_code && s_hash_keys_eq(state, key, entry->element.key)) { - rv = AWS_ERROR_SUCCESS; - break; - } - + rv = AWS_ERROR_SUCCESS; + break; + } + #ifdef CBMC # pragma CPROVER check push # pragma CPROVER check disable "unsigned-overflow" #endif - uint64_t entry_probe = (index - entry->hash_code) & state->mask; + uint64_t entry_probe = (index - entry->hash_code) & state->mask; #ifdef CBMC # pragma CPROVER check pop #endif - - if (entry_probe < probe_idx) { - /* We now know that our target entry cannot exist; if it did exist, - * it would be at the current location as it has a higher probe - * length than the entry we are examining and thus would have - * preempted that item - */ - rv = AWS_ERROR_HASHTBL_ITEM_NOT_FOUND; - break; - } - - probe_idx++; + + if (entry_probe < probe_idx) { + /* We now know that our target entry cannot exist; if it did exist, + * it would be at the current location as it has a higher probe + * length than the entry we are examining and thus would have + * preempted that item + */ + rv = AWS_ERROR_HASHTBL_ITEM_NOT_FOUND; + break; + } + + probe_idx++; + } + + *p_entry = entry; + if (p_probe_idx) { + *p_probe_idx = probe_idx; } - - *p_entry = entry; - if (p_probe_idx) { - *p_probe_idx = probe_idx; - } - - return rv; -} - -int aws_hash_table_find(const struct aws_hash_table *map, const void *key, struct aws_hash_element **p_elem) { + + return rv; +} + +int aws_hash_table_find(const struct aws_hash_table *map, const void *key, struct aws_hash_element **p_elem) { AWS_PRECONDITION(aws_hash_table_is_valid(map)); AWS_PRECONDITION(AWS_OBJECT_PTR_IS_WRITABLE(p_elem), "Input aws_hash_element pointer [p_elem] must be writable."); - struct hash_table_state *state = map->p_impl; - uint64_t hash_code = s_hash_for(state, key); - struct hash_table_entry *entry; - - int rv = s_find_entry(state, hash_code, key, &entry, NULL); - - if (rv == AWS_ERROR_SUCCESS) { - *p_elem = &entry->element; - } else { - *p_elem = NULL; - } + struct hash_table_state *state = map->p_impl; + uint64_t hash_code = s_hash_for(state, key); + struct hash_table_entry *entry; + + int rv = s_find_entry(state, hash_code, key, &entry, NULL); + + if (rv == AWS_ERROR_SUCCESS) { + *p_elem = &entry->element; + } else { + *p_elem = NULL; + } AWS_SUCCEED_WITH_POSTCONDITION(aws_hash_table_is_valid(map)); -} - +} + /** * Attempts to find a home for the given entry. * If the entry was empty (i.e. hash-code of 0), then the function does nothing and returns NULL * Otherwise, it emplaces the item, and returns a pointer to the newly emplaced entry. * This function is only called after the hash-table has been expanded to fit the new element, * so it should never fail. - */ -static struct hash_table_entry *s_emplace_item( - struct hash_table_state *state, - struct hash_table_entry entry, - size_t probe_idx) { + */ +static struct hash_table_entry *s_emplace_item( + struct hash_table_state *state, + struct hash_table_entry entry, + size_t probe_idx) { AWS_PRECONDITION(hash_table_state_is_valid(state)); - + if (entry.hash_code == 0) { AWS_RETURN_WITH_POSTCONDITION(NULL, hash_table_state_is_valid(state)); } @@ -439,263 +439,263 @@ static struct hash_table_entry *s_emplace_item( # pragma CPROVER check push # pragma CPROVER check disable "unsigned-overflow" #endif - size_t index = (size_t)(entry.hash_code + probe_idx) & state->mask; + size_t index = (size_t)(entry.hash_code + probe_idx) & state->mask; #ifdef CBMC # pragma CPROVER check pop #endif - struct hash_table_entry *victim = &state->slots[index]; - + struct hash_table_entry *victim = &state->slots[index]; + #ifdef CBMC # pragma CPROVER check push # pragma CPROVER check disable "unsigned-overflow" #endif - size_t victim_probe_idx = (size_t)(index - victim->hash_code) & state->mask; + size_t victim_probe_idx = (size_t)(index - victim->hash_code) & state->mask; #ifdef CBMC # pragma CPROVER check pop #endif - - if (!victim->hash_code || victim_probe_idx < probe_idx) { + + if (!victim->hash_code || victim_probe_idx < probe_idx) { /* The first thing we emplace is the entry itself. A pointer to its location becomes the rval */ if (!rval) { rval = victim; - } - - struct hash_table_entry tmp = *victim; - *victim = entry; - entry = tmp; - - probe_idx = victim_probe_idx + 1; - } else { - probe_idx++; - } - } - + } + + struct hash_table_entry tmp = *victim; + *victim = entry; + entry = tmp; + + probe_idx = victim_probe_idx + 1; + } else { + probe_idx++; + } + } + AWS_RETURN_WITH_POSTCONDITION( rval, hash_table_state_is_valid(state) && rval >= &state->slots[0] && rval < &state->slots[state->size], "Output hash_table_entry pointer [rval] must point in the slots of [state]."); -} - -static int s_expand_table(struct aws_hash_table *map) { - struct hash_table_state *old_state = map->p_impl; - struct hash_table_state template = *old_state; - +} + +static int s_expand_table(struct aws_hash_table *map) { + struct hash_table_state *old_state = map->p_impl; + struct hash_table_state template = *old_state; + size_t new_size; if (aws_mul_size_checked(template.size, 2, &new_size)) { return AWS_OP_ERR; } - + if (s_update_template_size(&template, new_size)) { return AWS_OP_ERR; } - struct hash_table_state *new_state = s_alloc_state(&template); - if (!new_state) { - return AWS_OP_ERR; - } - - for (size_t i = 0; i < old_state->size; i++) { - struct hash_table_entry entry = old_state->slots[i]; - if (entry.hash_code) { - /* We can directly emplace since we know we won't put the same item twice */ - s_emplace_item(new_state, entry, 0); - } - } - - map->p_impl = new_state; - aws_mem_release(new_state->alloc, old_state); - - return AWS_OP_SUCCESS; -} - -int aws_hash_table_create( - struct aws_hash_table *map, - const void *key, - struct aws_hash_element **p_elem, - int *was_created) { - - struct hash_table_state *state = map->p_impl; - uint64_t hash_code = s_hash_for(state, key); - struct hash_table_entry *entry; - size_t probe_idx; - int ignored; - if (!was_created) { - was_created = &ignored; - } - - int rv = s_find_entry(state, hash_code, key, &entry, &probe_idx); - - if (rv == AWS_ERROR_SUCCESS) { - if (p_elem) { - *p_elem = &entry->element; - } - *was_created = 0; - return AWS_OP_SUCCESS; - } - - /* Okay, we need to add an entry. Check the load factor first. */ - size_t incr_entry_count; - if (aws_add_size_checked(state->entry_count, 1, &incr_entry_count)) { - return AWS_OP_ERR; - } - if (incr_entry_count > state->max_load) { - rv = s_expand_table(map); - if (rv != AWS_OP_SUCCESS) { - /* Any error was already raised in expand_table */ - return rv; - } - state = map->p_impl; - /* If we expanded the table, we need to discard the probe index returned from find_entry, - * as it's likely that we can find a more desirable slot. If we don't, then later gets will - * terminate before reaching our probe index. - - * n.b. currently we ignore this probe_idx subsequently, but leaving - this here so we don't - * forget when we optimize later. */ - probe_idx = 0; - } - - state->entry_count++; - struct hash_table_entry new_entry; - new_entry.element.key = key; - new_entry.element.value = NULL; - new_entry.hash_code = hash_code; - - entry = s_emplace_item(state, new_entry, probe_idx); - - if (p_elem) { - *p_elem = &entry->element; - } - - *was_created = 1; - - return AWS_OP_SUCCESS; -} - -AWS_COMMON_API -int aws_hash_table_put(struct aws_hash_table *map, const void *key, void *value, int *was_created) { - struct aws_hash_element *p_elem; - int was_created_fallback; - - if (!was_created) { - was_created = &was_created_fallback; - } - - if (aws_hash_table_create(map, key, &p_elem, was_created)) { - return AWS_OP_ERR; - } - - /* - * aws_hash_table_create might resize the table, which results in map->p_impl changing. - * It is therefore important to wait to read p_impl until after we return. - */ - struct hash_table_state *state = map->p_impl; - - if (!*was_created) { - if (p_elem->key != key && state->destroy_key_fn) { - state->destroy_key_fn((void *)p_elem->key); - } - - if (state->destroy_value_fn) { - state->destroy_value_fn((void *)p_elem->value); - } - } - - p_elem->key = key; - p_elem->value = value; - - return AWS_OP_SUCCESS; -} - -/* Clears an entry. Does _not_ invoke destructor callbacks. - * Returns the last slot touched (note that if we wrap, we'll report an index - * lower than the original entry's index) - */ -static size_t s_remove_entry(struct hash_table_state *state, struct hash_table_entry *entry) { - AWS_PRECONDITION(hash_table_state_is_valid(state)); - AWS_PRECONDITION(state->entry_count > 0); + struct hash_table_state *new_state = s_alloc_state(&template); + if (!new_state) { + return AWS_OP_ERR; + } + + for (size_t i = 0; i < old_state->size; i++) { + struct hash_table_entry entry = old_state->slots[i]; + if (entry.hash_code) { + /* We can directly emplace since we know we won't put the same item twice */ + s_emplace_item(new_state, entry, 0); + } + } + + map->p_impl = new_state; + aws_mem_release(new_state->alloc, old_state); + + return AWS_OP_SUCCESS; +} + +int aws_hash_table_create( + struct aws_hash_table *map, + const void *key, + struct aws_hash_element **p_elem, + int *was_created) { + + struct hash_table_state *state = map->p_impl; + uint64_t hash_code = s_hash_for(state, key); + struct hash_table_entry *entry; + size_t probe_idx; + int ignored; + if (!was_created) { + was_created = &ignored; + } + + int rv = s_find_entry(state, hash_code, key, &entry, &probe_idx); + + if (rv == AWS_ERROR_SUCCESS) { + if (p_elem) { + *p_elem = &entry->element; + } + *was_created = 0; + return AWS_OP_SUCCESS; + } + + /* Okay, we need to add an entry. Check the load factor first. */ + size_t incr_entry_count; + if (aws_add_size_checked(state->entry_count, 1, &incr_entry_count)) { + return AWS_OP_ERR; + } + if (incr_entry_count > state->max_load) { + rv = s_expand_table(map); + if (rv != AWS_OP_SUCCESS) { + /* Any error was already raised in expand_table */ + return rv; + } + state = map->p_impl; + /* If we expanded the table, we need to discard the probe index returned from find_entry, + * as it's likely that we can find a more desirable slot. If we don't, then later gets will + * terminate before reaching our probe index. + + * n.b. currently we ignore this probe_idx subsequently, but leaving + this here so we don't + * forget when we optimize later. */ + probe_idx = 0; + } + + state->entry_count++; + struct hash_table_entry new_entry; + new_entry.element.key = key; + new_entry.element.value = NULL; + new_entry.hash_code = hash_code; + + entry = s_emplace_item(state, new_entry, probe_idx); + + if (p_elem) { + *p_elem = &entry->element; + } + + *was_created = 1; + + return AWS_OP_SUCCESS; +} + +AWS_COMMON_API +int aws_hash_table_put(struct aws_hash_table *map, const void *key, void *value, int *was_created) { + struct aws_hash_element *p_elem; + int was_created_fallback; + + if (!was_created) { + was_created = &was_created_fallback; + } + + if (aws_hash_table_create(map, key, &p_elem, was_created)) { + return AWS_OP_ERR; + } + + /* + * aws_hash_table_create might resize the table, which results in map->p_impl changing. + * It is therefore important to wait to read p_impl until after we return. + */ + struct hash_table_state *state = map->p_impl; + + if (!*was_created) { + if (p_elem->key != key && state->destroy_key_fn) { + state->destroy_key_fn((void *)p_elem->key); + } + + if (state->destroy_value_fn) { + state->destroy_value_fn((void *)p_elem->value); + } + } + + p_elem->key = key; + p_elem->value = value; + + return AWS_OP_SUCCESS; +} + +/* Clears an entry. Does _not_ invoke destructor callbacks. + * Returns the last slot touched (note that if we wrap, we'll report an index + * lower than the original entry's index) + */ +static size_t s_remove_entry(struct hash_table_state *state, struct hash_table_entry *entry) { + AWS_PRECONDITION(hash_table_state_is_valid(state)); + AWS_PRECONDITION(state->entry_count > 0); AWS_PRECONDITION( entry >= &state->slots[0] && entry < &state->slots[state->size], "Input hash_table_entry [entry] pointer must point in the available slots."); - state->entry_count--; - - /* Shift subsequent entries back until we find an entry that belongs at its - * current position. This is important to ensure that subsequent searches - * don't terminate at the removed element. - */ - size_t index = s_index_for(state, entry); - /* There is always at least one empty slot in the hash table, so this loop always terminates */ - while (1) { - size_t next_index = (index + 1) & state->mask; - - /* If we hit an empty slot, stop */ - if (!state->slots[next_index].hash_code) { - break; - } - /* If the next slot is at the start of the probe sequence, stop. - * We know that nothing with an earlier home slot is after this; - * otherwise this index-zero entry would have been evicted from its - * home. - */ - if ((state->slots[next_index].hash_code & state->mask) == next_index) { - break; - } - - /* Okay, shift this one back */ - state->slots[index] = state->slots[next_index]; - index = next_index; - } - - /* Clear the entry we shifted out of */ - AWS_ZERO_STRUCT(state->slots[index]); + state->entry_count--; + + /* Shift subsequent entries back until we find an entry that belongs at its + * current position. This is important to ensure that subsequent searches + * don't terminate at the removed element. + */ + size_t index = s_index_for(state, entry); + /* There is always at least one empty slot in the hash table, so this loop always terminates */ + while (1) { + size_t next_index = (index + 1) & state->mask; + + /* If we hit an empty slot, stop */ + if (!state->slots[next_index].hash_code) { + break; + } + /* If the next slot is at the start of the probe sequence, stop. + * We know that nothing with an earlier home slot is after this; + * otherwise this index-zero entry would have been evicted from its + * home. + */ + if ((state->slots[next_index].hash_code & state->mask) == next_index) { + break; + } + + /* Okay, shift this one back */ + state->slots[index] = state->slots[next_index]; + index = next_index; + } + + /* Clear the entry we shifted out of */ + AWS_ZERO_STRUCT(state->slots[index]); AWS_RETURN_WITH_POSTCONDITION(index, hash_table_state_is_valid(state) && index <= state->size); -} - -int aws_hash_table_remove( - struct aws_hash_table *map, - const void *key, - struct aws_hash_element *p_value, - int *was_present) { +} + +int aws_hash_table_remove( + struct aws_hash_table *map, + const void *key, + struct aws_hash_element *p_value, + int *was_present) { AWS_PRECONDITION(aws_hash_table_is_valid(map)); AWS_PRECONDITION( p_value == NULL || AWS_OBJECT_PTR_IS_WRITABLE(p_value), "Input pointer [p_value] must be NULL or writable."); AWS_PRECONDITION( was_present == NULL || AWS_OBJECT_PTR_IS_WRITABLE(was_present), "Input pointer [was_present] must be NULL or writable."); - - struct hash_table_state *state = map->p_impl; - uint64_t hash_code = s_hash_for(state, key); - struct hash_table_entry *entry; - int ignored; - - if (!was_present) { - was_present = &ignored; - } - - int rv = s_find_entry(state, hash_code, key, &entry, NULL); - - if (rv != AWS_ERROR_SUCCESS) { - *was_present = 0; + + struct hash_table_state *state = map->p_impl; + uint64_t hash_code = s_hash_for(state, key); + struct hash_table_entry *entry; + int ignored; + + if (!was_present) { + was_present = &ignored; + } + + int rv = s_find_entry(state, hash_code, key, &entry, NULL); + + if (rv != AWS_ERROR_SUCCESS) { + *was_present = 0; AWS_SUCCEED_WITH_POSTCONDITION(aws_hash_table_is_valid(map)); - } - - *was_present = 1; - - if (p_value) { - *p_value = entry->element; - } else { - if (state->destroy_key_fn) { - state->destroy_key_fn((void *)entry->element.key); - } - if (state->destroy_value_fn) { - state->destroy_value_fn(entry->element.value); - } - } - s_remove_entry(state, entry); - + } + + *was_present = 1; + + if (p_value) { + *p_value = entry->element; + } else { + if (state->destroy_key_fn) { + state->destroy_key_fn((void *)entry->element.key); + } + if (state->destroy_value_fn) { + state->destroy_value_fn(entry->element.value); + } + } + s_remove_entry(state, entry); + AWS_SUCCEED_WITH_POSTCONDITION(aws_hash_table_is_valid(map)); -} - +} + int aws_hash_table_remove_element(struct aws_hash_table *map, struct aws_hash_element *p_value) { AWS_PRECONDITION(aws_hash_table_is_valid(map)); AWS_PRECONDITION(p_value != NULL); @@ -708,213 +708,213 @@ int aws_hash_table_remove_element(struct aws_hash_table *map, struct aws_hash_el AWS_SUCCEED_WITH_POSTCONDITION(aws_hash_table_is_valid(map)); } -int aws_hash_table_foreach( - struct aws_hash_table *map, - int (*callback)(void *context, struct aws_hash_element *pElement), - void *context) { - - for (struct aws_hash_iter iter = aws_hash_iter_begin(map); !aws_hash_iter_done(&iter); aws_hash_iter_next(&iter)) { - int rv = callback(context, &iter.element); - - if (rv & AWS_COMMON_HASH_TABLE_ITER_DELETE) { - aws_hash_iter_delete(&iter, false); - } - - if (!(rv & AWS_COMMON_HASH_TABLE_ITER_CONTINUE)) { - break; - } - } - - return AWS_OP_SUCCESS; -} - -bool aws_hash_table_eq( - const struct aws_hash_table *a, - const struct aws_hash_table *b, - aws_hash_callback_eq_fn *value_eq) { +int aws_hash_table_foreach( + struct aws_hash_table *map, + int (*callback)(void *context, struct aws_hash_element *pElement), + void *context) { + + for (struct aws_hash_iter iter = aws_hash_iter_begin(map); !aws_hash_iter_done(&iter); aws_hash_iter_next(&iter)) { + int rv = callback(context, &iter.element); + + if (rv & AWS_COMMON_HASH_TABLE_ITER_DELETE) { + aws_hash_iter_delete(&iter, false); + } + + if (!(rv & AWS_COMMON_HASH_TABLE_ITER_CONTINUE)) { + break; + } + } + + return AWS_OP_SUCCESS; +} + +bool aws_hash_table_eq( + const struct aws_hash_table *a, + const struct aws_hash_table *b, + aws_hash_callback_eq_fn *value_eq) { AWS_PRECONDITION(aws_hash_table_is_valid(a)); AWS_PRECONDITION(aws_hash_table_is_valid(b)); AWS_PRECONDITION(value_eq != NULL); - if (aws_hash_table_get_entry_count(a) != aws_hash_table_get_entry_count(b)) { + if (aws_hash_table_get_entry_count(a) != aws_hash_table_get_entry_count(b)) { AWS_RETURN_WITH_POSTCONDITION(false, aws_hash_table_is_valid(a) && aws_hash_table_is_valid(b)); - } - - /* - * Now that we have established that the two tables have the same number of - * entries, we can simply iterate one and compare against the same key in - * the other. - */ + } + + /* + * Now that we have established that the two tables have the same number of + * entries, we can simply iterate one and compare against the same key in + * the other. + */ for (size_t i = 0; i < a->p_impl->size; ++i) { const struct hash_table_entry *const a_entry = &a->p_impl->slots[i]; if (a_entry->hash_code == 0) { continue; } - struct aws_hash_element *b_element = NULL; - + struct aws_hash_element *b_element = NULL; + aws_hash_table_find(b, a_entry->element.key, &b_element); - - if (!b_element) { - /* Key is present in A only */ + + if (!b_element) { + /* Key is present in A only */ AWS_RETURN_WITH_POSTCONDITION(false, aws_hash_table_is_valid(a) && aws_hash_table_is_valid(b)); - } - + } + if (!s_safe_eq_check(value_eq, a_entry->element.value, b_element->value)) { AWS_RETURN_WITH_POSTCONDITION(false, aws_hash_table_is_valid(a) && aws_hash_table_is_valid(b)); - } - } + } + } AWS_RETURN_WITH_POSTCONDITION(true, aws_hash_table_is_valid(a) && aws_hash_table_is_valid(b)); -} - -/** - * Given an iterator, and a start slot, find the next available filled slot if it exists - * Otherwise, return an iter that will return true for aws_hash_iter_done(). - * Note that aws_hash_iter_is_valid() need not hold on entry to the function, since - * it can be called on a partially constructed iter from aws_hash_iter_begin(). - * - * Note that calling this on an iterator which is "done" is idempotent: it will return another - * iterator which is "done". - */ -static inline void s_get_next_element(struct aws_hash_iter *iter, size_t start_slot) { - AWS_PRECONDITION(iter != NULL); +} + +/** + * Given an iterator, and a start slot, find the next available filled slot if it exists + * Otherwise, return an iter that will return true for aws_hash_iter_done(). + * Note that aws_hash_iter_is_valid() need not hold on entry to the function, since + * it can be called on a partially constructed iter from aws_hash_iter_begin(). + * + * Note that calling this on an iterator which is "done" is idempotent: it will return another + * iterator which is "done". + */ +static inline void s_get_next_element(struct aws_hash_iter *iter, size_t start_slot) { + AWS_PRECONDITION(iter != NULL); AWS_PRECONDITION(aws_hash_table_is_valid(iter->map)); - struct hash_table_state *state = iter->map->p_impl; - size_t limit = iter->limit; - - for (size_t i = start_slot; i < limit; i++) { - struct hash_table_entry *entry = &state->slots[i]; - - if (entry->hash_code) { - iter->element = entry->element; - iter->slot = i; - iter->status = AWS_HASH_ITER_STATUS_READY_FOR_USE; - return; - } - } - iter->element.key = NULL; - iter->element.value = NULL; - iter->slot = iter->limit; - iter->status = AWS_HASH_ITER_STATUS_DONE; - AWS_POSTCONDITION(aws_hash_iter_is_valid(iter)); -} - -struct aws_hash_iter aws_hash_iter_begin(const struct aws_hash_table *map) { - AWS_PRECONDITION(aws_hash_table_is_valid(map)); - struct hash_table_state *state = map->p_impl; - struct aws_hash_iter iter; + struct hash_table_state *state = iter->map->p_impl; + size_t limit = iter->limit; + + for (size_t i = start_slot; i < limit; i++) { + struct hash_table_entry *entry = &state->slots[i]; + + if (entry->hash_code) { + iter->element = entry->element; + iter->slot = i; + iter->status = AWS_HASH_ITER_STATUS_READY_FOR_USE; + return; + } + } + iter->element.key = NULL; + iter->element.value = NULL; + iter->slot = iter->limit; + iter->status = AWS_HASH_ITER_STATUS_DONE; + AWS_POSTCONDITION(aws_hash_iter_is_valid(iter)); +} + +struct aws_hash_iter aws_hash_iter_begin(const struct aws_hash_table *map) { + AWS_PRECONDITION(aws_hash_table_is_valid(map)); + struct hash_table_state *state = map->p_impl; + struct aws_hash_iter iter; AWS_ZERO_STRUCT(iter); - iter.map = map; - iter.limit = state->size; - s_get_next_element(&iter, 0); + iter.map = map; + iter.limit = state->size; + s_get_next_element(&iter, 0); AWS_RETURN_WITH_POSTCONDITION( iter, aws_hash_iter_is_valid(&iter) && (iter.status == AWS_HASH_ITER_STATUS_DONE || iter.status == AWS_HASH_ITER_STATUS_READY_FOR_USE), "The status of output aws_hash_iter [iter] must either be DONE or READY_FOR_USE."); -} - -bool aws_hash_iter_done(const struct aws_hash_iter *iter) { - AWS_PRECONDITION(aws_hash_iter_is_valid(iter)); +} + +bool aws_hash_iter_done(const struct aws_hash_iter *iter) { + AWS_PRECONDITION(aws_hash_iter_is_valid(iter)); AWS_PRECONDITION( iter->status == AWS_HASH_ITER_STATUS_DONE || iter->status == AWS_HASH_ITER_STATUS_READY_FOR_USE, "Input aws_hash_iter [iter] must either be done, or ready to use."); - /* - * SIZE_MAX is a valid (non-terminal) value for iter->slot in the event that - * we delete slot 0. See comments in aws_hash_iter_delete. - * - * As such we must use == rather than >= here. - */ - bool rval = (iter->slot == iter->limit); + /* + * SIZE_MAX is a valid (non-terminal) value for iter->slot in the event that + * we delete slot 0. See comments in aws_hash_iter_delete. + * + * As such we must use == rather than >= here. + */ + bool rval = (iter->slot == iter->limit); AWS_POSTCONDITION( iter->status == AWS_HASH_ITER_STATUS_DONE || iter->status == AWS_HASH_ITER_STATUS_READY_FOR_USE, "The status of output aws_hash_iter [iter] must either be DONE or READY_FOR_USE."); AWS_POSTCONDITION( rval == (iter->status == AWS_HASH_ITER_STATUS_DONE), "Output bool [rval] must be true if and only if the status of [iter] is DONE."); - AWS_POSTCONDITION(aws_hash_iter_is_valid(iter)); - return rval; -} - -void aws_hash_iter_next(struct aws_hash_iter *iter) { - AWS_PRECONDITION(aws_hash_iter_is_valid(iter)); + AWS_POSTCONDITION(aws_hash_iter_is_valid(iter)); + return rval; +} + +void aws_hash_iter_next(struct aws_hash_iter *iter) { + AWS_PRECONDITION(aws_hash_iter_is_valid(iter)); #ifdef CBMC # pragma CPROVER check push # pragma CPROVER check disable "unsigned-overflow" #endif - s_get_next_element(iter, iter->slot + 1); + s_get_next_element(iter, iter->slot + 1); #ifdef CBMC # pragma CPROVER check pop #endif AWS_POSTCONDITION( iter->status == AWS_HASH_ITER_STATUS_DONE || iter->status == AWS_HASH_ITER_STATUS_READY_FOR_USE, "The status of output aws_hash_iter [iter] must either be DONE or READY_FOR_USE."); - AWS_POSTCONDITION(aws_hash_iter_is_valid(iter)); -} - -void aws_hash_iter_delete(struct aws_hash_iter *iter, bool destroy_contents) { + AWS_POSTCONDITION(aws_hash_iter_is_valid(iter)); +} + +void aws_hash_iter_delete(struct aws_hash_iter *iter, bool destroy_contents) { AWS_PRECONDITION( iter->status == AWS_HASH_ITER_STATUS_READY_FOR_USE, "Input aws_hash_iter [iter] must be ready for use."); - AWS_PRECONDITION(aws_hash_iter_is_valid(iter)); + AWS_PRECONDITION(aws_hash_iter_is_valid(iter)); AWS_PRECONDITION( iter->map->p_impl->entry_count > 0, "The hash_table_state pointed by input [iter] must contain at least one entry."); - - struct hash_table_state *state = iter->map->p_impl; - if (destroy_contents) { - if (state->destroy_key_fn) { - state->destroy_key_fn((void *)iter->element.key); - } - if (state->destroy_value_fn) { - state->destroy_value_fn(iter->element.value); - } - } - - size_t last_index = s_remove_entry(state, &state->slots[iter->slot]); - - /* If we shifted elements that are not part of the window we intend to iterate - * over, it means we shifted an element that we already visited into the - * iter->limit - 1 position. To avoid double iteration, we'll now reduce the - * limit to compensate. - * - * Note that last_index cannot equal iter->slot, because slots[iter->slot] - * is empty before we start walking the table. - */ - if (last_index < iter->slot || last_index >= iter->limit) { - iter->limit--; - } - - /* - * After removing this entry, the next entry might be in the same slot, or - * in some later slot, or we might have no further entries. - * - * We also expect that the caller will call aws_hash_iter_done and aws_hash_iter_next - * after this delete call. This gets a bit tricky if we just deleted the value - * in slot 0, and a new value has shifted in. - * - * To deal with this, we'll just step back one slot, and let _next start iteration - * at our current slot. Note that if we just deleted slot 0, this will result in - * underflowing to SIZE_MAX; we have to take care in aws_hash_iter_done to avoid - * treating this as an end-of-iteration condition. - */ + + struct hash_table_state *state = iter->map->p_impl; + if (destroy_contents) { + if (state->destroy_key_fn) { + state->destroy_key_fn((void *)iter->element.key); + } + if (state->destroy_value_fn) { + state->destroy_value_fn(iter->element.value); + } + } + + size_t last_index = s_remove_entry(state, &state->slots[iter->slot]); + + /* If we shifted elements that are not part of the window we intend to iterate + * over, it means we shifted an element that we already visited into the + * iter->limit - 1 position. To avoid double iteration, we'll now reduce the + * limit to compensate. + * + * Note that last_index cannot equal iter->slot, because slots[iter->slot] + * is empty before we start walking the table. + */ + if (last_index < iter->slot || last_index >= iter->limit) { + iter->limit--; + } + + /* + * After removing this entry, the next entry might be in the same slot, or + * in some later slot, or we might have no further entries. + * + * We also expect that the caller will call aws_hash_iter_done and aws_hash_iter_next + * after this delete call. This gets a bit tricky if we just deleted the value + * in slot 0, and a new value has shifted in. + * + * To deal with this, we'll just step back one slot, and let _next start iteration + * at our current slot. Note that if we just deleted slot 0, this will result in + * underflowing to SIZE_MAX; we have to take care in aws_hash_iter_done to avoid + * treating this as an end-of-iteration condition. + */ #ifdef CBMC # pragma CPROVER check push # pragma CPROVER check disable "unsigned-overflow" #endif - iter->slot--; + iter->slot--; #ifdef CBMC # pragma CPROVER check pop #endif - iter->status = AWS_HASH_ITER_STATUS_DELETE_CALLED; + iter->status = AWS_HASH_ITER_STATUS_DELETE_CALLED; AWS_POSTCONDITION( iter->status == AWS_HASH_ITER_STATUS_DELETE_CALLED, "The status of output aws_hash_iter [iter] must be DELETE_CALLED."); - AWS_POSTCONDITION(aws_hash_iter_is_valid(iter)); -} - -void aws_hash_table_clear(struct aws_hash_table *map) { + AWS_POSTCONDITION(aws_hash_iter_is_valid(iter)); +} + +void aws_hash_table_clear(struct aws_hash_table *map) { AWS_PRECONDITION(aws_hash_table_is_valid(map)); - struct hash_table_state *state = map->p_impl; + struct hash_table_state *state = map->p_impl; /* Check that we have at least one destructor before iterating over the table */ if (state->destroy_key_fn || state->destroy_value_fn) { @@ -922,65 +922,65 @@ void aws_hash_table_clear(struct aws_hash_table *map) { struct hash_table_entry *entry = &state->slots[i]; if (!entry->hash_code) { continue; - } + } if (state->destroy_key_fn) { state->destroy_key_fn((void *)entry->element.key); - } + } if (state->destroy_value_fn) { - state->destroy_value_fn(entry->element.value); - } - } - } - /* Since hash code 0 represents an empty slot we can just zero out the - * entire table. */ - memset(state->slots, 0, sizeof(*state->slots) * state->size); - - state->entry_count = 0; + state->destroy_value_fn(entry->element.value); + } + } + } + /* Since hash code 0 represents an empty slot we can just zero out the + * entire table. */ + memset(state->slots, 0, sizeof(*state->slots) * state->size); + + state->entry_count = 0; AWS_POSTCONDITION(aws_hash_table_is_valid(map)); -} - -uint64_t aws_hash_c_string(const void *item) { +} + +uint64_t aws_hash_c_string(const void *item) { AWS_PRECONDITION(aws_c_string_is_valid(item)); - const char *str = item; - - /* first digits of pi in hex */ - uint32_t b = 0x3243F6A8, c = 0x885A308D; - hashlittle2(str, strlen(str), &c, &b); - - return ((uint64_t)b << 32) | c; -} - -uint64_t aws_hash_string(const void *item) { + const char *str = item; + + /* first digits of pi in hex */ + uint32_t b = 0x3243F6A8, c = 0x885A308D; + hashlittle2(str, strlen(str), &c, &b); + + return ((uint64_t)b << 32) | c; +} + +uint64_t aws_hash_string(const void *item) { AWS_PRECONDITION(aws_string_is_valid(item)); - const struct aws_string *str = item; - - /* first digits of pi in hex */ - uint32_t b = 0x3243F6A8, c = 0x885A308D; - hashlittle2(aws_string_bytes(str), str->len, &c, &b); + const struct aws_string *str = item; + + /* first digits of pi in hex */ + uint32_t b = 0x3243F6A8, c = 0x885A308D; + hashlittle2(aws_string_bytes(str), str->len, &c, &b); AWS_RETURN_WITH_POSTCONDITION(((uint64_t)b << 32) | c, aws_string_is_valid(str)); -} - -uint64_t aws_hash_byte_cursor_ptr(const void *item) { +} + +uint64_t aws_hash_byte_cursor_ptr(const void *item) { AWS_PRECONDITION(aws_byte_cursor_is_valid(item)); - const struct aws_byte_cursor *cur = item; - - /* first digits of pi in hex */ - uint32_t b = 0x3243F6A8, c = 0x885A308D; - hashlittle2(cur->ptr, cur->len, &c, &b); + const struct aws_byte_cursor *cur = item; + + /* first digits of pi in hex */ + uint32_t b = 0x3243F6A8, c = 0x885A308D; + hashlittle2(cur->ptr, cur->len, &c, &b); AWS_RETURN_WITH_POSTCONDITION(((uint64_t)b << 32) | c, aws_byte_cursor_is_valid(cur)); -} - -uint64_t aws_hash_ptr(const void *item) { +} + +uint64_t aws_hash_ptr(const void *item) { /* Since the numeric value of the pointer is considered, not the memory behind it, 0 is an acceptable value */ - /* first digits of e in hex - * 2.b7e 1516 28ae d2a6 */ - uint32_t b = 0x2b7e1516, c = 0x28aed2a6; - - hashlittle2(&item, sizeof(item), &c, &b); - - return ((uint64_t)b << 32) | c; -} - + /* first digits of e in hex + * 2.b7e 1516 28ae d2a6 */ + uint32_t b = 0x2b7e1516, c = 0x28aed2a6; + + hashlittle2(&item, sizeof(item), &c, &b); + + return ((uint64_t)b << 32) | c; +} + uint64_t aws_hash_combine(uint64_t item1, uint64_t item2) { uint32_t b = item2 & 0xFFFFFFFF; /* LSB */ uint32_t c = item2 >> 32; /* MSB */ @@ -989,28 +989,28 @@ uint64_t aws_hash_combine(uint64_t item1, uint64_t item2) { return ((uint64_t)b << 32) | c; } -bool aws_hash_callback_c_str_eq(const void *a, const void *b) { - AWS_PRECONDITION(aws_c_string_is_valid(a)); - AWS_PRECONDITION(aws_c_string_is_valid(b)); - bool rval = !strcmp(a, b); +bool aws_hash_callback_c_str_eq(const void *a, const void *b) { + AWS_PRECONDITION(aws_c_string_is_valid(a)); + AWS_PRECONDITION(aws_c_string_is_valid(b)); + bool rval = !strcmp(a, b); AWS_RETURN_WITH_POSTCONDITION(rval, aws_c_string_is_valid(a) && aws_c_string_is_valid(b)); -} - -bool aws_hash_callback_string_eq(const void *a, const void *b) { - AWS_PRECONDITION(aws_string_is_valid(a)); - AWS_PRECONDITION(aws_string_is_valid(b)); - bool rval = aws_string_eq(a, b); +} + +bool aws_hash_callback_string_eq(const void *a, const void *b) { + AWS_PRECONDITION(aws_string_is_valid(a)); + AWS_PRECONDITION(aws_string_is_valid(b)); + bool rval = aws_string_eq(a, b); AWS_RETURN_WITH_POSTCONDITION(rval, aws_c_string_is_valid(a) && aws_c_string_is_valid(b)); -} - -void aws_hash_callback_string_destroy(void *a) { - AWS_PRECONDITION(aws_string_is_valid(a)); - aws_string_destroy(a); -} - -bool aws_ptr_eq(const void *a, const void *b) { - return a == b; -} +} + +void aws_hash_callback_string_destroy(void *a) { + AWS_PRECONDITION(aws_string_is_valid(a)); + aws_string_destroy(a); +} + +bool aws_ptr_eq(const void *a, const void *b) { + return a == b; +} /** * Best-effort check of hash_table_state data-structure invariants diff --git a/contrib/restricted/aws/aws-c-common/source/lru_cache.c b/contrib/restricted/aws/aws-c-common/source/lru_cache.c index 37724fd079..15de626b96 100644 --- a/contrib/restricted/aws/aws-c-common/source/lru_cache.c +++ b/contrib/restricted/aws/aws-c-common/source/lru_cache.c @@ -1,18 +1,18 @@ /** * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. - */ -#include <aws/common/lru_cache.h> + */ +#include <aws/common/lru_cache.h> static int s_lru_cache_put(struct aws_cache *cache, const void *key, void *p_value); static int s_lru_cache_find(struct aws_cache *cache, const void *key, void **p_value); static void *s_lru_cache_use_lru_element(struct aws_cache *cache); static void *s_lru_cache_get_mru_element(const struct aws_cache *cache); - + struct lru_cache_impl_vtable { void *(*use_lru_element)(struct aws_cache *cache); void *(*get_mru_element)(const struct aws_cache *cache); -}; - +}; + static struct aws_cache_vtable s_lru_cache_vtable = { .destroy = aws_cache_base_default_destroy, .find = s_lru_cache_find, @@ -21,23 +21,23 @@ static struct aws_cache_vtable s_lru_cache_vtable = { .clear = aws_cache_base_default_clear, .get_element_count = aws_cache_base_default_get_element_count, }; - + struct aws_cache *aws_cache_new_lru( - struct aws_allocator *allocator, - aws_hash_fn *hash_fn, - aws_hash_callback_eq_fn *equals_fn, - aws_hash_callback_destroy_fn *destroy_key_fn, - aws_hash_callback_destroy_fn *destroy_value_fn, - size_t max_items) { - AWS_ASSERT(allocator); - AWS_ASSERT(max_items); + struct aws_allocator *allocator, + aws_hash_fn *hash_fn, + aws_hash_callback_eq_fn *equals_fn, + aws_hash_callback_destroy_fn *destroy_key_fn, + aws_hash_callback_destroy_fn *destroy_value_fn, + size_t max_items) { + AWS_ASSERT(allocator); + AWS_ASSERT(max_items); struct aws_cache *lru_cache = NULL; struct lru_cache_impl_vtable *impl = NULL; - + if (!aws_mem_acquire_many( allocator, 2, &lru_cache, sizeof(struct aws_cache), &impl, sizeof(struct lru_cache_impl_vtable))) { return NULL; - } + } impl->use_lru_element = s_lru_cache_use_lru_element; impl->get_mru_element = s_lru_cache_get_mru_element; lru_cache->allocator = allocator; @@ -49,15 +49,15 @@ struct aws_cache *aws_cache_new_lru( return NULL; } return lru_cache; -} - +} + /* implementation for lru cache put */ static int s_lru_cache_put(struct aws_cache *cache, const void *key, void *p_value) { - + if (aws_linked_hash_table_put(&cache->table, key, p_value)) { - return AWS_OP_ERR; - } - + return AWS_OP_ERR; + } + /* Manage the space if we actually added a new element and the cache is full. */ if (aws_linked_hash_table_get_element_count(&cache->table) > cache->max_items) { /* we're over the cache size limit. Remove whatever is in the front of @@ -66,46 +66,46 @@ static int s_lru_cache_put(struct aws_cache *cache, const void *key, void *p_val struct aws_linked_list_node *node = aws_linked_list_front(list); struct aws_linked_hash_table_node *table_node = AWS_CONTAINER_OF(node, struct aws_linked_hash_table_node, node); return aws_linked_hash_table_remove(&cache->table, table_node->key); - } - - return AWS_OP_SUCCESS; -} + } + + return AWS_OP_SUCCESS; +} /* implementation for lru cache find */ static int s_lru_cache_find(struct aws_cache *cache, const void *key, void **p_value) { return (aws_linked_hash_table_find_and_move_to_back(&cache->table, key, p_value)); -} - +} + static void *s_lru_cache_use_lru_element(struct aws_cache *cache) { const struct aws_linked_list *list = aws_linked_hash_table_get_iteration_list(&cache->table); if (aws_linked_list_empty(list)) { - return NULL; - } + return NULL; + } struct aws_linked_list_node *node = aws_linked_list_front(list); struct aws_linked_hash_table_node *lru_node = AWS_CONTAINER_OF(node, struct aws_linked_hash_table_node, node); - + aws_linked_hash_table_move_node_to_end_of_list(&cache->table, lru_node); return lru_node->value; -} +} static void *s_lru_cache_get_mru_element(const struct aws_cache *cache) { const struct aws_linked_list *list = aws_linked_hash_table_get_iteration_list(&cache->table); if (aws_linked_list_empty(list)) { - return NULL; - } + return NULL; + } struct aws_linked_list_node *node = aws_linked_list_back(list); struct aws_linked_hash_table_node *mru_node = AWS_CONTAINER_OF(node, struct aws_linked_hash_table_node, node); return mru_node->value; } - + void *aws_lru_cache_use_lru_element(struct aws_cache *cache) { AWS_PRECONDITION(cache); AWS_PRECONDITION(cache->impl); struct lru_cache_impl_vtable *impl_vtable = cache->impl; return impl_vtable->use_lru_element(cache); -} - +} + void *aws_lru_cache_get_mru_element(const struct aws_cache *cache) { AWS_PRECONDITION(cache); AWS_PRECONDITION(cache->impl); struct lru_cache_impl_vtable *impl_vtable = cache->impl; return impl_vtable->get_mru_element(cache); -} +} diff --git a/contrib/restricted/aws/aws-c-common/source/posix/clock.c b/contrib/restricted/aws/aws-c-common/source/posix/clock.c index a74515f5fe..90e213ea7c 100644 --- a/contrib/restricted/aws/aws-c-common/source/posix/clock.c +++ b/contrib/restricted/aws/aws-c-common/source/posix/clock.c @@ -1,136 +1,136 @@ /** * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. - */ - -#include <aws/common/clock.h> - -#include <time.h> - -static const uint64_t NS_PER_SEC = 1000000000; - -#if defined(CLOCK_MONOTONIC_RAW) -# define HIGH_RES_CLOCK CLOCK_MONOTONIC_RAW -#else -# define HIGH_RES_CLOCK CLOCK_MONOTONIC -#endif - -/* This entire compilation branch has two goals. First, prior to OSX Sierra, clock_gettime does not exist on OSX, so we - * already need to branch on that. Second, even if we compile on a newer OSX, which we will always do for bindings (e.g. - * python, dotnet, java etc...), we have to worry about the same lib being loaded on an older version, and thus, we'd - * get linker errors at runtime. To avoid this, we do a dynamic load - * to keep the function out of linker tables and only use the symbol if the current running process has access to the - * function. */ -#if defined(__MACH__) -# include <AvailabilityMacros.h> -# include <aws/common/thread.h> -# include <dlfcn.h> -# include <sys/time.h> - -static int s_legacy_get_time(uint64_t *timestamp) { - struct timeval tv; - int ret_val = gettimeofday(&tv, NULL); - - if (ret_val) { - return aws_raise_error(AWS_ERROR_CLOCK_FAILURE); - } - + */ + +#include <aws/common/clock.h> + +#include <time.h> + +static const uint64_t NS_PER_SEC = 1000000000; + +#if defined(CLOCK_MONOTONIC_RAW) +# define HIGH_RES_CLOCK CLOCK_MONOTONIC_RAW +#else +# define HIGH_RES_CLOCK CLOCK_MONOTONIC +#endif + +/* This entire compilation branch has two goals. First, prior to OSX Sierra, clock_gettime does not exist on OSX, so we + * already need to branch on that. Second, even if we compile on a newer OSX, which we will always do for bindings (e.g. + * python, dotnet, java etc...), we have to worry about the same lib being loaded on an older version, and thus, we'd + * get linker errors at runtime. To avoid this, we do a dynamic load + * to keep the function out of linker tables and only use the symbol if the current running process has access to the + * function. */ +#if defined(__MACH__) +# include <AvailabilityMacros.h> +# include <aws/common/thread.h> +# include <dlfcn.h> +# include <sys/time.h> + +static int s_legacy_get_time(uint64_t *timestamp) { + struct timeval tv; + int ret_val = gettimeofday(&tv, NULL); + + if (ret_val) { + return aws_raise_error(AWS_ERROR_CLOCK_FAILURE); + } + uint64_t secs = (uint64_t)tv.tv_sec; uint64_t u_secs = (uint64_t)tv.tv_usec; *timestamp = (secs * NS_PER_SEC) + (u_secs * 1000); - return AWS_OP_SUCCESS; -} - -# if MAC_OS_X_VERSION_MAX_ALLOWED >= 101200 -static aws_thread_once s_thread_once_flag = AWS_THREAD_ONCE_STATIC_INIT; -static int (*s_gettime_fn)(clockid_t __clock_id, struct timespec *__tp) = NULL; - + return AWS_OP_SUCCESS; +} + +# if MAC_OS_X_VERSION_MAX_ALLOWED >= 101200 +static aws_thread_once s_thread_once_flag = AWS_THREAD_ONCE_STATIC_INIT; +static int (*s_gettime_fn)(clockid_t __clock_id, struct timespec *__tp) = NULL; + static void s_do_osx_loads(void *user_data) { (void)user_data; - s_gettime_fn = (int (*)(clockid_t __clock_id, struct timespec * __tp)) dlsym(RTLD_DEFAULT, "clock_gettime"); -} - -int aws_high_res_clock_get_ticks(uint64_t *timestamp) { + s_gettime_fn = (int (*)(clockid_t __clock_id, struct timespec * __tp)) dlsym(RTLD_DEFAULT, "clock_gettime"); +} + +int aws_high_res_clock_get_ticks(uint64_t *timestamp) { aws_thread_call_once(&s_thread_once_flag, s_do_osx_loads, NULL); - int ret_val = 0; - - if (s_gettime_fn) { - struct timespec ts; - ret_val = s_gettime_fn(HIGH_RES_CLOCK, &ts); - - if (ret_val) { - return aws_raise_error(AWS_ERROR_CLOCK_FAILURE); - } - + int ret_val = 0; + + if (s_gettime_fn) { + struct timespec ts; + ret_val = s_gettime_fn(HIGH_RES_CLOCK, &ts); + + if (ret_val) { + return aws_raise_error(AWS_ERROR_CLOCK_FAILURE); + } + uint64_t secs = (uint64_t)ts.tv_sec; uint64_t n_secs = (uint64_t)ts.tv_nsec; *timestamp = (secs * NS_PER_SEC) + n_secs; - return AWS_OP_SUCCESS; - } - - return s_legacy_get_time(timestamp); -} - -int aws_sys_clock_get_ticks(uint64_t *timestamp) { + return AWS_OP_SUCCESS; + } + + return s_legacy_get_time(timestamp); +} + +int aws_sys_clock_get_ticks(uint64_t *timestamp) { aws_thread_call_once(&s_thread_once_flag, s_do_osx_loads, NULL); - int ret_val = 0; - - if (s_gettime_fn) { - struct timespec ts; - ret_val = s_gettime_fn(CLOCK_REALTIME, &ts); - if (ret_val) { - return aws_raise_error(AWS_ERROR_CLOCK_FAILURE); - } - + int ret_val = 0; + + if (s_gettime_fn) { + struct timespec ts; + ret_val = s_gettime_fn(CLOCK_REALTIME, &ts); + if (ret_val) { + return aws_raise_error(AWS_ERROR_CLOCK_FAILURE); + } + uint64_t secs = (uint64_t)ts.tv_sec; uint64_t n_secs = (uint64_t)ts.tv_nsec; *timestamp = (secs * NS_PER_SEC) + n_secs; - return AWS_OP_SUCCESS; - } - return s_legacy_get_time(timestamp); -} -# else -int aws_high_res_clock_get_ticks(uint64_t *timestamp) { - return s_legacy_get_time(timestamp); -} - -int aws_sys_clock_get_ticks(uint64_t *timestamp) { - return s_legacy_get_time(timestamp); -} - -# endif /* MAC_OS_X_VERSION_MAX_ALLOWED >= 101200 */ -/* Everywhere else, just link clock_gettime in directly */ -#else -int aws_high_res_clock_get_ticks(uint64_t *timestamp) { - int ret_val = 0; - - struct timespec ts; - - ret_val = clock_gettime(HIGH_RES_CLOCK, &ts); - - if (ret_val) { - return aws_raise_error(AWS_ERROR_CLOCK_FAILURE); - } - + return AWS_OP_SUCCESS; + } + return s_legacy_get_time(timestamp); +} +# else +int aws_high_res_clock_get_ticks(uint64_t *timestamp) { + return s_legacy_get_time(timestamp); +} + +int aws_sys_clock_get_ticks(uint64_t *timestamp) { + return s_legacy_get_time(timestamp); +} + +# endif /* MAC_OS_X_VERSION_MAX_ALLOWED >= 101200 */ +/* Everywhere else, just link clock_gettime in directly */ +#else +int aws_high_res_clock_get_ticks(uint64_t *timestamp) { + int ret_val = 0; + + struct timespec ts; + + ret_val = clock_gettime(HIGH_RES_CLOCK, &ts); + + if (ret_val) { + return aws_raise_error(AWS_ERROR_CLOCK_FAILURE); + } + uint64_t secs = (uint64_t)ts.tv_sec; uint64_t n_secs = (uint64_t)ts.tv_nsec; *timestamp = (secs * NS_PER_SEC) + n_secs; - return AWS_OP_SUCCESS; -} - -int aws_sys_clock_get_ticks(uint64_t *timestamp) { - int ret_val = 0; - - struct timespec ts; - ret_val = clock_gettime(CLOCK_REALTIME, &ts); - if (ret_val) { - return aws_raise_error(AWS_ERROR_CLOCK_FAILURE); - } - + return AWS_OP_SUCCESS; +} + +int aws_sys_clock_get_ticks(uint64_t *timestamp) { + int ret_val = 0; + + struct timespec ts; + ret_val = clock_gettime(CLOCK_REALTIME, &ts); + if (ret_val) { + return aws_raise_error(AWS_ERROR_CLOCK_FAILURE); + } + uint64_t secs = (uint64_t)ts.tv_sec; uint64_t n_secs = (uint64_t)ts.tv_nsec; *timestamp = (secs * NS_PER_SEC) + n_secs; - return AWS_OP_SUCCESS; -} -#endif /* defined(__MACH__) */ + return AWS_OP_SUCCESS; +} +#endif /* defined(__MACH__) */ diff --git a/contrib/restricted/aws/aws-c-common/source/posix/condition_variable.c b/contrib/restricted/aws/aws-c-common/source/posix/condition_variable.c index b4914e919b..ca321c6bfa 100644 --- a/contrib/restricted/aws/aws-c-common/source/posix/condition_variable.c +++ b/contrib/restricted/aws/aws-c-common/source/posix/condition_variable.c @@ -1,39 +1,39 @@ /** * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. - */ - -#include <aws/common/condition_variable.h> - -#include <aws/common/clock.h> -#include <aws/common/mutex.h> - -#include <errno.h> - -static int process_error_code(int err) { - switch (err) { - case ENOMEM: - return aws_raise_error(AWS_ERROR_OOM); - case ETIMEDOUT: - return aws_raise_error(AWS_ERROR_COND_VARIABLE_TIMED_OUT); - default: - return aws_raise_error(AWS_ERROR_COND_VARIABLE_ERROR_UNKNOWN); - } -} - -int aws_condition_variable_init(struct aws_condition_variable *condition_variable) { + */ + +#include <aws/common/condition_variable.h> + +#include <aws/common/clock.h> +#include <aws/common/mutex.h> + +#include <errno.h> + +static int process_error_code(int err) { + switch (err) { + case ENOMEM: + return aws_raise_error(AWS_ERROR_OOM); + case ETIMEDOUT: + return aws_raise_error(AWS_ERROR_COND_VARIABLE_TIMED_OUT); + default: + return aws_raise_error(AWS_ERROR_COND_VARIABLE_ERROR_UNKNOWN); + } +} + +int aws_condition_variable_init(struct aws_condition_variable *condition_variable) { AWS_PRECONDITION(condition_variable); - if (pthread_cond_init(&condition_variable->condition_handle, NULL)) { + if (pthread_cond_init(&condition_variable->condition_handle, NULL)) { AWS_ZERO_STRUCT(*condition_variable); - return aws_raise_error(AWS_ERROR_COND_VARIABLE_INIT_FAILED); - } - + return aws_raise_error(AWS_ERROR_COND_VARIABLE_INIT_FAILED); + } + condition_variable->initialized = true; - return AWS_OP_SUCCESS; -} - -void aws_condition_variable_clean_up(struct aws_condition_variable *condition_variable) { + return AWS_OP_SUCCESS; +} + +void aws_condition_variable_clean_up(struct aws_condition_variable *condition_variable) { AWS_PRECONDITION(condition_variable); if (condition_variable->initialized) { @@ -41,71 +41,71 @@ void aws_condition_variable_clean_up(struct aws_condition_variable *condition_va } AWS_ZERO_STRUCT(*condition_variable); -} - -int aws_condition_variable_notify_one(struct aws_condition_variable *condition_variable) { +} + +int aws_condition_variable_notify_one(struct aws_condition_variable *condition_variable) { AWS_PRECONDITION(condition_variable && condition_variable->initialized); - int err_code = pthread_cond_signal(&condition_variable->condition_handle); - - if (err_code) { - return process_error_code(err_code); - } - - return AWS_OP_SUCCESS; -} - -int aws_condition_variable_notify_all(struct aws_condition_variable *condition_variable) { + int err_code = pthread_cond_signal(&condition_variable->condition_handle); + + if (err_code) { + return process_error_code(err_code); + } + + return AWS_OP_SUCCESS; +} + +int aws_condition_variable_notify_all(struct aws_condition_variable *condition_variable) { AWS_PRECONDITION(condition_variable && condition_variable->initialized); - int err_code = pthread_cond_broadcast(&condition_variable->condition_handle); - - if (err_code) { - return process_error_code(err_code); - } - - return AWS_OP_SUCCESS; -} - -int aws_condition_variable_wait(struct aws_condition_variable *condition_variable, struct aws_mutex *mutex) { + int err_code = pthread_cond_broadcast(&condition_variable->condition_handle); + + if (err_code) { + return process_error_code(err_code); + } + + return AWS_OP_SUCCESS; +} + +int aws_condition_variable_wait(struct aws_condition_variable *condition_variable, struct aws_mutex *mutex) { AWS_PRECONDITION(condition_variable && condition_variable->initialized); AWS_PRECONDITION(mutex && mutex->initialized); - int err_code = pthread_cond_wait(&condition_variable->condition_handle, &mutex->mutex_handle); - - if (err_code) { - return process_error_code(err_code); - } - - return AWS_OP_SUCCESS; -} - -int aws_condition_variable_wait_for( - struct aws_condition_variable *condition_variable, - struct aws_mutex *mutex, - int64_t time_to_wait) { - + int err_code = pthread_cond_wait(&condition_variable->condition_handle, &mutex->mutex_handle); + + if (err_code) { + return process_error_code(err_code); + } + + return AWS_OP_SUCCESS; +} + +int aws_condition_variable_wait_for( + struct aws_condition_variable *condition_variable, + struct aws_mutex *mutex, + int64_t time_to_wait) { + AWS_PRECONDITION(condition_variable && condition_variable->initialized); AWS_PRECONDITION(mutex && mutex->initialized); - uint64_t current_sys_time = 0; - if (aws_sys_clock_get_ticks(¤t_sys_time)) { - return AWS_OP_ERR; - } - - time_to_wait += current_sys_time; - - struct timespec ts; - uint64_t remainder = 0; - ts.tv_sec = - (time_t)aws_timestamp_convert((uint64_t)time_to_wait, AWS_TIMESTAMP_NANOS, AWS_TIMESTAMP_SECS, &remainder); - ts.tv_nsec = (long)remainder; - - int err_code = pthread_cond_timedwait(&condition_variable->condition_handle, &mutex->mutex_handle, &ts); - - if (err_code) { - return process_error_code(err_code); - } - - return AWS_OP_SUCCESS; -} + uint64_t current_sys_time = 0; + if (aws_sys_clock_get_ticks(¤t_sys_time)) { + return AWS_OP_ERR; + } + + time_to_wait += current_sys_time; + + struct timespec ts; + uint64_t remainder = 0; + ts.tv_sec = + (time_t)aws_timestamp_convert((uint64_t)time_to_wait, AWS_TIMESTAMP_NANOS, AWS_TIMESTAMP_SECS, &remainder); + ts.tv_nsec = (long)remainder; + + int err_code = pthread_cond_timedwait(&condition_variable->condition_handle, &mutex->mutex_handle, &ts); + + if (err_code) { + return process_error_code(err_code); + } + + return AWS_OP_SUCCESS; +} diff --git a/contrib/restricted/aws/aws-c-common/source/posix/device_random.c b/contrib/restricted/aws/aws-c-common/source/posix/device_random.c index 995bb79aaf..f446002231 100644 --- a/contrib/restricted/aws/aws-c-common/source/posix/device_random.c +++ b/contrib/restricted/aws/aws-c-common/source/posix/device_random.c @@ -1,57 +1,57 @@ /** * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. - */ -#include <aws/common/device_random.h> - -#include <aws/common/byte_buf.h> -#include <aws/common/thread.h> - -#include <fcntl.h> -#include <unistd.h> - -static int s_rand_fd = -1; -static aws_thread_once s_rand_init = AWS_THREAD_ONCE_STATIC_INIT; - -#ifdef O_CLOEXEC -# define OPEN_FLAGS (O_RDONLY | O_CLOEXEC) -#else -# define OPEN_FLAGS (O_RDONLY) -#endif + */ +#include <aws/common/device_random.h> + +#include <aws/common/byte_buf.h> +#include <aws/common/thread.h> + +#include <fcntl.h> +#include <unistd.h> + +static int s_rand_fd = -1; +static aws_thread_once s_rand_init = AWS_THREAD_ONCE_STATIC_INIT; + +#ifdef O_CLOEXEC +# define OPEN_FLAGS (O_RDONLY | O_CLOEXEC) +#else +# define OPEN_FLAGS (O_RDONLY) +#endif static void s_init_rand(void *user_data) { (void)user_data; - s_rand_fd = open("/dev/urandom", OPEN_FLAGS); - - if (s_rand_fd == -1) { - s_rand_fd = open("/dev/urandom", O_RDONLY); - - if (s_rand_fd == -1) { - abort(); - } - } - - if (-1 == fcntl(s_rand_fd, F_SETFD, FD_CLOEXEC)) { - abort(); - } -} - -static int s_fallback_device_random_buffer(struct aws_byte_buf *output) { - + s_rand_fd = open("/dev/urandom", OPEN_FLAGS); + + if (s_rand_fd == -1) { + s_rand_fd = open("/dev/urandom", O_RDONLY); + + if (s_rand_fd == -1) { + abort(); + } + } + + if (-1 == fcntl(s_rand_fd, F_SETFD, FD_CLOEXEC)) { + abort(); + } +} + +static int s_fallback_device_random_buffer(struct aws_byte_buf *output) { + aws_thread_call_once(&s_rand_init, s_init_rand, NULL); - - size_t diff = output->capacity - output->len; - - ssize_t amount_read = read(s_rand_fd, output->buffer + output->len, diff); - - if (amount_read != diff) { - return aws_raise_error(AWS_ERROR_RANDOM_GEN_FAILED); - } - - output->len += diff; - - return AWS_OP_SUCCESS; -} - -int aws_device_random_buffer(struct aws_byte_buf *output) { - return s_fallback_device_random_buffer(output); -} + + size_t diff = output->capacity - output->len; + + ssize_t amount_read = read(s_rand_fd, output->buffer + output->len, diff); + + if (amount_read != diff) { + return aws_raise_error(AWS_ERROR_RANDOM_GEN_FAILED); + } + + output->len += diff; + + return AWS_OP_SUCCESS; +} + +int aws_device_random_buffer(struct aws_byte_buf *output) { + return s_fallback_device_random_buffer(output); +} diff --git a/contrib/restricted/aws/aws-c-common/source/posix/environment.c b/contrib/restricted/aws/aws-c-common/source/posix/environment.c index 5bc7679d6e..f4b69caea2 100644 --- a/contrib/restricted/aws/aws-c-common/source/posix/environment.c +++ b/contrib/restricted/aws/aws-c-common/source/posix/environment.c @@ -1,45 +1,45 @@ /** * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. - */ - -#include <aws/common/environment.h> - -#include <aws/common/string.h> -#include <stdlib.h> - -int aws_get_environment_value( - struct aws_allocator *allocator, - const struct aws_string *variable_name, - struct aws_string **value_out) { - + */ + +#include <aws/common/environment.h> + +#include <aws/common/string.h> +#include <stdlib.h> + +int aws_get_environment_value( + struct aws_allocator *allocator, + const struct aws_string *variable_name, + struct aws_string **value_out) { + const char *value = getenv(aws_string_c_str(variable_name)); - if (value == NULL) { - *value_out = NULL; - return AWS_OP_SUCCESS; - } - - *value_out = aws_string_new_from_c_str(allocator, value); - if (*value_out == NULL) { - return aws_raise_error(AWS_ERROR_ENVIRONMENT_GET); - } - - return AWS_OP_SUCCESS; -} - -int aws_set_environment_value(const struct aws_string *variable_name, const struct aws_string *value) { - + if (value == NULL) { + *value_out = NULL; + return AWS_OP_SUCCESS; + } + + *value_out = aws_string_new_from_c_str(allocator, value); + if (*value_out == NULL) { + return aws_raise_error(AWS_ERROR_ENVIRONMENT_GET); + } + + return AWS_OP_SUCCESS; +} + +int aws_set_environment_value(const struct aws_string *variable_name, const struct aws_string *value) { + if (setenv(aws_string_c_str(variable_name), aws_string_c_str(value), 1) != 0) { - return aws_raise_error(AWS_ERROR_ENVIRONMENT_SET); - } - - return AWS_OP_SUCCESS; -} - -int aws_unset_environment_value(const struct aws_string *variable_name) { + return aws_raise_error(AWS_ERROR_ENVIRONMENT_SET); + } + + return AWS_OP_SUCCESS; +} + +int aws_unset_environment_value(const struct aws_string *variable_name) { if (unsetenv(aws_string_c_str(variable_name)) != 0) { - return aws_raise_error(AWS_ERROR_ENVIRONMENT_UNSET); - } - - return AWS_OP_SUCCESS; -} + return aws_raise_error(AWS_ERROR_ENVIRONMENT_UNSET); + } + + return AWS_OP_SUCCESS; +} diff --git a/contrib/restricted/aws/aws-c-common/source/posix/mutex.c b/contrib/restricted/aws/aws-c-common/source/posix/mutex.c index adca71d8ff..2cbf2db66c 100644 --- a/contrib/restricted/aws/aws-c-common/source/posix/mutex.c +++ b/contrib/restricted/aws/aws-c-common/source/posix/mutex.c @@ -1,53 +1,53 @@ /** * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. - */ - -#include <aws/common/mutex.h> -#include <aws/common/posix/common.inl> - -#include <errno.h> - -void aws_mutex_clean_up(struct aws_mutex *mutex) { + */ + +#include <aws/common/mutex.h> +#include <aws/common/posix/common.inl> + +#include <errno.h> + +void aws_mutex_clean_up(struct aws_mutex *mutex) { AWS_PRECONDITION(mutex); if (mutex->initialized) { pthread_mutex_destroy(&mutex->mutex_handle); } AWS_ZERO_STRUCT(*mutex); -} - -int aws_mutex_init(struct aws_mutex *mutex) { +} + +int aws_mutex_init(struct aws_mutex *mutex) { AWS_PRECONDITION(mutex); - pthread_mutexattr_t attr; - int err_code = pthread_mutexattr_init(&attr); - int return_code = AWS_OP_SUCCESS; - - if (!err_code) { - if ((err_code = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_NORMAL)) || - (err_code = pthread_mutex_init(&mutex->mutex_handle, &attr))) { - - return_code = aws_private_convert_and_raise_error_code(err_code); - } - pthread_mutexattr_destroy(&attr); - } else { - return_code = aws_private_convert_and_raise_error_code(err_code); - } - + pthread_mutexattr_t attr; + int err_code = pthread_mutexattr_init(&attr); + int return_code = AWS_OP_SUCCESS; + + if (!err_code) { + if ((err_code = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_NORMAL)) || + (err_code = pthread_mutex_init(&mutex->mutex_handle, &attr))) { + + return_code = aws_private_convert_and_raise_error_code(err_code); + } + pthread_mutexattr_destroy(&attr); + } else { + return_code = aws_private_convert_and_raise_error_code(err_code); + } + mutex->initialized = (return_code == AWS_OP_SUCCESS); - return return_code; -} - -int aws_mutex_lock(struct aws_mutex *mutex) { + return return_code; +} + +int aws_mutex_lock(struct aws_mutex *mutex) { AWS_PRECONDITION(mutex && mutex->initialized); - return aws_private_convert_and_raise_error_code(pthread_mutex_lock(&mutex->mutex_handle)); -} - -int aws_mutex_try_lock(struct aws_mutex *mutex) { + return aws_private_convert_and_raise_error_code(pthread_mutex_lock(&mutex->mutex_handle)); +} + +int aws_mutex_try_lock(struct aws_mutex *mutex) { AWS_PRECONDITION(mutex && mutex->initialized); - return aws_private_convert_and_raise_error_code(pthread_mutex_trylock(&mutex->mutex_handle)); -} - -int aws_mutex_unlock(struct aws_mutex *mutex) { + return aws_private_convert_and_raise_error_code(pthread_mutex_trylock(&mutex->mutex_handle)); +} + +int aws_mutex_unlock(struct aws_mutex *mutex) { AWS_PRECONDITION(mutex && mutex->initialized); - return aws_private_convert_and_raise_error_code(pthread_mutex_unlock(&mutex->mutex_handle)); -} + return aws_private_convert_and_raise_error_code(pthread_mutex_unlock(&mutex->mutex_handle)); +} diff --git a/contrib/restricted/aws/aws-c-common/source/posix/rw_lock.c b/contrib/restricted/aws/aws-c-common/source/posix/rw_lock.c index 94ebe1fbf2..824477d6cf 100644 --- a/contrib/restricted/aws/aws-c-common/source/posix/rw_lock.c +++ b/contrib/restricted/aws/aws-c-common/source/posix/rw_lock.c @@ -1,49 +1,49 @@ /** * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. - */ - -#include <aws/common/atomics.h> -#include <aws/common/rw_lock.h> - -#include <aws/common/posix/common.inl> - -int aws_rw_lock_init(struct aws_rw_lock *lock) { - - return aws_private_convert_and_raise_error_code(pthread_rwlock_init(&lock->lock_handle, NULL)); -} - -void aws_rw_lock_clean_up(struct aws_rw_lock *lock) { - - pthread_rwlock_destroy(&lock->lock_handle); -} - -int aws_rw_lock_rlock(struct aws_rw_lock *lock) { - - return aws_private_convert_and_raise_error_code(pthread_rwlock_rdlock(&lock->lock_handle)); -} - -int aws_rw_lock_wlock(struct aws_rw_lock *lock) { - - return aws_private_convert_and_raise_error_code(pthread_rwlock_wrlock(&lock->lock_handle)); -} - -int aws_rw_lock_try_rlock(struct aws_rw_lock *lock) { - - return aws_private_convert_and_raise_error_code(pthread_rwlock_tryrdlock(&lock->lock_handle)); -} - -int aws_rw_lock_try_wlock(struct aws_rw_lock *lock) { - - return aws_private_convert_and_raise_error_code(pthread_rwlock_trywrlock(&lock->lock_handle)); -} - -int aws_rw_lock_runlock(struct aws_rw_lock *lock) { - - return aws_private_convert_and_raise_error_code(pthread_rwlock_unlock(&lock->lock_handle)); -} - -int aws_rw_lock_wunlock(struct aws_rw_lock *lock) { - - return aws_private_convert_and_raise_error_code(pthread_rwlock_unlock(&lock->lock_handle)); -} + */ + +#include <aws/common/atomics.h> +#include <aws/common/rw_lock.h> + +#include <aws/common/posix/common.inl> + +int aws_rw_lock_init(struct aws_rw_lock *lock) { + + return aws_private_convert_and_raise_error_code(pthread_rwlock_init(&lock->lock_handle, NULL)); +} + +void aws_rw_lock_clean_up(struct aws_rw_lock *lock) { + + pthread_rwlock_destroy(&lock->lock_handle); +} + +int aws_rw_lock_rlock(struct aws_rw_lock *lock) { + + return aws_private_convert_and_raise_error_code(pthread_rwlock_rdlock(&lock->lock_handle)); +} + +int aws_rw_lock_wlock(struct aws_rw_lock *lock) { + + return aws_private_convert_and_raise_error_code(pthread_rwlock_wrlock(&lock->lock_handle)); +} + +int aws_rw_lock_try_rlock(struct aws_rw_lock *lock) { + + return aws_private_convert_and_raise_error_code(pthread_rwlock_tryrdlock(&lock->lock_handle)); +} + +int aws_rw_lock_try_wlock(struct aws_rw_lock *lock) { + + return aws_private_convert_and_raise_error_code(pthread_rwlock_trywrlock(&lock->lock_handle)); +} + +int aws_rw_lock_runlock(struct aws_rw_lock *lock) { + + return aws_private_convert_and_raise_error_code(pthread_rwlock_unlock(&lock->lock_handle)); +} + +int aws_rw_lock_wunlock(struct aws_rw_lock *lock) { + + return aws_private_convert_and_raise_error_code(pthread_rwlock_unlock(&lock->lock_handle)); +} diff --git a/contrib/restricted/aws/aws-c-common/source/posix/system_info.c b/contrib/restricted/aws/aws-c-common/source/posix/system_info.c index 5fae2812ad..1311be4096 100644 --- a/contrib/restricted/aws/aws-c-common/source/posix/system_info.c +++ b/contrib/restricted/aws/aws-c-common/source/posix/system_info.c @@ -1,41 +1,41 @@ /** * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. - */ - -#include <aws/common/system_info.h> - + */ + +#include <aws/common/system_info.h> + #include <aws/common/byte_buf.h> #include <aws/common/logging.h> #include <aws/common/platform.h> -#if defined(__FreeBSD__) || defined(__NetBSD__) -# define __BSD_VISIBLE 1 -#endif - -#include <unistd.h> - -#if defined(HAVE_SYSCONF) -size_t aws_system_info_processor_count(void) { - long nprocs = sysconf(_SC_NPROCESSORS_ONLN); - if (AWS_LIKELY(nprocs >= 0)) { - return (size_t)nprocs; - } - +#if defined(__FreeBSD__) || defined(__NetBSD__) +# define __BSD_VISIBLE 1 +#endif + +#include <unistd.h> + +#if defined(HAVE_SYSCONF) +size_t aws_system_info_processor_count(void) { + long nprocs = sysconf(_SC_NPROCESSORS_ONLN); + if (AWS_LIKELY(nprocs >= 0)) { + return (size_t)nprocs; + } + AWS_FATAL_POSTCONDITION(nprocs >= 0); - return 0; -} -#else -size_t aws_system_info_processor_count(void) { -# if defined(AWS_NUM_CPU_CORES) + return 0; +} +#else +size_t aws_system_info_processor_count(void) { +# if defined(AWS_NUM_CPU_CORES) AWS_FATAL_PRECONDITION(AWS_NUM_CPU_CORES > 0); - return AWS_NUM_CPU_CORES; -# else - return 1; -# endif -} -#endif - + return AWS_NUM_CPU_CORES; +# else + return 1; +# endif +} +#endif + #include <ctype.h> #include <fcntl.h> @@ -72,37 +72,37 @@ bool aws_is_debugger_present(void) { return false; } -#include <signal.h> - -#ifndef __has_builtin -# define __has_builtin(x) 0 -#endif - -void aws_debug_break(void) { -#ifdef DEBUG_BUILD +#include <signal.h> + +#ifndef __has_builtin +# define __has_builtin(x) 0 +#endif + +void aws_debug_break(void) { +#ifdef DEBUG_BUILD if (aws_is_debugger_present()) { -# if __has_builtin(__builtin_debugtrap) +# if __has_builtin(__builtin_debugtrap) __builtin_debugtrap(); -# else +# else raise(SIGTRAP); -# endif +# endif } -#endif /* DEBUG_BUILD */ -} - -#if defined(AWS_HAVE_EXECINFO) -# include <execinfo.h> -# include <limits.h> - -# define AWS_BACKTRACE_DEPTH 128 - -struct aws_stack_frame_info { - char exe[PATH_MAX]; - char addr[32]; - char base[32]; /* base addr for dylib/exe */ - char function[128]; -}; - +#endif /* DEBUG_BUILD */ +} + +#if defined(AWS_HAVE_EXECINFO) +# include <execinfo.h> +# include <limits.h> + +# define AWS_BACKTRACE_DEPTH 128 + +struct aws_stack_frame_info { + char exe[PATH_MAX]; + char addr[32]; + char base[32]; /* base addr for dylib/exe */ + char function[128]; +}; + /* Ensure only safe characters in a path buffer in case someone tries to rename the exe and trigger shell execution via the sub commands used to resolve symbols */ @@ -119,95 +119,95 @@ char *s_whitelist_chars(char *path) { return path; } -# if defined(__APPLE__) -# include <ctype.h> -# include <dlfcn.h> -# include <mach-o/dyld.h> -static char s_exe_path[PATH_MAX]; -const char *s_get_executable_path() { - static const char *s_exe = NULL; - if (AWS_LIKELY(s_exe)) { - return s_exe; - } - uint32_t len = sizeof(s_exe_path); - if (!_NSGetExecutablePath(s_exe_path, &len)) { - s_exe = s_exe_path; - } - return s_exe; -} -int s_parse_symbol(const char *symbol, void *addr, struct aws_stack_frame_info *frame) { - /* symbols look like: <frame_idx> <exe-or-shared-lib> <addr> <function> + <offset> - */ - const char *current_exe = s_get_executable_path(); - /* parse exe/shared lib */ - const char *exe_start = strstr(symbol, " "); +# if defined(__APPLE__) +# include <ctype.h> +# include <dlfcn.h> +# include <mach-o/dyld.h> +static char s_exe_path[PATH_MAX]; +const char *s_get_executable_path() { + static const char *s_exe = NULL; + if (AWS_LIKELY(s_exe)) { + return s_exe; + } + uint32_t len = sizeof(s_exe_path); + if (!_NSGetExecutablePath(s_exe_path, &len)) { + s_exe = s_exe_path; + } + return s_exe; +} +int s_parse_symbol(const char *symbol, void *addr, struct aws_stack_frame_info *frame) { + /* symbols look like: <frame_idx> <exe-or-shared-lib> <addr> <function> + <offset> + */ + const char *current_exe = s_get_executable_path(); + /* parse exe/shared lib */ + const char *exe_start = strstr(symbol, " "); while (aws_isspace(*exe_start)) { - ++exe_start; + ++exe_start; + } + const char *exe_end = strstr(exe_start, " "); + strncpy(frame->exe, exe_start, exe_end - exe_start); + /* executables get basename'd, so restore the path */ + if (strstr(current_exe, frame->exe)) { + strncpy(frame->exe, current_exe, strlen(current_exe)); } - const char *exe_end = strstr(exe_start, " "); - strncpy(frame->exe, exe_start, exe_end - exe_start); - /* executables get basename'd, so restore the path */ - if (strstr(current_exe, frame->exe)) { - strncpy(frame->exe, current_exe, strlen(current_exe)); - } s_whitelist_chars(frame->exe); - - /* parse addr */ - const char *addr_start = strstr(exe_end, "0x"); - const char *addr_end = strstr(addr_start, " "); - strncpy(frame->addr, addr_start, addr_end - addr_start); - - /* parse function */ - const char *function_start = strstr(addr_end, " ") + 1; - const char *function_end = strstr(function_start, " "); + + /* parse addr */ + const char *addr_start = strstr(exe_end, "0x"); + const char *addr_end = strstr(addr_start, " "); + strncpy(frame->addr, addr_start, addr_end - addr_start); + + /* parse function */ + const char *function_start = strstr(addr_end, " ") + 1; + const char *function_end = strstr(function_start, " "); /* truncate function name if needed */ size_t function_len = function_end - function_start; if (function_len >= (sizeof(frame->function) - 1)) { function_len = sizeof(frame->function) - 1; } - strncpy(frame->function, function_start, function_end - function_start); - - /* find base addr for library/exe */ - Dl_info addr_info; - dladdr(addr, &addr_info); - snprintf(frame->base, sizeof(frame->base), "0x%p", addr_info.dli_fbase); - - return AWS_OP_SUCCESS; -} - -void s_resolve_cmd(char *cmd, size_t len, struct aws_stack_frame_info *frame) { - snprintf(cmd, len, "atos -o %s -l %s %s", frame->exe, frame->base, frame->addr); -} -# else -int s_parse_symbol(const char *symbol, void *addr, struct aws_stack_frame_info *frame) { + strncpy(frame->function, function_start, function_end - function_start); + + /* find base addr for library/exe */ + Dl_info addr_info; + dladdr(addr, &addr_info); + snprintf(frame->base, sizeof(frame->base), "0x%p", addr_info.dli_fbase); + + return AWS_OP_SUCCESS; +} + +void s_resolve_cmd(char *cmd, size_t len, struct aws_stack_frame_info *frame) { + snprintf(cmd, len, "atos -o %s -l %s %s", frame->exe, frame->base, frame->addr); +} +# else +int s_parse_symbol(const char *symbol, void *addr, struct aws_stack_frame_info *frame) { /* symbols look like: <exe-or-shared-lib>(<function>+<addr>) [0x<addr>] - * or: <exe-or-shared-lib> [0x<addr>] + * or: <exe-or-shared-lib> [0x<addr>] * or: [0x<addr>] - */ - (void)addr; - const char *open_paren = strstr(symbol, "("); - const char *close_paren = strstr(symbol, ")"); - const char *exe_end = open_paren; - /* there may not be a function in parens, or parens at all */ - if (open_paren == NULL || close_paren == NULL) { + */ + (void)addr; + const char *open_paren = strstr(symbol, "("); + const char *close_paren = strstr(symbol, ")"); + const char *exe_end = open_paren; + /* there may not be a function in parens, or parens at all */ + if (open_paren == NULL || close_paren == NULL) { exe_end = strstr(symbol, "["); - if (!exe_end) { - return AWS_OP_ERR; - } + if (!exe_end) { + return AWS_OP_ERR; + } /* if exe_end == symbol, there's no exe */ if (exe_end != symbol) { exe_end -= 1; } - } - - ptrdiff_t exe_len = exe_end - symbol; + } + + ptrdiff_t exe_len = exe_end - symbol; if (exe_len > 0) { strncpy(frame->exe, symbol, exe_len); - } + } s_whitelist_chars(frame->exe); - - long function_len = (open_paren && close_paren) ? close_paren - open_paren - 1 : 0; - if (function_len > 0) { /* dynamic symbol was found */ + + long function_len = (open_paren && close_paren) ? close_paren - open_paren - 1 : 0; + if (function_len > 0) { /* dynamic symbol was found */ /* there might be (<function>+<addr>) or just (<function>) */ const char *function_start = open_paren + 1; const char *plus = strstr(function_start, "+"); @@ -219,7 +219,7 @@ int s_parse_symbol(const char *symbol, void *addr, struct aws_stack_frame_info * long addr_len = close_paren - plus - 1; strncpy(frame->addr, plus + 1, addr_len); } - } + } if (frame->addr[0] == 0) { /* use the address in []'s, since it's all we have */ const char *addr_start = strstr(exe_end, "[") + 1; @@ -229,14 +229,14 @@ int s_parse_symbol(const char *symbol, void *addr, struct aws_stack_frame_info * } strncpy(frame->addr, addr_start, addr_end - addr_start); } - - return AWS_OP_SUCCESS; -} -void s_resolve_cmd(char *cmd, size_t len, struct aws_stack_frame_info *frame) { - snprintf(cmd, len, "addr2line -afips -e %s %s", frame->exe, frame->addr); -} -# endif - + + return AWS_OP_SUCCESS; +} +void s_resolve_cmd(char *cmd, size_t len, struct aws_stack_frame_info *frame) { + snprintf(cmd, len, "addr2line -afips -e %s %s", frame->exe, frame->addr); +} +# endif + size_t aws_backtrace(void **stack_frames, size_t num_frames) { return backtrace(stack_frames, (int)aws_min_size(num_frames, INT_MAX)); } @@ -294,58 +294,58 @@ char **aws_backtrace_addr2line(void *const *stack_frames, size_t stack_depth) { return (char **)lines.buffer; /* caller is responsible for freeing */ } -void aws_backtrace_print(FILE *fp, void *call_site_data) { - siginfo_t *siginfo = call_site_data; - if (siginfo) { - fprintf(fp, "Signal received: %d, errno: %d\n", siginfo->si_signo, siginfo->si_errno); - if (siginfo->si_signo == SIGSEGV) { - fprintf(fp, " SIGSEGV @ 0x%p\n", siginfo->si_addr); - } - } - - void *stack_frames[AWS_BACKTRACE_DEPTH]; +void aws_backtrace_print(FILE *fp, void *call_site_data) { + siginfo_t *siginfo = call_site_data; + if (siginfo) { + fprintf(fp, "Signal received: %d, errno: %d\n", siginfo->si_signo, siginfo->si_errno); + if (siginfo->si_signo == SIGSEGV) { + fprintf(fp, " SIGSEGV @ 0x%p\n", siginfo->si_addr); + } + } + + void *stack_frames[AWS_BACKTRACE_DEPTH]; size_t stack_depth = aws_backtrace(stack_frames, AWS_BACKTRACE_DEPTH); char **symbols = aws_backtrace_symbols(stack_frames, stack_depth); - if (symbols == NULL) { - fprintf(fp, "Unable to decode backtrace via backtrace_symbols\n"); - return; - } - + if (symbols == NULL) { + fprintf(fp, "Unable to decode backtrace via backtrace_symbols\n"); + return; + } + fprintf(fp, "################################################################################\n"); fprintf(fp, "Resolved stacktrace:\n"); fprintf(fp, "################################################################################\n"); /* symbols look like: <exe-or-shared-lib>(<function>+<addr>) [0x<addr>] - * or: <exe-or-shared-lib> [0x<addr>] + * or: <exe-or-shared-lib> [0x<addr>] * or: [0x<addr>] - * start at 1 to skip the current frame (this function) */ + * start at 1 to skip the current frame (this function) */ for (size_t frame_idx = 1; frame_idx < stack_depth; ++frame_idx) { - struct aws_stack_frame_info frame; - AWS_ZERO_STRUCT(frame); - const char *symbol = symbols[frame_idx]; - if (s_parse_symbol(symbol, stack_frames[frame_idx], &frame)) { - goto parse_failed; - } - - /* TODO: Emulate libunwind */ - char cmd[sizeof(struct aws_stack_frame_info)] = {0}; - s_resolve_cmd(cmd, sizeof(cmd), &frame); - FILE *out = popen(cmd, "r"); - if (!out) { - goto parse_failed; - } - char output[1024]; - if (fgets(output, sizeof(output), out)) { - /* if addr2line or atos don't know what to do with an address, they just echo it */ - /* if there are spaces in the output, then they resolved something */ - if (strstr(output, " ")) { - symbol = output; - } - } - pclose(out); - - parse_failed: - fprintf(fp, "%s%s", symbol, (symbol == symbols[frame_idx]) ? "\n" : ""); - } + struct aws_stack_frame_info frame; + AWS_ZERO_STRUCT(frame); + const char *symbol = symbols[frame_idx]; + if (s_parse_symbol(symbol, stack_frames[frame_idx], &frame)) { + goto parse_failed; + } + + /* TODO: Emulate libunwind */ + char cmd[sizeof(struct aws_stack_frame_info)] = {0}; + s_resolve_cmd(cmd, sizeof(cmd), &frame); + FILE *out = popen(cmd, "r"); + if (!out) { + goto parse_failed; + } + char output[1024]; + if (fgets(output, sizeof(output), out)) { + /* if addr2line or atos don't know what to do with an address, they just echo it */ + /* if there are spaces in the output, then they resolved something */ + if (strstr(output, " ")) { + symbol = output; + } + } + pclose(out); + + parse_failed: + fprintf(fp, "%s%s", symbol, (symbol == symbols[frame_idx]) ? "\n" : ""); + } fprintf(fp, "################################################################################\n"); fprintf(fp, "Raw stacktrace:\n"); @@ -356,14 +356,14 @@ void aws_backtrace_print(FILE *fp, void *call_site_data) { } fflush(fp); - free(symbols); -} - -#else -void aws_backtrace_print(FILE *fp, void *call_site_data) { + free(symbols); +} + +#else +void aws_backtrace_print(FILE *fp, void *call_site_data) { (void)call_site_data; - fprintf(fp, "No call stack information available\n"); -} + fprintf(fp, "No call stack information available\n"); +} size_t aws_backtrace(void **stack_frames, size_t size) { (void)stack_frames; @@ -382,7 +382,7 @@ char **aws_backtrace_addr2line(void *const *stack_frames, size_t stack_depth) { (void)stack_depth; return NULL; } -#endif /* AWS_HAVE_EXECINFO */ +#endif /* AWS_HAVE_EXECINFO */ void aws_backtrace_log() { void *stack_frames[1024]; diff --git a/contrib/restricted/aws/aws-c-common/source/posix/thread.c b/contrib/restricted/aws/aws-c-common/source/posix/thread.c index 1ae2660f1a..064d16882f 100644 --- a/contrib/restricted/aws/aws-c-common/source/posix/thread.c +++ b/contrib/restricted/aws/aws-c-common/source/posix/thread.c @@ -1,57 +1,57 @@ /** * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. - */ - + */ + #if !defined(__MACH__) # define _GNU_SOURCE #endif - -#include <aws/common/clock.h> + +#include <aws/common/clock.h> #include <aws/common/logging.h> #include <aws/common/private/dlloads.h> #include <aws/common/thread.h> - + #include <dlfcn.h> -#include <errno.h> +#include <errno.h> #include <inttypes.h> -#include <limits.h> +#include <limits.h> #include <sched.h> -#include <time.h> +#include <time.h> #include <unistd.h> - + #if defined(__FreeBSD__) || defined(__NETBSD__) # include <pthread_np.h> typedef cpuset_t cpu_set_t; #endif -static struct aws_thread_options s_default_options = { - /* this will make sure platform default stack size is used. */ +static struct aws_thread_options s_default_options = { + /* this will make sure platform default stack size is used. */ .stack_size = 0, .cpu_id = -1, }; - + struct thread_atexit_callback { aws_thread_atexit_fn *callback; void *user_data; struct thread_atexit_callback *next; }; -struct thread_wrapper { - struct aws_allocator *allocator; - void (*func)(void *arg); - void *arg; +struct thread_wrapper { + struct aws_allocator *allocator; + void (*func)(void *arg); + void *arg; struct thread_atexit_callback *atexit; void (*call_once)(void *); void *once_arg; struct aws_thread *thread; bool membind; -}; - +}; + static AWS_THREAD_LOCAL struct thread_wrapper *tl_wrapper = NULL; -static void *thread_fn(void *arg) { - struct thread_wrapper wrapper = *(struct thread_wrapper *)arg; +static void *thread_fn(void *arg) { + struct thread_wrapper wrapper = *(struct thread_wrapper *)arg; struct aws_allocator *allocator = wrapper.allocator; tl_wrapper = &wrapper; if (wrapper.membind && g_set_mempolicy_ptr) { @@ -73,7 +73,7 @@ static void *thread_fn(void *arg) { } } wrapper.func(wrapper.arg); - + struct thread_atexit_callback *exit_callback_data = wrapper.atexit; aws_mem_release(allocator, arg); @@ -89,23 +89,23 @@ static void *thread_fn(void *arg) { } tl_wrapper = NULL; - return NULL; -} - -const struct aws_thread_options *aws_default_thread_options(void) { - return &s_default_options; -} - -void aws_thread_clean_up(struct aws_thread *thread) { - if (thread->detach_state == AWS_THREAD_JOINABLE) { - pthread_detach(thread->thread_id); - } -} - + return NULL; +} + +const struct aws_thread_options *aws_default_thread_options(void) { + return &s_default_options; +} + +void aws_thread_clean_up(struct aws_thread *thread) { + if (thread->detach_state == AWS_THREAD_JOINABLE) { + pthread_detach(thread->thread_id); + } +} + static void s_call_once(void) { tl_wrapper->call_once(tl_wrapper->once_arg); -} - +} + void aws_thread_call_once(aws_thread_once *flag, void (*call_once)(void *), void *user_data) { // If this is a non-aws_thread, then gin up a temp thread wrapper struct thread_wrapper temp_wrapper; @@ -122,39 +122,39 @@ void aws_thread_call_once(aws_thread_once *flag, void (*call_once)(void *), void } } -int aws_thread_init(struct aws_thread *thread, struct aws_allocator *allocator) { +int aws_thread_init(struct aws_thread *thread, struct aws_allocator *allocator) { *thread = (struct aws_thread){.allocator = allocator, .detach_state = AWS_THREAD_NOT_CREATED}; - - return AWS_OP_SUCCESS; -} - -int aws_thread_launch( - struct aws_thread *thread, - void (*func)(void *arg), - void *arg, - const struct aws_thread_options *options) { - - pthread_attr_t attributes; - pthread_attr_t *attributes_ptr = NULL; - int attr_return = 0; - int allocation_failed = 0; - - if (options) { - attr_return = pthread_attr_init(&attributes); - - if (attr_return) { - goto cleanup; - } - - attributes_ptr = &attributes; - - if (options->stack_size > PTHREAD_STACK_MIN) { - attr_return = pthread_attr_setstacksize(attributes_ptr, options->stack_size); - - if (attr_return) { - goto cleanup; - } - } + + return AWS_OP_SUCCESS; +} + +int aws_thread_launch( + struct aws_thread *thread, + void (*func)(void *arg), + void *arg, + const struct aws_thread_options *options) { + + pthread_attr_t attributes; + pthread_attr_t *attributes_ptr = NULL; + int attr_return = 0; + int allocation_failed = 0; + + if (options) { + attr_return = pthread_attr_init(&attributes); + + if (attr_return) { + goto cleanup; + } + + attributes_ptr = &attributes; + + if (options->stack_size > PTHREAD_STACK_MIN) { + attr_return = pthread_attr_setstacksize(attributes_ptr, options->stack_size); + + if (attr_return) { + goto cleanup; + } + } /* AFAIK you can't set thread affinity on apple platforms, and it doesn't really matter since all memory * NUMA or not is setup in interleave mode. @@ -184,106 +184,106 @@ int aws_thread_launch( } } #endif /* !defined(__MACH__) && !defined(__ANDROID__) */ - } - - struct thread_wrapper *wrapper = + } + + struct thread_wrapper *wrapper = (struct thread_wrapper *)aws_mem_calloc(thread->allocator, 1, sizeof(struct thread_wrapper)); - - if (!wrapper) { - allocation_failed = 1; - goto cleanup; - } - + + if (!wrapper) { + allocation_failed = 1; + goto cleanup; + } + if (options && options->cpu_id >= 0) { wrapper->membind = true; } wrapper->thread = thread; - wrapper->allocator = thread->allocator; - wrapper->func = func; - wrapper->arg = arg; - attr_return = pthread_create(&thread->thread_id, attributes_ptr, thread_fn, (void *)wrapper); - - if (attr_return) { - goto cleanup; - } - - thread->detach_state = AWS_THREAD_JOINABLE; - -cleanup: - if (attributes_ptr) { - pthread_attr_destroy(attributes_ptr); - } - - if (attr_return == EINVAL) { - return aws_raise_error(AWS_ERROR_THREAD_INVALID_SETTINGS); - } - - if (attr_return == EAGAIN) { - return aws_raise_error(AWS_ERROR_THREAD_INSUFFICIENT_RESOURCE); - } - - if (attr_return == EPERM) { - return aws_raise_error(AWS_ERROR_THREAD_NO_PERMISSIONS); - } - - if (allocation_failed || attr_return == ENOMEM) { - return aws_raise_error(AWS_ERROR_OOM); - } - - return AWS_OP_SUCCESS; -} - + wrapper->allocator = thread->allocator; + wrapper->func = func; + wrapper->arg = arg; + attr_return = pthread_create(&thread->thread_id, attributes_ptr, thread_fn, (void *)wrapper); + + if (attr_return) { + goto cleanup; + } + + thread->detach_state = AWS_THREAD_JOINABLE; + +cleanup: + if (attributes_ptr) { + pthread_attr_destroy(attributes_ptr); + } + + if (attr_return == EINVAL) { + return aws_raise_error(AWS_ERROR_THREAD_INVALID_SETTINGS); + } + + if (attr_return == EAGAIN) { + return aws_raise_error(AWS_ERROR_THREAD_INSUFFICIENT_RESOURCE); + } + + if (attr_return == EPERM) { + return aws_raise_error(AWS_ERROR_THREAD_NO_PERMISSIONS); + } + + if (allocation_failed || attr_return == ENOMEM) { + return aws_raise_error(AWS_ERROR_OOM); + } + + return AWS_OP_SUCCESS; +} + aws_thread_id_t aws_thread_get_id(struct aws_thread *thread) { return thread->thread_id; -} - -enum aws_thread_detach_state aws_thread_get_detach_state(struct aws_thread *thread) { - return thread->detach_state; -} - -int aws_thread_join(struct aws_thread *thread) { - if (thread->detach_state == AWS_THREAD_JOINABLE) { - int err_no = pthread_join(thread->thread_id, 0); - - if (err_no) { - if (err_no == EINVAL) { - return aws_raise_error(AWS_ERROR_THREAD_NOT_JOINABLE); - } - if (err_no == ESRCH) { - return aws_raise_error(AWS_ERROR_THREAD_NO_SUCH_THREAD_ID); - } - if (err_no == EDEADLK) { - return aws_raise_error(AWS_ERROR_THREAD_DEADLOCK_DETECTED); - } - } - - thread->detach_state = AWS_THREAD_JOIN_COMPLETED; - } - - return AWS_OP_SUCCESS; -} - +} + +enum aws_thread_detach_state aws_thread_get_detach_state(struct aws_thread *thread) { + return thread->detach_state; +} + +int aws_thread_join(struct aws_thread *thread) { + if (thread->detach_state == AWS_THREAD_JOINABLE) { + int err_no = pthread_join(thread->thread_id, 0); + + if (err_no) { + if (err_no == EINVAL) { + return aws_raise_error(AWS_ERROR_THREAD_NOT_JOINABLE); + } + if (err_no == ESRCH) { + return aws_raise_error(AWS_ERROR_THREAD_NO_SUCH_THREAD_ID); + } + if (err_no == EDEADLK) { + return aws_raise_error(AWS_ERROR_THREAD_DEADLOCK_DETECTED); + } + } + + thread->detach_state = AWS_THREAD_JOIN_COMPLETED; + } + + return AWS_OP_SUCCESS; +} + aws_thread_id_t aws_thread_current_thread_id(void) { return pthread_self(); -} - +} + bool aws_thread_thread_id_equal(aws_thread_id_t t1, aws_thread_id_t t2) { return pthread_equal(t1, t2) != 0; } -void aws_thread_current_sleep(uint64_t nanos) { - uint64_t nano = 0; - time_t seconds = (time_t)aws_timestamp_convert(nanos, AWS_TIMESTAMP_NANOS, AWS_TIMESTAMP_SECS, &nano); - - struct timespec tm = { - .tv_sec = seconds, - .tv_nsec = (long)nano, - }; - struct timespec output; - - nanosleep(&tm, &output); -} +void aws_thread_current_sleep(uint64_t nanos) { + uint64_t nano = 0; + time_t seconds = (time_t)aws_timestamp_convert(nanos, AWS_TIMESTAMP_NANOS, AWS_TIMESTAMP_SECS, &nano); + + struct timespec tm = { + .tv_sec = seconds, + .tv_nsec = (long)nano, + }; + struct timespec output; + + nanosleep(&tm, &output); +} int aws_thread_current_at_exit(aws_thread_atexit_fn *callback, void *user_data) { if (!tl_wrapper) { diff --git a/contrib/restricted/aws/aws-c-common/source/posix/time.c b/contrib/restricted/aws/aws-c-common/source/posix/time.c index 73d35945c9..dd49d6b0b6 100644 --- a/contrib/restricted/aws/aws-c-common/source/posix/time.c +++ b/contrib/restricted/aws/aws-c-common/source/posix/time.c @@ -1,79 +1,79 @@ /** * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. - */ -#include <aws/common/time.h> - -#if defined(__ANDROID__) && !defined(__LP64__) -/* - * This branch brought to you by the kind folks at google chromium. It's been modified a bit, but - * gotta give credit where it's due.... I'm not a lawyer so I'm just gonna drop their copyright - * notification here to avoid all of that. - */ - -/* - * Copyright 2014 The Chromium Authors. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - * From src/base/os_compat_android.cc: - */ -# include <time64.h> - -static const time_t s_time_max = ~(1L << ((sizeof(time_t) * __CHAR_BIT__ - 1))); -static const time_t s_time_min = (1L << ((sizeof(time_t)) * __CHAR_BIT__ - 1)); - -/* 32-bit Android has only timegm64() and not timegm(). */ -time_t aws_timegm(struct tm *const t) { - - time64_t result = timegm64(t); - if (result < s_time_min || result > s_time_max) { - return -1; - } - return (time_t)result; -} - -#else - -# ifndef __APPLE__ -/* glibc.... you disappoint me.. */ -extern time_t timegm(struct tm *); -# endif - -time_t aws_timegm(struct tm *const t) { - return timegm(t); -} - -#endif /* defined(__ANDROID__) && !defined(__LP64__) */ - -void aws_localtime(time_t time, struct tm *t) { - localtime_r(&time, t); -} - -void aws_gmtime(time_t time, struct tm *t) { - gmtime_r(&time, t); -} + */ +#include <aws/common/time.h> + +#if defined(__ANDROID__) && !defined(__LP64__) +/* + * This branch brought to you by the kind folks at google chromium. It's been modified a bit, but + * gotta give credit where it's due.... I'm not a lawyer so I'm just gonna drop their copyright + * notification here to avoid all of that. + */ + +/* + * Copyright 2014 The Chromium Authors. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + * From src/base/os_compat_android.cc: + */ +# include <time64.h> + +static const time_t s_time_max = ~(1L << ((sizeof(time_t) * __CHAR_BIT__ - 1))); +static const time_t s_time_min = (1L << ((sizeof(time_t)) * __CHAR_BIT__ - 1)); + +/* 32-bit Android has only timegm64() and not timegm(). */ +time_t aws_timegm(struct tm *const t) { + + time64_t result = timegm64(t); + if (result < s_time_min || result > s_time_max) { + return -1; + } + return (time_t)result; +} + +#else + +# ifndef __APPLE__ +/* glibc.... you disappoint me.. */ +extern time_t timegm(struct tm *); +# endif + +time_t aws_timegm(struct tm *const t) { + return timegm(t); +} + +#endif /* defined(__ANDROID__) && !defined(__LP64__) */ + +void aws_localtime(time_t time, struct tm *t) { + localtime_r(&time, t); +} + +void aws_gmtime(time_t time, struct tm *t) { + gmtime_r(&time, t); +} diff --git a/contrib/restricted/aws/aws-c-common/source/priority_queue.c b/contrib/restricted/aws/aws-c-common/source/priority_queue.c index a985a39252..14ff421d5f 100644 --- a/contrib/restricted/aws/aws-c-common/source/priority_queue.c +++ b/contrib/restricted/aws/aws-c-common/source/priority_queue.c @@ -1,161 +1,161 @@ /** * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. - */ - -#include <aws/common/priority_queue.h> - -#include <string.h> - -#define PARENT_OF(index) (((index)&1) ? (index) >> 1 : (index) > 1 ? ((index)-2) >> 1 : 0) -#define LEFT_OF(index) (((index) << 1) + 1) -#define RIGHT_OF(index) (((index) << 1) + 2) - -static void s_swap(struct aws_priority_queue *queue, size_t a, size_t b) { + */ + +#include <aws/common/priority_queue.h> + +#include <string.h> + +#define PARENT_OF(index) (((index)&1) ? (index) >> 1 : (index) > 1 ? ((index)-2) >> 1 : 0) +#define LEFT_OF(index) (((index) << 1) + 1) +#define RIGHT_OF(index) (((index) << 1) + 2) + +static void s_swap(struct aws_priority_queue *queue, size_t a, size_t b) { AWS_PRECONDITION(aws_priority_queue_is_valid(queue)); AWS_PRECONDITION(a < queue->container.length); AWS_PRECONDITION(b < queue->container.length); AWS_PRECONDITION(aws_priority_queue_backpointer_index_valid(queue, a)); AWS_PRECONDITION(aws_priority_queue_backpointer_index_valid(queue, b)); - aws_array_list_swap(&queue->container, a, b); - - /* Invariant: If the backpointer array is initialized, we have enough room for all elements */ + aws_array_list_swap(&queue->container, a, b); + + /* Invariant: If the backpointer array is initialized, we have enough room for all elements */ if (!AWS_IS_ZEROED(queue->backpointers)) { - AWS_ASSERT(queue->backpointers.length > a); - AWS_ASSERT(queue->backpointers.length > b); - - struct aws_priority_queue_node **bp_a = &((struct aws_priority_queue_node **)queue->backpointers.data)[a]; - struct aws_priority_queue_node **bp_b = &((struct aws_priority_queue_node **)queue->backpointers.data)[b]; - - struct aws_priority_queue_node *tmp = *bp_a; - *bp_a = *bp_b; - *bp_b = tmp; - - if (*bp_a) { - (*bp_a)->current_index = a; - } - - if (*bp_b) { - (*bp_b)->current_index = b; - } - } + AWS_ASSERT(queue->backpointers.length > a); + AWS_ASSERT(queue->backpointers.length > b); + + struct aws_priority_queue_node **bp_a = &((struct aws_priority_queue_node **)queue->backpointers.data)[a]; + struct aws_priority_queue_node **bp_b = &((struct aws_priority_queue_node **)queue->backpointers.data)[b]; + + struct aws_priority_queue_node *tmp = *bp_a; + *bp_a = *bp_b; + *bp_b = tmp; + + if (*bp_a) { + (*bp_a)->current_index = a; + } + + if (*bp_b) { + (*bp_b)->current_index = b; + } + } AWS_POSTCONDITION(aws_priority_queue_is_valid(queue)); AWS_POSTCONDITION(aws_priority_queue_backpointer_index_valid(queue, a)); AWS_POSTCONDITION(aws_priority_queue_backpointer_index_valid(queue, b)); -} - -/* Precondition: with the exception of the given root element, the container must be - * in heap order */ -static bool s_sift_down(struct aws_priority_queue *queue, size_t root) { +} + +/* Precondition: with the exception of the given root element, the container must be + * in heap order */ +static bool s_sift_down(struct aws_priority_queue *queue, size_t root) { AWS_PRECONDITION(aws_priority_queue_is_valid(queue)); AWS_PRECONDITION(root < queue->container.length); - bool did_move = false; - - size_t len = aws_array_list_length(&queue->container); - - while (LEFT_OF(root) < len) { - size_t left = LEFT_OF(root); - size_t right = RIGHT_OF(root); - size_t first = root; - void *first_item = NULL, *other_item = NULL; - - aws_array_list_get_at_ptr(&queue->container, &first_item, root); - aws_array_list_get_at_ptr(&queue->container, &other_item, left); - - if (queue->pred(first_item, other_item) > 0) { - first = left; - first_item = other_item; - } - - if (right < len) { - aws_array_list_get_at_ptr(&queue->container, &other_item, right); - - /* choose the larger/smaller of the two in case of a max/min heap - * respectively */ - if (queue->pred(first_item, other_item) > 0) { - first = right; - first_item = other_item; - } - } - - if (first != root) { - s_swap(queue, first, root); - did_move = true; - root = first; - } else { - break; - } - } - + bool did_move = false; + + size_t len = aws_array_list_length(&queue->container); + + while (LEFT_OF(root) < len) { + size_t left = LEFT_OF(root); + size_t right = RIGHT_OF(root); + size_t first = root; + void *first_item = NULL, *other_item = NULL; + + aws_array_list_get_at_ptr(&queue->container, &first_item, root); + aws_array_list_get_at_ptr(&queue->container, &other_item, left); + + if (queue->pred(first_item, other_item) > 0) { + first = left; + first_item = other_item; + } + + if (right < len) { + aws_array_list_get_at_ptr(&queue->container, &other_item, right); + + /* choose the larger/smaller of the two in case of a max/min heap + * respectively */ + if (queue->pred(first_item, other_item) > 0) { + first = right; + first_item = other_item; + } + } + + if (first != root) { + s_swap(queue, first, root); + did_move = true; + root = first; + } else { + break; + } + } + AWS_POSTCONDITION(aws_priority_queue_is_valid(queue)); - return did_move; -} - -/* Precondition: Elements prior to the specified index must be in heap order. */ -static bool s_sift_up(struct aws_priority_queue *queue, size_t index) { + return did_move; +} + +/* Precondition: Elements prior to the specified index must be in heap order. */ +static bool s_sift_up(struct aws_priority_queue *queue, size_t index) { AWS_PRECONDITION(aws_priority_queue_is_valid(queue)); AWS_PRECONDITION(index < queue->container.length); - bool did_move = false; - - void *parent_item, *child_item; - size_t parent = PARENT_OF(index); - while (index) { - /* - * These get_ats are guaranteed to be successful; if they are not, we have - * serious state corruption, so just abort. - */ - - if (aws_array_list_get_at_ptr(&queue->container, &parent_item, parent) || - aws_array_list_get_at_ptr(&queue->container, &child_item, index)) { - abort(); - } - - if (queue->pred(parent_item, child_item) > 0) { - s_swap(queue, index, parent); - did_move = true; - index = parent; - parent = PARENT_OF(index); - } else { - break; - } - } - + bool did_move = false; + + void *parent_item, *child_item; + size_t parent = PARENT_OF(index); + while (index) { + /* + * These get_ats are guaranteed to be successful; if they are not, we have + * serious state corruption, so just abort. + */ + + if (aws_array_list_get_at_ptr(&queue->container, &parent_item, parent) || + aws_array_list_get_at_ptr(&queue->container, &child_item, index)) { + abort(); + } + + if (queue->pred(parent_item, child_item) > 0) { + s_swap(queue, index, parent); + did_move = true; + index = parent; + parent = PARENT_OF(index); + } else { + break; + } + } + AWS_POSTCONDITION(aws_priority_queue_is_valid(queue)); - return did_move; -} - -/* - * Precondition: With the exception of the given index, the heap condition holds for all elements. - * In particular, the parent of the current index is a predecessor of all children of the current index. - */ -static void s_sift_either(struct aws_priority_queue *queue, size_t index) { + return did_move; +} + +/* + * Precondition: With the exception of the given index, the heap condition holds for all elements. + * In particular, the parent of the current index is a predecessor of all children of the current index. + */ +static void s_sift_either(struct aws_priority_queue *queue, size_t index) { AWS_PRECONDITION(aws_priority_queue_is_valid(queue)); AWS_PRECONDITION(index < queue->container.length); - if (!index || !s_sift_up(queue, index)) { - s_sift_down(queue, index); - } + if (!index || !s_sift_up(queue, index)) { + s_sift_down(queue, index); + } AWS_POSTCONDITION(aws_priority_queue_is_valid(queue)); -} - -int aws_priority_queue_init_dynamic( - struct aws_priority_queue *queue, - struct aws_allocator *alloc, - size_t default_size, - size_t item_size, - aws_priority_queue_compare_fn *pred) { - +} + +int aws_priority_queue_init_dynamic( + struct aws_priority_queue *queue, + struct aws_allocator *alloc, + size_t default_size, + size_t item_size, + aws_priority_queue_compare_fn *pred) { + AWS_FATAL_PRECONDITION(queue != NULL); AWS_FATAL_PRECONDITION(alloc != NULL); AWS_FATAL_PRECONDITION(item_size > 0); - queue->pred = pred; - AWS_ZERO_STRUCT(queue->backpointers); - + queue->pred = pred; + AWS_ZERO_STRUCT(queue->backpointers); + int ret = aws_array_list_init_dynamic(&queue->container, alloc, default_size, item_size); if (ret == AWS_OP_SUCCESS) { AWS_POSTCONDITION(aws_priority_queue_is_valid(queue)); @@ -164,28 +164,28 @@ int aws_priority_queue_init_dynamic( AWS_POSTCONDITION(AWS_IS_ZEROED(queue->backpointers)); } return ret; -} - -void aws_priority_queue_init_static( - struct aws_priority_queue *queue, - void *heap, - size_t item_count, - size_t item_size, - aws_priority_queue_compare_fn *pred) { - +} + +void aws_priority_queue_init_static( + struct aws_priority_queue *queue, + void *heap, + size_t item_count, + size_t item_size, + aws_priority_queue_compare_fn *pred) { + AWS_FATAL_PRECONDITION(queue != NULL); AWS_FATAL_PRECONDITION(heap != NULL); AWS_FATAL_PRECONDITION(item_count > 0); AWS_FATAL_PRECONDITION(item_size > 0); - queue->pred = pred; - AWS_ZERO_STRUCT(queue->backpointers); - - aws_array_list_init_static(&queue->container, heap, item_count, item_size); + queue->pred = pred; + AWS_ZERO_STRUCT(queue->backpointers); + + aws_array_list_init_static(&queue->container, heap, item_count, item_size); AWS_POSTCONDITION(aws_priority_queue_is_valid(queue)); -} - +} + bool aws_priority_queue_backpointer_index_valid(const struct aws_priority_queue *const queue, size_t index) { if (AWS_IS_ZEROED(queue->backpointers)) { return true; @@ -243,105 +243,105 @@ bool aws_priority_queue_backpointers_valid(const struct aws_priority_queue *cons return ((backpointer_list_is_valid && backpointer_struct_is_valid) || AWS_IS_ZEROED(queue->backpointers)); } -bool aws_priority_queue_is_valid(const struct aws_priority_queue *const queue) { +bool aws_priority_queue_is_valid(const struct aws_priority_queue *const queue) { /* Pointer validity checks */ - if (!queue) { - return false; - } - bool pred_is_valid = (queue->pred != NULL); - bool container_is_valid = aws_array_list_is_valid(&queue->container); + if (!queue) { + return false; + } + bool pred_is_valid = (queue->pred != NULL); + bool container_is_valid = aws_array_list_is_valid(&queue->container); bool backpointers_valid = aws_priority_queue_backpointers_valid(queue); return pred_is_valid && container_is_valid && backpointers_valid; -} - -void aws_priority_queue_clean_up(struct aws_priority_queue *queue) { - aws_array_list_clean_up(&queue->container); +} + +void aws_priority_queue_clean_up(struct aws_priority_queue *queue) { + aws_array_list_clean_up(&queue->container); if (!AWS_IS_ZEROED(queue->backpointers)) { aws_array_list_clean_up(&queue->backpointers); } -} - -int aws_priority_queue_push(struct aws_priority_queue *queue, void *item) { +} + +int aws_priority_queue_push(struct aws_priority_queue *queue, void *item) { AWS_PRECONDITION(aws_priority_queue_is_valid(queue)); AWS_PRECONDITION(item && AWS_MEM_IS_READABLE(item, queue->container.item_size)); int rval = aws_priority_queue_push_ref(queue, item, NULL); AWS_POSTCONDITION(aws_priority_queue_is_valid(queue)); return rval; -} - -int aws_priority_queue_push_ref( - struct aws_priority_queue *queue, - void *item, - struct aws_priority_queue_node *backpointer) { +} + +int aws_priority_queue_push_ref( + struct aws_priority_queue *queue, + void *item, + struct aws_priority_queue_node *backpointer) { AWS_PRECONDITION(aws_priority_queue_is_valid(queue)); AWS_PRECONDITION(item && AWS_MEM_IS_READABLE(item, queue->container.item_size)); - int err = aws_array_list_push_back(&queue->container, item); - if (err) { + int err = aws_array_list_push_back(&queue->container, item); + if (err) { AWS_POSTCONDITION(aws_priority_queue_is_valid(queue)); - return err; - } - size_t index = aws_array_list_length(&queue->container) - 1; - - if (backpointer && !queue->backpointers.alloc) { - if (!queue->container.alloc) { - aws_raise_error(AWS_ERROR_UNSUPPORTED_OPERATION); - goto backpointer_update_failed; - } - - if (aws_array_list_init_dynamic( - &queue->backpointers, queue->container.alloc, index + 1, sizeof(struct aws_priority_queue_node *))) { - goto backpointer_update_failed; - } - - /* When we initialize the backpointers array we need to zero out all existing entries */ - memset(queue->backpointers.data, 0, queue->backpointers.current_size); - } - - /* - * Once we have any backpointers, we want to make sure we always have room in the backpointers array - * for all elements; otherwise, sift_down gets complicated if it runs out of memory when sifting an - * element with a backpointer down in the array. - */ + return err; + } + size_t index = aws_array_list_length(&queue->container) - 1; + + if (backpointer && !queue->backpointers.alloc) { + if (!queue->container.alloc) { + aws_raise_error(AWS_ERROR_UNSUPPORTED_OPERATION); + goto backpointer_update_failed; + } + + if (aws_array_list_init_dynamic( + &queue->backpointers, queue->container.alloc, index + 1, sizeof(struct aws_priority_queue_node *))) { + goto backpointer_update_failed; + } + + /* When we initialize the backpointers array we need to zero out all existing entries */ + memset(queue->backpointers.data, 0, queue->backpointers.current_size); + } + + /* + * Once we have any backpointers, we want to make sure we always have room in the backpointers array + * for all elements; otherwise, sift_down gets complicated if it runs out of memory when sifting an + * element with a backpointer down in the array. + */ if (!AWS_IS_ZEROED(queue->backpointers)) { - if (aws_array_list_set_at(&queue->backpointers, &backpointer, index)) { - goto backpointer_update_failed; - } - } - - if (backpointer) { - backpointer->current_index = index; - } - - s_sift_up(queue, aws_array_list_length(&queue->container) - 1); - + if (aws_array_list_set_at(&queue->backpointers, &backpointer, index)) { + goto backpointer_update_failed; + } + } + + if (backpointer) { + backpointer->current_index = index; + } + + s_sift_up(queue, aws_array_list_length(&queue->container) - 1); + AWS_POSTCONDITION(aws_priority_queue_is_valid(queue)); - return AWS_OP_SUCCESS; - -backpointer_update_failed: - /* Failed to initialize or grow the backpointer array, back out the node addition */ - aws_array_list_pop_back(&queue->container); + return AWS_OP_SUCCESS; + +backpointer_update_failed: + /* Failed to initialize or grow the backpointer array, back out the node addition */ + aws_array_list_pop_back(&queue->container); AWS_POSTCONDITION(aws_priority_queue_is_valid(queue)); - return AWS_OP_ERR; -} - -static int s_remove_node(struct aws_priority_queue *queue, void *item, size_t item_index) { + return AWS_OP_ERR; +} + +static int s_remove_node(struct aws_priority_queue *queue, void *item, size_t item_index) { AWS_PRECONDITION(aws_priority_queue_is_valid(queue)); AWS_PRECONDITION(item && AWS_MEM_IS_WRITABLE(item, queue->container.item_size)); - if (aws_array_list_get_at(&queue->container, item, item_index)) { - /* shouldn't happen, but if it does we've already raised an error... */ + if (aws_array_list_get_at(&queue->container, item, item_index)) { + /* shouldn't happen, but if it does we've already raised an error... */ AWS_POSTCONDITION(aws_priority_queue_is_valid(queue)); - return AWS_OP_ERR; - } - - size_t swap_with = aws_array_list_length(&queue->container) - 1; - struct aws_priority_queue_node *backpointer = NULL; - - if (item_index != swap_with) { - s_swap(queue, item_index, swap_with); - } - + return AWS_OP_ERR; + } + + size_t swap_with = aws_array_list_length(&queue->container) - 1; + struct aws_priority_queue_node *backpointer = NULL; + + if (item_index != swap_with) { + s_swap(queue, item_index, swap_with); + } + aws_array_list_pop_back(&queue->container); if (!AWS_IS_ZEROED(queue->backpointers)) { @@ -350,51 +350,51 @@ static int s_remove_node(struct aws_priority_queue *queue, void *item, size_t it backpointer->current_index = SIZE_MAX; } aws_array_list_pop_back(&queue->backpointers); - } - - if (item_index != swap_with) { - s_sift_either(queue, item_index); - } - + } + + if (item_index != swap_with) { + s_sift_either(queue, item_index); + } + AWS_POSTCONDITION(aws_priority_queue_is_valid(queue)); - return AWS_OP_SUCCESS; -} - -int aws_priority_queue_remove( - struct aws_priority_queue *queue, - void *item, - const struct aws_priority_queue_node *node) { + return AWS_OP_SUCCESS; +} + +int aws_priority_queue_remove( + struct aws_priority_queue *queue, + void *item, + const struct aws_priority_queue_node *node) { AWS_PRECONDITION(aws_priority_queue_is_valid(queue)); AWS_PRECONDITION(item && AWS_MEM_IS_WRITABLE(item, queue->container.item_size)); AWS_PRECONDITION(node && AWS_MEM_IS_READABLE(node, sizeof(struct aws_priority_queue_node))); AWS_ERROR_PRECONDITION( node->current_index < aws_array_list_length(&queue->container), AWS_ERROR_PRIORITY_QUEUE_BAD_NODE); AWS_ERROR_PRECONDITION(queue->backpointers.data, AWS_ERROR_PRIORITY_QUEUE_BAD_NODE); - + int rval = s_remove_node(queue, item, node->current_index); AWS_POSTCONDITION(aws_priority_queue_is_valid(queue)); return rval; -} - -int aws_priority_queue_pop(struct aws_priority_queue *queue, void *item) { +} + +int aws_priority_queue_pop(struct aws_priority_queue *queue, void *item) { AWS_PRECONDITION(aws_priority_queue_is_valid(queue)); AWS_PRECONDITION(item && AWS_MEM_IS_WRITABLE(item, queue->container.item_size)); AWS_ERROR_PRECONDITION(aws_array_list_length(&queue->container) != 0, AWS_ERROR_PRIORITY_QUEUE_EMPTY); - + int rval = s_remove_node(queue, item, 0); AWS_POSTCONDITION(aws_priority_queue_is_valid(queue)); return rval; -} - -int aws_priority_queue_top(const struct aws_priority_queue *queue, void **item) { +} + +int aws_priority_queue_top(const struct aws_priority_queue *queue, void **item) { AWS_ERROR_PRECONDITION(aws_array_list_length(&queue->container) != 0, AWS_ERROR_PRIORITY_QUEUE_EMPTY); - return aws_array_list_get_at_ptr(&queue->container, item, 0); -} - -size_t aws_priority_queue_size(const struct aws_priority_queue *queue) { - return aws_array_list_length(&queue->container); -} - -size_t aws_priority_queue_capacity(const struct aws_priority_queue *queue) { - return aws_array_list_capacity(&queue->container); -} + return aws_array_list_get_at_ptr(&queue->container, item, 0); +} + +size_t aws_priority_queue_size(const struct aws_priority_queue *queue) { + return aws_array_list_length(&queue->container); +} + +size_t aws_priority_queue_capacity(const struct aws_priority_queue *queue) { + return aws_array_list_capacity(&queue->container); +} diff --git a/contrib/restricted/aws/aws-c-common/source/string.c b/contrib/restricted/aws/aws-c-common/source/string.c index 4bd67ca7b2..d1abf0dbff 100644 --- a/contrib/restricted/aws/aws-c-common/source/string.c +++ b/contrib/restricted/aws/aws-c-common/source/string.c @@ -1,41 +1,41 @@ /** * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. - */ -#include <aws/common/string.h> - -struct aws_string *aws_string_new_from_c_str(struct aws_allocator *allocator, const char *c_str) { + */ +#include <aws/common/string.h> + +struct aws_string *aws_string_new_from_c_str(struct aws_allocator *allocator, const char *c_str) { AWS_PRECONDITION(allocator && c_str); - return aws_string_new_from_array(allocator, (const uint8_t *)c_str, strlen(c_str)); -} - -struct aws_string *aws_string_new_from_array(struct aws_allocator *allocator, const uint8_t *bytes, size_t len) { + return aws_string_new_from_array(allocator, (const uint8_t *)c_str, strlen(c_str)); +} + +struct aws_string *aws_string_new_from_array(struct aws_allocator *allocator, const uint8_t *bytes, size_t len) { AWS_PRECONDITION(allocator); AWS_PRECONDITION(AWS_MEM_IS_READABLE(bytes, len)); - size_t malloc_size; - if (aws_add_size_checked(sizeof(struct aws_string) + 1, len, &malloc_size)) { - return NULL; - } - struct aws_string *str = aws_mem_acquire(allocator, malloc_size); - if (!str) { - return NULL; - } - - /* Fields are declared const, so we need to copy them in like this */ - *(struct aws_allocator **)(&str->allocator) = allocator; - *(size_t *)(&str->len) = len; + size_t malloc_size; + if (aws_add_size_checked(sizeof(struct aws_string) + 1, len, &malloc_size)) { + return NULL; + } + struct aws_string *str = aws_mem_acquire(allocator, malloc_size); + if (!str) { + return NULL; + } + + /* Fields are declared const, so we need to copy them in like this */ + *(struct aws_allocator **)(&str->allocator) = allocator; + *(size_t *)(&str->len) = len; if (len > 0) { memcpy((void *)str->bytes, bytes, len); } - *(uint8_t *)&str->bytes[len] = '\0'; + *(uint8_t *)&str->bytes[len] = '\0'; AWS_RETURN_WITH_POSTCONDITION(str, aws_string_is_valid(str)); -} - -struct aws_string *aws_string_new_from_string(struct aws_allocator *allocator, const struct aws_string *str) { +} + +struct aws_string *aws_string_new_from_string(struct aws_allocator *allocator, const struct aws_string *str) { AWS_PRECONDITION(allocator && aws_string_is_valid(str)); - return aws_string_new_from_array(allocator, str->bytes, str->len); -} - + return aws_string_new_from_array(allocator, str->bytes, str->len); +} + struct aws_string *aws_string_new_from_cursor(struct aws_allocator *allocator, const struct aws_byte_cursor *cursor) { AWS_PRECONDITION(allocator && aws_byte_cursor_is_valid(cursor)); return aws_string_new_from_array(allocator, cursor->ptr, cursor->len); @@ -46,24 +46,24 @@ struct aws_string *aws_string_new_from_buf(struct aws_allocator *allocator, cons return aws_string_new_from_array(allocator, buf->buffer, buf->len); } -void aws_string_destroy(struct aws_string *str) { +void aws_string_destroy(struct aws_string *str) { AWS_PRECONDITION(!str || aws_string_is_valid(str)); - if (str && str->allocator) { - aws_mem_release(str->allocator, str); - } -} - -void aws_string_destroy_secure(struct aws_string *str) { + if (str && str->allocator) { + aws_mem_release(str->allocator, str); + } +} + +void aws_string_destroy_secure(struct aws_string *str) { AWS_PRECONDITION(!str || aws_string_is_valid(str)); - if (str) { - aws_secure_zero((void *)aws_string_bytes(str), str->len); - if (str->allocator) { - aws_mem_release(str->allocator, str); - } - } -} - -int aws_string_compare(const struct aws_string *a, const struct aws_string *b) { + if (str) { + aws_secure_zero((void *)aws_string_bytes(str), str->len); + if (str->allocator) { + aws_mem_release(str->allocator, str); + } + } +} + +int aws_string_compare(const struct aws_string *a, const struct aws_string *b) { AWS_PRECONDITION(!a || aws_string_is_valid(a)); AWS_PRECONDITION(!b || aws_string_is_valid(b)); if (a == b) { @@ -76,26 +76,26 @@ int aws_string_compare(const struct aws_string *a, const struct aws_string *b) { return 1; } - size_t len_a = a->len; - size_t len_b = b->len; - size_t min_len = len_a < len_b ? len_a : len_b; - - int ret = memcmp(aws_string_bytes(a), aws_string_bytes(b), min_len); + size_t len_a = a->len; + size_t len_b = b->len; + size_t min_len = len_a < len_b ? len_a : len_b; + + int ret = memcmp(aws_string_bytes(a), aws_string_bytes(b), min_len); AWS_POSTCONDITION(aws_string_is_valid(a)); AWS_POSTCONDITION(aws_string_is_valid(b)); - if (ret) { - return ret; /* overlapping characters differ */ - } - if (len_a == len_b) { - return 0; /* strings identical */ - } - if (len_a > len_b) { - return 1; /* string b is first n characters of string a */ - } - return -1; /* string a is first n characters of string b */ -} - -int aws_array_list_comparator_string(const void *a, const void *b) { + if (ret) { + return ret; /* overlapping characters differ */ + } + if (len_a == len_b) { + return 0; /* strings identical */ + } + if (len_a > len_b) { + return 1; /* string b is first n characters of string a */ + } + return -1; /* string a is first n characters of string b */ +} + +int aws_array_list_comparator_string(const void *a, const void *b) { if (a == b) { return 0; /* strings identical */ } @@ -105,10 +105,10 @@ int aws_array_list_comparator_string(const void *a, const void *b) { if (b == NULL) { return 1; } - const struct aws_string *str_a = *(const struct aws_string **)a; - const struct aws_string *str_b = *(const struct aws_string **)b; - return aws_string_compare(str_a, str_b); -} + const struct aws_string *str_a = *(const struct aws_string **)a; + const struct aws_string *str_b = *(const struct aws_string **)b; + return aws_string_compare(str_a, str_b); +} /** * Returns true if bytes of string are the same, false otherwise. diff --git a/contrib/restricted/aws/aws-c-common/source/task_scheduler.c b/contrib/restricted/aws/aws-c-common/source/task_scheduler.c index 66793d71bd..31ce7af1ab 100644 --- a/contrib/restricted/aws/aws-c-common/source/task_scheduler.c +++ b/contrib/restricted/aws/aws-c-common/source/task_scheduler.c @@ -1,16 +1,16 @@ /** * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. - */ - -#include <aws/common/task_scheduler.h> - + */ + +#include <aws/common/task_scheduler.h> + #include <aws/common/logging.h> #include <inttypes.h> -static const size_t DEFAULT_QUEUE_SIZE = 7; - +static const size_t DEFAULT_QUEUE_SIZE = 7; + void aws_task_init(struct aws_task *task, aws_task_fn *fn, void *arg, const char *type_tag) { AWS_ZERO_STRUCT(*task); task->fn = fn; @@ -43,17 +43,17 @@ void aws_task_run(struct aws_task *task, enum aws_task_status status) { task->fn(task, task->arg, status); } -static int s_compare_timestamps(const void *a, const void *b) { - uint64_t a_time = (*(struct aws_task **)a)->timestamp; - uint64_t b_time = (*(struct aws_task **)b)->timestamp; - return a_time > b_time; /* min-heap */ -} - -static void s_run_all(struct aws_task_scheduler *scheduler, uint64_t current_time, enum aws_task_status status); - -int aws_task_scheduler_init(struct aws_task_scheduler *scheduler, struct aws_allocator *alloc) { - AWS_ASSERT(alloc); - +static int s_compare_timestamps(const void *a, const void *b) { + uint64_t a_time = (*(struct aws_task **)a)->timestamp; + uint64_t b_time = (*(struct aws_task **)b)->timestamp; + return a_time > b_time; /* min-heap */ +} + +static void s_run_all(struct aws_task_scheduler *scheduler, uint64_t current_time, enum aws_task_status status); + +int aws_task_scheduler_init(struct aws_task_scheduler *scheduler, struct aws_allocator *alloc) { + AWS_ASSERT(alloc); + AWS_ZERO_STRUCT(*scheduler); if (aws_priority_queue_init_dynamic( @@ -61,95 +61,95 @@ int aws_task_scheduler_init(struct aws_task_scheduler *scheduler, struct aws_all return AWS_OP_ERR; }; - scheduler->alloc = alloc; - aws_linked_list_init(&scheduler->timed_list); - aws_linked_list_init(&scheduler->asap_list); + scheduler->alloc = alloc; + aws_linked_list_init(&scheduler->timed_list); + aws_linked_list_init(&scheduler->asap_list); AWS_POSTCONDITION(aws_task_scheduler_is_valid(scheduler)); return AWS_OP_SUCCESS; -} - -void aws_task_scheduler_clean_up(struct aws_task_scheduler *scheduler) { - AWS_ASSERT(scheduler); - +} + +void aws_task_scheduler_clean_up(struct aws_task_scheduler *scheduler) { + AWS_ASSERT(scheduler); + if (aws_task_scheduler_is_valid(scheduler)) { /* Execute all remaining tasks as CANCELED. * Do this in a loop so that tasks scheduled by other tasks are executed */ while (aws_task_scheduler_has_tasks(scheduler, NULL)) { s_run_all(scheduler, UINT64_MAX, AWS_TASK_STATUS_CANCELED); } - } - - aws_priority_queue_clean_up(&scheduler->timed_queue); + } + + aws_priority_queue_clean_up(&scheduler->timed_queue); AWS_ZERO_STRUCT(*scheduler); -} - +} + bool aws_task_scheduler_is_valid(const struct aws_task_scheduler *scheduler) { return scheduler && scheduler->alloc && aws_priority_queue_is_valid(&scheduler->timed_queue) && aws_linked_list_is_valid(&scheduler->asap_list) && aws_linked_list_is_valid(&scheduler->timed_list); } -bool aws_task_scheduler_has_tasks(const struct aws_task_scheduler *scheduler, uint64_t *next_task_time) { - AWS_ASSERT(scheduler); - - uint64_t timestamp = UINT64_MAX; - bool has_tasks = false; - - if (!aws_linked_list_empty(&scheduler->asap_list)) { - timestamp = 0; - has_tasks = true; - - } else { - /* Check whether timed_list or timed_queue has the earlier task */ - if (AWS_UNLIKELY(!aws_linked_list_empty(&scheduler->timed_list))) { - struct aws_linked_list_node *node = aws_linked_list_front(&scheduler->timed_list); - struct aws_task *task = AWS_CONTAINER_OF(node, struct aws_task, node); - timestamp = task->timestamp; - has_tasks = true; - } - - struct aws_task **task_ptrptr = NULL; - if (aws_priority_queue_top(&scheduler->timed_queue, (void **)&task_ptrptr) == AWS_OP_SUCCESS) { - if ((*task_ptrptr)->timestamp < timestamp) { - timestamp = (*task_ptrptr)->timestamp; - } - has_tasks = true; - } - } - - if (next_task_time) { - *next_task_time = timestamp; - } - return has_tasks; -} - -void aws_task_scheduler_schedule_now(struct aws_task_scheduler *scheduler, struct aws_task *task) { - AWS_ASSERT(scheduler); - AWS_ASSERT(task); - AWS_ASSERT(task->fn); - +bool aws_task_scheduler_has_tasks(const struct aws_task_scheduler *scheduler, uint64_t *next_task_time) { + AWS_ASSERT(scheduler); + + uint64_t timestamp = UINT64_MAX; + bool has_tasks = false; + + if (!aws_linked_list_empty(&scheduler->asap_list)) { + timestamp = 0; + has_tasks = true; + + } else { + /* Check whether timed_list or timed_queue has the earlier task */ + if (AWS_UNLIKELY(!aws_linked_list_empty(&scheduler->timed_list))) { + struct aws_linked_list_node *node = aws_linked_list_front(&scheduler->timed_list); + struct aws_task *task = AWS_CONTAINER_OF(node, struct aws_task, node); + timestamp = task->timestamp; + has_tasks = true; + } + + struct aws_task **task_ptrptr = NULL; + if (aws_priority_queue_top(&scheduler->timed_queue, (void **)&task_ptrptr) == AWS_OP_SUCCESS) { + if ((*task_ptrptr)->timestamp < timestamp) { + timestamp = (*task_ptrptr)->timestamp; + } + has_tasks = true; + } + } + + if (next_task_time) { + *next_task_time = timestamp; + } + return has_tasks; +} + +void aws_task_scheduler_schedule_now(struct aws_task_scheduler *scheduler, struct aws_task *task) { + AWS_ASSERT(scheduler); + AWS_ASSERT(task); + AWS_ASSERT(task->fn); + AWS_LOGF_DEBUG( AWS_LS_COMMON_TASK_SCHEDULER, "id=%p: Scheduling %s task for immediate execution", (void *)task, task->type_tag); - task->priority_queue_node.current_index = SIZE_MAX; - aws_linked_list_node_reset(&task->node); - task->timestamp = 0; - - aws_linked_list_push_back(&scheduler->asap_list, &task->node); -} - -void aws_task_scheduler_schedule_future( - struct aws_task_scheduler *scheduler, - struct aws_task *task, - uint64_t time_to_run) { - - AWS_ASSERT(scheduler); - AWS_ASSERT(task); - AWS_ASSERT(task->fn); - + task->priority_queue_node.current_index = SIZE_MAX; + aws_linked_list_node_reset(&task->node); + task->timestamp = 0; + + aws_linked_list_push_back(&scheduler->asap_list, &task->node); +} + +void aws_task_scheduler_schedule_future( + struct aws_task_scheduler *scheduler, + struct aws_task *task, + uint64_t time_to_run) { + + AWS_ASSERT(scheduler); + AWS_ASSERT(task); + AWS_ASSERT(task->fn); + AWS_LOGF_DEBUG( AWS_LS_COMMON_TASK_SCHEDULER, "id=%p: Scheduling %s task for future execution at time %" PRIu64, @@ -157,108 +157,108 @@ void aws_task_scheduler_schedule_future( task->type_tag, time_to_run); - task->timestamp = time_to_run; - - task->priority_queue_node.current_index = SIZE_MAX; - aws_linked_list_node_reset(&task->node); - int err = aws_priority_queue_push_ref(&scheduler->timed_queue, &task, &task->priority_queue_node); - if (AWS_UNLIKELY(err)) { - /* In the (very unlikely) case that we can't push into the timed_queue, - * perform a sorted insertion into timed_list. */ - struct aws_linked_list_node *node_i; - for (node_i = aws_linked_list_begin(&scheduler->timed_list); - node_i != aws_linked_list_end(&scheduler->timed_list); - node_i = aws_linked_list_next(node_i)) { - - struct aws_task *task_i = AWS_CONTAINER_OF(node_i, struct aws_task, node); - if (task_i->timestamp > time_to_run) { - break; - } - } - aws_linked_list_insert_before(node_i, &task->node); - } -} - -void aws_task_scheduler_run_all(struct aws_task_scheduler *scheduler, uint64_t current_time) { - AWS_ASSERT(scheduler); - - s_run_all(scheduler, current_time, AWS_TASK_STATUS_RUN_READY); -} - -static void s_run_all(struct aws_task_scheduler *scheduler, uint64_t current_time, enum aws_task_status status) { - - /* Move scheduled tasks to running_list before executing. - * This gives us the desired behavior that: if executing a task results in another task being scheduled, - * that new task is not executed until the next time run() is invoked. */ - struct aws_linked_list running_list; - aws_linked_list_init(&running_list); - - /* First move everything from asap_list */ - aws_linked_list_swap_contents(&running_list, &scheduler->asap_list); - - /* Next move tasks from timed_queue and timed_list, based on whichever's next-task is sooner. - * It's very unlikely that any tasks are in timed_list, so once it has no more valid tasks, - * break out of this complex loop in favor of a simpler one. */ - while (AWS_UNLIKELY(!aws_linked_list_empty(&scheduler->timed_list))) { - - struct aws_linked_list_node *timed_list_node = aws_linked_list_begin(&scheduler->timed_list); - struct aws_task *timed_list_task = AWS_CONTAINER_OF(timed_list_node, struct aws_task, node); - if (timed_list_task->timestamp > current_time) { - /* timed_list is out of valid tasks, break out of complex loop */ - break; - } - - /* Check if timed_queue has a task which is sooner */ - struct aws_task **timed_queue_task_ptrptr = NULL; - if (aws_priority_queue_top(&scheduler->timed_queue, (void **)&timed_queue_task_ptrptr) == AWS_OP_SUCCESS) { - if ((*timed_queue_task_ptrptr)->timestamp <= current_time) { - if ((*timed_queue_task_ptrptr)->timestamp < timed_list_task->timestamp) { - /* Take task from timed_queue */ - struct aws_task *timed_queue_task; - aws_priority_queue_pop(&scheduler->timed_queue, &timed_queue_task); - aws_linked_list_push_back(&running_list, &timed_queue_task->node); - continue; - } - } - } - - /* Take task from timed_list */ - aws_linked_list_pop_front(&scheduler->timed_list); - aws_linked_list_push_back(&running_list, &timed_list_task->node); - } - - /* Simpler loop that moves remaining valid tasks from timed_queue */ - struct aws_task **timed_queue_task_ptrptr = NULL; - while (aws_priority_queue_top(&scheduler->timed_queue, (void **)&timed_queue_task_ptrptr) == AWS_OP_SUCCESS) { - if ((*timed_queue_task_ptrptr)->timestamp > current_time) { - break; - } - - struct aws_task *next_timed_task; - aws_priority_queue_pop(&scheduler->timed_queue, &next_timed_task); - aws_linked_list_push_back(&running_list, &next_timed_task->node); - } - - /* Run tasks */ - while (!aws_linked_list_empty(&running_list)) { - struct aws_linked_list_node *task_node = aws_linked_list_pop_front(&running_list); - struct aws_task *task = AWS_CONTAINER_OF(task_node, struct aws_task, node); - aws_task_run(task, status); - } -} - -void aws_task_scheduler_cancel_task(struct aws_task_scheduler *scheduler, struct aws_task *task) { - /* attempt the linked lists first since those will be faster access and more likely to occur - * anyways. - */ - if (task->node.next) { - aws_linked_list_remove(&task->node); - } else { - aws_priority_queue_remove(&scheduler->timed_queue, &task, &task->priority_queue_node); - } + task->timestamp = time_to_run; + + task->priority_queue_node.current_index = SIZE_MAX; + aws_linked_list_node_reset(&task->node); + int err = aws_priority_queue_push_ref(&scheduler->timed_queue, &task, &task->priority_queue_node); + if (AWS_UNLIKELY(err)) { + /* In the (very unlikely) case that we can't push into the timed_queue, + * perform a sorted insertion into timed_list. */ + struct aws_linked_list_node *node_i; + for (node_i = aws_linked_list_begin(&scheduler->timed_list); + node_i != aws_linked_list_end(&scheduler->timed_list); + node_i = aws_linked_list_next(node_i)) { + + struct aws_task *task_i = AWS_CONTAINER_OF(node_i, struct aws_task, node); + if (task_i->timestamp > time_to_run) { + break; + } + } + aws_linked_list_insert_before(node_i, &task->node); + } +} + +void aws_task_scheduler_run_all(struct aws_task_scheduler *scheduler, uint64_t current_time) { + AWS_ASSERT(scheduler); + + s_run_all(scheduler, current_time, AWS_TASK_STATUS_RUN_READY); +} + +static void s_run_all(struct aws_task_scheduler *scheduler, uint64_t current_time, enum aws_task_status status) { + + /* Move scheduled tasks to running_list before executing. + * This gives us the desired behavior that: if executing a task results in another task being scheduled, + * that new task is not executed until the next time run() is invoked. */ + struct aws_linked_list running_list; + aws_linked_list_init(&running_list); + + /* First move everything from asap_list */ + aws_linked_list_swap_contents(&running_list, &scheduler->asap_list); + + /* Next move tasks from timed_queue and timed_list, based on whichever's next-task is sooner. + * It's very unlikely that any tasks are in timed_list, so once it has no more valid tasks, + * break out of this complex loop in favor of a simpler one. */ + while (AWS_UNLIKELY(!aws_linked_list_empty(&scheduler->timed_list))) { + + struct aws_linked_list_node *timed_list_node = aws_linked_list_begin(&scheduler->timed_list); + struct aws_task *timed_list_task = AWS_CONTAINER_OF(timed_list_node, struct aws_task, node); + if (timed_list_task->timestamp > current_time) { + /* timed_list is out of valid tasks, break out of complex loop */ + break; + } + + /* Check if timed_queue has a task which is sooner */ + struct aws_task **timed_queue_task_ptrptr = NULL; + if (aws_priority_queue_top(&scheduler->timed_queue, (void **)&timed_queue_task_ptrptr) == AWS_OP_SUCCESS) { + if ((*timed_queue_task_ptrptr)->timestamp <= current_time) { + if ((*timed_queue_task_ptrptr)->timestamp < timed_list_task->timestamp) { + /* Take task from timed_queue */ + struct aws_task *timed_queue_task; + aws_priority_queue_pop(&scheduler->timed_queue, &timed_queue_task); + aws_linked_list_push_back(&running_list, &timed_queue_task->node); + continue; + } + } + } + + /* Take task from timed_list */ + aws_linked_list_pop_front(&scheduler->timed_list); + aws_linked_list_push_back(&running_list, &timed_list_task->node); + } + + /* Simpler loop that moves remaining valid tasks from timed_queue */ + struct aws_task **timed_queue_task_ptrptr = NULL; + while (aws_priority_queue_top(&scheduler->timed_queue, (void **)&timed_queue_task_ptrptr) == AWS_OP_SUCCESS) { + if ((*timed_queue_task_ptrptr)->timestamp > current_time) { + break; + } + + struct aws_task *next_timed_task; + aws_priority_queue_pop(&scheduler->timed_queue, &next_timed_task); + aws_linked_list_push_back(&running_list, &next_timed_task->node); + } + + /* Run tasks */ + while (!aws_linked_list_empty(&running_list)) { + struct aws_linked_list_node *task_node = aws_linked_list_pop_front(&running_list); + struct aws_task *task = AWS_CONTAINER_OF(task_node, struct aws_task, node); + aws_task_run(task, status); + } +} + +void aws_task_scheduler_cancel_task(struct aws_task_scheduler *scheduler, struct aws_task *task) { + /* attempt the linked lists first since those will be faster access and more likely to occur + * anyways. + */ + if (task->node.next) { + aws_linked_list_remove(&task->node); + } else { + aws_priority_queue_remove(&scheduler->timed_queue, &task, &task->priority_queue_node); + } /* * No need to log cancellation specially; it will get logged during the run call with the canceled status */ - aws_task_run(task, AWS_TASK_STATUS_CANCELED); -} + aws_task_run(task, AWS_TASK_STATUS_CANCELED); +} diff --git a/contrib/restricted/aws/aws-c-common/source/uuid.c b/contrib/restricted/aws/aws-c-common/source/uuid.c index 3cf681ed62..a962abd653 100644 --- a/contrib/restricted/aws/aws-c-common/source/uuid.c +++ b/contrib/restricted/aws/aws-c-common/source/uuid.c @@ -1,99 +1,99 @@ /** * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. - */ -#include <aws/common/uuid.h> - -#include <aws/common/byte_buf.h> -#include <aws/common/device_random.h> - -#include <inttypes.h> -#include <stdio.h> - -#define HEX_CHAR_FMT "%02" SCNx8 - -#define UUID_FORMAT \ - HEX_CHAR_FMT HEX_CHAR_FMT HEX_CHAR_FMT HEX_CHAR_FMT \ - "-" HEX_CHAR_FMT HEX_CHAR_FMT "-" HEX_CHAR_FMT HEX_CHAR_FMT "-" HEX_CHAR_FMT HEX_CHAR_FMT \ - "-" HEX_CHAR_FMT HEX_CHAR_FMT HEX_CHAR_FMT HEX_CHAR_FMT HEX_CHAR_FMT HEX_CHAR_FMT - -#include <stdio.h> - -#ifdef _MSC_VER -/* disables warning non const declared initializers for Microsoft compilers */ -# pragma warning(disable : 4204) -# pragma warning(disable : 4706) -/* sprintf warning (we already check the bounds in this case). */ -# pragma warning(disable : 4996) -#endif - -int aws_uuid_init(struct aws_uuid *uuid) { - struct aws_byte_buf buf = aws_byte_buf_from_empty_array(uuid->uuid_data, sizeof(uuid->uuid_data)); - - return aws_device_random_buffer(&buf); -} - -int aws_uuid_init_from_str(struct aws_uuid *uuid, const struct aws_byte_cursor *uuid_str) { + */ +#include <aws/common/uuid.h> + +#include <aws/common/byte_buf.h> +#include <aws/common/device_random.h> + +#include <inttypes.h> +#include <stdio.h> + +#define HEX_CHAR_FMT "%02" SCNx8 + +#define UUID_FORMAT \ + HEX_CHAR_FMT HEX_CHAR_FMT HEX_CHAR_FMT HEX_CHAR_FMT \ + "-" HEX_CHAR_FMT HEX_CHAR_FMT "-" HEX_CHAR_FMT HEX_CHAR_FMT "-" HEX_CHAR_FMT HEX_CHAR_FMT \ + "-" HEX_CHAR_FMT HEX_CHAR_FMT HEX_CHAR_FMT HEX_CHAR_FMT HEX_CHAR_FMT HEX_CHAR_FMT + +#include <stdio.h> + +#ifdef _MSC_VER +/* disables warning non const declared initializers for Microsoft compilers */ +# pragma warning(disable : 4204) +# pragma warning(disable : 4706) +/* sprintf warning (we already check the bounds in this case). */ +# pragma warning(disable : 4996) +#endif + +int aws_uuid_init(struct aws_uuid *uuid) { + struct aws_byte_buf buf = aws_byte_buf_from_empty_array(uuid->uuid_data, sizeof(uuid->uuid_data)); + + return aws_device_random_buffer(&buf); +} + +int aws_uuid_init_from_str(struct aws_uuid *uuid, const struct aws_byte_cursor *uuid_str) { AWS_ERROR_PRECONDITION(uuid_str->len >= AWS_UUID_STR_LEN - 1, AWS_ERROR_INVALID_BUFFER_SIZE); - - char cpy[AWS_UUID_STR_LEN] = {0}; - memcpy(cpy, uuid_str->ptr, AWS_UUID_STR_LEN - 1); - - AWS_ZERO_STRUCT(*uuid); - - if (16 != sscanf( - cpy, - UUID_FORMAT, - &uuid->uuid_data[0], - &uuid->uuid_data[1], - &uuid->uuid_data[2], - &uuid->uuid_data[3], - &uuid->uuid_data[4], - &uuid->uuid_data[5], - &uuid->uuid_data[6], - &uuid->uuid_data[7], - &uuid->uuid_data[8], - &uuid->uuid_data[9], - &uuid->uuid_data[10], - &uuid->uuid_data[11], - &uuid->uuid_data[12], - &uuid->uuid_data[13], - &uuid->uuid_data[14], - &uuid->uuid_data[15])) { - return aws_raise_error(AWS_ERROR_MALFORMED_INPUT_STRING); - } - - return AWS_OP_SUCCESS; -} - -int aws_uuid_to_str(const struct aws_uuid *uuid, struct aws_byte_buf *output) { + + char cpy[AWS_UUID_STR_LEN] = {0}; + memcpy(cpy, uuid_str->ptr, AWS_UUID_STR_LEN - 1); + + AWS_ZERO_STRUCT(*uuid); + + if (16 != sscanf( + cpy, + UUID_FORMAT, + &uuid->uuid_data[0], + &uuid->uuid_data[1], + &uuid->uuid_data[2], + &uuid->uuid_data[3], + &uuid->uuid_data[4], + &uuid->uuid_data[5], + &uuid->uuid_data[6], + &uuid->uuid_data[7], + &uuid->uuid_data[8], + &uuid->uuid_data[9], + &uuid->uuid_data[10], + &uuid->uuid_data[11], + &uuid->uuid_data[12], + &uuid->uuid_data[13], + &uuid->uuid_data[14], + &uuid->uuid_data[15])) { + return aws_raise_error(AWS_ERROR_MALFORMED_INPUT_STRING); + } + + return AWS_OP_SUCCESS; +} + +int aws_uuid_to_str(const struct aws_uuid *uuid, struct aws_byte_buf *output) { AWS_ERROR_PRECONDITION(output->capacity - output->len >= AWS_UUID_STR_LEN, AWS_ERROR_SHORT_BUFFER); - - sprintf( - (char *)(output->buffer + output->len), - UUID_FORMAT, - uuid->uuid_data[0], - uuid->uuid_data[1], - uuid->uuid_data[2], - uuid->uuid_data[3], - uuid->uuid_data[4], - uuid->uuid_data[5], - uuid->uuid_data[6], - uuid->uuid_data[7], - uuid->uuid_data[8], - uuid->uuid_data[9], - uuid->uuid_data[10], - uuid->uuid_data[11], - uuid->uuid_data[12], - uuid->uuid_data[13], - uuid->uuid_data[14], - uuid->uuid_data[15]); - - output->len += AWS_UUID_STR_LEN - 1; - - return AWS_OP_SUCCESS; -} - -bool aws_uuid_equals(const struct aws_uuid *a, const struct aws_uuid *b) { - return 0 == memcmp(a->uuid_data, b->uuid_data, sizeof(a->uuid_data)); -} + + sprintf( + (char *)(output->buffer + output->len), + UUID_FORMAT, + uuid->uuid_data[0], + uuid->uuid_data[1], + uuid->uuid_data[2], + uuid->uuid_data[3], + uuid->uuid_data[4], + uuid->uuid_data[5], + uuid->uuid_data[6], + uuid->uuid_data[7], + uuid->uuid_data[8], + uuid->uuid_data[9], + uuid->uuid_data[10], + uuid->uuid_data[11], + uuid->uuid_data[12], + uuid->uuid_data[13], + uuid->uuid_data[14], + uuid->uuid_data[15]); + + output->len += AWS_UUID_STR_LEN - 1; + + return AWS_OP_SUCCESS; +} + +bool aws_uuid_equals(const struct aws_uuid *a, const struct aws_uuid *b) { + return 0 == memcmp(a->uuid_data, b->uuid_data, sizeof(a->uuid_data)); +} diff --git a/contrib/restricted/aws/aws-c-common/ya.make b/contrib/restricted/aws/aws-c-common/ya.make index ecdd568d4b..e2f9e4113b 100644 --- a/contrib/restricted/aws/aws-c-common/ya.make +++ b/contrib/restricted/aws/aws-c-common/ya.make @@ -1,13 +1,13 @@ # Generated by devtools/yamaker from nixpkgs 980c4c3c2f664ccc5002f7fd6e08059cf1f00e75. - -LIBRARY() - + +LIBRARY() + OWNER(g:cpp-contrib) - + VERSION(0.4.63) - + ORIGINAL_SOURCE(https://github.com/awslabs/aws-c-common/archive/v0.4.63.tar.gz) - + LICENSE( Apache-2.0 AND BSD-3-Clause AND @@ -16,15 +16,15 @@ LICENSE( LICENSE_TEXTS(.yandex_meta/licenses.list.txt) -ADDINCL( +ADDINCL( GLOBAL contrib/restricted/aws/aws-c-common/generated/include GLOBAL contrib/restricted/aws/aws-c-common/include -) - -NO_COMPILER_WARNINGS() - +) + +NO_COMPILER_WARNINGS() + NO_RUNTIME() - + IF (OS_DARWIN) LDFLAGS( -framework @@ -32,54 +32,54 @@ IF (OS_DARWIN) ) ENDIF() -SRCS( +SRCS( source/allocator.c source/allocator_sba.c - source/array_list.c - source/assert.c - source/byte_buf.c + source/array_list.c + source/assert.c + source/byte_buf.c source/cache.c - source/codegen.c - source/command_line_parser.c - source/common.c - source/condition_variable.c - source/date_time.c - source/device_random.c - source/encoding.c - source/error.c + source/codegen.c + source/command_line_parser.c + source/common.c + source/condition_variable.c + source/date_time.c + source/device_random.c + source/encoding.c + source/error.c source/fifo_cache.c - source/hash_table.c + source/hash_table.c source/lifo_cache.c source/linked_hash_table.c source/log_channel.c source/log_formatter.c source/log_writer.c source/logging.c - source/lru_cache.c + source/lru_cache.c source/math.c source/memtrace.c - source/posix/clock.c - source/posix/condition_variable.c - source/posix/device_random.c - source/posix/environment.c - source/posix/mutex.c + source/posix/clock.c + source/posix/condition_variable.c + source/posix/device_random.c + source/posix/environment.c + source/posix/mutex.c source/posix/process.c - source/posix/rw_lock.c - source/posix/system_info.c - source/posix/thread.c - source/posix/time.c - source/priority_queue.c + source/posix/rw_lock.c + source/posix/system_info.c + source/posix/thread.c + source/posix/time.c + source/priority_queue.c source/process_common.c source/ref_count.c source/resource_name.c source/ring_buffer.c source/statistics.c - source/string.c - source/task_scheduler.c - source/uuid.c + source/string.c + source/task_scheduler.c + source/uuid.c source/xml_parser.c -) - +) + IF (ARCH_ARM) SRCS( source/arch/arm/asm/cpuid.c @@ -91,4 +91,4 @@ ELSEIF (ARCH_X86_64) ) ENDIF() -END() +END() diff --git a/contrib/restricted/aws/aws-c-event-stream/LICENSE b/contrib/restricted/aws/aws-c-event-stream/LICENSE index c0fd617439..d645695673 100644 --- a/contrib/restricted/aws/aws-c-event-stream/LICENSE +++ b/contrib/restricted/aws/aws-c-event-stream/LICENSE @@ -1,202 +1,202 @@ - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/contrib/restricted/aws/aws-c-event-stream/README.md b/contrib/restricted/aws/aws-c-event-stream/README.md index b55cfca367..1ee0142ea8 100644 --- a/contrib/restricted/aws/aws-c-event-stream/README.md +++ b/contrib/restricted/aws/aws-c-event-stream/README.md @@ -1,9 +1,9 @@ -## AWS C Event Stream - -C99 implementation of the vnd.amazon.event-stream content-type. - -## License - +## AWS C Event Stream + +C99 implementation of the vnd.amazon.event-stream content-type. + +## License + This library is licensed under the Apache 2.0 License. ## Usage diff --git a/contrib/restricted/aws/aws-c-event-stream/include/aws/event-stream/event_stream.h b/contrib/restricted/aws/aws-c-event-stream/include/aws/event-stream/event_stream.h index b20813464a..41302db9a1 100644 --- a/contrib/restricted/aws/aws-c-event-stream/include/aws/event-stream/event_stream.h +++ b/contrib/restricted/aws/aws-c-event-stream/include/aws/event-stream/event_stream.h @@ -1,18 +1,18 @@ -#ifndef AWS_EVENT_STREAM_H_ -#define AWS_EVENT_STREAM_H_ - +#ifndef AWS_EVENT_STREAM_H_ +#define AWS_EVENT_STREAM_H_ + /** * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. - */ - -#include <aws/common/array_list.h> -#include <aws/common/byte_buf.h> + */ + +#include <aws/common/array_list.h> +#include <aws/common/byte_buf.h> #include <aws/common/logging.h> -#include <aws/event-stream/event_stream_exports.h> - -#include <stdio.h> - +#include <aws/event-stream/event_stream_exports.h> + +#include <stdio.h> + #define AWS_C_EVENT_STREAM_PACKAGE_ID 4 /* max message size is 16MB */ #define AWS_EVENT_STREAM_MAX_MESSAGE_SIZE (16 * 1024 * 1024) @@ -20,23 +20,23 @@ /* max header size is 128kb */ #define AWS_EVENT_STREAM_MAX_HEADERS_SIZE (128 * 1024) -enum aws_event_stream_errors { +enum aws_event_stream_errors { AWS_ERROR_EVENT_STREAM_BUFFER_LENGTH_MISMATCH = AWS_ERROR_ENUM_BEGIN_RANGE(AWS_C_EVENT_STREAM_PACKAGE_ID), - AWS_ERROR_EVENT_STREAM_INSUFFICIENT_BUFFER_LEN, - AWS_ERROR_EVENT_STREAM_MESSAGE_FIELD_SIZE_EXCEEDED, - AWS_ERROR_EVENT_STREAM_PRELUDE_CHECKSUM_FAILURE, - AWS_ERROR_EVENT_STREAM_MESSAGE_CHECKSUM_FAILURE, - AWS_ERROR_EVENT_STREAM_MESSAGE_INVALID_HEADERS_LEN, - AWS_ERROR_EVENT_STREAM_MESSAGE_UNKNOWN_HEADER_TYPE, - AWS_ERROR_EVENT_STREAM_MESSAGE_PARSER_ILLEGAL_STATE, + AWS_ERROR_EVENT_STREAM_INSUFFICIENT_BUFFER_LEN, + AWS_ERROR_EVENT_STREAM_MESSAGE_FIELD_SIZE_EXCEEDED, + AWS_ERROR_EVENT_STREAM_PRELUDE_CHECKSUM_FAILURE, + AWS_ERROR_EVENT_STREAM_MESSAGE_CHECKSUM_FAILURE, + AWS_ERROR_EVENT_STREAM_MESSAGE_INVALID_HEADERS_LEN, + AWS_ERROR_EVENT_STREAM_MESSAGE_UNKNOWN_HEADER_TYPE, + AWS_ERROR_EVENT_STREAM_MESSAGE_PARSER_ILLEGAL_STATE, AWS_ERROR_EVENT_STREAM_RPC_CONNECTION_CLOSED, AWS_ERROR_EVENT_STREAM_RPC_PROTOCOL_ERROR, AWS_ERROR_EVENT_STREAM_RPC_STREAM_CLOSED, AWS_ERROR_EVENT_STREAM_RPC_STREAM_NOT_ACTIVATED, AWS_ERROR_EVENT_STREAM_END_RANGE = AWS_ERROR_ENUM_END_RANGE(AWS_C_EVENT_STREAM_PACKAGE_ID), -}; - +}; + enum aws_event_stream_log_subject { AWS_LS_EVENT_STREAM_GENERAL = AWS_LOG_SUBJECT_BEGIN_RANGE(AWS_C_EVENT_STREAM_PACKAGE_ID), AWS_LS_EVENT_STREAM_CHANNEL_HANDLER, @@ -46,201 +46,201 @@ enum aws_event_stream_log_subject { AWS_LS_EVENT_STREAM_LAST = AWS_LOG_SUBJECT_END_RANGE(AWS_C_EVENT_STREAM_PACKAGE_ID), }; -struct aws_event_stream_message_prelude { - uint32_t total_len; - uint32_t headers_len; - uint32_t prelude_crc; -}; - -struct aws_event_stream_message { - struct aws_allocator *alloc; - uint8_t *message_buffer; - uint8_t owns_buffer; -}; - -#define AWS_EVENT_STREAM_PRELUDE_LENGTH (uint32_t)(sizeof(uint32_t) + sizeof(uint32_t) + sizeof(uint32_t)) - -#define AWS_EVENT_STREAM_TRAILER_LENGTH (uint32_t)(sizeof(uint32_t)) - -enum aws_event_stream_header_value_type { - AWS_EVENT_STREAM_HEADER_BOOL_TRUE = 0, - AWS_EVENT_STREAM_HEADER_BOOL_FALSE, - AWS_EVENT_STREAM_HEADER_BYTE, - AWS_EVENT_STREAM_HEADER_INT16, - AWS_EVENT_STREAM_HEADER_INT32, - AWS_EVENT_STREAM_HEADER_INT64, - AWS_EVENT_STREAM_HEADER_BYTE_BUF, - AWS_EVENT_STREAM_HEADER_STRING, - /* 64 bit integer (millis since epoch) */ - AWS_EVENT_STREAM_HEADER_TIMESTAMP, - AWS_EVENT_STREAM_HEADER_UUID -}; - -struct aws_event_stream_header_value_pair { - uint8_t header_name_len; - char header_name[INT8_MAX]; - enum aws_event_stream_header_value_type header_value_type; - union { - uint8_t *variable_len_val; - uint8_t static_val[16]; - } header_value; - - uint16_t header_value_len; - int8_t value_owned; -}; - -struct aws_event_stream_streaming_decoder; -typedef int(aws_event_stream_process_state_fn)( - struct aws_event_stream_streaming_decoder *decoder, - const uint8_t *data, - size_t len, - size_t *processed); - -/** - * Called by aws_aws_event_stream_streaming_decoder when payload data has been received. - * 'data' doesn't belong to you, so copy the data if it is needed beyond the scope of your callback. - * final_segment == 1 indicates the current data is the last payload buffer for that message. - */ -typedef void(aws_event_stream_process_on_payload_segment_fn)( - struct aws_event_stream_streaming_decoder *decoder, - struct aws_byte_buf *payload, - int8_t final_segment, - void *user_data); - -/** - * Called by aws_aws_event_stream_streaming_decoder when a new message has arrived. The prelude will contain metadata - * about the message. At this point no headers or payload have been received. prelude is copyable. - */ -typedef void(aws_event_stream_prelude_received_fn)( - struct aws_event_stream_streaming_decoder *decoder, - struct aws_event_stream_message_prelude *prelude, - void *user_data); - -/** - * Called by aws_aws_event_stream_streaming_decoder when a header is encountered. 'header' is not yours. Copy the data - * you want from it if your scope extends beyond your callback. - */ -typedef void(aws_event_stream_header_received_fn)( - struct aws_event_stream_streaming_decoder *decoder, - struct aws_event_stream_message_prelude *prelude, - struct aws_event_stream_header_value_pair *header, - void *user_data); - -/** - * Called by aws_aws_event_stream_streaming_decoder when an error is encountered. The decoder is not in a good state for - * usage after this callback. - */ -typedef void(aws_event_stream_on_error_fn)( - struct aws_event_stream_streaming_decoder *decoder, - struct aws_event_stream_message_prelude *prelude, - int error_code, - const char *message, - void *user_data); - -struct aws_event_stream_streaming_decoder { - struct aws_allocator *alloc; - uint8_t working_buffer[AWS_EVENT_STREAM_PRELUDE_LENGTH]; - size_t message_pos; - uint32_t running_crc; - size_t current_header_name_offset; - size_t current_header_value_offset; - struct aws_event_stream_header_value_pair current_header; - struct aws_event_stream_message_prelude prelude; - aws_event_stream_process_state_fn *state; - aws_event_stream_process_on_payload_segment_fn *on_payload; - aws_event_stream_prelude_received_fn *on_prelude; - aws_event_stream_header_received_fn *on_header; - aws_event_stream_on_error_fn *on_error; - void *user_context; -}; - +struct aws_event_stream_message_prelude { + uint32_t total_len; + uint32_t headers_len; + uint32_t prelude_crc; +}; + +struct aws_event_stream_message { + struct aws_allocator *alloc; + uint8_t *message_buffer; + uint8_t owns_buffer; +}; + +#define AWS_EVENT_STREAM_PRELUDE_LENGTH (uint32_t)(sizeof(uint32_t) + sizeof(uint32_t) + sizeof(uint32_t)) + +#define AWS_EVENT_STREAM_TRAILER_LENGTH (uint32_t)(sizeof(uint32_t)) + +enum aws_event_stream_header_value_type { + AWS_EVENT_STREAM_HEADER_BOOL_TRUE = 0, + AWS_EVENT_STREAM_HEADER_BOOL_FALSE, + AWS_EVENT_STREAM_HEADER_BYTE, + AWS_EVENT_STREAM_HEADER_INT16, + AWS_EVENT_STREAM_HEADER_INT32, + AWS_EVENT_STREAM_HEADER_INT64, + AWS_EVENT_STREAM_HEADER_BYTE_BUF, + AWS_EVENT_STREAM_HEADER_STRING, + /* 64 bit integer (millis since epoch) */ + AWS_EVENT_STREAM_HEADER_TIMESTAMP, + AWS_EVENT_STREAM_HEADER_UUID +}; + +struct aws_event_stream_header_value_pair { + uint8_t header_name_len; + char header_name[INT8_MAX]; + enum aws_event_stream_header_value_type header_value_type; + union { + uint8_t *variable_len_val; + uint8_t static_val[16]; + } header_value; + + uint16_t header_value_len; + int8_t value_owned; +}; + +struct aws_event_stream_streaming_decoder; +typedef int(aws_event_stream_process_state_fn)( + struct aws_event_stream_streaming_decoder *decoder, + const uint8_t *data, + size_t len, + size_t *processed); + +/** + * Called by aws_aws_event_stream_streaming_decoder when payload data has been received. + * 'data' doesn't belong to you, so copy the data if it is needed beyond the scope of your callback. + * final_segment == 1 indicates the current data is the last payload buffer for that message. + */ +typedef void(aws_event_stream_process_on_payload_segment_fn)( + struct aws_event_stream_streaming_decoder *decoder, + struct aws_byte_buf *payload, + int8_t final_segment, + void *user_data); + +/** + * Called by aws_aws_event_stream_streaming_decoder when a new message has arrived. The prelude will contain metadata + * about the message. At this point no headers or payload have been received. prelude is copyable. + */ +typedef void(aws_event_stream_prelude_received_fn)( + struct aws_event_stream_streaming_decoder *decoder, + struct aws_event_stream_message_prelude *prelude, + void *user_data); + +/** + * Called by aws_aws_event_stream_streaming_decoder when a header is encountered. 'header' is not yours. Copy the data + * you want from it if your scope extends beyond your callback. + */ +typedef void(aws_event_stream_header_received_fn)( + struct aws_event_stream_streaming_decoder *decoder, + struct aws_event_stream_message_prelude *prelude, + struct aws_event_stream_header_value_pair *header, + void *user_data); + +/** + * Called by aws_aws_event_stream_streaming_decoder when an error is encountered. The decoder is not in a good state for + * usage after this callback. + */ +typedef void(aws_event_stream_on_error_fn)( + struct aws_event_stream_streaming_decoder *decoder, + struct aws_event_stream_message_prelude *prelude, + int error_code, + const char *message, + void *user_data); + +struct aws_event_stream_streaming_decoder { + struct aws_allocator *alloc; + uint8_t working_buffer[AWS_EVENT_STREAM_PRELUDE_LENGTH]; + size_t message_pos; + uint32_t running_crc; + size_t current_header_name_offset; + size_t current_header_value_offset; + struct aws_event_stream_header_value_pair current_header; + struct aws_event_stream_message_prelude prelude; + aws_event_stream_process_state_fn *state; + aws_event_stream_process_on_payload_segment_fn *on_payload; + aws_event_stream_prelude_received_fn *on_prelude; + aws_event_stream_header_received_fn *on_header; + aws_event_stream_on_error_fn *on_error; + void *user_context; +}; + AWS_EXTERN_C_BEGIN -/** - * Initializes with a list of headers, the payload, and a payload length. CRCs will be computed for you. - * If headers or payload is NULL, then the fields will be appropriately set to indicate no headers and/or no payload. - * Both payload and headers will result in an allocation. - */ -AWS_EVENT_STREAM_API int aws_event_stream_message_init( - struct aws_event_stream_message *message, - struct aws_allocator *alloc, - struct aws_array_list *headers, - struct aws_byte_buf *payload); - -/** - * Zero allocation, Zero copy. The message will simply wrap the buffer. The message functions are only useful as long as - * buffer is referencable memory. - */ -AWS_EVENT_STREAM_API int aws_event_stream_message_from_buffer( - struct aws_event_stream_message *message, - struct aws_allocator *alloc, - struct aws_byte_buf *buffer); - -/** - * Allocates memory and copies buffer. Otherwise the same as aws_aws_event_stream_message_from_buffer. This is slower, - * but possibly safer. - */ -AWS_EVENT_STREAM_API int aws_event_stream_message_from_buffer_copy( - struct aws_event_stream_message *message, - struct aws_allocator *alloc, - const struct aws_byte_buf *buffer); - -/** - * Cleans up any internally allocated memory. Always call this for API compatibility reasons, even if you only used the - * aws_aws_event_stream_message_from_buffer function. - */ -AWS_EVENT_STREAM_API void aws_event_stream_message_clean_up(struct aws_event_stream_message *message); - -/** - * Returns the total length of the message (including the length field). - */ -AWS_EVENT_STREAM_API uint32_t aws_event_stream_message_total_length(const struct aws_event_stream_message *message); - -/** - * Returns the length of the headers portion of the message. - */ -AWS_EVENT_STREAM_API uint32_t aws_event_stream_message_headers_len(const struct aws_event_stream_message *message); - -/** - * Returns the prelude crc (crc32) - */ -AWS_EVENT_STREAM_API uint32_t aws_event_stream_message_prelude_crc(const struct aws_event_stream_message *message); - -/** - * Writes the message to fd in json format. All strings and binary fields are base64 encoded. - */ -AWS_EVENT_STREAM_API int aws_event_stream_message_to_debug_str( - FILE *fd, - const struct aws_event_stream_message *message); - -/** - * Adds the headers for the message to list. The memory in each header is owned as part of the message, do not free it - * or pass its address around. - */ -AWS_EVENT_STREAM_API int aws_event_stream_message_headers( - const struct aws_event_stream_message *message, - struct aws_array_list *headers); - -/** - * Returns a pointer to the beginning of the message payload. - */ -AWS_EVENT_STREAM_API const uint8_t *aws_event_stream_message_payload(const struct aws_event_stream_message *message); - -/** - * Returns the length of the message payload. - */ -AWS_EVENT_STREAM_API uint32_t aws_event_stream_message_payload_len(const struct aws_event_stream_message *message); - -/** - * Returns the checksum of the entire message (crc32) - */ -AWS_EVENT_STREAM_API uint32_t aws_event_stream_message_message_crc(const struct aws_event_stream_message *message); - -/** - * Returns the message as a buffer ready for transport. - */ -AWS_EVENT_STREAM_API const uint8_t *aws_event_stream_message_buffer(const struct aws_event_stream_message *message); - +/** + * Initializes with a list of headers, the payload, and a payload length. CRCs will be computed for you. + * If headers or payload is NULL, then the fields will be appropriately set to indicate no headers and/or no payload. + * Both payload and headers will result in an allocation. + */ +AWS_EVENT_STREAM_API int aws_event_stream_message_init( + struct aws_event_stream_message *message, + struct aws_allocator *alloc, + struct aws_array_list *headers, + struct aws_byte_buf *payload); + +/** + * Zero allocation, Zero copy. The message will simply wrap the buffer. The message functions are only useful as long as + * buffer is referencable memory. + */ +AWS_EVENT_STREAM_API int aws_event_stream_message_from_buffer( + struct aws_event_stream_message *message, + struct aws_allocator *alloc, + struct aws_byte_buf *buffer); + +/** + * Allocates memory and copies buffer. Otherwise the same as aws_aws_event_stream_message_from_buffer. This is slower, + * but possibly safer. + */ +AWS_EVENT_STREAM_API int aws_event_stream_message_from_buffer_copy( + struct aws_event_stream_message *message, + struct aws_allocator *alloc, + const struct aws_byte_buf *buffer); + +/** + * Cleans up any internally allocated memory. Always call this for API compatibility reasons, even if you only used the + * aws_aws_event_stream_message_from_buffer function. + */ +AWS_EVENT_STREAM_API void aws_event_stream_message_clean_up(struct aws_event_stream_message *message); + +/** + * Returns the total length of the message (including the length field). + */ +AWS_EVENT_STREAM_API uint32_t aws_event_stream_message_total_length(const struct aws_event_stream_message *message); + +/** + * Returns the length of the headers portion of the message. + */ +AWS_EVENT_STREAM_API uint32_t aws_event_stream_message_headers_len(const struct aws_event_stream_message *message); + +/** + * Returns the prelude crc (crc32) + */ +AWS_EVENT_STREAM_API uint32_t aws_event_stream_message_prelude_crc(const struct aws_event_stream_message *message); + +/** + * Writes the message to fd in json format. All strings and binary fields are base64 encoded. + */ +AWS_EVENT_STREAM_API int aws_event_stream_message_to_debug_str( + FILE *fd, + const struct aws_event_stream_message *message); + +/** + * Adds the headers for the message to list. The memory in each header is owned as part of the message, do not free it + * or pass its address around. + */ +AWS_EVENT_STREAM_API int aws_event_stream_message_headers( + const struct aws_event_stream_message *message, + struct aws_array_list *headers); + +/** + * Returns a pointer to the beginning of the message payload. + */ +AWS_EVENT_STREAM_API const uint8_t *aws_event_stream_message_payload(const struct aws_event_stream_message *message); + +/** + * Returns the length of the message payload. + */ +AWS_EVENT_STREAM_API uint32_t aws_event_stream_message_payload_len(const struct aws_event_stream_message *message); + +/** + * Returns the checksum of the entire message (crc32) + */ +AWS_EVENT_STREAM_API uint32_t aws_event_stream_message_message_crc(const struct aws_event_stream_message *message); + +/** + * Returns the message as a buffer ready for transport. + */ +AWS_EVENT_STREAM_API const uint8_t *aws_event_stream_message_buffer(const struct aws_event_stream_message *message); + AWS_EVENT_STREAM_API uint32_t aws_event_stream_compute_headers_required_buffer_len(const struct aws_array_list *headers); @@ -256,49 +256,49 @@ AWS_EVENT_STREAM_API int aws_event_stream_read_headers_from_buffer( struct aws_array_list *headers, const uint8_t *buffer, size_t headers_len); -/** - * Initialize a streaming decoder for messages with callbacks for usage and an optional user context pointer. - */ -AWS_EVENT_STREAM_API void aws_event_stream_streaming_decoder_init( - struct aws_event_stream_streaming_decoder *decoder, - struct aws_allocator *alloc, - aws_event_stream_process_on_payload_segment_fn *on_payload_segment, - aws_event_stream_prelude_received_fn *on_prelude, - aws_event_stream_header_received_fn *on_header, - aws_event_stream_on_error_fn *on_error, - void *user_data); - -/** - * Currently, no memory is allocated inside aws_aws_event_stream_streaming_decoder, but for future API compatibility, - * you should call this when finished with it. - */ -AWS_EVENT_STREAM_API void aws_event_stream_streaming_decoder_clean_up( - struct aws_event_stream_streaming_decoder *decoder); - -/** - * initializes a headers list for you. It will default to a capacity of 4 in dynamic mode. - */ -AWS_EVENT_STREAM_API int aws_event_stream_headers_list_init( - struct aws_array_list *headers, - struct aws_allocator *allocator); - -/** - * Cleans up the headers list. Also deallocates any headers that were the result of a copy flag for strings or buffer. - */ -AWS_EVENT_STREAM_API void aws_event_stream_headers_list_cleanup(struct aws_array_list *headers); - -/** - * Adds a string header to the list of headers. If copy is set to true, this will result in an allocation for the header - * value. Otherwise, the value will be set to the memory address of 'value'. - */ -AWS_EVENT_STREAM_API int aws_event_stream_add_string_header( - struct aws_array_list *headers, - const char *name, - uint8_t name_len, - const char *value, - uint16_t value_len, - int8_t copy); - +/** + * Initialize a streaming decoder for messages with callbacks for usage and an optional user context pointer. + */ +AWS_EVENT_STREAM_API void aws_event_stream_streaming_decoder_init( + struct aws_event_stream_streaming_decoder *decoder, + struct aws_allocator *alloc, + aws_event_stream_process_on_payload_segment_fn *on_payload_segment, + aws_event_stream_prelude_received_fn *on_prelude, + aws_event_stream_header_received_fn *on_header, + aws_event_stream_on_error_fn *on_error, + void *user_data); + +/** + * Currently, no memory is allocated inside aws_aws_event_stream_streaming_decoder, but for future API compatibility, + * you should call this when finished with it. + */ +AWS_EVENT_STREAM_API void aws_event_stream_streaming_decoder_clean_up( + struct aws_event_stream_streaming_decoder *decoder); + +/** + * initializes a headers list for you. It will default to a capacity of 4 in dynamic mode. + */ +AWS_EVENT_STREAM_API int aws_event_stream_headers_list_init( + struct aws_array_list *headers, + struct aws_allocator *allocator); + +/** + * Cleans up the headers list. Also deallocates any headers that were the result of a copy flag for strings or buffer. + */ +AWS_EVENT_STREAM_API void aws_event_stream_headers_list_cleanup(struct aws_array_list *headers); + +/** + * Adds a string header to the list of headers. If copy is set to true, this will result in an allocation for the header + * value. Otherwise, the value will be set to the memory address of 'value'. + */ +AWS_EVENT_STREAM_API int aws_event_stream_add_string_header( + struct aws_array_list *headers, + const char *name, + uint8_t name_len, + const char *value, + uint16_t value_len, + int8_t copy); + AWS_EVENT_STREAM_API struct aws_event_stream_header_value_pair aws_event_stream_create_string_header( struct aws_byte_cursor name, struct aws_byte_cursor value); @@ -307,162 +307,162 @@ AWS_EVENT_STREAM_API struct aws_event_stream_header_value_pair aws_event_stream_ struct aws_byte_cursor name, int32_t value); -/** - * Adds a byte header to the list of headers. - */ -AWS_EVENT_STREAM_API int aws_event_stream_add_byte_header( - struct aws_array_list *headers, - const char *name, - uint8_t name_len, - int8_t value); - -/** - * Adds a bool header to the list of headers. - */ -AWS_EVENT_STREAM_API int aws_event_stream_add_bool_header( - struct aws_array_list *headers, - const char *name, - uint8_t name_len, - int8_t value); - -/** - * adds a 16 bit integer to the list of headers. - */ -AWS_EVENT_STREAM_API int aws_event_stream_add_int16_header( - struct aws_array_list *headers, - const char *name, - uint8_t name_len, - int16_t value); - -/** - * adds a 32 bit integer to the list of headers. - */ -AWS_EVENT_STREAM_API int aws_event_stream_add_int32_header( - struct aws_array_list *headers, - const char *name, - uint8_t name_len, - int32_t value); - -/** - * adds a 64 bit integer to the list of headers. - */ -AWS_EVENT_STREAM_API int aws_event_stream_add_int64_header( - struct aws_array_list *headers, - const char *name, - uint8_t name_len, - int64_t value); - -/** - * Adds a byte-buffer header to the list of headers. If copy is set to true, this will result in an allocation for the - * header value. Otherwise, the value will be set to the memory address of 'value'. - */ -AWS_EVENT_STREAM_API int aws_event_stream_add_bytebuf_header( - struct aws_array_list *headers, - const char *name, - uint8_t name_len, - uint8_t *value, - uint16_t value_len, - int8_t copy); - -/** - * adds a 64 bit integer representing milliseconds since unix epoch to the list of headers. - */ -AWS_EVENT_STREAM_API int aws_event_stream_add_timestamp_header( - struct aws_array_list *headers, - const char *name, - uint8_t name_len, - int64_t value); - -/** - * adds a uuid buffer to the list of headers. Value must always be 16 bytes long. - */ -AWS_EVENT_STREAM_API int aws_event_stream_add_uuid_header( - struct aws_array_list *headers, - const char *name, - uint8_t name_len, - const uint8_t *value); - -/** - * Returns the header name. Note: this value is not null terminated - */ -AWS_EVENT_STREAM_API struct aws_byte_buf aws_event_stream_header_name( - struct aws_event_stream_header_value_pair *header); - -/** - * Returns the header value as a string. Note: this value is not null terminated. - */ -AWS_EVENT_STREAM_API struct aws_byte_buf aws_event_stream_header_value_as_string( - struct aws_event_stream_header_value_pair *header); - -/** - * Returns the header value as a byte - */ -AWS_EVENT_STREAM_API int8_t aws_event_stream_header_value_as_byte(struct aws_event_stream_header_value_pair *header); - -/** - * Returns the header value as a boolean value. - */ -AWS_EVENT_STREAM_API int8_t aws_event_stream_header_value_as_bool(struct aws_event_stream_header_value_pair *header); - -/** - * Returns the header value as a 16 bit integer. - */ -AWS_EVENT_STREAM_API int16_t aws_event_stream_header_value_as_int16(struct aws_event_stream_header_value_pair *header); - -/** - * Returns the header value as a 32 bit integer. - */ -AWS_EVENT_STREAM_API int32_t aws_event_stream_header_value_as_int32(struct aws_event_stream_header_value_pair *header); - -/** - * Returns the header value as a 64 bit integer. - */ -AWS_EVENT_STREAM_API int64_t aws_event_stream_header_value_as_int64(struct aws_event_stream_header_value_pair *header); - -/** - * Returns the header value as a pointer to a byte buffer, call aws_event_stream_header_value_length to determine - * the length of the buffer. - */ -AWS_EVENT_STREAM_API struct aws_byte_buf aws_event_stream_header_value_as_bytebuf( - struct aws_event_stream_header_value_pair *header); - -/** - * Returns the header value as a 64 bit integer representing milliseconds since unix epoch. - */ -AWS_EVENT_STREAM_API int64_t - aws_event_stream_header_value_as_timestamp(struct aws_event_stream_header_value_pair *header); - -/** - * Returns the header value a byte buffer which is 16 bytes long. Represents a UUID. - */ -AWS_EVENT_STREAM_API struct aws_byte_buf aws_event_stream_header_value_as_uuid( - struct aws_event_stream_header_value_pair *header); - -/** - * Returns the length of the header value buffer. This is mostly intended for string and byte buffer types. - */ -AWS_EVENT_STREAM_API uint16_t aws_event_stream_header_value_length(struct aws_event_stream_header_value_pair *header); - -/** - * The main driver of the decoder. Pass data that should be decoded with its length. A likely use-case here is in - * response to a read event from an io-device - */ -AWS_EVENT_STREAM_API int aws_event_stream_streaming_decoder_pump( - struct aws_event_stream_streaming_decoder *decoder, - const struct aws_byte_buf *data); - -/** +/** + * Adds a byte header to the list of headers. + */ +AWS_EVENT_STREAM_API int aws_event_stream_add_byte_header( + struct aws_array_list *headers, + const char *name, + uint8_t name_len, + int8_t value); + +/** + * Adds a bool header to the list of headers. + */ +AWS_EVENT_STREAM_API int aws_event_stream_add_bool_header( + struct aws_array_list *headers, + const char *name, + uint8_t name_len, + int8_t value); + +/** + * adds a 16 bit integer to the list of headers. + */ +AWS_EVENT_STREAM_API int aws_event_stream_add_int16_header( + struct aws_array_list *headers, + const char *name, + uint8_t name_len, + int16_t value); + +/** + * adds a 32 bit integer to the list of headers. + */ +AWS_EVENT_STREAM_API int aws_event_stream_add_int32_header( + struct aws_array_list *headers, + const char *name, + uint8_t name_len, + int32_t value); + +/** + * adds a 64 bit integer to the list of headers. + */ +AWS_EVENT_STREAM_API int aws_event_stream_add_int64_header( + struct aws_array_list *headers, + const char *name, + uint8_t name_len, + int64_t value); + +/** + * Adds a byte-buffer header to the list of headers. If copy is set to true, this will result in an allocation for the + * header value. Otherwise, the value will be set to the memory address of 'value'. + */ +AWS_EVENT_STREAM_API int aws_event_stream_add_bytebuf_header( + struct aws_array_list *headers, + const char *name, + uint8_t name_len, + uint8_t *value, + uint16_t value_len, + int8_t copy); + +/** + * adds a 64 bit integer representing milliseconds since unix epoch to the list of headers. + */ +AWS_EVENT_STREAM_API int aws_event_stream_add_timestamp_header( + struct aws_array_list *headers, + const char *name, + uint8_t name_len, + int64_t value); + +/** + * adds a uuid buffer to the list of headers. Value must always be 16 bytes long. + */ +AWS_EVENT_STREAM_API int aws_event_stream_add_uuid_header( + struct aws_array_list *headers, + const char *name, + uint8_t name_len, + const uint8_t *value); + +/** + * Returns the header name. Note: this value is not null terminated + */ +AWS_EVENT_STREAM_API struct aws_byte_buf aws_event_stream_header_name( + struct aws_event_stream_header_value_pair *header); + +/** + * Returns the header value as a string. Note: this value is not null terminated. + */ +AWS_EVENT_STREAM_API struct aws_byte_buf aws_event_stream_header_value_as_string( + struct aws_event_stream_header_value_pair *header); + +/** + * Returns the header value as a byte + */ +AWS_EVENT_STREAM_API int8_t aws_event_stream_header_value_as_byte(struct aws_event_stream_header_value_pair *header); + +/** + * Returns the header value as a boolean value. + */ +AWS_EVENT_STREAM_API int8_t aws_event_stream_header_value_as_bool(struct aws_event_stream_header_value_pair *header); + +/** + * Returns the header value as a 16 bit integer. + */ +AWS_EVENT_STREAM_API int16_t aws_event_stream_header_value_as_int16(struct aws_event_stream_header_value_pair *header); + +/** + * Returns the header value as a 32 bit integer. + */ +AWS_EVENT_STREAM_API int32_t aws_event_stream_header_value_as_int32(struct aws_event_stream_header_value_pair *header); + +/** + * Returns the header value as a 64 bit integer. + */ +AWS_EVENT_STREAM_API int64_t aws_event_stream_header_value_as_int64(struct aws_event_stream_header_value_pair *header); + +/** + * Returns the header value as a pointer to a byte buffer, call aws_event_stream_header_value_length to determine + * the length of the buffer. + */ +AWS_EVENT_STREAM_API struct aws_byte_buf aws_event_stream_header_value_as_bytebuf( + struct aws_event_stream_header_value_pair *header); + +/** + * Returns the header value as a 64 bit integer representing milliseconds since unix epoch. + */ +AWS_EVENT_STREAM_API int64_t + aws_event_stream_header_value_as_timestamp(struct aws_event_stream_header_value_pair *header); + +/** + * Returns the header value a byte buffer which is 16 bytes long. Represents a UUID. + */ +AWS_EVENT_STREAM_API struct aws_byte_buf aws_event_stream_header_value_as_uuid( + struct aws_event_stream_header_value_pair *header); + +/** + * Returns the length of the header value buffer. This is mostly intended for string and byte buffer types. + */ +AWS_EVENT_STREAM_API uint16_t aws_event_stream_header_value_length(struct aws_event_stream_header_value_pair *header); + +/** + * The main driver of the decoder. Pass data that should be decoded with its length. A likely use-case here is in + * response to a read event from an io-device + */ +AWS_EVENT_STREAM_API int aws_event_stream_streaming_decoder_pump( + struct aws_event_stream_streaming_decoder *decoder, + const struct aws_byte_buf *data); + +/** * Initializes internal datastructures used by aws-c-event-stream. * Must be called before using any functionality in aws-c-event-stream. - */ + */ AWS_EVENT_STREAM_API void aws_event_stream_library_init(struct aws_allocator *allocator); - + /** * Clean up internal datastructures used by aws-c-event-stream. * Must not be called until application is done using functionality in aws-c-event-stream. */ AWS_EVENT_STREAM_API void aws_event_stream_library_clean_up(void); - + AWS_EXTERN_C_END -#endif /* AWS_EVENT_STREAM_H_ */ +#endif /* AWS_EVENT_STREAM_H_ */ diff --git a/contrib/restricted/aws/aws-c-event-stream/include/aws/event-stream/event_stream_exports.h b/contrib/restricted/aws/aws-c-event-stream/include/aws/event-stream/event_stream_exports.h index 7611cc400c..57c531db77 100644 --- a/contrib/restricted/aws/aws-c-event-stream/include/aws/event-stream/event_stream_exports.h +++ b/contrib/restricted/aws/aws-c-event-stream/include/aws/event-stream/event_stream_exports.h @@ -1,29 +1,29 @@ -#ifndef AWS_EVENT_STREAM_EXPORTS_H_ -#define AWS_EVENT_STREAM_EXPORTS_H_ +#ifndef AWS_EVENT_STREAM_EXPORTS_H_ +#define AWS_EVENT_STREAM_EXPORTS_H_ /** * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. - */ -#if defined(USE_WINDOWS_DLL_SEMANTICS) || defined(WIN32) -# ifdef AWS_EVENT_STREAM_USE_IMPORT_EXPORT -# ifdef AWS_EVENT_STREAM_EXPORTS -# define AWS_EVENT_STREAM_API __declspec(dllexport) -# else -# define AWS_EVENT_STREAM_API __declspec(dllimport) -# endif /* AWS_EVENT_STREAM_EXPORTS */ -# else -# define AWS_EVENT_STREAM_API -# endif /* AWS_EVENT_STREAM_USE_IMPORT_EXPORT */ - -#else /* defined (USE_WINDOWS_DLL_SEMANTICS) || defined (WIN32) */ - -# if ((__GNUC__ >= 4) || defined(__clang__)) && defined(AWS_EVENT_STREAM_USE_IMPORT_EXPORT) && \ - defined(AWS_EVENT_STREAM_EXPORTS) -# define AWS_EVENT_STREAM_API __attribute__((visibility("default"))) -# else -# define AWS_EVENT_STREAM_API -# endif /* __GNUC__ >= 4 || defined(__clang__) */ - -#endif /* defined (USE_WINDOWS_DLL_SEMANTICS) || defined (WIN32) */ - -#endif /* AWS_EVENT_STREAM_EXPORTS_H */ + */ +#if defined(USE_WINDOWS_DLL_SEMANTICS) || defined(WIN32) +# ifdef AWS_EVENT_STREAM_USE_IMPORT_EXPORT +# ifdef AWS_EVENT_STREAM_EXPORTS +# define AWS_EVENT_STREAM_API __declspec(dllexport) +# else +# define AWS_EVENT_STREAM_API __declspec(dllimport) +# endif /* AWS_EVENT_STREAM_EXPORTS */ +# else +# define AWS_EVENT_STREAM_API +# endif /* AWS_EVENT_STREAM_USE_IMPORT_EXPORT */ + +#else /* defined (USE_WINDOWS_DLL_SEMANTICS) || defined (WIN32) */ + +# if ((__GNUC__ >= 4) || defined(__clang__)) && defined(AWS_EVENT_STREAM_USE_IMPORT_EXPORT) && \ + defined(AWS_EVENT_STREAM_EXPORTS) +# define AWS_EVENT_STREAM_API __attribute__((visibility("default"))) +# else +# define AWS_EVENT_STREAM_API +# endif /* __GNUC__ >= 4 || defined(__clang__) */ + +#endif /* defined (USE_WINDOWS_DLL_SEMANTICS) || defined (WIN32) */ + +#endif /* AWS_EVENT_STREAM_EXPORTS_H */ diff --git a/contrib/restricted/aws/aws-c-event-stream/source/event_stream.c b/contrib/restricted/aws/aws-c-event-stream/source/event_stream.c index 7e33aadc62..224690f100 100644 --- a/contrib/restricted/aws/aws-c-event-stream/source/event_stream.c +++ b/contrib/restricted/aws/aws-c-event-stream/source/event_stream.c @@ -1,47 +1,47 @@ /** * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. - */ - -#include <aws/event-stream/event_stream.h> - -#include <aws/checksums/crc.h> - -#include <aws/common/encoding.h> + */ + +#include <aws/event-stream/event_stream.h> + +#include <aws/checksums/crc.h> + +#include <aws/common/encoding.h> #include <aws/io/io.h> - -#include <inttypes.h> - -#define LIB_NAME "libaws-c-event-stream" - -#if _MSC_VER -# pragma warning(push) -# pragma warning(disable : 4221) /* aggregate initializer using local variable addresses */ -# pragma warning(disable : 4204) /* non-constant aggregate initializer */ -# pragma warning(disable : 4306) /* msft doesn't trust us to do pointer arithmetic. */ -#endif - -static struct aws_error_info s_errors[] = { - AWS_DEFINE_ERROR_INFO(AWS_ERROR_EVENT_STREAM_BUFFER_LENGTH_MISMATCH, "Buffer length mismatch", LIB_NAME), - AWS_DEFINE_ERROR_INFO(AWS_ERROR_EVENT_STREAM_INSUFFICIENT_BUFFER_LEN, "insufficient buffer length", LIB_NAME), - AWS_DEFINE_ERROR_INFO( - AWS_ERROR_EVENT_STREAM_MESSAGE_FIELD_SIZE_EXCEEDED, - "a field for the message was too large", - LIB_NAME), - AWS_DEFINE_ERROR_INFO(AWS_ERROR_EVENT_STREAM_PRELUDE_CHECKSUM_FAILURE, "prelude checksum was incorrect", LIB_NAME), - AWS_DEFINE_ERROR_INFO(AWS_ERROR_EVENT_STREAM_MESSAGE_CHECKSUM_FAILURE, "message checksum was incorrect", LIB_NAME), - AWS_DEFINE_ERROR_INFO( - AWS_ERROR_EVENT_STREAM_MESSAGE_INVALID_HEADERS_LEN, - "message headers length was incorrect", - LIB_NAME), - AWS_DEFINE_ERROR_INFO( - AWS_ERROR_EVENT_STREAM_MESSAGE_UNKNOWN_HEADER_TYPE, - "An unknown header type was encountered", - LIB_NAME), - AWS_DEFINE_ERROR_INFO( - AWS_ERROR_EVENT_STREAM_MESSAGE_PARSER_ILLEGAL_STATE, - "message parser encountered an illegal state", - LIB_NAME), + +#include <inttypes.h> + +#define LIB_NAME "libaws-c-event-stream" + +#if _MSC_VER +# pragma warning(push) +# pragma warning(disable : 4221) /* aggregate initializer using local variable addresses */ +# pragma warning(disable : 4204) /* non-constant aggregate initializer */ +# pragma warning(disable : 4306) /* msft doesn't trust us to do pointer arithmetic. */ +#endif + +static struct aws_error_info s_errors[] = { + AWS_DEFINE_ERROR_INFO(AWS_ERROR_EVENT_STREAM_BUFFER_LENGTH_MISMATCH, "Buffer length mismatch", LIB_NAME), + AWS_DEFINE_ERROR_INFO(AWS_ERROR_EVENT_STREAM_INSUFFICIENT_BUFFER_LEN, "insufficient buffer length", LIB_NAME), + AWS_DEFINE_ERROR_INFO( + AWS_ERROR_EVENT_STREAM_MESSAGE_FIELD_SIZE_EXCEEDED, + "a field for the message was too large", + LIB_NAME), + AWS_DEFINE_ERROR_INFO(AWS_ERROR_EVENT_STREAM_PRELUDE_CHECKSUM_FAILURE, "prelude checksum was incorrect", LIB_NAME), + AWS_DEFINE_ERROR_INFO(AWS_ERROR_EVENT_STREAM_MESSAGE_CHECKSUM_FAILURE, "message checksum was incorrect", LIB_NAME), + AWS_DEFINE_ERROR_INFO( + AWS_ERROR_EVENT_STREAM_MESSAGE_INVALID_HEADERS_LEN, + "message headers length was incorrect", + LIB_NAME), + AWS_DEFINE_ERROR_INFO( + AWS_ERROR_EVENT_STREAM_MESSAGE_UNKNOWN_HEADER_TYPE, + "An unknown header type was encountered", + LIB_NAME), + AWS_DEFINE_ERROR_INFO( + AWS_ERROR_EVENT_STREAM_MESSAGE_PARSER_ILLEGAL_STATE, + "message parser encountered an illegal state", + LIB_NAME), AWS_DEFINE_ERROR_INFO( AWS_ERROR_EVENT_STREAM_RPC_CONNECTION_CLOSED, "event stream rpc connection has been closed", @@ -60,15 +60,15 @@ static struct aws_error_info s_errors[] = { "aws_event_stream_rpc_client_continuation_activate()" " before using a stream continuation token.", LIB_NAME), -}; - -static struct aws_error_info_list s_list = { - .error_list = s_errors, - .count = sizeof(s_errors) / sizeof(struct aws_error_info), -}; - +}; + +static struct aws_error_info_list s_list = { + .error_list = s_errors, + .count = sizeof(s_errors) / sizeof(struct aws_error_info), +}; + static bool s_event_stream_library_initialized = false; - + static struct aws_log_subject_info s_event_stream_log_subject_infos[] = { DEFINE_LOG_SUBJECT_INFO( AWS_LS_EVENT_STREAM_GENERAL, @@ -97,11 +97,11 @@ void aws_event_stream_library_init(struct aws_allocator *allocator) { if (!s_event_stream_library_initialized) { s_event_stream_library_initialized = true; aws_io_library_init(allocator); - aws_register_error_info(&s_list); + aws_register_error_info(&s_list); aws_register_log_subject_info_list(&s_event_stream_log_subject_list); - } -} - + } +} + void aws_event_stream_library_clean_up(void) { if (s_event_stream_library_initialized) { s_event_stream_library_initialized = false; @@ -110,548 +110,548 @@ void aws_event_stream_library_clean_up(void) { } } -#define TOTAL_LEN_OFFSET 0 -#define PRELUDE_CRC_OFFSET (sizeof(uint32_t) + sizeof(uint32_t)) -#define HEADER_LEN_OFFSET sizeof(uint32_t) - -/* Computes the byte length necessary to store the headers represented in the headers list. - * returns that length. */ +#define TOTAL_LEN_OFFSET 0 +#define PRELUDE_CRC_OFFSET (sizeof(uint32_t) + sizeof(uint32_t)) +#define HEADER_LEN_OFFSET sizeof(uint32_t) + +/* Computes the byte length necessary to store the headers represented in the headers list. + * returns that length. */ uint32_t aws_event_stream_compute_headers_required_buffer_len(const struct aws_array_list *headers) { - if (!headers || !aws_array_list_length(headers)) { - return 0; - } - - size_t headers_count = aws_array_list_length(headers); - size_t headers_len = 0; - - for (size_t i = 0; i < headers_count; ++i) { - struct aws_event_stream_header_value_pair *header = NULL; - - aws_array_list_get_at_ptr(headers, (void **)&header, i); - - headers_len += sizeof(header->header_name_len) + header->header_name_len + 1; - - if (header->header_value_type == AWS_EVENT_STREAM_HEADER_STRING || - header->header_value_type == AWS_EVENT_STREAM_HEADER_BYTE_BUF) { - headers_len += sizeof(header->header_value_len); - } - - if (header->header_value_type != AWS_EVENT_STREAM_HEADER_BOOL_FALSE && - header->header_value_type != AWS_EVENT_STREAM_HEADER_BOOL_TRUE) { - headers_len += header->header_value_len; - } - } - - return (uint32_t)headers_len; -} - -/* adds the headers represented in the headers list to the buffer. - returns the new buffer offset for use elsewhere. Assumes buffer length is at least the length of the return value - from compute_headers_length() */ + if (!headers || !aws_array_list_length(headers)) { + return 0; + } + + size_t headers_count = aws_array_list_length(headers); + size_t headers_len = 0; + + for (size_t i = 0; i < headers_count; ++i) { + struct aws_event_stream_header_value_pair *header = NULL; + + aws_array_list_get_at_ptr(headers, (void **)&header, i); + + headers_len += sizeof(header->header_name_len) + header->header_name_len + 1; + + if (header->header_value_type == AWS_EVENT_STREAM_HEADER_STRING || + header->header_value_type == AWS_EVENT_STREAM_HEADER_BYTE_BUF) { + headers_len += sizeof(header->header_value_len); + } + + if (header->header_value_type != AWS_EVENT_STREAM_HEADER_BOOL_FALSE && + header->header_value_type != AWS_EVENT_STREAM_HEADER_BOOL_TRUE) { + headers_len += header->header_value_len; + } + } + + return (uint32_t)headers_len; +} + +/* adds the headers represented in the headers list to the buffer. + returns the new buffer offset for use elsewhere. Assumes buffer length is at least the length of the return value + from compute_headers_length() */ size_t aws_event_stream_write_headers_to_buffer(const struct aws_array_list *headers, uint8_t *buffer) { - if (!headers || !aws_array_list_length(headers)) { - return 0; - } - - size_t headers_count = aws_array_list_length(headers); - uint8_t *buffer_alias = buffer; - - for (size_t i = 0; i < headers_count; ++i) { - struct aws_event_stream_header_value_pair *header = NULL; - - aws_array_list_get_at_ptr(headers, (void **)&header, i); - *buffer_alias = (uint8_t)header->header_name_len; - buffer_alias++; - memcpy(buffer_alias, header->header_name, (size_t)header->header_name_len); - buffer_alias += header->header_name_len; - *buffer_alias = (uint8_t)header->header_value_type; - buffer_alias++; - switch (header->header_value_type) { - case AWS_EVENT_STREAM_HEADER_BOOL_FALSE: - case AWS_EVENT_STREAM_HEADER_BOOL_TRUE: - break; - case AWS_EVENT_STREAM_HEADER_BYTE: - *buffer_alias = header->header_value.static_val[0]; - buffer_alias++; - break; - /* additions of integers here assume the endianness conversion has already happened */ - case AWS_EVENT_STREAM_HEADER_INT16: - memcpy(buffer_alias, header->header_value.static_val, sizeof(uint16_t)); - buffer_alias += sizeof(uint16_t); - break; - case AWS_EVENT_STREAM_HEADER_INT32: - memcpy(buffer_alias, header->header_value.static_val, sizeof(uint32_t)); - buffer_alias += sizeof(uint32_t); - break; - case AWS_EVENT_STREAM_HEADER_INT64: - case AWS_EVENT_STREAM_HEADER_TIMESTAMP: - memcpy(buffer_alias, header->header_value.static_val, sizeof(uint64_t)); - buffer_alias += sizeof(uint64_t); - break; - case AWS_EVENT_STREAM_HEADER_BYTE_BUF: - case AWS_EVENT_STREAM_HEADER_STRING: - aws_write_u16(header->header_value_len, buffer_alias); - buffer_alias += sizeof(uint16_t); - memcpy(buffer_alias, header->header_value.variable_len_val, header->header_value_len); - buffer_alias += header->header_value_len; - break; - case AWS_EVENT_STREAM_HEADER_UUID: - memcpy(buffer_alias, header->header_value.static_val, 16); - buffer_alias += header->header_value_len; - break; - } - } - - return buffer_alias - buffer; -} - + if (!headers || !aws_array_list_length(headers)) { + return 0; + } + + size_t headers_count = aws_array_list_length(headers); + uint8_t *buffer_alias = buffer; + + for (size_t i = 0; i < headers_count; ++i) { + struct aws_event_stream_header_value_pair *header = NULL; + + aws_array_list_get_at_ptr(headers, (void **)&header, i); + *buffer_alias = (uint8_t)header->header_name_len; + buffer_alias++; + memcpy(buffer_alias, header->header_name, (size_t)header->header_name_len); + buffer_alias += header->header_name_len; + *buffer_alias = (uint8_t)header->header_value_type; + buffer_alias++; + switch (header->header_value_type) { + case AWS_EVENT_STREAM_HEADER_BOOL_FALSE: + case AWS_EVENT_STREAM_HEADER_BOOL_TRUE: + break; + case AWS_EVENT_STREAM_HEADER_BYTE: + *buffer_alias = header->header_value.static_val[0]; + buffer_alias++; + break; + /* additions of integers here assume the endianness conversion has already happened */ + case AWS_EVENT_STREAM_HEADER_INT16: + memcpy(buffer_alias, header->header_value.static_val, sizeof(uint16_t)); + buffer_alias += sizeof(uint16_t); + break; + case AWS_EVENT_STREAM_HEADER_INT32: + memcpy(buffer_alias, header->header_value.static_val, sizeof(uint32_t)); + buffer_alias += sizeof(uint32_t); + break; + case AWS_EVENT_STREAM_HEADER_INT64: + case AWS_EVENT_STREAM_HEADER_TIMESTAMP: + memcpy(buffer_alias, header->header_value.static_val, sizeof(uint64_t)); + buffer_alias += sizeof(uint64_t); + break; + case AWS_EVENT_STREAM_HEADER_BYTE_BUF: + case AWS_EVENT_STREAM_HEADER_STRING: + aws_write_u16(header->header_value_len, buffer_alias); + buffer_alias += sizeof(uint16_t); + memcpy(buffer_alias, header->header_value.variable_len_val, header->header_value_len); + buffer_alias += header->header_value_len; + break; + case AWS_EVENT_STREAM_HEADER_UUID: + memcpy(buffer_alias, header->header_value.static_val, 16); + buffer_alias += header->header_value_len; + break; + } + } + + return buffer_alias - buffer; +} + int aws_event_stream_read_headers_from_buffer( struct aws_array_list *headers, const uint8_t *buffer, size_t headers_len) { - + if (AWS_UNLIKELY(headers_len > AWS_EVENT_STREAM_MAX_HEADERS_SIZE)) { - return aws_raise_error(AWS_ERROR_EVENT_STREAM_MESSAGE_FIELD_SIZE_EXCEEDED); - } - - /* iterate the buffer per header. */ - const uint8_t *buffer_start = buffer; - while ((size_t)(buffer - buffer_start) < headers_len) { - struct aws_event_stream_header_value_pair header; - AWS_ZERO_STRUCT(header); - - /* get the header info from the buffer, make sure to increment buffer offset. */ - header.header_name_len = *buffer; - buffer += sizeof(header.header_name_len); - memcpy((void *)header.header_name, buffer, (size_t)header.header_name_len); - buffer += header.header_name_len; - header.header_value_type = (enum aws_event_stream_header_value_type) * buffer; - buffer++; - - switch (header.header_value_type) { - case AWS_EVENT_STREAM_HEADER_BOOL_FALSE: - header.header_value_len = 0; - header.header_value.static_val[0] = 0; - break; - case AWS_EVENT_STREAM_HEADER_BOOL_TRUE: - header.header_value_len = 0; - header.header_value.static_val[0] = 1; - break; - case AWS_EVENT_STREAM_HEADER_BYTE: - header.header_value_len = sizeof(uint8_t); - header.header_value.static_val[0] = *buffer; - buffer++; - break; - case AWS_EVENT_STREAM_HEADER_INT16: - header.header_value_len = sizeof(uint16_t); - memcpy(header.header_value.static_val, buffer, sizeof(uint16_t)); - buffer += sizeof(uint16_t); - break; - case AWS_EVENT_STREAM_HEADER_INT32: - header.header_value_len = sizeof(uint32_t); - memcpy(header.header_value.static_val, buffer, sizeof(uint32_t)); - buffer += sizeof(uint32_t); - break; - case AWS_EVENT_STREAM_HEADER_INT64: - case AWS_EVENT_STREAM_HEADER_TIMESTAMP: - header.header_value_len = sizeof(uint64_t); - memcpy(header.header_value.static_val, buffer, sizeof(uint64_t)); - buffer += sizeof(uint64_t); - break; - case AWS_EVENT_STREAM_HEADER_BYTE_BUF: - case AWS_EVENT_STREAM_HEADER_STRING: - header.header_value_len = aws_read_u16(buffer); - buffer += sizeof(header.header_value_len); - header.header_value.variable_len_val = (uint8_t *)buffer; - buffer += header.header_value_len; - break; - case AWS_EVENT_STREAM_HEADER_UUID: - header.header_value_len = 16; - memcpy(header.header_value.static_val, buffer, 16); - buffer += header.header_value_len; - break; - } - - if (aws_array_list_push_back(headers, (const void *)&header)) { - return AWS_OP_ERR; - } - } - - return AWS_OP_SUCCESS; -} - -/* initialize message with the arguments - * the underlying buffer will be allocated and payload will be copied. - * see specification, this code should simply add these fields according to that.*/ -int aws_event_stream_message_init( - struct aws_event_stream_message *message, - struct aws_allocator *alloc, - struct aws_array_list *headers, - struct aws_byte_buf *payload) { - - size_t payload_len = payload ? payload->len : 0; - + return aws_raise_error(AWS_ERROR_EVENT_STREAM_MESSAGE_FIELD_SIZE_EXCEEDED); + } + + /* iterate the buffer per header. */ + const uint8_t *buffer_start = buffer; + while ((size_t)(buffer - buffer_start) < headers_len) { + struct aws_event_stream_header_value_pair header; + AWS_ZERO_STRUCT(header); + + /* get the header info from the buffer, make sure to increment buffer offset. */ + header.header_name_len = *buffer; + buffer += sizeof(header.header_name_len); + memcpy((void *)header.header_name, buffer, (size_t)header.header_name_len); + buffer += header.header_name_len; + header.header_value_type = (enum aws_event_stream_header_value_type) * buffer; + buffer++; + + switch (header.header_value_type) { + case AWS_EVENT_STREAM_HEADER_BOOL_FALSE: + header.header_value_len = 0; + header.header_value.static_val[0] = 0; + break; + case AWS_EVENT_STREAM_HEADER_BOOL_TRUE: + header.header_value_len = 0; + header.header_value.static_val[0] = 1; + break; + case AWS_EVENT_STREAM_HEADER_BYTE: + header.header_value_len = sizeof(uint8_t); + header.header_value.static_val[0] = *buffer; + buffer++; + break; + case AWS_EVENT_STREAM_HEADER_INT16: + header.header_value_len = sizeof(uint16_t); + memcpy(header.header_value.static_val, buffer, sizeof(uint16_t)); + buffer += sizeof(uint16_t); + break; + case AWS_EVENT_STREAM_HEADER_INT32: + header.header_value_len = sizeof(uint32_t); + memcpy(header.header_value.static_val, buffer, sizeof(uint32_t)); + buffer += sizeof(uint32_t); + break; + case AWS_EVENT_STREAM_HEADER_INT64: + case AWS_EVENT_STREAM_HEADER_TIMESTAMP: + header.header_value_len = sizeof(uint64_t); + memcpy(header.header_value.static_val, buffer, sizeof(uint64_t)); + buffer += sizeof(uint64_t); + break; + case AWS_EVENT_STREAM_HEADER_BYTE_BUF: + case AWS_EVENT_STREAM_HEADER_STRING: + header.header_value_len = aws_read_u16(buffer); + buffer += sizeof(header.header_value_len); + header.header_value.variable_len_val = (uint8_t *)buffer; + buffer += header.header_value_len; + break; + case AWS_EVENT_STREAM_HEADER_UUID: + header.header_value_len = 16; + memcpy(header.header_value.static_val, buffer, 16); + buffer += header.header_value_len; + break; + } + + if (aws_array_list_push_back(headers, (const void *)&header)) { + return AWS_OP_ERR; + } + } + + return AWS_OP_SUCCESS; +} + +/* initialize message with the arguments + * the underlying buffer will be allocated and payload will be copied. + * see specification, this code should simply add these fields according to that.*/ +int aws_event_stream_message_init( + struct aws_event_stream_message *message, + struct aws_allocator *alloc, + struct aws_array_list *headers, + struct aws_byte_buf *payload) { + + size_t payload_len = payload ? payload->len : 0; + uint32_t headers_length = aws_event_stream_compute_headers_required_buffer_len(headers); - + if (AWS_UNLIKELY(headers_length > AWS_EVENT_STREAM_MAX_HEADERS_SIZE)) { - return aws_raise_error(AWS_ERROR_EVENT_STREAM_MESSAGE_FIELD_SIZE_EXCEEDED); - } - - uint32_t total_length = - (uint32_t)(AWS_EVENT_STREAM_PRELUDE_LENGTH + headers_length + payload_len + AWS_EVENT_STREAM_TRAILER_LENGTH); - - if (AWS_UNLIKELY(total_length < headers_length || total_length < payload_len)) { - return aws_raise_error(AWS_ERROR_OVERFLOW_DETECTED); - } - + return aws_raise_error(AWS_ERROR_EVENT_STREAM_MESSAGE_FIELD_SIZE_EXCEEDED); + } + + uint32_t total_length = + (uint32_t)(AWS_EVENT_STREAM_PRELUDE_LENGTH + headers_length + payload_len + AWS_EVENT_STREAM_TRAILER_LENGTH); + + if (AWS_UNLIKELY(total_length < headers_length || total_length < payload_len)) { + return aws_raise_error(AWS_ERROR_OVERFLOW_DETECTED); + } + if (AWS_UNLIKELY(total_length > AWS_EVENT_STREAM_MAX_MESSAGE_SIZE)) { - return aws_raise_error(AWS_ERROR_EVENT_STREAM_MESSAGE_FIELD_SIZE_EXCEEDED); - } - - message->alloc = alloc; - message->message_buffer = aws_mem_acquire(message->alloc, total_length); - - if (message->message_buffer) { - message->owns_buffer = 1; - aws_write_u32(total_length, message->message_buffer); - uint8_t *buffer_offset = message->message_buffer + sizeof(total_length); - aws_write_u32(headers_length, buffer_offset); - buffer_offset += sizeof(headers_length); - - uint32_t running_crc = - aws_checksums_crc32(message->message_buffer, (int)(buffer_offset - message->message_buffer), 0); - - const uint8_t *message_crc_boundary_start = buffer_offset; - aws_write_u32(running_crc, buffer_offset); - buffer_offset += sizeof(running_crc); - - if (headers_length) { + return aws_raise_error(AWS_ERROR_EVENT_STREAM_MESSAGE_FIELD_SIZE_EXCEEDED); + } + + message->alloc = alloc; + message->message_buffer = aws_mem_acquire(message->alloc, total_length); + + if (message->message_buffer) { + message->owns_buffer = 1; + aws_write_u32(total_length, message->message_buffer); + uint8_t *buffer_offset = message->message_buffer + sizeof(total_length); + aws_write_u32(headers_length, buffer_offset); + buffer_offset += sizeof(headers_length); + + uint32_t running_crc = + aws_checksums_crc32(message->message_buffer, (int)(buffer_offset - message->message_buffer), 0); + + const uint8_t *message_crc_boundary_start = buffer_offset; + aws_write_u32(running_crc, buffer_offset); + buffer_offset += sizeof(running_crc); + + if (headers_length) { buffer_offset += aws_event_stream_write_headers_to_buffer(headers, buffer_offset); - } - - if (payload) { - memcpy(buffer_offset, payload->buffer, payload->len); - buffer_offset += payload->len; - } - - running_crc = aws_checksums_crc32( - message_crc_boundary_start, (int)(buffer_offset - message_crc_boundary_start), running_crc); - aws_write_u32(running_crc, buffer_offset); - - return AWS_OP_SUCCESS; - } - - return aws_raise_error(AWS_ERROR_OOM); -} - -/* add buffer to the message (non-owning). Verify buffer crcs and that length fields are reasonable. */ -int aws_event_stream_message_from_buffer( - struct aws_event_stream_message *message, - struct aws_allocator *alloc, - struct aws_byte_buf *buffer) { + } + + if (payload) { + memcpy(buffer_offset, payload->buffer, payload->len); + buffer_offset += payload->len; + } + + running_crc = aws_checksums_crc32( + message_crc_boundary_start, (int)(buffer_offset - message_crc_boundary_start), running_crc); + aws_write_u32(running_crc, buffer_offset); + + return AWS_OP_SUCCESS; + } + + return aws_raise_error(AWS_ERROR_OOM); +} + +/* add buffer to the message (non-owning). Verify buffer crcs and that length fields are reasonable. */ +int aws_event_stream_message_from_buffer( + struct aws_event_stream_message *message, + struct aws_allocator *alloc, + struct aws_byte_buf *buffer) { AWS_ASSERT(buffer); - - message->alloc = alloc; - message->owns_buffer = 0; - - if (AWS_UNLIKELY(buffer->len < AWS_EVENT_STREAM_PRELUDE_LENGTH + AWS_EVENT_STREAM_TRAILER_LENGTH)) { - return aws_raise_error(AWS_ERROR_EVENT_STREAM_BUFFER_LENGTH_MISMATCH); - } - - uint32_t message_length = aws_read_u32(buffer->buffer + TOTAL_LEN_OFFSET); - - if (AWS_UNLIKELY(message_length != buffer->len)) { - return aws_raise_error(AWS_ERROR_EVENT_STREAM_BUFFER_LENGTH_MISMATCH); - } - + + message->alloc = alloc; + message->owns_buffer = 0; + + if (AWS_UNLIKELY(buffer->len < AWS_EVENT_STREAM_PRELUDE_LENGTH + AWS_EVENT_STREAM_TRAILER_LENGTH)) { + return aws_raise_error(AWS_ERROR_EVENT_STREAM_BUFFER_LENGTH_MISMATCH); + } + + uint32_t message_length = aws_read_u32(buffer->buffer + TOTAL_LEN_OFFSET); + + if (AWS_UNLIKELY(message_length != buffer->len)) { + return aws_raise_error(AWS_ERROR_EVENT_STREAM_BUFFER_LENGTH_MISMATCH); + } + if (AWS_UNLIKELY(message_length > AWS_EVENT_STREAM_MAX_MESSAGE_SIZE)) { - return aws_raise_error(AWS_ERROR_EVENT_STREAM_MESSAGE_FIELD_SIZE_EXCEEDED); - } - - uint32_t running_crc = aws_checksums_crc32(buffer->buffer, (int)PRELUDE_CRC_OFFSET, 0); - uint32_t prelude_crc = aws_read_u32(buffer->buffer + PRELUDE_CRC_OFFSET); - - if (running_crc != prelude_crc) { - return aws_raise_error(AWS_ERROR_EVENT_STREAM_PRELUDE_CHECKSUM_FAILURE); - } - - running_crc = aws_checksums_crc32( - buffer->buffer + PRELUDE_CRC_OFFSET, - (int)(message_length - PRELUDE_CRC_OFFSET - AWS_EVENT_STREAM_TRAILER_LENGTH), - running_crc); - uint32_t message_crc = aws_read_u32(buffer->buffer + message_length - AWS_EVENT_STREAM_TRAILER_LENGTH); - - if (running_crc != message_crc) { - return aws_raise_error(AWS_ERROR_EVENT_STREAM_MESSAGE_CHECKSUM_FAILURE); - } - - message->message_buffer = buffer->buffer; - - if (aws_event_stream_message_headers_len(message) > - message_length - AWS_EVENT_STREAM_PRELUDE_LENGTH - AWS_EVENT_STREAM_TRAILER_LENGTH) { - message->message_buffer = 0; - return aws_raise_error(AWS_ERROR_EVENT_STREAM_MESSAGE_INVALID_HEADERS_LEN); - } - - return AWS_OP_SUCCESS; -} - -/* Verify buffer crcs and that length fields are reasonable. Once that is done, the buffer is copied to the message. */ -int aws_event_stream_message_from_buffer_copy( - struct aws_event_stream_message *message, - struct aws_allocator *alloc, - const struct aws_byte_buf *buffer) { - int parse_value = aws_event_stream_message_from_buffer(message, alloc, (struct aws_byte_buf *)buffer); - - if (!parse_value) { - message->message_buffer = aws_mem_acquire(alloc, buffer->len); - - if (message->message_buffer) { - memcpy(message->message_buffer, buffer->buffer, buffer->len); - message->alloc = alloc; - message->owns_buffer = 1; - - return AWS_OP_SUCCESS; - } - - return aws_raise_error(AWS_ERROR_OOM); - } - - return parse_value; -} - -/* if buffer is owned, release the memory. */ -void aws_event_stream_message_clean_up(struct aws_event_stream_message *message) { - if (message->message_buffer && message->owns_buffer) { - aws_mem_release(message->alloc, message->message_buffer); - } -} - -uint32_t aws_event_stream_message_total_length(const struct aws_event_stream_message *message) { - return aws_read_u32(message->message_buffer + TOTAL_LEN_OFFSET); -} - -uint32_t aws_event_stream_message_headers_len(const struct aws_event_stream_message *message) { - return aws_read_u32(message->message_buffer + HEADER_LEN_OFFSET); -} - -uint32_t aws_event_stream_message_prelude_crc(const struct aws_event_stream_message *message) { - return aws_read_u32(message->message_buffer + PRELUDE_CRC_OFFSET); -} - -int aws_event_stream_message_headers(const struct aws_event_stream_message *message, struct aws_array_list *headers) { + return aws_raise_error(AWS_ERROR_EVENT_STREAM_MESSAGE_FIELD_SIZE_EXCEEDED); + } + + uint32_t running_crc = aws_checksums_crc32(buffer->buffer, (int)PRELUDE_CRC_OFFSET, 0); + uint32_t prelude_crc = aws_read_u32(buffer->buffer + PRELUDE_CRC_OFFSET); + + if (running_crc != prelude_crc) { + return aws_raise_error(AWS_ERROR_EVENT_STREAM_PRELUDE_CHECKSUM_FAILURE); + } + + running_crc = aws_checksums_crc32( + buffer->buffer + PRELUDE_CRC_OFFSET, + (int)(message_length - PRELUDE_CRC_OFFSET - AWS_EVENT_STREAM_TRAILER_LENGTH), + running_crc); + uint32_t message_crc = aws_read_u32(buffer->buffer + message_length - AWS_EVENT_STREAM_TRAILER_LENGTH); + + if (running_crc != message_crc) { + return aws_raise_error(AWS_ERROR_EVENT_STREAM_MESSAGE_CHECKSUM_FAILURE); + } + + message->message_buffer = buffer->buffer; + + if (aws_event_stream_message_headers_len(message) > + message_length - AWS_EVENT_STREAM_PRELUDE_LENGTH - AWS_EVENT_STREAM_TRAILER_LENGTH) { + message->message_buffer = 0; + return aws_raise_error(AWS_ERROR_EVENT_STREAM_MESSAGE_INVALID_HEADERS_LEN); + } + + return AWS_OP_SUCCESS; +} + +/* Verify buffer crcs and that length fields are reasonable. Once that is done, the buffer is copied to the message. */ +int aws_event_stream_message_from_buffer_copy( + struct aws_event_stream_message *message, + struct aws_allocator *alloc, + const struct aws_byte_buf *buffer) { + int parse_value = aws_event_stream_message_from_buffer(message, alloc, (struct aws_byte_buf *)buffer); + + if (!parse_value) { + message->message_buffer = aws_mem_acquire(alloc, buffer->len); + + if (message->message_buffer) { + memcpy(message->message_buffer, buffer->buffer, buffer->len); + message->alloc = alloc; + message->owns_buffer = 1; + + return AWS_OP_SUCCESS; + } + + return aws_raise_error(AWS_ERROR_OOM); + } + + return parse_value; +} + +/* if buffer is owned, release the memory. */ +void aws_event_stream_message_clean_up(struct aws_event_stream_message *message) { + if (message->message_buffer && message->owns_buffer) { + aws_mem_release(message->alloc, message->message_buffer); + } +} + +uint32_t aws_event_stream_message_total_length(const struct aws_event_stream_message *message) { + return aws_read_u32(message->message_buffer + TOTAL_LEN_OFFSET); +} + +uint32_t aws_event_stream_message_headers_len(const struct aws_event_stream_message *message) { + return aws_read_u32(message->message_buffer + HEADER_LEN_OFFSET); +} + +uint32_t aws_event_stream_message_prelude_crc(const struct aws_event_stream_message *message) { + return aws_read_u32(message->message_buffer + PRELUDE_CRC_OFFSET); +} + +int aws_event_stream_message_headers(const struct aws_event_stream_message *message, struct aws_array_list *headers) { return aws_event_stream_read_headers_from_buffer( - headers, - message->message_buffer + AWS_EVENT_STREAM_PRELUDE_LENGTH, - aws_event_stream_message_headers_len(message)); -} - -const uint8_t *aws_event_stream_message_payload(const struct aws_event_stream_message *message) { - return message->message_buffer + AWS_EVENT_STREAM_PRELUDE_LENGTH + aws_event_stream_message_headers_len(message); -} - -uint32_t aws_event_stream_message_payload_len(const struct aws_event_stream_message *message) { - return aws_event_stream_message_total_length(message) - - (AWS_EVENT_STREAM_PRELUDE_LENGTH + aws_event_stream_message_headers_len(message) + - AWS_EVENT_STREAM_TRAILER_LENGTH); -} - -uint32_t aws_event_stream_message_message_crc(const struct aws_event_stream_message *message) { - return aws_read_u32( - message->message_buffer + (aws_event_stream_message_total_length(message) - AWS_EVENT_STREAM_TRAILER_LENGTH)); -} - -const uint8_t *aws_event_stream_message_buffer(const struct aws_event_stream_message *message) { - return message->message_buffer; -} - -#define DEBUG_STR_PRELUDE_TOTAL_LEN "\"total_length\": " -#define DEBUG_STR_PRELUDE_HDRS_LEN "\"headers_length\": " -#define DEBUG_STR_PRELUDE_CRC "\"prelude_crc\": " -#define DEBUG_STR_MESSAGE_CRC "\"message_crc\": " -#define DEBUG_STR_HEADER_NAME "\"name\": " -#define DEBUG_STR_HEADER_VALUE "\"value\": " -#define DEBUG_STR_HEADER_TYPE "\"type\": " - -int aws_event_stream_message_to_debug_str(FILE *fd, const struct aws_event_stream_message *message) { - struct aws_array_list headers; - aws_event_stream_headers_list_init(&headers, message->alloc); - aws_event_stream_message_headers(message, &headers); - - fprintf( - fd, - "{\n " DEBUG_STR_PRELUDE_TOTAL_LEN "%d,\n " DEBUG_STR_PRELUDE_HDRS_LEN "%d,\n " DEBUG_STR_PRELUDE_CRC - "%d,\n", - aws_event_stream_message_total_length(message), - aws_event_stream_message_headers_len(message), - aws_event_stream_message_prelude_crc(message)); - - int count = 0; - - uint16_t headers_count = (uint16_t)aws_array_list_length(&headers); - - fprintf(fd, " \"headers\": ["); - - for (uint16_t i = 0; i < headers_count; ++i) { - struct aws_event_stream_header_value_pair *header = NULL; - - aws_array_list_get_at_ptr(&headers, (void **)&header, i); - - fprintf(fd, " {\n"); - - fprintf(fd, " " DEBUG_STR_HEADER_NAME "\""); - fwrite(header->header_name, sizeof(char), (size_t)header->header_name_len, fd); - fprintf(fd, "\",\n"); - - fprintf(fd, " " DEBUG_STR_HEADER_TYPE "%d,\n", header->header_value_type); - - if (header->header_value_type == AWS_EVENT_STREAM_HEADER_BOOL_FALSE) { - fprintf(fd, " " DEBUG_STR_HEADER_VALUE "false\n"); - } else if (header->header_value_type == AWS_EVENT_STREAM_HEADER_BOOL_TRUE) { - fprintf(fd, " " DEBUG_STR_HEADER_VALUE "true\n"); - } else if (header->header_value_type == AWS_EVENT_STREAM_HEADER_BYTE) { - int8_t int_value = (int8_t)header->header_value.static_val[0]; - fprintf(fd, " " DEBUG_STR_HEADER_VALUE "%d\n", (int)int_value); - } else if (header->header_value_type == AWS_EVENT_STREAM_HEADER_INT16) { - int16_t int_value = aws_read_u16(header->header_value.static_val); - fprintf(fd, " " DEBUG_STR_HEADER_VALUE "%d\n", (int)int_value); - } else if (header->header_value_type == AWS_EVENT_STREAM_HEADER_INT32) { - int32_t int_value = (int32_t)aws_read_u32(header->header_value.static_val); - fprintf(fd, " " DEBUG_STR_HEADER_VALUE "%d\n", (int)int_value); - } else if ( - header->header_value_type == AWS_EVENT_STREAM_HEADER_INT64 || - header->header_value_type == AWS_EVENT_STREAM_HEADER_TIMESTAMP) { - int64_t int_value = (int64_t)aws_read_u64(header->header_value.static_val); - fprintf(fd, " " DEBUG_STR_HEADER_VALUE "%lld\n", (long long)int_value); - } else { - size_t buffer_len = 0; - aws_base64_compute_encoded_len(header->header_value_len, &buffer_len); - char *encoded_buffer = (char *)aws_mem_acquire(message->alloc, buffer_len); - if (!encoded_buffer) { - return aws_raise_error(AWS_ERROR_OOM); - } - - struct aws_byte_buf encode_output = aws_byte_buf_from_array((uint8_t *)encoded_buffer, buffer_len); - - if (header->header_value_type == AWS_EVENT_STREAM_HEADER_UUID) { - struct aws_byte_cursor to_encode = - aws_byte_cursor_from_array(header->header_value.static_val, header->header_value_len); - - aws_base64_encode(&to_encode, &encode_output); - } else { - struct aws_byte_cursor to_encode = - aws_byte_cursor_from_array(header->header_value.variable_len_val, header->header_value_len); - aws_base64_encode(&to_encode, &encode_output); - } - fprintf(fd, " " DEBUG_STR_HEADER_VALUE "\"%s\"\n", encoded_buffer); - aws_mem_release(message->alloc, encoded_buffer); - } - - fprintf(fd, " }"); - - if (count < headers_count - 1) { - fprintf(fd, ","); - } - fprintf(fd, "\n"); - - count++; - } - aws_event_stream_headers_list_cleanup(&headers); - fprintf(fd, " ],\n"); - - size_t payload_len = aws_event_stream_message_payload_len(message); - const uint8_t *payload = aws_event_stream_message_payload(message); - size_t encoded_len = 0; - aws_base64_compute_encoded_len(payload_len, &encoded_len); - char *encoded_payload = (char *)aws_mem_acquire(message->alloc, encoded_len); - - if (!encoded_payload) { - return aws_raise_error(AWS_ERROR_OOM); - } - - struct aws_byte_cursor payload_buffer = aws_byte_cursor_from_array(payload, payload_len); - struct aws_byte_buf encoded_payload_buffer = aws_byte_buf_from_array((uint8_t *)encoded_payload, encoded_len); - - aws_base64_encode(&payload_buffer, &encoded_payload_buffer); - fprintf(fd, " \"payload\": \"%s\",\n", encoded_payload); - fprintf(fd, " " DEBUG_STR_MESSAGE_CRC "%d\n}\n", aws_event_stream_message_message_crc(message)); - - return AWS_OP_SUCCESS; -} - -int aws_event_stream_headers_list_init(struct aws_array_list *headers, struct aws_allocator *allocator) { + headers, + message->message_buffer + AWS_EVENT_STREAM_PRELUDE_LENGTH, + aws_event_stream_message_headers_len(message)); +} + +const uint8_t *aws_event_stream_message_payload(const struct aws_event_stream_message *message) { + return message->message_buffer + AWS_EVENT_STREAM_PRELUDE_LENGTH + aws_event_stream_message_headers_len(message); +} + +uint32_t aws_event_stream_message_payload_len(const struct aws_event_stream_message *message) { + return aws_event_stream_message_total_length(message) - + (AWS_EVENT_STREAM_PRELUDE_LENGTH + aws_event_stream_message_headers_len(message) + + AWS_EVENT_STREAM_TRAILER_LENGTH); +} + +uint32_t aws_event_stream_message_message_crc(const struct aws_event_stream_message *message) { + return aws_read_u32( + message->message_buffer + (aws_event_stream_message_total_length(message) - AWS_EVENT_STREAM_TRAILER_LENGTH)); +} + +const uint8_t *aws_event_stream_message_buffer(const struct aws_event_stream_message *message) { + return message->message_buffer; +} + +#define DEBUG_STR_PRELUDE_TOTAL_LEN "\"total_length\": " +#define DEBUG_STR_PRELUDE_HDRS_LEN "\"headers_length\": " +#define DEBUG_STR_PRELUDE_CRC "\"prelude_crc\": " +#define DEBUG_STR_MESSAGE_CRC "\"message_crc\": " +#define DEBUG_STR_HEADER_NAME "\"name\": " +#define DEBUG_STR_HEADER_VALUE "\"value\": " +#define DEBUG_STR_HEADER_TYPE "\"type\": " + +int aws_event_stream_message_to_debug_str(FILE *fd, const struct aws_event_stream_message *message) { + struct aws_array_list headers; + aws_event_stream_headers_list_init(&headers, message->alloc); + aws_event_stream_message_headers(message, &headers); + + fprintf( + fd, + "{\n " DEBUG_STR_PRELUDE_TOTAL_LEN "%d,\n " DEBUG_STR_PRELUDE_HDRS_LEN "%d,\n " DEBUG_STR_PRELUDE_CRC + "%d,\n", + aws_event_stream_message_total_length(message), + aws_event_stream_message_headers_len(message), + aws_event_stream_message_prelude_crc(message)); + + int count = 0; + + uint16_t headers_count = (uint16_t)aws_array_list_length(&headers); + + fprintf(fd, " \"headers\": ["); + + for (uint16_t i = 0; i < headers_count; ++i) { + struct aws_event_stream_header_value_pair *header = NULL; + + aws_array_list_get_at_ptr(&headers, (void **)&header, i); + + fprintf(fd, " {\n"); + + fprintf(fd, " " DEBUG_STR_HEADER_NAME "\""); + fwrite(header->header_name, sizeof(char), (size_t)header->header_name_len, fd); + fprintf(fd, "\",\n"); + + fprintf(fd, " " DEBUG_STR_HEADER_TYPE "%d,\n", header->header_value_type); + + if (header->header_value_type == AWS_EVENT_STREAM_HEADER_BOOL_FALSE) { + fprintf(fd, " " DEBUG_STR_HEADER_VALUE "false\n"); + } else if (header->header_value_type == AWS_EVENT_STREAM_HEADER_BOOL_TRUE) { + fprintf(fd, " " DEBUG_STR_HEADER_VALUE "true\n"); + } else if (header->header_value_type == AWS_EVENT_STREAM_HEADER_BYTE) { + int8_t int_value = (int8_t)header->header_value.static_val[0]; + fprintf(fd, " " DEBUG_STR_HEADER_VALUE "%d\n", (int)int_value); + } else if (header->header_value_type == AWS_EVENT_STREAM_HEADER_INT16) { + int16_t int_value = aws_read_u16(header->header_value.static_val); + fprintf(fd, " " DEBUG_STR_HEADER_VALUE "%d\n", (int)int_value); + } else if (header->header_value_type == AWS_EVENT_STREAM_HEADER_INT32) { + int32_t int_value = (int32_t)aws_read_u32(header->header_value.static_val); + fprintf(fd, " " DEBUG_STR_HEADER_VALUE "%d\n", (int)int_value); + } else if ( + header->header_value_type == AWS_EVENT_STREAM_HEADER_INT64 || + header->header_value_type == AWS_EVENT_STREAM_HEADER_TIMESTAMP) { + int64_t int_value = (int64_t)aws_read_u64(header->header_value.static_val); + fprintf(fd, " " DEBUG_STR_HEADER_VALUE "%lld\n", (long long)int_value); + } else { + size_t buffer_len = 0; + aws_base64_compute_encoded_len(header->header_value_len, &buffer_len); + char *encoded_buffer = (char *)aws_mem_acquire(message->alloc, buffer_len); + if (!encoded_buffer) { + return aws_raise_error(AWS_ERROR_OOM); + } + + struct aws_byte_buf encode_output = aws_byte_buf_from_array((uint8_t *)encoded_buffer, buffer_len); + + if (header->header_value_type == AWS_EVENT_STREAM_HEADER_UUID) { + struct aws_byte_cursor to_encode = + aws_byte_cursor_from_array(header->header_value.static_val, header->header_value_len); + + aws_base64_encode(&to_encode, &encode_output); + } else { + struct aws_byte_cursor to_encode = + aws_byte_cursor_from_array(header->header_value.variable_len_val, header->header_value_len); + aws_base64_encode(&to_encode, &encode_output); + } + fprintf(fd, " " DEBUG_STR_HEADER_VALUE "\"%s\"\n", encoded_buffer); + aws_mem_release(message->alloc, encoded_buffer); + } + + fprintf(fd, " }"); + + if (count < headers_count - 1) { + fprintf(fd, ","); + } + fprintf(fd, "\n"); + + count++; + } + aws_event_stream_headers_list_cleanup(&headers); + fprintf(fd, " ],\n"); + + size_t payload_len = aws_event_stream_message_payload_len(message); + const uint8_t *payload = aws_event_stream_message_payload(message); + size_t encoded_len = 0; + aws_base64_compute_encoded_len(payload_len, &encoded_len); + char *encoded_payload = (char *)aws_mem_acquire(message->alloc, encoded_len); + + if (!encoded_payload) { + return aws_raise_error(AWS_ERROR_OOM); + } + + struct aws_byte_cursor payload_buffer = aws_byte_cursor_from_array(payload, payload_len); + struct aws_byte_buf encoded_payload_buffer = aws_byte_buf_from_array((uint8_t *)encoded_payload, encoded_len); + + aws_base64_encode(&payload_buffer, &encoded_payload_buffer); + fprintf(fd, " \"payload\": \"%s\",\n", encoded_payload); + fprintf(fd, " " DEBUG_STR_MESSAGE_CRC "%d\n}\n", aws_event_stream_message_message_crc(message)); + + return AWS_OP_SUCCESS; +} + +int aws_event_stream_headers_list_init(struct aws_array_list *headers, struct aws_allocator *allocator) { AWS_ASSERT(headers); AWS_ASSERT(allocator); - - return aws_array_list_init_dynamic(headers, allocator, 4, sizeof(struct aws_event_stream_header_value_pair)); -} - -void aws_event_stream_headers_list_cleanup(struct aws_array_list *headers) { + + return aws_array_list_init_dynamic(headers, allocator, 4, sizeof(struct aws_event_stream_header_value_pair)); +} + +void aws_event_stream_headers_list_cleanup(struct aws_array_list *headers) { if (AWS_UNLIKELY(!headers || !aws_array_list_is_valid(headers))) { return; } - - for (size_t i = 0; i < aws_array_list_length(headers); ++i) { - struct aws_event_stream_header_value_pair *header = NULL; - aws_array_list_get_at_ptr(headers, (void **)&header, i); - - if (header->value_owned) { - aws_mem_release(headers->alloc, (void *)header->header_value.variable_len_val); - } - } - - aws_array_list_clean_up(headers); -} - -static int s_add_variable_len_header( - struct aws_array_list *headers, - struct aws_event_stream_header_value_pair *header, - const char *name, - uint8_t name_len, - uint8_t *value, - uint16_t value_len, - int8_t copy) { - - memcpy((void *)header->header_name, (void *)name, (size_t)name_len); - - if (copy) { - header->header_value.variable_len_val = aws_mem_acquire(headers->alloc, value_len); - if (!header->header_value.variable_len_val) { - return aws_raise_error(AWS_ERROR_OOM); - } - - header->value_owned = 1; - memcpy((void *)header->header_value.variable_len_val, (void *)value, value_len); - } else { - header->value_owned = 0; - header->header_value.variable_len_val = value; - } - - if (aws_array_list_push_back(headers, (void *)header)) { - if (header->value_owned) { - aws_mem_release(headers->alloc, (void *)header->header_value.variable_len_val); - } - return AWS_OP_ERR; - } - - return AWS_OP_SUCCESS; -} - -int aws_event_stream_add_string_header( - struct aws_array_list *headers, - const char *name, - uint8_t name_len, - const char *value, - uint16_t value_len, - int8_t copy) { - struct aws_event_stream_header_value_pair header = {.header_name_len = name_len, - .header_value_len = value_len, - .value_owned = copy, - .header_value_type = AWS_EVENT_STREAM_HEADER_STRING}; - - return s_add_variable_len_header(headers, &header, name, name_len, (uint8_t *)value, value_len, copy); -} - + + for (size_t i = 0; i < aws_array_list_length(headers); ++i) { + struct aws_event_stream_header_value_pair *header = NULL; + aws_array_list_get_at_ptr(headers, (void **)&header, i); + + if (header->value_owned) { + aws_mem_release(headers->alloc, (void *)header->header_value.variable_len_val); + } + } + + aws_array_list_clean_up(headers); +} + +static int s_add_variable_len_header( + struct aws_array_list *headers, + struct aws_event_stream_header_value_pair *header, + const char *name, + uint8_t name_len, + uint8_t *value, + uint16_t value_len, + int8_t copy) { + + memcpy((void *)header->header_name, (void *)name, (size_t)name_len); + + if (copy) { + header->header_value.variable_len_val = aws_mem_acquire(headers->alloc, value_len); + if (!header->header_value.variable_len_val) { + return aws_raise_error(AWS_ERROR_OOM); + } + + header->value_owned = 1; + memcpy((void *)header->header_value.variable_len_val, (void *)value, value_len); + } else { + header->value_owned = 0; + header->header_value.variable_len_val = value; + } + + if (aws_array_list_push_back(headers, (void *)header)) { + if (header->value_owned) { + aws_mem_release(headers->alloc, (void *)header->header_value.variable_len_val); + } + return AWS_OP_ERR; + } + + return AWS_OP_SUCCESS; +} + +int aws_event_stream_add_string_header( + struct aws_array_list *headers, + const char *name, + uint8_t name_len, + const char *value, + uint16_t value_len, + int8_t copy) { + struct aws_event_stream_header_value_pair header = {.header_name_len = name_len, + .header_value_len = value_len, + .value_owned = copy, + .header_value_type = AWS_EVENT_STREAM_HEADER_STRING}; + + return s_add_variable_len_header(headers, &header, name, name_len, (uint8_t *)value, value_len, copy); +} + struct aws_event_stream_header_value_pair aws_event_stream_create_string_header( struct aws_byte_cursor name, struct aws_byte_cursor value) { @@ -689,667 +689,667 @@ struct aws_event_stream_header_value_pair aws_event_stream_create_int32_header( return header; } -int aws_event_stream_add_byte_header(struct aws_array_list *headers, const char *name, uint8_t name_len, int8_t value) { - struct aws_event_stream_header_value_pair header = {.header_name_len = name_len, - .header_value_len = 1, - .value_owned = 0, - .header_value_type = AWS_EVENT_STREAM_HEADER_BYTE, - .header_value.static_val[0] = (uint8_t)value}; - - memcpy((void *)header.header_name, (void *)name, (size_t)name_len); - - return aws_array_list_push_back(headers, (void *)&header); -} - -int aws_event_stream_add_bool_header(struct aws_array_list *headers, const char *name, uint8_t name_len, int8_t value) { - struct aws_event_stream_header_value_pair header = { - .header_name_len = name_len, - .header_value_len = 0, - .value_owned = 0, - .header_value_type = value ? AWS_EVENT_STREAM_HEADER_BOOL_TRUE : AWS_EVENT_STREAM_HEADER_BOOL_FALSE, - }; - - memcpy((void *)header.header_name, (void *)name, (size_t)name_len); - - return aws_array_list_push_back(headers, (void *)&header); -} - -int aws_event_stream_add_int16_header( - struct aws_array_list *headers, - const char *name, - uint8_t name_len, - int16_t value) { - struct aws_event_stream_header_value_pair header = { - .header_name_len = name_len, - .header_value_len = sizeof(value), - .value_owned = 0, - .header_value_type = AWS_EVENT_STREAM_HEADER_INT16, - }; - - memcpy((void *)header.header_name, (void *)name, (size_t)name_len); - aws_write_u16((uint16_t)value, header.header_value.static_val); - - return aws_array_list_push_back(headers, (void *)&header); -} - -int aws_event_stream_add_int32_header( - struct aws_array_list *headers, - const char *name, - uint8_t name_len, - int32_t value) { - struct aws_event_stream_header_value_pair header = { - .header_name_len = name_len, - .header_value_len = sizeof(value), - .value_owned = 0, - .header_value_type = AWS_EVENT_STREAM_HEADER_INT32, - }; - - memcpy((void *)header.header_name, (void *)name, (size_t)name_len); - aws_write_u32((uint32_t)value, header.header_value.static_val); - - return aws_array_list_push_back(headers, (void *)&header); -} - -int aws_event_stream_add_int64_header( - struct aws_array_list *headers, - const char *name, - uint8_t name_len, - int64_t value) { - struct aws_event_stream_header_value_pair header = { - .header_name_len = name_len, - .header_value_len = sizeof(value), - .value_owned = 0, - .header_value_type = AWS_EVENT_STREAM_HEADER_INT64, - }; - - memcpy((void *)header.header_name, (void *)name, (size_t)name_len); - aws_write_u64((uint64_t)value, header.header_value.static_val); - - return aws_array_list_push_back(headers, (void *)&header); -} - -int aws_event_stream_add_bytebuf_header( - struct aws_array_list *headers, - const char *name, - uint8_t name_len, - uint8_t *value, - uint16_t value_len, - int8_t copy) { - struct aws_event_stream_header_value_pair header = {.header_name_len = name_len, - .header_value_len = value_len, - .value_owned = copy, - .header_value_type = AWS_EVENT_STREAM_HEADER_BYTE_BUF}; - - return s_add_variable_len_header(headers, &header, name, name_len, value, value_len, copy); -} - -int aws_event_stream_add_timestamp_header( - struct aws_array_list *headers, - const char *name, - uint8_t name_len, - int64_t value) { - struct aws_event_stream_header_value_pair header = { - .header_name_len = name_len, - .header_value_len = sizeof(uint64_t), - .value_owned = 0, - .header_value_type = AWS_EVENT_STREAM_HEADER_TIMESTAMP, - }; - - memcpy((void *)header.header_name, (void *)name, (size_t)name_len); - aws_write_u64((uint64_t)value, header.header_value.static_val); - - return aws_array_list_push_back(headers, (void *)&header); -} - -int aws_event_stream_add_uuid_header( - struct aws_array_list *headers, - const char *name, - uint8_t name_len, - const uint8_t *value) { - struct aws_event_stream_header_value_pair header = { - .header_name_len = name_len, - .header_value_len = 16, - .value_owned = 0, - .header_value_type = AWS_EVENT_STREAM_HEADER_UUID, - }; - - memcpy((void *)header.header_name, (void *)name, (size_t)name_len); - memcpy((void *)header.header_value.static_val, value, 16); - - return aws_array_list_push_back(headers, (void *)&header); -} - -struct aws_byte_buf aws_event_stream_header_name(struct aws_event_stream_header_value_pair *header) { - return aws_byte_buf_from_array((uint8_t *)header->header_name, header->header_name_len); -} - -int8_t aws_event_stream_header_value_as_byte(struct aws_event_stream_header_value_pair *header) { - return (int8_t)header->header_value.static_val[0]; -} - -struct aws_byte_buf aws_event_stream_header_value_as_string(struct aws_event_stream_header_value_pair *header) { - return aws_event_stream_header_value_as_bytebuf(header); -} - -int8_t aws_event_stream_header_value_as_bool(struct aws_event_stream_header_value_pair *header) { - return header->header_value_type == AWS_EVENT_STREAM_HEADER_BOOL_TRUE ? (int8_t)1 : (int8_t)0; -} - -int16_t aws_event_stream_header_value_as_int16(struct aws_event_stream_header_value_pair *header) { - return (int16_t)aws_read_u16(header->header_value.static_val); -} - -int32_t aws_event_stream_header_value_as_int32(struct aws_event_stream_header_value_pair *header) { - return (int32_t)aws_read_u32(header->header_value.static_val); -} - -int64_t aws_event_stream_header_value_as_int64(struct aws_event_stream_header_value_pair *header) { - return (int64_t)aws_read_u64(header->header_value.static_val); -} - -struct aws_byte_buf aws_event_stream_header_value_as_bytebuf(struct aws_event_stream_header_value_pair *header) { - return aws_byte_buf_from_array(header->header_value.variable_len_val, header->header_value_len); -} - -int64_t aws_event_stream_header_value_as_timestamp(struct aws_event_stream_header_value_pair *header) { - return aws_event_stream_header_value_as_int64(header); -} - -struct aws_byte_buf aws_event_stream_header_value_as_uuid(struct aws_event_stream_header_value_pair *header) { - return aws_byte_buf_from_array(header->header_value.static_val, 16); -} - -uint16_t aws_event_stream_header_value_length(struct aws_event_stream_header_value_pair *header) { - return header->header_value_len; -} - -static struct aws_event_stream_message_prelude s_empty_prelude = {.total_len = 0, .headers_len = 0, .prelude_crc = 0}; - -static void s_reset_header_state(struct aws_event_stream_streaming_decoder *decoder, uint8_t free_header_data) { - - if (free_header_data && decoder->current_header.value_owned) { - aws_mem_release(decoder->alloc, (void *)decoder->current_header.header_value.variable_len_val); - } - - memset((void *)&decoder->current_header, 0, sizeof(struct aws_event_stream_header_value_pair)); -} - -static void s_reset_state(struct aws_event_stream_streaming_decoder *decoder); - -static int s_headers_state( - struct aws_event_stream_streaming_decoder *decoder, - const uint8_t *data, - size_t len, - size_t *processed); - -static int s_read_header_value( - struct aws_event_stream_streaming_decoder *decoder, - const uint8_t *data, - size_t len, - size_t *processed) { - - size_t current_pos = decoder->message_pos; - - size_t length_read = current_pos - decoder->current_header_value_offset; - struct aws_event_stream_header_value_pair *current_header = &decoder->current_header; - - if (!length_read) { - /* save an allocation, this can only happen if the data we were handed is larger than the length of the header - * value. we don't really need to handle offsets in this case. This expects the user is living by the contract - * that they cannot act like they own this memory beyond the lifetime of their callback, and they should not - * mutate it */ - if (len >= current_header->header_value_len) { - /* this part works regardless of type since the layout of the union will line up. */ - current_header->header_value.variable_len_val = (uint8_t *)data; - current_header->value_owned = 0; - decoder->on_header(decoder, &decoder->prelude, &decoder->current_header, decoder->user_context); - *processed += current_header->header_value_len; - decoder->message_pos += current_header->header_value_len; - decoder->running_crc = - aws_checksums_crc32(data, (int)current_header->header_value_len, decoder->running_crc); - - s_reset_header_state(decoder, 1); - decoder->state = s_headers_state; - return AWS_OP_SUCCESS; - } - - /* a possible optimization later would be to only allocate this once, and then keep reusing the same buffer. for - * subsequent messages.*/ - if (current_header->header_value_type == AWS_EVENT_STREAM_HEADER_BYTE_BUF || - current_header->header_value_type == AWS_EVENT_STREAM_HEADER_STRING) { - current_header->header_value.variable_len_val = - aws_mem_acquire(decoder->alloc, decoder->current_header.header_value_len); - - if (!current_header->header_value.variable_len_val) { - return aws_raise_error(AWS_ERROR_OOM); - } - - current_header->value_owned = 1; - } - } - - size_t max_read = - len >= current_header->header_value_len - length_read ? current_header->header_value_len - length_read : len; - - const uint8_t *header_value_alias = current_header->header_value_type == AWS_EVENT_STREAM_HEADER_BYTE_BUF || - current_header->header_value_type == AWS_EVENT_STREAM_HEADER_STRING - ? current_header->header_value.variable_len_val - : current_header->header_value.static_val; - - memcpy((void *)(header_value_alias + length_read), data, max_read); - decoder->running_crc = aws_checksums_crc32(data, (int)max_read, decoder->running_crc); - - *processed += max_read; - decoder->message_pos += max_read; - length_read += max_read; - - if (length_read == current_header->header_value_len) { - decoder->on_header(decoder, &decoder->prelude, current_header, decoder->user_context); - s_reset_header_state(decoder, 1); - decoder->state = s_headers_state; - } - - return AWS_OP_SUCCESS; -} - -static int s_read_header_value_len( - struct aws_event_stream_streaming_decoder *decoder, - const uint8_t *data, - size_t len, - size_t *processed) { - size_t current_pos = decoder->message_pos; - - size_t length_portion_read = current_pos - decoder->current_header_value_offset; - - if (length_portion_read < sizeof(uint16_t)) { - size_t max_to_read = - len > sizeof(uint16_t) - length_portion_read ? sizeof(uint16_t) - length_portion_read : len; - memcpy(decoder->working_buffer + length_portion_read, data, max_to_read); - decoder->running_crc = aws_checksums_crc32(data, (int)max_to_read, decoder->running_crc); - - *processed += max_to_read; - decoder->message_pos += max_to_read; - - length_portion_read = decoder->message_pos - decoder->current_header_value_offset; - } - - if (length_portion_read == sizeof(uint16_t)) { - decoder->current_header.header_value_len = aws_read_u16(decoder->working_buffer); - decoder->current_header_value_offset = decoder->message_pos; - decoder->state = s_read_header_value; - } - - return AWS_OP_SUCCESS; -} - -static int s_read_header_type( - struct aws_event_stream_streaming_decoder *decoder, - const uint8_t *data, - size_t len, - size_t *processed) { - (void)len; - uint8_t type = *data; - decoder->running_crc = aws_checksums_crc32(data, 1, decoder->running_crc); - *processed += 1; - decoder->message_pos++; - decoder->current_header_value_offset++; - struct aws_event_stream_header_value_pair *current_header = &decoder->current_header; - - if (type >= AWS_EVENT_STREAM_HEADER_BOOL_FALSE && type <= AWS_EVENT_STREAM_HEADER_UUID) { - current_header->header_value_type = (enum aws_event_stream_header_value_type)type; - - switch (type) { - case AWS_EVENT_STREAM_HEADER_STRING: - case AWS_EVENT_STREAM_HEADER_BYTE_BUF: - decoder->state = s_read_header_value_len; - break; - case AWS_EVENT_STREAM_HEADER_BOOL_FALSE: - current_header->header_value_len = 0; - current_header->header_value.static_val[0] = 0; - decoder->on_header(decoder, &decoder->prelude, current_header, decoder->user_context); - s_reset_header_state(decoder, 1); - break; - case AWS_EVENT_STREAM_HEADER_BOOL_TRUE: - current_header->header_value_len = 0; - current_header->header_value.static_val[0] = 1; - decoder->on_header(decoder, &decoder->prelude, current_header, decoder->user_context); - s_reset_header_state(decoder, 1); - break; - case AWS_EVENT_STREAM_HEADER_BYTE: - current_header->header_value_len = 1; - decoder->state = s_read_header_value; - break; - case AWS_EVENT_STREAM_HEADER_INT16: - current_header->header_value_len = sizeof(uint16_t); - decoder->state = s_read_header_value; - break; - case AWS_EVENT_STREAM_HEADER_INT32: - current_header->header_value_len = sizeof(uint32_t); - decoder->state = s_read_header_value; - break; - case AWS_EVENT_STREAM_HEADER_INT64: - case AWS_EVENT_STREAM_HEADER_TIMESTAMP: - current_header->header_value_len = sizeof(uint64_t); - decoder->state = s_read_header_value; - break; - case AWS_EVENT_STREAM_HEADER_UUID: - current_header->header_value_len = 16; - decoder->state = s_read_header_value; - break; - default: - return aws_raise_error(AWS_ERROR_EVENT_STREAM_MESSAGE_UNKNOWN_HEADER_TYPE); - } - - return AWS_OP_SUCCESS; - } - - return aws_raise_error(AWS_ERROR_EVENT_STREAM_MESSAGE_UNKNOWN_HEADER_TYPE); -} - -static int s_read_header_name( - struct aws_event_stream_streaming_decoder *decoder, - const uint8_t *data, - size_t len, - size_t *processed) { - size_t current_pos = decoder->message_pos; - - size_t length_read = current_pos - decoder->current_header_name_offset; - - size_t max_read = len >= decoder->current_header.header_name_len - length_read - ? decoder->current_header.header_name_len - length_read - : len; - memcpy((void *)(decoder->current_header.header_name + length_read), data, max_read); - decoder->running_crc = aws_checksums_crc32(data, (int)max_read, decoder->running_crc); - - *processed += max_read; - decoder->message_pos += max_read; - length_read += max_read; - - if (length_read == decoder->current_header.header_name_len) { - decoder->state = s_read_header_type; - decoder->current_header_value_offset = decoder->message_pos; - } - - return AWS_OP_SUCCESS; -} - -static int s_read_header_name_len( - struct aws_event_stream_streaming_decoder *decoder, - const uint8_t *data, - size_t len, - size_t *processed) { - (void)len; - decoder->current_header.header_name_len = *data; - decoder->message_pos++; - decoder->current_header_name_offset++; - *processed += 1; - decoder->state = s_read_header_name; - decoder->running_crc = aws_checksums_crc32(data, 1, decoder->running_crc); - - return AWS_OP_SUCCESS; -} - -static int s_start_header( - struct aws_event_stream_streaming_decoder *decoder, - const uint8_t *data, - size_t len, - size_t *processed) /* NOLINT */ { - (void)data; - (void)len; - (void)processed; - decoder->state = s_read_header_name_len; - decoder->current_header_name_offset = decoder->message_pos; - - return AWS_OP_SUCCESS; -} - -static int s_payload_state( - struct aws_event_stream_streaming_decoder *decoder, - const uint8_t *data, - size_t len, - size_t *processed); - -/*Handles the initial state for header parsing. - will oscillate between multiple other states as well. - after all headers have been handled, payload will be set as the next state. */ -static int s_headers_state( - struct aws_event_stream_streaming_decoder *decoder, - const uint8_t *data, - size_t len, - size_t *processed) /* NOLINT */ { - (void)data; - (void)len; - (void)processed; - - size_t current_pos = decoder->message_pos; - - size_t headers_boundary = decoder->prelude.headers_len + AWS_EVENT_STREAM_PRELUDE_LENGTH; - - if (current_pos < headers_boundary) { - decoder->state = s_start_header; - return AWS_OP_SUCCESS; - } - - if (current_pos == headers_boundary) { - decoder->state = s_payload_state; - return AWS_OP_SUCCESS; - } - - return aws_raise_error(AWS_ERROR_EVENT_STREAM_MESSAGE_PARSER_ILLEGAL_STATE); -} - -/* handles reading the trailer. Once it has been read, it will be compared to the running checksum. If successful, - * the state will be reset. */ -static int s_read_trailer_state( - struct aws_event_stream_streaming_decoder *decoder, - const uint8_t *data, - size_t len, - size_t *processed) { - - size_t remaining_amount = decoder->prelude.total_len - decoder->message_pos; - size_t segment_length = len > remaining_amount ? remaining_amount : len; - size_t offset = sizeof(uint32_t) - remaining_amount; - memcpy(decoder->working_buffer + offset, data, segment_length); - decoder->message_pos += segment_length; - *processed += segment_length; - - if (decoder->message_pos == decoder->prelude.total_len) { - uint32_t message_crc = aws_read_u32(decoder->working_buffer); - - if (message_crc == decoder->running_crc) { - s_reset_state(decoder); - } else { - char error_message[70]; - snprintf( - error_message, - sizeof(error_message), - "CRC Mismatch. message_crc was 0x08%" PRIX32 ", but computed 0x08%" PRIX32, - message_crc, - decoder->running_crc); - aws_raise_error(AWS_ERROR_EVENT_STREAM_MESSAGE_CHECKSUM_FAILURE); - decoder->on_error( - decoder, - &decoder->prelude, - AWS_ERROR_EVENT_STREAM_MESSAGE_CHECKSUM_FAILURE, - error_message, - decoder->user_context); - return AWS_OP_ERR; - } - } - - return AWS_OP_SUCCESS; -} - -/* handles the reading of the payload up to the final checksum. Sets read_trailer_state as the new state once - * the payload has been processed. */ -static int s_payload_state( - struct aws_event_stream_streaming_decoder *decoder, - const uint8_t *data, - size_t len, - size_t *processed) { - - if (decoder->message_pos < decoder->prelude.total_len - AWS_EVENT_STREAM_TRAILER_LENGTH) { - size_t remaining_amount = decoder->prelude.total_len - decoder->message_pos - AWS_EVENT_STREAM_TRAILER_LENGTH; - size_t segment_length = len > remaining_amount ? remaining_amount : len; - int8_t final_segment = - (segment_length + decoder->message_pos) == (decoder->prelude.total_len - AWS_EVENT_STREAM_TRAILER_LENGTH); - struct aws_byte_buf payload_buf = aws_byte_buf_from_array(data, segment_length); - decoder->on_payload(decoder, &payload_buf, final_segment, decoder->user_context); - decoder->message_pos += segment_length; - decoder->running_crc = aws_checksums_crc32(data, (int)segment_length, decoder->running_crc); - *processed += segment_length; - } - - if (decoder->message_pos == decoder->prelude.total_len - AWS_EVENT_STREAM_TRAILER_LENGTH) { - decoder->state = s_read_trailer_state; - } - - return AWS_OP_SUCCESS; -} - -/* Parses the payload and verifies checksums. Sets the next state if successful. */ -static int s_verify_prelude_state( - struct aws_event_stream_streaming_decoder *decoder, - const uint8_t *data, - size_t len, - size_t *processed) /* NOLINT */ { - (void)data; - (void)len; - (void)processed; - - decoder->prelude.headers_len = aws_read_u32(decoder->working_buffer + HEADER_LEN_OFFSET); - decoder->prelude.prelude_crc = aws_read_u32(decoder->working_buffer + PRELUDE_CRC_OFFSET); - decoder->prelude.total_len = aws_read_u32(decoder->working_buffer + TOTAL_LEN_OFFSET); - - decoder->running_crc = aws_checksums_crc32(decoder->working_buffer, PRELUDE_CRC_OFFSET, 0); - - if (AWS_LIKELY(decoder->running_crc == decoder->prelude.prelude_crc)) { - - if (AWS_UNLIKELY( +int aws_event_stream_add_byte_header(struct aws_array_list *headers, const char *name, uint8_t name_len, int8_t value) { + struct aws_event_stream_header_value_pair header = {.header_name_len = name_len, + .header_value_len = 1, + .value_owned = 0, + .header_value_type = AWS_EVENT_STREAM_HEADER_BYTE, + .header_value.static_val[0] = (uint8_t)value}; + + memcpy((void *)header.header_name, (void *)name, (size_t)name_len); + + return aws_array_list_push_back(headers, (void *)&header); +} + +int aws_event_stream_add_bool_header(struct aws_array_list *headers, const char *name, uint8_t name_len, int8_t value) { + struct aws_event_stream_header_value_pair header = { + .header_name_len = name_len, + .header_value_len = 0, + .value_owned = 0, + .header_value_type = value ? AWS_EVENT_STREAM_HEADER_BOOL_TRUE : AWS_EVENT_STREAM_HEADER_BOOL_FALSE, + }; + + memcpy((void *)header.header_name, (void *)name, (size_t)name_len); + + return aws_array_list_push_back(headers, (void *)&header); +} + +int aws_event_stream_add_int16_header( + struct aws_array_list *headers, + const char *name, + uint8_t name_len, + int16_t value) { + struct aws_event_stream_header_value_pair header = { + .header_name_len = name_len, + .header_value_len = sizeof(value), + .value_owned = 0, + .header_value_type = AWS_EVENT_STREAM_HEADER_INT16, + }; + + memcpy((void *)header.header_name, (void *)name, (size_t)name_len); + aws_write_u16((uint16_t)value, header.header_value.static_val); + + return aws_array_list_push_back(headers, (void *)&header); +} + +int aws_event_stream_add_int32_header( + struct aws_array_list *headers, + const char *name, + uint8_t name_len, + int32_t value) { + struct aws_event_stream_header_value_pair header = { + .header_name_len = name_len, + .header_value_len = sizeof(value), + .value_owned = 0, + .header_value_type = AWS_EVENT_STREAM_HEADER_INT32, + }; + + memcpy((void *)header.header_name, (void *)name, (size_t)name_len); + aws_write_u32((uint32_t)value, header.header_value.static_val); + + return aws_array_list_push_back(headers, (void *)&header); +} + +int aws_event_stream_add_int64_header( + struct aws_array_list *headers, + const char *name, + uint8_t name_len, + int64_t value) { + struct aws_event_stream_header_value_pair header = { + .header_name_len = name_len, + .header_value_len = sizeof(value), + .value_owned = 0, + .header_value_type = AWS_EVENT_STREAM_HEADER_INT64, + }; + + memcpy((void *)header.header_name, (void *)name, (size_t)name_len); + aws_write_u64((uint64_t)value, header.header_value.static_val); + + return aws_array_list_push_back(headers, (void *)&header); +} + +int aws_event_stream_add_bytebuf_header( + struct aws_array_list *headers, + const char *name, + uint8_t name_len, + uint8_t *value, + uint16_t value_len, + int8_t copy) { + struct aws_event_stream_header_value_pair header = {.header_name_len = name_len, + .header_value_len = value_len, + .value_owned = copy, + .header_value_type = AWS_EVENT_STREAM_HEADER_BYTE_BUF}; + + return s_add_variable_len_header(headers, &header, name, name_len, value, value_len, copy); +} + +int aws_event_stream_add_timestamp_header( + struct aws_array_list *headers, + const char *name, + uint8_t name_len, + int64_t value) { + struct aws_event_stream_header_value_pair header = { + .header_name_len = name_len, + .header_value_len = sizeof(uint64_t), + .value_owned = 0, + .header_value_type = AWS_EVENT_STREAM_HEADER_TIMESTAMP, + }; + + memcpy((void *)header.header_name, (void *)name, (size_t)name_len); + aws_write_u64((uint64_t)value, header.header_value.static_val); + + return aws_array_list_push_back(headers, (void *)&header); +} + +int aws_event_stream_add_uuid_header( + struct aws_array_list *headers, + const char *name, + uint8_t name_len, + const uint8_t *value) { + struct aws_event_stream_header_value_pair header = { + .header_name_len = name_len, + .header_value_len = 16, + .value_owned = 0, + .header_value_type = AWS_EVENT_STREAM_HEADER_UUID, + }; + + memcpy((void *)header.header_name, (void *)name, (size_t)name_len); + memcpy((void *)header.header_value.static_val, value, 16); + + return aws_array_list_push_back(headers, (void *)&header); +} + +struct aws_byte_buf aws_event_stream_header_name(struct aws_event_stream_header_value_pair *header) { + return aws_byte_buf_from_array((uint8_t *)header->header_name, header->header_name_len); +} + +int8_t aws_event_stream_header_value_as_byte(struct aws_event_stream_header_value_pair *header) { + return (int8_t)header->header_value.static_val[0]; +} + +struct aws_byte_buf aws_event_stream_header_value_as_string(struct aws_event_stream_header_value_pair *header) { + return aws_event_stream_header_value_as_bytebuf(header); +} + +int8_t aws_event_stream_header_value_as_bool(struct aws_event_stream_header_value_pair *header) { + return header->header_value_type == AWS_EVENT_STREAM_HEADER_BOOL_TRUE ? (int8_t)1 : (int8_t)0; +} + +int16_t aws_event_stream_header_value_as_int16(struct aws_event_stream_header_value_pair *header) { + return (int16_t)aws_read_u16(header->header_value.static_val); +} + +int32_t aws_event_stream_header_value_as_int32(struct aws_event_stream_header_value_pair *header) { + return (int32_t)aws_read_u32(header->header_value.static_val); +} + +int64_t aws_event_stream_header_value_as_int64(struct aws_event_stream_header_value_pair *header) { + return (int64_t)aws_read_u64(header->header_value.static_val); +} + +struct aws_byte_buf aws_event_stream_header_value_as_bytebuf(struct aws_event_stream_header_value_pair *header) { + return aws_byte_buf_from_array(header->header_value.variable_len_val, header->header_value_len); +} + +int64_t aws_event_stream_header_value_as_timestamp(struct aws_event_stream_header_value_pair *header) { + return aws_event_stream_header_value_as_int64(header); +} + +struct aws_byte_buf aws_event_stream_header_value_as_uuid(struct aws_event_stream_header_value_pair *header) { + return aws_byte_buf_from_array(header->header_value.static_val, 16); +} + +uint16_t aws_event_stream_header_value_length(struct aws_event_stream_header_value_pair *header) { + return header->header_value_len; +} + +static struct aws_event_stream_message_prelude s_empty_prelude = {.total_len = 0, .headers_len = 0, .prelude_crc = 0}; + +static void s_reset_header_state(struct aws_event_stream_streaming_decoder *decoder, uint8_t free_header_data) { + + if (free_header_data && decoder->current_header.value_owned) { + aws_mem_release(decoder->alloc, (void *)decoder->current_header.header_value.variable_len_val); + } + + memset((void *)&decoder->current_header, 0, sizeof(struct aws_event_stream_header_value_pair)); +} + +static void s_reset_state(struct aws_event_stream_streaming_decoder *decoder); + +static int s_headers_state( + struct aws_event_stream_streaming_decoder *decoder, + const uint8_t *data, + size_t len, + size_t *processed); + +static int s_read_header_value( + struct aws_event_stream_streaming_decoder *decoder, + const uint8_t *data, + size_t len, + size_t *processed) { + + size_t current_pos = decoder->message_pos; + + size_t length_read = current_pos - decoder->current_header_value_offset; + struct aws_event_stream_header_value_pair *current_header = &decoder->current_header; + + if (!length_read) { + /* save an allocation, this can only happen if the data we were handed is larger than the length of the header + * value. we don't really need to handle offsets in this case. This expects the user is living by the contract + * that they cannot act like they own this memory beyond the lifetime of their callback, and they should not + * mutate it */ + if (len >= current_header->header_value_len) { + /* this part works regardless of type since the layout of the union will line up. */ + current_header->header_value.variable_len_val = (uint8_t *)data; + current_header->value_owned = 0; + decoder->on_header(decoder, &decoder->prelude, &decoder->current_header, decoder->user_context); + *processed += current_header->header_value_len; + decoder->message_pos += current_header->header_value_len; + decoder->running_crc = + aws_checksums_crc32(data, (int)current_header->header_value_len, decoder->running_crc); + + s_reset_header_state(decoder, 1); + decoder->state = s_headers_state; + return AWS_OP_SUCCESS; + } + + /* a possible optimization later would be to only allocate this once, and then keep reusing the same buffer. for + * subsequent messages.*/ + if (current_header->header_value_type == AWS_EVENT_STREAM_HEADER_BYTE_BUF || + current_header->header_value_type == AWS_EVENT_STREAM_HEADER_STRING) { + current_header->header_value.variable_len_val = + aws_mem_acquire(decoder->alloc, decoder->current_header.header_value_len); + + if (!current_header->header_value.variable_len_val) { + return aws_raise_error(AWS_ERROR_OOM); + } + + current_header->value_owned = 1; + } + } + + size_t max_read = + len >= current_header->header_value_len - length_read ? current_header->header_value_len - length_read : len; + + const uint8_t *header_value_alias = current_header->header_value_type == AWS_EVENT_STREAM_HEADER_BYTE_BUF || + current_header->header_value_type == AWS_EVENT_STREAM_HEADER_STRING + ? current_header->header_value.variable_len_val + : current_header->header_value.static_val; + + memcpy((void *)(header_value_alias + length_read), data, max_read); + decoder->running_crc = aws_checksums_crc32(data, (int)max_read, decoder->running_crc); + + *processed += max_read; + decoder->message_pos += max_read; + length_read += max_read; + + if (length_read == current_header->header_value_len) { + decoder->on_header(decoder, &decoder->prelude, current_header, decoder->user_context); + s_reset_header_state(decoder, 1); + decoder->state = s_headers_state; + } + + return AWS_OP_SUCCESS; +} + +static int s_read_header_value_len( + struct aws_event_stream_streaming_decoder *decoder, + const uint8_t *data, + size_t len, + size_t *processed) { + size_t current_pos = decoder->message_pos; + + size_t length_portion_read = current_pos - decoder->current_header_value_offset; + + if (length_portion_read < sizeof(uint16_t)) { + size_t max_to_read = + len > sizeof(uint16_t) - length_portion_read ? sizeof(uint16_t) - length_portion_read : len; + memcpy(decoder->working_buffer + length_portion_read, data, max_to_read); + decoder->running_crc = aws_checksums_crc32(data, (int)max_to_read, decoder->running_crc); + + *processed += max_to_read; + decoder->message_pos += max_to_read; + + length_portion_read = decoder->message_pos - decoder->current_header_value_offset; + } + + if (length_portion_read == sizeof(uint16_t)) { + decoder->current_header.header_value_len = aws_read_u16(decoder->working_buffer); + decoder->current_header_value_offset = decoder->message_pos; + decoder->state = s_read_header_value; + } + + return AWS_OP_SUCCESS; +} + +static int s_read_header_type( + struct aws_event_stream_streaming_decoder *decoder, + const uint8_t *data, + size_t len, + size_t *processed) { + (void)len; + uint8_t type = *data; + decoder->running_crc = aws_checksums_crc32(data, 1, decoder->running_crc); + *processed += 1; + decoder->message_pos++; + decoder->current_header_value_offset++; + struct aws_event_stream_header_value_pair *current_header = &decoder->current_header; + + if (type >= AWS_EVENT_STREAM_HEADER_BOOL_FALSE && type <= AWS_EVENT_STREAM_HEADER_UUID) { + current_header->header_value_type = (enum aws_event_stream_header_value_type)type; + + switch (type) { + case AWS_EVENT_STREAM_HEADER_STRING: + case AWS_EVENT_STREAM_HEADER_BYTE_BUF: + decoder->state = s_read_header_value_len; + break; + case AWS_EVENT_STREAM_HEADER_BOOL_FALSE: + current_header->header_value_len = 0; + current_header->header_value.static_val[0] = 0; + decoder->on_header(decoder, &decoder->prelude, current_header, decoder->user_context); + s_reset_header_state(decoder, 1); + break; + case AWS_EVENT_STREAM_HEADER_BOOL_TRUE: + current_header->header_value_len = 0; + current_header->header_value.static_val[0] = 1; + decoder->on_header(decoder, &decoder->prelude, current_header, decoder->user_context); + s_reset_header_state(decoder, 1); + break; + case AWS_EVENT_STREAM_HEADER_BYTE: + current_header->header_value_len = 1; + decoder->state = s_read_header_value; + break; + case AWS_EVENT_STREAM_HEADER_INT16: + current_header->header_value_len = sizeof(uint16_t); + decoder->state = s_read_header_value; + break; + case AWS_EVENT_STREAM_HEADER_INT32: + current_header->header_value_len = sizeof(uint32_t); + decoder->state = s_read_header_value; + break; + case AWS_EVENT_STREAM_HEADER_INT64: + case AWS_EVENT_STREAM_HEADER_TIMESTAMP: + current_header->header_value_len = sizeof(uint64_t); + decoder->state = s_read_header_value; + break; + case AWS_EVENT_STREAM_HEADER_UUID: + current_header->header_value_len = 16; + decoder->state = s_read_header_value; + break; + default: + return aws_raise_error(AWS_ERROR_EVENT_STREAM_MESSAGE_UNKNOWN_HEADER_TYPE); + } + + return AWS_OP_SUCCESS; + } + + return aws_raise_error(AWS_ERROR_EVENT_STREAM_MESSAGE_UNKNOWN_HEADER_TYPE); +} + +static int s_read_header_name( + struct aws_event_stream_streaming_decoder *decoder, + const uint8_t *data, + size_t len, + size_t *processed) { + size_t current_pos = decoder->message_pos; + + size_t length_read = current_pos - decoder->current_header_name_offset; + + size_t max_read = len >= decoder->current_header.header_name_len - length_read + ? decoder->current_header.header_name_len - length_read + : len; + memcpy((void *)(decoder->current_header.header_name + length_read), data, max_read); + decoder->running_crc = aws_checksums_crc32(data, (int)max_read, decoder->running_crc); + + *processed += max_read; + decoder->message_pos += max_read; + length_read += max_read; + + if (length_read == decoder->current_header.header_name_len) { + decoder->state = s_read_header_type; + decoder->current_header_value_offset = decoder->message_pos; + } + + return AWS_OP_SUCCESS; +} + +static int s_read_header_name_len( + struct aws_event_stream_streaming_decoder *decoder, + const uint8_t *data, + size_t len, + size_t *processed) { + (void)len; + decoder->current_header.header_name_len = *data; + decoder->message_pos++; + decoder->current_header_name_offset++; + *processed += 1; + decoder->state = s_read_header_name; + decoder->running_crc = aws_checksums_crc32(data, 1, decoder->running_crc); + + return AWS_OP_SUCCESS; +} + +static int s_start_header( + struct aws_event_stream_streaming_decoder *decoder, + const uint8_t *data, + size_t len, + size_t *processed) /* NOLINT */ { + (void)data; + (void)len; + (void)processed; + decoder->state = s_read_header_name_len; + decoder->current_header_name_offset = decoder->message_pos; + + return AWS_OP_SUCCESS; +} + +static int s_payload_state( + struct aws_event_stream_streaming_decoder *decoder, + const uint8_t *data, + size_t len, + size_t *processed); + +/*Handles the initial state for header parsing. + will oscillate between multiple other states as well. + after all headers have been handled, payload will be set as the next state. */ +static int s_headers_state( + struct aws_event_stream_streaming_decoder *decoder, + const uint8_t *data, + size_t len, + size_t *processed) /* NOLINT */ { + (void)data; + (void)len; + (void)processed; + + size_t current_pos = decoder->message_pos; + + size_t headers_boundary = decoder->prelude.headers_len + AWS_EVENT_STREAM_PRELUDE_LENGTH; + + if (current_pos < headers_boundary) { + decoder->state = s_start_header; + return AWS_OP_SUCCESS; + } + + if (current_pos == headers_boundary) { + decoder->state = s_payload_state; + return AWS_OP_SUCCESS; + } + + return aws_raise_error(AWS_ERROR_EVENT_STREAM_MESSAGE_PARSER_ILLEGAL_STATE); +} + +/* handles reading the trailer. Once it has been read, it will be compared to the running checksum. If successful, + * the state will be reset. */ +static int s_read_trailer_state( + struct aws_event_stream_streaming_decoder *decoder, + const uint8_t *data, + size_t len, + size_t *processed) { + + size_t remaining_amount = decoder->prelude.total_len - decoder->message_pos; + size_t segment_length = len > remaining_amount ? remaining_amount : len; + size_t offset = sizeof(uint32_t) - remaining_amount; + memcpy(decoder->working_buffer + offset, data, segment_length); + decoder->message_pos += segment_length; + *processed += segment_length; + + if (decoder->message_pos == decoder->prelude.total_len) { + uint32_t message_crc = aws_read_u32(decoder->working_buffer); + + if (message_crc == decoder->running_crc) { + s_reset_state(decoder); + } else { + char error_message[70]; + snprintf( + error_message, + sizeof(error_message), + "CRC Mismatch. message_crc was 0x08%" PRIX32 ", but computed 0x08%" PRIX32, + message_crc, + decoder->running_crc); + aws_raise_error(AWS_ERROR_EVENT_STREAM_MESSAGE_CHECKSUM_FAILURE); + decoder->on_error( + decoder, + &decoder->prelude, + AWS_ERROR_EVENT_STREAM_MESSAGE_CHECKSUM_FAILURE, + error_message, + decoder->user_context); + return AWS_OP_ERR; + } + } + + return AWS_OP_SUCCESS; +} + +/* handles the reading of the payload up to the final checksum. Sets read_trailer_state as the new state once + * the payload has been processed. */ +static int s_payload_state( + struct aws_event_stream_streaming_decoder *decoder, + const uint8_t *data, + size_t len, + size_t *processed) { + + if (decoder->message_pos < decoder->prelude.total_len - AWS_EVENT_STREAM_TRAILER_LENGTH) { + size_t remaining_amount = decoder->prelude.total_len - decoder->message_pos - AWS_EVENT_STREAM_TRAILER_LENGTH; + size_t segment_length = len > remaining_amount ? remaining_amount : len; + int8_t final_segment = + (segment_length + decoder->message_pos) == (decoder->prelude.total_len - AWS_EVENT_STREAM_TRAILER_LENGTH); + struct aws_byte_buf payload_buf = aws_byte_buf_from_array(data, segment_length); + decoder->on_payload(decoder, &payload_buf, final_segment, decoder->user_context); + decoder->message_pos += segment_length; + decoder->running_crc = aws_checksums_crc32(data, (int)segment_length, decoder->running_crc); + *processed += segment_length; + } + + if (decoder->message_pos == decoder->prelude.total_len - AWS_EVENT_STREAM_TRAILER_LENGTH) { + decoder->state = s_read_trailer_state; + } + + return AWS_OP_SUCCESS; +} + +/* Parses the payload and verifies checksums. Sets the next state if successful. */ +static int s_verify_prelude_state( + struct aws_event_stream_streaming_decoder *decoder, + const uint8_t *data, + size_t len, + size_t *processed) /* NOLINT */ { + (void)data; + (void)len; + (void)processed; + + decoder->prelude.headers_len = aws_read_u32(decoder->working_buffer + HEADER_LEN_OFFSET); + decoder->prelude.prelude_crc = aws_read_u32(decoder->working_buffer + PRELUDE_CRC_OFFSET); + decoder->prelude.total_len = aws_read_u32(decoder->working_buffer + TOTAL_LEN_OFFSET); + + decoder->running_crc = aws_checksums_crc32(decoder->working_buffer, PRELUDE_CRC_OFFSET, 0); + + if (AWS_LIKELY(decoder->running_crc == decoder->prelude.prelude_crc)) { + + if (AWS_UNLIKELY( decoder->prelude.headers_len > AWS_EVENT_STREAM_MAX_HEADERS_SIZE || decoder->prelude.total_len > AWS_EVENT_STREAM_MAX_MESSAGE_SIZE)) { - aws_raise_error(AWS_ERROR_EVENT_STREAM_MESSAGE_FIELD_SIZE_EXCEEDED); - char error_message[] = "Maximum message field size exceeded"; - - decoder->on_error( - decoder, - &decoder->prelude, - AWS_ERROR_EVENT_STREAM_MESSAGE_FIELD_SIZE_EXCEEDED, - error_message, - decoder->user_context); - return AWS_OP_ERR; - } - + aws_raise_error(AWS_ERROR_EVENT_STREAM_MESSAGE_FIELD_SIZE_EXCEEDED); + char error_message[] = "Maximum message field size exceeded"; + + decoder->on_error( + decoder, + &decoder->prelude, + AWS_ERROR_EVENT_STREAM_MESSAGE_FIELD_SIZE_EXCEEDED, + error_message, + decoder->user_context); + return AWS_OP_ERR; + } + /* Should only call on_prelude() after passing crc check and limitation check, otherwise call on_prelude() with * incorrect prelude is error prune. */ decoder->on_prelude(decoder, &decoder->prelude, decoder->user_context); - decoder->running_crc = aws_checksums_crc32( - decoder->working_buffer + PRELUDE_CRC_OFFSET, - (int)sizeof(decoder->prelude.prelude_crc), - decoder->running_crc); - memset(decoder->working_buffer, 0, sizeof(decoder->working_buffer)); - decoder->state = decoder->prelude.headers_len > 0 ? s_headers_state : s_payload_state; - } else { - char error_message[70]; - snprintf( - error_message, - sizeof(error_message), - "CRC Mismatch. prelude_crc was 0x08%" PRIX32 ", but computed 0x08%" PRIX32, - decoder->prelude.prelude_crc, - decoder->running_crc); - - aws_raise_error(AWS_ERROR_EVENT_STREAM_PRELUDE_CHECKSUM_FAILURE); - decoder->on_error( - decoder, - &decoder->prelude, - AWS_ERROR_EVENT_STREAM_PRELUDE_CHECKSUM_FAILURE, - error_message, - decoder->user_context); - return AWS_OP_ERR; - } - - return AWS_OP_SUCCESS; -} - -/* initial state handles up to the reading of the prelude */ -static int s_start_state( - struct aws_event_stream_streaming_decoder *decoder, - const uint8_t *data, - size_t len, - size_t *processed) { - - size_t previous_position = decoder->message_pos; - if (decoder->message_pos < AWS_EVENT_STREAM_PRELUDE_LENGTH) { - if (len >= AWS_EVENT_STREAM_PRELUDE_LENGTH - decoder->message_pos) { - memcpy( - decoder->working_buffer + decoder->message_pos, - data, - AWS_EVENT_STREAM_PRELUDE_LENGTH - decoder->message_pos); - decoder->message_pos += AWS_EVENT_STREAM_PRELUDE_LENGTH - decoder->message_pos; - } else { - memcpy(decoder->working_buffer + decoder->message_pos, data, len); - decoder->message_pos += len; - } - - *processed += decoder->message_pos - previous_position; - } - - if (decoder->message_pos == AWS_EVENT_STREAM_PRELUDE_LENGTH) { - decoder->state = s_verify_prelude_state; - } - - return AWS_OP_SUCCESS; -} - -static void s_reset_state(struct aws_event_stream_streaming_decoder *decoder) { - decoder->message_pos = 0; - decoder->prelude = s_empty_prelude; - decoder->running_crc = 0; - memset(decoder->working_buffer, 0, sizeof(decoder->working_buffer)); - decoder->state = s_start_state; -} - -void aws_event_stream_streaming_decoder_init( - struct aws_event_stream_streaming_decoder *decoder, - struct aws_allocator *alloc, - aws_event_stream_process_on_payload_segment_fn *on_payload_segment, - aws_event_stream_prelude_received_fn *on_prelude, - aws_event_stream_header_received_fn *on_header, - aws_event_stream_on_error_fn *on_error, - void *user_data) { - - s_reset_state(decoder); - decoder->alloc = alloc; - decoder->on_error = on_error; - decoder->on_header = on_header; - decoder->on_payload = on_payload_segment; - decoder->on_prelude = on_prelude; - decoder->user_context = user_data; -} - -void aws_event_stream_streaming_decoder_clean_up(struct aws_event_stream_streaming_decoder *decoder) { - s_reset_state(decoder); - decoder->on_error = 0; - decoder->on_header = 0; - decoder->on_payload = 0; - decoder->on_prelude = 0; - decoder->user_context = 0; -} - -/* Simply sends the data to the state machine until all has been processed or an error is returned. */ -int aws_event_stream_streaming_decoder_pump( - struct aws_event_stream_streaming_decoder *decoder, - const struct aws_byte_buf *data) { - - size_t processed = 0; - int err_val = 0; - while (!err_val && data->buffer && data->len && processed < data->len) { - err_val = decoder->state(decoder, data->buffer + processed, data->len - processed, &processed); - } - - return err_val; -} -#if _MSC_VER -# pragma warning(pop) -#endif + decoder->running_crc = aws_checksums_crc32( + decoder->working_buffer + PRELUDE_CRC_OFFSET, + (int)sizeof(decoder->prelude.prelude_crc), + decoder->running_crc); + memset(decoder->working_buffer, 0, sizeof(decoder->working_buffer)); + decoder->state = decoder->prelude.headers_len > 0 ? s_headers_state : s_payload_state; + } else { + char error_message[70]; + snprintf( + error_message, + sizeof(error_message), + "CRC Mismatch. prelude_crc was 0x08%" PRIX32 ", but computed 0x08%" PRIX32, + decoder->prelude.prelude_crc, + decoder->running_crc); + + aws_raise_error(AWS_ERROR_EVENT_STREAM_PRELUDE_CHECKSUM_FAILURE); + decoder->on_error( + decoder, + &decoder->prelude, + AWS_ERROR_EVENT_STREAM_PRELUDE_CHECKSUM_FAILURE, + error_message, + decoder->user_context); + return AWS_OP_ERR; + } + + return AWS_OP_SUCCESS; +} + +/* initial state handles up to the reading of the prelude */ +static int s_start_state( + struct aws_event_stream_streaming_decoder *decoder, + const uint8_t *data, + size_t len, + size_t *processed) { + + size_t previous_position = decoder->message_pos; + if (decoder->message_pos < AWS_EVENT_STREAM_PRELUDE_LENGTH) { + if (len >= AWS_EVENT_STREAM_PRELUDE_LENGTH - decoder->message_pos) { + memcpy( + decoder->working_buffer + decoder->message_pos, + data, + AWS_EVENT_STREAM_PRELUDE_LENGTH - decoder->message_pos); + decoder->message_pos += AWS_EVENT_STREAM_PRELUDE_LENGTH - decoder->message_pos; + } else { + memcpy(decoder->working_buffer + decoder->message_pos, data, len); + decoder->message_pos += len; + } + + *processed += decoder->message_pos - previous_position; + } + + if (decoder->message_pos == AWS_EVENT_STREAM_PRELUDE_LENGTH) { + decoder->state = s_verify_prelude_state; + } + + return AWS_OP_SUCCESS; +} + +static void s_reset_state(struct aws_event_stream_streaming_decoder *decoder) { + decoder->message_pos = 0; + decoder->prelude = s_empty_prelude; + decoder->running_crc = 0; + memset(decoder->working_buffer, 0, sizeof(decoder->working_buffer)); + decoder->state = s_start_state; +} + +void aws_event_stream_streaming_decoder_init( + struct aws_event_stream_streaming_decoder *decoder, + struct aws_allocator *alloc, + aws_event_stream_process_on_payload_segment_fn *on_payload_segment, + aws_event_stream_prelude_received_fn *on_prelude, + aws_event_stream_header_received_fn *on_header, + aws_event_stream_on_error_fn *on_error, + void *user_data) { + + s_reset_state(decoder); + decoder->alloc = alloc; + decoder->on_error = on_error; + decoder->on_header = on_header; + decoder->on_payload = on_payload_segment; + decoder->on_prelude = on_prelude; + decoder->user_context = user_data; +} + +void aws_event_stream_streaming_decoder_clean_up(struct aws_event_stream_streaming_decoder *decoder) { + s_reset_state(decoder); + decoder->on_error = 0; + decoder->on_header = 0; + decoder->on_payload = 0; + decoder->on_prelude = 0; + decoder->user_context = 0; +} + +/* Simply sends the data to the state machine until all has been processed or an error is returned. */ +int aws_event_stream_streaming_decoder_pump( + struct aws_event_stream_streaming_decoder *decoder, + const struct aws_byte_buf *data) { + + size_t processed = 0; + int err_val = 0; + while (!err_val && data->buffer && data->len && processed < data->len) { + err_val = decoder->state(decoder, data->buffer + processed, data->len - processed, &processed); + } + + return err_val; +} +#if _MSC_VER +# pragma warning(pop) +#endif diff --git a/contrib/restricted/aws/aws-c-event-stream/ya.make b/contrib/restricted/aws/aws-c-event-stream/ya.make index d6325e058f..97058617dc 100644 --- a/contrib/restricted/aws/aws-c-event-stream/ya.make +++ b/contrib/restricted/aws/aws-c-event-stream/ya.make @@ -1,35 +1,35 @@ -# Generated by devtools/yamaker. - -LIBRARY() - +# Generated by devtools/yamaker. + +LIBRARY() + OWNER(g:cpp-contrib) - + VERSION(0.2.6) - -LICENSE(Apache-2.0) - + +LICENSE(Apache-2.0) + LICENSE_TEXTS(.yandex_meta/licenses.list.txt) -PEERDIR( +PEERDIR( contrib/restricted/aws/aws-c-common contrib/restricted/aws/aws-c-io contrib/restricted/aws/aws-checksums -) - -ADDINCL( +) + +ADDINCL( GLOBAL contrib/restricted/aws/aws-c-event-stream/include -) - -NO_COMPILER_WARNINGS() - +) + +NO_COMPILER_WARNINGS() + NO_RUNTIME() - -SRCS( - source/event_stream.c + +SRCS( + source/event_stream.c source/event_stream_channel_handler.c source/event_stream_rpc.c source/event_stream_rpc_client.c source/event_stream_rpc_server.c -) - -END() +) + +END() diff --git a/contrib/restricted/aws/aws-checksums/LICENSE b/contrib/restricted/aws/aws-checksums/LICENSE index 405c36854a..8dada3edaf 100644 --- a/contrib/restricted/aws/aws-checksums/LICENSE +++ b/contrib/restricted/aws/aws-checksums/LICENSE @@ -1,201 +1,201 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "{}" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright {yyyy} {name of copyright owner} - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "{}" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright {yyyy} {name of copyright owner} + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/contrib/restricted/aws/aws-checksums/README.md b/contrib/restricted/aws/aws-checksums/README.md index 9a93d7b35e..de0142db85 100644 --- a/contrib/restricted/aws/aws-checksums/README.md +++ b/contrib/restricted/aws/aws-checksums/README.md @@ -1,2 +1,2 @@ -# aws-checksums -Cross-Platform HW accelerated CRC32c and CRC32 with fallback to efficient SW implementations. C interface with language bindings for each of our SDKs +# aws-checksums +Cross-Platform HW accelerated CRC32c and CRC32 with fallback to efficient SW implementations. C interface with language bindings for each of our SDKs diff --git a/contrib/restricted/aws/aws-checksums/include/aws/checksums/crc.h b/contrib/restricted/aws/aws-checksums/include/aws/checksums/crc.h index 443210bb13..0bb3022e78 100644 --- a/contrib/restricted/aws/aws-checksums/include/aws/checksums/crc.h +++ b/contrib/restricted/aws/aws-checksums/include/aws/checksums/crc.h @@ -1,35 +1,35 @@ -#ifndef AWS_CHECKSUMS_CRC_H -#define AWS_CHECKSUMS_CRC_H +#ifndef AWS_CHECKSUMS_CRC_H +#define AWS_CHECKSUMS_CRC_H /** * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. - */ - -#include <aws/checksums/exports.h> -#include <stdint.h> - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * The entry point function to perform a CRC32 (Ethernet, gzip) computation. - * Selects a suitable implementation based on hardware capabilities. - * Pass 0 in the previousCrc32 parameter as an initial value unless continuing - * to update a running crc in a subsequent call. - */ -AWS_CHECKSUMS_API uint32_t aws_checksums_crc32(const uint8_t *input, int length, uint32_t previousCrc32); - -/** - * The entry point function to perform a Castagnoli CRC32c (iSCSI) computation. - * Selects a suitable implementation based on hardware capabilities. - * Pass 0 in the previousCrc32 parameter as an initial value unless continuing - * to update a running crc in a subsequent call. - */ -AWS_CHECKSUMS_API uint32_t aws_checksums_crc32c(const uint8_t *input, int length, uint32_t previousCrc32); - -#ifdef __cplusplus -} -#endif - -#endif /* AWS_CHECKSUMS_CRC_H */ + */ + +#include <aws/checksums/exports.h> +#include <stdint.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * The entry point function to perform a CRC32 (Ethernet, gzip) computation. + * Selects a suitable implementation based on hardware capabilities. + * Pass 0 in the previousCrc32 parameter as an initial value unless continuing + * to update a running crc in a subsequent call. + */ +AWS_CHECKSUMS_API uint32_t aws_checksums_crc32(const uint8_t *input, int length, uint32_t previousCrc32); + +/** + * The entry point function to perform a Castagnoli CRC32c (iSCSI) computation. + * Selects a suitable implementation based on hardware capabilities. + * Pass 0 in the previousCrc32 parameter as an initial value unless continuing + * to update a running crc in a subsequent call. + */ +AWS_CHECKSUMS_API uint32_t aws_checksums_crc32c(const uint8_t *input, int length, uint32_t previousCrc32); + +#ifdef __cplusplus +} +#endif + +#endif /* AWS_CHECKSUMS_CRC_H */ diff --git a/contrib/restricted/aws/aws-checksums/include/aws/checksums/exports.h b/contrib/restricted/aws/aws-checksums/include/aws/checksums/exports.h index b675f06f2a..a14e84e440 100644 --- a/contrib/restricted/aws/aws-checksums/include/aws/checksums/exports.h +++ b/contrib/restricted/aws/aws-checksums/include/aws/checksums/exports.h @@ -1,18 +1,18 @@ -#ifndef AWS_CHECKSUMS_EXPORTS_H -#define AWS_CHECKSUMS_EXPORTS_H +#ifndef AWS_CHECKSUMS_EXPORTS_H +#define AWS_CHECKSUMS_EXPORTS_H /** * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. - */ + */ #if defined(AWS_C_RT_USE_WINDOWS_DLL_SEMANTICS) || defined(_WIN32) # ifdef AWS_CHECKSUMS_USE_IMPORT_EXPORT -# ifdef AWS_CHECKSUMS_EXPORTS -# define AWS_CHECKSUMS_API __declspec(dllexport) -# else -# define AWS_CHECKSUMS_API __declspec(dllimport) -# endif /* AWS_CHECKSUMS_EXPORTS */ -# else -# define AWS_CHECKSUMS_API +# ifdef AWS_CHECKSUMS_EXPORTS +# define AWS_CHECKSUMS_API __declspec(dllexport) +# else +# define AWS_CHECKSUMS_API __declspec(dllimport) +# endif /* AWS_CHECKSUMS_EXPORTS */ +# else +# define AWS_CHECKSUMS_API # endif /* AWS_CHECKSUMS_USE_IMPORT_EXPORT */ #else /* defined (AWS_C_RT_USE_WINDOWS_DLL_SEMANTICS) || defined (_WIN32) */ # if ((__GNUC__ >= 4) || defined(__clang__)) && defined(AWS_CHECKSUMS_USE_IMPORT_EXPORT) && \ @@ -22,5 +22,5 @@ # define AWS_CHECKSUMS_API # endif /* __GNUC__ >= 4 || defined(__clang__) */ #endif /* defined (AWS_C_RT_USE_WINDOWS_DLL_SEMANTICS) || defined (_WIN32) */ - -#endif /* AWS_CHECKSUMS_EXPORTS_H */ + +#endif /* AWS_CHECKSUMS_EXPORTS_H */ diff --git a/contrib/restricted/aws/aws-checksums/include/aws/checksums/private/crc_priv.h b/contrib/restricted/aws/aws-checksums/include/aws/checksums/private/crc_priv.h index f5c504ee4c..221c86f9a2 100644 --- a/contrib/restricted/aws/aws-checksums/include/aws/checksums/private/crc_priv.h +++ b/contrib/restricted/aws/aws-checksums/include/aws/checksums/private/crc_priv.h @@ -1,33 +1,33 @@ -#ifndef AWS_CHECKSUMS_PRIVATE_CRC_PRIV_H -#define AWS_CHECKSUMS_PRIVATE_CRC_PRIV_H +#ifndef AWS_CHECKSUMS_PRIVATE_CRC_PRIV_H +#define AWS_CHECKSUMS_PRIVATE_CRC_PRIV_H /** * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. - */ - -#define AWS_CRC32_SIZE_BYTES 4 - -#include <aws/checksums/exports.h> -#include <stdint.h> - -#ifdef __cplusplus -extern "C" { -#endif - -/* Computes CRC32 (Ethernet, gzip, et. al.) using a (slow) reference implementation. */ -AWS_CHECKSUMS_API uint32_t aws_checksums_crc32_sw(const uint8_t *input, int length, uint32_t previousCrc32); - -/* Computes the Castagnoli CRC32c (iSCSI) using a (slow) reference implementation. */ -AWS_CHECKSUMS_API uint32_t aws_checksums_crc32c_sw(const uint8_t *input, int length, uint32_t previousCrc32c); - -/* Computes the Castagnoli CRC32c (iSCSI). */ -AWS_CHECKSUMS_API uint32_t aws_checksums_crc32c_hw(const uint8_t *data, int length, uint32_t previousCrc32); - + */ + +#define AWS_CRC32_SIZE_BYTES 4 + +#include <aws/checksums/exports.h> +#include <stdint.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/* Computes CRC32 (Ethernet, gzip, et. al.) using a (slow) reference implementation. */ +AWS_CHECKSUMS_API uint32_t aws_checksums_crc32_sw(const uint8_t *input, int length, uint32_t previousCrc32); + +/* Computes the Castagnoli CRC32c (iSCSI) using a (slow) reference implementation. */ +AWS_CHECKSUMS_API uint32_t aws_checksums_crc32c_sw(const uint8_t *input, int length, uint32_t previousCrc32c); + +/* Computes the Castagnoli CRC32c (iSCSI). */ +AWS_CHECKSUMS_API uint32_t aws_checksums_crc32c_hw(const uint8_t *data, int length, uint32_t previousCrc32); + /* Computes CRC32 (Ethernet, gzip, et. al.) using crc instructions. */ AWS_CHECKSUMS_API uint32_t aws_checksums_crc32_hw(const uint8_t *data, int length, uint32_t previousCrc32); -#ifdef __cplusplus -} -#endif - -#endif /* AWS_CHECKSUMS_PRIVATE_CRC_PRIV_H */ +#ifdef __cplusplus +} +#endif + +#endif /* AWS_CHECKSUMS_PRIVATE_CRC_PRIV_H */ diff --git a/contrib/restricted/aws/aws-checksums/source/crc.c b/contrib/restricted/aws/aws-checksums/source/crc.c index cf2f450b4d..f5d3e802fd 100644 --- a/contrib/restricted/aws/aws-checksums/source/crc.c +++ b/contrib/restricted/aws/aws-checksums/source/crc.c @@ -1,16 +1,16 @@ /** * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. - */ -#include <aws/checksums/crc.h> -#include <aws/checksums/private/crc_priv.h> - + */ +#include <aws/checksums/crc.h> +#include <aws/checksums/private/crc_priv.h> + #include <aws/common/cpuid.h> -static uint32_t (*s_crc32c_fn_ptr)(const uint8_t *input, int length, uint32_t previousCrc32) = 0; +static uint32_t (*s_crc32c_fn_ptr)(const uint8_t *input, int length, uint32_t previousCrc32) = 0; static uint32_t (*s_crc32_fn_ptr)(const uint8_t *input, int length, uint32_t previousCrc32) = 0; - -uint32_t aws_checksums_crc32(const uint8_t *input, int length, uint32_t previousCrc32) { + +uint32_t aws_checksums_crc32(const uint8_t *input, int length, uint32_t previousCrc32) { if (AWS_UNLIKELY(!s_crc32_fn_ptr)) { if (aws_cpu_has_feature(AWS_CPU_FEATURE_ARM_CRC)) { s_crc32_fn_ptr = aws_checksums_crc32_hw; @@ -19,15 +19,15 @@ uint32_t aws_checksums_crc32(const uint8_t *input, int length, uint32_t previous } } return s_crc32_fn_ptr(input, length, previousCrc32); -} - -uint32_t aws_checksums_crc32c(const uint8_t *input, int length, uint32_t previousCrc32) { +} + +uint32_t aws_checksums_crc32c(const uint8_t *input, int length, uint32_t previousCrc32) { if (AWS_UNLIKELY(!s_crc32c_fn_ptr)) { if (aws_cpu_has_feature(AWS_CPU_FEATURE_SSE_4_2) || aws_cpu_has_feature(AWS_CPU_FEATURE_ARM_CRC)) { - s_crc32c_fn_ptr = aws_checksums_crc32c_hw; - } else { - s_crc32c_fn_ptr = aws_checksums_crc32c_sw; - } - } - return s_crc32c_fn_ptr(input, length, previousCrc32); -} + s_crc32c_fn_ptr = aws_checksums_crc32c_hw; + } else { + s_crc32c_fn_ptr = aws_checksums_crc32c_sw; + } + } + return s_crc32c_fn_ptr(input, length, previousCrc32); +} diff --git a/contrib/restricted/aws/aws-checksums/source/crc_sw.c b/contrib/restricted/aws/aws-checksums/source/crc_sw.c index e61cd0e1a2..9bc326b9e8 100644 --- a/contrib/restricted/aws/aws-checksums/source/crc_sw.c +++ b/contrib/restricted/aws/aws-checksums/source/crc_sw.c @@ -1,1290 +1,1290 @@ /** * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. - */ -#include <aws/checksums/private/crc_priv.h> -#include <stddef.h> - -/* The Ethernet, gzip, et.al CRC32 polynomial (reverse of 0x04C11DB7) */ -#define CRC32_POLYNOMIAL 0xEDB88320 - -/* The Castagnoli, iSCSI CRC32c polynomial (reverse of 0x1EDC6F41) */ -#define CRC32C_POLYNOMIAL 0x82F63B78 - -/** CRC32 (Ethernet, gzip) lookup table for slice-by-4/8/16 */ -const uint32_t CRC32_TABLE[16][256] = { - { - 0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F, 0xE963A535, 0x9E6495A3, /* [0][0x08]*/ - 0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988, 0x09B64C2B, 0x7EB17CBD, 0xE7B82D07, 0x90BF1D91, /* [0][0x10]*/ - 0x1DB71064, 0x6AB020F2, 0xF3B97148, 0x84BE41DE, 0x1ADAD47D, 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7, /* [0][0x18]*/ - 0x136C9856, 0x646BA8C0, 0xFD62F97A, 0x8A65C9EC, 0x14015C4F, 0x63066CD9, 0xFA0F3D63, 0x8D080DF5, /* [0][0x20]*/ - 0x3B6E20C8, 0x4C69105E, 0xD56041E4, 0xA2677172, 0x3C03E4D1, 0x4B04D447, 0xD20D85FD, 0xA50AB56B, /* [0][0x28]*/ - 0x35B5A8FA, 0x42B2986C, 0xDBBBC9D6, 0xACBCF940, 0x32D86CE3, 0x45DF5C75, 0xDCD60DCF, 0xABD13D59, /* [0][0x30]*/ - 0x26D930AC, 0x51DE003A, 0xC8D75180, 0xBFD06116, 0x21B4F4B5, 0x56B3C423, 0xCFBA9599, 0xB8BDA50F, /* [0][0x38]*/ - 0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924, 0x2F6F7C87, 0x58684C11, 0xC1611DAB, 0xB6662D3D, /* [0][0x40]*/ - 0x76DC4190, 0x01DB7106, 0x98D220BC, 0xEFD5102A, 0x71B18589, 0x06B6B51F, 0x9FBFE4A5, 0xE8B8D433, /* [0][0x48]*/ - 0x7807C9A2, 0x0F00F934, 0x9609A88E, 0xE10E9818, 0x7F6A0DBB, 0x086D3D2D, 0x91646C97, 0xE6635C01, /* [0][0x50]*/ - 0x6B6B51F4, 0x1C6C6162, 0x856530D8, 0xF262004E, 0x6C0695ED, 0x1B01A57B, 0x8208F4C1, 0xF50FC457, /* [0][0x58]*/ - 0x65B0D9C6, 0x12B7E950, 0x8BBEB8EA, 0xFCB9887C, 0x62DD1DDF, 0x15DA2D49, 0x8CD37CF3, 0xFBD44C65, /* [0][0x60]*/ - 0x4DB26158, 0x3AB551CE, 0xA3BC0074, 0xD4BB30E2, 0x4ADFA541, 0x3DD895D7, 0xA4D1C46D, 0xD3D6F4FB, /* [0][0x68]*/ - 0x4369E96A, 0x346ED9FC, 0xAD678846, 0xDA60B8D0, 0x44042D73, 0x33031DE5, 0xAA0A4C5F, 0xDD0D7CC9, /* [0][0x70]*/ - 0x5005713C, 0x270241AA, 0xBE0B1010, 0xC90C2086, 0x5768B525, 0x206F85B3, 0xB966D409, 0xCE61E49F, /* [0][0x78]*/ - 0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4, 0x59B33D17, 0x2EB40D81, 0xB7BD5C3B, 0xC0BA6CAD, /* [0][0x80]*/ - 0xEDB88320, 0x9ABFB3B6, 0x03B6E20C, 0x74B1D29A, 0xEAD54739, 0x9DD277AF, 0x04DB2615, 0x73DC1683, /* [0][0x88]*/ - 0xE3630B12, 0x94643B84, 0x0D6D6A3E, 0x7A6A5AA8, 0xE40ECF0B, 0x9309FF9D, 0x0A00AE27, 0x7D079EB1, /* [0][0x90]*/ - 0xF00F9344, 0x8708A3D2, 0x1E01F268, 0x6906C2FE, 0xF762575D, 0x806567CB, 0x196C3671, 0x6E6B06E7, /* [0][0x98]*/ - 0xFED41B76, 0x89D32BE0, 0x10DA7A5A, 0x67DD4ACC, 0xF9B9DF6F, 0x8EBEEFF9, 0x17B7BE43, 0x60B08ED5, /* [0][0xa0]*/ - 0xD6D6A3E8, 0xA1D1937E, 0x38D8C2C4, 0x4FDFF252, 0xD1BB67F1, 0xA6BC5767, 0x3FB506DD, 0x48B2364B, /* [0][0xa8]*/ - 0xD80D2BDA, 0xAF0A1B4C, 0x36034AF6, 0x41047A60, 0xDF60EFC3, 0xA867DF55, 0x316E8EEF, 0x4669BE79, /* [0][0xb0]*/ - 0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236, 0xCC0C7795, 0xBB0B4703, 0x220216B9, 0x5505262F, /* [0][0xb8]*/ - 0xC5BA3BBE, 0xB2BD0B28, 0x2BB45A92, 0x5CB36A04, 0xC2D7FFA7, 0xB5D0CF31, 0x2CD99E8B, 0x5BDEAE1D, /* [0][0xc0]*/ - 0x9B64C2B0, 0xEC63F226, 0x756AA39C, 0x026D930A, 0x9C0906A9, 0xEB0E363F, 0x72076785, 0x05005713, /* [0][0xc8]*/ - 0x95BF4A82, 0xE2B87A14, 0x7BB12BAE, 0x0CB61B38, 0x92D28E9B, 0xE5D5BE0D, 0x7CDCEFB7, 0x0BDBDF21, /* [0][0xd0]*/ - 0x86D3D2D4, 0xF1D4E242, 0x68DDB3F8, 0x1FDA836E, 0x81BE16CD, 0xF6B9265B, 0x6FB077E1, 0x18B74777, /* [0][0xd8]*/ - 0x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C, 0x8F659EFF, 0xF862AE69, 0x616BFFD3, 0x166CCF45, /* [0][0xe0]*/ - 0xA00AE278, 0xD70DD2EE, 0x4E048354, 0x3903B3C2, 0xA7672661, 0xD06016F7, 0x4969474D, 0x3E6E77DB, /* [0][0xe8]*/ - 0xAED16A4A, 0xD9D65ADC, 0x40DF0B66, 0x37D83BF0, 0xA9BCAE53, 0xDEBB9EC5, 0x47B2CF7F, 0x30B5FFE9, /* [0][0xf0]*/ - 0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6, 0xBAD03605, 0xCDD70693, 0x54DE5729, 0x23D967BF, /* [0][0xf8]*/ - 0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94, 0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D /* [0][0x100]*/ - }, - { - 0x00000000, 0x191B3141, 0x32366282, 0x2B2D53C3, 0x646CC504, 0x7D77F445, 0x565AA786, 0x4F4196C7, /* [1][0x08]*/ - 0xC8D98A08, 0xD1C2BB49, 0xFAEFE88A, 0xE3F4D9CB, 0xACB54F0C, 0xB5AE7E4D, 0x9E832D8E, 0x87981CCF, /* [1][0x10]*/ - 0x4AC21251, 0x53D92310, 0x78F470D3, 0x61EF4192, 0x2EAED755, 0x37B5E614, 0x1C98B5D7, 0x05838496, /* [1][0x18]*/ - 0x821B9859, 0x9B00A918, 0xB02DFADB, 0xA936CB9A, 0xE6775D5D, 0xFF6C6C1C, 0xD4413FDF, 0xCD5A0E9E, /* [1][0x20]*/ - 0x958424A2, 0x8C9F15E3, 0xA7B24620, 0xBEA97761, 0xF1E8E1A6, 0xE8F3D0E7, 0xC3DE8324, 0xDAC5B265, /* [1][0x28]*/ - 0x5D5DAEAA, 0x44469FEB, 0x6F6BCC28, 0x7670FD69, 0x39316BAE, 0x202A5AEF, 0x0B07092C, 0x121C386D, /* [1][0x30]*/ - 0xDF4636F3, 0xC65D07B2, 0xED705471, 0xF46B6530, 0xBB2AF3F7, 0xA231C2B6, 0x891C9175, 0x9007A034, /* [1][0x38]*/ - 0x179FBCFB, 0x0E848DBA, 0x25A9DE79, 0x3CB2EF38, 0x73F379FF, 0x6AE848BE, 0x41C51B7D, 0x58DE2A3C, /* [1][0x40]*/ - 0xF0794F05, 0xE9627E44, 0xC24F2D87, 0xDB541CC6, 0x94158A01, 0x8D0EBB40, 0xA623E883, 0xBF38D9C2, /* [1][0x48]*/ - 0x38A0C50D, 0x21BBF44C, 0x0A96A78F, 0x138D96CE, 0x5CCC0009, 0x45D73148, 0x6EFA628B, 0x77E153CA, /* [1][0x50]*/ - 0xBABB5D54, 0xA3A06C15, 0x888D3FD6, 0x91960E97, 0xDED79850, 0xC7CCA911, 0xECE1FAD2, 0xF5FACB93, /* [1][0x58]*/ - 0x7262D75C, 0x6B79E61D, 0x4054B5DE, 0x594F849F, 0x160E1258, 0x0F152319, 0x243870DA, 0x3D23419B, /* [1][0x60]*/ - 0x65FD6BA7, 0x7CE65AE6, 0x57CB0925, 0x4ED03864, 0x0191AEA3, 0x188A9FE2, 0x33A7CC21, 0x2ABCFD60, /* [1][0x68]*/ - 0xAD24E1AF, 0xB43FD0EE, 0x9F12832D, 0x8609B26C, 0xC94824AB, 0xD05315EA, 0xFB7E4629, 0xE2657768, /* [1][0x70]*/ - 0x2F3F79F6, 0x362448B7, 0x1D091B74, 0x04122A35, 0x4B53BCF2, 0x52488DB3, 0x7965DE70, 0x607EEF31, /* [1][0x78]*/ - 0xE7E6F3FE, 0xFEFDC2BF, 0xD5D0917C, 0xCCCBA03D, 0x838A36FA, 0x9A9107BB, 0xB1BC5478, 0xA8A76539, /* [1][0x80]*/ - 0x3B83984B, 0x2298A90A, 0x09B5FAC9, 0x10AECB88, 0x5FEF5D4F, 0x46F46C0E, 0x6DD93FCD, 0x74C20E8C, /* [1][0x88]*/ - 0xF35A1243, 0xEA412302, 0xC16C70C1, 0xD8774180, 0x9736D747, 0x8E2DE606, 0xA500B5C5, 0xBC1B8484, /* [1][0x90]*/ - 0x71418A1A, 0x685ABB5B, 0x4377E898, 0x5A6CD9D9, 0x152D4F1E, 0x0C367E5F, 0x271B2D9C, 0x3E001CDD, /* [1][0x98]*/ - 0xB9980012, 0xA0833153, 0x8BAE6290, 0x92B553D1, 0xDDF4C516, 0xC4EFF457, 0xEFC2A794, 0xF6D996D5, /* [1][0xa0]*/ - 0xAE07BCE9, 0xB71C8DA8, 0x9C31DE6B, 0x852AEF2A, 0xCA6B79ED, 0xD37048AC, 0xF85D1B6F, 0xE1462A2E, /* [1][0xa8]*/ - 0x66DE36E1, 0x7FC507A0, 0x54E85463, 0x4DF36522, 0x02B2F3E5, 0x1BA9C2A4, 0x30849167, 0x299FA026, /* [1][0xb0]*/ - 0xE4C5AEB8, 0xFDDE9FF9, 0xD6F3CC3A, 0xCFE8FD7B, 0x80A96BBC, 0x99B25AFD, 0xB29F093E, 0xAB84387F, /* [1][0xb8]*/ - 0x2C1C24B0, 0x350715F1, 0x1E2A4632, 0x07317773, 0x4870E1B4, 0x516BD0F5, 0x7A468336, 0x635DB277, /* [1][0xc0]*/ - 0xCBFAD74E, 0xD2E1E60F, 0xF9CCB5CC, 0xE0D7848D, 0xAF96124A, 0xB68D230B, 0x9DA070C8, 0x84BB4189, /* [1][0xc8]*/ - 0x03235D46, 0x1A386C07, 0x31153FC4, 0x280E0E85, 0x674F9842, 0x7E54A903, 0x5579FAC0, 0x4C62CB81, /* [1][0xd0]*/ - 0x8138C51F, 0x9823F45E, 0xB30EA79D, 0xAA1596DC, 0xE554001B, 0xFC4F315A, 0xD7626299, 0xCE7953D8, /* [1][0xd8]*/ - 0x49E14F17, 0x50FA7E56, 0x7BD72D95, 0x62CC1CD4, 0x2D8D8A13, 0x3496BB52, 0x1FBBE891, 0x06A0D9D0, /* [1][0xe0]*/ - 0x5E7EF3EC, 0x4765C2AD, 0x6C48916E, 0x7553A02F, 0x3A1236E8, 0x230907A9, 0x0824546A, 0x113F652B, /* [1][0xe8]*/ - 0x96A779E4, 0x8FBC48A5, 0xA4911B66, 0xBD8A2A27, 0xF2CBBCE0, 0xEBD08DA1, 0xC0FDDE62, 0xD9E6EF23, /* [1][0xf0]*/ - 0x14BCE1BD, 0x0DA7D0FC, 0x268A833F, 0x3F91B27E, 0x70D024B9, 0x69CB15F8, 0x42E6463B, 0x5BFD777A, /* [1][0xf8]*/ - 0xDC656BB5, 0xC57E5AF4, 0xEE530937, 0xF7483876, 0xB809AEB1, 0xA1129FF0, 0x8A3FCC33, 0x9324FD72 /* [1][0x100]*/ - }, - { - 0x00000000, 0x01C26A37, 0x0384D46E, 0x0246BE59, 0x0709A8DC, 0x06CBC2EB, 0x048D7CB2, 0x054F1685, /* [2][0x08]*/ - 0x0E1351B8, 0x0FD13B8F, 0x0D9785D6, 0x0C55EFE1, 0x091AF964, 0x08D89353, 0x0A9E2D0A, 0x0B5C473D, /* [2][0x10]*/ - 0x1C26A370, 0x1DE4C947, 0x1FA2771E, 0x1E601D29, 0x1B2F0BAC, 0x1AED619B, 0x18ABDFC2, 0x1969B5F5, /* [2][0x18]*/ - 0x1235F2C8, 0x13F798FF, 0x11B126A6, 0x10734C91, 0x153C5A14, 0x14FE3023, 0x16B88E7A, 0x177AE44D, /* [2][0x20]*/ - 0x384D46E0, 0x398F2CD7, 0x3BC9928E, 0x3A0BF8B9, 0x3F44EE3C, 0x3E86840B, 0x3CC03A52, 0x3D025065, /* [2][0x28]*/ - 0x365E1758, 0x379C7D6F, 0x35DAC336, 0x3418A901, 0x3157BF84, 0x3095D5B3, 0x32D36BEA, 0x331101DD, /* [2][0x30]*/ - 0x246BE590, 0x25A98FA7, 0x27EF31FE, 0x262D5BC9, 0x23624D4C, 0x22A0277B, 0x20E69922, 0x2124F315, /* [2][0x38]*/ - 0x2A78B428, 0x2BBADE1F, 0x29FC6046, 0x283E0A71, 0x2D711CF4, 0x2CB376C3, 0x2EF5C89A, 0x2F37A2AD, /* [2][0x40]*/ - 0x709A8DC0, 0x7158E7F7, 0x731E59AE, 0x72DC3399, 0x7793251C, 0x76514F2B, 0x7417F172, 0x75D59B45, /* [2][0x48]*/ - 0x7E89DC78, 0x7F4BB64F, 0x7D0D0816, 0x7CCF6221, 0x798074A4, 0x78421E93, 0x7A04A0CA, 0x7BC6CAFD, /* [2][0x50]*/ - 0x6CBC2EB0, 0x6D7E4487, 0x6F38FADE, 0x6EFA90E9, 0x6BB5866C, 0x6A77EC5B, 0x68315202, 0x69F33835, /* [2][0x58]*/ - 0x62AF7F08, 0x636D153F, 0x612BAB66, 0x60E9C151, 0x65A6D7D4, 0x6464BDE3, 0x662203BA, 0x67E0698D, /* [2][0x60]*/ - 0x48D7CB20, 0x4915A117, 0x4B531F4E, 0x4A917579, 0x4FDE63FC, 0x4E1C09CB, 0x4C5AB792, 0x4D98DDA5, /* [2][0x68]*/ - 0x46C49A98, 0x4706F0AF, 0x45404EF6, 0x448224C1, 0x41CD3244, 0x400F5873, 0x4249E62A, 0x438B8C1D, /* [2][0x70]*/ - 0x54F16850, 0x55330267, 0x5775BC3E, 0x56B7D609, 0x53F8C08C, 0x523AAABB, 0x507C14E2, 0x51BE7ED5, /* [2][0x78]*/ - 0x5AE239E8, 0x5B2053DF, 0x5966ED86, 0x58A487B1, 0x5DEB9134, 0x5C29FB03, 0x5E6F455A, 0x5FAD2F6D, /* [2][0x80]*/ - 0xE1351B80, 0xE0F771B7, 0xE2B1CFEE, 0xE373A5D9, 0xE63CB35C, 0xE7FED96B, 0xE5B86732, 0xE47A0D05, /* [2][0x88]*/ - 0xEF264A38, 0xEEE4200F, 0xECA29E56, 0xED60F461, 0xE82FE2E4, 0xE9ED88D3, 0xEBAB368A, 0xEA695CBD, /* [2][0x90]*/ - 0xFD13B8F0, 0xFCD1D2C7, 0xFE976C9E, 0xFF5506A9, 0xFA1A102C, 0xFBD87A1B, 0xF99EC442, 0xF85CAE75, /* [2][0x98]*/ - 0xF300E948, 0xF2C2837F, 0xF0843D26, 0xF1465711, 0xF4094194, 0xF5CB2BA3, 0xF78D95FA, 0xF64FFFCD, /* [2][0xa0]*/ - 0xD9785D60, 0xD8BA3757, 0xDAFC890E, 0xDB3EE339, 0xDE71F5BC, 0xDFB39F8B, 0xDDF521D2, 0xDC374BE5, /* [2][0xa8]*/ - 0xD76B0CD8, 0xD6A966EF, 0xD4EFD8B6, 0xD52DB281, 0xD062A404, 0xD1A0CE33, 0xD3E6706A, 0xD2241A5D, /* [2][0xb0]*/ - 0xC55EFE10, 0xC49C9427, 0xC6DA2A7E, 0xC7184049, 0xC25756CC, 0xC3953CFB, 0xC1D382A2, 0xC011E895, /* [2][0xb8]*/ - 0xCB4DAFA8, 0xCA8FC59F, 0xC8C97BC6, 0xC90B11F1, 0xCC440774, 0xCD866D43, 0xCFC0D31A, 0xCE02B92D, /* [2][0xc0]*/ - 0x91AF9640, 0x906DFC77, 0x922B422E, 0x93E92819, 0x96A63E9C, 0x976454AB, 0x9522EAF2, 0x94E080C5, /* [2][0xc8]*/ - 0x9FBCC7F8, 0x9E7EADCF, 0x9C381396, 0x9DFA79A1, 0x98B56F24, 0x99770513, 0x9B31BB4A, 0x9AF3D17D, /* [2][0xd0]*/ - 0x8D893530, 0x8C4B5F07, 0x8E0DE15E, 0x8FCF8B69, 0x8A809DEC, 0x8B42F7DB, 0x89044982, 0x88C623B5, /* [2][0xd8]*/ - 0x839A6488, 0x82580EBF, 0x801EB0E6, 0x81DCDAD1, 0x8493CC54, 0x8551A663, 0x8717183A, 0x86D5720D, /* [2][0xe0]*/ - 0xA9E2D0A0, 0xA820BA97, 0xAA6604CE, 0xABA46EF9, 0xAEEB787C, 0xAF29124B, 0xAD6FAC12, 0xACADC625, /* [2][0xe8]*/ - 0xA7F18118, 0xA633EB2F, 0xA4755576, 0xA5B73F41, 0xA0F829C4, 0xA13A43F3, 0xA37CFDAA, 0xA2BE979D, /* [2][0xf0]*/ - 0xB5C473D0, 0xB40619E7, 0xB640A7BE, 0xB782CD89, 0xB2CDDB0C, 0xB30FB13B, 0xB1490F62, 0xB08B6555, /* [2][0xf8]*/ - 0xBBD72268, 0xBA15485F, 0xB853F606, 0xB9919C31, 0xBCDE8AB4, 0xBD1CE083, 0xBF5A5EDA, 0xBE9834ED /* [2][0x100]*/ - }, - { - 0x00000000, 0xB8BC6765, 0xAA09C88B, 0x12B5AFEE, 0x8F629757, 0x37DEF032, 0x256B5FDC, 0x9DD738B9, /* [3][0x08]*/ - 0xC5B428EF, 0x7D084F8A, 0x6FBDE064, 0xD7018701, 0x4AD6BFB8, 0xF26AD8DD, 0xE0DF7733, 0x58631056, /* [3][0x10]*/ - 0x5019579F, 0xE8A530FA, 0xFA109F14, 0x42ACF871, 0xDF7BC0C8, 0x67C7A7AD, 0x75720843, 0xCDCE6F26, /* [3][0x18]*/ - 0x95AD7F70, 0x2D111815, 0x3FA4B7FB, 0x8718D09E, 0x1ACFE827, 0xA2738F42, 0xB0C620AC, 0x087A47C9, /* [3][0x20]*/ - 0xA032AF3E, 0x188EC85B, 0x0A3B67B5, 0xB28700D0, 0x2F503869, 0x97EC5F0C, 0x8559F0E2, 0x3DE59787, /* [3][0x28]*/ - 0x658687D1, 0xDD3AE0B4, 0xCF8F4F5A, 0x7733283F, 0xEAE41086, 0x525877E3, 0x40EDD80D, 0xF851BF68, /* [3][0x30]*/ - 0xF02BF8A1, 0x48979FC4, 0x5A22302A, 0xE29E574F, 0x7F496FF6, 0xC7F50893, 0xD540A77D, 0x6DFCC018, /* [3][0x38]*/ - 0x359FD04E, 0x8D23B72B, 0x9F9618C5, 0x272A7FA0, 0xBAFD4719, 0x0241207C, 0x10F48F92, 0xA848E8F7, /* [3][0x40]*/ - 0x9B14583D, 0x23A83F58, 0x311D90B6, 0x89A1F7D3, 0x1476CF6A, 0xACCAA80F, 0xBE7F07E1, 0x06C36084, /* [3][0x48]*/ - 0x5EA070D2, 0xE61C17B7, 0xF4A9B859, 0x4C15DF3C, 0xD1C2E785, 0x697E80E0, 0x7BCB2F0E, 0xC377486B, /* [3][0x50]*/ - 0xCB0D0FA2, 0x73B168C7, 0x6104C729, 0xD9B8A04C, 0x446F98F5, 0xFCD3FF90, 0xEE66507E, 0x56DA371B, /* [3][0x58]*/ - 0x0EB9274D, 0xB6054028, 0xA4B0EFC6, 0x1C0C88A3, 0x81DBB01A, 0x3967D77F, 0x2BD27891, 0x936E1FF4, /* [3][0x60]*/ - 0x3B26F703, 0x839A9066, 0x912F3F88, 0x299358ED, 0xB4446054, 0x0CF80731, 0x1E4DA8DF, 0xA6F1CFBA, /* [3][0x68]*/ - 0xFE92DFEC, 0x462EB889, 0x549B1767, 0xEC277002, 0x71F048BB, 0xC94C2FDE, 0xDBF98030, 0x6345E755, /* [3][0x70]*/ - 0x6B3FA09C, 0xD383C7F9, 0xC1366817, 0x798A0F72, 0xE45D37CB, 0x5CE150AE, 0x4E54FF40, 0xF6E89825, /* [3][0x78]*/ - 0xAE8B8873, 0x1637EF16, 0x048240F8, 0xBC3E279D, 0x21E91F24, 0x99557841, 0x8BE0D7AF, 0x335CB0CA, /* [3][0x80]*/ - 0xED59B63B, 0x55E5D15E, 0x47507EB0, 0xFFEC19D5, 0x623B216C, 0xDA874609, 0xC832E9E7, 0x708E8E82, /* [3][0x88]*/ - 0x28ED9ED4, 0x9051F9B1, 0x82E4565F, 0x3A58313A, 0xA78F0983, 0x1F336EE6, 0x0D86C108, 0xB53AA66D, /* [3][0x90]*/ - 0xBD40E1A4, 0x05FC86C1, 0x1749292F, 0xAFF54E4A, 0x322276F3, 0x8A9E1196, 0x982BBE78, 0x2097D91D, /* [3][0x98]*/ - 0x78F4C94B, 0xC048AE2E, 0xD2FD01C0, 0x6A4166A5, 0xF7965E1C, 0x4F2A3979, 0x5D9F9697, 0xE523F1F2, /* [3][0xa0]*/ - 0x4D6B1905, 0xF5D77E60, 0xE762D18E, 0x5FDEB6EB, 0xC2098E52, 0x7AB5E937, 0x680046D9, 0xD0BC21BC, /* [3][0xa8]*/ - 0x88DF31EA, 0x3063568F, 0x22D6F961, 0x9A6A9E04, 0x07BDA6BD, 0xBF01C1D8, 0xADB46E36, 0x15080953, /* [3][0xb0]*/ - 0x1D724E9A, 0xA5CE29FF, 0xB77B8611, 0x0FC7E174, 0x9210D9CD, 0x2AACBEA8, 0x38191146, 0x80A57623, /* [3][0xb8]*/ - 0xD8C66675, 0x607A0110, 0x72CFAEFE, 0xCA73C99B, 0x57A4F122, 0xEF189647, 0xFDAD39A9, 0x45115ECC, /* [3][0xc0]*/ - 0x764DEE06, 0xCEF18963, 0xDC44268D, 0x64F841E8, 0xF92F7951, 0x41931E34, 0x5326B1DA, 0xEB9AD6BF, /* [3][0xc8]*/ - 0xB3F9C6E9, 0x0B45A18C, 0x19F00E62, 0xA14C6907, 0x3C9B51BE, 0x842736DB, 0x96929935, 0x2E2EFE50, /* [3][0xd0]*/ - 0x2654B999, 0x9EE8DEFC, 0x8C5D7112, 0x34E11677, 0xA9362ECE, 0x118A49AB, 0x033FE645, 0xBB838120, /* [3][0xd8]*/ - 0xE3E09176, 0x5B5CF613, 0x49E959FD, 0xF1553E98, 0x6C820621, 0xD43E6144, 0xC68BCEAA, 0x7E37A9CF, /* [3][0xe0]*/ - 0xD67F4138, 0x6EC3265D, 0x7C7689B3, 0xC4CAEED6, 0x591DD66F, 0xE1A1B10A, 0xF3141EE4, 0x4BA87981, /* [3][0xe8]*/ - 0x13CB69D7, 0xAB770EB2, 0xB9C2A15C, 0x017EC639, 0x9CA9FE80, 0x241599E5, 0x36A0360B, 0x8E1C516E, /* [3][0xf0]*/ - 0x866616A7, 0x3EDA71C2, 0x2C6FDE2C, 0x94D3B949, 0x090481F0, 0xB1B8E695, 0xA30D497B, 0x1BB12E1E, /* [3][0xf8]*/ - 0x43D23E48, 0xFB6E592D, 0xE9DBF6C3, 0x516791A6, 0xCCB0A91F, 0x740CCE7A, 0x66B96194, 0xDE0506F1 /* [3][0x100]*/ - }, - { - 0x00000000, 0x3D6029B0, 0x7AC05360, 0x47A07AD0, 0xF580A6C0, 0xC8E08F70, 0x8F40F5A0, 0xB220DC10, /* [4][0x08]*/ - 0x30704BC1, 0x0D106271, 0x4AB018A1, 0x77D03111, 0xC5F0ED01, 0xF890C4B1, 0xBF30BE61, 0x825097D1, /* [4][0x10]*/ - 0x60E09782, 0x5D80BE32, 0x1A20C4E2, 0x2740ED52, 0x95603142, 0xA80018F2, 0xEFA06222, 0xD2C04B92, /* [4][0x18]*/ - 0x5090DC43, 0x6DF0F5F3, 0x2A508F23, 0x1730A693, 0xA5107A83, 0x98705333, 0xDFD029E3, 0xE2B00053, /* [4][0x20]*/ - 0xC1C12F04, 0xFCA106B4, 0xBB017C64, 0x866155D4, 0x344189C4, 0x0921A074, 0x4E81DAA4, 0x73E1F314, /* [4][0x28]*/ - 0xF1B164C5, 0xCCD14D75, 0x8B7137A5, 0xB6111E15, 0x0431C205, 0x3951EBB5, 0x7EF19165, 0x4391B8D5, /* [4][0x30]*/ - 0xA121B886, 0x9C419136, 0xDBE1EBE6, 0xE681C256, 0x54A11E46, 0x69C137F6, 0x2E614D26, 0x13016496, /* [4][0x38]*/ - 0x9151F347, 0xAC31DAF7, 0xEB91A027, 0xD6F18997, 0x64D15587, 0x59B17C37, 0x1E1106E7, 0x23712F57, /* [4][0x40]*/ - 0x58F35849, 0x659371F9, 0x22330B29, 0x1F532299, 0xAD73FE89, 0x9013D739, 0xD7B3ADE9, 0xEAD38459, /* [4][0x48]*/ - 0x68831388, 0x55E33A38, 0x124340E8, 0x2F236958, 0x9D03B548, 0xA0639CF8, 0xE7C3E628, 0xDAA3CF98, /* [4][0x50]*/ - 0x3813CFCB, 0x0573E67B, 0x42D39CAB, 0x7FB3B51B, 0xCD93690B, 0xF0F340BB, 0xB7533A6B, 0x8A3313DB, /* [4][0x58]*/ - 0x0863840A, 0x3503ADBA, 0x72A3D76A, 0x4FC3FEDA, 0xFDE322CA, 0xC0830B7A, 0x872371AA, 0xBA43581A, /* [4][0x60]*/ - 0x9932774D, 0xA4525EFD, 0xE3F2242D, 0xDE920D9D, 0x6CB2D18D, 0x51D2F83D, 0x167282ED, 0x2B12AB5D, /* [4][0x68]*/ - 0xA9423C8C, 0x9422153C, 0xD3826FEC, 0xEEE2465C, 0x5CC29A4C, 0x61A2B3FC, 0x2602C92C, 0x1B62E09C, /* [4][0x70]*/ - 0xF9D2E0CF, 0xC4B2C97F, 0x8312B3AF, 0xBE729A1F, 0x0C52460F, 0x31326FBF, 0x7692156F, 0x4BF23CDF, /* [4][0x78]*/ - 0xC9A2AB0E, 0xF4C282BE, 0xB362F86E, 0x8E02D1DE, 0x3C220DCE, 0x0142247E, 0x46E25EAE, 0x7B82771E, /* [4][0x80]*/ - 0xB1E6B092, 0x8C869922, 0xCB26E3F2, 0xF646CA42, 0x44661652, 0x79063FE2, 0x3EA64532, 0x03C66C82, /* [4][0x88]*/ - 0x8196FB53, 0xBCF6D2E3, 0xFB56A833, 0xC6368183, 0x74165D93, 0x49767423, 0x0ED60EF3, 0x33B62743, /* [4][0x90]*/ - 0xD1062710, 0xEC660EA0, 0xABC67470, 0x96A65DC0, 0x248681D0, 0x19E6A860, 0x5E46D2B0, 0x6326FB00, /* [4][0x98]*/ - 0xE1766CD1, 0xDC164561, 0x9BB63FB1, 0xA6D61601, 0x14F6CA11, 0x2996E3A1, 0x6E369971, 0x5356B0C1, /* [4][0xa0]*/ - 0x70279F96, 0x4D47B626, 0x0AE7CCF6, 0x3787E546, 0x85A73956, 0xB8C710E6, 0xFF676A36, 0xC2074386, /* [4][0xa8]*/ - 0x4057D457, 0x7D37FDE7, 0x3A978737, 0x07F7AE87, 0xB5D77297, 0x88B75B27, 0xCF1721F7, 0xF2770847, /* [4][0xb0]*/ - 0x10C70814, 0x2DA721A4, 0x6A075B74, 0x576772C4, 0xE547AED4, 0xD8278764, 0x9F87FDB4, 0xA2E7D404, /* [4][0xb8]*/ - 0x20B743D5, 0x1DD76A65, 0x5A7710B5, 0x67173905, 0xD537E515, 0xE857CCA5, 0xAFF7B675, 0x92979FC5, /* [4][0xc0]*/ - 0xE915E8DB, 0xD475C16B, 0x93D5BBBB, 0xAEB5920B, 0x1C954E1B, 0x21F567AB, 0x66551D7B, 0x5B3534CB, /* [4][0xc8]*/ - 0xD965A31A, 0xE4058AAA, 0xA3A5F07A, 0x9EC5D9CA, 0x2CE505DA, 0x11852C6A, 0x562556BA, 0x6B457F0A, /* [4][0xd0]*/ - 0x89F57F59, 0xB49556E9, 0xF3352C39, 0xCE550589, 0x7C75D999, 0x4115F029, 0x06B58AF9, 0x3BD5A349, /* [4][0xd8]*/ - 0xB9853498, 0x84E51D28, 0xC34567F8, 0xFE254E48, 0x4C059258, 0x7165BBE8, 0x36C5C138, 0x0BA5E888, /* [4][0xe0]*/ - 0x28D4C7DF, 0x15B4EE6F, 0x521494BF, 0x6F74BD0F, 0xDD54611F, 0xE03448AF, 0xA794327F, 0x9AF41BCF, /* [4][0xe8]*/ - 0x18A48C1E, 0x25C4A5AE, 0x6264DF7E, 0x5F04F6CE, 0xED242ADE, 0xD044036E, 0x97E479BE, 0xAA84500E, /* [4][0xf0]*/ - 0x4834505D, 0x755479ED, 0x32F4033D, 0x0F942A8D, 0xBDB4F69D, 0x80D4DF2D, 0xC774A5FD, 0xFA148C4D, /* [4][0xf8]*/ - 0x78441B9C, 0x4524322C, 0x028448FC, 0x3FE4614C, 0x8DC4BD5C, 0xB0A494EC, 0xF704EE3C, 0xCA64C78C /* [4][0x100]*/ - }, - { - 0x00000000, 0xCB5CD3A5, 0x4DC8A10B, 0x869472AE, 0x9B914216, 0x50CD91B3, 0xD659E31D, 0x1D0530B8, /* [5][0x08]*/ - 0xEC53826D, 0x270F51C8, 0xA19B2366, 0x6AC7F0C3, 0x77C2C07B, 0xBC9E13DE, 0x3A0A6170, 0xF156B2D5, /* [5][0x10]*/ - 0x03D6029B, 0xC88AD13E, 0x4E1EA390, 0x85427035, 0x9847408D, 0x531B9328, 0xD58FE186, 0x1ED33223, /* [5][0x18]*/ - 0xEF8580F6, 0x24D95353, 0xA24D21FD, 0x6911F258, 0x7414C2E0, 0xBF481145, 0x39DC63EB, 0xF280B04E, /* [5][0x20]*/ - 0x07AC0536, 0xCCF0D693, 0x4A64A43D, 0x81387798, 0x9C3D4720, 0x57619485, 0xD1F5E62B, 0x1AA9358E, /* [5][0x28]*/ - 0xEBFF875B, 0x20A354FE, 0xA6372650, 0x6D6BF5F5, 0x706EC54D, 0xBB3216E8, 0x3DA66446, 0xF6FAB7E3, /* [5][0x30]*/ - 0x047A07AD, 0xCF26D408, 0x49B2A6A6, 0x82EE7503, 0x9FEB45BB, 0x54B7961E, 0xD223E4B0, 0x197F3715, /* [5][0x38]*/ - 0xE82985C0, 0x23755665, 0xA5E124CB, 0x6EBDF76E, 0x73B8C7D6, 0xB8E41473, 0x3E7066DD, 0xF52CB578, /* [5][0x40]*/ - 0x0F580A6C, 0xC404D9C9, 0x4290AB67, 0x89CC78C2, 0x94C9487A, 0x5F959BDF, 0xD901E971, 0x125D3AD4, /* [5][0x48]*/ - 0xE30B8801, 0x28575BA4, 0xAEC3290A, 0x659FFAAF, 0x789ACA17, 0xB3C619B2, 0x35526B1C, 0xFE0EB8B9, /* [5][0x50]*/ - 0x0C8E08F7, 0xC7D2DB52, 0x4146A9FC, 0x8A1A7A59, 0x971F4AE1, 0x5C439944, 0xDAD7EBEA, 0x118B384F, /* [5][0x58]*/ - 0xE0DD8A9A, 0x2B81593F, 0xAD152B91, 0x6649F834, 0x7B4CC88C, 0xB0101B29, 0x36846987, 0xFDD8BA22, /* [5][0x60]*/ - 0x08F40F5A, 0xC3A8DCFF, 0x453CAE51, 0x8E607DF4, 0x93654D4C, 0x58399EE9, 0xDEADEC47, 0x15F13FE2, /* [5][0x68]*/ - 0xE4A78D37, 0x2FFB5E92, 0xA96F2C3C, 0x6233FF99, 0x7F36CF21, 0xB46A1C84, 0x32FE6E2A, 0xF9A2BD8F, /* [5][0x70]*/ - 0x0B220DC1, 0xC07EDE64, 0x46EAACCA, 0x8DB67F6F, 0x90B34FD7, 0x5BEF9C72, 0xDD7BEEDC, 0x16273D79, /* [5][0x78]*/ - 0xE7718FAC, 0x2C2D5C09, 0xAAB92EA7, 0x61E5FD02, 0x7CE0CDBA, 0xB7BC1E1F, 0x31286CB1, 0xFA74BF14, /* [5][0x80]*/ - 0x1EB014D8, 0xD5ECC77D, 0x5378B5D3, 0x98246676, 0x852156CE, 0x4E7D856B, 0xC8E9F7C5, 0x03B52460, /* [5][0x88]*/ - 0xF2E396B5, 0x39BF4510, 0xBF2B37BE, 0x7477E41B, 0x6972D4A3, 0xA22E0706, 0x24BA75A8, 0xEFE6A60D, /* [5][0x90]*/ - 0x1D661643, 0xD63AC5E6, 0x50AEB748, 0x9BF264ED, 0x86F75455, 0x4DAB87F0, 0xCB3FF55E, 0x006326FB, /* [5][0x98]*/ - 0xF135942E, 0x3A69478B, 0xBCFD3525, 0x77A1E680, 0x6AA4D638, 0xA1F8059D, 0x276C7733, 0xEC30A496, /* [5][0xa0]*/ - 0x191C11EE, 0xD240C24B, 0x54D4B0E5, 0x9F886340, 0x828D53F8, 0x49D1805D, 0xCF45F2F3, 0x04192156, /* [5][0xa8]*/ - 0xF54F9383, 0x3E134026, 0xB8873288, 0x73DBE12D, 0x6EDED195, 0xA5820230, 0x2316709E, 0xE84AA33B, /* [5][0xb0]*/ - 0x1ACA1375, 0xD196C0D0, 0x5702B27E, 0x9C5E61DB, 0x815B5163, 0x4A0782C6, 0xCC93F068, 0x07CF23CD, /* [5][0xb8]*/ - 0xF6999118, 0x3DC542BD, 0xBB513013, 0x700DE3B6, 0x6D08D30E, 0xA65400AB, 0x20C07205, 0xEB9CA1A0, /* [5][0xc0]*/ - 0x11E81EB4, 0xDAB4CD11, 0x5C20BFBF, 0x977C6C1A, 0x8A795CA2, 0x41258F07, 0xC7B1FDA9, 0x0CED2E0C, /* [5][0xc8]*/ - 0xFDBB9CD9, 0x36E74F7C, 0xB0733DD2, 0x7B2FEE77, 0x662ADECF, 0xAD760D6A, 0x2BE27FC4, 0xE0BEAC61, /* [5][0xd0]*/ - 0x123E1C2F, 0xD962CF8A, 0x5FF6BD24, 0x94AA6E81, 0x89AF5E39, 0x42F38D9C, 0xC467FF32, 0x0F3B2C97, /* [5][0xd8]*/ - 0xFE6D9E42, 0x35314DE7, 0xB3A53F49, 0x78F9ECEC, 0x65FCDC54, 0xAEA00FF1, 0x28347D5F, 0xE368AEFA, /* [5][0xe0]*/ - 0x16441B82, 0xDD18C827, 0x5B8CBA89, 0x90D0692C, 0x8DD55994, 0x46898A31, 0xC01DF89F, 0x0B412B3A, /* [5][0xe8]*/ - 0xFA1799EF, 0x314B4A4A, 0xB7DF38E4, 0x7C83EB41, 0x6186DBF9, 0xAADA085C, 0x2C4E7AF2, 0xE712A957, /* [5][0xf0]*/ - 0x15921919, 0xDECECABC, 0x585AB812, 0x93066BB7, 0x8E035B0F, 0x455F88AA, 0xC3CBFA04, 0x089729A1, /* [5][0xf8]*/ - 0xF9C19B74, 0x329D48D1, 0xB4093A7F, 0x7F55E9DA, 0x6250D962, 0xA90C0AC7, 0x2F987869, 0xE4C4ABCC /* [5][0x100]*/ - }, - { - 0x00000000, 0xA6770BB4, 0x979F1129, 0x31E81A9D, 0xF44F2413, 0x52382FA7, 0x63D0353A, 0xC5A73E8E, /* [6][0x08]*/ - 0x33EF4E67, 0x959845D3, 0xA4705F4E, 0x020754FA, 0xC7A06A74, 0x61D761C0, 0x503F7B5D, 0xF64870E9, /* [6][0x10]*/ - 0x67DE9CCE, 0xC1A9977A, 0xF0418DE7, 0x56368653, 0x9391B8DD, 0x35E6B369, 0x040EA9F4, 0xA279A240, /* [6][0x18]*/ - 0x5431D2A9, 0xF246D91D, 0xC3AEC380, 0x65D9C834, 0xA07EF6BA, 0x0609FD0E, 0x37E1E793, 0x9196EC27, /* [6][0x20]*/ - 0xCFBD399C, 0x69CA3228, 0x582228B5, 0xFE552301, 0x3BF21D8F, 0x9D85163B, 0xAC6D0CA6, 0x0A1A0712, /* [6][0x28]*/ - 0xFC5277FB, 0x5A257C4F, 0x6BCD66D2, 0xCDBA6D66, 0x081D53E8, 0xAE6A585C, 0x9F8242C1, 0x39F54975, /* [6][0x30]*/ - 0xA863A552, 0x0E14AEE6, 0x3FFCB47B, 0x998BBFCF, 0x5C2C8141, 0xFA5B8AF5, 0xCBB39068, 0x6DC49BDC, /* [6][0x38]*/ - 0x9B8CEB35, 0x3DFBE081, 0x0C13FA1C, 0xAA64F1A8, 0x6FC3CF26, 0xC9B4C492, 0xF85CDE0F, 0x5E2BD5BB, /* [6][0x40]*/ - 0x440B7579, 0xE27C7ECD, 0xD3946450, 0x75E36FE4, 0xB044516A, 0x16335ADE, 0x27DB4043, 0x81AC4BF7, /* [6][0x48]*/ - 0x77E43B1E, 0xD19330AA, 0xE07B2A37, 0x460C2183, 0x83AB1F0D, 0x25DC14B9, 0x14340E24, 0xB2430590, /* [6][0x50]*/ - 0x23D5E9B7, 0x85A2E203, 0xB44AF89E, 0x123DF32A, 0xD79ACDA4, 0x71EDC610, 0x4005DC8D, 0xE672D739, /* [6][0x58]*/ - 0x103AA7D0, 0xB64DAC64, 0x87A5B6F9, 0x21D2BD4D, 0xE47583C3, 0x42028877, 0x73EA92EA, 0xD59D995E, /* [6][0x60]*/ - 0x8BB64CE5, 0x2DC14751, 0x1C295DCC, 0xBA5E5678, 0x7FF968F6, 0xD98E6342, 0xE86679DF, 0x4E11726B, /* [6][0x68]*/ - 0xB8590282, 0x1E2E0936, 0x2FC613AB, 0x89B1181F, 0x4C162691, 0xEA612D25, 0xDB8937B8, 0x7DFE3C0C, /* [6][0x70]*/ - 0xEC68D02B, 0x4A1FDB9F, 0x7BF7C102, 0xDD80CAB6, 0x1827F438, 0xBE50FF8C, 0x8FB8E511, 0x29CFEEA5, /* [6][0x78]*/ - 0xDF879E4C, 0x79F095F8, 0x48188F65, 0xEE6F84D1, 0x2BC8BA5F, 0x8DBFB1EB, 0xBC57AB76, 0x1A20A0C2, /* [6][0x80]*/ - 0x8816EAF2, 0x2E61E146, 0x1F89FBDB, 0xB9FEF06F, 0x7C59CEE1, 0xDA2EC555, 0xEBC6DFC8, 0x4DB1D47C, /* [6][0x88]*/ - 0xBBF9A495, 0x1D8EAF21, 0x2C66B5BC, 0x8A11BE08, 0x4FB68086, 0xE9C18B32, 0xD82991AF, 0x7E5E9A1B, /* [6][0x90]*/ - 0xEFC8763C, 0x49BF7D88, 0x78576715, 0xDE206CA1, 0x1B87522F, 0xBDF0599B, 0x8C184306, 0x2A6F48B2, /* [6][0x98]*/ - 0xDC27385B, 0x7A5033EF, 0x4BB82972, 0xEDCF22C6, 0x28681C48, 0x8E1F17FC, 0xBFF70D61, 0x198006D5, /* [6][0xa0]*/ - 0x47ABD36E, 0xE1DCD8DA, 0xD034C247, 0x7643C9F3, 0xB3E4F77D, 0x1593FCC9, 0x247BE654, 0x820CEDE0, /* [6][0xa8]*/ - 0x74449D09, 0xD23396BD, 0xE3DB8C20, 0x45AC8794, 0x800BB91A, 0x267CB2AE, 0x1794A833, 0xB1E3A387, /* [6][0xb0]*/ - 0x20754FA0, 0x86024414, 0xB7EA5E89, 0x119D553D, 0xD43A6BB3, 0x724D6007, 0x43A57A9A, 0xE5D2712E, /* [6][0xb8]*/ - 0x139A01C7, 0xB5ED0A73, 0x840510EE, 0x22721B5A, 0xE7D525D4, 0x41A22E60, 0x704A34FD, 0xD63D3F49, /* [6][0xc0]*/ - 0xCC1D9F8B, 0x6A6A943F, 0x5B828EA2, 0xFDF58516, 0x3852BB98, 0x9E25B02C, 0xAFCDAAB1, 0x09BAA105, /* [6][0xc8]*/ - 0xFFF2D1EC, 0x5985DA58, 0x686DC0C5, 0xCE1ACB71, 0x0BBDF5FF, 0xADCAFE4B, 0x9C22E4D6, 0x3A55EF62, /* [6][0xd0]*/ - 0xABC30345, 0x0DB408F1, 0x3C5C126C, 0x9A2B19D8, 0x5F8C2756, 0xF9FB2CE2, 0xC813367F, 0x6E643DCB, /* [6][0xd8]*/ - 0x982C4D22, 0x3E5B4696, 0x0FB35C0B, 0xA9C457BF, 0x6C636931, 0xCA146285, 0xFBFC7818, 0x5D8B73AC, /* [6][0xe0]*/ - 0x03A0A617, 0xA5D7ADA3, 0x943FB73E, 0x3248BC8A, 0xF7EF8204, 0x519889B0, 0x6070932D, 0xC6079899, /* [6][0xe8]*/ - 0x304FE870, 0x9638E3C4, 0xA7D0F959, 0x01A7F2ED, 0xC400CC63, 0x6277C7D7, 0x539FDD4A, 0xF5E8D6FE, /* [6][0xf0]*/ - 0x647E3AD9, 0xC209316D, 0xF3E12BF0, 0x55962044, 0x90311ECA, 0x3646157E, 0x07AE0FE3, 0xA1D90457, /* [6][0xf8]*/ - 0x579174BE, 0xF1E67F0A, 0xC00E6597, 0x66796E23, 0xA3DE50AD, 0x05A95B19, 0x34414184, 0x92364A30 /* [6][0x100]*/ - }, - { - 0x00000000, 0xCCAA009E, 0x4225077D, 0x8E8F07E3, 0x844A0EFA, 0x48E00E64, 0xC66F0987, 0x0AC50919, /* [7][0x08]*/ - 0xD3E51BB5, 0x1F4F1B2B, 0x91C01CC8, 0x5D6A1C56, 0x57AF154F, 0x9B0515D1, 0x158A1232, 0xD92012AC, /* [7][0x10]*/ - 0x7CBB312B, 0xB01131B5, 0x3E9E3656, 0xF23436C8, 0xF8F13FD1, 0x345B3F4F, 0xBAD438AC, 0x767E3832, /* [7][0x18]*/ - 0xAF5E2A9E, 0x63F42A00, 0xED7B2DE3, 0x21D12D7D, 0x2B142464, 0xE7BE24FA, 0x69312319, 0xA59B2387, /* [7][0x20]*/ - 0xF9766256, 0x35DC62C8, 0xBB53652B, 0x77F965B5, 0x7D3C6CAC, 0xB1966C32, 0x3F196BD1, 0xF3B36B4F, /* [7][0x28]*/ - 0x2A9379E3, 0xE639797D, 0x68B67E9E, 0xA41C7E00, 0xAED97719, 0x62737787, 0xECFC7064, 0x205670FA, /* [7][0x30]*/ - 0x85CD537D, 0x496753E3, 0xC7E85400, 0x0B42549E, 0x01875D87, 0xCD2D5D19, 0x43A25AFA, 0x8F085A64, /* [7][0x38]*/ - 0x562848C8, 0x9A824856, 0x140D4FB5, 0xD8A74F2B, 0xD2624632, 0x1EC846AC, 0x9047414F, 0x5CED41D1, /* [7][0x40]*/ - 0x299DC2ED, 0xE537C273, 0x6BB8C590, 0xA712C50E, 0xADD7CC17, 0x617DCC89, 0xEFF2CB6A, 0x2358CBF4, /* [7][0x48]*/ - 0xFA78D958, 0x36D2D9C6, 0xB85DDE25, 0x74F7DEBB, 0x7E32D7A2, 0xB298D73C, 0x3C17D0DF, 0xF0BDD041, /* [7][0x50]*/ - 0x5526F3C6, 0x998CF358, 0x1703F4BB, 0xDBA9F425, 0xD16CFD3C, 0x1DC6FDA2, 0x9349FA41, 0x5FE3FADF, /* [7][0x58]*/ - 0x86C3E873, 0x4A69E8ED, 0xC4E6EF0E, 0x084CEF90, 0x0289E689, 0xCE23E617, 0x40ACE1F4, 0x8C06E16A, /* [7][0x60]*/ - 0xD0EBA0BB, 0x1C41A025, 0x92CEA7C6, 0x5E64A758, 0x54A1AE41, 0x980BAEDF, 0x1684A93C, 0xDA2EA9A2, /* [7][0x68]*/ - 0x030EBB0E, 0xCFA4BB90, 0x412BBC73, 0x8D81BCED, 0x8744B5F4, 0x4BEEB56A, 0xC561B289, 0x09CBB217, /* [7][0x70]*/ - 0xAC509190, 0x60FA910E, 0xEE7596ED, 0x22DF9673, 0x281A9F6A, 0xE4B09FF4, 0x6A3F9817, 0xA6959889, /* [7][0x78]*/ - 0x7FB58A25, 0xB31F8ABB, 0x3D908D58, 0xF13A8DC6, 0xFBFF84DF, 0x37558441, 0xB9DA83A2, 0x7570833C, /* [7][0x80]*/ - 0x533B85DA, 0x9F918544, 0x111E82A7, 0xDDB48239, 0xD7718B20, 0x1BDB8BBE, 0x95548C5D, 0x59FE8CC3, /* [7][0x88]*/ - 0x80DE9E6F, 0x4C749EF1, 0xC2FB9912, 0x0E51998C, 0x04949095, 0xC83E900B, 0x46B197E8, 0x8A1B9776, /* [7][0x90]*/ - 0x2F80B4F1, 0xE32AB46F, 0x6DA5B38C, 0xA10FB312, 0xABCABA0B, 0x6760BA95, 0xE9EFBD76, 0x2545BDE8, /* [7][0x98]*/ - 0xFC65AF44, 0x30CFAFDA, 0xBE40A839, 0x72EAA8A7, 0x782FA1BE, 0xB485A120, 0x3A0AA6C3, 0xF6A0A65D, /* [7][0xa0]*/ - 0xAA4DE78C, 0x66E7E712, 0xE868E0F1, 0x24C2E06F, 0x2E07E976, 0xE2ADE9E8, 0x6C22EE0B, 0xA088EE95, /* [7][0xa8]*/ - 0x79A8FC39, 0xB502FCA7, 0x3B8DFB44, 0xF727FBDA, 0xFDE2F2C3, 0x3148F25D, 0xBFC7F5BE, 0x736DF520, /* [7][0xb0]*/ - 0xD6F6D6A7, 0x1A5CD639, 0x94D3D1DA, 0x5879D144, 0x52BCD85D, 0x9E16D8C3, 0x1099DF20, 0xDC33DFBE, /* [7][0xb8]*/ - 0x0513CD12, 0xC9B9CD8C, 0x4736CA6F, 0x8B9CCAF1, 0x8159C3E8, 0x4DF3C376, 0xC37CC495, 0x0FD6C40B, /* [7][0xc0]*/ - 0x7AA64737, 0xB60C47A9, 0x3883404A, 0xF42940D4, 0xFEEC49CD, 0x32464953, 0xBCC94EB0, 0x70634E2E, /* [7][0xc8]*/ - 0xA9435C82, 0x65E95C1C, 0xEB665BFF, 0x27CC5B61, 0x2D095278, 0xE1A352E6, 0x6F2C5505, 0xA386559B, /* [7][0xd0]*/ - 0x061D761C, 0xCAB77682, 0x44387161, 0x889271FF, 0x825778E6, 0x4EFD7878, 0xC0727F9B, 0x0CD87F05, /* [7][0xd8]*/ - 0xD5F86DA9, 0x19526D37, 0x97DD6AD4, 0x5B776A4A, 0x51B26353, 0x9D1863CD, 0x1397642E, 0xDF3D64B0, /* [7][0xe0]*/ - 0x83D02561, 0x4F7A25FF, 0xC1F5221C, 0x0D5F2282, 0x079A2B9B, 0xCB302B05, 0x45BF2CE6, 0x89152C78, /* [7][0xe8]*/ - 0x50353ED4, 0x9C9F3E4A, 0x121039A9, 0xDEBA3937, 0xD47F302E, 0x18D530B0, 0x965A3753, 0x5AF037CD, /* [7][0xf0]*/ - 0xFF6B144A, 0x33C114D4, 0xBD4E1337, 0x71E413A9, 0x7B211AB0, 0xB78B1A2E, 0x39041DCD, 0xF5AE1D53, /* [7][0xf8]*/ - 0x2C8E0FFF, 0xE0240F61, 0x6EAB0882, 0xA201081C, 0xA8C40105, 0x646E019B, 0xEAE10678, 0x264B06E6 /* [7][0x100]*/ - }, - { - 0x00000000, 0x177B1443, 0x2EF62886, 0x398D3CC5, 0x5DEC510C, 0x4A97454F, 0x731A798A, 0x64616DC9, /* [8][0x08]*/ - 0xBBD8A218, 0xACA3B65B, 0x952E8A9E, 0x82559EDD, 0xE634F314, 0xF14FE757, 0xC8C2DB92, 0xDFB9CFD1, /* [8][0x10]*/ - 0xACC04271, 0xBBBB5632, 0x82366AF7, 0x954D7EB4, 0xF12C137D, 0xE657073E, 0xDFDA3BFB, 0xC8A12FB8, /* [8][0x18]*/ - 0x1718E069, 0x0063F42A, 0x39EEC8EF, 0x2E95DCAC, 0x4AF4B165, 0x5D8FA526, 0x640299E3, 0x73798DA0, /* [8][0x20]*/ - 0x82F182A3, 0x958A96E0, 0xAC07AA25, 0xBB7CBE66, 0xDF1DD3AF, 0xC866C7EC, 0xF1EBFB29, 0xE690EF6A, /* [8][0x28]*/ - 0x392920BB, 0x2E5234F8, 0x17DF083D, 0x00A41C7E, 0x64C571B7, 0x73BE65F4, 0x4A335931, 0x5D484D72, /* [8][0x30]*/ - 0x2E31C0D2, 0x394AD491, 0x00C7E854, 0x17BCFC17, 0x73DD91DE, 0x64A6859D, 0x5D2BB958, 0x4A50AD1B, /* [8][0x38]*/ - 0x95E962CA, 0x82927689, 0xBB1F4A4C, 0xAC645E0F, 0xC80533C6, 0xDF7E2785, 0xE6F31B40, 0xF1880F03, /* [8][0x40]*/ - 0xDE920307, 0xC9E91744, 0xF0642B81, 0xE71F3FC2, 0x837E520B, 0x94054648, 0xAD887A8D, 0xBAF36ECE, /* [8][0x48]*/ - 0x654AA11F, 0x7231B55C, 0x4BBC8999, 0x5CC79DDA, 0x38A6F013, 0x2FDDE450, 0x1650D895, 0x012BCCD6, /* [8][0x50]*/ - 0x72524176, 0x65295535, 0x5CA469F0, 0x4BDF7DB3, 0x2FBE107A, 0x38C50439, 0x014838FC, 0x16332CBF, /* [8][0x58]*/ - 0xC98AE36E, 0xDEF1F72D, 0xE77CCBE8, 0xF007DFAB, 0x9466B262, 0x831DA621, 0xBA909AE4, 0xADEB8EA7, /* [8][0x60]*/ - 0x5C6381A4, 0x4B1895E7, 0x7295A922, 0x65EEBD61, 0x018FD0A8, 0x16F4C4EB, 0x2F79F82E, 0x3802EC6D, /* [8][0x68]*/ - 0xE7BB23BC, 0xF0C037FF, 0xC94D0B3A, 0xDE361F79, 0xBA5772B0, 0xAD2C66F3, 0x94A15A36, 0x83DA4E75, /* [8][0x70]*/ - 0xF0A3C3D5, 0xE7D8D796, 0xDE55EB53, 0xC92EFF10, 0xAD4F92D9, 0xBA34869A, 0x83B9BA5F, 0x94C2AE1C, /* [8][0x78]*/ - 0x4B7B61CD, 0x5C00758E, 0x658D494B, 0x72F65D08, 0x169730C1, 0x01EC2482, 0x38611847, 0x2F1A0C04, /* [8][0x80]*/ - 0x6655004F, 0x712E140C, 0x48A328C9, 0x5FD83C8A, 0x3BB95143, 0x2CC24500, 0x154F79C5, 0x02346D86, /* [8][0x88]*/ - 0xDD8DA257, 0xCAF6B614, 0xF37B8AD1, 0xE4009E92, 0x8061F35B, 0x971AE718, 0xAE97DBDD, 0xB9ECCF9E, /* [8][0x90]*/ - 0xCA95423E, 0xDDEE567D, 0xE4636AB8, 0xF3187EFB, 0x97791332, 0x80020771, 0xB98F3BB4, 0xAEF42FF7, /* [8][0x98]*/ - 0x714DE026, 0x6636F465, 0x5FBBC8A0, 0x48C0DCE3, 0x2CA1B12A, 0x3BDAA569, 0x025799AC, 0x152C8DEF, /* [8][0xa0]*/ - 0xE4A482EC, 0xF3DF96AF, 0xCA52AA6A, 0xDD29BE29, 0xB948D3E0, 0xAE33C7A3, 0x97BEFB66, 0x80C5EF25, /* [8][0xa8]*/ - 0x5F7C20F4, 0x480734B7, 0x718A0872, 0x66F11C31, 0x029071F8, 0x15EB65BB, 0x2C66597E, 0x3B1D4D3D, /* [8][0xb0]*/ - 0x4864C09D, 0x5F1FD4DE, 0x6692E81B, 0x71E9FC58, 0x15889191, 0x02F385D2, 0x3B7EB917, 0x2C05AD54, /* [8][0xb8]*/ - 0xF3BC6285, 0xE4C776C6, 0xDD4A4A03, 0xCA315E40, 0xAE503389, 0xB92B27CA, 0x80A61B0F, 0x97DD0F4C, /* [8][0xc0]*/ - 0xB8C70348, 0xAFBC170B, 0x96312BCE, 0x814A3F8D, 0xE52B5244, 0xF2504607, 0xCBDD7AC2, 0xDCA66E81, /* [8][0xc8]*/ - 0x031FA150, 0x1464B513, 0x2DE989D6, 0x3A929D95, 0x5EF3F05C, 0x4988E41F, 0x7005D8DA, 0x677ECC99, /* [8][0xd0]*/ - 0x14074139, 0x037C557A, 0x3AF169BF, 0x2D8A7DFC, 0x49EB1035, 0x5E900476, 0x671D38B3, 0x70662CF0, /* [8][0xd8]*/ - 0xAFDFE321, 0xB8A4F762, 0x8129CBA7, 0x9652DFE4, 0xF233B22D, 0xE548A66E, 0xDCC59AAB, 0xCBBE8EE8, /* [8][0xe0]*/ - 0x3A3681EB, 0x2D4D95A8, 0x14C0A96D, 0x03BBBD2E, 0x67DAD0E7, 0x70A1C4A4, 0x492CF861, 0x5E57EC22, /* [8][0xe8]*/ - 0x81EE23F3, 0x969537B0, 0xAF180B75, 0xB8631F36, 0xDC0272FF, 0xCB7966BC, 0xF2F45A79, 0xE58F4E3A, /* [8][0xf0]*/ - 0x96F6C39A, 0x818DD7D9, 0xB800EB1C, 0xAF7BFF5F, 0xCB1A9296, 0xDC6186D5, 0xE5ECBA10, 0xF297AE53, /* [8][0xf8]*/ - 0x2D2E6182, 0x3A5575C1, 0x03D84904, 0x14A35D47, 0x70C2308E, 0x67B924CD, 0x5E341808, 0x494F0C4B /* [8][0x100]*/ - }, - { - 0x00000000, 0xEFC26B3E, 0x04F5D03D, 0xEB37BB03, 0x09EBA07A, 0xE629CB44, 0x0D1E7047, 0xE2DC1B79, /* [9][0x08]*/ - 0x13D740F4, 0xFC152BCA, 0x172290C9, 0xF8E0FBF7, 0x1A3CE08E, 0xF5FE8BB0, 0x1EC930B3, 0xF10B5B8D, /* [9][0x10]*/ - 0x27AE81E8, 0xC86CEAD6, 0x235B51D5, 0xCC993AEB, 0x2E452192, 0xC1874AAC, 0x2AB0F1AF, 0xC5729A91, /* [9][0x18]*/ - 0x3479C11C, 0xDBBBAA22, 0x308C1121, 0xDF4E7A1F, 0x3D926166, 0xD2500A58, 0x3967B15B, 0xD6A5DA65, /* [9][0x20]*/ - 0x4F5D03D0, 0xA09F68EE, 0x4BA8D3ED, 0xA46AB8D3, 0x46B6A3AA, 0xA974C894, 0x42437397, 0xAD8118A9, /* [9][0x28]*/ - 0x5C8A4324, 0xB348281A, 0x587F9319, 0xB7BDF827, 0x5561E35E, 0xBAA38860, 0x51943363, 0xBE56585D, /* [9][0x30]*/ - 0x68F38238, 0x8731E906, 0x6C065205, 0x83C4393B, 0x61182242, 0x8EDA497C, 0x65EDF27F, 0x8A2F9941, /* [9][0x38]*/ - 0x7B24C2CC, 0x94E6A9F2, 0x7FD112F1, 0x901379CF, 0x72CF62B6, 0x9D0D0988, 0x763AB28B, 0x99F8D9B5, /* [9][0x40]*/ - 0x9EBA07A0, 0x71786C9E, 0x9A4FD79D, 0x758DBCA3, 0x9751A7DA, 0x7893CCE4, 0x93A477E7, 0x7C661CD9, /* [9][0x48]*/ - 0x8D6D4754, 0x62AF2C6A, 0x89989769, 0x665AFC57, 0x8486E72E, 0x6B448C10, 0x80733713, 0x6FB15C2D, /* [9][0x50]*/ - 0xB9148648, 0x56D6ED76, 0xBDE15675, 0x52233D4B, 0xB0FF2632, 0x5F3D4D0C, 0xB40AF60F, 0x5BC89D31, /* [9][0x58]*/ - 0xAAC3C6BC, 0x4501AD82, 0xAE361681, 0x41F47DBF, 0xA32866C6, 0x4CEA0DF8, 0xA7DDB6FB, 0x481FDDC5, /* [9][0x60]*/ - 0xD1E70470, 0x3E256F4E, 0xD512D44D, 0x3AD0BF73, 0xD80CA40A, 0x37CECF34, 0xDCF97437, 0x333B1F09, /* [9][0x68]*/ - 0xC2304484, 0x2DF22FBA, 0xC6C594B9, 0x2907FF87, 0xCBDBE4FE, 0x24198FC0, 0xCF2E34C3, 0x20EC5FFD, /* [9][0x70]*/ - 0xF6498598, 0x198BEEA6, 0xF2BC55A5, 0x1D7E3E9B, 0xFFA225E2, 0x10604EDC, 0xFB57F5DF, 0x14959EE1, /* [9][0x78]*/ - 0xE59EC56C, 0x0A5CAE52, 0xE16B1551, 0x0EA97E6F, 0xEC756516, 0x03B70E28, 0xE880B52B, 0x0742DE15, /* [9][0x80]*/ - 0xE6050901, 0x09C7623F, 0xE2F0D93C, 0x0D32B202, 0xEFEEA97B, 0x002CC245, 0xEB1B7946, 0x04D91278, /* [9][0x88]*/ - 0xF5D249F5, 0x1A1022CB, 0xF12799C8, 0x1EE5F2F6, 0xFC39E98F, 0x13FB82B1, 0xF8CC39B2, 0x170E528C, /* [9][0x90]*/ - 0xC1AB88E9, 0x2E69E3D7, 0xC55E58D4, 0x2A9C33EA, 0xC8402893, 0x278243AD, 0xCCB5F8AE, 0x23779390, /* [9][0x98]*/ - 0xD27CC81D, 0x3DBEA323, 0xD6891820, 0x394B731E, 0xDB976867, 0x34550359, 0xDF62B85A, 0x30A0D364, /* [9][0xa0]*/ - 0xA9580AD1, 0x469A61EF, 0xADADDAEC, 0x426FB1D2, 0xA0B3AAAB, 0x4F71C195, 0xA4467A96, 0x4B8411A8, /* [9][0xa8]*/ - 0xBA8F4A25, 0x554D211B, 0xBE7A9A18, 0x51B8F126, 0xB364EA5F, 0x5CA68161, 0xB7913A62, 0x5853515C, /* [9][0xb0]*/ - 0x8EF68B39, 0x6134E007, 0x8A035B04, 0x65C1303A, 0x871D2B43, 0x68DF407D, 0x83E8FB7E, 0x6C2A9040, /* [9][0xb8]*/ - 0x9D21CBCD, 0x72E3A0F3, 0x99D41BF0, 0x761670CE, 0x94CA6BB7, 0x7B080089, 0x903FBB8A, 0x7FFDD0B4, /* [9][0xc0]*/ - 0x78BF0EA1, 0x977D659F, 0x7C4ADE9C, 0x9388B5A2, 0x7154AEDB, 0x9E96C5E5, 0x75A17EE6, 0x9A6315D8, /* [9][0xc8]*/ - 0x6B684E55, 0x84AA256B, 0x6F9D9E68, 0x805FF556, 0x6283EE2F, 0x8D418511, 0x66763E12, 0x89B4552C, /* [9][0xd0]*/ - 0x5F118F49, 0xB0D3E477, 0x5BE45F74, 0xB426344A, 0x56FA2F33, 0xB938440D, 0x520FFF0E, 0xBDCD9430, /* [9][0xd8]*/ - 0x4CC6CFBD, 0xA304A483, 0x48331F80, 0xA7F174BE, 0x452D6FC7, 0xAAEF04F9, 0x41D8BFFA, 0xAE1AD4C4, /* [9][0xe0]*/ - 0x37E20D71, 0xD820664F, 0x3317DD4C, 0xDCD5B672, 0x3E09AD0B, 0xD1CBC635, 0x3AFC7D36, 0xD53E1608, /* [9][0xe8]*/ - 0x24354D85, 0xCBF726BB, 0x20C09DB8, 0xCF02F686, 0x2DDEEDFF, 0xC21C86C1, 0x292B3DC2, 0xC6E956FC, /* [9][0xf0]*/ - 0x104C8C99, 0xFF8EE7A7, 0x14B95CA4, 0xFB7B379A, 0x19A72CE3, 0xF66547DD, 0x1D52FCDE, 0xF29097E0, /* [9][0xf8]*/ - 0x039BCC6D, 0xEC59A753, 0x076E1C50, 0xE8AC776E, 0x0A706C17, 0xE5B20729, 0x0E85BC2A, 0xE147D714 /* [9][0x100]*/ - }, - { - 0x00000000, 0xC18EDFC0, 0x586CB9C1, 0x99E26601, 0xB0D97382, 0x7157AC42, 0xE8B5CA43, 0x293B1583, /* [10][0x08]*/ - 0xBAC3E145, 0x7B4D3E85, 0xE2AF5884, 0x23218744, 0x0A1A92C7, 0xCB944D07, 0x52762B06, 0x93F8F4C6, /* [10][0x10]*/ - 0xAEF6C4CB, 0x6F781B0B, 0xF69A7D0A, 0x3714A2CA, 0x1E2FB749, 0xDFA16889, 0x46430E88, 0x87CDD148, /* [10][0x18]*/ - 0x1435258E, 0xD5BBFA4E, 0x4C599C4F, 0x8DD7438F, 0xA4EC560C, 0x656289CC, 0xFC80EFCD, 0x3D0E300D, /* [10][0x20]*/ - 0x869C8FD7, 0x47125017, 0xDEF03616, 0x1F7EE9D6, 0x3645FC55, 0xF7CB2395, 0x6E294594, 0xAFA79A54, /* [10][0x28]*/ - 0x3C5F6E92, 0xFDD1B152, 0x6433D753, 0xA5BD0893, 0x8C861D10, 0x4D08C2D0, 0xD4EAA4D1, 0x15647B11, /* [10][0x30]*/ - 0x286A4B1C, 0xE9E494DC, 0x7006F2DD, 0xB1882D1D, 0x98B3389E, 0x593DE75E, 0xC0DF815F, 0x01515E9F, /* [10][0x38]*/ - 0x92A9AA59, 0x53277599, 0xCAC51398, 0x0B4BCC58, 0x2270D9DB, 0xE3FE061B, 0x7A1C601A, 0xBB92BFDA, /* [10][0x40]*/ - 0xD64819EF, 0x17C6C62F, 0x8E24A02E, 0x4FAA7FEE, 0x66916A6D, 0xA71FB5AD, 0x3EFDD3AC, 0xFF730C6C, /* [10][0x48]*/ - 0x6C8BF8AA, 0xAD05276A, 0x34E7416B, 0xF5699EAB, 0xDC528B28, 0x1DDC54E8, 0x843E32E9, 0x45B0ED29, /* [10][0x50]*/ - 0x78BEDD24, 0xB93002E4, 0x20D264E5, 0xE15CBB25, 0xC867AEA6, 0x09E97166, 0x900B1767, 0x5185C8A7, /* [10][0x58]*/ - 0xC27D3C61, 0x03F3E3A1, 0x9A1185A0, 0x5B9F5A60, 0x72A44FE3, 0xB32A9023, 0x2AC8F622, 0xEB4629E2, /* [10][0x60]*/ - 0x50D49638, 0x915A49F8, 0x08B82FF9, 0xC936F039, 0xE00DE5BA, 0x21833A7A, 0xB8615C7B, 0x79EF83BB, /* [10][0x68]*/ - 0xEA17777D, 0x2B99A8BD, 0xB27BCEBC, 0x73F5117C, 0x5ACE04FF, 0x9B40DB3F, 0x02A2BD3E, 0xC32C62FE, /* [10][0x70]*/ - 0xFE2252F3, 0x3FAC8D33, 0xA64EEB32, 0x67C034F2, 0x4EFB2171, 0x8F75FEB1, 0x169798B0, 0xD7194770, /* [10][0x78]*/ - 0x44E1B3B6, 0x856F6C76, 0x1C8D0A77, 0xDD03D5B7, 0xF438C034, 0x35B61FF4, 0xAC5479F5, 0x6DDAA635, /* [10][0x80]*/ - 0x77E1359F, 0xB66FEA5F, 0x2F8D8C5E, 0xEE03539E, 0xC738461D, 0x06B699DD, 0x9F54FFDC, 0x5EDA201C, /* [10][0x88]*/ - 0xCD22D4DA, 0x0CAC0B1A, 0x954E6D1B, 0x54C0B2DB, 0x7DFBA758, 0xBC757898, 0x25971E99, 0xE419C159, /* [10][0x90]*/ - 0xD917F154, 0x18992E94, 0x817B4895, 0x40F59755, 0x69CE82D6, 0xA8405D16, 0x31A23B17, 0xF02CE4D7, /* [10][0x98]*/ - 0x63D41011, 0xA25ACFD1, 0x3BB8A9D0, 0xFA367610, 0xD30D6393, 0x1283BC53, 0x8B61DA52, 0x4AEF0592, /* [10][0xa0]*/ - 0xF17DBA48, 0x30F36588, 0xA9110389, 0x689FDC49, 0x41A4C9CA, 0x802A160A, 0x19C8700B, 0xD846AFCB, /* [10][0xa8]*/ - 0x4BBE5B0D, 0x8A3084CD, 0x13D2E2CC, 0xD25C3D0C, 0xFB67288F, 0x3AE9F74F, 0xA30B914E, 0x62854E8E, /* [10][0xb0]*/ - 0x5F8B7E83, 0x9E05A143, 0x07E7C742, 0xC6691882, 0xEF520D01, 0x2EDCD2C1, 0xB73EB4C0, 0x76B06B00, /* [10][0xb8]*/ - 0xE5489FC6, 0x24C64006, 0xBD242607, 0x7CAAF9C7, 0x5591EC44, 0x941F3384, 0x0DFD5585, 0xCC738A45, /* [10][0xc0]*/ - 0xA1A92C70, 0x6027F3B0, 0xF9C595B1, 0x384B4A71, 0x11705FF2, 0xD0FE8032, 0x491CE633, 0x889239F3, /* [10][0xc8]*/ - 0x1B6ACD35, 0xDAE412F5, 0x430674F4, 0x8288AB34, 0xABB3BEB7, 0x6A3D6177, 0xF3DF0776, 0x3251D8B6, /* [10][0xd0]*/ - 0x0F5FE8BB, 0xCED1377B, 0x5733517A, 0x96BD8EBA, 0xBF869B39, 0x7E0844F9, 0xE7EA22F8, 0x2664FD38, /* [10][0xd8]*/ - 0xB59C09FE, 0x7412D63E, 0xEDF0B03F, 0x2C7E6FFF, 0x05457A7C, 0xC4CBA5BC, 0x5D29C3BD, 0x9CA71C7D, /* [10][0xe0]*/ - 0x2735A3A7, 0xE6BB7C67, 0x7F591A66, 0xBED7C5A6, 0x97ECD025, 0x56620FE5, 0xCF8069E4, 0x0E0EB624, /* [10][0xe8]*/ - 0x9DF642E2, 0x5C789D22, 0xC59AFB23, 0x041424E3, 0x2D2F3160, 0xECA1EEA0, 0x754388A1, 0xB4CD5761, /* [10][0xf0]*/ - 0x89C3676C, 0x484DB8AC, 0xD1AFDEAD, 0x1021016D, 0x391A14EE, 0xF894CB2E, 0x6176AD2F, 0xA0F872EF, /* [10][0xf8]*/ - 0x33008629, 0xF28E59E9, 0x6B6C3FE8, 0xAAE2E028, 0x83D9F5AB, 0x42572A6B, 0xDBB54C6A, 0x1A3B93AA /* [10][0x100]*/ - }, - { - 0x00000000, 0x9BA54C6F, 0xEC3B9E9F, 0x779ED2F0, 0x03063B7F, 0x98A37710, 0xEF3DA5E0, 0x7498E98F, /* [11][0x08]*/ - 0x060C76FE, 0x9DA93A91, 0xEA37E861, 0x7192A40E, 0x050A4D81, 0x9EAF01EE, 0xE931D31E, 0x72949F71, /* [11][0x10]*/ - 0x0C18EDFC, 0x97BDA193, 0xE0237363, 0x7B863F0C, 0x0F1ED683, 0x94BB9AEC, 0xE325481C, 0x78800473, /* [11][0x18]*/ - 0x0A149B02, 0x91B1D76D, 0xE62F059D, 0x7D8A49F2, 0x0912A07D, 0x92B7EC12, 0xE5293EE2, 0x7E8C728D, /* [11][0x20]*/ - 0x1831DBF8, 0x83949797, 0xF40A4567, 0x6FAF0908, 0x1B37E087, 0x8092ACE8, 0xF70C7E18, 0x6CA93277, /* [11][0x28]*/ - 0x1E3DAD06, 0x8598E169, 0xF2063399, 0x69A37FF6, 0x1D3B9679, 0x869EDA16, 0xF10008E6, 0x6AA54489, /* [11][0x30]*/ - 0x14293604, 0x8F8C7A6B, 0xF812A89B, 0x63B7E4F4, 0x172F0D7B, 0x8C8A4114, 0xFB1493E4, 0x60B1DF8B, /* [11][0x38]*/ - 0x122540FA, 0x89800C95, 0xFE1EDE65, 0x65BB920A, 0x11237B85, 0x8A8637EA, 0xFD18E51A, 0x66BDA975, /* [11][0x40]*/ - 0x3063B7F0, 0xABC6FB9F, 0xDC58296F, 0x47FD6500, 0x33658C8F, 0xA8C0C0E0, 0xDF5E1210, 0x44FB5E7F, /* [11][0x48]*/ - 0x366FC10E, 0xADCA8D61, 0xDA545F91, 0x41F113FE, 0x3569FA71, 0xAECCB61E, 0xD95264EE, 0x42F72881, /* [11][0x50]*/ - 0x3C7B5A0C, 0xA7DE1663, 0xD040C493, 0x4BE588FC, 0x3F7D6173, 0xA4D82D1C, 0xD346FFEC, 0x48E3B383, /* [11][0x58]*/ - 0x3A772CF2, 0xA1D2609D, 0xD64CB26D, 0x4DE9FE02, 0x3971178D, 0xA2D45BE2, 0xD54A8912, 0x4EEFC57D, /* [11][0x60]*/ - 0x28526C08, 0xB3F72067, 0xC469F297, 0x5FCCBEF8, 0x2B545777, 0xB0F11B18, 0xC76FC9E8, 0x5CCA8587, /* [11][0x68]*/ - 0x2E5E1AF6, 0xB5FB5699, 0xC2658469, 0x59C0C806, 0x2D582189, 0xB6FD6DE6, 0xC163BF16, 0x5AC6F379, /* [11][0x70]*/ - 0x244A81F4, 0xBFEFCD9B, 0xC8711F6B, 0x53D45304, 0x274CBA8B, 0xBCE9F6E4, 0xCB772414, 0x50D2687B, /* [11][0x78]*/ - 0x2246F70A, 0xB9E3BB65, 0xCE7D6995, 0x55D825FA, 0x2140CC75, 0xBAE5801A, 0xCD7B52EA, 0x56DE1E85, /* [11][0x80]*/ - 0x60C76FE0, 0xFB62238F, 0x8CFCF17F, 0x1759BD10, 0x63C1549F, 0xF86418F0, 0x8FFACA00, 0x145F866F, /* [11][0x88]*/ - 0x66CB191E, 0xFD6E5571, 0x8AF08781, 0x1155CBEE, 0x65CD2261, 0xFE686E0E, 0x89F6BCFE, 0x1253F091, /* [11][0x90]*/ - 0x6CDF821C, 0xF77ACE73, 0x80E41C83, 0x1B4150EC, 0x6FD9B963, 0xF47CF50C, 0x83E227FC, 0x18476B93, /* [11][0x98]*/ - 0x6AD3F4E2, 0xF176B88D, 0x86E86A7D, 0x1D4D2612, 0x69D5CF9D, 0xF27083F2, 0x85EE5102, 0x1E4B1D6D, /* [11][0xa0]*/ - 0x78F6B418, 0xE353F877, 0x94CD2A87, 0x0F6866E8, 0x7BF08F67, 0xE055C308, 0x97CB11F8, 0x0C6E5D97, /* [11][0xa8]*/ - 0x7EFAC2E6, 0xE55F8E89, 0x92C15C79, 0x09641016, 0x7DFCF999, 0xE659B5F6, 0x91C76706, 0x0A622B69, /* [11][0xb0]*/ - 0x74EE59E4, 0xEF4B158B, 0x98D5C77B, 0x03708B14, 0x77E8629B, 0xEC4D2EF4, 0x9BD3FC04, 0x0076B06B, /* [11][0xb8]*/ - 0x72E22F1A, 0xE9476375, 0x9ED9B185, 0x057CFDEA, 0x71E41465, 0xEA41580A, 0x9DDF8AFA, 0x067AC695, /* [11][0xc0]*/ - 0x50A4D810, 0xCB01947F, 0xBC9F468F, 0x273A0AE0, 0x53A2E36F, 0xC807AF00, 0xBF997DF0, 0x243C319F, /* [11][0xc8]*/ - 0x56A8AEEE, 0xCD0DE281, 0xBA933071, 0x21367C1E, 0x55AE9591, 0xCE0BD9FE, 0xB9950B0E, 0x22304761, /* [11][0xd0]*/ - 0x5CBC35EC, 0xC7197983, 0xB087AB73, 0x2B22E71C, 0x5FBA0E93, 0xC41F42FC, 0xB381900C, 0x2824DC63, /* [11][0xd8]*/ - 0x5AB04312, 0xC1150F7D, 0xB68BDD8D, 0x2D2E91E2, 0x59B6786D, 0xC2133402, 0xB58DE6F2, 0x2E28AA9D, /* [11][0xe0]*/ - 0x489503E8, 0xD3304F87, 0xA4AE9D77, 0x3F0BD118, 0x4B933897, 0xD03674F8, 0xA7A8A608, 0x3C0DEA67, /* [11][0xe8]*/ - 0x4E997516, 0xD53C3979, 0xA2A2EB89, 0x3907A7E6, 0x4D9F4E69, 0xD63A0206, 0xA1A4D0F6, 0x3A019C99, /* [11][0xf0]*/ - 0x448DEE14, 0xDF28A27B, 0xA8B6708B, 0x33133CE4, 0x478BD56B, 0xDC2E9904, 0xABB04BF4, 0x3015079B, /* [11][0xf8]*/ - 0x428198EA, 0xD924D485, 0xAEBA0675, 0x351F4A1A, 0x4187A395, 0xDA22EFFA, 0xADBC3D0A, 0x36197165 /* [11][0x100]*/ - }, - { - 0x00000000, 0xDD96D985, 0x605CB54B, 0xBDCA6CCE, 0xC0B96A96, 0x1D2FB313, 0xA0E5DFDD, 0x7D730658, /* [12][0x08]*/ - 0x5A03D36D, 0x87950AE8, 0x3A5F6626, 0xE7C9BFA3, 0x9ABAB9FB, 0x472C607E, 0xFAE60CB0, 0x2770D535, /* [12][0x10]*/ - 0xB407A6DA, 0x69917F5F, 0xD45B1391, 0x09CDCA14, 0x74BECC4C, 0xA92815C9, 0x14E27907, 0xC974A082, /* [12][0x18]*/ - 0xEE0475B7, 0x3392AC32, 0x8E58C0FC, 0x53CE1979, 0x2EBD1F21, 0xF32BC6A4, 0x4EE1AA6A, 0x937773EF, /* [12][0x20]*/ - 0xB37E4BF5, 0x6EE89270, 0xD322FEBE, 0x0EB4273B, 0x73C72163, 0xAE51F8E6, 0x139B9428, 0xCE0D4DAD, /* [12][0x28]*/ - 0xE97D9898, 0x34EB411D, 0x89212DD3, 0x54B7F456, 0x29C4F20E, 0xF4522B8B, 0x49984745, 0x940E9EC0, /* [12][0x30]*/ - 0x0779ED2F, 0xDAEF34AA, 0x67255864, 0xBAB381E1, 0xC7C087B9, 0x1A565E3C, 0xA79C32F2, 0x7A0AEB77, /* [12][0x38]*/ - 0x5D7A3E42, 0x80ECE7C7, 0x3D268B09, 0xE0B0528C, 0x9DC354D4, 0x40558D51, 0xFD9FE19F, 0x2009381A, /* [12][0x40]*/ - 0xBD8D91AB, 0x601B482E, 0xDDD124E0, 0x0047FD65, 0x7D34FB3D, 0xA0A222B8, 0x1D684E76, 0xC0FE97F3, /* [12][0x48]*/ - 0xE78E42C6, 0x3A189B43, 0x87D2F78D, 0x5A442E08, 0x27372850, 0xFAA1F1D5, 0x476B9D1B, 0x9AFD449E, /* [12][0x50]*/ - 0x098A3771, 0xD41CEEF4, 0x69D6823A, 0xB4405BBF, 0xC9335DE7, 0x14A58462, 0xA96FE8AC, 0x74F93129, /* [12][0x58]*/ - 0x5389E41C, 0x8E1F3D99, 0x33D55157, 0xEE4388D2, 0x93308E8A, 0x4EA6570F, 0xF36C3BC1, 0x2EFAE244, /* [12][0x60]*/ - 0x0EF3DA5E, 0xD36503DB, 0x6EAF6F15, 0xB339B690, 0xCE4AB0C8, 0x13DC694D, 0xAE160583, 0x7380DC06, /* [12][0x68]*/ - 0x54F00933, 0x8966D0B6, 0x34ACBC78, 0xE93A65FD, 0x944963A5, 0x49DFBA20, 0xF415D6EE, 0x29830F6B, /* [12][0x70]*/ - 0xBAF47C84, 0x6762A501, 0xDAA8C9CF, 0x073E104A, 0x7A4D1612, 0xA7DBCF97, 0x1A11A359, 0xC7877ADC, /* [12][0x78]*/ - 0xE0F7AFE9, 0x3D61766C, 0x80AB1AA2, 0x5D3DC327, 0x204EC57F, 0xFDD81CFA, 0x40127034, 0x9D84A9B1, /* [12][0x80]*/ - 0xA06A2517, 0x7DFCFC92, 0xC036905C, 0x1DA049D9, 0x60D34F81, 0xBD459604, 0x008FFACA, 0xDD19234F, /* [12][0x88]*/ - 0xFA69F67A, 0x27FF2FFF, 0x9A354331, 0x47A39AB4, 0x3AD09CEC, 0xE7464569, 0x5A8C29A7, 0x871AF022, /* [12][0x90]*/ - 0x146D83CD, 0xC9FB5A48, 0x74313686, 0xA9A7EF03, 0xD4D4E95B, 0x094230DE, 0xB4885C10, 0x691E8595, /* [12][0x98]*/ - 0x4E6E50A0, 0x93F88925, 0x2E32E5EB, 0xF3A43C6E, 0x8ED73A36, 0x5341E3B3, 0xEE8B8F7D, 0x331D56F8, /* [12][0xa0]*/ - 0x13146EE2, 0xCE82B767, 0x7348DBA9, 0xAEDE022C, 0xD3AD0474, 0x0E3BDDF1, 0xB3F1B13F, 0x6E6768BA, /* [12][0xa8]*/ - 0x4917BD8F, 0x9481640A, 0x294B08C4, 0xF4DDD141, 0x89AED719, 0x54380E9C, 0xE9F26252, 0x3464BBD7, /* [12][0xb0]*/ - 0xA713C838, 0x7A8511BD, 0xC74F7D73, 0x1AD9A4F6, 0x67AAA2AE, 0xBA3C7B2B, 0x07F617E5, 0xDA60CE60, /* [12][0xb8]*/ - 0xFD101B55, 0x2086C2D0, 0x9D4CAE1E, 0x40DA779B, 0x3DA971C3, 0xE03FA846, 0x5DF5C488, 0x80631D0D, /* [12][0xc0]*/ - 0x1DE7B4BC, 0xC0716D39, 0x7DBB01F7, 0xA02DD872, 0xDD5EDE2A, 0x00C807AF, 0xBD026B61, 0x6094B2E4, /* [12][0xc8]*/ - 0x47E467D1, 0x9A72BE54, 0x27B8D29A, 0xFA2E0B1F, 0x875D0D47, 0x5ACBD4C2, 0xE701B80C, 0x3A976189, /* [12][0xd0]*/ - 0xA9E01266, 0x7476CBE3, 0xC9BCA72D, 0x142A7EA8, 0x695978F0, 0xB4CFA175, 0x0905CDBB, 0xD493143E, /* [12][0xd8]*/ - 0xF3E3C10B, 0x2E75188E, 0x93BF7440, 0x4E29ADC5, 0x335AAB9D, 0xEECC7218, 0x53061ED6, 0x8E90C753, /* [12][0xe0]*/ - 0xAE99FF49, 0x730F26CC, 0xCEC54A02, 0x13539387, 0x6E2095DF, 0xB3B64C5A, 0x0E7C2094, 0xD3EAF911, /* [12][0xe8]*/ - 0xF49A2C24, 0x290CF5A1, 0x94C6996F, 0x495040EA, 0x342346B2, 0xE9B59F37, 0x547FF3F9, 0x89E92A7C, /* [12][0xf0]*/ - 0x1A9E5993, 0xC7088016, 0x7AC2ECD8, 0xA754355D, 0xDA273305, 0x07B1EA80, 0xBA7B864E, 0x67ED5FCB, /* [12][0xf8]*/ - 0x409D8AFE, 0x9D0B537B, 0x20C13FB5, 0xFD57E630, 0x8024E068, 0x5DB239ED, 0xE0785523, 0x3DEE8CA6 /* [12][0x100]*/ - }, - { - 0x00000000, 0x9D0FE176, 0xE16EC4AD, 0x7C6125DB, 0x19AC8F1B, 0x84A36E6D, 0xF8C24BB6, 0x65CDAAC0, /* [13][0x08]*/ - 0x33591E36, 0xAE56FF40, 0xD237DA9B, 0x4F383BED, 0x2AF5912D, 0xB7FA705B, 0xCB9B5580, 0x5694B4F6, /* [13][0x10]*/ - 0x66B23C6C, 0xFBBDDD1A, 0x87DCF8C1, 0x1AD319B7, 0x7F1EB377, 0xE2115201, 0x9E7077DA, 0x037F96AC, /* [13][0x18]*/ - 0x55EB225A, 0xC8E4C32C, 0xB485E6F7, 0x298A0781, 0x4C47AD41, 0xD1484C37, 0xAD2969EC, 0x3026889A, /* [13][0x20]*/ - 0xCD6478D8, 0x506B99AE, 0x2C0ABC75, 0xB1055D03, 0xD4C8F7C3, 0x49C716B5, 0x35A6336E, 0xA8A9D218, /* [13][0x28]*/ - 0xFE3D66EE, 0x63328798, 0x1F53A243, 0x825C4335, 0xE791E9F5, 0x7A9E0883, 0x06FF2D58, 0x9BF0CC2E, /* [13][0x30]*/ - 0xABD644B4, 0x36D9A5C2, 0x4AB88019, 0xD7B7616F, 0xB27ACBAF, 0x2F752AD9, 0x53140F02, 0xCE1BEE74, /* [13][0x38]*/ - 0x988F5A82, 0x0580BBF4, 0x79E19E2F, 0xE4EE7F59, 0x8123D599, 0x1C2C34EF, 0x604D1134, 0xFD42F042, /* [13][0x40]*/ - 0x41B9F7F1, 0xDCB61687, 0xA0D7335C, 0x3DD8D22A, 0x581578EA, 0xC51A999C, 0xB97BBC47, 0x24745D31, /* [13][0x48]*/ - 0x72E0E9C7, 0xEFEF08B1, 0x938E2D6A, 0x0E81CC1C, 0x6B4C66DC, 0xF64387AA, 0x8A22A271, 0x172D4307, /* [13][0x50]*/ - 0x270BCB9D, 0xBA042AEB, 0xC6650F30, 0x5B6AEE46, 0x3EA74486, 0xA3A8A5F0, 0xDFC9802B, 0x42C6615D, /* [13][0x58]*/ - 0x1452D5AB, 0x895D34DD, 0xF53C1106, 0x6833F070, 0x0DFE5AB0, 0x90F1BBC6, 0xEC909E1D, 0x719F7F6B, /* [13][0x60]*/ - 0x8CDD8F29, 0x11D26E5F, 0x6DB34B84, 0xF0BCAAF2, 0x95710032, 0x087EE144, 0x741FC49F, 0xE91025E9, /* [13][0x68]*/ - 0xBF84911F, 0x228B7069, 0x5EEA55B2, 0xC3E5B4C4, 0xA6281E04, 0x3B27FF72, 0x4746DAA9, 0xDA493BDF, /* [13][0x70]*/ - 0xEA6FB345, 0x77605233, 0x0B0177E8, 0x960E969E, 0xF3C33C5E, 0x6ECCDD28, 0x12ADF8F3, 0x8FA21985, /* [13][0x78]*/ - 0xD936AD73, 0x44394C05, 0x385869DE, 0xA55788A8, 0xC09A2268, 0x5D95C31E, 0x21F4E6C5, 0xBCFB07B3, /* [13][0x80]*/ - 0x8373EFE2, 0x1E7C0E94, 0x621D2B4F, 0xFF12CA39, 0x9ADF60F9, 0x07D0818F, 0x7BB1A454, 0xE6BE4522, /* [13][0x88]*/ - 0xB02AF1D4, 0x2D2510A2, 0x51443579, 0xCC4BD40F, 0xA9867ECF, 0x34899FB9, 0x48E8BA62, 0xD5E75B14, /* [13][0x90]*/ - 0xE5C1D38E, 0x78CE32F8, 0x04AF1723, 0x99A0F655, 0xFC6D5C95, 0x6162BDE3, 0x1D039838, 0x800C794E, /* [13][0x98]*/ - 0xD698CDB8, 0x4B972CCE, 0x37F60915, 0xAAF9E863, 0xCF3442A3, 0x523BA3D5, 0x2E5A860E, 0xB3556778, /* [13][0xa0]*/ - 0x4E17973A, 0xD318764C, 0xAF795397, 0x3276B2E1, 0x57BB1821, 0xCAB4F957, 0xB6D5DC8C, 0x2BDA3DFA, /* [13][0xa8]*/ - 0x7D4E890C, 0xE041687A, 0x9C204DA1, 0x012FACD7, 0x64E20617, 0xF9EDE761, 0x858CC2BA, 0x188323CC, /* [13][0xb0]*/ - 0x28A5AB56, 0xB5AA4A20, 0xC9CB6FFB, 0x54C48E8D, 0x3109244D, 0xAC06C53B, 0xD067E0E0, 0x4D680196, /* [13][0xb8]*/ - 0x1BFCB560, 0x86F35416, 0xFA9271CD, 0x679D90BB, 0x02503A7B, 0x9F5FDB0D, 0xE33EFED6, 0x7E311FA0, /* [13][0xc0]*/ - 0xC2CA1813, 0x5FC5F965, 0x23A4DCBE, 0xBEAB3DC8, 0xDB669708, 0x4669767E, 0x3A0853A5, 0xA707B2D3, /* [13][0xc8]*/ - 0xF1930625, 0x6C9CE753, 0x10FDC288, 0x8DF223FE, 0xE83F893E, 0x75306848, 0x09514D93, 0x945EACE5, /* [13][0xd0]*/ - 0xA478247F, 0x3977C509, 0x4516E0D2, 0xD81901A4, 0xBDD4AB64, 0x20DB4A12, 0x5CBA6FC9, 0xC1B58EBF, /* [13][0xd8]*/ - 0x97213A49, 0x0A2EDB3F, 0x764FFEE4, 0xEB401F92, 0x8E8DB552, 0x13825424, 0x6FE371FF, 0xF2EC9089, /* [13][0xe0]*/ - 0x0FAE60CB, 0x92A181BD, 0xEEC0A466, 0x73CF4510, 0x1602EFD0, 0x8B0D0EA6, 0xF76C2B7D, 0x6A63CA0B, /* [13][0xe8]*/ - 0x3CF77EFD, 0xA1F89F8B, 0xDD99BA50, 0x40965B26, 0x255BF1E6, 0xB8541090, 0xC435354B, 0x593AD43D, /* [13][0xf0]*/ - 0x691C5CA7, 0xF413BDD1, 0x8872980A, 0x157D797C, 0x70B0D3BC, 0xEDBF32CA, 0x91DE1711, 0x0CD1F667, /* [13][0xf8]*/ - 0x5A454291, 0xC74AA3E7, 0xBB2B863C, 0x2624674A, 0x43E9CD8A, 0xDEE62CFC, 0xA2870927, 0x3F88E851 /* [13][0x100]*/ - }, - { - 0x00000000, 0xB9FBDBE8, 0xA886B191, 0x117D6A79, 0x8A7C6563, 0x3387BE8B, 0x22FAD4F2, 0x9B010F1A, /* [14][0x08]*/ - 0xCF89CC87, 0x7672176F, 0x670F7D16, 0xDEF4A6FE, 0x45F5A9E4, 0xFC0E720C, 0xED731875, 0x5488C39D, /* [14][0x10]*/ - 0x44629F4F, 0xFD9944A7, 0xECE42EDE, 0x551FF536, 0xCE1EFA2C, 0x77E521C4, 0x66984BBD, 0xDF639055, /* [14][0x18]*/ - 0x8BEB53C8, 0x32108820, 0x236DE259, 0x9A9639B1, 0x019736AB, 0xB86CED43, 0xA911873A, 0x10EA5CD2, /* [14][0x20]*/ - 0x88C53E9E, 0x313EE576, 0x20438F0F, 0x99B854E7, 0x02B95BFD, 0xBB428015, 0xAA3FEA6C, 0x13C43184, /* [14][0x28]*/ - 0x474CF219, 0xFEB729F1, 0xEFCA4388, 0x56319860, 0xCD30977A, 0x74CB4C92, 0x65B626EB, 0xDC4DFD03, /* [14][0x30]*/ - 0xCCA7A1D1, 0x755C7A39, 0x64211040, 0xDDDACBA8, 0x46DBC4B2, 0xFF201F5A, 0xEE5D7523, 0x57A6AECB, /* [14][0x38]*/ - 0x032E6D56, 0xBAD5B6BE, 0xABA8DCC7, 0x1253072F, 0x89520835, 0x30A9D3DD, 0x21D4B9A4, 0x982F624C, /* [14][0x40]*/ - 0xCAFB7B7D, 0x7300A095, 0x627DCAEC, 0xDB861104, 0x40871E1E, 0xF97CC5F6, 0xE801AF8F, 0x51FA7467, /* [14][0x48]*/ - 0x0572B7FA, 0xBC896C12, 0xADF4066B, 0x140FDD83, 0x8F0ED299, 0x36F50971, 0x27886308, 0x9E73B8E0, /* [14][0x50]*/ - 0x8E99E432, 0x37623FDA, 0x261F55A3, 0x9FE48E4B, 0x04E58151, 0xBD1E5AB9, 0xAC6330C0, 0x1598EB28, /* [14][0x58]*/ - 0x411028B5, 0xF8EBF35D, 0xE9969924, 0x506D42CC, 0xCB6C4DD6, 0x7297963E, 0x63EAFC47, 0xDA1127AF, /* [14][0x60]*/ - 0x423E45E3, 0xFBC59E0B, 0xEAB8F472, 0x53432F9A, 0xC8422080, 0x71B9FB68, 0x60C49111, 0xD93F4AF9, /* [14][0x68]*/ - 0x8DB78964, 0x344C528C, 0x253138F5, 0x9CCAE31D, 0x07CBEC07, 0xBE3037EF, 0xAF4D5D96, 0x16B6867E, /* [14][0x70]*/ - 0x065CDAAC, 0xBFA70144, 0xAEDA6B3D, 0x1721B0D5, 0x8C20BFCF, 0x35DB6427, 0x24A60E5E, 0x9D5DD5B6, /* [14][0x78]*/ - 0xC9D5162B, 0x702ECDC3, 0x6153A7BA, 0xD8A87C52, 0x43A97348, 0xFA52A8A0, 0xEB2FC2D9, 0x52D41931, /* [14][0x80]*/ - 0x4E87F0BB, 0xF77C2B53, 0xE601412A, 0x5FFA9AC2, 0xC4FB95D8, 0x7D004E30, 0x6C7D2449, 0xD586FFA1, /* [14][0x88]*/ - 0x810E3C3C, 0x38F5E7D4, 0x29888DAD, 0x90735645, 0x0B72595F, 0xB28982B7, 0xA3F4E8CE, 0x1A0F3326, /* [14][0x90]*/ - 0x0AE56FF4, 0xB31EB41C, 0xA263DE65, 0x1B98058D, 0x80990A97, 0x3962D17F, 0x281FBB06, 0x91E460EE, /* [14][0x98]*/ - 0xC56CA373, 0x7C97789B, 0x6DEA12E2, 0xD411C90A, 0x4F10C610, 0xF6EB1DF8, 0xE7967781, 0x5E6DAC69, /* [14][0xa0]*/ - 0xC642CE25, 0x7FB915CD, 0x6EC47FB4, 0xD73FA45C, 0x4C3EAB46, 0xF5C570AE, 0xE4B81AD7, 0x5D43C13F, /* [14][0xa8]*/ - 0x09CB02A2, 0xB030D94A, 0xA14DB333, 0x18B668DB, 0x83B767C1, 0x3A4CBC29, 0x2B31D650, 0x92CA0DB8, /* [14][0xb0]*/ - 0x8220516A, 0x3BDB8A82, 0x2AA6E0FB, 0x935D3B13, 0x085C3409, 0xB1A7EFE1, 0xA0DA8598, 0x19215E70, /* [14][0xb8]*/ - 0x4DA99DED, 0xF4524605, 0xE52F2C7C, 0x5CD4F794, 0xC7D5F88E, 0x7E2E2366, 0x6F53491F, 0xD6A892F7, /* [14][0xc0]*/ - 0x847C8BC6, 0x3D87502E, 0x2CFA3A57, 0x9501E1BF, 0x0E00EEA5, 0xB7FB354D, 0xA6865F34, 0x1F7D84DC, /* [14][0xc8]*/ - 0x4BF54741, 0xF20E9CA9, 0xE373F6D0, 0x5A882D38, 0xC1892222, 0x7872F9CA, 0x690F93B3, 0xD0F4485B, /* [14][0xd0]*/ - 0xC01E1489, 0x79E5CF61, 0x6898A518, 0xD1637EF0, 0x4A6271EA, 0xF399AA02, 0xE2E4C07B, 0x5B1F1B93, /* [14][0xd8]*/ - 0x0F97D80E, 0xB66C03E6, 0xA711699F, 0x1EEAB277, 0x85EBBD6D, 0x3C106685, 0x2D6D0CFC, 0x9496D714, /* [14][0xe0]*/ - 0x0CB9B558, 0xB5426EB0, 0xA43F04C9, 0x1DC4DF21, 0x86C5D03B, 0x3F3E0BD3, 0x2E4361AA, 0x97B8BA42, /* [14][0xe8]*/ - 0xC33079DF, 0x7ACBA237, 0x6BB6C84E, 0xD24D13A6, 0x494C1CBC, 0xF0B7C754, 0xE1CAAD2D, 0x583176C5, /* [14][0xf0]*/ - 0x48DB2A17, 0xF120F1FF, 0xE05D9B86, 0x59A6406E, 0xC2A74F74, 0x7B5C949C, 0x6A21FEE5, 0xD3DA250D, /* [14][0xf8]*/ - 0x8752E690, 0x3EA93D78, 0x2FD45701, 0x962F8CE9, 0x0D2E83F3, 0xB4D5581B, 0xA5A83262, 0x1C53E98A /* [14][0x100]*/ - }, - { - 0x00000000, 0xAE689191, 0x87A02563, 0x29C8B4F2, 0xD4314C87, 0x7A59DD16, 0x539169E4, 0xFDF9F875, /* [15][0x08]*/ - 0x73139F4F, 0xDD7B0EDE, 0xF4B3BA2C, 0x5ADB2BBD, 0xA722D3C8, 0x094A4259, 0x2082F6AB, 0x8EEA673A, /* [15][0x10]*/ - 0xE6273E9E, 0x484FAF0F, 0x61871BFD, 0xCFEF8A6C, 0x32167219, 0x9C7EE388, 0xB5B6577A, 0x1BDEC6EB, /* [15][0x18]*/ - 0x9534A1D1, 0x3B5C3040, 0x129484B2, 0xBCFC1523, 0x4105ED56, 0xEF6D7CC7, 0xC6A5C835, 0x68CD59A4, /* [15][0x20]*/ - 0x173F7B7D, 0xB957EAEC, 0x909F5E1E, 0x3EF7CF8F, 0xC30E37FA, 0x6D66A66B, 0x44AE1299, 0xEAC68308, /* [15][0x28]*/ - 0x642CE432, 0xCA4475A3, 0xE38CC151, 0x4DE450C0, 0xB01DA8B5, 0x1E753924, 0x37BD8DD6, 0x99D51C47, /* [15][0x30]*/ - 0xF11845E3, 0x5F70D472, 0x76B86080, 0xD8D0F111, 0x25290964, 0x8B4198F5, 0xA2892C07, 0x0CE1BD96, /* [15][0x38]*/ - 0x820BDAAC, 0x2C634B3D, 0x05ABFFCF, 0xABC36E5E, 0x563A962B, 0xF85207BA, 0xD19AB348, 0x7FF222D9, /* [15][0x40]*/ - 0x2E7EF6FA, 0x8016676B, 0xA9DED399, 0x07B64208, 0xFA4FBA7D, 0x54272BEC, 0x7DEF9F1E, 0xD3870E8F, /* [15][0x48]*/ - 0x5D6D69B5, 0xF305F824, 0xDACD4CD6, 0x74A5DD47, 0x895C2532, 0x2734B4A3, 0x0EFC0051, 0xA09491C0, /* [15][0x50]*/ - 0xC859C864, 0x663159F5, 0x4FF9ED07, 0xE1917C96, 0x1C6884E3, 0xB2001572, 0x9BC8A180, 0x35A03011, /* [15][0x58]*/ - 0xBB4A572B, 0x1522C6BA, 0x3CEA7248, 0x9282E3D9, 0x6F7B1BAC, 0xC1138A3D, 0xE8DB3ECF, 0x46B3AF5E, /* [15][0x60]*/ - 0x39418D87, 0x97291C16, 0xBEE1A8E4, 0x10893975, 0xED70C100, 0x43185091, 0x6AD0E463, 0xC4B875F2, /* [15][0x68]*/ - 0x4A5212C8, 0xE43A8359, 0xCDF237AB, 0x639AA63A, 0x9E635E4F, 0x300BCFDE, 0x19C37B2C, 0xB7ABEABD, /* [15][0x70]*/ - 0xDF66B319, 0x710E2288, 0x58C6967A, 0xF6AE07EB, 0x0B57FF9E, 0xA53F6E0F, 0x8CF7DAFD, 0x229F4B6C, /* [15][0x78]*/ - 0xAC752C56, 0x021DBDC7, 0x2BD50935, 0x85BD98A4, 0x784460D1, 0xD62CF140, 0xFFE445B2, 0x518CD423, /* [15][0x80]*/ - 0x5CFDEDF4, 0xF2957C65, 0xDB5DC897, 0x75355906, 0x88CCA173, 0x26A430E2, 0x0F6C8410, 0xA1041581, /* [15][0x88]*/ - 0x2FEE72BB, 0x8186E32A, 0xA84E57D8, 0x0626C649, 0xFBDF3E3C, 0x55B7AFAD, 0x7C7F1B5F, 0xD2178ACE, /* [15][0x90]*/ - 0xBADAD36A, 0x14B242FB, 0x3D7AF609, 0x93126798, 0x6EEB9FED, 0xC0830E7C, 0xE94BBA8E, 0x47232B1F, /* [15][0x98]*/ - 0xC9C94C25, 0x67A1DDB4, 0x4E696946, 0xE001F8D7, 0x1DF800A2, 0xB3909133, 0x9A5825C1, 0x3430B450, /* [15][0xa0]*/ - 0x4BC29689, 0xE5AA0718, 0xCC62B3EA, 0x620A227B, 0x9FF3DA0E, 0x319B4B9F, 0x1853FF6D, 0xB63B6EFC, /* [15][0xa8]*/ - 0x38D109C6, 0x96B99857, 0xBF712CA5, 0x1119BD34, 0xECE04541, 0x4288D4D0, 0x6B406022, 0xC528F1B3, /* [15][0xb0]*/ - 0xADE5A817, 0x038D3986, 0x2A458D74, 0x842D1CE5, 0x79D4E490, 0xD7BC7501, 0xFE74C1F3, 0x501C5062, /* [15][0xb8]*/ - 0xDEF63758, 0x709EA6C9, 0x5956123B, 0xF73E83AA, 0x0AC77BDF, 0xA4AFEA4E, 0x8D675EBC, 0x230FCF2D, /* [15][0xc0]*/ - 0x72831B0E, 0xDCEB8A9F, 0xF5233E6D, 0x5B4BAFFC, 0xA6B25789, 0x08DAC618, 0x211272EA, 0x8F7AE37B, /* [15][0xc8]*/ - 0x01908441, 0xAFF815D0, 0x8630A122, 0x285830B3, 0xD5A1C8C6, 0x7BC95957, 0x5201EDA5, 0xFC697C34, /* [15][0xd0]*/ - 0x94A42590, 0x3ACCB401, 0x130400F3, 0xBD6C9162, 0x40956917, 0xEEFDF886, 0xC7354C74, 0x695DDDE5, /* [15][0xd8]*/ - 0xE7B7BADF, 0x49DF2B4E, 0x60179FBC, 0xCE7F0E2D, 0x3386F658, 0x9DEE67C9, 0xB426D33B, 0x1A4E42AA, /* [15][0xe0]*/ - 0x65BC6073, 0xCBD4F1E2, 0xE21C4510, 0x4C74D481, 0xB18D2CF4, 0x1FE5BD65, 0x362D0997, 0x98459806, /* [15][0xe8]*/ - 0x16AFFF3C, 0xB8C76EAD, 0x910FDA5F, 0x3F674BCE, 0xC29EB3BB, 0x6CF6222A, 0x453E96D8, 0xEB560749, /* [15][0xf0]*/ - 0x839B5EED, 0x2DF3CF7C, 0x043B7B8E, 0xAA53EA1F, 0x57AA126A, 0xF9C283FB, 0xD00A3709, 0x7E62A698, /* [15][0xf8]*/ - 0xF088C1A2, 0x5EE05033, 0x7728E4C1, 0xD9407550, 0x24B98D25, 0x8AD11CB4, 0xA319A846, 0x0D7139D7 /* [15][0x100]*/ - }}; - -/** Castagnoli CRC32c (iSCSI) lookup table for slice-by-4/8/16 */ -const uint32_t CRC32C_TABLE[16][256] = { - { - 0x00000000, 0xF26B8303, 0xE13B70F7, 0x1350F3F4, 0xC79A971F, 0x35F1141C, 0x26A1E7E8, 0xD4CA64EB, /* [0][0x08]*/ - 0x8AD958CF, 0x78B2DBCC, 0x6BE22838, 0x9989AB3B, 0x4D43CFD0, 0xBF284CD3, 0xAC78BF27, 0x5E133C24, /* [0][0x10]*/ - 0x105EC76F, 0xE235446C, 0xF165B798, 0x030E349B, 0xD7C45070, 0x25AFD373, 0x36FF2087, 0xC494A384, /* [0][0x18]*/ - 0x9A879FA0, 0x68EC1CA3, 0x7BBCEF57, 0x89D76C54, 0x5D1D08BF, 0xAF768BBC, 0xBC267848, 0x4E4DFB4B, /* [0][0x20]*/ - 0x20BD8EDE, 0xD2D60DDD, 0xC186FE29, 0x33ED7D2A, 0xE72719C1, 0x154C9AC2, 0x061C6936, 0xF477EA35, /* [0][0x28]*/ - 0xAA64D611, 0x580F5512, 0x4B5FA6E6, 0xB93425E5, 0x6DFE410E, 0x9F95C20D, 0x8CC531F9, 0x7EAEB2FA, /* [0][0x30]*/ - 0x30E349B1, 0xC288CAB2, 0xD1D83946, 0x23B3BA45, 0xF779DEAE, 0x05125DAD, 0x1642AE59, 0xE4292D5A, /* [0][0x38]*/ - 0xBA3A117E, 0x4851927D, 0x5B016189, 0xA96AE28A, 0x7DA08661, 0x8FCB0562, 0x9C9BF696, 0x6EF07595, /* [0][0x40]*/ - 0x417B1DBC, 0xB3109EBF, 0xA0406D4B, 0x522BEE48, 0x86E18AA3, 0x748A09A0, 0x67DAFA54, 0x95B17957, /* [0][0x48]*/ - 0xCBA24573, 0x39C9C670, 0x2A993584, 0xD8F2B687, 0x0C38D26C, 0xFE53516F, 0xED03A29B, 0x1F682198, /* [0][0x50]*/ - 0x5125DAD3, 0xA34E59D0, 0xB01EAA24, 0x42752927, 0x96BF4DCC, 0x64D4CECF, 0x77843D3B, 0x85EFBE38, /* [0][0x58]*/ - 0xDBFC821C, 0x2997011F, 0x3AC7F2EB, 0xC8AC71E8, 0x1C661503, 0xEE0D9600, 0xFD5D65F4, 0x0F36E6F7, /* [0][0x60]*/ - 0x61C69362, 0x93AD1061, 0x80FDE395, 0x72966096, 0xA65C047D, 0x5437877E, 0x4767748A, 0xB50CF789, /* [0][0x68]*/ - 0xEB1FCBAD, 0x197448AE, 0x0A24BB5A, 0xF84F3859, 0x2C855CB2, 0xDEEEDFB1, 0xCDBE2C45, 0x3FD5AF46, /* [0][0x70]*/ - 0x7198540D, 0x83F3D70E, 0x90A324FA, 0x62C8A7F9, 0xB602C312, 0x44694011, 0x5739B3E5, 0xA55230E6, /* [0][0x78]*/ - 0xFB410CC2, 0x092A8FC1, 0x1A7A7C35, 0xE811FF36, 0x3CDB9BDD, 0xCEB018DE, 0xDDE0EB2A, 0x2F8B6829, /* [0][0x80]*/ - 0x82F63B78, 0x709DB87B, 0x63CD4B8F, 0x91A6C88C, 0x456CAC67, 0xB7072F64, 0xA457DC90, 0x563C5F93, /* [0][0x88]*/ - 0x082F63B7, 0xFA44E0B4, 0xE9141340, 0x1B7F9043, 0xCFB5F4A8, 0x3DDE77AB, 0x2E8E845F, 0xDCE5075C, /* [0][0x90]*/ - 0x92A8FC17, 0x60C37F14, 0x73938CE0, 0x81F80FE3, 0x55326B08, 0xA759E80B, 0xB4091BFF, 0x466298FC, /* [0][0x98]*/ - 0x1871A4D8, 0xEA1A27DB, 0xF94AD42F, 0x0B21572C, 0xDFEB33C7, 0x2D80B0C4, 0x3ED04330, 0xCCBBC033, /* [0][0xa0]*/ - 0xA24BB5A6, 0x502036A5, 0x4370C551, 0xB11B4652, 0x65D122B9, 0x97BAA1BA, 0x84EA524E, 0x7681D14D, /* [0][0xa8]*/ - 0x2892ED69, 0xDAF96E6A, 0xC9A99D9E, 0x3BC21E9D, 0xEF087A76, 0x1D63F975, 0x0E330A81, 0xFC588982, /* [0][0xb0]*/ - 0xB21572C9, 0x407EF1CA, 0x532E023E, 0xA145813D, 0x758FE5D6, 0x87E466D5, 0x94B49521, 0x66DF1622, /* [0][0xb8]*/ - 0x38CC2A06, 0xCAA7A905, 0xD9F75AF1, 0x2B9CD9F2, 0xFF56BD19, 0x0D3D3E1A, 0x1E6DCDEE, 0xEC064EED, /* [0][0xc0]*/ - 0xC38D26C4, 0x31E6A5C7, 0x22B65633, 0xD0DDD530, 0x0417B1DB, 0xF67C32D8, 0xE52CC12C, 0x1747422F, /* [0][0xc8]*/ - 0x49547E0B, 0xBB3FFD08, 0xA86F0EFC, 0x5A048DFF, 0x8ECEE914, 0x7CA56A17, 0x6FF599E3, 0x9D9E1AE0, /* [0][0xd0]*/ - 0xD3D3E1AB, 0x21B862A8, 0x32E8915C, 0xC083125F, 0x144976B4, 0xE622F5B7, 0xF5720643, 0x07198540, /* [0][0xd8]*/ - 0x590AB964, 0xAB613A67, 0xB831C993, 0x4A5A4A90, 0x9E902E7B, 0x6CFBAD78, 0x7FAB5E8C, 0x8DC0DD8F, /* [0][0xe0]*/ - 0xE330A81A, 0x115B2B19, 0x020BD8ED, 0xF0605BEE, 0x24AA3F05, 0xD6C1BC06, 0xC5914FF2, 0x37FACCF1, /* [0][0xe8]*/ - 0x69E9F0D5, 0x9B8273D6, 0x88D28022, 0x7AB90321, 0xAE7367CA, 0x5C18E4C9, 0x4F48173D, 0xBD23943E, /* [0][0xf0]*/ - 0xF36E6F75, 0x0105EC76, 0x12551F82, 0xE03E9C81, 0x34F4F86A, 0xC69F7B69, 0xD5CF889D, 0x27A40B9E, /* [0][0xf8]*/ - 0x79B737BA, 0x8BDCB4B9, 0x988C474D, 0x6AE7C44E, 0xBE2DA0A5, 0x4C4623A6, 0x5F16D052, 0xAD7D5351 /* [0][0x100]*/ - }, - { - 0x00000000, 0x13A29877, 0x274530EE, 0x34E7A899, 0x4E8A61DC, 0x5D28F9AB, 0x69CF5132, 0x7A6DC945, /* [1][0x08]*/ - 0x9D14C3B8, 0x8EB65BCF, 0xBA51F356, 0xA9F36B21, 0xD39EA264, 0xC03C3A13, 0xF4DB928A, 0xE7790AFD, /* [1][0x10]*/ - 0x3FC5F181, 0x2C6769F6, 0x1880C16F, 0x0B225918, 0x714F905D, 0x62ED082A, 0x560AA0B3, 0x45A838C4, /* [1][0x18]*/ - 0xA2D13239, 0xB173AA4E, 0x859402D7, 0x96369AA0, 0xEC5B53E5, 0xFFF9CB92, 0xCB1E630B, 0xD8BCFB7C, /* [1][0x20]*/ - 0x7F8BE302, 0x6C297B75, 0x58CED3EC, 0x4B6C4B9B, 0x310182DE, 0x22A31AA9, 0x1644B230, 0x05E62A47, /* [1][0x28]*/ - 0xE29F20BA, 0xF13DB8CD, 0xC5DA1054, 0xD6788823, 0xAC154166, 0xBFB7D911, 0x8B507188, 0x98F2E9FF, /* [1][0x30]*/ - 0x404E1283, 0x53EC8AF4, 0x670B226D, 0x74A9BA1A, 0x0EC4735F, 0x1D66EB28, 0x298143B1, 0x3A23DBC6, /* [1][0x38]*/ - 0xDD5AD13B, 0xCEF8494C, 0xFA1FE1D5, 0xE9BD79A2, 0x93D0B0E7, 0x80722890, 0xB4958009, 0xA737187E, /* [1][0x40]*/ - 0xFF17C604, 0xECB55E73, 0xD852F6EA, 0xCBF06E9D, 0xB19DA7D8, 0xA23F3FAF, 0x96D89736, 0x857A0F41, /* [1][0x48]*/ - 0x620305BC, 0x71A19DCB, 0x45463552, 0x56E4AD25, 0x2C896460, 0x3F2BFC17, 0x0BCC548E, 0x186ECCF9, /* [1][0x50]*/ - 0xC0D23785, 0xD370AFF2, 0xE797076B, 0xF4359F1C, 0x8E585659, 0x9DFACE2E, 0xA91D66B7, 0xBABFFEC0, /* [1][0x58]*/ - 0x5DC6F43D, 0x4E646C4A, 0x7A83C4D3, 0x69215CA4, 0x134C95E1, 0x00EE0D96, 0x3409A50F, 0x27AB3D78, /* [1][0x60]*/ - 0x809C2506, 0x933EBD71, 0xA7D915E8, 0xB47B8D9F, 0xCE1644DA, 0xDDB4DCAD, 0xE9537434, 0xFAF1EC43, /* [1][0x68]*/ - 0x1D88E6BE, 0x0E2A7EC9, 0x3ACDD650, 0x296F4E27, 0x53028762, 0x40A01F15, 0x7447B78C, 0x67E52FFB, /* [1][0x70]*/ - 0xBF59D487, 0xACFB4CF0, 0x981CE469, 0x8BBE7C1E, 0xF1D3B55B, 0xE2712D2C, 0xD69685B5, 0xC5341DC2, /* [1][0x78]*/ - 0x224D173F, 0x31EF8F48, 0x050827D1, 0x16AABFA6, 0x6CC776E3, 0x7F65EE94, 0x4B82460D, 0x5820DE7A, /* [1][0x80]*/ - 0xFBC3FAF9, 0xE861628E, 0xDC86CA17, 0xCF245260, 0xB5499B25, 0xA6EB0352, 0x920CABCB, 0x81AE33BC, /* [1][0x88]*/ - 0x66D73941, 0x7575A136, 0x419209AF, 0x523091D8, 0x285D589D, 0x3BFFC0EA, 0x0F186873, 0x1CBAF004, /* [1][0x90]*/ - 0xC4060B78, 0xD7A4930F, 0xE3433B96, 0xF0E1A3E1, 0x8A8C6AA4, 0x992EF2D3, 0xADC95A4A, 0xBE6BC23D, /* [1][0x98]*/ - 0x5912C8C0, 0x4AB050B7, 0x7E57F82E, 0x6DF56059, 0x1798A91C, 0x043A316B, 0x30DD99F2, 0x237F0185, /* [1][0xa0]*/ - 0x844819FB, 0x97EA818C, 0xA30D2915, 0xB0AFB162, 0xCAC27827, 0xD960E050, 0xED8748C9, 0xFE25D0BE, /* [1][0xa8]*/ - 0x195CDA43, 0x0AFE4234, 0x3E19EAAD, 0x2DBB72DA, 0x57D6BB9F, 0x447423E8, 0x70938B71, 0x63311306, /* [1][0xb0]*/ - 0xBB8DE87A, 0xA82F700D, 0x9CC8D894, 0x8F6A40E3, 0xF50789A6, 0xE6A511D1, 0xD242B948, 0xC1E0213F, /* [1][0xb8]*/ - 0x26992BC2, 0x353BB3B5, 0x01DC1B2C, 0x127E835B, 0x68134A1E, 0x7BB1D269, 0x4F567AF0, 0x5CF4E287, /* [1][0xc0]*/ - 0x04D43CFD, 0x1776A48A, 0x23910C13, 0x30339464, 0x4A5E5D21, 0x59FCC556, 0x6D1B6DCF, 0x7EB9F5B8, /* [1][0xc8]*/ - 0x99C0FF45, 0x8A626732, 0xBE85CFAB, 0xAD2757DC, 0xD74A9E99, 0xC4E806EE, 0xF00FAE77, 0xE3AD3600, /* [1][0xd0]*/ - 0x3B11CD7C, 0x28B3550B, 0x1C54FD92, 0x0FF665E5, 0x759BACA0, 0x663934D7, 0x52DE9C4E, 0x417C0439, /* [1][0xd8]*/ - 0xA6050EC4, 0xB5A796B3, 0x81403E2A, 0x92E2A65D, 0xE88F6F18, 0xFB2DF76F, 0xCFCA5FF6, 0xDC68C781, /* [1][0xe0]*/ - 0x7B5FDFFF, 0x68FD4788, 0x5C1AEF11, 0x4FB87766, 0x35D5BE23, 0x26772654, 0x12908ECD, 0x013216BA, /* [1][0xe8]*/ - 0xE64B1C47, 0xF5E98430, 0xC10E2CA9, 0xD2ACB4DE, 0xA8C17D9B, 0xBB63E5EC, 0x8F844D75, 0x9C26D502, /* [1][0xf0]*/ - 0x449A2E7E, 0x5738B609, 0x63DF1E90, 0x707D86E7, 0x0A104FA2, 0x19B2D7D5, 0x2D557F4C, 0x3EF7E73B, /* [1][0xf8]*/ - 0xD98EEDC6, 0xCA2C75B1, 0xFECBDD28, 0xED69455F, 0x97048C1A, 0x84A6146D, 0xB041BCF4, 0xA3E32483 /* [1][0x100]*/ - }, - { - 0x00000000, 0xA541927E, 0x4F6F520D, 0xEA2EC073, 0x9EDEA41A, 0x3B9F3664, 0xD1B1F617, 0x74F06469, /* [2][0x08]*/ - 0x38513EC5, 0x9D10ACBB, 0x773E6CC8, 0xD27FFEB6, 0xA68F9ADF, 0x03CE08A1, 0xE9E0C8D2, 0x4CA15AAC, /* [2][0x10]*/ - 0x70A27D8A, 0xD5E3EFF4, 0x3FCD2F87, 0x9A8CBDF9, 0xEE7CD990, 0x4B3D4BEE, 0xA1138B9D, 0x045219E3, /* [2][0x18]*/ - 0x48F3434F, 0xEDB2D131, 0x079C1142, 0xA2DD833C, 0xD62DE755, 0x736C752B, 0x9942B558, 0x3C032726, /* [2][0x20]*/ - 0xE144FB14, 0x4405696A, 0xAE2BA919, 0x0B6A3B67, 0x7F9A5F0E, 0xDADBCD70, 0x30F50D03, 0x95B49F7D, /* [2][0x28]*/ - 0xD915C5D1, 0x7C5457AF, 0x967A97DC, 0x333B05A2, 0x47CB61CB, 0xE28AF3B5, 0x08A433C6, 0xADE5A1B8, /* [2][0x30]*/ - 0x91E6869E, 0x34A714E0, 0xDE89D493, 0x7BC846ED, 0x0F382284, 0xAA79B0FA, 0x40577089, 0xE516E2F7, /* [2][0x38]*/ - 0xA9B7B85B, 0x0CF62A25, 0xE6D8EA56, 0x43997828, 0x37691C41, 0x92288E3F, 0x78064E4C, 0xDD47DC32, /* [2][0x40]*/ - 0xC76580D9, 0x622412A7, 0x880AD2D4, 0x2D4B40AA, 0x59BB24C3, 0xFCFAB6BD, 0x16D476CE, 0xB395E4B0, /* [2][0x48]*/ - 0xFF34BE1C, 0x5A752C62, 0xB05BEC11, 0x151A7E6F, 0x61EA1A06, 0xC4AB8878, 0x2E85480B, 0x8BC4DA75, /* [2][0x50]*/ - 0xB7C7FD53, 0x12866F2D, 0xF8A8AF5E, 0x5DE93D20, 0x29195949, 0x8C58CB37, 0x66760B44, 0xC337993A, /* [2][0x58]*/ - 0x8F96C396, 0x2AD751E8, 0xC0F9919B, 0x65B803E5, 0x1148678C, 0xB409F5F2, 0x5E273581, 0xFB66A7FF, /* [2][0x60]*/ - 0x26217BCD, 0x8360E9B3, 0x694E29C0, 0xCC0FBBBE, 0xB8FFDFD7, 0x1DBE4DA9, 0xF7908DDA, 0x52D11FA4, /* [2][0x68]*/ - 0x1E704508, 0xBB31D776, 0x511F1705, 0xF45E857B, 0x80AEE112, 0x25EF736C, 0xCFC1B31F, 0x6A802161, /* [2][0x70]*/ - 0x56830647, 0xF3C29439, 0x19EC544A, 0xBCADC634, 0xC85DA25D, 0x6D1C3023, 0x8732F050, 0x2273622E, /* [2][0x78]*/ - 0x6ED23882, 0xCB93AAFC, 0x21BD6A8F, 0x84FCF8F1, 0xF00C9C98, 0x554D0EE6, 0xBF63CE95, 0x1A225CEB, /* [2][0x80]*/ - 0x8B277743, 0x2E66E53D, 0xC448254E, 0x6109B730, 0x15F9D359, 0xB0B84127, 0x5A968154, 0xFFD7132A, /* [2][0x88]*/ - 0xB3764986, 0x1637DBF8, 0xFC191B8B, 0x595889F5, 0x2DA8ED9C, 0x88E97FE2, 0x62C7BF91, 0xC7862DEF, /* [2][0x90]*/ - 0xFB850AC9, 0x5EC498B7, 0xB4EA58C4, 0x11ABCABA, 0x655BAED3, 0xC01A3CAD, 0x2A34FCDE, 0x8F756EA0, /* [2][0x98]*/ - 0xC3D4340C, 0x6695A672, 0x8CBB6601, 0x29FAF47F, 0x5D0A9016, 0xF84B0268, 0x1265C21B, 0xB7245065, /* [2][0xa0]*/ - 0x6A638C57, 0xCF221E29, 0x250CDE5A, 0x804D4C24, 0xF4BD284D, 0x51FCBA33, 0xBBD27A40, 0x1E93E83E, /* [2][0xa8]*/ - 0x5232B292, 0xF77320EC, 0x1D5DE09F, 0xB81C72E1, 0xCCEC1688, 0x69AD84F6, 0x83834485, 0x26C2D6FB, /* [2][0xb0]*/ - 0x1AC1F1DD, 0xBF8063A3, 0x55AEA3D0, 0xF0EF31AE, 0x841F55C7, 0x215EC7B9, 0xCB7007CA, 0x6E3195B4, /* [2][0xb8]*/ - 0x2290CF18, 0x87D15D66, 0x6DFF9D15, 0xC8BE0F6B, 0xBC4E6B02, 0x190FF97C, 0xF321390F, 0x5660AB71, /* [2][0xc0]*/ - 0x4C42F79A, 0xE90365E4, 0x032DA597, 0xA66C37E9, 0xD29C5380, 0x77DDC1FE, 0x9DF3018D, 0x38B293F3, /* [2][0xc8]*/ - 0x7413C95F, 0xD1525B21, 0x3B7C9B52, 0x9E3D092C, 0xEACD6D45, 0x4F8CFF3B, 0xA5A23F48, 0x00E3AD36, /* [2][0xd0]*/ - 0x3CE08A10, 0x99A1186E, 0x738FD81D, 0xD6CE4A63, 0xA23E2E0A, 0x077FBC74, 0xED517C07, 0x4810EE79, /* [2][0xd8]*/ - 0x04B1B4D5, 0xA1F026AB, 0x4BDEE6D8, 0xEE9F74A6, 0x9A6F10CF, 0x3F2E82B1, 0xD50042C2, 0x7041D0BC, /* [2][0xe0]*/ - 0xAD060C8E, 0x08479EF0, 0xE2695E83, 0x4728CCFD, 0x33D8A894, 0x96993AEA, 0x7CB7FA99, 0xD9F668E7, /* [2][0xe8]*/ - 0x9557324B, 0x3016A035, 0xDA386046, 0x7F79F238, 0x0B899651, 0xAEC8042F, 0x44E6C45C, 0xE1A75622, /* [2][0xf0]*/ - 0xDDA47104, 0x78E5E37A, 0x92CB2309, 0x378AB177, 0x437AD51E, 0xE63B4760, 0x0C158713, 0xA954156D, /* [2][0xf8]*/ - 0xE5F54FC1, 0x40B4DDBF, 0xAA9A1DCC, 0x0FDB8FB2, 0x7B2BEBDB, 0xDE6A79A5, 0x3444B9D6, 0x91052BA8 /* [2][0x100]*/ - }, - { - 0x00000000, 0xDD45AAB8, 0xBF672381, 0x62228939, 0x7B2231F3, 0xA6679B4B, 0xC4451272, 0x1900B8CA, /* [3][0x08]*/ - 0xF64463E6, 0x2B01C95E, 0x49234067, 0x9466EADF, 0x8D665215, 0x5023F8AD, 0x32017194, 0xEF44DB2C, /* [3][0x10]*/ - 0xE964B13D, 0x34211B85, 0x560392BC, 0x8B463804, 0x924680CE, 0x4F032A76, 0x2D21A34F, 0xF06409F7, /* [3][0x18]*/ - 0x1F20D2DB, 0xC2657863, 0xA047F15A, 0x7D025BE2, 0x6402E328, 0xB9474990, 0xDB65C0A9, 0x06206A11, /* [3][0x20]*/ - 0xD725148B, 0x0A60BE33, 0x6842370A, 0xB5079DB2, 0xAC072578, 0x71428FC0, 0x136006F9, 0xCE25AC41, /* [3][0x28]*/ - 0x2161776D, 0xFC24DDD5, 0x9E0654EC, 0x4343FE54, 0x5A43469E, 0x8706EC26, 0xE524651F, 0x3861CFA7, /* [3][0x30]*/ - 0x3E41A5B6, 0xE3040F0E, 0x81268637, 0x5C632C8F, 0x45639445, 0x98263EFD, 0xFA04B7C4, 0x27411D7C, /* [3][0x38]*/ - 0xC805C650, 0x15406CE8, 0x7762E5D1, 0xAA274F69, 0xB327F7A3, 0x6E625D1B, 0x0C40D422, 0xD1057E9A, /* [3][0x40]*/ - 0xABA65FE7, 0x76E3F55F, 0x14C17C66, 0xC984D6DE, 0xD0846E14, 0x0DC1C4AC, 0x6FE34D95, 0xB2A6E72D, /* [3][0x48]*/ - 0x5DE23C01, 0x80A796B9, 0xE2851F80, 0x3FC0B538, 0x26C00DF2, 0xFB85A74A, 0x99A72E73, 0x44E284CB, /* [3][0x50]*/ - 0x42C2EEDA, 0x9F874462, 0xFDA5CD5B, 0x20E067E3, 0x39E0DF29, 0xE4A57591, 0x8687FCA8, 0x5BC25610, /* [3][0x58]*/ - 0xB4868D3C, 0x69C32784, 0x0BE1AEBD, 0xD6A40405, 0xCFA4BCCF, 0x12E11677, 0x70C39F4E, 0xAD8635F6, /* [3][0x60]*/ - 0x7C834B6C, 0xA1C6E1D4, 0xC3E468ED, 0x1EA1C255, 0x07A17A9F, 0xDAE4D027, 0xB8C6591E, 0x6583F3A6, /* [3][0x68]*/ - 0x8AC7288A, 0x57828232, 0x35A00B0B, 0xE8E5A1B3, 0xF1E51979, 0x2CA0B3C1, 0x4E823AF8, 0x93C79040, /* [3][0x70]*/ - 0x95E7FA51, 0x48A250E9, 0x2A80D9D0, 0xF7C57368, 0xEEC5CBA2, 0x3380611A, 0x51A2E823, 0x8CE7429B, /* [3][0x78]*/ - 0x63A399B7, 0xBEE6330F, 0xDCC4BA36, 0x0181108E, 0x1881A844, 0xC5C402FC, 0xA7E68BC5, 0x7AA3217D, /* [3][0x80]*/ - 0x52A0C93F, 0x8FE56387, 0xEDC7EABE, 0x30824006, 0x2982F8CC, 0xF4C75274, 0x96E5DB4D, 0x4BA071F5, /* [3][0x88]*/ - 0xA4E4AAD9, 0x79A10061, 0x1B838958, 0xC6C623E0, 0xDFC69B2A, 0x02833192, 0x60A1B8AB, 0xBDE41213, /* [3][0x90]*/ - 0xBBC47802, 0x6681D2BA, 0x04A35B83, 0xD9E6F13B, 0xC0E649F1, 0x1DA3E349, 0x7F816A70, 0xA2C4C0C8, /* [3][0x98]*/ - 0x4D801BE4, 0x90C5B15C, 0xF2E73865, 0x2FA292DD, 0x36A22A17, 0xEBE780AF, 0x89C50996, 0x5480A32E, /* [3][0xa0]*/ - 0x8585DDB4, 0x58C0770C, 0x3AE2FE35, 0xE7A7548D, 0xFEA7EC47, 0x23E246FF, 0x41C0CFC6, 0x9C85657E, /* [3][0xa8]*/ - 0x73C1BE52, 0xAE8414EA, 0xCCA69DD3, 0x11E3376B, 0x08E38FA1, 0xD5A62519, 0xB784AC20, 0x6AC10698, /* [3][0xb0]*/ - 0x6CE16C89, 0xB1A4C631, 0xD3864F08, 0x0EC3E5B0, 0x17C35D7A, 0xCA86F7C2, 0xA8A47EFB, 0x75E1D443, /* [3][0xb8]*/ - 0x9AA50F6F, 0x47E0A5D7, 0x25C22CEE, 0xF8878656, 0xE1873E9C, 0x3CC29424, 0x5EE01D1D, 0x83A5B7A5, /* [3][0xc0]*/ - 0xF90696D8, 0x24433C60, 0x4661B559, 0x9B241FE1, 0x8224A72B, 0x5F610D93, 0x3D4384AA, 0xE0062E12, /* [3][0xc8]*/ - 0x0F42F53E, 0xD2075F86, 0xB025D6BF, 0x6D607C07, 0x7460C4CD, 0xA9256E75, 0xCB07E74C, 0x16424DF4, /* [3][0xd0]*/ - 0x106227E5, 0xCD278D5D, 0xAF050464, 0x7240AEDC, 0x6B401616, 0xB605BCAE, 0xD4273597, 0x09629F2F, /* [3][0xd8]*/ - 0xE6264403, 0x3B63EEBB, 0x59416782, 0x8404CD3A, 0x9D0475F0, 0x4041DF48, 0x22635671, 0xFF26FCC9, /* [3][0xe0]*/ - 0x2E238253, 0xF36628EB, 0x9144A1D2, 0x4C010B6A, 0x5501B3A0, 0x88441918, 0xEA669021, 0x37233A99, /* [3][0xe8]*/ - 0xD867E1B5, 0x05224B0D, 0x6700C234, 0xBA45688C, 0xA345D046, 0x7E007AFE, 0x1C22F3C7, 0xC167597F, /* [3][0xf0]*/ - 0xC747336E, 0x1A0299D6, 0x782010EF, 0xA565BA57, 0xBC65029D, 0x6120A825, 0x0302211C, 0xDE478BA4, /* [3][0xf8]*/ - 0x31035088, 0xEC46FA30, 0x8E647309, 0x5321D9B1, 0x4A21617B, 0x9764CBC3, 0xF54642FA, 0x2803E842 /* [3][0x100]*/ - }, - { - 0x00000000, 0x38116FAC, 0x7022DF58, 0x4833B0F4, 0xE045BEB0, 0xD854D11C, 0x906761E8, 0xA8760E44, /* [4][0x08]*/ - 0xC5670B91, 0xFD76643D, 0xB545D4C9, 0x8D54BB65, 0x2522B521, 0x1D33DA8D, 0x55006A79, 0x6D1105D5, /* [4][0x10]*/ - 0x8F2261D3, 0xB7330E7F, 0xFF00BE8B, 0xC711D127, 0x6F67DF63, 0x5776B0CF, 0x1F45003B, 0x27546F97, /* [4][0x18]*/ - 0x4A456A42, 0x725405EE, 0x3A67B51A, 0x0276DAB6, 0xAA00D4F2, 0x9211BB5E, 0xDA220BAA, 0xE2336406, /* [4][0x20]*/ - 0x1BA8B557, 0x23B9DAFB, 0x6B8A6A0F, 0x539B05A3, 0xFBED0BE7, 0xC3FC644B, 0x8BCFD4BF, 0xB3DEBB13, /* [4][0x28]*/ - 0xDECFBEC6, 0xE6DED16A, 0xAEED619E, 0x96FC0E32, 0x3E8A0076, 0x069B6FDA, 0x4EA8DF2E, 0x76B9B082, /* [4][0x30]*/ - 0x948AD484, 0xAC9BBB28, 0xE4A80BDC, 0xDCB96470, 0x74CF6A34, 0x4CDE0598, 0x04EDB56C, 0x3CFCDAC0, /* [4][0x38]*/ - 0x51EDDF15, 0x69FCB0B9, 0x21CF004D, 0x19DE6FE1, 0xB1A861A5, 0x89B90E09, 0xC18ABEFD, 0xF99BD151, /* [4][0x40]*/ - 0x37516AAE, 0x0F400502, 0x4773B5F6, 0x7F62DA5A, 0xD714D41E, 0xEF05BBB2, 0xA7360B46, 0x9F2764EA, /* [4][0x48]*/ - 0xF236613F, 0xCA270E93, 0x8214BE67, 0xBA05D1CB, 0x1273DF8F, 0x2A62B023, 0x625100D7, 0x5A406F7B, /* [4][0x50]*/ - 0xB8730B7D, 0x806264D1, 0xC851D425, 0xF040BB89, 0x5836B5CD, 0x6027DA61, 0x28146A95, 0x10050539, /* [4][0x58]*/ - 0x7D1400EC, 0x45056F40, 0x0D36DFB4, 0x3527B018, 0x9D51BE5C, 0xA540D1F0, 0xED736104, 0xD5620EA8, /* [4][0x60]*/ - 0x2CF9DFF9, 0x14E8B055, 0x5CDB00A1, 0x64CA6F0D, 0xCCBC6149, 0xF4AD0EE5, 0xBC9EBE11, 0x848FD1BD, /* [4][0x68]*/ - 0xE99ED468, 0xD18FBBC4, 0x99BC0B30, 0xA1AD649C, 0x09DB6AD8, 0x31CA0574, 0x79F9B580, 0x41E8DA2C, /* [4][0x70]*/ - 0xA3DBBE2A, 0x9BCAD186, 0xD3F96172, 0xEBE80EDE, 0x439E009A, 0x7B8F6F36, 0x33BCDFC2, 0x0BADB06E, /* [4][0x78]*/ - 0x66BCB5BB, 0x5EADDA17, 0x169E6AE3, 0x2E8F054F, 0x86F90B0B, 0xBEE864A7, 0xF6DBD453, 0xCECABBFF, /* [4][0x80]*/ - 0x6EA2D55C, 0x56B3BAF0, 0x1E800A04, 0x269165A8, 0x8EE76BEC, 0xB6F60440, 0xFEC5B4B4, 0xC6D4DB18, /* [4][0x88]*/ - 0xABC5DECD, 0x93D4B161, 0xDBE70195, 0xE3F66E39, 0x4B80607D, 0x73910FD1, 0x3BA2BF25, 0x03B3D089, /* [4][0x90]*/ - 0xE180B48F, 0xD991DB23, 0x91A26BD7, 0xA9B3047B, 0x01C50A3F, 0x39D46593, 0x71E7D567, 0x49F6BACB, /* [4][0x98]*/ - 0x24E7BF1E, 0x1CF6D0B2, 0x54C56046, 0x6CD40FEA, 0xC4A201AE, 0xFCB36E02, 0xB480DEF6, 0x8C91B15A, /* [4][0xa0]*/ - 0x750A600B, 0x4D1B0FA7, 0x0528BF53, 0x3D39D0FF, 0x954FDEBB, 0xAD5EB117, 0xE56D01E3, 0xDD7C6E4F, /* [4][0xa8]*/ - 0xB06D6B9A, 0x887C0436, 0xC04FB4C2, 0xF85EDB6E, 0x5028D52A, 0x6839BA86, 0x200A0A72, 0x181B65DE, /* [4][0xb0]*/ - 0xFA2801D8, 0xC2396E74, 0x8A0ADE80, 0xB21BB12C, 0x1A6DBF68, 0x227CD0C4, 0x6A4F6030, 0x525E0F9C, /* [4][0xb8]*/ - 0x3F4F0A49, 0x075E65E5, 0x4F6DD511, 0x777CBABD, 0xDF0AB4F9, 0xE71BDB55, 0xAF286BA1, 0x9739040D, /* [4][0xc0]*/ - 0x59F3BFF2, 0x61E2D05E, 0x29D160AA, 0x11C00F06, 0xB9B60142, 0x81A76EEE, 0xC994DE1A, 0xF185B1B6, /* [4][0xc8]*/ - 0x9C94B463, 0xA485DBCF, 0xECB66B3B, 0xD4A70497, 0x7CD10AD3, 0x44C0657F, 0x0CF3D58B, 0x34E2BA27, /* [4][0xd0]*/ - 0xD6D1DE21, 0xEEC0B18D, 0xA6F30179, 0x9EE26ED5, 0x36946091, 0x0E850F3D, 0x46B6BFC9, 0x7EA7D065, /* [4][0xd8]*/ - 0x13B6D5B0, 0x2BA7BA1C, 0x63940AE8, 0x5B856544, 0xF3F36B00, 0xCBE204AC, 0x83D1B458, 0xBBC0DBF4, /* [4][0xe0]*/ - 0x425B0AA5, 0x7A4A6509, 0x3279D5FD, 0x0A68BA51, 0xA21EB415, 0x9A0FDBB9, 0xD23C6B4D, 0xEA2D04E1, /* [4][0xe8]*/ - 0x873C0134, 0xBF2D6E98, 0xF71EDE6C, 0xCF0FB1C0, 0x6779BF84, 0x5F68D028, 0x175B60DC, 0x2F4A0F70, /* [4][0xf0]*/ - 0xCD796B76, 0xF56804DA, 0xBD5BB42E, 0x854ADB82, 0x2D3CD5C6, 0x152DBA6A, 0x5D1E0A9E, 0x650F6532, /* [4][0xf8]*/ - 0x081E60E7, 0x300F0F4B, 0x783CBFBF, 0x402DD013, 0xE85BDE57, 0xD04AB1FB, 0x9879010F, 0xA0686EA3 /* [4][0x100]*/ - }, - { - 0x00000000, 0xEF306B19, 0xDB8CA0C3, 0x34BCCBDA, 0xB2F53777, 0x5DC55C6E, 0x697997B4, 0x8649FCAD, /* [5][0x08]*/ - 0x6006181F, 0x8F367306, 0xBB8AB8DC, 0x54BAD3C5, 0xD2F32F68, 0x3DC34471, 0x097F8FAB, 0xE64FE4B2, /* [5][0x10]*/ - 0xC00C303E, 0x2F3C5B27, 0x1B8090FD, 0xF4B0FBE4, 0x72F90749, 0x9DC96C50, 0xA975A78A, 0x4645CC93, /* [5][0x18]*/ - 0xA00A2821, 0x4F3A4338, 0x7B8688E2, 0x94B6E3FB, 0x12FF1F56, 0xFDCF744F, 0xC973BF95, 0x2643D48C, /* [5][0x20]*/ - 0x85F4168D, 0x6AC47D94, 0x5E78B64E, 0xB148DD57, 0x370121FA, 0xD8314AE3, 0xEC8D8139, 0x03BDEA20, /* [5][0x28]*/ - 0xE5F20E92, 0x0AC2658B, 0x3E7EAE51, 0xD14EC548, 0x570739E5, 0xB83752FC, 0x8C8B9926, 0x63BBF23F, /* [5][0x30]*/ - 0x45F826B3, 0xAAC84DAA, 0x9E748670, 0x7144ED69, 0xF70D11C4, 0x183D7ADD, 0x2C81B107, 0xC3B1DA1E, /* [5][0x38]*/ - 0x25FE3EAC, 0xCACE55B5, 0xFE729E6F, 0x1142F576, 0x970B09DB, 0x783B62C2, 0x4C87A918, 0xA3B7C201, /* [5][0x40]*/ - 0x0E045BEB, 0xE13430F2, 0xD588FB28, 0x3AB89031, 0xBCF16C9C, 0x53C10785, 0x677DCC5F, 0x884DA746, /* [5][0x48]*/ - 0x6E0243F4, 0x813228ED, 0xB58EE337, 0x5ABE882E, 0xDCF77483, 0x33C71F9A, 0x077BD440, 0xE84BBF59, /* [5][0x50]*/ - 0xCE086BD5, 0x213800CC, 0x1584CB16, 0xFAB4A00F, 0x7CFD5CA2, 0x93CD37BB, 0xA771FC61, 0x48419778, /* [5][0x58]*/ - 0xAE0E73CA, 0x413E18D3, 0x7582D309, 0x9AB2B810, 0x1CFB44BD, 0xF3CB2FA4, 0xC777E47E, 0x28478F67, /* [5][0x60]*/ - 0x8BF04D66, 0x64C0267F, 0x507CEDA5, 0xBF4C86BC, 0x39057A11, 0xD6351108, 0xE289DAD2, 0x0DB9B1CB, /* [5][0x68]*/ - 0xEBF65579, 0x04C63E60, 0x307AF5BA, 0xDF4A9EA3, 0x5903620E, 0xB6330917, 0x828FC2CD, 0x6DBFA9D4, /* [5][0x70]*/ - 0x4BFC7D58, 0xA4CC1641, 0x9070DD9B, 0x7F40B682, 0xF9094A2F, 0x16392136, 0x2285EAEC, 0xCDB581F5, /* [5][0x78]*/ - 0x2BFA6547, 0xC4CA0E5E, 0xF076C584, 0x1F46AE9D, 0x990F5230, 0x763F3929, 0x4283F2F3, 0xADB399EA, /* [5][0x80]*/ - 0x1C08B7D6, 0xF338DCCF, 0xC7841715, 0x28B47C0C, 0xAEFD80A1, 0x41CDEBB8, 0x75712062, 0x9A414B7B, /* [5][0x88]*/ - 0x7C0EAFC9, 0x933EC4D0, 0xA7820F0A, 0x48B26413, 0xCEFB98BE, 0x21CBF3A7, 0x1577387D, 0xFA475364, /* [5][0x90]*/ - 0xDC0487E8, 0x3334ECF1, 0x0788272B, 0xE8B84C32, 0x6EF1B09F, 0x81C1DB86, 0xB57D105C, 0x5A4D7B45, /* [5][0x98]*/ - 0xBC029FF7, 0x5332F4EE, 0x678E3F34, 0x88BE542D, 0x0EF7A880, 0xE1C7C399, 0xD57B0843, 0x3A4B635A, /* [5][0xa0]*/ - 0x99FCA15B, 0x76CCCA42, 0x42700198, 0xAD406A81, 0x2B09962C, 0xC439FD35, 0xF08536EF, 0x1FB55DF6, /* [5][0xa8]*/ - 0xF9FAB944, 0x16CAD25D, 0x22761987, 0xCD46729E, 0x4B0F8E33, 0xA43FE52A, 0x90832EF0, 0x7FB345E9, /* [5][0xb0]*/ - 0x59F09165, 0xB6C0FA7C, 0x827C31A6, 0x6D4C5ABF, 0xEB05A612, 0x0435CD0B, 0x308906D1, 0xDFB96DC8, /* [5][0xb8]*/ - 0x39F6897A, 0xD6C6E263, 0xE27A29B9, 0x0D4A42A0, 0x8B03BE0D, 0x6433D514, 0x508F1ECE, 0xBFBF75D7, /* [5][0xc0]*/ - 0x120CEC3D, 0xFD3C8724, 0xC9804CFE, 0x26B027E7, 0xA0F9DB4A, 0x4FC9B053, 0x7B757B89, 0x94451090, /* [5][0xc8]*/ - 0x720AF422, 0x9D3A9F3B, 0xA98654E1, 0x46B63FF8, 0xC0FFC355, 0x2FCFA84C, 0x1B736396, 0xF443088F, /* [5][0xd0]*/ - 0xD200DC03, 0x3D30B71A, 0x098C7CC0, 0xE6BC17D9, 0x60F5EB74, 0x8FC5806D, 0xBB794BB7, 0x544920AE, /* [5][0xd8]*/ - 0xB206C41C, 0x5D36AF05, 0x698A64DF, 0x86BA0FC6, 0x00F3F36B, 0xEFC39872, 0xDB7F53A8, 0x344F38B1, /* [5][0xe0]*/ - 0x97F8FAB0, 0x78C891A9, 0x4C745A73, 0xA344316A, 0x250DCDC7, 0xCA3DA6DE, 0xFE816D04, 0x11B1061D, /* [5][0xe8]*/ - 0xF7FEE2AF, 0x18CE89B6, 0x2C72426C, 0xC3422975, 0x450BD5D8, 0xAA3BBEC1, 0x9E87751B, 0x71B71E02, /* [5][0xf0]*/ - 0x57F4CA8E, 0xB8C4A197, 0x8C786A4D, 0x63480154, 0xE501FDF9, 0x0A3196E0, 0x3E8D5D3A, 0xD1BD3623, /* [5][0xf8]*/ - 0x37F2D291, 0xD8C2B988, 0xEC7E7252, 0x034E194B, 0x8507E5E6, 0x6A378EFF, 0x5E8B4525, 0xB1BB2E3C /* [5][0x100]*/ - }, - { - 0x00000000, 0x68032CC8, 0xD0065990, 0xB8057558, 0xA5E0C5D1, 0xCDE3E919, 0x75E69C41, 0x1DE5B089, /* [6][0x08]*/ - 0x4E2DFD53, 0x262ED19B, 0x9E2BA4C3, 0xF628880B, 0xEBCD3882, 0x83CE144A, 0x3BCB6112, 0x53C84DDA, /* [6][0x10]*/ - 0x9C5BFAA6, 0xF458D66E, 0x4C5DA336, 0x245E8FFE, 0x39BB3F77, 0x51B813BF, 0xE9BD66E7, 0x81BE4A2F, /* [6][0x18]*/ - 0xD27607F5, 0xBA752B3D, 0x02705E65, 0x6A7372AD, 0x7796C224, 0x1F95EEEC, 0xA7909BB4, 0xCF93B77C, /* [6][0x20]*/ - 0x3D5B83BD, 0x5558AF75, 0xED5DDA2D, 0x855EF6E5, 0x98BB466C, 0xF0B86AA4, 0x48BD1FFC, 0x20BE3334, /* [6][0x28]*/ - 0x73767EEE, 0x1B755226, 0xA370277E, 0xCB730BB6, 0xD696BB3F, 0xBE9597F7, 0x0690E2AF, 0x6E93CE67, /* [6][0x30]*/ - 0xA100791B, 0xC90355D3, 0x7106208B, 0x19050C43, 0x04E0BCCA, 0x6CE39002, 0xD4E6E55A, 0xBCE5C992, /* [6][0x38]*/ - 0xEF2D8448, 0x872EA880, 0x3F2BDDD8, 0x5728F110, 0x4ACD4199, 0x22CE6D51, 0x9ACB1809, 0xF2C834C1, /* [6][0x40]*/ - 0x7AB7077A, 0x12B42BB2, 0xAAB15EEA, 0xC2B27222, 0xDF57C2AB, 0xB754EE63, 0x0F519B3B, 0x6752B7F3, /* [6][0x48]*/ - 0x349AFA29, 0x5C99D6E1, 0xE49CA3B9, 0x8C9F8F71, 0x917A3FF8, 0xF9791330, 0x417C6668, 0x297F4AA0, /* [6][0x50]*/ - 0xE6ECFDDC, 0x8EEFD114, 0x36EAA44C, 0x5EE98884, 0x430C380D, 0x2B0F14C5, 0x930A619D, 0xFB094D55, /* [6][0x58]*/ - 0xA8C1008F, 0xC0C22C47, 0x78C7591F, 0x10C475D7, 0x0D21C55E, 0x6522E996, 0xDD279CCE, 0xB524B006, /* [6][0x60]*/ - 0x47EC84C7, 0x2FEFA80F, 0x97EADD57, 0xFFE9F19F, 0xE20C4116, 0x8A0F6DDE, 0x320A1886, 0x5A09344E, /* [6][0x68]*/ - 0x09C17994, 0x61C2555C, 0xD9C72004, 0xB1C40CCC, 0xAC21BC45, 0xC422908D, 0x7C27E5D5, 0x1424C91D, /* [6][0x70]*/ - 0xDBB77E61, 0xB3B452A9, 0x0BB127F1, 0x63B20B39, 0x7E57BBB0, 0x16549778, 0xAE51E220, 0xC652CEE8, /* [6][0x78]*/ - 0x959A8332, 0xFD99AFFA, 0x459CDAA2, 0x2D9FF66A, 0x307A46E3, 0x58796A2B, 0xE07C1F73, 0x887F33BB, /* [6][0x80]*/ - 0xF56E0EF4, 0x9D6D223C, 0x25685764, 0x4D6B7BAC, 0x508ECB25, 0x388DE7ED, 0x808892B5, 0xE88BBE7D, /* [6][0x88]*/ - 0xBB43F3A7, 0xD340DF6F, 0x6B45AA37, 0x034686FF, 0x1EA33676, 0x76A01ABE, 0xCEA56FE6, 0xA6A6432E, /* [6][0x90]*/ - 0x6935F452, 0x0136D89A, 0xB933ADC2, 0xD130810A, 0xCCD53183, 0xA4D61D4B, 0x1CD36813, 0x74D044DB, /* [6][0x98]*/ - 0x27180901, 0x4F1B25C9, 0xF71E5091, 0x9F1D7C59, 0x82F8CCD0, 0xEAFBE018, 0x52FE9540, 0x3AFDB988, /* [6][0xa0]*/ - 0xC8358D49, 0xA036A181, 0x1833D4D9, 0x7030F811, 0x6DD54898, 0x05D66450, 0xBDD31108, 0xD5D03DC0, /* [6][0xa8]*/ - 0x8618701A, 0xEE1B5CD2, 0x561E298A, 0x3E1D0542, 0x23F8B5CB, 0x4BFB9903, 0xF3FEEC5B, 0x9BFDC093, /* [6][0xb0]*/ - 0x546E77EF, 0x3C6D5B27, 0x84682E7F, 0xEC6B02B7, 0xF18EB23E, 0x998D9EF6, 0x2188EBAE, 0x498BC766, /* [6][0xb8]*/ - 0x1A438ABC, 0x7240A674, 0xCA45D32C, 0xA246FFE4, 0xBFA34F6D, 0xD7A063A5, 0x6FA516FD, 0x07A63A35, /* [6][0xc0]*/ - 0x8FD9098E, 0xE7DA2546, 0x5FDF501E, 0x37DC7CD6, 0x2A39CC5F, 0x423AE097, 0xFA3F95CF, 0x923CB907, /* [6][0xc8]*/ - 0xC1F4F4DD, 0xA9F7D815, 0x11F2AD4D, 0x79F18185, 0x6414310C, 0x0C171DC4, 0xB412689C, 0xDC114454, /* [6][0xd0]*/ - 0x1382F328, 0x7B81DFE0, 0xC384AAB8, 0xAB878670, 0xB66236F9, 0xDE611A31, 0x66646F69, 0x0E6743A1, /* [6][0xd8]*/ - 0x5DAF0E7B, 0x35AC22B3, 0x8DA957EB, 0xE5AA7B23, 0xF84FCBAA, 0x904CE762, 0x2849923A, 0x404ABEF2, /* [6][0xe0]*/ - 0xB2828A33, 0xDA81A6FB, 0x6284D3A3, 0x0A87FF6B, 0x17624FE2, 0x7F61632A, 0xC7641672, 0xAF673ABA, /* [6][0xe8]*/ - 0xFCAF7760, 0x94AC5BA8, 0x2CA92EF0, 0x44AA0238, 0x594FB2B1, 0x314C9E79, 0x8949EB21, 0xE14AC7E9, /* [6][0xf0]*/ - 0x2ED97095, 0x46DA5C5D, 0xFEDF2905, 0x96DC05CD, 0x8B39B544, 0xE33A998C, 0x5B3FECD4, 0x333CC01C, /* [6][0xf8]*/ - 0x60F48DC6, 0x08F7A10E, 0xB0F2D456, 0xD8F1F89E, 0xC5144817, 0xAD1764DF, 0x15121187, 0x7D113D4F /* [6][0x100]*/ - }, - { - 0x00000000, 0x493C7D27, 0x9278FA4E, 0xDB448769, 0x211D826D, 0x6821FF4A, 0xB3657823, 0xFA590504, /* [7][0x08]*/ - 0x423B04DA, 0x0B0779FD, 0xD043FE94, 0x997F83B3, 0x632686B7, 0x2A1AFB90, 0xF15E7CF9, 0xB86201DE, /* [7][0x10]*/ - 0x847609B4, 0xCD4A7493, 0x160EF3FA, 0x5F328EDD, 0xA56B8BD9, 0xEC57F6FE, 0x37137197, 0x7E2F0CB0, /* [7][0x18]*/ - 0xC64D0D6E, 0x8F717049, 0x5435F720, 0x1D098A07, 0xE7508F03, 0xAE6CF224, 0x7528754D, 0x3C14086A, /* [7][0x20]*/ - 0x0D006599, 0x443C18BE, 0x9F789FD7, 0xD644E2F0, 0x2C1DE7F4, 0x65219AD3, 0xBE651DBA, 0xF759609D, /* [7][0x28]*/ - 0x4F3B6143, 0x06071C64, 0xDD439B0D, 0x947FE62A, 0x6E26E32E, 0x271A9E09, 0xFC5E1960, 0xB5626447, /* [7][0x30]*/ - 0x89766C2D, 0xC04A110A, 0x1B0E9663, 0x5232EB44, 0xA86BEE40, 0xE1579367, 0x3A13140E, 0x732F6929, /* [7][0x38]*/ - 0xCB4D68F7, 0x827115D0, 0x593592B9, 0x1009EF9E, 0xEA50EA9A, 0xA36C97BD, 0x782810D4, 0x31146DF3, /* [7][0x40]*/ - 0x1A00CB32, 0x533CB615, 0x8878317C, 0xC1444C5B, 0x3B1D495F, 0x72213478, 0xA965B311, 0xE059CE36, /* [7][0x48]*/ - 0x583BCFE8, 0x1107B2CF, 0xCA4335A6, 0x837F4881, 0x79264D85, 0x301A30A2, 0xEB5EB7CB, 0xA262CAEC, /* [7][0x50]*/ - 0x9E76C286, 0xD74ABFA1, 0x0C0E38C8, 0x453245EF, 0xBF6B40EB, 0xF6573DCC, 0x2D13BAA5, 0x642FC782, /* [7][0x58]*/ - 0xDC4DC65C, 0x9571BB7B, 0x4E353C12, 0x07094135, 0xFD504431, 0xB46C3916, 0x6F28BE7F, 0x2614C358, /* [7][0x60]*/ - 0x1700AEAB, 0x5E3CD38C, 0x857854E5, 0xCC4429C2, 0x361D2CC6, 0x7F2151E1, 0xA465D688, 0xED59ABAF, /* [7][0x68]*/ - 0x553BAA71, 0x1C07D756, 0xC743503F, 0x8E7F2D18, 0x7426281C, 0x3D1A553B, 0xE65ED252, 0xAF62AF75, /* [7][0x70]*/ - 0x9376A71F, 0xDA4ADA38, 0x010E5D51, 0x48322076, 0xB26B2572, 0xFB575855, 0x2013DF3C, 0x692FA21B, /* [7][0x78]*/ - 0xD14DA3C5, 0x9871DEE2, 0x4335598B, 0x0A0924AC, 0xF05021A8, 0xB96C5C8F, 0x6228DBE6, 0x2B14A6C1, /* [7][0x80]*/ - 0x34019664, 0x7D3DEB43, 0xA6796C2A, 0xEF45110D, 0x151C1409, 0x5C20692E, 0x8764EE47, 0xCE589360, /* [7][0x88]*/ - 0x763A92BE, 0x3F06EF99, 0xE44268F0, 0xAD7E15D7, 0x572710D3, 0x1E1B6DF4, 0xC55FEA9D, 0x8C6397BA, /* [7][0x90]*/ - 0xB0779FD0, 0xF94BE2F7, 0x220F659E, 0x6B3318B9, 0x916A1DBD, 0xD856609A, 0x0312E7F3, 0x4A2E9AD4, /* [7][0x98]*/ - 0xF24C9B0A, 0xBB70E62D, 0x60346144, 0x29081C63, 0xD3511967, 0x9A6D6440, 0x4129E329, 0x08159E0E, /* [7][0xa0]*/ - 0x3901F3FD, 0x703D8EDA, 0xAB7909B3, 0xE2457494, 0x181C7190, 0x51200CB7, 0x8A648BDE, 0xC358F6F9, /* [7][0xa8]*/ - 0x7B3AF727, 0x32068A00, 0xE9420D69, 0xA07E704E, 0x5A27754A, 0x131B086D, 0xC85F8F04, 0x8163F223, /* [7][0xb0]*/ - 0xBD77FA49, 0xF44B876E, 0x2F0F0007, 0x66337D20, 0x9C6A7824, 0xD5560503, 0x0E12826A, 0x472EFF4D, /* [7][0xb8]*/ - 0xFF4CFE93, 0xB67083B4, 0x6D3404DD, 0x240879FA, 0xDE517CFE, 0x976D01D9, 0x4C2986B0, 0x0515FB97, /* [7][0xc0]*/ - 0x2E015D56, 0x673D2071, 0xBC79A718, 0xF545DA3F, 0x0F1CDF3B, 0x4620A21C, 0x9D642575, 0xD4585852, /* [7][0xc8]*/ - 0x6C3A598C, 0x250624AB, 0xFE42A3C2, 0xB77EDEE5, 0x4D27DBE1, 0x041BA6C6, 0xDF5F21AF, 0x96635C88, /* [7][0xd0]*/ - 0xAA7754E2, 0xE34B29C5, 0x380FAEAC, 0x7133D38B, 0x8B6AD68F, 0xC256ABA8, 0x19122CC1, 0x502E51E6, /* [7][0xd8]*/ - 0xE84C5038, 0xA1702D1F, 0x7A34AA76, 0x3308D751, 0xC951D255, 0x806DAF72, 0x5B29281B, 0x1215553C, /* [7][0xe0]*/ - 0x230138CF, 0x6A3D45E8, 0xB179C281, 0xF845BFA6, 0x021CBAA2, 0x4B20C785, 0x906440EC, 0xD9583DCB, /* [7][0xe8]*/ - 0x613A3C15, 0x28064132, 0xF342C65B, 0xBA7EBB7C, 0x4027BE78, 0x091BC35F, 0xD25F4436, 0x9B633911, /* [7][0xf0]*/ - 0xA777317B, 0xEE4B4C5C, 0x350FCB35, 0x7C33B612, 0x866AB316, 0xCF56CE31, 0x14124958, 0x5D2E347F, /* [7][0xf8]*/ - 0xE54C35A1, 0xAC704886, 0x7734CFEF, 0x3E08B2C8, 0xC451B7CC, 0x8D6DCAEB, 0x56294D82, 0x1F1530A5 /* [7][0x100]*/ - }, - { - 0x00000000, 0xF43ED648, 0xED91DA61, 0x19AF0C29, 0xDECFC233, 0x2AF1147B, 0x335E1852, 0xC760CE1A, /* [8][0x08]*/ - 0xB873F297, 0x4C4D24DF, 0x55E228F6, 0xA1DCFEBE, 0x66BC30A4, 0x9282E6EC, 0x8B2DEAC5, 0x7F133C8D, /* [8][0x10]*/ - 0x750B93DF, 0x81354597, 0x989A49BE, 0x6CA49FF6, 0xABC451EC, 0x5FFA87A4, 0x46558B8D, 0xB26B5DC5, /* [8][0x18]*/ - 0xCD786148, 0x3946B700, 0x20E9BB29, 0xD4D76D61, 0x13B7A37B, 0xE7897533, 0xFE26791A, 0x0A18AF52, /* [8][0x20]*/ - 0xEA1727BE, 0x1E29F1F6, 0x0786FDDF, 0xF3B82B97, 0x34D8E58D, 0xC0E633C5, 0xD9493FEC, 0x2D77E9A4, /* [8][0x28]*/ - 0x5264D529, 0xA65A0361, 0xBFF50F48, 0x4BCBD900, 0x8CAB171A, 0x7895C152, 0x613ACD7B, 0x95041B33, /* [8][0x30]*/ - 0x9F1CB461, 0x6B226229, 0x728D6E00, 0x86B3B848, 0x41D37652, 0xB5EDA01A, 0xAC42AC33, 0x587C7A7B, /* [8][0x38]*/ - 0x276F46F6, 0xD35190BE, 0xCAFE9C97, 0x3EC04ADF, 0xF9A084C5, 0x0D9E528D, 0x14315EA4, 0xE00F88EC, /* [8][0x40]*/ - 0xD1C2398D, 0x25FCEFC5, 0x3C53E3EC, 0xC86D35A4, 0x0F0DFBBE, 0xFB332DF6, 0xE29C21DF, 0x16A2F797, /* [8][0x48]*/ - 0x69B1CB1A, 0x9D8F1D52, 0x8420117B, 0x701EC733, 0xB77E0929, 0x4340DF61, 0x5AEFD348, 0xAED10500, /* [8][0x50]*/ - 0xA4C9AA52, 0x50F77C1A, 0x49587033, 0xBD66A67B, 0x7A066861, 0x8E38BE29, 0x9797B200, 0x63A96448, /* [8][0x58]*/ - 0x1CBA58C5, 0xE8848E8D, 0xF12B82A4, 0x051554EC, 0xC2759AF6, 0x364B4CBE, 0x2FE44097, 0xDBDA96DF, /* [8][0x60]*/ - 0x3BD51E33, 0xCFEBC87B, 0xD644C452, 0x227A121A, 0xE51ADC00, 0x11240A48, 0x088B0661, 0xFCB5D029, /* [8][0x68]*/ - 0x83A6ECA4, 0x77983AEC, 0x6E3736C5, 0x9A09E08D, 0x5D692E97, 0xA957F8DF, 0xB0F8F4F6, 0x44C622BE, /* [8][0x70]*/ - 0x4EDE8DEC, 0xBAE05BA4, 0xA34F578D, 0x577181C5, 0x90114FDF, 0x642F9997, 0x7D8095BE, 0x89BE43F6, /* [8][0x78]*/ - 0xF6AD7F7B, 0x0293A933, 0x1B3CA51A, 0xEF027352, 0x2862BD48, 0xDC5C6B00, 0xC5F36729, 0x31CDB161, /* [8][0x80]*/ - 0xA66805EB, 0x5256D3A3, 0x4BF9DF8A, 0xBFC709C2, 0x78A7C7D8, 0x8C991190, 0x95361DB9, 0x6108CBF1, /* [8][0x88]*/ - 0x1E1BF77C, 0xEA252134, 0xF38A2D1D, 0x07B4FB55, 0xC0D4354F, 0x34EAE307, 0x2D45EF2E, 0xD97B3966, /* [8][0x90]*/ - 0xD3639634, 0x275D407C, 0x3EF24C55, 0xCACC9A1D, 0x0DAC5407, 0xF992824F, 0xE03D8E66, 0x1403582E, /* [8][0x98]*/ - 0x6B1064A3, 0x9F2EB2EB, 0x8681BEC2, 0x72BF688A, 0xB5DFA690, 0x41E170D8, 0x584E7CF1, 0xAC70AAB9, /* [8][0xa0]*/ - 0x4C7F2255, 0xB841F41D, 0xA1EEF834, 0x55D02E7C, 0x92B0E066, 0x668E362E, 0x7F213A07, 0x8B1FEC4F, /* [8][0xa8]*/ - 0xF40CD0C2, 0x0032068A, 0x199D0AA3, 0xEDA3DCEB, 0x2AC312F1, 0xDEFDC4B9, 0xC752C890, 0x336C1ED8, /* [8][0xb0]*/ - 0x3974B18A, 0xCD4A67C2, 0xD4E56BEB, 0x20DBBDA3, 0xE7BB73B9, 0x1385A5F1, 0x0A2AA9D8, 0xFE147F90, /* [8][0xb8]*/ - 0x8107431D, 0x75399555, 0x6C96997C, 0x98A84F34, 0x5FC8812E, 0xABF65766, 0xB2595B4F, 0x46678D07, /* [8][0xc0]*/ - 0x77AA3C66, 0x8394EA2E, 0x9A3BE607, 0x6E05304F, 0xA965FE55, 0x5D5B281D, 0x44F42434, 0xB0CAF27C, /* [8][0xc8]*/ - 0xCFD9CEF1, 0x3BE718B9, 0x22481490, 0xD676C2D8, 0x11160CC2, 0xE528DA8A, 0xFC87D6A3, 0x08B900EB, /* [8][0xd0]*/ - 0x02A1AFB9, 0xF69F79F1, 0xEF3075D8, 0x1B0EA390, 0xDC6E6D8A, 0x2850BBC2, 0x31FFB7EB, 0xC5C161A3, /* [8][0xd8]*/ - 0xBAD25D2E, 0x4EEC8B66, 0x5743874F, 0xA37D5107, 0x641D9F1D, 0x90234955, 0x898C457C, 0x7DB29334, /* [8][0xe0]*/ - 0x9DBD1BD8, 0x6983CD90, 0x702CC1B9, 0x841217F1, 0x4372D9EB, 0xB74C0FA3, 0xAEE3038A, 0x5ADDD5C2, /* [8][0xe8]*/ - 0x25CEE94F, 0xD1F03F07, 0xC85F332E, 0x3C61E566, 0xFB012B7C, 0x0F3FFD34, 0x1690F11D, 0xE2AE2755, /* [8][0xf0]*/ - 0xE8B68807, 0x1C885E4F, 0x05275266, 0xF119842E, 0x36794A34, 0xC2479C7C, 0xDBE89055, 0x2FD6461D, /* [8][0xf8]*/ - 0x50C57A90, 0xA4FBACD8, 0xBD54A0F1, 0x496A76B9, 0x8E0AB8A3, 0x7A346EEB, 0x639B62C2, 0x97A5B48A /* [8][0x100]*/ - }, - { - 0x00000000, 0xCB567BA5, 0x934081BB, 0x5816FA1E, 0x236D7587, 0xE83B0E22, 0xB02DF43C, 0x7B7B8F99, /* [9][0x08]*/ - 0x46DAEB0E, 0x8D8C90AB, 0xD59A6AB5, 0x1ECC1110, 0x65B79E89, 0xAEE1E52C, 0xF6F71F32, 0x3DA16497, /* [9][0x10]*/ - 0x8DB5D61C, 0x46E3ADB9, 0x1EF557A7, 0xD5A32C02, 0xAED8A39B, 0x658ED83E, 0x3D982220, 0xF6CE5985, /* [9][0x18]*/ - 0xCB6F3D12, 0x003946B7, 0x582FBCA9, 0x9379C70C, 0xE8024895, 0x23543330, 0x7B42C92E, 0xB014B28B, /* [9][0x20]*/ - 0x1E87DAC9, 0xD5D1A16C, 0x8DC75B72, 0x469120D7, 0x3DEAAF4E, 0xF6BCD4EB, 0xAEAA2EF5, 0x65FC5550, /* [9][0x28]*/ - 0x585D31C7, 0x930B4A62, 0xCB1DB07C, 0x004BCBD9, 0x7B304440, 0xB0663FE5, 0xE870C5FB, 0x2326BE5E, /* [9][0x30]*/ - 0x93320CD5, 0x58647770, 0x00728D6E, 0xCB24F6CB, 0xB05F7952, 0x7B0902F7, 0x231FF8E9, 0xE849834C, /* [9][0x38]*/ - 0xD5E8E7DB, 0x1EBE9C7E, 0x46A86660, 0x8DFE1DC5, 0xF685925C, 0x3DD3E9F9, 0x65C513E7, 0xAE936842, /* [9][0x40]*/ - 0x3D0FB592, 0xF659CE37, 0xAE4F3429, 0x65194F8C, 0x1E62C015, 0xD534BBB0, 0x8D2241AE, 0x46743A0B, /* [9][0x48]*/ - 0x7BD55E9C, 0xB0832539, 0xE895DF27, 0x23C3A482, 0x58B82B1B, 0x93EE50BE, 0xCBF8AAA0, 0x00AED105, /* [9][0x50]*/ - 0xB0BA638E, 0x7BEC182B, 0x23FAE235, 0xE8AC9990, 0x93D71609, 0x58816DAC, 0x009797B2, 0xCBC1EC17, /* [9][0x58]*/ - 0xF6608880, 0x3D36F325, 0x6520093B, 0xAE76729E, 0xD50DFD07, 0x1E5B86A2, 0x464D7CBC, 0x8D1B0719, /* [9][0x60]*/ - 0x23886F5B, 0xE8DE14FE, 0xB0C8EEE0, 0x7B9E9545, 0x00E51ADC, 0xCBB36179, 0x93A59B67, 0x58F3E0C2, /* [9][0x68]*/ - 0x65528455, 0xAE04FFF0, 0xF61205EE, 0x3D447E4B, 0x463FF1D2, 0x8D698A77, 0xD57F7069, 0x1E290BCC, /* [9][0x70]*/ - 0xAE3DB947, 0x656BC2E2, 0x3D7D38FC, 0xF62B4359, 0x8D50CCC0, 0x4606B765, 0x1E104D7B, 0xD54636DE, /* [9][0x78]*/ - 0xE8E75249, 0x23B129EC, 0x7BA7D3F2, 0xB0F1A857, 0xCB8A27CE, 0x00DC5C6B, 0x58CAA675, 0x939CDDD0, /* [9][0x80]*/ - 0x7A1F6B24, 0xB1491081, 0xE95FEA9F, 0x2209913A, 0x59721EA3, 0x92246506, 0xCA329F18, 0x0164E4BD, /* [9][0x88]*/ - 0x3CC5802A, 0xF793FB8F, 0xAF850191, 0x64D37A34, 0x1FA8F5AD, 0xD4FE8E08, 0x8CE87416, 0x47BE0FB3, /* [9][0x90]*/ - 0xF7AABD38, 0x3CFCC69D, 0x64EA3C83, 0xAFBC4726, 0xD4C7C8BF, 0x1F91B31A, 0x47874904, 0x8CD132A1, /* [9][0x98]*/ - 0xB1705636, 0x7A262D93, 0x2230D78D, 0xE966AC28, 0x921D23B1, 0x594B5814, 0x015DA20A, 0xCA0BD9AF, /* [9][0xa0]*/ - 0x6498B1ED, 0xAFCECA48, 0xF7D83056, 0x3C8E4BF3, 0x47F5C46A, 0x8CA3BFCF, 0xD4B545D1, 0x1FE33E74, /* [9][0xa8]*/ - 0x22425AE3, 0xE9142146, 0xB102DB58, 0x7A54A0FD, 0x012F2F64, 0xCA7954C1, 0x926FAEDF, 0x5939D57A, /* [9][0xb0]*/ - 0xE92D67F1, 0x227B1C54, 0x7A6DE64A, 0xB13B9DEF, 0xCA401276, 0x011669D3, 0x590093CD, 0x9256E868, /* [9][0xb8]*/ - 0xAFF78CFF, 0x64A1F75A, 0x3CB70D44, 0xF7E176E1, 0x8C9AF978, 0x47CC82DD, 0x1FDA78C3, 0xD48C0366, /* [9][0xc0]*/ - 0x4710DEB6, 0x8C46A513, 0xD4505F0D, 0x1F0624A8, 0x647DAB31, 0xAF2BD094, 0xF73D2A8A, 0x3C6B512F, /* [9][0xc8]*/ - 0x01CA35B8, 0xCA9C4E1D, 0x928AB403, 0x59DCCFA6, 0x22A7403F, 0xE9F13B9A, 0xB1E7C184, 0x7AB1BA21, /* [9][0xd0]*/ - 0xCAA508AA, 0x01F3730F, 0x59E58911, 0x92B3F2B4, 0xE9C87D2D, 0x229E0688, 0x7A88FC96, 0xB1DE8733, /* [9][0xd8]*/ - 0x8C7FE3A4, 0x47299801, 0x1F3F621F, 0xD46919BA, 0xAF129623, 0x6444ED86, 0x3C521798, 0xF7046C3D, /* [9][0xe0]*/ - 0x5997047F, 0x92C17FDA, 0xCAD785C4, 0x0181FE61, 0x7AFA71F8, 0xB1AC0A5D, 0xE9BAF043, 0x22EC8BE6, /* [9][0xe8]*/ - 0x1F4DEF71, 0xD41B94D4, 0x8C0D6ECA, 0x475B156F, 0x3C209AF6, 0xF776E153, 0xAF601B4D, 0x643660E8, /* [9][0xf0]*/ - 0xD422D263, 0x1F74A9C6, 0x476253D8, 0x8C34287D, 0xF74FA7E4, 0x3C19DC41, 0x640F265F, 0xAF595DFA, /* [9][0xf8]*/ - 0x92F8396D, 0x59AE42C8, 0x01B8B8D6, 0xCAEEC373, 0xB1954CEA, 0x7AC3374F, 0x22D5CD51, 0xE983B6F4 /* [9][0x100]*/ - }, - { - 0x00000000, 0x9771F7C1, 0x2B0F9973, 0xBC7E6EB2, 0x561F32E6, 0xC16EC527, 0x7D10AB95, 0xEA615C54, /* [10][0x08]*/ - 0xAC3E65CC, 0x3B4F920D, 0x8731FCBF, 0x10400B7E, 0xFA21572A, 0x6D50A0EB, 0xD12ECE59, 0x465F3998, /* [10][0x10]*/ - 0x5D90BD69, 0xCAE14AA8, 0x769F241A, 0xE1EED3DB, 0x0B8F8F8F, 0x9CFE784E, 0x208016FC, 0xB7F1E13D, /* [10][0x18]*/ - 0xF1AED8A5, 0x66DF2F64, 0xDAA141D6, 0x4DD0B617, 0xA7B1EA43, 0x30C01D82, 0x8CBE7330, 0x1BCF84F1, /* [10][0x20]*/ - 0xBB217AD2, 0x2C508D13, 0x902EE3A1, 0x075F1460, 0xED3E4834, 0x7A4FBFF5, 0xC631D147, 0x51402686, /* [10][0x28]*/ - 0x171F1F1E, 0x806EE8DF, 0x3C10866D, 0xAB6171AC, 0x41002DF8, 0xD671DA39, 0x6A0FB48B, 0xFD7E434A, /* [10][0x30]*/ - 0xE6B1C7BB, 0x71C0307A, 0xCDBE5EC8, 0x5ACFA909, 0xB0AEF55D, 0x27DF029C, 0x9BA16C2E, 0x0CD09BEF, /* [10][0x38]*/ - 0x4A8FA277, 0xDDFE55B6, 0x61803B04, 0xF6F1CCC5, 0x1C909091, 0x8BE16750, 0x379F09E2, 0xA0EEFE23, /* [10][0x40]*/ - 0x73AE8355, 0xE4DF7494, 0x58A11A26, 0xCFD0EDE7, 0x25B1B1B3, 0xB2C04672, 0x0EBE28C0, 0x99CFDF01, /* [10][0x48]*/ - 0xDF90E699, 0x48E11158, 0xF49F7FEA, 0x63EE882B, 0x898FD47F, 0x1EFE23BE, 0xA2804D0C, 0x35F1BACD, /* [10][0x50]*/ - 0x2E3E3E3C, 0xB94FC9FD, 0x0531A74F, 0x9240508E, 0x78210CDA, 0xEF50FB1B, 0x532E95A9, 0xC45F6268, /* [10][0x58]*/ - 0x82005BF0, 0x1571AC31, 0xA90FC283, 0x3E7E3542, 0xD41F6916, 0x436E9ED7, 0xFF10F065, 0x686107A4, /* [10][0x60]*/ - 0xC88FF987, 0x5FFE0E46, 0xE38060F4, 0x74F19735, 0x9E90CB61, 0x09E13CA0, 0xB59F5212, 0x22EEA5D3, /* [10][0x68]*/ - 0x64B19C4B, 0xF3C06B8A, 0x4FBE0538, 0xD8CFF2F9, 0x32AEAEAD, 0xA5DF596C, 0x19A137DE, 0x8ED0C01F, /* [10][0x70]*/ - 0x951F44EE, 0x026EB32F, 0xBE10DD9D, 0x29612A5C, 0xC3007608, 0x547181C9, 0xE80FEF7B, 0x7F7E18BA, /* [10][0x78]*/ - 0x39212122, 0xAE50D6E3, 0x122EB851, 0x855F4F90, 0x6F3E13C4, 0xF84FE405, 0x44318AB7, 0xD3407D76, /* [10][0x80]*/ - 0xE75D06AA, 0x702CF16B, 0xCC529FD9, 0x5B236818, 0xB142344C, 0x2633C38D, 0x9A4DAD3F, 0x0D3C5AFE, /* [10][0x88]*/ - 0x4B636366, 0xDC1294A7, 0x606CFA15, 0xF71D0DD4, 0x1D7C5180, 0x8A0DA641, 0x3673C8F3, 0xA1023F32, /* [10][0x90]*/ - 0xBACDBBC3, 0x2DBC4C02, 0x91C222B0, 0x06B3D571, 0xECD28925, 0x7BA37EE4, 0xC7DD1056, 0x50ACE797, /* [10][0x98]*/ - 0x16F3DE0F, 0x818229CE, 0x3DFC477C, 0xAA8DB0BD, 0x40ECECE9, 0xD79D1B28, 0x6BE3759A, 0xFC92825B, /* [10][0xa0]*/ - 0x5C7C7C78, 0xCB0D8BB9, 0x7773E50B, 0xE00212CA, 0x0A634E9E, 0x9D12B95F, 0x216CD7ED, 0xB61D202C, /* [10][0xa8]*/ - 0xF04219B4, 0x6733EE75, 0xDB4D80C7, 0x4C3C7706, 0xA65D2B52, 0x312CDC93, 0x8D52B221, 0x1A2345E0, /* [10][0xb0]*/ - 0x01ECC111, 0x969D36D0, 0x2AE35862, 0xBD92AFA3, 0x57F3F3F7, 0xC0820436, 0x7CFC6A84, 0xEB8D9D45, /* [10][0xb8]*/ - 0xADD2A4DD, 0x3AA3531C, 0x86DD3DAE, 0x11ACCA6F, 0xFBCD963B, 0x6CBC61FA, 0xD0C20F48, 0x47B3F889, /* [10][0xc0]*/ - 0x94F385FF, 0x0382723E, 0xBFFC1C8C, 0x288DEB4D, 0xC2ECB719, 0x559D40D8, 0xE9E32E6A, 0x7E92D9AB, /* [10][0xc8]*/ - 0x38CDE033, 0xAFBC17F2, 0x13C27940, 0x84B38E81, 0x6ED2D2D5, 0xF9A32514, 0x45DD4BA6, 0xD2ACBC67, /* [10][0xd0]*/ - 0xC9633896, 0x5E12CF57, 0xE26CA1E5, 0x751D5624, 0x9F7C0A70, 0x080DFDB1, 0xB4739303, 0x230264C2, /* [10][0xd8]*/ - 0x655D5D5A, 0xF22CAA9B, 0x4E52C429, 0xD92333E8, 0x33426FBC, 0xA433987D, 0x184DF6CF, 0x8F3C010E, /* [10][0xe0]*/ - 0x2FD2FF2D, 0xB8A308EC, 0x04DD665E, 0x93AC919F, 0x79CDCDCB, 0xEEBC3A0A, 0x52C254B8, 0xC5B3A379, /* [10][0xe8]*/ - 0x83EC9AE1, 0x149D6D20, 0xA8E30392, 0x3F92F453, 0xD5F3A807, 0x42825FC6, 0xFEFC3174, 0x698DC6B5, /* [10][0xf0]*/ - 0x72424244, 0xE533B585, 0x594DDB37, 0xCE3C2CF6, 0x245D70A2, 0xB32C8763, 0x0F52E9D1, 0x98231E10, /* [10][0xf8]*/ - 0xDE7C2788, 0x490DD049, 0xF573BEFB, 0x6202493A, 0x8863156E, 0x1F12E2AF, 0xA36C8C1D, 0x341D7BDC /* [10][0x100]*/ - }, - { - 0x00000000, 0x3171D430, 0x62E3A860, 0x53927C50, 0xC5C750C0, 0xF4B684F0, 0xA724F8A0, 0x96552C90, /* [11][0x08]*/ - 0x8E62D771, 0xBF130341, 0xEC817F11, 0xDDF0AB21, 0x4BA587B1, 0x7AD45381, 0x29462FD1, 0x1837FBE1, /* [11][0x10]*/ - 0x1929D813, 0x28580C23, 0x7BCA7073, 0x4ABBA443, 0xDCEE88D3, 0xED9F5CE3, 0xBE0D20B3, 0x8F7CF483, /* [11][0x18]*/ - 0x974B0F62, 0xA63ADB52, 0xF5A8A702, 0xC4D97332, 0x528C5FA2, 0x63FD8B92, 0x306FF7C2, 0x011E23F2, /* [11][0x20]*/ - 0x3253B026, 0x03226416, 0x50B01846, 0x61C1CC76, 0xF794E0E6, 0xC6E534D6, 0x95774886, 0xA4069CB6, /* [11][0x28]*/ - 0xBC316757, 0x8D40B367, 0xDED2CF37, 0xEFA31B07, 0x79F63797, 0x4887E3A7, 0x1B159FF7, 0x2A644BC7, /* [11][0x30]*/ - 0x2B7A6835, 0x1A0BBC05, 0x4999C055, 0x78E81465, 0xEEBD38F5, 0xDFCCECC5, 0x8C5E9095, 0xBD2F44A5, /* [11][0x38]*/ - 0xA518BF44, 0x94696B74, 0xC7FB1724, 0xF68AC314, 0x60DFEF84, 0x51AE3BB4, 0x023C47E4, 0x334D93D4, /* [11][0x40]*/ - 0x64A7604C, 0x55D6B47C, 0x0644C82C, 0x37351C1C, 0xA160308C, 0x9011E4BC, 0xC38398EC, 0xF2F24CDC, /* [11][0x48]*/ - 0xEAC5B73D, 0xDBB4630D, 0x88261F5D, 0xB957CB6D, 0x2F02E7FD, 0x1E7333CD, 0x4DE14F9D, 0x7C909BAD, /* [11][0x50]*/ - 0x7D8EB85F, 0x4CFF6C6F, 0x1F6D103F, 0x2E1CC40F, 0xB849E89F, 0x89383CAF, 0xDAAA40FF, 0xEBDB94CF, /* [11][0x58]*/ - 0xF3EC6F2E, 0xC29DBB1E, 0x910FC74E, 0xA07E137E, 0x362B3FEE, 0x075AEBDE, 0x54C8978E, 0x65B943BE, /* [11][0x60]*/ - 0x56F4D06A, 0x6785045A, 0x3417780A, 0x0566AC3A, 0x933380AA, 0xA242549A, 0xF1D028CA, 0xC0A1FCFA, /* [11][0x68]*/ - 0xD896071B, 0xE9E7D32B, 0xBA75AF7B, 0x8B047B4B, 0x1D5157DB, 0x2C2083EB, 0x7FB2FFBB, 0x4EC32B8B, /* [11][0x70]*/ - 0x4FDD0879, 0x7EACDC49, 0x2D3EA019, 0x1C4F7429, 0x8A1A58B9, 0xBB6B8C89, 0xE8F9F0D9, 0xD98824E9, /* [11][0x78]*/ - 0xC1BFDF08, 0xF0CE0B38, 0xA35C7768, 0x922DA358, 0x04788FC8, 0x35095BF8, 0x669B27A8, 0x57EAF398, /* [11][0x80]*/ - 0xC94EC098, 0xF83F14A8, 0xABAD68F8, 0x9ADCBCC8, 0x0C899058, 0x3DF84468, 0x6E6A3838, 0x5F1BEC08, /* [11][0x88]*/ - 0x472C17E9, 0x765DC3D9, 0x25CFBF89, 0x14BE6BB9, 0x82EB4729, 0xB39A9319, 0xE008EF49, 0xD1793B79, /* [11][0x90]*/ - 0xD067188B, 0xE116CCBB, 0xB284B0EB, 0x83F564DB, 0x15A0484B, 0x24D19C7B, 0x7743E02B, 0x4632341B, /* [11][0x98]*/ - 0x5E05CFFA, 0x6F741BCA, 0x3CE6679A, 0x0D97B3AA, 0x9BC29F3A, 0xAAB34B0A, 0xF921375A, 0xC850E36A, /* [11][0xa0]*/ - 0xFB1D70BE, 0xCA6CA48E, 0x99FED8DE, 0xA88F0CEE, 0x3EDA207E, 0x0FABF44E, 0x5C39881E, 0x6D485C2E, /* [11][0xa8]*/ - 0x757FA7CF, 0x440E73FF, 0x179C0FAF, 0x26EDDB9F, 0xB0B8F70F, 0x81C9233F, 0xD25B5F6F, 0xE32A8B5F, /* [11][0xb0]*/ - 0xE234A8AD, 0xD3457C9D, 0x80D700CD, 0xB1A6D4FD, 0x27F3F86D, 0x16822C5D, 0x4510500D, 0x7461843D, /* [11][0xb8]*/ - 0x6C567FDC, 0x5D27ABEC, 0x0EB5D7BC, 0x3FC4038C, 0xA9912F1C, 0x98E0FB2C, 0xCB72877C, 0xFA03534C, /* [11][0xc0]*/ - 0xADE9A0D4, 0x9C9874E4, 0xCF0A08B4, 0xFE7BDC84, 0x682EF014, 0x595F2424, 0x0ACD5874, 0x3BBC8C44, /* [11][0xc8]*/ - 0x238B77A5, 0x12FAA395, 0x4168DFC5, 0x70190BF5, 0xE64C2765, 0xD73DF355, 0x84AF8F05, 0xB5DE5B35, /* [11][0xd0]*/ - 0xB4C078C7, 0x85B1ACF7, 0xD623D0A7, 0xE7520497, 0x71072807, 0x4076FC37, 0x13E48067, 0x22955457, /* [11][0xd8]*/ - 0x3AA2AFB6, 0x0BD37B86, 0x584107D6, 0x6930D3E6, 0xFF65FF76, 0xCE142B46, 0x9D865716, 0xACF78326, /* [11][0xe0]*/ - 0x9FBA10F2, 0xAECBC4C2, 0xFD59B892, 0xCC286CA2, 0x5A7D4032, 0x6B0C9402, 0x389EE852, 0x09EF3C62, /* [11][0xe8]*/ - 0x11D8C783, 0x20A913B3, 0x733B6FE3, 0x424ABBD3, 0xD41F9743, 0xE56E4373, 0xB6FC3F23, 0x878DEB13, /* [11][0xf0]*/ - 0x8693C8E1, 0xB7E21CD1, 0xE4706081, 0xD501B4B1, 0x43549821, 0x72254C11, 0x21B73041, 0x10C6E471, /* [11][0xf8]*/ - 0x08F11F90, 0x3980CBA0, 0x6A12B7F0, 0x5B6363C0, 0xCD364F50, 0xFC479B60, 0xAFD5E730, 0x9EA43300 /* [11][0x100]*/ - }, - { - 0x00000000, 0x30D23865, 0x61A470CA, 0x517648AF, 0xC348E194, 0xF39AD9F1, 0xA2EC915E, 0x923EA93B, /* [12][0x08]*/ - 0x837DB5D9, 0xB3AF8DBC, 0xE2D9C513, 0xD20BFD76, 0x4035544D, 0x70E76C28, 0x21912487, 0x11431CE2, /* [12][0x10]*/ - 0x03171D43, 0x33C52526, 0x62B36D89, 0x526155EC, 0xC05FFCD7, 0xF08DC4B2, 0xA1FB8C1D, 0x9129B478, /* [12][0x18]*/ - 0x806AA89A, 0xB0B890FF, 0xE1CED850, 0xD11CE035, 0x4322490E, 0x73F0716B, 0x228639C4, 0x125401A1, /* [12][0x20]*/ - 0x062E3A86, 0x36FC02E3, 0x678A4A4C, 0x57587229, 0xC566DB12, 0xF5B4E377, 0xA4C2ABD8, 0x941093BD, /* [12][0x28]*/ - 0x85538F5F, 0xB581B73A, 0xE4F7FF95, 0xD425C7F0, 0x461B6ECB, 0x76C956AE, 0x27BF1E01, 0x176D2664, /* [12][0x30]*/ - 0x053927C5, 0x35EB1FA0, 0x649D570F, 0x544F6F6A, 0xC671C651, 0xF6A3FE34, 0xA7D5B69B, 0x97078EFE, /* [12][0x38]*/ - 0x8644921C, 0xB696AA79, 0xE7E0E2D6, 0xD732DAB3, 0x450C7388, 0x75DE4BED, 0x24A80342, 0x147A3B27, /* [12][0x40]*/ - 0x0C5C750C, 0x3C8E4D69, 0x6DF805C6, 0x5D2A3DA3, 0xCF149498, 0xFFC6ACFD, 0xAEB0E452, 0x9E62DC37, /* [12][0x48]*/ - 0x8F21C0D5, 0xBFF3F8B0, 0xEE85B01F, 0xDE57887A, 0x4C692141, 0x7CBB1924, 0x2DCD518B, 0x1D1F69EE, /* [12][0x50]*/ - 0x0F4B684F, 0x3F99502A, 0x6EEF1885, 0x5E3D20E0, 0xCC0389DB, 0xFCD1B1BE, 0xADA7F911, 0x9D75C174, /* [12][0x58]*/ - 0x8C36DD96, 0xBCE4E5F3, 0xED92AD5C, 0xDD409539, 0x4F7E3C02, 0x7FAC0467, 0x2EDA4CC8, 0x1E0874AD, /* [12][0x60]*/ - 0x0A724F8A, 0x3AA077EF, 0x6BD63F40, 0x5B040725, 0xC93AAE1E, 0xF9E8967B, 0xA89EDED4, 0x984CE6B1, /* [12][0x68]*/ - 0x890FFA53, 0xB9DDC236, 0xE8AB8A99, 0xD879B2FC, 0x4A471BC7, 0x7A9523A2, 0x2BE36B0D, 0x1B315368, /* [12][0x70]*/ - 0x096552C9, 0x39B76AAC, 0x68C12203, 0x58131A66, 0xCA2DB35D, 0xFAFF8B38, 0xAB89C397, 0x9B5BFBF2, /* [12][0x78]*/ - 0x8A18E710, 0xBACADF75, 0xEBBC97DA, 0xDB6EAFBF, 0x49500684, 0x79823EE1, 0x28F4764E, 0x18264E2B, /* [12][0x80]*/ - 0x18B8EA18, 0x286AD27D, 0x791C9AD2, 0x49CEA2B7, 0xDBF00B8C, 0xEB2233E9, 0xBA547B46, 0x8A864323, /* [12][0x88]*/ - 0x9BC55FC1, 0xAB1767A4, 0xFA612F0B, 0xCAB3176E, 0x588DBE55, 0x685F8630, 0x3929CE9F, 0x09FBF6FA, /* [12][0x90]*/ - 0x1BAFF75B, 0x2B7DCF3E, 0x7A0B8791, 0x4AD9BFF4, 0xD8E716CF, 0xE8352EAA, 0xB9436605, 0x89915E60, /* [12][0x98]*/ - 0x98D24282, 0xA8007AE7, 0xF9763248, 0xC9A40A2D, 0x5B9AA316, 0x6B489B73, 0x3A3ED3DC, 0x0AECEBB9, /* [12][0xa0]*/ - 0x1E96D09E, 0x2E44E8FB, 0x7F32A054, 0x4FE09831, 0xDDDE310A, 0xED0C096F, 0xBC7A41C0, 0x8CA879A5, /* [12][0xa8]*/ - 0x9DEB6547, 0xAD395D22, 0xFC4F158D, 0xCC9D2DE8, 0x5EA384D3, 0x6E71BCB6, 0x3F07F419, 0x0FD5CC7C, /* [12][0xb0]*/ - 0x1D81CDDD, 0x2D53F5B8, 0x7C25BD17, 0x4CF78572, 0xDEC92C49, 0xEE1B142C, 0xBF6D5C83, 0x8FBF64E6, /* [12][0xb8]*/ - 0x9EFC7804, 0xAE2E4061, 0xFF5808CE, 0xCF8A30AB, 0x5DB49990, 0x6D66A1F5, 0x3C10E95A, 0x0CC2D13F, /* [12][0xc0]*/ - 0x14E49F14, 0x2436A771, 0x7540EFDE, 0x4592D7BB, 0xD7AC7E80, 0xE77E46E5, 0xB6080E4A, 0x86DA362F, /* [12][0xc8]*/ - 0x97992ACD, 0xA74B12A8, 0xF63D5A07, 0xC6EF6262, 0x54D1CB59, 0x6403F33C, 0x3575BB93, 0x05A783F6, /* [12][0xd0]*/ - 0x17F38257, 0x2721BA32, 0x7657F29D, 0x4685CAF8, 0xD4BB63C3, 0xE4695BA6, 0xB51F1309, 0x85CD2B6C, /* [12][0xd8]*/ - 0x948E378E, 0xA45C0FEB, 0xF52A4744, 0xC5F87F21, 0x57C6D61A, 0x6714EE7F, 0x3662A6D0, 0x06B09EB5, /* [12][0xe0]*/ - 0x12CAA592, 0x22189DF7, 0x736ED558, 0x43BCED3D, 0xD1824406, 0xE1507C63, 0xB02634CC, 0x80F40CA9, /* [12][0xe8]*/ - 0x91B7104B, 0xA165282E, 0xF0136081, 0xC0C158E4, 0x52FFF1DF, 0x622DC9BA, 0x335B8115, 0x0389B970, /* [12][0xf0]*/ - 0x11DDB8D1, 0x210F80B4, 0x7079C81B, 0x40ABF07E, 0xD2955945, 0xE2476120, 0xB331298F, 0x83E311EA, /* [12][0xf8]*/ - 0x92A00D08, 0xA272356D, 0xF3047DC2, 0xC3D645A7, 0x51E8EC9C, 0x613AD4F9, 0x304C9C56, 0x009EA433 /* [12][0x100]*/ - }, - { - 0x00000000, 0x54075546, 0xA80EAA8C, 0xFC09FFCA, 0x55F123E9, 0x01F676AF, 0xFDFF8965, 0xA9F8DC23, /* [13][0x08]*/ - 0xABE247D2, 0xFFE51294, 0x03ECED5E, 0x57EBB818, 0xFE13643B, 0xAA14317D, 0x561DCEB7, 0x021A9BF1, /* [13][0x10]*/ - 0x5228F955, 0x062FAC13, 0xFA2653D9, 0xAE21069F, 0x07D9DABC, 0x53DE8FFA, 0xAFD77030, 0xFBD02576, /* [13][0x18]*/ - 0xF9CABE87, 0xADCDEBC1, 0x51C4140B, 0x05C3414D, 0xAC3B9D6E, 0xF83CC828, 0x043537E2, 0x503262A4, /* [13][0x20]*/ - 0xA451F2AA, 0xF056A7EC, 0x0C5F5826, 0x58580D60, 0xF1A0D143, 0xA5A78405, 0x59AE7BCF, 0x0DA92E89, /* [13][0x28]*/ - 0x0FB3B578, 0x5BB4E03E, 0xA7BD1FF4, 0xF3BA4AB2, 0x5A429691, 0x0E45C3D7, 0xF24C3C1D, 0xA64B695B, /* [13][0x30]*/ - 0xF6790BFF, 0xA27E5EB9, 0x5E77A173, 0x0A70F435, 0xA3882816, 0xF78F7D50, 0x0B86829A, 0x5F81D7DC, /* [13][0x38]*/ - 0x5D9B4C2D, 0x099C196B, 0xF595E6A1, 0xA192B3E7, 0x086A6FC4, 0x5C6D3A82, 0xA064C548, 0xF463900E, /* [13][0x40]*/ - 0x4D4F93A5, 0x1948C6E3, 0xE5413929, 0xB1466C6F, 0x18BEB04C, 0x4CB9E50A, 0xB0B01AC0, 0xE4B74F86, /* [13][0x48]*/ - 0xE6ADD477, 0xB2AA8131, 0x4EA37EFB, 0x1AA42BBD, 0xB35CF79E, 0xE75BA2D8, 0x1B525D12, 0x4F550854, /* [13][0x50]*/ - 0x1F676AF0, 0x4B603FB6, 0xB769C07C, 0xE36E953A, 0x4A964919, 0x1E911C5F, 0xE298E395, 0xB69FB6D3, /* [13][0x58]*/ - 0xB4852D22, 0xE0827864, 0x1C8B87AE, 0x488CD2E8, 0xE1740ECB, 0xB5735B8D, 0x497AA447, 0x1D7DF101, /* [13][0x60]*/ - 0xE91E610F, 0xBD193449, 0x4110CB83, 0x15179EC5, 0xBCEF42E6, 0xE8E817A0, 0x14E1E86A, 0x40E6BD2C, /* [13][0x68]*/ - 0x42FC26DD, 0x16FB739B, 0xEAF28C51, 0xBEF5D917, 0x170D0534, 0x430A5072, 0xBF03AFB8, 0xEB04FAFE, /* [13][0x70]*/ - 0xBB36985A, 0xEF31CD1C, 0x133832D6, 0x473F6790, 0xEEC7BBB3, 0xBAC0EEF5, 0x46C9113F, 0x12CE4479, /* [13][0x78]*/ - 0x10D4DF88, 0x44D38ACE, 0xB8DA7504, 0xECDD2042, 0x4525FC61, 0x1122A927, 0xED2B56ED, 0xB92C03AB, /* [13][0x80]*/ - 0x9A9F274A, 0xCE98720C, 0x32918DC6, 0x6696D880, 0xCF6E04A3, 0x9B6951E5, 0x6760AE2F, 0x3367FB69, /* [13][0x88]*/ - 0x317D6098, 0x657A35DE, 0x9973CA14, 0xCD749F52, 0x648C4371, 0x308B1637, 0xCC82E9FD, 0x9885BCBB, /* [13][0x90]*/ - 0xC8B7DE1F, 0x9CB08B59, 0x60B97493, 0x34BE21D5, 0x9D46FDF6, 0xC941A8B0, 0x3548577A, 0x614F023C, /* [13][0x98]*/ - 0x635599CD, 0x3752CC8B, 0xCB5B3341, 0x9F5C6607, 0x36A4BA24, 0x62A3EF62, 0x9EAA10A8, 0xCAAD45EE, /* [13][0xa0]*/ - 0x3ECED5E0, 0x6AC980A6, 0x96C07F6C, 0xC2C72A2A, 0x6B3FF609, 0x3F38A34F, 0xC3315C85, 0x973609C3, /* [13][0xa8]*/ - 0x952C9232, 0xC12BC774, 0x3D2238BE, 0x69256DF8, 0xC0DDB1DB, 0x94DAE49D, 0x68D31B57, 0x3CD44E11, /* [13][0xb0]*/ - 0x6CE62CB5, 0x38E179F3, 0xC4E88639, 0x90EFD37F, 0x39170F5C, 0x6D105A1A, 0x9119A5D0, 0xC51EF096, /* [13][0xb8]*/ - 0xC7046B67, 0x93033E21, 0x6F0AC1EB, 0x3B0D94AD, 0x92F5488E, 0xC6F21DC8, 0x3AFBE202, 0x6EFCB744, /* [13][0xc0]*/ - 0xD7D0B4EF, 0x83D7E1A9, 0x7FDE1E63, 0x2BD94B25, 0x82219706, 0xD626C240, 0x2A2F3D8A, 0x7E2868CC, /* [13][0xc8]*/ - 0x7C32F33D, 0x2835A67B, 0xD43C59B1, 0x803B0CF7, 0x29C3D0D4, 0x7DC48592, 0x81CD7A58, 0xD5CA2F1E, /* [13][0xd0]*/ - 0x85F84DBA, 0xD1FF18FC, 0x2DF6E736, 0x79F1B270, 0xD0096E53, 0x840E3B15, 0x7807C4DF, 0x2C009199, /* [13][0xd8]*/ - 0x2E1A0A68, 0x7A1D5F2E, 0x8614A0E4, 0xD213F5A2, 0x7BEB2981, 0x2FEC7CC7, 0xD3E5830D, 0x87E2D64B, /* [13][0xe0]*/ - 0x73814645, 0x27861303, 0xDB8FECC9, 0x8F88B98F, 0x267065AC, 0x727730EA, 0x8E7ECF20, 0xDA799A66, /* [13][0xe8]*/ - 0xD8630197, 0x8C6454D1, 0x706DAB1B, 0x246AFE5D, 0x8D92227E, 0xD9957738, 0x259C88F2, 0x719BDDB4, /* [13][0xf0]*/ - 0x21A9BF10, 0x75AEEA56, 0x89A7159C, 0xDDA040DA, 0x74589CF9, 0x205FC9BF, 0xDC563675, 0x88516333, /* [13][0xf8]*/ - 0x8A4BF8C2, 0xDE4CAD84, 0x2245524E, 0x76420708, 0xDFBADB2B, 0x8BBD8E6D, 0x77B471A7, 0x23B324E1 /* [13][0x100]*/ - }, - { - 0x00000000, 0x678EFD01, 0xCF1DFA02, 0xA8930703, 0x9BD782F5, 0xFC597FF4, 0x54CA78F7, 0x334485F6, /* [14][0x08]*/ - 0x3243731B, 0x55CD8E1A, 0xFD5E8919, 0x9AD07418, 0xA994F1EE, 0xCE1A0CEF, 0x66890BEC, 0x0107F6ED, /* [14][0x10]*/ - 0x6486E636, 0x03081B37, 0xAB9B1C34, 0xCC15E135, 0xFF5164C3, 0x98DF99C2, 0x304C9EC1, 0x57C263C0, /* [14][0x18]*/ - 0x56C5952D, 0x314B682C, 0x99D86F2F, 0xFE56922E, 0xCD1217D8, 0xAA9CEAD9, 0x020FEDDA, 0x658110DB, /* [14][0x20]*/ - 0xC90DCC6C, 0xAE83316D, 0x0610366E, 0x619ECB6F, 0x52DA4E99, 0x3554B398, 0x9DC7B49B, 0xFA49499A, /* [14][0x28]*/ - 0xFB4EBF77, 0x9CC04276, 0x34534575, 0x53DDB874, 0x60993D82, 0x0717C083, 0xAF84C780, 0xC80A3A81, /* [14][0x30]*/ - 0xAD8B2A5A, 0xCA05D75B, 0x6296D058, 0x05182D59, 0x365CA8AF, 0x51D255AE, 0xF94152AD, 0x9ECFAFAC, /* [14][0x38]*/ - 0x9FC85941, 0xF846A440, 0x50D5A343, 0x375B5E42, 0x041FDBB4, 0x639126B5, 0xCB0221B6, 0xAC8CDCB7, /* [14][0x40]*/ - 0x97F7EE29, 0xF0791328, 0x58EA142B, 0x3F64E92A, 0x0C206CDC, 0x6BAE91DD, 0xC33D96DE, 0xA4B36BDF, /* [14][0x48]*/ - 0xA5B49D32, 0xC23A6033, 0x6AA96730, 0x0D279A31, 0x3E631FC7, 0x59EDE2C6, 0xF17EE5C5, 0x96F018C4, /* [14][0x50]*/ - 0xF371081F, 0x94FFF51E, 0x3C6CF21D, 0x5BE20F1C, 0x68A68AEA, 0x0F2877EB, 0xA7BB70E8, 0xC0358DE9, /* [14][0x58]*/ - 0xC1327B04, 0xA6BC8605, 0x0E2F8106, 0x69A17C07, 0x5AE5F9F1, 0x3D6B04F0, 0x95F803F3, 0xF276FEF2, /* [14][0x60]*/ - 0x5EFA2245, 0x3974DF44, 0x91E7D847, 0xF6692546, 0xC52DA0B0, 0xA2A35DB1, 0x0A305AB2, 0x6DBEA7B3, /* [14][0x68]*/ - 0x6CB9515E, 0x0B37AC5F, 0xA3A4AB5C, 0xC42A565D, 0xF76ED3AB, 0x90E02EAA, 0x387329A9, 0x5FFDD4A8, /* [14][0x70]*/ - 0x3A7CC473, 0x5DF23972, 0xF5613E71, 0x92EFC370, 0xA1AB4686, 0xC625BB87, 0x6EB6BC84, 0x09384185, /* [14][0x78]*/ - 0x083FB768, 0x6FB14A69, 0xC7224D6A, 0xA0ACB06B, 0x93E8359D, 0xF466C89C, 0x5CF5CF9F, 0x3B7B329E, /* [14][0x80]*/ - 0x2A03AAA3, 0x4D8D57A2, 0xE51E50A1, 0x8290ADA0, 0xB1D42856, 0xD65AD557, 0x7EC9D254, 0x19472F55, /* [14][0x88]*/ - 0x1840D9B8, 0x7FCE24B9, 0xD75D23BA, 0xB0D3DEBB, 0x83975B4D, 0xE419A64C, 0x4C8AA14F, 0x2B045C4E, /* [14][0x90]*/ - 0x4E854C95, 0x290BB194, 0x8198B697, 0xE6164B96, 0xD552CE60, 0xB2DC3361, 0x1A4F3462, 0x7DC1C963, /* [14][0x98]*/ - 0x7CC63F8E, 0x1B48C28F, 0xB3DBC58C, 0xD455388D, 0xE711BD7B, 0x809F407A, 0x280C4779, 0x4F82BA78, /* [14][0xa0]*/ - 0xE30E66CF, 0x84809BCE, 0x2C139CCD, 0x4B9D61CC, 0x78D9E43A, 0x1F57193B, 0xB7C41E38, 0xD04AE339, /* [14][0xa8]*/ - 0xD14D15D4, 0xB6C3E8D5, 0x1E50EFD6, 0x79DE12D7, 0x4A9A9721, 0x2D146A20, 0x85876D23, 0xE2099022, /* [14][0xb0]*/ - 0x878880F9, 0xE0067DF8, 0x48957AFB, 0x2F1B87FA, 0x1C5F020C, 0x7BD1FF0D, 0xD342F80E, 0xB4CC050F, /* [14][0xb8]*/ - 0xB5CBF3E2, 0xD2450EE3, 0x7AD609E0, 0x1D58F4E1, 0x2E1C7117, 0x49928C16, 0xE1018B15, 0x868F7614, /* [14][0xc0]*/ - 0xBDF4448A, 0xDA7AB98B, 0x72E9BE88, 0x15674389, 0x2623C67F, 0x41AD3B7E, 0xE93E3C7D, 0x8EB0C17C, /* [14][0xc8]*/ - 0x8FB73791, 0xE839CA90, 0x40AACD93, 0x27243092, 0x1460B564, 0x73EE4865, 0xDB7D4F66, 0xBCF3B267, /* [14][0xd0]*/ - 0xD972A2BC, 0xBEFC5FBD, 0x166F58BE, 0x71E1A5BF, 0x42A52049, 0x252BDD48, 0x8DB8DA4B, 0xEA36274A, /* [14][0xd8]*/ - 0xEB31D1A7, 0x8CBF2CA6, 0x242C2BA5, 0x43A2D6A4, 0x70E65352, 0x1768AE53, 0xBFFBA950, 0xD8755451, /* [14][0xe0]*/ - 0x74F988E6, 0x137775E7, 0xBBE472E4, 0xDC6A8FE5, 0xEF2E0A13, 0x88A0F712, 0x2033F011, 0x47BD0D10, /* [14][0xe8]*/ - 0x46BAFBFD, 0x213406FC, 0x89A701FF, 0xEE29FCFE, 0xDD6D7908, 0xBAE38409, 0x1270830A, 0x75FE7E0B, /* [14][0xf0]*/ - 0x107F6ED0, 0x77F193D1, 0xDF6294D2, 0xB8EC69D3, 0x8BA8EC25, 0xEC261124, 0x44B51627, 0x233BEB26, /* [14][0xf8]*/ - 0x223C1DCB, 0x45B2E0CA, 0xED21E7C9, 0x8AAF1AC8, 0xB9EB9F3E, 0xDE65623F, 0x76F6653C, 0x1178983D /* [14][0x100]*/ - }, - { - 0x00000000, 0xF20C0DFE, 0xE1F46D0D, 0x13F860F3, 0xC604ACEB, 0x3408A115, 0x27F0C1E6, 0xD5FCCC18, /* [15][0x08]*/ - 0x89E52F27, 0x7BE922D9, 0x6811422A, 0x9A1D4FD4, 0x4FE183CC, 0xBDED8E32, 0xAE15EEC1, 0x5C19E33F, /* [15][0x10]*/ - 0x162628BF, 0xE42A2541, 0xF7D245B2, 0x05DE484C, 0xD0228454, 0x222E89AA, 0x31D6E959, 0xC3DAE4A7, /* [15][0x18]*/ - 0x9FC30798, 0x6DCF0A66, 0x7E376A95, 0x8C3B676B, 0x59C7AB73, 0xABCBA68D, 0xB833C67E, 0x4A3FCB80, /* [15][0x20]*/ - 0x2C4C517E, 0xDE405C80, 0xCDB83C73, 0x3FB4318D, 0xEA48FD95, 0x1844F06B, 0x0BBC9098, 0xF9B09D66, /* [15][0x28]*/ - 0xA5A97E59, 0x57A573A7, 0x445D1354, 0xB6511EAA, 0x63ADD2B2, 0x91A1DF4C, 0x8259BFBF, 0x7055B241, /* [15][0x30]*/ - 0x3A6A79C1, 0xC866743F, 0xDB9E14CC, 0x29921932, 0xFC6ED52A, 0x0E62D8D4, 0x1D9AB827, 0xEF96B5D9, /* [15][0x38]*/ - 0xB38F56E6, 0x41835B18, 0x527B3BEB, 0xA0773615, 0x758BFA0D, 0x8787F7F3, 0x947F9700, 0x66739AFE, /* [15][0x40]*/ - 0x5898A2FC, 0xAA94AF02, 0xB96CCFF1, 0x4B60C20F, 0x9E9C0E17, 0x6C9003E9, 0x7F68631A, 0x8D646EE4, /* [15][0x48]*/ - 0xD17D8DDB, 0x23718025, 0x3089E0D6, 0xC285ED28, 0x17792130, 0xE5752CCE, 0xF68D4C3D, 0x048141C3, /* [15][0x50]*/ - 0x4EBE8A43, 0xBCB287BD, 0xAF4AE74E, 0x5D46EAB0, 0x88BA26A8, 0x7AB62B56, 0x694E4BA5, 0x9B42465B, /* [15][0x58]*/ - 0xC75BA564, 0x3557A89A, 0x26AFC869, 0xD4A3C597, 0x015F098F, 0xF3530471, 0xE0AB6482, 0x12A7697C, /* [15][0x60]*/ - 0x74D4F382, 0x86D8FE7C, 0x95209E8F, 0x672C9371, 0xB2D05F69, 0x40DC5297, 0x53243264, 0xA1283F9A, /* [15][0x68]*/ - 0xFD31DCA5, 0x0F3DD15B, 0x1CC5B1A8, 0xEEC9BC56, 0x3B35704E, 0xC9397DB0, 0xDAC11D43, 0x28CD10BD, /* [15][0x70]*/ - 0x62F2DB3D, 0x90FED6C3, 0x8306B630, 0x710ABBCE, 0xA4F677D6, 0x56FA7A28, 0x45021ADB, 0xB70E1725, /* [15][0x78]*/ - 0xEB17F41A, 0x191BF9E4, 0x0AE39917, 0xF8EF94E9, 0x2D1358F1, 0xDF1F550F, 0xCCE735FC, 0x3EEB3802, /* [15][0x80]*/ - 0xB13145F8, 0x433D4806, 0x50C528F5, 0xA2C9250B, 0x7735E913, 0x8539E4ED, 0x96C1841E, 0x64CD89E0, /* [15][0x88]*/ - 0x38D46ADF, 0xCAD86721, 0xD92007D2, 0x2B2C0A2C, 0xFED0C634, 0x0CDCCBCA, 0x1F24AB39, 0xED28A6C7, /* [15][0x90]*/ - 0xA7176D47, 0x551B60B9, 0x46E3004A, 0xB4EF0DB4, 0x6113C1AC, 0x931FCC52, 0x80E7ACA1, 0x72EBA15F, /* [15][0x98]*/ - 0x2EF24260, 0xDCFE4F9E, 0xCF062F6D, 0x3D0A2293, 0xE8F6EE8B, 0x1AFAE375, 0x09028386, 0xFB0E8E78, /* [15][0xa0]*/ - 0x9D7D1486, 0x6F711978, 0x7C89798B, 0x8E857475, 0x5B79B86D, 0xA975B593, 0xBA8DD560, 0x4881D89E, /* [15][0xa8]*/ - 0x14983BA1, 0xE694365F, 0xF56C56AC, 0x07605B52, 0xD29C974A, 0x20909AB4, 0x3368FA47, 0xC164F7B9, /* [15][0xb0]*/ - 0x8B5B3C39, 0x795731C7, 0x6AAF5134, 0x98A35CCA, 0x4D5F90D2, 0xBF539D2C, 0xACABFDDF, 0x5EA7F021, /* [15][0xb8]*/ - 0x02BE131E, 0xF0B21EE0, 0xE34A7E13, 0x114673ED, 0xC4BABFF5, 0x36B6B20B, 0x254ED2F8, 0xD742DF06, /* [15][0xc0]*/ - 0xE9A9E704, 0x1BA5EAFA, 0x085D8A09, 0xFA5187F7, 0x2FAD4BEF, 0xDDA14611, 0xCE5926E2, 0x3C552B1C, /* [15][0xc8]*/ - 0x604CC823, 0x9240C5DD, 0x81B8A52E, 0x73B4A8D0, 0xA64864C8, 0x54446936, 0x47BC09C5, 0xB5B0043B, /* [15][0xd0]*/ - 0xFF8FCFBB, 0x0D83C245, 0x1E7BA2B6, 0xEC77AF48, 0x398B6350, 0xCB876EAE, 0xD87F0E5D, 0x2A7303A3, /* [15][0xd8]*/ - 0x766AE09C, 0x8466ED62, 0x979E8D91, 0x6592806F, 0xB06E4C77, 0x42624189, 0x519A217A, 0xA3962C84, /* [15][0xe0]*/ - 0xC5E5B67A, 0x37E9BB84, 0x2411DB77, 0xD61DD689, 0x03E11A91, 0xF1ED176F, 0xE215779C, 0x10197A62, /* [15][0xe8]*/ - 0x4C00995D, 0xBE0C94A3, 0xADF4F450, 0x5FF8F9AE, 0x8A0435B6, 0x78083848, 0x6BF058BB, 0x99FC5545, /* [15][0xf0]*/ - 0xD3C39EC5, 0x21CF933B, 0x3237F3C8, 0xC03BFE36, 0x15C7322E, 0xE7CB3FD0, 0xF4335F23, 0x063F52DD, /* [15][0xf8]*/ - 0x5A26B1E2, 0xA82ABC1C, 0xBBD2DCEF, 0x49DED111, 0x9C221D09, 0x6E2E10F7, 0x7DD67004, 0x8FDA7DFA /* [15][0x100]*/ - }}; - -/* private (static) function factoring out byte-by-byte CRC computation using just one slice of the lookup table*/ -static uint32_t s_crc_generic_sb1(const uint8_t *input, int length, uint32_t crc, const uint32_t *table_ptr) { - uint32_t(*table)[16][256] = (uint32_t(*)[16][256])table_ptr; - while (length-- > 0) { - crc = (crc >> 8) ^ (*table)[0][(crc & 0xff) ^ *input++]; - } - return crc; -} - -/* The inner loops of the CRC functions that process large blocks of data work best when input is aligned*/ -/* This function begins processing input data one byte at a time until the input pointer is 4-byte aligned*/ -/* Advances the input pointer and reduces the length (both passed by reference)*/ -static inline uint32_t s_crc_generic_align( - const uint8_t **input, - int *length, - uint32_t crc, - const uint32_t *table_ptr) { - - /* Get the 4-byte memory alignment of our input buffer by looking at the least significant 2 bits*/ - size_t input_alignment = ((size_t)*input) & 0x3; - - /* Compute the number of input bytes that precede the first 4-byte aligned block (will be in range 0-3)*/ - size_t leading = (4 - input_alignment) & 0x3; - - /* Determine what's left without the leading input bytes (might be negative)*/ - size_t remaining = *length - leading; - - /* Process unaligned leading input bytes one at a time*/ - if (leading && remaining > 0) { - crc = s_crc_generic_sb1(*input, (uint32_t)leading, crc, table_ptr); - *input += leading; - *length -= (int)leading; - } - - return crc; -} - -/* private (static) function to compute a generic slice-by-4 CRC using the specified lookup table (4 table slices)*/ -static uint32_t s_crc_generic_sb4(const uint8_t *input, int length, uint32_t crc, const uint32_t *table_ptr) { - const uint32_t *current = (const uint32_t *)input; - int remaining = length; - uint32_t(*table)[16][256] = (uint32_t(*)[16][256])table_ptr; - - while (remaining >= 4) { - crc ^= *current++; - crc = (*table)[3][crc & 0xff] ^ (*table)[2][(crc >> 8) & 0xff] ^ (*table)[1][(crc >> 16) & 0xff] ^ - (*table)[0][crc >> 24]; - remaining -= 4; - } - - return s_crc_generic_sb1(&input[length - remaining], remaining, crc, table_ptr); -} - -/* private (static) function to compute a generic slice-by-8 CRC using the specified lookup table (8 table slices)*/ -static uint32_t s_crc_generic_sb8(const uint8_t *input, int length, uint32_t crc, const uint32_t *table_ptr) { - const uint32_t *current = (const uint32_t *)input; - int remaining = length; - uint32_t(*table)[16][256] = (uint32_t(*)[16][256])table_ptr; - - while (remaining >= 8) { - uint32_t c1 = *current++ ^ crc; - uint32_t c2 = *current++; - uint32_t t1 = (*table)[7][c1 & 0xff] ^ (*table)[6][(c1 >> 8) & 0xff] ^ (*table)[5][(c1 >> 16) & 0xff] ^ - (*table)[4][(c1 >> 24) & 0xff]; - uint32_t t2 = (*table)[3][c2 & 0xff] ^ (*table)[2][(c2 >> 8) & 0xff] ^ (*table)[1][(c2 >> 16) & 0xff] ^ - (*table)[0][(c2 >> 24) & 0xff]; - crc = t1 ^ t2; - remaining -= 8; - } - return s_crc_generic_sb4(&input[length - remaining], remaining, crc, table_ptr); -} - -/* private (static) function to compute a generic slice-by-16 CRC using the specified lookup table (all 16 table - * slices)*/ -static uint32_t s_crc_generic_sb16(const uint8_t *input, int length, uint32_t crc, const uint32_t *table_ptr) { - const uint32_t *current = (const uint32_t *)input; - int remaining = length; - uint32_t(*table)[16][256] = (uint32_t(*)[16][256])table_ptr; - - while (remaining >= 16) { - uint32_t c1 = *current++ ^ crc; - uint32_t c2 = *current++; - uint32_t c3 = *current++; - uint32_t c4 = *current++; - uint32_t t1 = (*table)[15][c1 & 0xff] ^ (*table)[14][(c1 >> 8) & 0xff] ^ (*table)[13][(c1 >> 16) & 0xff] ^ - (*table)[12][(c1 >> 24) & 0xff]; - uint32_t t2 = (*table)[11][c2 & 0xff] ^ (*table)[10][(c2 >> 8) & 0xff] ^ (*table)[9][(c2 >> 16) & 0xff] ^ - (*table)[8][(c2 >> 24) & 0xff]; - uint32_t t3 = (*table)[7][c3 & 0xff] ^ (*table)[6][(c3 >> 8) & 0xff] ^ (*table)[5][(c3 >> 16) & 0xff] ^ - (*table)[4][(c3 >> 24) & 0xff]; - uint32_t t4 = (*table)[3][c4 & 0xff] ^ (*table)[2][(c4 >> 8) & 0xff] ^ (*table)[1][(c4 >> 16) & 0xff] ^ - (*table)[0][(c4 >> 24) & 0xff]; - crc = t1 ^ t2 ^ t3 ^ t4; - remaining -= 16; - } - return s_crc_generic_sb4(&input[length - remaining], remaining, crc, table_ptr); -} - -static uint32_t s_crc32_no_slice(const uint8_t *input, int length, uint32_t previousCrc32) { - return ~s_crc_generic_sb1(input, length, ~previousCrc32, &CRC32_TABLE[0][0]); -} - -/* Computes CRC32 (Ethernet, gzip, et. al.) using slice-by-4. */ -static uint32_t s_crc32_sb4(const uint8_t *input, int length, uint32_t previousCrc32) { - uint32_t crc = s_crc_generic_align(&input, &length, ~previousCrc32, &CRC32_TABLE[0][0]); - return ~s_crc_generic_sb4(input, length, crc, &CRC32_TABLE[0][0]); -} - -/* Computes CRC32 (Ethernet, gzip, et. al.) using slice-by-8. */ -static uint32_t s_crc32_sb8(const uint8_t *input, int length, uint32_t previousCrc32) { - uint32_t crc = s_crc_generic_align(&input, &length, ~previousCrc32, &CRC32_TABLE[0][0]); - return ~s_crc_generic_sb8(input, length, crc, &CRC32_TABLE[0][0]); -} - -/* Computes CRC32 (Ethernet, gzip, et. al.) using slice-by-16. */ -static uint32_t s_crc32_sb16(const uint8_t *input, int length, uint32_t previousCrc32) { - uint32_t crc = s_crc_generic_align(&input, &length, ~previousCrc32, &CRC32_TABLE[0][0]); - return ~s_crc_generic_sb16(input, length, crc, &CRC32_TABLE[0][0]); -} - -static uint32_t s_crc32c_no_slice(const uint8_t *input, int length, uint32_t previousCrc32c) { - return ~s_crc_generic_sb1(input, length, ~previousCrc32c, &CRC32C_TABLE[0][0]); -} - -/* Computes the Castagnoli CRC32c (iSCSI) using slice-by-4. */ -static uint32_t s_crc32c_sb4(const uint8_t *input, int length, uint32_t previousCrc32) { - uint32_t crc = s_crc_generic_align(&input, &length, ~previousCrc32, &CRC32C_TABLE[0][0]); - return ~s_crc_generic_sb4(input, length, crc, &CRC32C_TABLE[0][0]); -} - -/* Computes the Castagnoli CRC32c (iSCSI) using slice-by-8. */ -static uint32_t s_crc32c_sb8(const uint8_t *input, int length, uint32_t previousCrc32) { - uint32_t crc = s_crc_generic_align(&input, &length, ~previousCrc32, &CRC32C_TABLE[0][0]); - return ~s_crc_generic_sb8(input, length, crc, &CRC32C_TABLE[0][0]); -} - -/* Computes the Castagnoli CRC32c (iSCSI) using slice-by-16. */ -static uint32_t s_crc32c_sb16(const uint8_t *input, int length, uint32_t previousCrc32) { - uint32_t crc = s_crc_generic_align(&input, &length, ~previousCrc32, &CRC32C_TABLE[0][0]); - return ~s_crc_generic_sb16(input, length, crc, &CRC32C_TABLE[0][0]); -} - -/** - * Computes the Ethernet, gzip CRC32 of the specified data buffer. - * Pass 0 in the previousCrc32 parameter as an initial value unless continuing to update a running crc in a subsequent - * call - */ -uint32_t aws_checksums_crc32_sw(const uint8_t *input, int length, uint32_t previousCrc32) { - if (length >= 16) { - return s_crc32_sb16(input, length, previousCrc32); - } - - if (length >= 8) { - return s_crc32_sb8(input, length, previousCrc32); - } - - if (length >= 4) { - return s_crc32_sb4(input, length, previousCrc32); - } - - return s_crc32_no_slice(input, length, previousCrc32); -} - -/** - * Computes the Castagnoli iSCSI CRC32c of the specified data buffer. - * Pass 0 in the previousCrc32c parameter as an initial value unless continuing to update a running crc in a subsequent - * call - */ -uint32_t aws_checksums_crc32c_sw(const uint8_t *input, int length, uint32_t previousCrc32c) { - if (length >= 16) { - return s_crc32c_sb16(input, length, previousCrc32c); - } - - if (length >= 8) { - return s_crc32c_sb8(input, length, previousCrc32c); - } - - if (length >= 4) { - return s_crc32c_sb4(input, length, previousCrc32c); - } - - return s_crc32c_no_slice(input, length, previousCrc32c); -} + */ +#include <aws/checksums/private/crc_priv.h> +#include <stddef.h> + +/* The Ethernet, gzip, et.al CRC32 polynomial (reverse of 0x04C11DB7) */ +#define CRC32_POLYNOMIAL 0xEDB88320 + +/* The Castagnoli, iSCSI CRC32c polynomial (reverse of 0x1EDC6F41) */ +#define CRC32C_POLYNOMIAL 0x82F63B78 + +/** CRC32 (Ethernet, gzip) lookup table for slice-by-4/8/16 */ +const uint32_t CRC32_TABLE[16][256] = { + { + 0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F, 0xE963A535, 0x9E6495A3, /* [0][0x08]*/ + 0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988, 0x09B64C2B, 0x7EB17CBD, 0xE7B82D07, 0x90BF1D91, /* [0][0x10]*/ + 0x1DB71064, 0x6AB020F2, 0xF3B97148, 0x84BE41DE, 0x1ADAD47D, 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7, /* [0][0x18]*/ + 0x136C9856, 0x646BA8C0, 0xFD62F97A, 0x8A65C9EC, 0x14015C4F, 0x63066CD9, 0xFA0F3D63, 0x8D080DF5, /* [0][0x20]*/ + 0x3B6E20C8, 0x4C69105E, 0xD56041E4, 0xA2677172, 0x3C03E4D1, 0x4B04D447, 0xD20D85FD, 0xA50AB56B, /* [0][0x28]*/ + 0x35B5A8FA, 0x42B2986C, 0xDBBBC9D6, 0xACBCF940, 0x32D86CE3, 0x45DF5C75, 0xDCD60DCF, 0xABD13D59, /* [0][0x30]*/ + 0x26D930AC, 0x51DE003A, 0xC8D75180, 0xBFD06116, 0x21B4F4B5, 0x56B3C423, 0xCFBA9599, 0xB8BDA50F, /* [0][0x38]*/ + 0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924, 0x2F6F7C87, 0x58684C11, 0xC1611DAB, 0xB6662D3D, /* [0][0x40]*/ + 0x76DC4190, 0x01DB7106, 0x98D220BC, 0xEFD5102A, 0x71B18589, 0x06B6B51F, 0x9FBFE4A5, 0xE8B8D433, /* [0][0x48]*/ + 0x7807C9A2, 0x0F00F934, 0x9609A88E, 0xE10E9818, 0x7F6A0DBB, 0x086D3D2D, 0x91646C97, 0xE6635C01, /* [0][0x50]*/ + 0x6B6B51F4, 0x1C6C6162, 0x856530D8, 0xF262004E, 0x6C0695ED, 0x1B01A57B, 0x8208F4C1, 0xF50FC457, /* [0][0x58]*/ + 0x65B0D9C6, 0x12B7E950, 0x8BBEB8EA, 0xFCB9887C, 0x62DD1DDF, 0x15DA2D49, 0x8CD37CF3, 0xFBD44C65, /* [0][0x60]*/ + 0x4DB26158, 0x3AB551CE, 0xA3BC0074, 0xD4BB30E2, 0x4ADFA541, 0x3DD895D7, 0xA4D1C46D, 0xD3D6F4FB, /* [0][0x68]*/ + 0x4369E96A, 0x346ED9FC, 0xAD678846, 0xDA60B8D0, 0x44042D73, 0x33031DE5, 0xAA0A4C5F, 0xDD0D7CC9, /* [0][0x70]*/ + 0x5005713C, 0x270241AA, 0xBE0B1010, 0xC90C2086, 0x5768B525, 0x206F85B3, 0xB966D409, 0xCE61E49F, /* [0][0x78]*/ + 0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4, 0x59B33D17, 0x2EB40D81, 0xB7BD5C3B, 0xC0BA6CAD, /* [0][0x80]*/ + 0xEDB88320, 0x9ABFB3B6, 0x03B6E20C, 0x74B1D29A, 0xEAD54739, 0x9DD277AF, 0x04DB2615, 0x73DC1683, /* [0][0x88]*/ + 0xE3630B12, 0x94643B84, 0x0D6D6A3E, 0x7A6A5AA8, 0xE40ECF0B, 0x9309FF9D, 0x0A00AE27, 0x7D079EB1, /* [0][0x90]*/ + 0xF00F9344, 0x8708A3D2, 0x1E01F268, 0x6906C2FE, 0xF762575D, 0x806567CB, 0x196C3671, 0x6E6B06E7, /* [0][0x98]*/ + 0xFED41B76, 0x89D32BE0, 0x10DA7A5A, 0x67DD4ACC, 0xF9B9DF6F, 0x8EBEEFF9, 0x17B7BE43, 0x60B08ED5, /* [0][0xa0]*/ + 0xD6D6A3E8, 0xA1D1937E, 0x38D8C2C4, 0x4FDFF252, 0xD1BB67F1, 0xA6BC5767, 0x3FB506DD, 0x48B2364B, /* [0][0xa8]*/ + 0xD80D2BDA, 0xAF0A1B4C, 0x36034AF6, 0x41047A60, 0xDF60EFC3, 0xA867DF55, 0x316E8EEF, 0x4669BE79, /* [0][0xb0]*/ + 0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236, 0xCC0C7795, 0xBB0B4703, 0x220216B9, 0x5505262F, /* [0][0xb8]*/ + 0xC5BA3BBE, 0xB2BD0B28, 0x2BB45A92, 0x5CB36A04, 0xC2D7FFA7, 0xB5D0CF31, 0x2CD99E8B, 0x5BDEAE1D, /* [0][0xc0]*/ + 0x9B64C2B0, 0xEC63F226, 0x756AA39C, 0x026D930A, 0x9C0906A9, 0xEB0E363F, 0x72076785, 0x05005713, /* [0][0xc8]*/ + 0x95BF4A82, 0xE2B87A14, 0x7BB12BAE, 0x0CB61B38, 0x92D28E9B, 0xE5D5BE0D, 0x7CDCEFB7, 0x0BDBDF21, /* [0][0xd0]*/ + 0x86D3D2D4, 0xF1D4E242, 0x68DDB3F8, 0x1FDA836E, 0x81BE16CD, 0xF6B9265B, 0x6FB077E1, 0x18B74777, /* [0][0xd8]*/ + 0x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C, 0x8F659EFF, 0xF862AE69, 0x616BFFD3, 0x166CCF45, /* [0][0xe0]*/ + 0xA00AE278, 0xD70DD2EE, 0x4E048354, 0x3903B3C2, 0xA7672661, 0xD06016F7, 0x4969474D, 0x3E6E77DB, /* [0][0xe8]*/ + 0xAED16A4A, 0xD9D65ADC, 0x40DF0B66, 0x37D83BF0, 0xA9BCAE53, 0xDEBB9EC5, 0x47B2CF7F, 0x30B5FFE9, /* [0][0xf0]*/ + 0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6, 0xBAD03605, 0xCDD70693, 0x54DE5729, 0x23D967BF, /* [0][0xf8]*/ + 0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94, 0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D /* [0][0x100]*/ + }, + { + 0x00000000, 0x191B3141, 0x32366282, 0x2B2D53C3, 0x646CC504, 0x7D77F445, 0x565AA786, 0x4F4196C7, /* [1][0x08]*/ + 0xC8D98A08, 0xD1C2BB49, 0xFAEFE88A, 0xE3F4D9CB, 0xACB54F0C, 0xB5AE7E4D, 0x9E832D8E, 0x87981CCF, /* [1][0x10]*/ + 0x4AC21251, 0x53D92310, 0x78F470D3, 0x61EF4192, 0x2EAED755, 0x37B5E614, 0x1C98B5D7, 0x05838496, /* [1][0x18]*/ + 0x821B9859, 0x9B00A918, 0xB02DFADB, 0xA936CB9A, 0xE6775D5D, 0xFF6C6C1C, 0xD4413FDF, 0xCD5A0E9E, /* [1][0x20]*/ + 0x958424A2, 0x8C9F15E3, 0xA7B24620, 0xBEA97761, 0xF1E8E1A6, 0xE8F3D0E7, 0xC3DE8324, 0xDAC5B265, /* [1][0x28]*/ + 0x5D5DAEAA, 0x44469FEB, 0x6F6BCC28, 0x7670FD69, 0x39316BAE, 0x202A5AEF, 0x0B07092C, 0x121C386D, /* [1][0x30]*/ + 0xDF4636F3, 0xC65D07B2, 0xED705471, 0xF46B6530, 0xBB2AF3F7, 0xA231C2B6, 0x891C9175, 0x9007A034, /* [1][0x38]*/ + 0x179FBCFB, 0x0E848DBA, 0x25A9DE79, 0x3CB2EF38, 0x73F379FF, 0x6AE848BE, 0x41C51B7D, 0x58DE2A3C, /* [1][0x40]*/ + 0xF0794F05, 0xE9627E44, 0xC24F2D87, 0xDB541CC6, 0x94158A01, 0x8D0EBB40, 0xA623E883, 0xBF38D9C2, /* [1][0x48]*/ + 0x38A0C50D, 0x21BBF44C, 0x0A96A78F, 0x138D96CE, 0x5CCC0009, 0x45D73148, 0x6EFA628B, 0x77E153CA, /* [1][0x50]*/ + 0xBABB5D54, 0xA3A06C15, 0x888D3FD6, 0x91960E97, 0xDED79850, 0xC7CCA911, 0xECE1FAD2, 0xF5FACB93, /* [1][0x58]*/ + 0x7262D75C, 0x6B79E61D, 0x4054B5DE, 0x594F849F, 0x160E1258, 0x0F152319, 0x243870DA, 0x3D23419B, /* [1][0x60]*/ + 0x65FD6BA7, 0x7CE65AE6, 0x57CB0925, 0x4ED03864, 0x0191AEA3, 0x188A9FE2, 0x33A7CC21, 0x2ABCFD60, /* [1][0x68]*/ + 0xAD24E1AF, 0xB43FD0EE, 0x9F12832D, 0x8609B26C, 0xC94824AB, 0xD05315EA, 0xFB7E4629, 0xE2657768, /* [1][0x70]*/ + 0x2F3F79F6, 0x362448B7, 0x1D091B74, 0x04122A35, 0x4B53BCF2, 0x52488DB3, 0x7965DE70, 0x607EEF31, /* [1][0x78]*/ + 0xE7E6F3FE, 0xFEFDC2BF, 0xD5D0917C, 0xCCCBA03D, 0x838A36FA, 0x9A9107BB, 0xB1BC5478, 0xA8A76539, /* [1][0x80]*/ + 0x3B83984B, 0x2298A90A, 0x09B5FAC9, 0x10AECB88, 0x5FEF5D4F, 0x46F46C0E, 0x6DD93FCD, 0x74C20E8C, /* [1][0x88]*/ + 0xF35A1243, 0xEA412302, 0xC16C70C1, 0xD8774180, 0x9736D747, 0x8E2DE606, 0xA500B5C5, 0xBC1B8484, /* [1][0x90]*/ + 0x71418A1A, 0x685ABB5B, 0x4377E898, 0x5A6CD9D9, 0x152D4F1E, 0x0C367E5F, 0x271B2D9C, 0x3E001CDD, /* [1][0x98]*/ + 0xB9980012, 0xA0833153, 0x8BAE6290, 0x92B553D1, 0xDDF4C516, 0xC4EFF457, 0xEFC2A794, 0xF6D996D5, /* [1][0xa0]*/ + 0xAE07BCE9, 0xB71C8DA8, 0x9C31DE6B, 0x852AEF2A, 0xCA6B79ED, 0xD37048AC, 0xF85D1B6F, 0xE1462A2E, /* [1][0xa8]*/ + 0x66DE36E1, 0x7FC507A0, 0x54E85463, 0x4DF36522, 0x02B2F3E5, 0x1BA9C2A4, 0x30849167, 0x299FA026, /* [1][0xb0]*/ + 0xE4C5AEB8, 0xFDDE9FF9, 0xD6F3CC3A, 0xCFE8FD7B, 0x80A96BBC, 0x99B25AFD, 0xB29F093E, 0xAB84387F, /* [1][0xb8]*/ + 0x2C1C24B0, 0x350715F1, 0x1E2A4632, 0x07317773, 0x4870E1B4, 0x516BD0F5, 0x7A468336, 0x635DB277, /* [1][0xc0]*/ + 0xCBFAD74E, 0xD2E1E60F, 0xF9CCB5CC, 0xE0D7848D, 0xAF96124A, 0xB68D230B, 0x9DA070C8, 0x84BB4189, /* [1][0xc8]*/ + 0x03235D46, 0x1A386C07, 0x31153FC4, 0x280E0E85, 0x674F9842, 0x7E54A903, 0x5579FAC0, 0x4C62CB81, /* [1][0xd0]*/ + 0x8138C51F, 0x9823F45E, 0xB30EA79D, 0xAA1596DC, 0xE554001B, 0xFC4F315A, 0xD7626299, 0xCE7953D8, /* [1][0xd8]*/ + 0x49E14F17, 0x50FA7E56, 0x7BD72D95, 0x62CC1CD4, 0x2D8D8A13, 0x3496BB52, 0x1FBBE891, 0x06A0D9D0, /* [1][0xe0]*/ + 0x5E7EF3EC, 0x4765C2AD, 0x6C48916E, 0x7553A02F, 0x3A1236E8, 0x230907A9, 0x0824546A, 0x113F652B, /* [1][0xe8]*/ + 0x96A779E4, 0x8FBC48A5, 0xA4911B66, 0xBD8A2A27, 0xF2CBBCE0, 0xEBD08DA1, 0xC0FDDE62, 0xD9E6EF23, /* [1][0xf0]*/ + 0x14BCE1BD, 0x0DA7D0FC, 0x268A833F, 0x3F91B27E, 0x70D024B9, 0x69CB15F8, 0x42E6463B, 0x5BFD777A, /* [1][0xf8]*/ + 0xDC656BB5, 0xC57E5AF4, 0xEE530937, 0xF7483876, 0xB809AEB1, 0xA1129FF0, 0x8A3FCC33, 0x9324FD72 /* [1][0x100]*/ + }, + { + 0x00000000, 0x01C26A37, 0x0384D46E, 0x0246BE59, 0x0709A8DC, 0x06CBC2EB, 0x048D7CB2, 0x054F1685, /* [2][0x08]*/ + 0x0E1351B8, 0x0FD13B8F, 0x0D9785D6, 0x0C55EFE1, 0x091AF964, 0x08D89353, 0x0A9E2D0A, 0x0B5C473D, /* [2][0x10]*/ + 0x1C26A370, 0x1DE4C947, 0x1FA2771E, 0x1E601D29, 0x1B2F0BAC, 0x1AED619B, 0x18ABDFC2, 0x1969B5F5, /* [2][0x18]*/ + 0x1235F2C8, 0x13F798FF, 0x11B126A6, 0x10734C91, 0x153C5A14, 0x14FE3023, 0x16B88E7A, 0x177AE44D, /* [2][0x20]*/ + 0x384D46E0, 0x398F2CD7, 0x3BC9928E, 0x3A0BF8B9, 0x3F44EE3C, 0x3E86840B, 0x3CC03A52, 0x3D025065, /* [2][0x28]*/ + 0x365E1758, 0x379C7D6F, 0x35DAC336, 0x3418A901, 0x3157BF84, 0x3095D5B3, 0x32D36BEA, 0x331101DD, /* [2][0x30]*/ + 0x246BE590, 0x25A98FA7, 0x27EF31FE, 0x262D5BC9, 0x23624D4C, 0x22A0277B, 0x20E69922, 0x2124F315, /* [2][0x38]*/ + 0x2A78B428, 0x2BBADE1F, 0x29FC6046, 0x283E0A71, 0x2D711CF4, 0x2CB376C3, 0x2EF5C89A, 0x2F37A2AD, /* [2][0x40]*/ + 0x709A8DC0, 0x7158E7F7, 0x731E59AE, 0x72DC3399, 0x7793251C, 0x76514F2B, 0x7417F172, 0x75D59B45, /* [2][0x48]*/ + 0x7E89DC78, 0x7F4BB64F, 0x7D0D0816, 0x7CCF6221, 0x798074A4, 0x78421E93, 0x7A04A0CA, 0x7BC6CAFD, /* [2][0x50]*/ + 0x6CBC2EB0, 0x6D7E4487, 0x6F38FADE, 0x6EFA90E9, 0x6BB5866C, 0x6A77EC5B, 0x68315202, 0x69F33835, /* [2][0x58]*/ + 0x62AF7F08, 0x636D153F, 0x612BAB66, 0x60E9C151, 0x65A6D7D4, 0x6464BDE3, 0x662203BA, 0x67E0698D, /* [2][0x60]*/ + 0x48D7CB20, 0x4915A117, 0x4B531F4E, 0x4A917579, 0x4FDE63FC, 0x4E1C09CB, 0x4C5AB792, 0x4D98DDA5, /* [2][0x68]*/ + 0x46C49A98, 0x4706F0AF, 0x45404EF6, 0x448224C1, 0x41CD3244, 0x400F5873, 0x4249E62A, 0x438B8C1D, /* [2][0x70]*/ + 0x54F16850, 0x55330267, 0x5775BC3E, 0x56B7D609, 0x53F8C08C, 0x523AAABB, 0x507C14E2, 0x51BE7ED5, /* [2][0x78]*/ + 0x5AE239E8, 0x5B2053DF, 0x5966ED86, 0x58A487B1, 0x5DEB9134, 0x5C29FB03, 0x5E6F455A, 0x5FAD2F6D, /* [2][0x80]*/ + 0xE1351B80, 0xE0F771B7, 0xE2B1CFEE, 0xE373A5D9, 0xE63CB35C, 0xE7FED96B, 0xE5B86732, 0xE47A0D05, /* [2][0x88]*/ + 0xEF264A38, 0xEEE4200F, 0xECA29E56, 0xED60F461, 0xE82FE2E4, 0xE9ED88D3, 0xEBAB368A, 0xEA695CBD, /* [2][0x90]*/ + 0xFD13B8F0, 0xFCD1D2C7, 0xFE976C9E, 0xFF5506A9, 0xFA1A102C, 0xFBD87A1B, 0xF99EC442, 0xF85CAE75, /* [2][0x98]*/ + 0xF300E948, 0xF2C2837F, 0xF0843D26, 0xF1465711, 0xF4094194, 0xF5CB2BA3, 0xF78D95FA, 0xF64FFFCD, /* [2][0xa0]*/ + 0xD9785D60, 0xD8BA3757, 0xDAFC890E, 0xDB3EE339, 0xDE71F5BC, 0xDFB39F8B, 0xDDF521D2, 0xDC374BE5, /* [2][0xa8]*/ + 0xD76B0CD8, 0xD6A966EF, 0xD4EFD8B6, 0xD52DB281, 0xD062A404, 0xD1A0CE33, 0xD3E6706A, 0xD2241A5D, /* [2][0xb0]*/ + 0xC55EFE10, 0xC49C9427, 0xC6DA2A7E, 0xC7184049, 0xC25756CC, 0xC3953CFB, 0xC1D382A2, 0xC011E895, /* [2][0xb8]*/ + 0xCB4DAFA8, 0xCA8FC59F, 0xC8C97BC6, 0xC90B11F1, 0xCC440774, 0xCD866D43, 0xCFC0D31A, 0xCE02B92D, /* [2][0xc0]*/ + 0x91AF9640, 0x906DFC77, 0x922B422E, 0x93E92819, 0x96A63E9C, 0x976454AB, 0x9522EAF2, 0x94E080C5, /* [2][0xc8]*/ + 0x9FBCC7F8, 0x9E7EADCF, 0x9C381396, 0x9DFA79A1, 0x98B56F24, 0x99770513, 0x9B31BB4A, 0x9AF3D17D, /* [2][0xd0]*/ + 0x8D893530, 0x8C4B5F07, 0x8E0DE15E, 0x8FCF8B69, 0x8A809DEC, 0x8B42F7DB, 0x89044982, 0x88C623B5, /* [2][0xd8]*/ + 0x839A6488, 0x82580EBF, 0x801EB0E6, 0x81DCDAD1, 0x8493CC54, 0x8551A663, 0x8717183A, 0x86D5720D, /* [2][0xe0]*/ + 0xA9E2D0A0, 0xA820BA97, 0xAA6604CE, 0xABA46EF9, 0xAEEB787C, 0xAF29124B, 0xAD6FAC12, 0xACADC625, /* [2][0xe8]*/ + 0xA7F18118, 0xA633EB2F, 0xA4755576, 0xA5B73F41, 0xA0F829C4, 0xA13A43F3, 0xA37CFDAA, 0xA2BE979D, /* [2][0xf0]*/ + 0xB5C473D0, 0xB40619E7, 0xB640A7BE, 0xB782CD89, 0xB2CDDB0C, 0xB30FB13B, 0xB1490F62, 0xB08B6555, /* [2][0xf8]*/ + 0xBBD72268, 0xBA15485F, 0xB853F606, 0xB9919C31, 0xBCDE8AB4, 0xBD1CE083, 0xBF5A5EDA, 0xBE9834ED /* [2][0x100]*/ + }, + { + 0x00000000, 0xB8BC6765, 0xAA09C88B, 0x12B5AFEE, 0x8F629757, 0x37DEF032, 0x256B5FDC, 0x9DD738B9, /* [3][0x08]*/ + 0xC5B428EF, 0x7D084F8A, 0x6FBDE064, 0xD7018701, 0x4AD6BFB8, 0xF26AD8DD, 0xE0DF7733, 0x58631056, /* [3][0x10]*/ + 0x5019579F, 0xE8A530FA, 0xFA109F14, 0x42ACF871, 0xDF7BC0C8, 0x67C7A7AD, 0x75720843, 0xCDCE6F26, /* [3][0x18]*/ + 0x95AD7F70, 0x2D111815, 0x3FA4B7FB, 0x8718D09E, 0x1ACFE827, 0xA2738F42, 0xB0C620AC, 0x087A47C9, /* [3][0x20]*/ + 0xA032AF3E, 0x188EC85B, 0x0A3B67B5, 0xB28700D0, 0x2F503869, 0x97EC5F0C, 0x8559F0E2, 0x3DE59787, /* [3][0x28]*/ + 0x658687D1, 0xDD3AE0B4, 0xCF8F4F5A, 0x7733283F, 0xEAE41086, 0x525877E3, 0x40EDD80D, 0xF851BF68, /* [3][0x30]*/ + 0xF02BF8A1, 0x48979FC4, 0x5A22302A, 0xE29E574F, 0x7F496FF6, 0xC7F50893, 0xD540A77D, 0x6DFCC018, /* [3][0x38]*/ + 0x359FD04E, 0x8D23B72B, 0x9F9618C5, 0x272A7FA0, 0xBAFD4719, 0x0241207C, 0x10F48F92, 0xA848E8F7, /* [3][0x40]*/ + 0x9B14583D, 0x23A83F58, 0x311D90B6, 0x89A1F7D3, 0x1476CF6A, 0xACCAA80F, 0xBE7F07E1, 0x06C36084, /* [3][0x48]*/ + 0x5EA070D2, 0xE61C17B7, 0xF4A9B859, 0x4C15DF3C, 0xD1C2E785, 0x697E80E0, 0x7BCB2F0E, 0xC377486B, /* [3][0x50]*/ + 0xCB0D0FA2, 0x73B168C7, 0x6104C729, 0xD9B8A04C, 0x446F98F5, 0xFCD3FF90, 0xEE66507E, 0x56DA371B, /* [3][0x58]*/ + 0x0EB9274D, 0xB6054028, 0xA4B0EFC6, 0x1C0C88A3, 0x81DBB01A, 0x3967D77F, 0x2BD27891, 0x936E1FF4, /* [3][0x60]*/ + 0x3B26F703, 0x839A9066, 0x912F3F88, 0x299358ED, 0xB4446054, 0x0CF80731, 0x1E4DA8DF, 0xA6F1CFBA, /* [3][0x68]*/ + 0xFE92DFEC, 0x462EB889, 0x549B1767, 0xEC277002, 0x71F048BB, 0xC94C2FDE, 0xDBF98030, 0x6345E755, /* [3][0x70]*/ + 0x6B3FA09C, 0xD383C7F9, 0xC1366817, 0x798A0F72, 0xE45D37CB, 0x5CE150AE, 0x4E54FF40, 0xF6E89825, /* [3][0x78]*/ + 0xAE8B8873, 0x1637EF16, 0x048240F8, 0xBC3E279D, 0x21E91F24, 0x99557841, 0x8BE0D7AF, 0x335CB0CA, /* [3][0x80]*/ + 0xED59B63B, 0x55E5D15E, 0x47507EB0, 0xFFEC19D5, 0x623B216C, 0xDA874609, 0xC832E9E7, 0x708E8E82, /* [3][0x88]*/ + 0x28ED9ED4, 0x9051F9B1, 0x82E4565F, 0x3A58313A, 0xA78F0983, 0x1F336EE6, 0x0D86C108, 0xB53AA66D, /* [3][0x90]*/ + 0xBD40E1A4, 0x05FC86C1, 0x1749292F, 0xAFF54E4A, 0x322276F3, 0x8A9E1196, 0x982BBE78, 0x2097D91D, /* [3][0x98]*/ + 0x78F4C94B, 0xC048AE2E, 0xD2FD01C0, 0x6A4166A5, 0xF7965E1C, 0x4F2A3979, 0x5D9F9697, 0xE523F1F2, /* [3][0xa0]*/ + 0x4D6B1905, 0xF5D77E60, 0xE762D18E, 0x5FDEB6EB, 0xC2098E52, 0x7AB5E937, 0x680046D9, 0xD0BC21BC, /* [3][0xa8]*/ + 0x88DF31EA, 0x3063568F, 0x22D6F961, 0x9A6A9E04, 0x07BDA6BD, 0xBF01C1D8, 0xADB46E36, 0x15080953, /* [3][0xb0]*/ + 0x1D724E9A, 0xA5CE29FF, 0xB77B8611, 0x0FC7E174, 0x9210D9CD, 0x2AACBEA8, 0x38191146, 0x80A57623, /* [3][0xb8]*/ + 0xD8C66675, 0x607A0110, 0x72CFAEFE, 0xCA73C99B, 0x57A4F122, 0xEF189647, 0xFDAD39A9, 0x45115ECC, /* [3][0xc0]*/ + 0x764DEE06, 0xCEF18963, 0xDC44268D, 0x64F841E8, 0xF92F7951, 0x41931E34, 0x5326B1DA, 0xEB9AD6BF, /* [3][0xc8]*/ + 0xB3F9C6E9, 0x0B45A18C, 0x19F00E62, 0xA14C6907, 0x3C9B51BE, 0x842736DB, 0x96929935, 0x2E2EFE50, /* [3][0xd0]*/ + 0x2654B999, 0x9EE8DEFC, 0x8C5D7112, 0x34E11677, 0xA9362ECE, 0x118A49AB, 0x033FE645, 0xBB838120, /* [3][0xd8]*/ + 0xE3E09176, 0x5B5CF613, 0x49E959FD, 0xF1553E98, 0x6C820621, 0xD43E6144, 0xC68BCEAA, 0x7E37A9CF, /* [3][0xe0]*/ + 0xD67F4138, 0x6EC3265D, 0x7C7689B3, 0xC4CAEED6, 0x591DD66F, 0xE1A1B10A, 0xF3141EE4, 0x4BA87981, /* [3][0xe8]*/ + 0x13CB69D7, 0xAB770EB2, 0xB9C2A15C, 0x017EC639, 0x9CA9FE80, 0x241599E5, 0x36A0360B, 0x8E1C516E, /* [3][0xf0]*/ + 0x866616A7, 0x3EDA71C2, 0x2C6FDE2C, 0x94D3B949, 0x090481F0, 0xB1B8E695, 0xA30D497B, 0x1BB12E1E, /* [3][0xf8]*/ + 0x43D23E48, 0xFB6E592D, 0xE9DBF6C3, 0x516791A6, 0xCCB0A91F, 0x740CCE7A, 0x66B96194, 0xDE0506F1 /* [3][0x100]*/ + }, + { + 0x00000000, 0x3D6029B0, 0x7AC05360, 0x47A07AD0, 0xF580A6C0, 0xC8E08F70, 0x8F40F5A0, 0xB220DC10, /* [4][0x08]*/ + 0x30704BC1, 0x0D106271, 0x4AB018A1, 0x77D03111, 0xC5F0ED01, 0xF890C4B1, 0xBF30BE61, 0x825097D1, /* [4][0x10]*/ + 0x60E09782, 0x5D80BE32, 0x1A20C4E2, 0x2740ED52, 0x95603142, 0xA80018F2, 0xEFA06222, 0xD2C04B92, /* [4][0x18]*/ + 0x5090DC43, 0x6DF0F5F3, 0x2A508F23, 0x1730A693, 0xA5107A83, 0x98705333, 0xDFD029E3, 0xE2B00053, /* [4][0x20]*/ + 0xC1C12F04, 0xFCA106B4, 0xBB017C64, 0x866155D4, 0x344189C4, 0x0921A074, 0x4E81DAA4, 0x73E1F314, /* [4][0x28]*/ + 0xF1B164C5, 0xCCD14D75, 0x8B7137A5, 0xB6111E15, 0x0431C205, 0x3951EBB5, 0x7EF19165, 0x4391B8D5, /* [4][0x30]*/ + 0xA121B886, 0x9C419136, 0xDBE1EBE6, 0xE681C256, 0x54A11E46, 0x69C137F6, 0x2E614D26, 0x13016496, /* [4][0x38]*/ + 0x9151F347, 0xAC31DAF7, 0xEB91A027, 0xD6F18997, 0x64D15587, 0x59B17C37, 0x1E1106E7, 0x23712F57, /* [4][0x40]*/ + 0x58F35849, 0x659371F9, 0x22330B29, 0x1F532299, 0xAD73FE89, 0x9013D739, 0xD7B3ADE9, 0xEAD38459, /* [4][0x48]*/ + 0x68831388, 0x55E33A38, 0x124340E8, 0x2F236958, 0x9D03B548, 0xA0639CF8, 0xE7C3E628, 0xDAA3CF98, /* [4][0x50]*/ + 0x3813CFCB, 0x0573E67B, 0x42D39CAB, 0x7FB3B51B, 0xCD93690B, 0xF0F340BB, 0xB7533A6B, 0x8A3313DB, /* [4][0x58]*/ + 0x0863840A, 0x3503ADBA, 0x72A3D76A, 0x4FC3FEDA, 0xFDE322CA, 0xC0830B7A, 0x872371AA, 0xBA43581A, /* [4][0x60]*/ + 0x9932774D, 0xA4525EFD, 0xE3F2242D, 0xDE920D9D, 0x6CB2D18D, 0x51D2F83D, 0x167282ED, 0x2B12AB5D, /* [4][0x68]*/ + 0xA9423C8C, 0x9422153C, 0xD3826FEC, 0xEEE2465C, 0x5CC29A4C, 0x61A2B3FC, 0x2602C92C, 0x1B62E09C, /* [4][0x70]*/ + 0xF9D2E0CF, 0xC4B2C97F, 0x8312B3AF, 0xBE729A1F, 0x0C52460F, 0x31326FBF, 0x7692156F, 0x4BF23CDF, /* [4][0x78]*/ + 0xC9A2AB0E, 0xF4C282BE, 0xB362F86E, 0x8E02D1DE, 0x3C220DCE, 0x0142247E, 0x46E25EAE, 0x7B82771E, /* [4][0x80]*/ + 0xB1E6B092, 0x8C869922, 0xCB26E3F2, 0xF646CA42, 0x44661652, 0x79063FE2, 0x3EA64532, 0x03C66C82, /* [4][0x88]*/ + 0x8196FB53, 0xBCF6D2E3, 0xFB56A833, 0xC6368183, 0x74165D93, 0x49767423, 0x0ED60EF3, 0x33B62743, /* [4][0x90]*/ + 0xD1062710, 0xEC660EA0, 0xABC67470, 0x96A65DC0, 0x248681D0, 0x19E6A860, 0x5E46D2B0, 0x6326FB00, /* [4][0x98]*/ + 0xE1766CD1, 0xDC164561, 0x9BB63FB1, 0xA6D61601, 0x14F6CA11, 0x2996E3A1, 0x6E369971, 0x5356B0C1, /* [4][0xa0]*/ + 0x70279F96, 0x4D47B626, 0x0AE7CCF6, 0x3787E546, 0x85A73956, 0xB8C710E6, 0xFF676A36, 0xC2074386, /* [4][0xa8]*/ + 0x4057D457, 0x7D37FDE7, 0x3A978737, 0x07F7AE87, 0xB5D77297, 0x88B75B27, 0xCF1721F7, 0xF2770847, /* [4][0xb0]*/ + 0x10C70814, 0x2DA721A4, 0x6A075B74, 0x576772C4, 0xE547AED4, 0xD8278764, 0x9F87FDB4, 0xA2E7D404, /* [4][0xb8]*/ + 0x20B743D5, 0x1DD76A65, 0x5A7710B5, 0x67173905, 0xD537E515, 0xE857CCA5, 0xAFF7B675, 0x92979FC5, /* [4][0xc0]*/ + 0xE915E8DB, 0xD475C16B, 0x93D5BBBB, 0xAEB5920B, 0x1C954E1B, 0x21F567AB, 0x66551D7B, 0x5B3534CB, /* [4][0xc8]*/ + 0xD965A31A, 0xE4058AAA, 0xA3A5F07A, 0x9EC5D9CA, 0x2CE505DA, 0x11852C6A, 0x562556BA, 0x6B457F0A, /* [4][0xd0]*/ + 0x89F57F59, 0xB49556E9, 0xF3352C39, 0xCE550589, 0x7C75D999, 0x4115F029, 0x06B58AF9, 0x3BD5A349, /* [4][0xd8]*/ + 0xB9853498, 0x84E51D28, 0xC34567F8, 0xFE254E48, 0x4C059258, 0x7165BBE8, 0x36C5C138, 0x0BA5E888, /* [4][0xe0]*/ + 0x28D4C7DF, 0x15B4EE6F, 0x521494BF, 0x6F74BD0F, 0xDD54611F, 0xE03448AF, 0xA794327F, 0x9AF41BCF, /* [4][0xe8]*/ + 0x18A48C1E, 0x25C4A5AE, 0x6264DF7E, 0x5F04F6CE, 0xED242ADE, 0xD044036E, 0x97E479BE, 0xAA84500E, /* [4][0xf0]*/ + 0x4834505D, 0x755479ED, 0x32F4033D, 0x0F942A8D, 0xBDB4F69D, 0x80D4DF2D, 0xC774A5FD, 0xFA148C4D, /* [4][0xf8]*/ + 0x78441B9C, 0x4524322C, 0x028448FC, 0x3FE4614C, 0x8DC4BD5C, 0xB0A494EC, 0xF704EE3C, 0xCA64C78C /* [4][0x100]*/ + }, + { + 0x00000000, 0xCB5CD3A5, 0x4DC8A10B, 0x869472AE, 0x9B914216, 0x50CD91B3, 0xD659E31D, 0x1D0530B8, /* [5][0x08]*/ + 0xEC53826D, 0x270F51C8, 0xA19B2366, 0x6AC7F0C3, 0x77C2C07B, 0xBC9E13DE, 0x3A0A6170, 0xF156B2D5, /* [5][0x10]*/ + 0x03D6029B, 0xC88AD13E, 0x4E1EA390, 0x85427035, 0x9847408D, 0x531B9328, 0xD58FE186, 0x1ED33223, /* [5][0x18]*/ + 0xEF8580F6, 0x24D95353, 0xA24D21FD, 0x6911F258, 0x7414C2E0, 0xBF481145, 0x39DC63EB, 0xF280B04E, /* [5][0x20]*/ + 0x07AC0536, 0xCCF0D693, 0x4A64A43D, 0x81387798, 0x9C3D4720, 0x57619485, 0xD1F5E62B, 0x1AA9358E, /* [5][0x28]*/ + 0xEBFF875B, 0x20A354FE, 0xA6372650, 0x6D6BF5F5, 0x706EC54D, 0xBB3216E8, 0x3DA66446, 0xF6FAB7E3, /* [5][0x30]*/ + 0x047A07AD, 0xCF26D408, 0x49B2A6A6, 0x82EE7503, 0x9FEB45BB, 0x54B7961E, 0xD223E4B0, 0x197F3715, /* [5][0x38]*/ + 0xE82985C0, 0x23755665, 0xA5E124CB, 0x6EBDF76E, 0x73B8C7D6, 0xB8E41473, 0x3E7066DD, 0xF52CB578, /* [5][0x40]*/ + 0x0F580A6C, 0xC404D9C9, 0x4290AB67, 0x89CC78C2, 0x94C9487A, 0x5F959BDF, 0xD901E971, 0x125D3AD4, /* [5][0x48]*/ + 0xE30B8801, 0x28575BA4, 0xAEC3290A, 0x659FFAAF, 0x789ACA17, 0xB3C619B2, 0x35526B1C, 0xFE0EB8B9, /* [5][0x50]*/ + 0x0C8E08F7, 0xC7D2DB52, 0x4146A9FC, 0x8A1A7A59, 0x971F4AE1, 0x5C439944, 0xDAD7EBEA, 0x118B384F, /* [5][0x58]*/ + 0xE0DD8A9A, 0x2B81593F, 0xAD152B91, 0x6649F834, 0x7B4CC88C, 0xB0101B29, 0x36846987, 0xFDD8BA22, /* [5][0x60]*/ + 0x08F40F5A, 0xC3A8DCFF, 0x453CAE51, 0x8E607DF4, 0x93654D4C, 0x58399EE9, 0xDEADEC47, 0x15F13FE2, /* [5][0x68]*/ + 0xE4A78D37, 0x2FFB5E92, 0xA96F2C3C, 0x6233FF99, 0x7F36CF21, 0xB46A1C84, 0x32FE6E2A, 0xF9A2BD8F, /* [5][0x70]*/ + 0x0B220DC1, 0xC07EDE64, 0x46EAACCA, 0x8DB67F6F, 0x90B34FD7, 0x5BEF9C72, 0xDD7BEEDC, 0x16273D79, /* [5][0x78]*/ + 0xE7718FAC, 0x2C2D5C09, 0xAAB92EA7, 0x61E5FD02, 0x7CE0CDBA, 0xB7BC1E1F, 0x31286CB1, 0xFA74BF14, /* [5][0x80]*/ + 0x1EB014D8, 0xD5ECC77D, 0x5378B5D3, 0x98246676, 0x852156CE, 0x4E7D856B, 0xC8E9F7C5, 0x03B52460, /* [5][0x88]*/ + 0xF2E396B5, 0x39BF4510, 0xBF2B37BE, 0x7477E41B, 0x6972D4A3, 0xA22E0706, 0x24BA75A8, 0xEFE6A60D, /* [5][0x90]*/ + 0x1D661643, 0xD63AC5E6, 0x50AEB748, 0x9BF264ED, 0x86F75455, 0x4DAB87F0, 0xCB3FF55E, 0x006326FB, /* [5][0x98]*/ + 0xF135942E, 0x3A69478B, 0xBCFD3525, 0x77A1E680, 0x6AA4D638, 0xA1F8059D, 0x276C7733, 0xEC30A496, /* [5][0xa0]*/ + 0x191C11EE, 0xD240C24B, 0x54D4B0E5, 0x9F886340, 0x828D53F8, 0x49D1805D, 0xCF45F2F3, 0x04192156, /* [5][0xa8]*/ + 0xF54F9383, 0x3E134026, 0xB8873288, 0x73DBE12D, 0x6EDED195, 0xA5820230, 0x2316709E, 0xE84AA33B, /* [5][0xb0]*/ + 0x1ACA1375, 0xD196C0D0, 0x5702B27E, 0x9C5E61DB, 0x815B5163, 0x4A0782C6, 0xCC93F068, 0x07CF23CD, /* [5][0xb8]*/ + 0xF6999118, 0x3DC542BD, 0xBB513013, 0x700DE3B6, 0x6D08D30E, 0xA65400AB, 0x20C07205, 0xEB9CA1A0, /* [5][0xc0]*/ + 0x11E81EB4, 0xDAB4CD11, 0x5C20BFBF, 0x977C6C1A, 0x8A795CA2, 0x41258F07, 0xC7B1FDA9, 0x0CED2E0C, /* [5][0xc8]*/ + 0xFDBB9CD9, 0x36E74F7C, 0xB0733DD2, 0x7B2FEE77, 0x662ADECF, 0xAD760D6A, 0x2BE27FC4, 0xE0BEAC61, /* [5][0xd0]*/ + 0x123E1C2F, 0xD962CF8A, 0x5FF6BD24, 0x94AA6E81, 0x89AF5E39, 0x42F38D9C, 0xC467FF32, 0x0F3B2C97, /* [5][0xd8]*/ + 0xFE6D9E42, 0x35314DE7, 0xB3A53F49, 0x78F9ECEC, 0x65FCDC54, 0xAEA00FF1, 0x28347D5F, 0xE368AEFA, /* [5][0xe0]*/ + 0x16441B82, 0xDD18C827, 0x5B8CBA89, 0x90D0692C, 0x8DD55994, 0x46898A31, 0xC01DF89F, 0x0B412B3A, /* [5][0xe8]*/ + 0xFA1799EF, 0x314B4A4A, 0xB7DF38E4, 0x7C83EB41, 0x6186DBF9, 0xAADA085C, 0x2C4E7AF2, 0xE712A957, /* [5][0xf0]*/ + 0x15921919, 0xDECECABC, 0x585AB812, 0x93066BB7, 0x8E035B0F, 0x455F88AA, 0xC3CBFA04, 0x089729A1, /* [5][0xf8]*/ + 0xF9C19B74, 0x329D48D1, 0xB4093A7F, 0x7F55E9DA, 0x6250D962, 0xA90C0AC7, 0x2F987869, 0xE4C4ABCC /* [5][0x100]*/ + }, + { + 0x00000000, 0xA6770BB4, 0x979F1129, 0x31E81A9D, 0xF44F2413, 0x52382FA7, 0x63D0353A, 0xC5A73E8E, /* [6][0x08]*/ + 0x33EF4E67, 0x959845D3, 0xA4705F4E, 0x020754FA, 0xC7A06A74, 0x61D761C0, 0x503F7B5D, 0xF64870E9, /* [6][0x10]*/ + 0x67DE9CCE, 0xC1A9977A, 0xF0418DE7, 0x56368653, 0x9391B8DD, 0x35E6B369, 0x040EA9F4, 0xA279A240, /* [6][0x18]*/ + 0x5431D2A9, 0xF246D91D, 0xC3AEC380, 0x65D9C834, 0xA07EF6BA, 0x0609FD0E, 0x37E1E793, 0x9196EC27, /* [6][0x20]*/ + 0xCFBD399C, 0x69CA3228, 0x582228B5, 0xFE552301, 0x3BF21D8F, 0x9D85163B, 0xAC6D0CA6, 0x0A1A0712, /* [6][0x28]*/ + 0xFC5277FB, 0x5A257C4F, 0x6BCD66D2, 0xCDBA6D66, 0x081D53E8, 0xAE6A585C, 0x9F8242C1, 0x39F54975, /* [6][0x30]*/ + 0xA863A552, 0x0E14AEE6, 0x3FFCB47B, 0x998BBFCF, 0x5C2C8141, 0xFA5B8AF5, 0xCBB39068, 0x6DC49BDC, /* [6][0x38]*/ + 0x9B8CEB35, 0x3DFBE081, 0x0C13FA1C, 0xAA64F1A8, 0x6FC3CF26, 0xC9B4C492, 0xF85CDE0F, 0x5E2BD5BB, /* [6][0x40]*/ + 0x440B7579, 0xE27C7ECD, 0xD3946450, 0x75E36FE4, 0xB044516A, 0x16335ADE, 0x27DB4043, 0x81AC4BF7, /* [6][0x48]*/ + 0x77E43B1E, 0xD19330AA, 0xE07B2A37, 0x460C2183, 0x83AB1F0D, 0x25DC14B9, 0x14340E24, 0xB2430590, /* [6][0x50]*/ + 0x23D5E9B7, 0x85A2E203, 0xB44AF89E, 0x123DF32A, 0xD79ACDA4, 0x71EDC610, 0x4005DC8D, 0xE672D739, /* [6][0x58]*/ + 0x103AA7D0, 0xB64DAC64, 0x87A5B6F9, 0x21D2BD4D, 0xE47583C3, 0x42028877, 0x73EA92EA, 0xD59D995E, /* [6][0x60]*/ + 0x8BB64CE5, 0x2DC14751, 0x1C295DCC, 0xBA5E5678, 0x7FF968F6, 0xD98E6342, 0xE86679DF, 0x4E11726B, /* [6][0x68]*/ + 0xB8590282, 0x1E2E0936, 0x2FC613AB, 0x89B1181F, 0x4C162691, 0xEA612D25, 0xDB8937B8, 0x7DFE3C0C, /* [6][0x70]*/ + 0xEC68D02B, 0x4A1FDB9F, 0x7BF7C102, 0xDD80CAB6, 0x1827F438, 0xBE50FF8C, 0x8FB8E511, 0x29CFEEA5, /* [6][0x78]*/ + 0xDF879E4C, 0x79F095F8, 0x48188F65, 0xEE6F84D1, 0x2BC8BA5F, 0x8DBFB1EB, 0xBC57AB76, 0x1A20A0C2, /* [6][0x80]*/ + 0x8816EAF2, 0x2E61E146, 0x1F89FBDB, 0xB9FEF06F, 0x7C59CEE1, 0xDA2EC555, 0xEBC6DFC8, 0x4DB1D47C, /* [6][0x88]*/ + 0xBBF9A495, 0x1D8EAF21, 0x2C66B5BC, 0x8A11BE08, 0x4FB68086, 0xE9C18B32, 0xD82991AF, 0x7E5E9A1B, /* [6][0x90]*/ + 0xEFC8763C, 0x49BF7D88, 0x78576715, 0xDE206CA1, 0x1B87522F, 0xBDF0599B, 0x8C184306, 0x2A6F48B2, /* [6][0x98]*/ + 0xDC27385B, 0x7A5033EF, 0x4BB82972, 0xEDCF22C6, 0x28681C48, 0x8E1F17FC, 0xBFF70D61, 0x198006D5, /* [6][0xa0]*/ + 0x47ABD36E, 0xE1DCD8DA, 0xD034C247, 0x7643C9F3, 0xB3E4F77D, 0x1593FCC9, 0x247BE654, 0x820CEDE0, /* [6][0xa8]*/ + 0x74449D09, 0xD23396BD, 0xE3DB8C20, 0x45AC8794, 0x800BB91A, 0x267CB2AE, 0x1794A833, 0xB1E3A387, /* [6][0xb0]*/ + 0x20754FA0, 0x86024414, 0xB7EA5E89, 0x119D553D, 0xD43A6BB3, 0x724D6007, 0x43A57A9A, 0xE5D2712E, /* [6][0xb8]*/ + 0x139A01C7, 0xB5ED0A73, 0x840510EE, 0x22721B5A, 0xE7D525D4, 0x41A22E60, 0x704A34FD, 0xD63D3F49, /* [6][0xc0]*/ + 0xCC1D9F8B, 0x6A6A943F, 0x5B828EA2, 0xFDF58516, 0x3852BB98, 0x9E25B02C, 0xAFCDAAB1, 0x09BAA105, /* [6][0xc8]*/ + 0xFFF2D1EC, 0x5985DA58, 0x686DC0C5, 0xCE1ACB71, 0x0BBDF5FF, 0xADCAFE4B, 0x9C22E4D6, 0x3A55EF62, /* [6][0xd0]*/ + 0xABC30345, 0x0DB408F1, 0x3C5C126C, 0x9A2B19D8, 0x5F8C2756, 0xF9FB2CE2, 0xC813367F, 0x6E643DCB, /* [6][0xd8]*/ + 0x982C4D22, 0x3E5B4696, 0x0FB35C0B, 0xA9C457BF, 0x6C636931, 0xCA146285, 0xFBFC7818, 0x5D8B73AC, /* [6][0xe0]*/ + 0x03A0A617, 0xA5D7ADA3, 0x943FB73E, 0x3248BC8A, 0xF7EF8204, 0x519889B0, 0x6070932D, 0xC6079899, /* [6][0xe8]*/ + 0x304FE870, 0x9638E3C4, 0xA7D0F959, 0x01A7F2ED, 0xC400CC63, 0x6277C7D7, 0x539FDD4A, 0xF5E8D6FE, /* [6][0xf0]*/ + 0x647E3AD9, 0xC209316D, 0xF3E12BF0, 0x55962044, 0x90311ECA, 0x3646157E, 0x07AE0FE3, 0xA1D90457, /* [6][0xf8]*/ + 0x579174BE, 0xF1E67F0A, 0xC00E6597, 0x66796E23, 0xA3DE50AD, 0x05A95B19, 0x34414184, 0x92364A30 /* [6][0x100]*/ + }, + { + 0x00000000, 0xCCAA009E, 0x4225077D, 0x8E8F07E3, 0x844A0EFA, 0x48E00E64, 0xC66F0987, 0x0AC50919, /* [7][0x08]*/ + 0xD3E51BB5, 0x1F4F1B2B, 0x91C01CC8, 0x5D6A1C56, 0x57AF154F, 0x9B0515D1, 0x158A1232, 0xD92012AC, /* [7][0x10]*/ + 0x7CBB312B, 0xB01131B5, 0x3E9E3656, 0xF23436C8, 0xF8F13FD1, 0x345B3F4F, 0xBAD438AC, 0x767E3832, /* [7][0x18]*/ + 0xAF5E2A9E, 0x63F42A00, 0xED7B2DE3, 0x21D12D7D, 0x2B142464, 0xE7BE24FA, 0x69312319, 0xA59B2387, /* [7][0x20]*/ + 0xF9766256, 0x35DC62C8, 0xBB53652B, 0x77F965B5, 0x7D3C6CAC, 0xB1966C32, 0x3F196BD1, 0xF3B36B4F, /* [7][0x28]*/ + 0x2A9379E3, 0xE639797D, 0x68B67E9E, 0xA41C7E00, 0xAED97719, 0x62737787, 0xECFC7064, 0x205670FA, /* [7][0x30]*/ + 0x85CD537D, 0x496753E3, 0xC7E85400, 0x0B42549E, 0x01875D87, 0xCD2D5D19, 0x43A25AFA, 0x8F085A64, /* [7][0x38]*/ + 0x562848C8, 0x9A824856, 0x140D4FB5, 0xD8A74F2B, 0xD2624632, 0x1EC846AC, 0x9047414F, 0x5CED41D1, /* [7][0x40]*/ + 0x299DC2ED, 0xE537C273, 0x6BB8C590, 0xA712C50E, 0xADD7CC17, 0x617DCC89, 0xEFF2CB6A, 0x2358CBF4, /* [7][0x48]*/ + 0xFA78D958, 0x36D2D9C6, 0xB85DDE25, 0x74F7DEBB, 0x7E32D7A2, 0xB298D73C, 0x3C17D0DF, 0xF0BDD041, /* [7][0x50]*/ + 0x5526F3C6, 0x998CF358, 0x1703F4BB, 0xDBA9F425, 0xD16CFD3C, 0x1DC6FDA2, 0x9349FA41, 0x5FE3FADF, /* [7][0x58]*/ + 0x86C3E873, 0x4A69E8ED, 0xC4E6EF0E, 0x084CEF90, 0x0289E689, 0xCE23E617, 0x40ACE1F4, 0x8C06E16A, /* [7][0x60]*/ + 0xD0EBA0BB, 0x1C41A025, 0x92CEA7C6, 0x5E64A758, 0x54A1AE41, 0x980BAEDF, 0x1684A93C, 0xDA2EA9A2, /* [7][0x68]*/ + 0x030EBB0E, 0xCFA4BB90, 0x412BBC73, 0x8D81BCED, 0x8744B5F4, 0x4BEEB56A, 0xC561B289, 0x09CBB217, /* [7][0x70]*/ + 0xAC509190, 0x60FA910E, 0xEE7596ED, 0x22DF9673, 0x281A9F6A, 0xE4B09FF4, 0x6A3F9817, 0xA6959889, /* [7][0x78]*/ + 0x7FB58A25, 0xB31F8ABB, 0x3D908D58, 0xF13A8DC6, 0xFBFF84DF, 0x37558441, 0xB9DA83A2, 0x7570833C, /* [7][0x80]*/ + 0x533B85DA, 0x9F918544, 0x111E82A7, 0xDDB48239, 0xD7718B20, 0x1BDB8BBE, 0x95548C5D, 0x59FE8CC3, /* [7][0x88]*/ + 0x80DE9E6F, 0x4C749EF1, 0xC2FB9912, 0x0E51998C, 0x04949095, 0xC83E900B, 0x46B197E8, 0x8A1B9776, /* [7][0x90]*/ + 0x2F80B4F1, 0xE32AB46F, 0x6DA5B38C, 0xA10FB312, 0xABCABA0B, 0x6760BA95, 0xE9EFBD76, 0x2545BDE8, /* [7][0x98]*/ + 0xFC65AF44, 0x30CFAFDA, 0xBE40A839, 0x72EAA8A7, 0x782FA1BE, 0xB485A120, 0x3A0AA6C3, 0xF6A0A65D, /* [7][0xa0]*/ + 0xAA4DE78C, 0x66E7E712, 0xE868E0F1, 0x24C2E06F, 0x2E07E976, 0xE2ADE9E8, 0x6C22EE0B, 0xA088EE95, /* [7][0xa8]*/ + 0x79A8FC39, 0xB502FCA7, 0x3B8DFB44, 0xF727FBDA, 0xFDE2F2C3, 0x3148F25D, 0xBFC7F5BE, 0x736DF520, /* [7][0xb0]*/ + 0xD6F6D6A7, 0x1A5CD639, 0x94D3D1DA, 0x5879D144, 0x52BCD85D, 0x9E16D8C3, 0x1099DF20, 0xDC33DFBE, /* [7][0xb8]*/ + 0x0513CD12, 0xC9B9CD8C, 0x4736CA6F, 0x8B9CCAF1, 0x8159C3E8, 0x4DF3C376, 0xC37CC495, 0x0FD6C40B, /* [7][0xc0]*/ + 0x7AA64737, 0xB60C47A9, 0x3883404A, 0xF42940D4, 0xFEEC49CD, 0x32464953, 0xBCC94EB0, 0x70634E2E, /* [7][0xc8]*/ + 0xA9435C82, 0x65E95C1C, 0xEB665BFF, 0x27CC5B61, 0x2D095278, 0xE1A352E6, 0x6F2C5505, 0xA386559B, /* [7][0xd0]*/ + 0x061D761C, 0xCAB77682, 0x44387161, 0x889271FF, 0x825778E6, 0x4EFD7878, 0xC0727F9B, 0x0CD87F05, /* [7][0xd8]*/ + 0xD5F86DA9, 0x19526D37, 0x97DD6AD4, 0x5B776A4A, 0x51B26353, 0x9D1863CD, 0x1397642E, 0xDF3D64B0, /* [7][0xe0]*/ + 0x83D02561, 0x4F7A25FF, 0xC1F5221C, 0x0D5F2282, 0x079A2B9B, 0xCB302B05, 0x45BF2CE6, 0x89152C78, /* [7][0xe8]*/ + 0x50353ED4, 0x9C9F3E4A, 0x121039A9, 0xDEBA3937, 0xD47F302E, 0x18D530B0, 0x965A3753, 0x5AF037CD, /* [7][0xf0]*/ + 0xFF6B144A, 0x33C114D4, 0xBD4E1337, 0x71E413A9, 0x7B211AB0, 0xB78B1A2E, 0x39041DCD, 0xF5AE1D53, /* [7][0xf8]*/ + 0x2C8E0FFF, 0xE0240F61, 0x6EAB0882, 0xA201081C, 0xA8C40105, 0x646E019B, 0xEAE10678, 0x264B06E6 /* [7][0x100]*/ + }, + { + 0x00000000, 0x177B1443, 0x2EF62886, 0x398D3CC5, 0x5DEC510C, 0x4A97454F, 0x731A798A, 0x64616DC9, /* [8][0x08]*/ + 0xBBD8A218, 0xACA3B65B, 0x952E8A9E, 0x82559EDD, 0xE634F314, 0xF14FE757, 0xC8C2DB92, 0xDFB9CFD1, /* [8][0x10]*/ + 0xACC04271, 0xBBBB5632, 0x82366AF7, 0x954D7EB4, 0xF12C137D, 0xE657073E, 0xDFDA3BFB, 0xC8A12FB8, /* [8][0x18]*/ + 0x1718E069, 0x0063F42A, 0x39EEC8EF, 0x2E95DCAC, 0x4AF4B165, 0x5D8FA526, 0x640299E3, 0x73798DA0, /* [8][0x20]*/ + 0x82F182A3, 0x958A96E0, 0xAC07AA25, 0xBB7CBE66, 0xDF1DD3AF, 0xC866C7EC, 0xF1EBFB29, 0xE690EF6A, /* [8][0x28]*/ + 0x392920BB, 0x2E5234F8, 0x17DF083D, 0x00A41C7E, 0x64C571B7, 0x73BE65F4, 0x4A335931, 0x5D484D72, /* [8][0x30]*/ + 0x2E31C0D2, 0x394AD491, 0x00C7E854, 0x17BCFC17, 0x73DD91DE, 0x64A6859D, 0x5D2BB958, 0x4A50AD1B, /* [8][0x38]*/ + 0x95E962CA, 0x82927689, 0xBB1F4A4C, 0xAC645E0F, 0xC80533C6, 0xDF7E2785, 0xE6F31B40, 0xF1880F03, /* [8][0x40]*/ + 0xDE920307, 0xC9E91744, 0xF0642B81, 0xE71F3FC2, 0x837E520B, 0x94054648, 0xAD887A8D, 0xBAF36ECE, /* [8][0x48]*/ + 0x654AA11F, 0x7231B55C, 0x4BBC8999, 0x5CC79DDA, 0x38A6F013, 0x2FDDE450, 0x1650D895, 0x012BCCD6, /* [8][0x50]*/ + 0x72524176, 0x65295535, 0x5CA469F0, 0x4BDF7DB3, 0x2FBE107A, 0x38C50439, 0x014838FC, 0x16332CBF, /* [8][0x58]*/ + 0xC98AE36E, 0xDEF1F72D, 0xE77CCBE8, 0xF007DFAB, 0x9466B262, 0x831DA621, 0xBA909AE4, 0xADEB8EA7, /* [8][0x60]*/ + 0x5C6381A4, 0x4B1895E7, 0x7295A922, 0x65EEBD61, 0x018FD0A8, 0x16F4C4EB, 0x2F79F82E, 0x3802EC6D, /* [8][0x68]*/ + 0xE7BB23BC, 0xF0C037FF, 0xC94D0B3A, 0xDE361F79, 0xBA5772B0, 0xAD2C66F3, 0x94A15A36, 0x83DA4E75, /* [8][0x70]*/ + 0xF0A3C3D5, 0xE7D8D796, 0xDE55EB53, 0xC92EFF10, 0xAD4F92D9, 0xBA34869A, 0x83B9BA5F, 0x94C2AE1C, /* [8][0x78]*/ + 0x4B7B61CD, 0x5C00758E, 0x658D494B, 0x72F65D08, 0x169730C1, 0x01EC2482, 0x38611847, 0x2F1A0C04, /* [8][0x80]*/ + 0x6655004F, 0x712E140C, 0x48A328C9, 0x5FD83C8A, 0x3BB95143, 0x2CC24500, 0x154F79C5, 0x02346D86, /* [8][0x88]*/ + 0xDD8DA257, 0xCAF6B614, 0xF37B8AD1, 0xE4009E92, 0x8061F35B, 0x971AE718, 0xAE97DBDD, 0xB9ECCF9E, /* [8][0x90]*/ + 0xCA95423E, 0xDDEE567D, 0xE4636AB8, 0xF3187EFB, 0x97791332, 0x80020771, 0xB98F3BB4, 0xAEF42FF7, /* [8][0x98]*/ + 0x714DE026, 0x6636F465, 0x5FBBC8A0, 0x48C0DCE3, 0x2CA1B12A, 0x3BDAA569, 0x025799AC, 0x152C8DEF, /* [8][0xa0]*/ + 0xE4A482EC, 0xF3DF96AF, 0xCA52AA6A, 0xDD29BE29, 0xB948D3E0, 0xAE33C7A3, 0x97BEFB66, 0x80C5EF25, /* [8][0xa8]*/ + 0x5F7C20F4, 0x480734B7, 0x718A0872, 0x66F11C31, 0x029071F8, 0x15EB65BB, 0x2C66597E, 0x3B1D4D3D, /* [8][0xb0]*/ + 0x4864C09D, 0x5F1FD4DE, 0x6692E81B, 0x71E9FC58, 0x15889191, 0x02F385D2, 0x3B7EB917, 0x2C05AD54, /* [8][0xb8]*/ + 0xF3BC6285, 0xE4C776C6, 0xDD4A4A03, 0xCA315E40, 0xAE503389, 0xB92B27CA, 0x80A61B0F, 0x97DD0F4C, /* [8][0xc0]*/ + 0xB8C70348, 0xAFBC170B, 0x96312BCE, 0x814A3F8D, 0xE52B5244, 0xF2504607, 0xCBDD7AC2, 0xDCA66E81, /* [8][0xc8]*/ + 0x031FA150, 0x1464B513, 0x2DE989D6, 0x3A929D95, 0x5EF3F05C, 0x4988E41F, 0x7005D8DA, 0x677ECC99, /* [8][0xd0]*/ + 0x14074139, 0x037C557A, 0x3AF169BF, 0x2D8A7DFC, 0x49EB1035, 0x5E900476, 0x671D38B3, 0x70662CF0, /* [8][0xd8]*/ + 0xAFDFE321, 0xB8A4F762, 0x8129CBA7, 0x9652DFE4, 0xF233B22D, 0xE548A66E, 0xDCC59AAB, 0xCBBE8EE8, /* [8][0xe0]*/ + 0x3A3681EB, 0x2D4D95A8, 0x14C0A96D, 0x03BBBD2E, 0x67DAD0E7, 0x70A1C4A4, 0x492CF861, 0x5E57EC22, /* [8][0xe8]*/ + 0x81EE23F3, 0x969537B0, 0xAF180B75, 0xB8631F36, 0xDC0272FF, 0xCB7966BC, 0xF2F45A79, 0xE58F4E3A, /* [8][0xf0]*/ + 0x96F6C39A, 0x818DD7D9, 0xB800EB1C, 0xAF7BFF5F, 0xCB1A9296, 0xDC6186D5, 0xE5ECBA10, 0xF297AE53, /* [8][0xf8]*/ + 0x2D2E6182, 0x3A5575C1, 0x03D84904, 0x14A35D47, 0x70C2308E, 0x67B924CD, 0x5E341808, 0x494F0C4B /* [8][0x100]*/ + }, + { + 0x00000000, 0xEFC26B3E, 0x04F5D03D, 0xEB37BB03, 0x09EBA07A, 0xE629CB44, 0x0D1E7047, 0xE2DC1B79, /* [9][0x08]*/ + 0x13D740F4, 0xFC152BCA, 0x172290C9, 0xF8E0FBF7, 0x1A3CE08E, 0xF5FE8BB0, 0x1EC930B3, 0xF10B5B8D, /* [9][0x10]*/ + 0x27AE81E8, 0xC86CEAD6, 0x235B51D5, 0xCC993AEB, 0x2E452192, 0xC1874AAC, 0x2AB0F1AF, 0xC5729A91, /* [9][0x18]*/ + 0x3479C11C, 0xDBBBAA22, 0x308C1121, 0xDF4E7A1F, 0x3D926166, 0xD2500A58, 0x3967B15B, 0xD6A5DA65, /* [9][0x20]*/ + 0x4F5D03D0, 0xA09F68EE, 0x4BA8D3ED, 0xA46AB8D3, 0x46B6A3AA, 0xA974C894, 0x42437397, 0xAD8118A9, /* [9][0x28]*/ + 0x5C8A4324, 0xB348281A, 0x587F9319, 0xB7BDF827, 0x5561E35E, 0xBAA38860, 0x51943363, 0xBE56585D, /* [9][0x30]*/ + 0x68F38238, 0x8731E906, 0x6C065205, 0x83C4393B, 0x61182242, 0x8EDA497C, 0x65EDF27F, 0x8A2F9941, /* [9][0x38]*/ + 0x7B24C2CC, 0x94E6A9F2, 0x7FD112F1, 0x901379CF, 0x72CF62B6, 0x9D0D0988, 0x763AB28B, 0x99F8D9B5, /* [9][0x40]*/ + 0x9EBA07A0, 0x71786C9E, 0x9A4FD79D, 0x758DBCA3, 0x9751A7DA, 0x7893CCE4, 0x93A477E7, 0x7C661CD9, /* [9][0x48]*/ + 0x8D6D4754, 0x62AF2C6A, 0x89989769, 0x665AFC57, 0x8486E72E, 0x6B448C10, 0x80733713, 0x6FB15C2D, /* [9][0x50]*/ + 0xB9148648, 0x56D6ED76, 0xBDE15675, 0x52233D4B, 0xB0FF2632, 0x5F3D4D0C, 0xB40AF60F, 0x5BC89D31, /* [9][0x58]*/ + 0xAAC3C6BC, 0x4501AD82, 0xAE361681, 0x41F47DBF, 0xA32866C6, 0x4CEA0DF8, 0xA7DDB6FB, 0x481FDDC5, /* [9][0x60]*/ + 0xD1E70470, 0x3E256F4E, 0xD512D44D, 0x3AD0BF73, 0xD80CA40A, 0x37CECF34, 0xDCF97437, 0x333B1F09, /* [9][0x68]*/ + 0xC2304484, 0x2DF22FBA, 0xC6C594B9, 0x2907FF87, 0xCBDBE4FE, 0x24198FC0, 0xCF2E34C3, 0x20EC5FFD, /* [9][0x70]*/ + 0xF6498598, 0x198BEEA6, 0xF2BC55A5, 0x1D7E3E9B, 0xFFA225E2, 0x10604EDC, 0xFB57F5DF, 0x14959EE1, /* [9][0x78]*/ + 0xE59EC56C, 0x0A5CAE52, 0xE16B1551, 0x0EA97E6F, 0xEC756516, 0x03B70E28, 0xE880B52B, 0x0742DE15, /* [9][0x80]*/ + 0xE6050901, 0x09C7623F, 0xE2F0D93C, 0x0D32B202, 0xEFEEA97B, 0x002CC245, 0xEB1B7946, 0x04D91278, /* [9][0x88]*/ + 0xF5D249F5, 0x1A1022CB, 0xF12799C8, 0x1EE5F2F6, 0xFC39E98F, 0x13FB82B1, 0xF8CC39B2, 0x170E528C, /* [9][0x90]*/ + 0xC1AB88E9, 0x2E69E3D7, 0xC55E58D4, 0x2A9C33EA, 0xC8402893, 0x278243AD, 0xCCB5F8AE, 0x23779390, /* [9][0x98]*/ + 0xD27CC81D, 0x3DBEA323, 0xD6891820, 0x394B731E, 0xDB976867, 0x34550359, 0xDF62B85A, 0x30A0D364, /* [9][0xa0]*/ + 0xA9580AD1, 0x469A61EF, 0xADADDAEC, 0x426FB1D2, 0xA0B3AAAB, 0x4F71C195, 0xA4467A96, 0x4B8411A8, /* [9][0xa8]*/ + 0xBA8F4A25, 0x554D211B, 0xBE7A9A18, 0x51B8F126, 0xB364EA5F, 0x5CA68161, 0xB7913A62, 0x5853515C, /* [9][0xb0]*/ + 0x8EF68B39, 0x6134E007, 0x8A035B04, 0x65C1303A, 0x871D2B43, 0x68DF407D, 0x83E8FB7E, 0x6C2A9040, /* [9][0xb8]*/ + 0x9D21CBCD, 0x72E3A0F3, 0x99D41BF0, 0x761670CE, 0x94CA6BB7, 0x7B080089, 0x903FBB8A, 0x7FFDD0B4, /* [9][0xc0]*/ + 0x78BF0EA1, 0x977D659F, 0x7C4ADE9C, 0x9388B5A2, 0x7154AEDB, 0x9E96C5E5, 0x75A17EE6, 0x9A6315D8, /* [9][0xc8]*/ + 0x6B684E55, 0x84AA256B, 0x6F9D9E68, 0x805FF556, 0x6283EE2F, 0x8D418511, 0x66763E12, 0x89B4552C, /* [9][0xd0]*/ + 0x5F118F49, 0xB0D3E477, 0x5BE45F74, 0xB426344A, 0x56FA2F33, 0xB938440D, 0x520FFF0E, 0xBDCD9430, /* [9][0xd8]*/ + 0x4CC6CFBD, 0xA304A483, 0x48331F80, 0xA7F174BE, 0x452D6FC7, 0xAAEF04F9, 0x41D8BFFA, 0xAE1AD4C4, /* [9][0xe0]*/ + 0x37E20D71, 0xD820664F, 0x3317DD4C, 0xDCD5B672, 0x3E09AD0B, 0xD1CBC635, 0x3AFC7D36, 0xD53E1608, /* [9][0xe8]*/ + 0x24354D85, 0xCBF726BB, 0x20C09DB8, 0xCF02F686, 0x2DDEEDFF, 0xC21C86C1, 0x292B3DC2, 0xC6E956FC, /* [9][0xf0]*/ + 0x104C8C99, 0xFF8EE7A7, 0x14B95CA4, 0xFB7B379A, 0x19A72CE3, 0xF66547DD, 0x1D52FCDE, 0xF29097E0, /* [9][0xf8]*/ + 0x039BCC6D, 0xEC59A753, 0x076E1C50, 0xE8AC776E, 0x0A706C17, 0xE5B20729, 0x0E85BC2A, 0xE147D714 /* [9][0x100]*/ + }, + { + 0x00000000, 0xC18EDFC0, 0x586CB9C1, 0x99E26601, 0xB0D97382, 0x7157AC42, 0xE8B5CA43, 0x293B1583, /* [10][0x08]*/ + 0xBAC3E145, 0x7B4D3E85, 0xE2AF5884, 0x23218744, 0x0A1A92C7, 0xCB944D07, 0x52762B06, 0x93F8F4C6, /* [10][0x10]*/ + 0xAEF6C4CB, 0x6F781B0B, 0xF69A7D0A, 0x3714A2CA, 0x1E2FB749, 0xDFA16889, 0x46430E88, 0x87CDD148, /* [10][0x18]*/ + 0x1435258E, 0xD5BBFA4E, 0x4C599C4F, 0x8DD7438F, 0xA4EC560C, 0x656289CC, 0xFC80EFCD, 0x3D0E300D, /* [10][0x20]*/ + 0x869C8FD7, 0x47125017, 0xDEF03616, 0x1F7EE9D6, 0x3645FC55, 0xF7CB2395, 0x6E294594, 0xAFA79A54, /* [10][0x28]*/ + 0x3C5F6E92, 0xFDD1B152, 0x6433D753, 0xA5BD0893, 0x8C861D10, 0x4D08C2D0, 0xD4EAA4D1, 0x15647B11, /* [10][0x30]*/ + 0x286A4B1C, 0xE9E494DC, 0x7006F2DD, 0xB1882D1D, 0x98B3389E, 0x593DE75E, 0xC0DF815F, 0x01515E9F, /* [10][0x38]*/ + 0x92A9AA59, 0x53277599, 0xCAC51398, 0x0B4BCC58, 0x2270D9DB, 0xE3FE061B, 0x7A1C601A, 0xBB92BFDA, /* [10][0x40]*/ + 0xD64819EF, 0x17C6C62F, 0x8E24A02E, 0x4FAA7FEE, 0x66916A6D, 0xA71FB5AD, 0x3EFDD3AC, 0xFF730C6C, /* [10][0x48]*/ + 0x6C8BF8AA, 0xAD05276A, 0x34E7416B, 0xF5699EAB, 0xDC528B28, 0x1DDC54E8, 0x843E32E9, 0x45B0ED29, /* [10][0x50]*/ + 0x78BEDD24, 0xB93002E4, 0x20D264E5, 0xE15CBB25, 0xC867AEA6, 0x09E97166, 0x900B1767, 0x5185C8A7, /* [10][0x58]*/ + 0xC27D3C61, 0x03F3E3A1, 0x9A1185A0, 0x5B9F5A60, 0x72A44FE3, 0xB32A9023, 0x2AC8F622, 0xEB4629E2, /* [10][0x60]*/ + 0x50D49638, 0x915A49F8, 0x08B82FF9, 0xC936F039, 0xE00DE5BA, 0x21833A7A, 0xB8615C7B, 0x79EF83BB, /* [10][0x68]*/ + 0xEA17777D, 0x2B99A8BD, 0xB27BCEBC, 0x73F5117C, 0x5ACE04FF, 0x9B40DB3F, 0x02A2BD3E, 0xC32C62FE, /* [10][0x70]*/ + 0xFE2252F3, 0x3FAC8D33, 0xA64EEB32, 0x67C034F2, 0x4EFB2171, 0x8F75FEB1, 0x169798B0, 0xD7194770, /* [10][0x78]*/ + 0x44E1B3B6, 0x856F6C76, 0x1C8D0A77, 0xDD03D5B7, 0xF438C034, 0x35B61FF4, 0xAC5479F5, 0x6DDAA635, /* [10][0x80]*/ + 0x77E1359F, 0xB66FEA5F, 0x2F8D8C5E, 0xEE03539E, 0xC738461D, 0x06B699DD, 0x9F54FFDC, 0x5EDA201C, /* [10][0x88]*/ + 0xCD22D4DA, 0x0CAC0B1A, 0x954E6D1B, 0x54C0B2DB, 0x7DFBA758, 0xBC757898, 0x25971E99, 0xE419C159, /* [10][0x90]*/ + 0xD917F154, 0x18992E94, 0x817B4895, 0x40F59755, 0x69CE82D6, 0xA8405D16, 0x31A23B17, 0xF02CE4D7, /* [10][0x98]*/ + 0x63D41011, 0xA25ACFD1, 0x3BB8A9D0, 0xFA367610, 0xD30D6393, 0x1283BC53, 0x8B61DA52, 0x4AEF0592, /* [10][0xa0]*/ + 0xF17DBA48, 0x30F36588, 0xA9110389, 0x689FDC49, 0x41A4C9CA, 0x802A160A, 0x19C8700B, 0xD846AFCB, /* [10][0xa8]*/ + 0x4BBE5B0D, 0x8A3084CD, 0x13D2E2CC, 0xD25C3D0C, 0xFB67288F, 0x3AE9F74F, 0xA30B914E, 0x62854E8E, /* [10][0xb0]*/ + 0x5F8B7E83, 0x9E05A143, 0x07E7C742, 0xC6691882, 0xEF520D01, 0x2EDCD2C1, 0xB73EB4C0, 0x76B06B00, /* [10][0xb8]*/ + 0xE5489FC6, 0x24C64006, 0xBD242607, 0x7CAAF9C7, 0x5591EC44, 0x941F3384, 0x0DFD5585, 0xCC738A45, /* [10][0xc0]*/ + 0xA1A92C70, 0x6027F3B0, 0xF9C595B1, 0x384B4A71, 0x11705FF2, 0xD0FE8032, 0x491CE633, 0x889239F3, /* [10][0xc8]*/ + 0x1B6ACD35, 0xDAE412F5, 0x430674F4, 0x8288AB34, 0xABB3BEB7, 0x6A3D6177, 0xF3DF0776, 0x3251D8B6, /* [10][0xd0]*/ + 0x0F5FE8BB, 0xCED1377B, 0x5733517A, 0x96BD8EBA, 0xBF869B39, 0x7E0844F9, 0xE7EA22F8, 0x2664FD38, /* [10][0xd8]*/ + 0xB59C09FE, 0x7412D63E, 0xEDF0B03F, 0x2C7E6FFF, 0x05457A7C, 0xC4CBA5BC, 0x5D29C3BD, 0x9CA71C7D, /* [10][0xe0]*/ + 0x2735A3A7, 0xE6BB7C67, 0x7F591A66, 0xBED7C5A6, 0x97ECD025, 0x56620FE5, 0xCF8069E4, 0x0E0EB624, /* [10][0xe8]*/ + 0x9DF642E2, 0x5C789D22, 0xC59AFB23, 0x041424E3, 0x2D2F3160, 0xECA1EEA0, 0x754388A1, 0xB4CD5761, /* [10][0xf0]*/ + 0x89C3676C, 0x484DB8AC, 0xD1AFDEAD, 0x1021016D, 0x391A14EE, 0xF894CB2E, 0x6176AD2F, 0xA0F872EF, /* [10][0xf8]*/ + 0x33008629, 0xF28E59E9, 0x6B6C3FE8, 0xAAE2E028, 0x83D9F5AB, 0x42572A6B, 0xDBB54C6A, 0x1A3B93AA /* [10][0x100]*/ + }, + { + 0x00000000, 0x9BA54C6F, 0xEC3B9E9F, 0x779ED2F0, 0x03063B7F, 0x98A37710, 0xEF3DA5E0, 0x7498E98F, /* [11][0x08]*/ + 0x060C76FE, 0x9DA93A91, 0xEA37E861, 0x7192A40E, 0x050A4D81, 0x9EAF01EE, 0xE931D31E, 0x72949F71, /* [11][0x10]*/ + 0x0C18EDFC, 0x97BDA193, 0xE0237363, 0x7B863F0C, 0x0F1ED683, 0x94BB9AEC, 0xE325481C, 0x78800473, /* [11][0x18]*/ + 0x0A149B02, 0x91B1D76D, 0xE62F059D, 0x7D8A49F2, 0x0912A07D, 0x92B7EC12, 0xE5293EE2, 0x7E8C728D, /* [11][0x20]*/ + 0x1831DBF8, 0x83949797, 0xF40A4567, 0x6FAF0908, 0x1B37E087, 0x8092ACE8, 0xF70C7E18, 0x6CA93277, /* [11][0x28]*/ + 0x1E3DAD06, 0x8598E169, 0xF2063399, 0x69A37FF6, 0x1D3B9679, 0x869EDA16, 0xF10008E6, 0x6AA54489, /* [11][0x30]*/ + 0x14293604, 0x8F8C7A6B, 0xF812A89B, 0x63B7E4F4, 0x172F0D7B, 0x8C8A4114, 0xFB1493E4, 0x60B1DF8B, /* [11][0x38]*/ + 0x122540FA, 0x89800C95, 0xFE1EDE65, 0x65BB920A, 0x11237B85, 0x8A8637EA, 0xFD18E51A, 0x66BDA975, /* [11][0x40]*/ + 0x3063B7F0, 0xABC6FB9F, 0xDC58296F, 0x47FD6500, 0x33658C8F, 0xA8C0C0E0, 0xDF5E1210, 0x44FB5E7F, /* [11][0x48]*/ + 0x366FC10E, 0xADCA8D61, 0xDA545F91, 0x41F113FE, 0x3569FA71, 0xAECCB61E, 0xD95264EE, 0x42F72881, /* [11][0x50]*/ + 0x3C7B5A0C, 0xA7DE1663, 0xD040C493, 0x4BE588FC, 0x3F7D6173, 0xA4D82D1C, 0xD346FFEC, 0x48E3B383, /* [11][0x58]*/ + 0x3A772CF2, 0xA1D2609D, 0xD64CB26D, 0x4DE9FE02, 0x3971178D, 0xA2D45BE2, 0xD54A8912, 0x4EEFC57D, /* [11][0x60]*/ + 0x28526C08, 0xB3F72067, 0xC469F297, 0x5FCCBEF8, 0x2B545777, 0xB0F11B18, 0xC76FC9E8, 0x5CCA8587, /* [11][0x68]*/ + 0x2E5E1AF6, 0xB5FB5699, 0xC2658469, 0x59C0C806, 0x2D582189, 0xB6FD6DE6, 0xC163BF16, 0x5AC6F379, /* [11][0x70]*/ + 0x244A81F4, 0xBFEFCD9B, 0xC8711F6B, 0x53D45304, 0x274CBA8B, 0xBCE9F6E4, 0xCB772414, 0x50D2687B, /* [11][0x78]*/ + 0x2246F70A, 0xB9E3BB65, 0xCE7D6995, 0x55D825FA, 0x2140CC75, 0xBAE5801A, 0xCD7B52EA, 0x56DE1E85, /* [11][0x80]*/ + 0x60C76FE0, 0xFB62238F, 0x8CFCF17F, 0x1759BD10, 0x63C1549F, 0xF86418F0, 0x8FFACA00, 0x145F866F, /* [11][0x88]*/ + 0x66CB191E, 0xFD6E5571, 0x8AF08781, 0x1155CBEE, 0x65CD2261, 0xFE686E0E, 0x89F6BCFE, 0x1253F091, /* [11][0x90]*/ + 0x6CDF821C, 0xF77ACE73, 0x80E41C83, 0x1B4150EC, 0x6FD9B963, 0xF47CF50C, 0x83E227FC, 0x18476B93, /* [11][0x98]*/ + 0x6AD3F4E2, 0xF176B88D, 0x86E86A7D, 0x1D4D2612, 0x69D5CF9D, 0xF27083F2, 0x85EE5102, 0x1E4B1D6D, /* [11][0xa0]*/ + 0x78F6B418, 0xE353F877, 0x94CD2A87, 0x0F6866E8, 0x7BF08F67, 0xE055C308, 0x97CB11F8, 0x0C6E5D97, /* [11][0xa8]*/ + 0x7EFAC2E6, 0xE55F8E89, 0x92C15C79, 0x09641016, 0x7DFCF999, 0xE659B5F6, 0x91C76706, 0x0A622B69, /* [11][0xb0]*/ + 0x74EE59E4, 0xEF4B158B, 0x98D5C77B, 0x03708B14, 0x77E8629B, 0xEC4D2EF4, 0x9BD3FC04, 0x0076B06B, /* [11][0xb8]*/ + 0x72E22F1A, 0xE9476375, 0x9ED9B185, 0x057CFDEA, 0x71E41465, 0xEA41580A, 0x9DDF8AFA, 0x067AC695, /* [11][0xc0]*/ + 0x50A4D810, 0xCB01947F, 0xBC9F468F, 0x273A0AE0, 0x53A2E36F, 0xC807AF00, 0xBF997DF0, 0x243C319F, /* [11][0xc8]*/ + 0x56A8AEEE, 0xCD0DE281, 0xBA933071, 0x21367C1E, 0x55AE9591, 0xCE0BD9FE, 0xB9950B0E, 0x22304761, /* [11][0xd0]*/ + 0x5CBC35EC, 0xC7197983, 0xB087AB73, 0x2B22E71C, 0x5FBA0E93, 0xC41F42FC, 0xB381900C, 0x2824DC63, /* [11][0xd8]*/ + 0x5AB04312, 0xC1150F7D, 0xB68BDD8D, 0x2D2E91E2, 0x59B6786D, 0xC2133402, 0xB58DE6F2, 0x2E28AA9D, /* [11][0xe0]*/ + 0x489503E8, 0xD3304F87, 0xA4AE9D77, 0x3F0BD118, 0x4B933897, 0xD03674F8, 0xA7A8A608, 0x3C0DEA67, /* [11][0xe8]*/ + 0x4E997516, 0xD53C3979, 0xA2A2EB89, 0x3907A7E6, 0x4D9F4E69, 0xD63A0206, 0xA1A4D0F6, 0x3A019C99, /* [11][0xf0]*/ + 0x448DEE14, 0xDF28A27B, 0xA8B6708B, 0x33133CE4, 0x478BD56B, 0xDC2E9904, 0xABB04BF4, 0x3015079B, /* [11][0xf8]*/ + 0x428198EA, 0xD924D485, 0xAEBA0675, 0x351F4A1A, 0x4187A395, 0xDA22EFFA, 0xADBC3D0A, 0x36197165 /* [11][0x100]*/ + }, + { + 0x00000000, 0xDD96D985, 0x605CB54B, 0xBDCA6CCE, 0xC0B96A96, 0x1D2FB313, 0xA0E5DFDD, 0x7D730658, /* [12][0x08]*/ + 0x5A03D36D, 0x87950AE8, 0x3A5F6626, 0xE7C9BFA3, 0x9ABAB9FB, 0x472C607E, 0xFAE60CB0, 0x2770D535, /* [12][0x10]*/ + 0xB407A6DA, 0x69917F5F, 0xD45B1391, 0x09CDCA14, 0x74BECC4C, 0xA92815C9, 0x14E27907, 0xC974A082, /* [12][0x18]*/ + 0xEE0475B7, 0x3392AC32, 0x8E58C0FC, 0x53CE1979, 0x2EBD1F21, 0xF32BC6A4, 0x4EE1AA6A, 0x937773EF, /* [12][0x20]*/ + 0xB37E4BF5, 0x6EE89270, 0xD322FEBE, 0x0EB4273B, 0x73C72163, 0xAE51F8E6, 0x139B9428, 0xCE0D4DAD, /* [12][0x28]*/ + 0xE97D9898, 0x34EB411D, 0x89212DD3, 0x54B7F456, 0x29C4F20E, 0xF4522B8B, 0x49984745, 0x940E9EC0, /* [12][0x30]*/ + 0x0779ED2F, 0xDAEF34AA, 0x67255864, 0xBAB381E1, 0xC7C087B9, 0x1A565E3C, 0xA79C32F2, 0x7A0AEB77, /* [12][0x38]*/ + 0x5D7A3E42, 0x80ECE7C7, 0x3D268B09, 0xE0B0528C, 0x9DC354D4, 0x40558D51, 0xFD9FE19F, 0x2009381A, /* [12][0x40]*/ + 0xBD8D91AB, 0x601B482E, 0xDDD124E0, 0x0047FD65, 0x7D34FB3D, 0xA0A222B8, 0x1D684E76, 0xC0FE97F3, /* [12][0x48]*/ + 0xE78E42C6, 0x3A189B43, 0x87D2F78D, 0x5A442E08, 0x27372850, 0xFAA1F1D5, 0x476B9D1B, 0x9AFD449E, /* [12][0x50]*/ + 0x098A3771, 0xD41CEEF4, 0x69D6823A, 0xB4405BBF, 0xC9335DE7, 0x14A58462, 0xA96FE8AC, 0x74F93129, /* [12][0x58]*/ + 0x5389E41C, 0x8E1F3D99, 0x33D55157, 0xEE4388D2, 0x93308E8A, 0x4EA6570F, 0xF36C3BC1, 0x2EFAE244, /* [12][0x60]*/ + 0x0EF3DA5E, 0xD36503DB, 0x6EAF6F15, 0xB339B690, 0xCE4AB0C8, 0x13DC694D, 0xAE160583, 0x7380DC06, /* [12][0x68]*/ + 0x54F00933, 0x8966D0B6, 0x34ACBC78, 0xE93A65FD, 0x944963A5, 0x49DFBA20, 0xF415D6EE, 0x29830F6B, /* [12][0x70]*/ + 0xBAF47C84, 0x6762A501, 0xDAA8C9CF, 0x073E104A, 0x7A4D1612, 0xA7DBCF97, 0x1A11A359, 0xC7877ADC, /* [12][0x78]*/ + 0xE0F7AFE9, 0x3D61766C, 0x80AB1AA2, 0x5D3DC327, 0x204EC57F, 0xFDD81CFA, 0x40127034, 0x9D84A9B1, /* [12][0x80]*/ + 0xA06A2517, 0x7DFCFC92, 0xC036905C, 0x1DA049D9, 0x60D34F81, 0xBD459604, 0x008FFACA, 0xDD19234F, /* [12][0x88]*/ + 0xFA69F67A, 0x27FF2FFF, 0x9A354331, 0x47A39AB4, 0x3AD09CEC, 0xE7464569, 0x5A8C29A7, 0x871AF022, /* [12][0x90]*/ + 0x146D83CD, 0xC9FB5A48, 0x74313686, 0xA9A7EF03, 0xD4D4E95B, 0x094230DE, 0xB4885C10, 0x691E8595, /* [12][0x98]*/ + 0x4E6E50A0, 0x93F88925, 0x2E32E5EB, 0xF3A43C6E, 0x8ED73A36, 0x5341E3B3, 0xEE8B8F7D, 0x331D56F8, /* [12][0xa0]*/ + 0x13146EE2, 0xCE82B767, 0x7348DBA9, 0xAEDE022C, 0xD3AD0474, 0x0E3BDDF1, 0xB3F1B13F, 0x6E6768BA, /* [12][0xa8]*/ + 0x4917BD8F, 0x9481640A, 0x294B08C4, 0xF4DDD141, 0x89AED719, 0x54380E9C, 0xE9F26252, 0x3464BBD7, /* [12][0xb0]*/ + 0xA713C838, 0x7A8511BD, 0xC74F7D73, 0x1AD9A4F6, 0x67AAA2AE, 0xBA3C7B2B, 0x07F617E5, 0xDA60CE60, /* [12][0xb8]*/ + 0xFD101B55, 0x2086C2D0, 0x9D4CAE1E, 0x40DA779B, 0x3DA971C3, 0xE03FA846, 0x5DF5C488, 0x80631D0D, /* [12][0xc0]*/ + 0x1DE7B4BC, 0xC0716D39, 0x7DBB01F7, 0xA02DD872, 0xDD5EDE2A, 0x00C807AF, 0xBD026B61, 0x6094B2E4, /* [12][0xc8]*/ + 0x47E467D1, 0x9A72BE54, 0x27B8D29A, 0xFA2E0B1F, 0x875D0D47, 0x5ACBD4C2, 0xE701B80C, 0x3A976189, /* [12][0xd0]*/ + 0xA9E01266, 0x7476CBE3, 0xC9BCA72D, 0x142A7EA8, 0x695978F0, 0xB4CFA175, 0x0905CDBB, 0xD493143E, /* [12][0xd8]*/ + 0xF3E3C10B, 0x2E75188E, 0x93BF7440, 0x4E29ADC5, 0x335AAB9D, 0xEECC7218, 0x53061ED6, 0x8E90C753, /* [12][0xe0]*/ + 0xAE99FF49, 0x730F26CC, 0xCEC54A02, 0x13539387, 0x6E2095DF, 0xB3B64C5A, 0x0E7C2094, 0xD3EAF911, /* [12][0xe8]*/ + 0xF49A2C24, 0x290CF5A1, 0x94C6996F, 0x495040EA, 0x342346B2, 0xE9B59F37, 0x547FF3F9, 0x89E92A7C, /* [12][0xf0]*/ + 0x1A9E5993, 0xC7088016, 0x7AC2ECD8, 0xA754355D, 0xDA273305, 0x07B1EA80, 0xBA7B864E, 0x67ED5FCB, /* [12][0xf8]*/ + 0x409D8AFE, 0x9D0B537B, 0x20C13FB5, 0xFD57E630, 0x8024E068, 0x5DB239ED, 0xE0785523, 0x3DEE8CA6 /* [12][0x100]*/ + }, + { + 0x00000000, 0x9D0FE176, 0xE16EC4AD, 0x7C6125DB, 0x19AC8F1B, 0x84A36E6D, 0xF8C24BB6, 0x65CDAAC0, /* [13][0x08]*/ + 0x33591E36, 0xAE56FF40, 0xD237DA9B, 0x4F383BED, 0x2AF5912D, 0xB7FA705B, 0xCB9B5580, 0x5694B4F6, /* [13][0x10]*/ + 0x66B23C6C, 0xFBBDDD1A, 0x87DCF8C1, 0x1AD319B7, 0x7F1EB377, 0xE2115201, 0x9E7077DA, 0x037F96AC, /* [13][0x18]*/ + 0x55EB225A, 0xC8E4C32C, 0xB485E6F7, 0x298A0781, 0x4C47AD41, 0xD1484C37, 0xAD2969EC, 0x3026889A, /* [13][0x20]*/ + 0xCD6478D8, 0x506B99AE, 0x2C0ABC75, 0xB1055D03, 0xD4C8F7C3, 0x49C716B5, 0x35A6336E, 0xA8A9D218, /* [13][0x28]*/ + 0xFE3D66EE, 0x63328798, 0x1F53A243, 0x825C4335, 0xE791E9F5, 0x7A9E0883, 0x06FF2D58, 0x9BF0CC2E, /* [13][0x30]*/ + 0xABD644B4, 0x36D9A5C2, 0x4AB88019, 0xD7B7616F, 0xB27ACBAF, 0x2F752AD9, 0x53140F02, 0xCE1BEE74, /* [13][0x38]*/ + 0x988F5A82, 0x0580BBF4, 0x79E19E2F, 0xE4EE7F59, 0x8123D599, 0x1C2C34EF, 0x604D1134, 0xFD42F042, /* [13][0x40]*/ + 0x41B9F7F1, 0xDCB61687, 0xA0D7335C, 0x3DD8D22A, 0x581578EA, 0xC51A999C, 0xB97BBC47, 0x24745D31, /* [13][0x48]*/ + 0x72E0E9C7, 0xEFEF08B1, 0x938E2D6A, 0x0E81CC1C, 0x6B4C66DC, 0xF64387AA, 0x8A22A271, 0x172D4307, /* [13][0x50]*/ + 0x270BCB9D, 0xBA042AEB, 0xC6650F30, 0x5B6AEE46, 0x3EA74486, 0xA3A8A5F0, 0xDFC9802B, 0x42C6615D, /* [13][0x58]*/ + 0x1452D5AB, 0x895D34DD, 0xF53C1106, 0x6833F070, 0x0DFE5AB0, 0x90F1BBC6, 0xEC909E1D, 0x719F7F6B, /* [13][0x60]*/ + 0x8CDD8F29, 0x11D26E5F, 0x6DB34B84, 0xF0BCAAF2, 0x95710032, 0x087EE144, 0x741FC49F, 0xE91025E9, /* [13][0x68]*/ + 0xBF84911F, 0x228B7069, 0x5EEA55B2, 0xC3E5B4C4, 0xA6281E04, 0x3B27FF72, 0x4746DAA9, 0xDA493BDF, /* [13][0x70]*/ + 0xEA6FB345, 0x77605233, 0x0B0177E8, 0x960E969E, 0xF3C33C5E, 0x6ECCDD28, 0x12ADF8F3, 0x8FA21985, /* [13][0x78]*/ + 0xD936AD73, 0x44394C05, 0x385869DE, 0xA55788A8, 0xC09A2268, 0x5D95C31E, 0x21F4E6C5, 0xBCFB07B3, /* [13][0x80]*/ + 0x8373EFE2, 0x1E7C0E94, 0x621D2B4F, 0xFF12CA39, 0x9ADF60F9, 0x07D0818F, 0x7BB1A454, 0xE6BE4522, /* [13][0x88]*/ + 0xB02AF1D4, 0x2D2510A2, 0x51443579, 0xCC4BD40F, 0xA9867ECF, 0x34899FB9, 0x48E8BA62, 0xD5E75B14, /* [13][0x90]*/ + 0xE5C1D38E, 0x78CE32F8, 0x04AF1723, 0x99A0F655, 0xFC6D5C95, 0x6162BDE3, 0x1D039838, 0x800C794E, /* [13][0x98]*/ + 0xD698CDB8, 0x4B972CCE, 0x37F60915, 0xAAF9E863, 0xCF3442A3, 0x523BA3D5, 0x2E5A860E, 0xB3556778, /* [13][0xa0]*/ + 0x4E17973A, 0xD318764C, 0xAF795397, 0x3276B2E1, 0x57BB1821, 0xCAB4F957, 0xB6D5DC8C, 0x2BDA3DFA, /* [13][0xa8]*/ + 0x7D4E890C, 0xE041687A, 0x9C204DA1, 0x012FACD7, 0x64E20617, 0xF9EDE761, 0x858CC2BA, 0x188323CC, /* [13][0xb0]*/ + 0x28A5AB56, 0xB5AA4A20, 0xC9CB6FFB, 0x54C48E8D, 0x3109244D, 0xAC06C53B, 0xD067E0E0, 0x4D680196, /* [13][0xb8]*/ + 0x1BFCB560, 0x86F35416, 0xFA9271CD, 0x679D90BB, 0x02503A7B, 0x9F5FDB0D, 0xE33EFED6, 0x7E311FA0, /* [13][0xc0]*/ + 0xC2CA1813, 0x5FC5F965, 0x23A4DCBE, 0xBEAB3DC8, 0xDB669708, 0x4669767E, 0x3A0853A5, 0xA707B2D3, /* [13][0xc8]*/ + 0xF1930625, 0x6C9CE753, 0x10FDC288, 0x8DF223FE, 0xE83F893E, 0x75306848, 0x09514D93, 0x945EACE5, /* [13][0xd0]*/ + 0xA478247F, 0x3977C509, 0x4516E0D2, 0xD81901A4, 0xBDD4AB64, 0x20DB4A12, 0x5CBA6FC9, 0xC1B58EBF, /* [13][0xd8]*/ + 0x97213A49, 0x0A2EDB3F, 0x764FFEE4, 0xEB401F92, 0x8E8DB552, 0x13825424, 0x6FE371FF, 0xF2EC9089, /* [13][0xe0]*/ + 0x0FAE60CB, 0x92A181BD, 0xEEC0A466, 0x73CF4510, 0x1602EFD0, 0x8B0D0EA6, 0xF76C2B7D, 0x6A63CA0B, /* [13][0xe8]*/ + 0x3CF77EFD, 0xA1F89F8B, 0xDD99BA50, 0x40965B26, 0x255BF1E6, 0xB8541090, 0xC435354B, 0x593AD43D, /* [13][0xf0]*/ + 0x691C5CA7, 0xF413BDD1, 0x8872980A, 0x157D797C, 0x70B0D3BC, 0xEDBF32CA, 0x91DE1711, 0x0CD1F667, /* [13][0xf8]*/ + 0x5A454291, 0xC74AA3E7, 0xBB2B863C, 0x2624674A, 0x43E9CD8A, 0xDEE62CFC, 0xA2870927, 0x3F88E851 /* [13][0x100]*/ + }, + { + 0x00000000, 0xB9FBDBE8, 0xA886B191, 0x117D6A79, 0x8A7C6563, 0x3387BE8B, 0x22FAD4F2, 0x9B010F1A, /* [14][0x08]*/ + 0xCF89CC87, 0x7672176F, 0x670F7D16, 0xDEF4A6FE, 0x45F5A9E4, 0xFC0E720C, 0xED731875, 0x5488C39D, /* [14][0x10]*/ + 0x44629F4F, 0xFD9944A7, 0xECE42EDE, 0x551FF536, 0xCE1EFA2C, 0x77E521C4, 0x66984BBD, 0xDF639055, /* [14][0x18]*/ + 0x8BEB53C8, 0x32108820, 0x236DE259, 0x9A9639B1, 0x019736AB, 0xB86CED43, 0xA911873A, 0x10EA5CD2, /* [14][0x20]*/ + 0x88C53E9E, 0x313EE576, 0x20438F0F, 0x99B854E7, 0x02B95BFD, 0xBB428015, 0xAA3FEA6C, 0x13C43184, /* [14][0x28]*/ + 0x474CF219, 0xFEB729F1, 0xEFCA4388, 0x56319860, 0xCD30977A, 0x74CB4C92, 0x65B626EB, 0xDC4DFD03, /* [14][0x30]*/ + 0xCCA7A1D1, 0x755C7A39, 0x64211040, 0xDDDACBA8, 0x46DBC4B2, 0xFF201F5A, 0xEE5D7523, 0x57A6AECB, /* [14][0x38]*/ + 0x032E6D56, 0xBAD5B6BE, 0xABA8DCC7, 0x1253072F, 0x89520835, 0x30A9D3DD, 0x21D4B9A4, 0x982F624C, /* [14][0x40]*/ + 0xCAFB7B7D, 0x7300A095, 0x627DCAEC, 0xDB861104, 0x40871E1E, 0xF97CC5F6, 0xE801AF8F, 0x51FA7467, /* [14][0x48]*/ + 0x0572B7FA, 0xBC896C12, 0xADF4066B, 0x140FDD83, 0x8F0ED299, 0x36F50971, 0x27886308, 0x9E73B8E0, /* [14][0x50]*/ + 0x8E99E432, 0x37623FDA, 0x261F55A3, 0x9FE48E4B, 0x04E58151, 0xBD1E5AB9, 0xAC6330C0, 0x1598EB28, /* [14][0x58]*/ + 0x411028B5, 0xF8EBF35D, 0xE9969924, 0x506D42CC, 0xCB6C4DD6, 0x7297963E, 0x63EAFC47, 0xDA1127AF, /* [14][0x60]*/ + 0x423E45E3, 0xFBC59E0B, 0xEAB8F472, 0x53432F9A, 0xC8422080, 0x71B9FB68, 0x60C49111, 0xD93F4AF9, /* [14][0x68]*/ + 0x8DB78964, 0x344C528C, 0x253138F5, 0x9CCAE31D, 0x07CBEC07, 0xBE3037EF, 0xAF4D5D96, 0x16B6867E, /* [14][0x70]*/ + 0x065CDAAC, 0xBFA70144, 0xAEDA6B3D, 0x1721B0D5, 0x8C20BFCF, 0x35DB6427, 0x24A60E5E, 0x9D5DD5B6, /* [14][0x78]*/ + 0xC9D5162B, 0x702ECDC3, 0x6153A7BA, 0xD8A87C52, 0x43A97348, 0xFA52A8A0, 0xEB2FC2D9, 0x52D41931, /* [14][0x80]*/ + 0x4E87F0BB, 0xF77C2B53, 0xE601412A, 0x5FFA9AC2, 0xC4FB95D8, 0x7D004E30, 0x6C7D2449, 0xD586FFA1, /* [14][0x88]*/ + 0x810E3C3C, 0x38F5E7D4, 0x29888DAD, 0x90735645, 0x0B72595F, 0xB28982B7, 0xA3F4E8CE, 0x1A0F3326, /* [14][0x90]*/ + 0x0AE56FF4, 0xB31EB41C, 0xA263DE65, 0x1B98058D, 0x80990A97, 0x3962D17F, 0x281FBB06, 0x91E460EE, /* [14][0x98]*/ + 0xC56CA373, 0x7C97789B, 0x6DEA12E2, 0xD411C90A, 0x4F10C610, 0xF6EB1DF8, 0xE7967781, 0x5E6DAC69, /* [14][0xa0]*/ + 0xC642CE25, 0x7FB915CD, 0x6EC47FB4, 0xD73FA45C, 0x4C3EAB46, 0xF5C570AE, 0xE4B81AD7, 0x5D43C13F, /* [14][0xa8]*/ + 0x09CB02A2, 0xB030D94A, 0xA14DB333, 0x18B668DB, 0x83B767C1, 0x3A4CBC29, 0x2B31D650, 0x92CA0DB8, /* [14][0xb0]*/ + 0x8220516A, 0x3BDB8A82, 0x2AA6E0FB, 0x935D3B13, 0x085C3409, 0xB1A7EFE1, 0xA0DA8598, 0x19215E70, /* [14][0xb8]*/ + 0x4DA99DED, 0xF4524605, 0xE52F2C7C, 0x5CD4F794, 0xC7D5F88E, 0x7E2E2366, 0x6F53491F, 0xD6A892F7, /* [14][0xc0]*/ + 0x847C8BC6, 0x3D87502E, 0x2CFA3A57, 0x9501E1BF, 0x0E00EEA5, 0xB7FB354D, 0xA6865F34, 0x1F7D84DC, /* [14][0xc8]*/ + 0x4BF54741, 0xF20E9CA9, 0xE373F6D0, 0x5A882D38, 0xC1892222, 0x7872F9CA, 0x690F93B3, 0xD0F4485B, /* [14][0xd0]*/ + 0xC01E1489, 0x79E5CF61, 0x6898A518, 0xD1637EF0, 0x4A6271EA, 0xF399AA02, 0xE2E4C07B, 0x5B1F1B93, /* [14][0xd8]*/ + 0x0F97D80E, 0xB66C03E6, 0xA711699F, 0x1EEAB277, 0x85EBBD6D, 0x3C106685, 0x2D6D0CFC, 0x9496D714, /* [14][0xe0]*/ + 0x0CB9B558, 0xB5426EB0, 0xA43F04C9, 0x1DC4DF21, 0x86C5D03B, 0x3F3E0BD3, 0x2E4361AA, 0x97B8BA42, /* [14][0xe8]*/ + 0xC33079DF, 0x7ACBA237, 0x6BB6C84E, 0xD24D13A6, 0x494C1CBC, 0xF0B7C754, 0xE1CAAD2D, 0x583176C5, /* [14][0xf0]*/ + 0x48DB2A17, 0xF120F1FF, 0xE05D9B86, 0x59A6406E, 0xC2A74F74, 0x7B5C949C, 0x6A21FEE5, 0xD3DA250D, /* [14][0xf8]*/ + 0x8752E690, 0x3EA93D78, 0x2FD45701, 0x962F8CE9, 0x0D2E83F3, 0xB4D5581B, 0xA5A83262, 0x1C53E98A /* [14][0x100]*/ + }, + { + 0x00000000, 0xAE689191, 0x87A02563, 0x29C8B4F2, 0xD4314C87, 0x7A59DD16, 0x539169E4, 0xFDF9F875, /* [15][0x08]*/ + 0x73139F4F, 0xDD7B0EDE, 0xF4B3BA2C, 0x5ADB2BBD, 0xA722D3C8, 0x094A4259, 0x2082F6AB, 0x8EEA673A, /* [15][0x10]*/ + 0xE6273E9E, 0x484FAF0F, 0x61871BFD, 0xCFEF8A6C, 0x32167219, 0x9C7EE388, 0xB5B6577A, 0x1BDEC6EB, /* [15][0x18]*/ + 0x9534A1D1, 0x3B5C3040, 0x129484B2, 0xBCFC1523, 0x4105ED56, 0xEF6D7CC7, 0xC6A5C835, 0x68CD59A4, /* [15][0x20]*/ + 0x173F7B7D, 0xB957EAEC, 0x909F5E1E, 0x3EF7CF8F, 0xC30E37FA, 0x6D66A66B, 0x44AE1299, 0xEAC68308, /* [15][0x28]*/ + 0x642CE432, 0xCA4475A3, 0xE38CC151, 0x4DE450C0, 0xB01DA8B5, 0x1E753924, 0x37BD8DD6, 0x99D51C47, /* [15][0x30]*/ + 0xF11845E3, 0x5F70D472, 0x76B86080, 0xD8D0F111, 0x25290964, 0x8B4198F5, 0xA2892C07, 0x0CE1BD96, /* [15][0x38]*/ + 0x820BDAAC, 0x2C634B3D, 0x05ABFFCF, 0xABC36E5E, 0x563A962B, 0xF85207BA, 0xD19AB348, 0x7FF222D9, /* [15][0x40]*/ + 0x2E7EF6FA, 0x8016676B, 0xA9DED399, 0x07B64208, 0xFA4FBA7D, 0x54272BEC, 0x7DEF9F1E, 0xD3870E8F, /* [15][0x48]*/ + 0x5D6D69B5, 0xF305F824, 0xDACD4CD6, 0x74A5DD47, 0x895C2532, 0x2734B4A3, 0x0EFC0051, 0xA09491C0, /* [15][0x50]*/ + 0xC859C864, 0x663159F5, 0x4FF9ED07, 0xE1917C96, 0x1C6884E3, 0xB2001572, 0x9BC8A180, 0x35A03011, /* [15][0x58]*/ + 0xBB4A572B, 0x1522C6BA, 0x3CEA7248, 0x9282E3D9, 0x6F7B1BAC, 0xC1138A3D, 0xE8DB3ECF, 0x46B3AF5E, /* [15][0x60]*/ + 0x39418D87, 0x97291C16, 0xBEE1A8E4, 0x10893975, 0xED70C100, 0x43185091, 0x6AD0E463, 0xC4B875F2, /* [15][0x68]*/ + 0x4A5212C8, 0xE43A8359, 0xCDF237AB, 0x639AA63A, 0x9E635E4F, 0x300BCFDE, 0x19C37B2C, 0xB7ABEABD, /* [15][0x70]*/ + 0xDF66B319, 0x710E2288, 0x58C6967A, 0xF6AE07EB, 0x0B57FF9E, 0xA53F6E0F, 0x8CF7DAFD, 0x229F4B6C, /* [15][0x78]*/ + 0xAC752C56, 0x021DBDC7, 0x2BD50935, 0x85BD98A4, 0x784460D1, 0xD62CF140, 0xFFE445B2, 0x518CD423, /* [15][0x80]*/ + 0x5CFDEDF4, 0xF2957C65, 0xDB5DC897, 0x75355906, 0x88CCA173, 0x26A430E2, 0x0F6C8410, 0xA1041581, /* [15][0x88]*/ + 0x2FEE72BB, 0x8186E32A, 0xA84E57D8, 0x0626C649, 0xFBDF3E3C, 0x55B7AFAD, 0x7C7F1B5F, 0xD2178ACE, /* [15][0x90]*/ + 0xBADAD36A, 0x14B242FB, 0x3D7AF609, 0x93126798, 0x6EEB9FED, 0xC0830E7C, 0xE94BBA8E, 0x47232B1F, /* [15][0x98]*/ + 0xC9C94C25, 0x67A1DDB4, 0x4E696946, 0xE001F8D7, 0x1DF800A2, 0xB3909133, 0x9A5825C1, 0x3430B450, /* [15][0xa0]*/ + 0x4BC29689, 0xE5AA0718, 0xCC62B3EA, 0x620A227B, 0x9FF3DA0E, 0x319B4B9F, 0x1853FF6D, 0xB63B6EFC, /* [15][0xa8]*/ + 0x38D109C6, 0x96B99857, 0xBF712CA5, 0x1119BD34, 0xECE04541, 0x4288D4D0, 0x6B406022, 0xC528F1B3, /* [15][0xb0]*/ + 0xADE5A817, 0x038D3986, 0x2A458D74, 0x842D1CE5, 0x79D4E490, 0xD7BC7501, 0xFE74C1F3, 0x501C5062, /* [15][0xb8]*/ + 0xDEF63758, 0x709EA6C9, 0x5956123B, 0xF73E83AA, 0x0AC77BDF, 0xA4AFEA4E, 0x8D675EBC, 0x230FCF2D, /* [15][0xc0]*/ + 0x72831B0E, 0xDCEB8A9F, 0xF5233E6D, 0x5B4BAFFC, 0xA6B25789, 0x08DAC618, 0x211272EA, 0x8F7AE37B, /* [15][0xc8]*/ + 0x01908441, 0xAFF815D0, 0x8630A122, 0x285830B3, 0xD5A1C8C6, 0x7BC95957, 0x5201EDA5, 0xFC697C34, /* [15][0xd0]*/ + 0x94A42590, 0x3ACCB401, 0x130400F3, 0xBD6C9162, 0x40956917, 0xEEFDF886, 0xC7354C74, 0x695DDDE5, /* [15][0xd8]*/ + 0xE7B7BADF, 0x49DF2B4E, 0x60179FBC, 0xCE7F0E2D, 0x3386F658, 0x9DEE67C9, 0xB426D33B, 0x1A4E42AA, /* [15][0xe0]*/ + 0x65BC6073, 0xCBD4F1E2, 0xE21C4510, 0x4C74D481, 0xB18D2CF4, 0x1FE5BD65, 0x362D0997, 0x98459806, /* [15][0xe8]*/ + 0x16AFFF3C, 0xB8C76EAD, 0x910FDA5F, 0x3F674BCE, 0xC29EB3BB, 0x6CF6222A, 0x453E96D8, 0xEB560749, /* [15][0xf0]*/ + 0x839B5EED, 0x2DF3CF7C, 0x043B7B8E, 0xAA53EA1F, 0x57AA126A, 0xF9C283FB, 0xD00A3709, 0x7E62A698, /* [15][0xf8]*/ + 0xF088C1A2, 0x5EE05033, 0x7728E4C1, 0xD9407550, 0x24B98D25, 0x8AD11CB4, 0xA319A846, 0x0D7139D7 /* [15][0x100]*/ + }}; + +/** Castagnoli CRC32c (iSCSI) lookup table for slice-by-4/8/16 */ +const uint32_t CRC32C_TABLE[16][256] = { + { + 0x00000000, 0xF26B8303, 0xE13B70F7, 0x1350F3F4, 0xC79A971F, 0x35F1141C, 0x26A1E7E8, 0xD4CA64EB, /* [0][0x08]*/ + 0x8AD958CF, 0x78B2DBCC, 0x6BE22838, 0x9989AB3B, 0x4D43CFD0, 0xBF284CD3, 0xAC78BF27, 0x5E133C24, /* [0][0x10]*/ + 0x105EC76F, 0xE235446C, 0xF165B798, 0x030E349B, 0xD7C45070, 0x25AFD373, 0x36FF2087, 0xC494A384, /* [0][0x18]*/ + 0x9A879FA0, 0x68EC1CA3, 0x7BBCEF57, 0x89D76C54, 0x5D1D08BF, 0xAF768BBC, 0xBC267848, 0x4E4DFB4B, /* [0][0x20]*/ + 0x20BD8EDE, 0xD2D60DDD, 0xC186FE29, 0x33ED7D2A, 0xE72719C1, 0x154C9AC2, 0x061C6936, 0xF477EA35, /* [0][0x28]*/ + 0xAA64D611, 0x580F5512, 0x4B5FA6E6, 0xB93425E5, 0x6DFE410E, 0x9F95C20D, 0x8CC531F9, 0x7EAEB2FA, /* [0][0x30]*/ + 0x30E349B1, 0xC288CAB2, 0xD1D83946, 0x23B3BA45, 0xF779DEAE, 0x05125DAD, 0x1642AE59, 0xE4292D5A, /* [0][0x38]*/ + 0xBA3A117E, 0x4851927D, 0x5B016189, 0xA96AE28A, 0x7DA08661, 0x8FCB0562, 0x9C9BF696, 0x6EF07595, /* [0][0x40]*/ + 0x417B1DBC, 0xB3109EBF, 0xA0406D4B, 0x522BEE48, 0x86E18AA3, 0x748A09A0, 0x67DAFA54, 0x95B17957, /* [0][0x48]*/ + 0xCBA24573, 0x39C9C670, 0x2A993584, 0xD8F2B687, 0x0C38D26C, 0xFE53516F, 0xED03A29B, 0x1F682198, /* [0][0x50]*/ + 0x5125DAD3, 0xA34E59D0, 0xB01EAA24, 0x42752927, 0x96BF4DCC, 0x64D4CECF, 0x77843D3B, 0x85EFBE38, /* [0][0x58]*/ + 0xDBFC821C, 0x2997011F, 0x3AC7F2EB, 0xC8AC71E8, 0x1C661503, 0xEE0D9600, 0xFD5D65F4, 0x0F36E6F7, /* [0][0x60]*/ + 0x61C69362, 0x93AD1061, 0x80FDE395, 0x72966096, 0xA65C047D, 0x5437877E, 0x4767748A, 0xB50CF789, /* [0][0x68]*/ + 0xEB1FCBAD, 0x197448AE, 0x0A24BB5A, 0xF84F3859, 0x2C855CB2, 0xDEEEDFB1, 0xCDBE2C45, 0x3FD5AF46, /* [0][0x70]*/ + 0x7198540D, 0x83F3D70E, 0x90A324FA, 0x62C8A7F9, 0xB602C312, 0x44694011, 0x5739B3E5, 0xA55230E6, /* [0][0x78]*/ + 0xFB410CC2, 0x092A8FC1, 0x1A7A7C35, 0xE811FF36, 0x3CDB9BDD, 0xCEB018DE, 0xDDE0EB2A, 0x2F8B6829, /* [0][0x80]*/ + 0x82F63B78, 0x709DB87B, 0x63CD4B8F, 0x91A6C88C, 0x456CAC67, 0xB7072F64, 0xA457DC90, 0x563C5F93, /* [0][0x88]*/ + 0x082F63B7, 0xFA44E0B4, 0xE9141340, 0x1B7F9043, 0xCFB5F4A8, 0x3DDE77AB, 0x2E8E845F, 0xDCE5075C, /* [0][0x90]*/ + 0x92A8FC17, 0x60C37F14, 0x73938CE0, 0x81F80FE3, 0x55326B08, 0xA759E80B, 0xB4091BFF, 0x466298FC, /* [0][0x98]*/ + 0x1871A4D8, 0xEA1A27DB, 0xF94AD42F, 0x0B21572C, 0xDFEB33C7, 0x2D80B0C4, 0x3ED04330, 0xCCBBC033, /* [0][0xa0]*/ + 0xA24BB5A6, 0x502036A5, 0x4370C551, 0xB11B4652, 0x65D122B9, 0x97BAA1BA, 0x84EA524E, 0x7681D14D, /* [0][0xa8]*/ + 0x2892ED69, 0xDAF96E6A, 0xC9A99D9E, 0x3BC21E9D, 0xEF087A76, 0x1D63F975, 0x0E330A81, 0xFC588982, /* [0][0xb0]*/ + 0xB21572C9, 0x407EF1CA, 0x532E023E, 0xA145813D, 0x758FE5D6, 0x87E466D5, 0x94B49521, 0x66DF1622, /* [0][0xb8]*/ + 0x38CC2A06, 0xCAA7A905, 0xD9F75AF1, 0x2B9CD9F2, 0xFF56BD19, 0x0D3D3E1A, 0x1E6DCDEE, 0xEC064EED, /* [0][0xc0]*/ + 0xC38D26C4, 0x31E6A5C7, 0x22B65633, 0xD0DDD530, 0x0417B1DB, 0xF67C32D8, 0xE52CC12C, 0x1747422F, /* [0][0xc8]*/ + 0x49547E0B, 0xBB3FFD08, 0xA86F0EFC, 0x5A048DFF, 0x8ECEE914, 0x7CA56A17, 0x6FF599E3, 0x9D9E1AE0, /* [0][0xd0]*/ + 0xD3D3E1AB, 0x21B862A8, 0x32E8915C, 0xC083125F, 0x144976B4, 0xE622F5B7, 0xF5720643, 0x07198540, /* [0][0xd8]*/ + 0x590AB964, 0xAB613A67, 0xB831C993, 0x4A5A4A90, 0x9E902E7B, 0x6CFBAD78, 0x7FAB5E8C, 0x8DC0DD8F, /* [0][0xe0]*/ + 0xE330A81A, 0x115B2B19, 0x020BD8ED, 0xF0605BEE, 0x24AA3F05, 0xD6C1BC06, 0xC5914FF2, 0x37FACCF1, /* [0][0xe8]*/ + 0x69E9F0D5, 0x9B8273D6, 0x88D28022, 0x7AB90321, 0xAE7367CA, 0x5C18E4C9, 0x4F48173D, 0xBD23943E, /* [0][0xf0]*/ + 0xF36E6F75, 0x0105EC76, 0x12551F82, 0xE03E9C81, 0x34F4F86A, 0xC69F7B69, 0xD5CF889D, 0x27A40B9E, /* [0][0xf8]*/ + 0x79B737BA, 0x8BDCB4B9, 0x988C474D, 0x6AE7C44E, 0xBE2DA0A5, 0x4C4623A6, 0x5F16D052, 0xAD7D5351 /* [0][0x100]*/ + }, + { + 0x00000000, 0x13A29877, 0x274530EE, 0x34E7A899, 0x4E8A61DC, 0x5D28F9AB, 0x69CF5132, 0x7A6DC945, /* [1][0x08]*/ + 0x9D14C3B8, 0x8EB65BCF, 0xBA51F356, 0xA9F36B21, 0xD39EA264, 0xC03C3A13, 0xF4DB928A, 0xE7790AFD, /* [1][0x10]*/ + 0x3FC5F181, 0x2C6769F6, 0x1880C16F, 0x0B225918, 0x714F905D, 0x62ED082A, 0x560AA0B3, 0x45A838C4, /* [1][0x18]*/ + 0xA2D13239, 0xB173AA4E, 0x859402D7, 0x96369AA0, 0xEC5B53E5, 0xFFF9CB92, 0xCB1E630B, 0xD8BCFB7C, /* [1][0x20]*/ + 0x7F8BE302, 0x6C297B75, 0x58CED3EC, 0x4B6C4B9B, 0x310182DE, 0x22A31AA9, 0x1644B230, 0x05E62A47, /* [1][0x28]*/ + 0xE29F20BA, 0xF13DB8CD, 0xC5DA1054, 0xD6788823, 0xAC154166, 0xBFB7D911, 0x8B507188, 0x98F2E9FF, /* [1][0x30]*/ + 0x404E1283, 0x53EC8AF4, 0x670B226D, 0x74A9BA1A, 0x0EC4735F, 0x1D66EB28, 0x298143B1, 0x3A23DBC6, /* [1][0x38]*/ + 0xDD5AD13B, 0xCEF8494C, 0xFA1FE1D5, 0xE9BD79A2, 0x93D0B0E7, 0x80722890, 0xB4958009, 0xA737187E, /* [1][0x40]*/ + 0xFF17C604, 0xECB55E73, 0xD852F6EA, 0xCBF06E9D, 0xB19DA7D8, 0xA23F3FAF, 0x96D89736, 0x857A0F41, /* [1][0x48]*/ + 0x620305BC, 0x71A19DCB, 0x45463552, 0x56E4AD25, 0x2C896460, 0x3F2BFC17, 0x0BCC548E, 0x186ECCF9, /* [1][0x50]*/ + 0xC0D23785, 0xD370AFF2, 0xE797076B, 0xF4359F1C, 0x8E585659, 0x9DFACE2E, 0xA91D66B7, 0xBABFFEC0, /* [1][0x58]*/ + 0x5DC6F43D, 0x4E646C4A, 0x7A83C4D3, 0x69215CA4, 0x134C95E1, 0x00EE0D96, 0x3409A50F, 0x27AB3D78, /* [1][0x60]*/ + 0x809C2506, 0x933EBD71, 0xA7D915E8, 0xB47B8D9F, 0xCE1644DA, 0xDDB4DCAD, 0xE9537434, 0xFAF1EC43, /* [1][0x68]*/ + 0x1D88E6BE, 0x0E2A7EC9, 0x3ACDD650, 0x296F4E27, 0x53028762, 0x40A01F15, 0x7447B78C, 0x67E52FFB, /* [1][0x70]*/ + 0xBF59D487, 0xACFB4CF0, 0x981CE469, 0x8BBE7C1E, 0xF1D3B55B, 0xE2712D2C, 0xD69685B5, 0xC5341DC2, /* [1][0x78]*/ + 0x224D173F, 0x31EF8F48, 0x050827D1, 0x16AABFA6, 0x6CC776E3, 0x7F65EE94, 0x4B82460D, 0x5820DE7A, /* [1][0x80]*/ + 0xFBC3FAF9, 0xE861628E, 0xDC86CA17, 0xCF245260, 0xB5499B25, 0xA6EB0352, 0x920CABCB, 0x81AE33BC, /* [1][0x88]*/ + 0x66D73941, 0x7575A136, 0x419209AF, 0x523091D8, 0x285D589D, 0x3BFFC0EA, 0x0F186873, 0x1CBAF004, /* [1][0x90]*/ + 0xC4060B78, 0xD7A4930F, 0xE3433B96, 0xF0E1A3E1, 0x8A8C6AA4, 0x992EF2D3, 0xADC95A4A, 0xBE6BC23D, /* [1][0x98]*/ + 0x5912C8C0, 0x4AB050B7, 0x7E57F82E, 0x6DF56059, 0x1798A91C, 0x043A316B, 0x30DD99F2, 0x237F0185, /* [1][0xa0]*/ + 0x844819FB, 0x97EA818C, 0xA30D2915, 0xB0AFB162, 0xCAC27827, 0xD960E050, 0xED8748C9, 0xFE25D0BE, /* [1][0xa8]*/ + 0x195CDA43, 0x0AFE4234, 0x3E19EAAD, 0x2DBB72DA, 0x57D6BB9F, 0x447423E8, 0x70938B71, 0x63311306, /* [1][0xb0]*/ + 0xBB8DE87A, 0xA82F700D, 0x9CC8D894, 0x8F6A40E3, 0xF50789A6, 0xE6A511D1, 0xD242B948, 0xC1E0213F, /* [1][0xb8]*/ + 0x26992BC2, 0x353BB3B5, 0x01DC1B2C, 0x127E835B, 0x68134A1E, 0x7BB1D269, 0x4F567AF0, 0x5CF4E287, /* [1][0xc0]*/ + 0x04D43CFD, 0x1776A48A, 0x23910C13, 0x30339464, 0x4A5E5D21, 0x59FCC556, 0x6D1B6DCF, 0x7EB9F5B8, /* [1][0xc8]*/ + 0x99C0FF45, 0x8A626732, 0xBE85CFAB, 0xAD2757DC, 0xD74A9E99, 0xC4E806EE, 0xF00FAE77, 0xE3AD3600, /* [1][0xd0]*/ + 0x3B11CD7C, 0x28B3550B, 0x1C54FD92, 0x0FF665E5, 0x759BACA0, 0x663934D7, 0x52DE9C4E, 0x417C0439, /* [1][0xd8]*/ + 0xA6050EC4, 0xB5A796B3, 0x81403E2A, 0x92E2A65D, 0xE88F6F18, 0xFB2DF76F, 0xCFCA5FF6, 0xDC68C781, /* [1][0xe0]*/ + 0x7B5FDFFF, 0x68FD4788, 0x5C1AEF11, 0x4FB87766, 0x35D5BE23, 0x26772654, 0x12908ECD, 0x013216BA, /* [1][0xe8]*/ + 0xE64B1C47, 0xF5E98430, 0xC10E2CA9, 0xD2ACB4DE, 0xA8C17D9B, 0xBB63E5EC, 0x8F844D75, 0x9C26D502, /* [1][0xf0]*/ + 0x449A2E7E, 0x5738B609, 0x63DF1E90, 0x707D86E7, 0x0A104FA2, 0x19B2D7D5, 0x2D557F4C, 0x3EF7E73B, /* [1][0xf8]*/ + 0xD98EEDC6, 0xCA2C75B1, 0xFECBDD28, 0xED69455F, 0x97048C1A, 0x84A6146D, 0xB041BCF4, 0xA3E32483 /* [1][0x100]*/ + }, + { + 0x00000000, 0xA541927E, 0x4F6F520D, 0xEA2EC073, 0x9EDEA41A, 0x3B9F3664, 0xD1B1F617, 0x74F06469, /* [2][0x08]*/ + 0x38513EC5, 0x9D10ACBB, 0x773E6CC8, 0xD27FFEB6, 0xA68F9ADF, 0x03CE08A1, 0xE9E0C8D2, 0x4CA15AAC, /* [2][0x10]*/ + 0x70A27D8A, 0xD5E3EFF4, 0x3FCD2F87, 0x9A8CBDF9, 0xEE7CD990, 0x4B3D4BEE, 0xA1138B9D, 0x045219E3, /* [2][0x18]*/ + 0x48F3434F, 0xEDB2D131, 0x079C1142, 0xA2DD833C, 0xD62DE755, 0x736C752B, 0x9942B558, 0x3C032726, /* [2][0x20]*/ + 0xE144FB14, 0x4405696A, 0xAE2BA919, 0x0B6A3B67, 0x7F9A5F0E, 0xDADBCD70, 0x30F50D03, 0x95B49F7D, /* [2][0x28]*/ + 0xD915C5D1, 0x7C5457AF, 0x967A97DC, 0x333B05A2, 0x47CB61CB, 0xE28AF3B5, 0x08A433C6, 0xADE5A1B8, /* [2][0x30]*/ + 0x91E6869E, 0x34A714E0, 0xDE89D493, 0x7BC846ED, 0x0F382284, 0xAA79B0FA, 0x40577089, 0xE516E2F7, /* [2][0x38]*/ + 0xA9B7B85B, 0x0CF62A25, 0xE6D8EA56, 0x43997828, 0x37691C41, 0x92288E3F, 0x78064E4C, 0xDD47DC32, /* [2][0x40]*/ + 0xC76580D9, 0x622412A7, 0x880AD2D4, 0x2D4B40AA, 0x59BB24C3, 0xFCFAB6BD, 0x16D476CE, 0xB395E4B0, /* [2][0x48]*/ + 0xFF34BE1C, 0x5A752C62, 0xB05BEC11, 0x151A7E6F, 0x61EA1A06, 0xC4AB8878, 0x2E85480B, 0x8BC4DA75, /* [2][0x50]*/ + 0xB7C7FD53, 0x12866F2D, 0xF8A8AF5E, 0x5DE93D20, 0x29195949, 0x8C58CB37, 0x66760B44, 0xC337993A, /* [2][0x58]*/ + 0x8F96C396, 0x2AD751E8, 0xC0F9919B, 0x65B803E5, 0x1148678C, 0xB409F5F2, 0x5E273581, 0xFB66A7FF, /* [2][0x60]*/ + 0x26217BCD, 0x8360E9B3, 0x694E29C0, 0xCC0FBBBE, 0xB8FFDFD7, 0x1DBE4DA9, 0xF7908DDA, 0x52D11FA4, /* [2][0x68]*/ + 0x1E704508, 0xBB31D776, 0x511F1705, 0xF45E857B, 0x80AEE112, 0x25EF736C, 0xCFC1B31F, 0x6A802161, /* [2][0x70]*/ + 0x56830647, 0xF3C29439, 0x19EC544A, 0xBCADC634, 0xC85DA25D, 0x6D1C3023, 0x8732F050, 0x2273622E, /* [2][0x78]*/ + 0x6ED23882, 0xCB93AAFC, 0x21BD6A8F, 0x84FCF8F1, 0xF00C9C98, 0x554D0EE6, 0xBF63CE95, 0x1A225CEB, /* [2][0x80]*/ + 0x8B277743, 0x2E66E53D, 0xC448254E, 0x6109B730, 0x15F9D359, 0xB0B84127, 0x5A968154, 0xFFD7132A, /* [2][0x88]*/ + 0xB3764986, 0x1637DBF8, 0xFC191B8B, 0x595889F5, 0x2DA8ED9C, 0x88E97FE2, 0x62C7BF91, 0xC7862DEF, /* [2][0x90]*/ + 0xFB850AC9, 0x5EC498B7, 0xB4EA58C4, 0x11ABCABA, 0x655BAED3, 0xC01A3CAD, 0x2A34FCDE, 0x8F756EA0, /* [2][0x98]*/ + 0xC3D4340C, 0x6695A672, 0x8CBB6601, 0x29FAF47F, 0x5D0A9016, 0xF84B0268, 0x1265C21B, 0xB7245065, /* [2][0xa0]*/ + 0x6A638C57, 0xCF221E29, 0x250CDE5A, 0x804D4C24, 0xF4BD284D, 0x51FCBA33, 0xBBD27A40, 0x1E93E83E, /* [2][0xa8]*/ + 0x5232B292, 0xF77320EC, 0x1D5DE09F, 0xB81C72E1, 0xCCEC1688, 0x69AD84F6, 0x83834485, 0x26C2D6FB, /* [2][0xb0]*/ + 0x1AC1F1DD, 0xBF8063A3, 0x55AEA3D0, 0xF0EF31AE, 0x841F55C7, 0x215EC7B9, 0xCB7007CA, 0x6E3195B4, /* [2][0xb8]*/ + 0x2290CF18, 0x87D15D66, 0x6DFF9D15, 0xC8BE0F6B, 0xBC4E6B02, 0x190FF97C, 0xF321390F, 0x5660AB71, /* [2][0xc0]*/ + 0x4C42F79A, 0xE90365E4, 0x032DA597, 0xA66C37E9, 0xD29C5380, 0x77DDC1FE, 0x9DF3018D, 0x38B293F3, /* [2][0xc8]*/ + 0x7413C95F, 0xD1525B21, 0x3B7C9B52, 0x9E3D092C, 0xEACD6D45, 0x4F8CFF3B, 0xA5A23F48, 0x00E3AD36, /* [2][0xd0]*/ + 0x3CE08A10, 0x99A1186E, 0x738FD81D, 0xD6CE4A63, 0xA23E2E0A, 0x077FBC74, 0xED517C07, 0x4810EE79, /* [2][0xd8]*/ + 0x04B1B4D5, 0xA1F026AB, 0x4BDEE6D8, 0xEE9F74A6, 0x9A6F10CF, 0x3F2E82B1, 0xD50042C2, 0x7041D0BC, /* [2][0xe0]*/ + 0xAD060C8E, 0x08479EF0, 0xE2695E83, 0x4728CCFD, 0x33D8A894, 0x96993AEA, 0x7CB7FA99, 0xD9F668E7, /* [2][0xe8]*/ + 0x9557324B, 0x3016A035, 0xDA386046, 0x7F79F238, 0x0B899651, 0xAEC8042F, 0x44E6C45C, 0xE1A75622, /* [2][0xf0]*/ + 0xDDA47104, 0x78E5E37A, 0x92CB2309, 0x378AB177, 0x437AD51E, 0xE63B4760, 0x0C158713, 0xA954156D, /* [2][0xf8]*/ + 0xE5F54FC1, 0x40B4DDBF, 0xAA9A1DCC, 0x0FDB8FB2, 0x7B2BEBDB, 0xDE6A79A5, 0x3444B9D6, 0x91052BA8 /* [2][0x100]*/ + }, + { + 0x00000000, 0xDD45AAB8, 0xBF672381, 0x62228939, 0x7B2231F3, 0xA6679B4B, 0xC4451272, 0x1900B8CA, /* [3][0x08]*/ + 0xF64463E6, 0x2B01C95E, 0x49234067, 0x9466EADF, 0x8D665215, 0x5023F8AD, 0x32017194, 0xEF44DB2C, /* [3][0x10]*/ + 0xE964B13D, 0x34211B85, 0x560392BC, 0x8B463804, 0x924680CE, 0x4F032A76, 0x2D21A34F, 0xF06409F7, /* [3][0x18]*/ + 0x1F20D2DB, 0xC2657863, 0xA047F15A, 0x7D025BE2, 0x6402E328, 0xB9474990, 0xDB65C0A9, 0x06206A11, /* [3][0x20]*/ + 0xD725148B, 0x0A60BE33, 0x6842370A, 0xB5079DB2, 0xAC072578, 0x71428FC0, 0x136006F9, 0xCE25AC41, /* [3][0x28]*/ + 0x2161776D, 0xFC24DDD5, 0x9E0654EC, 0x4343FE54, 0x5A43469E, 0x8706EC26, 0xE524651F, 0x3861CFA7, /* [3][0x30]*/ + 0x3E41A5B6, 0xE3040F0E, 0x81268637, 0x5C632C8F, 0x45639445, 0x98263EFD, 0xFA04B7C4, 0x27411D7C, /* [3][0x38]*/ + 0xC805C650, 0x15406CE8, 0x7762E5D1, 0xAA274F69, 0xB327F7A3, 0x6E625D1B, 0x0C40D422, 0xD1057E9A, /* [3][0x40]*/ + 0xABA65FE7, 0x76E3F55F, 0x14C17C66, 0xC984D6DE, 0xD0846E14, 0x0DC1C4AC, 0x6FE34D95, 0xB2A6E72D, /* [3][0x48]*/ + 0x5DE23C01, 0x80A796B9, 0xE2851F80, 0x3FC0B538, 0x26C00DF2, 0xFB85A74A, 0x99A72E73, 0x44E284CB, /* [3][0x50]*/ + 0x42C2EEDA, 0x9F874462, 0xFDA5CD5B, 0x20E067E3, 0x39E0DF29, 0xE4A57591, 0x8687FCA8, 0x5BC25610, /* [3][0x58]*/ + 0xB4868D3C, 0x69C32784, 0x0BE1AEBD, 0xD6A40405, 0xCFA4BCCF, 0x12E11677, 0x70C39F4E, 0xAD8635F6, /* [3][0x60]*/ + 0x7C834B6C, 0xA1C6E1D4, 0xC3E468ED, 0x1EA1C255, 0x07A17A9F, 0xDAE4D027, 0xB8C6591E, 0x6583F3A6, /* [3][0x68]*/ + 0x8AC7288A, 0x57828232, 0x35A00B0B, 0xE8E5A1B3, 0xF1E51979, 0x2CA0B3C1, 0x4E823AF8, 0x93C79040, /* [3][0x70]*/ + 0x95E7FA51, 0x48A250E9, 0x2A80D9D0, 0xF7C57368, 0xEEC5CBA2, 0x3380611A, 0x51A2E823, 0x8CE7429B, /* [3][0x78]*/ + 0x63A399B7, 0xBEE6330F, 0xDCC4BA36, 0x0181108E, 0x1881A844, 0xC5C402FC, 0xA7E68BC5, 0x7AA3217D, /* [3][0x80]*/ + 0x52A0C93F, 0x8FE56387, 0xEDC7EABE, 0x30824006, 0x2982F8CC, 0xF4C75274, 0x96E5DB4D, 0x4BA071F5, /* [3][0x88]*/ + 0xA4E4AAD9, 0x79A10061, 0x1B838958, 0xC6C623E0, 0xDFC69B2A, 0x02833192, 0x60A1B8AB, 0xBDE41213, /* [3][0x90]*/ + 0xBBC47802, 0x6681D2BA, 0x04A35B83, 0xD9E6F13B, 0xC0E649F1, 0x1DA3E349, 0x7F816A70, 0xA2C4C0C8, /* [3][0x98]*/ + 0x4D801BE4, 0x90C5B15C, 0xF2E73865, 0x2FA292DD, 0x36A22A17, 0xEBE780AF, 0x89C50996, 0x5480A32E, /* [3][0xa0]*/ + 0x8585DDB4, 0x58C0770C, 0x3AE2FE35, 0xE7A7548D, 0xFEA7EC47, 0x23E246FF, 0x41C0CFC6, 0x9C85657E, /* [3][0xa8]*/ + 0x73C1BE52, 0xAE8414EA, 0xCCA69DD3, 0x11E3376B, 0x08E38FA1, 0xD5A62519, 0xB784AC20, 0x6AC10698, /* [3][0xb0]*/ + 0x6CE16C89, 0xB1A4C631, 0xD3864F08, 0x0EC3E5B0, 0x17C35D7A, 0xCA86F7C2, 0xA8A47EFB, 0x75E1D443, /* [3][0xb8]*/ + 0x9AA50F6F, 0x47E0A5D7, 0x25C22CEE, 0xF8878656, 0xE1873E9C, 0x3CC29424, 0x5EE01D1D, 0x83A5B7A5, /* [3][0xc0]*/ + 0xF90696D8, 0x24433C60, 0x4661B559, 0x9B241FE1, 0x8224A72B, 0x5F610D93, 0x3D4384AA, 0xE0062E12, /* [3][0xc8]*/ + 0x0F42F53E, 0xD2075F86, 0xB025D6BF, 0x6D607C07, 0x7460C4CD, 0xA9256E75, 0xCB07E74C, 0x16424DF4, /* [3][0xd0]*/ + 0x106227E5, 0xCD278D5D, 0xAF050464, 0x7240AEDC, 0x6B401616, 0xB605BCAE, 0xD4273597, 0x09629F2F, /* [3][0xd8]*/ + 0xE6264403, 0x3B63EEBB, 0x59416782, 0x8404CD3A, 0x9D0475F0, 0x4041DF48, 0x22635671, 0xFF26FCC9, /* [3][0xe0]*/ + 0x2E238253, 0xF36628EB, 0x9144A1D2, 0x4C010B6A, 0x5501B3A0, 0x88441918, 0xEA669021, 0x37233A99, /* [3][0xe8]*/ + 0xD867E1B5, 0x05224B0D, 0x6700C234, 0xBA45688C, 0xA345D046, 0x7E007AFE, 0x1C22F3C7, 0xC167597F, /* [3][0xf0]*/ + 0xC747336E, 0x1A0299D6, 0x782010EF, 0xA565BA57, 0xBC65029D, 0x6120A825, 0x0302211C, 0xDE478BA4, /* [3][0xf8]*/ + 0x31035088, 0xEC46FA30, 0x8E647309, 0x5321D9B1, 0x4A21617B, 0x9764CBC3, 0xF54642FA, 0x2803E842 /* [3][0x100]*/ + }, + { + 0x00000000, 0x38116FAC, 0x7022DF58, 0x4833B0F4, 0xE045BEB0, 0xD854D11C, 0x906761E8, 0xA8760E44, /* [4][0x08]*/ + 0xC5670B91, 0xFD76643D, 0xB545D4C9, 0x8D54BB65, 0x2522B521, 0x1D33DA8D, 0x55006A79, 0x6D1105D5, /* [4][0x10]*/ + 0x8F2261D3, 0xB7330E7F, 0xFF00BE8B, 0xC711D127, 0x6F67DF63, 0x5776B0CF, 0x1F45003B, 0x27546F97, /* [4][0x18]*/ + 0x4A456A42, 0x725405EE, 0x3A67B51A, 0x0276DAB6, 0xAA00D4F2, 0x9211BB5E, 0xDA220BAA, 0xE2336406, /* [4][0x20]*/ + 0x1BA8B557, 0x23B9DAFB, 0x6B8A6A0F, 0x539B05A3, 0xFBED0BE7, 0xC3FC644B, 0x8BCFD4BF, 0xB3DEBB13, /* [4][0x28]*/ + 0xDECFBEC6, 0xE6DED16A, 0xAEED619E, 0x96FC0E32, 0x3E8A0076, 0x069B6FDA, 0x4EA8DF2E, 0x76B9B082, /* [4][0x30]*/ + 0x948AD484, 0xAC9BBB28, 0xE4A80BDC, 0xDCB96470, 0x74CF6A34, 0x4CDE0598, 0x04EDB56C, 0x3CFCDAC0, /* [4][0x38]*/ + 0x51EDDF15, 0x69FCB0B9, 0x21CF004D, 0x19DE6FE1, 0xB1A861A5, 0x89B90E09, 0xC18ABEFD, 0xF99BD151, /* [4][0x40]*/ + 0x37516AAE, 0x0F400502, 0x4773B5F6, 0x7F62DA5A, 0xD714D41E, 0xEF05BBB2, 0xA7360B46, 0x9F2764EA, /* [4][0x48]*/ + 0xF236613F, 0xCA270E93, 0x8214BE67, 0xBA05D1CB, 0x1273DF8F, 0x2A62B023, 0x625100D7, 0x5A406F7B, /* [4][0x50]*/ + 0xB8730B7D, 0x806264D1, 0xC851D425, 0xF040BB89, 0x5836B5CD, 0x6027DA61, 0x28146A95, 0x10050539, /* [4][0x58]*/ + 0x7D1400EC, 0x45056F40, 0x0D36DFB4, 0x3527B018, 0x9D51BE5C, 0xA540D1F0, 0xED736104, 0xD5620EA8, /* [4][0x60]*/ + 0x2CF9DFF9, 0x14E8B055, 0x5CDB00A1, 0x64CA6F0D, 0xCCBC6149, 0xF4AD0EE5, 0xBC9EBE11, 0x848FD1BD, /* [4][0x68]*/ + 0xE99ED468, 0xD18FBBC4, 0x99BC0B30, 0xA1AD649C, 0x09DB6AD8, 0x31CA0574, 0x79F9B580, 0x41E8DA2C, /* [4][0x70]*/ + 0xA3DBBE2A, 0x9BCAD186, 0xD3F96172, 0xEBE80EDE, 0x439E009A, 0x7B8F6F36, 0x33BCDFC2, 0x0BADB06E, /* [4][0x78]*/ + 0x66BCB5BB, 0x5EADDA17, 0x169E6AE3, 0x2E8F054F, 0x86F90B0B, 0xBEE864A7, 0xF6DBD453, 0xCECABBFF, /* [4][0x80]*/ + 0x6EA2D55C, 0x56B3BAF0, 0x1E800A04, 0x269165A8, 0x8EE76BEC, 0xB6F60440, 0xFEC5B4B4, 0xC6D4DB18, /* [4][0x88]*/ + 0xABC5DECD, 0x93D4B161, 0xDBE70195, 0xE3F66E39, 0x4B80607D, 0x73910FD1, 0x3BA2BF25, 0x03B3D089, /* [4][0x90]*/ + 0xE180B48F, 0xD991DB23, 0x91A26BD7, 0xA9B3047B, 0x01C50A3F, 0x39D46593, 0x71E7D567, 0x49F6BACB, /* [4][0x98]*/ + 0x24E7BF1E, 0x1CF6D0B2, 0x54C56046, 0x6CD40FEA, 0xC4A201AE, 0xFCB36E02, 0xB480DEF6, 0x8C91B15A, /* [4][0xa0]*/ + 0x750A600B, 0x4D1B0FA7, 0x0528BF53, 0x3D39D0FF, 0x954FDEBB, 0xAD5EB117, 0xE56D01E3, 0xDD7C6E4F, /* [4][0xa8]*/ + 0xB06D6B9A, 0x887C0436, 0xC04FB4C2, 0xF85EDB6E, 0x5028D52A, 0x6839BA86, 0x200A0A72, 0x181B65DE, /* [4][0xb0]*/ + 0xFA2801D8, 0xC2396E74, 0x8A0ADE80, 0xB21BB12C, 0x1A6DBF68, 0x227CD0C4, 0x6A4F6030, 0x525E0F9C, /* [4][0xb8]*/ + 0x3F4F0A49, 0x075E65E5, 0x4F6DD511, 0x777CBABD, 0xDF0AB4F9, 0xE71BDB55, 0xAF286BA1, 0x9739040D, /* [4][0xc0]*/ + 0x59F3BFF2, 0x61E2D05E, 0x29D160AA, 0x11C00F06, 0xB9B60142, 0x81A76EEE, 0xC994DE1A, 0xF185B1B6, /* [4][0xc8]*/ + 0x9C94B463, 0xA485DBCF, 0xECB66B3B, 0xD4A70497, 0x7CD10AD3, 0x44C0657F, 0x0CF3D58B, 0x34E2BA27, /* [4][0xd0]*/ + 0xD6D1DE21, 0xEEC0B18D, 0xA6F30179, 0x9EE26ED5, 0x36946091, 0x0E850F3D, 0x46B6BFC9, 0x7EA7D065, /* [4][0xd8]*/ + 0x13B6D5B0, 0x2BA7BA1C, 0x63940AE8, 0x5B856544, 0xF3F36B00, 0xCBE204AC, 0x83D1B458, 0xBBC0DBF4, /* [4][0xe0]*/ + 0x425B0AA5, 0x7A4A6509, 0x3279D5FD, 0x0A68BA51, 0xA21EB415, 0x9A0FDBB9, 0xD23C6B4D, 0xEA2D04E1, /* [4][0xe8]*/ + 0x873C0134, 0xBF2D6E98, 0xF71EDE6C, 0xCF0FB1C0, 0x6779BF84, 0x5F68D028, 0x175B60DC, 0x2F4A0F70, /* [4][0xf0]*/ + 0xCD796B76, 0xF56804DA, 0xBD5BB42E, 0x854ADB82, 0x2D3CD5C6, 0x152DBA6A, 0x5D1E0A9E, 0x650F6532, /* [4][0xf8]*/ + 0x081E60E7, 0x300F0F4B, 0x783CBFBF, 0x402DD013, 0xE85BDE57, 0xD04AB1FB, 0x9879010F, 0xA0686EA3 /* [4][0x100]*/ + }, + { + 0x00000000, 0xEF306B19, 0xDB8CA0C3, 0x34BCCBDA, 0xB2F53777, 0x5DC55C6E, 0x697997B4, 0x8649FCAD, /* [5][0x08]*/ + 0x6006181F, 0x8F367306, 0xBB8AB8DC, 0x54BAD3C5, 0xD2F32F68, 0x3DC34471, 0x097F8FAB, 0xE64FE4B2, /* [5][0x10]*/ + 0xC00C303E, 0x2F3C5B27, 0x1B8090FD, 0xF4B0FBE4, 0x72F90749, 0x9DC96C50, 0xA975A78A, 0x4645CC93, /* [5][0x18]*/ + 0xA00A2821, 0x4F3A4338, 0x7B8688E2, 0x94B6E3FB, 0x12FF1F56, 0xFDCF744F, 0xC973BF95, 0x2643D48C, /* [5][0x20]*/ + 0x85F4168D, 0x6AC47D94, 0x5E78B64E, 0xB148DD57, 0x370121FA, 0xD8314AE3, 0xEC8D8139, 0x03BDEA20, /* [5][0x28]*/ + 0xE5F20E92, 0x0AC2658B, 0x3E7EAE51, 0xD14EC548, 0x570739E5, 0xB83752FC, 0x8C8B9926, 0x63BBF23F, /* [5][0x30]*/ + 0x45F826B3, 0xAAC84DAA, 0x9E748670, 0x7144ED69, 0xF70D11C4, 0x183D7ADD, 0x2C81B107, 0xC3B1DA1E, /* [5][0x38]*/ + 0x25FE3EAC, 0xCACE55B5, 0xFE729E6F, 0x1142F576, 0x970B09DB, 0x783B62C2, 0x4C87A918, 0xA3B7C201, /* [5][0x40]*/ + 0x0E045BEB, 0xE13430F2, 0xD588FB28, 0x3AB89031, 0xBCF16C9C, 0x53C10785, 0x677DCC5F, 0x884DA746, /* [5][0x48]*/ + 0x6E0243F4, 0x813228ED, 0xB58EE337, 0x5ABE882E, 0xDCF77483, 0x33C71F9A, 0x077BD440, 0xE84BBF59, /* [5][0x50]*/ + 0xCE086BD5, 0x213800CC, 0x1584CB16, 0xFAB4A00F, 0x7CFD5CA2, 0x93CD37BB, 0xA771FC61, 0x48419778, /* [5][0x58]*/ + 0xAE0E73CA, 0x413E18D3, 0x7582D309, 0x9AB2B810, 0x1CFB44BD, 0xF3CB2FA4, 0xC777E47E, 0x28478F67, /* [5][0x60]*/ + 0x8BF04D66, 0x64C0267F, 0x507CEDA5, 0xBF4C86BC, 0x39057A11, 0xD6351108, 0xE289DAD2, 0x0DB9B1CB, /* [5][0x68]*/ + 0xEBF65579, 0x04C63E60, 0x307AF5BA, 0xDF4A9EA3, 0x5903620E, 0xB6330917, 0x828FC2CD, 0x6DBFA9D4, /* [5][0x70]*/ + 0x4BFC7D58, 0xA4CC1641, 0x9070DD9B, 0x7F40B682, 0xF9094A2F, 0x16392136, 0x2285EAEC, 0xCDB581F5, /* [5][0x78]*/ + 0x2BFA6547, 0xC4CA0E5E, 0xF076C584, 0x1F46AE9D, 0x990F5230, 0x763F3929, 0x4283F2F3, 0xADB399EA, /* [5][0x80]*/ + 0x1C08B7D6, 0xF338DCCF, 0xC7841715, 0x28B47C0C, 0xAEFD80A1, 0x41CDEBB8, 0x75712062, 0x9A414B7B, /* [5][0x88]*/ + 0x7C0EAFC9, 0x933EC4D0, 0xA7820F0A, 0x48B26413, 0xCEFB98BE, 0x21CBF3A7, 0x1577387D, 0xFA475364, /* [5][0x90]*/ + 0xDC0487E8, 0x3334ECF1, 0x0788272B, 0xE8B84C32, 0x6EF1B09F, 0x81C1DB86, 0xB57D105C, 0x5A4D7B45, /* [5][0x98]*/ + 0xBC029FF7, 0x5332F4EE, 0x678E3F34, 0x88BE542D, 0x0EF7A880, 0xE1C7C399, 0xD57B0843, 0x3A4B635A, /* [5][0xa0]*/ + 0x99FCA15B, 0x76CCCA42, 0x42700198, 0xAD406A81, 0x2B09962C, 0xC439FD35, 0xF08536EF, 0x1FB55DF6, /* [5][0xa8]*/ + 0xF9FAB944, 0x16CAD25D, 0x22761987, 0xCD46729E, 0x4B0F8E33, 0xA43FE52A, 0x90832EF0, 0x7FB345E9, /* [5][0xb0]*/ + 0x59F09165, 0xB6C0FA7C, 0x827C31A6, 0x6D4C5ABF, 0xEB05A612, 0x0435CD0B, 0x308906D1, 0xDFB96DC8, /* [5][0xb8]*/ + 0x39F6897A, 0xD6C6E263, 0xE27A29B9, 0x0D4A42A0, 0x8B03BE0D, 0x6433D514, 0x508F1ECE, 0xBFBF75D7, /* [5][0xc0]*/ + 0x120CEC3D, 0xFD3C8724, 0xC9804CFE, 0x26B027E7, 0xA0F9DB4A, 0x4FC9B053, 0x7B757B89, 0x94451090, /* [5][0xc8]*/ + 0x720AF422, 0x9D3A9F3B, 0xA98654E1, 0x46B63FF8, 0xC0FFC355, 0x2FCFA84C, 0x1B736396, 0xF443088F, /* [5][0xd0]*/ + 0xD200DC03, 0x3D30B71A, 0x098C7CC0, 0xE6BC17D9, 0x60F5EB74, 0x8FC5806D, 0xBB794BB7, 0x544920AE, /* [5][0xd8]*/ + 0xB206C41C, 0x5D36AF05, 0x698A64DF, 0x86BA0FC6, 0x00F3F36B, 0xEFC39872, 0xDB7F53A8, 0x344F38B1, /* [5][0xe0]*/ + 0x97F8FAB0, 0x78C891A9, 0x4C745A73, 0xA344316A, 0x250DCDC7, 0xCA3DA6DE, 0xFE816D04, 0x11B1061D, /* [5][0xe8]*/ + 0xF7FEE2AF, 0x18CE89B6, 0x2C72426C, 0xC3422975, 0x450BD5D8, 0xAA3BBEC1, 0x9E87751B, 0x71B71E02, /* [5][0xf0]*/ + 0x57F4CA8E, 0xB8C4A197, 0x8C786A4D, 0x63480154, 0xE501FDF9, 0x0A3196E0, 0x3E8D5D3A, 0xD1BD3623, /* [5][0xf8]*/ + 0x37F2D291, 0xD8C2B988, 0xEC7E7252, 0x034E194B, 0x8507E5E6, 0x6A378EFF, 0x5E8B4525, 0xB1BB2E3C /* [5][0x100]*/ + }, + { + 0x00000000, 0x68032CC8, 0xD0065990, 0xB8057558, 0xA5E0C5D1, 0xCDE3E919, 0x75E69C41, 0x1DE5B089, /* [6][0x08]*/ + 0x4E2DFD53, 0x262ED19B, 0x9E2BA4C3, 0xF628880B, 0xEBCD3882, 0x83CE144A, 0x3BCB6112, 0x53C84DDA, /* [6][0x10]*/ + 0x9C5BFAA6, 0xF458D66E, 0x4C5DA336, 0x245E8FFE, 0x39BB3F77, 0x51B813BF, 0xE9BD66E7, 0x81BE4A2F, /* [6][0x18]*/ + 0xD27607F5, 0xBA752B3D, 0x02705E65, 0x6A7372AD, 0x7796C224, 0x1F95EEEC, 0xA7909BB4, 0xCF93B77C, /* [6][0x20]*/ + 0x3D5B83BD, 0x5558AF75, 0xED5DDA2D, 0x855EF6E5, 0x98BB466C, 0xF0B86AA4, 0x48BD1FFC, 0x20BE3334, /* [6][0x28]*/ + 0x73767EEE, 0x1B755226, 0xA370277E, 0xCB730BB6, 0xD696BB3F, 0xBE9597F7, 0x0690E2AF, 0x6E93CE67, /* [6][0x30]*/ + 0xA100791B, 0xC90355D3, 0x7106208B, 0x19050C43, 0x04E0BCCA, 0x6CE39002, 0xD4E6E55A, 0xBCE5C992, /* [6][0x38]*/ + 0xEF2D8448, 0x872EA880, 0x3F2BDDD8, 0x5728F110, 0x4ACD4199, 0x22CE6D51, 0x9ACB1809, 0xF2C834C1, /* [6][0x40]*/ + 0x7AB7077A, 0x12B42BB2, 0xAAB15EEA, 0xC2B27222, 0xDF57C2AB, 0xB754EE63, 0x0F519B3B, 0x6752B7F3, /* [6][0x48]*/ + 0x349AFA29, 0x5C99D6E1, 0xE49CA3B9, 0x8C9F8F71, 0x917A3FF8, 0xF9791330, 0x417C6668, 0x297F4AA0, /* [6][0x50]*/ + 0xE6ECFDDC, 0x8EEFD114, 0x36EAA44C, 0x5EE98884, 0x430C380D, 0x2B0F14C5, 0x930A619D, 0xFB094D55, /* [6][0x58]*/ + 0xA8C1008F, 0xC0C22C47, 0x78C7591F, 0x10C475D7, 0x0D21C55E, 0x6522E996, 0xDD279CCE, 0xB524B006, /* [6][0x60]*/ + 0x47EC84C7, 0x2FEFA80F, 0x97EADD57, 0xFFE9F19F, 0xE20C4116, 0x8A0F6DDE, 0x320A1886, 0x5A09344E, /* [6][0x68]*/ + 0x09C17994, 0x61C2555C, 0xD9C72004, 0xB1C40CCC, 0xAC21BC45, 0xC422908D, 0x7C27E5D5, 0x1424C91D, /* [6][0x70]*/ + 0xDBB77E61, 0xB3B452A9, 0x0BB127F1, 0x63B20B39, 0x7E57BBB0, 0x16549778, 0xAE51E220, 0xC652CEE8, /* [6][0x78]*/ + 0x959A8332, 0xFD99AFFA, 0x459CDAA2, 0x2D9FF66A, 0x307A46E3, 0x58796A2B, 0xE07C1F73, 0x887F33BB, /* [6][0x80]*/ + 0xF56E0EF4, 0x9D6D223C, 0x25685764, 0x4D6B7BAC, 0x508ECB25, 0x388DE7ED, 0x808892B5, 0xE88BBE7D, /* [6][0x88]*/ + 0xBB43F3A7, 0xD340DF6F, 0x6B45AA37, 0x034686FF, 0x1EA33676, 0x76A01ABE, 0xCEA56FE6, 0xA6A6432E, /* [6][0x90]*/ + 0x6935F452, 0x0136D89A, 0xB933ADC2, 0xD130810A, 0xCCD53183, 0xA4D61D4B, 0x1CD36813, 0x74D044DB, /* [6][0x98]*/ + 0x27180901, 0x4F1B25C9, 0xF71E5091, 0x9F1D7C59, 0x82F8CCD0, 0xEAFBE018, 0x52FE9540, 0x3AFDB988, /* [6][0xa0]*/ + 0xC8358D49, 0xA036A181, 0x1833D4D9, 0x7030F811, 0x6DD54898, 0x05D66450, 0xBDD31108, 0xD5D03DC0, /* [6][0xa8]*/ + 0x8618701A, 0xEE1B5CD2, 0x561E298A, 0x3E1D0542, 0x23F8B5CB, 0x4BFB9903, 0xF3FEEC5B, 0x9BFDC093, /* [6][0xb0]*/ + 0x546E77EF, 0x3C6D5B27, 0x84682E7F, 0xEC6B02B7, 0xF18EB23E, 0x998D9EF6, 0x2188EBAE, 0x498BC766, /* [6][0xb8]*/ + 0x1A438ABC, 0x7240A674, 0xCA45D32C, 0xA246FFE4, 0xBFA34F6D, 0xD7A063A5, 0x6FA516FD, 0x07A63A35, /* [6][0xc0]*/ + 0x8FD9098E, 0xE7DA2546, 0x5FDF501E, 0x37DC7CD6, 0x2A39CC5F, 0x423AE097, 0xFA3F95CF, 0x923CB907, /* [6][0xc8]*/ + 0xC1F4F4DD, 0xA9F7D815, 0x11F2AD4D, 0x79F18185, 0x6414310C, 0x0C171DC4, 0xB412689C, 0xDC114454, /* [6][0xd0]*/ + 0x1382F328, 0x7B81DFE0, 0xC384AAB8, 0xAB878670, 0xB66236F9, 0xDE611A31, 0x66646F69, 0x0E6743A1, /* [6][0xd8]*/ + 0x5DAF0E7B, 0x35AC22B3, 0x8DA957EB, 0xE5AA7B23, 0xF84FCBAA, 0x904CE762, 0x2849923A, 0x404ABEF2, /* [6][0xe0]*/ + 0xB2828A33, 0xDA81A6FB, 0x6284D3A3, 0x0A87FF6B, 0x17624FE2, 0x7F61632A, 0xC7641672, 0xAF673ABA, /* [6][0xe8]*/ + 0xFCAF7760, 0x94AC5BA8, 0x2CA92EF0, 0x44AA0238, 0x594FB2B1, 0x314C9E79, 0x8949EB21, 0xE14AC7E9, /* [6][0xf0]*/ + 0x2ED97095, 0x46DA5C5D, 0xFEDF2905, 0x96DC05CD, 0x8B39B544, 0xE33A998C, 0x5B3FECD4, 0x333CC01C, /* [6][0xf8]*/ + 0x60F48DC6, 0x08F7A10E, 0xB0F2D456, 0xD8F1F89E, 0xC5144817, 0xAD1764DF, 0x15121187, 0x7D113D4F /* [6][0x100]*/ + }, + { + 0x00000000, 0x493C7D27, 0x9278FA4E, 0xDB448769, 0x211D826D, 0x6821FF4A, 0xB3657823, 0xFA590504, /* [7][0x08]*/ + 0x423B04DA, 0x0B0779FD, 0xD043FE94, 0x997F83B3, 0x632686B7, 0x2A1AFB90, 0xF15E7CF9, 0xB86201DE, /* [7][0x10]*/ + 0x847609B4, 0xCD4A7493, 0x160EF3FA, 0x5F328EDD, 0xA56B8BD9, 0xEC57F6FE, 0x37137197, 0x7E2F0CB0, /* [7][0x18]*/ + 0xC64D0D6E, 0x8F717049, 0x5435F720, 0x1D098A07, 0xE7508F03, 0xAE6CF224, 0x7528754D, 0x3C14086A, /* [7][0x20]*/ + 0x0D006599, 0x443C18BE, 0x9F789FD7, 0xD644E2F0, 0x2C1DE7F4, 0x65219AD3, 0xBE651DBA, 0xF759609D, /* [7][0x28]*/ + 0x4F3B6143, 0x06071C64, 0xDD439B0D, 0x947FE62A, 0x6E26E32E, 0x271A9E09, 0xFC5E1960, 0xB5626447, /* [7][0x30]*/ + 0x89766C2D, 0xC04A110A, 0x1B0E9663, 0x5232EB44, 0xA86BEE40, 0xE1579367, 0x3A13140E, 0x732F6929, /* [7][0x38]*/ + 0xCB4D68F7, 0x827115D0, 0x593592B9, 0x1009EF9E, 0xEA50EA9A, 0xA36C97BD, 0x782810D4, 0x31146DF3, /* [7][0x40]*/ + 0x1A00CB32, 0x533CB615, 0x8878317C, 0xC1444C5B, 0x3B1D495F, 0x72213478, 0xA965B311, 0xE059CE36, /* [7][0x48]*/ + 0x583BCFE8, 0x1107B2CF, 0xCA4335A6, 0x837F4881, 0x79264D85, 0x301A30A2, 0xEB5EB7CB, 0xA262CAEC, /* [7][0x50]*/ + 0x9E76C286, 0xD74ABFA1, 0x0C0E38C8, 0x453245EF, 0xBF6B40EB, 0xF6573DCC, 0x2D13BAA5, 0x642FC782, /* [7][0x58]*/ + 0xDC4DC65C, 0x9571BB7B, 0x4E353C12, 0x07094135, 0xFD504431, 0xB46C3916, 0x6F28BE7F, 0x2614C358, /* [7][0x60]*/ + 0x1700AEAB, 0x5E3CD38C, 0x857854E5, 0xCC4429C2, 0x361D2CC6, 0x7F2151E1, 0xA465D688, 0xED59ABAF, /* [7][0x68]*/ + 0x553BAA71, 0x1C07D756, 0xC743503F, 0x8E7F2D18, 0x7426281C, 0x3D1A553B, 0xE65ED252, 0xAF62AF75, /* [7][0x70]*/ + 0x9376A71F, 0xDA4ADA38, 0x010E5D51, 0x48322076, 0xB26B2572, 0xFB575855, 0x2013DF3C, 0x692FA21B, /* [7][0x78]*/ + 0xD14DA3C5, 0x9871DEE2, 0x4335598B, 0x0A0924AC, 0xF05021A8, 0xB96C5C8F, 0x6228DBE6, 0x2B14A6C1, /* [7][0x80]*/ + 0x34019664, 0x7D3DEB43, 0xA6796C2A, 0xEF45110D, 0x151C1409, 0x5C20692E, 0x8764EE47, 0xCE589360, /* [7][0x88]*/ + 0x763A92BE, 0x3F06EF99, 0xE44268F0, 0xAD7E15D7, 0x572710D3, 0x1E1B6DF4, 0xC55FEA9D, 0x8C6397BA, /* [7][0x90]*/ + 0xB0779FD0, 0xF94BE2F7, 0x220F659E, 0x6B3318B9, 0x916A1DBD, 0xD856609A, 0x0312E7F3, 0x4A2E9AD4, /* [7][0x98]*/ + 0xF24C9B0A, 0xBB70E62D, 0x60346144, 0x29081C63, 0xD3511967, 0x9A6D6440, 0x4129E329, 0x08159E0E, /* [7][0xa0]*/ + 0x3901F3FD, 0x703D8EDA, 0xAB7909B3, 0xE2457494, 0x181C7190, 0x51200CB7, 0x8A648BDE, 0xC358F6F9, /* [7][0xa8]*/ + 0x7B3AF727, 0x32068A00, 0xE9420D69, 0xA07E704E, 0x5A27754A, 0x131B086D, 0xC85F8F04, 0x8163F223, /* [7][0xb0]*/ + 0xBD77FA49, 0xF44B876E, 0x2F0F0007, 0x66337D20, 0x9C6A7824, 0xD5560503, 0x0E12826A, 0x472EFF4D, /* [7][0xb8]*/ + 0xFF4CFE93, 0xB67083B4, 0x6D3404DD, 0x240879FA, 0xDE517CFE, 0x976D01D9, 0x4C2986B0, 0x0515FB97, /* [7][0xc0]*/ + 0x2E015D56, 0x673D2071, 0xBC79A718, 0xF545DA3F, 0x0F1CDF3B, 0x4620A21C, 0x9D642575, 0xD4585852, /* [7][0xc8]*/ + 0x6C3A598C, 0x250624AB, 0xFE42A3C2, 0xB77EDEE5, 0x4D27DBE1, 0x041BA6C6, 0xDF5F21AF, 0x96635C88, /* [7][0xd0]*/ + 0xAA7754E2, 0xE34B29C5, 0x380FAEAC, 0x7133D38B, 0x8B6AD68F, 0xC256ABA8, 0x19122CC1, 0x502E51E6, /* [7][0xd8]*/ + 0xE84C5038, 0xA1702D1F, 0x7A34AA76, 0x3308D751, 0xC951D255, 0x806DAF72, 0x5B29281B, 0x1215553C, /* [7][0xe0]*/ + 0x230138CF, 0x6A3D45E8, 0xB179C281, 0xF845BFA6, 0x021CBAA2, 0x4B20C785, 0x906440EC, 0xD9583DCB, /* [7][0xe8]*/ + 0x613A3C15, 0x28064132, 0xF342C65B, 0xBA7EBB7C, 0x4027BE78, 0x091BC35F, 0xD25F4436, 0x9B633911, /* [7][0xf0]*/ + 0xA777317B, 0xEE4B4C5C, 0x350FCB35, 0x7C33B612, 0x866AB316, 0xCF56CE31, 0x14124958, 0x5D2E347F, /* [7][0xf8]*/ + 0xE54C35A1, 0xAC704886, 0x7734CFEF, 0x3E08B2C8, 0xC451B7CC, 0x8D6DCAEB, 0x56294D82, 0x1F1530A5 /* [7][0x100]*/ + }, + { + 0x00000000, 0xF43ED648, 0xED91DA61, 0x19AF0C29, 0xDECFC233, 0x2AF1147B, 0x335E1852, 0xC760CE1A, /* [8][0x08]*/ + 0xB873F297, 0x4C4D24DF, 0x55E228F6, 0xA1DCFEBE, 0x66BC30A4, 0x9282E6EC, 0x8B2DEAC5, 0x7F133C8D, /* [8][0x10]*/ + 0x750B93DF, 0x81354597, 0x989A49BE, 0x6CA49FF6, 0xABC451EC, 0x5FFA87A4, 0x46558B8D, 0xB26B5DC5, /* [8][0x18]*/ + 0xCD786148, 0x3946B700, 0x20E9BB29, 0xD4D76D61, 0x13B7A37B, 0xE7897533, 0xFE26791A, 0x0A18AF52, /* [8][0x20]*/ + 0xEA1727BE, 0x1E29F1F6, 0x0786FDDF, 0xF3B82B97, 0x34D8E58D, 0xC0E633C5, 0xD9493FEC, 0x2D77E9A4, /* [8][0x28]*/ + 0x5264D529, 0xA65A0361, 0xBFF50F48, 0x4BCBD900, 0x8CAB171A, 0x7895C152, 0x613ACD7B, 0x95041B33, /* [8][0x30]*/ + 0x9F1CB461, 0x6B226229, 0x728D6E00, 0x86B3B848, 0x41D37652, 0xB5EDA01A, 0xAC42AC33, 0x587C7A7B, /* [8][0x38]*/ + 0x276F46F6, 0xD35190BE, 0xCAFE9C97, 0x3EC04ADF, 0xF9A084C5, 0x0D9E528D, 0x14315EA4, 0xE00F88EC, /* [8][0x40]*/ + 0xD1C2398D, 0x25FCEFC5, 0x3C53E3EC, 0xC86D35A4, 0x0F0DFBBE, 0xFB332DF6, 0xE29C21DF, 0x16A2F797, /* [8][0x48]*/ + 0x69B1CB1A, 0x9D8F1D52, 0x8420117B, 0x701EC733, 0xB77E0929, 0x4340DF61, 0x5AEFD348, 0xAED10500, /* [8][0x50]*/ + 0xA4C9AA52, 0x50F77C1A, 0x49587033, 0xBD66A67B, 0x7A066861, 0x8E38BE29, 0x9797B200, 0x63A96448, /* [8][0x58]*/ + 0x1CBA58C5, 0xE8848E8D, 0xF12B82A4, 0x051554EC, 0xC2759AF6, 0x364B4CBE, 0x2FE44097, 0xDBDA96DF, /* [8][0x60]*/ + 0x3BD51E33, 0xCFEBC87B, 0xD644C452, 0x227A121A, 0xE51ADC00, 0x11240A48, 0x088B0661, 0xFCB5D029, /* [8][0x68]*/ + 0x83A6ECA4, 0x77983AEC, 0x6E3736C5, 0x9A09E08D, 0x5D692E97, 0xA957F8DF, 0xB0F8F4F6, 0x44C622BE, /* [8][0x70]*/ + 0x4EDE8DEC, 0xBAE05BA4, 0xA34F578D, 0x577181C5, 0x90114FDF, 0x642F9997, 0x7D8095BE, 0x89BE43F6, /* [8][0x78]*/ + 0xF6AD7F7B, 0x0293A933, 0x1B3CA51A, 0xEF027352, 0x2862BD48, 0xDC5C6B00, 0xC5F36729, 0x31CDB161, /* [8][0x80]*/ + 0xA66805EB, 0x5256D3A3, 0x4BF9DF8A, 0xBFC709C2, 0x78A7C7D8, 0x8C991190, 0x95361DB9, 0x6108CBF1, /* [8][0x88]*/ + 0x1E1BF77C, 0xEA252134, 0xF38A2D1D, 0x07B4FB55, 0xC0D4354F, 0x34EAE307, 0x2D45EF2E, 0xD97B3966, /* [8][0x90]*/ + 0xD3639634, 0x275D407C, 0x3EF24C55, 0xCACC9A1D, 0x0DAC5407, 0xF992824F, 0xE03D8E66, 0x1403582E, /* [8][0x98]*/ + 0x6B1064A3, 0x9F2EB2EB, 0x8681BEC2, 0x72BF688A, 0xB5DFA690, 0x41E170D8, 0x584E7CF1, 0xAC70AAB9, /* [8][0xa0]*/ + 0x4C7F2255, 0xB841F41D, 0xA1EEF834, 0x55D02E7C, 0x92B0E066, 0x668E362E, 0x7F213A07, 0x8B1FEC4F, /* [8][0xa8]*/ + 0xF40CD0C2, 0x0032068A, 0x199D0AA3, 0xEDA3DCEB, 0x2AC312F1, 0xDEFDC4B9, 0xC752C890, 0x336C1ED8, /* [8][0xb0]*/ + 0x3974B18A, 0xCD4A67C2, 0xD4E56BEB, 0x20DBBDA3, 0xE7BB73B9, 0x1385A5F1, 0x0A2AA9D8, 0xFE147F90, /* [8][0xb8]*/ + 0x8107431D, 0x75399555, 0x6C96997C, 0x98A84F34, 0x5FC8812E, 0xABF65766, 0xB2595B4F, 0x46678D07, /* [8][0xc0]*/ + 0x77AA3C66, 0x8394EA2E, 0x9A3BE607, 0x6E05304F, 0xA965FE55, 0x5D5B281D, 0x44F42434, 0xB0CAF27C, /* [8][0xc8]*/ + 0xCFD9CEF1, 0x3BE718B9, 0x22481490, 0xD676C2D8, 0x11160CC2, 0xE528DA8A, 0xFC87D6A3, 0x08B900EB, /* [8][0xd0]*/ + 0x02A1AFB9, 0xF69F79F1, 0xEF3075D8, 0x1B0EA390, 0xDC6E6D8A, 0x2850BBC2, 0x31FFB7EB, 0xC5C161A3, /* [8][0xd8]*/ + 0xBAD25D2E, 0x4EEC8B66, 0x5743874F, 0xA37D5107, 0x641D9F1D, 0x90234955, 0x898C457C, 0x7DB29334, /* [8][0xe0]*/ + 0x9DBD1BD8, 0x6983CD90, 0x702CC1B9, 0x841217F1, 0x4372D9EB, 0xB74C0FA3, 0xAEE3038A, 0x5ADDD5C2, /* [8][0xe8]*/ + 0x25CEE94F, 0xD1F03F07, 0xC85F332E, 0x3C61E566, 0xFB012B7C, 0x0F3FFD34, 0x1690F11D, 0xE2AE2755, /* [8][0xf0]*/ + 0xE8B68807, 0x1C885E4F, 0x05275266, 0xF119842E, 0x36794A34, 0xC2479C7C, 0xDBE89055, 0x2FD6461D, /* [8][0xf8]*/ + 0x50C57A90, 0xA4FBACD8, 0xBD54A0F1, 0x496A76B9, 0x8E0AB8A3, 0x7A346EEB, 0x639B62C2, 0x97A5B48A /* [8][0x100]*/ + }, + { + 0x00000000, 0xCB567BA5, 0x934081BB, 0x5816FA1E, 0x236D7587, 0xE83B0E22, 0xB02DF43C, 0x7B7B8F99, /* [9][0x08]*/ + 0x46DAEB0E, 0x8D8C90AB, 0xD59A6AB5, 0x1ECC1110, 0x65B79E89, 0xAEE1E52C, 0xF6F71F32, 0x3DA16497, /* [9][0x10]*/ + 0x8DB5D61C, 0x46E3ADB9, 0x1EF557A7, 0xD5A32C02, 0xAED8A39B, 0x658ED83E, 0x3D982220, 0xF6CE5985, /* [9][0x18]*/ + 0xCB6F3D12, 0x003946B7, 0x582FBCA9, 0x9379C70C, 0xE8024895, 0x23543330, 0x7B42C92E, 0xB014B28B, /* [9][0x20]*/ + 0x1E87DAC9, 0xD5D1A16C, 0x8DC75B72, 0x469120D7, 0x3DEAAF4E, 0xF6BCD4EB, 0xAEAA2EF5, 0x65FC5550, /* [9][0x28]*/ + 0x585D31C7, 0x930B4A62, 0xCB1DB07C, 0x004BCBD9, 0x7B304440, 0xB0663FE5, 0xE870C5FB, 0x2326BE5E, /* [9][0x30]*/ + 0x93320CD5, 0x58647770, 0x00728D6E, 0xCB24F6CB, 0xB05F7952, 0x7B0902F7, 0x231FF8E9, 0xE849834C, /* [9][0x38]*/ + 0xD5E8E7DB, 0x1EBE9C7E, 0x46A86660, 0x8DFE1DC5, 0xF685925C, 0x3DD3E9F9, 0x65C513E7, 0xAE936842, /* [9][0x40]*/ + 0x3D0FB592, 0xF659CE37, 0xAE4F3429, 0x65194F8C, 0x1E62C015, 0xD534BBB0, 0x8D2241AE, 0x46743A0B, /* [9][0x48]*/ + 0x7BD55E9C, 0xB0832539, 0xE895DF27, 0x23C3A482, 0x58B82B1B, 0x93EE50BE, 0xCBF8AAA0, 0x00AED105, /* [9][0x50]*/ + 0xB0BA638E, 0x7BEC182B, 0x23FAE235, 0xE8AC9990, 0x93D71609, 0x58816DAC, 0x009797B2, 0xCBC1EC17, /* [9][0x58]*/ + 0xF6608880, 0x3D36F325, 0x6520093B, 0xAE76729E, 0xD50DFD07, 0x1E5B86A2, 0x464D7CBC, 0x8D1B0719, /* [9][0x60]*/ + 0x23886F5B, 0xE8DE14FE, 0xB0C8EEE0, 0x7B9E9545, 0x00E51ADC, 0xCBB36179, 0x93A59B67, 0x58F3E0C2, /* [9][0x68]*/ + 0x65528455, 0xAE04FFF0, 0xF61205EE, 0x3D447E4B, 0x463FF1D2, 0x8D698A77, 0xD57F7069, 0x1E290BCC, /* [9][0x70]*/ + 0xAE3DB947, 0x656BC2E2, 0x3D7D38FC, 0xF62B4359, 0x8D50CCC0, 0x4606B765, 0x1E104D7B, 0xD54636DE, /* [9][0x78]*/ + 0xE8E75249, 0x23B129EC, 0x7BA7D3F2, 0xB0F1A857, 0xCB8A27CE, 0x00DC5C6B, 0x58CAA675, 0x939CDDD0, /* [9][0x80]*/ + 0x7A1F6B24, 0xB1491081, 0xE95FEA9F, 0x2209913A, 0x59721EA3, 0x92246506, 0xCA329F18, 0x0164E4BD, /* [9][0x88]*/ + 0x3CC5802A, 0xF793FB8F, 0xAF850191, 0x64D37A34, 0x1FA8F5AD, 0xD4FE8E08, 0x8CE87416, 0x47BE0FB3, /* [9][0x90]*/ + 0xF7AABD38, 0x3CFCC69D, 0x64EA3C83, 0xAFBC4726, 0xD4C7C8BF, 0x1F91B31A, 0x47874904, 0x8CD132A1, /* [9][0x98]*/ + 0xB1705636, 0x7A262D93, 0x2230D78D, 0xE966AC28, 0x921D23B1, 0x594B5814, 0x015DA20A, 0xCA0BD9AF, /* [9][0xa0]*/ + 0x6498B1ED, 0xAFCECA48, 0xF7D83056, 0x3C8E4BF3, 0x47F5C46A, 0x8CA3BFCF, 0xD4B545D1, 0x1FE33E74, /* [9][0xa8]*/ + 0x22425AE3, 0xE9142146, 0xB102DB58, 0x7A54A0FD, 0x012F2F64, 0xCA7954C1, 0x926FAEDF, 0x5939D57A, /* [9][0xb0]*/ + 0xE92D67F1, 0x227B1C54, 0x7A6DE64A, 0xB13B9DEF, 0xCA401276, 0x011669D3, 0x590093CD, 0x9256E868, /* [9][0xb8]*/ + 0xAFF78CFF, 0x64A1F75A, 0x3CB70D44, 0xF7E176E1, 0x8C9AF978, 0x47CC82DD, 0x1FDA78C3, 0xD48C0366, /* [9][0xc0]*/ + 0x4710DEB6, 0x8C46A513, 0xD4505F0D, 0x1F0624A8, 0x647DAB31, 0xAF2BD094, 0xF73D2A8A, 0x3C6B512F, /* [9][0xc8]*/ + 0x01CA35B8, 0xCA9C4E1D, 0x928AB403, 0x59DCCFA6, 0x22A7403F, 0xE9F13B9A, 0xB1E7C184, 0x7AB1BA21, /* [9][0xd0]*/ + 0xCAA508AA, 0x01F3730F, 0x59E58911, 0x92B3F2B4, 0xE9C87D2D, 0x229E0688, 0x7A88FC96, 0xB1DE8733, /* [9][0xd8]*/ + 0x8C7FE3A4, 0x47299801, 0x1F3F621F, 0xD46919BA, 0xAF129623, 0x6444ED86, 0x3C521798, 0xF7046C3D, /* [9][0xe0]*/ + 0x5997047F, 0x92C17FDA, 0xCAD785C4, 0x0181FE61, 0x7AFA71F8, 0xB1AC0A5D, 0xE9BAF043, 0x22EC8BE6, /* [9][0xe8]*/ + 0x1F4DEF71, 0xD41B94D4, 0x8C0D6ECA, 0x475B156F, 0x3C209AF6, 0xF776E153, 0xAF601B4D, 0x643660E8, /* [9][0xf0]*/ + 0xD422D263, 0x1F74A9C6, 0x476253D8, 0x8C34287D, 0xF74FA7E4, 0x3C19DC41, 0x640F265F, 0xAF595DFA, /* [9][0xf8]*/ + 0x92F8396D, 0x59AE42C8, 0x01B8B8D6, 0xCAEEC373, 0xB1954CEA, 0x7AC3374F, 0x22D5CD51, 0xE983B6F4 /* [9][0x100]*/ + }, + { + 0x00000000, 0x9771F7C1, 0x2B0F9973, 0xBC7E6EB2, 0x561F32E6, 0xC16EC527, 0x7D10AB95, 0xEA615C54, /* [10][0x08]*/ + 0xAC3E65CC, 0x3B4F920D, 0x8731FCBF, 0x10400B7E, 0xFA21572A, 0x6D50A0EB, 0xD12ECE59, 0x465F3998, /* [10][0x10]*/ + 0x5D90BD69, 0xCAE14AA8, 0x769F241A, 0xE1EED3DB, 0x0B8F8F8F, 0x9CFE784E, 0x208016FC, 0xB7F1E13D, /* [10][0x18]*/ + 0xF1AED8A5, 0x66DF2F64, 0xDAA141D6, 0x4DD0B617, 0xA7B1EA43, 0x30C01D82, 0x8CBE7330, 0x1BCF84F1, /* [10][0x20]*/ + 0xBB217AD2, 0x2C508D13, 0x902EE3A1, 0x075F1460, 0xED3E4834, 0x7A4FBFF5, 0xC631D147, 0x51402686, /* [10][0x28]*/ + 0x171F1F1E, 0x806EE8DF, 0x3C10866D, 0xAB6171AC, 0x41002DF8, 0xD671DA39, 0x6A0FB48B, 0xFD7E434A, /* [10][0x30]*/ + 0xE6B1C7BB, 0x71C0307A, 0xCDBE5EC8, 0x5ACFA909, 0xB0AEF55D, 0x27DF029C, 0x9BA16C2E, 0x0CD09BEF, /* [10][0x38]*/ + 0x4A8FA277, 0xDDFE55B6, 0x61803B04, 0xF6F1CCC5, 0x1C909091, 0x8BE16750, 0x379F09E2, 0xA0EEFE23, /* [10][0x40]*/ + 0x73AE8355, 0xE4DF7494, 0x58A11A26, 0xCFD0EDE7, 0x25B1B1B3, 0xB2C04672, 0x0EBE28C0, 0x99CFDF01, /* [10][0x48]*/ + 0xDF90E699, 0x48E11158, 0xF49F7FEA, 0x63EE882B, 0x898FD47F, 0x1EFE23BE, 0xA2804D0C, 0x35F1BACD, /* [10][0x50]*/ + 0x2E3E3E3C, 0xB94FC9FD, 0x0531A74F, 0x9240508E, 0x78210CDA, 0xEF50FB1B, 0x532E95A9, 0xC45F6268, /* [10][0x58]*/ + 0x82005BF0, 0x1571AC31, 0xA90FC283, 0x3E7E3542, 0xD41F6916, 0x436E9ED7, 0xFF10F065, 0x686107A4, /* [10][0x60]*/ + 0xC88FF987, 0x5FFE0E46, 0xE38060F4, 0x74F19735, 0x9E90CB61, 0x09E13CA0, 0xB59F5212, 0x22EEA5D3, /* [10][0x68]*/ + 0x64B19C4B, 0xF3C06B8A, 0x4FBE0538, 0xD8CFF2F9, 0x32AEAEAD, 0xA5DF596C, 0x19A137DE, 0x8ED0C01F, /* [10][0x70]*/ + 0x951F44EE, 0x026EB32F, 0xBE10DD9D, 0x29612A5C, 0xC3007608, 0x547181C9, 0xE80FEF7B, 0x7F7E18BA, /* [10][0x78]*/ + 0x39212122, 0xAE50D6E3, 0x122EB851, 0x855F4F90, 0x6F3E13C4, 0xF84FE405, 0x44318AB7, 0xD3407D76, /* [10][0x80]*/ + 0xE75D06AA, 0x702CF16B, 0xCC529FD9, 0x5B236818, 0xB142344C, 0x2633C38D, 0x9A4DAD3F, 0x0D3C5AFE, /* [10][0x88]*/ + 0x4B636366, 0xDC1294A7, 0x606CFA15, 0xF71D0DD4, 0x1D7C5180, 0x8A0DA641, 0x3673C8F3, 0xA1023F32, /* [10][0x90]*/ + 0xBACDBBC3, 0x2DBC4C02, 0x91C222B0, 0x06B3D571, 0xECD28925, 0x7BA37EE4, 0xC7DD1056, 0x50ACE797, /* [10][0x98]*/ + 0x16F3DE0F, 0x818229CE, 0x3DFC477C, 0xAA8DB0BD, 0x40ECECE9, 0xD79D1B28, 0x6BE3759A, 0xFC92825B, /* [10][0xa0]*/ + 0x5C7C7C78, 0xCB0D8BB9, 0x7773E50B, 0xE00212CA, 0x0A634E9E, 0x9D12B95F, 0x216CD7ED, 0xB61D202C, /* [10][0xa8]*/ + 0xF04219B4, 0x6733EE75, 0xDB4D80C7, 0x4C3C7706, 0xA65D2B52, 0x312CDC93, 0x8D52B221, 0x1A2345E0, /* [10][0xb0]*/ + 0x01ECC111, 0x969D36D0, 0x2AE35862, 0xBD92AFA3, 0x57F3F3F7, 0xC0820436, 0x7CFC6A84, 0xEB8D9D45, /* [10][0xb8]*/ + 0xADD2A4DD, 0x3AA3531C, 0x86DD3DAE, 0x11ACCA6F, 0xFBCD963B, 0x6CBC61FA, 0xD0C20F48, 0x47B3F889, /* [10][0xc0]*/ + 0x94F385FF, 0x0382723E, 0xBFFC1C8C, 0x288DEB4D, 0xC2ECB719, 0x559D40D8, 0xE9E32E6A, 0x7E92D9AB, /* [10][0xc8]*/ + 0x38CDE033, 0xAFBC17F2, 0x13C27940, 0x84B38E81, 0x6ED2D2D5, 0xF9A32514, 0x45DD4BA6, 0xD2ACBC67, /* [10][0xd0]*/ + 0xC9633896, 0x5E12CF57, 0xE26CA1E5, 0x751D5624, 0x9F7C0A70, 0x080DFDB1, 0xB4739303, 0x230264C2, /* [10][0xd8]*/ + 0x655D5D5A, 0xF22CAA9B, 0x4E52C429, 0xD92333E8, 0x33426FBC, 0xA433987D, 0x184DF6CF, 0x8F3C010E, /* [10][0xe0]*/ + 0x2FD2FF2D, 0xB8A308EC, 0x04DD665E, 0x93AC919F, 0x79CDCDCB, 0xEEBC3A0A, 0x52C254B8, 0xC5B3A379, /* [10][0xe8]*/ + 0x83EC9AE1, 0x149D6D20, 0xA8E30392, 0x3F92F453, 0xD5F3A807, 0x42825FC6, 0xFEFC3174, 0x698DC6B5, /* [10][0xf0]*/ + 0x72424244, 0xE533B585, 0x594DDB37, 0xCE3C2CF6, 0x245D70A2, 0xB32C8763, 0x0F52E9D1, 0x98231E10, /* [10][0xf8]*/ + 0xDE7C2788, 0x490DD049, 0xF573BEFB, 0x6202493A, 0x8863156E, 0x1F12E2AF, 0xA36C8C1D, 0x341D7BDC /* [10][0x100]*/ + }, + { + 0x00000000, 0x3171D430, 0x62E3A860, 0x53927C50, 0xC5C750C0, 0xF4B684F0, 0xA724F8A0, 0x96552C90, /* [11][0x08]*/ + 0x8E62D771, 0xBF130341, 0xEC817F11, 0xDDF0AB21, 0x4BA587B1, 0x7AD45381, 0x29462FD1, 0x1837FBE1, /* [11][0x10]*/ + 0x1929D813, 0x28580C23, 0x7BCA7073, 0x4ABBA443, 0xDCEE88D3, 0xED9F5CE3, 0xBE0D20B3, 0x8F7CF483, /* [11][0x18]*/ + 0x974B0F62, 0xA63ADB52, 0xF5A8A702, 0xC4D97332, 0x528C5FA2, 0x63FD8B92, 0x306FF7C2, 0x011E23F2, /* [11][0x20]*/ + 0x3253B026, 0x03226416, 0x50B01846, 0x61C1CC76, 0xF794E0E6, 0xC6E534D6, 0x95774886, 0xA4069CB6, /* [11][0x28]*/ + 0xBC316757, 0x8D40B367, 0xDED2CF37, 0xEFA31B07, 0x79F63797, 0x4887E3A7, 0x1B159FF7, 0x2A644BC7, /* [11][0x30]*/ + 0x2B7A6835, 0x1A0BBC05, 0x4999C055, 0x78E81465, 0xEEBD38F5, 0xDFCCECC5, 0x8C5E9095, 0xBD2F44A5, /* [11][0x38]*/ + 0xA518BF44, 0x94696B74, 0xC7FB1724, 0xF68AC314, 0x60DFEF84, 0x51AE3BB4, 0x023C47E4, 0x334D93D4, /* [11][0x40]*/ + 0x64A7604C, 0x55D6B47C, 0x0644C82C, 0x37351C1C, 0xA160308C, 0x9011E4BC, 0xC38398EC, 0xF2F24CDC, /* [11][0x48]*/ + 0xEAC5B73D, 0xDBB4630D, 0x88261F5D, 0xB957CB6D, 0x2F02E7FD, 0x1E7333CD, 0x4DE14F9D, 0x7C909BAD, /* [11][0x50]*/ + 0x7D8EB85F, 0x4CFF6C6F, 0x1F6D103F, 0x2E1CC40F, 0xB849E89F, 0x89383CAF, 0xDAAA40FF, 0xEBDB94CF, /* [11][0x58]*/ + 0xF3EC6F2E, 0xC29DBB1E, 0x910FC74E, 0xA07E137E, 0x362B3FEE, 0x075AEBDE, 0x54C8978E, 0x65B943BE, /* [11][0x60]*/ + 0x56F4D06A, 0x6785045A, 0x3417780A, 0x0566AC3A, 0x933380AA, 0xA242549A, 0xF1D028CA, 0xC0A1FCFA, /* [11][0x68]*/ + 0xD896071B, 0xE9E7D32B, 0xBA75AF7B, 0x8B047B4B, 0x1D5157DB, 0x2C2083EB, 0x7FB2FFBB, 0x4EC32B8B, /* [11][0x70]*/ + 0x4FDD0879, 0x7EACDC49, 0x2D3EA019, 0x1C4F7429, 0x8A1A58B9, 0xBB6B8C89, 0xE8F9F0D9, 0xD98824E9, /* [11][0x78]*/ + 0xC1BFDF08, 0xF0CE0B38, 0xA35C7768, 0x922DA358, 0x04788FC8, 0x35095BF8, 0x669B27A8, 0x57EAF398, /* [11][0x80]*/ + 0xC94EC098, 0xF83F14A8, 0xABAD68F8, 0x9ADCBCC8, 0x0C899058, 0x3DF84468, 0x6E6A3838, 0x5F1BEC08, /* [11][0x88]*/ + 0x472C17E9, 0x765DC3D9, 0x25CFBF89, 0x14BE6BB9, 0x82EB4729, 0xB39A9319, 0xE008EF49, 0xD1793B79, /* [11][0x90]*/ + 0xD067188B, 0xE116CCBB, 0xB284B0EB, 0x83F564DB, 0x15A0484B, 0x24D19C7B, 0x7743E02B, 0x4632341B, /* [11][0x98]*/ + 0x5E05CFFA, 0x6F741BCA, 0x3CE6679A, 0x0D97B3AA, 0x9BC29F3A, 0xAAB34B0A, 0xF921375A, 0xC850E36A, /* [11][0xa0]*/ + 0xFB1D70BE, 0xCA6CA48E, 0x99FED8DE, 0xA88F0CEE, 0x3EDA207E, 0x0FABF44E, 0x5C39881E, 0x6D485C2E, /* [11][0xa8]*/ + 0x757FA7CF, 0x440E73FF, 0x179C0FAF, 0x26EDDB9F, 0xB0B8F70F, 0x81C9233F, 0xD25B5F6F, 0xE32A8B5F, /* [11][0xb0]*/ + 0xE234A8AD, 0xD3457C9D, 0x80D700CD, 0xB1A6D4FD, 0x27F3F86D, 0x16822C5D, 0x4510500D, 0x7461843D, /* [11][0xb8]*/ + 0x6C567FDC, 0x5D27ABEC, 0x0EB5D7BC, 0x3FC4038C, 0xA9912F1C, 0x98E0FB2C, 0xCB72877C, 0xFA03534C, /* [11][0xc0]*/ + 0xADE9A0D4, 0x9C9874E4, 0xCF0A08B4, 0xFE7BDC84, 0x682EF014, 0x595F2424, 0x0ACD5874, 0x3BBC8C44, /* [11][0xc8]*/ + 0x238B77A5, 0x12FAA395, 0x4168DFC5, 0x70190BF5, 0xE64C2765, 0xD73DF355, 0x84AF8F05, 0xB5DE5B35, /* [11][0xd0]*/ + 0xB4C078C7, 0x85B1ACF7, 0xD623D0A7, 0xE7520497, 0x71072807, 0x4076FC37, 0x13E48067, 0x22955457, /* [11][0xd8]*/ + 0x3AA2AFB6, 0x0BD37B86, 0x584107D6, 0x6930D3E6, 0xFF65FF76, 0xCE142B46, 0x9D865716, 0xACF78326, /* [11][0xe0]*/ + 0x9FBA10F2, 0xAECBC4C2, 0xFD59B892, 0xCC286CA2, 0x5A7D4032, 0x6B0C9402, 0x389EE852, 0x09EF3C62, /* [11][0xe8]*/ + 0x11D8C783, 0x20A913B3, 0x733B6FE3, 0x424ABBD3, 0xD41F9743, 0xE56E4373, 0xB6FC3F23, 0x878DEB13, /* [11][0xf0]*/ + 0x8693C8E1, 0xB7E21CD1, 0xE4706081, 0xD501B4B1, 0x43549821, 0x72254C11, 0x21B73041, 0x10C6E471, /* [11][0xf8]*/ + 0x08F11F90, 0x3980CBA0, 0x6A12B7F0, 0x5B6363C0, 0xCD364F50, 0xFC479B60, 0xAFD5E730, 0x9EA43300 /* [11][0x100]*/ + }, + { + 0x00000000, 0x30D23865, 0x61A470CA, 0x517648AF, 0xC348E194, 0xF39AD9F1, 0xA2EC915E, 0x923EA93B, /* [12][0x08]*/ + 0x837DB5D9, 0xB3AF8DBC, 0xE2D9C513, 0xD20BFD76, 0x4035544D, 0x70E76C28, 0x21912487, 0x11431CE2, /* [12][0x10]*/ + 0x03171D43, 0x33C52526, 0x62B36D89, 0x526155EC, 0xC05FFCD7, 0xF08DC4B2, 0xA1FB8C1D, 0x9129B478, /* [12][0x18]*/ + 0x806AA89A, 0xB0B890FF, 0xE1CED850, 0xD11CE035, 0x4322490E, 0x73F0716B, 0x228639C4, 0x125401A1, /* [12][0x20]*/ + 0x062E3A86, 0x36FC02E3, 0x678A4A4C, 0x57587229, 0xC566DB12, 0xF5B4E377, 0xA4C2ABD8, 0x941093BD, /* [12][0x28]*/ + 0x85538F5F, 0xB581B73A, 0xE4F7FF95, 0xD425C7F0, 0x461B6ECB, 0x76C956AE, 0x27BF1E01, 0x176D2664, /* [12][0x30]*/ + 0x053927C5, 0x35EB1FA0, 0x649D570F, 0x544F6F6A, 0xC671C651, 0xF6A3FE34, 0xA7D5B69B, 0x97078EFE, /* [12][0x38]*/ + 0x8644921C, 0xB696AA79, 0xE7E0E2D6, 0xD732DAB3, 0x450C7388, 0x75DE4BED, 0x24A80342, 0x147A3B27, /* [12][0x40]*/ + 0x0C5C750C, 0x3C8E4D69, 0x6DF805C6, 0x5D2A3DA3, 0xCF149498, 0xFFC6ACFD, 0xAEB0E452, 0x9E62DC37, /* [12][0x48]*/ + 0x8F21C0D5, 0xBFF3F8B0, 0xEE85B01F, 0xDE57887A, 0x4C692141, 0x7CBB1924, 0x2DCD518B, 0x1D1F69EE, /* [12][0x50]*/ + 0x0F4B684F, 0x3F99502A, 0x6EEF1885, 0x5E3D20E0, 0xCC0389DB, 0xFCD1B1BE, 0xADA7F911, 0x9D75C174, /* [12][0x58]*/ + 0x8C36DD96, 0xBCE4E5F3, 0xED92AD5C, 0xDD409539, 0x4F7E3C02, 0x7FAC0467, 0x2EDA4CC8, 0x1E0874AD, /* [12][0x60]*/ + 0x0A724F8A, 0x3AA077EF, 0x6BD63F40, 0x5B040725, 0xC93AAE1E, 0xF9E8967B, 0xA89EDED4, 0x984CE6B1, /* [12][0x68]*/ + 0x890FFA53, 0xB9DDC236, 0xE8AB8A99, 0xD879B2FC, 0x4A471BC7, 0x7A9523A2, 0x2BE36B0D, 0x1B315368, /* [12][0x70]*/ + 0x096552C9, 0x39B76AAC, 0x68C12203, 0x58131A66, 0xCA2DB35D, 0xFAFF8B38, 0xAB89C397, 0x9B5BFBF2, /* [12][0x78]*/ + 0x8A18E710, 0xBACADF75, 0xEBBC97DA, 0xDB6EAFBF, 0x49500684, 0x79823EE1, 0x28F4764E, 0x18264E2B, /* [12][0x80]*/ + 0x18B8EA18, 0x286AD27D, 0x791C9AD2, 0x49CEA2B7, 0xDBF00B8C, 0xEB2233E9, 0xBA547B46, 0x8A864323, /* [12][0x88]*/ + 0x9BC55FC1, 0xAB1767A4, 0xFA612F0B, 0xCAB3176E, 0x588DBE55, 0x685F8630, 0x3929CE9F, 0x09FBF6FA, /* [12][0x90]*/ + 0x1BAFF75B, 0x2B7DCF3E, 0x7A0B8791, 0x4AD9BFF4, 0xD8E716CF, 0xE8352EAA, 0xB9436605, 0x89915E60, /* [12][0x98]*/ + 0x98D24282, 0xA8007AE7, 0xF9763248, 0xC9A40A2D, 0x5B9AA316, 0x6B489B73, 0x3A3ED3DC, 0x0AECEBB9, /* [12][0xa0]*/ + 0x1E96D09E, 0x2E44E8FB, 0x7F32A054, 0x4FE09831, 0xDDDE310A, 0xED0C096F, 0xBC7A41C0, 0x8CA879A5, /* [12][0xa8]*/ + 0x9DEB6547, 0xAD395D22, 0xFC4F158D, 0xCC9D2DE8, 0x5EA384D3, 0x6E71BCB6, 0x3F07F419, 0x0FD5CC7C, /* [12][0xb0]*/ + 0x1D81CDDD, 0x2D53F5B8, 0x7C25BD17, 0x4CF78572, 0xDEC92C49, 0xEE1B142C, 0xBF6D5C83, 0x8FBF64E6, /* [12][0xb8]*/ + 0x9EFC7804, 0xAE2E4061, 0xFF5808CE, 0xCF8A30AB, 0x5DB49990, 0x6D66A1F5, 0x3C10E95A, 0x0CC2D13F, /* [12][0xc0]*/ + 0x14E49F14, 0x2436A771, 0x7540EFDE, 0x4592D7BB, 0xD7AC7E80, 0xE77E46E5, 0xB6080E4A, 0x86DA362F, /* [12][0xc8]*/ + 0x97992ACD, 0xA74B12A8, 0xF63D5A07, 0xC6EF6262, 0x54D1CB59, 0x6403F33C, 0x3575BB93, 0x05A783F6, /* [12][0xd0]*/ + 0x17F38257, 0x2721BA32, 0x7657F29D, 0x4685CAF8, 0xD4BB63C3, 0xE4695BA6, 0xB51F1309, 0x85CD2B6C, /* [12][0xd8]*/ + 0x948E378E, 0xA45C0FEB, 0xF52A4744, 0xC5F87F21, 0x57C6D61A, 0x6714EE7F, 0x3662A6D0, 0x06B09EB5, /* [12][0xe0]*/ + 0x12CAA592, 0x22189DF7, 0x736ED558, 0x43BCED3D, 0xD1824406, 0xE1507C63, 0xB02634CC, 0x80F40CA9, /* [12][0xe8]*/ + 0x91B7104B, 0xA165282E, 0xF0136081, 0xC0C158E4, 0x52FFF1DF, 0x622DC9BA, 0x335B8115, 0x0389B970, /* [12][0xf0]*/ + 0x11DDB8D1, 0x210F80B4, 0x7079C81B, 0x40ABF07E, 0xD2955945, 0xE2476120, 0xB331298F, 0x83E311EA, /* [12][0xf8]*/ + 0x92A00D08, 0xA272356D, 0xF3047DC2, 0xC3D645A7, 0x51E8EC9C, 0x613AD4F9, 0x304C9C56, 0x009EA433 /* [12][0x100]*/ + }, + { + 0x00000000, 0x54075546, 0xA80EAA8C, 0xFC09FFCA, 0x55F123E9, 0x01F676AF, 0xFDFF8965, 0xA9F8DC23, /* [13][0x08]*/ + 0xABE247D2, 0xFFE51294, 0x03ECED5E, 0x57EBB818, 0xFE13643B, 0xAA14317D, 0x561DCEB7, 0x021A9BF1, /* [13][0x10]*/ + 0x5228F955, 0x062FAC13, 0xFA2653D9, 0xAE21069F, 0x07D9DABC, 0x53DE8FFA, 0xAFD77030, 0xFBD02576, /* [13][0x18]*/ + 0xF9CABE87, 0xADCDEBC1, 0x51C4140B, 0x05C3414D, 0xAC3B9D6E, 0xF83CC828, 0x043537E2, 0x503262A4, /* [13][0x20]*/ + 0xA451F2AA, 0xF056A7EC, 0x0C5F5826, 0x58580D60, 0xF1A0D143, 0xA5A78405, 0x59AE7BCF, 0x0DA92E89, /* [13][0x28]*/ + 0x0FB3B578, 0x5BB4E03E, 0xA7BD1FF4, 0xF3BA4AB2, 0x5A429691, 0x0E45C3D7, 0xF24C3C1D, 0xA64B695B, /* [13][0x30]*/ + 0xF6790BFF, 0xA27E5EB9, 0x5E77A173, 0x0A70F435, 0xA3882816, 0xF78F7D50, 0x0B86829A, 0x5F81D7DC, /* [13][0x38]*/ + 0x5D9B4C2D, 0x099C196B, 0xF595E6A1, 0xA192B3E7, 0x086A6FC4, 0x5C6D3A82, 0xA064C548, 0xF463900E, /* [13][0x40]*/ + 0x4D4F93A5, 0x1948C6E3, 0xE5413929, 0xB1466C6F, 0x18BEB04C, 0x4CB9E50A, 0xB0B01AC0, 0xE4B74F86, /* [13][0x48]*/ + 0xE6ADD477, 0xB2AA8131, 0x4EA37EFB, 0x1AA42BBD, 0xB35CF79E, 0xE75BA2D8, 0x1B525D12, 0x4F550854, /* [13][0x50]*/ + 0x1F676AF0, 0x4B603FB6, 0xB769C07C, 0xE36E953A, 0x4A964919, 0x1E911C5F, 0xE298E395, 0xB69FB6D3, /* [13][0x58]*/ + 0xB4852D22, 0xE0827864, 0x1C8B87AE, 0x488CD2E8, 0xE1740ECB, 0xB5735B8D, 0x497AA447, 0x1D7DF101, /* [13][0x60]*/ + 0xE91E610F, 0xBD193449, 0x4110CB83, 0x15179EC5, 0xBCEF42E6, 0xE8E817A0, 0x14E1E86A, 0x40E6BD2C, /* [13][0x68]*/ + 0x42FC26DD, 0x16FB739B, 0xEAF28C51, 0xBEF5D917, 0x170D0534, 0x430A5072, 0xBF03AFB8, 0xEB04FAFE, /* [13][0x70]*/ + 0xBB36985A, 0xEF31CD1C, 0x133832D6, 0x473F6790, 0xEEC7BBB3, 0xBAC0EEF5, 0x46C9113F, 0x12CE4479, /* [13][0x78]*/ + 0x10D4DF88, 0x44D38ACE, 0xB8DA7504, 0xECDD2042, 0x4525FC61, 0x1122A927, 0xED2B56ED, 0xB92C03AB, /* [13][0x80]*/ + 0x9A9F274A, 0xCE98720C, 0x32918DC6, 0x6696D880, 0xCF6E04A3, 0x9B6951E5, 0x6760AE2F, 0x3367FB69, /* [13][0x88]*/ + 0x317D6098, 0x657A35DE, 0x9973CA14, 0xCD749F52, 0x648C4371, 0x308B1637, 0xCC82E9FD, 0x9885BCBB, /* [13][0x90]*/ + 0xC8B7DE1F, 0x9CB08B59, 0x60B97493, 0x34BE21D5, 0x9D46FDF6, 0xC941A8B0, 0x3548577A, 0x614F023C, /* [13][0x98]*/ + 0x635599CD, 0x3752CC8B, 0xCB5B3341, 0x9F5C6607, 0x36A4BA24, 0x62A3EF62, 0x9EAA10A8, 0xCAAD45EE, /* [13][0xa0]*/ + 0x3ECED5E0, 0x6AC980A6, 0x96C07F6C, 0xC2C72A2A, 0x6B3FF609, 0x3F38A34F, 0xC3315C85, 0x973609C3, /* [13][0xa8]*/ + 0x952C9232, 0xC12BC774, 0x3D2238BE, 0x69256DF8, 0xC0DDB1DB, 0x94DAE49D, 0x68D31B57, 0x3CD44E11, /* [13][0xb0]*/ + 0x6CE62CB5, 0x38E179F3, 0xC4E88639, 0x90EFD37F, 0x39170F5C, 0x6D105A1A, 0x9119A5D0, 0xC51EF096, /* [13][0xb8]*/ + 0xC7046B67, 0x93033E21, 0x6F0AC1EB, 0x3B0D94AD, 0x92F5488E, 0xC6F21DC8, 0x3AFBE202, 0x6EFCB744, /* [13][0xc0]*/ + 0xD7D0B4EF, 0x83D7E1A9, 0x7FDE1E63, 0x2BD94B25, 0x82219706, 0xD626C240, 0x2A2F3D8A, 0x7E2868CC, /* [13][0xc8]*/ + 0x7C32F33D, 0x2835A67B, 0xD43C59B1, 0x803B0CF7, 0x29C3D0D4, 0x7DC48592, 0x81CD7A58, 0xD5CA2F1E, /* [13][0xd0]*/ + 0x85F84DBA, 0xD1FF18FC, 0x2DF6E736, 0x79F1B270, 0xD0096E53, 0x840E3B15, 0x7807C4DF, 0x2C009199, /* [13][0xd8]*/ + 0x2E1A0A68, 0x7A1D5F2E, 0x8614A0E4, 0xD213F5A2, 0x7BEB2981, 0x2FEC7CC7, 0xD3E5830D, 0x87E2D64B, /* [13][0xe0]*/ + 0x73814645, 0x27861303, 0xDB8FECC9, 0x8F88B98F, 0x267065AC, 0x727730EA, 0x8E7ECF20, 0xDA799A66, /* [13][0xe8]*/ + 0xD8630197, 0x8C6454D1, 0x706DAB1B, 0x246AFE5D, 0x8D92227E, 0xD9957738, 0x259C88F2, 0x719BDDB4, /* [13][0xf0]*/ + 0x21A9BF10, 0x75AEEA56, 0x89A7159C, 0xDDA040DA, 0x74589CF9, 0x205FC9BF, 0xDC563675, 0x88516333, /* [13][0xf8]*/ + 0x8A4BF8C2, 0xDE4CAD84, 0x2245524E, 0x76420708, 0xDFBADB2B, 0x8BBD8E6D, 0x77B471A7, 0x23B324E1 /* [13][0x100]*/ + }, + { + 0x00000000, 0x678EFD01, 0xCF1DFA02, 0xA8930703, 0x9BD782F5, 0xFC597FF4, 0x54CA78F7, 0x334485F6, /* [14][0x08]*/ + 0x3243731B, 0x55CD8E1A, 0xFD5E8919, 0x9AD07418, 0xA994F1EE, 0xCE1A0CEF, 0x66890BEC, 0x0107F6ED, /* [14][0x10]*/ + 0x6486E636, 0x03081B37, 0xAB9B1C34, 0xCC15E135, 0xFF5164C3, 0x98DF99C2, 0x304C9EC1, 0x57C263C0, /* [14][0x18]*/ + 0x56C5952D, 0x314B682C, 0x99D86F2F, 0xFE56922E, 0xCD1217D8, 0xAA9CEAD9, 0x020FEDDA, 0x658110DB, /* [14][0x20]*/ + 0xC90DCC6C, 0xAE83316D, 0x0610366E, 0x619ECB6F, 0x52DA4E99, 0x3554B398, 0x9DC7B49B, 0xFA49499A, /* [14][0x28]*/ + 0xFB4EBF77, 0x9CC04276, 0x34534575, 0x53DDB874, 0x60993D82, 0x0717C083, 0xAF84C780, 0xC80A3A81, /* [14][0x30]*/ + 0xAD8B2A5A, 0xCA05D75B, 0x6296D058, 0x05182D59, 0x365CA8AF, 0x51D255AE, 0xF94152AD, 0x9ECFAFAC, /* [14][0x38]*/ + 0x9FC85941, 0xF846A440, 0x50D5A343, 0x375B5E42, 0x041FDBB4, 0x639126B5, 0xCB0221B6, 0xAC8CDCB7, /* [14][0x40]*/ + 0x97F7EE29, 0xF0791328, 0x58EA142B, 0x3F64E92A, 0x0C206CDC, 0x6BAE91DD, 0xC33D96DE, 0xA4B36BDF, /* [14][0x48]*/ + 0xA5B49D32, 0xC23A6033, 0x6AA96730, 0x0D279A31, 0x3E631FC7, 0x59EDE2C6, 0xF17EE5C5, 0x96F018C4, /* [14][0x50]*/ + 0xF371081F, 0x94FFF51E, 0x3C6CF21D, 0x5BE20F1C, 0x68A68AEA, 0x0F2877EB, 0xA7BB70E8, 0xC0358DE9, /* [14][0x58]*/ + 0xC1327B04, 0xA6BC8605, 0x0E2F8106, 0x69A17C07, 0x5AE5F9F1, 0x3D6B04F0, 0x95F803F3, 0xF276FEF2, /* [14][0x60]*/ + 0x5EFA2245, 0x3974DF44, 0x91E7D847, 0xF6692546, 0xC52DA0B0, 0xA2A35DB1, 0x0A305AB2, 0x6DBEA7B3, /* [14][0x68]*/ + 0x6CB9515E, 0x0B37AC5F, 0xA3A4AB5C, 0xC42A565D, 0xF76ED3AB, 0x90E02EAA, 0x387329A9, 0x5FFDD4A8, /* [14][0x70]*/ + 0x3A7CC473, 0x5DF23972, 0xF5613E71, 0x92EFC370, 0xA1AB4686, 0xC625BB87, 0x6EB6BC84, 0x09384185, /* [14][0x78]*/ + 0x083FB768, 0x6FB14A69, 0xC7224D6A, 0xA0ACB06B, 0x93E8359D, 0xF466C89C, 0x5CF5CF9F, 0x3B7B329E, /* [14][0x80]*/ + 0x2A03AAA3, 0x4D8D57A2, 0xE51E50A1, 0x8290ADA0, 0xB1D42856, 0xD65AD557, 0x7EC9D254, 0x19472F55, /* [14][0x88]*/ + 0x1840D9B8, 0x7FCE24B9, 0xD75D23BA, 0xB0D3DEBB, 0x83975B4D, 0xE419A64C, 0x4C8AA14F, 0x2B045C4E, /* [14][0x90]*/ + 0x4E854C95, 0x290BB194, 0x8198B697, 0xE6164B96, 0xD552CE60, 0xB2DC3361, 0x1A4F3462, 0x7DC1C963, /* [14][0x98]*/ + 0x7CC63F8E, 0x1B48C28F, 0xB3DBC58C, 0xD455388D, 0xE711BD7B, 0x809F407A, 0x280C4779, 0x4F82BA78, /* [14][0xa0]*/ + 0xE30E66CF, 0x84809BCE, 0x2C139CCD, 0x4B9D61CC, 0x78D9E43A, 0x1F57193B, 0xB7C41E38, 0xD04AE339, /* [14][0xa8]*/ + 0xD14D15D4, 0xB6C3E8D5, 0x1E50EFD6, 0x79DE12D7, 0x4A9A9721, 0x2D146A20, 0x85876D23, 0xE2099022, /* [14][0xb0]*/ + 0x878880F9, 0xE0067DF8, 0x48957AFB, 0x2F1B87FA, 0x1C5F020C, 0x7BD1FF0D, 0xD342F80E, 0xB4CC050F, /* [14][0xb8]*/ + 0xB5CBF3E2, 0xD2450EE3, 0x7AD609E0, 0x1D58F4E1, 0x2E1C7117, 0x49928C16, 0xE1018B15, 0x868F7614, /* [14][0xc0]*/ + 0xBDF4448A, 0xDA7AB98B, 0x72E9BE88, 0x15674389, 0x2623C67F, 0x41AD3B7E, 0xE93E3C7D, 0x8EB0C17C, /* [14][0xc8]*/ + 0x8FB73791, 0xE839CA90, 0x40AACD93, 0x27243092, 0x1460B564, 0x73EE4865, 0xDB7D4F66, 0xBCF3B267, /* [14][0xd0]*/ + 0xD972A2BC, 0xBEFC5FBD, 0x166F58BE, 0x71E1A5BF, 0x42A52049, 0x252BDD48, 0x8DB8DA4B, 0xEA36274A, /* [14][0xd8]*/ + 0xEB31D1A7, 0x8CBF2CA6, 0x242C2BA5, 0x43A2D6A4, 0x70E65352, 0x1768AE53, 0xBFFBA950, 0xD8755451, /* [14][0xe0]*/ + 0x74F988E6, 0x137775E7, 0xBBE472E4, 0xDC6A8FE5, 0xEF2E0A13, 0x88A0F712, 0x2033F011, 0x47BD0D10, /* [14][0xe8]*/ + 0x46BAFBFD, 0x213406FC, 0x89A701FF, 0xEE29FCFE, 0xDD6D7908, 0xBAE38409, 0x1270830A, 0x75FE7E0B, /* [14][0xf0]*/ + 0x107F6ED0, 0x77F193D1, 0xDF6294D2, 0xB8EC69D3, 0x8BA8EC25, 0xEC261124, 0x44B51627, 0x233BEB26, /* [14][0xf8]*/ + 0x223C1DCB, 0x45B2E0CA, 0xED21E7C9, 0x8AAF1AC8, 0xB9EB9F3E, 0xDE65623F, 0x76F6653C, 0x1178983D /* [14][0x100]*/ + }, + { + 0x00000000, 0xF20C0DFE, 0xE1F46D0D, 0x13F860F3, 0xC604ACEB, 0x3408A115, 0x27F0C1E6, 0xD5FCCC18, /* [15][0x08]*/ + 0x89E52F27, 0x7BE922D9, 0x6811422A, 0x9A1D4FD4, 0x4FE183CC, 0xBDED8E32, 0xAE15EEC1, 0x5C19E33F, /* [15][0x10]*/ + 0x162628BF, 0xE42A2541, 0xF7D245B2, 0x05DE484C, 0xD0228454, 0x222E89AA, 0x31D6E959, 0xC3DAE4A7, /* [15][0x18]*/ + 0x9FC30798, 0x6DCF0A66, 0x7E376A95, 0x8C3B676B, 0x59C7AB73, 0xABCBA68D, 0xB833C67E, 0x4A3FCB80, /* [15][0x20]*/ + 0x2C4C517E, 0xDE405C80, 0xCDB83C73, 0x3FB4318D, 0xEA48FD95, 0x1844F06B, 0x0BBC9098, 0xF9B09D66, /* [15][0x28]*/ + 0xA5A97E59, 0x57A573A7, 0x445D1354, 0xB6511EAA, 0x63ADD2B2, 0x91A1DF4C, 0x8259BFBF, 0x7055B241, /* [15][0x30]*/ + 0x3A6A79C1, 0xC866743F, 0xDB9E14CC, 0x29921932, 0xFC6ED52A, 0x0E62D8D4, 0x1D9AB827, 0xEF96B5D9, /* [15][0x38]*/ + 0xB38F56E6, 0x41835B18, 0x527B3BEB, 0xA0773615, 0x758BFA0D, 0x8787F7F3, 0x947F9700, 0x66739AFE, /* [15][0x40]*/ + 0x5898A2FC, 0xAA94AF02, 0xB96CCFF1, 0x4B60C20F, 0x9E9C0E17, 0x6C9003E9, 0x7F68631A, 0x8D646EE4, /* [15][0x48]*/ + 0xD17D8DDB, 0x23718025, 0x3089E0D6, 0xC285ED28, 0x17792130, 0xE5752CCE, 0xF68D4C3D, 0x048141C3, /* [15][0x50]*/ + 0x4EBE8A43, 0xBCB287BD, 0xAF4AE74E, 0x5D46EAB0, 0x88BA26A8, 0x7AB62B56, 0x694E4BA5, 0x9B42465B, /* [15][0x58]*/ + 0xC75BA564, 0x3557A89A, 0x26AFC869, 0xD4A3C597, 0x015F098F, 0xF3530471, 0xE0AB6482, 0x12A7697C, /* [15][0x60]*/ + 0x74D4F382, 0x86D8FE7C, 0x95209E8F, 0x672C9371, 0xB2D05F69, 0x40DC5297, 0x53243264, 0xA1283F9A, /* [15][0x68]*/ + 0xFD31DCA5, 0x0F3DD15B, 0x1CC5B1A8, 0xEEC9BC56, 0x3B35704E, 0xC9397DB0, 0xDAC11D43, 0x28CD10BD, /* [15][0x70]*/ + 0x62F2DB3D, 0x90FED6C3, 0x8306B630, 0x710ABBCE, 0xA4F677D6, 0x56FA7A28, 0x45021ADB, 0xB70E1725, /* [15][0x78]*/ + 0xEB17F41A, 0x191BF9E4, 0x0AE39917, 0xF8EF94E9, 0x2D1358F1, 0xDF1F550F, 0xCCE735FC, 0x3EEB3802, /* [15][0x80]*/ + 0xB13145F8, 0x433D4806, 0x50C528F5, 0xA2C9250B, 0x7735E913, 0x8539E4ED, 0x96C1841E, 0x64CD89E0, /* [15][0x88]*/ + 0x38D46ADF, 0xCAD86721, 0xD92007D2, 0x2B2C0A2C, 0xFED0C634, 0x0CDCCBCA, 0x1F24AB39, 0xED28A6C7, /* [15][0x90]*/ + 0xA7176D47, 0x551B60B9, 0x46E3004A, 0xB4EF0DB4, 0x6113C1AC, 0x931FCC52, 0x80E7ACA1, 0x72EBA15F, /* [15][0x98]*/ + 0x2EF24260, 0xDCFE4F9E, 0xCF062F6D, 0x3D0A2293, 0xE8F6EE8B, 0x1AFAE375, 0x09028386, 0xFB0E8E78, /* [15][0xa0]*/ + 0x9D7D1486, 0x6F711978, 0x7C89798B, 0x8E857475, 0x5B79B86D, 0xA975B593, 0xBA8DD560, 0x4881D89E, /* [15][0xa8]*/ + 0x14983BA1, 0xE694365F, 0xF56C56AC, 0x07605B52, 0xD29C974A, 0x20909AB4, 0x3368FA47, 0xC164F7B9, /* [15][0xb0]*/ + 0x8B5B3C39, 0x795731C7, 0x6AAF5134, 0x98A35CCA, 0x4D5F90D2, 0xBF539D2C, 0xACABFDDF, 0x5EA7F021, /* [15][0xb8]*/ + 0x02BE131E, 0xF0B21EE0, 0xE34A7E13, 0x114673ED, 0xC4BABFF5, 0x36B6B20B, 0x254ED2F8, 0xD742DF06, /* [15][0xc0]*/ + 0xE9A9E704, 0x1BA5EAFA, 0x085D8A09, 0xFA5187F7, 0x2FAD4BEF, 0xDDA14611, 0xCE5926E2, 0x3C552B1C, /* [15][0xc8]*/ + 0x604CC823, 0x9240C5DD, 0x81B8A52E, 0x73B4A8D0, 0xA64864C8, 0x54446936, 0x47BC09C5, 0xB5B0043B, /* [15][0xd0]*/ + 0xFF8FCFBB, 0x0D83C245, 0x1E7BA2B6, 0xEC77AF48, 0x398B6350, 0xCB876EAE, 0xD87F0E5D, 0x2A7303A3, /* [15][0xd8]*/ + 0x766AE09C, 0x8466ED62, 0x979E8D91, 0x6592806F, 0xB06E4C77, 0x42624189, 0x519A217A, 0xA3962C84, /* [15][0xe0]*/ + 0xC5E5B67A, 0x37E9BB84, 0x2411DB77, 0xD61DD689, 0x03E11A91, 0xF1ED176F, 0xE215779C, 0x10197A62, /* [15][0xe8]*/ + 0x4C00995D, 0xBE0C94A3, 0xADF4F450, 0x5FF8F9AE, 0x8A0435B6, 0x78083848, 0x6BF058BB, 0x99FC5545, /* [15][0xf0]*/ + 0xD3C39EC5, 0x21CF933B, 0x3237F3C8, 0xC03BFE36, 0x15C7322E, 0xE7CB3FD0, 0xF4335F23, 0x063F52DD, /* [15][0xf8]*/ + 0x5A26B1E2, 0xA82ABC1C, 0xBBD2DCEF, 0x49DED111, 0x9C221D09, 0x6E2E10F7, 0x7DD67004, 0x8FDA7DFA /* [15][0x100]*/ + }}; + +/* private (static) function factoring out byte-by-byte CRC computation using just one slice of the lookup table*/ +static uint32_t s_crc_generic_sb1(const uint8_t *input, int length, uint32_t crc, const uint32_t *table_ptr) { + uint32_t(*table)[16][256] = (uint32_t(*)[16][256])table_ptr; + while (length-- > 0) { + crc = (crc >> 8) ^ (*table)[0][(crc & 0xff) ^ *input++]; + } + return crc; +} + +/* The inner loops of the CRC functions that process large blocks of data work best when input is aligned*/ +/* This function begins processing input data one byte at a time until the input pointer is 4-byte aligned*/ +/* Advances the input pointer and reduces the length (both passed by reference)*/ +static inline uint32_t s_crc_generic_align( + const uint8_t **input, + int *length, + uint32_t crc, + const uint32_t *table_ptr) { + + /* Get the 4-byte memory alignment of our input buffer by looking at the least significant 2 bits*/ + size_t input_alignment = ((size_t)*input) & 0x3; + + /* Compute the number of input bytes that precede the first 4-byte aligned block (will be in range 0-3)*/ + size_t leading = (4 - input_alignment) & 0x3; + + /* Determine what's left without the leading input bytes (might be negative)*/ + size_t remaining = *length - leading; + + /* Process unaligned leading input bytes one at a time*/ + if (leading && remaining > 0) { + crc = s_crc_generic_sb1(*input, (uint32_t)leading, crc, table_ptr); + *input += leading; + *length -= (int)leading; + } + + return crc; +} + +/* private (static) function to compute a generic slice-by-4 CRC using the specified lookup table (4 table slices)*/ +static uint32_t s_crc_generic_sb4(const uint8_t *input, int length, uint32_t crc, const uint32_t *table_ptr) { + const uint32_t *current = (const uint32_t *)input; + int remaining = length; + uint32_t(*table)[16][256] = (uint32_t(*)[16][256])table_ptr; + + while (remaining >= 4) { + crc ^= *current++; + crc = (*table)[3][crc & 0xff] ^ (*table)[2][(crc >> 8) & 0xff] ^ (*table)[1][(crc >> 16) & 0xff] ^ + (*table)[0][crc >> 24]; + remaining -= 4; + } + + return s_crc_generic_sb1(&input[length - remaining], remaining, crc, table_ptr); +} + +/* private (static) function to compute a generic slice-by-8 CRC using the specified lookup table (8 table slices)*/ +static uint32_t s_crc_generic_sb8(const uint8_t *input, int length, uint32_t crc, const uint32_t *table_ptr) { + const uint32_t *current = (const uint32_t *)input; + int remaining = length; + uint32_t(*table)[16][256] = (uint32_t(*)[16][256])table_ptr; + + while (remaining >= 8) { + uint32_t c1 = *current++ ^ crc; + uint32_t c2 = *current++; + uint32_t t1 = (*table)[7][c1 & 0xff] ^ (*table)[6][(c1 >> 8) & 0xff] ^ (*table)[5][(c1 >> 16) & 0xff] ^ + (*table)[4][(c1 >> 24) & 0xff]; + uint32_t t2 = (*table)[3][c2 & 0xff] ^ (*table)[2][(c2 >> 8) & 0xff] ^ (*table)[1][(c2 >> 16) & 0xff] ^ + (*table)[0][(c2 >> 24) & 0xff]; + crc = t1 ^ t2; + remaining -= 8; + } + return s_crc_generic_sb4(&input[length - remaining], remaining, crc, table_ptr); +} + +/* private (static) function to compute a generic slice-by-16 CRC using the specified lookup table (all 16 table + * slices)*/ +static uint32_t s_crc_generic_sb16(const uint8_t *input, int length, uint32_t crc, const uint32_t *table_ptr) { + const uint32_t *current = (const uint32_t *)input; + int remaining = length; + uint32_t(*table)[16][256] = (uint32_t(*)[16][256])table_ptr; + + while (remaining >= 16) { + uint32_t c1 = *current++ ^ crc; + uint32_t c2 = *current++; + uint32_t c3 = *current++; + uint32_t c4 = *current++; + uint32_t t1 = (*table)[15][c1 & 0xff] ^ (*table)[14][(c1 >> 8) & 0xff] ^ (*table)[13][(c1 >> 16) & 0xff] ^ + (*table)[12][(c1 >> 24) & 0xff]; + uint32_t t2 = (*table)[11][c2 & 0xff] ^ (*table)[10][(c2 >> 8) & 0xff] ^ (*table)[9][(c2 >> 16) & 0xff] ^ + (*table)[8][(c2 >> 24) & 0xff]; + uint32_t t3 = (*table)[7][c3 & 0xff] ^ (*table)[6][(c3 >> 8) & 0xff] ^ (*table)[5][(c3 >> 16) & 0xff] ^ + (*table)[4][(c3 >> 24) & 0xff]; + uint32_t t4 = (*table)[3][c4 & 0xff] ^ (*table)[2][(c4 >> 8) & 0xff] ^ (*table)[1][(c4 >> 16) & 0xff] ^ + (*table)[0][(c4 >> 24) & 0xff]; + crc = t1 ^ t2 ^ t3 ^ t4; + remaining -= 16; + } + return s_crc_generic_sb4(&input[length - remaining], remaining, crc, table_ptr); +} + +static uint32_t s_crc32_no_slice(const uint8_t *input, int length, uint32_t previousCrc32) { + return ~s_crc_generic_sb1(input, length, ~previousCrc32, &CRC32_TABLE[0][0]); +} + +/* Computes CRC32 (Ethernet, gzip, et. al.) using slice-by-4. */ +static uint32_t s_crc32_sb4(const uint8_t *input, int length, uint32_t previousCrc32) { + uint32_t crc = s_crc_generic_align(&input, &length, ~previousCrc32, &CRC32_TABLE[0][0]); + return ~s_crc_generic_sb4(input, length, crc, &CRC32_TABLE[0][0]); +} + +/* Computes CRC32 (Ethernet, gzip, et. al.) using slice-by-8. */ +static uint32_t s_crc32_sb8(const uint8_t *input, int length, uint32_t previousCrc32) { + uint32_t crc = s_crc_generic_align(&input, &length, ~previousCrc32, &CRC32_TABLE[0][0]); + return ~s_crc_generic_sb8(input, length, crc, &CRC32_TABLE[0][0]); +} + +/* Computes CRC32 (Ethernet, gzip, et. al.) using slice-by-16. */ +static uint32_t s_crc32_sb16(const uint8_t *input, int length, uint32_t previousCrc32) { + uint32_t crc = s_crc_generic_align(&input, &length, ~previousCrc32, &CRC32_TABLE[0][0]); + return ~s_crc_generic_sb16(input, length, crc, &CRC32_TABLE[0][0]); +} + +static uint32_t s_crc32c_no_slice(const uint8_t *input, int length, uint32_t previousCrc32c) { + return ~s_crc_generic_sb1(input, length, ~previousCrc32c, &CRC32C_TABLE[0][0]); +} + +/* Computes the Castagnoli CRC32c (iSCSI) using slice-by-4. */ +static uint32_t s_crc32c_sb4(const uint8_t *input, int length, uint32_t previousCrc32) { + uint32_t crc = s_crc_generic_align(&input, &length, ~previousCrc32, &CRC32C_TABLE[0][0]); + return ~s_crc_generic_sb4(input, length, crc, &CRC32C_TABLE[0][0]); +} + +/* Computes the Castagnoli CRC32c (iSCSI) using slice-by-8. */ +static uint32_t s_crc32c_sb8(const uint8_t *input, int length, uint32_t previousCrc32) { + uint32_t crc = s_crc_generic_align(&input, &length, ~previousCrc32, &CRC32C_TABLE[0][0]); + return ~s_crc_generic_sb8(input, length, crc, &CRC32C_TABLE[0][0]); +} + +/* Computes the Castagnoli CRC32c (iSCSI) using slice-by-16. */ +static uint32_t s_crc32c_sb16(const uint8_t *input, int length, uint32_t previousCrc32) { + uint32_t crc = s_crc_generic_align(&input, &length, ~previousCrc32, &CRC32C_TABLE[0][0]); + return ~s_crc_generic_sb16(input, length, crc, &CRC32C_TABLE[0][0]); +} + +/** + * Computes the Ethernet, gzip CRC32 of the specified data buffer. + * Pass 0 in the previousCrc32 parameter as an initial value unless continuing to update a running crc in a subsequent + * call + */ +uint32_t aws_checksums_crc32_sw(const uint8_t *input, int length, uint32_t previousCrc32) { + if (length >= 16) { + return s_crc32_sb16(input, length, previousCrc32); + } + + if (length >= 8) { + return s_crc32_sb8(input, length, previousCrc32); + } + + if (length >= 4) { + return s_crc32_sb4(input, length, previousCrc32); + } + + return s_crc32_no_slice(input, length, previousCrc32); +} + +/** + * Computes the Castagnoli iSCSI CRC32c of the specified data buffer. + * Pass 0 in the previousCrc32c parameter as an initial value unless continuing to update a running crc in a subsequent + * call + */ +uint32_t aws_checksums_crc32c_sw(const uint8_t *input, int length, uint32_t previousCrc32c) { + if (length >= 16) { + return s_crc32c_sb16(input, length, previousCrc32c); + } + + if (length >= 8) { + return s_crc32c_sb8(input, length, previousCrc32c); + } + + if (length >= 4) { + return s_crc32c_sb4(input, length, previousCrc32c); + } + + return s_crc32c_no_slice(input, length, previousCrc32c); +} diff --git a/contrib/restricted/aws/aws-checksums/ya.make b/contrib/restricted/aws/aws-checksums/ya.make index c668b477c9..a08a095ee1 100644 --- a/contrib/restricted/aws/aws-checksums/ya.make +++ b/contrib/restricted/aws/aws-checksums/ya.make @@ -1,27 +1,27 @@ -# Generated by devtools/yamaker. - -LIBRARY() - +# Generated by devtools/yamaker. + +LIBRARY() + OWNER(g:cpp-contrib) - + VERSION(0.1.10) - -LICENSE(Apache-2.0) - + +LICENSE(Apache-2.0) + LICENSE_TEXTS(.yandex_meta/licenses.list.txt) PEERDIR( contrib/restricted/aws/aws-c-common ) -ADDINCL( +ADDINCL( GLOBAL contrib/restricted/aws/aws-checksums/include -) - -NO_COMPILER_WARNINGS() - +) + +NO_COMPILER_WARNINGS() + NO_RUNTIME() - + CFLAGS( -DAWS_CHECKSUMS_EXPORTS -DAWS_CHECKSUMS_USE_IMPORT_EXPORT @@ -36,10 +36,10 @@ IF (BUILD_TYPE == "DEBUG") ) ENDIF() -SRCS( - source/crc.c - source/crc_sw.c +SRCS( + source/crc.c + source/crc_sw.c source/intel/asm/crc32c_sse42_asm.c -) - -END() +) + +END() |