Thanks for using Compiler Explorer
Sponsors
Jakt
C++
Ada
Analysis
Android Java
Android Kotlin
Assembly
C
C3
Carbon
C++ (Circle)
CIRCT
Clean
CMake
CMakeScript
COBOL
C++ for OpenCL
MLIR
Cppx
Cppx-Blue
Cppx-Gold
Cpp2-cppfront
Crystal
C#
CUDA C++
D
Dart
Elixir
Erlang
Fortran
F#
GLSL
Go
Haskell
HLSL
Hook
Hylo
IL
ispc
Java
Julia
Kotlin
LLVM IR
LLVM MIR
Modula-2
Nim
Objective-C
Objective-C++
OCaml
Odin
OpenCL C
Pascal
Pony
Python
Racket
Ruby
Rust
Snowball
Scala
Slang
Solidity
Spice
SPIR-V
Swift
LLVM TableGen
Toit
TypeScript Native
V
Vala
Visual Basic
Vyper
WASM
Zig
Javascript
GIMPLE
Ygen
c++ source #1
Output
Compile to binary object
Link to binary
Execute the code
Intel asm syntax
Demangle identifiers
Verbose demangling
Filters
Unused labels
Library functions
Directives
Comments
Horizontal whitespace
Debug intrinsics
Compiler
6502-c++ 11.1.0
ARM GCC 10.2.0
ARM GCC 10.3.0
ARM GCC 10.4.0
ARM GCC 10.5.0
ARM GCC 11.1.0
ARM GCC 11.2.0
ARM GCC 11.3.0
ARM GCC 11.4.0
ARM GCC 12.1.0
ARM GCC 12.2.0
ARM GCC 12.3.0
ARM GCC 12.4.0
ARM GCC 13.1.0
ARM GCC 13.2.0
ARM GCC 13.2.0 (unknown-eabi)
ARM GCC 13.3.0
ARM GCC 13.3.0 (unknown-eabi)
ARM GCC 14.1.0
ARM GCC 14.1.0 (unknown-eabi)
ARM GCC 14.2.0
ARM GCC 14.2.0 (unknown-eabi)
ARM GCC 4.5.4
ARM GCC 4.6.4
ARM GCC 5.4
ARM GCC 6.3.0
ARM GCC 6.4.0
ARM GCC 7.3.0
ARM GCC 7.5.0
ARM GCC 8.2.0
ARM GCC 8.5.0
ARM GCC 9.3.0
ARM GCC 9.4.0
ARM GCC 9.5.0
ARM GCC trunk
ARM gcc 10.2.1 (none)
ARM gcc 10.3.1 (2021.07 none)
ARM gcc 10.3.1 (2021.10 none)
ARM gcc 11.2.1 (none)
ARM gcc 5.4.1 (none)
ARM gcc 7.2.1 (none)
ARM gcc 8.2 (WinCE)
ARM gcc 8.3.1 (none)
ARM gcc 9.2.1 (none)
ARM msvc v19.0 (WINE)
ARM msvc v19.10 (WINE)
ARM msvc v19.14 (WINE)
ARM64 Morello gcc 10.1 Alpha 2
ARM64 gcc 10.2
ARM64 gcc 10.3
ARM64 gcc 10.4
ARM64 gcc 10.5.0
ARM64 gcc 11.1
ARM64 gcc 11.2
ARM64 gcc 11.3
ARM64 gcc 11.4.0
ARM64 gcc 12.1
ARM64 gcc 12.2.0
ARM64 gcc 12.3.0
ARM64 gcc 12.4.0
ARM64 gcc 13.1.0
ARM64 gcc 13.2.0
ARM64 gcc 13.3.0
ARM64 gcc 14.1.0
ARM64 gcc 14.2.0
ARM64 gcc 4.9.4
ARM64 gcc 5.4
ARM64 gcc 5.5.0
ARM64 gcc 6.3
ARM64 gcc 6.4
ARM64 gcc 7.3
ARM64 gcc 7.5
ARM64 gcc 8.2
ARM64 gcc 8.5
ARM64 gcc 9.3
ARM64 gcc 9.4
ARM64 gcc 9.5
ARM64 gcc trunk
ARM64 msvc v19.14 (WINE)
AVR gcc 10.3.0
AVR gcc 11.1.0
AVR gcc 12.1.0
AVR gcc 12.2.0
AVR gcc 12.3.0
AVR gcc 12.4.0
AVR gcc 13.1.0
AVR gcc 13.2.0
AVR gcc 13.3.0
AVR gcc 14.1.0
AVR gcc 14.2.0
AVR gcc 4.5.4
AVR gcc 4.6.4
AVR gcc 5.4.0
AVR gcc 9.2.0
AVR gcc 9.3.0
Arduino Mega (1.8.9)
Arduino Uno (1.8.9)
BPF clang (trunk)
BPF clang 13.0.0
BPF clang 14.0.0
BPF clang 15.0.0
BPF clang 16.0.0
BPF clang 17.0.1
BPF clang 18.1.0
BPF clang 19.1.0
EDG (experimental reflection)
EDG 6.5
EDG 6.5 (GNU mode gcc 13)
EDG 6.6
EDG 6.6 (GNU mode gcc 13)
FRC 2019
FRC 2020
FRC 2023
HPPA gcc 14.2.0
KVX ACB 4.1.0 (GCC 7.5.0)
KVX ACB 4.1.0-cd1 (GCC 7.5.0)
KVX ACB 4.10.0 (GCC 10.3.1)
KVX ACB 4.11.1 (GCC 10.3.1)
KVX ACB 4.12.0 (GCC 11.3.0)
KVX ACB 4.2.0 (GCC 7.5.0)
KVX ACB 4.3.0 (GCC 7.5.0)
KVX ACB 4.4.0 (GCC 7.5.0)
KVX ACB 4.6.0 (GCC 9.4.1)
KVX ACB 4.8.0 (GCC 9.4.1)
KVX ACB 4.9.0 (GCC 9.4.1)
KVX ACB 5.0.0 (GCC 12.2.1)
KVX ACB 5.2.0 (GCC 13.2.1)
LoongArch64 clang (trunk)
LoongArch64 clang 17.0.1
LoongArch64 clang 18.1.0
LoongArch64 clang 19.1.0
M68K gcc 13.1.0
M68K gcc 13.2.0
M68K gcc 13.3.0
M68K gcc 14.1.0
M68K gcc 14.2.0
M68k clang (trunk)
MRISC32 gcc (trunk)
MSP430 gcc 4.5.3
MSP430 gcc 5.3.0
MSP430 gcc 6.2.1
MinGW clang 14.0.3
MinGW clang 14.0.6
MinGW clang 15.0.7
MinGW clang 16.0.0
MinGW clang 16.0.2
MinGW gcc 11.3.0
MinGW gcc 12.1.0
MinGW gcc 12.2.0
MinGW gcc 13.1.0
RISC-V (32-bits) gcc (trunk)
RISC-V (32-bits) gcc 10.2.0
RISC-V (32-bits) gcc 10.3.0
RISC-V (32-bits) gcc 11.2.0
RISC-V (32-bits) gcc 11.3.0
RISC-V (32-bits) gcc 11.4.0
RISC-V (32-bits) gcc 12.1.0
RISC-V (32-bits) gcc 12.2.0
RISC-V (32-bits) gcc 12.3.0
RISC-V (32-bits) gcc 12.4.0
RISC-V (32-bits) gcc 13.1.0
RISC-V (32-bits) gcc 13.2.0
RISC-V (32-bits) gcc 13.3.0
RISC-V (32-bits) gcc 14.1.0
RISC-V (32-bits) gcc 14.2.0
RISC-V (32-bits) gcc 8.2.0
RISC-V (32-bits) gcc 8.5.0
RISC-V (32-bits) gcc 9.4.0
RISC-V (64-bits) gcc (trunk)
RISC-V (64-bits) gcc 10.2.0
RISC-V (64-bits) gcc 10.3.0
RISC-V (64-bits) gcc 11.2.0
RISC-V (64-bits) gcc 11.3.0
RISC-V (64-bits) gcc 11.4.0
RISC-V (64-bits) gcc 12.1.0
RISC-V (64-bits) gcc 12.2.0
RISC-V (64-bits) gcc 12.3.0
RISC-V (64-bits) gcc 12.4.0
RISC-V (64-bits) gcc 13.1.0
RISC-V (64-bits) gcc 13.2.0
RISC-V (64-bits) gcc 13.3.0
RISC-V (64-bits) gcc 14.1.0
RISC-V (64-bits) gcc 14.2.0
RISC-V (64-bits) gcc 8.2.0
RISC-V (64-bits) gcc 8.5.0
RISC-V (64-bits) gcc 9.4.0
RISC-V rv32gc clang (trunk)
RISC-V rv32gc clang 10.0.0
RISC-V rv32gc clang 10.0.1
RISC-V rv32gc clang 11.0.0
RISC-V rv32gc clang 11.0.1
RISC-V rv32gc clang 12.0.0
RISC-V rv32gc clang 12.0.1
RISC-V rv32gc clang 13.0.0
RISC-V rv32gc clang 13.0.1
RISC-V rv32gc clang 14.0.0
RISC-V rv32gc clang 15.0.0
RISC-V rv32gc clang 16.0.0
RISC-V rv32gc clang 17.0.1
RISC-V rv32gc clang 18.1.0
RISC-V rv32gc clang 19.1.0
RISC-V rv32gc clang 9.0.0
RISC-V rv32gc clang 9.0.1
RISC-V rv64gc clang (trunk)
RISC-V rv64gc clang 10.0.0
RISC-V rv64gc clang 10.0.1
RISC-V rv64gc clang 11.0.0
RISC-V rv64gc clang 11.0.1
RISC-V rv64gc clang 12.0.0
RISC-V rv64gc clang 12.0.1
RISC-V rv64gc clang 13.0.0
RISC-V rv64gc clang 13.0.1
RISC-V rv64gc clang 14.0.0
RISC-V rv64gc clang 15.0.0
RISC-V rv64gc clang 16.0.0
RISC-V rv64gc clang 17.0.1
RISC-V rv64gc clang 18.1.0
RISC-V rv64gc clang 19.1.0
RISC-V rv64gc clang 9.0.0
RISC-V rv64gc clang 9.0.1
Raspbian Buster
Raspbian Stretch
SPARC LEON gcc 12.2.0
SPARC LEON gcc 12.3.0
SPARC LEON gcc 12.4.0
SPARC LEON gcc 13.1.0
SPARC LEON gcc 13.2.0
SPARC LEON gcc 13.3.0
SPARC LEON gcc 14.1.0
SPARC LEON gcc 14.2.0
SPARC gcc 12.2.0
SPARC gcc 12.3.0
SPARC gcc 12.4.0
SPARC gcc 13.1.0
SPARC gcc 13.2.0
SPARC gcc 13.3.0
SPARC gcc 14.1.0
SPARC gcc 14.2.0
SPARC64 gcc 12.2.0
SPARC64 gcc 12.3.0
SPARC64 gcc 12.4.0
SPARC64 gcc 13.1.0
SPARC64 gcc 13.2.0
SPARC64 gcc 13.3.0
SPARC64 gcc 14.1.0
SPARC64 gcc 14.2.0
TI C6x gcc 12.2.0
TI C6x gcc 12.3.0
TI C6x gcc 12.4.0
TI C6x gcc 13.1.0
TI C6x gcc 13.2.0
TI C6x gcc 13.3.0
TI C6x gcc 14.1.0
TI C6x gcc 14.2.0
TI CL430 21.6.1
VAX gcc NetBSDELF 10.4.0
VAX gcc NetBSDELF 10.5.0 (Nov 15 03:50:22 2023)
WebAssembly clang (trunk)
Xtensa ESP32 gcc 11.2.0 (2022r1)
Xtensa ESP32 gcc 12.2.0 (20230208)
Xtensa ESP32 gcc 8.2.0 (2019r2)
Xtensa ESP32 gcc 8.2.0 (2020r1)
Xtensa ESP32 gcc 8.2.0 (2020r2)
Xtensa ESP32 gcc 8.4.0 (2020r3)
Xtensa ESP32 gcc 8.4.0 (2021r1)
Xtensa ESP32 gcc 8.4.0 (2021r2)
Xtensa ESP32-S2 gcc 11.2.0 (2022r1)
Xtensa ESP32-S2 gcc 12.2.0 (20230208)
Xtensa ESP32-S2 gcc 8.2.0 (2019r2)
Xtensa ESP32-S2 gcc 8.2.0 (2020r1)
Xtensa ESP32-S2 gcc 8.2.0 (2020r2)
Xtensa ESP32-S2 gcc 8.4.0 (2020r3)
Xtensa ESP32-S2 gcc 8.4.0 (2021r1)
Xtensa ESP32-S2 gcc 8.4.0 (2021r2)
Xtensa ESP32-S3 gcc 11.2.0 (2022r1)
Xtensa ESP32-S3 gcc 12.2.0 (20230208)
Xtensa ESP32-S3 gcc 8.4.0 (2020r3)
Xtensa ESP32-S3 gcc 8.4.0 (2021r1)
Xtensa ESP32-S3 gcc 8.4.0 (2021r2)
arm64 msvc v19.20 VS16.0
arm64 msvc v19.21 VS16.1
arm64 msvc v19.22 VS16.2
arm64 msvc v19.23 VS16.3
arm64 msvc v19.24 VS16.4
arm64 msvc v19.25 VS16.5
arm64 msvc v19.27 VS16.7
arm64 msvc v19.28 VS16.8
arm64 msvc v19.28 VS16.9
arm64 msvc v19.29 VS16.10
arm64 msvc v19.29 VS16.11
arm64 msvc v19.30 VS17.0
arm64 msvc v19.31 VS17.1
arm64 msvc v19.32 VS17.2
arm64 msvc v19.33 VS17.3
arm64 msvc v19.34 VS17.4
arm64 msvc v19.35 VS17.5
arm64 msvc v19.36 VS17.6
arm64 msvc v19.37 VS17.7
arm64 msvc v19.38 VS17.8
arm64 msvc v19.39 VS17.9
arm64 msvc v19.40 VS17.10
arm64 msvc v19.latest
armv7-a clang (trunk)
armv7-a clang 10.0.0
armv7-a clang 10.0.1
armv7-a clang 11.0.0
armv7-a clang 11.0.1
armv7-a clang 12.0.0
armv7-a clang 12.0.1
armv7-a clang 13.0.0
armv7-a clang 13.0.1
armv7-a clang 14.0.0
armv7-a clang 15.0.0
armv7-a clang 16.0.0
armv7-a clang 17.0.1
armv7-a clang 18.1.0
armv7-a clang 19.1.0
armv7-a clang 9.0.0
armv7-a clang 9.0.1
armv8-a clang (all architectural features, trunk)
armv8-a clang (trunk)
armv8-a clang 10.0.0
armv8-a clang 10.0.1
armv8-a clang 11.0.0
armv8-a clang 11.0.1
armv8-a clang 12.0.0
armv8-a clang 13.0.0
armv8-a clang 14.0.0
armv8-a clang 15.0.0
armv8-a clang 16.0.0
armv8-a clang 17.0.1
armv8-a clang 18.1.0
armv8-a clang 19.1.0
armv8-a clang 9.0.0
armv8-a clang 9.0.1
clang-cl 18.1.0
ellcc 0.1.33
ellcc 0.1.34
ellcc 2017-07-16
hexagon-clang 16.0.5
llvm-mos atari2600-3e
llvm-mos atari2600-4k
llvm-mos atari2600-common
llvm-mos atari5200-supercart
llvm-mos atari8-cart-megacart
llvm-mos atari8-cart-std
llvm-mos atari8-cart-xegs
llvm-mos atari8-common
llvm-mos atari8-dos
llvm-mos c128
llvm-mos c64
llvm-mos commodore
llvm-mos cpm65
llvm-mos cx16
llvm-mos dodo
llvm-mos eater
llvm-mos mega65
llvm-mos nes
llvm-mos nes-action53
llvm-mos nes-cnrom
llvm-mos nes-gtrom
llvm-mos nes-mmc1
llvm-mos nes-mmc3
llvm-mos nes-nrom
llvm-mos nes-unrom
llvm-mos nes-unrom-512
llvm-mos osi-c1p
llvm-mos pce
llvm-mos pce-cd
llvm-mos pce-common
llvm-mos pet
llvm-mos rp6502
llvm-mos rpc8e
llvm-mos supervision
llvm-mos vic20
loongarch64 gcc 12.2.0
loongarch64 gcc 12.3.0
loongarch64 gcc 12.4.0
loongarch64 gcc 13.1.0
loongarch64 gcc 13.2.0
loongarch64 gcc 13.3.0
loongarch64 gcc 14.1.0
loongarch64 gcc 14.2.0
mips clang 13.0.0
mips clang 14.0.0
mips clang 15.0.0
mips clang 16.0.0
mips clang 17.0.1
mips clang 18.1.0
mips clang 19.1.0
mips gcc 11.2.0
mips gcc 12.1.0
mips gcc 12.2.0
mips gcc 12.3.0
mips gcc 12.4.0
mips gcc 13.1.0
mips gcc 13.2.0
mips gcc 13.3.0
mips gcc 14.1.0
mips gcc 14.2.0
mips gcc 4.9.4
mips gcc 5.4
mips gcc 5.5.0
mips gcc 9.3.0 (codescape)
mips gcc 9.5.0
mips64 (el) gcc 12.1.0
mips64 (el) gcc 12.2.0
mips64 (el) gcc 12.3.0
mips64 (el) gcc 12.4.0
mips64 (el) gcc 13.1.0
mips64 (el) gcc 13.2.0
mips64 (el) gcc 13.3.0
mips64 (el) gcc 14.1.0
mips64 (el) gcc 14.2.0
mips64 (el) gcc 4.9.4
mips64 (el) gcc 5.4.0
mips64 (el) gcc 5.5.0
mips64 (el) gcc 9.5.0
mips64 clang 13.0.0
mips64 clang 14.0.0
mips64 clang 15.0.0
mips64 clang 16.0.0
mips64 clang 17.0.1
mips64 clang 18.1.0
mips64 clang 19.1.0
mips64 gcc 11.2.0
mips64 gcc 12.1.0
mips64 gcc 12.2.0
mips64 gcc 12.3.0
mips64 gcc 12.4.0
mips64 gcc 13.1.0
mips64 gcc 13.2.0
mips64 gcc 13.3.0
mips64 gcc 14.1.0
mips64 gcc 14.2.0
mips64 gcc 4.9.4
mips64 gcc 5.4.0
mips64 gcc 5.5.0
mips64 gcc 9.5.0
mips64el clang 13.0.0
mips64el clang 14.0.0
mips64el clang 15.0.0
mips64el clang 16.0.0
mips64el clang 17.0.1
mips64el clang 18.1.0
mips64el clang 19.1.0
mipsel clang 13.0.0
mipsel clang 14.0.0
mipsel clang 15.0.0
mipsel clang 16.0.0
mipsel clang 17.0.1
mipsel clang 18.1.0
mipsel clang 19.1.0
mipsel gcc 12.1.0
mipsel gcc 12.2.0
mipsel gcc 12.3.0
mipsel gcc 12.4.0
mipsel gcc 13.1.0
mipsel gcc 13.2.0
mipsel gcc 13.3.0
mipsel gcc 14.1.0
mipsel gcc 14.2.0
mipsel gcc 4.9.4
mipsel gcc 5.4.0
mipsel gcc 5.5.0
mipsel gcc 9.5.0
nanoMIPS gcc 6.3.0 (mtk)
power gcc 11.2.0
power gcc 12.1.0
power gcc 12.2.0
power gcc 12.3.0
power gcc 12.4.0
power gcc 13.1.0
power gcc 13.2.0
power gcc 13.3.0
power gcc 14.1.0
power gcc 14.2.0
power gcc 4.8.5
power64 AT12.0 (gcc8)
power64 AT13.0 (gcc9)
power64 gcc 11.2.0
power64 gcc 12.1.0
power64 gcc 12.2.0
power64 gcc 12.3.0
power64 gcc 12.4.0
power64 gcc 13.1.0
power64 gcc 13.2.0
power64 gcc 13.3.0
power64 gcc 14.1.0
power64 gcc 14.2.0
power64 gcc trunk
power64le AT12.0 (gcc8)
power64le AT13.0 (gcc9)
power64le clang (trunk)
power64le gcc 11.2.0
power64le gcc 12.1.0
power64le gcc 12.2.0
power64le gcc 12.3.0
power64le gcc 12.4.0
power64le gcc 13.1.0
power64le gcc 13.2.0
power64le gcc 13.3.0
power64le gcc 14.1.0
power64le gcc 14.2.0
power64le gcc 6.3.0
power64le gcc trunk
powerpc64 clang (trunk)
s390x gcc 11.2.0
s390x gcc 12.1.0
s390x gcc 12.2.0
s390x gcc 12.3.0
s390x gcc 12.4.0
s390x gcc 13.1.0
s390x gcc 13.2.0
s390x gcc 13.3.0
s390x gcc 14.1.0
s390x gcc 14.2.0
sh gcc 12.2.0
sh gcc 12.3.0
sh gcc 12.4.0
sh gcc 13.1.0
sh gcc 13.2.0
sh gcc 13.3.0
sh gcc 14.1.0
sh gcc 14.2.0
sh gcc 4.9.4
sh gcc 9.5.0
vast (trunk)
x64 msvc v19.0 (WINE)
x64 msvc v19.10 (WINE)
x64 msvc v19.14 (WINE)
x64 msvc v19.20 VS16.0
x64 msvc v19.21 VS16.1
x64 msvc v19.22 VS16.2
x64 msvc v19.23 VS16.3
x64 msvc v19.24 VS16.4
x64 msvc v19.25 VS16.5
x64 msvc v19.27 VS16.7
x64 msvc v19.28 VS16.8
x64 msvc v19.28 VS16.9
x64 msvc v19.29 VS16.10
x64 msvc v19.29 VS16.11
x64 msvc v19.30 VS17.0
x64 msvc v19.31 VS17.1
x64 msvc v19.32 VS17.2
x64 msvc v19.33 VS17.3
x64 msvc v19.34 VS17.4
x64 msvc v19.35 VS17.5
x64 msvc v19.36 VS17.6
x64 msvc v19.37 VS17.7
x64 msvc v19.38 VS17.8
x64 msvc v19.39 VS17.9
x64 msvc v19.40 VS17.10
x64 msvc v19.latest
x86 djgpp 4.9.4
x86 djgpp 5.5.0
x86 djgpp 6.4.0
x86 djgpp 7.2.0
x86 msvc v19.0 (WINE)
x86 msvc v19.10 (WINE)
x86 msvc v19.14 (WINE)
x86 msvc v19.20 VS16.0
x86 msvc v19.21 VS16.1
x86 msvc v19.22 VS16.2
x86 msvc v19.23 VS16.3
x86 msvc v19.24 VS16.4
x86 msvc v19.25 VS16.5
x86 msvc v19.27 VS16.7
x86 msvc v19.28 VS16.8
x86 msvc v19.28 VS16.9
x86 msvc v19.29 VS16.10
x86 msvc v19.29 VS16.11
x86 msvc v19.30 VS17.0
x86 msvc v19.31 VS17.1
x86 msvc v19.32 VS17.2
x86 msvc v19.33 VS17.3
x86 msvc v19.34 VS17.4
x86 msvc v19.35 VS17.5
x86 msvc v19.36 VS17.6
x86 msvc v19.37 VS17.7
x86 msvc v19.38 VS17.8
x86 msvc v19.39 VS17.9
x86 msvc v19.40 VS17.10
x86 msvc v19.latest
x86 nvc++ 22.11
x86 nvc++ 22.7
x86 nvc++ 22.9
x86 nvc++ 23.1
x86 nvc++ 23.11
x86 nvc++ 23.3
x86 nvc++ 23.5
x86 nvc++ 23.7
x86 nvc++ 23.9
x86 nvc++ 24.1
x86 nvc++ 24.11
x86 nvc++ 24.3
x86 nvc++ 24.5
x86 nvc++ 24.7
x86 nvc++ 24.9
x86-64 Zapcc 190308
x86-64 clang (Chris Bazley N3089)
x86-64 clang (EricWF contracts)
x86-64 clang (amd-staging)
x86-64 clang (assertions trunk)
x86-64 clang (clangir)
x86-64 clang (dascandy contracts)
x86-64 clang (experimental -Wlifetime)
x86-64 clang (experimental P1061)
x86-64 clang (experimental P1144)
x86-64 clang (experimental P1221)
x86-64 clang (experimental P2996)
x86-64 clang (experimental P2998)
x86-64 clang (experimental P3068)
x86-64 clang (experimental P3309)
x86-64 clang (experimental P3367)
x86-64 clang (experimental P3372)
x86-64 clang (experimental metaprogramming - P2632)
x86-64 clang (old concepts branch)
x86-64 clang (p1974)
x86-64 clang (pattern matching - P2688)
x86-64 clang (reflection)
x86-64 clang (resugar)
x86-64 clang (string interpolation - P3412)
x86-64 clang (thephd.dev)
x86-64 clang (trunk)
x86-64 clang (variadic friends - P2893)
x86-64 clang (widberg)
x86-64 clang 10.0.0
x86-64 clang 10.0.0 (assertions)
x86-64 clang 10.0.1
x86-64 clang 11.0.0
x86-64 clang 11.0.0 (assertions)
x86-64 clang 11.0.1
x86-64 clang 12.0.0
x86-64 clang 12.0.0 (assertions)
x86-64 clang 12.0.1
x86-64 clang 13.0.0
x86-64 clang 13.0.0 (assertions)
x86-64 clang 13.0.1
x86-64 clang 14.0.0
x86-64 clang 14.0.0 (assertions)
x86-64 clang 15.0.0
x86-64 clang 15.0.0 (assertions)
x86-64 clang 16.0.0
x86-64 clang 16.0.0 (assertions)
x86-64 clang 17.0.1
x86-64 clang 17.0.1 (assertions)
x86-64 clang 18.1.0
x86-64 clang 18.1.0 (assertions)
x86-64 clang 19.1.0
x86-64 clang 19.1.0 (assertions)
x86-64 clang 2.6.0 (assertions)
x86-64 clang 2.7.0 (assertions)
x86-64 clang 2.8.0 (assertions)
x86-64 clang 2.9.0 (assertions)
x86-64 clang 3.0.0
x86-64 clang 3.0.0 (assertions)
x86-64 clang 3.1
x86-64 clang 3.1 (assertions)
x86-64 clang 3.2
x86-64 clang 3.2 (assertions)
x86-64 clang 3.3
x86-64 clang 3.3 (assertions)
x86-64 clang 3.4 (assertions)
x86-64 clang 3.4.1
x86-64 clang 3.5
x86-64 clang 3.5 (assertions)
x86-64 clang 3.5.1
x86-64 clang 3.5.2
x86-64 clang 3.6
x86-64 clang 3.6 (assertions)
x86-64 clang 3.7
x86-64 clang 3.7 (assertions)
x86-64 clang 3.7.1
x86-64 clang 3.8
x86-64 clang 3.8 (assertions)
x86-64 clang 3.8.1
x86-64 clang 3.9.0
x86-64 clang 3.9.0 (assertions)
x86-64 clang 3.9.1
x86-64 clang 4.0.0
x86-64 clang 4.0.0 (assertions)
x86-64 clang 4.0.1
x86-64 clang 5.0.0
x86-64 clang 5.0.0 (assertions)
x86-64 clang 5.0.1
x86-64 clang 5.0.2
x86-64 clang 6.0.0
x86-64 clang 6.0.0 (assertions)
x86-64 clang 6.0.1
x86-64 clang 7.0.0
x86-64 clang 7.0.0 (assertions)
x86-64 clang 7.0.1
x86-64 clang 7.1.0
x86-64 clang 8.0.0
x86-64 clang 8.0.0 (assertions)
x86-64 clang 8.0.1
x86-64 clang 9.0.0
x86-64 clang 9.0.0 (assertions)
x86-64 clang 9.0.1
x86-64 clang rocm-4.5.2
x86-64 clang rocm-5.0.2
x86-64 clang rocm-5.1.3
x86-64 clang rocm-5.2.3
x86-64 clang rocm-5.3.3
x86-64 clang rocm-5.7.0
x86-64 clang rocm-6.0.2
x86-64 clang rocm-6.1.2
x86-64 gcc (contract labels)
x86-64 gcc (contracts natural syntax)
x86-64 gcc (contracts)
x86-64 gcc (coroutines)
x86-64 gcc (modules)
x86-64 gcc (trunk)
x86-64 gcc 10.1
x86-64 gcc 10.2
x86-64 gcc 10.3
x86-64 gcc 10.3 (assertions)
x86-64 gcc 10.4
x86-64 gcc 10.4 (assertions)
x86-64 gcc 10.5
x86-64 gcc 10.5 (assertions)
x86-64 gcc 11.1
x86-64 gcc 11.1 (assertions)
x86-64 gcc 11.2
x86-64 gcc 11.2 (assertions)
x86-64 gcc 11.3
x86-64 gcc 11.3 (assertions)
x86-64 gcc 11.4
x86-64 gcc 11.4 (assertions)
x86-64 gcc 12.1
x86-64 gcc 12.1 (assertions)
x86-64 gcc 12.2
x86-64 gcc 12.2 (assertions)
x86-64 gcc 12.3
x86-64 gcc 12.3 (assertions)
x86-64 gcc 12.4
x86-64 gcc 12.4 (assertions)
x86-64 gcc 13.1
x86-64 gcc 13.1 (assertions)
x86-64 gcc 13.2
x86-64 gcc 13.2 (assertions)
x86-64 gcc 13.3
x86-64 gcc 13.3 (assertions)
x86-64 gcc 14.1
x86-64 gcc 14.1 (assertions)
x86-64 gcc 14.2
x86-64 gcc 14.2 (assertions)
x86-64 gcc 3.4.6
x86-64 gcc 4.0.4
x86-64 gcc 4.1.2
x86-64 gcc 4.4.7
x86-64 gcc 4.5.3
x86-64 gcc 4.6.4
x86-64 gcc 4.7.1
x86-64 gcc 4.7.2
x86-64 gcc 4.7.3
x86-64 gcc 4.7.4
x86-64 gcc 4.8.1
x86-64 gcc 4.8.2
x86-64 gcc 4.8.3
x86-64 gcc 4.8.4
x86-64 gcc 4.8.5
x86-64 gcc 4.9.0
x86-64 gcc 4.9.1
x86-64 gcc 4.9.2
x86-64 gcc 4.9.3
x86-64 gcc 4.9.4
x86-64 gcc 5.1
x86-64 gcc 5.2
x86-64 gcc 5.3
x86-64 gcc 5.4
x86-64 gcc 5.5
x86-64 gcc 6.1
x86-64 gcc 6.2
x86-64 gcc 6.3
x86-64 gcc 6.4
x86-64 gcc 6.5
x86-64 gcc 7.1
x86-64 gcc 7.2
x86-64 gcc 7.3
x86-64 gcc 7.4
x86-64 gcc 7.5
x86-64 gcc 8.1
x86-64 gcc 8.2
x86-64 gcc 8.3
x86-64 gcc 8.4
x86-64 gcc 8.5
x86-64 gcc 9.1
x86-64 gcc 9.2
x86-64 gcc 9.3
x86-64 gcc 9.4
x86-64 gcc 9.5
x86-64 icc 13.0.1
x86-64 icc 16.0.3
x86-64 icc 17.0.0
x86-64 icc 18.0.0
x86-64 icc 19.0.0
x86-64 icc 19.0.1
x86-64 icc 2021.1.2
x86-64 icc 2021.10.0
x86-64 icc 2021.2.0
x86-64 icc 2021.3.0
x86-64 icc 2021.4.0
x86-64 icc 2021.5.0
x86-64 icc 2021.6.0
x86-64 icc 2021.7.0
x86-64 icc 2021.7.1
x86-64 icc 2021.8.0
x86-64 icc 2021.9.0
x86-64 icx 2021.1.2
x86-64 icx 2021.2.0
x86-64 icx 2021.3.0
x86-64 icx 2021.4.0
x86-64 icx 2022.0.0
x86-64 icx 2022.1.0
x86-64 icx 2022.2.0
x86-64 icx 2022.2.1
x86-64 icx 2023.0.0
x86-64 icx 2023.1.0
x86-64 icx 2023.2.1
x86-64 icx 2024.0.0
x86-64 icx 2024.1.0
x86-64 icx 2024.2.0
x86-64 icx 2025.0.0
x86-64 icx 2025.0.0
zig c++ 0.10.0
zig c++ 0.11.0
zig c++ 0.12.0
zig c++ 0.12.1
zig c++ 0.13.0
zig c++ 0.6.0
zig c++ 0.7.0
zig c++ 0.7.1
zig c++ 0.8.0
zig c++ 0.9.0
zig c++ trunk
Options
Source code
#include <https://raw.githubusercontent.com/pdimov/hash2/refs/heads/develop/include/boost/hash2/hash_append_fwd.hpp> #include <https://raw.githubusercontent.com/pdimov/hash2/refs/heads/develop/include/boost/hash2/is_trivially_equality_comparable.hpp> #include <https://raw.githubusercontent.com/pdimov/hash2/refs/heads/develop/include/boost/hash2/is_endian_independent.hpp> #include <https://raw.githubusercontent.com/pdimov/hash2/refs/heads/develop/include/boost/hash2/endian.hpp> // #include <boost/hash2/is_contiguously_hashable.hpp> #ifndef BOOST_HASH2_IS_CONTIGUOUSLY_HASHABLE_HPP_INCLUDED #define BOOST_HASH2_IS_CONTIGUOUSLY_HASHABLE_HPP_INCLUDED // Copyright 2017, 2023, 2024 Peter Dimov. // Distributed under the Boost Software License, Version 1.0. // https://www.boost.org/LICENSE_1_0.txt //#include <boost/hash2/is_trivially_equality_comparable.hpp> //#include <boost/hash2/is_endian_independent.hpp> //#include <boost/hash2/endian.hpp> #include <type_traits> #include <cstddef> namespace boost { namespace hash2 { template<class T, endian E> struct is_contiguously_hashable: std::integral_constant<bool, is_trivially_equality_comparable<T>::value && (E == endian::native || is_endian_independent<T>::value)> { }; template<class T, std::size_t N, endian E> struct is_contiguously_hashable<T[N], E>: is_contiguously_hashable<T, E> { }; } // namespace hash2 } // namespace boost #endif // #ifndef BOOST_HASH2_IS_CONTIGUOUSLY_HASHABLE_HPP_INCLUDED #include <https://raw.githubusercontent.com/pdimov/hash2/refs/heads/develop/include/boost/hash2/has_constant_size.hpp> #include <https://raw.githubusercontent.com/pdimov/hash2/refs/heads/develop/include/boost/hash2/detail/config.hpp> //#include <boost/hash2/detail/is_constant_evaluated.hpp> #ifndef BOOST_HASH2_DETAIL_IS_CONSTANT_EVALUATED_HPP_INCLUDED #define BOOST_HASH2_DETAIL_IS_CONSTANT_EVALUATED_HPP_INCLUDED // Copyright 2024 Peter Dimov // Distributed under the Boost Software License, Version 1.0. // https://www.boost.org/LICENSE_1_0.txt //#include <boost/hash2/detail/config.hpp> namespace boost { namespace hash2 { namespace detail { constexpr bool is_constant_evaluated() noexcept { #if defined(BOOST_HASH2_HAS_BUILTIN_IS_CONSTANT_EVALUATED) return __builtin_is_constant_evaluated(); #else return true; #endif } } // namespace detail } // namespace hash2 } // namespace boost #endif // #ifndef BOOST_HASH2_DETAIL_IS_CONSTANT_EVALUATED_HPP_INCLUDED //#include <boost/hash2/detail/read.hpp> #ifndef BOOST_HASH2_DETAIL_READ_HPP_INCLUDED #define BOOST_HASH2_DETAIL_READ_HPP_INCLUDED // Copyright 2017, 2018, 2024 Peter Dimov // Distributed under the Boost Software License, Version 1.0. // https://www.boost.org/LICENSE_1_0.txt //#include <boost/hash2/endian.hpp> //#include <boost/hash2/detail/is_constant_evaluated.hpp> #include <boost/config.hpp> #include <cstdint> #include <cstring> namespace boost { namespace hash2 { namespace detail { BOOST_FORCEINLINE BOOST_CXX14_CONSTEXPR std::uint32_t read32le( unsigned char const * p ) noexcept { if( !detail::is_constant_evaluated() && endian::native == endian::little ) { std::uint32_t v = 0; std::memcpy( &v, p, sizeof(v) ); return v; } else { return static_cast<std::uint32_t>( p[0] ) | ( static_cast<std::uint32_t>( p[1] ) << 8 ) | ( static_cast<std::uint32_t>( p[2] ) << 16 ) | ( static_cast<std::uint32_t>( p[3] ) << 24 ); } } BOOST_FORCEINLINE BOOST_CXX14_CONSTEXPR std::uint64_t read64le( unsigned char const * p ) noexcept { if( !detail::is_constant_evaluated() && endian::native == endian::little ) { std::uint64_t v = 0; std::memcpy( &v, p, sizeof(v) ); return v; } else { return static_cast<std::uint64_t>( p[0] ) | ( static_cast<std::uint64_t>( p[1] ) << 8 ) | ( static_cast<std::uint64_t>( p[2] ) << 16 ) | ( static_cast<std::uint64_t>( p[3] ) << 24 ) | ( static_cast<std::uint64_t>( p[4] ) << 32 ) | ( static_cast<std::uint64_t>( p[5] ) << 40 ) | ( static_cast<std::uint64_t>( p[6] ) << 48 ) | ( static_cast<std::uint64_t>( p[7] ) << 56 ); } } BOOST_FORCEINLINE BOOST_CXX14_CONSTEXPR std::uint32_t read32be( unsigned char const * p ) noexcept { return static_cast<std::uint32_t>( p[3] ) | ( static_cast<std::uint32_t>( p[2] ) << 8 ) | ( static_cast<std::uint32_t>( p[1] ) << 16 ) | ( static_cast<std::uint32_t>( p[0] ) << 24 ); } BOOST_FORCEINLINE BOOST_CXX14_CONSTEXPR std::uint64_t read64be( unsigned char const * p ) noexcept { return static_cast<std::uint64_t>( p[7] ) | ( static_cast<std::uint64_t>( p[6] ) << 8 ) | ( static_cast<std::uint64_t>( p[5] ) << 16 ) | ( static_cast<std::uint64_t>( p[4] ) << 24 ) | ( static_cast<std::uint64_t>( p[3] ) << 32 ) | ( static_cast<std::uint64_t>( p[2] ) << 40 ) | ( static_cast<std::uint64_t>( p[1] ) << 48 ) | ( static_cast<std::uint64_t>( p[0] ) << 56 ); } } // namespace detail } // namespace hash2 } // namespace boost #endif // #ifndef BOOST_HASH2_DETAIL_READ_HPP_INCLUDED //#include <boost/hash2/get_integral_result.hpp> #ifndef BOOST_HASH2_GET_INTEGRAL_RESULT_HPP_INCLUDED #define BOOST_HASH2_GET_INTEGRAL_RESULT_HPP_INCLUDED // Copyright 2017, 2018 Peter Dimov. // Distributed under the Boost Software License, Version 1.0. // https://www.boost.org/LICENSE_1_0.txt //#include <boost/hash2/detail/read.hpp> #include <type_traits> #include <limits> #include <cstddef> namespace boost { namespace hash2 { namespace detail { // identity template<class U, class R> constexpr typename std::enable_if<sizeof(R) == sizeof(U), U>::type get_result_multiplier() { return 1; } // contraction // 2 -> 1 template<class U, class R> constexpr typename std::enable_if<sizeof(R) == 2 && sizeof(U) == 1, R>::type get_result_multiplier() { return 0xBF01; } // 4 -> 1 template<class U, class R> constexpr typename std::enable_if<sizeof(R) == 4 && sizeof(U) == 1, R>::type get_result_multiplier() { return 0x7F7F7F7Fu; } // 8 -> 1 template<class U, class R> constexpr typename std::enable_if<sizeof(R) == 8 && sizeof(U) == 1, R>::type get_result_multiplier() { return 0x7F7F7F7F7F7F7F7Full; } // 4 -> 2 template<class U, class R> constexpr typename std::enable_if<sizeof(R) == 4 && sizeof(U) == 2, R>::type get_result_multiplier() { return 0xBFFF0001u; } // 8 -> 2 template<class U, class R> constexpr typename std::enable_if<sizeof(R) == 8 && sizeof(U) == 2, R>::type get_result_multiplier() { return 0xBFFFBFFFBFFFBFFFull; } // 8 -> 4 template<class U, class R> constexpr typename std::enable_if<sizeof(R) == 8 && sizeof(U) == 4, R>::type get_result_multiplier() { return 0xBFFFFFFF00000001ull; } // expansion // 1 -> 2 template<class U, class R> constexpr typename std::enable_if<sizeof(R) == 1 && sizeof(U) == 2, U>::type get_result_multiplier() { return 0x7F7F; } // 1 -> 4 template<class U, class R> constexpr typename std::enable_if<sizeof(R) == 1 && sizeof(U) == 4, U>::type get_result_multiplier() { return 0xBFBFBFBFu; } // 1 -> 8 template<class U, class R> constexpr typename std::enable_if<sizeof(R) == 1 && sizeof(U) == 8, U>::type get_result_multiplier() { return 0xDFDFDFDFDFDFDFDFull; } // 2 -> 4 template<class U, class R> constexpr typename std::enable_if<sizeof(R) == 2 && sizeof(U) == 4, U>::type get_result_multiplier() { return 0x7FFF7FFFu; } // 2 -> 8 template<class U, class R> constexpr typename std::enable_if<sizeof(R) == 2 && sizeof(U) == 8, U>::type get_result_multiplier() { return 0x7FFF7FFF7FFF7FFFull; } // 4 -> 8 template<class U, class R> constexpr typename std::enable_if<sizeof(R) == 4 && sizeof(U) == 8, U>::type get_result_multiplier() { return 0x7FFFFFFF7FFFFFFFull; } } // namespace detail // contraction template<class T, class R> typename std::enable_if<std::is_integral<R>::value && (sizeof(R) > sizeof(T)), T>::type get_integral_result( R const & r ) { static_assert( std::is_integral<T>::value, "T must be integral" ); static_assert( !std::is_same<typename std::remove_cv<T>::type, bool>::value, "T must not be bool" ); static_assert( std::is_unsigned<R>::value, "R must be unsigned" ); typedef typename std::make_unsigned<T>::type U; constexpr auto m = detail::get_result_multiplier<U, R>(); return static_cast<T>( static_cast<U>( ( r * m ) >> ( std::numeric_limits<R>::digits - std::numeric_limits<U>::digits ) ) ); } // identity or expansion template<class T, class R> typename std::enable_if<std::is_integral<R>::value && (sizeof(R) <= sizeof(T)), T>::type get_integral_result( R const & r ) { static_assert( std::is_integral<T>::value, "T must be integral" ); static_assert( !std::is_same<typename std::remove_cv<T>::type, bool>::value, "T must not be bool" ); static_assert( std::is_unsigned<R>::value, "R must be unsigned" ); typedef typename std::make_unsigned<T>::type U; constexpr auto m = detail::get_result_multiplier<U, R>(); return static_cast<T>( static_cast<U>( r * m ) ); } // array-like R template<class T, class R> typename std::enable_if< !std::is_integral<R>::value, T >::type get_integral_result( R const & r ) { static_assert( std::is_integral<T>::value, "T must be integral" ); static_assert( !std::is_same<typename std::remove_cv<T>::type, bool>::value, "T must not be bool" ); static_assert( R().size() >= 8, "Array-like result type is too short" ); return static_cast<T>( detail::read64le( r.data() ) ); } } // namespace hash2 } // namespace boost #endif // #ifndef BOOST_HASH2_GET_INTEGRAL_RESULT_HPP_INCLUDED //#include <boost/hash2/flavor.hpp> #ifndef BOOST_HASH2_FLAVOR_HPP_INCLUDED #define BOOST_HASH2_FLAVOR_HPP_INCLUDED // Copyright 2024 Peter Dimov. // Distributed under the Boost Software License, Version 1.0. // https://www.boost.org/LICENSE_1_0.txt //#include <boost/hash2/endian.hpp> #include <cstdint> namespace boost { namespace hash2 { struct default_flavor { using size_type = std::uint64_t; static constexpr auto byte_order = endian::native; }; struct little_endian_flavor { using size_type = std::uint64_t; static constexpr auto byte_order = endian::little; }; struct big_endian_flavor { using size_type = std::uint64_t; static constexpr auto byte_order = endian::big; }; } // namespace hash2 } // namespace boost #endif // #ifndef BOOST_HASH2_FLAVOR_HPP_INCLUDED //#include <boost/hash2/detail/bit_cast.hpp> #ifndef BOOST_HASH2_DETAIL_BIT_CAST_HPP_INCLUDED #define BOOST_HASH2_DETAIL_BIT_CAST_HPP_INCLUDED // Copyright 2024 Peter Dimov // Distributed under the Boost Software License, Version 1.0. // https://www.boost.org/LICENSE_1_0.txt //#include <boost/hash2/detail/config.hpp> #include <boost/config.hpp> #include <type_traits> #include <cstring> namespace boost { namespace hash2 { namespace detail { template<class To, class From> BOOST_CXX14_CONSTEXPR To bit_cast( From const& from ) noexcept { static_assert( sizeof(From) == sizeof(To), "Types must be the same size" ); #if defined(BOOST_LIBSTDCXX_VERSION) && BOOST_LIBSTDCXX_VERSION < 50000 // std::is_trivially_copyable doesn't exist in libstdc++ 4.x #else static_assert( std::is_trivially_copyable<From>::value, "Types must be trivially copyable" ); static_assert( std::is_trivially_copyable<To>::value, "Types must be trivially copyable" ); #endif #if defined(BOOST_HASH2_HAS_BUILTIN_BIT_CAST) return __builtin_bit_cast( To, from ); #else To to{}; std::memcpy( &to, &from, sizeof(From) ); return to; #endif } } // namespace detail } // namespace hash2 } // namespace boost #endif // #ifndef BOOST_HASH2_DETAIL_BIT_CAST_HPP_INCLUDED //#include <boost/hash2/detail/write.hpp> #ifndef BOOST_HASH2_DETAIL_WRITE_HPP_INCLUDED #define BOOST_HASH2_DETAIL_WRITE_HPP_INCLUDED // Copyright 2017, 2018, 2024 Peter Dimov // Distributed under the Boost Software License, Version 1.0. // https://www.boost.org/LICENSE_1_0.txt //#include <boost/hash2/endian.hpp> //#include <boost/hash2/detail/is_constant_evaluated.hpp> #include <boost/config.hpp> #include <type_traits> #include <cstdint> #include <cstring> namespace boost { namespace hash2 { namespace detail { // little endian BOOST_FORCEINLINE BOOST_CXX14_CONSTEXPR void write16le( unsigned char* p, std::uint16_t v ) noexcept { if( !detail::is_constant_evaluated() && endian::native == endian::little ) { std::memcpy( p, &v, sizeof(v) ); } else { p[0] = static_cast<unsigned char>( v & 0xFF ); p[1] = static_cast<unsigned char>( ( v >> 8 ) & 0xFF ); } } BOOST_FORCEINLINE BOOST_CXX14_CONSTEXPR void write32le( unsigned char* p, std::uint32_t v ) noexcept { if( !detail::is_constant_evaluated() && endian::native == endian::little ) { std::memcpy( p, &v, sizeof(v) ); } else { p[0] = static_cast<unsigned char>( v & 0xFF ); p[1] = static_cast<unsigned char>( ( v >> 8 ) & 0xFF ); p[2] = static_cast<unsigned char>( ( v >> 16 ) & 0xFF ); p[3] = static_cast<unsigned char>( ( v >> 24 ) & 0xFF ); } } BOOST_FORCEINLINE BOOST_CXX14_CONSTEXPR void write64le( unsigned char* p, std::uint64_t v ) noexcept { if( !detail::is_constant_evaluated() && endian::native == endian::little ) { std::memcpy( p, &v, sizeof(v) ); } else { p[0] = static_cast<unsigned char>( v & 0xFF ); p[1] = static_cast<unsigned char>( ( v >> 8 ) & 0xFF ); p[2] = static_cast<unsigned char>( ( v >> 16 ) & 0xFF ); p[3] = static_cast<unsigned char>( ( v >> 24 ) & 0xFF ); p[4] = static_cast<unsigned char>( ( v >> 32 ) & 0xFF ); p[5] = static_cast<unsigned char>( ( v >> 40 ) & 0xFF ); p[6] = static_cast<unsigned char>( ( v >> 48 ) & 0xFF ); p[7] = static_cast<unsigned char>( ( v >> 56 ) & 0xFF ); } } // big endian BOOST_FORCEINLINE BOOST_CXX14_CONSTEXPR void write16be( unsigned char* p, std::uint16_t v ) noexcept { p[0] = static_cast<unsigned char>( ( v >> 8 ) & 0xFF ); p[1] = static_cast<unsigned char>( v & 0xFF ); } BOOST_FORCEINLINE BOOST_CXX14_CONSTEXPR void write32be( unsigned char* p, std::uint32_t v ) noexcept { p[0] = static_cast<unsigned char>( ( v >> 24 ) & 0xFF ); p[1] = static_cast<unsigned char>( ( v >> 16 ) & 0xFF ); p[2] = static_cast<unsigned char>( ( v >> 8 ) & 0xFF ); p[3] = static_cast<unsigned char>( v & 0xFF ); } BOOST_FORCEINLINE BOOST_CXX14_CONSTEXPR void write64be( unsigned char* p, std::uint64_t v ) noexcept { p[0] = static_cast<unsigned char>( ( v >> 56 ) & 0xFF ); p[1] = static_cast<unsigned char>( ( v >> 48 ) & 0xFF ); p[2] = static_cast<unsigned char>( ( v >> 40 ) & 0xFF ); p[3] = static_cast<unsigned char>( ( v >> 32 ) & 0xFF ); p[4] = static_cast<unsigned char>( ( v >> 24 ) & 0xFF ); p[5] = static_cast<unsigned char>( ( v >> 16 ) & 0xFF ); p[6] = static_cast<unsigned char>( ( v >> 8 ) & 0xFF ); p[7] = static_cast<unsigned char>( v & 0xFF ); } // any endian // template<class T> BOOST_FORCEINLINE BOOST_CXX14_CONSTEXPR void write( T v, endian e, unsigned char (&w)[ sizeof(T) ] ) noexcept; template<class T> BOOST_FORCEINLINE BOOST_CXX14_CONSTEXPR typename std::enable_if<std::is_integral<T>::value && sizeof(T) == 1, void>::type write( T v, endian /*e*/, unsigned char (&w)[ sizeof(T) ] ) noexcept { w[ 0 ] = static_cast<unsigned char>( v ); } template<class T> BOOST_FORCEINLINE BOOST_CXX14_CONSTEXPR typename std::enable_if<std::is_integral<T>::value && sizeof(T) == 2, void>::type write( T v, endian e, unsigned char (&w)[ sizeof(T) ] ) noexcept { if( e == endian::little ) { write16le( w, static_cast<std::uint16_t>( v ) ); } else { write16be( w, static_cast<std::uint16_t>( v ) ); } } template<class T> BOOST_FORCEINLINE BOOST_CXX14_CONSTEXPR typename std::enable_if<std::is_integral<T>::value && sizeof(T) == 4, void>::type write( T v, endian e, unsigned char (&w)[ sizeof(T) ] ) noexcept { if( e == endian::little ) { write32le( w, static_cast<std::uint32_t>( v ) ); } else { write32be( w, static_cast<std::uint32_t>( v ) ); } } template<class T> BOOST_FORCEINLINE BOOST_CXX14_CONSTEXPR typename std::enable_if<std::is_integral<T>::value && sizeof(T) == 8, void>::type write( T v, endian e, unsigned char (&w)[ sizeof(T) ] ) noexcept { if( e == endian::little ) { write64le( w, static_cast<std::uint64_t>( v ) ); } else { write64be( w, static_cast<std::uint64_t>( v ) ); } } } // namespace detail } // namespace hash2 } // namespace boost #endif // #ifndef BOOST_HASH2_DETAIL_WRITE_HPP_INCLUDED //#include <boost/hash2/detail/has_tag_invoke.hpp> #ifndef BOOST_HASH2_DETAIL_HAS_TAG_INVOKE_HPP_INCLUDED #define BOOST_HASH2_DETAIL_HAS_TAG_INVOKE_HPP_INCLUDED // Copyright 2024 Peter Dimov. // Distributed under the Boost Software License, Version 1.0. // https://www.boost.org/LICENSE_1_0.txt //#include <boost/hash2/endian.hpp> #include <type_traits> #include <cstdint> #include <cstddef> namespace boost { namespace hash2 { struct hash_append_tag; namespace detail { struct hash_archetype { using result_type = std::uint64_t; hash_archetype(); explicit hash_archetype( std::uint64_t ); hash_archetype( unsigned char const*, std::size_t ); void update( void const*, std::size_t ); result_type result(); }; struct flavor_archetype { using size_type = std::uint32_t; static constexpr auto byte_order = endian::native; }; template<class T, class En = void> struct has_tag_invoke: std::false_type { }; template<class T> struct has_tag_invoke<T, decltype( tag_invoke( std::declval<hash_append_tag const&>(), std::declval<hash_archetype&>(), std::declval<flavor_archetype const&>(), std::declval<T const&>() ), void())>: std::true_type { }; } // namespace detail } // namespace hash2 } // namespace boost #endif // #ifndef BOOST_HASH2_DETAIL_HAS_TAG_INVOKE_HPP_INCLUDED // #include <boost/hash2/hash_append.hpp> #ifndef BOOST_HASH2_HASH_APPEND_HPP_INCLUDED #define BOOST_HASH2_HASH_APPEND_HPP_INCLUDED // Copyright 2017, 2018, 2023, 2024 Peter Dimov. // Distributed under the Boost Software License, Version 1.0. // https://www.boost.org/LICENSE_1_0.txt // // Based on // // Types Don't Know # // Howard E. Hinnant, Vinnie Falco, John Bytheway // http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n3980.html //#include <boost/hash2/hash_append_fwd.hpp> //#include <boost/hash2/is_contiguously_hashable.hpp> //#include <boost/hash2/has_constant_size.hpp> //#include <boost/hash2/get_integral_result.hpp> //#include <boost/hash2/flavor.hpp> //#include <boost/hash2/detail/is_constant_evaluated.hpp> //#include <boost/hash2/detail/bit_cast.hpp> //#include <boost/hash2/detail/write.hpp> //#include <boost/hash2/detail/has_tag_invoke.hpp> #include <boost/container_hash/is_range.hpp> #include <boost/container_hash/is_contiguous_range.hpp> #include <boost/container_hash/is_unordered_range.hpp> #include <boost/container_hash/is_tuple_like.hpp> #include <boost/container_hash/is_described_class.hpp> #include <boost/describe/bases.hpp> #include <boost/describe/members.hpp> #include <boost/mp11/algorithm.hpp> #include <boost/mp11/integer_sequence.hpp> #include <cstdint> #include <type_traits> #include <iterator> namespace boost { template<class T, std::size_t N> class array; namespace hash2 { // hash_append_range namespace detail { template<class Hash, class Flavor, class It> BOOST_CXX14_CONSTEXPR void hash_append_range_( Hash& h, Flavor const& f, It first, It last ) { for( ; first != last; ++first ) { typename std::iterator_traits<It>::value_type const& v = *first; hash2::hash_append( h, f, v ); } } template<class Hash, class Flavor> BOOST_CXX14_CONSTEXPR void hash_append_range_( Hash& h, Flavor const& /*f*/, unsigned char* first, unsigned char* last ) { h.update( first, last - first ); } template<class Hash, class Flavor> BOOST_CXX14_CONSTEXPR void hash_append_range_( Hash& h, Flavor const& /*f*/, unsigned char const* first, unsigned char const* last ) { h.update( first, last - first ); } #if defined(BOOST_NO_CXX14_CONSTEXPR) template<class Hash, class Flavor, class T> typename std::enable_if< is_contiguously_hashable<T, Flavor::byte_order>::value, void >::type hash_append_range_( Hash& h, Flavor const& /*f*/, T* first, T* last ) { h.update( first, (last - first) * sizeof(T) ); } #else template<class Hash, class Flavor, class T> BOOST_CXX14_CONSTEXPR typename std::enable_if< is_contiguously_hashable<T, Flavor::byte_order>::value, void >::type hash_append_range_( Hash& h, Flavor const& f, T* first, T* last ) { if( !detail::is_constant_evaluated() ) { h.update( first, (last - first) * sizeof(T) ); } else { for( ; first != last; ++first ) { hash2::hash_append( h, f, *first ); } } } #endif } // namespace detail template<class Hash, class Flavor = default_flavor, class It> BOOST_CXX14_CONSTEXPR void hash_append_range( Hash& h, Flavor const& f, It first, It last ) { detail::hash_append_range_( h, f, first, last ); } // hash_append_size template<class Hash, class Flavor = default_flavor, class T> BOOST_CXX14_CONSTEXPR void hash_append_size( Hash& h, Flavor const& f, T const& v ) { hash2::hash_append( h, f, static_cast<typename Flavor::size_type>( v ) ); } // hash_append_sized_range namespace detail { template<class Hash, class Flavor, class It> void BOOST_CXX14_CONSTEXPR hash_append_sized_range_( Hash& h, Flavor const& f, It first, It last, std::input_iterator_tag ) { typename std::iterator_traits<It>::difference_type m = 0; for( ; first != last; ++first, ++m ) { hash2::hash_append( h, f, *first ); } hash2::hash_append_size( h, f, m ); } template<class Hash, class Flavor, class It> BOOST_CXX14_CONSTEXPR void hash_append_sized_range_( Hash& h, Flavor const& f, It first, It last, std::random_access_iterator_tag ) { hash2::hash_append_range( h, f, first, last ); hash2::hash_append_size( h, f, last - first ); } } // namespace detail template<class Hash, class Flavor = default_flavor, class It> BOOST_CXX14_CONSTEXPR void hash_append_sized_range( Hash& h, Flavor const& f, It first, It last ) { detail::hash_append_sized_range_( h, f, first, last, typename std::iterator_traits<It>::iterator_category() ); } // hash_append_unordered_range template<class Hash, class Flavor = default_flavor, class It> BOOST_CXX14_CONSTEXPR void hash_append_unordered_range( Hash& h, Flavor const& f, It first, It last ) { typename std::iterator_traits<It>::difference_type m = 0; std::uint64_t w = 0; for( ; first != last; ++first, ++m ) { Hash h2( h ); hash2::hash_append( h2, f, *first ); w += hash2::get_integral_result<std::uint64_t>( h2.result() ); } hash2::hash_append( h, f, w ); hash2::hash_append_size( h, f, m ); } // do_hash_append struct hash_append_tag { }; namespace detail { // integral types template<class Hash, class Flavor, class T> BOOST_CXX14_CONSTEXPR typename std::enable_if< std::is_integral<T>::value, void >::type do_hash_append( Hash& h, Flavor const& /*f*/, T const& v ) { constexpr auto N = sizeof(T); unsigned char tmp[ N ] = {}; detail::write( v, Flavor::byte_order, tmp ); h.update( tmp, N ); } // enum types template<class Hash, class Flavor, class T> BOOST_CXX14_CONSTEXPR typename std::enable_if< std::is_enum<T>::value, void >::type do_hash_append( Hash& h, Flavor const& f, T const& v ) { hash2::hash_append( h, f, static_cast<typename std::underlying_type<T>::type>( v ) ); } // pointer types // never constexpr template<class Hash, class Flavor, class T> typename std::enable_if< std::is_pointer<T>::value, void >::type do_hash_append( Hash& h, Flavor const& f, T const& v ) { hash2::hash_append( h, f, reinterpret_cast<std::uintptr_t>( v ) ); } // floating point template<class Hash, class Flavor, class T> BOOST_CXX14_CONSTEXPR typename std::enable_if< std::is_floating_point<T>::value && sizeof(T) == 4, void >::type do_hash_append( Hash& h, Flavor const& f, T const& v ) { hash2::hash_append( h, f, detail::bit_cast<std::uint32_t>( v + 0 ) ); } template<class Hash, class Flavor, class T> BOOST_CXX14_CONSTEXPR typename std::enable_if< std::is_floating_point<T>::value && sizeof(T) == 8, void >::type do_hash_append( Hash& h, Flavor const& f, T const& v ) { hash2::hash_append( h, f, detail::bit_cast<std::uint64_t>( v + 0 ) ); } // std::nullptr_t // not constexpr for consistency with T* template<class Hash, class Flavor, class T> typename std::enable_if< std::is_same<T, std::nullptr_t>::value, void >::type do_hash_append( Hash& h, Flavor const& f, T const& v ) { hash2::hash_append( h, f, static_cast<void*>( v ) ); } // C arrays template<class Hash, class Flavor, class T, std::size_t N> BOOST_CXX14_CONSTEXPR void do_hash_append( Hash& h, Flavor const& f, T const (&v)[ N ] ) { hash2::hash_append_range( h, f, v + 0, v + N ); } // contiguous containers and ranges, w/ size template<class Hash, class Flavor, class T> BOOST_CXX14_CONSTEXPR typename std::enable_if< container_hash::is_contiguous_range<T>::value && !has_constant_size<T>::value, void >::type do_hash_append( Hash& h, Flavor const& f, T const& v ) { hash2::hash_append_range( h, f, v.data(), v.data() + v.size() ); hash2::hash_append_size( h, f, v.size() ); } // containers and ranges, w/ size template<class Hash, class Flavor, class T> BOOST_CXX14_CONSTEXPR typename std::enable_if< container_hash::is_range<T>::value && !has_constant_size<T>::value && !container_hash::is_contiguous_range<T>::value && !container_hash::is_unordered_range<T>::value, void >::type do_hash_append( Hash& h, Flavor const& f, T const& v ) { hash2::hash_append_sized_range( h, f, v.begin(), v.end() ); } #if defined(BOOST_MSVC) # pragma warning(push) # pragma warning(disable: 4702) // unreachable code #endif // constant size contiguous containers and ranges (std::array, boost::array, hash2::digest) template<class Hash, class Flavor, class T> BOOST_CXX14_CONSTEXPR typename std::enable_if< container_hash::is_contiguous_range<T>::value && has_constant_size<T>::value, void >::type do_hash_append( Hash& h, Flavor const& f, T const& v ) { if( v.size() == 0 ) { // A hash_append call must always result in a call to Hash::update hash2::hash_append( h, f, '\x00' ); } else { // std::array<>::data() is only constexpr in C++17; boost::array<>::operator[] isn't constexpr hash2::hash_append_range( h, f, &v.front(), &v.front() + v.size() ); } } // constant size non-contiguous containers and ranges template<class Hash, class Flavor, class T> BOOST_CXX14_CONSTEXPR typename std::enable_if< container_hash::is_range<T>::value && has_constant_size<T>::value && !container_hash::is_contiguous_range<T>::value, void >::type do_hash_append( Hash& h, Flavor const& f, T const& v ) { if( v.begin() == v.end() ) { // A hash_append call must always result in a call to Hash::update hash2::hash_append( h, f, '\x00' ); } else { hash2::hash_append_range( h, f, v.begin(), v.end() ); } } #if defined(BOOST_MSVC) # pragma warning(pop) #endif // unordered containers (is_unordered_range implies is_range) template<class Hash, class Flavor, class T> BOOST_CXX14_CONSTEXPR typename std::enable_if< container_hash::is_unordered_range<T>::value, void >::type do_hash_append( Hash& h, Flavor const& f, T const& v ) { hash2::hash_append_unordered_range( h, f, v.begin(), v.end() ); } // tuple-likes template<class Hash, class Flavor, class T, std::size_t... J> BOOST_CXX14_CONSTEXPR void hash_append_tuple( Hash& h, Flavor const& f, T const& v, mp11::integer_sequence<std::size_t, J...> ) { using std::get; int a[] = { ((void)hash2::hash_append( h, f, get<J>(v) ), 0)... }; (void)a; } template<class Hash, class Flavor, class T> BOOST_CXX14_CONSTEXPR void hash_append_tuple( Hash& h, Flavor const& f, T const& /*v*/, mp11::integer_sequence<std::size_t> ) { // A hash_append call must always result in a call to Hash::update hash2::hash_append( h, f, '\x00' ); } template<class Hash, class Flavor, class T> BOOST_CXX14_CONSTEXPR typename std::enable_if< !container_hash::is_range<T>::value && container_hash::is_tuple_like<T>::value, void >::type do_hash_append( Hash& h, Flavor const& f, T const& v ) { using Seq = mp11::make_index_sequence<std::tuple_size<T>::value>; detail::hash_append_tuple( h, f, v, Seq() ); } // described classes #if defined(BOOST_DESCRIBE_CXX14) #if defined(_MSC_VER) && _MSC_VER == 1900 # pragma warning(push) # pragma warning(disable: 4100) // unreferenced formal parameter #endif template<class Hash, class Flavor, class T> BOOST_CXX14_CONSTEXPR typename std::enable_if< container_hash::is_described_class<T>::value, void >::type do_hash_append( Hash& h, Flavor const& f, T const& v ) { static_assert( !std::is_union<T>::value, "Described unions are not supported" ); std::size_t r = 0; using Bd = describe::describe_bases<T, describe::mod_any_access>; mp11::mp_for_each<Bd>([&](auto D){ using B = typename decltype(D)::type; hash2::hash_append( h, f, (B const&)v ); ++r; }); using Md = describe::describe_members<T, describe::mod_any_access>; mp11::mp_for_each<Md>([&](auto D){ hash2::hash_append( h, f, v.*D.pointer ); ++r; }); // A hash_append call must always result in a call to Hash::update if( r == 0 ) { hash2::hash_append( h, f, '\x00' ); } } #if defined(_MSC_VER) && _MSC_VER == 1900 # pragma warning(pop) #endif #endif // defined(BOOST_DESCRIBE_CXX14) // classes with tag_invoke template<class Hash, class Flavor, class T> BOOST_CXX14_CONSTEXPR typename std::enable_if< detail::has_tag_invoke<T>::value, void >::type do_hash_append( Hash& h, Flavor const& f, T const& v ) { tag_invoke( hash_append_tag(), h, f, v ); } } // namespace detail // hash_append template<class Hash, class Flavor = default_flavor, class T> BOOST_CXX14_CONSTEXPR void hash_append( Hash& h, Flavor const& f, T const& v ) { if( !detail::is_constant_evaluated() && is_contiguously_hashable<T, Flavor::byte_order>::value ) { h.update( &v, sizeof(T) ); } else { detail::do_hash_append( h, f, v ); } } } // namespace hash2 } // namespace boost #endif // #ifndef BOOST_HASH2_HASH_APPEND_HPP_INCLUDED //#include <boost/hash2/detail/memcpy.hpp> #ifndef BOOST_HASH2_DETAIL_MEMCPY_HPP_INCLUDED #define BOOST_HASH2_DETAIL_MEMCPY_HPP_INCLUDED // Copyright 2024 Peter Dimov // Distributed under the Boost Software License, Version 1.0. // https://www.boost.org/LICENSE_1_0.txt //#include <boost/hash2/detail/is_constant_evaluated.hpp> #include <boost/config.hpp> #include <cstring> namespace boost { namespace hash2 { namespace detail { #if defined(BOOST_NO_CXX14_CONSTEXPR) BOOST_FORCEINLINE void memcpy( unsigned char* d, unsigned char const* s, std::size_t n ) noexcept { std::memcpy( d, s, n ); } #else constexpr void memcpy( unsigned char* d, unsigned char const* s, std::size_t n ) noexcept { if( !detail::is_constant_evaluated() ) { std::memcpy( d, s, n ); } else { for( std::size_t i = 0; i < n; ++i ) { d[ i ] = s[ i ]; } } } #endif } // namespace detail } // namespace hash2 } // namespace boost #endif // #ifndef BOOST_HASH2_DETAIL_MEMCPY_HPP_INCLUDED //#include <boost/hash2/detail/memcmp.hpp> #ifndef BOOST_HASH2_DETAIL_MEMCMP_HPP_INCLUDED #define BOOST_HASH2_DETAIL_MEMCMP_HPP_INCLUDED // Copyright 2024 Peter Dimov // Distributed under the Boost Software License, Version 1.0. // https://www.boost.org/LICENSE_1_0.txt //#include <boost/hash2/detail/is_constant_evaluated.hpp> #include <boost/config.hpp> #include <cstring> namespace boost { namespace hash2 { namespace detail { #if defined(BOOST_NO_CXX14_CONSTEXPR) BOOST_FORCEINLINE int memcmp( unsigned char const* p, unsigned char const* q, std::size_t n ) noexcept { return std::memcmp( p, q, n ); } #else constexpr int memcmp( unsigned char const* p, unsigned char const* q, std::size_t n ) noexcept { if( !detail::is_constant_evaluated() ) { return std::memcmp( p, q, n ); } else { for( std::size_t i = 0; i < n; ++i ) { if( p[ i ] != q[ i ] ) return p[ i ] - q[ i ]; } return 0; } } #endif } // namespace detail } // namespace hash2 } // namespace boost #endif // #ifndef BOOST_HASH2_DETAIL_MEMCMP_HPP_INCLUDED //#include <boost/hash2/digest.hpp> #ifndef BOOST_HASH2_DIGEST_HPP_INCLUDED #define BOOST_HASH2_DIGEST_HPP_INCLUDED // Copyright 2024 Peter Dimov // Distributed under the Boost Software License, Version 1.0. // https://www.boost.org/LICENSE_1_0.txt //#include <boost/hash2/detail/memcpy.hpp> //#include <boost/hash2/detail/memcmp.hpp> #include <boost/assert.hpp> #include <boost/config.hpp> #include <string> #include <iosfwd> #include <cstddef> namespace boost { namespace hash2 { template<std::size_t N> class digest { private: unsigned char data_[ N ] = {}; public: // constructors digest() = default; BOOST_CXX14_CONSTEXPR digest( unsigned char const (&v)[ N ] ) noexcept { detail::memcpy( data_, v, N ); } // iteration using value_type = unsigned char; using reference = unsigned char&; using const_reference = unsigned char const&; using iterator = unsigned char*; using const_iterator = unsigned char const*; using size_type = std::size_t; using difference_type = std::ptrdiff_t; BOOST_CXX14_CONSTEXPR iterator begin() noexcept { return data_; } constexpr const_iterator begin() const noexcept { return data_; } BOOST_CXX14_CONSTEXPR iterator end() noexcept { return data_ + N; } constexpr const_iterator end() const noexcept { return data_ + N; } // data, size BOOST_CXX14_CONSTEXPR unsigned char* data() noexcept { return data_; } constexpr unsigned char const* data() const noexcept { return data_; } constexpr size_type size() const noexcept { return N; } constexpr size_type max_size() const noexcept { return N; } // element access BOOST_CXX14_CONSTEXPR reference operator[]( std::size_t i ) { BOOST_ASSERT( i < N ); return data_[ i ]; } BOOST_CXX14_CONSTEXPR const_reference operator[]( std::size_t i ) const { BOOST_ASSERT( i < N ); return data_[ i ]; } BOOST_CXX14_CONSTEXPR reference front() noexcept { return data_[ 0 ]; } constexpr const_reference front() const noexcept { return data_[ 0 ]; } BOOST_CXX14_CONSTEXPR reference back() noexcept { return data_[ N-1 ]; } constexpr const_reference back() const noexcept { return data_[ N-1 ]; } }; // comparisons template<std::size_t N> BOOST_CXX14_CONSTEXPR bool operator==( digest<N> const& a, digest<N> const& b ) noexcept { return detail::memcmp( a.data(), b.data(), N ) == 0; } template<std::size_t N> BOOST_CXX14_CONSTEXPR bool operator!=( digest<N> const& a, digest<N> const& b ) noexcept { return !( a == b ); } // to_chars template<std::size_t N> BOOST_CXX14_CONSTEXPR char* to_chars( digest<N> const& v, char* first, char* last ) noexcept { if( last - first < static_cast<std::ptrdiff_t>( 2 * N ) ) { return nullptr; } constexpr char digits[] = "0123456789abcdef"; for( std::size_t i = 0; i < N; ++i ) { first[ i*2 + 0 ] = digits[ v[i] >> 4 ]; first[ i*2 + 1 ] = digits[ v[i] & 0x0F ]; } return first + N * 2; } template<std::size_t N, std::size_t M> BOOST_CXX14_CONSTEXPR void to_chars( digest<N> const& v, char (&w)[ M ] ) noexcept { static_assert( M >= 2 * N + 1, "Output buffer not large enough" ); *to_chars( v, w, w + M ) = 0; } // operator<< template<std::size_t N> std::ostream& operator<<( std::ostream& os, digest<N> const& v ) { char tmp[ 2*N+1 ]; to_chars( v, tmp ); os << tmp; return os; } // to_string template<std::size_t N> std::string to_string( digest<N> const& v ) { char tmp[ 2*N+1 ]; to_chars( v, tmp ); return std::string( tmp, 2*N ); } } // namespace hash2 } // namespace boost #endif // #ifndef BOOST_HASH2_DIGEST_HPP_INCLUDED //#include <boost/hash2/detail/read.hpp> //#include <boost/hash2/detail/write.hpp> #include <https://raw.githubusercontent.com/pdimov/hash2/refs/heads/develop/include/boost/hash2/detail/rot.hpp> //#include <boost/hash2/detail/memset.hpp> #ifndef BOOST_HASH2_DETAIL_MEMSET_HPP_INCLUDED #define BOOST_HASH2_DETAIL_MEMSET_HPP_INCLUDED // Copyright 2024 Peter Dimov // Distributed under the Boost Software License, Version 1.0. // https://www.boost.org/LICENSE_1_0.txt //#include <boost/hash2/detail/is_constant_evaluated.hpp> #include <boost/config.hpp> #include <cstring> namespace boost { namespace hash2 { namespace detail { #if defined(BOOST_NO_CXX14_CONSTEXPR) BOOST_FORCEINLINE void memset( unsigned char* p, unsigned char v, std::size_t n ) noexcept { std::memset( p, v, n ); } #else constexpr void memset( unsigned char* p, unsigned char v, std::size_t n ) noexcept { if( !detail::is_constant_evaluated() ) { std::memset( p, v, n ); } else { for( std::size_t i = 0; i < n; ++i ) { p[ i ] = v; } } } #endif } // namespace detail } // namespace hash2 } // namespace boost #endif // #ifndef BOOST_HASH2_DETAIL_MEMSET_HPP_INCLUDED // #include <boost/hash2/ripemd.hpp> #ifndef BOOST_HASH2_RIPEMD_HPP_INCLUDED #define BOOST_HASH2_RIPEMD_HPP_INCLUDED // Copyright 2017, 2018 Peter Dimov // Copyright 2024 Christian Mazakas // Distributed under the Boost Software License, Version 1.0. // https://www.boost.org/LICENSE_1_0.txt // // RIPEMD-160 message digest algorithm, https://www.esat.kuleuven.be/cosic/publications/article-317.pdf // https://homes.esat.kuleuven.be/~bosselae/ripemd/rmd160.c // https://homes.esat.kuleuven.be/~bosselae/ripemd/rmd160.h // RIPEMD-128 message digest algorithm, https://homes.esat.kuleuven.be/~bosselae/ripemd/rmd128.txt // https://homes.esat.kuleuven.be/~bosselae/ripemd/rmd128.c // https://homes.esat.kuleuven.be/~bosselae/ripemd/rmd128.h //#include <boost/hash2/hmac.hpp> //#include <boost/hash2/digest.hpp> //#include <boost/hash2/detail/read.hpp> //#include <boost/hash2/detail/write.hpp> //#include <boost/hash2/detail/rot.hpp> //#include <boost/hash2/detail/memset.hpp> #include <boost/assert.hpp> #include <boost/config.hpp> #include <cstdint> #include <cstring> #include <cstddef> namespace boost { namespace hash2 { class ripemd_128 { private: std::uint32_t state_[ 4 ] = { 0x67452301u, 0xEFCDAB89u, 0x98BADCFEu, 0x10325476u }; static constexpr int N = 64; unsigned char buffer_[ N ] = {}; std::size_t m_ = 0; // == n_ % N std::uint64_t n_ = 0; private: static BOOST_FORCEINLINE BOOST_CXX14_CONSTEXPR std::uint32_t F1( std::uint32_t x, std::uint32_t y, std::uint32_t z) { return x ^ y ^ z; } static BOOST_FORCEINLINE BOOST_CXX14_CONSTEXPR std::uint32_t F2( std::uint32_t x, std::uint32_t y, std::uint32_t z) { return (x & y) | (~x & z); } static BOOST_FORCEINLINE BOOST_CXX14_CONSTEXPR std::uint32_t F3( std::uint32_t x, std::uint32_t y, std::uint32_t z) { return (x | ~y) ^ z; } static BOOST_FORCEINLINE BOOST_CXX14_CONSTEXPR std::uint32_t F4( std::uint32_t x, std::uint32_t y, std::uint32_t z) { return (x & z) | (y & ~z); } static BOOST_FORCEINLINE BOOST_CXX14_CONSTEXPR void R1( std::uint32_t & a, std::uint32_t b, std::uint32_t & c, std::uint32_t d, std::uint32_t x, std::uint32_t s ) { a += F1(b, c, d) + x; a = detail::rotl(a, s); } static BOOST_FORCEINLINE BOOST_CXX14_CONSTEXPR void R2( std::uint32_t & a, std::uint32_t b, std::uint32_t & c, std::uint32_t d, std::uint32_t x, std::uint32_t s ) { a += F2(b, c, d) + x + 0x5a827999u; a = detail::rotl(a, s); } static BOOST_FORCEINLINE BOOST_CXX14_CONSTEXPR void R3( std::uint32_t & a, std::uint32_t b, std::uint32_t & c, std::uint32_t d, std::uint32_t x, std::uint32_t s ) { a += F3(b, c, d) + x + 0x6ed9eba1u; a = detail::rotl(a, s); } static BOOST_FORCEINLINE BOOST_CXX14_CONSTEXPR void R4( std::uint32_t & a, std::uint32_t b, std::uint32_t & c, std::uint32_t d, std::uint32_t x, std::uint32_t s ) { a += F4(b, c, d) + x + 0x8f1bbcdcu; a = detail::rotl(a, s); } static BOOST_FORCEINLINE BOOST_CXX14_CONSTEXPR void RR1( std::uint32_t & a, std::uint32_t b, std::uint32_t & c, std::uint32_t d, std::uint32_t x, std::uint32_t s ) { a += F4(b, c, d) + x + 0x50a28be6u; a = detail::rotl(a, s); } static BOOST_FORCEINLINE BOOST_CXX14_CONSTEXPR void RR2( std::uint32_t & a, std::uint32_t b, std::uint32_t & c, std::uint32_t d, std::uint32_t x, std::uint32_t s ) { a += F3(b, c, d) + x + 0x5c4dd124u; a = detail::rotl(a, s); } static BOOST_FORCEINLINE BOOST_CXX14_CONSTEXPR void RR3( std::uint32_t & a, std::uint32_t b, std::uint32_t & c, std::uint32_t d, std::uint32_t x, std::uint32_t s ) { a += F2(b, c, d) + x + 0x6d703ef3u; a = detail::rotl(a, s); } static BOOST_FORCEINLINE BOOST_CXX14_CONSTEXPR void RR4( std::uint32_t & a, std::uint32_t b, std::uint32_t & c, std::uint32_t d, std::uint32_t x, std::uint32_t s ) { a += F1(b, c, d) + x; a = detail::rotl(a, s); } BOOST_CXX14_CONSTEXPR void transform( unsigned char const block[ 64 ] ) { std::uint32_t aa = state_[ 0 ]; std::uint32_t bb = state_[ 1 ]; std::uint32_t cc = state_[ 2 ]; std::uint32_t dd = state_[ 3 ]; std::uint32_t aaa = state_[ 0 ]; std::uint32_t bbb = state_[ 1 ]; std::uint32_t ccc = state_[ 2 ]; std::uint32_t ddd = state_[ 3 ]; std::uint32_t X[ 16 ] = {}; for( int i = 0; i < 16; ++i ) { X[ i ] = detail::read32le( block + i * 4 ); } // A B C D R1(aa, bb, cc, dd, X[ 0], 11); R1(dd, aa, bb, cc, X[ 1], 14); R1(cc, dd, aa, bb, X[ 2], 15); R1(bb, cc, dd, aa, X[ 3], 12); R1(aa, bb, cc, dd, X[ 4], 5); R1(dd, aa, bb, cc, X[ 5], 8); R1(cc, dd, aa, bb, X[ 6], 7); R1(bb, cc, dd, aa, X[ 7], 9); R1(aa, bb, cc, dd, X[ 8], 11); R1(dd, aa, bb, cc, X[ 9], 13); R1(cc, dd, aa, bb, X[10], 14); R1(bb, cc, dd, aa, X[11], 15); R1(aa, bb, cc, dd, X[12], 6); R1(dd, aa, bb, cc, X[13], 7); R1(cc, dd, aa, bb, X[14], 9); R1(bb, cc, dd, aa, X[15], 8); RR1(aaa, bbb, ccc, ddd, X[ 5], 8); RR1(ddd, aaa, bbb, ccc, X[14], 9); RR1(ccc, ddd, aaa, bbb, X[ 7], 9); RR1(bbb, ccc, ddd, aaa, X[ 0], 11); RR1(aaa, bbb, ccc, ddd, X[ 9], 13); RR1(ddd, aaa, bbb, ccc, X[ 2], 15); RR1(ccc, ddd, aaa, bbb, X[11], 15); RR1(bbb, ccc, ddd, aaa, X[ 4], 5); RR1(aaa, bbb, ccc, ddd, X[13], 7); RR1(ddd, aaa, bbb, ccc, X[ 6], 7); RR1(ccc, ddd, aaa, bbb, X[15], 8); RR1(bbb, ccc, ddd, aaa, X[ 8], 11); RR1(aaa, bbb, ccc, ddd, X[ 1], 14); RR1(ddd, aaa, bbb, ccc, X[10], 14); RR1(ccc, ddd, aaa, bbb, X[ 3], 12); RR1(bbb, ccc, ddd, aaa, X[12], 6); R2(aa, bb, cc, dd, X[ 7], 7); R2(dd, aa, bb, cc, X[ 4], 6); R2(cc, dd, aa, bb, X[13], 8); R2(bb, cc, dd, aa, X[ 1], 13); R2(aa, bb, cc, dd, X[10], 11); R2(dd, aa, bb, cc, X[ 6], 9); R2(cc, dd, aa, bb, X[15], 7); R2(bb, cc, dd, aa, X[ 3], 15); R2(aa, bb, cc, dd, X[12], 7); R2(dd, aa, bb, cc, X[ 0], 12); R2(cc, dd, aa, bb, X[ 9], 15); R2(bb, cc, dd, aa, X[ 5], 9); R2(aa, bb, cc, dd, X[ 2], 11); R2(dd, aa, bb, cc, X[14], 7); R2(cc, dd, aa, bb, X[11], 13); R2(bb, cc, dd, aa, X[ 8], 12); RR2(aaa, bbb, ccc, ddd, X[ 6], 9); RR2(ddd, aaa, bbb, ccc, X[11], 13); RR2(ccc, ddd, aaa, bbb, X[ 3], 15); RR2(bbb, ccc, ddd, aaa, X[ 7], 7); RR2(aaa, bbb, ccc, ddd, X[ 0], 12); RR2(ddd, aaa, bbb, ccc, X[13], 8); RR2(ccc, ddd, aaa, bbb, X[ 5], 9); RR2(bbb, ccc, ddd, aaa, X[10], 11); RR2(aaa, bbb, ccc, ddd, X[14], 7); RR2(ddd, aaa, bbb, ccc, X[15], 7); RR2(ccc, ddd, aaa, bbb, X[ 8], 12); RR2(bbb, ccc, ddd, aaa, X[12], 7); RR2(aaa, bbb, ccc, ddd, X[ 4], 6); RR2(ddd, aaa, bbb, ccc, X[ 9], 15); RR2(ccc, ddd, aaa, bbb, X[ 1], 13); RR2(bbb, ccc, ddd, aaa, X[ 2], 11); R3(aa, bb, cc, dd, X[ 3], 11); R3(dd, aa, bb, cc, X[10], 13); R3(cc, dd, aa, bb, X[14], 6); R3(bb, cc, dd, aa, X[ 4], 7); R3(aa, bb, cc, dd, X[ 9], 14); R3(dd, aa, bb, cc, X[15], 9); R3(cc, dd, aa, bb, X[ 8], 13); R3(bb, cc, dd, aa, X[ 1], 15); R3(aa, bb, cc, dd, X[ 2], 14); R3(dd, aa, bb, cc, X[ 7], 8); R3(cc, dd, aa, bb, X[ 0], 13); R3(bb, cc, dd, aa, X[ 6], 6); R3(aa, bb, cc, dd, X[13], 5); R3(dd, aa, bb, cc, X[11], 12); R3(cc, dd, aa, bb, X[ 5], 7); R3(bb, cc, dd, aa, X[12], 5); RR3(aaa, bbb, ccc, ddd, X[15], 9); RR3(ddd, aaa, bbb, ccc, X[ 5], 7); RR3(ccc, ddd, aaa, bbb, X[ 1], 15); RR3(bbb, ccc, ddd, aaa, X[ 3], 11); RR3(aaa, bbb, ccc, ddd, X[ 7], 8); RR3(ddd, aaa, bbb, ccc, X[14], 6); RR3(ccc, ddd, aaa, bbb, X[ 6], 6); RR3(bbb, ccc, ddd, aaa, X[ 9], 14); RR3(aaa, bbb, ccc, ddd, X[11], 12); RR3(ddd, aaa, bbb, ccc, X[ 8], 13); RR3(ccc, ddd, aaa, bbb, X[12], 5); RR3(bbb, ccc, ddd, aaa, X[ 2], 14); RR3(aaa, bbb, ccc, ddd, X[10], 13); RR3(ddd, aaa, bbb, ccc, X[ 0], 13); RR3(ccc, ddd, aaa, bbb, X[ 4], 7); RR3(bbb, ccc, ddd, aaa, X[13], 5); R4(aa, bb, cc, dd, X[ 1], 11); R4(dd, aa, bb, cc, X[ 9], 12); R4(cc, dd, aa, bb, X[11], 14); R4(bb, cc, dd, aa, X[10], 15); R4(aa, bb, cc, dd, X[ 0], 14); R4(dd, aa, bb, cc, X[ 8], 15); R4(cc, dd, aa, bb, X[12], 9); R4(bb, cc, dd, aa, X[ 4], 8); R4(aa, bb, cc, dd, X[13], 9); R4(dd, aa, bb, cc, X[ 3], 14); R4(cc, dd, aa, bb, X[ 7], 5); R4(bb, cc, dd, aa, X[15], 6); R4(aa, bb, cc, dd, X[14], 8); R4(dd, aa, bb, cc, X[ 5], 6); R4(cc, dd, aa, bb, X[ 6], 5); R4(bb, cc, dd, aa, X[ 2], 12); RR4(aaa, bbb, ccc, ddd, X[ 8], 15); RR4(ddd, aaa, bbb, ccc, X[ 6], 5); RR4(ccc, ddd, aaa, bbb, X[ 4], 8); RR4(bbb, ccc, ddd, aaa, X[ 1], 11); RR4(aaa, bbb, ccc, ddd, X[ 3], 14); RR4(ddd, aaa, bbb, ccc, X[11], 14); RR4(ccc, ddd, aaa, bbb, X[15], 6); RR4(bbb, ccc, ddd, aaa, X[ 0], 14); RR4(aaa, bbb, ccc, ddd, X[ 5], 6); RR4(ddd, aaa, bbb, ccc, X[12], 9); RR4(ccc, ddd, aaa, bbb, X[ 2], 12); RR4(bbb, ccc, ddd, aaa, X[13], 9); RR4(aaa, bbb, ccc, ddd, X[ 9], 12); RR4(ddd, aaa, bbb, ccc, X[ 7], 5); RR4(ccc, ddd, aaa, bbb, X[10], 15); RR4(bbb, ccc, ddd, aaa, X[14], 8); ddd += cc + state_[ 1 ]; state_[ 1 ] = state_[ 2 ] + dd + aaa; state_[ 2 ] = state_[ 3 ] + aa + bbb; state_[ 3 ] = state_[ 0 ] + bb + ccc; state_[ 0 ] = ddd; } public: typedef digest<16> result_type; static constexpr int block_size = 64; ripemd_128() = default; explicit BOOST_CXX14_CONSTEXPR ripemd_128( std::uint64_t seed ) { if( seed != 0 ) { unsigned char tmp[ 8 ] = {}; detail::write64le( tmp, seed ); update( tmp, 8 ); result(); } } BOOST_CXX14_CONSTEXPR ripemd_128( unsigned char const * p, std::size_t n ) { if( n != 0 ) { update( p, n ); result(); } } BOOST_CXX14_CONSTEXPR void update( unsigned char const* p, std::size_t n ) { BOOST_ASSERT( m_ == n_ % N ); if( n == 0 ) return; n_ += n; if( m_ > 0 ) { std::size_t k = N - m_; if( n < k ) { k = n; } detail::memcpy( buffer_ + m_, p, k ); p += k; n -= k; m_ += k; if( m_ < N ) return; BOOST_ASSERT( m_ == N ); transform( buffer_ ); m_ = 0; detail::memset( buffer_, 0, N ); } BOOST_ASSERT( m_ == 0 ); while( n >= N ) { transform( p ); p += N; n -= N; } BOOST_ASSERT( n < N ); if( n > 0 ) { detail::memcpy( buffer_, p, n ); m_ = n; } BOOST_ASSERT( m_ == n_ % N ); } void update( void const * pv, std::size_t n ) { unsigned char const* p = static_cast<unsigned char const*>( pv ); update( p, n ); } BOOST_CXX14_CONSTEXPR result_type result() { BOOST_ASSERT( m_ == n_ % N ); unsigned char bits[ 8 ] = {}; detail::write64le( bits, n_ * 8 ); std::size_t k = m_ < 56? 56 - m_: 120 - m_; unsigned char padding[ 64 ] = { 0x80 }; update( padding, k ); update( bits, 8 ); BOOST_ASSERT( m_ == 0 ); result_type digest; for( int i = 0; i < 4; ++i ) { detail::write32le( &digest[ i * 4 ], state_[ i ] ); } return digest; } }; class ripemd_160 { private: std::uint32_t state_[ 5 ] = { 0x67452301u, 0xefcdab89u, 0x98badcfeu, 0x10325476u, 0xc3d2e1f0u }; static constexpr int N = 64; unsigned char buffer_[ N ] = {}; std::size_t m_ = 0; // == n_ % N std::uint64_t n_ = 0; private: static BOOST_FORCEINLINE BOOST_CXX14_CONSTEXPR std::uint32_t F1( std::uint32_t x, std::uint32_t y, std::uint32_t z) { return x ^ y ^ z; } static BOOST_FORCEINLINE BOOST_CXX14_CONSTEXPR std::uint32_t F2( std::uint32_t x, std::uint32_t y, std::uint32_t z) { return (x & y) | (~x & z); } static BOOST_FORCEINLINE BOOST_CXX14_CONSTEXPR std::uint32_t F3( std::uint32_t x, std::uint32_t y, std::uint32_t z) { return (x | ~y) ^ z; } static BOOST_FORCEINLINE BOOST_CXX14_CONSTEXPR std::uint32_t F4( std::uint32_t x, std::uint32_t y, std::uint32_t z) { return (x & z) | (y & ~z); } static BOOST_FORCEINLINE BOOST_CXX14_CONSTEXPR std::uint32_t F5( std::uint32_t x, std::uint32_t y, std::uint32_t z) { return x ^ (y | ~z); } static BOOST_FORCEINLINE BOOST_CXX14_CONSTEXPR void R1( std::uint32_t & a, std::uint32_t b, std::uint32_t & c, std::uint32_t d, std::uint32_t e, std::uint32_t x, std::uint32_t s ) { a += F1(b, c, d) + x; a = detail::rotl(a, s) + e; c = detail::rotl(c, 10); } static BOOST_FORCEINLINE BOOST_CXX14_CONSTEXPR void R2( std::uint32_t & a, std::uint32_t b, std::uint32_t & c, std::uint32_t d, std::uint32_t e, std::uint32_t x, std::uint32_t s ) { a += F2(b, c, d) + x + 0x5a827999u; a = detail::rotl(a, s) + e; c = detail::rotl(c, 10); } static BOOST_FORCEINLINE BOOST_CXX14_CONSTEXPR void R3( std::uint32_t & a, std::uint32_t b, std::uint32_t & c, std::uint32_t d, std::uint32_t e, std::uint32_t x, std::uint32_t s ) { a += F3(b, c, d) + x + 0x6ed9eba1u; a = detail::rotl(a, s) + e; c = detail::rotl(c, 10); } static BOOST_FORCEINLINE BOOST_CXX14_CONSTEXPR void R4( std::uint32_t & a, std::uint32_t b, std::uint32_t & c, std::uint32_t d, std::uint32_t e, std::uint32_t x, std::uint32_t s ) { a += F4(b, c, d) + x + 0x8f1bbcdcu; a = detail::rotl(a, s) + e; c = detail::rotl(c, 10); } static BOOST_FORCEINLINE BOOST_CXX14_CONSTEXPR void R5( std::uint32_t & a, std::uint32_t b, std::uint32_t & c, std::uint32_t d, std::uint32_t e, std::uint32_t x, std::uint32_t s ) { a += F5(b, c, d) + x + 0xa953fd4eu; a = detail::rotl(a, s) + e; c = detail::rotl(c, 10); } static BOOST_FORCEINLINE BOOST_CXX14_CONSTEXPR void RR1( std::uint32_t & a, std::uint32_t b, std::uint32_t & c, std::uint32_t d, std::uint32_t e, std::uint32_t x, std::uint32_t s ) { a += F5(b, c, d) + x + 0x50a28be6u; a = detail::rotl(a, s) + e; c = detail::rotl(c, 10); } static BOOST_FORCEINLINE BOOST_CXX14_CONSTEXPR void RR2( std::uint32_t & a, std::uint32_t b, std::uint32_t & c, std::uint32_t d, std::uint32_t e, std::uint32_t x, std::uint32_t s ) { a += F4(b, c, d) + x + 0x5c4dd124u; a = detail::rotl(a, s) + e; c = detail::rotl(c, 10); } static BOOST_FORCEINLINE BOOST_CXX14_CONSTEXPR void RR3( std::uint32_t & a, std::uint32_t b, std::uint32_t & c, std::uint32_t d, std::uint32_t e, std::uint32_t x, std::uint32_t s ) { a += F3(b, c, d) + x + 0x6d703ef3u; a = detail::rotl(a, s) + e; c = detail::rotl(c, 10); } static BOOST_FORCEINLINE BOOST_CXX14_CONSTEXPR void RR4( std::uint32_t & a, std::uint32_t b, std::uint32_t & c, std::uint32_t d, std::uint32_t e, std::uint32_t x, std::uint32_t s ) { a += F2(b, c, d) + x + 0x7a6d76e9u; a = detail::rotl(a, s) + e; c = detail::rotl(c, 10); } static BOOST_FORCEINLINE BOOST_CXX14_CONSTEXPR void RR5( std::uint32_t & a, std::uint32_t b, std::uint32_t & c, std::uint32_t d, std::uint32_t e, std::uint32_t x, std::uint32_t s ) { a += F1(b, c, d) + x; a = detail::rotl(a, s) + e; c = detail::rotl(c, 10); } BOOST_CXX14_CONSTEXPR void transform( unsigned char const block[ 64 ] ) { std::uint32_t aa = state_[ 0 ]; std::uint32_t bb = state_[ 1 ]; std::uint32_t cc = state_[ 2 ]; std::uint32_t dd = state_[ 3 ]; std::uint32_t ee = state_[ 4 ]; std::uint32_t aaa = state_[ 0 ]; std::uint32_t bbb = state_[ 1 ]; std::uint32_t ccc = state_[ 2 ]; std::uint32_t ddd = state_[ 3 ]; std::uint32_t eee = state_[ 4 ]; std::uint32_t X[ 16 ] = {}; for( int i = 0; i < 16; ++i ) { X[ i ] = detail::read32le( block + i * 4 ); } // each function mutates a and c inputs so that we can easily rotate the arguments when expanding the evaluation // of the core algorithm in the paper: // T = rotl(A + f(j, B, C, D) + X[i][r[j]] + K[j], s) // A = E // E = D // D = rotl(C, 10) // C = B // B = T // mutating A in-place as T permits us to use it as B in the next call and so on and so forth // mutating C in-place permits us to use it as D in later calls as well and so on and so forth // A B C D E R1(aa, bb, cc, dd, ee, X[ 0], 11); R1(ee, aa, bb, cc, dd, X[ 1], 14); R1(dd, ee, aa, bb, cc, X[ 2], 15); R1(cc, dd, ee, aa, bb, X[ 3], 12); R1(bb, cc, dd, ee, aa, X[ 4], 5); R1(aa, bb, cc, dd, ee, X[ 5], 8); R1(ee, aa, bb, cc, dd, X[ 6], 7); R1(dd, ee, aa, bb, cc, X[ 7], 9); R1(cc, dd, ee, aa, bb, X[ 8], 11); R1(bb, cc, dd, ee, aa, X[ 9], 13); R1(aa, bb, cc, dd, ee, X[10], 14); R1(ee, aa, bb, cc, dd, X[11], 15); R1(dd, ee, aa, bb, cc, X[12], 6); R1(cc, dd, ee, aa, bb, X[13], 7); R1(bb, cc, dd, ee, aa, X[14], 9); R1(aa, bb, cc, dd, ee, X[15], 8); RR1(aaa, bbb, ccc, ddd, eee, X[ 5], 8); RR1(eee, aaa, bbb, ccc, ddd, X[14], 9); RR1(ddd, eee, aaa, bbb, ccc, X[ 7], 9); RR1(ccc, ddd, eee, aaa, bbb, X[ 0], 11); RR1(bbb, ccc, ddd, eee, aaa, X[ 9], 13); RR1(aaa, bbb, ccc, ddd, eee, X[ 2], 15); RR1(eee, aaa, bbb, ccc, ddd, X[11], 15); RR1(ddd, eee, aaa, bbb, ccc, X[ 4], 5); RR1(ccc, ddd, eee, aaa, bbb, X[13], 7); RR1(bbb, ccc, ddd, eee, aaa, X[ 6], 7); RR1(aaa, bbb, ccc, ddd, eee, X[15], 8); RR1(eee, aaa, bbb, ccc, ddd, X[ 8], 11); RR1(ddd, eee, aaa, bbb, ccc, X[ 1], 14); RR1(ccc, ddd, eee, aaa, bbb, X[10], 14); RR1(bbb, ccc, ddd, eee, aaa, X[ 3], 12); RR1(aaa, bbb, ccc, ddd, eee, X[12], 6); R2(ee, aa, bb, cc, dd, X[ 7], 7); R2(dd, ee, aa, bb, cc, X[ 4], 6); R2(cc, dd, ee, aa, bb, X[13], 8); R2(bb, cc, dd, ee, aa, X[ 1], 13); R2(aa, bb, cc, dd, ee, X[10], 11); R2(ee, aa, bb, cc, dd, X[ 6], 9); R2(dd, ee, aa, bb, cc, X[15], 7); R2(cc, dd, ee, aa, bb, X[ 3], 15); R2(bb, cc, dd, ee, aa, X[12], 7); R2(aa, bb, cc, dd, ee, X[ 0], 12); R2(ee, aa, bb, cc, dd, X[ 9], 15); R2(dd, ee, aa, bb, cc, X[ 5], 9); R2(cc, dd, ee, aa, bb, X[ 2], 11); R2(bb, cc, dd, ee, aa, X[14], 7); R2(aa, bb, cc, dd, ee, X[11], 13); R2(ee, aa, bb, cc, dd, X[ 8], 12); RR2(eee, aaa, bbb, ccc, ddd, X[ 6], 9); RR2(ddd, eee, aaa, bbb, ccc, X[11], 13); RR2(ccc, ddd, eee, aaa, bbb, X[ 3], 15); RR2(bbb, ccc, ddd, eee, aaa, X[ 7], 7); RR2(aaa, bbb, ccc, ddd, eee, X[ 0], 12); RR2(eee, aaa, bbb, ccc, ddd, X[13], 8); RR2(ddd, eee, aaa, bbb, ccc, X[ 5], 9); RR2(ccc, ddd, eee, aaa, bbb, X[10], 11); RR2(bbb, ccc, ddd, eee, aaa, X[14], 7); RR2(aaa, bbb, ccc, ddd, eee, X[15], 7); RR2(eee, aaa, bbb, ccc, ddd, X[ 8], 12); RR2(ddd, eee, aaa, bbb, ccc, X[12], 7); RR2(ccc, ddd, eee, aaa, bbb, X[ 4], 6); RR2(bbb, ccc, ddd, eee, aaa, X[ 9], 15); RR2(aaa, bbb, ccc, ddd, eee, X[ 1], 13); RR2(eee, aaa, bbb, ccc, ddd, X[ 2], 11); R3(dd, ee, aa, bb, cc, X[ 3], 11); R3(cc, dd, ee, aa, bb, X[10], 13); R3(bb, cc, dd, ee, aa, X[14], 6); R3(aa, bb, cc, dd, ee, X[ 4], 7); R3(ee, aa, bb, cc, dd, X[ 9], 14); R3(dd, ee, aa, bb, cc, X[15], 9); R3(cc, dd, ee, aa, bb, X[ 8], 13); R3(bb, cc, dd, ee, aa, X[ 1], 15); R3(aa, bb, cc, dd, ee, X[ 2], 14); R3(ee, aa, bb, cc, dd, X[ 7], 8); R3(dd, ee, aa, bb, cc, X[ 0], 13); R3(cc, dd, ee, aa, bb, X[ 6], 6); R3(bb, cc, dd, ee, aa, X[13], 5); R3(aa, bb, cc, dd, ee, X[11], 12); R3(ee, aa, bb, cc, dd, X[ 5], 7); R3(dd, ee, aa, bb, cc, X[12], 5); RR3(ddd, eee, aaa, bbb, ccc, X[15], 9); RR3(ccc, ddd, eee, aaa, bbb, X[ 5], 7); RR3(bbb, ccc, ddd, eee, aaa, X[ 1], 15); RR3(aaa, bbb, ccc, ddd, eee, X[ 3], 11); RR3(eee, aaa, bbb, ccc, ddd, X[ 7], 8); RR3(ddd, eee, aaa, bbb, ccc, X[14], 6); RR3(ccc, ddd, eee, aaa, bbb, X[ 6], 6); RR3(bbb, ccc, ddd, eee, aaa, X[ 9], 14); RR3(aaa, bbb, ccc, ddd, eee, X[11], 12); RR3(eee, aaa, bbb, ccc, ddd, X[ 8], 13); RR3(ddd, eee, aaa, bbb, ccc, X[12], 5); RR3(ccc, ddd, eee, aaa, bbb, X[ 2], 14); RR3(bbb, ccc, ddd, eee, aaa, X[10], 13); RR3(aaa, bbb, ccc, ddd, eee, X[ 0], 13); RR3(eee, aaa, bbb, ccc, ddd, X[ 4], 7); RR3(ddd, eee, aaa, bbb, ccc, X[13], 5); R4(cc, dd, ee, aa, bb, X[ 1], 11); R4(bb, cc, dd, ee, aa, X[ 9], 12); R4(aa, bb, cc, dd, ee, X[11], 14); R4(ee, aa, bb, cc, dd, X[10], 15); R4(dd, ee, aa, bb, cc, X[ 0], 14); R4(cc, dd, ee, aa, bb, X[ 8], 15); R4(bb, cc, dd, ee, aa, X[12], 9); R4(aa, bb, cc, dd, ee, X[ 4], 8); R4(ee, aa, bb, cc, dd, X[13], 9); R4(dd, ee, aa, bb, cc, X[ 3], 14); R4(cc, dd, ee, aa, bb, X[ 7], 5); R4(bb, cc, dd, ee, aa, X[15], 6); R4(aa, bb, cc, dd, ee, X[14], 8); R4(ee, aa, bb, cc, dd, X[ 5], 6); R4(dd, ee, aa, bb, cc, X[ 6], 5); R4(cc, dd, ee, aa, bb, X[ 2], 12); RR4(ccc, ddd, eee, aaa, bbb, X[ 8], 15); RR4(bbb, ccc, ddd, eee, aaa, X[ 6], 5); RR4(aaa, bbb, ccc, ddd, eee, X[ 4], 8); RR4(eee, aaa, bbb, ccc, ddd, X[ 1], 11); RR4(ddd, eee, aaa, bbb, ccc, X[ 3], 14); RR4(ccc, ddd, eee, aaa, bbb, X[11], 14); RR4(bbb, ccc, ddd, eee, aaa, X[15], 6); RR4(aaa, bbb, ccc, ddd, eee, X[ 0], 14); RR4(eee, aaa, bbb, ccc, ddd, X[ 5], 6); RR4(ddd, eee, aaa, bbb, ccc, X[12], 9); RR4(ccc, ddd, eee, aaa, bbb, X[ 2], 12); RR4(bbb, ccc, ddd, eee, aaa, X[13], 9); RR4(aaa, bbb, ccc, ddd, eee, X[ 9], 12); RR4(eee, aaa, bbb, ccc, ddd, X[ 7], 5); RR4(ddd, eee, aaa, bbb, ccc, X[10], 15); RR4(ccc, ddd, eee, aaa, bbb, X[14], 8); R5(bb, cc, dd, ee, aa, X[ 4], 9); R5(aa, bb, cc, dd, ee, X[ 0], 15); R5(ee, aa, bb, cc, dd, X[ 5], 5); R5(dd, ee, aa, bb, cc, X[ 9], 11); R5(cc, dd, ee, aa, bb, X[ 7], 6); R5(bb, cc, dd, ee, aa, X[12], 8); R5(aa, bb, cc, dd, ee, X[ 2], 13); R5(ee, aa, bb, cc, dd, X[10], 12); R5(dd, ee, aa, bb, cc, X[14], 5); R5(cc, dd, ee, aa, bb, X[ 1], 12); R5(bb, cc, dd, ee, aa, X[ 3], 13); R5(aa, bb, cc, dd, ee, X[ 8], 14); R5(ee, aa, bb, cc, dd, X[11], 11); R5(dd, ee, aa, bb, cc, X[ 6], 8); R5(cc, dd, ee, aa, bb, X[15], 5); R5(bb, cc, dd, ee, aa, X[13], 6); RR5(bbb, ccc, ddd, eee, aaa, X[12] , 8); RR5(aaa, bbb, ccc, ddd, eee, X[15] , 5); RR5(eee, aaa, bbb, ccc, ddd, X[10] , 12); RR5(ddd, eee, aaa, bbb, ccc, X[ 4] , 9); RR5(ccc, ddd, eee, aaa, bbb, X[ 1] , 12); RR5(bbb, ccc, ddd, eee, aaa, X[ 5] , 5); RR5(aaa, bbb, ccc, ddd, eee, X[ 8] , 14); RR5(eee, aaa, bbb, ccc, ddd, X[ 7] , 6); RR5(ddd, eee, aaa, bbb, ccc, X[ 6] , 8); RR5(ccc, ddd, eee, aaa, bbb, X[ 2] , 13); RR5(bbb, ccc, ddd, eee, aaa, X[13] , 6); RR5(aaa, bbb, ccc, ddd, eee, X[14] , 5); RR5(eee, aaa, bbb, ccc, ddd, X[ 0] , 15); RR5(ddd, eee, aaa, bbb, ccc, X[ 3] , 13); RR5(ccc, ddd, eee, aaa, bbb, X[ 9] , 11); RR5(bbb, ccc, ddd, eee, aaa, X[11] , 11); ddd += cc + state_[ 1 ]; state_[ 1 ] = state_[ 2 ] + dd + eee; state_[ 2 ] = state_[ 3 ] + ee + aaa; state_[ 3 ] = state_[ 4 ] + aa + bbb; state_[ 4 ] = state_[ 0 ] + bb + ccc; state_[ 0 ] = ddd; } public: typedef digest<20> result_type; static constexpr int block_size = 64; ripemd_160() = default; explicit BOOST_CXX14_CONSTEXPR ripemd_160( std::uint64_t seed ) { if( seed != 0 ) { unsigned char tmp[ 8 ] = {}; detail::write64le( tmp, seed ); update( tmp, 8 ); result(); } } BOOST_CXX14_CONSTEXPR ripemd_160( unsigned char const * p, std::size_t n ) { if( n != 0 ) { update( p, n ); result(); } } BOOST_CXX14_CONSTEXPR void update( unsigned char const* p, std::size_t n ) { BOOST_ASSERT( m_ == n_ % N ); if( n == 0 ) return; n_ += n; if( m_ > 0 ) { std::size_t k = N - m_; if( n < k ) { k = n; } detail::memcpy( buffer_ + m_, p, k ); p += k; n -= k; m_ += k; if( m_ < N ) return; BOOST_ASSERT( m_ == N ); transform( buffer_ ); m_ = 0; detail::memset( buffer_, 0, N ); } BOOST_ASSERT( m_ == 0 ); while( n >= N ) { transform( p ); p += N; n -= N; } BOOST_ASSERT( n < N ); if( n > 0 ) { detail::memcpy( buffer_, p, n ); m_ = n; } BOOST_ASSERT( m_ == n_ % N ); } void update( void const * pv, std::size_t n ) { unsigned char const* p = static_cast<unsigned char const*>( pv ); update( p, n ); } BOOST_CXX14_CONSTEXPR result_type result() { BOOST_ASSERT( m_ == n_ % N ); unsigned char bits[ 8 ] = {}; detail::write64le( bits, n_ * 8 ); std::size_t k = m_ < 56? 56 - m_: 120 - m_; unsigned char padding[ 64 ] = { 0x80 }; update( padding, k ); update( bits, 8 ); BOOST_ASSERT( m_ == 0 ); result_type digest; for( int i = 0; i < 5; ++i ) { detail::write32le( &digest[ i * 4 ], state_[ i ] ); } return digest; } }; //using hmac_ripemd_160 = hmac<ripemd_160>; //using hmac_ripemd_128 = hmac<ripemd_128>; } // namespace hash2 } // namespace boost #endif // #ifndef BOOST_HASH2_RIPEMD_HPP_INCLUDED #include <boost/describe/class.hpp> // For this struct we just call hash_append for each member. struct MyStruct1 { double d0; double d1; double d2; int x; char c; template <class Hash, class Flavor> friend void tag_invoke(boost::hash2::hash_append_tag const&, Hash& h, Flavor const& f, MyStruct1 const& v) { boost::hash2::hash_append(h, f, v.d0); boost::hash2::hash_append(h, f, v.d1); boost::hash2::hash_append(h, f, v.d2); boost::hash2::hash_append(h, f, v.x); boost::hash2::hash_append(h, f, v.c); } }; // For this struct we explot that Boost.Describe gives us reflection and we do not do nothing except specify BOOST_DESCRIBE_STRUCT macro struct MyStruct3 { double d0; double d1; double d2; int x; char c; }; BOOST_DESCRIBE_STRUCT(MyStruct3, (), (d0, d1, d2, x, c)); struct hash_archetype { using result_type = std::uint64_t; hash_archetype(); explicit hash_archetype( std::uint64_t ); hash_archetype( unsigned char const*, std::size_t ); void update( void const*, std::size_t ); result_type result(); }; using Hash = boost::hash2::ripemd_128; auto f1( MyStruct1 const& st ) { Hash hash; boost::hash2::hash_append( hash, {}, st ); return hash.result(); } auto f2( MyStruct3 const& st ) { Hash hash; boost::hash2::hash_append( hash, {}, st ); return hash.result(); }
Become a Patron
Sponsor on GitHub
Donate via PayPal
Source on GitHub
Mailing list
Installed libraries
Wiki
Report an issue
How it works
Contact the author
CE on Mastodon
CE on Bluesky
About the author
Statistics
Changelog
Version tree