@@ -37,11 +37,13 @@ class sha3_base final {
37
37
38
38
BOOST_CRYPT_GPU_ENABLED_CONSTEXPR auto process_message_block () noexcept -> void;
39
39
40
+ template <compat::size_t Extent = compat::dynamic_extent>
40
41
[[nodiscard]] BOOST_CRYPT_GPU_ENABLED_CONSTEXPR
41
- auto update (compat::span<const compat::byte> data) noexcept -> state;
42
+ auto update (compat::span<const compat::byte, Extent > data) noexcept -> state;
42
43
44
+ template <compat::size_t Extent = compat::dynamic_extent>
43
45
BOOST_CRYPT_GPU_ENABLED_CONSTEXPR
44
- auto xof_digest_impl (compat::span<compat::byte> data, compat::size_t amount) noexcept -> void;
46
+ auto xof_digest_impl (compat::span<compat::byte, Extent > data, compat::size_t amount) noexcept -> void;
45
47
46
48
BOOST_CRYPT_GPU_ENABLED_CONSTEXPR
47
49
auto sha_digest_impl (compat::span<compat::byte, digest_size> data) const noexcept -> void;
@@ -57,7 +59,8 @@ class sha3_base final {
57
59
58
60
BOOST_CRYPT_GPU_ENABLED_CONSTEXPR auto init () noexcept -> void;
59
61
60
- BOOST_CRYPT_GPU_ENABLED_CONSTEXPR auto process_bytes (compat::span<const compat::byte> data) noexcept -> state;
62
+ template <compat::size_t Extent = compat::dynamic_extent>
63
+ BOOST_CRYPT_GPU_ENABLED_CONSTEXPR auto process_bytes (compat::span<const compat::byte, Extent> data) noexcept -> state;
61
64
62
65
template <concepts::sized_range SizedRange>
63
66
BOOST_CRYPT_GPU_ENABLED auto process_bytes (SizedRange&& data) noexcept -> state;
@@ -241,14 +244,30 @@ BOOST_CRYPT_GPU_ENABLED_CONSTEXPR auto sha3_base<digest_size, is_xof>::process_m
241
244
buffer_index_ = 0U ;
242
245
}
243
246
247
+ // In the fixed extent case where we check Extent == 0 this can make the rest of the code unreachable
248
+ // We consider this a good thing since this means our compile time checks are working
249
+ #ifdef _MSC_VER
250
+ #pragma warning(push)
251
+ #pragma warning(disable : 4702)
252
+ #endif
253
+
244
254
template <compat::size_t digest_size, bool is_xof>
255
+ template <compat::size_t Extent>
245
256
[[nodiscard]] BOOST_CRYPT_GPU_ENABLED_CONSTEXPR
246
- auto sha3_base<digest_size, is_xof>::update(compat::span<const compat::byte> data) noexcept -> state
257
+ auto sha3_base<digest_size, is_xof>::update(compat::span<const compat::byte, Extent > data) noexcept -> state
247
258
{
248
- if (data.empty ())
259
+ if constexpr (Extent == compat::dynamic_extent)
260
+ {
261
+ if (data.empty ())
262
+ {
263
+ return state::success;
264
+ }
265
+ }
266
+ else if constexpr (Extent == 0U )
249
267
{
250
268
return state::success;
251
269
}
270
+
252
271
if (computed_)
253
272
{
254
273
corrupted_ = true ;
@@ -271,6 +290,10 @@ auto sha3_base<digest_size, is_xof>::update(compat::span<const compat::byte> dat
271
290
return state::success;
272
291
}
273
292
293
+ #ifdef _MSC_VER
294
+ #pragma warning(pop)
295
+ #endif
296
+
274
297
template <compat::size_t digest_size, bool is_xof>
275
298
BOOST_CRYPT_GPU_ENABLED_CONSTEXPR sha3_base<digest_size, is_xof>::~sha3_base () noexcept
276
299
{
@@ -292,8 +315,9 @@ BOOST_CRYPT_GPU_ENABLED_CONSTEXPR auto sha3_base<digest_size, is_xof>::init() no
292
315
}
293
316
294
317
template <compat::size_t digest_size, bool is_xof>
318
+ template <compat::size_t Extent>
295
319
BOOST_CRYPT_GPU_ENABLED_CONSTEXPR auto
296
- sha3_base<digest_size, is_xof>::process_bytes(compat::span<const compat::byte> data) noexcept -> state
320
+ sha3_base<digest_size, is_xof>::process_bytes(compat::span<const compat::byte, Extent > data) noexcept -> state
297
321
{
298
322
return update (data);
299
323
}
@@ -333,8 +357,9 @@ BOOST_CRYPT_GPU_ENABLED_CONSTEXPR auto sha3_base<digest_size, is_xof>::finalize(
333
357
}
334
358
335
359
template <compat::size_t digest_size, bool is_xof>
360
+ template <compat::size_t Extent>
336
361
BOOST_CRYPT_GPU_ENABLED_CONSTEXPR
337
- auto sha3_base<digest_size, is_xof>::xof_digest_impl(compat::span<compat::byte> data, std::size_t amount) noexcept -> void
362
+ auto sha3_base<digest_size, is_xof>::xof_digest_impl(compat::span<compat::byte, Extent > data, std::size_t amount) noexcept -> void
338
363
{
339
364
static_assert (is_xof, " Calling for variable amounts of data is not allowed with non-XOF hashers" );
340
365
@@ -390,11 +415,19 @@ sha3_base<digest_size, is_xof>::get_digest() noexcept
390
415
}
391
416
392
417
return_type digest {};
393
- xof_digest_impl (digest, digest_size);
418
+ compat::span<compat::byte, digest_size> digest_span {digest};
419
+ xof_digest_impl (digest_span, digest_size);
394
420
395
421
return digest;
396
422
}
397
423
424
+ // In the fixed extent case where we check Extent < digest_size this can make the rest of the code unreachable
425
+ // We consider this a good thing since this means our compile time checks are working
426
+ #ifdef _MSC_VER
427
+ #pragma warning(push)
428
+ #pragma warning(disable : 4702)
429
+ #endif
430
+
398
431
template <compat::size_t digest_size, bool is_xof>
399
432
template <bool Const, compat::size_t Extent>
400
433
[[nodiscard]] BOOST_CRYPT_GPU_ENABLED_CONSTEXPR
@@ -404,7 +437,15 @@ compat::enable_if_t<Const, state> sha3_base<digest_size, is_xof>::get_digest(com
404
437
{
405
438
return state::state_error;
406
439
}
407
- if (data.size () < digest_size)
440
+
441
+ if constexpr (Extent == compat::dynamic_extent)
442
+ {
443
+ if (data.size () < digest_size)
444
+ {
445
+ return state::insufficient_output_length;
446
+ }
447
+ }
448
+ else if constexpr (Extent < digest_size)
408
449
{
409
450
return state::insufficient_output_length;
410
451
}
@@ -431,6 +472,10 @@ compat::enable_if_t<Const, state> sha3_base<digest_size, is_xof>::get_digest(com
431
472
return state::success;
432
473
}
433
474
475
+ #ifdef _MSC_VER
476
+ #pragma warning(pop)
477
+ #endif
478
+
434
479
template <compat::size_t digest_size, bool is_xof>
435
480
template <bool Const, compat::size_t Extent>
436
481
[[nodiscard]] BOOST_CRYPT_GPU_ENABLED_CONSTEXPR
@@ -459,15 +504,13 @@ compat::enable_if_t<Const, state> sha3_base<digest_size, is_xof>::get_digest(Ran
459
504
return state::state_error;
460
505
}
461
506
462
- const auto data_size { std::size ( data)};
507
+ auto data_span {compat::span<value_type>(compat::forward<Range>( data) )};
463
508
464
- if (data_size < digest_size)
509
+ if (data_span. size_bytes () < digest_size)
465
510
{
466
511
return state::insufficient_output_length;
467
512
}
468
513
469
- auto data_span {compat::span<value_type>(compat::forward<Range>(data))};
470
-
471
514
#if defined(__clang__) && __clang_major__ >= 19
472
515
#pragma clang diagnostic push
473
516
#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-container"
@@ -499,15 +542,14 @@ compat::enable_if_t<Const, state> sha3_base<digest_size, is_xof>::get_digest(Ran
499
542
return state::state_error;
500
543
}
501
544
502
- const auto data_size {std::size (data)};
503
545
auto data_span {compat::span<value_type>(compat::forward<Range>(data))};
504
546
505
547
#if defined(__clang__) && __clang_major__ >= 19
506
548
#pragma clang diagnostic push
507
549
#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-container"
508
550
#endif
509
551
510
- xof_digest_impl (compat::span<compat::byte>(compat::as_writable_bytes (data_span).data (), data_size), data_size );
552
+ xof_digest_impl (compat::span<compat::byte>(compat::as_writable_bytes (data_span).data (), data_span. size_bytes ()), data_span. size_bytes () );
511
553
512
554
#if defined(__clang__) && __clang_major__ >= 19
513
555
#pragma clang diagnostic pop
@@ -526,7 +568,7 @@ compat::enable_if_t<Const, state> sha3_base<digest_size, is_xof>::get_digest(com
526
568
return state::state_error;
527
569
}
528
570
529
- if (data.size () < amount)
571
+ if (data.size_bytes () < amount)
530
572
{
531
573
return state::insufficient_output_length;
532
574
}
@@ -549,13 +591,13 @@ compat::enable_if_t<Const, state> sha3_base<digest_size, is_xof>::get_digest(Ran
549
591
return state::state_error;
550
592
}
551
593
552
- if (std::size (data) < amount)
594
+ auto data_span {compat::span<value_type>(compat::forward<Range>(data))};
595
+
596
+ if (data_span.size_bytes () < amount)
553
597
{
554
598
return state::insufficient_output_length;
555
599
}
556
600
557
- auto data_span {compat::span<value_type>(compat::forward<Range>(data))};
558
-
559
601
#if defined(__clang__) && __clang_major__ >= 19
560
602
#pragma clang diagnostic push
561
603
#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-container"
0 commit comments