duckdb 0.9.3-dev0.0 → 0.9.3-dev3.0
Sign up to get free protection for your applications and to get access to all the features.
- package/LICENSE +1 -1
- package/binding.gyp +32 -7
- package/package.json +1 -1
- package/src/connection.cpp +6 -6
- package/src/database.cpp +9 -9
- package/src/duckdb/extension/icu/icu-datefunc.cpp +22 -10
- package/src/duckdb/extension/icu/icu-datepart.cpp +42 -22
- package/src/duckdb/extension/icu/icu-datetrunc.cpp +40 -7
- package/src/duckdb/extension/icu/icu-strptime.cpp +14 -8
- package/src/duckdb/extension/icu/icu-table-range.cpp +1 -1
- package/src/duckdb/extension/icu/icu-timezone.cpp +43 -16
- package/src/duckdb/extension/icu/icu_extension.cpp +1 -1
- package/src/duckdb/extension/icu/include/icu-datefunc.hpp +3 -0
- package/src/duckdb/extension/icu/third_party/icu/stubdata/stubdata.cpp +1 -1
- package/src/duckdb/extension/json/buffered_json_reader.cpp +78 -62
- package/src/duckdb/extension/json/include/buffered_json_reader.hpp +11 -7
- package/src/duckdb/extension/json/include/json_common.hpp +0 -14
- package/src/duckdb/extension/json/include/json_deserializer.hpp +1 -0
- package/src/duckdb/extension/json/include/json_functions.hpp +1 -0
- package/src/duckdb/extension/json/include/json_scan.hpp +19 -5
- package/src/duckdb/extension/json/include/json_serializer.hpp +2 -1
- package/src/duckdb/extension/json/include/json_structure.hpp +12 -10
- package/src/duckdb/extension/json/json_common.cpp +1 -0
- package/src/duckdb/extension/json/json_deserializer.cpp +13 -0
- package/src/duckdb/extension/json/json_extension.cpp +3 -3
- package/src/duckdb/extension/json/json_functions/copy_json.cpp +8 -4
- package/src/duckdb/extension/json/json_functions/json_array_length.cpp +1 -1
- package/src/duckdb/extension/json/json_functions/json_contains.cpp +3 -3
- package/src/duckdb/extension/json/json_functions/json_create.cpp +53 -8
- package/src/duckdb/extension/json/json_functions/json_extract.cpp +10 -6
- package/src/duckdb/extension/json/json_functions/json_keys.cpp +1 -1
- package/src/duckdb/extension/json/json_functions/json_merge_patch.cpp +2 -3
- package/src/duckdb/extension/json/json_functions/json_serialize_plan.cpp +210 -0
- package/src/duckdb/extension/json/json_functions/json_serialize_sql.cpp +22 -19
- package/src/duckdb/extension/json/json_functions/json_structure.cpp +71 -43
- package/src/duckdb/extension/json/json_functions/json_transform.cpp +105 -8
- package/src/duckdb/extension/json/json_functions/json_type.cpp +1 -1
- package/src/duckdb/extension/json/json_functions/json_valid.cpp +1 -1
- package/src/duckdb/extension/json/json_functions/read_json.cpp +43 -18
- package/src/duckdb/extension/json/json_functions/read_json_objects.cpp +1 -1
- package/src/duckdb/extension/json/json_functions.cpp +9 -5
- package/src/duckdb/extension/json/json_scan.cpp +147 -125
- package/src/duckdb/extension/json/json_serializer.cpp +9 -0
- package/src/duckdb/extension/json/serialize_json.cpp +6 -0
- package/src/duckdb/extension/parquet/column_reader.cpp +53 -18
- package/src/duckdb/extension/parquet/column_writer.cpp +29 -6
- package/src/duckdb/extension/parquet/include/column_reader.hpp +0 -1
- package/src/duckdb/extension/parquet/include/decode_utils.hpp +2 -2
- package/src/duckdb/extension/parquet/include/parquet_crypto.hpp +87 -0
- package/src/duckdb/extension/parquet/include/parquet_dbp_decoder.hpp +4 -3
- package/src/duckdb/extension/parquet/include/parquet_decimal_utils.hpp +16 -3
- package/src/duckdb/extension/parquet/include/parquet_metadata.hpp +10 -0
- package/src/duckdb/extension/parquet/include/parquet_reader.hpp +34 -6
- package/src/duckdb/extension/parquet/include/parquet_statistics.hpp +3 -2
- package/src/duckdb/extension/parquet/include/parquet_timestamp.hpp +2 -0
- package/src/duckdb/extension/parquet/include/parquet_writer.hpp +21 -1
- package/src/duckdb/extension/parquet/parquet_crypto.cpp +370 -0
- package/src/duckdb/extension/parquet/parquet_extension.cpp +254 -24
- package/src/duckdb/extension/parquet/parquet_metadata.cpp +204 -16
- package/src/duckdb/extension/parquet/parquet_reader.cpp +108 -34
- package/src/duckdb/extension/parquet/parquet_statistics.cpp +75 -30
- package/src/duckdb/extension/parquet/parquet_timestamp.cpp +15 -8
- package/src/duckdb/extension/parquet/parquet_writer.cpp +62 -10
- package/src/duckdb/extension/parquet/serialize_parquet.cpp +60 -0
- package/src/duckdb/src/catalog/catalog.cpp +23 -25
- package/src/duckdb/src/catalog/catalog_entry/column_dependency_manager.cpp +1 -0
- package/src/duckdb/src/catalog/catalog_entry/dependency/dependency_dependent_entry.cpp +31 -0
- package/src/duckdb/src/catalog/catalog_entry/dependency/dependency_entry.cpp +44 -0
- package/src/duckdb/src/catalog/catalog_entry/dependency/dependency_subject_entry.cpp +31 -0
- package/src/duckdb/src/catalog/catalog_entry/duck_index_entry.cpp +35 -10
- package/src/duckdb/src/catalog/catalog_entry/duck_schema_entry.cpp +22 -6
- package/src/duckdb/src/catalog/catalog_entry/duck_table_entry.cpp +110 -33
- package/src/duckdb/src/catalog/catalog_entry/index_catalog_entry.cpp +33 -17
- package/src/duckdb/src/catalog/catalog_entry/macro_catalog_entry.cpp +16 -0
- package/src/duckdb/src/catalog/catalog_entry/schema_catalog_entry.cpp +7 -6
- package/src/duckdb/src/catalog/catalog_entry/sequence_catalog_entry.cpp +88 -14
- package/src/duckdb/src/catalog/catalog_entry/table_catalog_entry.cpp +6 -15
- package/src/duckdb/src/catalog/catalog_entry/type_catalog_entry.cpp +20 -20
- package/src/duckdb/src/catalog/catalog_entry/view_catalog_entry.cpp +4 -0
- package/src/duckdb/src/catalog/catalog_entry.cpp +29 -0
- package/src/duckdb/src/catalog/catalog_set.cpp +358 -343
- package/src/duckdb/src/catalog/catalog_transaction.cpp +4 -0
- package/src/duckdb/src/catalog/default/default_functions.cpp +13 -4
- package/src/duckdb/src/catalog/default/default_schemas.cpp +5 -1
- package/src/duckdb/src/catalog/default/default_views.cpp +6 -2
- package/src/duckdb/src/catalog/dependency_catalog_set.cpp +51 -0
- package/src/duckdb/src/catalog/dependency_manager.cpp +510 -114
- package/src/duckdb/src/catalog/duck_catalog.cpp +4 -4
- package/src/duckdb/src/common/adbc/adbc.cpp +73 -53
- package/src/duckdb/src/common/adbc/driver_manager.cpp +1101 -268
- package/src/duckdb/src/common/arrow/arrow_wrapper.cpp +20 -9
- package/src/duckdb/src/common/bind_helpers.cpp +1 -0
- package/src/duckdb/src/common/box_renderer.cpp +52 -1
- package/src/duckdb/src/common/compressed_file_system.cpp +1 -0
- package/src/duckdb/src/common/constants.cpp +0 -1
- package/src/duckdb/src/common/enum_util.cpp +522 -107
- package/src/duckdb/src/common/enums/catalog_type.cpp +64 -1
- package/src/duckdb/src/common/enums/compression_type.cpp +14 -0
- package/src/duckdb/src/common/enums/date_part_specifier.cpp +1 -0
- package/src/duckdb/src/common/enums/expression_type.cpp +4 -0
- package/src/duckdb/src/common/enums/file_compression_type.cpp +1 -0
- package/src/duckdb/src/common/enums/join_type.cpp +33 -0
- package/src/duckdb/src/common/enums/logical_operator_type.cpp +5 -3
- package/src/duckdb/src/common/enums/optimizer_type.cpp +9 -1
- package/src/duckdb/src/common/enums/physical_operator_type.cpp +8 -4
- package/src/duckdb/src/common/enums/statement_type.cpp +2 -2
- package/src/duckdb/src/common/error_data.cpp +113 -0
- package/src/duckdb/src/common/exception/binder_exception.cpp +47 -0
- package/src/duckdb/src/common/exception/catalog_exception.cpp +55 -0
- package/src/duckdb/src/common/exception/parser_exception.cpp +19 -0
- package/src/duckdb/src/common/exception.cpp +110 -121
- package/src/duckdb/src/common/exception_format_value.cpp +9 -1
- package/src/duckdb/src/common/extra_type_info.cpp +48 -0
- package/src/duckdb/src/common/file_system.cpp +12 -7
- package/src/duckdb/src/common/gzip_file_system.cpp +18 -18
- package/src/duckdb/src/common/hive_partitioning.cpp +5 -1
- package/src/duckdb/src/common/http_state.cpp +20 -3
- package/src/duckdb/src/common/local_file_system.cpp +213 -15
- package/src/duckdb/src/common/multi_file_reader.cpp +20 -7
- package/src/duckdb/src/common/operator/cast_operators.cpp +397 -414
- package/src/duckdb/src/common/operator/convert_to_string.cpp +4 -0
- package/src/duckdb/src/common/operator/string_cast.cpp +5 -0
- package/src/duckdb/src/common/progress_bar/progress_bar.cpp +61 -12
- package/src/duckdb/src/common/progress_bar/terminal_progress_bar_display.cpp +13 -4
- package/src/duckdb/src/common/radix_partitioning.cpp +1 -1
- package/src/duckdb/src/common/row_operations/row_aggregate.cpp +2 -1
- package/src/duckdb/src/common/row_operations/row_gather.cpp +7 -1
- package/src/duckdb/src/common/row_operations/row_heap_gather.cpp +78 -12
- package/src/duckdb/src/common/row_operations/row_heap_scatter.cpp +222 -61
- package/src/duckdb/src/common/row_operations/row_matcher.cpp +6 -1
- package/src/duckdb/src/common/row_operations/row_radix_scatter.cpp +51 -0
- package/src/duckdb/src/common/row_operations/row_scatter.cpp +8 -1
- package/src/duckdb/src/common/serializer/binary_deserializer.cpp +6 -0
- package/src/duckdb/src/common/serializer/binary_serializer.cpp +5 -0
- package/src/duckdb/src/common/serializer/serializer.cpp +19 -0
- package/src/duckdb/src/common/sort/comparators.cpp +126 -0
- package/src/duckdb/src/common/sort/partition_state.cpp +17 -17
- package/src/duckdb/src/common/sort/radix_sort.cpp +2 -1
- package/src/duckdb/src/common/sort/sort_state.cpp +10 -5
- package/src/duckdb/src/common/sort/sorted_block.cpp +7 -6
- package/src/duckdb/src/common/string_util.cpp +302 -24
- package/src/duckdb/src/common/tree_renderer.cpp +8 -6
- package/src/duckdb/src/common/types/cast_helpers.cpp +6 -0
- package/src/duckdb/src/common/types/column/column_data_allocator.cpp +1 -1
- package/src/duckdb/src/common/types/column/column_data_collection.cpp +58 -0
- package/src/duckdb/src/common/types/column/column_data_collection_segment.cpp +8 -1
- package/src/duckdb/src/common/types/data_chunk.cpp +9 -0
- package/src/duckdb/src/common/types/date.cpp +2 -2
- package/src/duckdb/src/common/types/hash.cpp +9 -1
- package/src/duckdb/src/common/types/hugeint.cpp +229 -51
- package/src/duckdb/src/common/types/hyperloglog.cpp +10 -3
- package/src/duckdb/src/common/types/interval.cpp +67 -12
- package/src/duckdb/src/common/types/list_segment.cpp +98 -4
- package/src/duckdb/src/common/types/row/partitioned_tuple_data.cpp +11 -1
- package/src/duckdb/src/common/types/row/row_data_collection.cpp +1 -1
- package/src/duckdb/src/common/types/row/row_data_collection_scanner.cpp +2 -2
- package/src/duckdb/src/common/types/row/tuple_data_allocator.cpp +3 -2
- package/src/duckdb/src/common/types/row/tuple_data_collection.cpp +63 -3
- package/src/duckdb/src/common/types/row/tuple_data_scatter_gather.cpp +331 -127
- package/src/duckdb/src/common/types/time.cpp +47 -75
- package/src/duckdb/src/common/types/timestamp.cpp +16 -3
- package/src/duckdb/src/common/types/uhugeint.cpp +746 -0
- package/src/duckdb/src/common/types/validity_mask.cpp +6 -2
- package/src/duckdb/src/common/types/value.cpp +183 -27
- package/src/duckdb/src/common/types/vector.cpp +331 -30
- package/src/duckdb/src/common/types/vector_buffer.cpp +29 -1
- package/src/duckdb/src/common/types/vector_cache.cpp +22 -1
- package/src/duckdb/src/common/types.cpp +606 -90
- package/src/duckdb/src/common/value_operations/comparison_operations.cpp +21 -1
- package/src/duckdb/src/common/vector_operations/comparison_operators.cpp +5 -0
- package/src/duckdb/src/common/vector_operations/generators.cpp +2 -2
- package/src/duckdb/src/common/vector_operations/is_distinct_from.cpp +131 -2
- package/src/duckdb/src/common/vector_operations/vector_copy.cpp +26 -4
- package/src/duckdb/src/common/vector_operations/vector_hash.cpp +41 -0
- package/src/duckdb/src/common/vector_operations/vector_storage.cpp +7 -0
- package/src/duckdb/src/common/virtual_file_system.cpp +0 -1
- package/src/duckdb/src/core_functions/aggregate/distributive/approx_count.cpp +2 -1
- package/src/duckdb/src/core_functions/aggregate/distributive/arg_min_max.cpp +144 -56
- package/src/duckdb/src/core_functions/aggregate/distributive/bitagg.cpp +2 -0
- package/src/duckdb/src/core_functions/aggregate/distributive/bitstring_agg.cpp +27 -0
- package/src/duckdb/src/core_functions/aggregate/distributive/entropy.cpp +4 -3
- package/src/duckdb/src/core_functions/aggregate/distributive/kurtosis.cpp +25 -5
- package/src/duckdb/src/core_functions/aggregate/distributive/minmax.cpp +100 -3
- package/src/duckdb/src/core_functions/aggregate/distributive/string_agg.cpp +2 -1
- package/src/duckdb/src/core_functions/aggregate/holistic/approximate_quantile.cpp +9 -1
- package/src/duckdb/src/core_functions/aggregate/holistic/mode.cpp +83 -52
- package/src/duckdb/src/core_functions/aggregate/holistic/quantile.cpp +485 -289
- package/src/duckdb/src/core_functions/aggregate/holistic/reservoir_quantile.cpp +3 -3
- package/src/duckdb/src/core_functions/aggregate/nested/histogram.cpp +24 -26
- package/src/duckdb/src/core_functions/aggregate/nested/list.cpp +34 -37
- package/src/duckdb/src/core_functions/function_list.cpp +30 -1
- package/src/duckdb/src/core_functions/lambda_functions.cpp +416 -0
- package/src/duckdb/src/core_functions/scalar/array/array_functions.cpp +294 -0
- package/src/duckdb/src/core_functions/scalar/array/array_value.cpp +87 -0
- package/src/duckdb/src/core_functions/scalar/blob/create_sort_key.cpp +686 -0
- package/src/duckdb/src/core_functions/scalar/blob/encode.cpp +1 -0
- package/src/duckdb/src/core_functions/scalar/date/current.cpp +3 -3
- package/src/duckdb/src/core_functions/scalar/date/date_part.cpp +295 -20
- package/src/duckdb/src/core_functions/scalar/date/make_date.cpp +1 -0
- package/src/duckdb/src/core_functions/scalar/date/strftime.cpp +8 -7
- package/src/duckdb/src/core_functions/scalar/date/to_interval.cpp +84 -23
- package/src/duckdb/src/core_functions/scalar/generic/error.cpp +4 -4
- package/src/duckdb/src/core_functions/scalar/generic/least.cpp +7 -8
- package/src/duckdb/src/core_functions/scalar/generic/stats.cpp +1 -1
- package/src/duckdb/src/core_functions/scalar/generic/system_functions.cpp +17 -6
- package/src/duckdb/src/core_functions/scalar/list/array_slice.cpp +8 -0
- package/src/duckdb/src/core_functions/scalar/list/list_aggregates.cpp +28 -14
- package/src/duckdb/src/core_functions/scalar/list/list_filter.cpp +49 -0
- package/src/duckdb/src/core_functions/scalar/list/list_reduce.cpp +230 -0
- package/src/duckdb/src/core_functions/scalar/list/list_sort.cpp +85 -16
- package/src/duckdb/src/core_functions/scalar/list/list_transform.cpp +41 -0
- package/src/duckdb/src/core_functions/scalar/list/list_value.cpp +21 -2
- package/src/duckdb/src/core_functions/scalar/map/map.cpp +6 -5
- package/src/duckdb/src/core_functions/scalar/map/map_entries.cpp +2 -2
- package/src/duckdb/src/core_functions/scalar/map/map_from_entries.cpp +1 -2
- package/src/duckdb/src/core_functions/scalar/math/numeric.cpp +24 -4
- package/src/duckdb/src/core_functions/scalar/operators/bitwise.cpp +6 -0
- package/src/duckdb/src/core_functions/scalar/random/random.cpp +2 -2
- package/src/duckdb/src/core_functions/scalar/random/setseed.cpp +2 -2
- package/src/duckdb/src/core_functions/scalar/secret/which_secret.cpp +28 -0
- package/src/duckdb/src/core_functions/scalar/string/bar.cpp +9 -4
- package/src/duckdb/src/core_functions/scalar/string/format_bytes.cpp +7 -2
- package/src/duckdb/src/core_functions/scalar/string/hex.cpp +63 -4
- package/src/duckdb/src/core_functions/scalar/string/pad.cpp +2 -2
- package/src/duckdb/src/core_functions/scalar/string/parse_path.cpp +348 -0
- package/src/duckdb/src/core_functions/scalar/string/regexp_escape.cpp +22 -0
- package/src/duckdb/src/core_functions/scalar/string/string_split.cpp +6 -5
- package/src/duckdb/src/core_functions/scalar/struct/struct_insert.cpp +3 -3
- package/src/duckdb/src/core_functions/scalar/struct/struct_pack.cpp +1 -1
- package/src/duckdb/src/execution/aggregate_hashtable.cpp +9 -2
- package/src/duckdb/src/execution/column_binding_resolver.cpp +44 -10
- package/src/duckdb/src/execution/expression_executor/execute_between.cpp +4 -0
- package/src/duckdb/src/execution/expression_executor/execute_case.cpp +4 -0
- package/src/duckdb/src/execution/expression_executor/execute_comparison.cpp +4 -0
- package/src/duckdb/src/execution/expression_executor.cpp +2 -1
- package/src/duckdb/src/execution/index/art/art.cpp +202 -53
- package/src/duckdb/src/execution/index/art/art_key.cpp +20 -27
- package/src/duckdb/src/execution/index/fixed_size_allocator.cpp +52 -17
- package/src/duckdb/src/execution/index/fixed_size_buffer.cpp +14 -8
- package/src/duckdb/src/execution/index/index_type_set.cpp +32 -0
- package/src/duckdb/src/execution/index/unknown_index.cpp +65 -0
- package/src/duckdb/src/execution/join_hashtable.cpp +151 -174
- package/src/duckdb/src/execution/nested_loop_join/nested_loop_join_inner.cpp +4 -0
- package/src/duckdb/src/execution/nested_loop_join/nested_loop_join_mark.cpp +4 -0
- package/src/duckdb/src/execution/operator/aggregate/aggregate_object.cpp +2 -1
- package/src/duckdb/src/execution/operator/aggregate/physical_hash_aggregate.cpp +82 -36
- package/src/duckdb/src/execution/operator/aggregate/physical_ungrouped_aggregate.cpp +58 -32
- package/src/duckdb/src/execution/operator/aggregate/physical_window.cpp +35 -19
- package/src/duckdb/src/execution/operator/csv_scanner/buffer_manager/csv_buffer.cpp +90 -0
- package/src/duckdb/src/execution/operator/csv_scanner/buffer_manager/csv_buffer_manager.cpp +124 -0
- package/src/duckdb/src/execution/operator/csv_scanner/buffer_manager/csv_file_handle.cpp +97 -0
- package/src/duckdb/src/execution/operator/csv_scanner/scanner/base_scanner.cpp +71 -0
- package/src/duckdb/src/execution/operator/csv_scanner/scanner/column_count_scanner.cpp +98 -0
- package/src/duckdb/src/execution/operator/csv_scanner/scanner/scanner_boundary.cpp +105 -0
- package/src/duckdb/src/execution/operator/csv_scanner/scanner/skip_scanner.cpp +63 -0
- package/src/duckdb/src/execution/operator/csv_scanner/scanner/string_value_scanner.cpp +1091 -0
- package/src/duckdb/src/execution/operator/csv_scanner/sniffer/csv_sniffer.cpp +124 -26
- package/src/duckdb/src/execution/operator/csv_scanner/sniffer/dialect_detection.cpp +117 -129
- package/src/duckdb/src/execution/operator/csv_scanner/sniffer/header_detection.cpp +46 -22
- package/src/duckdb/src/execution/operator/csv_scanner/sniffer/type_detection.cpp +83 -199
- package/src/duckdb/src/execution/operator/csv_scanner/sniffer/type_refinement.cpp +21 -122
- package/src/duckdb/src/execution/operator/csv_scanner/sniffer/type_replacement.cpp +18 -17
- package/src/duckdb/src/execution/operator/csv_scanner/state_machine/csv_state_machine.cpp +22 -0
- package/src/duckdb/src/execution/operator/csv_scanner/state_machine/csv_state_machine_cache.cpp +201 -0
- package/src/duckdb/src/execution/operator/csv_scanner/table_function/csv_file_scanner.cpp +221 -0
- package/src/duckdb/src/execution/operator/csv_scanner/table_function/global_csv_state.cpp +204 -0
- package/src/duckdb/src/execution/operator/csv_scanner/util/csv_error.cpp +186 -0
- package/src/duckdb/src/execution/operator/csv_scanner/util/csv_reader_options.cpp +532 -0
- package/src/duckdb/src/execution/operator/helper/physical_buffered_collector.cpp +85 -0
- package/src/duckdb/src/execution/operator/helper/physical_create_secret.cpp +21 -0
- package/src/duckdb/src/execution/operator/helper/physical_materialized_collector.cpp +1 -1
- package/src/duckdb/src/execution/operator/helper/physical_pragma.cpp +2 -2
- package/src/duckdb/src/execution/operator/helper/physical_reservoir_sample.cpp +34 -9
- package/src/duckdb/src/execution/operator/helper/physical_result_collector.cpp +10 -0
- package/src/duckdb/src/execution/operator/helper/physical_transaction.cpp +1 -0
- package/src/duckdb/src/execution/operator/helper/physical_vacuum.cpp +25 -10
- package/src/duckdb/src/execution/operator/join/perfect_hash_join_executor.cpp +7 -8
- package/src/duckdb/src/execution/operator/join/physical_asof_join.cpp +1 -1
- package/src/duckdb/src/execution/operator/join/physical_blockwise_nl_join.cpp +5 -2
- package/src/duckdb/src/execution/operator/join/physical_comparison_join.cpp +1 -1
- package/src/duckdb/src/execution/operator/join/physical_delim_join.cpp +5 -127
- package/src/duckdb/src/execution/operator/join/physical_hash_join.cpp +221 -61
- package/src/duckdb/src/execution/operator/join/physical_iejoin.cpp +18 -21
- package/src/duckdb/src/execution/operator/join/physical_join.cpp +10 -5
- package/src/duckdb/src/execution/operator/join/physical_left_delim_join.cpp +137 -0
- package/src/duckdb/src/execution/operator/join/physical_nested_loop_join.cpp +11 -4
- package/src/duckdb/src/execution/operator/join/physical_piecewise_merge_join.cpp +2 -2
- package/src/duckdb/src/execution/operator/join/physical_range_join.cpp +19 -4
- package/src/duckdb/src/execution/operator/join/physical_right_delim_join.cpp +121 -0
- package/src/duckdb/src/execution/operator/persistent/physical_batch_insert.cpp +3 -2
- package/src/duckdb/src/execution/operator/persistent/physical_copy_database.cpp +59 -0
- package/src/duckdb/src/execution/operator/persistent/physical_copy_to_file.cpp +132 -92
- package/src/duckdb/src/execution/operator/persistent/physical_export.cpp +54 -54
- package/src/duckdb/src/execution/operator/persistent/physical_insert.cpp +1 -1
- package/src/duckdb/src/execution/operator/projection/physical_unnest.cpp +4 -0
- package/src/duckdb/src/execution/operator/scan/physical_column_data_scan.cpp +21 -3
- package/src/duckdb/src/execution/operator/schema/physical_alter.cpp +1 -0
- package/src/duckdb/src/execution/operator/schema/physical_attach.cpp +61 -43
- package/src/duckdb/src/execution/operator/schema/physical_create_art_index.cpp +15 -13
- package/src/duckdb/src/execution/operator/schema/physical_create_schema.cpp +1 -0
- package/src/duckdb/src/execution/operator/schema/physical_drop.cpp +10 -0
- package/src/duckdb/src/execution/operator/set/physical_cte.cpp +44 -90
- package/src/duckdb/src/execution/operator/set/physical_recursive_cte.cpp +3 -0
- package/src/duckdb/src/execution/operator/set/physical_union.cpp +8 -4
- package/src/duckdb/src/execution/physical_operator.cpp +3 -1
- package/src/duckdb/src/execution/physical_plan/plan_comparison_join.cpp +30 -143
- package/src/duckdb/src/execution/physical_plan/plan_copy_database.cpp +12 -0
- package/src/duckdb/src/execution/physical_plan/plan_copy_to_file.cpp +11 -4
- package/src/duckdb/src/execution/physical_plan/plan_create_index.cpp +8 -8
- package/src/duckdb/src/execution/physical_plan/plan_create_secret.cpp +11 -0
- package/src/duckdb/src/execution/physical_plan/plan_create_table.cpp +9 -8
- package/src/duckdb/src/execution/physical_plan/plan_cte.cpp +5 -3
- package/src/duckdb/src/execution/physical_plan/plan_delim_join.cpp +15 -6
- package/src/duckdb/src/execution/physical_plan/plan_positional_join.cpp +1 -0
- package/src/duckdb/src/execution/physical_plan/plan_pragma.cpp +1 -1
- package/src/duckdb/src/execution/physical_plan/plan_recursive_cte.cpp +3 -1
- package/src/duckdb/src/execution/physical_plan/plan_set_operation.cpp +90 -12
- package/src/duckdb/src/execution/physical_plan/plan_window.cpp +67 -22
- package/src/duckdb/src/execution/physical_plan_generator.cpp +6 -3
- package/src/duckdb/src/execution/radix_partitioned_hashtable.cpp +163 -32
- package/src/duckdb/src/execution/reservoir_sample.cpp +112 -32
- package/src/duckdb/src/execution/window_executor.cpp +291 -26
- package/src/duckdb/src/execution/window_segment_tree.cpp +958 -114
- package/src/duckdb/src/function/aggregate/distributive/count.cpp +18 -16
- package/src/duckdb/src/function/aggregate/distributive/first.cpp +11 -4
- package/src/duckdb/src/function/aggregate/sorted_aggregate_function.cpp +303 -131
- package/src/duckdb/src/function/cast/array_casts.cpp +226 -0
- package/src/duckdb/src/function/cast/bit_cast.cpp +2 -0
- package/src/duckdb/src/function/cast/cast_function_set.cpp +13 -2
- package/src/duckdb/src/function/cast/decimal_cast.cpp +2 -0
- package/src/duckdb/src/function/cast/default_casts.cpp +4 -1
- package/src/duckdb/src/function/cast/list_casts.cpp +151 -6
- package/src/duckdb/src/function/cast/numeric_casts.cpp +4 -0
- package/src/duckdb/src/function/cast/string_cast.cpp +95 -5
- package/src/duckdb/src/function/cast/struct_cast.cpp +53 -19
- package/src/duckdb/src/function/cast/time_casts.cpp +23 -1
- package/src/duckdb/src/function/cast/union/from_struct.cpp +1 -0
- package/src/duckdb/src/function/cast/union_casts.cpp +4 -3
- package/src/duckdb/src/function/cast/vector_cast_helpers.cpp +8 -4
- package/src/duckdb/src/function/cast_rules.cpp +197 -31
- package/src/duckdb/src/function/compression_config.cpp +4 -0
- package/src/duckdb/src/function/function.cpp +15 -9
- package/src/duckdb/src/function/function_binder.cpp +80 -29
- package/src/duckdb/src/function/function_set.cpp +6 -6
- package/src/duckdb/src/function/pragma/pragma_functions.cpp +10 -8
- package/src/duckdb/src/function/pragma/pragma_queries.cpp +34 -38
- package/src/duckdb/src/function/scalar/compressed_materialization/compress_integral.cpp +12 -0
- package/src/duckdb/src/function/scalar/list/contains_or_position.cpp +10 -1
- package/src/duckdb/src/function/scalar/list/list_concat.cpp +11 -1
- package/src/duckdb/src/function/scalar/list/list_extract.cpp +14 -3
- package/src/duckdb/src/function/scalar/list/list_resize.cpp +4 -0
- package/src/duckdb/src/function/scalar/list/list_select.cpp +176 -0
- package/src/duckdb/src/function/scalar/list/list_zip.cpp +165 -0
- package/src/duckdb/src/function/scalar/nested_functions.cpp +33 -0
- package/src/duckdb/src/function/scalar/operators/add.cpp +53 -6
- package/src/duckdb/src/function/scalar/operators/arithmetic.cpp +48 -14
- package/src/duckdb/src/function/scalar/operators/multiply.cpp +9 -1
- package/src/duckdb/src/function/scalar/operators/subtract.cpp +19 -4
- package/src/duckdb/src/function/scalar/sequence/nextval.cpp +28 -55
- package/src/duckdb/src/function/scalar/strftime_format.cpp +242 -19
- package/src/duckdb/src/function/scalar/string/caseconvert.cpp +2 -2
- package/src/duckdb/src/function/scalar/string/concat.cpp +16 -6
- package/src/duckdb/src/function/scalar/string/length.cpp +124 -24
- package/src/duckdb/src/function/scalar/string/regexp.cpp +27 -27
- package/src/duckdb/src/function/scalar/struct/struct_extract.cpp +64 -15
- package/src/duckdb/src/function/scalar/system/aggregate_export.cpp +4 -3
- package/src/duckdb/src/function/scalar_function.cpp +8 -7
- package/src/duckdb/src/function/table/arrow/arrow_duck_schema.cpp +12 -0
- package/src/duckdb/src/function/table/arrow.cpp +20 -27
- package/src/duckdb/src/function/table/arrow_conversion.cpp +433 -150
- package/src/duckdb/src/function/table/copy_csv.cpp +62 -62
- package/src/duckdb/src/function/table/range.cpp +6 -3
- package/src/duckdb/src/function/table/read_csv.cpp +107 -759
- package/src/duckdb/src/function/table/read_file.cpp +242 -0
- package/src/duckdb/src/function/table/sniff_csv.cpp +275 -0
- package/src/duckdb/src/function/table/system/duckdb_columns.cpp +15 -3
- package/src/duckdb/src/function/table/system/duckdb_databases.cpp +5 -0
- package/src/duckdb/src/function/table/system/duckdb_dependencies.cpp +9 -13
- package/src/duckdb/src/function/table/system/duckdb_functions.cpp +67 -14
- package/src/duckdb/src/function/table/system/duckdb_indexes.cpp +12 -15
- package/src/duckdb/src/function/table/system/duckdb_memory.cpp +63 -0
- package/src/duckdb/src/function/table/system/duckdb_optimizers.cpp +57 -0
- package/src/duckdb/src/function/table/system/duckdb_schemas.cpp +5 -0
- package/src/duckdb/src/function/table/system/duckdb_secrets.cpp +128 -0
- package/src/duckdb/src/function/table/system/duckdb_sequences.cpp +12 -6
- package/src/duckdb/src/function/table/system/duckdb_settings.cpp +0 -1
- package/src/duckdb/src/function/table/system/duckdb_tables.cpp +5 -0
- package/src/duckdb/src/function/table/system/duckdb_types.cpp +6 -0
- package/src/duckdb/src/function/table/system/duckdb_views.cpp +5 -0
- package/src/duckdb/src/function/table/system/pragma_table_info.cpp +166 -64
- package/src/duckdb/src/function/table/system/test_all_types.cpp +2 -1
- package/src/duckdb/src/function/table/system_functions.cpp +3 -2
- package/src/duckdb/src/function/table/table_scan.cpp +50 -110
- package/src/duckdb/src/function/table/version/pragma_version.cpp +4 -44
- package/src/duckdb/src/function/table_function.cpp +2 -2
- package/src/duckdb/src/include/duckdb/catalog/catalog.hpp +4 -3
- package/src/duckdb/src/include/duckdb/catalog/catalog_entry/dependency/dependency_dependent_entry.hpp +27 -0
- package/src/duckdb/src/include/duckdb/catalog/catalog_entry/dependency/dependency_entry.hpp +66 -0
- package/src/duckdb/src/include/duckdb/catalog/catalog_entry/dependency/dependency_subject_entry.hpp +27 -0
- package/src/duckdb/src/include/duckdb/catalog/catalog_entry/duck_index_entry.hpp +25 -5
- package/src/duckdb/src/include/duckdb/catalog/catalog_entry/duck_schema_entry.hpp +3 -1
- package/src/duckdb/src/include/duckdb/catalog/catalog_entry/duck_table_entry.hpp +2 -1
- package/src/duckdb/src/include/duckdb/catalog/catalog_entry/index_catalog_entry.hpp +19 -5
- package/src/duckdb/src/include/duckdb/catalog/catalog_entry/list.hpp +1 -0
- package/src/duckdb/src/include/duckdb/catalog/catalog_entry/scalar_macro_catalog_entry.hpp +2 -0
- package/src/duckdb/src/include/duckdb/catalog/catalog_entry/schema_catalog_entry.hpp +1 -1
- package/src/duckdb/src/include/duckdb/catalog/catalog_entry/sequence_catalog_entry.hpp +26 -11
- package/src/duckdb/src/include/duckdb/catalog/catalog_entry/table_catalog_entry.hpp +1 -0
- package/src/duckdb/src/include/duckdb/catalog/catalog_entry/table_macro_catalog_entry.hpp +2 -0
- package/src/duckdb/src/include/duckdb/catalog/catalog_entry/type_catalog_entry.hpp +1 -0
- package/src/duckdb/src/include/duckdb/catalog/catalog_entry/view_catalog_entry.hpp +2 -0
- package/src/duckdb/src/include/duckdb/catalog/catalog_entry.hpp +15 -0
- package/src/duckdb/src/include/duckdb/catalog/catalog_set.hpp +41 -49
- package/src/duckdb/src/include/duckdb/catalog/catalog_transaction.hpp +1 -0
- package/src/duckdb/src/include/duckdb/catalog/default/builtin_types/types.hpp +3 -1
- package/src/duckdb/src/include/duckdb/catalog/dependency.hpp +120 -8
- package/src/duckdb/src/include/duckdb/catalog/dependency_catalog_set.hpp +32 -0
- package/src/duckdb/src/include/duckdb/catalog/dependency_list.hpp +2 -0
- package/src/duckdb/src/include/duckdb/catalog/dependency_manager.hpp +92 -12
- package/src/duckdb/src/include/duckdb/catalog/standard_entry.hpp +1 -1
- package/src/duckdb/src/include/duckdb/common/adbc/adbc-init.hpp +4 -2
- package/src/duckdb/src/include/duckdb/common/adbc/adbc.h +1153 -12
- package/src/duckdb/src/include/duckdb/common/adbc/adbc.hpp +6 -6
- package/src/duckdb/src/include/duckdb/common/adbc/driver_manager.h +0 -2
- package/src/duckdb/src/include/duckdb/common/adbc/options.h +64 -0
- package/src/duckdb/src/include/duckdb/common/adbc/single_batch_array_stream.hpp +8 -0
- package/src/duckdb/src/include/duckdb/common/arrow/arrow.hpp +25 -6
- package/src/duckdb/src/include/duckdb/common/arrow/arrow_wrapper.hpp +3 -3
- package/src/duckdb/src/include/duckdb/common/arrow/result_arrow_wrapper.hpp +1 -1
- package/src/duckdb/src/include/duckdb/common/bit_utils.hpp +30 -0
- package/src/duckdb/src/include/duckdb/common/bitpacking.hpp +6 -6
- package/src/duckdb/src/include/duckdb/common/case_insensitive_map.hpp +10 -0
- package/src/duckdb/src/include/duckdb/common/constants.hpp +1 -0
- package/src/duckdb/src/include/duckdb/common/enum_util.hpp +75 -19
- package/src/duckdb/src/include/duckdb/common/enums/catalog_type.hpp +11 -1
- package/src/duckdb/src/include/duckdb/common/enums/compression_type.hpp +3 -0
- package/src/duckdb/src/include/duckdb/common/enums/expression_type.hpp +2 -0
- package/src/duckdb/src/include/duckdb/common/enums/index_constraint_type.hpp +35 -0
- package/src/duckdb/src/include/duckdb/common/enums/join_type.hpp +16 -3
- package/src/duckdb/src/include/duckdb/common/enums/logical_operator_type.hpp +6 -5
- package/src/duckdb/src/include/duckdb/common/enums/memory_tag.hpp +32 -0
- package/src/duckdb/src/include/duckdb/common/enums/on_create_conflict.hpp +26 -0
- package/src/duckdb/src/include/duckdb/common/enums/optimizer_type.hpp +2 -0
- package/src/duckdb/src/include/duckdb/common/enums/pending_execution_result.hpp +7 -1
- package/src/duckdb/src/include/duckdb/common/enums/physical_operator_type.hpp +9 -3
- package/src/duckdb/src/include/duckdb/common/enums/statement_type.hpp +6 -5
- package/src/duckdb/src/include/duckdb/common/enums/tableref_type.hpp +3 -2
- package/src/duckdb/src/include/duckdb/common/enums/wal_type.hpp +1 -0
- package/src/duckdb/src/include/duckdb/common/error_data.hpp +72 -0
- package/src/duckdb/src/include/duckdb/common/exception/binder_exception.hpp +47 -0
- package/src/duckdb/src/include/duckdb/common/exception/catalog_exception.hpp +39 -0
- package/src/duckdb/src/include/duckdb/common/exception/conversion_exception.hpp +27 -0
- package/src/duckdb/src/include/duckdb/common/exception/http_exception.hpp +62 -0
- package/src/duckdb/src/include/duckdb/common/exception/list.hpp +6 -0
- package/src/duckdb/src/include/duckdb/common/exception/parser_exception.hpp +29 -0
- package/src/duckdb/src/include/duckdb/common/exception/transaction_exception.hpp +25 -0
- package/src/duckdb/src/include/duckdb/common/exception.hpp +52 -166
- package/src/duckdb/src/include/duckdb/common/exception_format_value.hpp +7 -4
- package/src/duckdb/src/include/duckdb/common/extra_type_info.hpp +53 -1
- package/src/duckdb/src/include/duckdb/common/helper.hpp +13 -3
- package/src/duckdb/src/include/duckdb/common/http_state.hpp +18 -4
- package/src/duckdb/src/include/duckdb/common/hugeint.hpp +5 -1
- package/src/duckdb/src/include/duckdb/common/limits.hpp +19 -1
- package/src/duckdb/src/include/duckdb/common/local_file_system.hpp +1 -0
- package/src/duckdb/src/include/duckdb/common/multi_file_reader.hpp +7 -2
- package/src/duckdb/src/include/duckdb/common/numeric_utils.hpp +16 -3
- package/src/duckdb/src/include/duckdb/common/operator/add.hpp +13 -2
- package/src/duckdb/src/include/duckdb/common/operator/cast_operators.hpp +114 -5
- package/src/duckdb/src/include/duckdb/common/operator/comparison_operators.hpp +0 -4
- package/src/duckdb/src/include/duckdb/common/operator/convert_to_string.hpp +2 -0
- package/src/duckdb/src/include/duckdb/common/operator/decimal_cast_operators.hpp +29 -0
- package/src/duckdb/src/include/duckdb/common/operator/double_cast_operator.hpp +52 -0
- package/src/duckdb/src/include/duckdb/common/operator/integer_cast_operator.hpp +459 -0
- package/src/duckdb/src/include/duckdb/common/operator/multiply.hpp +2 -0
- package/src/duckdb/src/include/duckdb/common/operator/numeric_cast.hpp +136 -0
- package/src/duckdb/src/include/duckdb/common/operator/string_cast.hpp +2 -0
- package/src/duckdb/src/include/duckdb/common/operator/subtract.hpp +7 -1
- package/src/duckdb/src/include/duckdb/common/optional_idx.hpp +7 -5
- package/src/duckdb/src/include/duckdb/common/platform.h +53 -0
- package/src/duckdb/src/include/duckdb/common/progress_bar/display/terminal_progress_bar_display.hpp +5 -5
- package/src/duckdb/src/include/duckdb/common/progress_bar/progress_bar.hpp +22 -6
- package/src/duckdb/src/include/duckdb/common/radix.hpp +6 -0
- package/src/duckdb/src/include/duckdb/common/row_operations/row_operations.hpp +20 -6
- package/src/duckdb/src/include/duckdb/common/serializer/binary_deserializer.hpp +1 -0
- package/src/duckdb/src/include/duckdb/common/serializer/binary_serializer.hpp +1 -0
- package/src/duckdb/src/include/duckdb/common/serializer/deserializer.hpp +43 -4
- package/src/duckdb/src/include/duckdb/common/serializer/serialization_traits.hpp +1 -0
- package/src/duckdb/src/include/duckdb/common/serializer/serializer.hpp +15 -0
- package/src/duckdb/src/include/duckdb/common/sort/comparators.hpp +2 -0
- package/src/duckdb/src/include/duckdb/common/sort/partition_state.hpp +12 -2
- package/src/duckdb/src/include/duckdb/common/sort/sort.hpp +81 -0
- package/src/duckdb/src/include/duckdb/common/sort/sorted_block.hpp +0 -78
- package/src/duckdb/src/include/duckdb/common/string_util.hpp +23 -1
- package/src/duckdb/src/include/duckdb/common/type_util.hpp +5 -1
- package/src/duckdb/src/include/duckdb/common/types/cast_helpers.hpp +26 -3
- package/src/duckdb/src/include/duckdb/common/types/conflict_manager.hpp +8 -0
- package/src/duckdb/src/include/duckdb/common/types/data_chunk.hpp +3 -0
- package/src/duckdb/src/include/duckdb/common/types/date.hpp +3 -0
- package/src/duckdb/src/include/duckdb/common/types/datetime.hpp +5 -3
- package/src/duckdb/src/include/duckdb/common/types/hash.hpp +2 -0
- package/src/duckdb/src/include/duckdb/common/types/hugeint.hpp +81 -15
- package/src/duckdb/src/include/duckdb/common/types/interval.hpp +57 -29
- package/src/duckdb/src/include/duckdb/common/types/list_segment.hpp +1 -1
- package/src/duckdb/src/include/duckdb/common/types/row/partitioned_tuple_data.hpp +4 -2
- package/src/duckdb/src/include/duckdb/common/types/row/row_data_collection.hpp +2 -2
- package/src/duckdb/src/include/duckdb/common/types/row/tuple_data_collection.hpp +26 -22
- package/src/duckdb/src/include/duckdb/common/types/row/tuple_data_states.hpp +7 -0
- package/src/duckdb/src/include/duckdb/common/types/string_type.hpp +7 -5
- package/src/duckdb/src/include/duckdb/common/types/time.hpp +6 -2
- package/src/duckdb/src/include/duckdb/common/types/timestamp.hpp +2 -0
- package/src/duckdb/src/include/duckdb/common/types/uhugeint.hpp +216 -0
- package/src/duckdb/src/include/duckdb/common/types/validity_mask.hpp +18 -10
- package/src/duckdb/src/include/duckdb/common/types/value.hpp +31 -0
- package/src/duckdb/src/include/duckdb/common/types/vector.hpp +18 -2
- package/src/duckdb/src/include/duckdb/common/types/vector_buffer.hpp +22 -1
- package/src/duckdb/src/include/duckdb/common/types.hpp +151 -49
- package/src/duckdb/src/include/duckdb/common/uhugeint.hpp +81 -0
- package/src/duckdb/src/include/duckdb/common/vector_operations/aggregate_executor.hpp +70 -6
- package/src/duckdb/src/include/duckdb/common/vector_size.hpp +6 -6
- package/src/duckdb/src/include/duckdb/core_functions/aggregate/distributive_functions.hpp +29 -2
- package/src/duckdb/src/include/duckdb/core_functions/lambda_functions.hpp +131 -0
- package/src/duckdb/src/include/duckdb/core_functions/scalar/array_functions.hpp +69 -0
- package/src/duckdb/src/include/duckdb/core_functions/scalar/blob_functions.hpp +9 -0
- package/src/duckdb/src/include/duckdb/core_functions/scalar/date_functions.hpp +40 -4
- package/src/duckdb/src/include/duckdb/core_functions/scalar/list_functions.hpp +42 -0
- package/src/duckdb/src/include/duckdb/core_functions/scalar/secret_functions.hpp +27 -0
- package/src/duckdb/src/include/duckdb/core_functions/scalar/string_functions.hpp +56 -2
- package/src/duckdb/src/include/duckdb/core_functions/to_interval.hpp +29 -0
- package/src/duckdb/src/include/duckdb/execution/aggregate_hashtable.hpp +2 -2
- package/src/duckdb/src/include/duckdb/execution/executor.hpp +11 -13
- package/src/duckdb/src/include/duckdb/execution/index/art/art.hpp +34 -19
- package/src/duckdb/src/include/duckdb/execution/index/fixed_size_allocator.hpp +18 -14
- package/src/duckdb/src/include/duckdb/execution/index/fixed_size_buffer.hpp +2 -1
- package/src/duckdb/src/include/duckdb/execution/index/index_type.hpp +57 -0
- package/src/duckdb/src/include/duckdb/execution/index/index_type_set.hpp +29 -0
- package/src/duckdb/src/include/duckdb/execution/index/unknown_index.hpp +65 -0
- package/src/duckdb/src/include/duckdb/execution/join_hashtable.hpp +35 -24
- package/src/duckdb/src/include/duckdb/execution/merge_sort_tree.hpp +630 -0
- package/src/duckdb/src/include/duckdb/execution/operator/aggregate/physical_hash_aggregate.hpp +2 -0
- package/src/duckdb/src/include/duckdb/execution/operator/aggregate/physical_window.hpp +3 -2
- package/src/duckdb/src/include/duckdb/execution/operator/csv_scanner/buffer_manager/csv_buffer.hpp +103 -0
- package/src/duckdb/src/include/duckdb/execution/operator/csv_scanner/buffer_manager/csv_buffer_manager.hpp +74 -0
- package/src/duckdb/src/include/duckdb/execution/operator/csv_scanner/buffer_manager/csv_file_handle.hpp +60 -0
- package/src/duckdb/src/include/duckdb/execution/operator/csv_scanner/options/csv_option.hpp +155 -0
- package/src/duckdb/src/include/duckdb/execution/operator/csv_scanner/options/csv_reader_options.hpp +163 -0
- package/src/duckdb/src/include/duckdb/execution/operator/csv_scanner/options/state_machine_options.hpp +35 -0
- package/src/duckdb/src/include/duckdb/execution/operator/csv_scanner/scanner/base_scanner.hpp +228 -0
- package/src/duckdb/src/include/duckdb/execution/operator/csv_scanner/scanner/column_count_scanner.hpp +70 -0
- package/src/duckdb/src/include/duckdb/execution/operator/csv_scanner/scanner/scanner_boundary.hpp +93 -0
- package/src/duckdb/src/include/duckdb/execution/operator/csv_scanner/scanner/skip_scanner.hpp +60 -0
- package/src/duckdb/src/include/duckdb/execution/operator/csv_scanner/scanner/string_value_scanner.hpp +197 -0
- package/src/duckdb/src/include/duckdb/execution/operator/csv_scanner/sniffer/csv_sniffer.hpp +189 -0
- package/src/duckdb/src/include/duckdb/execution/operator/csv_scanner/sniffer/quote_rules.hpp +21 -0
- package/src/duckdb/src/include/duckdb/execution/operator/csv_scanner/state_machine/csv_state.hpp +30 -0
- package/src/duckdb/src/include/duckdb/execution/operator/csv_scanner/state_machine/csv_state_machine.hpp +99 -0
- package/src/duckdb/src/include/duckdb/execution/operator/csv_scanner/state_machine/csv_state_machine_cache.hpp +87 -0
- package/src/duckdb/src/include/duckdb/execution/operator/csv_scanner/table_function/csv_file_scanner.hpp +70 -0
- package/src/duckdb/src/include/duckdb/execution/operator/csv_scanner/table_function/global_csv_state.hpp +80 -0
- package/src/duckdb/src/include/duckdb/execution/operator/csv_scanner/util/csv_casting.hpp +137 -0
- package/src/duckdb/src/include/duckdb/execution/operator/csv_scanner/util/csv_error.hpp +104 -0
- package/src/duckdb/src/include/duckdb/execution/operator/helper/physical_batch_collector.hpp +0 -4
- package/src/duckdb/src/include/duckdb/execution/operator/helper/physical_buffered_collector.hpp +37 -0
- package/src/duckdb/src/include/duckdb/execution/operator/helper/physical_create_secret.hpp +38 -0
- package/src/duckdb/src/include/duckdb/execution/operator/helper/physical_pragma.hpp +4 -7
- package/src/duckdb/src/include/duckdb/execution/operator/helper/physical_reservoir_sample.hpp +6 -2
- package/src/duckdb/src/include/duckdb/execution/operator/join/physical_blockwise_nl_join.hpp +1 -2
- package/src/duckdb/src/include/duckdb/execution/operator/join/physical_delim_join.hpp +5 -18
- package/src/duckdb/src/include/duckdb/execution/operator/join/physical_hash_join.hpp +14 -5
- package/src/duckdb/src/include/duckdb/execution/operator/join/physical_iejoin.hpp +2 -2
- package/src/duckdb/src/include/duckdb/execution/operator/join/physical_join.hpp +2 -1
- package/src/duckdb/src/include/duckdb/execution/operator/join/physical_left_delim_join.hpp +37 -0
- package/src/duckdb/src/include/duckdb/execution/operator/join/physical_nested_loop_join.hpp +1 -2
- package/src/duckdb/src/include/duckdb/execution/operator/join/physical_piecewise_merge_join.hpp +1 -1
- package/src/duckdb/src/include/duckdb/execution/operator/join/physical_range_join.hpp +1 -1
- package/src/duckdb/src/include/duckdb/execution/operator/join/physical_right_delim_join.hpp +37 -0
- package/src/duckdb/src/include/duckdb/execution/operator/order/physical_order.hpp +0 -1
- package/src/duckdb/src/include/duckdb/execution/operator/order/physical_top_n.hpp +0 -1
- package/src/duckdb/src/include/duckdb/execution/operator/persistent/physical_copy_database.hpp +35 -0
- package/src/duckdb/src/include/duckdb/execution/operator/persistent/physical_copy_to_file.hpp +8 -3
- package/src/duckdb/src/include/duckdb/execution/operator/persistent/physical_export.hpp +14 -0
- package/src/duckdb/src/include/duckdb/execution/operator/scan/physical_column_data_scan.hpp +1 -4
- package/src/duckdb/src/include/duckdb/execution/operator/scan/physical_expression_scan.hpp +0 -1
- package/src/duckdb/src/include/duckdb/execution/operator/set/physical_cte.hpp +17 -12
- package/src/duckdb/src/include/duckdb/execution/operator/set/physical_recursive_cte.hpp +4 -0
- package/src/duckdb/src/include/duckdb/execution/operator/set/physical_union.hpp +3 -1
- package/src/duckdb/src/include/duckdb/execution/physical_operator.hpp +2 -1
- package/src/duckdb/src/include/duckdb/execution/physical_plan_generator.hpp +6 -2
- package/src/duckdb/src/include/duckdb/execution/radix_partitioned_hashtable.hpp +3 -1
- package/src/duckdb/src/include/duckdb/execution/reservoir_sample.hpp +32 -18
- package/src/duckdb/src/include/duckdb/execution/task_error_manager.hpp +57 -0
- package/src/duckdb/src/include/duckdb/execution/window_executor.hpp +2 -0
- package/src/duckdb/src/include/duckdb/execution/window_segment_tree.hpp +101 -19
- package/src/duckdb/src/include/duckdb/function/aggregate_function.hpp +46 -14
- package/src/duckdb/src/include/duckdb/function/aggregate_state.hpp +6 -2
- package/src/duckdb/src/include/duckdb/function/built_in_functions.hpp +1 -0
- package/src/duckdb/src/include/duckdb/function/cast/bound_cast_data.hpp +26 -1
- package/src/duckdb/src/include/duckdb/function/cast/cast_function_set.hpp +3 -0
- package/src/duckdb/src/include/duckdb/function/cast/default_casts.hpp +1 -0
- package/src/duckdb/src/include/duckdb/function/cast/vector_cast_helpers.hpp +7 -1
- package/src/duckdb/src/include/duckdb/function/compression/compression.hpp +10 -0
- package/src/duckdb/src/include/duckdb/function/copy_function.hpp +16 -4
- package/src/duckdb/src/include/duckdb/function/function.hpp +12 -7
- package/src/duckdb/src/include/duckdb/function/function_binder.hpp +15 -12
- package/src/duckdb/src/include/duckdb/function/function_serialization.hpp +4 -3
- package/src/duckdb/src/include/duckdb/function/macro_function.hpp +3 -3
- package/src/duckdb/src/include/duckdb/function/pragma/pragma_functions.hpp +4 -1
- package/src/duckdb/src/include/duckdb/function/scalar/list/contains_or_position.hpp +3 -0
- package/src/duckdb/src/include/duckdb/function/scalar/nested_functions.hpp +21 -1
- package/src/duckdb/src/include/duckdb/function/scalar/sequence_functions.hpp +22 -0
- package/src/duckdb/src/include/duckdb/function/scalar/strftime_format.hpp +16 -2
- package/src/duckdb/src/include/duckdb/function/scalar_function.hpp +22 -8
- package/src/duckdb/src/include/duckdb/function/table/arrow/arrow_duck_schema.hpp +6 -0
- package/src/duckdb/src/include/duckdb/function/table/arrow.hpp +35 -3
- package/src/duckdb/src/include/duckdb/function/table/list.hpp +1 -0
- package/src/duckdb/src/include/duckdb/function/table/range.hpp +12 -0
- package/src/duckdb/src/include/duckdb/function/table/read_csv.hpp +14 -16
- package/src/duckdb/src/include/duckdb/function/table/system_functions.hpp +12 -8
- package/src/duckdb/src/include/duckdb/function/table/table_scan.hpp +0 -2
- package/src/duckdb/src/include/duckdb/function/table_function.hpp +8 -3
- package/src/duckdb/src/include/duckdb/main/appender.hpp +3 -1
- package/src/duckdb/src/include/duckdb/main/attached_database.hpp +3 -2
- package/src/duckdb/src/include/duckdb/main/buffered_data/buffered_data.hpp +89 -0
- package/src/duckdb/src/include/duckdb/main/buffered_data/simple_buffered_data.hpp +53 -0
- package/src/duckdb/src/include/duckdb/main/capi/capi_internal.hpp +2 -1
- package/src/duckdb/src/include/duckdb/main/capi/cast/generic.hpp +2 -0
- package/src/duckdb/src/include/duckdb/main/chunk_scan_state/query_result.hpp +4 -4
- package/src/duckdb/src/include/duckdb/main/chunk_scan_state.hpp +3 -3
- package/src/duckdb/src/include/duckdb/main/client_config.hpp +8 -10
- package/src/duckdb/src/include/duckdb/main/client_context.hpp +22 -23
- package/src/duckdb/src/include/duckdb/main/client_context_state.hpp +37 -0
- package/src/duckdb/src/include/duckdb/main/client_data.hpp +1 -7
- package/src/duckdb/src/include/duckdb/main/config.hpp +24 -7
- package/src/duckdb/src/include/duckdb/main/connection.hpp +8 -1
- package/src/duckdb/src/include/duckdb/main/connection_manager.hpp +17 -26
- package/src/duckdb/src/include/duckdb/main/database.hpp +4 -2
- package/src/duckdb/src/include/duckdb/main/database_manager.hpp +39 -7
- package/src/duckdb/src/include/duckdb/main/database_path_and_type.hpp +5 -4
- package/src/duckdb/src/include/duckdb/main/error_manager.hpp +4 -1
- package/src/duckdb/src/include/duckdb/main/extension_entries.hpp +203 -197
- package/src/duckdb/src/include/duckdb/main/extension_helper.hpp +42 -16
- package/src/duckdb/src/include/duckdb/main/extension_util.hpp +8 -1
- package/src/duckdb/src/include/duckdb/main/materialized_query_result.hpp +1 -1
- package/src/duckdb/src/include/duckdb/main/pending_query_result.hpp +5 -2
- package/src/duckdb/src/include/duckdb/main/prepared_statement.hpp +4 -4
- package/src/duckdb/src/include/duckdb/main/prepared_statement_data.hpp +2 -0
- package/src/duckdb/src/include/duckdb/main/query_profiler.hpp +0 -32
- package/src/duckdb/src/include/duckdb/main/query_result.hpp +13 -12
- package/src/duckdb/src/include/duckdb/main/relation/read_csv_relation.hpp +6 -6
- package/src/duckdb/src/include/duckdb/main/relation/setop_relation.hpp +3 -1
- package/src/duckdb/src/include/duckdb/main/secret/secret.hpp +206 -0
- package/src/duckdb/src/include/duckdb/main/secret/secret_manager.hpp +211 -0
- package/src/duckdb/src/include/duckdb/main/secret/secret_storage.hpp +164 -0
- package/src/duckdb/src/include/duckdb/main/settings.hpp +52 -13
- package/src/duckdb/src/include/duckdb/main/stream_query_result.hpp +9 -1
- package/src/duckdb/src/include/duckdb/optimizer/deliminator.hpp +4 -1
- package/src/duckdb/src/include/duckdb/optimizer/filter_pushdown.hpp +2 -0
- package/src/duckdb/src/include/duckdb/optimizer/join_order/join_node.hpp +1 -1
- package/src/duckdb/src/include/duckdb/optimizer/join_order/join_relation.hpp +2 -0
- package/src/duckdb/src/include/duckdb/optimizer/join_order/query_graph_manager.hpp +3 -0
- package/src/duckdb/src/include/duckdb/optimizer/join_order/relation_statistics_helper.hpp +1 -0
- package/src/duckdb/src/include/duckdb/parallel/event.hpp +2 -2
- package/src/duckdb/src/include/duckdb/parallel/meta_pipeline.hpp +14 -22
- package/src/duckdb/src/include/duckdb/parallel/pipeline.hpp +20 -0
- package/src/duckdb/src/include/duckdb/parallel/pipeline_executor.hpp +3 -5
- package/src/duckdb/src/include/duckdb/parallel/task.hpp +7 -0
- package/src/duckdb/src/include/duckdb/parallel/task_scheduler.hpp +10 -4
- package/src/duckdb/src/include/duckdb/parser/base_expression.hpp +3 -0
- package/src/duckdb/src/include/duckdb/parser/column_definition.hpp +8 -1
- package/src/duckdb/src/include/duckdb/parser/expression/function_expression.hpp +11 -4
- package/src/duckdb/src/include/duckdb/parser/expression/lambda_expression.hpp +16 -9
- package/src/duckdb/src/include/duckdb/parser/expression/lambdaref_expression.hpp +47 -0
- package/src/duckdb/src/include/duckdb/parser/expression/list.hpp +1 -0
- package/src/duckdb/src/include/duckdb/parser/expression/window_expression.hpp +29 -2
- package/src/duckdb/src/include/duckdb/parser/parsed_data/alter_info.hpp +2 -1
- package/src/duckdb/src/include/duckdb/parser/parsed_data/alter_table_info.hpp +47 -2
- package/src/duckdb/src/include/duckdb/parser/parsed_data/attach_info.hpp +3 -0
- package/src/duckdb/src/include/duckdb/parser/parsed_data/bound_pragma_info.hpp +29 -0
- package/src/duckdb/src/include/duckdb/parser/parsed_data/comment_on_info.hpp +45 -0
- package/src/duckdb/src/include/duckdb/parser/parsed_data/create_index_info.hpp +21 -22
- package/src/duckdb/src/include/duckdb/parser/parsed_data/create_info.hpp +5 -11
- package/src/duckdb/src/include/duckdb/parser/parsed_data/create_schema_info.hpp +23 -0
- package/src/duckdb/src/include/duckdb/parser/parsed_data/create_secret_info.hpp +47 -0
- package/src/duckdb/src/include/duckdb/parser/parsed_data/create_table_info.hpp +3 -1
- package/src/duckdb/src/include/duckdb/parser/parsed_data/create_type_info.hpp +2 -0
- package/src/duckdb/src/include/duckdb/parser/parsed_data/create_view_info.hpp +4 -0
- package/src/duckdb/src/include/duckdb/parser/parsed_data/drop_info.hpp +6 -1
- package/src/duckdb/src/include/duckdb/parser/parsed_data/extra_drop_info.hpp +66 -0
- package/src/duckdb/src/include/duckdb/parser/parsed_data/parse_info.hpp +3 -1
- package/src/duckdb/src/include/duckdb/parser/parsed_data/pragma_info.hpp +8 -4
- package/src/duckdb/src/include/duckdb/parser/parsed_expression.hpp +1 -3
- package/src/duckdb/src/include/duckdb/parser/parser_extension.hpp +2 -0
- package/src/duckdb/src/include/duckdb/parser/qualified_name.hpp +1 -1
- package/src/duckdb/src/include/duckdb/parser/query_error_context.hpp +5 -22
- package/src/duckdb/src/include/duckdb/parser/query_node/set_operation_node.hpp +2 -0
- package/src/duckdb/src/include/duckdb/parser/statement/copy_database_statement.hpp +40 -0
- package/src/duckdb/src/include/duckdb/parser/statement/list.hpp +1 -1
- package/src/duckdb/src/include/duckdb/parser/statement/set_statement.hpp +4 -3
- package/src/duckdb/src/include/duckdb/parser/tableref/emptytableref.hpp +2 -2
- package/src/duckdb/src/include/duckdb/parser/tableref/list.hpp +1 -0
- package/src/duckdb/src/include/duckdb/parser/tableref/showref.hpp +47 -0
- package/src/duckdb/src/include/duckdb/parser/tableref.hpp +2 -1
- package/src/duckdb/src/include/duckdb/parser/tokens.hpp +2 -1
- package/src/duckdb/src/include/duckdb/parser/transformer.hpp +20 -3
- package/src/duckdb/src/include/duckdb/planner/bind_context.hpp +5 -1
- package/src/duckdb/src/include/duckdb/planner/binder.hpp +24 -27
- package/src/duckdb/src/include/duckdb/planner/bound_result_modifier.hpp +4 -0
- package/src/duckdb/src/include/duckdb/planner/expression/bound_cast_expression.hpp +4 -0
- package/src/duckdb/src/include/duckdb/planner/expression/bound_comparison_expression.hpp +4 -1
- package/src/duckdb/src/include/duckdb/planner/expression/bound_function_expression.hpp +2 -1
- package/src/duckdb/src/include/duckdb/planner/expression/bound_lambda_expression.hpp +4 -2
- package/src/duckdb/src/include/duckdb/planner/expression/bound_lambdaref_expression.hpp +5 -6
- package/src/duckdb/src/include/duckdb/planner/expression/bound_window_expression.hpp +11 -0
- package/src/duckdb/src/include/duckdb/planner/expression.hpp +2 -1
- package/src/duckdb/src/include/duckdb/planner/expression_binder/column_alias_binder.hpp +2 -2
- package/src/duckdb/src/include/duckdb/planner/expression_binder/index_binder.hpp +3 -2
- package/src/duckdb/src/include/duckdb/planner/expression_binder/order_binder.hpp +2 -1
- package/src/duckdb/src/include/duckdb/planner/expression_binder/table_function_binder.hpp +2 -1
- package/src/duckdb/src/include/duckdb/planner/expression_binder.hpp +65 -22
- package/src/duckdb/src/include/duckdb/planner/filter/struct_filter.hpp +41 -0
- package/src/duckdb/src/include/duckdb/planner/logical_tokens.hpp +2 -1
- package/src/duckdb/src/include/duckdb/planner/operator/list.hpp +2 -1
- package/src/duckdb/src/include/duckdb/planner/operator/logical_comparison_join.hpp +2 -0
- package/src/duckdb/src/include/duckdb/planner/operator/logical_copy_database.hpp +45 -0
- package/src/duckdb/src/include/duckdb/planner/operator/logical_copy_to_file.hpp +3 -0
- package/src/duckdb/src/include/duckdb/planner/operator/logical_create_secret.hpp +43 -0
- package/src/duckdb/src/include/duckdb/planner/operator/logical_cteref.hpp +3 -2
- package/src/duckdb/src/include/duckdb/planner/operator/logical_pragma.hpp +5 -10
- package/src/duckdb/src/include/duckdb/planner/operator/logical_recursive_cte.hpp +2 -0
- package/src/duckdb/src/include/duckdb/planner/operator/logical_set_operation.hpp +11 -4
- package/src/duckdb/src/include/duckdb/planner/parsed_data/bound_create_table_info.hpp +3 -3
- package/src/duckdb/src/include/duckdb/planner/pragma_handler.hpp +1 -1
- package/src/duckdb/src/include/duckdb/planner/query_node/bound_set_operation_node.hpp +2 -0
- package/src/duckdb/src/include/duckdb/planner/subquery/flatten_dependent_join.hpp +3 -0
- package/src/duckdb/src/include/duckdb/planner/subquery/rewrite_cte_scan.hpp +29 -0
- package/src/duckdb/src/include/duckdb/planner/table_binding.hpp +9 -7
- package/src/duckdb/src/include/duckdb/planner/table_filter.hpp +2 -1
- package/src/duckdb/src/include/duckdb/planner/tableref/bound_dummytableref.hpp +3 -2
- package/src/duckdb/src/include/duckdb/storage/buffer/block_handle.hpp +9 -5
- package/src/duckdb/src/include/duckdb/storage/buffer/buffer_pool.hpp +23 -6
- package/src/duckdb/src/include/duckdb/storage/buffer/temporary_file_information.hpp +7 -0
- package/src/duckdb/src/include/duckdb/storage/buffer_manager.hpp +11 -4
- package/src/duckdb/src/include/duckdb/storage/checkpoint/row_group_writer.hpp +0 -3
- package/src/duckdb/src/include/duckdb/storage/checkpoint/string_checkpoint_state.hpp +1 -1
- package/src/duckdb/src/include/duckdb/storage/checkpoint/table_data_writer.hpp +7 -7
- package/src/duckdb/src/include/duckdb/storage/checkpoint_manager.hpp +1 -1
- package/src/duckdb/src/include/duckdb/storage/compression/alp/algorithm/alp.hpp +408 -0
- package/src/duckdb/src/include/duckdb/storage/compression/alp/alp_analyze.hpp +173 -0
- package/src/duckdb/src/include/duckdb/storage/compression/alp/alp_compress.hpp +283 -0
- package/src/duckdb/src/include/duckdb/storage/compression/alp/alp_constants.hpp +134 -0
- package/src/duckdb/src/include/duckdb/storage/compression/alp/alp_fetch.hpp +42 -0
- package/src/duckdb/src/include/duckdb/storage/compression/alp/alp_scan.hpp +244 -0
- package/src/duckdb/src/include/duckdb/storage/compression/alp/alp_utils.hpp +103 -0
- package/src/duckdb/src/include/duckdb/storage/compression/alprd/algorithm/alprd.hpp +235 -0
- package/src/duckdb/src/include/duckdb/storage/compression/alprd/alprd_analyze.hpp +134 -0
- package/src/duckdb/src/include/duckdb/storage/compression/alprd/alprd_compress.hpp +301 -0
- package/src/duckdb/src/include/duckdb/storage/compression/alprd/alprd_constants.hpp +35 -0
- package/src/duckdb/src/include/duckdb/storage/compression/alprd/alprd_fetch.hpp +41 -0
- package/src/duckdb/src/include/duckdb/storage/compression/alprd/alprd_scan.hpp +252 -0
- package/src/duckdb/src/include/duckdb/storage/compression/chimp/chimp_analyze.hpp +7 -103
- package/src/duckdb/src/include/duckdb/storage/compression/chimp/chimp_compress.hpp +5 -234
- package/src/duckdb/src/include/duckdb/storage/compression/chimp/chimp_scan.hpp +2 -2
- package/src/duckdb/src/include/duckdb/storage/compression/patas/patas_analyze.hpp +7 -107
- package/src/duckdb/src/include/duckdb/storage/compression/patas/patas_compress.hpp +5 -184
- package/src/duckdb/src/include/duckdb/storage/data_table.hpp +12 -17
- package/src/duckdb/src/include/duckdb/storage/database_size.hpp +1 -0
- package/src/duckdb/src/include/duckdb/storage/index.hpp +40 -42
- package/src/duckdb/src/include/duckdb/storage/index_storage_info.hpp +77 -0
- package/src/duckdb/src/include/duckdb/storage/metadata/metadata_manager.hpp +6 -2
- package/src/duckdb/src/include/duckdb/storage/object_cache.hpp +0 -1
- package/src/duckdb/src/include/duckdb/storage/partial_block_manager.hpp +12 -6
- package/src/duckdb/src/include/duckdb/storage/segment/uncompressed.hpp +8 -3
- package/src/duckdb/src/include/duckdb/storage/standard_buffer_manager.hpp +17 -17
- package/src/duckdb/src/include/duckdb/storage/statistics/array_stats.hpp +40 -0
- package/src/duckdb/src/include/duckdb/storage/statistics/base_statistics.hpp +12 -3
- package/src/duckdb/src/include/duckdb/storage/statistics/numeric_stats_union.hpp +3 -0
- package/src/duckdb/src/include/duckdb/storage/storage_extension.hpp +3 -2
- package/src/duckdb/src/include/duckdb/storage/storage_info.hpp +49 -24
- package/src/duckdb/src/include/duckdb/storage/storage_manager.hpp +8 -4
- package/src/duckdb/src/include/duckdb/storage/table/array_column_data.hpp +67 -0
- package/src/duckdb/src/include/duckdb/storage/table/column_data.hpp +3 -3
- package/src/duckdb/src/include/duckdb/storage/table/column_data_checkpointer.hpp +1 -0
- package/src/duckdb/src/include/duckdb/storage/table/column_segment.hpp +1 -2
- package/src/duckdb/src/include/duckdb/storage/table/data_table_info.hpp +8 -3
- package/src/duckdb/src/include/duckdb/storage/table/list_column_data.hpp +1 -1
- package/src/duckdb/src/include/duckdb/storage/table/row_group.hpp +4 -2
- package/src/duckdb/src/include/duckdb/storage/table/row_group_collection.hpp +7 -0
- package/src/duckdb/src/include/duckdb/storage/table/scan_state.hpp +12 -1
- package/src/duckdb/src/include/duckdb/storage/table/standard_column_data.hpp +1 -1
- package/src/duckdb/src/include/duckdb/storage/table/struct_column_data.hpp +1 -1
- package/src/duckdb/src/include/duckdb/storage/table/table_index_list.hpp +16 -12
- package/src/duckdb/src/include/duckdb/storage/table/table_statistics.hpp +4 -0
- package/src/duckdb/src/include/duckdb/storage/table_storage_info.hpp +6 -9
- package/src/duckdb/src/include/duckdb/storage/temporary_memory_manager.hpp +119 -0
- package/src/duckdb/src/include/duckdb/storage/write_ahead_log.hpp +13 -55
- package/src/duckdb/src/include/duckdb/transaction/duck_transaction.hpp +1 -1
- package/src/duckdb/src/include/duckdb/transaction/duck_transaction_manager.hpp +4 -5
- package/src/duckdb/src/include/duckdb/transaction/local_storage.hpp +2 -2
- package/src/duckdb/src/include/duckdb/transaction/meta_transaction.hpp +6 -3
- package/src/duckdb/src/include/duckdb/transaction/transaction_context.hpp +4 -4
- package/src/duckdb/src/include/duckdb/transaction/transaction_manager.hpp +3 -3
- package/src/duckdb/src/include/duckdb/verification/fetch_row_verifier.hpp +25 -0
- package/src/duckdb/src/include/duckdb/verification/statement_verifier.hpp +5 -0
- package/src/duckdb/src/include/duckdb.h +571 -143
- package/src/duckdb/src/main/appender.cpp +17 -2
- package/src/duckdb/src/main/attached_database.cpp +24 -12
- package/src/duckdb/src/main/buffered_data/simple_buffered_data.cpp +96 -0
- package/src/duckdb/src/main/capi/appender-c.cpp +42 -3
- package/src/duckdb/src/main/capi/arrow-c.cpp +32 -9
- package/src/duckdb/src/main/capi/datetime-c.cpp +22 -0
- package/src/duckdb/src/main/capi/duckdb-c.cpp +14 -4
- package/src/duckdb/src/main/capi/duckdb_value-c.cpp +66 -2
- package/src/duckdb/src/main/capi/helper-c.cpp +76 -2
- package/src/duckdb/src/main/capi/hugeint-c.cpp +23 -0
- package/src/duckdb/src/main/capi/logical_types-c.cpp +27 -3
- package/src/duckdb/src/main/capi/pending-c.cpp +43 -9
- package/src/duckdb/src/main/capi/prepared-c.cpp +38 -2
- package/src/duckdb/src/main/capi/result-c.cpp +54 -3
- package/src/duckdb/src/main/capi/table_function-c.cpp +4 -4
- package/src/duckdb/src/main/capi/value-c.cpp +10 -0
- package/src/duckdb/src/main/chunk_scan_state/query_result.cpp +3 -3
- package/src/duckdb/src/main/client_context.cpp +259 -250
- package/src/duckdb/src/main/client_data.cpp +0 -1
- package/src/duckdb/src/main/client_verify.cpp +26 -8
- package/src/duckdb/src/main/config.cpp +34 -13
- package/src/duckdb/src/main/connection.cpp +27 -6
- package/src/duckdb/src/main/connection_manager.cpp +54 -0
- package/src/duckdb/src/main/database.cpp +44 -39
- package/src/duckdb/src/main/database_manager.cpp +106 -8
- package/src/duckdb/src/main/database_path_and_type.cpp +27 -8
- package/src/duckdb/src/main/db_instance_cache.cpp +4 -4
- package/src/duckdb/src/main/error_manager.cpp +12 -3
- package/src/duckdb/src/main/extension/extension_alias.cpp +2 -2
- package/src/duckdb/src/main/extension/extension_helper.cpp +15 -16
- package/src/duckdb/src/main/extension/extension_install.cpp +33 -24
- package/src/duckdb/src/main/extension/extension_load.cpp +22 -21
- package/src/duckdb/src/main/extension/extension_util.cpp +12 -0
- package/src/duckdb/src/main/materialized_query_result.cpp +1 -1
- package/src/duckdb/src/main/pending_query_result.cpp +25 -8
- package/src/duckdb/src/main/prepared_statement.cpp +5 -5
- package/src/duckdb/src/main/prepared_statement_data.cpp +8 -1
- package/src/duckdb/src/main/query_profiler.cpp +11 -11
- package/src/duckdb/src/main/query_result.cpp +32 -6
- package/src/duckdb/src/main/relation/cross_product_relation.cpp +1 -1
- package/src/duckdb/src/main/relation/join_relation.cpp +2 -2
- package/src/duckdb/src/main/relation/read_csv_relation.cpp +38 -32
- package/src/duckdb/src/main/relation/setop_relation.cpp +5 -3
- package/src/duckdb/src/main/relation.cpp +5 -5
- package/src/duckdb/src/main/secret/secret.cpp +135 -0
- package/src/duckdb/src/main/secret/secret_manager.cpp +634 -0
- package/src/duckdb/src/main/secret/secret_storage.cpp +233 -0
- package/src/duckdb/src/main/settings/settings.cpp +133 -38
- package/src/duckdb/src/main/stream_query_result.cpp +53 -14
- package/src/duckdb/src/optimizer/column_lifetime_analyzer.cpp +6 -0
- package/src/duckdb/src/optimizer/cse_optimizer.cpp +1 -1
- package/src/duckdb/src/optimizer/deliminator.cpp +136 -14
- package/src/duckdb/src/optimizer/filter_combiner.cpp +72 -26
- package/src/duckdb/src/optimizer/filter_pushdown.cpp +3 -0
- package/src/duckdb/src/optimizer/join_order/cardinality_estimator.cpp +2 -1
- package/src/duckdb/src/optimizer/join_order/cost_model.cpp +0 -1
- package/src/duckdb/src/optimizer/join_order/join_node.cpp +4 -0
- package/src/duckdb/src/optimizer/join_order/join_order_optimizer.cpp +3 -6
- package/src/duckdb/src/optimizer/join_order/join_relation_set.cpp +20 -0
- package/src/duckdb/src/optimizer/join_order/query_graph_manager.cpp +71 -40
- package/src/duckdb/src/optimizer/join_order/relation_manager.cpp +12 -3
- package/src/duckdb/src/optimizer/join_order/relation_statistics_helper.cpp +77 -3
- package/src/duckdb/src/optimizer/pushdown/pushdown_projection.cpp +7 -7
- package/src/duckdb/src/optimizer/pushdown/pushdown_semi_anti_join.cpp +56 -0
- package/src/duckdb/src/optimizer/remove_unused_columns.cpp +21 -0
- package/src/duckdb/src/optimizer/rule/date_part_simplification.cpp +2 -2
- package/src/duckdb/src/optimizer/rule/move_constants.cpp +15 -10
- package/src/duckdb/src/optimizer/rule/ordered_aggregate_optimizer.cpp +70 -0
- package/src/duckdb/src/optimizer/rule/regex_optimizations.cpp +17 -5
- package/src/duckdb/src/optimizer/statistics/expression/propagate_cast.cpp +1 -0
- package/src/duckdb/src/optimizer/statistics/expression/propagate_comparison.cpp +1 -0
- package/src/duckdb/src/optimizer/statistics/operator/propagate_filter.cpp +1 -2
- package/src/duckdb/src/optimizer/statistics/operator/propagate_join.cpp +22 -9
- package/src/duckdb/src/optimizer/statistics/operator/propagate_window.cpp +28 -4
- package/src/duckdb/src/optimizer/unnest_rewriter.cpp +12 -7
- package/src/duckdb/src/parallel/event.cpp +2 -2
- package/src/duckdb/src/parallel/executor.cpp +114 -81
- package/src/duckdb/src/parallel/executor_task.cpp +2 -4
- package/src/duckdb/src/parallel/meta_pipeline.cpp +28 -29
- package/src/duckdb/src/parallel/pipeline.cpp +41 -41
- package/src/duckdb/src/parallel/pipeline_event.cpp +2 -4
- package/src/duckdb/src/parallel/pipeline_executor.cpp +13 -75
- package/src/duckdb/src/parallel/task_scheduler.cpp +22 -13
- package/src/duckdb/src/parser/column_definition.cpp +22 -4
- package/src/duckdb/src/parser/column_list.cpp +2 -1
- package/src/duckdb/src/parser/expression/function_expression.cpp +1 -1
- package/src/duckdb/src/parser/expression/lambda_expression.cpp +51 -0
- package/src/duckdb/src/parser/expression/lambdaref_expression.cpp +59 -0
- package/src/duckdb/src/parser/expression/window_expression.cpp +9 -1
- package/src/duckdb/src/parser/parsed_data/alter_table_info.cpp +40 -0
- package/src/duckdb/src/parser/parsed_data/attach_info.cpp +1 -0
- package/src/duckdb/src/parser/parsed_data/comment_on_info.cpp +19 -0
- package/src/duckdb/src/parser/parsed_data/create_index_info.cpp +11 -9
- package/src/duckdb/src/parser/parsed_data/create_info.cpp +1 -0
- package/src/duckdb/src/parser/parsed_data/create_secret_info.cpp +22 -0
- package/src/duckdb/src/parser/parsed_data/create_table_info.cpp +17 -0
- package/src/duckdb/src/parser/parsed_data/create_type_info.cpp +19 -0
- package/src/duckdb/src/parser/parsed_data/create_view_info.cpp +13 -9
- package/src/duckdb/src/parser/parsed_data/drop_info.cpp +8 -9
- package/src/duckdb/src/parser/parsed_data/extra_drop_info.cpp +16 -0
- package/src/duckdb/src/parser/parsed_expression_iterator.cpp +3 -1
- package/src/duckdb/src/parser/parser.cpp +14 -8
- package/src/duckdb/src/parser/query_error_context.cpp +12 -13
- package/src/duckdb/src/parser/query_node/select_node.cpp +5 -1
- package/src/duckdb/src/parser/query_node/set_operation_node.cpp +8 -13
- package/src/duckdb/src/parser/statement/copy_database_statement.cpp +41 -0
- package/src/duckdb/src/parser/statement/set_statement.cpp +5 -1
- package/src/duckdb/src/parser/tableref/basetableref.cpp +1 -0
- package/src/duckdb/src/parser/tableref/showref.cpp +47 -0
- package/src/duckdb/src/parser/transform/constraint/transform_constraint.cpp +6 -2
- package/src/duckdb/src/parser/transform/expression/transform_bool_expr.cpp +1 -0
- package/src/duckdb/src/parser/transform/expression/transform_boolean_test.cpp +30 -15
- package/src/duckdb/src/parser/transform/expression/transform_case.cpp +1 -0
- package/src/duckdb/src/parser/transform/expression/transform_columnref.cpp +3 -2
- package/src/duckdb/src/parser/transform/expression/transform_constant.cpp +34 -4
- package/src/duckdb/src/parser/transform/expression/transform_function.cpp +26 -12
- package/src/duckdb/src/parser/transform/expression/transform_grouping_function.cpp +1 -1
- package/src/duckdb/src/parser/transform/expression/transform_interval.cpp +34 -5
- package/src/duckdb/src/parser/transform/expression/transform_is_null.cpp +3 -1
- package/src/duckdb/src/parser/transform/expression/transform_lambda.cpp +3 -1
- package/src/duckdb/src/parser/transform/expression/transform_multi_assign_reference.cpp +3 -3
- package/src/duckdb/src/parser/transform/expression/transform_operator.cpp +3 -3
- package/src/duckdb/src/parser/transform/expression/transform_positional_reference.cpp +1 -1
- package/src/duckdb/src/parser/transform/expression/transform_subquery.cpp +13 -13
- package/src/duckdb/src/parser/transform/helpers/nodetype_to_string.cpp +2 -0
- package/src/duckdb/src/parser/transform/helpers/transform_cte.cpp +1 -1
- package/src/duckdb/src/parser/transform/helpers/transform_typename.cpp +32 -1
- package/src/duckdb/src/parser/transform/statement/transform_alter_table.cpp +1 -1
- package/src/duckdb/src/parser/transform/statement/transform_attach.cpp +1 -0
- package/src/duckdb/src/parser/transform/statement/transform_comment_on.cpp +108 -0
- package/src/duckdb/src/parser/transform/statement/transform_copy.cpp +45 -37
- package/src/duckdb/src/parser/transform/statement/transform_copy_database.cpp +29 -0
- package/src/duckdb/src/parser/transform/statement/transform_create_index.cpp +5 -14
- package/src/duckdb/src/parser/transform/statement/transform_create_table.cpp +0 -1
- package/src/duckdb/src/parser/transform/statement/transform_delete.cpp +1 -1
- package/src/duckdb/src/parser/transform/statement/transform_drop.cpp +25 -6
- package/src/duckdb/src/parser/transform/statement/transform_import.cpp +2 -1
- package/src/duckdb/src/parser/transform/statement/transform_pragma.cpp +6 -14
- package/src/duckdb/src/parser/transform/statement/transform_secret.cpp +103 -0
- package/src/duckdb/src/parser/transform/statement/transform_select.cpp +8 -1
- package/src/duckdb/src/parser/transform/statement/transform_select_node.cpp +4 -8
- package/src/duckdb/src/parser/transform/statement/transform_set.cpp +18 -5
- package/src/duckdb/src/parser/transform/statement/transform_show.cpp +14 -41
- package/src/duckdb/src/parser/transform/statement/transform_show_select.cpp +13 -6
- package/src/duckdb/src/parser/transform/statement/transform_use.cpp +3 -1
- package/src/duckdb/src/parser/transform/tableref/transform_base_tableref.cpp +1 -1
- package/src/duckdb/src/parser/transform/tableref/transform_join.cpp +1 -2
- package/src/duckdb/src/parser/transform/tableref/transform_pivot.cpp +6 -5
- package/src/duckdb/src/parser/transform/tableref/transform_table_function.cpp +1 -1
- package/src/duckdb/src/parser/transformer.cpp +22 -0
- package/src/duckdb/src/planner/bind_context.cpp +23 -14
- package/src/duckdb/src/planner/binder/expression/bind_aggregate_expression.cpp +15 -14
- package/src/duckdb/src/planner/binder/expression/bind_between_expression.cpp +20 -9
- package/src/duckdb/src/planner/binder/expression/bind_case_expression.cpp +12 -7
- package/src/duckdb/src/planner/binder/expression/bind_cast_expression.cpp +4 -4
- package/src/duckdb/src/planner/binder/expression/bind_collate_expression.cpp +3 -3
- package/src/duckdb/src/planner/binder/expression/bind_columnref_expression.cpp +279 -195
- package/src/duckdb/src/planner/binder/expression/bind_comparison_expression.cpp +103 -17
- package/src/duckdb/src/planner/binder/expression/bind_conjunction_expression.cpp +3 -3
- package/src/duckdb/src/planner/binder/expression/bind_function_expression.cpp +91 -68
- package/src/duckdb/src/planner/binder/expression/bind_lambda.cpp +116 -84
- package/src/duckdb/src/planner/binder/expression/bind_macro_expression.cpp +85 -15
- package/src/duckdb/src/planner/binder/expression/bind_operator_expression.cpp +68 -31
- package/src/duckdb/src/planner/binder/expression/bind_star_expression.cpp +7 -7
- package/src/duckdb/src/planner/binder/expression/bind_subquery_expression.cpp +11 -7
- package/src/duckdb/src/planner/binder/expression/bind_unnest_expression.cpp +42 -19
- package/src/duckdb/src/planner/binder/expression/bind_window_expression.cpp +38 -16
- package/src/duckdb/src/planner/binder/query_node/bind_cte_node.cpp +16 -7
- package/src/duckdb/src/planner/binder/query_node/bind_recursive_cte_node.cpp +3 -0
- package/src/duckdb/src/planner/binder/query_node/bind_select_node.cpp +83 -12
- package/src/duckdb/src/planner/binder/query_node/bind_setop_node.cpp +28 -37
- package/src/duckdb/src/planner/binder/query_node/bind_table_macro_node.cpp +3 -4
- package/src/duckdb/src/planner/binder/query_node/plan_cte_node.cpp +2 -2
- package/src/duckdb/src/planner/binder/query_node/plan_recursive_cte_node.cpp +3 -3
- package/src/duckdb/src/planner/binder/query_node/plan_setop.cpp +7 -5
- package/src/duckdb/src/planner/binder/query_node/plan_subquery.cpp +10 -0
- package/src/duckdb/src/planner/binder/statement/bind_copy.cpp +48 -50
- package/src/duckdb/src/planner/binder/statement/bind_copy_database.cpp +187 -0
- package/src/duckdb/src/planner/binder/statement/bind_create.cpp +38 -22
- package/src/duckdb/src/planner/binder/statement/bind_create_table.cpp +8 -15
- package/src/duckdb/src/planner/binder/statement/bind_drop.cpp +6 -1
- package/src/duckdb/src/planner/binder/statement/bind_export.cpp +2 -2
- package/src/duckdb/src/planner/binder/statement/bind_insert.cpp +12 -10
- package/src/duckdb/src/planner/binder/statement/bind_pragma.cpp +37 -13
- package/src/duckdb/src/planner/binder/statement/bind_set.cpp +8 -2
- package/src/duckdb/src/planner/binder/statement/bind_simple.cpp +2 -0
- package/src/duckdb/src/planner/binder/statement/bind_summarize.cpp +29 -14
- package/src/duckdb/src/planner/binder/statement/bind_vacuum.cpp +1 -1
- package/src/duckdb/src/planner/binder/tableref/bind_basetableref.cpp +16 -6
- package/src/duckdb/src/planner/binder/tableref/bind_expressionlistref.cpp +11 -4
- package/src/duckdb/src/planner/binder/tableref/bind_joinref.cpp +1 -1
- package/src/duckdb/src/planner/binder/tableref/bind_named_parameters.cpp +2 -2
- package/src/duckdb/src/planner/binder/tableref/bind_pivot.cpp +18 -17
- package/src/duckdb/src/planner/binder/tableref/bind_showref.cpp +85 -0
- package/src/duckdb/src/planner/binder/tableref/bind_table_function.cpp +11 -17
- package/src/duckdb/src/planner/binder/tableref/plan_cteref.cpp +1 -9
- package/src/duckdb/src/planner/binder.cpp +31 -26
- package/src/duckdb/src/planner/bound_result_modifier.cpp +24 -0
- package/src/duckdb/src/planner/expression/bound_aggregate_expression.cpp +1 -1
- package/src/duckdb/src/planner/expression/bound_cast_expression.cpp +10 -1
- package/src/duckdb/src/planner/expression/bound_function_expression.cpp +20 -4
- package/src/duckdb/src/planner/expression/bound_lambdaref_expression.cpp +9 -10
- package/src/duckdb/src/planner/expression/bound_window_expression.cpp +65 -3
- package/src/duckdb/src/planner/expression.cpp +15 -5
- package/src/duckdb/src/planner/expression_binder/base_select_binder.cpp +5 -6
- package/src/duckdb/src/planner/expression_binder/check_binder.cpp +9 -8
- package/src/duckdb/src/planner/expression_binder/column_alias_binder.cpp +10 -7
- package/src/duckdb/src/planner/expression_binder/having_binder.cpp +9 -4
- package/src/duckdb/src/planner/expression_binder/index_binder.cpp +0 -25
- package/src/duckdb/src/planner/expression_binder/order_binder.cpp +8 -11
- package/src/duckdb/src/planner/expression_binder/qualify_binder.cpp +3 -2
- package/src/duckdb/src/planner/expression_binder/table_function_binder.cpp +15 -8
- package/src/duckdb/src/planner/expression_binder/where_binder.cpp +3 -4
- package/src/duckdb/src/planner/expression_binder.cpp +51 -25
- package/src/duckdb/src/planner/expression_iterator.cpp +2 -1
- package/src/duckdb/src/planner/filter/constant_filter.cpp +1 -0
- package/src/duckdb/src/planner/filter/struct_filter.cpp +33 -0
- package/src/duckdb/src/planner/joinside.cpp +1 -1
- package/src/duckdb/src/planner/logical_operator.cpp +2 -1
- package/src/duckdb/src/planner/operator/logical_copy_database.cpp +32 -0
- package/src/duckdb/src/planner/operator/logical_copy_to_file.cpp +13 -4
- package/src/duckdb/src/planner/operator/logical_create_table.cpp +2 -0
- package/src/duckdb/src/planner/operator/logical_get.cpp +4 -1
- package/src/duckdb/src/planner/operator/logical_join.cpp +8 -0
- package/src/duckdb/src/planner/planner.cpp +24 -23
- package/src/duckdb/src/planner/pragma_handler.cpp +10 -19
- package/src/duckdb/src/planner/subquery/flatten_dependent_join.cpp +99 -6
- package/src/duckdb/src/planner/subquery/rewrite_cte_scan.cpp +36 -0
- package/src/duckdb/src/planner/table_binding.cpp +14 -12
- package/src/duckdb/src/storage/buffer/block_handle.cpp +12 -10
- package/src/duckdb/src/storage/buffer/block_manager.cpp +1 -1
- package/src/duckdb/src/storage/buffer/buffer_pool.cpp +25 -9
- package/src/duckdb/src/storage/buffer/buffer_pool_reservation.cpp +4 -3
- package/src/duckdb/src/storage/buffer_manager.cpp +14 -3
- package/src/duckdb/src/storage/checkpoint/row_group_writer.cpp +0 -8
- package/src/duckdb/src/storage/checkpoint/table_data_writer.cpp +15 -7
- package/src/duckdb/src/storage/checkpoint/write_overflow_strings_to_disk.cpp +1 -1
- package/src/duckdb/src/storage/checkpoint_manager.cpp +94 -41
- package/src/duckdb/src/storage/compression/alp/alp.cpp +57 -0
- package/src/duckdb/src/storage/compression/alp/alp_constants.cpp +13 -0
- package/src/duckdb/src/storage/compression/alprd.cpp +57 -0
- package/src/duckdb/src/storage/compression/bitpacking.cpp +86 -55
- package/src/duckdb/src/storage/compression/bitpacking_hugeint.cpp +41 -41
- package/src/duckdb/src/storage/compression/dictionary_compression.cpp +1 -3
- package/src/duckdb/src/storage/compression/fixed_size_uncompressed.cpp +2 -0
- package/src/duckdb/src/storage/compression/fsst.cpp +4 -4
- package/src/duckdb/src/storage/compression/numeric_constant.cpp +3 -0
- package/src/duckdb/src/storage/compression/rle.cpp +6 -4
- package/src/duckdb/src/storage/compression/string_uncompressed.cpp +7 -7
- package/src/duckdb/src/storage/compression/uncompressed.cpp +1 -0
- package/src/duckdb/src/storage/compression/validity_uncompressed.cpp +6 -6
- package/src/duckdb/src/storage/data_table.cpp +32 -96
- package/src/duckdb/src/storage/index.cpp +23 -11
- package/src/duckdb/src/storage/local_storage.cpp +36 -19
- package/src/duckdb/src/storage/metadata/metadata_manager.cpp +2 -2
- package/src/duckdb/src/storage/partial_block_manager.cpp +1 -1
- package/src/duckdb/src/storage/serialization/serialize_create_info.cpp +9 -4
- package/src/duckdb/src/storage/serialization/serialize_expression.cpp +3 -3
- package/src/duckdb/src/storage/serialization/serialize_extra_drop_info.cpp +42 -0
- package/src/duckdb/src/storage/serialization/serialize_logical_operator.cpp +7 -17
- package/src/duckdb/src/storage/serialization/serialize_macro_function.cpp +2 -2
- package/src/duckdb/src/storage/serialization/serialize_nodes.cpp +84 -77
- package/src/duckdb/src/storage/serialization/serialize_parse_info.cpp +63 -4
- package/src/duckdb/src/storage/serialization/serialize_parsed_expression.cpp +23 -0
- package/src/duckdb/src/storage/serialization/serialize_query_node.cpp +2 -0
- package/src/duckdb/src/storage/serialization/serialize_storage.cpp +35 -0
- package/src/duckdb/src/storage/serialization/serialize_table_filter.cpp +19 -0
- package/src/duckdb/src/storage/serialization/serialize_tableref.cpp +22 -1
- package/src/duckdb/src/storage/serialization/serialize_types.cpp +50 -0
- package/src/duckdb/src/storage/single_file_block_manager.cpp +46 -7
- package/src/duckdb/src/storage/standard_buffer_manager.cpp +57 -28
- package/src/duckdb/src/storage/statistics/array_stats.cpp +131 -0
- package/src/duckdb/src/storage/statistics/base_statistics.cpp +62 -4
- package/src/duckdb/src/storage/statistics/column_statistics.cpp +1 -0
- package/src/duckdb/src/storage/statistics/distinct_statistics.cpp +3 -1
- package/src/duckdb/src/storage/statistics/numeric_stats.cpp +21 -0
- package/src/duckdb/src/storage/statistics/numeric_stats_union.cpp +5 -0
- package/src/duckdb/src/storage/statistics/string_stats.cpp +2 -2
- package/src/duckdb/src/storage/storage_info.cpp +1 -1
- package/src/duckdb/src/storage/storage_manager.cpp +47 -22
- package/src/duckdb/src/storage/table/array_column_data.cpp +241 -0
- package/src/duckdb/src/storage/table/chunk_info.cpp +2 -1
- package/src/duckdb/src/storage/table/column_checkpoint_state.cpp +3 -1
- package/src/duckdb/src/storage/table/column_data.cpp +41 -18
- package/src/duckdb/src/storage/table/column_data_checkpointer.cpp +12 -3
- package/src/duckdb/src/storage/table/column_segment.cpp +40 -6
- package/src/duckdb/src/storage/table/list_column_data.cpp +18 -15
- package/src/duckdb/src/storage/table/row_group.cpp +73 -21
- package/src/duckdb/src/storage/table/row_group_collection.cpp +395 -20
- package/src/duckdb/src/storage/table/row_version_manager.cpp +2 -1
- package/src/duckdb/src/storage/table/scan_state.cpp +4 -0
- package/src/duckdb/src/storage/table/standard_column_data.cpp +11 -5
- package/src/duckdb/src/storage/table/struct_column_data.cpp +30 -10
- package/src/duckdb/src/storage/table/table_statistics.cpp +7 -1
- package/src/duckdb/src/storage/table/update_segment.cpp +18 -2
- package/src/duckdb/src/storage/table_index_list.cpp +73 -7
- package/src/duckdb/src/storage/temporary_memory_manager.cpp +148 -0
- package/src/duckdb/src/storage/wal_replay.cpp +329 -152
- package/src/duckdb/src/storage/write_ahead_log.cpp +157 -137
- package/src/duckdb/src/transaction/cleanup_state.cpp +3 -2
- package/src/duckdb/src/transaction/commit_state.cpp +89 -63
- package/src/duckdb/src/transaction/duck_transaction.cpp +5 -3
- package/src/duckdb/src/transaction/duck_transaction_manager.cpp +26 -54
- package/src/duckdb/src/transaction/meta_transaction.cpp +37 -23
- package/src/duckdb/src/transaction/transaction_context.cpp +23 -4
- package/src/duckdb/src/transaction/undo_buffer.cpp +16 -2
- package/src/duckdb/src/verification/fetch_row_verifier.cpp +13 -0
- package/src/duckdb/src/verification/prepared_statement_verifier.cpp +5 -7
- package/src/duckdb/src/verification/statement_verifier.cpp +6 -5
- package/src/duckdb/third_party/fast_float/fast_float/fast_float.h +100 -29
- package/src/duckdb/third_party/fmt/include/fmt/format-inl.h +1 -1
- package/src/duckdb/third_party/fmt/include/fmt/format.h +4 -2
- package/src/duckdb/third_party/fmt/include/fmt/printf.h +5 -5
- package/src/duckdb/third_party/libpg_query/include/nodes/nodes.hpp +4 -0
- package/src/duckdb/third_party/libpg_query/include/nodes/parsenodes.hpp +82 -21
- package/src/duckdb/third_party/libpg_query/include/parser/gram.hpp +551 -1004
- package/src/duckdb/third_party/libpg_query/include/parser/kwlist.hpp +17 -3
- package/src/duckdb/third_party/libpg_query/src_backend_parser_gram.cpp +24861 -23465
- package/src/duckdb/third_party/libpg_query/src_backend_parser_scan.cpp +420 -389
- package/src/duckdb/third_party/mbedtls/include/mbedtls/aes.h +640 -1
- package/src/duckdb/third_party/mbedtls/include/mbedtls/aes_alt.h +1 -0
- package/src/duckdb/third_party/mbedtls/include/mbedtls/aria.h +358 -0
- package/src/duckdb/third_party/mbedtls/include/mbedtls/aria_alt.h +1 -0
- package/src/duckdb/third_party/mbedtls/include/mbedtls/camellia.h +316 -0
- package/src/duckdb/third_party/mbedtls/include/mbedtls/camellia_alt.h +1 -0
- package/src/duckdb/third_party/mbedtls/include/mbedtls/ccm.h +1 -1
- package/src/duckdb/third_party/mbedtls/include/mbedtls/ccm_alt.h +1 -0
- package/src/duckdb/third_party/mbedtls/include/mbedtls/chacha20.h +1 -0
- package/src/duckdb/third_party/mbedtls/include/mbedtls/chachapoly.h +1 -0
- package/src/duckdb/third_party/mbedtls/include/mbedtls/cipher.h +124 -124
- package/src/duckdb/third_party/mbedtls/include/mbedtls/cmac.h +1 -0
- package/src/duckdb/third_party/mbedtls/include/mbedtls/entropy.h +293 -0
- package/src/duckdb/third_party/mbedtls/include/mbedtls/gcm.h +383 -0
- package/src/duckdb/third_party/mbedtls/include/mbedtls/gcm_alt.h +1 -0
- package/src/duckdb/third_party/mbedtls/include/mbedtls/mbedtls_config.h +9 -0
- package/src/duckdb/third_party/mbedtls/include/mbedtls/nist_kw.h +1 -0
- package/src/duckdb/third_party/mbedtls/include/mbedtls/timing.h +1 -0
- package/src/duckdb/third_party/mbedtls/include/mbedtls_wrapper.hpp +35 -6
- package/src/duckdb/third_party/mbedtls/library/aes.cpp +2171 -0
- package/src/duckdb/third_party/mbedtls/library/aesni.h +1 -0
- package/src/duckdb/third_party/mbedtls/library/aria.cpp +1058 -0
- package/src/duckdb/third_party/mbedtls/library/camellia.cpp +1087 -0
- package/src/duckdb/third_party/mbedtls/library/cipher.cpp +1633 -0
- package/src/duckdb/third_party/mbedtls/library/cipher_wrap.cpp +2270 -0
- package/src/duckdb/third_party/mbedtls/library/cipher_wrap.h +146 -0
- package/src/duckdb/third_party/mbedtls/library/entropy.cpp +701 -0
- package/src/duckdb/third_party/mbedtls/library/entropy_poll.cpp +237 -0
- package/src/duckdb/third_party/mbedtls/library/entropy_poll.h +76 -0
- package/src/duckdb/third_party/mbedtls/library/gcm.cpp +1161 -0
- package/src/duckdb/third_party/mbedtls/library/padlock.h +1 -0
- package/src/duckdb/third_party/mbedtls/mbedtls_wrapper.cpp +132 -24
- package/src/duckdb/third_party/pcg/pcg_uint128.hpp +1 -1
- package/src/duckdb/third_party/skiplist/HeadNode.h +934 -0
- package/src/duckdb/third_party/skiplist/IntegrityEnums.h +62 -0
- package/src/duckdb/third_party/skiplist/Node.h +641 -0
- package/src/duckdb/third_party/skiplist/NodeRefs.h +251 -0
- package/src/duckdb/third_party/skiplist/RollingMedian.h +202 -0
- package/src/duckdb/third_party/skiplist/SkipList.cpp +40 -0
- package/src/duckdb/third_party/skiplist/SkipList.h +549 -0
- package/src/duckdb/third_party/thrift/thrift/thrift-config.h +1 -1
- package/src/duckdb/ub_extension_json_json_functions.cpp +2 -0
- package/src/duckdb/ub_src_catalog.cpp +3 -1
- package/src/duckdb/ub_src_catalog_catalog_entry_dependency.cpp +6 -0
- package/src/duckdb/ub_src_common.cpp +1 -1
- package/src/duckdb/ub_src_common_exception.cpp +6 -0
- package/src/duckdb/ub_src_common_types.cpp +2 -2
- package/src/duckdb/ub_src_core_functions.cpp +2 -0
- package/src/duckdb/ub_src_core_functions_scalar_array.cpp +4 -0
- package/src/duckdb/ub_src_core_functions_scalar_blob.cpp +2 -0
- package/src/duckdb/ub_src_core_functions_scalar_list.cpp +7 -3
- package/src/duckdb/ub_src_core_functions_scalar_secret.cpp +2 -0
- package/src/duckdb/ub_src_core_functions_scalar_string.cpp +4 -0
- package/src/duckdb/ub_src_execution_index.cpp +4 -0
- package/src/duckdb/ub_src_execution_operator_csv_scanner_buffer_manager.cpp +6 -0
- package/src/duckdb/ub_src_execution_operator_csv_scanner_scanner.cpp +10 -0
- package/src/duckdb/ub_src_execution_operator_csv_scanner_state_machine.cpp +4 -0
- package/src/duckdb/ub_src_execution_operator_csv_scanner_table_function.cpp +4 -0
- package/src/duckdb/ub_src_execution_operator_csv_scanner_util.cpp +4 -0
- package/src/duckdb/ub_src_execution_operator_helper.cpp +4 -0
- package/src/duckdb/ub_src_execution_operator_join.cpp +4 -2
- package/src/duckdb/ub_src_execution_operator_persistent.cpp +2 -0
- package/src/duckdb/ub_src_execution_physical_plan.cpp +4 -2
- package/src/duckdb/ub_src_function_cast.cpp +2 -0
- package/src/duckdb/ub_src_function_scalar_list.cpp +4 -0
- package/src/duckdb/ub_src_function_table.cpp +4 -4
- package/src/duckdb/ub_src_function_table_system.cpp +6 -0
- package/src/duckdb/ub_src_main.cpp +2 -0
- package/src/duckdb/ub_src_main_buffered_data.cpp +2 -0
- package/src/duckdb/ub_src_main_secret.cpp +6 -0
- package/src/duckdb/ub_src_optimizer_pushdown.cpp +2 -0
- package/src/duckdb/ub_src_parser_expression.cpp +2 -0
- package/src/duckdb/ub_src_parser_parsed_data.cpp +6 -0
- package/src/duckdb/ub_src_parser_statement.cpp +2 -2
- package/src/duckdb/ub_src_parser_tableref.cpp +2 -0
- package/src/duckdb/ub_src_parser_transform_statement.cpp +6 -0
- package/src/duckdb/ub_src_planner_binder_statement.cpp +2 -2
- package/src/duckdb/ub_src_planner_binder_tableref.cpp +2 -0
- package/src/duckdb/ub_src_planner_filter.cpp +2 -0
- package/src/duckdb/ub_src_planner_operator.cpp +2 -0
- package/src/duckdb/ub_src_planner_subquery.cpp +2 -0
- package/src/duckdb/ub_src_storage.cpp +2 -0
- package/src/duckdb/ub_src_storage_compression.cpp +2 -0
- package/src/duckdb/ub_src_storage_compression_alp.cpp +4 -0
- package/src/duckdb/ub_src_storage_serialization.cpp +2 -0
- package/src/duckdb/ub_src_storage_statistics.cpp +2 -0
- package/src/duckdb/ub_src_storage_table.cpp +2 -0
- package/src/duckdb_node.hpp +1 -1
- package/src/statement.cpp +2 -2
- package/src/utils.cpp +1 -15
@@ -0,0 +1,1633 @@
|
|
1
|
+
/**
|
2
|
+
* \file cipher.c
|
3
|
+
*
|
4
|
+
* \brief Generic cipher wrapper for mbed TLS
|
5
|
+
*
|
6
|
+
* \author Adriaan de Jong <dejong@fox-it.com>
|
7
|
+
*
|
8
|
+
* Copyright The Mbed TLS Contributors
|
9
|
+
* SPDX-License-Identifier: Apache-2.0
|
10
|
+
*
|
11
|
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may
|
12
|
+
* not use this file except in compliance with the License.
|
13
|
+
* You may obtain a copy of the License at
|
14
|
+
*
|
15
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
16
|
+
*
|
17
|
+
* Unless required by applicable law or agreed to in writing, software
|
18
|
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
19
|
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
20
|
+
* See the License for the specific language governing permissions and
|
21
|
+
* limitations under the License.
|
22
|
+
*/
|
23
|
+
|
24
|
+
#include "common.h"
|
25
|
+
|
26
|
+
#if defined(MBEDTLS_CIPHER_C)
|
27
|
+
|
28
|
+
#include "mbedtls/cipher.h"
|
29
|
+
#include "cipher_wrap.h"
|
30
|
+
#include "mbedtls/platform_util.h"
|
31
|
+
#include "mbedtls/error.h"
|
32
|
+
#include "mbedtls/constant_time.h"
|
33
|
+
|
34
|
+
#include <stdlib.h>
|
35
|
+
#include <string.h>
|
36
|
+
|
37
|
+
#if defined(MBEDTLS_CHACHAPOLY_C)
|
38
|
+
#include "mbedtls/chachapoly.h"
|
39
|
+
#endif
|
40
|
+
|
41
|
+
#if defined(MBEDTLS_GCM_C)
|
42
|
+
#include "mbedtls/gcm.h"
|
43
|
+
#endif
|
44
|
+
|
45
|
+
#if defined(MBEDTLS_CCM_C)
|
46
|
+
#include "mbedtls/ccm.h"
|
47
|
+
#endif
|
48
|
+
|
49
|
+
#if defined(MBEDTLS_CHACHA20_C)
|
50
|
+
#include "mbedtls/chacha20.h"
|
51
|
+
#endif
|
52
|
+
|
53
|
+
#if defined(MBEDTLS_CMAC_C)
|
54
|
+
#include "mbedtls/cmac.h"
|
55
|
+
#endif
|
56
|
+
|
57
|
+
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
58
|
+
#include "psa/crypto.h"
|
59
|
+
#include "mbedtls/psa_util.h"
|
60
|
+
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
61
|
+
|
62
|
+
#if defined(MBEDTLS_NIST_KW_C)
|
63
|
+
#include "mbedtls/nist_kw.h"
|
64
|
+
#endif
|
65
|
+
|
66
|
+
#if defined(MBEDTLS_PLATFORM_C)
|
67
|
+
#include "mbedtls/platform.h"
|
68
|
+
#else
|
69
|
+
#define mbedtls_calloc calloc
|
70
|
+
#define mbedtls_free free
|
71
|
+
#endif
|
72
|
+
|
73
|
+
#define CIPHER_VALIDATE_RET( cond ) \
|
74
|
+
MBEDTLS_INTERNAL_VALIDATE_RET( cond, MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA )
|
75
|
+
#define CIPHER_VALIDATE( cond ) \
|
76
|
+
MBEDTLS_INTERNAL_VALIDATE( cond )
|
77
|
+
|
78
|
+
static int supported_init = 0;
|
79
|
+
|
80
|
+
const int *mbedtls_cipher_list( void )
|
81
|
+
{
|
82
|
+
const mbedtls_cipher_definition_t *def;
|
83
|
+
int *type;
|
84
|
+
|
85
|
+
if( ! supported_init )
|
86
|
+
{
|
87
|
+
def = mbedtls_cipher_definitions;
|
88
|
+
type = mbedtls_cipher_supported;
|
89
|
+
|
90
|
+
while( def->type != 0 )
|
91
|
+
*type++ = (*def++).type;
|
92
|
+
|
93
|
+
*type = 0;
|
94
|
+
|
95
|
+
supported_init = 1;
|
96
|
+
}
|
97
|
+
|
98
|
+
return( mbedtls_cipher_supported );
|
99
|
+
}
|
100
|
+
|
101
|
+
const mbedtls_cipher_info_t *mbedtls_cipher_info_from_type(
|
102
|
+
const mbedtls_cipher_type_t cipher_type )
|
103
|
+
{
|
104
|
+
const mbedtls_cipher_definition_t *def;
|
105
|
+
|
106
|
+
for( def = mbedtls_cipher_definitions; def->info != NULL; def++ )
|
107
|
+
if( def->type == cipher_type )
|
108
|
+
return( def->info );
|
109
|
+
|
110
|
+
return( NULL );
|
111
|
+
}
|
112
|
+
|
113
|
+
const mbedtls_cipher_info_t *mbedtls_cipher_info_from_string(
|
114
|
+
const char *cipher_name )
|
115
|
+
{
|
116
|
+
const mbedtls_cipher_definition_t *def;
|
117
|
+
|
118
|
+
if( NULL == cipher_name )
|
119
|
+
return( NULL );
|
120
|
+
|
121
|
+
for( def = mbedtls_cipher_definitions; def->info != NULL; def++ )
|
122
|
+
if( ! strcmp( def->info->name, cipher_name ) )
|
123
|
+
return( def->info );
|
124
|
+
|
125
|
+
return( NULL );
|
126
|
+
}
|
127
|
+
|
128
|
+
const mbedtls_cipher_info_t *mbedtls_cipher_info_from_values(
|
129
|
+
const mbedtls_cipher_id_t cipher_id,
|
130
|
+
int key_bitlen,
|
131
|
+
const mbedtls_cipher_mode_t mode )
|
132
|
+
{
|
133
|
+
const mbedtls_cipher_definition_t *def;
|
134
|
+
|
135
|
+
for( def = mbedtls_cipher_definitions; def->info != NULL; def++ )
|
136
|
+
if( def->info->base->cipher == cipher_id &&
|
137
|
+
def->info->key_bitlen == (unsigned) key_bitlen &&
|
138
|
+
def->info->mode == mode )
|
139
|
+
return( def->info );
|
140
|
+
|
141
|
+
return( NULL );
|
142
|
+
}
|
143
|
+
|
144
|
+
void mbedtls_cipher_init( mbedtls_cipher_context_t *ctx )
|
145
|
+
{
|
146
|
+
CIPHER_VALIDATE( ctx != NULL );
|
147
|
+
memset( ctx, 0, sizeof( mbedtls_cipher_context_t ) );
|
148
|
+
}
|
149
|
+
|
150
|
+
void mbedtls_cipher_free( mbedtls_cipher_context_t *ctx )
|
151
|
+
{
|
152
|
+
if( ctx == NULL )
|
153
|
+
return;
|
154
|
+
|
155
|
+
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
156
|
+
if( ctx->psa_enabled == 1 )
|
157
|
+
{
|
158
|
+
if( ctx->cipher_ctx != NULL )
|
159
|
+
{
|
160
|
+
mbedtls_cipher_context_psa * const cipher_psa =
|
161
|
+
(mbedtls_cipher_context_psa *) ctx->cipher_ctx;
|
162
|
+
|
163
|
+
if( cipher_psa->slot_state == MBEDTLS_CIPHER_PSA_KEY_OWNED )
|
164
|
+
{
|
165
|
+
/* xxx_free() doesn't allow to return failures. */
|
166
|
+
(void) psa_destroy_key( cipher_psa->slot );
|
167
|
+
}
|
168
|
+
|
169
|
+
mbedtls_platform_zeroize( cipher_psa, sizeof( *cipher_psa ) );
|
170
|
+
mbedtls_free( cipher_psa );
|
171
|
+
}
|
172
|
+
|
173
|
+
mbedtls_platform_zeroize( ctx, sizeof(mbedtls_cipher_context_t) );
|
174
|
+
return;
|
175
|
+
}
|
176
|
+
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
177
|
+
|
178
|
+
#if defined(MBEDTLS_CMAC_C)
|
179
|
+
if( ctx->cmac_ctx )
|
180
|
+
{
|
181
|
+
mbedtls_platform_zeroize( ctx->cmac_ctx,
|
182
|
+
sizeof( mbedtls_cmac_context_t ) );
|
183
|
+
mbedtls_free( ctx->cmac_ctx );
|
184
|
+
}
|
185
|
+
#endif
|
186
|
+
|
187
|
+
if( ctx->cipher_ctx )
|
188
|
+
ctx->cipher_info->base->ctx_free_func( ctx->cipher_ctx );
|
189
|
+
|
190
|
+
mbedtls_platform_zeroize( ctx, sizeof(mbedtls_cipher_context_t) );
|
191
|
+
}
|
192
|
+
|
193
|
+
int mbedtls_cipher_setup( mbedtls_cipher_context_t *ctx,
|
194
|
+
const mbedtls_cipher_info_t *cipher_info )
|
195
|
+
{
|
196
|
+
CIPHER_VALIDATE_RET( ctx != NULL );
|
197
|
+
if( cipher_info == NULL )
|
198
|
+
return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
|
199
|
+
|
200
|
+
memset( ctx, 0, sizeof( mbedtls_cipher_context_t ) );
|
201
|
+
|
202
|
+
if( NULL == ( ctx->cipher_ctx = cipher_info->base->ctx_alloc_func() ) )
|
203
|
+
return( MBEDTLS_ERR_CIPHER_ALLOC_FAILED );
|
204
|
+
|
205
|
+
ctx->cipher_info = cipher_info;
|
206
|
+
|
207
|
+
#if defined(MBEDTLS_CIPHER_MODE_WITH_PADDING)
|
208
|
+
/*
|
209
|
+
* Ignore possible errors caused by a cipher mode that doesn't use padding
|
210
|
+
*/
|
211
|
+
#if defined(MBEDTLS_CIPHER_PADDING_PKCS7)
|
212
|
+
(void) mbedtls_cipher_set_padding_mode( ctx, MBEDTLS_PADDING_PKCS7 );
|
213
|
+
#else
|
214
|
+
(void) mbedtls_cipher_set_padding_mode( ctx, MBEDTLS_PADDING_NONE );
|
215
|
+
#endif
|
216
|
+
#endif /* MBEDTLS_CIPHER_MODE_WITH_PADDING */
|
217
|
+
|
218
|
+
return( 0 );
|
219
|
+
}
|
220
|
+
|
221
|
+
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
222
|
+
int mbedtls_cipher_setup_psa( mbedtls_cipher_context_t *ctx,
|
223
|
+
const mbedtls_cipher_info_t *cipher_info,
|
224
|
+
size_t taglen )
|
225
|
+
{
|
226
|
+
psa_algorithm_t alg;
|
227
|
+
mbedtls_cipher_context_psa *cipher_psa;
|
228
|
+
|
229
|
+
if( NULL == cipher_info || NULL == ctx )
|
230
|
+
return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
|
231
|
+
|
232
|
+
/* Check that the underlying cipher mode and cipher type are
|
233
|
+
* supported by the underlying PSA Crypto implementation. */
|
234
|
+
alg = mbedtls_psa_translate_cipher_mode( cipher_info->mode, taglen );
|
235
|
+
if( alg == 0 )
|
236
|
+
return( MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE );
|
237
|
+
if( mbedtls_psa_translate_cipher_type( cipher_info->type ) == 0 )
|
238
|
+
return( MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE );
|
239
|
+
|
240
|
+
memset( ctx, 0, sizeof( mbedtls_cipher_context_t ) );
|
241
|
+
|
242
|
+
cipher_psa = mbedtls_calloc( 1, sizeof(mbedtls_cipher_context_psa ) );
|
243
|
+
if( cipher_psa == NULL )
|
244
|
+
return( MBEDTLS_ERR_CIPHER_ALLOC_FAILED );
|
245
|
+
cipher_psa->alg = alg;
|
246
|
+
ctx->cipher_ctx = cipher_psa;
|
247
|
+
ctx->cipher_info = cipher_info;
|
248
|
+
ctx->psa_enabled = 1;
|
249
|
+
return( 0 );
|
250
|
+
}
|
251
|
+
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
252
|
+
|
253
|
+
int mbedtls_cipher_setkey( mbedtls_cipher_context_t *ctx,
|
254
|
+
const unsigned char *key,
|
255
|
+
int key_bitlen,
|
256
|
+
const mbedtls_operation_t operation )
|
257
|
+
{
|
258
|
+
CIPHER_VALIDATE_RET( ctx != NULL );
|
259
|
+
CIPHER_VALIDATE_RET( key != NULL );
|
260
|
+
CIPHER_VALIDATE_RET( operation == MBEDTLS_ENCRYPT ||
|
261
|
+
operation == MBEDTLS_DECRYPT );
|
262
|
+
if( ctx->cipher_info == NULL )
|
263
|
+
return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
|
264
|
+
|
265
|
+
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
266
|
+
if( ctx->psa_enabled == 1 )
|
267
|
+
{
|
268
|
+
mbedtls_cipher_context_psa * const cipher_psa =
|
269
|
+
(mbedtls_cipher_context_psa *) ctx->cipher_ctx;
|
270
|
+
|
271
|
+
size_t const key_bytelen = ( (size_t) key_bitlen + 7 ) / 8;
|
272
|
+
|
273
|
+
psa_status_t status;
|
274
|
+
psa_key_type_t key_type;
|
275
|
+
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
|
276
|
+
|
277
|
+
/* PSA Crypto API only accepts byte-aligned keys. */
|
278
|
+
if( key_bitlen % 8 != 0 )
|
279
|
+
return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
|
280
|
+
|
281
|
+
/* Don't allow keys to be set multiple times. */
|
282
|
+
if( cipher_psa->slot_state != MBEDTLS_CIPHER_PSA_KEY_UNSET )
|
283
|
+
return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
|
284
|
+
|
285
|
+
key_type = mbedtls_psa_translate_cipher_type(
|
286
|
+
ctx->cipher_info->type );
|
287
|
+
if( key_type == 0 )
|
288
|
+
return( MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE );
|
289
|
+
psa_set_key_type( &attributes, key_type );
|
290
|
+
|
291
|
+
/* Mbed TLS' cipher layer doesn't enforce the mode of operation
|
292
|
+
* (encrypt vs. decrypt): it is possible to setup a key for encryption
|
293
|
+
* and use it for AEAD decryption. Until tests relying on this
|
294
|
+
* are changed, allow any usage in PSA. */
|
295
|
+
psa_set_key_usage_flags( &attributes,
|
296
|
+
/* mbedtls_psa_translate_cipher_operation( operation ); */
|
297
|
+
PSA_KEY_USAGE_ENCRYPT | PSA_KEY_USAGE_DECRYPT );
|
298
|
+
psa_set_key_algorithm( &attributes, cipher_psa->alg );
|
299
|
+
|
300
|
+
status = psa_import_key( &attributes, key, key_bytelen,
|
301
|
+
&cipher_psa->slot );
|
302
|
+
switch( status )
|
303
|
+
{
|
304
|
+
case PSA_SUCCESS:
|
305
|
+
break;
|
306
|
+
case PSA_ERROR_INSUFFICIENT_MEMORY:
|
307
|
+
return( MBEDTLS_ERR_CIPHER_ALLOC_FAILED );
|
308
|
+
case PSA_ERROR_NOT_SUPPORTED:
|
309
|
+
return( MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE );
|
310
|
+
default:
|
311
|
+
return( MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED );
|
312
|
+
}
|
313
|
+
/* Indicate that we own the key slot and need to
|
314
|
+
* destroy it in mbedtls_cipher_free(). */
|
315
|
+
cipher_psa->slot_state = MBEDTLS_CIPHER_PSA_KEY_OWNED;
|
316
|
+
|
317
|
+
ctx->key_bitlen = key_bitlen;
|
318
|
+
ctx->operation = operation;
|
319
|
+
return( 0 );
|
320
|
+
}
|
321
|
+
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
322
|
+
|
323
|
+
if( ( ctx->cipher_info->flags & MBEDTLS_CIPHER_VARIABLE_KEY_LEN ) == 0 &&
|
324
|
+
(int) ctx->cipher_info->key_bitlen != key_bitlen )
|
325
|
+
{
|
326
|
+
return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
|
327
|
+
}
|
328
|
+
|
329
|
+
ctx->key_bitlen = key_bitlen;
|
330
|
+
ctx->operation = operation;
|
331
|
+
|
332
|
+
/*
|
333
|
+
* For OFB, CFB and CTR mode always use the encryption key schedule
|
334
|
+
*/
|
335
|
+
if( MBEDTLS_ENCRYPT == operation ||
|
336
|
+
MBEDTLS_MODE_CFB == ctx->cipher_info->mode ||
|
337
|
+
MBEDTLS_MODE_OFB == ctx->cipher_info->mode ||
|
338
|
+
MBEDTLS_MODE_CTR == ctx->cipher_info->mode )
|
339
|
+
{
|
340
|
+
return( ctx->cipher_info->base->setkey_enc_func( ctx->cipher_ctx, key,
|
341
|
+
ctx->key_bitlen ) );
|
342
|
+
}
|
343
|
+
|
344
|
+
if( MBEDTLS_DECRYPT == operation )
|
345
|
+
return( ctx->cipher_info->base->setkey_dec_func( ctx->cipher_ctx, key,
|
346
|
+
ctx->key_bitlen ) );
|
347
|
+
|
348
|
+
return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
|
349
|
+
}
|
350
|
+
|
351
|
+
int mbedtls_cipher_set_iv( mbedtls_cipher_context_t *ctx,
|
352
|
+
const unsigned char *iv,
|
353
|
+
size_t iv_len )
|
354
|
+
{
|
355
|
+
size_t actual_iv_size;
|
356
|
+
|
357
|
+
CIPHER_VALIDATE_RET( ctx != NULL );
|
358
|
+
CIPHER_VALIDATE_RET( iv_len == 0 || iv != NULL );
|
359
|
+
if( ctx->cipher_info == NULL )
|
360
|
+
return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
|
361
|
+
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
362
|
+
if( ctx->psa_enabled == 1 )
|
363
|
+
{
|
364
|
+
/* While PSA Crypto has an API for multipart
|
365
|
+
* operations, we currently don't make it
|
366
|
+
* accessible through the cipher layer. */
|
367
|
+
return( MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE );
|
368
|
+
}
|
369
|
+
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
370
|
+
|
371
|
+
/* avoid buffer overflow in ctx->iv */
|
372
|
+
if( iv_len > MBEDTLS_MAX_IV_LENGTH )
|
373
|
+
return( MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE );
|
374
|
+
|
375
|
+
if( ( ctx->cipher_info->flags & MBEDTLS_CIPHER_VARIABLE_IV_LEN ) != 0 )
|
376
|
+
actual_iv_size = iv_len;
|
377
|
+
else
|
378
|
+
{
|
379
|
+
actual_iv_size = ctx->cipher_info->iv_size;
|
380
|
+
|
381
|
+
/* avoid reading past the end of input buffer */
|
382
|
+
if( actual_iv_size > iv_len )
|
383
|
+
return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
|
384
|
+
}
|
385
|
+
|
386
|
+
#if defined(MBEDTLS_CHACHA20_C)
|
387
|
+
if ( ctx->cipher_info->type == MBEDTLS_CIPHER_CHACHA20 )
|
388
|
+
{
|
389
|
+
if ( 0 != mbedtls_chacha20_starts( (mbedtls_chacha20_context*)ctx->cipher_ctx,
|
390
|
+
iv,
|
391
|
+
0U ) ) /* Initial counter value */
|
392
|
+
{
|
393
|
+
return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
|
394
|
+
}
|
395
|
+
}
|
396
|
+
#endif
|
397
|
+
|
398
|
+
#if defined(MBEDTLS_GCM_C)
|
399
|
+
if( MBEDTLS_MODE_GCM == ctx->cipher_info->mode )
|
400
|
+
{
|
401
|
+
return( mbedtls_gcm_starts( (mbedtls_gcm_context *) ctx->cipher_ctx,
|
402
|
+
ctx->operation,
|
403
|
+
iv, iv_len ) );
|
404
|
+
}
|
405
|
+
#endif
|
406
|
+
|
407
|
+
#if defined(MBEDTLS_CCM_C)
|
408
|
+
if( MBEDTLS_MODE_CCM_STAR_NO_TAG == ctx->cipher_info->mode )
|
409
|
+
{
|
410
|
+
int set_lengths_result;
|
411
|
+
int ccm_star_mode;
|
412
|
+
|
413
|
+
set_lengths_result = mbedtls_ccm_set_lengths(
|
414
|
+
(mbedtls_ccm_context *) ctx->cipher_ctx,
|
415
|
+
0, 0, 0 );
|
416
|
+
if( set_lengths_result != 0 )
|
417
|
+
return set_lengths_result;
|
418
|
+
|
419
|
+
if( ctx->operation == MBEDTLS_DECRYPT )
|
420
|
+
ccm_star_mode = MBEDTLS_CCM_STAR_DECRYPT;
|
421
|
+
else if( ctx->operation == MBEDTLS_ENCRYPT )
|
422
|
+
ccm_star_mode = MBEDTLS_CCM_STAR_ENCRYPT;
|
423
|
+
else
|
424
|
+
return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA;
|
425
|
+
|
426
|
+
return( mbedtls_ccm_starts( (mbedtls_ccm_context *) ctx->cipher_ctx,
|
427
|
+
ccm_star_mode,
|
428
|
+
iv, iv_len ) );
|
429
|
+
}
|
430
|
+
#endif
|
431
|
+
|
432
|
+
if ( actual_iv_size != 0 )
|
433
|
+
{
|
434
|
+
memcpy( ctx->iv, iv, actual_iv_size );
|
435
|
+
ctx->iv_size = actual_iv_size;
|
436
|
+
}
|
437
|
+
|
438
|
+
return( 0 );
|
439
|
+
}
|
440
|
+
|
441
|
+
int mbedtls_cipher_reset( mbedtls_cipher_context_t *ctx )
|
442
|
+
{
|
443
|
+
CIPHER_VALIDATE_RET( ctx != NULL );
|
444
|
+
if( ctx->cipher_info == NULL )
|
445
|
+
return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
|
446
|
+
|
447
|
+
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
448
|
+
if( ctx->psa_enabled == 1 )
|
449
|
+
{
|
450
|
+
/* We don't support resetting PSA-based
|
451
|
+
* cipher contexts, yet. */
|
452
|
+
return( MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE );
|
453
|
+
}
|
454
|
+
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
455
|
+
|
456
|
+
ctx->unprocessed_len = 0;
|
457
|
+
|
458
|
+
return( 0 );
|
459
|
+
}
|
460
|
+
|
461
|
+
#if defined(MBEDTLS_GCM_C) || defined(MBEDTLS_CHACHAPOLY_C)
|
462
|
+
int mbedtls_cipher_update_ad( mbedtls_cipher_context_t *ctx,
|
463
|
+
const unsigned char *ad, size_t ad_len )
|
464
|
+
{
|
465
|
+
CIPHER_VALIDATE_RET( ctx != NULL );
|
466
|
+
CIPHER_VALIDATE_RET( ad_len == 0 || ad != NULL );
|
467
|
+
if( ctx->cipher_info == NULL )
|
468
|
+
return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
|
469
|
+
|
470
|
+
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
471
|
+
if( ctx->psa_enabled == 1 )
|
472
|
+
{
|
473
|
+
/* While PSA Crypto has an API for multipart
|
474
|
+
* operations, we currently don't make it
|
475
|
+
* accessible through the cipher layer. */
|
476
|
+
return( MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE );
|
477
|
+
}
|
478
|
+
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
479
|
+
|
480
|
+
#if defined(MBEDTLS_GCM_C)
|
481
|
+
if( MBEDTLS_MODE_GCM == ctx->cipher_info->mode )
|
482
|
+
{
|
483
|
+
return( mbedtls_gcm_update_ad( (mbedtls_gcm_context *) ctx->cipher_ctx,
|
484
|
+
ad, ad_len ) );
|
485
|
+
}
|
486
|
+
#endif
|
487
|
+
|
488
|
+
#if defined(MBEDTLS_CHACHAPOLY_C)
|
489
|
+
if (MBEDTLS_CIPHER_CHACHA20_POLY1305 == ctx->cipher_info->type )
|
490
|
+
{
|
491
|
+
int result;
|
492
|
+
mbedtls_chachapoly_mode_t mode;
|
493
|
+
|
494
|
+
mode = ( ctx->operation == MBEDTLS_ENCRYPT )
|
495
|
+
? MBEDTLS_CHACHAPOLY_ENCRYPT
|
496
|
+
: MBEDTLS_CHACHAPOLY_DECRYPT;
|
497
|
+
|
498
|
+
result = mbedtls_chachapoly_starts( (mbedtls_chachapoly_context*) ctx->cipher_ctx,
|
499
|
+
ctx->iv,
|
500
|
+
mode );
|
501
|
+
if ( result != 0 )
|
502
|
+
return( result );
|
503
|
+
|
504
|
+
return( mbedtls_chachapoly_update_aad( (mbedtls_chachapoly_context*) ctx->cipher_ctx,
|
505
|
+
ad, ad_len ) );
|
506
|
+
}
|
507
|
+
#endif
|
508
|
+
|
509
|
+
return( 0 );
|
510
|
+
}
|
511
|
+
#endif /* MBEDTLS_GCM_C || MBEDTLS_CHACHAPOLY_C */
|
512
|
+
|
513
|
+
int mbedtls_cipher_update( mbedtls_cipher_context_t *ctx, const unsigned char *input,
|
514
|
+
size_t ilen, unsigned char *output, size_t *olen )
|
515
|
+
{
|
516
|
+
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
517
|
+
size_t block_size;
|
518
|
+
|
519
|
+
CIPHER_VALIDATE_RET( ctx != NULL );
|
520
|
+
CIPHER_VALIDATE_RET( ilen == 0 || input != NULL );
|
521
|
+
CIPHER_VALIDATE_RET( output != NULL );
|
522
|
+
CIPHER_VALIDATE_RET( olen != NULL );
|
523
|
+
if( ctx->cipher_info == NULL )
|
524
|
+
return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
|
525
|
+
|
526
|
+
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
527
|
+
if( ctx->psa_enabled == 1 )
|
528
|
+
{
|
529
|
+
/* While PSA Crypto has an API for multipart
|
530
|
+
* operations, we currently don't make it
|
531
|
+
* accessible through the cipher layer. */
|
532
|
+
return( MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE );
|
533
|
+
}
|
534
|
+
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
535
|
+
|
536
|
+
*olen = 0;
|
537
|
+
block_size = mbedtls_cipher_get_block_size( ctx );
|
538
|
+
if ( 0 == block_size )
|
539
|
+
{
|
540
|
+
return( MBEDTLS_ERR_CIPHER_INVALID_CONTEXT );
|
541
|
+
}
|
542
|
+
|
543
|
+
if( ctx->cipher_info->mode == MBEDTLS_MODE_ECB )
|
544
|
+
{
|
545
|
+
if( ilen != block_size )
|
546
|
+
return( MBEDTLS_ERR_CIPHER_FULL_BLOCK_EXPECTED );
|
547
|
+
|
548
|
+
*olen = ilen;
|
549
|
+
|
550
|
+
if( 0 != ( ret = ctx->cipher_info->base->ecb_func( ctx->cipher_ctx,
|
551
|
+
ctx->operation, input, output ) ) )
|
552
|
+
{
|
553
|
+
return( ret );
|
554
|
+
}
|
555
|
+
|
556
|
+
return( 0 );
|
557
|
+
}
|
558
|
+
|
559
|
+
#if defined(MBEDTLS_GCM_C)
|
560
|
+
if( ctx->cipher_info->mode == MBEDTLS_MODE_GCM )
|
561
|
+
{
|
562
|
+
return( mbedtls_gcm_update( (mbedtls_gcm_context *) ctx->cipher_ctx,
|
563
|
+
input, ilen,
|
564
|
+
output, ilen, olen ) );
|
565
|
+
}
|
566
|
+
#endif
|
567
|
+
|
568
|
+
#if defined(MBEDTLS_CCM_C)
|
569
|
+
if( ctx->cipher_info->mode == MBEDTLS_MODE_CCM_STAR_NO_TAG )
|
570
|
+
{
|
571
|
+
return( mbedtls_ccm_update( (mbedtls_ccm_context *) ctx->cipher_ctx,
|
572
|
+
input, ilen,
|
573
|
+
output, ilen, olen ) );
|
574
|
+
}
|
575
|
+
#endif
|
576
|
+
|
577
|
+
#if defined(MBEDTLS_CHACHAPOLY_C)
|
578
|
+
if ( ctx->cipher_info->type == MBEDTLS_CIPHER_CHACHA20_POLY1305 )
|
579
|
+
{
|
580
|
+
*olen = ilen;
|
581
|
+
return( mbedtls_chachapoly_update( (mbedtls_chachapoly_context*) ctx->cipher_ctx,
|
582
|
+
ilen, input, output ) );
|
583
|
+
}
|
584
|
+
#endif
|
585
|
+
|
586
|
+
if( input == output &&
|
587
|
+
( ctx->unprocessed_len != 0 || ilen % block_size ) )
|
588
|
+
{
|
589
|
+
return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
|
590
|
+
}
|
591
|
+
|
592
|
+
#if defined(MBEDTLS_CIPHER_MODE_CBC)
|
593
|
+
if( ctx->cipher_info->mode == MBEDTLS_MODE_CBC )
|
594
|
+
{
|
595
|
+
size_t copy_len = 0;
|
596
|
+
|
597
|
+
/*
|
598
|
+
* If there is not enough data for a full block, cache it.
|
599
|
+
*/
|
600
|
+
if( ( ctx->operation == MBEDTLS_DECRYPT && NULL != ctx->add_padding &&
|
601
|
+
ilen <= block_size - ctx->unprocessed_len ) ||
|
602
|
+
( ctx->operation == MBEDTLS_DECRYPT && NULL == ctx->add_padding &&
|
603
|
+
ilen < block_size - ctx->unprocessed_len ) ||
|
604
|
+
( ctx->operation == MBEDTLS_ENCRYPT &&
|
605
|
+
ilen < block_size - ctx->unprocessed_len ) )
|
606
|
+
{
|
607
|
+
memcpy( &( ctx->unprocessed_data[ctx->unprocessed_len] ), input,
|
608
|
+
ilen );
|
609
|
+
|
610
|
+
ctx->unprocessed_len += ilen;
|
611
|
+
return( 0 );
|
612
|
+
}
|
613
|
+
|
614
|
+
/*
|
615
|
+
* Process cached data first
|
616
|
+
*/
|
617
|
+
if( 0 != ctx->unprocessed_len )
|
618
|
+
{
|
619
|
+
copy_len = block_size - ctx->unprocessed_len;
|
620
|
+
|
621
|
+
memcpy( &( ctx->unprocessed_data[ctx->unprocessed_len] ), input,
|
622
|
+
copy_len );
|
623
|
+
|
624
|
+
if( 0 != ( ret = ctx->cipher_info->base->cbc_func( ctx->cipher_ctx,
|
625
|
+
ctx->operation, block_size, ctx->iv,
|
626
|
+
ctx->unprocessed_data, output ) ) )
|
627
|
+
{
|
628
|
+
return( ret );
|
629
|
+
}
|
630
|
+
|
631
|
+
*olen += block_size;
|
632
|
+
output += block_size;
|
633
|
+
ctx->unprocessed_len = 0;
|
634
|
+
|
635
|
+
input += copy_len;
|
636
|
+
ilen -= copy_len;
|
637
|
+
}
|
638
|
+
|
639
|
+
/*
|
640
|
+
* Cache final, incomplete block
|
641
|
+
*/
|
642
|
+
if( 0 != ilen )
|
643
|
+
{
|
644
|
+
/* Encryption: only cache partial blocks
|
645
|
+
* Decryption w/ padding: always keep at least one whole block
|
646
|
+
* Decryption w/o padding: only cache partial blocks
|
647
|
+
*/
|
648
|
+
copy_len = ilen % block_size;
|
649
|
+
if( copy_len == 0 &&
|
650
|
+
ctx->operation == MBEDTLS_DECRYPT &&
|
651
|
+
NULL != ctx->add_padding)
|
652
|
+
{
|
653
|
+
copy_len = block_size;
|
654
|
+
}
|
655
|
+
|
656
|
+
memcpy( ctx->unprocessed_data, &( input[ilen - copy_len] ),
|
657
|
+
copy_len );
|
658
|
+
|
659
|
+
ctx->unprocessed_len += copy_len;
|
660
|
+
ilen -= copy_len;
|
661
|
+
}
|
662
|
+
|
663
|
+
/*
|
664
|
+
* Process remaining full blocks
|
665
|
+
*/
|
666
|
+
if( ilen )
|
667
|
+
{
|
668
|
+
if( 0 != ( ret = ctx->cipher_info->base->cbc_func( ctx->cipher_ctx,
|
669
|
+
ctx->operation, ilen, ctx->iv, input, output ) ) )
|
670
|
+
{
|
671
|
+
return( ret );
|
672
|
+
}
|
673
|
+
|
674
|
+
*olen += ilen;
|
675
|
+
}
|
676
|
+
|
677
|
+
return( 0 );
|
678
|
+
}
|
679
|
+
#endif /* MBEDTLS_CIPHER_MODE_CBC */
|
680
|
+
|
681
|
+
#if defined(MBEDTLS_CIPHER_MODE_CFB)
|
682
|
+
if( ctx->cipher_info->mode == MBEDTLS_MODE_CFB )
|
683
|
+
{
|
684
|
+
if( 0 != ( ret = ctx->cipher_info->base->cfb_func( ctx->cipher_ctx,
|
685
|
+
ctx->operation, ilen, &ctx->unprocessed_len, ctx->iv,
|
686
|
+
input, output ) ) )
|
687
|
+
{
|
688
|
+
return( ret );
|
689
|
+
}
|
690
|
+
|
691
|
+
*olen = ilen;
|
692
|
+
|
693
|
+
return( 0 );
|
694
|
+
}
|
695
|
+
#endif /* MBEDTLS_CIPHER_MODE_CFB */
|
696
|
+
|
697
|
+
#if defined(MBEDTLS_CIPHER_MODE_OFB)
|
698
|
+
if( ctx->cipher_info->mode == MBEDTLS_MODE_OFB )
|
699
|
+
{
|
700
|
+
if( 0 != ( ret = ctx->cipher_info->base->ofb_func( ctx->cipher_ctx,
|
701
|
+
ilen, &ctx->unprocessed_len, ctx->iv, input, output ) ) )
|
702
|
+
{
|
703
|
+
return( ret );
|
704
|
+
}
|
705
|
+
|
706
|
+
*olen = ilen;
|
707
|
+
|
708
|
+
return( 0 );
|
709
|
+
}
|
710
|
+
#endif /* MBEDTLS_CIPHER_MODE_OFB */
|
711
|
+
|
712
|
+
#if defined(MBEDTLS_CIPHER_MODE_CTR)
|
713
|
+
if( ctx->cipher_info->mode == MBEDTLS_MODE_CTR )
|
714
|
+
{
|
715
|
+
if( 0 != ( ret = ctx->cipher_info->base->ctr_func( ctx->cipher_ctx,
|
716
|
+
ilen, &ctx->unprocessed_len, ctx->iv,
|
717
|
+
ctx->unprocessed_data, input, output ) ) )
|
718
|
+
{
|
719
|
+
return( ret );
|
720
|
+
}
|
721
|
+
|
722
|
+
*olen = ilen;
|
723
|
+
|
724
|
+
return( 0 );
|
725
|
+
}
|
726
|
+
#endif /* MBEDTLS_CIPHER_MODE_CTR */
|
727
|
+
|
728
|
+
#if defined(MBEDTLS_CIPHER_MODE_XTS)
|
729
|
+
if( ctx->cipher_info->mode == MBEDTLS_MODE_XTS )
|
730
|
+
{
|
731
|
+
if( ctx->unprocessed_len > 0 ) {
|
732
|
+
/* We can only process an entire data unit at a time. */
|
733
|
+
return( MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE );
|
734
|
+
}
|
735
|
+
|
736
|
+
ret = ctx->cipher_info->base->xts_func( ctx->cipher_ctx,
|
737
|
+
ctx->operation, ilen, ctx->iv, input, output );
|
738
|
+
if( ret != 0 )
|
739
|
+
{
|
740
|
+
return( ret );
|
741
|
+
}
|
742
|
+
|
743
|
+
*olen = ilen;
|
744
|
+
|
745
|
+
return( 0 );
|
746
|
+
}
|
747
|
+
#endif /* MBEDTLS_CIPHER_MODE_XTS */
|
748
|
+
|
749
|
+
#if defined(MBEDTLS_CIPHER_MODE_STREAM)
|
750
|
+
if( ctx->cipher_info->mode == MBEDTLS_MODE_STREAM )
|
751
|
+
{
|
752
|
+
if( 0 != ( ret = ctx->cipher_info->base->stream_func( ctx->cipher_ctx,
|
753
|
+
ilen, input, output ) ) )
|
754
|
+
{
|
755
|
+
return( ret );
|
756
|
+
}
|
757
|
+
|
758
|
+
*olen = ilen;
|
759
|
+
|
760
|
+
return( 0 );
|
761
|
+
}
|
762
|
+
#endif /* MBEDTLS_CIPHER_MODE_STREAM */
|
763
|
+
|
764
|
+
return( MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE );
|
765
|
+
}
|
766
|
+
|
767
|
+
#if defined(MBEDTLS_CIPHER_MODE_WITH_PADDING)
|
768
|
+
#if defined(MBEDTLS_CIPHER_PADDING_PKCS7)
|
769
|
+
/*
|
770
|
+
* PKCS7 (and PKCS5) padding: fill with ll bytes, with ll = padding_len
|
771
|
+
*/
|
772
|
+
static void add_pkcs_padding( unsigned char *output, size_t output_len,
|
773
|
+
size_t data_len )
|
774
|
+
{
|
775
|
+
size_t padding_len = output_len - data_len;
|
776
|
+
unsigned char i;
|
777
|
+
|
778
|
+
for( i = 0; i < padding_len; i++ )
|
779
|
+
output[data_len + i] = (unsigned char) padding_len;
|
780
|
+
}
|
781
|
+
|
782
|
+
static int get_pkcs_padding( unsigned char *input, size_t input_len,
|
783
|
+
size_t *data_len )
|
784
|
+
{
|
785
|
+
size_t i, pad_idx;
|
786
|
+
unsigned char padding_len, bad = 0;
|
787
|
+
|
788
|
+
if( NULL == input || NULL == data_len )
|
789
|
+
return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
|
790
|
+
|
791
|
+
padding_len = input[input_len - 1];
|
792
|
+
*data_len = input_len - padding_len;
|
793
|
+
|
794
|
+
/* Avoid logical || since it results in a branch */
|
795
|
+
bad |= padding_len > input_len;
|
796
|
+
bad |= padding_len == 0;
|
797
|
+
|
798
|
+
/* The number of bytes checked must be independent of padding_len,
|
799
|
+
* so pick input_len, which is usually 8 or 16 (one block) */
|
800
|
+
pad_idx = input_len - padding_len;
|
801
|
+
for( i = 0; i < input_len; i++ )
|
802
|
+
bad |= ( input[i] ^ padding_len ) * ( i >= pad_idx );
|
803
|
+
|
804
|
+
return( MBEDTLS_ERR_CIPHER_INVALID_PADDING * ( bad != 0 ) );
|
805
|
+
}
|
806
|
+
#endif /* MBEDTLS_CIPHER_PADDING_PKCS7 */
|
807
|
+
|
808
|
+
#if defined(MBEDTLS_CIPHER_PADDING_ONE_AND_ZEROS)
|
809
|
+
/*
|
810
|
+
* One and zeros padding: fill with 80 00 ... 00
|
811
|
+
*/
|
812
|
+
static void add_one_and_zeros_padding( unsigned char *output,
|
813
|
+
size_t output_len, size_t data_len )
|
814
|
+
{
|
815
|
+
size_t padding_len = output_len - data_len;
|
816
|
+
unsigned char i = 0;
|
817
|
+
|
818
|
+
output[data_len] = 0x80;
|
819
|
+
for( i = 1; i < padding_len; i++ )
|
820
|
+
output[data_len + i] = 0x00;
|
821
|
+
}
|
822
|
+
|
823
|
+
static int get_one_and_zeros_padding( unsigned char *input, size_t input_len,
|
824
|
+
size_t *data_len )
|
825
|
+
{
|
826
|
+
size_t i;
|
827
|
+
unsigned char done = 0, prev_done, bad;
|
828
|
+
|
829
|
+
if( NULL == input || NULL == data_len )
|
830
|
+
return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
|
831
|
+
|
832
|
+
bad = 0x80;
|
833
|
+
*data_len = 0;
|
834
|
+
for( i = input_len; i > 0; i-- )
|
835
|
+
{
|
836
|
+
prev_done = done;
|
837
|
+
done |= ( input[i - 1] != 0 );
|
838
|
+
*data_len |= ( i - 1 ) * ( done != prev_done );
|
839
|
+
bad ^= input[i - 1] * ( done != prev_done );
|
840
|
+
}
|
841
|
+
|
842
|
+
return( MBEDTLS_ERR_CIPHER_INVALID_PADDING * ( bad != 0 ) );
|
843
|
+
|
844
|
+
}
|
845
|
+
#endif /* MBEDTLS_CIPHER_PADDING_ONE_AND_ZEROS */
|
846
|
+
|
847
|
+
#if defined(MBEDTLS_CIPHER_PADDING_ZEROS_AND_LEN)
|
848
|
+
/*
|
849
|
+
* Zeros and len padding: fill with 00 ... 00 ll, where ll is padding length
|
850
|
+
*/
|
851
|
+
static void add_zeros_and_len_padding( unsigned char *output,
|
852
|
+
size_t output_len, size_t data_len )
|
853
|
+
{
|
854
|
+
size_t padding_len = output_len - data_len;
|
855
|
+
unsigned char i = 0;
|
856
|
+
|
857
|
+
for( i = 1; i < padding_len; i++ )
|
858
|
+
output[data_len + i - 1] = 0x00;
|
859
|
+
output[output_len - 1] = (unsigned char) padding_len;
|
860
|
+
}
|
861
|
+
|
862
|
+
static int get_zeros_and_len_padding( unsigned char *input, size_t input_len,
|
863
|
+
size_t *data_len )
|
864
|
+
{
|
865
|
+
size_t i, pad_idx;
|
866
|
+
unsigned char padding_len, bad = 0;
|
867
|
+
|
868
|
+
if( NULL == input || NULL == data_len )
|
869
|
+
return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
|
870
|
+
|
871
|
+
padding_len = input[input_len - 1];
|
872
|
+
*data_len = input_len - padding_len;
|
873
|
+
|
874
|
+
/* Avoid logical || since it results in a branch */
|
875
|
+
bad |= padding_len > input_len;
|
876
|
+
bad |= padding_len == 0;
|
877
|
+
|
878
|
+
/* The number of bytes checked must be independent of padding_len */
|
879
|
+
pad_idx = input_len - padding_len;
|
880
|
+
for( i = 0; i < input_len - 1; i++ )
|
881
|
+
bad |= input[i] * ( i >= pad_idx );
|
882
|
+
|
883
|
+
return( MBEDTLS_ERR_CIPHER_INVALID_PADDING * ( bad != 0 ) );
|
884
|
+
}
|
885
|
+
#endif /* MBEDTLS_CIPHER_PADDING_ZEROS_AND_LEN */
|
886
|
+
|
887
|
+
#if defined(MBEDTLS_CIPHER_PADDING_ZEROS)
|
888
|
+
/*
|
889
|
+
* Zero padding: fill with 00 ... 00
|
890
|
+
*/
|
891
|
+
static void add_zeros_padding( unsigned char *output,
|
892
|
+
size_t output_len, size_t data_len )
|
893
|
+
{
|
894
|
+
size_t i;
|
895
|
+
|
896
|
+
for( i = data_len; i < output_len; i++ )
|
897
|
+
output[i] = 0x00;
|
898
|
+
}
|
899
|
+
|
900
|
+
static int get_zeros_padding( unsigned char *input, size_t input_len,
|
901
|
+
size_t *data_len )
|
902
|
+
{
|
903
|
+
size_t i;
|
904
|
+
unsigned char done = 0, prev_done;
|
905
|
+
|
906
|
+
if( NULL == input || NULL == data_len )
|
907
|
+
return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
|
908
|
+
|
909
|
+
*data_len = 0;
|
910
|
+
for( i = input_len; i > 0; i-- )
|
911
|
+
{
|
912
|
+
prev_done = done;
|
913
|
+
done |= ( input[i-1] != 0 );
|
914
|
+
*data_len |= i * ( done != prev_done );
|
915
|
+
}
|
916
|
+
|
917
|
+
return( 0 );
|
918
|
+
}
|
919
|
+
#endif /* MBEDTLS_CIPHER_PADDING_ZEROS */
|
920
|
+
|
921
|
+
/*
|
922
|
+
* No padding: don't pad :)
|
923
|
+
*
|
924
|
+
* There is no add_padding function (check for NULL in mbedtls_cipher_finish)
|
925
|
+
* but a trivial get_padding function
|
926
|
+
*/
|
927
|
+
static int get_no_padding( unsigned char *input, size_t input_len,
|
928
|
+
size_t *data_len )
|
929
|
+
{
|
930
|
+
if( NULL == input || NULL == data_len )
|
931
|
+
return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
|
932
|
+
|
933
|
+
*data_len = input_len;
|
934
|
+
|
935
|
+
return( 0 );
|
936
|
+
}
|
937
|
+
#endif /* MBEDTLS_CIPHER_MODE_WITH_PADDING */
|
938
|
+
|
939
|
+
int mbedtls_cipher_finish( mbedtls_cipher_context_t *ctx,
|
940
|
+
unsigned char *output, size_t *olen )
|
941
|
+
{
|
942
|
+
CIPHER_VALIDATE_RET( ctx != NULL );
|
943
|
+
CIPHER_VALIDATE_RET( output != NULL );
|
944
|
+
CIPHER_VALIDATE_RET( olen != NULL );
|
945
|
+
if( ctx->cipher_info == NULL )
|
946
|
+
return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
|
947
|
+
|
948
|
+
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
949
|
+
if( ctx->psa_enabled == 1 )
|
950
|
+
{
|
951
|
+
/* While PSA Crypto has an API for multipart
|
952
|
+
* operations, we currently don't make it
|
953
|
+
* accessible through the cipher layer. */
|
954
|
+
return( MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE );
|
955
|
+
}
|
956
|
+
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
957
|
+
|
958
|
+
*olen = 0;
|
959
|
+
|
960
|
+
if( MBEDTLS_MODE_CFB == ctx->cipher_info->mode ||
|
961
|
+
MBEDTLS_MODE_OFB == ctx->cipher_info->mode ||
|
962
|
+
MBEDTLS_MODE_CTR == ctx->cipher_info->mode ||
|
963
|
+
MBEDTLS_MODE_GCM == ctx->cipher_info->mode ||
|
964
|
+
MBEDTLS_MODE_CCM_STAR_NO_TAG == ctx->cipher_info->mode ||
|
965
|
+
MBEDTLS_MODE_XTS == ctx->cipher_info->mode ||
|
966
|
+
MBEDTLS_MODE_STREAM == ctx->cipher_info->mode )
|
967
|
+
{
|
968
|
+
return( 0 );
|
969
|
+
}
|
970
|
+
|
971
|
+
if ( ( MBEDTLS_CIPHER_CHACHA20 == ctx->cipher_info->type ) ||
|
972
|
+
( MBEDTLS_CIPHER_CHACHA20_POLY1305 == ctx->cipher_info->type ) )
|
973
|
+
{
|
974
|
+
return( 0 );
|
975
|
+
}
|
976
|
+
|
977
|
+
if( MBEDTLS_MODE_ECB == ctx->cipher_info->mode )
|
978
|
+
{
|
979
|
+
if( ctx->unprocessed_len != 0 )
|
980
|
+
return( MBEDTLS_ERR_CIPHER_FULL_BLOCK_EXPECTED );
|
981
|
+
|
982
|
+
return( 0 );
|
983
|
+
}
|
984
|
+
|
985
|
+
#if defined(MBEDTLS_CIPHER_MODE_CBC)
|
986
|
+
if( MBEDTLS_MODE_CBC == ctx->cipher_info->mode )
|
987
|
+
{
|
988
|
+
int ret = 0;
|
989
|
+
|
990
|
+
if( MBEDTLS_ENCRYPT == ctx->operation )
|
991
|
+
{
|
992
|
+
/* check for 'no padding' mode */
|
993
|
+
if( NULL == ctx->add_padding )
|
994
|
+
{
|
995
|
+
if( 0 != ctx->unprocessed_len )
|
996
|
+
return( MBEDTLS_ERR_CIPHER_FULL_BLOCK_EXPECTED );
|
997
|
+
|
998
|
+
return( 0 );
|
999
|
+
}
|
1000
|
+
|
1001
|
+
ctx->add_padding( ctx->unprocessed_data, mbedtls_cipher_get_iv_size( ctx ),
|
1002
|
+
ctx->unprocessed_len );
|
1003
|
+
}
|
1004
|
+
else if( mbedtls_cipher_get_block_size( ctx ) != ctx->unprocessed_len )
|
1005
|
+
{
|
1006
|
+
/*
|
1007
|
+
* For decrypt operations, expect a full block,
|
1008
|
+
* or an empty block if no padding
|
1009
|
+
*/
|
1010
|
+
if( NULL == ctx->add_padding && 0 == ctx->unprocessed_len )
|
1011
|
+
return( 0 );
|
1012
|
+
|
1013
|
+
return( MBEDTLS_ERR_CIPHER_FULL_BLOCK_EXPECTED );
|
1014
|
+
}
|
1015
|
+
|
1016
|
+
/* cipher block */
|
1017
|
+
if( 0 != ( ret = ctx->cipher_info->base->cbc_func( ctx->cipher_ctx,
|
1018
|
+
ctx->operation, mbedtls_cipher_get_block_size( ctx ), ctx->iv,
|
1019
|
+
ctx->unprocessed_data, output ) ) )
|
1020
|
+
{
|
1021
|
+
return( ret );
|
1022
|
+
}
|
1023
|
+
|
1024
|
+
/* Set output size for decryption */
|
1025
|
+
if( MBEDTLS_DECRYPT == ctx->operation )
|
1026
|
+
return( ctx->get_padding( output, mbedtls_cipher_get_block_size( ctx ),
|
1027
|
+
olen ) );
|
1028
|
+
|
1029
|
+
/* Set output size for encryption */
|
1030
|
+
*olen = mbedtls_cipher_get_block_size( ctx );
|
1031
|
+
return( 0 );
|
1032
|
+
}
|
1033
|
+
#else
|
1034
|
+
((void) output);
|
1035
|
+
#endif /* MBEDTLS_CIPHER_MODE_CBC */
|
1036
|
+
|
1037
|
+
return( MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE );
|
1038
|
+
}
|
1039
|
+
|
1040
|
+
#if defined(MBEDTLS_CIPHER_MODE_WITH_PADDING)
|
1041
|
+
int mbedtls_cipher_set_padding_mode( mbedtls_cipher_context_t *ctx,
|
1042
|
+
mbedtls_cipher_padding_t mode )
|
1043
|
+
{
|
1044
|
+
CIPHER_VALIDATE_RET( ctx != NULL );
|
1045
|
+
|
1046
|
+
if( NULL == ctx->cipher_info || MBEDTLS_MODE_CBC != ctx->cipher_info->mode )
|
1047
|
+
{
|
1048
|
+
return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
|
1049
|
+
}
|
1050
|
+
|
1051
|
+
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
1052
|
+
if( ctx->psa_enabled == 1 )
|
1053
|
+
{
|
1054
|
+
/* While PSA Crypto knows about CBC padding
|
1055
|
+
* schemes, we currently don't make them
|
1056
|
+
* accessible through the cipher layer. */
|
1057
|
+
if( mode != MBEDTLS_PADDING_NONE )
|
1058
|
+
return( MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE );
|
1059
|
+
|
1060
|
+
return( 0 );
|
1061
|
+
}
|
1062
|
+
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
1063
|
+
|
1064
|
+
switch( mode )
|
1065
|
+
{
|
1066
|
+
#if defined(MBEDTLS_CIPHER_PADDING_PKCS7)
|
1067
|
+
case MBEDTLS_PADDING_PKCS7:
|
1068
|
+
ctx->add_padding = add_pkcs_padding;
|
1069
|
+
ctx->get_padding = get_pkcs_padding;
|
1070
|
+
break;
|
1071
|
+
#endif
|
1072
|
+
#if defined(MBEDTLS_CIPHER_PADDING_ONE_AND_ZEROS)
|
1073
|
+
case MBEDTLS_PADDING_ONE_AND_ZEROS:
|
1074
|
+
ctx->add_padding = add_one_and_zeros_padding;
|
1075
|
+
ctx->get_padding = get_one_and_zeros_padding;
|
1076
|
+
break;
|
1077
|
+
#endif
|
1078
|
+
#if defined(MBEDTLS_CIPHER_PADDING_ZEROS_AND_LEN)
|
1079
|
+
case MBEDTLS_PADDING_ZEROS_AND_LEN:
|
1080
|
+
ctx->add_padding = add_zeros_and_len_padding;
|
1081
|
+
ctx->get_padding = get_zeros_and_len_padding;
|
1082
|
+
break;
|
1083
|
+
#endif
|
1084
|
+
#if defined(MBEDTLS_CIPHER_PADDING_ZEROS)
|
1085
|
+
case MBEDTLS_PADDING_ZEROS:
|
1086
|
+
ctx->add_padding = add_zeros_padding;
|
1087
|
+
ctx->get_padding = get_zeros_padding;
|
1088
|
+
break;
|
1089
|
+
#endif
|
1090
|
+
case MBEDTLS_PADDING_NONE:
|
1091
|
+
ctx->add_padding = NULL;
|
1092
|
+
ctx->get_padding = get_no_padding;
|
1093
|
+
break;
|
1094
|
+
|
1095
|
+
default:
|
1096
|
+
return( MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE );
|
1097
|
+
}
|
1098
|
+
|
1099
|
+
return( 0 );
|
1100
|
+
}
|
1101
|
+
#endif /* MBEDTLS_CIPHER_MODE_WITH_PADDING */
|
1102
|
+
|
1103
|
+
#if defined(MBEDTLS_GCM_C) || defined(MBEDTLS_CHACHAPOLY_C)
|
1104
|
+
int mbedtls_cipher_write_tag( mbedtls_cipher_context_t *ctx,
|
1105
|
+
unsigned char *tag, size_t tag_len )
|
1106
|
+
{
|
1107
|
+
CIPHER_VALIDATE_RET( ctx != NULL );
|
1108
|
+
CIPHER_VALIDATE_RET( tag_len == 0 || tag != NULL );
|
1109
|
+
if( ctx->cipher_info == NULL )
|
1110
|
+
return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
|
1111
|
+
|
1112
|
+
if( MBEDTLS_ENCRYPT != ctx->operation )
|
1113
|
+
return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
|
1114
|
+
|
1115
|
+
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
1116
|
+
if( ctx->psa_enabled == 1 )
|
1117
|
+
{
|
1118
|
+
/* While PSA Crypto has an API for multipart
|
1119
|
+
* operations, we currently don't make it
|
1120
|
+
* accessible through the cipher layer. */
|
1121
|
+
return( MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE );
|
1122
|
+
}
|
1123
|
+
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
1124
|
+
|
1125
|
+
#if defined(MBEDTLS_GCM_C)
|
1126
|
+
if( MBEDTLS_MODE_GCM == ctx->cipher_info->mode )
|
1127
|
+
{
|
1128
|
+
size_t output_length;
|
1129
|
+
/* The code here doesn't yet support alternative implementations
|
1130
|
+
* that can delay up to a block of output. */
|
1131
|
+
return( mbedtls_gcm_finish( (mbedtls_gcm_context *) ctx->cipher_ctx,
|
1132
|
+
NULL, 0, &output_length,
|
1133
|
+
tag, tag_len ) );
|
1134
|
+
}
|
1135
|
+
#endif
|
1136
|
+
|
1137
|
+
#if defined(MBEDTLS_CHACHAPOLY_C)
|
1138
|
+
if ( MBEDTLS_CIPHER_CHACHA20_POLY1305 == ctx->cipher_info->type )
|
1139
|
+
{
|
1140
|
+
/* Don't allow truncated MAC for Poly1305 */
|
1141
|
+
if ( tag_len != 16U )
|
1142
|
+
return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
|
1143
|
+
|
1144
|
+
return( mbedtls_chachapoly_finish(
|
1145
|
+
(mbedtls_chachapoly_context*) ctx->cipher_ctx, tag ) );
|
1146
|
+
}
|
1147
|
+
#endif
|
1148
|
+
|
1149
|
+
return( 0 );
|
1150
|
+
}
|
1151
|
+
|
1152
|
+
int mbedtls_cipher_check_tag( mbedtls_cipher_context_t *ctx,
|
1153
|
+
const unsigned char *tag, size_t tag_len )
|
1154
|
+
{
|
1155
|
+
unsigned char check_tag[16];
|
1156
|
+
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
1157
|
+
|
1158
|
+
CIPHER_VALIDATE_RET( ctx != NULL );
|
1159
|
+
CIPHER_VALIDATE_RET( tag_len == 0 || tag != NULL );
|
1160
|
+
if( ctx->cipher_info == NULL )
|
1161
|
+
return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
|
1162
|
+
|
1163
|
+
if( MBEDTLS_DECRYPT != ctx->operation )
|
1164
|
+
{
|
1165
|
+
return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
|
1166
|
+
}
|
1167
|
+
|
1168
|
+
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
1169
|
+
if( ctx->psa_enabled == 1 )
|
1170
|
+
{
|
1171
|
+
/* While PSA Crypto has an API for multipart
|
1172
|
+
* operations, we currently don't make it
|
1173
|
+
* accessible through the cipher layer. */
|
1174
|
+
return( MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE );
|
1175
|
+
}
|
1176
|
+
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
1177
|
+
|
1178
|
+
/* Status to return on a non-authenticated algorithm. It would make sense
|
1179
|
+
* to return MBEDTLS_ERR_CIPHER_INVALID_CONTEXT or perhaps
|
1180
|
+
* MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA, but at the time I write this our
|
1181
|
+
* unit tests assume 0. */
|
1182
|
+
ret = 0;
|
1183
|
+
|
1184
|
+
#if defined(MBEDTLS_GCM_C)
|
1185
|
+
if( MBEDTLS_MODE_GCM == ctx->cipher_info->mode )
|
1186
|
+
{
|
1187
|
+
size_t output_length;
|
1188
|
+
/* The code here doesn't yet support alternative implementations
|
1189
|
+
* that can delay up to a block of output. */
|
1190
|
+
|
1191
|
+
if( tag_len > sizeof( check_tag ) )
|
1192
|
+
return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
|
1193
|
+
|
1194
|
+
if( 0 != ( ret = mbedtls_gcm_finish(
|
1195
|
+
(mbedtls_gcm_context *) ctx->cipher_ctx,
|
1196
|
+
NULL, 0, &output_length,
|
1197
|
+
check_tag, tag_len ) ) )
|
1198
|
+
{
|
1199
|
+
return( ret );
|
1200
|
+
}
|
1201
|
+
|
1202
|
+
/* Check the tag in "constant-time" */
|
1203
|
+
if( mbedtls_ct_memcmp( tag, check_tag, tag_len ) != 0 )
|
1204
|
+
{
|
1205
|
+
ret = MBEDTLS_ERR_CIPHER_AUTH_FAILED;
|
1206
|
+
goto exit;
|
1207
|
+
}
|
1208
|
+
}
|
1209
|
+
#endif /* MBEDTLS_GCM_C */
|
1210
|
+
|
1211
|
+
#if defined(MBEDTLS_CHACHAPOLY_C)
|
1212
|
+
if ( MBEDTLS_CIPHER_CHACHA20_POLY1305 == ctx->cipher_info->type )
|
1213
|
+
{
|
1214
|
+
/* Don't allow truncated MAC for Poly1305 */
|
1215
|
+
if ( tag_len != sizeof( check_tag ) )
|
1216
|
+
return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
|
1217
|
+
|
1218
|
+
ret = mbedtls_chachapoly_finish(
|
1219
|
+
(mbedtls_chachapoly_context*) ctx->cipher_ctx, check_tag );
|
1220
|
+
if ( ret != 0 )
|
1221
|
+
{
|
1222
|
+
return( ret );
|
1223
|
+
}
|
1224
|
+
|
1225
|
+
/* Check the tag in "constant-time" */
|
1226
|
+
if( mbedtls_ct_memcmp( tag, check_tag, tag_len ) != 0 )
|
1227
|
+
{
|
1228
|
+
ret = MBEDTLS_ERR_CIPHER_AUTH_FAILED;
|
1229
|
+
goto exit;
|
1230
|
+
}
|
1231
|
+
}
|
1232
|
+
#endif /* MBEDTLS_CHACHAPOLY_C */
|
1233
|
+
|
1234
|
+
exit:
|
1235
|
+
mbedtls_platform_zeroize( check_tag, tag_len );
|
1236
|
+
return( ret );
|
1237
|
+
}
|
1238
|
+
#endif /* MBEDTLS_GCM_C || MBEDTLS_CHACHAPOLY_C */
|
1239
|
+
|
1240
|
+
/*
|
1241
|
+
* Packet-oriented wrapper for non-AEAD modes
|
1242
|
+
*/
|
1243
|
+
int mbedtls_cipher_crypt( mbedtls_cipher_context_t *ctx,
|
1244
|
+
const unsigned char *iv, size_t iv_len,
|
1245
|
+
const unsigned char *input, size_t ilen,
|
1246
|
+
unsigned char *output, size_t *olen )
|
1247
|
+
{
|
1248
|
+
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
1249
|
+
size_t finish_olen;
|
1250
|
+
|
1251
|
+
CIPHER_VALIDATE_RET( ctx != NULL );
|
1252
|
+
CIPHER_VALIDATE_RET( iv_len == 0 || iv != NULL );
|
1253
|
+
CIPHER_VALIDATE_RET( ilen == 0 || input != NULL );
|
1254
|
+
CIPHER_VALIDATE_RET( output != NULL );
|
1255
|
+
CIPHER_VALIDATE_RET( olen != NULL );
|
1256
|
+
|
1257
|
+
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
1258
|
+
if( ctx->psa_enabled == 1 )
|
1259
|
+
{
|
1260
|
+
/* As in the non-PSA case, we don't check that
|
1261
|
+
* a key has been set. If not, the key slot will
|
1262
|
+
* still be in its default state of 0, which is
|
1263
|
+
* guaranteed to be invalid, hence the PSA-call
|
1264
|
+
* below will gracefully fail. */
|
1265
|
+
mbedtls_cipher_context_psa * const cipher_psa =
|
1266
|
+
(mbedtls_cipher_context_psa *) ctx->cipher_ctx;
|
1267
|
+
|
1268
|
+
psa_status_t status;
|
1269
|
+
psa_cipher_operation_t cipher_op = PSA_CIPHER_OPERATION_INIT;
|
1270
|
+
size_t part_len;
|
1271
|
+
|
1272
|
+
if( ctx->operation == MBEDTLS_DECRYPT )
|
1273
|
+
{
|
1274
|
+
status = psa_cipher_decrypt_setup( &cipher_op,
|
1275
|
+
cipher_psa->slot,
|
1276
|
+
cipher_psa->alg );
|
1277
|
+
}
|
1278
|
+
else if( ctx->operation == MBEDTLS_ENCRYPT )
|
1279
|
+
{
|
1280
|
+
status = psa_cipher_encrypt_setup( &cipher_op,
|
1281
|
+
cipher_psa->slot,
|
1282
|
+
cipher_psa->alg );
|
1283
|
+
}
|
1284
|
+
else
|
1285
|
+
return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
|
1286
|
+
|
1287
|
+
/* In the following, we can immediately return on an error,
|
1288
|
+
* because the PSA Crypto API guarantees that cipher operations
|
1289
|
+
* are terminated by unsuccessful calls to psa_cipher_update(),
|
1290
|
+
* and by any call to psa_cipher_finish(). */
|
1291
|
+
if( status != PSA_SUCCESS )
|
1292
|
+
return( MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED );
|
1293
|
+
|
1294
|
+
if( ctx->cipher_info->mode != MBEDTLS_MODE_ECB )
|
1295
|
+
{
|
1296
|
+
status = psa_cipher_set_iv( &cipher_op, iv, iv_len );
|
1297
|
+
if( status != PSA_SUCCESS )
|
1298
|
+
return( MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED );
|
1299
|
+
}
|
1300
|
+
|
1301
|
+
status = psa_cipher_update( &cipher_op,
|
1302
|
+
input, ilen,
|
1303
|
+
output, ilen, olen );
|
1304
|
+
if( status != PSA_SUCCESS )
|
1305
|
+
return( MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED );
|
1306
|
+
|
1307
|
+
status = psa_cipher_finish( &cipher_op,
|
1308
|
+
output + *olen, ilen - *olen,
|
1309
|
+
&part_len );
|
1310
|
+
if( status != PSA_SUCCESS )
|
1311
|
+
return( MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED );
|
1312
|
+
|
1313
|
+
*olen += part_len;
|
1314
|
+
return( 0 );
|
1315
|
+
}
|
1316
|
+
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
1317
|
+
|
1318
|
+
if( ( ret = mbedtls_cipher_set_iv( ctx, iv, iv_len ) ) != 0 )
|
1319
|
+
return( ret );
|
1320
|
+
|
1321
|
+
if( ( ret = mbedtls_cipher_reset( ctx ) ) != 0 )
|
1322
|
+
return( ret );
|
1323
|
+
|
1324
|
+
if( ( ret = mbedtls_cipher_update( ctx, input, ilen,
|
1325
|
+
output, olen ) ) != 0 )
|
1326
|
+
return( ret );
|
1327
|
+
|
1328
|
+
if( ( ret = mbedtls_cipher_finish( ctx, output + *olen,
|
1329
|
+
&finish_olen ) ) != 0 )
|
1330
|
+
return( ret );
|
1331
|
+
|
1332
|
+
*olen += finish_olen;
|
1333
|
+
|
1334
|
+
return( 0 );
|
1335
|
+
}
|
1336
|
+
|
1337
|
+
#if defined(MBEDTLS_CIPHER_MODE_AEAD)
|
1338
|
+
/*
|
1339
|
+
* Packet-oriented encryption for AEAD modes: internal function used by
|
1340
|
+
* mbedtls_cipher_auth_encrypt_ext().
|
1341
|
+
*/
|
1342
|
+
static int mbedtls_cipher_aead_encrypt( mbedtls_cipher_context_t *ctx,
|
1343
|
+
const unsigned char *iv, size_t iv_len,
|
1344
|
+
const unsigned char *ad, size_t ad_len,
|
1345
|
+
const unsigned char *input, size_t ilen,
|
1346
|
+
unsigned char *output, size_t *olen,
|
1347
|
+
unsigned char *tag, size_t tag_len )
|
1348
|
+
{
|
1349
|
+
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
1350
|
+
if( ctx->psa_enabled == 1 )
|
1351
|
+
{
|
1352
|
+
/* As in the non-PSA case, we don't check that
|
1353
|
+
* a key has been set. If not, the key slot will
|
1354
|
+
* still be in its default state of 0, which is
|
1355
|
+
* guaranteed to be invalid, hence the PSA-call
|
1356
|
+
* below will gracefully fail. */
|
1357
|
+
mbedtls_cipher_context_psa * const cipher_psa =
|
1358
|
+
(mbedtls_cipher_context_psa *) ctx->cipher_ctx;
|
1359
|
+
|
1360
|
+
psa_status_t status;
|
1361
|
+
|
1362
|
+
/* PSA Crypto API always writes the authentication tag
|
1363
|
+
* at the end of the encrypted message. */
|
1364
|
+
if( output == NULL || tag != output + ilen )
|
1365
|
+
return( MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE );
|
1366
|
+
|
1367
|
+
status = psa_aead_encrypt( cipher_psa->slot,
|
1368
|
+
cipher_psa->alg,
|
1369
|
+
iv, iv_len,
|
1370
|
+
ad, ad_len,
|
1371
|
+
input, ilen,
|
1372
|
+
output, ilen + tag_len, olen );
|
1373
|
+
if( status != PSA_SUCCESS )
|
1374
|
+
return( MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED );
|
1375
|
+
|
1376
|
+
*olen -= tag_len;
|
1377
|
+
return( 0 );
|
1378
|
+
}
|
1379
|
+
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
1380
|
+
|
1381
|
+
#if defined(MBEDTLS_GCM_C)
|
1382
|
+
if( MBEDTLS_MODE_GCM == ctx->cipher_info->mode )
|
1383
|
+
{
|
1384
|
+
*olen = ilen;
|
1385
|
+
return( mbedtls_gcm_crypt_and_tag( (mbedtls_gcm_context *)ctx->cipher_ctx, MBEDTLS_GCM_ENCRYPT,
|
1386
|
+
ilen, iv, iv_len, ad, ad_len,
|
1387
|
+
input, output, tag_len, tag ) );
|
1388
|
+
}
|
1389
|
+
#endif /* MBEDTLS_GCM_C */
|
1390
|
+
#if defined(MBEDTLS_CCM_C)
|
1391
|
+
if( MBEDTLS_MODE_CCM == ctx->cipher_info->mode )
|
1392
|
+
{
|
1393
|
+
*olen = ilen;
|
1394
|
+
return( mbedtls_ccm_encrypt_and_tag( ctx->cipher_ctx, ilen,
|
1395
|
+
iv, iv_len, ad, ad_len, input, output,
|
1396
|
+
tag, tag_len ) );
|
1397
|
+
}
|
1398
|
+
#endif /* MBEDTLS_CCM_C */
|
1399
|
+
#if defined(MBEDTLS_CHACHAPOLY_C)
|
1400
|
+
if ( MBEDTLS_CIPHER_CHACHA20_POLY1305 == ctx->cipher_info->type )
|
1401
|
+
{
|
1402
|
+
/* ChachaPoly has fixed length nonce and MAC (tag) */
|
1403
|
+
if ( ( iv_len != ctx->cipher_info->iv_size ) ||
|
1404
|
+
( tag_len != 16U ) )
|
1405
|
+
{
|
1406
|
+
return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
|
1407
|
+
}
|
1408
|
+
|
1409
|
+
*olen = ilen;
|
1410
|
+
return( mbedtls_chachapoly_encrypt_and_tag( ctx->cipher_ctx,
|
1411
|
+
ilen, iv, ad, ad_len, input, output, tag ) );
|
1412
|
+
}
|
1413
|
+
#endif /* MBEDTLS_CHACHAPOLY_C */
|
1414
|
+
|
1415
|
+
return( MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE );
|
1416
|
+
}
|
1417
|
+
|
1418
|
+
/*
|
1419
|
+
* Packet-oriented encryption for AEAD modes: internal function used by
|
1420
|
+
* mbedtls_cipher_auth_encrypt_ext().
|
1421
|
+
*/
|
1422
|
+
static int mbedtls_cipher_aead_decrypt( mbedtls_cipher_context_t *ctx,
|
1423
|
+
const unsigned char *iv, size_t iv_len,
|
1424
|
+
const unsigned char *ad, size_t ad_len,
|
1425
|
+
const unsigned char *input, size_t ilen,
|
1426
|
+
unsigned char *output, size_t *olen,
|
1427
|
+
const unsigned char *tag, size_t tag_len )
|
1428
|
+
{
|
1429
|
+
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
1430
|
+
if( ctx->psa_enabled == 1 )
|
1431
|
+
{
|
1432
|
+
/* As in the non-PSA case, we don't check that
|
1433
|
+
* a key has been set. If not, the key slot will
|
1434
|
+
* still be in its default state of 0, which is
|
1435
|
+
* guaranteed to be invalid, hence the PSA-call
|
1436
|
+
* below will gracefully fail. */
|
1437
|
+
mbedtls_cipher_context_psa * const cipher_psa =
|
1438
|
+
(mbedtls_cipher_context_psa *) ctx->cipher_ctx;
|
1439
|
+
|
1440
|
+
psa_status_t status;
|
1441
|
+
|
1442
|
+
/* PSA Crypto API always writes the authentication tag
|
1443
|
+
* at the end of the encrypted message. */
|
1444
|
+
if( input == NULL || tag != input + ilen )
|
1445
|
+
return( MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE );
|
1446
|
+
|
1447
|
+
status = psa_aead_decrypt( cipher_psa->slot,
|
1448
|
+
cipher_psa->alg,
|
1449
|
+
iv, iv_len,
|
1450
|
+
ad, ad_len,
|
1451
|
+
input, ilen + tag_len,
|
1452
|
+
output, ilen, olen );
|
1453
|
+
if( status == PSA_ERROR_INVALID_SIGNATURE )
|
1454
|
+
return( MBEDTLS_ERR_CIPHER_AUTH_FAILED );
|
1455
|
+
else if( status != PSA_SUCCESS )
|
1456
|
+
return( MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED );
|
1457
|
+
|
1458
|
+
return( 0 );
|
1459
|
+
}
|
1460
|
+
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
1461
|
+
|
1462
|
+
#if defined(MBEDTLS_GCM_C)
|
1463
|
+
if( MBEDTLS_MODE_GCM == ctx->cipher_info->mode )
|
1464
|
+
{
|
1465
|
+
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
1466
|
+
|
1467
|
+
*olen = ilen;
|
1468
|
+
ret = mbedtls_gcm_auth_decrypt( (mbedtls_gcm_context *)ctx->cipher_ctx, ilen,
|
1469
|
+
iv, iv_len, ad, ad_len,
|
1470
|
+
tag, tag_len, input, output );
|
1471
|
+
|
1472
|
+
if( ret == MBEDTLS_ERR_GCM_AUTH_FAILED )
|
1473
|
+
ret = MBEDTLS_ERR_CIPHER_AUTH_FAILED;
|
1474
|
+
|
1475
|
+
return( ret );
|
1476
|
+
}
|
1477
|
+
#endif /* MBEDTLS_GCM_C */
|
1478
|
+
#if defined(MBEDTLS_CCM_C)
|
1479
|
+
if( MBEDTLS_MODE_CCM == ctx->cipher_info->mode )
|
1480
|
+
{
|
1481
|
+
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
1482
|
+
|
1483
|
+
*olen = ilen;
|
1484
|
+
ret = mbedtls_ccm_auth_decrypt( ctx->cipher_ctx, ilen,
|
1485
|
+
iv, iv_len, ad, ad_len,
|
1486
|
+
input, output, tag, tag_len );
|
1487
|
+
|
1488
|
+
if( ret == MBEDTLS_ERR_CCM_AUTH_FAILED )
|
1489
|
+
ret = MBEDTLS_ERR_CIPHER_AUTH_FAILED;
|
1490
|
+
|
1491
|
+
return( ret );
|
1492
|
+
}
|
1493
|
+
#endif /* MBEDTLS_CCM_C */
|
1494
|
+
#if defined(MBEDTLS_CHACHAPOLY_C)
|
1495
|
+
if ( MBEDTLS_CIPHER_CHACHA20_POLY1305 == ctx->cipher_info->type )
|
1496
|
+
{
|
1497
|
+
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
1498
|
+
|
1499
|
+
/* ChachaPoly has fixed length nonce and MAC (tag) */
|
1500
|
+
if ( ( iv_len != ctx->cipher_info->iv_size ) ||
|
1501
|
+
( tag_len != 16U ) )
|
1502
|
+
{
|
1503
|
+
return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
|
1504
|
+
}
|
1505
|
+
|
1506
|
+
*olen = ilen;
|
1507
|
+
ret = mbedtls_chachapoly_auth_decrypt( ctx->cipher_ctx, ilen,
|
1508
|
+
iv, ad, ad_len, tag, input, output );
|
1509
|
+
|
1510
|
+
if( ret == MBEDTLS_ERR_CHACHAPOLY_AUTH_FAILED )
|
1511
|
+
ret = MBEDTLS_ERR_CIPHER_AUTH_FAILED;
|
1512
|
+
|
1513
|
+
return( ret );
|
1514
|
+
}
|
1515
|
+
#endif /* MBEDTLS_CHACHAPOLY_C */
|
1516
|
+
|
1517
|
+
return( MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE );
|
1518
|
+
}
|
1519
|
+
#endif /* MBEDTLS_CIPHER_MODE_AEAD */
|
1520
|
+
|
1521
|
+
#if defined(MBEDTLS_CIPHER_MODE_AEAD) || defined(MBEDTLS_NIST_KW_C)
|
1522
|
+
/*
|
1523
|
+
* Packet-oriented encryption for AEAD/NIST_KW: public function.
|
1524
|
+
*/
|
1525
|
+
int mbedtls_cipher_auth_encrypt_ext( mbedtls_cipher_context_t *ctx,
|
1526
|
+
const unsigned char *iv, size_t iv_len,
|
1527
|
+
const unsigned char *ad, size_t ad_len,
|
1528
|
+
const unsigned char *input, size_t ilen,
|
1529
|
+
unsigned char *output, size_t output_len,
|
1530
|
+
size_t *olen, size_t tag_len )
|
1531
|
+
{
|
1532
|
+
CIPHER_VALIDATE_RET( ctx != NULL );
|
1533
|
+
CIPHER_VALIDATE_RET( iv_len == 0 || iv != NULL );
|
1534
|
+
CIPHER_VALIDATE_RET( ad_len == 0 || ad != NULL );
|
1535
|
+
CIPHER_VALIDATE_RET( ilen == 0 || input != NULL );
|
1536
|
+
CIPHER_VALIDATE_RET( output != NULL );
|
1537
|
+
CIPHER_VALIDATE_RET( olen != NULL );
|
1538
|
+
|
1539
|
+
#if defined(MBEDTLS_NIST_KW_C)
|
1540
|
+
if(
|
1541
|
+
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
1542
|
+
ctx->psa_enabled == 0 &&
|
1543
|
+
#endif
|
1544
|
+
( MBEDTLS_MODE_KW == ctx->cipher_info->mode ||
|
1545
|
+
MBEDTLS_MODE_KWP == ctx->cipher_info->mode ) )
|
1546
|
+
{
|
1547
|
+
mbedtls_nist_kw_mode_t mode = ( MBEDTLS_MODE_KW == ctx->cipher_info->mode ) ?
|
1548
|
+
MBEDTLS_KW_MODE_KW : MBEDTLS_KW_MODE_KWP;
|
1549
|
+
|
1550
|
+
/* There is no iv, tag or ad associated with KW and KWP,
|
1551
|
+
* so these length should be 0 as documented. */
|
1552
|
+
if( iv_len != 0 || tag_len != 0 || ad_len != 0 )
|
1553
|
+
return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
|
1554
|
+
|
1555
|
+
(void) iv;
|
1556
|
+
(void) ad;
|
1557
|
+
|
1558
|
+
return( mbedtls_nist_kw_wrap( ctx->cipher_ctx, mode, input, ilen,
|
1559
|
+
output, olen, output_len ) );
|
1560
|
+
}
|
1561
|
+
#endif /* MBEDTLS_NIST_KW_C */
|
1562
|
+
|
1563
|
+
#if defined(MBEDTLS_CIPHER_MODE_AEAD)
|
1564
|
+
/* AEAD case: check length before passing on to shared function */
|
1565
|
+
if( output_len < ilen + tag_len )
|
1566
|
+
return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
|
1567
|
+
|
1568
|
+
int ret = mbedtls_cipher_aead_encrypt( ctx, iv, iv_len, ad, ad_len,
|
1569
|
+
input, ilen, output, olen,
|
1570
|
+
output + ilen, tag_len );
|
1571
|
+
*olen += tag_len;
|
1572
|
+
return( ret );
|
1573
|
+
#else
|
1574
|
+
return( MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE );
|
1575
|
+
#endif /* MBEDTLS_CIPHER_MODE_AEAD */
|
1576
|
+
}
|
1577
|
+
|
1578
|
+
/*
|
1579
|
+
* Packet-oriented decryption for AEAD/NIST_KW: public function.
|
1580
|
+
*/
|
1581
|
+
int mbedtls_cipher_auth_decrypt_ext( mbedtls_cipher_context_t *ctx,
|
1582
|
+
const unsigned char *iv, size_t iv_len,
|
1583
|
+
const unsigned char *ad, size_t ad_len,
|
1584
|
+
const unsigned char *input, size_t ilen,
|
1585
|
+
unsigned char *output, size_t output_len,
|
1586
|
+
size_t *olen, size_t tag_len )
|
1587
|
+
{
|
1588
|
+
CIPHER_VALIDATE_RET( ctx != NULL );
|
1589
|
+
CIPHER_VALIDATE_RET( iv_len == 0 || iv != NULL );
|
1590
|
+
CIPHER_VALIDATE_RET( ad_len == 0 || ad != NULL );
|
1591
|
+
CIPHER_VALIDATE_RET( ilen == 0 || input != NULL );
|
1592
|
+
CIPHER_VALIDATE_RET( output_len == 0 || output != NULL );
|
1593
|
+
CIPHER_VALIDATE_RET( olen != NULL );
|
1594
|
+
|
1595
|
+
#if defined(MBEDTLS_NIST_KW_C)
|
1596
|
+
if(
|
1597
|
+
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
1598
|
+
ctx->psa_enabled == 0 &&
|
1599
|
+
#endif
|
1600
|
+
( MBEDTLS_MODE_KW == ctx->cipher_info->mode ||
|
1601
|
+
MBEDTLS_MODE_KWP == ctx->cipher_info->mode ) )
|
1602
|
+
{
|
1603
|
+
mbedtls_nist_kw_mode_t mode = ( MBEDTLS_MODE_KW == ctx->cipher_info->mode ) ?
|
1604
|
+
MBEDTLS_KW_MODE_KW : MBEDTLS_KW_MODE_KWP;
|
1605
|
+
|
1606
|
+
/* There is no iv, tag or ad associated with KW and KWP,
|
1607
|
+
* so these length should be 0 as documented. */
|
1608
|
+
if( iv_len != 0 || tag_len != 0 || ad_len != 0 )
|
1609
|
+
return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
|
1610
|
+
|
1611
|
+
(void) iv;
|
1612
|
+
(void) ad;
|
1613
|
+
|
1614
|
+
return( mbedtls_nist_kw_unwrap( ctx->cipher_ctx, mode, input, ilen,
|
1615
|
+
output, olen, output_len ) );
|
1616
|
+
}
|
1617
|
+
#endif /* MBEDTLS_NIST_KW_C */
|
1618
|
+
|
1619
|
+
#if defined(MBEDTLS_CIPHER_MODE_AEAD)
|
1620
|
+
/* AEAD case: check length before passing on to shared function */
|
1621
|
+
if( ilen < tag_len || output_len < ilen - tag_len )
|
1622
|
+
return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
|
1623
|
+
|
1624
|
+
return( mbedtls_cipher_aead_decrypt( ctx, iv, iv_len, ad, ad_len,
|
1625
|
+
input, ilen - tag_len, output, olen,
|
1626
|
+
input + ilen - tag_len, tag_len ) );
|
1627
|
+
#else
|
1628
|
+
return( MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE );
|
1629
|
+
#endif /* MBEDTLS_CIPHER_MODE_AEAD */
|
1630
|
+
}
|
1631
|
+
#endif /* MBEDTLS_CIPHER_MODE_AEAD || MBEDTLS_NIST_KW_C */
|
1632
|
+
|
1633
|
+
#endif /* MBEDTLS_CIPHER_C */
|