@series-inc/rundot-syncplay 6.0.0-rc.2 → 6.0.0-rc.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +133 -0
- package/core/deterministic-math.d.ts +75 -1
- package/core/native/instance_ledger.hpp +1095 -0
- package/core/native/legacy_checkpoint_ids.hpp +107 -0
- package/core/native/physics/abi.cpp +39 -211
- package/core/native/physics/abi.hpp +2 -6
- package/core/native/physics/articulation.cpp +1434 -0
- package/core/native/physics/articulation.hpp +279 -0
- package/core/native/physics/buoyancy.cpp +1588 -0
- package/core/native/physics/buoyancy.hpp +254 -0
- package/core/native/physics/capsule_triangle.cpp +168 -0
- package/core/native/physics/capsule_triangle.hpp +40 -0
- package/core/native/physics/capsule_triangle_native.inc +291 -0
- package/core/native/physics/certified_sum.hpp +218 -0
- package/core/native/physics/character.cpp +638 -0
- package/core/native/physics/character.hpp +169 -0
- package/core/native/physics/checkpoint_schema.hpp +379 -0
- package/core/native/physics/cloth.cpp +1401 -0
- package/core/native/physics/cloth.hpp +357 -0
- package/core/native/physics/constraint_rows.cpp +363 -2
- package/core/native/physics/constraint_rows.hpp +72 -1
- package/core/native/physics/deformable_query.cpp +1630 -0
- package/core/native/physics/deformable_query.hpp +578 -0
- package/core/native/physics/distance.cpp +1166 -0
- package/core/native/physics/distance.hpp +151 -0
- package/core/native/physics/exact/exact-applied.cpp +101 -0
- package/core/native/physics/exact/exact-applied.hpp +112 -0
- package/core/native/physics/exact/exact-dyadic.cpp +691 -0
- package/core/native/physics/exact/exact-dyadic.hpp +58 -0
- package/core/native/physics/exact/exact-operation.hpp +51 -0
- package/core/native/physics/exact/word-core.hpp +262 -0
- package/core/native/physics/extended_abi.cpp +1242 -0
- package/core/native/physics/extended_abi.hpp +355 -0
- package/core/native/physics/extended_abi_characters.cpp +261 -0
- package/core/native/physics/extended_abi_characters.hpp +434 -0
- package/core/native/physics/extended_abi_core_features.cpp +713 -0
- package/core/native/physics/extended_abi_core_features.hpp +226 -0
- package/core/native/physics/extended_abi_deformables.cpp +448 -0
- package/core/native/physics/extended_abi_deformables.hpp +867 -0
- package/core/native/physics/extended_abi_vehicles.cpp +411 -0
- package/core/native/physics/extended_abi_vehicles.hpp +222 -0
- package/core/native/physics/fracture.cpp +1981 -0
- package/core/native/physics/fracture.hpp +460 -0
- package/core/native/physics/gear.cpp +563 -0
- package/core/native/physics/gear.hpp +158 -0
- package/core/native/physics/geometry_memory.hpp +476 -0
- package/core/native/physics/geometry_store.cpp +547 -0
- package/core/native/physics/geometry_store.hpp +134 -0
- package/core/native/physics/lag_compensation.cpp +1626 -0
- package/core/native/physics/lag_compensation.hpp +405 -0
- package/core/native/physics/mass_properties.cpp +449 -0
- package/core/native/physics/mass_properties.hpp +23 -0
- package/core/native/physics/material_pose.hpp +988 -0
- package/core/native/physics/particles.cpp +1065 -0
- package/core/native/physics/particles.hpp +261 -0
- package/core/native/physics/path_joint.cpp +781 -0
- package/core/native/physics/path_joint.hpp +154 -0
- package/core/native/physics/physics.cpp +13043 -1065
- package/core/native/physics/physics.hpp +184 -8
- package/core/native/physics/planar_deformable.cpp +2433 -0
- package/core/native/physics/planar_deformable.hpp +889 -0
- package/core/native/physics/platformer_2d.cpp +1353 -0
- package/core/native/physics/platformer_2d.hpp +340 -0
- package/core/native/physics/powered_ragdoll.cpp +1100 -0
- package/core/native/physics/powered_ragdoll.hpp +279 -0
- package/core/native/physics/powertrain.cpp +586 -0
- package/core/native/physics/powertrain.hpp +180 -0
- package/core/native/physics/pulley.cpp +311 -0
- package/core/native/physics/pulley.hpp +121 -0
- package/core/native/physics/ragdoll.cpp +586 -0
- package/core/native/physics/ragdoll.hpp +221 -0
- package/core/native/physics/rope.cpp +692 -0
- package/core/native/physics/rope.hpp +215 -0
- package/core/native/physics/rounded_convex.cpp +1229 -0
- package/core/native/physics/rounded_convex.hpp +287 -0
- package/core/native/physics/sdf_geometry.cpp +1821 -0
- package/core/native/physics/sdf_geometry.hpp +474 -0
- package/core/native/physics/soft_body.cpp +1449 -0
- package/core/native/physics/soft_body.hpp +328 -0
- package/core/native/physics/soft_collision.cpp +1862 -0
- package/core/native/physics/soft_collision.hpp +561 -0
- package/core/native/physics/surface_velocity.cpp +366 -0
- package/core/native/physics/surface_velocity.hpp +243 -0
- package/core/native/physics/topology.cpp +357 -39
- package/core/native/physics/topology.hpp +97 -6
- package/core/native/physics/tracks.cpp +1179 -0
- package/core/native/physics/tracks.hpp +404 -0
- package/core/native/physics/vehicle.cpp +629 -0
- package/core/native/physics/vehicle.hpp +191 -0
- package/core/native/physics/voxel_cooking.cpp +1929 -0
- package/core/native/physics/voxel_cooking.hpp +395 -0
- package/core/native/physics/world.cpp +5290 -854
- package/core/native/physics/world.hpp +796 -24
- package/core/native/physics/world_abi.cpp +3840 -306
- package/core/native/physics/world_abi.hpp +530 -10
- package/core/native/physics/world_digest_visitor.hpp +277 -0
- package/core/native/physics/world_strong_digest.hpp +557 -0
- package/core/native/physics2d/ccd.cpp +1302 -0
- package/core/native/physics2d/ccd.hpp +141 -0
- package/core/native/physics2d/checkpoint_memory.hpp +349 -0
- package/core/native/physics2d/clock_primitives.hpp +138 -0
- package/core/native/physics2d/commands.cpp +174 -28
- package/core/native/physics2d/commands.hpp +3 -1
- package/core/native/physics2d/compound.cpp +581 -0
- package/core/native/physics2d/compound.hpp +248 -0
- package/core/native/physics2d/contour.cpp +325 -0
- package/core/native/physics2d/contour.hpp +143 -0
- package/core/native/physics2d/frame_scope.hpp +124 -0
- package/core/native/physics2d/joint_phases.hpp +93 -0
- package/core/native/physics2d/joints.cpp +587 -150
- package/core/native/physics2d/joints.hpp +5 -0
- package/core/native/physics2d/memory_private.hpp +125 -0
- package/core/native/physics2d/owned_abi.cpp +1354 -879
- package/core/native/physics2d/owned_abi.hpp +190 -52
- package/core/native/physics2d/phase_test_hooks.hpp +17 -0
- package/core/native/physics2d/physics2d.cpp +2073 -120
- package/core/native/physics2d/physics2d.hpp +154 -2
- package/core/native/physics2d/queries.cpp +1055 -79
- package/core/native/physics2d/queries.hpp +71 -5
- package/core/native/physics2d/world.cpp +1313 -353
- package/core/native/physics2d/world.hpp +124 -13
- package/core/native/sha256/sha256_compress_unsigned.hpp +68 -0
- package/core/native/sha256/sha256_fips_constants.hpp +24 -0
- package/core/native/sha256/sha256_length.hpp +56 -0
- package/core/native/sha256/sha256_memo.hpp +48 -0
- package/core/native/sha256/sha256_sink.hpp +234 -0
- package/core/physics2d-owned.d.ts +466 -126
- package/core/runtime.d.ts +192 -19
- package/core/scripts/build-native.mjs +34 -0
- package/core/scripts/build-wasm-physics.mjs +272 -23
- package/core/scripts/extended-physics-profile.mjs +634 -0
- package/core/scripts/generate-physics2d-vectors.mjs +59 -0
- package/core/src/kinetix-deterministic-math.d.ts +2 -0
- package/core/src/kinetix-deterministic-math.mjs +513 -27
- package/core/src/kinetix-owned-runtime-adapter.mjs +788 -0
- package/core/src/kinetix-runtime-adapter-utils.mjs +54 -6
- package/core/src/kinetix-runtime-contract.mjs +55 -9
- package/core/src/kinetix-runtime-identity.mjs +12 -1
- package/core/src/kinetix-session-config.mjs +7 -2
- package/core/src/kinetix-state-report.mjs +36 -0
- package/core/src/physics/abi-constants.mjs +5 -4
- package/core/src/physics/articulation.d.mts +194 -0
- package/core/src/physics/articulation.mjs +1141 -0
- package/core/src/physics/buoyancy.d.mts +143 -0
- package/core/src/physics/buoyancy.mjs +268 -0
- package/core/src/physics/cloth.d.mts +314 -0
- package/core/src/physics/cloth.mjs +1156 -0
- package/core/src/physics/deformable-query.d.mts +217 -0
- package/core/src/physics/deformable-query.mjs +1412 -0
- package/core/src/physics/distance.d.mts +160 -0
- package/core/src/physics/distance.mjs +175 -0
- package/core/src/physics/extended-wasm-instance.d.mts +5 -0
- package/core/src/physics/extended-wasm-instance.mjs +48 -0
- package/core/src/physics/feature-api.d.mts +74 -0
- package/core/src/physics/feature-api.mjs +98 -0
- package/core/src/physics/fracture.d.mts +133 -0
- package/core/src/physics/fracture.mjs +1324 -0
- package/core/src/physics/gear.d.mts +585 -0
- package/core/src/physics/gear.mjs +955 -0
- package/core/src/physics/lag-compensation.d.mts +101 -0
- package/core/src/physics/lag-compensation.mjs +1100 -0
- package/core/src/physics/mass-properties.d.mts +114 -0
- package/core/src/physics/mass-properties.mjs +137 -468
- package/core/src/physics/particles.d.mts +177 -0
- package/core/src/physics/particles.mjs +758 -0
- package/core/src/physics/path-joint.d.mts +171 -0
- package/core/src/physics/path-joint.mjs +1231 -0
- package/core/src/physics/physics-extended-wasm-module.generated.mjs +13 -0
- package/core/src/physics/physics-profile-wasm-module.generated.mjs +48 -0
- package/core/src/physics/physics-wasm-module.generated.mjs +34 -5
- package/core/src/physics/powered-ragdoll.d.mts +188 -0
- package/core/src/physics/powered-ragdoll.mjs +1043 -0
- package/core/src/physics/powertrain.d.mts +260 -0
- package/core/src/physics/powertrain.mjs +621 -0
- package/core/src/physics/pulley.d.mts +98 -0
- package/core/src/physics/pulley.mjs +686 -0
- package/core/src/physics/ragdoll.d.mts +289 -0
- package/core/src/physics/ragdoll.mjs +1323 -0
- package/core/src/physics/rope.d.mts +241 -0
- package/core/src/physics/rope.mjs +319 -0
- package/core/src/physics/rounded-convex.d.mts +328 -0
- package/core/src/physics/rounded-convex.mjs +1404 -0
- package/core/src/physics/sdf-geometry.d.mts +117 -0
- package/core/src/physics/sdf-geometry.mjs +1204 -0
- package/core/src/physics/soft-body.d.mts +144 -0
- package/core/src/physics/soft-body.mjs +1285 -0
- package/core/src/physics/soft-collision.d.mts +651 -0
- package/core/src/physics/soft-collision.mjs +1883 -0
- package/core/src/physics/surface-velocity.d.mts +156 -0
- package/core/src/physics/surface-velocity.mjs +722 -0
- package/core/src/physics/tracks.d.mts +411 -0
- package/core/src/physics/tracks.mjs +1074 -0
- package/core/src/physics/vehicle.d.mts +3 -0
- package/core/src/physics/vehicle.mjs +172 -0
- package/core/src/physics/voxel-cooking.d.mts +219 -0
- package/core/src/physics/voxel-cooking.mjs +1499 -0
- package/core/src/physics/voxel-swept-quad.mjs +110 -0
- package/core/src/physics/wasm-instance.mjs +160 -23
- package/core/src/physics/world.d.mts +62 -0
- package/core/src/physics/world.mjs +1947 -152
- package/core/src/physics2d/body-state.mjs +218 -15
- package/core/src/physics2d/collision.d.mts +52 -0
- package/core/src/physics2d/collision.mjs +234 -0
- package/core/src/physics2d/compound.mjs +454 -0
- package/core/src/physics2d/contour-state.mjs +771 -0
- package/core/src/physics2d/feature-api.d.mts +211 -0
- package/core/src/physics2d/feature-api.mjs +3 -0
- package/core/src/physics2d/fluid-state.mjs +145 -0
- package/core/src/physics2d/joint-state.mjs +1 -1
- package/core/src/physics2d/owned-queries.mjs +3 -1
- package/core/src/physics2d/owned-transport.mjs +268 -122
- package/core/src/physics2d/owned-world.mjs +353 -230
- package/core/src/physics2d/particle-fluid.d.mts +152 -0
- package/core/src/physics2d/particle-fluid.mjs +233 -0
- package/core/src/physics2d/physics2d-wasm-module.generated.mjs +27 -10
- package/core/src/physics2d/query-codec.mjs +61 -13
- package/core/src/physics2d/submerged-geometry.d.mts +51 -0
- package/core/src/physics2d/submerged-geometry.mjs +186 -0
- package/core/src/runtime.mjs +23 -0
- package/core/src/shared/bytes.d.mts +2 -0
- package/core/src/shared/bytes.mjs +33 -0
- package/core/src/shared/sha256.d.mts +3 -0
- package/core/src/shared/sha256.mjs +72 -22
- package/core/units.d.ts +50 -0
- package/core/world.d.ts +253 -5
- package/dist/authority-room.d.ts +9 -0
- package/dist/authority-room.js +45 -16
- package/dist/browser.d.ts +6 -5
- package/dist/browser.js +4 -3
- package/dist/cadence.d.ts +7 -0
- package/dist/cadence.js +19 -0
- package/dist/canonical.d.ts +1 -0
- package/dist/canonical.js +3 -0
- package/dist/checksum-policy.d.ts +10 -0
- package/dist/checksum-policy.js +14 -0
- package/dist/collider-cooking-hull.d.ts +18 -0
- package/dist/collider-cooking-hull.js +248 -0
- package/dist/collider-cooking.d.ts +140 -0
- package/dist/collider-cooking.js +794 -0
- package/dist/compat/v5.d.ts +121 -0
- package/dist/compat/v5.js +479 -0
- package/dist/creator.d.ts +7 -6
- package/dist/creator.js +4 -3
- package/dist/game-byte-section.d.ts +36 -0
- package/dist/game-byte-section.js +350 -0
- package/dist/index.d.ts +13 -6
- package/dist/index.js +9 -4
- package/dist/instant-replay.d.ts +27 -2
- package/dist/instant-replay.js +91 -16
- package/dist/lag-compensation3d.js +11 -10
- package/dist/match-log.d.ts +21 -4
- package/dist/match-log.js +92 -9
- package/dist/math.d.ts +2 -0
- package/dist/math.js +1 -0
- package/dist/modules/character-3d.d.ts +16 -1
- package/dist/modules/character-3d.js +42 -5
- package/dist/modules/combat.js +6 -5
- package/dist/movement3d-revision1.d.ts +2 -0
- package/dist/movement3d-revision1.js +973 -0
- package/dist/movement3d.d.ts +53 -3
- package/dist/movement3d.js +917 -247
- package/dist/networked-client.d.ts +15 -0
- package/dist/networked-client.js +378 -105
- package/dist/node.d.ts +3 -2
- package/dist/node.js +2 -1
- package/dist/physics/2d.d.ts +38 -4
- package/dist/physics/2d.js +57 -36
- package/dist/physics/3d.d.ts +755 -111
- package/dist/physics/3d.js +2355 -158
- package/dist/physics/edit-result-graph.d.ts +36 -0
- package/dist/physics/edit-result-graph.js +141 -0
- package/dist/physics/game-codec3d.d.ts +41 -0
- package/dist/physics/game-codec3d.js +544 -0
- package/dist/physics/installed-checkpoint3d.d.ts +13 -0
- package/dist/physics/installed-checkpoint3d.js +120 -0
- package/dist/physics/installed-runtime3d.d.ts +51 -0
- package/dist/physics/installed-runtime3d.js +372 -0
- package/dist/physics/installed-state-commitment3d.d.ts +2 -0
- package/dist/physics/installed-state-commitment3d.js +24 -0
- package/dist/physics/units.d.ts +38 -0
- package/dist/physics/units.js +56 -0
- package/dist/physics/vehicle-state3d.d.ts +93 -0
- package/dist/physics/vehicle-state3d.js +1191 -0
- package/dist/physics/voxel-body-state.d.ts +61 -0
- package/dist/physics/voxel-body-state.js +410 -0
- package/dist/r3f-render-adapter.d.ts +59 -1
- package/dist/r3f-render-adapter.js +137 -2
- package/dist/replay.d.ts +13 -0
- package/dist/replay.js +95 -70
- package/dist/run-room-transport.js +5 -1
- package/dist/runner.d.ts +17 -2
- package/dist/runner.js +472 -84
- package/dist/runtime-cleanup.d.ts +54 -0
- package/dist/runtime-cleanup.js +266 -0
- package/dist/runtime-lease.d.ts +11 -1
- package/dist/runtime-lease.js +23 -10
- package/dist/runtime-room-metadata.d.ts +2 -8
- package/dist/runtime-room-metadata.js +11 -14
- package/dist/runtime-session.d.ts +8 -0
- package/dist/runtime-session.js +222 -58
- package/dist/schema-codegen.js +3 -0
- package/dist/schema-dsl-binary.d.ts +10 -4
- package/dist/schema-dsl-binary.js +375 -76
- package/dist/scratch-pool.d.ts +32 -0
- package/dist/scratch-pool.js +60 -0
- package/dist/sdk-session.d.ts +1 -0
- package/dist/sdk-session.js +4 -0
- package/dist/secret-config.js +2 -60
- package/dist/secret-crypto.js +70 -36
- package/dist/session-snapshot.d.ts +15 -4
- package/dist/session-snapshot.js +35 -33
- package/dist/session-wire.js +14 -22
- package/dist/sparse-set.d.ts +1 -0
- package/dist/sparse-set.js +22 -0
- package/dist/spatial/spatial-grid-3d.d.ts +41 -0
- package/dist/spatial/spatial-grid-3d.js +115 -0
- package/dist/synctest.d.ts +9 -0
- package/dist/synctest.js +106 -17
- package/dist/testing-network.d.ts +2 -0
- package/dist/testing-network.js +122 -18
- package/dist/testing.d.ts +27 -6
- package/dist/testing.js +297 -56
- package/dist/tools/index.d.ts +3 -2
- package/dist/tools/index.js +3 -2
- package/dist/tools/module-certification.d.ts +6 -0
- package/dist/tools/module-certification.js +26 -2
- package/package.json +18 -5
- package/core/scripts/run-box3d-benchmark.mjs +0 -350
- package/core/src/physics/index.mjs +0 -3169
|
@@ -5,19 +5,19 @@
|
|
|
5
5
|
#include "physics2d.hpp"
|
|
6
6
|
#include "queries.hpp"
|
|
7
7
|
#include "commands.hpp"
|
|
8
|
+
#include "checkpoint_memory.hpp"
|
|
8
9
|
|
|
9
10
|
#include <cstddef>
|
|
10
|
-
#include <cstdint>
|
|
11
11
|
#include <type_traits>
|
|
12
12
|
|
|
13
13
|
namespace rundot::kinetix::physics2d {
|
|
14
14
|
|
|
15
|
-
constexpr std::uint32_t kOwnedWorld2DAbiVersion =
|
|
16
|
-
constexpr std::uint32_t kOwnedWorld2DSnapshotVersion =
|
|
15
|
+
constexpr std::uint32_t kOwnedWorld2DAbiVersion = 7;
|
|
16
|
+
constexpr std::uint32_t kOwnedWorld2DSnapshotVersion = 6;
|
|
17
17
|
constexpr std::uint32_t kOwnedWorld2DPhysicsProfile = 1;
|
|
18
18
|
constexpr std::uint32_t kOwnedWorld2DSnapshotMagic = 0x32445753u;
|
|
19
|
-
constexpr std::size_t kOwnedWorld2DSnapshotHeaderBytes =
|
|
20
|
-
constexpr std::size_t kOwnedWorld2DMaxSnapshotBytes =
|
|
19
|
+
constexpr std::size_t kOwnedWorld2DSnapshotHeaderBytes = 156;
|
|
20
|
+
constexpr std::size_t kOwnedWorld2DMaxSnapshotBytes = 25'336'996;
|
|
21
21
|
constexpr std::uint32_t kOwnedWorld2DExhaustedId = 0xffff'ffffu;
|
|
22
22
|
|
|
23
23
|
struct FixedStepTiming2D {
|
|
@@ -26,15 +26,13 @@ struct FixedStepTiming2D {
|
|
|
26
26
|
std::uint32_t velocityIterations = 6;
|
|
27
27
|
};
|
|
28
28
|
|
|
29
|
-
struct Gravity2D {
|
|
30
|
-
double x = 0.0;
|
|
31
|
-
double y = -9.81;
|
|
32
|
-
};
|
|
33
|
-
|
|
34
29
|
struct WorldConfig2D {
|
|
35
30
|
std::uint32_t bodyCapacity = kMaxBodies;
|
|
36
31
|
std::uint32_t jointCapacity = kMaxJoints;
|
|
37
32
|
std::uint32_t fluidCapacity = kMaxFluidRegions;
|
|
33
|
+
std::uint32_t contactCapacity = 0;
|
|
34
|
+
std::uint32_t contourEdgeCapacity = 0;
|
|
35
|
+
std::uint32_t checkpointCapacity = kDefaultCheckpointCapacity;
|
|
38
36
|
std::uint32_t physicsProfile = kOwnedWorld2DPhysicsProfile;
|
|
39
37
|
FixedStepTiming2D fixedTiming{};
|
|
40
38
|
Gravity2D initialGravity{};
|
|
@@ -62,6 +60,12 @@ enum class WorldStatus2D : std::int32_t {
|
|
|
62
60
|
SnapshotSettingsMismatch = -117,
|
|
63
61
|
CheckpointCapacity = -118,
|
|
64
62
|
InvalidCheckpoint = -119,
|
|
63
|
+
ContourCapacity = -120,
|
|
64
|
+
InvalidContour = -121,
|
|
65
|
+
WorldAttached = -122,
|
|
66
|
+
InitialStateMismatch = -123,
|
|
67
|
+
CheckpointTokenExhausted = -124,
|
|
68
|
+
AttachmentTokenExhausted = -125,
|
|
65
69
|
};
|
|
66
70
|
|
|
67
71
|
struct WorldResult2D {
|
|
@@ -87,6 +91,12 @@ struct WorldState2DView {
|
|
|
87
91
|
std::uint32_t breakEventCount = 0;
|
|
88
92
|
const GearReactionEntry2D* gearReactions = nullptr;
|
|
89
93
|
std::uint32_t gearReactionCount = 0;
|
|
94
|
+
const ContactEvent2D* activePairs = nullptr;
|
|
95
|
+
std::uint32_t activePairCount = 0;
|
|
96
|
+
const ContactEvent2D* priorPairs = nullptr;
|
|
97
|
+
std::uint32_t priorPairCount = 0;
|
|
98
|
+
const ContourEdge2D* contourEdges = nullptr;
|
|
99
|
+
std::uint32_t contourEdgeCount = 0;
|
|
90
100
|
std::uint64_t frame = 0;
|
|
91
101
|
std::uint32_t nextBodyId = 1;
|
|
92
102
|
std::uint32_t nextJointId = 1;
|
|
@@ -114,6 +124,7 @@ class alignas(8) World2D {
|
|
|
114
124
|
const WorldConfig2D& config() const;
|
|
115
125
|
WorldIdentity2D identity() const;
|
|
116
126
|
std::size_t retainedBytes() const;
|
|
127
|
+
std::size_t checkpointPayloadBytes() const;
|
|
117
128
|
bool storageOverlaps(const void* pointer, std::size_t bytes) const;
|
|
118
129
|
// This view is borrowed. Any mutation or World2D destruction ends its lifetime.
|
|
119
130
|
// Public JS adapters must copy results before they return them.
|
|
@@ -124,6 +135,11 @@ class alignas(8) World2D {
|
|
|
124
135
|
WorldResult2D setGravity(double x, double y);
|
|
125
136
|
WorldResult2D step();
|
|
126
137
|
WorldResult2D step(const StepOptions& options);
|
|
138
|
+
std::uint32_t contactEventCount() const;
|
|
139
|
+
WorldResult2D copyContactEvents(
|
|
140
|
+
ContactEvent2D* output,
|
|
141
|
+
std::uint32_t outputCapacity,
|
|
142
|
+
std::uint32_t* outputCount) const;
|
|
127
143
|
|
|
128
144
|
EditResult2D edit(
|
|
129
145
|
const TopologyCommand2D* commands,
|
|
@@ -141,7 +157,15 @@ class alignas(8) World2D {
|
|
|
141
157
|
std::uint32_t* handleCount,
|
|
142
158
|
RemovedIdentity2D* removed,
|
|
143
159
|
std::uint32_t removedCapacity,
|
|
144
|
-
std::uint32_t* removedCount
|
|
160
|
+
std::uint32_t* removedCount,
|
|
161
|
+
const ContourEdge2D* contourEdgePayloads = nullptr,
|
|
162
|
+
std::uint32_t contourEdgePayloadCount = 0);
|
|
163
|
+
std::size_t contourEdgeCount() const noexcept;
|
|
164
|
+
WorldResult2D readContourEdges(
|
|
165
|
+
std::uint32_t bodyId,
|
|
166
|
+
ContourEdge2D* output,
|
|
167
|
+
std::uint32_t capacity,
|
|
168
|
+
std::uint32_t* outputCount) const noexcept;
|
|
145
169
|
EditResult2D resolveBody(std::uint32_t id, EntityHandle2D* output) const;
|
|
146
170
|
EditResult2D resolveJoint(std::uint32_t id, EntityHandle2D* output) const;
|
|
147
171
|
EditResult2D resolveFluid(std::uint32_t id, EntityHandle2D* output) const;
|
|
@@ -152,6 +176,10 @@ class alignas(8) World2D {
|
|
|
152
176
|
std::size_t outputCapacity,
|
|
153
177
|
std::size_t* outputSize) const;
|
|
154
178
|
WorldResult2D restore(const std::uint8_t* bytes, std::size_t byteCount);
|
|
179
|
+
WorldResult2D restoreAuthorized(
|
|
180
|
+
const std::uint8_t* bytes,
|
|
181
|
+
std::size_t byteCount,
|
|
182
|
+
std::uint32_t attachmentToken);
|
|
155
183
|
WorldResult2D captureCheckpoint(std::uint32_t* checkpointHandle);
|
|
156
184
|
WorldResult2D restoreCheckpoint(std::uint32_t checkpointHandle);
|
|
157
185
|
WorldResult2D releaseCheckpoint(std::uint32_t checkpointHandle);
|
|
@@ -163,8 +191,56 @@ class alignas(8) World2D {
|
|
|
163
191
|
std::uint8_t* output,
|
|
164
192
|
std::size_t outputCapacity,
|
|
165
193
|
std::size_t* outputSize) const;
|
|
194
|
+
|
|
195
|
+
std::uint64_t mutationRevision() const noexcept;
|
|
196
|
+
bool isAttached() const noexcept;
|
|
197
|
+
std::uint32_t attachmentToken() const noexcept;
|
|
198
|
+
WorldResult2D attach(std::uint64_t expectedInitialDigest, std::uint32_t* outputToken);
|
|
199
|
+
WorldResult2D detach(std::uint32_t token);
|
|
200
|
+
|
|
201
|
+
std::uint32_t checkpointCapacity() const noexcept;
|
|
202
|
+
std::uint32_t checkpointLiveCount() const noexcept;
|
|
203
|
+
bool checkpointPreflight(std::uint32_t requiredSlots = 1) const noexcept;
|
|
204
|
+
|
|
205
|
+
WorldResult2D captureCheckpointToken(
|
|
206
|
+
std::uint32_t attachmentToken,
|
|
207
|
+
CheckpointToken2D* outputToken);
|
|
208
|
+
WorldResult2D restoreCheckpointToken(
|
|
209
|
+
std::uint32_t attachmentToken,
|
|
210
|
+
std::uint32_t slotIndex,
|
|
211
|
+
std::uint32_t generation);
|
|
212
|
+
WorldResult2D releaseCheckpointToken(
|
|
213
|
+
std::uint32_t attachmentToken,
|
|
214
|
+
std::uint32_t slotIndex,
|
|
215
|
+
std::uint32_t generation);
|
|
216
|
+
WorldResult2D checkpointCaptureSizeToken(
|
|
217
|
+
std::uint32_t attachmentToken,
|
|
218
|
+
std::uint32_t slotIndex,
|
|
219
|
+
std::uint32_t generation,
|
|
220
|
+
std::size_t* outputSize) const;
|
|
221
|
+
WorldResult2D captureCheckpointSnapshotToken(
|
|
222
|
+
std::uint32_t attachmentToken,
|
|
223
|
+
std::uint32_t slotIndex,
|
|
224
|
+
std::uint32_t generation,
|
|
225
|
+
std::uint8_t* output,
|
|
226
|
+
std::size_t outputCapacity,
|
|
227
|
+
std::size_t* outputSize) const;
|
|
228
|
+
|
|
166
229
|
WorldResult2D digest(std::uint64_t* output) const;
|
|
167
230
|
|
|
231
|
+
#ifdef RUNDOT_PHYSICS2D_PHASE_TEST_HOOKS
|
|
232
|
+
bool debugAdvanceMutationRevisionForTest(std::uint64_t value) noexcept;
|
|
233
|
+
const std::uint8_t* debugSlotPayloadForTest(
|
|
234
|
+
std::uint32_t slotIndex,
|
|
235
|
+
std::size_t* bytes) const noexcept;
|
|
236
|
+
bool debugSlotCredentialForTest(
|
|
237
|
+
std::uint32_t slotIndex,
|
|
238
|
+
std::uint32_t* generation,
|
|
239
|
+
std::uint32_t* legacyCredential,
|
|
240
|
+
std::uint8_t* kind) const noexcept;
|
|
241
|
+
const void* debugStagedRangeForTest(std::uint32_t index, std::size_t* bytes) const noexcept;
|
|
242
|
+
#endif
|
|
243
|
+
|
|
168
244
|
std::int32_t raycast(
|
|
169
245
|
const RaycastQuery2D* request,
|
|
170
246
|
const QueryFilter2D* filter,
|
|
@@ -179,6 +255,13 @@ class alignas(8) World2D {
|
|
|
179
255
|
OverlapHit2D* output,
|
|
180
256
|
std::uint32_t outputCapacity,
|
|
181
257
|
std::uint32_t* outputCount);
|
|
258
|
+
std::int32_t overlapContacts(
|
|
259
|
+
const OverlapQuery2D* request,
|
|
260
|
+
const QueryFilter2D* filter,
|
|
261
|
+
const std::uint32_t* excludedIds,
|
|
262
|
+
OverlapContactHit2D* output,
|
|
263
|
+
std::uint32_t outputCapacity,
|
|
264
|
+
std::uint32_t* outputCount);
|
|
182
265
|
std::int32_t shapeCast(
|
|
183
266
|
const ShapeCastQuery2D* request,
|
|
184
267
|
const QueryFilter2D* filter,
|
|
@@ -196,19 +279,47 @@ class alignas(8) World2D {
|
|
|
196
279
|
|
|
197
280
|
private:
|
|
198
281
|
struct Storage;
|
|
282
|
+
#ifdef RUNDOT_PHYSICS2D_PHASE_TEST_HOOKS
|
|
283
|
+
friend struct WorldPublicationProbe2D;
|
|
284
|
+
#endif
|
|
199
285
|
|
|
200
286
|
WorldConfig2D config_{};
|
|
201
287
|
Storage* storage_ = nullptr;
|
|
202
288
|
WorldResult2D constructionResult_{WorldStatus2D::NotReady, kStepOk};
|
|
203
289
|
|
|
204
290
|
WorldResult2D stageAndValidate(const WorldState2DView& state);
|
|
205
|
-
// T2c topology edits use this
|
|
291
|
+
// T2c topology edits use this checked publish. They preserve live handle epochs
|
|
206
292
|
// and the latest successful step outputs.
|
|
207
|
-
|
|
293
|
+
WorldResult2D commitStagedTopology() noexcept;
|
|
208
294
|
bool topologyEditAliases(
|
|
209
295
|
const void* const* pointers,
|
|
210
296
|
const std::size_t* sizes,
|
|
211
297
|
std::uint32_t count) const;
|
|
298
|
+
bool acceptOutput(const void* pointer, std::size_t bytes, std::size_t alignment) const;
|
|
299
|
+
bool acceptOutputs(
|
|
300
|
+
const void* const* pointers,
|
|
301
|
+
const std::size_t* sizes,
|
|
302
|
+
const std::size_t* alignments,
|
|
303
|
+
std::uint32_t count) const;
|
|
304
|
+
bool tokenCredentialMatches(std::uint32_t slotIndex, std::uint32_t generation) const noexcept;
|
|
305
|
+
WorldResult2D captureCheckpointCredential(
|
|
306
|
+
CheckpointCredentialKind2D kind,
|
|
307
|
+
std::uint32_t* legacyHandle,
|
|
308
|
+
CheckpointToken2D* tokenOut);
|
|
309
|
+
bool resolveLegacyCheckpoint(
|
|
310
|
+
std::uint32_t handle,
|
|
311
|
+
std::uint32_t& slotIndex,
|
|
312
|
+
std::uint32_t& generation) const;
|
|
313
|
+
WorldResult2D restoreResolvedCheckpoint(std::uint32_t slotIndex);
|
|
314
|
+
WorldResult2D releaseResolvedCheckpoint(std::uint32_t slotIndex);
|
|
315
|
+
WorldResult2D checkpointSizeResolved(
|
|
316
|
+
std::uint32_t slotIndex,
|
|
317
|
+
std::size_t* outputSize) const;
|
|
318
|
+
WorldResult2D captureSnapshotResolved(
|
|
319
|
+
std::uint32_t slotIndex,
|
|
320
|
+
std::uint8_t* output,
|
|
321
|
+
std::size_t required,
|
|
322
|
+
std::size_t* outputSize) const;
|
|
212
323
|
void normalizeTopologyJoint(JointRecord2D& joint) const;
|
|
213
324
|
WorldResult2D commitStaged();
|
|
214
325
|
void release();
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include "sha256_fips_constants.hpp"
|
|
4
|
+
|
|
5
|
+
#include <cstdint>
|
|
6
|
+
|
|
7
|
+
namespace rundot::sha256 {
|
|
8
|
+
|
|
9
|
+
// Compression from the frozen component_runtime.cpp loop.
|
|
10
|
+
// Rotate counts at the call sites are 2, 6, 7, 11, 13, 17, 18, 19, 22, and 25.
|
|
11
|
+
struct CompressUnsigned {
|
|
12
|
+
template <unsigned Bits>
|
|
13
|
+
static std::uint32_t rotr(std::uint32_t value) noexcept {
|
|
14
|
+
static_assert(Bits > 0 && Bits < 32);
|
|
15
|
+
return (value >> Bits) | (value << (32u - Bits));
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
static void transform(std::uint32_t state[8], const std::uint8_t chunk[64]) noexcept {
|
|
19
|
+
std::uint32_t schedule[64];
|
|
20
|
+
for (int index = 0; index < 16; ++index) {
|
|
21
|
+
schedule[index] = (static_cast<std::uint32_t>(chunk[index * 4]) << 24) |
|
|
22
|
+
(static_cast<std::uint32_t>(chunk[index * 4 + 1]) << 16) |
|
|
23
|
+
(static_cast<std::uint32_t>(chunk[index * 4 + 2]) << 8) |
|
|
24
|
+
static_cast<std::uint32_t>(chunk[index * 4 + 3]);
|
|
25
|
+
}
|
|
26
|
+
for (int index = 16; index < 64; ++index) {
|
|
27
|
+
const std::uint32_t small = rotr<7>(schedule[index - 15]) ^ rotr<18>(schedule[index - 15]) ^
|
|
28
|
+
(schedule[index - 15] >> 3);
|
|
29
|
+
const std::uint32_t large = rotr<17>(schedule[index - 2]) ^ rotr<19>(schedule[index - 2]) ^
|
|
30
|
+
(schedule[index - 2] >> 10);
|
|
31
|
+
schedule[index] = schedule[index - 16] + small + schedule[index - 7] + large;
|
|
32
|
+
}
|
|
33
|
+
std::uint32_t a = state[0];
|
|
34
|
+
std::uint32_t b = state[1];
|
|
35
|
+
std::uint32_t c = state[2];
|
|
36
|
+
std::uint32_t d = state[3];
|
|
37
|
+
std::uint32_t e = state[4];
|
|
38
|
+
std::uint32_t f = state[5];
|
|
39
|
+
std::uint32_t g = state[6];
|
|
40
|
+
std::uint32_t h = state[7];
|
|
41
|
+
for (int index = 0; index < 64; ++index) {
|
|
42
|
+
const std::uint32_t s1 = rotr<6>(e) ^ rotr<11>(e) ^ rotr<25>(e);
|
|
43
|
+
const std::uint32_t ch = (e & f) ^ (~e & g);
|
|
44
|
+
const std::uint32_t temp1 = h + s1 + ch + kRound[index] + schedule[index];
|
|
45
|
+
const std::uint32_t s0 = rotr<2>(a) ^ rotr<13>(a) ^ rotr<22>(a);
|
|
46
|
+
const std::uint32_t maj = (a & b) ^ (a & c) ^ (b & c);
|
|
47
|
+
const std::uint32_t temp2 = s0 + maj;
|
|
48
|
+
h = g;
|
|
49
|
+
g = f;
|
|
50
|
+
f = e;
|
|
51
|
+
e = d + temp1;
|
|
52
|
+
d = c;
|
|
53
|
+
c = b;
|
|
54
|
+
b = a;
|
|
55
|
+
a = temp1 + temp2;
|
|
56
|
+
}
|
|
57
|
+
state[0] += a;
|
|
58
|
+
state[1] += b;
|
|
59
|
+
state[2] += c;
|
|
60
|
+
state[3] += d;
|
|
61
|
+
state[4] += e;
|
|
62
|
+
state[5] += f;
|
|
63
|
+
state[6] += g;
|
|
64
|
+
state[7] += h;
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
} // namespace rundot::sha256
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
// FIPS 180-4 initial hash and round constants.
|
|
3
|
+
// Extracted from the frozen component_runtime.cpp Sha256 struct.
|
|
4
|
+
#include <cstdint>
|
|
5
|
+
|
|
6
|
+
namespace rundot::sha256 {
|
|
7
|
+
|
|
8
|
+
inline constexpr std::uint32_t kInit[8] = {
|
|
9
|
+
0x6a09e667u, 0xbb67ae85u, 0x3c6ef372u, 0xa54ff53au,
|
|
10
|
+
0x510e527fu, 0x9b05688cu, 0x1f83d9abu, 0x5be0cd19u,
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
inline constexpr std::uint32_t kRound[64] = {
|
|
14
|
+
0x428a2f98u, 0x71374491u, 0xb5c0fbcfu, 0xe9b5dba5u, 0x3956c25bu, 0x59f111f1u, 0x923f82a4u, 0xab1c5ed5u,
|
|
15
|
+
0xd807aa98u, 0x12835b01u, 0x243185beu, 0x550c7dc3u, 0x72be5d74u, 0x80deb1feu, 0x9bdc06a7u, 0xc19bf174u,
|
|
16
|
+
0xe49b69c1u, 0xefbe4786u, 0x0fc19dc6u, 0x240ca1ccu, 0x2de92c6fu, 0x4a7484aau, 0x5cb0a9dcu, 0x76f988dau,
|
|
17
|
+
0x983e5152u, 0xa831c66du, 0xb00327c8u, 0xbf597fc7u, 0xc6e00bf3u, 0xd5a79147u, 0x06ca6351u, 0x14292967u,
|
|
18
|
+
0x27b70a85u, 0x2e1b2138u, 0x4d2c6dfcu, 0x53380d13u, 0x650a7354u, 0x766a0abbu, 0x81c2c92eu, 0x92722c85u,
|
|
19
|
+
0xa2bfe8a1u, 0xa81a664bu, 0xc24b8b70u, 0xc76c51a3u, 0xd192e819u, 0xd6990624u, 0xf40e3585u, 0x106aa070u,
|
|
20
|
+
0x19a4c116u, 0x1e376c08u, 0x2748774cu, 0x34b0bcb5u, 0x391c0cb3u, 0x4ed8aa4au, 0x5b9cca4fu, 0x682e6ff3u,
|
|
21
|
+
0x748f82eeu, 0x78a5636fu, 0x84c87814u, 0x8cc70208u, 0x90befffau, 0xa4506cebu, 0xbef9a3f7u, 0xc67178f2u,
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
} // namespace rundot::sha256
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <cstdint>
|
|
4
|
+
|
|
5
|
+
namespace rundot::sha256 {
|
|
6
|
+
|
|
7
|
+
enum class LengthAdd : std::uint8_t { Ok, Overflow };
|
|
8
|
+
|
|
9
|
+
struct BitLengthAdd {
|
|
10
|
+
LengthAdd status;
|
|
11
|
+
std::uint64_t bits;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
// Add byteCount*8 to a SHA-256 bit length.
|
|
15
|
+
// The sum must fit in 64 bits. On overflow, bits stays at the old value.
|
|
16
|
+
inline constexpr BitLengthAdd addBitLength(std::uint64_t bitLength, std::uint64_t byteCount) noexcept {
|
|
17
|
+
constexpr std::uint64_t kMaxBytes = UINT64_MAX / 8u;
|
|
18
|
+
if (byteCount > kMaxBytes) return {LengthAdd::Overflow, bitLength};
|
|
19
|
+
const std::uint64_t added = byteCount * 8u;
|
|
20
|
+
if (bitLength > UINT64_MAX - added) return {LengthAdd::Overflow, bitLength};
|
|
21
|
+
return {LengthAdd::Ok, bitLength + added};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// SHA-256 length field and digest words are big-endian.
|
|
25
|
+
// Field writers for the physics visitor are little-endian. Do not mix them.
|
|
26
|
+
inline void storeBeU64(std::uint8_t out[8], std::uint64_t value) noexcept {
|
|
27
|
+
for (unsigned index = 0; index < 8; ++index) {
|
|
28
|
+
const unsigned shift = 56u - index * 8u;
|
|
29
|
+
out[index] = static_cast<std::uint8_t>((value >> shift) & 0xffu);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
inline void storeBeU32(std::uint8_t out[4], std::uint32_t value) noexcept {
|
|
34
|
+
out[0] = static_cast<std::uint8_t>((value >> 24) & 0xffu);
|
|
35
|
+
out[1] = static_cast<std::uint8_t>((value >> 16) & 0xffu);
|
|
36
|
+
out[2] = static_cast<std::uint8_t>((value >> 8) & 0xffu);
|
|
37
|
+
out[3] = static_cast<std::uint8_t>(value & 0xffu);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
static_assert(addBitLength(0, 0).status == LengthAdd::Ok);
|
|
41
|
+
static_assert(addBitLength(0, 0).bits == 0);
|
|
42
|
+
static_assert(addBitLength(0, UINT64_MAX / 8u).status == LengthAdd::Ok);
|
|
43
|
+
static_assert(addBitLength(0, UINT64_MAX / 8u).bits == (UINT64_MAX / 8u) * 8u);
|
|
44
|
+
static_assert(addBitLength(0, UINT64_MAX / 8u + 1u).status == LengthAdd::Overflow);
|
|
45
|
+
static_assert(addBitLength(0, UINT64_MAX / 8u + 1u).bits == 0);
|
|
46
|
+
static_assert(addBitLength(UINT64_MAX, 0).status == LengthAdd::Ok);
|
|
47
|
+
static_assert(addBitLength(UINT64_MAX, 0).bits == UINT64_MAX);
|
|
48
|
+
// One byte adds 8 bits. UINT64_MAX - 8 is the last length that can take that byte.
|
|
49
|
+
static_assert(addBitLength(UINT64_MAX - 8u, 1).status == LengthAdd::Ok);
|
|
50
|
+
static_assert(addBitLength(UINT64_MAX - 8u, 1).bits == UINT64_MAX);
|
|
51
|
+
static_assert(addBitLength(UINT64_MAX - 7u, 1).status == LengthAdd::Overflow);
|
|
52
|
+
static_assert(addBitLength(UINT64_MAX - 7u, 1).bits == UINT64_MAX - 7u);
|
|
53
|
+
static_assert(addBitLength(8u, UINT64_MAX / 8u).status == LengthAdd::Overflow);
|
|
54
|
+
static_assert(addBitLength(8u, UINT64_MAX / 8u).bits == 8u);
|
|
55
|
+
|
|
56
|
+
} // namespace rundot::sha256
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <atomic>
|
|
4
|
+
#include <cstdint>
|
|
5
|
+
|
|
6
|
+
namespace rundot::sha256 {
|
|
7
|
+
|
|
8
|
+
inline constexpr std::uint8_t kMemoEmpty = 0;
|
|
9
|
+
inline constexpr std::uint8_t kMemoFilling = 1;
|
|
10
|
+
inline constexpr std::uint8_t kMemoReady = 2;
|
|
11
|
+
|
|
12
|
+
// The winner writes the bytes, then release-stores ready.
|
|
13
|
+
// A loser does not wait, does not lock, and does not write.
|
|
14
|
+
// A failed winner leaves the state at filling. Later callers compute a local result.
|
|
15
|
+
template <typename Fill>
|
|
16
|
+
bool tryPublishMemo(std::atomic<std::uint8_t>& state, Fill&& fill) noexcept {
|
|
17
|
+
std::uint8_t expected = kMemoEmpty;
|
|
18
|
+
if (!state.compare_exchange_strong(
|
|
19
|
+
expected, kMemoFilling, std::memory_order_acq_rel, std::memory_order_acquire)) {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
if (!fill()) return false;
|
|
23
|
+
state.store(kMemoReady, std::memory_order_release);
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
inline bool memoIsReady(const std::atomic<std::uint8_t>& state) noexcept {
|
|
28
|
+
return state.load(std::memory_order_acquire) == kMemoReady;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
#if defined(RUNDOT_PHYSICS_PHASE_TEST_HOOKS)
|
|
32
|
+
// Fill counters. A memo hit does not increment them.
|
|
33
|
+
inline std::atomic<std::uint64_t> gStrongRecordLeafFills{0};
|
|
34
|
+
inline std::atomic<std::uint64_t> gStrongRootSealFills{0};
|
|
35
|
+
inline std::atomic<std::uint64_t> gStrongMaterialStreamFills{0};
|
|
36
|
+
inline std::atomic<std::uint64_t> gStrongTileLeafFills{0};
|
|
37
|
+
inline std::atomic<std::uint64_t> gStrongCheckpointPayloadFills{0};
|
|
38
|
+
|
|
39
|
+
inline void resetStrongFillCounters() noexcept {
|
|
40
|
+
gStrongRecordLeafFills.store(0, std::memory_order_relaxed);
|
|
41
|
+
gStrongRootSealFills.store(0, std::memory_order_relaxed);
|
|
42
|
+
gStrongMaterialStreamFills.store(0, std::memory_order_relaxed);
|
|
43
|
+
gStrongTileLeafFills.store(0, std::memory_order_relaxed);
|
|
44
|
+
gStrongCheckpointPayloadFills.store(0, std::memory_order_relaxed);
|
|
45
|
+
}
|
|
46
|
+
#endif
|
|
47
|
+
|
|
48
|
+
} // namespace rundot::sha256
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
// One streaming SHA-256 sink. Compression is the only part that varies.
|
|
4
|
+
// Sha256Sink is the production compression.
|
|
5
|
+
|
|
6
|
+
#include "sha256_compress_unsigned.hpp"
|
|
7
|
+
#include "sha256_fips_constants.hpp"
|
|
8
|
+
#include "sha256_length.hpp"
|
|
9
|
+
|
|
10
|
+
#include <array>
|
|
11
|
+
#include <bit>
|
|
12
|
+
#include <cstddef>
|
|
13
|
+
#include <cstdint>
|
|
14
|
+
#include <cstdlib>
|
|
15
|
+
#include <cstring>
|
|
16
|
+
#include <limits>
|
|
17
|
+
#include <span>
|
|
18
|
+
|
|
19
|
+
namespace rundot::sha256 {
|
|
20
|
+
|
|
21
|
+
enum class SinkStatus : std::uint8_t {
|
|
22
|
+
Ok = 0,
|
|
23
|
+
InvalidInput = 1,
|
|
24
|
+
LengthOverflow = 2,
|
|
25
|
+
NeedsReset = 3,
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
struct DigestResult {
|
|
29
|
+
SinkStatus status = SinkStatus::Ok;
|
|
30
|
+
std::array<std::uint8_t, 32> bytes{};
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
// f64 writes raw IEEE-754 bits. -0.0 differs from 0.0. NaN payloads differ.
|
|
34
|
+
static_assert(std::numeric_limits<double>::is_iec559);
|
|
35
|
+
static_assert(std::endian::native == std::endian::little);
|
|
36
|
+
|
|
37
|
+
template <typename Compress>
|
|
38
|
+
class BasicSink {
|
|
39
|
+
public:
|
|
40
|
+
BasicSink() noexcept { reset(); }
|
|
41
|
+
|
|
42
|
+
void reset() noexcept {
|
|
43
|
+
std::memcpy(state_, kInit, sizeof(kInit));
|
|
44
|
+
bitLength_ = 0;
|
|
45
|
+
bufferLength_ = 0;
|
|
46
|
+
std::memset(buffer_, 0, sizeof(buffer_));
|
|
47
|
+
digest_.fill(0);
|
|
48
|
+
finalized_ = false;
|
|
49
|
+
failed_ = false;
|
|
50
|
+
failStatus_ = SinkStatus::Ok;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Check the pointer before a span exists. A null pointer with a positive size
|
|
54
|
+
// is InvalidInput. This path does not build std::span(nullptr, size).
|
|
55
|
+
[[nodiscard]] SinkStatus update(const std::uint8_t* data, std::size_t size) noexcept {
|
|
56
|
+
if (failed_) return failStatus_;
|
|
57
|
+
if (finalized_) return SinkStatus::NeedsReset;
|
|
58
|
+
if (data == nullptr && size > 0) return latch(SinkStatus::InvalidInput);
|
|
59
|
+
return update(std::span<const std::uint8_t>(data, size));
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Reject a bad span, a repeat after final, and a bit-length overflow
|
|
63
|
+
// before any state change. An empty span is a no-op and returns Ok.
|
|
64
|
+
// InvalidInput and LengthOverflow latch. A later update does not change state.
|
|
65
|
+
[[nodiscard]] SinkStatus update(std::span<const std::uint8_t> data) noexcept {
|
|
66
|
+
if (failed_) return failStatus_;
|
|
67
|
+
if (finalized_) return SinkStatus::NeedsReset;
|
|
68
|
+
if (data.size() > 0 && data.data() == nullptr) return latch(SinkStatus::InvalidInput);
|
|
69
|
+
const BitLengthAdd added = addBitLength(bitLength_, static_cast<std::uint64_t>(data.size()));
|
|
70
|
+
if (added.status != LengthAdd::Ok) return latch(SinkStatus::LengthOverflow);
|
|
71
|
+
|
|
72
|
+
const std::uint8_t* cursor = data.data();
|
|
73
|
+
std::size_t size = data.size();
|
|
74
|
+
bitLength_ = added.bits;
|
|
75
|
+
while (size > 0) {
|
|
76
|
+
const std::size_t room = 64u - bufferLength_;
|
|
77
|
+
const std::size_t take = size < room ? size : room;
|
|
78
|
+
std::memcpy(buffer_ + bufferLength_, cursor, take);
|
|
79
|
+
bufferLength_ += take;
|
|
80
|
+
cursor += take;
|
|
81
|
+
size -= take;
|
|
82
|
+
if (bufferLength_ == 64u) {
|
|
83
|
+
Compress::transform(state_, buffer_);
|
|
84
|
+
bufferLength_ = 0;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return SinkStatus::Ok;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Ok returns 32 digest bytes. A sticky failure returns that status and zero bytes.
|
|
91
|
+
// It does not pad and it does not return a digest of the accepted prefix.
|
|
92
|
+
// A second call after a successful final returns the cached bytes.
|
|
93
|
+
// NeedsReset does not clear a successful cache.
|
|
94
|
+
[[nodiscard]] DigestResult final() noexcept {
|
|
95
|
+
DigestResult result;
|
|
96
|
+
if (failed_) {
|
|
97
|
+
result.status = failStatus_;
|
|
98
|
+
return result;
|
|
99
|
+
}
|
|
100
|
+
if (finalized_) {
|
|
101
|
+
result.status = SinkStatus::Ok;
|
|
102
|
+
result.bytes = digest_;
|
|
103
|
+
return result;
|
|
104
|
+
}
|
|
105
|
+
if (bufferLength_ > 63u) std::abort();
|
|
106
|
+
|
|
107
|
+
std::uint32_t state[8];
|
|
108
|
+
std::memcpy(state, state_, sizeof(state));
|
|
109
|
+
std::uint8_t block[64];
|
|
110
|
+
std::memset(block, 0, sizeof(block));
|
|
111
|
+
if (bufferLength_ > 0) std::memcpy(block, buffer_, bufferLength_);
|
|
112
|
+
|
|
113
|
+
std::size_t used = bufferLength_;
|
|
114
|
+
const std::uint64_t bits = bitLength_;
|
|
115
|
+
block[used++] = 0x80u;
|
|
116
|
+
if (used > 56u) {
|
|
117
|
+
while (used < 64u) block[used++] = 0u;
|
|
118
|
+
Compress::transform(state, block);
|
|
119
|
+
used = 0;
|
|
120
|
+
std::memset(block, 0, sizeof(block));
|
|
121
|
+
}
|
|
122
|
+
while (used < 56u) block[used++] = 0u;
|
|
123
|
+
storeBeU64(block + 56, bits);
|
|
124
|
+
Compress::transform(state, block);
|
|
125
|
+
for (int word = 0; word < 8; ++word) {
|
|
126
|
+
storeBeU32(digest_.data() + static_cast<std::size_t>(word) * 4u, state[word]);
|
|
127
|
+
}
|
|
128
|
+
finalized_ = true;
|
|
129
|
+
result.status = SinkStatus::Ok;
|
|
130
|
+
result.bytes = digest_;
|
|
131
|
+
return result;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
private:
|
|
135
|
+
[[nodiscard]] SinkStatus latch(SinkStatus status) noexcept {
|
|
136
|
+
failed_ = true;
|
|
137
|
+
failStatus_ = status;
|
|
138
|
+
return failStatus_;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
#if defined(RUNDOT_SHA256_SINK_TEST_ACCESS)
|
|
142
|
+
friend struct SinkTestAccess;
|
|
143
|
+
#endif
|
|
144
|
+
std::uint32_t state_[8]{};
|
|
145
|
+
std::uint64_t bitLength_ = 0;
|
|
146
|
+
std::uint8_t buffer_[64]{};
|
|
147
|
+
std::size_t bufferLength_ = 0;
|
|
148
|
+
std::array<std::uint8_t, 32> digest_{};
|
|
149
|
+
bool finalized_ = false;
|
|
150
|
+
bool failed_ = false;
|
|
151
|
+
SinkStatus failStatus_ = SinkStatus::Ok;
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
#if defined(RUNDOT_SHA256_SINK_TEST_ACCESS)
|
|
155
|
+
struct SinkTestAccess {
|
|
156
|
+
template <typename Compress>
|
|
157
|
+
static SinkStatus setBitLength(BasicSink<Compress>& sink, std::uint64_t bits) noexcept {
|
|
158
|
+
if (sink.finalized_ || sink.bufferLength_ != 0) return SinkStatus::InvalidInput;
|
|
159
|
+
sink.bitLength_ = bits;
|
|
160
|
+
return SinkStatus::Ok;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
template <typename Compress>
|
|
164
|
+
static std::uint64_t bitLength(const BasicSink<Compress>& sink) noexcept {
|
|
165
|
+
return sink.bitLength_;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
template <typename Compress>
|
|
169
|
+
static std::size_t bufferLength(const BasicSink<Compress>& sink) noexcept {
|
|
170
|
+
return sink.bufferLength_;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
template <typename Compress>
|
|
174
|
+
static bool failed(const BasicSink<Compress>& sink) noexcept {
|
|
175
|
+
return sink.failed_;
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
#endif
|
|
179
|
+
|
|
180
|
+
// Little-endian field bytes for a checkpoint visitor.
|
|
181
|
+
// This is not the endianness of SHA-256 words.
|
|
182
|
+
template <typename Sink>
|
|
183
|
+
class LeFieldWriter {
|
|
184
|
+
public:
|
|
185
|
+
explicit LeFieldWriter(Sink& sink) noexcept : sink_(sink) {}
|
|
186
|
+
|
|
187
|
+
[[nodiscard]] SinkStatus u8(std::uint8_t value) noexcept {
|
|
188
|
+
return sink_.update(std::span<const std::uint8_t>(&value, 1));
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
[[nodiscard]] SinkStatus u32(std::uint32_t value) noexcept {
|
|
192
|
+
std::uint8_t tmp[4];
|
|
193
|
+
tmp[0] = static_cast<std::uint8_t>(value & 0xffu);
|
|
194
|
+
tmp[1] = static_cast<std::uint8_t>((value >> 8) & 0xffu);
|
|
195
|
+
tmp[2] = static_cast<std::uint8_t>((value >> 16) & 0xffu);
|
|
196
|
+
tmp[3] = static_cast<std::uint8_t>((value >> 24) & 0xffu);
|
|
197
|
+
return sink_.update(tmp);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
[[nodiscard]] SinkStatus u64(std::uint64_t value) noexcept {
|
|
201
|
+
std::uint8_t tmp[8];
|
|
202
|
+
for (unsigned index = 0; index < 8; ++index) {
|
|
203
|
+
const unsigned shift = index * 8u;
|
|
204
|
+
tmp[index] = static_cast<std::uint8_t>((value >> shift) & 0xffu);
|
|
205
|
+
}
|
|
206
|
+
return sink_.update(tmp);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
[[nodiscard]] SinkStatus i64(std::int64_t value) noexcept { return u64(static_cast<std::uint64_t>(value)); }
|
|
210
|
+
|
|
211
|
+
// Raw IEEE-754 bits.
|
|
212
|
+
[[nodiscard]] SinkStatus f64(double value) noexcept { return u64(std::bit_cast<std::uint64_t>(value)); }
|
|
213
|
+
|
|
214
|
+
[[nodiscard]] SinkStatus bytes(std::span<const std::uint8_t> data) noexcept { return sink_.update(data); }
|
|
215
|
+
|
|
216
|
+
// Domain text is u8 length, then the literal bytes. N includes the terminator.
|
|
217
|
+
template <std::size_t N>
|
|
218
|
+
[[nodiscard]] SinkStatus domainLiteral(const char (&text)[N]) noexcept {
|
|
219
|
+
static_assert(N >= 2);
|
|
220
|
+
static_assert(N - 1 <= 255);
|
|
221
|
+
const auto status = u8(static_cast<std::uint8_t>(N - 1));
|
|
222
|
+
if (status != SinkStatus::Ok) return status;
|
|
223
|
+
return bytes(std::span<const std::uint8_t>(reinterpret_cast<const std::uint8_t*>(text), N - 1));
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
private:
|
|
227
|
+
Sink& sink_;
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
using Sha256Sink = BasicSink<CompressUnsigned>;
|
|
231
|
+
|
|
232
|
+
static_assert(sizeof(Sha256Sink) <= 192);
|
|
233
|
+
|
|
234
|
+
} // namespace rundot::sha256
|