From: Chris Duncan Date: Fri, 10 Jan 2025 23:03:14 +0000 (-0800) Subject: Clean up unneeded files. Convert compute shader into .wgsl file supported by esbuild... X-Git-Tag: v0.0.1~15 X-Git-Url: https://zoso.dev/?a=commitdiff_plain;h=8a4b108ebdc86f750e56197ccc28410b3effcc9d;p=nano-pow.git Clean up unneeded files. Convert compute shader into .wgsl file supported by esbuild plugin. Update copyright notices. Rewrite test file and page. --- diff --git a/benchmarks.md b/benchmarks.md index e78b851..7db2aba 100644 --- a/benchmarks.md +++ b/benchmarks.md @@ -1,3 +1,8 @@ + + PASS Original PoW module: Time to calculate proof-of-work for a send block 16 times Total: 89756 ms Average: 5609.75 ms diff --git a/esbuild.mjs b/esbuild.mjs new file mode 100644 index 0000000..0b439d6 --- /dev/null +++ b/esbuild.mjs @@ -0,0 +1,22 @@ +// SPDX-FileCopyrightText: 2025 Chris Duncan +// SPDX-License-Identifier: GPL-3.0-or-later + +import { build } from 'esbuild' +import { glsl } from "esbuild-plugin-glsl" + +await build({ + entryPoints: [ + { out: 'main.min', in: 'build/main.js' }, + { out: 'global.min', in: 'build/global.js' } + ], + outdir: 'dist', + target: 'esnext', + format: 'esm', + platform: 'browser', + bundle: true, + plugins: [ + glsl({ + minify: true + }) + ] +}) diff --git a/index.html b/index.html deleted file mode 100644 index c9d4dbe..0000000 --- a/index.html +++ /dev/null @@ -1,87 +0,0 @@ - - - - - - - - - - - - -

nano-pow

-

Total:
Average:
Harmonic:
Geometric:
Minimum:
Maximum:

-

- - - diff --git a/index.ts b/index.ts deleted file mode 100644 index 308a582..0000000 --- a/index.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { - NanoPowGpuComputeShader, - NanoPowGlFragmentShader, - NanoPowGlVertexShader -} from "./src/shaders" - -import { - NanoPowGl, - NanoPowGpu -} from "./src/classes" - -export { - NanoPowGpuComputeShader, - NanoPowGlFragmentShader, - NanoPowGlVertexShader, - NanoPowGl, - NanoPowGpu -} diff --git a/package-lock.json b/package-lock.json index be966ad..1f7ebe8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,43 +1,171 @@ { - "name": "libnemo", - "version": "0.0.21", + "name": "nano-pow", + "version": "0.0.1", "lockfileVersion": 3, "requires": true, "packages": { "": { - "name": "libnemo", - "version": "0.0.21", + "name": "nano-pow", + "version": "0.0.1", "license": "(GPL-3.0-or-later AND MIT)", "devDependencies": { - "@types/node": "^22.10.1", - "@types/w3c-web-hid": "^1.0.6", - "@types/w3c-web-usb": "^1.0.10", - "@types/web-bluetooth": "^0.0.20", + "@types/node": "^22.10.5", "@webgpu/types": "^0.1.52", - "esbuild": "^0.24.0", - "nano-webgl-pow": "^1.1.1", - "typescript": "^5.6.3" + "esbuild": "^0.24.2", + "esbuild-plugin-glsl": "^1.2.2", + "typescript": "^5.7.3" }, "funding": { "type": "nano", "url": "nano:nano_1zosoqs47yt47bnfg7sdf46kj7asn58b7uzm9ek95jw7ccatq37898u1zoso" - }, - "optionalDependencies": { - "@ledgerhq/hw-transport-web-ble": "^6.29.4", - "@ledgerhq/hw-transport-webhid": "^6.29.4", - "@ledgerhq/hw-transport-webusb": "^6.29.4" } }, - "node_modules/@esbuild/linux-x64": { - "version": "0.24.0", - "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.24.0.tgz", - "integrity": "sha512-vbutsFqQ+foy3wSSbmjBXXIJ6PL3scghJoM8zCL142cGaZKAdCZHyf+Bpu/MmX9zT9Q0zFBVKb36Ma5Fzfa8xA==", + "node_modules/@esbuild/aix-ppc64": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.24.2.tgz", + "integrity": "sha512-thpVCb/rhxE/BnMLQ7GReQLLN8q9qbHmI55F4489/ByVg2aQaQ6kbcLb6FHkocZzQhxc4gx0sCk0tJkKBFzDhA==", + "cpu": [ + "ppc64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "aix" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/android-arm": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.24.2.tgz", + "integrity": "sha512-tmwl4hJkCfNHwFB3nBa8z1Uy3ypZpxqxfTQOcHX+xRByyYgunVbZ9MzUUfb0RxaHIMnbHagwAxuTL+tnNM+1/Q==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/android-arm64": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.24.2.tgz", + "integrity": "sha512-cNLgeqCqV8WxfcTIOeL4OAtSmL8JjcN6m09XIgro1Wi7cF4t/THaWEa7eL5CMoMBdjoHOTh/vwTO/o2TRXIyzg==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/android-x64": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.24.2.tgz", + "integrity": "sha512-B6Q0YQDqMx9D7rvIcsXfmJfvUYLoP722bgfBlO5cGvNVb5V/+Y7nhBE3mHV9OpxBf4eAS2S68KZztiPaWq4XYw==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/darwin-arm64": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.24.2.tgz", + "integrity": "sha512-kj3AnYWc+CekmZnS5IPu9D+HWtUI49hbnyqk0FLEJDbzCIQt7hg7ucF1SQAilhtYpIujfaHr6O0UHlzzSPdOeA==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/darwin-x64": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.24.2.tgz", + "integrity": "sha512-WeSrmwwHaPkNR5H3yYfowhZcbriGqooyu3zI/3GGpF8AyUdsrrP0X6KumITGA9WOyiJavnGZUwPGvxvwfWPHIA==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/freebsd-arm64": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.24.2.tgz", + "integrity": "sha512-UN8HXjtJ0k/Mj6a9+5u6+2eZ2ERD7Edt1Q9IZiB5UZAIdPnVKDoG7mdTVGhHJIeEml60JteamR3qhsr1r8gXvg==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/freebsd-x64": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.24.2.tgz", + "integrity": "sha512-TvW7wE/89PYW+IevEJXZ5sF6gJRDY/14hyIGFXdIucxCsbRmLUcjseQu1SyTko+2idmCw94TgyaEZi9HUSOe3Q==", "cpu": [ "x64" ], "dev": true, "license": "MIT", "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-arm": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.24.2.tgz", + "integrity": "sha512-n0WRM/gWIdU29J57hJyUdIsk0WarGd6To0s+Y+LwvlC55wt+GT/OgkwoXCXvIue1i1sSNWblHEig00GBWiJgfA==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, "os": [ "linux" ], @@ -45,215 +173,353 @@ "node": ">=18" } }, - "node_modules/@ledgerhq/devices": { - "version": "8.4.4", - "resolved": "https://registry.npmjs.org/@ledgerhq/devices/-/devices-8.4.4.tgz", - "integrity": "sha512-sz/ryhe/R687RHtevIE9RlKaV8kkKykUV4k29e7GAVwzHX1gqG+O75cu1NCJUHLbp3eABV5FdvZejqRUlLis9A==", - "license": "Apache-2.0", + "node_modules/@esbuild/linux-arm64": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.24.2.tgz", + "integrity": "sha512-7HnAD6074BW43YvvUmE/35Id9/NB7BeX5EoNkK9obndmZBUk8xmJJeU7DwmUeN7tkysslb2eSl6CTrYz6oEMQg==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", "optional": true, - "dependencies": { - "@ledgerhq/errors": "^6.19.1", - "@ledgerhq/logs": "^6.12.0", - "rxjs": "^7.8.1", - "semver": "^7.3.5" + "os": [ + "linux" + ], + "engines": { + "node": ">=18" } }, - "node_modules/@ledgerhq/errors": { - "version": "6.19.1", - "resolved": "https://registry.npmjs.org/@ledgerhq/errors/-/errors-6.19.1.tgz", - "integrity": "sha512-75yK7Nnit/Gp7gdrJAz0ipp31CCgncRp+evWt6QawQEtQKYEDfGo10QywgrrBBixeRxwnMy1DP6g2oCWRf1bjw==", - "license": "Apache-2.0", - "optional": true + "node_modules/@esbuild/linux-ia32": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.24.2.tgz", + "integrity": "sha512-sfv0tGPQhcZOgTKO3oBE9xpHuUqguHvSo4jl+wjnKwFpapx+vUDcawbwPNuBIAYdRAvIDBfZVvXprIj3HA+Ugw==", + "cpu": [ + "ia32" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } }, - "node_modules/@ledgerhq/hw-transport": { - "version": "6.31.4", - "resolved": "https://registry.npmjs.org/@ledgerhq/hw-transport/-/hw-transport-6.31.4.tgz", - "integrity": "sha512-6c1ir/cXWJm5dCWdq55NPgCJ3UuKuuxRvf//Xs36Bq9BwkV2YaRQhZITAkads83l07NAdR16hkTWqqpwFMaI6A==", - "license": "Apache-2.0", + "node_modules/@esbuild/linux-loong64": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.24.2.tgz", + "integrity": "sha512-CN9AZr8kEndGooS35ntToZLTQLHEjtVB5n7dl8ZcTZMonJ7CCfStrYhrzF97eAecqVbVJ7APOEe18RPI4KLhwQ==", + "cpu": [ + "loong64" + ], + "dev": true, + "license": "MIT", "optional": true, - "dependencies": { - "@ledgerhq/devices": "^8.4.4", - "@ledgerhq/errors": "^6.19.1", - "@ledgerhq/logs": "^6.12.0", - "events": "^3.3.0" + "os": [ + "linux" + ], + "engines": { + "node": ">=18" } }, - "node_modules/@ledgerhq/hw-transport-web-ble": { - "version": "6.29.4", - "resolved": "https://registry.npmjs.org/@ledgerhq/hw-transport-web-ble/-/hw-transport-web-ble-6.29.4.tgz", - "integrity": "sha512-OJyp6CryvyFlg1L9uifo5hYYdDt+WPw8/0ijBixYhYmGvlRz2W6/F2c5rG/zBQWcNnNydPOLjLJM0vR070RfCw==", - "license": "Apache-2.0", + "node_modules/@esbuild/linux-mips64el": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.24.2.tgz", + "integrity": "sha512-iMkk7qr/wl3exJATwkISxI7kTcmHKE+BlymIAbHO8xanq/TjHaaVThFF6ipWzPHryoFsesNQJPE/3wFJw4+huw==", + "cpu": [ + "mips64el" + ], + "dev": true, + "license": "MIT", "optional": true, - "dependencies": { - "@ledgerhq/devices": "^8.4.4", - "@ledgerhq/errors": "^6.19.1", - "@ledgerhq/hw-transport": "^6.31.4", - "@ledgerhq/logs": "^6.12.0", - "rxjs": "^7.8.1" + "os": [ + "linux" + ], + "engines": { + "node": ">=18" } }, - "node_modules/@ledgerhq/hw-transport-webhid": { - "version": "6.29.4", - "resolved": "https://registry.npmjs.org/@ledgerhq/hw-transport-webhid/-/hw-transport-webhid-6.29.4.tgz", - "integrity": "sha512-XkF37lcuyg9zVExMyfDQathWly8rRcGac13wgZATBa3nZ+hUzzWr5QVKg1pKCw10izVHGErW/9a4tbb72rUEmQ==", - "license": "Apache-2.0", + "node_modules/@esbuild/linux-ppc64": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.24.2.tgz", + "integrity": "sha512-shsVrgCZ57Vr2L8mm39kO5PPIb+843FStGt7sGGoqiiWYconSxwTiuswC1VJZLCjNiMLAMh34jg4VSEQb+iEbw==", + "cpu": [ + "ppc64" + ], + "dev": true, + "license": "MIT", "optional": true, - "dependencies": { - "@ledgerhq/devices": "^8.4.4", - "@ledgerhq/errors": "^6.19.1", - "@ledgerhq/hw-transport": "^6.31.4", - "@ledgerhq/logs": "^6.12.0" + "os": [ + "linux" + ], + "engines": { + "node": ">=18" } }, - "node_modules/@ledgerhq/hw-transport-webusb": { - "version": "6.29.4", - "resolved": "https://registry.npmjs.org/@ledgerhq/hw-transport-webusb/-/hw-transport-webusb-6.29.4.tgz", - "integrity": "sha512-HoGF1LlBT9HEGBQy2XeCHrFdv/FEOZU0+J+yfKcgAQIAiASr2MLvdzwoJbUS8h6Gn+vc+/BjzBSO3JNn7Loqbg==", - "license": "Apache-2.0", + "node_modules/@esbuild/linux-riscv64": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.24.2.tgz", + "integrity": "sha512-4eSFWnU9Hhd68fW16GD0TINewo1L6dRrB+oLNNbYyMUAeOD2yCK5KXGK1GH4qD/kT+bTEXjsyTCiJGHPZ3eM9Q==", + "cpu": [ + "riscv64" + ], + "dev": true, + "license": "MIT", "optional": true, - "dependencies": { - "@ledgerhq/devices": "^8.4.4", - "@ledgerhq/errors": "^6.19.1", - "@ledgerhq/hw-transport": "^6.31.4", - "@ledgerhq/logs": "^6.12.0" + "os": [ + "linux" + ], + "engines": { + "node": ">=18" } }, - "node_modules/@ledgerhq/logs": { - "version": "6.12.0", - "resolved": "https://registry.npmjs.org/@ledgerhq/logs/-/logs-6.12.0.tgz", - "integrity": "sha512-ExDoj1QV5eC6TEbMdLUMMk9cfvNKhhv5gXol4SmULRVCx/3iyCPhJ74nsb3S0Vb+/f+XujBEj3vQn5+cwS0fNA==", - "license": "Apache-2.0", - "optional": true + "node_modules/@esbuild/linux-s390x": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.24.2.tgz", + "integrity": "sha512-S0Bh0A53b0YHL2XEXC20bHLuGMOhFDO6GN4b3YjRLK//Ep3ql3erpNcPlEFed93hsQAjAQDNsvcK+hV90FubSw==", + "cpu": [ + "s390x" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } }, - "node_modules/@types/node": { - "version": "22.10.1", - "resolved": "https://registry.npmjs.org/@types/node/-/node-22.10.1.tgz", - "integrity": "sha512-qKgsUwfHZV2WCWLAnVP1JqnpE6Im6h3Y0+fYgMTasNQ7V++CBX5OT1as0g0f+OyubbFqhf6XVNIsmN4IIhEgGQ==", + "node_modules/@esbuild/linux-x64": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.24.2.tgz", + "integrity": "sha512-8Qi4nQcCTbLnK9WoMjdC9NiTG6/E38RNICU6sUNqK0QFxCYgoARqVqxdFmWkdonVsvGqWhmm7MO0jyTqLqwj0Q==", + "cpu": [ + "x64" + ], "dev": true, "license": "MIT", - "dependencies": { - "undici-types": "~6.20.0" + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" } }, - "node_modules/@types/w3c-web-hid": { - "version": "1.0.6", - "resolved": "https://registry.npmjs.org/@types/w3c-web-hid/-/w3c-web-hid-1.0.6.tgz", - "integrity": "sha512-IWyssXmRDo6K7s31dxf+U+x/XUWuVsl9qUIYbJmpUHPcTv/COfBCKw/F0smI45+gPV34brjyP30BFcIsHgYWLA==", + "node_modules/@esbuild/netbsd-arm64": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/@esbuild/netbsd-arm64/-/netbsd-arm64-0.24.2.tgz", + "integrity": "sha512-wuLK/VztRRpMt9zyHSazyCVdCXlpHkKm34WUyinD2lzK07FAHTq0KQvZZlXikNWkDGoT6x3TD51jKQ7gMVpopw==", + "cpu": [ + "arm64" + ], "dev": true, - "license": "MIT" + "license": "MIT", + "optional": true, + "os": [ + "netbsd" + ], + "engines": { + "node": ">=18" + } }, - "node_modules/@types/w3c-web-usb": { - "version": "1.0.10", - "resolved": "https://registry.npmjs.org/@types/w3c-web-usb/-/w3c-web-usb-1.0.10.tgz", - "integrity": "sha512-CHgUI5kTc/QLMP8hODUHhge0D4vx+9UiAwIGiT0sTy/B2XpdX1U5rJt6JSISgr6ikRT7vxV9EVAFeYZqUnl1gQ==", + "node_modules/@esbuild/netbsd-x64": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.24.2.tgz", + "integrity": "sha512-VefFaQUc4FMmJuAxmIHgUmfNiLXY438XrL4GDNV1Y1H/RW3qow68xTwjZKfj/+Plp9NANmzbH5R40Meudu8mmw==", + "cpu": [ + "x64" + ], "dev": true, - "license": "MIT" + "license": "MIT", + "optional": true, + "os": [ + "netbsd" + ], + "engines": { + "node": ">=18" + } }, - "node_modules/@types/web-bluetooth": { - "version": "0.0.20", - "resolved": "https://registry.npmjs.org/@types/web-bluetooth/-/web-bluetooth-0.0.20.tgz", - "integrity": "sha512-g9gZnnXVq7gM7v3tJCWV/qw7w+KeOlSHAhgF9RytFyifW6AF61hdT2ucrYhPq9hLs5JIryeupHV3qGk95dH9ow==", + "node_modules/@esbuild/openbsd-arm64": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/@esbuild/openbsd-arm64/-/openbsd-arm64-0.24.2.tgz", + "integrity": "sha512-YQbi46SBct6iKnszhSvdluqDmxCJA+Pu280Av9WICNwQmMxV7nLRHZfjQzwbPs3jeWnuAhE9Jy0NrnJ12Oz+0A==", + "cpu": [ + "arm64" + ], "dev": true, - "license": "MIT" + "license": "MIT", + "optional": true, + "os": [ + "openbsd" + ], + "engines": { + "node": ">=18" + } }, - "node_modules/@webgpu/types": { - "version": "0.1.52", - "resolved": "https://registry.npmjs.org/@webgpu/types/-/types-0.1.52.tgz", - "integrity": "sha512-eI883Nlag2hGIkhXxAnq8s4APpqXWuPL3Gbn2ghiU12UjLvfCbVqHK4XfXl3eLRTatqcMmeK7jws7IwWsGfbzw==", + "node_modules/@esbuild/openbsd-x64": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.24.2.tgz", + "integrity": "sha512-+iDS6zpNM6EnJyWv0bMGLWSWeXGN/HTaF/LXHXHwejGsVi+ooqDfMCCTerNFxEkM3wYVcExkeGXNqshc9iMaOA==", + "cpu": [ + "x64" + ], "dev": true, - "license": "BSD-3-Clause" + "license": "MIT", + "optional": true, + "os": [ + "openbsd" + ], + "engines": { + "node": ">=18" + } }, - "node_modules/esbuild": { - "version": "0.24.0", - "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.24.0.tgz", - "integrity": "sha512-FuLPevChGDshgSicjisSooU0cemp/sGXR841D5LHMB7mTVOmsEHcAxaH3irL53+8YDIeVNQEySh4DaYU/iuPqQ==", + "node_modules/@esbuild/sunos-x64": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.24.2.tgz", + "integrity": "sha512-hTdsW27jcktEvpwNHJU4ZwWFGkz2zRJUz8pvddmXPtXDzVKTTINmlmga3ZzwcuMpUvLw7JkLy9QLKyGpD2Yxig==", + "cpu": [ + "x64" + ], "dev": true, - "hasInstallScript": true, "license": "MIT", - "bin": { - "esbuild": "bin/esbuild" - }, + "optional": true, + "os": [ + "sunos" + ], "engines": { "node": ">=18" - }, - "optionalDependencies": { - "@esbuild/aix-ppc64": "0.24.0", - "@esbuild/android-arm": "0.24.0", - "@esbuild/android-arm64": "0.24.0", - "@esbuild/android-x64": "0.24.0", - "@esbuild/darwin-arm64": "0.24.0", - "@esbuild/darwin-x64": "0.24.0", - "@esbuild/freebsd-arm64": "0.24.0", - "@esbuild/freebsd-x64": "0.24.0", - "@esbuild/linux-arm": "0.24.0", - "@esbuild/linux-arm64": "0.24.0", - "@esbuild/linux-ia32": "0.24.0", - "@esbuild/linux-loong64": "0.24.0", - "@esbuild/linux-mips64el": "0.24.0", - "@esbuild/linux-ppc64": "0.24.0", - "@esbuild/linux-riscv64": "0.24.0", - "@esbuild/linux-s390x": "0.24.0", - "@esbuild/linux-x64": "0.24.0", - "@esbuild/netbsd-x64": "0.24.0", - "@esbuild/openbsd-arm64": "0.24.0", - "@esbuild/openbsd-x64": "0.24.0", - "@esbuild/sunos-x64": "0.24.0", - "@esbuild/win32-arm64": "0.24.0", - "@esbuild/win32-ia32": "0.24.0", - "@esbuild/win32-x64": "0.24.0" } }, - "node_modules/events": { - "version": "3.3.0", - "resolved": "https://registry.npmjs.org/events/-/events-3.3.0.tgz", - "integrity": "sha512-mQw+2fkQbALzQ7V0MY0IqdnXNOeTtP4r0lN9z7AAawCXgqea7bDii20AYrIBrFd/Hx0M2Ocz6S111CaFkUcb0Q==", + "node_modules/@esbuild/win32-arm64": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.24.2.tgz", + "integrity": "sha512-LihEQ2BBKVFLOC9ZItT9iFprsE9tqjDjnbulhHoFxYQtQfai7qfluVODIYxt1PgdoyQkz23+01rzwNwYfutxUQ==", + "cpu": [ + "arm64" + ], + "dev": true, "license": "MIT", "optional": true, + "os": [ + "win32" + ], "engines": { - "node": ">=0.8.x" + "node": ">=18" } }, - "node_modules/nano-webgl-pow": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/nano-webgl-pow/-/nano-webgl-pow-1.1.1.tgz", - "integrity": "sha512-IKAg7qx2y4n9dnT7tYYypOun/aV+35SfRxJCVnc63GboWQ5/woVIVAZcdX5VfXM1mLYBzADvXxoWZ39G3iPOFA==", + "node_modules/@esbuild/win32-ia32": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.24.2.tgz", + "integrity": "sha512-q+iGUwfs8tncmFC9pcnD5IvRHAzmbwQ3GPS5/ceCyHdjXubwQWI12MKWSNSMYLJMq23/IUCvJMS76PDqXe1fxA==", + "cpu": [ + "ia32" + ], "dev": true, - "license": "MIT" + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=18" + } }, - "node_modules/rxjs": { - "version": "7.8.1", - "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-7.8.1.tgz", - "integrity": "sha512-AA3TVj+0A2iuIoQkWEK/tqFjBq2j+6PO6Y0zJcvzLAFhEFIO3HL0vls9hWLncZbAAbK0mar7oZ4V079I/qPMxg==", - "license": "Apache-2.0", + "node_modules/@esbuild/win32-x64": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.24.2.tgz", + "integrity": "sha512-7VTgWzgMGvup6aSqDPLiW5zHaxYJGTO4OokMjIlrCtf+VpEL+cXKtCvg723iguPYI5oaUNdS+/V7OU2gvXVWEg==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@types/node": { + "version": "22.10.5", + "resolved": "https://registry.npmjs.org/@types/node/-/node-22.10.5.tgz", + "integrity": "sha512-F8Q+SeGimwOo86fiovQh8qiXfFEh2/ocYv7tU5pJ3EXMSSxk1Joj5wefpFK2fHTf/N6HKGSxIDBT9f3gCxXPkQ==", + "dev": true, + "license": "MIT", "dependencies": { - "tslib": "^2.1.0" + "undici-types": "~6.20.0" } }, - "node_modules/semver": { - "version": "7.6.3", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.3.tgz", - "integrity": "sha512-oVekP1cKtI+CTDvHWYFUcMtsK/00wmAEfyqKfNdARm8u1wNVhSgaX7A8d4UuIlUI5e84iEwOhs7ZPYRmzU9U6A==", - "license": "ISC", - "optional": true, + "node_modules/@webgpu/types": { + "version": "0.1.52", + "resolved": "https://registry.npmjs.org/@webgpu/types/-/types-0.1.52.tgz", + "integrity": "sha512-eI883Nlag2hGIkhXxAnq8s4APpqXWuPL3Gbn2ghiU12UjLvfCbVqHK4XfXl3eLRTatqcMmeK7jws7IwWsGfbzw==", + "dev": true, + "license": "BSD-3-Clause" + }, + "node_modules/esbuild": { + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.24.2.tgz", + "integrity": "sha512-+9egpBW8I3CD5XPe0n6BfT5fxLzxrlDzqydF3aviG+9ni1lDC/OvMHcxqEFV0+LANZG5R1bFMWfUrjVsdwxJvA==", + "dev": true, + "hasInstallScript": true, + "license": "MIT", "bin": { - "semver": "bin/semver.js" + "esbuild": "bin/esbuild" }, "engines": { - "node": ">=10" + "node": ">=18" + }, + "optionalDependencies": { + "@esbuild/aix-ppc64": "0.24.2", + "@esbuild/android-arm": "0.24.2", + "@esbuild/android-arm64": "0.24.2", + "@esbuild/android-x64": "0.24.2", + "@esbuild/darwin-arm64": "0.24.2", + "@esbuild/darwin-x64": "0.24.2", + "@esbuild/freebsd-arm64": "0.24.2", + "@esbuild/freebsd-x64": "0.24.2", + "@esbuild/linux-arm": "0.24.2", + "@esbuild/linux-arm64": "0.24.2", + "@esbuild/linux-ia32": "0.24.2", + "@esbuild/linux-loong64": "0.24.2", + "@esbuild/linux-mips64el": "0.24.2", + "@esbuild/linux-ppc64": "0.24.2", + "@esbuild/linux-riscv64": "0.24.2", + "@esbuild/linux-s390x": "0.24.2", + "@esbuild/linux-x64": "0.24.2", + "@esbuild/netbsd-arm64": "0.24.2", + "@esbuild/netbsd-x64": "0.24.2", + "@esbuild/openbsd-arm64": "0.24.2", + "@esbuild/openbsd-x64": "0.24.2", + "@esbuild/sunos-x64": "0.24.2", + "@esbuild/win32-arm64": "0.24.2", + "@esbuild/win32-ia32": "0.24.2", + "@esbuild/win32-x64": "0.24.2" } }, - "node_modules/tslib": { - "version": "2.8.1", - "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.8.1.tgz", - "integrity": "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==", - "license": "0BSD", - "optional": true + "node_modules/esbuild-plugin-glsl": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/esbuild-plugin-glsl/-/esbuild-plugin-glsl-1.2.2.tgz", + "integrity": "sha512-HqRe6qf+9q3U4ugce7EXnXf+c+bRGZZWNkUSiJBYCKRLkA5ThhklNxlc1Z/rcBM8DIAKAdZGk+j6nTBaA5SV6A==", + "dev": true, + "license": "Zlib", + "engines": { + "node": ">= 0.10.18" + }, + "peerDependencies": { + "esbuild": "0.x.x" + } }, "node_modules/typescript": { - "version": "5.6.3", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.6.3.tgz", - "integrity": "sha512-hjcS1mhfuyi4WW8IWtjP7brDrG2cuDZukyrYrSauoXGNgx0S7zceP07adYkJycEr56BOUTNPzbInooiN3fn1qw==", + "version": "5.7.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.7.3.tgz", + "integrity": "sha512-84MVSjMEHP+FQRPy3pX9sTVV/INIex71s9TL2Gm5FG/WG1SqXeKyZ0k7/blY/4FdOzI12CBy1vGc4og/eus0fw==", "dev": true, "license": "Apache-2.0", "bin": { diff --git a/package-lock.json.license b/package-lock.json.license index 36ee55c..7f56691 100644 --- a/package-lock.json.license +++ b/package-lock.json.license @@ -1,2 +1,2 @@ -SPDX-FileCopyrightText: 2024 Chris Duncan +SPDX-FileCopyrightText: 2025 Chris Duncan SPDX-License-Identifier: GPL-3.0-or-later diff --git a/package.json b/package.json index 8b6fb75..dc81fa6 100644 --- a/package.json +++ b/package.json @@ -40,12 +40,12 @@ "url": "git+https://zoso.dev/nano-pow.git" }, "scripts": { - "build": "rm -rf dist && tsc && esbuild main.min=dist/main.js global.min=dist/global.js --outdir=dist --target=esnext --format=esm --platform=browser --bundle --sourcemap", - "test": "npm run build && esbuild test.min=test/test.main.mjs --outdir=dist --target=esnext --format=esm --platform=browser --bundle --sourcemap", - "test:node": "npm run build -- --platform=node && node --test --test-force-exit --env-file .env", - "test:coverage": "npm run test:node -- --experimental-test-coverage", - "test:coverage:report": "npm run test:coverage -- --test-reporter=lcov --test-reporter-destination=coverage.info && genhtml coverage.info --output-directory test/coverage && rm coverage.info && xdg-open test/coverage/index.html", - "test:performance": "npm run build && esbuild perf.min=test/perf.main.mjs --outdir=dist --target=esnext --format=esm --platform=browser --bundle --sourcemap" + "build": "rm -rf dist && tsc && node esbuild.mjs" + }, + "imports": { + "#dist/*": "./dist/*", + "#classes": "./src/classes/index.js", + "#shaders": "./src/shaders/index.js" }, "devDependencies": { "@types/node": "^22.10.5", diff --git a/package.json.license b/package.json.license index 36ee55c..7f56691 100644 --- a/package.json.license +++ b/package.json.license @@ -1,2 +1,2 @@ -SPDX-FileCopyrightText: 2024 Chris Duncan +SPDX-FileCopyrightText: 2025 Chris Duncan SPDX-License-Identifier: GPL-3.0-or-later diff --git a/performance.html b/performance.html deleted file mode 100644 index 106863b..0000000 --- a/performance.html +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - diff --git a/src/classes/gl.ts b/src/classes/gl.ts index e2bca1b..ee29266 100644 --- a/src/classes/gl.ts +++ b/src/classes/gl.ts @@ -1,8 +1,7 @@ -// SPDX-FileCopyrightText: 2024 Chris Duncan +// SPDX-FileCopyrightText: 2025 Chris Duncan // SPDX-License-Identifier: GPL-3.0-or-later -// Based on nano-webgl-pow by Ben Green (numtel) -// https://github.com/numtel/nano-webgl-pow -import { NanoPowGlFragmentShader, NanoPowGlVertexShader } from '../shaders/index.js' + +import { NanoPowGlFragmentShader, NanoPowGlVertexShader } from '#shaders' export class NanoPowGl { /** Used to set canvas size. Must be a multiple of 256. */ diff --git a/src/classes/gpu.ts b/src/classes/gpu.ts index a09a11c..85d907b 100644 --- a/src/classes/gpu.ts +++ b/src/classes/gpu.ts @@ -1,8 +1,8 @@ -// SPDX-FileCopyrightText: 2024 Chris Duncan +// SPDX-FileCopyrightText: 2025 Chris Duncan // SPDX-License-Identifier: GPL-3.0-or-later -// BLAKE2b hashing implementation derived from nano-webgl-pow by Ben Green (https://github.com/numtel/nano-webgl-pow) /// -import { NanoPowGpuComputeShader } from '../shaders/index.js' + +import { NanoPowGpuComputeShader } from '#shaders' /** * Nano proof-of-work using WebGPU. @@ -144,8 +144,8 @@ export class NanoPowGpu { uboView.setUint32(36, threshold, true) this.#device.queue.writeBuffer(this.#uboBuffer, 0, uboView) - // Reset `found` flag to 0u in WORK before each calculation - this.#device.queue.writeBuffer(this.#gpuBuffer, 8, new Uint32Array([0])) + // Reset `nonce` and `found` to 0u in WORK before each calculation + this.#device.queue.writeBuffer(this.#gpuBuffer, 0, new Uint32Array([0, 0, 0])) // Bind UBO read and GPU write buffers const bindGroup = this.#device.createBindGroup({ diff --git a/src/classes/index.ts b/src/classes/index.ts index b7298fa..525577e 100644 --- a/src/classes/index.ts +++ b/src/classes/index.ts @@ -1,5 +1,8 @@ -import { NanoPowGl } from "./gl" -import { NanoPowGpu } from "./gpu" +// SPDX-FileCopyrightText: 2025 Chris Duncan +// SPDX-License-Identifier: GPL-3.0-or-later + +import { NanoPowGl } from "./gl.js" +import { NanoPowGpu } from "./gpu.js" export { NanoPowGl, diff --git a/src/global.ts b/src/global.ts new file mode 100644 index 0000000..d41eefb --- /dev/null +++ b/src/global.ts @@ -0,0 +1,5 @@ +// SPDX-FileCopyrightText: 2025 Chris Duncan +// SPDX-License-Identifier: GPL-3.0-or-later + +import * as main from './main.js' +(globalThis as any).NanoPow ??= main diff --git a/src/main.ts b/src/main.ts new file mode 100644 index 0000000..1a0d874 --- /dev/null +++ b/src/main.ts @@ -0,0 +1,8 @@ +// SPDX-FileCopyrightText: 2025 Chris Duncan +// SPDX-License-Identifier: GPL-3.0-or-later + +import { NanoPowGl, NanoPowGpu } from "#classes" +export { + NanoPowGl, + NanoPowGpu +} diff --git a/src/shaders/gpu-compute.ts b/src/shaders/gpu-compute.ts index 340c50f..cee367c 100644 --- a/src/shaders/gpu-compute.ts +++ b/src/shaders/gpu-compute.ts @@ -20,8 +20,9 @@ const BLAKE2B_IV32_1: u32 = 0x6A09E667u; /** * Main compute function -* 8-byte work is split into two 4-byte u32. Low 4 bytes are random u32 from -* UBO. High 4 bytes are the random value XOR'd with index of each thread. +* A random u32 provided by the UBO is copied to form a pair. Each component of +* this 8-byte value is then XOR'd with a different dimensional index from +* the thread identifier. */ @compute @workgroup_size(256) fn main(@builtin(global_invocation_id) id: vec3) { diff --git a/src/shaders/gpu-compute.wgsl b/src/shaders/gpu-compute.wgsl new file mode 100644 index 0000000..8036a7d --- /dev/null +++ b/src/shaders/gpu-compute.wgsl @@ -0,0 +1,7669 @@ +// SPDX-FileCopyrightText: 2025 Chris Duncan +// SPDX-License-Identifier: GPL-3.0-or-later + +struct UBO { + blockhash: array, 2>, + random: u32, + threshold: u32 +}; +@group(0) @binding(0) var ubo: UBO; + +struct WORK { + nonce: vec2, + found: atomic +}; +@group(0) @binding(1) var work: WORK; + +/** +* Defined separately from uint v[32] below as the original value is required +* to calculate the second uint32 of the digest for threshold comparison +*/ +const BLAKE2B_IV32_1: u32 = 0x6A09E667u; + +/** +* Main compute function +* A random u32 provided by the UBO is copied to form a pair. Each component of +* this 8-byte value is then XOR'd with a different dimensional index from +* the thread identifier. +*/ +@compute @workgroup_size(256) +fn main(@builtin(global_invocation_id) id: vec3) { + if (atomicLoad(&work.found) != 0u) { return; } + + let threshold: u32 = ubo.threshold; + + /** + * Initialize (nonce||blockhash) concatenation + */ + var m0: u32 = ubo.random ^ id.x; + var m1: u32 = ubo.random ^ id.y; + var m2: u32 = ubo.blockhash[0u].x; + var m3: u32 = ubo.blockhash[0u].y; + var m4: u32 = ubo.blockhash[0u].z; + var m5: u32 = ubo.blockhash[0u].w; + var m6: u32 = ubo.blockhash[1u].x; + var m7: u32 = ubo.blockhash[1u].y; + var m8: u32 = ubo.blockhash[1u].z; + var m9: u32 = ubo.blockhash[1u].w; + + /** + * Compression buffer intialized to 2 instances of initialization vector + * The following values have been modified from the BLAKE2B_IV: + * OUTLEN is constant 8 bytes + * v[0u] ^= 0x01010000u ^ uint(OUTLEN); + * INLEN is constant 40 bytes: work value (8) + block hash (32) + * v[24u] ^= uint(INLEN); + * It is always the "last" compression at this INLEN + * v[28u] = ~v[28u]; + * v[29u] = ~v[29u]; + */ + var v0: u32 = 0xF2BDC900u; + var v1: u32 = 0x6A09E667u; + var v2: u32 = 0x84CAA73Bu; + var v3: u32 = 0xBB67AE85u; + var v4: u32 = 0xFE94F82Bu; + var v5: u32 = 0x3C6EF372u; + var v6: u32 = 0x5F1D36F1u; + var v7: u32 = 0xA54FF53Au; + var v8: u32 = 0xADE682D1u; + var v9: u32 = 0x510E527Fu; + var v10: u32 = 0x2B3E6C1Fu; + var v11: u32 = 0x9B05688Cu; + var v12: u32 = 0xFB41BD6Bu; + var v13: u32 = 0x1F83D9ABu; + var v14: u32 = 0x137E2179u; + var v15: u32 = 0x5BE0CD19u; + var v16: u32 = 0xF3BCC908u; + var v17: u32 = 0x6A09E667u; + var v18: u32 = 0x84CAA73Bu; + var v19: u32 = 0xBB67AE85u; + var v20: u32 = 0xFE94F82Bu; + var v21: u32 = 0x3C6EF372u; + var v22: u32 = 0x5F1D36F1u; + var v23: u32 = 0xA54FF53Au; + var v24: u32 = 0xADE682F9u; + var v25: u32 = 0x510E527Fu; + var v26: u32 = 0x2B3E6C1Fu; + var v27: u32 = 0x9B05688Cu; + var v28: u32 = 0x04BE4294u; + var v29: u32 = 0xE07C2654u; + var v30: u32 = 0x137E2179u; + var v31: u32 = 0x5BE0CD19u; + + + + + + /** + * Twelve rounds of G mixing as part of BLAKE2b compression step. + * Each sigma r index correlates with the reference implementation, but each + * sigma i index, and each v index, is doubled due to using two u32 array + * elements to represent one uint64_t. + */ + var o0: u32; + var o1: u32; + var xor0: u32; + var xor1: u32; + + /**************************************************************************** + * ROUND(0) * + ****************************************************************************/ + + /** + * r=0, i=0(x2), a=v[0-1], b=v[8-9], c=v[16-17], d=v[24-25] + */ + + // a = a + b + o0 = v0 + v8; + o1 = v1 + v9; + o1 = o1 + select(0u, 1u, o0 < v0); + v0 = o0; + v1 = o1; + + // a = a + m[sigma[r][2*i+0]] + o0 = v0 + m0; + o1 = v1 + m1; + o1 = o1 + select(0u, 1u, o0 < v0); + v0 = o0; + v1 = o1; + + // d = rotr64(d ^ a, 32) + xor0 = v24 ^ v0; + xor1 = v25 ^ v1; + v24 = xor1; + v25 = xor0; + + // c = c + d + o0 = v16 + v24; + o1 = v17 + v25; + o1 = o1 + select(0u, 1u, o0 < v16); + v16 = o0; + v17 = o1; + + // b = rotr64(b ^ c, 24) + xor0 = v8 ^ v16; + xor1 = v9 ^ v17; + v8 = (xor0 >> 24u) ^ (xor1 << 8u); + v9 = (xor1 >> 24u) ^ (xor0 << 8u); + + // a = a + b + o0 = v0 + v8; + o1 = v1 + v9; + o1 = o1 + select(0u, 1u, o0 < v0); + v0 = o0; + v1 = o1; + + // a = a + m[sigma[r][2*i+1]] + o0 = v0 + m2; + o1 = v1 + m3; + o1 = o1 + select(0u, 1u, o0 < v0); + v0 = o0; + v1 = o1; + + // d = rotr64(d ^ a, 16) + xor0 = v24 ^ v0; + xor1 = v25 ^ v1; + v24 = (xor0 >> 16u) ^ (xor1 << 16u); + v25 = (xor1 >> 16u) ^ (xor0 << 16u); + + // c = c + d + o0 = v16 + v24; + o1 = v17 + v25; + o1 = o1 + select(0u, 1u, o0 < v16); + v16 = o0; + v17 = o1; + + // b = rotr64(b ^ c, 63) + xor0 = v8 ^ v16; + xor1 = v9 ^ v17; + v8 = (xor1 >> 31u) ^ (xor0 << 1u); + v9 = (xor0 >> 31u) ^ (xor1 << 1u); + + + + + + /** + * r=0, i=1(x2), a=v[2-3], b=v[10-11], c=v[18-19], d=v[26-27] + */ + + // a = a + b + o0 = v2 + v10; + o1 = v3 + v11; + o1 = o1 + select(0u, 1u, o0 < v2); + v2 = o0; + v3 = o1; + + // a = a + m[sigma[r][2*i+0]] + o0 = v2 + m4; + o1 = v3 + m5; + o1 = o1 + select(0u, 1u, o0 < v2); + v2 = o0; + v3 = o1; + + // d = rotr64(d ^ a, 32) + xor0 = v26 ^ v2; + xor1 = v27 ^ v3; + v26 = xor1; + v27 = xor0; + + // c = c + d + o0 = v18 + v26; + o1 = v19 + v27; + o1 = o1 + select(0u, 1u, o0 < v18); + v18 = o0; + v19 = o1; + + // b = rotr64(b ^ c, 24) + xor0 = v10 ^ v18; + xor1 = v11 ^ v19; + v10 = (xor0 >> 24u) ^ (xor1 << 8u); + v11 = (xor1 >> 24u) ^ (xor0 << 8u); + + // a = a + b + o0 = v2 + v10; + o1 = v3 + v11; + o1 = o1 + select(0u, 1u, o0 < v2); + v2 = o0; + v3 = o1; + + // a = a + m[sigma[r][2*i+1]] + o0 = v2 + m6; + o1 = v3 + m7; + o1 = o1 + select(0u, 1u, o0 < v2); + v2 = o0; + v3 = o1; + + // d = rotr64(d ^ a, 16) + xor0 = v26 ^ v2; + xor1 = v27 ^ v3; + v26 = (xor0 >> 16u) ^ (xor1 << 16u); + v27 = (xor1 >> 16u) ^ (xor0 << 16u); + + // c = c + d + o0 = v18 + v26; + o1 = v19 + v27; + o1 = o1 + select(0u, 1u, o0 < v18); + v18 = o0; + v19 = o1; + + // b = rotr64(b ^ c, 63) + xor0 = v10 ^ v18; + xor1 = v11 ^ v19; + v10 = (xor1 >> 31u) ^ (xor0 << 1u); + v11 = (xor0 >> 31u) ^ (xor1 << 1u); + + + + + + /** + * r=0, i=2(x2), a=v[2-3], b=v[10-11], c=v[18-19], d=v[26-27] + */ + + // a = a + b + o0 = v4 + v12; + o1 = v5 + v13; + o1 = o1 + select(0u, 1u, o0 < v4); + v4 = o0; + v5 = o1; + + // a = a + m[sigma[r][2*i+0]] + o0 = v4 + m8; + o1 = v5 + m9; + o1 = o1 + select(0u, 1u, o0 < v4); + v4 = o0; + v5 = o1; + + // d = rotr64(d ^ a, 32) + xor0 = v28 ^ v4; + xor1 = v29 ^ v5; + v28 = xor1; + v29 = xor0; + + // c = c + d + o0 = v20 + v28; + o1 = v21 + v29; + o1 = o1 + select(0u, 1u, o0 < v20); + v20 = o0; + v21 = o1; + + // b = rotr64(b ^ c, 24) + xor0 = v12 ^ v20; + xor1 = v13 ^ v21; + v12 = (xor0 >> 24u) ^ (xor1 << 8u); + v13 = (xor1 >> 24u) ^ (xor0 << 8u); + + // a = a + b + o0 = v4 + v12; + o1 = v5 + v13; + o1 = o1 + select(0u, 1u, o0 < v4); + v4 = o0; + v5 = o1; + + // // a = a + m[sigma[r][2*i+1]] + // // skip since adding 0u does nothing + // o0 = v4 + 0u; + // o1 = v5 + 0u; + // if (v4 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v4 = o0; + // v5 = o1; + + // d = rotr64(d ^ a, 16) + xor0 = v28 ^ v4; + xor1 = v29 ^ v5; + v28 = (xor0 >> 16u) ^ (xor1 << 16u); + v29 = (xor1 >> 16u) ^ (xor0 << 16u); + + // c = c + d + o0 = v20 + v28; + o1 = v21 + v29; + o1 = o1 + select(0u, 1u, o0 < v20); + v20 = o0; + v21 = o1; + + // b = rotr64(b ^ c, 63) + xor0 = v12 ^ v20; + xor1 = v13 ^ v21; + v12 = (xor1 >> 31u) ^ (xor0 << 1u); + v13 = (xor0 >> 31u) ^ (xor1 << 1u); + + + + + + /** + * r=0, i=3(x2), a=v[6-7], b=v[14-15], c=v[22-23], d=v[30-31] + */ + + // a = a + b + o0 = v6 + v14; + o1 = v7 + v15; + o1 = o1 + select(0u, 1u, o0 < v6); + v6 = o0; + v7 = o1; + + // // a = a + m[sigma[r][2*i+0]] + // // skip since adding 0u does nothing + // o0 = v6 + 0u; + // o1 = v7 + 0u; + // if (v6 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v6 = o0; + // v7 = o1; + + // d = rotr64(d ^ a, 32) + xor0 = v30 ^ v6; + xor1 = v31 ^ v7; + v30 = xor1; + v31 = xor0; + + // c = c + d + o0 = v22 + v30; + o1 = v23 + v31; + o1 = o1 + select(0u, 1u, o0 < v22); + v22 = o0; + v23 = o1; + + // b = rotr64(b ^ c, 24) + xor0 = v14 ^ v22; + xor1 = v15 ^ v23; + v14 = (xor0 >> 24u) ^ (xor1 << 8u); + v15 = (xor1 >> 24u) ^ (xor0 << 8u); + + // a = a + b + o0 = v6 + v14; + o1 = v7 + v15; + o1 = o1 + select(0u, 1u, o0 < v6); + v6 = o0; + v7 = o1; + + // // a = a + m[sigma[r][2*i+1]] + // // skip since adding 0u does nothing + // o0 = v6 + 0u; + // o1 = v7 + 0u; + // if (v6 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v6 = o0; + // v7 = o1; + + // d = rotr64(d ^ a, 16) + xor0 = v30 ^ v6; + xor1 = v31 ^ v7; + v30 = (xor0 >> 16u) ^ (xor1 << 16u); + v31 = (xor1 >> 16u) ^ (xor0 << 16u); + + // c = c + d + o0 = v22 + v30; + o1 = v23 + v31; + o1 = o1 + select(0u, 1u, o0 < v22); + v22 = o0; + v23 = o1; + + // b = rotr64(b ^ c, 63) + xor0 = v14 ^ v22; + xor1 = v15 ^ v23; + v14 = (xor1 >> 31u) ^ (xor0 << 1u); + v15 = (xor0 >> 31u) ^ (xor1 << 1u); + + + + + + /** + * r=0, i=4(x2), a=v[0-1], b=v[10-11], c=v[20-21], d=v[30-31] + */ + + // a = a + b + o0 = v0 + v10; + o1 = v1 + v11; + o1 = o1 + select(0u, 1u, o0 < v0); + v0 = o0; + v1 = o1; + + // // a = a + m[sigma[r][2*i+0]] + // // skip since adding 0u does nothing + // o0 = v0 + 0u; + // o1 = v1 + 0u; + // if (v0 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v0 = o0; + // v1 = o1; + + // d = rotr64(d ^ a, 32) + xor0 = v30 ^ v0; + xor1 = v31 ^ v1; + v30 = xor1; + v31 = xor0; + + // c = c + d + o0 = v20 + v30; + o1 = v21 + v31; + o1 = o1 + select(0u, 1u, o0 < v20); + v20 = o0; + v21 = o1; + + // b = rotr64(b ^ c, 24) + xor0 = v10 ^ v20; + xor1 = v11 ^ v21; + v10 = (xor0 >> 24u) ^ (xor1 << 8u); + v11 = (xor1 >> 24u) ^ (xor0 << 8u); + + // a = a + b + o0 = v0 + v10; + o1 = v1 + v11; + o1 = o1 + select(0u, 1u, o0 < v0); + v0 = o0; + v1 = o1; + + // // a = a + m[sigma[r][2*i+1]] + // // skip since adding 0u does nothing + // o0 = v0 + 0u; + // o1 = v1 + 0u; + // if (v0 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v0 = o0; + // v1 = o1; + + // d = rotr64(d ^ a, 16) + xor0 = v30 ^ v0; + xor1 = v31 ^ v1; + v30 = (xor0 >> 16u) ^ (xor1 << 16u); + v31 = (xor1 >> 16u) ^ (xor0 << 16u); + + // c = c + d + o0 = v20 + v30; + o1 = v21 + v31; + o1 = o1 + select(0u, 1u, o0 < v20); + v20 = o0; + v21 = o1; + + // b = rotr64(b ^ c, 63) + xor0 = v10 ^ v20; + xor1 = v11 ^ v21; + v10 = (xor1 >> 31u) ^ (xor0 << 1u); + v11 = (xor0 >> 31u) ^ (xor1 << 1u); + + + + + + /** + * r=0, i=5(x2), a=v[2-3], b=v[12-13], c=v[22-23], d=v[24-25] + */ + + // a = a + b + o0 = v2 + v12; + o1 = v3 + v13; + o1 = o1 + select(0u, 1u, o0 < v2); + v2 = o0; + v3 = o1; + + // // a = a + m[sigma[r][2*i+0]] + // // skip since adding 0u does nothing + // o0 = v2 + 0u; + // o1 = v3 + 0u; + // if (v2 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v2 = o0; + // v3 = o1; + + // d = rotr64(d ^ a, 32) + xor0 = v24 ^ v2; + xor1 = v25 ^ v3; + v24 = xor1; + v25 = xor0; + + // c = c + d + o0 = v22 + v24; + o1 = v23 + v25; + o1 = o1 + select(0u, 1u, o0 < v22); + v22 = o0; + v23 = o1; + + // b = rotr64(b ^ c, 24) + xor0 = v12 ^ v22; + xor1 = v13 ^ v23; + v12 = (xor0 >> 24u) ^ (xor1 << 8u); + v13 = (xor1 >> 24u) ^ (xor0 << 8u); + + // a = a + b + o0 = v2 + v12; + o1 = v3 + v13; + o1 = o1 + select(0u, 1u, o0 < v2); + v2 = o0; + v3 = o1; + + // // a = a + m[sigma[r][2*i+1]] + // // skip since adding 0u does nothing + // o0 = v2 + 0u; + // o1 = v3 + 0u; + // if (v2 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v2 = o0; + // v3 = o1; + + // d = rotr64(d ^ a, 16) + xor0 = v24 ^ v2; + xor1 = v25 ^ v3; + v24 = (xor0 >> 16u) ^ (xor1 << 16u); + v25 = (xor1 >> 16u) ^ (xor0 << 16u); + + // c = c + d + o0 = v22 + v24; + o1 = v23 + v25; + o1 = o1 + select(0u, 1u, o0 < v22); + v22 = o0; + v23 = o1; + + // b = rotr64(b ^ c, 63) + xor0 = v12 ^ v22; + xor1 = v13 ^ v23; + v12 = (xor1 >> 31u) ^ (xor0 << 1u); + v13 = (xor0 >> 31u) ^ (xor1 << 1u); + + + + + + /** + * r=0, i=6(x2), a=v[4-6], b=v[14-15], c=v[16-17], d=v[26-27] + */ + + // a = a + b + o0 = v4 + v14; + o1 = v5 + v15; + o1 = o1 + select(0u, 1u, o0 < v4); + v4 = o0; + v5 = o1; + + // // a = a + m[sigma[r][2*i+0]] + // // skip since adding 0u does nothing + // o0 = v4 + 0u; + // o1 = v5 + 0u; + // if (v4 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v4 = o0; + // v5 = o1; + + // d = rotr64(d ^ a, 32) + xor0 = v26 ^ v4; + xor1 = v27 ^ v5; + v26 = xor1; + v27 = xor0; + + // c = c + d + o0 = v16 + v26; + o1 = v17 + v27; + o1 = o1 + select(0u, 1u, o0 < v16); + v16 = o0; + v17 = o1; + + // b = rotr64(b ^ c, 24) + xor0 = v14 ^ v16; + xor1 = v15 ^ v17; + v14 = (xor0 >> 24u) ^ (xor1 << 8u); + v15 = (xor1 >> 24u) ^ (xor0 << 8u); + + // a = a + b + o0 = v4 + v14; + o1 = v5 + v15; + o1 = o1 + select(0u, 1u, o0 < v4); + v4 = o0; + v5 = o1; + + // // a = a + m[sigma[r][2*i+1]] + // // skip since adding 0u does nothing + // o0 = v4 + 0u; + // o1 = v5 + 0u; + // if (v4 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v4 = o0; + // v5 = o1; + + // d = rotr64(d ^ a, 16) + xor0 = v26 ^ v4; + xor1 = v27 ^ v5; + v26 = (xor0 >> 16u) ^ (xor1 << 16u); + v27 = (xor1 >> 16u) ^ (xor0 << 16u); + + // c = c + d + o0 = v16 + v26; + o1 = v17 + v27; + o1 = o1 + select(0u, 1u, o0 < v16); + v16 = o0; + v17 = o1; + + // b = rotr64(b ^ c, 63) + xor0 = v14 ^ v16; + xor1 = v15 ^ v17; + v14 = (xor1 >> 31u) ^ (xor0 << 1u); + v15 = (xor0 >> 31u) ^ (xor1 << 1u); + + + + + + /** + * r=0, i=7(x2), a=v[6-7], b=v[8-9], c=v[18-19], d=v[28-29] + */ + + // a = a + b + o0 = v6 + v8; + o1 = v7 + v9; + o1 = o1 + select(0u, 1u, o0 < v6); + v6 = o0; + v7 = o1; + + // // a = a + m[sigma[r][2*i+0]] + // // skip since adding 0u does nothing + // o0 = v6 + 0u; + // o1 = v7 + 0u; + // if (v6 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v6 = o0; + // v7 = o1; + + // d = rotr64(d ^ a, 32) + xor0 = v28 ^ v6; + xor1 = v29 ^ v7; + v28 = xor1; + v29 = xor0; + + // c = c + d + o0 = v18 + v28; + o1 = v19 + v29; + o1 = o1 + select(0u, 1u, o0 < v18); + v18 = o0; + v19 = o1; + + // b = rotr64(b ^ c, 24) + xor0 = v8 ^ v18; + xor1 = v9 ^ v19; + v8 = (xor0 >> 24u) ^ (xor1 << 8u); + v9 = (xor1 >> 24u) ^ (xor0 << 8u); + + // a = a + b + o0 = v6 + v8; + o1 = v7 + v9; + o1 = o1 + select(0u, 1u, o0 < v6); + v6 = o0; + v7 = o1; + + // // a = a + m[sigma[r][2*i+1]] + // // skip since adding 0u does nothing + // o0 = v6 + 0u; + // o1 = v7 + 0u; + // if (v6 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v6 = o0; + // v7 = o1; + + // d = rotr64(d ^ a, 16) + xor0 = v28 ^ v6; + xor1 = v29 ^ v7; + v28 = (xor0 >> 16u) ^ (xor1 << 16u); + v29 = (xor1 >> 16u) ^ (xor0 << 16u); + + // c = c + d + o0 = v18 + v28; + o1 = v19 + v29; + o1 = o1 + select(0u, 1u, o0 < v18); + v18 = o0; + v19 = o1; + + // b = rotr64(b ^ c, 63) + xor0 = v8 ^ v18; + xor1 = v9 ^ v19; + v8 = (xor1 >> 31u) ^ (xor0 << 1u); + v9 = (xor0 >> 31u) ^ (xor1 << 1u); + + + + + + /**************************************************************************** + * ROUND(1) * + ****************************************************************************/ + + /** + * r=1, i=0(x2), a=v[0-1], b=v[8-9], c=v[16-17], d=v[24-25] + */ + + // a = a + b + o0 = v0 + v8; + o1 = v1 + v9; + o1 = o1 + select(0u, 1u, o0 < v0); + v0 = o0; + v1 = o1; + + // // a = a + m[sigma[r][2*i+0]] + // // skip since adding 0u does nothing + // o0 = v0 + 0u; + // o1 = v1 + 0u; + // if (v0 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v0 = o0; + // v1 = o1; + + // d = rotr64(d ^ a, 32) + xor0 = v24 ^ v0; + xor1 = v25 ^ v1; + v24 = xor1; + v25 = xor0; + + // c = c + d + o0 = v16 + v24; + o1 = v17 + v25; + o1 = o1 + select(0u, 1u, o0 < v16); + v16 = o0; + v17 = o1; + + // b = rotr64(b ^ c, 24) + xor0 = v8 ^ v16; + xor1 = v9 ^ v17; + v8 = (xor0 >> 24u) ^ (xor1 << 8u); + v9 = (xor1 >> 24u) ^ (xor0 << 8u); + + // a = a + b + o0 = v0 + v8; + o1 = v1 + v9; + o1 = o1 + select(0u, 1u, o0 < v0); + v0 = o0; + v1 = o1; + + // // a = a + m[sigma[r][2*i+1]] + // // skip since adding 0u does nothing + // o0 = v0 + 0u; + // o1 = v1 + 0u; + // if (v0 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v0 = o0; + // v1 = o1; + + // d = rotr64(d ^ a, 16) + xor0 = v24 ^ v0; + xor1 = v25 ^ v1; + v24 = (xor0 >> 16u) ^ (xor1 << 16u); + v25 = (xor1 >> 16u) ^ (xor0 << 16u); + + // c = c + d + o0 = v16 + v24; + o1 = v17 + v25; + o1 = o1 + select(0u, 1u, o0 < v16); + v16 = o0; + v17 = o1; + + // b = rotr64(b ^ c, 63) + xor0 = v8 ^ v16; + xor1 = v9 ^ v17; + v8 = (xor1 >> 31u) ^ (xor0 << 1u); + v9 = (xor0 >> 31u) ^ (xor1 << 1u); + + + + + + /** + * r=1, i=1(x2), a=v[2-3], b=v[10-11], c=v[18-19], d=v[26-27] + */ + + // a = a + b + o0 = v2 + v10; + o1 = v3 + v11; + o1 = o1 + select(0u, 1u, o0 < v2); + v2 = o0; + v3 = o1; + + // a = a + m[sigma[r][2*i+0]] + o0 = v2 + m8; + o1 = v3 + m9; + o1 = o1 + select(0u, 1u, o0 < v2); + v2 = o0; + v3 = o1; + + // d = rotr64(d ^ a, 32) + xor0 = v26 ^ v2; + xor1 = v27 ^ v3; + v26 = xor1; + v27 = xor0; + + // c = c + d + o0 = v18 + v26; + o1 = v19 + v27; + o1 = o1 + select(0u, 1u, o0 < v18); + v18 = o0; + v19 = o1; + + // b = rotr64(b ^ c, 24) + xor0 = v10 ^ v18; + xor1 = v11 ^ v19; + v10 = (xor0 >> 24u) ^ (xor1 << 8u); + v11 = (xor1 >> 24u) ^ (xor0 << 8u); + + // a = a + b + o0 = v2 + v10; + o1 = v3 + v11; + o1 = o1 + select(0u, 1u, o0 < v2); + v2 = o0; + v3 = o1; + + // // a = a + m[sigma[r][2*i+1]] + // // skip since adding 0u does nothing + // o0 = v2 + 0u; + // o1 = v3 + 0u; + // if (v2 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v2 = o0; + // v3 = o1; + + // d = rotr64(d ^ a, 16) + xor0 = v26 ^ v2; + xor1 = v27 ^ v3; + v26 = (xor0 >> 16u) ^ (xor1 << 16u); + v27 = (xor1 >> 16u) ^ (xor0 << 16u); + + // c = c + d + o0 = v18 + v26; + o1 = v19 + v27; + o1 = o1 + select(0u, 1u, o0 < v18); + v18 = o0; + v19 = o1; + + // b = rotr64(b ^ c, 63) + xor0 = v10 ^ v18; + xor1 = v11 ^ v19; + v10 = (xor1 >> 31u) ^ (xor0 << 1u); + v11 = (xor0 >> 31u) ^ (xor1 << 1u); + + + + + + /** + * r=1, i=2(x2), a=v[4-5], b=v[12-13], c=v[20-21], d=v[28-29] + */ + + // a = a + b + o0 = v4 + v12; + o1 = v5 + v13; + o1 = o1 + select(0u, 1u, o0 < v4); + v4 = o0; + v5 = o1; + + // // a = a + m[sigma[r][2*i+0]] + // // skip since adding 0u does nothing + // o0 = v4 + 0u; + // o1 = v5 + 0u; + // if (v4 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v4 = o0; + // v5 = o1; + + // d = rotr64(d ^ a, 32) + xor0 = v28 ^ v4; + xor1 = v29 ^ v5; + v28 = xor1; + v29 = xor0; + + // c = c + d + o0 = v20 + v28; + o1 = v21 + v29; + o1 = o1 + select(0u, 1u, o0 < v20); + v20 = o0; + v21 = o1; + + // b = rotr64(b ^ c, 24) + xor0 = v12 ^ v20; + xor1 = v13 ^ v21; + v12 = (xor0 >> 24u) ^ (xor1 << 8u); + v13 = (xor1 >> 24u) ^ (xor0 << 8u); + + // a = a + b + o0 = v4 + v12; + o1 = v5 + v13; + o1 = o1 + select(0u, 1u, o0 < v4); + v4 = o0; + v5 = o1; + + // // a = a + m[sigma[r][2*i+1]] + // // skip since adding 0u does nothing + // o0 = v4 + 0u; + // o1 = v5 + 0u; + // if (v4 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v4 = o0; + // v5 = o1; + + // d = rotr64(d ^ a, 16) + xor0 = v28 ^ v4; + xor1 = v29 ^ v5; + v28 = (xor0 >> 16u) ^ (xor1 << 16u); + v29 = (xor1 >> 16u) ^ (xor0 << 16u); + + // c = c + d + o0 = v20 + v28; + o1 = v21 + v29; + o1 = o1 + select(0u, 1u, o0 < v20); + v20 = o0; + v21 = o1; + + // b = rotr64(b ^ c, 63) + xor0 = v12 ^ v20; + xor1 = v13 ^ v21; + v12 = (xor1 >> 31u) ^ (xor0 << 1u); + v13 = (xor0 >> 31u) ^ (xor1 << 1u); + + + + + + /** + * r=1, i=3(x2), a=v[6-7], b=v[14-15], c=v[22-23], d=v[30-31] + */ + + // a = a + b + o0 = v6 + v14; + o1 = v7 + v15; + o1 = o1 + select(0u, 1u, o0 < v6); + v6 = o0; + v7 = o1; + + // // a = a + m[sigma[r][2*i+0]] + // // skip since adding 0u does nothing + // o0 = v6 + 0u; + // o1 = v7 + 0u; + // if (v6 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v6 = o0; + // v7 = o1; + + // d = rotr64(d ^ a, 32) + xor0 = v30 ^ v6; + xor1 = v31 ^ v7; + v30 = xor1; + v31 = xor0; + + // c = c + d + o0 = v22 + v30; + o1 = v23 + v31; + o1 = o1 + select(0u, 1u, o0 < v22); + v22 = o0; + v23 = o1; + + // b = rotr64(b ^ c, 24) + xor0 = v14 ^ v22; + xor1 = v15 ^ v23; + v14 = (xor0 >> 24u) ^ (xor1 << 8u); + v15 = (xor1 >> 24u) ^ (xor0 << 8u); + + // a = a + b + o0 = v6 + v14; + o1 = v7 + v15; + o1 = o1 + select(0u, 1u, o0 < v6); + v6 = o0; + v7 = o1; + + // // a = a + m[sigma[r][2*i+1]] + // // skip since adding 0u does nothing + // o0 = v6 + 0u; + // o1 = v7 + 0u; + // if (v6 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v6 = o0; + // v7 = o1; + + // d = rotr64(d ^ a, 16) + xor0 = v30 ^ v6; + xor1 = v31 ^ v7; + v30 = (xor0 >> 16u) ^ (xor1 << 16u); + v31 = (xor1 >> 16u) ^ (xor0 << 16u); + + // c = c + d + o0 = v22 + v30; + o1 = v23 + v31; + o1 = o1 + select(0u, 1u, o0 < v22); + v22 = o0; + v23 = o1; + + // b = rotr64(b ^ c, 63) + xor0 = v14 ^ v22; + xor1 = v15 ^ v23; + v14 = (xor1 >> 31u) ^ (xor0 << 1u); + v15 = (xor0 >> 31u) ^ (xor1 << 1u); + + + + + + /** + * r=1, i=4(x2), a=v[0-1], b=v[11-12], c=v[21-22], d=v[30-31] + */ + + // a = a + b + o0 = v0 + v10; + o1 = v1 + v11; + o1 = o1 + select(0u, 1u, o0 < v0); + v0 = o0; + v1 = o1; + + // a = a + m[sigma[r][2*i+0]] + o0 = v0 + m2; + o1 = v1 + m3; + o1 = o1 + select(0u, 1u, o0 < v0); + v0 = o0; + v1 = o1; + + // d = rotr64(d ^ a, 32) + xor0 = v30 ^ v0; + xor1 = v31 ^ v1; + v30 = xor1; + v31 = xor0; + + // c = c + d + o0 = v20 + v30; + o1 = v21 + v31; + o1 = o1 + select(0u, 1u, o0 < v20); + v20 = o0; + v21 = o1; + + // b = rotr64(b ^ c, 24) + xor0 = v10 ^ v20; + xor1 = v11 ^ v21; + v10 = (xor0 >> 24u) ^ (xor1 << 8u); + v11 = (xor1 >> 24u) ^ (xor0 << 8u); + + // a = a + b + o0 = v0 + v10; + o1 = v1 + v11; + o1 = o1 + select(0u, 1u, o0 < v0); + v0 = o0; + v1 = o1; + + // // a = a + m[sigma[r][2*i+1]] + // // skip since adding 0u does nothing + // o0 = v0 + 0u; + // o1 = v1 + 0u; + // if (v0 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v0 = o0; + // v1 = o1; + + // d = rotr64(d ^ a, 16) + xor0 = v30 ^ v0; + xor1 = v31 ^ v1; + v30 = (xor0 >> 16u) ^ (xor1 << 16u); + v31 = (xor1 >> 16u) ^ (xor0 << 16u); + + // c = c + d + o0 = v20 + v30; + o1 = v21 + v31; + o1 = o1 + select(0u, 1u, o0 < v20); + v20 = o0; + v21 = o1; + + // b = rotr64(b ^ c, 63) + xor0 = v10 ^ v20; + xor1 = v11 ^ v21; + v10 = (xor1 >> 31u) ^ (xor0 << 1u); + v11 = (xor0 >> 31u) ^ (xor1 << 1u); + + + + + + /** + * r=1, i=5(x2), a=v[2-3], b=v[12-13], c=v[22-23], d=v[24-25] + */ + + // a = a + b + o0 = v2 + v12; + o1 = v3 + v13; + o1 = o1 + select(0u, 1u, o0 < v2); + v2 = o0; + v3 = o1; + + // a = a + m[sigma[r][2*i+0]] + o0 = v2 + m0; + o1 = v3 + m1; + o1 = o1 + select(0u, 1u, o0 < v2); + v2 = o0; + v3 = o1; + + // d = rotr64(d ^ a, 32) + xor0 = v24 ^ v2; + xor1 = v25 ^ v3; + v24 = xor1; + v25 = xor0; + + // c = c + d + o0 = v22 + v24; + o1 = v23 + v25; + o1 = o1 + select(0u, 1u, o0 < v22); + v22 = o0; + v23 = o1; + + // b = rotr64(b ^ c, 24) + xor0 = v12 ^ v22; + xor1 = v13 ^ v23; + v12 = (xor0 >> 24u) ^ (xor1 << 8u); + v13 = (xor1 >> 24u) ^ (xor0 << 8u); + + // a = a + b + o0 = v2 + v12; + o1 = v3 + v13; + o1 = o1 + select(0u, 1u, o0 < v2); + v2 = o0; + v3 = o1; + + // a = a + m[sigma[r][2*i+1]] + o0 = v2 + m4; + o1 = v3 + m5; + o1 = o1 + select(0u, 1u, o0 < v2); + v2 = o0; + v3 = o1; + + // d = rotr64(d ^ a, 16) + xor0 = v24 ^ v2; + xor1 = v25 ^ v3; + v24 = (xor0 >> 16u) ^ (xor1 << 16u); + v25 = (xor1 >> 16u) ^ (xor0 << 16u); + + // c = c + d + o0 = v22 + v24; + o1 = v23 + v25; + o1 = o1 + select(0u, 1u, o0 < v22); + v22 = o0; + v23 = o1; + + // b = rotr64(b ^ c, 63) + xor0 = v12 ^ v22; + xor1 = v13 ^ v23; + v12 = (xor1 >> 31u) ^ (xor0 << 1u); + v13 = (xor0 >> 31u) ^ (xor1 << 1u); + + + + + + /** + * r=1, i=6(x2), a=v[4-5], b=v[14-15], c=v[16-17], d=v[26-27] + */ + + // a = a + b + o0 = v4 + v14; + o1 = v5 + v15; + o1 = o1 + select(0u, 1u, o0 < v4); + v4 = o0; + v5 = o1; + + // // a = a + m[sigma[r][2*i+0]] + // // skip since adding 0u does nothing + // o0 = v4 + 0u; + // o1 = v5 + 0u; + // if (v4 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v4 = o0; + // v5 = o1; + + // d = rotr64(d ^ a, 32) + xor0 = v26 ^ v4; + xor1 = v27 ^ v5; + v26 = xor1; + v27 = xor0; + + // c = c + d + o0 = v16 + v26; + o1 = v17 + v27; + o1 = o1 + select(0u, 1u, o0 < v16); + v16 = o0; + v17 = o1; + + // b = rotr64(b ^ c, 24) + xor0 = v14 ^ v16; + xor1 = v15 ^ v17; + v14 = (xor0 >> 24u) ^ (xor1 << 8u); + v15 = (xor1 >> 24u) ^ (xor0 << 8u); + + // a = a + b + o0 = v4 + v14; + o1 = v5 + v15; + o1 = o1 + select(0u, 1u, o0 < v4); + v4 = o0; + v5 = o1; + + // // a = a + m[sigma[r][2*i+1]] + // // skip since adding 0u does nothing + // o0 = v4 + 0u; + // o1 = v5 + 0u; + // if (v4 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v4 = o0; + // v5 = o1; + + // d = rotr64(d ^ a, 16) + xor0 = v26 ^ v4; + xor1 = v27 ^ v5; + v26 = (xor0 >> 16u) ^ (xor1 << 16u); + v27 = (xor1 >> 16u) ^ (xor0 << 16u); + + // c = c + d + o0 = v16 + v26; + o1 = v17 + v27; + o1 = o1 + select(0u, 1u, o0 < v16); + v16 = o0; + v17 = o1; + + // b = rotr64(b ^ c, 63) + xor0 = v14 ^ v16; + xor1 = v15 ^ v17; + v14 = (xor1 >> 31u) ^ (xor0 << 1u); + v15 = (xor0 >> 31u) ^ (xor1 << 1u); + + + + + + /** + * r=1, i=7(x2), a=v[6-7], b=v[8-9], c=v[18-19], d=v[28-29] + */ + + // a = a + b + o0 = v6 + v8; + o1 = v7 + v9; + o1 = o1 + select(0u, 1u, o0 < v6); + v6 = o0; + v7 = o1; + + // // a = a + m[sigma[r][2*i+0]] + // // skip since adding 0u does nothing + // o0 = v6 + 0u; + // o1 = v7 + 0u; + // if (v6 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v6 = o0; + // v7 = o1; + + // d = rotr64(d ^ a, 32) + xor0 = v28 ^ v6; + xor1 = v29 ^ v7; + v28 = xor1; + v29 = xor0; + + // c = c + d + o0 = v18 + v28; + o1 = v19 + v29; + o1 = o1 + select(0u, 1u, o0 < v18); + v18 = o0; + v19 = o1; + + // b = rotr64(b ^ c, 24) + xor0 = v8 ^ v18; + xor1 = v9 ^ v19; + v8 = (xor0 >> 24u) ^ (xor1 << 8u); + v9 = (xor1 >> 24u) ^ (xor0 << 8u); + + // a = a + b + o0 = v6 + v8; + o1 = v7 + v9; + o1 = o1 + select(0u, 1u, o0 < v6); + v6 = o0; + v7 = o1; + + // a = a + m[sigma[r][2*i+1]] + o0 = v6 + m6; + o1 = v7 + m7; + o1 = o1 + select(0u, 1u, o0 < v6); + v6 = o0; + v7 = o1; + + // d = rotr64(d ^ a, 16) + xor0 = v28 ^ v6; + xor1 = v29 ^ v7; + v28 = (xor0 >> 16u) ^ (xor1 << 16u); + v29 = (xor1 >> 16u) ^ (xor0 << 16u); + + // c = c + d + o0 = v18 + v28; + o1 = v19 + v29; + o1 = o1 + select(0u, 1u, o0 < v18); + v18 = o0; + v19 = o1; + + // b = rotr64(b ^ c, 63) + xor0 = v8 ^ v18; + xor1 = v9 ^ v19; + v8 = (xor1 >> 31u) ^ (xor0 << 1u); + v9 = (xor0 >> 31u) ^ (xor1 << 1u); + + + + + + /**************************************************************************** + * ROUND(2) * + ****************************************************************************/ + + /** + * r=2, i=0(x2), a=v[0-1], b=v[8-9], c=v[16-17], d=v[24-25] + */ + + // a = a + b + o0 = v0 + v8; + o1 = v1 + v9; + o1 = o1 + select(0u, 1u, o0 < v0); + v0 = o0; + v1 = o1; + + // // a = a + m[sigma[r][2*i+0]] + // // skip since adding 0u does nothing + // o0 = v0 + 0u; + // o1 = v1 + 0u; + // if (v0 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v0 = o0; + // v1 = o1; + + // d = rotr64(d ^ a, 32) + xor0 = v24 ^ v0; + xor1 = v25 ^ v1; + v24 = xor1; + v25 = xor0; + + // c = c + d + o0 = v16 + v24; + o1 = v17 + v25; + o1 = o1 + select(0u, 1u, o0 < v16); + v16 = o0; + v17 = o1; + + // b = rotr64(b ^ c, 24) + xor0 = v8 ^ v16; + xor1 = v9 ^ v17; + v8 = (xor0 >> 24u) ^ (xor1 << 8u); + v9 = (xor1 >> 24u) ^ (xor0 << 8u); + + // a = a + b + o0 = v0 + v8; + o1 = v1 + v9; + o1 = o1 + select(0u, 1u, o0 < v0); + v0 = o0; + v1 = o1; + + // // a = a + m[sigma[r][2*i+1]] + // // skip since adding 0u does nothing + // o0 = v0 + 0u; + // o1 = v1 + 0u; + // if (v0 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v0 = o0; + // v1 = o1; + + // d = rotr64(d ^ a, 16) + xor0 = v24 ^ v0; + xor1 = v25 ^ v1; + v24 = (xor0 >> 16u) ^ (xor1 << 16u); + v25 = (xor1 >> 16u) ^ (xor0 << 16u); + + // c = c + d + o0 = v16 + v24; + o1 = v17 + v25; + o1 = o1 + select(0u, 1u, o0 < v16); + v16 = o0; + v17 = o1; + + // b = rotr64(b ^ c, 63) + xor0 = v8 ^ v16; + xor1 = v9 ^ v17; + v8 = (xor1 >> 31u) ^ (xor0 << 1u); + v9 = (xor0 >> 31u) ^ (xor1 << 1u); + + + + + + /** + * r=2, i=1(x2), a=v[2-3], b=v[10-11], c=v[18-19], d=v[26-27] + */ + + // a = a + b + o0 = v2 + v10; + o1 = v3 + v11; + o1 = o1 + select(0u, 1u, o0 < v2); + v2 = o0; + v3 = o1; + + // // a = a + m[sigma[r][2*i+0]] + // // skip since adding 0u does nothing + // o0 = v2 + 0u; + // o1 = v3 + 0u; + // if (v2 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v2 = o0; + // v3 = o1; + + // d = rotr64(d ^ a, 32) + xor0 = v26 ^ v2; + xor1 = v27 ^ v3; + v26 = xor1; + v27 = xor0; + + // c = c + d + o0 = v18 + v26; + o1 = v19 + v27; + o1 = o1 + select(0u, 1u, o0 < v18); + v18 = o0; + v19 = o1; + + // b = rotr64(b ^ c, 24) + xor0 = v10 ^ v18; + xor1 = v11 ^ v19; + v10 = (xor0 >> 24u) ^ (xor1 << 8u); + v11 = (xor1 >> 24u) ^ (xor0 << 8u); + + // a = a + b + o0 = v2 + v10; + o1 = v3 + v11; + o1 = o1 + select(0u, 1u, o0 < v2); + v2 = o0; + v3 = o1; + + // a = a + m[sigma[r][2*i+1]] + o0 = v2 + m0; + o1 = v3 + m1; + o1 = o1 + select(0u, 1u, o0 < v2); + v2 = o0; + v3 = o1; + + // d = rotr64(d ^ a, 16) + xor0 = v26 ^ v2; + xor1 = v27 ^ v3; + v26 = (xor0 >> 16u) ^ (xor1 << 16u); + v27 = (xor1 >> 16u) ^ (xor0 << 16u); + + // c = c + d + o0 = v18 + v26; + o1 = v19 + v27; + o1 = o1 + select(0u, 1u, o0 < v18); + v18 = o0; + v19 = o1; + + // b = rotr64(b ^ c, 63) + xor0 = v10 ^ v18; + xor1 = v11 ^ v19; + v10 = (xor1 >> 31u) ^ (xor0 << 1u); + v11 = (xor0 >> 31u) ^ (xor1 << 1u); + + + + + + /** + * r=2, i=2(x2), a=v[4-5], b=v[12-13], c=v[20-21], d=v[28-29] + */ + + // a = a + b + o0 = v4 + v12; + o1 = v5 + v13; + o1 = o1 + select(0u, 1u, o0 < v4); + v4 = o0; + v5 = o1; + + // // a = a + m[sigma[r][2*i+0]] + // // skip since adding 0u does nothing + // o0 = v4 + 0u; + // o1 = v5 + 0u; + // if (v4 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v4 = o0; + // v5 = o1; + + // d = rotr64(d ^ a, 32) + xor0 = v28 ^ v4; + xor1 = v29 ^ v5; + v28 = xor1; + v29 = xor0; + + // c = c + d + o0 = v20 + v28; + o1 = v21 + v29; + o1 = o1 + select(0u, 1u, o0 < v20); + v20 = o0; + v21 = o1; + + // b = rotr64(b ^ c, 24) + xor0 = v12 ^ v20; + xor1 = v13 ^ v21; + v12 = (xor0 >> 24u) ^ (xor1 << 8u); + v13 = (xor1 >> 24u) ^ (xor0 << 8u); + + // a = a + b + o0 = v4 + v12; + o1 = v5 + v13; + o1 = o1 + select(0u, 1u, o0 < v4); + v4 = o0; + v5 = o1; + + // a = a + m[sigma[r][2*i+1]] + o0 = v4 + m4; + o1 = v5 + m5; + o1 = o1 + select(0u, 1u, o0 < v4); + v4 = o0; + v5 = o1; + + // d = rotr64(d ^ a, 16) + xor0 = v28 ^ v4; + xor1 = v29 ^ v5; + v28 = (xor0 >> 16u) ^ (xor1 << 16u); + v29 = (xor1 >> 16u) ^ (xor0 << 16u); + + // c = c + d + o0 = v20 + v28; + o1 = v21 + v29; + o1 = o1 + select(0u, 1u, o0 < v20); + v20 = o0; + v21 = o1; + + // b = rotr64(b ^ c, 63) + xor0 = v12 ^ v20; + xor1 = v13 ^ v21; + v12 = (xor1 >> 31u) ^ (xor0 << 1u); + v13 = (xor0 >> 31u) ^ (xor1 << 1u); + + + + + + /** + * r=2, i=3(x2), a=v[6-7], b=v[14-15], c=v[22-23], d=v[30-31] + */ + + // a = a + b + o0 = v6 + v14; + o1 = v7 + v15; + o1 = o1 + select(0u, 1u, o0 < v6); + v6 = o0; + v7 = o1; + + // // a = a + m[sigma[r][2*i+0]] + // // skip since adding 0u does nothing + // o0 = v6 + 0u; + // o1 = v7 + 0u; + // if (v6 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v6 = o0; + // v7 = o1; + + // d = rotr64(d ^ a, 32) + xor0 = v30 ^ v6; + xor1 = v31 ^ v7; + v30 = xor1; + v31 = xor0; + + // c = c + d + o0 = v22 + v30; + o1 = v23 + v31; + o1 = o1 + select(0u, 1u, o0 < v22); + v22 = o0; + v23 = o1; + + // b = rotr64(b ^ c, 24) + xor0 = v14 ^ v22; + xor1 = v15 ^ v23; + v14 = (xor0 >> 24u) ^ (xor1 << 8u); + v15 = (xor1 >> 24u) ^ (xor0 << 8u); + + // a = a + b + o0 = v6 + v14; + o1 = v7 + v15; + o1 = o1 + select(0u, 1u, o0 < v6); + v6 = o0; + v7 = o1; + + // // a = a + m[sigma[r][2*i+1]] + // // skip since adding 0u does nothing + // o0 = v6 + 0u; + // o1 = v7 + 0u; + // if (v6 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v6 = o0; + // v7 = o1; + + // d = rotr64(d ^ a, 16) + xor0 = v30 ^ v6; + xor1 = v31 ^ v7; + v30 = (xor0 >> 16u) ^ (xor1 << 16u); + v31 = (xor1 >> 16u) ^ (xor0 << 16u); + + // c = c + d + o0 = v22 + v30; + o1 = v23 + v31; + o1 = o1 + select(0u, 1u, o0 < v22); + v22 = o0; + v23 = o1; + + // b = rotr64(b ^ c, 63) + xor0 = v14 ^ v22; + xor1 = v15 ^ v23; + v14 = (xor1 >> 31u) ^ (xor0 << 1u); + v15 = (xor0 >> 31u) ^ (xor1 << 1u); + + + + + + /** + * r=2, i=4(x2), a=v[0-1], b=v[10-11], c=v[20-21], d=v[30-31] + */ + + // a = a + b + o0 = v0 + v10; + o1 = v1 + v11; + o1 = o1 + select(0u, 1u, o0 < v0); + v0 = o0; + v1 = o1; + + // // a = a + m[sigma[r][2*i+0]] + // // skip since adding 0u does nothing + // o0 = v0 + 0u; + // o1 = v1 + 0u; + // if (v0 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v0 = o0; + // v1 = o1; + + // d = rotr64(d ^ a, 32) + xor0 = v30 ^ v0; + xor1 = v31 ^ v1; + v30 = xor1; + v31 = xor0; + + // c = c + d + o0 = v20 + v30; + o1 = v21 + v31; + o1 = o1 + select(0u, 1u, o0 < v20); + v20 = o0; + v21 = o1; + + // b = rotr64(b ^ c, 24) + xor0 = v10 ^ v20; + xor1 = v11 ^ v21; + v10 = (xor0 >> 24u) ^ (xor1 << 8u); + v11 = (xor1 >> 24u) ^ (xor0 << 8u); + + // a = a + b + o0 = v0 + v10; + o1 = v1 + v11; + o1 = o1 + select(0u, 1u, o0 < v0); + v0 = o0; + v1 = o1; + + // // a = a + m[sigma[r][2*i+1]] + // // skip since adding 0u does nothing + // o0 = v0 + 0u; + // o1 = v1 + 0u; + // if (v0 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v0 = o0; + // v1 = o1; + + // d = rotr64(d ^ a, 16) + xor0 = v30 ^ v0; + xor1 = v31 ^ v1; + v30 = (xor0 >> 16u) ^ (xor1 << 16u); + v31 = (xor1 >> 16u) ^ (xor0 << 16u); + + // c = c + d + o0 = v20 + v30; + o1 = v21 + v31; + o1 = o1 + select(0u, 1u, o0 < v20); + v20 = o0; + v21 = o1; + + // b = rotr64(b ^ c, 63) + xor0 = v10 ^ v20; + xor1 = v11 ^ v21; + v10 = (xor1 >> 31u) ^ (xor0 << 1u); + v11 = (xor0 >> 31u) ^ (xor1 << 1u); + + + + + + /** + * r=2, i=5(x2), a=v[2-3], b=v[12-13], c=v[22-23], d=v[24-25] + */ + + // a = a + b + o0 = v2 + v12; + o1 = v3 + v13; + o1 = o1 + select(0u, 1u, o0 < v2); + v2 = o0; + v3 = o1; + + // a = a + m[sigma[r][2*i+0]] + o0 = v2 + m6; + o1 = v3 + m7; + o1 = o1 + select(0u, 1u, o0 < v2); + v2 = o0; + v3 = o1; + + // d = rotr64(d ^ a, 32) + xor0 = v24 ^ v2; + xor1 = v25 ^ v3; + v24 = xor1; + v25 = xor0; + + // c = c + d + o0 = v22 + v24; + o1 = v23 + v25; + o1 = o1 + select(0u, 1u, o0 < v22); + v22 = o0; + v23 = o1; + + // b = rotr64(b ^ c, 24) + xor0 = v12 ^ v22; + xor1 = v13 ^ v23; + v12 = (xor0 >> 24u) ^ (xor1 << 8u); + v13 = (xor1 >> 24u) ^ (xor0 << 8u); + + // a = a + b + o0 = v2 + v12; + o1 = v3 + v13; + o1 = o1 + select(0u, 1u, o0 < v2); + v2 = o0; + v3 = o1; + + // // a = a + m[sigma[r][2*i+1]] + // // skip since adding 0u does nothing + // o0 = v2 + 0u; + // o1 = v3 + 0u; + // if (v2 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v2 = o0; + // v3 = o1; + + // d = rotr64(d ^ a, 16) + xor0 = v24 ^ v2; + xor1 = v25 ^ v3; + v24 = (xor0 >> 16u) ^ (xor1 << 16u); + v25 = (xor1 >> 16u) ^ (xor0 << 16u); + + // c = c + d + o0 = v22 + v24; + o1 = v23 + v25; + o1 = o1 + select(0u, 1u, o0 < v22); + v22 = o0; + v23 = o1; + + // b = rotr64(b ^ c, 63) + xor0 = v12 ^ v22; + xor1 = v13 ^ v23; + v12 = (xor1 >> 31u) ^ (xor0 << 1u); + v13 = (xor0 >> 31u) ^ (xor1 << 1u); + + + + + + /** + * r=2, i=6(x2), a=v[4-5], b=v[14-15], c=v[16-17], d=v[26-27] + */ + + // a = a + b + o0 = v4 + v14; + o1 = v5 + v15; + o1 = o1 + select(0u, 1u, o0 < v4); + v4 = o0; + v5 = o1; + + // // a = a + m[sigma[r][2*i+0]] + // // skip since adding 0u does nothing + // o0 = v4 + 0u; + // o1 = v5 + 0u; + // if (v4 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v4 = o0; + // v5 = o1; + + // d = rotr64(d ^ a, 32) + xor0 = v26 ^ v4; + xor1 = v27 ^ v5; + v26 = xor1; + v27 = xor0; + + // c = c + d + o0 = v16 + v26; + o1 = v17 + v27; + o1 = o1 + select(0u, 1u, o0 < v16); + v16 = o0; + v17 = o1; + + // b = rotr64(b ^ c, 24) + xor0 = v14 ^ v16; + xor1 = v15 ^ v17; + v14 = (xor0 >> 24u) ^ (xor1 << 8u); + v15 = (xor1 >> 24u) ^ (xor0 << 8u); + + // a = a + b + o0 = v4 + v14; + o1 = v5 + v15; + o1 = o1 + select(0u, 1u, o0 < v4); + v4 = o0; + v5 = o1; + + // a = a + m[sigma[r][2*i+1]] + o0 = v4 + m2; + o1 = v5 + m3; + o1 = o1 + select(0u, 1u, o0 < v4); + v4 = o0; + v5 = o1; + + // d = rotr64(d ^ a, 16) + xor0 = v26 ^ v4; + xor1 = v27 ^ v5; + v26 = (xor0 >> 16u) ^ (xor1 << 16u); + v27 = (xor1 >> 16u) ^ (xor0 << 16u); + + // c = c + d + o0 = v16 + v26; + o1 = v17 + v27; + o1 = o1 + select(0u, 1u, o0 < v16); + v16 = o0; + v17 = o1; + + // b = rotr64(b ^ c, 63) + xor0 = v14 ^ v16; + xor1 = v15 ^ v17; + v14 = (xor1 >> 31u) ^ (xor0 << 1u); + v15 = (xor0 >> 31u) ^ (xor1 << 1u); + + + + + + /** + * r=2, i=7(x2), a=v[6-7], b=v[8-9], c=v[18-19], d=v[28-29] + */ + + // a = a + b + o0 = v6 + v8; + o1 = v7 + v9; + o1 = o1 + select(0u, 1u, o0 < v6); + v6 = o0; + v7 = o1; + + // // a = a + m[sigma[r][2*i+0]] + // // skip since adding 0u does nothing + // o0 = v6 + 0u; + // o1 = v7 + 0u; + // if (v6 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v6 = o0; + // v7 = o1; + + // d = rotr64(d ^ a, 32) + xor0 = v28 ^ v6; + xor1 = v29 ^ v7; + v28 = xor1; + v29 = xor0; + + // c = c + d + o0 = v18 + v28; + o1 = v19 + v29; + o1 = o1 + select(0u, 1u, o0 < v18); + v18 = o0; + v19 = o1; + + // b = rotr64(b ^ c, 24) + xor0 = v8 ^ v18; + xor1 = v9 ^ v19; + v8 = (xor0 >> 24u) ^ (xor1 << 8u); + v9 = (xor1 >> 24u) ^ (xor0 << 8u); + + // a = a + b + o0 = v6 + v8; + o1 = v7 + v9; + o1 = o1 + select(0u, 1u, o0 < v6); + v6 = o0; + v7 = o1; + + // a = a + m[sigma[r][2*i+1]] + o0 = v6 + m8; + o1 = v7 + m9; + o1 = o1 + select(0u, 1u, o0 < v6); + v6 = o0; + v7 = o1; + + // d = rotr64(d ^ a, 16) + xor0 = v28 ^ v6; + xor1 = v29 ^ v7; + v28 = (xor0 >> 16u) ^ (xor1 << 16u); + v29 = (xor1 >> 16u) ^ (xor0 << 16u); + + // c = c + d + o0 = v18 + v28; + o1 = v19 + v29; + o1 = o1 + select(0u, 1u, o0 < v18); + v18 = o0; + v19 = o1; + + // b = rotr64(b ^ c, 63) + xor0 = v8 ^ v18; + xor1 = v9 ^ v19; + v8 = (xor1 >> 31u) ^ (xor0 << 1u); + v9 = (xor0 >> 31u) ^ (xor1 << 1u); + + + + + + /**************************************************************************** + * ROUND(3) * + ****************************************************************************/ + + /** + * r=3, i=0(x2), a=v[0-1], b=v[8-9], c=v[16-17], d=v[24-25] + */ + + // a = a + b + o0 = v0 + v8; + o1 = v1 + v9; + o1 = o1 + select(0u, 1u, o0 < v0); + v0 = o0; + v1 = o1; + + // // a = a + m[sigma[r][2*i+0]] + // // skip since adding 0u does nothing + // o0 = v0 + 0u; + // o1 = v1 + 0u; + // if (v0 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v0 = o0; + // v1 = o1; + + // d = rotr64(d ^ a, 32) + xor0 = v24 ^ v0; + xor1 = v25 ^ v1; + v24 = xor1; + v25 = xor0; + + // c = c + d + o0 = v16 + v24; + o1 = v17 + v25; + o1 = o1 + select(0u, 1u, o0 < v16); + v16 = o0; + v17 = o1; + + // b = rotr64(b ^ c, 24) + xor0 = v8 ^ v16; + xor1 = v9 ^ v17; + v8 = (xor0 >> 24u) ^ (xor1 << 8u); + v9 = (xor1 >> 24u) ^ (xor0 << 8u); + + // a = a + b + o0 = v0 + v8; + o1 = v1 + v9; + o1 = o1 + select(0u, 1u, o0 < v0); + v0 = o0; + v1 = o1; + + // // a = a + m[sigma[r][2*i+1]] + // // skip since adding 0u does nothing + // o0 = v0 + 0u; + // o1 = v1 + 0u; + // if (v0 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v0 = o0; + // v1 = o1; + + // d = rotr64(d ^ a, 16) + xor0 = v24 ^ v0; + xor1 = v25 ^ v1; + v24 = (xor0 >> 16u) ^ (xor1 << 16u); + v25 = (xor1 >> 16u) ^ (xor0 << 16u); + + // c = c + d + o0 = v16 + v24; + o1 = v17 + v25; + o1 = o1 + select(0u, 1u, o0 < v16); + v16 = o0; + v17 = o1; + + // b = rotr64(b ^ c, 63) + xor0 = v8 ^ v16; + xor1 = v9 ^ v17; + v8 = (xor1 >> 31u) ^ (xor0 << 1u); + v9 = (xor0 >> 31u) ^ (xor1 << 1u); + + + + + + /** + * r=3, i=1(x2), a=v[2-3], b=v[10-11], c=v[18-19], d=v[26-27] + */ + + // a = a + b + o0 = v2 + v10; + o1 = v3 + v11; + o1 = o1 + select(0u, 1u, o0 < v2); + v2 = o0; + v3 = o1; + + // a = a + m[sigma[r][2*i+0]] + o0 = v2 + m6; + o1 = v3 + m7; + o1 = o1 + select(0u, 1u, o0 < v2); + v2 = o0; + v3 = o1; + + // d = rotr64(d ^ a, 32) + xor0 = v26 ^ v2; + xor1 = v27 ^ v3; + v26 = xor1; + v27 = xor0; + + // c = c + d + o0 = v18 + v26; + o1 = v19 + v27; + o1 = o1 + select(0u, 1u, o0 < v18); + v18 = o0; + v19 = o1; + + // b = rotr64(b ^ c, 24) + xor0 = v10 ^ v18; + xor1 = v11 ^ v19; + v10 = (xor0 >> 24u) ^ (xor1 << 8u); + v11 = (xor1 >> 24u) ^ (xor0 << 8u); + + // a = a + b + o0 = v2 + v10; + o1 = v3 + v11; + o1 = o1 + select(0u, 1u, o0 < v2); + v2 = o0; + v3 = o1; + + // a = a + m[sigma[r][2*i+1]] + o0 = v2 + m2; + o1 = v3 + m3; + o1 = o1 + select(0u, 1u, o0 < v2); + v2 = o0; + v3 = o1; + + // d = rotr64(d ^ a, 16) + xor0 = v26 ^ v2; + xor1 = v27 ^ v3; + v26 = (xor0 >> 16u) ^ (xor1 << 16u); + v27 = (xor1 >> 16u) ^ (xor0 << 16u); + + // c = c + d + o0 = v18 + v26; + o1 = v19 + v27; + o1 = o1 + select(0u, 1u, o0 < v18); + v18 = o0; + v19 = o1; + + // b = rotr64(b ^ c, 63) + xor0 = v10 ^ v18; + xor1 = v11 ^ v19; + v10 = (xor1 >> 31u) ^ (xor0 << 1u); + v11 = (xor0 >> 31u) ^ (xor1 << 1u); + + + + + + /** + * r=3, i=2(x2), a=v[4-5], b=v[12-13], c=v[20-21], d=v[28-29] + */ + + // a = a + b + o0 = v4 + v12; + o1 = v5 + v13; + o1 = o1 + select(0u, 1u, o0 < v4); + v4 = o0; + v5 = o1; + + // // a = a + m[sigma[r][2*i+0]] + // // skip since adding 0u does nothing + // o0 = v4 + 0u; + // o1 = v5 + 0u; + // if (v4 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v4 = o0; + // v5 = o1; + + // d = rotr64(d ^ a, 32) + xor0 = v28 ^ v4; + xor1 = v29 ^ v5; + v28 = xor1; + v29 = xor0; + + // c = c + d + o0 = v20 + v28; + o1 = v21 + v29; + o1 = o1 + select(0u, 1u, o0 < v20); + v20 = o0; + v21 = o1; + + // b = rotr64(b ^ c, 24) + xor0 = v12 ^ v20; + xor1 = v13 ^ v21; + v12 = (xor0 >> 24u) ^ (xor1 << 8u); + v13 = (xor1 >> 24u) ^ (xor0 << 8u); + + // a = a + b + o0 = v4 + v12; + o1 = v5 + v13; + o1 = o1 + select(0u, 1u, o0 < v4); + v4 = o0; + v5 = o1; + + // // a = a + m[sigma[r][2*i+1]] + // // skip since adding 0u does nothing + // o0 = v4 + 0u; + // o1 = v5 + 0u; + // if (v4 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v4 = o0; + // v5 = o1; + + // d = rotr64(d ^ a, 16) + xor0 = v28 ^ v4; + xor1 = v29 ^ v5; + v28 = (xor0 >> 16u) ^ (xor1 << 16u); + v29 = (xor1 >> 16u) ^ (xor0 << 16u); + + // c = c + d + o0 = v20 + v28; + o1 = v21 + v29; + o1 = o1 + select(0u, 1u, o0 < v20); + v20 = o0; + v21 = o1; + + // b = rotr64(b ^ c, 63) + xor0 = v12 ^ v20; + xor1 = v13 ^ v21; + v12 = (xor1 >> 31u) ^ (xor0 << 1u); + v13 = (xor0 >> 31u) ^ (xor1 << 1u); + + + + + + /** + * r=3, i=3(x2), a=v[6-7], b=v[14-15], c=v[22-23], d=v[30-31] + */ + + // a = a + b + o0 = v6 + v14; + o1 = v7 + v15; + o1 = o1 + select(0u, 1u, o0 < v6); + v6 = o0; + v7 = o1; + + // // a = a + m[sigma[r][2*i+0]] + // // skip since adding 0u does nothing + // o0 = v6 + 0u; + // o1 = v7 + 0u; + // if (v6 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v6 = o0; + // v7 = o1; + + // d = rotr64(d ^ a, 32) + xor0 = v30 ^ v6; + xor1 = v31 ^ v7; + v30 = xor1; + v31 = xor0; + + // c = c + d + o0 = v22 + v30; + o1 = v23 + v31; + o1 = o1 + select(0u, 1u, o0 < v22); + v22 = o0; + v23 = o1; + + // b = rotr64(b ^ c, 24) + xor0 = v14 ^ v22; + xor1 = v15 ^ v23; + v14 = (xor0 >> 24u) ^ (xor1 << 8u); + v15 = (xor1 >> 24u) ^ (xor0 << 8u); + + // a = a + b + o0 = v6 + v14; + o1 = v7 + v15; + o1 = o1 + select(0u, 1u, o0 < v6); + v6 = o0; + v7 = o1; + + // // a = a + m[sigma[r][2*i+1]] + // // skip since adding 0u does nothing + // o0 = v6 + 0u; + // o1 = v7 + 0u; + // if (v6 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v6 = o0; + // v7 = o1; + + // d = rotr64(d ^ a, 16) + xor0 = v30 ^ v6; + xor1 = v31 ^ v7; + v30 = (xor0 >> 16u) ^ (xor1 << 16u); + v31 = (xor1 >> 16u) ^ (xor0 << 16u); + + // c = c + d + o0 = v22 + v30; + o1 = v23 + v31; + o1 = o1 + select(0u, 1u, o0 < v22); + v22 = o0; + v23 = o1; + + // b = rotr64(b ^ c, 63) + xor0 = v14 ^ v22; + xor1 = v15 ^ v23; + v14 = (xor1 >> 31u) ^ (xor0 << 1u); + v15 = (xor0 >> 31u) ^ (xor1 << 1u); + + + + + + /** + * r=3, i=4(x2), a=v[0-1], b=v[10-11], c=v[20-21], d=v[30-31] + */ + + // a = a + b + o0 = v0 + v10; + o1 = v1 + v11; + o1 = o1 + select(0u, 1u, o0 < v0); + v0 = o0; + v1 = o1; + + // a = a + m[sigma[r][2*i+0]] + o0 = v0 + m4; + o1 = v1 + m5; + o1 = o1 + select(0u, 1u, o0 < v0); + v0 = o0; + v1 = o1; + + // d = rotr64(d ^ a, 32) + xor0 = v30 ^ v0; + xor1 = v31 ^ v1; + v30 = xor1; + v31 = xor0; + + // c = c + d + o0 = v20 + v30; + o1 = v21 + v31; + o1 = o1 + select(0u, 1u, o0 < v20); + v20 = o0; + v21 = o1; + + // b = rotr64(b ^ c, 24) + xor0 = v10 ^ v20; + xor1 = v11 ^ v21; + v10 = (xor0 >> 24u) ^ (xor1 << 8u); + v11 = (xor1 >> 24u) ^ (xor0 << 8u); + + // a = a + b + o0 = v0 + v10; + o1 = v1 + v11; + o1 = o1 + select(0u, 1u, o0 < v0); + v0 = o0; + v1 = o1; + + // // a = a + m[sigma[r][2*i+1]] + // // skip since adding 0u does nothing + // o0 = v0 + 0u; + // o1 = v1 + 0u; + // if (v0 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v0 = o0; + // v1 = o1; + + // d = rotr64(d ^ a, 16) + xor0 = v30 ^ v0; + xor1 = v31 ^ v1; + v30 = (xor0 >> 16u) ^ (xor1 << 16u); + v31 = (xor1 >> 16u) ^ (xor0 << 16u); + + // c = c + d + o0 = v20 + v30; + o1 = v21 + v31; + o1 = o1 + select(0u, 1u, o0 < v20); + v20 = o0; + v21 = o1; + + // b = rotr64(b ^ c, 63) + xor0 = v10 ^ v20; + xor1 = v11 ^ v21; + v10 = (xor1 >> 31u) ^ (xor0 << 1u); + v11 = (xor0 >> 31u) ^ (xor1 << 1u); + + + + + + /** + * r=3, i=5(x2), a=v[2-3], b=v[12-13], c=v[22-23], d=v[24-25] + */ + + // a = a + b + o0 = v2 + v12; + o1 = v3 + v13; + o1 = o1 + select(0u, 1u, o0 < v2); + v2 = o0; + v3 = o1; + + // // a = a + m[sigma[r][2*i+0]] + // // skip since adding 0u does nothing + // o0 = v2 + 0u; + // o1 = v3 + 0u; + // if (v2 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v2 = o0; + // v3 = o1; + + // d = rotr64(d ^ a, 32) + xor0 = v24 ^ v2; + xor1 = v25 ^ v3; + v24 = xor1; + v25 = xor0; + + // c = c + d + o0 = v22 + v24; + o1 = v23 + v25; + o1 = o1 + select(0u, 1u, o0 < v22); + v22 = o0; + v23 = o1; + + // b = rotr64(b ^ c, 24) + xor0 = v12 ^ v22; + xor1 = v13 ^ v23; + v12 = (xor0 >> 24u) ^ (xor1 << 8u); + v13 = (xor1 >> 24u) ^ (xor0 << 8u); + + // a = a + b + o0 = v2 + v12; + o1 = v3 + v13; + o1 = o1 + select(0u, 1u, o0 < v2); + v2 = o0; + v3 = o1; + + // // a = a + m[sigma[r][2*i+1]] + // // skip since adding 0u does nothing + // o0 = v2 + 0u; + // o1 = v3 + 0u; + // if (v2 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v2 = o0; + // v3 = o1; + + // d = rotr64(d ^ a, 16) + xor0 = v24 ^ v2; + xor1 = v25 ^ v3; + v24 = (xor0 >> 16u) ^ (xor1 << 16u); + v25 = (xor1 >> 16u) ^ (xor0 << 16u); + + // c = c + d + o0 = v22 + v24; + o1 = v23 + v25; + o1 = o1 + select(0u, 1u, o0 < v22); + v22 = o0; + v23 = o1; + + // b = rotr64(b ^ c, 63) + xor0 = v12 ^ v22; + xor1 = v13 ^ v23; + v12 = (xor1 >> 31u) ^ (xor0 << 1u); + v13 = (xor0 >> 31u) ^ (xor1 << 1u); + + + + + + /** + * r=3, i=6(x2), a=v[4-5], b=v[14-15], c=v[16-17], d=v[26-27] + */ + + // a = a + b + o0 = v4 + v14; + o1 = v5 + v15; + o1 = o1 + select(0u, 1u, o0 < v4); + v4 = o0; + v5 = o1; + + // a = a + m[sigma[r][2*i+0]] + o0 = v4 + m8; + o1 = v5 + m9; + o1 = o1 + select(0u, 1u, o0 < v4); + v4 = o0; + v5 = o1; + + // d = rotr64(d ^ a, 32) + xor0 = v26 ^ v4; + xor1 = v27 ^ v5; + v26 = xor1; + v27 = xor0; + + // c = c + d + o0 = v16 + v26; + o1 = v17 + v27; + o1 = o1 + select(0u, 1u, o0 < v16); + v16 = o0; + v17 = o1; + + // b = rotr64(b ^ c, 24) + xor0 = v14 ^ v16; + xor1 = v15 ^ v17; + v14 = (xor0 >> 24u) ^ (xor1 << 8u); + v15 = (xor1 >> 24u) ^ (xor0 << 8u); + + // a = a + b + o0 = v4 + v14; + o1 = v5 + v15; + o1 = o1 + select(0u, 1u, o0 < v4); + v4 = o0; + v5 = o1; + + // a = a + m[sigma[r][2*i+1]] + o0 = v4 + m0; + o1 = v5 + m1; + o1 = o1 + select(0u, 1u, o0 < v4); + v4 = o0; + v5 = o1; + + // d = rotr64(d ^ a, 16) + xor0 = v26 ^ v4; + xor1 = v27 ^ v5; + v26 = (xor0 >> 16u) ^ (xor1 << 16u); + v27 = (xor1 >> 16u) ^ (xor0 << 16u); + + // c = c + d + o0 = v16 + v26; + o1 = v17 + v27; + o1 = o1 + select(0u, 1u, o0 < v16); + v16 = o0; + v17 = o1; + + // b = rotr64(b ^ c, 63) + xor0 = v14 ^ v16; + xor1 = v15 ^ v17; + v14 = (xor1 >> 31u) ^ (xor0 << 1u); + v15 = (xor0 >> 31u) ^ (xor1 << 1u); + + + + + + /** + * r=3, i=7(x2), a=v[6-7], b=v[8-9], c=v[18-19], d=v[28-29] + */ + + // a = a + b + o0 = v6 + v8; + o1 = v7 + v9; + o1 = o1 + select(0u, 1u, o0 < v6); + v6 = o0; + v7 = o1; + + // // a = a + m[sigma[r][2*i+0]] + // // skip since adding 0u does nothing + // o0 = v6 + 0u; + // o1 = v7 + 0u; + // if (v6 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v6 = o0; + // v7 = o1; + + // d = rotr64(d ^ a, 32) + xor0 = v28 ^ v6; + xor1 = v29 ^ v7; + v28 = xor1; + v29 = xor0; + + // c = c + d + o0 = v18 + v28; + o1 = v19 + v29; + o1 = o1 + select(0u, 1u, o0 < v18); + v18 = o0; + v19 = o1; + + // b = rotr64(b ^ c, 24) + xor0 = v8 ^ v18; + xor1 = v9 ^ v19; + v8 = (xor0 >> 24u) ^ (xor1 << 8u); + v9 = (xor1 >> 24u) ^ (xor0 << 8u); + + // a = a + b + o0 = v6 + v8; + o1 = v7 + v9; + o1 = o1 + select(0u, 1u, o0 < v6); + v6 = o0; + v7 = o1; + + // // a = a + m[sigma[r][2*i+1]] + // // skip since adding 0u does nothing + // o0 = v6 + 0u; + // o1 = v7 + 0u; + // if (v6 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v6 = o0; + // v7 = o1; + + // d = rotr64(d ^ a, 16) + xor0 = v28 ^ v6; + xor1 = v29 ^ v7; + v28 = (xor0 >> 16u) ^ (xor1 << 16u); + v29 = (xor1 >> 16u) ^ (xor0 << 16u); + + // c = c + d + o0 = v18 + v28; + o1 = v19 + v29; + o1 = o1 + select(0u, 1u, o0 < v18); + v18 = o0; + v19 = o1; + + // b = rotr64(b ^ c, 63) + xor0 = v8 ^ v18; + xor1 = v9 ^ v19; + v8 = (xor1 >> 31u) ^ (xor0 << 1u); + v9 = (xor0 >> 31u) ^ (xor1 << 1u); + + + + + + /**************************************************************************** + * ROUND(4) * + ****************************************************************************/ + + /** + * r=4, i=0(x2), a=v[0-1], b=v[8-9], c=v[16-17], d=v[24-25] + */ + + // a = a + b + o0 = v0 + v8; + o1 = v1 + v9; + o1 = o1 + select(0u, 1u, o0 < v0); + v0 = o0; + v1 = o1; + + // // a = a + m[sigma[r][2*i+0]] + // // skip since adding 0u does nothing + // o0 = v0 + 0u; + // o1 = v1 + 0u; + // if (v0 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v0 = o0; + // v1 = o1; + + // d = rotr64(d ^ a, 32) + xor0 = v24 ^ v0; + xor1 = v25 ^ v1; + v24 = xor1; + v25 = xor0; + + // c = c + d + o0 = v16 + v24; + o1 = v17 + v25; + o1 = o1 + select(0u, 1u, o0 < v16); + v16 = o0; + v17 = o1; + + // b = rotr64(b ^ c, 24) + xor0 = v8 ^ v16; + xor1 = v9 ^ v17; + v8 = (xor0 >> 24u) ^ (xor1 << 8u); + v9 = (xor1 >> 24u) ^ (xor0 << 8u); + + // a = a + b + o0 = v0 + v8; + o1 = v1 + v9; + o1 = o1 + select(0u, 1u, o0 < v0); + v0 = o0; + v1 = o1; + + // a = a + m[sigma[r][2*i+1]] + o0 = v0 + m0; + o1 = v1 + m1; + o1 = o1 + select(0u, 1u, o0 < v0); + v0 = o0; + v1 = o1; + + // d = rotr64(d ^ a, 16) + xor0 = v24 ^ v0; + xor1 = v25 ^ v1; + v24 = (xor0 >> 16u) ^ (xor1 << 16u); + v25 = (xor1 >> 16u) ^ (xor0 << 16u); + + // c = c + d + o0 = v16 + v24; + o1 = v17 + v25; + o1 = o1 + select(0u, 1u, o0 < v16); + v16 = o0; + v17 = o1; + + // b = rotr64(b ^ c, 63) + xor0 = v8 ^ v16; + xor1 = v9 ^ v17; + v8 = (xor1 >> 31u) ^ (xor0 << 1u); + v9 = (xor0 >> 31u) ^ (xor1 << 1u); + + + + + + /** + * r=4, i=1(x2), a=v[2-3], b=v[10-11], c=v[18-19], d=v[26-27] + */ + + // a = a + b + o0 = v2 + v10; + o1 = v3 + v11; + o1 = o1 + select(0u, 1u, o0 < v2); + v2 = o0; + v3 = o1; + + // // a = a + m[sigma[r][2*i+0]] + // // skip since adding 0u does nothing + // o0 = v2 + 0u; + // o1 = v3 + 0u; + // if (v2 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v2 = o0; + // v3 = o1; + + // d = rotr64(d ^ a, 32) + xor0 = v26 ^ v2; + xor1 = v27 ^ v3; + v26 = xor1; + v27 = xor0; + + // c = c + d + o0 = v18 + v26; + o1 = v19 + v27; + o1 = o1 + select(0u, 1u, o0 < v18); + v18 = o0; + v19 = o1; + + // b = rotr64(b ^ c, 24) + xor0 = v10 ^ v18; + xor1 = v11 ^ v19; + v10 = (xor0 >> 24u) ^ (xor1 << 8u); + v11 = (xor1 >> 24u) ^ (xor0 << 8u); + + // a = a + b + o0 = v2 + v10; + o1 = v3 + v11; + o1 = o1 + select(0u, 1u, o0 < v2); + v2 = o0; + v3 = o1; + + // // a = a + m[sigma[r][2*i+1]] + // // skip since adding 0u does nothing + // o0 = v2 + 0u; + // o1 = v3 + 0u; + // if (v2 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v2 = o0; + // v3 = o1; + + // d = rotr64(d ^ a, 16) + xor0 = v26 ^ v2; + xor1 = v27 ^ v3; + v26 = (xor0 >> 16u) ^ (xor1 << 16u); + v27 = (xor1 >> 16u) ^ (xor0 << 16u); + + // c = c + d + o0 = v18 + v26; + o1 = v19 + v27; + o1 = o1 + select(0u, 1u, o0 < v18); + v18 = o0; + v19 = o1; + + // b = rotr64(b ^ c, 63) + xor0 = v10 ^ v18; + xor1 = v11 ^ v19; + v10 = (xor1 >> 31u) ^ (xor0 << 1u); + v11 = (xor0 >> 31u) ^ (xor1 << 1u); + + + + + + /** + * r=4, i=2(x2), a=v[4-5], b=v[12-13], c=v[20-21], d=v[28-29] + */ + + // a = a + b + o0 = v4 + v12; + o1 = v5 + v13; + o1 = o1 + select(0u, 1u, o0 < v4); + v4 = o0; + v5 = o1; + + // a = a + m[sigma[r][2*i+0]] + o0 = v4 + m4; + o1 = v5 + m5; + o1 = o1 + select(0u, 1u, o0 < v4); + v4 = o0; + v5 = o1; + + // d = rotr64(d ^ a, 32) + xor0 = v28 ^ v4; + xor1 = v29 ^ v5; + v28 = xor1; + v29 = xor0; + + // c = c + d + o0 = v20 + v28; + o1 = v21 + v29; + o1 = o1 + select(0u, 1u, o0 < v20); + v20 = o0; + v21 = o1; + + // b = rotr64(b ^ c, 24) + xor0 = v12 ^ v20; + xor1 = v13 ^ v21; + v12 = (xor0 >> 24u) ^ (xor1 << 8u); + v13 = (xor1 >> 24u) ^ (xor0 << 8u); + + // a = a + b + o0 = v4 + v12; + o1 = v5 + v13; + o1 = o1 + select(0u, 1u, o0 < v4); + v4 = o0; + v5 = o1; + + // a = a + m[sigma[r][2*i+1]] + o0 = v4 + m8; + o1 = v5 + m9; + o1 = o1 + select(0u, 1u, o0 < v4); + v4 = o0; + v5 = o1; + + // d = rotr64(d ^ a, 16) + xor0 = v28 ^ v4; + xor1 = v29 ^ v5; + v28 = (xor0 >> 16u) ^ (xor1 << 16u); + v29 = (xor1 >> 16u) ^ (xor0 << 16u); + + // c = c + d + o0 = v20 + v28; + o1 = v21 + v29; + o1 = o1 + select(0u, 1u, o0 < v20); + v20 = o0; + v21 = o1; + + // b = rotr64(b ^ c, 63) + xor0 = v12 ^ v20; + xor1 = v13 ^ v21; + v12 = (xor1 >> 31u) ^ (xor0 << 1u); + v13 = (xor0 >> 31u) ^ (xor1 << 1u); + + + + + + /** + * r=4, i=3(x2), a=v[6-7], b=v[14-15], c=v[22-23], d=v[30-31] + */ + + // a = a + b + o0 = v6 + v14; + o1 = v7 + v15; + o1 = o1 + select(0u, 1u, o0 < v6); + v6 = o0; + v7 = o1; + + // // a = a + m[sigma[r][2*i+0]] + // // skip since adding 0u does nothing + // o0 = v6 + 0u; + // o1 = v7 + 0u; + // if (v6 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v6 = o0; + // v7 = o1; + + // d = rotr64(d ^ a, 32) + xor0 = v30 ^ v6; + xor1 = v31 ^ v7; + v30 = xor1; + v31 = xor0; + + // c = c + d + o0 = v22 + v30; + o1 = v23 + v31; + o1 = o1 + select(0u, 1u, o0 < v22); + v22 = o0; + v23 = o1; + + // b = rotr64(b ^ c, 24) + xor0 = v14 ^ v22; + xor1 = v15 ^ v23; + v14 = (xor0 >> 24u) ^ (xor1 << 8u); + v15 = (xor1 >> 24u) ^ (xor0 << 8u); + + // a = a + b + o0 = v6 + v14; + o1 = v7 + v15; + o1 = o1 + select(0u, 1u, o0 < v6); + v6 = o0; + v7 = o1; + + // // a = a + m[sigma[r][2*i+1]] + // // skip since adding 0u does nothing + // o0 = v6 + 0u; + // o1 = v7 + 0u; + // if (v6 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v6 = o0; + // v7 = o1; + + // d = rotr64(d ^ a, 16) + xor0 = v30 ^ v6; + xor1 = v31 ^ v7; + v30 = (xor0 >> 16u) ^ (xor1 << 16u); + v31 = (xor1 >> 16u) ^ (xor0 << 16u); + + // c = c + d + o0 = v22 + v30; + o1 = v23 + v31; + o1 = o1 + select(0u, 1u, o0 < v22); + v22 = o0; + v23 = o1; + + // b = rotr64(b ^ c, 63) + xor0 = v14 ^ v22; + xor1 = v15 ^ v23; + v14 = (xor1 >> 31u) ^ (xor0 << 1u); + v15 = (xor0 >> 31u) ^ (xor1 << 1u); + + + + + + /** + * r=4, i=4(x2), a=v[0-1], b=v[10-11], c=v[20-21], d=v[30-31] + */ + + // a = a + b + o0 = v0 + v10; + o1 = v1 + v11; + o1 = o1 + select(0u, 1u, o0 < v0); + v0 = o0; + v1 = o1; + + // // a = a + m[sigma[r][2*i+0]] + // // skip since adding 0u does nothing + // o0 = v0 + 0u; + // o1 = v1 + 0u; + // if (v0 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v0 = o0; + // v1 = o1; + + // d = rotr64(d ^ a, 32) + xor0 = v30 ^ v0; + xor1 = v31 ^ v1; + v30 = xor1; + v31 = xor0; + + // c = c + d + o0 = v20 + v30; + o1 = v21 + v31; + o1 = o1 + select(0u, 1u, o0 < v20); + v20 = o0; + v21 = o1; + + // b = rotr64(b ^ c, 24) + xor0 = v10 ^ v20; + xor1 = v11 ^ v21; + v10 = (xor0 >> 24u) ^ (xor1 << 8u); + v11 = (xor1 >> 24u) ^ (xor0 << 8u); + + // a = a + b + o0 = v0 + v10; + o1 = v1 + v11; + o1 = o1 + select(0u, 1u, o0 < v0); + v0 = o0; + v1 = o1; + + // a = a + m[sigma[r][2*i+1]] + o0 = v0 + m2; + o1 = v1 + m3; + o1 = o1 + select(0u, 1u, o0 < v0); + v0 = o0; + v1 = o1; + + // d = rotr64(d ^ a, 16) + xor0 = v30 ^ v0; + xor1 = v31 ^ v1; + v30 = (xor0 >> 16u) ^ (xor1 << 16u); + v31 = (xor1 >> 16u) ^ (xor0 << 16u); + + // c = c + d + o0 = v20 + v30; + o1 = v21 + v31; + o1 = o1 + select(0u, 1u, o0 < v20); + v20 = o0; + v21 = o1; + + // b = rotr64(b ^ c, 63) + xor0 = v10 ^ v20; + xor1 = v11 ^ v21; + v10 = (xor1 >> 31u) ^ (xor0 << 1u); + v11 = (xor0 >> 31u) ^ (xor1 << 1u); + + + + + + /** + * r=4, i=5(x2), a=v[2-3], b=v[12-13], c=v[22-23], d=v[24-25] + */ + + // a = a + b + o0 = v2 + v12; + o1 = v3 + v13; + o1 = o1 + select(0u, 1u, o0 < v2); + v2 = o0; + v3 = o1; + + // // a = a + m[sigma[r][2*i+0]] + // // skip since adding 0u does nothing + // o0 = v2 + 0u; + // o1 = v3 + 0u; + // if (v2 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v2 = o0; + // v3 = o1; + + // d = rotr64(d ^ a, 32) + xor0 = v24 ^ v2; + xor1 = v25 ^ v3; + v24 = xor1; + v25 = xor0; + + // c = c + d + o0 = v22 + v24; + o1 = v23 + v25; + o1 = o1 + select(0u, 1u, o0 < v22); + v22 = o0; + v23 = o1; + + // b = rotr64(b ^ c, 24) + xor0 = v12 ^ v22; + xor1 = v13 ^ v23; + v12 = (xor0 >> 24u) ^ (xor1 << 8u); + v13 = (xor1 >> 24u) ^ (xor0 << 8u); + + // a = a + b + o0 = v2 + v12; + o1 = v3 + v13; + o1 = o1 + select(0u, 1u, o0 < v2); + v2 = o0; + v3 = o1; + + // // a = a + m[sigma[r][2*i+1]] + // // skip since adding 0u does nothing + // o0 = v2 + 0u; + // o1 = v3 + 0u; + // if (v2 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v2 = o0; + // v3 = o1; + + // d = rotr64(d ^ a, 16) + xor0 = v24 ^ v2; + xor1 = v25 ^ v3; + v24 = (xor0 >> 16u) ^ (xor1 << 16u); + v25 = (xor1 >> 16u) ^ (xor0 << 16u); + + // c = c + d + o0 = v22 + v24; + o1 = v23 + v25; + o1 = o1 + select(0u, 1u, o0 < v22); + v22 = o0; + v23 = o1; + + // b = rotr64(b ^ c, 63) + xor0 = v12 ^ v22; + xor1 = v13 ^ v23; + v12 = (xor1 >> 31u) ^ (xor0 << 1u); + v13 = (xor0 >> 31u) ^ (xor1 << 1u); + + + + + + /** + * r=4, i=6(x2), a=v[4-5], b=v[14-15], c=v[16-17], d=v[26-27] + */ + + // a = a + b + o0 = v4 + v14; + o1 = v5 + v15; + o1 = o1 + select(0u, 1u, o0 < v4); + v4 = o0; + v5 = o1; + + // // a = a + m[sigma[r][2*i+0]] + // // skip since adding 0u does nothing + // o0 = v4 + 0u; + // o1 = v5 + 0u; + // if (v4 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v4 = o0; + // v5 = o1; + + // d = rotr64(d ^ a, 32) + xor0 = v26 ^ v4; + xor1 = v27 ^ v5; + v26 = xor1; + v27 = xor0; + + // c = c + d + o0 = v16 + v26; + o1 = v17 + v27; + o1 = o1 + select(0u, 1u, o0 < v16); + v16 = o0; + v17 = o1; + + // b = rotr64(b ^ c, 24) + xor0 = v14 ^ v16; + xor1 = v15 ^ v17; + v14 = (xor0 >> 24u) ^ (xor1 << 8u); + v15 = (xor1 >> 24u) ^ (xor0 << 8u); + + // a = a + b + o0 = v4 + v14; + o1 = v5 + v15; + o1 = o1 + select(0u, 1u, o0 < v4); + v4 = o0; + v5 = o1; + + // // a = a + m[sigma[r][2*i+1]] + // // skip since adding 0u does nothing + // o0 = v4 + 0u; + // o1 = v5 + 0u; + // if (v4 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v4 = o0; + // v5 = o1; + + // d = rotr64(d ^ a, 16) + xor0 = v26 ^ v4; + xor1 = v27 ^ v5; + v26 = (xor0 >> 16u) ^ (xor1 << 16u); + v27 = (xor1 >> 16u) ^ (xor0 << 16u); + + // c = c + d + o0 = v16 + v26; + o1 = v17 + v27; + o1 = o1 + select(0u, 1u, o0 < v16); + v16 = o0; + v17 = o1; + + // b = rotr64(b ^ c, 63) + xor0 = v14 ^ v16; + xor1 = v15 ^ v17; + v14 = (xor1 >> 31u) ^ (xor0 << 1u); + v15 = (xor0 >> 31u) ^ (xor1 << 1u); + + + + + + /** + * r=4, i=7(x2), a=v[6-7], b=v[8-9], c=v[18-19], d=v[28-29] + */ + + // a = a + b + o0 = v6 + v8; + o1 = v7 + v9; + o1 = o1 + select(0u, 1u, o0 < v6); + v6 = o0; + v7 = o1; + + // a = a + m[sigma[r][2*i+0]] + o0 = v6 + m6; + o1 = v7 + m7; + o1 = o1 + select(0u, 1u, o0 < v6); + v6 = o0; + v7 = o1; + + // d = rotr64(d ^ a, 32) + xor0 = v28 ^ v6; + xor1 = v29 ^ v7; + v28 = xor1; + v29 = xor0; + + // c = c + d + o0 = v18 + v28; + o1 = v19 + v29; + o1 = o1 + select(0u, 1u, o0 < v18); + v18 = o0; + v19 = o1; + + // b = rotr64(b ^ c, 24) + xor0 = v8 ^ v18; + xor1 = v9 ^ v19; + v8 = (xor0 >> 24u) ^ (xor1 << 8u); + v9 = (xor1 >> 24u) ^ (xor0 << 8u); + + // a = a + b + o0 = v6 + v8; + o1 = v7 + v9; + o1 = o1 + select(0u, 1u, o0 < v6); + v6 = o0; + v7 = o1; + + // // a = a + m[sigma[r][2*i+1]] + // // skip since adding 0u does nothing + // o0 = v6 + 0u; + // o1 = v7 + 0u; + // if (v6 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v6 = o0; + // v7 = o1; + + // d = rotr64(d ^ a, 16) + xor0 = v28 ^ v6; + xor1 = v29 ^ v7; + v28 = (xor0 >> 16u) ^ (xor1 << 16u); + v29 = (xor1 >> 16u) ^ (xor0 << 16u); + + // c = c + d + o0 = v18 + v28; + o1 = v19 + v29; + o1 = o1 + select(0u, 1u, o0 < v18); + v18 = o0; + v19 = o1; + + // b = rotr64(b ^ c, 63) + xor0 = v8 ^ v18; + xor1 = v9 ^ v19; + v8 = (xor1 >> 31u) ^ (xor0 << 1u); + v9 = (xor0 >> 31u) ^ (xor1 << 1u); + + + + + + /**************************************************************************** + * ROUND(5) * + ****************************************************************************/ + + /** + * r=5, i=0(x2), a=v[0-1], b=v[8-9], c=v[16-17], d=v[24-25] + */ + + // a = a + b + o0 = v0 + v8; + o1 = v1 + v9; + o1 = o1 + select(0u, 1u, o0 < v0); + v0 = o0; + v1 = o1; + + // a = a + m[sigma[r][2*i+0]] + o0 = v0 + m4; + o1 = v1 + m5; + o1 = o1 + select(0u, 1u, o0 < v0); + v0 = o0; + v1 = o1; + + // d = rotr64(d ^ a, 32) + xor0 = v24 ^ v0; + xor1 = v25 ^ v1; + v24 = xor1; + v25 = xor0; + + // c = c + d + o0 = v16 + v24; + o1 = v17 + v25; + o1 = o1 + select(0u, 1u, o0 < v16); + v16 = o0; + v17 = o1; + + // b = rotr64(b ^ c, 24) + xor0 = v8 ^ v16; + xor1 = v9 ^ v17; + v8 = (xor0 >> 24u) ^ (xor1 << 8u); + v9 = (xor1 >> 24u) ^ (xor0 << 8u); + + // a = a + b + o0 = v0 + v8; + o1 = v1 + v9; + o1 = o1 + select(0u, 1u, o0 < v0); + v0 = o0; + v1 = o1; + + // // a = a + m[sigma[r][2*i+1]] + // // skip since adding 0u does nothing + // o0 = v0 + 0u; + // o1 = v1 + 0u; + // if (v0 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v0 = o0; + // v1 = o1; + + // d = rotr64(d ^ a, 16) + xor0 = v24 ^ v0; + xor1 = v25 ^ v1; + v24 = (xor0 >> 16u) ^ (xor1 << 16u); + v25 = (xor1 >> 16u) ^ (xor0 << 16u); + + // c = c + d + o0 = v16 + v24; + o1 = v17 + v25; + o1 = o1 + select(0u, 1u, o0 < v16); + v16 = o0; + v17 = o1; + + // b = rotr64(b ^ c, 63) + xor0 = v8 ^ v16; + xor1 = v9 ^ v17; + v8 = (xor1 >> 31u) ^ (xor0 << 1u); + v9 = (xor0 >> 31u) ^ (xor1 << 1u); + + + + + + /** + * r=5, i=1(x2), a=v[2-3], b=v[10-11], c=v[18-19], d=v[26-27] + */ + + // a = a + b + o0 = v2 + v10; + o1 = v3 + v11; + o1 = o1 + select(0u, 1u, o0 < v2); + v2 = o0; + v3 = o1; + + // // a = a + m[sigma[r][2*i+0]] + // // skip since adding 0u does nothing + // o0 = v2 + 0u; + // o1 = v3 + 0u; + // if (v2 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v2 = o0; + // v3 = o1; + + // d = rotr64(d ^ a, 32) + xor0 = v26 ^ v2; + xor1 = v27 ^ v3; + v26 = xor1; + v27 = xor0; + + // c = c + d + o0 = v18 + v26; + o1 = v19 + v27; + o1 = o1 + select(0u, 1u, o0 < v18); + v18 = o0; + v19 = o1; + + // b = rotr64(b ^ c, 24) + xor0 = v10 ^ v18; + xor1 = v11 ^ v19; + v10 = (xor0 >> 24u) ^ (xor1 << 8u); + v11 = (xor1 >> 24u) ^ (xor0 << 8u); + + // a = a + b + o0 = v2 + v10; + o1 = v3 + v11; + o1 = o1 + select(0u, 1u, o0 < v2); + v2 = o0; + v3 = o1; + + // // a = a + m[sigma[r][2*i+1]] + // // skip since adding 0u does nothing + // o0 = v2 + 0u; + // o1 = v3 + 0u; + // if (v2 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v2 = o0; + // v3 = o1; + + // d = rotr64(d ^ a, 16) + xor0 = v26 ^ v2; + xor1 = v27 ^ v3; + v26 = (xor0 >> 16u) ^ (xor1 << 16u); + v27 = (xor1 >> 16u) ^ (xor0 << 16u); + + // c = c + d + o0 = v18 + v26; + o1 = v19 + v27; + o1 = o1 + select(0u, 1u, o0 < v18); + v18 = o0; + v19 = o1; + + // b = rotr64(b ^ c, 63) + xor0 = v10 ^ v18; + xor1 = v11 ^ v19; + v10 = (xor1 >> 31u) ^ (xor0 << 1u); + v11 = (xor0 >> 31u) ^ (xor1 << 1u); + + + + + + /** + * r=5, i=2(x2), a=v[4-5], b=v[12-13], c=v[20-21], d=v[28-29] + */ + + // a = a + b + o0 = v4 + v12; + o1 = v5 + v13; + o1 = o1 + select(0u, 1u, o0 < v4); + v4 = o0; + v5 = o1; + + // a = a + m[sigma[r][2*i+0]] + o0 = v4 + m0; + o1 = v5 + m1; + o1 = o1 + select(0u, 1u, o0 < v4); + v4 = o0; + v5 = o1; + + // d = rotr64(d ^ a, 32) + xor0 = v28 ^ v4; + xor1 = v29 ^ v5; + v28 = xor1; + v29 = xor0; + + // c = c + d + o0 = v20 + v28; + o1 = v21 + v29; + o1 = o1 + select(0u, 1u, o0 < v20); + v20 = o0; + v21 = o1; + + // b = rotr64(b ^ c, 24) + xor0 = v12 ^ v20; + xor1 = v13 ^ v21; + v12 = (xor0 >> 24u) ^ (xor1 << 8u); + v13 = (xor1 >> 24u) ^ (xor0 << 8u); + + // a = a + b + o0 = v4 + v12; + o1 = v5 + v13; + o1 = o1 + select(0u, 1u, o0 < v4); + v4 = o0; + v5 = o1; + + // // a = a + m[sigma[r][2*i+1]] + // // skip since adding 0u does nothing + // o0 = v4 + 0u; + // o1 = v5 + 0u; + // if (v4 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v4 = o0; + // v5 = o1; + + // d = rotr64(d ^ a, 16) + xor0 = v28 ^ v4; + xor1 = v29 ^ v5; + v28 = (xor0 >> 16u) ^ (xor1 << 16u); + v29 = (xor1 >> 16u) ^ (xor0 << 16u); + + // c = c + d + o0 = v20 + v28; + o1 = v21 + v29; + o1 = o1 + select(0u, 1u, o0 < v20); + v20 = o0; + v21 = o1; + + // b = rotr64(b ^ c, 63) + xor0 = v12 ^ v20; + xor1 = v13 ^ v21; + v12 = (xor1 >> 31u) ^ (xor0 << 1u); + v13 = (xor0 >> 31u) ^ (xor1 << 1u); + + + + + + /** + * r=5, i=3(x2), a=v[6-7], b=v[14-15], c=v[22-23], d=v[30-31] + */ + + // a = a + b + o0 = v6 + v14; + o1 = v7 + v15; + o1 = o1 + select(0u, 1u, o0 < v6); + v6 = o0; + v7 = o1; + + // // a = a + m[sigma[r][2*i+0]] + // // skip since adding 0u does nothing + // o0 = v6 + 0u; + // o1 = v7 + 0u; + // if (v6 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v6 = o0; + // v7 = o1; + + // d = rotr64(d ^ a, 32) + xor0 = v30 ^ v6; + xor1 = v31 ^ v7; + v30 = xor1; + v31 = xor0; + + // c = c + d + o0 = v22 + v30; + o1 = v23 + v31; + o1 = o1 + select(0u, 1u, o0 < v22); + v22 = o0; + v23 = o1; + + // b = rotr64(b ^ c, 24) + xor0 = v14 ^ v22; + xor1 = v15 ^ v23; + v14 = (xor0 >> 24u) ^ (xor1 << 8u); + v15 = (xor1 >> 24u) ^ (xor0 << 8u); + + // a = a + b + o0 = v6 + v14; + o1 = v7 + v15; + o1 = o1 + select(0u, 1u, o0 < v6); + v6 = o0; + v7 = o1; + + // a = a + m[sigma[r][2*i+1]] + o0 = v6 + m6; + o1 = v7 + m7; + o1 = o1 + select(0u, 1u, o0 < v6); + v6 = o0; + v7 = o1; + + // d = rotr64(d ^ a, 16) + xor0 = v30 ^ v6; + xor1 = v31 ^ v7; + v30 = (xor0 >> 16u) ^ (xor1 << 16u); + v31 = (xor1 >> 16u) ^ (xor0 << 16u); + + // c = c + d + o0 = v22 + v30; + o1 = v23 + v31; + o1 = o1 + select(0u, 1u, o0 < v22); + v22 = o0; + v23 = o1; + + // b = rotr64(b ^ c, 63) + xor0 = v14 ^ v22; + xor1 = v15 ^ v23; + v14 = (xor1 >> 31u) ^ (xor0 << 1u); + v15 = (xor0 >> 31u) ^ (xor1 << 1u); + + + + + + /** + * r=5, i=4(x2), a=v[0-1], b=v[10-11], c=v[20-21], d=v[30-31] + */ + + // a = a + b + o0 = v0 + v10; + o1 = v1 + v11; + o1 = o1 + select(0u, 1u, o0 < v0); + v0 = o0; + v1 = o1; + + // a = a + m[sigma[r][2*i+0]] + o0 = v0 + m8; + o1 = v1 + m9; + o1 = o1 + select(0u, 1u, o0 < v0); + v0 = o0; + v1 = o1; + + // d = rotr64(d ^ a, 32) + xor0 = v30 ^ v0; + xor1 = v31 ^ v1; + v30 = xor1; + v31 = xor0; + + // c = c + d + o0 = v20 + v30; + o1 = v21 + v31; + o1 = o1 + select(0u, 1u, o0 < v20); + v20 = o0; + v21 = o1; + + // b = rotr64(b ^ c, 24) + xor0 = v10 ^ v20; + xor1 = v11 ^ v21; + v10 = (xor0 >> 24u) ^ (xor1 << 8u); + v11 = (xor1 >> 24u) ^ (xor0 << 8u); + + // a = a + b + o0 = v0 + v10; + o1 = v1 + v11; + o1 = o1 + select(0u, 1u, o0 < v0); + v0 = o0; + v1 = o1; + + // // a = a + m[sigma[r][2*i+1]] + // // skip since adding 0u does nothing + // o0 = v0 + 0u; + // o1 = v1 + 0u; + // if (v0 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v0 = o0; + // v1 = o1; + + // d = rotr64(d ^ a, 16) + xor0 = v30 ^ v0; + xor1 = v31 ^ v1; + v30 = (xor0 >> 16u) ^ (xor1 << 16u); + v31 = (xor1 >> 16u) ^ (xor0 << 16u); + + // c = c + d + o0 = v20 + v30; + o1 = v21 + v31; + o1 = o1 + select(0u, 1u, o0 < v20); + v20 = o0; + v21 = o1; + + // b = rotr64(b ^ c, 63) + xor0 = v10 ^ v20; + xor1 = v11 ^ v21; + v10 = (xor1 >> 31u) ^ (xor0 << 1u); + v11 = (xor0 >> 31u) ^ (xor1 << 1u); + + + + + + /** + * r=5, i=5(x2), a=v[2-3], b=v[12-13], c=v[22-23], d=v[24-25] + */ + + // a = a + b + o0 = v2 + v12; + o1 = v3 + v13; + o1 = o1 + select(0u, 1u, o0 < v2); + v2 = o0; + v3 = o1; + + // // a = a + m[sigma[r][2*i+0]] + // // skip since adding 0u does nothing + // o0 = v2 + 0u; + // o1 = v3 + 0u; + // if (v2 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v2 = o0; + // v3 = o1; + + // d = rotr64(d ^ a, 32) + xor0 = v24 ^ v2; + xor1 = v25 ^ v3; + v24 = xor1; + v25 = xor0; + + // c = c + d + o0 = v22 + v24; + o1 = v23 + v25; + o1 = o1 + select(0u, 1u, o0 < v22); + v22 = o0; + v23 = o1; + + // b = rotr64(b ^ c, 24) + xor0 = v12 ^ v22; + xor1 = v13 ^ v23; + v12 = (xor0 >> 24u) ^ (xor1 << 8u); + v13 = (xor1 >> 24u) ^ (xor0 << 8u); + + // a = a + b + o0 = v2 + v12; + o1 = v3 + v13; + o1 = o1 + select(0u, 1u, o0 < v2); + v2 = o0; + v3 = o1; + + // // a = a + m[sigma[r][2*i+1]] + // // skip since adding 0u does nothing + // o0 = v2 + 0u; + // o1 = v3 + 0u; + // if (v2 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v2 = o0; + // v3 = o1; + + // d = rotr64(d ^ a, 16) + xor0 = v24 ^ v2; + xor1 = v25 ^ v3; + v24 = (xor0 >> 16u) ^ (xor1 << 16u); + v25 = (xor1 >> 16u) ^ (xor0 << 16u); + + // c = c + d + o0 = v22 + v24; + o1 = v23 + v25; + o1 = o1 + select(0u, 1u, o0 < v22); + v22 = o0; + v23 = o1; + + // b = rotr64(b ^ c, 63) + xor0 = v12 ^ v22; + xor1 = v13 ^ v23; + v12 = (xor1 >> 31u) ^ (xor0 << 1u); + v13 = (xor0 >> 31u) ^ (xor1 << 1u); + + + + + + /** + * r=5, i=6(x2), a=v[4-5], b=v[14-15], c=v[16-17], d=v[26-27] + */ + + // a = a + b + o0 = v4 + v14; + o1 = v5 + v15; + o1 = o1 + select(0u, 1u, o0 < v4); + v4 = o0; + v5 = o1; + + // // a = a + m[sigma[r][2*i+0]] + // // skip since adding 0u does nothing + // o0 = v4 + 0u; + // o1 = v5 + 0u; + // if (v4 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v4 = o0; + // v5 = o1; + + // d = rotr64(d ^ a, 32) + xor0 = v26 ^ v4; + xor1 = v27 ^ v5; + v26 = xor1; + v27 = xor0; + + // c = c + d + o0 = v16 + v26; + o1 = v17 + v27; + o1 = o1 + select(0u, 1u, o0 < v16); + v16 = o0; + v17 = o1; + + // b = rotr64(b ^ c, 24) + xor0 = v14 ^ v16; + xor1 = v15 ^ v17; + v14 = (xor0 >> 24u) ^ (xor1 << 8u); + v15 = (xor1 >> 24u) ^ (xor0 << 8u); + + // a = a + b + o0 = v4 + v14; + o1 = v5 + v15; + o1 = o1 + select(0u, 1u, o0 < v4); + v4 = o0; + v5 = o1; + + // // a = a + m[sigma[r][2*i+1]] + // // skip since adding 0u does nothing + // o0 = v4 + 0u; + // o1 = v5 + 0u; + // if (v4 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v4 = o0; + // v5 = o1; + + // d = rotr64(d ^ a, 16) + xor0 = v26 ^ v4; + xor1 = v27 ^ v5; + v26 = (xor0 >> 16u) ^ (xor1 << 16u); + v27 = (xor1 >> 16u) ^ (xor0 << 16u); + + // c = c + d + o0 = v16 + v26; + o1 = v17 + v27; + o1 = o1 + select(0u, 1u, o0 < v16); + v16 = o0; + v17 = o1; + + // b = rotr64(b ^ c, 63) + xor0 = v14 ^ v16; + xor1 = v15 ^ v17; + v14 = (xor1 >> 31u) ^ (xor0 << 1u); + v15 = (xor0 >> 31u) ^ (xor1 << 1u); + + + + + + /** + * r=5, i=7(x2), a=v[6-7], b=v[8-9], c=v[18-19], d=v[28-29] + */ + + // a = a + b + o0 = v6 + v8; + o1 = v7 + v9; + o1 = o1 + select(0u, 1u, o0 < v6); + v6 = o0; + v7 = o1; + + // a = a + m[sigma[r][2*i+0]] + o0 = v6 + m2; + o1 = v7 + m3; + o1 = o1 + select(0u, 1u, o0 < v6); + v6 = o0; + v7 = o1; + + // d = rotr64(d ^ a, 32) + xor0 = v28 ^ v6; + xor1 = v29 ^ v7; + v28 = xor1; + v29 = xor0; + + // c = c + d + o0 = v18 + v28; + o1 = v19 + v29; + o1 = o1 + select(0u, 1u, o0 < v18); + v18 = o0; + v19 = o1; + + // b = rotr64(b ^ c, 24) + xor0 = v8 ^ v18; + xor1 = v9 ^ v19; + v8 = (xor0 >> 24u) ^ (xor1 << 8u); + v9 = (xor1 >> 24u) ^ (xor0 << 8u); + + // a = a + b + o0 = v6 + v8; + o1 = v7 + v9; + o1 = o1 + select(0u, 1u, o0 < v6); + v6 = o0; + v7 = o1; + + // // a = a + m[sigma[r][2*i+1]] + // // skip since adding 0u does nothing + // o0 = v6 + 0u; + // o1 = v7 + 0u; + // if (v6 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v6 = o0; + // v7 = o1; + + // d = rotr64(d ^ a, 16) + xor0 = v28 ^ v6; + xor1 = v29 ^ v7; + v28 = (xor0 >> 16u) ^ (xor1 << 16u); + v29 = (xor1 >> 16u) ^ (xor0 << 16u); + + // c = c + d + o0 = v18 + v28; + o1 = v19 + v29; + o1 = o1 + select(0u, 1u, o0 < v18); + v18 = o0; + v19 = o1; + + // b = rotr64(b ^ c, 63) + xor0 = v8 ^ v18; + xor1 = v9 ^ v19; + v8 = (xor1 >> 31u) ^ (xor0 << 1u); + v9 = (xor0 >> 31u) ^ (xor1 << 1u); + + + + + + /**************************************************************************** + * ROUND(6) * + ****************************************************************************/ + + /** + * r=6, i=0(x2), a=v[0-1], b=v[8-9], c=v[16-17], d=v[24-25] + */ + + // a = a + b + o0 = v0 + v8; + o1 = v1 + v9; + o1 = o1 + select(0u, 1u, o0 < v0); + v0 = o0; + v1 = o1; + + // // a = a + m[sigma[r][2*i+0]] + // // skip since adding 0u does nothing + // o0 = v0 + 0u; + // o1 = v1 + 0u; + // if (v0 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v0 = o0; + // v1 = o1; + + // d = rotr64(d ^ a, 32) + xor0 = v24 ^ v0; + xor1 = v25 ^ v1; + v24 = xor1; + v25 = xor0; + + // c = c + d + o0 = v16 + v24; + o1 = v17 + v25; + o1 = o1 + select(0u, 1u, o0 < v16); + v16 = o0; + v17 = o1; + + // b = rotr64(b ^ c, 24) + xor0 = v8 ^ v16; + xor1 = v9 ^ v17; + v8 = (xor0 >> 24u) ^ (xor1 << 8u); + v9 = (xor1 >> 24u) ^ (xor0 << 8u); + + // a = a + b + o0 = v0 + v8; + o1 = v1 + v9; + o1 = o1 + select(0u, 1u, o0 < v0); + v0 = o0; + v1 = o1; + + // // a = a + m[sigma[r][2*i+1]] + // // skip since adding 0u does nothing + // o0 = v0 + 0u; + // o1 = v1 + 0u; + // if (v0 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v0 = o0; + // v1 = o1; + + // d = rotr64(d ^ a, 16) + xor0 = v24 ^ v0; + xor1 = v25 ^ v1; + v24 = (xor0 >> 16u) ^ (xor1 << 16u); + v25 = (xor1 >> 16u) ^ (xor0 << 16u); + + // c = c + d + o0 = v16 + v24; + o1 = v17 + v25; + o1 = o1 + select(0u, 1u, o0 < v16); + v16 = o0; + v17 = o1; + + // b = rotr64(b ^ c, 63) + xor0 = v8 ^ v16; + xor1 = v9 ^ v17; + v8 = (xor1 >> 31u) ^ (xor0 << 1u); + v9 = (xor0 >> 31u) ^ (xor1 << 1u); + + + + + + /** + * r=6, i=1(x2), a=v[2-3], b=v[10-11], c=v[18-19], d=v[26-27] + */ + + // a = a + b + o0 = v2 + v10; + o1 = v3 + v11; + o1 = o1 + select(0u, 1u, o0 < v2); + v2 = o0; + v3 = o1; + + // a = a + m[sigma[r][2*i+0]] + o0 = v2 + m2; + o1 = v3 + m3; + o1 = o1 + select(0u, 1u, o0 < v2); + v2 = o0; + v3 = o1; + + // d = rotr64(d ^ a, 32) + xor0 = v26 ^ v2; + xor1 = v27 ^ v3; + v26 = xor1; + v27 = xor0; + + // c = c + d + o0 = v18 + v26; + o1 = v19 + v27; + o1 = o1 + select(0u, 1u, o0 < v18); + v18 = o0; + v19 = o1; + + // b = rotr64(b ^ c, 24) + xor0 = v10 ^ v18; + xor1 = v11 ^ v19; + v10 = (xor0 >> 24u) ^ (xor1 << 8u); + v11 = (xor1 >> 24u) ^ (xor0 << 8u); + + // a = a + b + o0 = v2 + v10; + o1 = v3 + v11; + o1 = o1 + select(0u, 1u, o0 < v2); + v2 = o0; + v3 = o1; + + // // a = a + m[sigma[r][2*i+1]] + // // skip since adding 0u does nothing + // o0 = v2 + 0u; + // o1 = v3 + 0u; + // if (v2 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v2 = o0; + // v3 = o1; + + // d = rotr64(d ^ a, 16) + xor0 = v26 ^ v2; + xor1 = v27 ^ v3; + v26 = (xor0 >> 16u) ^ (xor1 << 16u); + v27 = (xor1 >> 16u) ^ (xor0 << 16u); + + // c = c + d + o0 = v18 + v26; + o1 = v19 + v27; + o1 = o1 + select(0u, 1u, o0 < v18); + v18 = o0; + v19 = o1; + + // b = rotr64(b ^ c, 63) + xor0 = v10 ^ v18; + xor1 = v11 ^ v19; + v10 = (xor1 >> 31u) ^ (xor0 << 1u); + v11 = (xor0 >> 31u) ^ (xor1 << 1u); + + + + + + /** + * r=6, i=2(x2), a=v[4-5], b=v[12-13], c=v[20-21], d=v[28-29] + */ + + // a = a + b + o0 = v4 + v12; + o1 = v5 + v13; + o1 = o1 + select(0u, 1u, o0 < v4); + v4 = o0; + v5 = o1; + + // // a = a + m[sigma[r][2*i+0]] + // // skip since adding 0u does nothing + // o0 = v4 + 0u; + // o1 = v5 + 0u; + // if (v4 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v4 = o0; + // v5 = o1; + + // d = rotr64(d ^ a, 32) + xor0 = v28 ^ v4; + xor1 = v29 ^ v5; + v28 = xor1; + v29 = xor0; + + // c = c + d + o0 = v20 + v28; + o1 = v21 + v29; + o1 = o1 + select(0u, 1u, o0 < v20); + v20 = o0; + v21 = o1; + + // b = rotr64(b ^ c, 24) + xor0 = v12 ^ v20; + xor1 = v13 ^ v21; + v12 = (xor0 >> 24u) ^ (xor1 << 8u); + v13 = (xor1 >> 24u) ^ (xor0 << 8u); + + // a = a + b + o0 = v4 + v12; + o1 = v5 + v13; + o1 = o1 + select(0u, 1u, o0 < v4); + v4 = o0; + v5 = o1; + + // // a = a + m[sigma[r][2*i+1]] + // // skip since adding 0u does nothing + // o0 = v4 + 0u; + // o1 = v5 + 0u; + // if (v4 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v4 = o0; + // v5 = o1; + + // d = rotr64(d ^ a, 16) + xor0 = v28 ^ v4; + xor1 = v29 ^ v5; + v28 = (xor0 >> 16u) ^ (xor1 << 16u); + v29 = (xor1 >> 16u) ^ (xor0 << 16u); + + // c = c + d + o0 = v20 + v28; + o1 = v21 + v29; + o1 = o1 + select(0u, 1u, o0 < v20); + v20 = o0; + v21 = o1; + + // b = rotr64(b ^ c, 63) + xor0 = v12 ^ v20; + xor1 = v13 ^ v21; + v12 = (xor1 >> 31u) ^ (xor0 << 1u); + v13 = (xor0 >> 31u) ^ (xor1 << 1u); + + + + + + /** + * r=6, i=3(x2), a=v[6-7], b=v[14-15], c=v[22-23], d=v[30-31] + */ + + // a = a + b + o0 = v6 + v14; + o1 = v7 + v15; + o1 = o1 + select(0u, 1u, o0 < v6); + v6 = o0; + v7 = o1; + + // a = a + m[sigma[r][2*i+0]] + o0 = v6 + m8; + o1 = v7 + m9; + o1 = o1 + select(0u, 1u, o0 < v6); + v6 = o0; + v7 = o1; + + // d = rotr64(d ^ a, 32) + xor0 = v30 ^ v6; + xor1 = v31 ^ v7; + v30 = xor1; + v31 = xor0; + + // c = c + d + o0 = v22 + v30; + o1 = v23 + v31; + o1 = o1 + select(0u, 1u, o0 < v22); + v22 = o0; + v23 = o1; + + // b = rotr64(b ^ c, 24) + xor0 = v14 ^ v22; + xor1 = v15 ^ v23; + v14 = (xor0 >> 24u) ^ (xor1 << 8u); + v15 = (xor1 >> 24u) ^ (xor0 << 8u); + + // a = a + b + o0 = v6 + v14; + o1 = v7 + v15; + o1 = o1 + select(0u, 1u, o0 < v6); + v6 = o0; + v7 = o1; + + // // a = a + m[sigma[r][2*i+1]] + // // skip since adding 0u does nothing + // o0 = v6 + 0u; + // o1 = v7 + 0u; + // if (v6 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v6 = o0; + // v7 = o1; + + // d = rotr64(d ^ a, 16) + xor0 = v30 ^ v6; + xor1 = v31 ^ v7; + v30 = (xor0 >> 16u) ^ (xor1 << 16u); + v31 = (xor1 >> 16u) ^ (xor0 << 16u); + + // c = c + d + o0 = v22 + v30; + o1 = v23 + v31; + o1 = o1 + select(0u, 1u, o0 < v22); + v22 = o0; + v23 = o1; + + // b = rotr64(b ^ c, 63) + xor0 = v14 ^ v22; + xor1 = v15 ^ v23; + v14 = (xor1 >> 31u) ^ (xor0 << 1u); + v15 = (xor0 >> 31u) ^ (xor1 << 1u); + + + + + + /** + * r=6, i=4(x2), a=v[0-1], b=v[10-11], c=v[20-21], d=v[30-31] + */ + + // a = a + b + o0 = v0 + v10; + o1 = v1 + v11; + o1 = o1 + select(0u, 1u, o0 < v0); + v0 = o0; + v1 = o1; + + // a = a + m[sigma[r][2*i+0]] + o0 = v0 + m0; + o1 = v1 + m1; + o1 = o1 + select(0u, 1u, o0 < v0); + v0 = o0; + v1 = o1; + + // d = rotr64(d ^ a, 32) + xor0 = v30 ^ v0; + xor1 = v31 ^ v1; + v30 = xor1; + v31 = xor0; + + // c = c + d + o0 = v20 + v30; + o1 = v21 + v31; + o1 = o1 + select(0u, 1u, o0 < v20); + v20 = o0; + v21 = o1; + + // b = rotr64(b ^ c, 24) + xor0 = v10 ^ v20; + xor1 = v11 ^ v21; + v10 = (xor0 >> 24u) ^ (xor1 << 8u); + v11 = (xor1 >> 24u) ^ (xor0 << 8u); + + // a = a + b + o0 = v0 + v10; + o1 = v1 + v11; + o1 = o1 + select(0u, 1u, o0 < v0); + v0 = o0; + v1 = o1; + + // // a = a + m[sigma[r][2*i+1]] + // // skip since adding 0u does nothing + // o0 = v0 + 0u; + // o1 = v1 + 0u; + // if (v0 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v0 = o0; + // v1 = o1; + + // d = rotr64(d ^ a, 16) + xor0 = v30 ^ v0; + xor1 = v31 ^ v1; + v30 = (xor0 >> 16u) ^ (xor1 << 16u); + v31 = (xor1 >> 16u) ^ (xor0 << 16u); + + // c = c + d + o0 = v20 + v30; + o1 = v21 + v31; + o1 = o1 + select(0u, 1u, o0 < v20); + v20 = o0; + v21 = o1; + + // b = rotr64(b ^ c, 63) + xor0 = v10 ^ v20; + xor1 = v11 ^ v21; + v10 = (xor1 >> 31u) ^ (xor0 << 1u); + v11 = (xor0 >> 31u) ^ (xor1 << 1u); + + + + + + /** + * r=6, i=5(x2), a=v[2-3], b=v[12-13], c=v[22-23], d=v[24-25] + */ + + // a = a + b + o0 = v2 + v12; + o1 = v3 + v13; + o1 = o1 + select(0u, 1u, o0 < v2); + v2 = o0; + v3 = o1; + + // // a = a + m[sigma[r][2*i+0]] + // // skip since adding 0u does nothing + // o0 = v2 + 0u; + // o1 = v3 + 0u; + // if (v2 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v2 = o0; + // v3 = o1; + + // d = rotr64(d ^ a, 32) + xor0 = v24 ^ v2; + xor1 = v25 ^ v3; + v24 = xor1; + v25 = xor0; + + // c = c + d + o0 = v22 + v24; + o1 = v23 + v25; + o1 = o1 + select(0u, 1u, o0 < v22); + v22 = o0; + v23 = o1; + + // b = rotr64(b ^ c, 24) + xor0 = v12 ^ v22; + xor1 = v13 ^ v23; + v12 = (xor0 >> 24u) ^ (xor1 << 8u); + v13 = (xor1 >> 24u) ^ (xor0 << 8u); + + // a = a + b + o0 = v2 + v12; + o1 = v3 + v13; + o1 = o1 + select(0u, 1u, o0 < v2); + v2 = o0; + v3 = o1; + + // a = a + m[sigma[r][2*i+1]] + o0 = v2 + m6; + o1 = v3 + m7; + o1 = o1 + select(0u, 1u, o0 < v2); + v2 = o0; + v3 = o1; + + // d = rotr64(d ^ a, 16) + xor0 = v24 ^ v2; + xor1 = v25 ^ v3; + v24 = (xor0 >> 16u) ^ (xor1 << 16u); + v25 = (xor1 >> 16u) ^ (xor0 << 16u); + + // c = c + d + o0 = v22 + v24; + o1 = v23 + v25; + o1 = o1 + select(0u, 1u, o0 < v22); + v22 = o0; + v23 = o1; + + // b = rotr64(b ^ c, 63) + xor0 = v12 ^ v22; + xor1 = v13 ^ v23; + v12 = (xor1 >> 31u) ^ (xor0 << 1u); + v13 = (xor0 >> 31u) ^ (xor1 << 1u); + + + + + + /** + * r=6, i=6(x2), a=v[4-5], b=v[14-15], c=v[16-17], d=v[26-27] + */ + + // a = a + b + o0 = v4 + v14; + o1 = v5 + v15; + o1 = o1 + select(0u, 1u, o0 < v4); + v4 = o0; + v5 = o1; + + // // a = a + m[sigma[r][2*i+0]] + // // skip since adding 0u does nothing + // o0 = v4 + 0u; + // o1 = v5 + 0u; + // if (v4 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v4 = o0; + // v5 = o1; + + // d = rotr64(d ^ a, 32) + xor0 = v26 ^ v4; + xor1 = v27 ^ v5; + v26 = xor1; + v27 = xor0; + + // c = c + d + o0 = v16 + v26; + o1 = v17 + v27; + o1 = o1 + select(0u, 1u, o0 < v16); + v16 = o0; + v17 = o1; + + // b = rotr64(b ^ c, 24) + xor0 = v14 ^ v16; + xor1 = v15 ^ v17; + v14 = (xor0 >> 24u) ^ (xor1 << 8u); + v15 = (xor1 >> 24u) ^ (xor0 << 8u); + + // a = a + b + o0 = v4 + v14; + o1 = v5 + v15; + o1 = o1 + select(0u, 1u, o0 < v4); + v4 = o0; + v5 = o1; + + // a = a + m[sigma[r][2*i+1]] + o0 = v4 + m4; + o1 = v5 + m5; + o1 = o1 + select(0u, 1u, o0 < v4); + v4 = o0; + v5 = o1; + + // d = rotr64(d ^ a, 16) + xor0 = v26 ^ v4; + xor1 = v27 ^ v5; + v26 = (xor0 >> 16u) ^ (xor1 << 16u); + v27 = (xor1 >> 16u) ^ (xor0 << 16u); + + // c = c + d + o0 = v16 + v26; + o1 = v17 + v27; + o1 = o1 + select(0u, 1u, o0 < v16); + v16 = o0; + v17 = o1; + + // b = rotr64(b ^ c, 63) + xor0 = v14 ^ v16; + xor1 = v15 ^ v17; + v14 = (xor1 >> 31u) ^ (xor0 << 1u); + v15 = (xor0 >> 31u) ^ (xor1 << 1u); + + + + + + /** + * r=6, i=7(x2), a=v[6-7], b=v[8-9], c=v[18-19], d=v[28-29] + */ + + // a = a + b + o0 = v6 + v8; + o1 = v7 + v9; + o1 = o1 + select(0u, 1u, o0 < v6); + v6 = o0; + v7 = o1; + + // // a = a + m[sigma[r][2*i+0]] + // // skip since adding 0u does nothing + // o0 = v6 + 0u; + // o1 = v7 + 0u; + // if (v6 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v6 = o0; + // v7 = o1; + + // d = rotr64(d ^ a, 32) + xor0 = v28 ^ v6; + xor1 = v29 ^ v7; + v28 = xor1; + v29 = xor0; + + // c = c + d + o0 = v18 + v28; + o1 = v19 + v29; + o1 = o1 + select(0u, 1u, o0 < v18); + v18 = o0; + v19 = o1; + + // b = rotr64(b ^ c, 24) + xor0 = v8 ^ v18; + xor1 = v9 ^ v19; + v8 = (xor0 >> 24u) ^ (xor1 << 8u); + v9 = (xor1 >> 24u) ^ (xor0 << 8u); + + // a = a + b + o0 = v6 + v8; + o1 = v7 + v9; + o1 = o1 + select(0u, 1u, o0 < v6); + v6 = o0; + v7 = o1; + + // // a = a + m[sigma[r][2*i+1]] + // // skip since adding 0u does nothing + // o0 = v6 + 0u; + // o1 = v7 + 0u; + // if (v6 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v6 = o0; + // v7 = o1; + + // d = rotr64(d ^ a, 16) + xor0 = v28 ^ v6; + xor1 = v29 ^ v7; + v28 = (xor0 >> 16u) ^ (xor1 << 16u); + v29 = (xor1 >> 16u) ^ (xor0 << 16u); + + // c = c + d + o0 = v18 + v28; + o1 = v19 + v29; + o1 = o1 + select(0u, 1u, o0 < v18); + v18 = o0; + v19 = o1; + + // b = rotr64(b ^ c, 63) + xor0 = v8 ^ v18; + xor1 = v9 ^ v19; + v8 = (xor1 >> 31u) ^ (xor0 << 1u); + v9 = (xor0 >> 31u) ^ (xor1 << 1u); + + + + + + /**************************************************************************** + * ROUND(7) * + ****************************************************************************/ + + /** + * r=7, i=0(x2), a=v[0-1], b=v[8-9], c=v[16-17], d=v[24-25] + */ + + // a = a + b + o0 = v0 + v8; + o1 = v1 + v9; + o1 = o1 + select(0u, 1u, o0 < v0); + v0 = o0; + v1 = o1; + + // // a = a + m[sigma[r][2*i+0]] + // // skip since adding 0u does nothing + // o0 = v0 + 0u; + // o1 = v1 + 0u; + // if (v0 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v0 = o0; + // v1 = o1; + + // d = rotr64(d ^ a, 32) + xor0 = v24 ^ v0; + xor1 = v25 ^ v1; + v24 = xor1; + v25 = xor0; + + // c = c + d + o0 = v16 + v24; + o1 = v17 + v25; + o1 = o1 + select(0u, 1u, o0 < v16); + v16 = o0; + v17 = o1; + + // b = rotr64(b ^ c, 24) + xor0 = v8 ^ v16; + xor1 = v9 ^ v17; + v8 = (xor0 >> 24u) ^ (xor1 << 8u); + v9 = (xor1 >> 24u) ^ (xor0 << 8u); + + // a = a + b + o0 = v0 + v8; + o1 = v1 + v9; + o1 = o1 + select(0u, 1u, o0 < v0); + v0 = o0; + v1 = o1; + + // // a = a + m[sigma[r][2*i+1]] + // // skip since adding 0u does nothing + // o0 = v0 + 0u; + // o1 = v1 + 0u; + // if (v0 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v0 = o0; + // v1 = o1; + + // d = rotr64(d ^ a, 16) + xor0 = v24 ^ v0; + xor1 = v25 ^ v1; + v24 = (xor0 >> 16u) ^ (xor1 << 16u); + v25 = (xor1 >> 16u) ^ (xor0 << 16u); + + // c = c + d + o0 = v16 + v24; + o1 = v17 + v25; + o1 = o1 + select(0u, 1u, o0 < v16); + v16 = o0; + v17 = o1; + + // b = rotr64(b ^ c, 63) + xor0 = v8 ^ v16; + xor1 = v9 ^ v17; + v8 = (xor1 >> 31u) ^ (xor0 << 1u); + v9 = (xor0 >> 31u) ^ (xor1 << 1u); + + + + + + /** + * r=7, i=1(x2), a=v[2-3], b=v[10-11], c=v[18-19], d=v[26-27] + */ + + // a = a + b + o0 = v2 + v10; + o1 = v3 + v11; + o1 = o1 + select(0u, 1u, o0 < v2); + v2 = o0; + v3 = o1; + + // // a = a + m[sigma[r][2*i+0]] + // // skip since adding 0u does nothing + // o0 = v2 + 0u; + // o1 = v3 + 0u; + // if (v2 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v2 = o0; + // v3 = o1; + + // d = rotr64(d ^ a, 32) + xor0 = v26 ^ v2; + xor1 = v27 ^ v3; + v26 = xor1; + v27 = xor0; + + // c = c + d + o0 = v18 + v26; + o1 = v19 + v27; + o1 = o1 + select(0u, 1u, o0 < v18); + v18 = o0; + v19 = o1; + + // b = rotr64(b ^ c, 24) + xor0 = v10 ^ v18; + xor1 = v11 ^ v19; + v10 = (xor0 >> 24u) ^ (xor1 << 8u); + v11 = (xor1 >> 24u) ^ (xor0 << 8u); + + // a = a + b + o0 = v2 + v10; + o1 = v3 + v11; + o1 = o1 + select(0u, 1u, o0 < v2); + v2 = o0; + v3 = o1; + + // // a = a + m[sigma[r][2*i+1]] + // // skip since adding 0u does nothing + // o0 = v2 + 0u; + // o1 = v3 + 0u; + // if (v2 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v2 = o0; + // v3 = o1; + + // d = rotr64(d ^ a, 16) + xor0 = v26 ^ v2; + xor1 = v27 ^ v3; + v26 = (xor0 >> 16u) ^ (xor1 << 16u); + v27 = (xor1 >> 16u) ^ (xor0 << 16u); + + // c = c + d + o0 = v18 + v26; + o1 = v19 + v27; + o1 = o1 + select(0u, 1u, o0 < v18); + v18 = o0; + v19 = o1; + + // b = rotr64(b ^ c, 63) + xor0 = v10 ^ v18; + xor1 = v11 ^ v19; + v10 = (xor1 >> 31u) ^ (xor0 << 1u); + v11 = (xor0 >> 31u) ^ (xor1 << 1u); + + + + + + /** + * r=7, i=2(x2), a=v[4-5], b=v[12-13], c=v[20-21], d=v[28-29] + */ + + // a = a + b + o0 = v4 + v12; + o1 = v5 + v13; + o1 = o1 + select(0u, 1u, o0 < v4); + v4 = o0; + v5 = o1; + + // // a = a + m[sigma[r][2*i+0]] + // // skip since adding 0u does nothing + // o0 = v4 + 0u; + // o1 = v5 + 0u; + // if (v4 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v4 = o0; + // v5 = o1; + + // d = rotr64(d ^ a, 32) + xor0 = v28 ^ v4; + xor1 = v29 ^ v5; + v28 = xor1; + v29 = xor0; + + // c = c + d + o0 = v20 + v28; + o1 = v21 + v29; + o1 = o1 + select(0u, 1u, o0 < v20); + v20 = o0; + v21 = o1; + + // b = rotr64(b ^ c, 24) + xor0 = v12 ^ v20; + xor1 = v13 ^ v21; + v12 = (xor0 >> 24u) ^ (xor1 << 8u); + v13 = (xor1 >> 24u) ^ (xor0 << 8u); + + // a = a + b + o0 = v4 + v12; + o1 = v5 + v13; + o1 = o1 + select(0u, 1u, o0 < v4); + v4 = o0; + v5 = o1; + + // a = a + m[sigma[r][2*i+1]] + o0 = v4 + m2; + o1 = v5 + m3; + o1 = o1 + select(0u, 1u, o0 < v4); + v4 = o0; + v5 = o1; + + // d = rotr64(d ^ a, 16) + xor0 = v28 ^ v4; + xor1 = v29 ^ v5; + v28 = (xor0 >> 16u) ^ (xor1 << 16u); + v29 = (xor1 >> 16u) ^ (xor0 << 16u); + + // c = c + d + o0 = v20 + v28; + o1 = v21 + v29; + o1 = o1 + select(0u, 1u, o0 < v20); + v20 = o0; + v21 = o1; + + // b = rotr64(b ^ c, 63) + xor0 = v12 ^ v20; + xor1 = v13 ^ v21; + v12 = (xor1 >> 31u) ^ (xor0 << 1u); + v13 = (xor0 >> 31u) ^ (xor1 << 1u); + + + + + + /** + * r=7, i=3(x2), a=v[6-7], b=v[14-15], c=v[22-23], d=v[30-31] + */ + + // a = a + b + o0 = v6 + v14; + o1 = v7 + v15; + o1 = o1 + select(0u, 1u, o0 < v6); + v6 = o0; + v7 = o1; + + // a = a + m[sigma[r][2*i+0]] + o0 = v6 + m6; + o1 = v7 + m7; + o1 = o1 + select(0u, 1u, o0 < v6); + v6 = o0; + v7 = o1; + + // d = rotr64(d ^ a, 32) + xor0 = v30 ^ v6; + xor1 = v31 ^ v7; + v30 = xor1; + v31 = xor0; + + // c = c + d + o0 = v22 + v30; + o1 = v23 + v31; + o1 = o1 + select(0u, 1u, o0 < v22); + v22 = o0; + v23 = o1; + + // b = rotr64(b ^ c, 24) + xor0 = v14 ^ v22; + xor1 = v15 ^ v23; + v14 = (xor0 >> 24u) ^ (xor1 << 8u); + v15 = (xor1 >> 24u) ^ (xor0 << 8u); + + // a = a + b + o0 = v6 + v14; + o1 = v7 + v15; + o1 = o1 + select(0u, 1u, o0 < v6); + v6 = o0; + v7 = o1; + + // // a = a + m[sigma[r][2*i+1]] + // // skip since adding 0u does nothing + // o0 = v6 + 0u; + // o1 = v7 + 0u; + // if (v6 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v6 = o0; + // v7 = o1; + + // d = rotr64(d ^ a, 16) + xor0 = v30 ^ v6; + xor1 = v31 ^ v7; + v30 = (xor0 >> 16u) ^ (xor1 << 16u); + v31 = (xor1 >> 16u) ^ (xor0 << 16u); + + // c = c + d + o0 = v22 + v30; + o1 = v23 + v31; + o1 = o1 + select(0u, 1u, o0 < v22); + v22 = o0; + v23 = o1; + + // b = rotr64(b ^ c, 63) + xor0 = v14 ^ v22; + xor1 = v15 ^ v23; + v14 = (xor1 >> 31u) ^ (xor0 << 1u); + v15 = (xor0 >> 31u) ^ (xor1 << 1u); + + + + + + /** + * r=7, i=4(x2), a=v[0-1], b=v[10-11], c=v[20-21], d=v[30-31] + */ + + // a = a + b + o0 = v0 + v10; + o1 = v1 + v11; + o1 = o1 + select(0u, 1u, o0 < v0); + v0 = o0; + v1 = o1; + + // // a = a + m[sigma[r][2*i+0]] + // // skip since adding 0u does nothing + // o0 = v0 + 0u; + // o1 = v1 + 0u; + // if (v0 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v0 = o0; + // v1 = o1; + + // d = rotr64(d ^ a, 32) + xor0 = v30 ^ v0; + xor1 = v31 ^ v1; + v30 = xor1; + v31 = xor0; + + // c = c + d + o0 = v20 + v30; + o1 = v21 + v31; + o1 = o1 + select(0u, 1u, o0 < v20); + v20 = o0; + v21 = o1; + + // b = rotr64(b ^ c, 24) + xor0 = v10 ^ v20; + xor1 = v11 ^ v21; + v10 = (xor0 >> 24u) ^ (xor1 << 8u); + v11 = (xor1 >> 24u) ^ (xor0 << 8u); + + // a = a + b + o0 = v0 + v10; + o1 = v1 + v11; + o1 = o1 + select(0u, 1u, o0 < v0); + v0 = o0; + v1 = o1; + + // a = a + m[sigma[r][2*i+1]] + o0 = v0 + m0; + o1 = v1 + m1; + o1 = o1 + select(0u, 1u, o0 < v0); + v0 = o0; + v1 = o1; + + // d = rotr64(d ^ a, 16) + xor0 = v30 ^ v0; + xor1 = v31 ^ v1; + v30 = (xor0 >> 16u) ^ (xor1 << 16u); + v31 = (xor1 >> 16u) ^ (xor0 << 16u); + + // c = c + d + o0 = v20 + v30; + o1 = v21 + v31; + o1 = o1 + select(0u, 1u, o0 < v20); + v20 = o0; + v21 = o1; + + // b = rotr64(b ^ c, 63) + xor0 = v10 ^ v20; + xor1 = v11 ^ v21; + v10 = (xor1 >> 31u) ^ (xor0 << 1u); + v11 = (xor0 >> 31u) ^ (xor1 << 1u); + + + + + + /** + * r=7, i=5(x2), a=v[2-3], b=v[12-13], c=v[22-23], d=v[24-25] + */ + + // a = a + b + o0 = v2 + v12; + o1 = v3 + v13; + o1 = o1 + select(0u, 1u, o0 < v2); + v2 = o0; + v3 = o1; + + // // a = a + m[sigma[r][2*i+0]] + // // skip since adding 0u does nothing + // o0 = v2 + 0u; + // o1 = v3 + 0u; + // if (v2 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v2 = o0; + // v3 = o1; + + // d = rotr64(d ^ a, 32) + xor0 = v24 ^ v2; + xor1 = v25 ^ v3; + v24 = xor1; + v25 = xor0; + + // c = c + d + o0 = v22 + v24; + o1 = v23 + v25; + o1 = o1 + select(0u, 1u, o0 < v22); + v22 = o0; + v23 = o1; + + // b = rotr64(b ^ c, 24) + xor0 = v12 ^ v22; + xor1 = v13 ^ v23; + v12 = (xor0 >> 24u) ^ (xor1 << 8u); + v13 = (xor1 >> 24u) ^ (xor0 << 8u); + + // a = a + b + o0 = v2 + v12; + o1 = v3 + v13; + o1 = o1 + select(0u, 1u, o0 < v2); + v2 = o0; + v3 = o1; + + // a = a + m[sigma[r][2*i+1]] + o0 = v2 + m8; + o1 = v3 + m9; + o1 = o1 + select(0u, 1u, o0 < v2); + v2 = o0; + v3 = o1; + + // d = rotr64(d ^ a, 16) + xor0 = v24 ^ v2; + xor1 = v25 ^ v3; + v24 = (xor0 >> 16u) ^ (xor1 << 16u); + v25 = (xor1 >> 16u) ^ (xor0 << 16u); + + // c = c + d + o0 = v22 + v24; + o1 = v23 + v25; + o1 = o1 + select(0u, 1u, o0 < v22); + v22 = o0; + v23 = o1; + + // b = rotr64(b ^ c, 63) + xor0 = v12 ^ v22; + xor1 = v13 ^ v23; + v12 = (xor1 >> 31u) ^ (xor0 << 1u); + v13 = (xor0 >> 31u) ^ (xor1 << 1u); + + + + + + /** + * r=7, i=6(x2), a=v[4-5], b=v[14-15], c=v[16-17], d=v[26-27] + */ + + // a = a + b + o0 = v4 + v14; + o1 = v5 + v15; + o1 = o1 + select(0u, 1u, o0 < v4); + v4 = o0; + v5 = o1; + + // // a = a + m[sigma[r][2*i+0]] + // // skip since adding 0u does nothing + // o0 = v4 + 0u; + // o1 = v5 + 0u; + // if (v4 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v4 = o0; + // v5 = o1; + + // d = rotr64(d ^ a, 32) + xor0 = v26 ^ v4; + xor1 = v27 ^ v5; + v26 = xor1; + v27 = xor0; + + // c = c + d + o0 = v16 + v26; + o1 = v17 + v27; + o1 = o1 + select(0u, 1u, o0 < v16); + v16 = o0; + v17 = o1; + + // b = rotr64(b ^ c, 24) + xor0 = v14 ^ v16; + xor1 = v15 ^ v17; + v14 = (xor0 >> 24u) ^ (xor1 << 8u); + v15 = (xor1 >> 24u) ^ (xor0 << 8u); + + // a = a + b + o0 = v4 + v14; + o1 = v5 + v15; + o1 = o1 + select(0u, 1u, o0 < v4); + v4 = o0; + v5 = o1; + + // // a = a + m[sigma[r][2*i+1]] + // // skip since adding 0u does nothing + // o0 = v4 + 0u; + // o1 = v5 + 0u; + // if (v4 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v4 = o0; + // v5 = o1; + + // d = rotr64(d ^ a, 16) + xor0 = v26 ^ v4; + xor1 = v27 ^ v5; + v26 = (xor0 >> 16u) ^ (xor1 << 16u); + v27 = (xor1 >> 16u) ^ (xor0 << 16u); + + // c = c + d + o0 = v16 + v26; + o1 = v17 + v27; + o1 = o1 + select(0u, 1u, o0 < v16); + v16 = o0; + v17 = o1; + + // b = rotr64(b ^ c, 63) + xor0 = v14 ^ v16; + xor1 = v15 ^ v17; + v14 = (xor1 >> 31u) ^ (xor0 << 1u); + v15 = (xor0 >> 31u) ^ (xor1 << 1u); + + + + + + /** + * r=7, i=7(x2), a=v[6-7], b=v[8-9], c=v[18-19], d=v[28-29] + */ + + // a = a + b + o0 = v6 + v8; + o1 = v7 + v9; + o1 = o1 + select(0u, 1u, o0 < v6); + v6 = o0; + v7 = o1; + + // a = a + m[sigma[r][2*i+0]] + o0 = v6 + m4; + o1 = v7 + m5; + o1 = o1 + select(0u, 1u, o0 < v6); + v6 = o0; + v7 = o1; + + // d = rotr64(d ^ a, 32) + xor0 = v28 ^ v6; + xor1 = v29 ^ v7; + v28 = xor1; + v29 = xor0; + + // c = c + d + o0 = v18 + v28; + o1 = v19 + v29; + o1 = o1 + select(0u, 1u, o0 < v18); + v18 = o0; + v19 = o1; + + // b = rotr64(b ^ c, 24) + xor0 = v8 ^ v18; + xor1 = v9 ^ v19; + v8 = (xor0 >> 24u) ^ (xor1 << 8u); + v9 = (xor1 >> 24u) ^ (xor0 << 8u); + + // a = a + b + o0 = v6 + v8; + o1 = v7 + v9; + o1 = o1 + select(0u, 1u, o0 < v6); + v6 = o0; + v7 = o1; + + // // a = a + m[sigma[r][2*i+1]] + // // skip since adding 0u does nothing + // o0 = v6 + 0u; + // o1 = v7 + 0u; + // if (v6 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v6 = o0; + // v7 = o1; + + // d = rotr64(d ^ a, 16) + xor0 = v28 ^ v6; + xor1 = v29 ^ v7; + v28 = (xor0 >> 16u) ^ (xor1 << 16u); + v29 = (xor1 >> 16u) ^ (xor0 << 16u); + + // c = c + d + o0 = v18 + v28; + o1 = v19 + v29; + o1 = o1 + select(0u, 1u, o0 < v18); + v18 = o0; + v19 = o1; + + // b = rotr64(b ^ c, 63) + xor0 = v8 ^ v18; + xor1 = v9 ^ v19; + v8 = (xor1 >> 31u) ^ (xor0 << 1u); + v9 = (xor0 >> 31u) ^ (xor1 << 1u); + + + + + + /**************************************************************************** + * ROUND(8) * + ****************************************************************************/ + + /** + * r=8, i=0(x2), a=v[0-1], b=v[8-9], c=v[16-17], d=v[24-25] + */ + + // a = a + b + o0 = v0 + v8; + o1 = v1 + v9; + o1 = o1 + select(0u, 1u, o0 < v0); + v0 = o0; + v1 = o1; + + // // a = a + m[sigma[r][2*i+0]] + // // skip since adding 0u does nothing + // o0 = v0 + 0u; + // o1 = v1 + 0u; + // if (v0 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v0 = o0; + // v1 = o1; + + // d = rotr64(d ^ a, 32) + xor0 = v24 ^ v0; + xor1 = v25 ^ v1; + v24 = xor1; + v25 = xor0; + + // c = c + d + o0 = v16 + v24; + o1 = v17 + v25; + o1 = o1 + select(0u, 1u, o0 < v16); + v16 = o0; + v17 = o1; + + // b = rotr64(b ^ c, 24) + xor0 = v8 ^ v16; + xor1 = v9 ^ v17; + v8 = (xor0 >> 24u) ^ (xor1 << 8u); + v9 = (xor1 >> 24u) ^ (xor0 << 8u); + + // a = a + b + o0 = v0 + v8; + o1 = v1 + v9; + o1 = o1 + select(0u, 1u, o0 < v0); + v0 = o0; + v1 = o1; + + // // a = a + m[sigma[r][2*i+1]] + // // skip since adding 0u does nothing + // o0 = v0 + 0u; + // o1 = v1 + 0u; + // if (v0 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v0 = o0; + // v1 = o1; + + // d = rotr64(d ^ a, 16) + xor0 = v24 ^ v0; + xor1 = v25 ^ v1; + v24 = (xor0 >> 16u) ^ (xor1 << 16u); + v25 = (xor1 >> 16u) ^ (xor0 << 16u); + + // c = c + d + o0 = v16 + v24; + o1 = v17 + v25; + o1 = o1 + select(0u, 1u, o0 < v16); + v16 = o0; + v17 = o1; + + // b = rotr64(b ^ c, 63) + xor0 = v8 ^ v16; + xor1 = v9 ^ v17; + v8 = (xor1 >> 31u) ^ (xor0 << 1u); + v9 = (xor0 >> 31u) ^ (xor1 << 1u); + + + + + + /** + * r=8, i=1(x2), a=v[2-3], b=v[10-11], c=v[18-19], d=v[26-27] + */ + + // a = a + b + o0 = v2 + v10; + o1 = v3 + v11; + o1 = o1 + select(0u, 1u, o0 < v2); + v2 = o0; + v3 = o1; + + // // a = a + m[sigma[r][2*i+0]] + // // skip since adding 0u does nothing + // o0 = v2 + 0u; + // o1 = v3 + 0u; + // if (v2 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v2 = o0; + // v3 = o1; + + // d = rotr64(d ^ a, 32) + xor0 = v26 ^ v2; + xor1 = v27 ^ v3; + v26 = xor1; + v27 = xor0; + + // c = c + d + o0 = v18 + v26; + o1 = v19 + v27; + o1 = o1 + select(0u, 1u, o0 < v18); + v18 = o0; + v19 = o1; + + // b = rotr64(b ^ c, 24) + xor0 = v10 ^ v18; + xor1 = v11 ^ v19; + v10 = (xor0 >> 24u) ^ (xor1 << 8u); + v11 = (xor1 >> 24u) ^ (xor0 << 8u); + + // a = a + b + o0 = v2 + v10; + o1 = v3 + v11; + o1 = o1 + select(0u, 1u, o0 < v2); + v2 = o0; + v3 = o1; + + // // a = a + m[sigma[r][2*i+1]] + // // skip since adding 0u does nothing + // o0 = v2 + 0u; + // o1 = v3 + 0u; + // if (v2 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v2 = o0; + // v3 = o1; + + // d = rotr64(d ^ a, 16) + xor0 = v26 ^ v2; + xor1 = v27 ^ v3; + v26 = (xor0 >> 16u) ^ (xor1 << 16u); + v27 = (xor1 >> 16u) ^ (xor0 << 16u); + + // c = c + d + o0 = v18 + v26; + o1 = v19 + v27; + o1 = o1 + select(0u, 1u, o0 < v18); + v18 = o0; + v19 = o1; + + // b = rotr64(b ^ c, 63) + xor0 = v10 ^ v18; + xor1 = v11 ^ v19; + v10 = (xor1 >> 31u) ^ (xor0 << 1u); + v11 = (xor0 >> 31u) ^ (xor1 << 1u); + + + + + + /** + * r=8, i=2(x2), a=v[4-5], b=v[12-13], c=v[20-21], d=v[28-29] + */ + + // a = a + b + o0 = v4 + v12; + o1 = v5 + v13; + o1 = o1 + select(0u, 1u, o0 < v4); + v4 = o0; + v5 = o1; + + // // a = a + m[sigma[r][2*i+0]] + // // skip since adding 0u does nothing + // o0 = v4 + 0u; + // o1 = v5 + 0u; + // if (v4 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v4 = o0; + // v5 = o1; + + // d = rotr64(d ^ a, 32) + xor0 = v28 ^ v4; + xor1 = v29 ^ v5; + v28 = xor1; + v29 = xor0; + + // c = c + d + o0 = v20 + v28; + o1 = v21 + v29; + o1 = o1 + select(0u, 1u, o0 < v20); + v20 = o0; + v21 = o1; + + // b = rotr64(b ^ c, 24) + xor0 = v12 ^ v20; + xor1 = v13 ^ v21; + v12 = (xor0 >> 24u) ^ (xor1 << 8u); + v13 = (xor1 >> 24u) ^ (xor0 << 8u); + + // a = a + b + o0 = v4 + v12; + o1 = v5 + v13; + o1 = o1 + select(0u, 1u, o0 < v4); + v4 = o0; + v5 = o1; + + // a = a + m[sigma[r][2*i+1]] + o0 = v4 + m6; + o1 = v5 + m7; + o1 = o1 + select(0u, 1u, o0 < v4); + v4 = o0; + v5 = o1; + + // d = rotr64(d ^ a, 16) + xor0 = v28 ^ v4; + xor1 = v29 ^ v5; + v28 = (xor0 >> 16u) ^ (xor1 << 16u); + v29 = (xor1 >> 16u) ^ (xor0 << 16u); + + // c = c + d + o0 = v20 + v28; + o1 = v21 + v29; + o1 = o1 + select(0u, 1u, o0 < v20); + v20 = o0; + v21 = o1; + + // b = rotr64(b ^ c, 63) + xor0 = v12 ^ v20; + xor1 = v13 ^ v21; + v12 = (xor1 >> 31u) ^ (xor0 << 1u); + v13 = (xor0 >> 31u) ^ (xor1 << 1u); + + + + + + /** + * r=8, i=3(x2), a=v[6-7], b=v[14-15], c=v[22-23], d=v[30-31] + */ + + // a = a + b + o0 = v6 + v14; + o1 = v7 + v15; + o1 = o1 + select(0u, 1u, o0 < v6); + v6 = o0; + v7 = o1; + + // a = a + m[sigma[r][2*i+0]] + o0 = v6 + m0; + o1 = v7 + m1; + o1 = o1 + select(0u, 1u, o0 < v6); + v6 = o0; + v7 = o1; + + // d = rotr64(d ^ a, 32) + xor0 = v30 ^ v6; + xor1 = v31 ^ v7; + v30 = xor1; + v31 = xor0; + + // c = c + d + o0 = v22 + v30; + o1 = v23 + v31; + o1 = o1 + select(0u, 1u, o0 < v22); + v22 = o0; + v23 = o1; + + // b = rotr64(b ^ c, 24) + xor0 = v14 ^ v22; + xor1 = v15 ^ v23; + v14 = (xor0 >> 24u) ^ (xor1 << 8u); + v15 = (xor1 >> 24u) ^ (xor0 << 8u); + + // a = a + b + o0 = v6 + v14; + o1 = v7 + v15; + o1 = o1 + select(0u, 1u, o0 < v6); + v6 = o0; + v7 = o1; + + // // a = a + m[sigma[r][2*i+1]] + // // skip since adding 0u does nothing + // o0 = v6 + 0u; + // o1 = v7 + 0u; + // if (v6 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v6 = o0; + // v7 = o1; + + // d = rotr64(d ^ a, 16) + xor0 = v30 ^ v6; + xor1 = v31 ^ v7; + v30 = (xor0 >> 16u) ^ (xor1 << 16u); + v31 = (xor1 >> 16u) ^ (xor0 << 16u); + + // c = c + d + o0 = v22 + v30; + o1 = v23 + v31; + o1 = o1 + select(0u, 1u, o0 < v22); + v22 = o0; + v23 = o1; + + // b = rotr64(b ^ c, 63) + xor0 = v14 ^ v22; + xor1 = v15 ^ v23; + v14 = (xor1 >> 31u) ^ (xor0 << 1u); + v15 = (xor0 >> 31u) ^ (xor1 << 1u); + + + + + + /** + * r=8, i=4(x2), a=v[0-1], b=v[10-11], c=v[20-21], d=v[30-31] + */ + + // a = a + b + o0 = v0 + v10; + o1 = v1 + v11; + o1 = o1 + select(0u, 1u, o0 < v0); + v0 = o0; + v1 = o1; + + // // a = a + m[sigma[r][2*i+0]] + // // skip since adding 0u does nothing + // o0 = v0 + 0u; + // o1 = v1 + 0u; + // if (v0 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v0 = o0; + // v1 = o1; + + // d = rotr64(d ^ a, 32) + xor0 = v30 ^ v0; + xor1 = v31 ^ v1; + v30 = xor1; + v31 = xor0; + + // c = c + d + o0 = v20 + v30; + o1 = v21 + v31; + o1 = o1 + select(0u, 1u, o0 < v20); + v20 = o0; + v21 = o1; + + // b = rotr64(b ^ c, 24) + xor0 = v10 ^ v20; + xor1 = v11 ^ v21; + v10 = (xor0 >> 24u) ^ (xor1 << 8u); + v11 = (xor1 >> 24u) ^ (xor0 << 8u); + + // a = a + b + o0 = v0 + v10; + o1 = v1 + v11; + o1 = o1 + select(0u, 1u, o0 < v0); + v0 = o0; + v1 = o1; + + // a = a + m[sigma[r][2*i+1]] + o0 = v0 + m4; + o1 = v1 + m5; + o1 = o1 + select(0u, 1u, o0 < v0); + v0 = o0; + v1 = o1; + + // d = rotr64(d ^ a, 16) + xor0 = v30 ^ v0; + xor1 = v31 ^ v1; + v30 = (xor0 >> 16u) ^ (xor1 << 16u); + v31 = (xor1 >> 16u) ^ (xor0 << 16u); + + // c = c + d + o0 = v20 + v30; + o1 = v21 + v31; + o1 = o1 + select(0u, 1u, o0 < v20); + v20 = o0; + v21 = o1; + + // b = rotr64(b ^ c, 63) + xor0 = v10 ^ v20; + xor1 = v11 ^ v21; + v10 = (xor1 >> 31u) ^ (xor0 << 1u); + v11 = (xor0 >> 31u) ^ (xor1 << 1u); + + + + + + /** + * r=8, i=5(x2), a=v[2-3], b=v[12-13], c=v[22-23], d=v[24-25] + */ + + // a = a + b + o0 = v2 + v12; + o1 = v3 + v13; + o1 = o1 + select(0u, 1u, o0 < v2); + v2 = o0; + v3 = o1; + + // // a = a + m[sigma[r][2*i+0]] + // // skip since adding 0u does nothing + // o0 = v2 + 0u; + // o1 = v3 + 0u; + // if (v2 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v2 = o0; + // v3 = o1; + + // d = rotr64(d ^ a, 32) + xor0 = v24 ^ v2; + xor1 = v25 ^ v3; + v24 = xor1; + v25 = xor0; + + // c = c + d + o0 = v22 + v24; + o1 = v23 + v25; + o1 = o1 + select(0u, 1u, o0 < v22); + v22 = o0; + v23 = o1; + + // b = rotr64(b ^ c, 24) + xor0 = v12 ^ v22; + xor1 = v13 ^ v23; + v12 = (xor0 >> 24u) ^ (xor1 << 8u); + v13 = (xor1 >> 24u) ^ (xor0 << 8u); + + // a = a + b + o0 = v2 + v12; + o1 = v3 + v13; + o1 = o1 + select(0u, 1u, o0 < v2); + v2 = o0; + v3 = o1; + + // // a = a + m[sigma[r][2*i+1]] + // // skip since adding 0u does nothing + // o0 = v2 + 0u; + // o1 = v3 + 0u; + // if (v2 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v2 = o0; + // v3 = o1; + + // d = rotr64(d ^ a, 16) + xor0 = v24 ^ v2; + xor1 = v25 ^ v3; + v24 = (xor0 >> 16u) ^ (xor1 << 16u); + v25 = (xor1 >> 16u) ^ (xor0 << 16u); + + // c = c + d + o0 = v22 + v24; + o1 = v23 + v25; + o1 = o1 + select(0u, 1u, o0 < v22); + v22 = o0; + v23 = o1; + + // b = rotr64(b ^ c, 63) + xor0 = v12 ^ v22; + xor1 = v13 ^ v23; + v12 = (xor1 >> 31u) ^ (xor0 << 1u); + v13 = (xor0 >> 31u) ^ (xor1 << 1u); + + + + + + /** + * r=8, i=6(x2), a=v[4-5], b=v[14-15], c=v[16-17], d=v[26-27] + */ + + // a = a + b + o0 = v4 + v14; + o1 = v5 + v15; + o1 = o1 + select(0u, 1u, o0 < v4); + v4 = o0; + v5 = o1; + + // a = a + m[sigma[r][2*i+0]] + o0 = v4 + m2; + o1 = v5 + m3; + o1 = o1 + select(0u, 1u, o0 < v4); + v4 = o0; + v5 = o1; + + // d = rotr64(d ^ a, 32) + xor0 = v26 ^ v4; + xor1 = v27 ^ v5; + v26 = xor1; + v27 = xor0; + + // c = c + d + o0 = v16 + v26; + o1 = v17 + v27; + o1 = o1 + select(0u, 1u, o0 < v16); + v16 = o0; + v17 = o1; + + // b = rotr64(b ^ c, 24) + xor0 = v14 ^ v16; + xor1 = v15 ^ v17; + v14 = (xor0 >> 24u) ^ (xor1 << 8u); + v15 = (xor1 >> 24u) ^ (xor0 << 8u); + + // a = a + b + o0 = v4 + v14; + o1 = v5 + v15; + o1 = o1 + select(0u, 1u, o0 < v4); + v4 = o0; + v5 = o1; + + // a = a + m[sigma[r][2*i+1]] + o0 = v4 + m8; + o1 = v5 + m9; + o1 = o1 + select(0u, 1u, o0 < v4); + v4 = o0; + v5 = o1; + + // d = rotr64(d ^ a, 16) + xor0 = v26 ^ v4; + xor1 = v27 ^ v5; + v26 = (xor0 >> 16u) ^ (xor1 << 16u); + v27 = (xor1 >> 16u) ^ (xor0 << 16u); + + // c = c + d + o0 = v16 + v26; + o1 = v17 + v27; + o1 = o1 + select(0u, 1u, o0 < v16); + v16 = o0; + v17 = o1; + + // b = rotr64(b ^ c, 63) + xor0 = v14 ^ v16; + xor1 = v15 ^ v17; + v14 = (xor1 >> 31u) ^ (xor0 << 1u); + v15 = (xor0 >> 31u) ^ (xor1 << 1u); + + + + + + /** + * r=8, i=7(x2), a=v[6-7], b=v[8-9], c=v[18-19], d=v[28-29] + */ + + // a = a + b + o0 = v6 + v8; + o1 = v7 + v9; + o1 = o1 + select(0u, 1u, o0 < v6); + v6 = o0; + v7 = o1; + + // // a = a + m[sigma[r][2*i+0]] + // // skip since adding 0u does nothing + // o0 = v6 + 0u; + // o1 = v7 + 0u; + // if (v6 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v6 = o0; + // v7 = o1; + + // d = rotr64(d ^ a, 32) + xor0 = v28 ^ v6; + xor1 = v29 ^ v7; + v28 = xor1; + v29 = xor0; + + // c = c + d + o0 = v18 + v28; + o1 = v19 + v29; + o1 = o1 + select(0u, 1u, o0 < v18); + v18 = o0; + v19 = o1; + + // b = rotr64(b ^ c, 24) + xor0 = v8 ^ v18; + xor1 = v9 ^ v19; + v8 = (xor0 >> 24u) ^ (xor1 << 8u); + v9 = (xor1 >> 24u) ^ (xor0 << 8u); + + // a = a + b + o0 = v6 + v8; + o1 = v7 + v9; + o1 = o1 + select(0u, 1u, o0 < v6); + v6 = o0; + v7 = o1; + + // // a = a + m[sigma[r][2*i+1]] + // // skip since adding 0u does nothing + // o0 = v6 + 0u; + // o1 = v7 + 0u; + // if (v6 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v6 = o0; + // v7 = o1; + + // d = rotr64(d ^ a, 16) + xor0 = v28 ^ v6; + xor1 = v29 ^ v7; + v28 = (xor0 >> 16u) ^ (xor1 << 16u); + v29 = (xor1 >> 16u) ^ (xor0 << 16u); + + // c = c + d + o0 = v18 + v28; + o1 = v19 + v29; + o1 = o1 + select(0u, 1u, o0 < v18); + v18 = o0; + v19 = o1; + + // b = rotr64(b ^ c, 63) + xor0 = v8 ^ v18; + xor1 = v9 ^ v19; + v8 = (xor1 >> 31u) ^ (xor0 << 1u); + v9 = (xor0 >> 31u) ^ (xor1 << 1u); + + + + + + /**************************************************************************** + * ROUND(9) * + ****************************************************************************/ + + /** + * r=9, i=0(x2), a=v[0-1], b=v[8-9], c=v[16-17], d=v[24-25] + */ + + // a = a + b + o0 = v0 + v8; + o1 = v1 + v9; + o1 = o1 + select(0u, 1u, o0 < v0); + v0 = o0; + v1 = o1; + + // // a = a + m[sigma[r][2*i+0]] + // // skip since adding 0u does nothing + // o0 = v0 + 0u; + // o1 = v1 + 0u; + // if (v0 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v0 = o0; + // v1 = o1; + + // d = rotr64(d ^ a, 32) + xor0 = v24 ^ v0; + xor1 = v25 ^ v1; + v24 = xor1; + v25 = xor0; + + // c = c + d + o0 = v16 + v24; + o1 = v17 + v25; + o1 = o1 + select(0u, 1u, o0 < v16); + v16 = o0; + v17 = o1; + + // b = rotr64(b ^ c, 24) + xor0 = v8 ^ v16; + xor1 = v9 ^ v17; + v8 = (xor0 >> 24u) ^ (xor1 << 8u); + v9 = (xor1 >> 24u) ^ (xor0 << 8u); + + // a = a + b + o0 = v0 + v8; + o1 = v1 + v9; + o1 = o1 + select(0u, 1u, o0 < v0); + v0 = o0; + v1 = o1; + + // a = a + m[sigma[r][2*i+1]] + o0 = v0 + m4; + o1 = v1 + m5; + o1 = o1 + select(0u, 1u, o0 < v0); + v0 = o0; + v1 = o1; + + // d = rotr64(d ^ a, 16) + xor0 = v24 ^ v0; + xor1 = v25 ^ v1; + v24 = (xor0 >> 16u) ^ (xor1 << 16u); + v25 = (xor1 >> 16u) ^ (xor0 << 16u); + + // c = c + d + o0 = v16 + v24; + o1 = v17 + v25; + o1 = o1 + select(0u, 1u, o0 < v16); + v16 = o0; + v17 = o1; + + // b = rotr64(b ^ c, 63) + xor0 = v8 ^ v16; + xor1 = v9 ^ v17; + v8 = (xor1 >> 31u) ^ (xor0 << 1u); + v9 = (xor0 >> 31u) ^ (xor1 << 1u); + + + + + + /** + * r=9, i=1(x2), a=v[2-3], b=v[10-11], c=v[18-19], d=v[26-27] + */ + + // a = a + b + o0 = v2 + v10; + o1 = v3 + v11; + o1 = o1 + select(0u, 1u, o0 < v2); + v2 = o0; + v3 = o1; + + // // a = a + m[sigma[r][2*i+0]] + // // skip since adding 0u does nothing + // o0 = v2 + 0u; + // o1 = v3 + 0u; + // if (v2 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v2 = o0; + // v3 = o1; + + // d = rotr64(d ^ a, 32) + xor0 = v26 ^ v2; + xor1 = v27 ^ v3; + v26 = xor1; + v27 = xor0; + + // c = c + d + o0 = v18 + v26; + o1 = v19 + v27; + o1 = o1 + select(0u, 1u, o0 < v18); + v18 = o0; + v19 = o1; + + // b = rotr64(b ^ c, 24) + xor0 = v10 ^ v18; + xor1 = v11 ^ v19; + v10 = (xor0 >> 24u) ^ (xor1 << 8u); + v11 = (xor1 >> 24u) ^ (xor0 << 8u); + + // a = a + b + o0 = v2 + v10; + o1 = v3 + v11; + o1 = o1 + select(0u, 1u, o0 < v2); + v2 = o0; + v3 = o1; + + // a = a + m[sigma[r][2*i+1]] + o0 = v2 + m8; + o1 = v3 + m9; + o1 = o1 + select(0u, 1u, o0 < v2); + v2 = o0; + v3 = o1; + + // d = rotr64(d ^ a, 16) + xor0 = v26 ^ v2; + xor1 = v27 ^ v3; + v26 = (xor0 >> 16u) ^ (xor1 << 16u); + v27 = (xor1 >> 16u) ^ (xor0 << 16u); + + // c = c + d + o0 = v18 + v26; + o1 = v19 + v27; + o1 = o1 + select(0u, 1u, o0 < v18); + v18 = o0; + v19 = o1; + + // b = rotr64(b ^ c, 63) + xor0 = v10 ^ v18; + xor1 = v11 ^ v19; + v10 = (xor1 >> 31u) ^ (xor0 << 1u); + v11 = (xor0 >> 31u) ^ (xor1 << 1u); + + + + + + /** + * r=9, i=2(x2), a=v[4-5], b=v[12-13], c=v[20-21], d=v[28-29] + */ + + // a = a + b + o0 = v4 + v12; + o1 = v5 + v13; + o1 = o1 + select(0u, 1u, o0 < v4); + v4 = o0; + v5 = o1; + + // // a = a + m[sigma[r][2*i+0]] + // // skip since adding 0u does nothing + // o0 = v4 + 0u; + // o1 = v5 + 0u; + // if (v4 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v4 = o0; + // v5 = o1; + + // d = rotr64(d ^ a, 32) + xor0 = v28 ^ v4; + xor1 = v29 ^ v5; + v28 = xor1; + v29 = xor0; + + // c = c + d + o0 = v20 + v28; + o1 = v21 + v29; + o1 = o1 + select(0u, 1u, o0 < v20); + v20 = o0; + v21 = o1; + + // b = rotr64(b ^ c, 24) + xor0 = v12 ^ v20; + xor1 = v13 ^ v21; + v12 = (xor0 >> 24u) ^ (xor1 << 8u); + v13 = (xor1 >> 24u) ^ (xor0 << 8u); + + // a = a + b + o0 = v4 + v12; + o1 = v5 + v13; + o1 = o1 + select(0u, 1u, o0 < v4); + v4 = o0; + v5 = o1; + + // // a = a + m[sigma[r][2*i+1]] + // // skip since adding 0u does nothing + // o0 = v4 + 0u; + // o1 = v5 + 0u; + // if (v4 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v4 = o0; + // v5 = o1; + + // d = rotr64(d ^ a, 16) + xor0 = v28 ^ v4; + xor1 = v29 ^ v5; + v28 = (xor0 >> 16u) ^ (xor1 << 16u); + v29 = (xor1 >> 16u) ^ (xor0 << 16u); + + // c = c + d + o0 = v20 + v28; + o1 = v21 + v29; + o1 = o1 + select(0u, 1u, o0 < v20); + v20 = o0; + v21 = o1; + + // b = rotr64(b ^ c, 63) + xor0 = v12 ^ v20; + xor1 = v13 ^ v21; + v12 = (xor1 >> 31u) ^ (xor0 << 1u); + v13 = (xor0 >> 31u) ^ (xor1 << 1u); + + + + + + /** + * r=9, i=3(x2), a=v[6-7], b=v[14-15], c=v[22-23], d=v[30-31] + */ + + // a = a + b + o0 = v6 + v14; + o1 = v7 + v15; + o1 = o1 + select(0u, 1u, o0 < v6); + v6 = o0; + v7 = o1; + + // a = a + m[sigma[r][2*i+0]] + o0 = v6 + m2; + o1 = v7 + m3; + o1 = o1 + select(0u, 1u, o0 < v6); + v6 = o0; + v7 = o1; + + // d = rotr64(d ^ a, 32) + xor0 = v30 ^ v6; + xor1 = v31 ^ v7; + v30 = xor1; + v31 = xor0; + + // c = c + d + o0 = v22 + v30; + o1 = v23 + v31; + o1 = o1 + select(0u, 1u, o0 < v22); + v22 = o0; + v23 = o1; + + // b = rotr64(b ^ c, 24) + xor0 = v14 ^ v22; + xor1 = v15 ^ v23; + v14 = (xor0 >> 24u) ^ (xor1 << 8u); + v15 = (xor1 >> 24u) ^ (xor0 << 8u); + + // a = a + b + o0 = v6 + v14; + o1 = v7 + v15; + o1 = o1 + select(0u, 1u, o0 < v6); + v6 = o0; + v7 = o1; + + // // a = a + m[sigma[r][2*i+1]] + // // skip since adding 0u does nothing + // o0 = v6 + 0u; + // o1 = v7 + 0u; + // if (v6 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v6 = o0; + // v7 = o1; + + // d = rotr64(d ^ a, 16) + xor0 = v30 ^ v6; + xor1 = v31 ^ v7; + v30 = (xor0 >> 16u) ^ (xor1 << 16u); + v31 = (xor1 >> 16u) ^ (xor0 << 16u); + + // c = c + d + o0 = v22 + v30; + o1 = v23 + v31; + o1 = o1 + select(0u, 1u, o0 < v22); + v22 = o0; + v23 = o1; + + // b = rotr64(b ^ c, 63) + xor0 = v14 ^ v22; + xor1 = v15 ^ v23; + v14 = (xor1 >> 31u) ^ (xor0 << 1u); + v15 = (xor0 >> 31u) ^ (xor1 << 1u); + + + + + + /** + * r=9, i=4(x2), a=v[0-1], b=v[10-11], c=v[20-21], d=v[30-31] + */ + + // a = a + b + o0 = v0 + v10; + o1 = v1 + v11; + o1 = o1 + select(0u, 1u, o0 < v0); + v0 = o0; + v1 = o1; + + // // a = a + m[sigma[r][2*i+0]] + // // skip since adding 0u does nothing + // o0 = v0 + 0u; + // o1 = v1 + 0u; + // if (v0 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v0 = o0; + // v1 = o1; + + // d = rotr64(d ^ a, 32) + xor0 = v30 ^ v0; + xor1 = v31 ^ v1; + v30 = xor1; + v31 = xor0; + + // c = c + d + o0 = v20 + v30; + o1 = v21 + v31; + o1 = o1 + select(0u, 1u, o0 < v20); + v20 = o0; + v21 = o1; + + // b = rotr64(b ^ c, 24) + xor0 = v10 ^ v20; + xor1 = v11 ^ v21; + v10 = (xor0 >> 24u) ^ (xor1 << 8u); + v11 = (xor1 >> 24u) ^ (xor0 << 8u); + + // a = a + b + o0 = v0 + v10; + o1 = v1 + v11; + o1 = o1 + select(0u, 1u, o0 < v0); + v0 = o0; + v1 = o1; + + // // a = a + m[sigma[r][2*i+1]] + // // skip since adding 0u does nothing + // o0 = v0 + 0u; + // o1 = v1 + 0u; + // if (v0 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v0 = o0; + // v1 = o1; + + // d = rotr64(d ^ a, 16) + xor0 = v30 ^ v0; + xor1 = v31 ^ v1; + v30 = (xor0 >> 16u) ^ (xor1 << 16u); + v31 = (xor1 >> 16u) ^ (xor0 << 16u); + + // c = c + d + o0 = v20 + v30; + o1 = v21 + v31; + o1 = o1 + select(0u, 1u, o0 < v20); + v20 = o0; + v21 = o1; + + // b = rotr64(b ^ c, 63) + xor0 = v10 ^ v20; + xor1 = v11 ^ v21; + v10 = (xor1 >> 31u) ^ (xor0 << 1u); + v11 = (xor0 >> 31u) ^ (xor1 << 1u); + + + + + + /** + * r=9, i=5(x2), a=v[2-3], b=v[12-13], c=v[22-23], d=v[24-25] + */ + + // a = a + b + o0 = v2 + v12; + o1 = v3 + v13; + o1 = o1 + select(0u, 1u, o0 < v2); + v2 = o0; + v3 = o1; + + // // a = a + m[sigma[r][2*i+0]] + // // skip since adding 0u does nothing + // o0 = v2 + 0u; + // o1 = v3 + 0u; + // if (v2 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v2 = o0; + // v3 = o1; + + // d = rotr64(d ^ a, 32) + xor0 = v24 ^ v2; + xor1 = v25 ^ v3; + v24 = xor1; + v25 = xor0; + + // c = c + d + o0 = v22 + v24; + o1 = v23 + v25; + o1 = o1 + select(0u, 1u, o0 < v22); + v22 = o0; + v23 = o1; + + // b = rotr64(b ^ c, 24) + xor0 = v12 ^ v22; + xor1 = v13 ^ v23; + v12 = (xor0 >> 24u) ^ (xor1 << 8u); + v13 = (xor1 >> 24u) ^ (xor0 << 8u); + + // a = a + b + o0 = v2 + v12; + o1 = v3 + v13; + o1 = o1 + select(0u, 1u, o0 < v2); + v2 = o0; + v3 = o1; + + // // a = a + m[sigma[r][2*i+1]] + // // skip since adding 0u does nothing + // o0 = v2 + 0u; + // o1 = v3 + 0u; + // if (v2 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v2 = o0; + // v3 = o1; + + // d = rotr64(d ^ a, 16) + xor0 = v24 ^ v2; + xor1 = v25 ^ v3; + v24 = (xor0 >> 16u) ^ (xor1 << 16u); + v25 = (xor1 >> 16u) ^ (xor0 << 16u); + + // c = c + d + o0 = v22 + v24; + o1 = v23 + v25; + o1 = o1 + select(0u, 1u, o0 < v22); + v22 = o0; + v23 = o1; + + // b = rotr64(b ^ c, 63) + xor0 = v12 ^ v22; + xor1 = v13 ^ v23; + v12 = (xor1 >> 31u) ^ (xor0 << 1u); + v13 = (xor0 >> 31u) ^ (xor1 << 1u); + + + + + + /** + * r=9, i=6(x2), a=v[4-5], b=v[14-15], c=v[16-17], d=v[26-27] + */ + + // a = a + b + o0 = v4 + v14; + o1 = v5 + v15; + o1 = o1 + select(0u, 1u, o0 < v4); + v4 = o0; + v5 = o1; + + // a = a + m[sigma[r][2*i+0]] + o0 = v4 + m6; + o1 = v5 + m7; + o1 = o1 + select(0u, 1u, o0 < v4); + v4 = o0; + v5 = o1; + + // d = rotr64(d ^ a, 32) + xor0 = v26 ^ v4; + xor1 = v27 ^ v5; + v26 = xor1; + v27 = xor0; + + // c = c + d + o0 = v16 + v26; + o1 = v17 + v27; + o1 = o1 + select(0u, 1u, o0 < v16); + v16 = o0; + v17 = o1; + + // b = rotr64(b ^ c, 24) + xor0 = v14 ^ v16; + xor1 = v15 ^ v17; + v14 = (xor0 >> 24u) ^ (xor1 << 8u); + v15 = (xor1 >> 24u) ^ (xor0 << 8u); + + // a = a + b + o0 = v4 + v14; + o1 = v5 + v15; + o1 = o1 + select(0u, 1u, o0 < v4); + v4 = o0; + v5 = o1; + + // // a = a + m[sigma[r][2*i+1]] + // // skip since adding 0u does nothing + // o0 = v4 + 0u; + // o1 = v5 + 0u; + // if (v4 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v4 = o0; + // v5 = o1; + + // d = rotr64(d ^ a, 16) + xor0 = v26 ^ v4; + xor1 = v27 ^ v5; + v26 = (xor0 >> 16u) ^ (xor1 << 16u); + v27 = (xor1 >> 16u) ^ (xor0 << 16u); + + // c = c + d + o0 = v16 + v26; + o1 = v17 + v27; + o1 = o1 + select(0u, 1u, o0 < v16); + v16 = o0; + v17 = o1; + + // b = rotr64(b ^ c, 63) + xor0 = v14 ^ v16; + xor1 = v15 ^ v17; + v14 = (xor1 >> 31u) ^ (xor0 << 1u); + v15 = (xor0 >> 31u) ^ (xor1 << 1u); + + + + + + /** + * r=9, i=7(x2), a=v[6-7], b=v[8-9], c=v[18-19], d=v[28-29] + */ + + // a = a + b + o0 = v6 + v8; + o1 = v7 + v9; + o1 = o1 + select(0u, 1u, o0 < v6); + v6 = o0; + v7 = o1; + + // // a = a + m[sigma[r][2*i+0]] + // // skip since adding 0u does nothing + // o0 = v6 + 0u; + // o1 = v7 + 0u; + // if (v6 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v6 = o0; + // v7 = o1; + + // d = rotr64(d ^ a, 32) + xor0 = v28 ^ v6; + xor1 = v29 ^ v7; + v28 = xor1; + v29 = xor0; + + // c = c + d + o0 = v18 + v28; + o1 = v19 + v29; + o1 = o1 + select(0u, 1u, o0 < v18); + v18 = o0; + v19 = o1; + + // b = rotr64(b ^ c, 24) + xor0 = v8 ^ v18; + xor1 = v9 ^ v19; + v8 = (xor0 >> 24u) ^ (xor1 << 8u); + v9 = (xor1 >> 24u) ^ (xor0 << 8u); + + // a = a + b + o0 = v6 + v8; + o1 = v7 + v9; + o1 = o1 + select(0u, 1u, o0 < v6); + v6 = o0; + v7 = o1; + + // a = a + m[sigma[r][2*i+1]] + o0 = v6 + m0; + o1 = v7 + m1; + o1 = o1 + select(0u, 1u, o0 < v6); + v6 = o0; + v7 = o1; + + // d = rotr64(d ^ a, 16) + xor0 = v28 ^ v6; + xor1 = v29 ^ v7; + v28 = (xor0 >> 16u) ^ (xor1 << 16u); + v29 = (xor1 >> 16u) ^ (xor0 << 16u); + + // c = c + d + o0 = v18 + v28; + o1 = v19 + v29; + o1 = o1 + select(0u, 1u, o0 < v18); + v18 = o0; + v19 = o1; + + // b = rotr64(b ^ c, 63) + xor0 = v8 ^ v18; + xor1 = v9 ^ v19; + v8 = (xor1 >> 31u) ^ (xor0 << 1u); + v9 = (xor0 >> 31u) ^ (xor1 << 1u); + + + + + + /**************************************************************************** + * ROUND(10) * + ****************************************************************************/ + + /** + * r=10, i=0(x2), a=v[0-1], b=v[8-9], c=v[16-17], d=v[24-25] + */ + + // a = a + b + o0 = v0 + v8; + o1 = v1 + v9; + o1 = o1 + select(0u, 1u, o0 < v0); + v0 = o0; + v1 = o1; + + // a = a + m[sigma[r][2*i+0]] + o0 = v0 + m0; + o1 = v1 + m1; + o1 = o1 + select(0u, 1u, o0 < v0); + v0 = o0; + v1 = o1; + + // d = rotr64(d ^ a, 32) + xor0 = v24 ^ v0; + xor1 = v25 ^ v1; + v24 = xor1; + v25 = xor0; + + // c = c + d + o0 = v16 + v24; + o1 = v17 + v25; + o1 = o1 + select(0u, 1u, o0 < v16); + v16 = o0; + v17 = o1; + + // b = rotr64(b ^ c, 24) + xor0 = v8 ^ v16; + xor1 = v9 ^ v17; + v8 = (xor0 >> 24u) ^ (xor1 << 8u); + v9 = (xor1 >> 24u) ^ (xor0 << 8u); + + // a = a + b + o0 = v0 + v8; + o1 = v1 + v9; + o1 = o1 + select(0u, 1u, o0 < v0); + v0 = o0; + v1 = o1; + + // a = a + m[sigma[r][2*i+1]] + o0 = v0 + m2; + o1 = v1 + m3; + o1 = o1 + select(0u, 1u, o0 < v0); + v0 = o0; + v1 = o1; + + // d = rotr64(d ^ a, 16) + xor0 = v24 ^ v0; + xor1 = v25 ^ v1; + v24 = (xor0 >> 16u) ^ (xor1 << 16u); + v25 = (xor1 >> 16u) ^ (xor0 << 16u); + + // c = c + d + o0 = v16 + v24; + o1 = v17 + v25; + o1 = o1 + select(0u, 1u, o0 < v16); + v16 = o0; + v17 = o1; + + // b = rotr64(b ^ c, 63) + xor0 = v8 ^ v16; + xor1 = v9 ^ v17; + v8 = (xor1 >> 31u) ^ (xor0 << 1u); + v9 = (xor0 >> 31u) ^ (xor1 << 1u); + + + + + + /** + * r=10, i=1(x2), a=v[2-3], b=v[10-11], c=v[18-19], d=v[26-27] + */ + + // a = a + b + o0 = v2 + v10; + o1 = v3 + v11; + o1 = o1 + select(0u, 1u, o0 < v2); + v2 = o0; + v3 = o1; + + // a = a + m[sigma[r][2*i+0]] + o0 = v2 + m4; + o1 = v3 + m5; + o1 = o1 + select(0u, 1u, o0 < v2); + v2 = o0; + v3 = o1; + + // d = rotr64(d ^ a, 32) + xor0 = v26 ^ v2; + xor1 = v27 ^ v3; + v26 = xor1; + v27 = xor0; + + // c = c + d + o0 = v18 + v26; + o1 = v19 + v27; + o1 = o1 + select(0u, 1u, o0 < v18); + v18 = o0; + v19 = o1; + + // b = rotr64(b ^ c, 24) + xor0 = v10 ^ v18; + xor1 = v11 ^ v19; + v10 = (xor0 >> 24u) ^ (xor1 << 8u); + v11 = (xor1 >> 24u) ^ (xor0 << 8u); + + // a = a + b + o0 = v2 + v10; + o1 = v3 + v11; + o1 = o1 + select(0u, 1u, o0 < v2); + v2 = o0; + v3 = o1; + + // a = a + m[sigma[r][2*i+1]] + o0 = v2 + m6; + o1 = v3 + m7; + o1 = o1 + select(0u, 1u, o0 < v2); + v2 = o0; + v3 = o1; + + // d = rotr64(d ^ a, 16) + xor0 = v26 ^ v2; + xor1 = v27 ^ v3; + v26 = (xor0 >> 16u) ^ (xor1 << 16u); + v27 = (xor1 >> 16u) ^ (xor0 << 16u); + + // c = c + d + o0 = v18 + v26; + o1 = v19 + v27; + o1 = o1 + select(0u, 1u, o0 < v18); + v18 = o0; + v19 = o1; + + // b = rotr64(b ^ c, 63) + xor0 = v10 ^ v18; + xor1 = v11 ^ v19; + v10 = (xor1 >> 31u) ^ (xor0 << 1u); + v11 = (xor0 >> 31u) ^ (xor1 << 1u); + + + + + + /** + * r=10, i=2(x2), a=v[4-5], b=v[12-13], c=v[20-21], d=v[28-29] + */ + + // a = a + b + o0 = v4 + v12; + o1 = v5 + v13; + o1 = o1 + select(0u, 1u, o0 < v4); + v4 = o0; + v5 = o1; + + // a = a + m[sigma[r][2*i+0]] + o0 = v4 + m8; + o1 = v5 + m9; + o1 = o1 + select(0u, 1u, o0 < v4); + v4 = o0; + v5 = o1; + + // d = rotr64(d ^ a, 32) + xor0 = v28 ^ v4; + xor1 = v29 ^ v5; + v28 = xor1; + v29 = xor0; + + // c = c + d + o0 = v20 + v28; + o1 = v21 + v29; + o1 = o1 + select(0u, 1u, o0 < v20); + v20 = o0; + v21 = o1; + + // b = rotr64(b ^ c, 24) + xor0 = v12 ^ v20; + xor1 = v13 ^ v21; + v12 = (xor0 >> 24u) ^ (xor1 << 8u); + v13 = (xor1 >> 24u) ^ (xor0 << 8u); + + // a = a + b + o0 = v4 + v12; + o1 = v5 + v13; + o1 = o1 + select(0u, 1u, o0 < v4); + v4 = o0; + v5 = o1; + + // // a = a + m[sigma[r][2*i+1]] + // // skip since adding 0u does nothing + // o0 = v4 + 0u; + // o1 = v5 + 0u; + // if (v4 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v4 = o0; + // v5 = o1; + + // d = rotr64(d ^ a, 16) + xor0 = v28 ^ v4; + xor1 = v29 ^ v5; + v28 = (xor0 >> 16u) ^ (xor1 << 16u); + v29 = (xor1 >> 16u) ^ (xor0 << 16u); + + // c = c + d + o0 = v20 + v28; + o1 = v21 + v29; + o1 = o1 + select(0u, 1u, o0 < v20); + v20 = o0; + v21 = o1; + + // b = rotr64(b ^ c, 63) + xor0 = v12 ^ v20; + xor1 = v13 ^ v21; + v12 = (xor1 >> 31u) ^ (xor0 << 1u); + v13 = (xor0 >> 31u) ^ (xor1 << 1u); + + + + + + /** + * r=10, i=3(x2), a=v[6-7], b=v[14-15], c=v[22-23], d=v[30-31] + */ + + // a = a + b + o0 = v6 + v14; + o1 = v7 + v15; + o1 = o1 + select(0u, 1u, o0 < v6); + v6 = o0; + v7 = o1; + + // // a = a + m[sigma[r][2*i+0]] + // // skip since adding 0u does nothing + // o0 = v6 + 0u; + // o1 = v7 + 0u; + // if (v6 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v6 = o0; + // v7 = o1; + + // d = rotr64(d ^ a, 32) + xor0 = v30 ^ v6; + xor1 = v31 ^ v7; + v30 = xor1; + v31 = xor0; + + // c = c + d + o0 = v22 + v30; + o1 = v23 + v31; + o1 = o1 + select(0u, 1u, o0 < v22); + v22 = o0; + v23 = o1; + + // b = rotr64(b ^ c, 24) + xor0 = v14 ^ v22; + xor1 = v15 ^ v23; + v14 = (xor0 >> 24u) ^ (xor1 << 8u); + v15 = (xor1 >> 24u) ^ (xor0 << 8u); + + // a = a + b + o0 = v6 + v14; + o1 = v7 + v15; + o1 = o1 + select(0u, 1u, o0 < v6); + v6 = o0; + v7 = o1; + + // // a = a + m[sigma[r][2*i+1]] + // // skip since adding 0u does nothing + // o0 = v6 + 0u; + // o1 = v7 + 0u; + // if (v6 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v6 = o0; + // v7 = o1; + + // d = rotr64(d ^ a, 16) + xor0 = v30 ^ v6; + xor1 = v31 ^ v7; + v30 = (xor0 >> 16u) ^ (xor1 << 16u); + v31 = (xor1 >> 16u) ^ (xor0 << 16u); + + // c = c + d + o0 = v22 + v30; + o1 = v23 + v31; + o1 = o1 + select(0u, 1u, o0 < v22); + v22 = o0; + v23 = o1; + + // b = rotr64(b ^ c, 63) + xor0 = v14 ^ v22; + xor1 = v15 ^ v23; + v14 = (xor1 >> 31u) ^ (xor0 << 1u); + v15 = (xor0 >> 31u) ^ (xor1 << 1u); + + + + + + /** + * r=10, i=4(x2), a=v[0-1], b=v[10-11], c=v[20-21], d=v[30-31] + */ + + // a = a + b + o0 = v0 + v10; + o1 = v1 + v11; + o1 = o1 + select(0u, 1u, o0 < v0); + v0 = o0; + v1 = o1; + + // // a = a + m[sigma[r][2*i+0]] + // // skip since adding 0u does nothing + // o0 = v0 + 0u; + // o1 = v1 + 0u; + // if (v0 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v0 = o0; + // v1 = o1; + + // d = rotr64(d ^ a, 32) + xor0 = v30 ^ v0; + xor1 = v31 ^ v1; + v30 = xor1; + v31 = xor0; + + // c = c + d + o0 = v20 + v30; + o1 = v21 + v31; + o1 = o1 + select(0u, 1u, o0 < v20); + v20 = o0; + v21 = o1; + + // b = rotr64(b ^ c, 24) + xor0 = v10 ^ v20; + xor1 = v11 ^ v21; + v10 = (xor0 >> 24u) ^ (xor1 << 8u); + v11 = (xor1 >> 24u) ^ (xor0 << 8u); + + // a = a + b + o0 = v0 + v10; + o1 = v1 + v11; + o1 = o1 + select(0u, 1u, o0 < v0); + v0 = o0; + v1 = o1; + + // // a = a + m[sigma[r][2*i+1]] + // // skip since adding 0u does nothing + // o0 = v0 + 0u; + // o1 = v1 + 0u; + // if (v0 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v0 = o0; + // v1 = o1; + + // d = rotr64(d ^ a, 16) + xor0 = v30 ^ v0; + xor1 = v31 ^ v1; + v30 = (xor0 >> 16u) ^ (xor1 << 16u); + v31 = (xor1 >> 16u) ^ (xor0 << 16u); + + // c = c + d + o0 = v20 + v30; + o1 = v21 + v31; + o1 = o1 + select(0u, 1u, o0 < v20); + v20 = o0; + v21 = o1; + + // b = rotr64(b ^ c, 63) + xor0 = v10 ^ v20; + xor1 = v11 ^ v21; + v10 = (xor1 >> 31u) ^ (xor0 << 1u); + v11 = (xor0 >> 31u) ^ (xor1 << 1u); + + + + + + /** + * r=10, i=5(x2), a=v[2-3], b=v[12-13], c=v[22-23], d=v[24-25] + */ + + // a = a + b + o0 = v2 + v12; + o1 = v3 + v13; + o1 = o1 + select(0u, 1u, o0 < v2); + v2 = o0; + v3 = o1; + + // // a = a + m[sigma[r][2*i+0]] + // // skip since adding 0u does nothing + // o0 = v2 + 0u; + // o1 = v3 + 0u; + // if (v2 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v2 = o0; + // v3 = o1; + + // d = rotr64(d ^ a, 32) + xor0 = v24 ^ v2; + xor1 = v25 ^ v3; + v24 = xor1; + v25 = xor0; + + // c = c + d + o0 = v22 + v24; + o1 = v23 + v25; + o1 = o1 + select(0u, 1u, o0 < v22); + v22 = o0; + v23 = o1; + + // b = rotr64(b ^ c, 24) + xor0 = v12 ^ v22; + xor1 = v13 ^ v23; + v12 = (xor0 >> 24u) ^ (xor1 << 8u); + v13 = (xor1 >> 24u) ^ (xor0 << 8u); + + // a = a + b + o0 = v2 + v12; + o1 = v3 + v13; + o1 = o1 + select(0u, 1u, o0 < v2); + v2 = o0; + v3 = o1; + + // // a = a + m[sigma[r][2*i+1]] + // // skip since adding 0u does nothing + // o0 = v2 + 0u; + // o1 = v3 + 0u; + // if (v2 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v2 = o0; + // v3 = o1; + + // d = rotr64(d ^ a, 16) + xor0 = v24 ^ v2; + xor1 = v25 ^ v3; + v24 = (xor0 >> 16u) ^ (xor1 << 16u); + v25 = (xor1 >> 16u) ^ (xor0 << 16u); + + // c = c + d + o0 = v22 + v24; + o1 = v23 + v25; + o1 = o1 + select(0u, 1u, o0 < v22); + v22 = o0; + v23 = o1; + + // b = rotr64(b ^ c, 63) + xor0 = v12 ^ v22; + xor1 = v13 ^ v23; + v12 = (xor1 >> 31u) ^ (xor0 << 1u); + v13 = (xor0 >> 31u) ^ (xor1 << 1u); + + + + + + /** + * r=10, i=6(x2), a=v[4-5], b=v[14-15], c=v[16-17], d=v[26-27] + */ + + // a = a + b + o0 = v4 + v14; + o1 = v5 + v15; + o1 = o1 + select(0u, 1u, o0 < v4); + v4 = o0; + v5 = o1; + + // // a = a + m[sigma[r][2*i+0]] + // // skip since adding 0u does nothing + // o0 = v4 + 0u; + // o1 = v5 + 0u; + // if (v4 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v4 = o0; + // v5 = o1; + + // d = rotr64(d ^ a, 32) + xor0 = v26 ^ v4; + xor1 = v27 ^ v5; + v26 = xor1; + v27 = xor0; + + // c = c + d + o0 = v16 + v26; + o1 = v17 + v27; + o1 = o1 + select(0u, 1u, o0 < v16); + v16 = o0; + v17 = o1; + + // b = rotr64(b ^ c, 24) + xor0 = v14 ^ v16; + xor1 = v15 ^ v17; + v14 = (xor0 >> 24u) ^ (xor1 << 8u); + v15 = (xor1 >> 24u) ^ (xor0 << 8u); + + // a = a + b + o0 = v4 + v14; + o1 = v5 + v15; + o1 = o1 + select(0u, 1u, o0 < v4); + v4 = o0; + v5 = o1; + + // // a = a + m[sigma[r][2*i+1]] + // // skip since adding 0u does nothing + // o0 = v4 + 0u; + // o1 = v5 + 0u; + // if (v4 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v4 = o0; + // v5 = o1; + + // d = rotr64(d ^ a, 16) + xor0 = v26 ^ v4; + xor1 = v27 ^ v5; + v26 = (xor0 >> 16u) ^ (xor1 << 16u); + v27 = (xor1 >> 16u) ^ (xor0 << 16u); + + // c = c + d + o0 = v16 + v26; + o1 = v17 + v27; + o1 = o1 + select(0u, 1u, o0 < v16); + v16 = o0; + v17 = o1; + + // b = rotr64(b ^ c, 63) + xor0 = v14 ^ v16; + xor1 = v15 ^ v17; + v14 = (xor1 >> 31u) ^ (xor0 << 1u); + v15 = (xor0 >> 31u) ^ (xor1 << 1u); + + + + + + /** + * r=10, i=7(x2), a=v[6-7], b=v[8-9], c=v[18-19], d=v[28-29] + */ + + // a = a + b + o0 = v6 + v8; + o1 = v7 + v9; + o1 = o1 + select(0u, 1u, o0 < v6); + v6 = o0; + v7 = o1; + + // // a = a + m[sigma[r][2*i+0]] + // // skip since adding 0u does nothing + // o0 = v6 + 0u; + // o1 = v7 + 0u; + // if (v6 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v6 = o0; + // v7 = o1; + + // d = rotr64(d ^ a, 32) + xor0 = v28 ^ v6; + xor1 = v29 ^ v7; + v28 = xor1; + v29 = xor0; + + // c = c + d + o0 = v18 + v28; + o1 = v19 + v29; + o1 = o1 + select(0u, 1u, o0 < v18); + v18 = o0; + v19 = o1; + + // b = rotr64(b ^ c, 24) + xor0 = v8 ^ v18; + xor1 = v9 ^ v19; + v8 = (xor0 >> 24u) ^ (xor1 << 8u); + v9 = (xor1 >> 24u) ^ (xor0 << 8u); + + // a = a + b + o0 = v6 + v8; + o1 = v7 + v9; + o1 = o1 + select(0u, 1u, o0 < v6); + v6 = o0; + v7 = o1; + + // // a = a + m[sigma[r][2*i+1]] + // // skip since adding 0u does nothing + // o0 = v6 + 0u; + // o1 = v7 + 0u; + // if (v6 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v6 = o0; + // v7 = o1; + + // d = rotr64(d ^ a, 16) + xor0 = v28 ^ v6; + xor1 = v29 ^ v7; + v28 = (xor0 >> 16u) ^ (xor1 << 16u); + v29 = (xor1 >> 16u) ^ (xor0 << 16u); + + // c = c + d + o0 = v18 + v28; + o1 = v19 + v29; + o1 = o1 + select(0u, 1u, o0 < v18); + v18 = o0; + v19 = o1; + + // b = rotr64(b ^ c, 63) + xor0 = v8 ^ v18; + xor1 = v9 ^ v19; + v8 = (xor1 >> 31u) ^ (xor0 << 1u); + v9 = (xor0 >> 31u) ^ (xor1 << 1u); + + + + + + /**************************************************************************** + * ROUND(11) * + ****************************************************************************/ + + /** + * r=11, i=0(x2), a=v[0-1], b=v[8-9], c=v[16-17], d=v[24-25] + */ + + // a = a + b + o0 = v0 + v8; + o1 = v1 + v9; + o1 = o1 + select(0u, 1u, o0 < v0); + v0 = o0; + v1 = o1; + + // // a = a + m[sigma[r][2*i+0]] + // // skip since adding 0u does nothing + // o0 = v0 + 0u; + // o1 = v1 + 0u; + // if (v0 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v0 = o0; + // v1 = o1; + + // d = rotr64(d ^ a, 32) + xor0 = v24 ^ v0; + xor1 = v25 ^ v1; + v24 = xor1; + v25 = xor0; + + // c = c + d + o0 = v16 + v24; + o1 = v17 + v25; + o1 = o1 + select(0u, 1u, o0 < v16); + v16 = o0; + v17 = o1; + + // b = rotr64(b ^ c, 24) + xor0 = v8 ^ v16; + xor1 = v9 ^ v17; + v8 = (xor0 >> 24u) ^ (xor1 << 8u); + v9 = (xor1 >> 24u) ^ (xor0 << 8u); + + // a = a + b + o0 = v0 + v8; + o1 = v1 + v9; + o1 = o1 + select(0u, 1u, o0 < v0); + v0 = o0; + v1 = o1; + + // // a = a + m[sigma[r][2*i+1]] + // // skip since adding 0u does nothing + // o0 = v0 + 0u; + // o1 = v1 + 0u; + // if (v0 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v0 = o0; + // v1 = o1; + + // d = rotr64(d ^ a, 16) + xor0 = v24 ^ v0; + xor1 = v25 ^ v1; + v24 = (xor0 >> 16u) ^ (xor1 << 16u); + v25 = (xor1 >> 16u) ^ (xor0 << 16u); + + // c = c + d + o0 = v16 + v24; + o1 = v17 + v25; + o1 = o1 + select(0u, 1u, o0 < v16); + v16 = o0; + v17 = o1; + + // b = rotr64(b ^ c, 63) + xor0 = v8 ^ v16; + xor1 = v9 ^ v17; + v8 = (xor1 >> 31u) ^ (xor0 << 1u); + v9 = (xor0 >> 31u) ^ (xor1 << 1u); + + + + + + /** + * r=11, i=1(x2), a=v[2-3], b=v[10-11], c=v[18-19], d=v[26-27] + */ + + // a = a + b + o0 = v2 + v10; + o1 = v3 + v11; + o1 = o1 + select(0u, 1u, o0 < v2); + v2 = o0; + v3 = o1; + + // a = a + m[sigma[r][2*i+0]] + o0 = v2 + m8; + o1 = v3 + m9; + o1 = o1 + select(0u, 1u, o0 < v2); + v2 = o0; + v3 = o1; + + // d = rotr64(d ^ a, 32) + xor0 = v26 ^ v2; + xor1 = v27 ^ v3; + v26 = xor1; + v27 = xor0; + + // c = c + d + o0 = v18 + v26; + o1 = v19 + v27; + o1 = o1 + select(0u, 1u, o0 < v18); + v18 = o0; + v19 = o1; + + // b = rotr64(b ^ c, 24) + xor0 = v10 ^ v18; + xor1 = v11 ^ v19; + v10 = (xor0 >> 24u) ^ (xor1 << 8u); + v11 = (xor1 >> 24u) ^ (xor0 << 8u); + + // a = a + b + o0 = v2 + v10; + o1 = v3 + v11; + o1 = o1 + select(0u, 1u, o0 < v2); + v2 = o0; + v3 = o1; + + // // a = a + m[sigma[r][2*i+1]] + // // skip since adding 0u does nothing + // o0 = v2 + 0u; + // o1 = v3 + 0u; + // if (v2 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v2 = o0; + // v3 = o1; + + // d = rotr64(d ^ a, 16) + xor0 = v26 ^ v2; + xor1 = v27 ^ v3; + v26 = (xor0 >> 16u) ^ (xor1 << 16u); + v27 = (xor1 >> 16u) ^ (xor0 << 16u); + + // c = c + d + o0 = v18 + v26; + o1 = v19 + v27; + o1 = o1 + select(0u, 1u, o0 < v18); + v18 = o0; + v19 = o1; + + // b = rotr64(b ^ c, 63) + xor0 = v10 ^ v18; + xor1 = v11 ^ v19; + v10 = (xor1 >> 31u) ^ (xor0 << 1u); + v11 = (xor0 >> 31u) ^ (xor1 << 1u); + + + + + + /** + * r=11, i=2(x2), a=v[4-5], b=v[12-13], c=v[20-21], d=v[28-29] + */ + + // a = a + b + o0 = v4 + v12; + o1 = v5 + v13; + o1 = o1 + select(0u, 1u, o0 < v4); + v4 = o0; + v5 = o1; + + // // a = a + m[sigma[r][2*i+0]] + // // skip since adding 0u does nothing + // o0 = v4 + 0u; + // o1 = v5 + 0u; + // if (v4 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v4 = o0; + // v5 = o1; + + // d = rotr64(d ^ a, 32) + xor0 = v28 ^ v4; + xor1 = v29 ^ v5; + v28 = xor1; + v29 = xor0; + + // c = c + d + o0 = v20 + v28; + o1 = v21 + v29; + o1 = o1 + select(0u, 1u, o0 < v20); + v20 = o0; + v21 = o1; + + // b = rotr64(b ^ c, 24) + xor0 = v12 ^ v20; + xor1 = v13 ^ v21; + v12 = (xor0 >> 24u) ^ (xor1 << 8u); + v13 = (xor1 >> 24u) ^ (xor0 << 8u); + + // a = a + b + o0 = v4 + v12; + o1 = v5 + v13; + o1 = o1 + select(0u, 1u, o0 < v4); + v4 = o0; + v5 = o1; + + // // a = a + m[sigma[r][2*i+1]] + // // skip since adding 0u does nothing + // o0 = v4 + 0u; + // o1 = v5 + 0u; + // if (v4 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v4 = o0; + // v5 = o1; + + // d = rotr64(d ^ a, 16) + xor0 = v28 ^ v4; + xor1 = v29 ^ v5; + v28 = (xor0 >> 16u) ^ (xor1 << 16u); + v29 = (xor1 >> 16u) ^ (xor0 << 16u); + + // c = c + d + o0 = v20 + v28; + o1 = v21 + v29; + o1 = o1 + select(0u, 1u, o0 < v20); + v20 = o0; + v21 = o1; + + // b = rotr64(b ^ c, 63) + xor0 = v12 ^ v20; + xor1 = v13 ^ v21; + v12 = (xor1 >> 31u) ^ (xor0 << 1u); + v13 = (xor0 >> 31u) ^ (xor1 << 1u); + + + + + + /** + * r=11, i=3(x2), a=v[6-7], b=v[14-15], c=v[22-23], d=v[30-31] + */ + + // a = a + b + o0 = v6 + v14; + o1 = v7 + v15; + o1 = o1 + select(0u, 1u, o0 < v6); + v6 = o0; + v7 = o1; + + // // a = a + m[sigma[r][2*i+0]] + // // skip since adding 0u does nothing + // o0 = v6 + 0u; + // o1 = v7 + 0u; + // if (v6 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v6 = o0; + // v7 = o1; + + // d = rotr64(d ^ a, 32) + xor0 = v30 ^ v6; + xor1 = v31 ^ v7; + v30 = xor1; + v31 = xor0; + + // c = c + d + o0 = v22 + v30; + o1 = v23 + v31; + o1 = o1 + select(0u, 1u, o0 < v22); + v22 = o0; + v23 = o1; + + // b = rotr64(b ^ c, 24) + xor0 = v14 ^ v22; + xor1 = v15 ^ v23; + v14 = (xor0 >> 24u) ^ (xor1 << 8u); + v15 = (xor1 >> 24u) ^ (xor0 << 8u); + + // a = a + b + o0 = v6 + v14; + o1 = v7 + v15; + o1 = o1 + select(0u, 1u, o0 < v6); + v6 = o0; + v7 = o1; + + // // a = a + m[sigma[r][2*i+1]] + // // skip since adding 0u does nothing + // o0 = v6 + 0u; + // o1 = v7 + 0u; + // if (v6 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v6 = o0; + // v7 = o1; + + // d = rotr64(d ^ a, 16) + xor0 = v30 ^ v6; + xor1 = v31 ^ v7; + v30 = (xor0 >> 16u) ^ (xor1 << 16u); + v31 = (xor1 >> 16u) ^ (xor0 << 16u); + + // c = c + d + o0 = v22 + v30; + o1 = v23 + v31; + o1 = o1 + select(0u, 1u, o0 < v22); + v22 = o0; + v23 = o1; + + // b = rotr64(b ^ c, 63) + xor0 = v14 ^ v22; + xor1 = v15 ^ v23; + v14 = (xor1 >> 31u) ^ (xor0 << 1u); + v15 = (xor0 >> 31u) ^ (xor1 << 1u); + + + + + + /** + * r=11, i=4(x2), a=v[0-1], b=v[10-11], c=v[20-21], d=v[30-31] + */ + + // a = a + b + o0 = v0 + v10; + o1 = v1 + v11; + o1 = o1 + select(0u, 1u, o0 < v0); + v0 = o0; + v1 = o1; + + // a = a + m[sigma[r][2*i+0]] + o0 = v0 + m2; + o1 = v1 + m3; + o1 = o1 + select(0u, 1u, o0 < v0); + v0 = o0; + v1 = o1; + + // d = rotr64(d ^ a, 32) + xor0 = v30 ^ v0; + xor1 = v31 ^ v1; + v30 = xor1; + v31 = xor0; + + // c = c + d + o0 = v20 + v30; + o1 = v21 + v31; + o1 = o1 + select(0u, 1u, o0 < v20); + v20 = o0; + v21 = o1; + + // b = rotr64(b ^ c, 24) + xor0 = v10 ^ v20; + xor1 = v11 ^ v21; + v10 = (xor0 >> 24u) ^ (xor1 << 8u); + v11 = (xor1 >> 24u) ^ (xor0 << 8u); + + // a = a + b + o0 = v0 + v10; + o1 = v1 + v11; + o1 = o1 + select(0u, 1u, o0 < v0); + v0 = o0; + v1 = o1; + + // // a = a + m[sigma[r][2*i+1]] + // // skip since adding 0u does nothing + // o0 = v0 + 0u; + // o1 = v1 + 0u; + // if (v0 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v0 = o0; + // v1 = o1; + + // d = rotr64(d ^ a, 16) + xor0 = v30 ^ v0; + xor1 = v31 ^ v1; + v30 = (xor0 >> 16u) ^ (xor1 << 16u); + v31 = (xor1 >> 16u) ^ (xor0 << 16u); + + // c = c + d + o0 = v20 + v30; + o1 = v21 + v31; + o1 = o1 + select(0u, 1u, o0 < v20); + v20 = o0; + v21 = o1; + + // b = rotr64(b ^ c, 63) + xor0 = v10 ^ v20; + xor1 = v11 ^ v21; + v10 = (xor1 >> 31u) ^ (xor0 << 1u); + v11 = (xor0 >> 31u) ^ (xor1 << 1u); + + + + + + /** + * r=11, i=5(x2), a=v[2-3], b=v[12-13], c=v[22-23], d=v[24-25] + */ + + // a = a + b + o0 = v2 + v12; + o1 = v3 + v13; + o1 = o1 + select(0u, 1u, o0 < v2); + v2 = o0; + v3 = o1; + + // a = a + m[sigma[r][2*i+0]] + o0 = v2 + m0; + o1 = v3 + m1; + o1 = o1 + select(0u, 1u, o0 < v2); + v2 = o0; + v3 = o1; + + // d = rotr64(d ^ a, 32) + xor0 = v24 ^ v2; + xor1 = v25 ^ v3; + v24 = xor1; + v25 = xor0; + + // c = c + d + o0 = v22 + v24; + o1 = v23 + v25; + o1 = o1 + select(0u, 1u, o0 < v22); + v22 = o0; + v23 = o1; + + // b = rotr64(b ^ c, 24) + xor0 = v12 ^ v22; + xor1 = v13 ^ v23; + v12 = (xor0 >> 24u) ^ (xor1 << 8u); + v13 = (xor1 >> 24u) ^ (xor0 << 8u); + + // a = a + b + o0 = v2 + v12; + o1 = v3 + v13; + o1 = o1 + select(0u, 1u, o0 < v2); + v2 = o0; + v3 = o1; + + // a = a + m[sigma[r][2*i+1]] + o0 = v2 + m4; + o1 = v3 + m5; + o1 = o1 + select(0u, 1u, o0 < v2); + v2 = o0; + v3 = o1; + + // d = rotr64(d ^ a, 16) + xor0 = v24 ^ v2; + xor1 = v25 ^ v3; + v24 = (xor0 >> 16u) ^ (xor1 << 16u); + v25 = (xor1 >> 16u) ^ (xor0 << 16u); + + // c = c + d + o0 = v22 + v24; + o1 = v23 + v25; + o1 = o1 + select(0u, 1u, o0 < v22); + v22 = o0; + v23 = o1; + + // b = rotr64(b ^ c, 63) + xor0 = v12 ^ v22; + xor1 = v13 ^ v23; + v12 = (xor1 >> 31u) ^ (xor0 << 1u); + v13 = (xor0 >> 31u) ^ (xor1 << 1u); + + + + + + /** + * r=11, i=6(x2), a=v[4-5], b=v[14-15], c=v[16-17], d=v[26-27] + */ + + // a = a + b + o0 = v4 + v14; + o1 = v5 + v15; + o1 = o1 + select(0u, 1u, o0 < v4); + v4 = o0; + v5 = o1; + + // // a = a + m[sigma[r][2*i+0]] + // // skip since adding 0u does nothing + // o0 = v4 + 0u; + // o1 = v5 + 0u; + // if (v4 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v4 = o0; + // v5 = o1; + + // d = rotr64(d ^ a, 32) + xor0 = v26 ^ v4; + xor1 = v27 ^ v5; + v26 = xor1; + v27 = xor0; + + // c = c + d + o0 = v16 + v26; + o1 = v17 + v27; + o1 = o1 + select(0u, 1u, o0 < v16); + v16 = o0; + v17 = o1; + + // b = rotr64(b ^ c, 24) + xor0 = v14 ^ v16; + xor1 = v15 ^ v17; + v14 = (xor0 >> 24u) ^ (xor1 << 8u); + v15 = (xor1 >> 24u) ^ (xor0 << 8u); + + // a = a + b + o0 = v4 + v14; + o1 = v5 + v15; + o1 = o1 + select(0u, 1u, o0 < v4); + v4 = o0; + v5 = o1; + + // // a = a + m[sigma[r][2*i+1]] + // // skip since adding 0u does nothing + // o0 = v4 + 0u; + // o1 = v5 + 0u; + // if (v4 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v4 = o0; + // v5 = o1; + + // d = rotr64(d ^ a, 16) + xor0 = v26 ^ v4; + xor1 = v27 ^ v5; + v26 = (xor0 >> 16u) ^ (xor1 << 16u); + v27 = (xor1 >> 16u) ^ (xor0 << 16u); + + // c = c + d + o0 = v16 + v26; + o1 = v17 + v27; + o1 = o1 + select(0u, 1u, o0 < v16); + v16 = o0; + v17 = o1; + + // b = rotr64(b ^ c, 63) + xor0 = v14 ^ v16; + xor1 = v15 ^ v17; + v14 = (xor1 >> 31u) ^ (xor0 << 1u); + v15 = (xor0 >> 31u) ^ (xor1 << 1u); + + + + + + /** + * r=11, i=7(x2), a=v[6-7], b=v[8-9], c=v[18-19], d=v[28-29] + */ + + // a = a + b + o0 = v6 + v8; + o1 = v7 + v9; + o1 = o1 + select(0u, 1u, o0 < v6); + v6 = o0; + v7 = o1; + + // // a = a + m[sigma[r][2*i+0]] + // // skip since adding 0u does nothing + // o0 = v6 + 0u; + // o1 = v7 + 0u; + // if (v6 > 0xFFFFFFFFu - 0u) { + // o1 = o1 + 1u; + // } + // v6 = o0; + // v7 = o1; + + // d = rotr64(d ^ a, 32) + xor0 = v28 ^ v6; + xor1 = v29 ^ v7; + v28 = xor1; + v29 = xor0; + + // c = c + d + o0 = v18 + v28; + o1 = v19 + v29; + o1 = o1 + select(0u, 1u, o0 < v18); + v18 = o0; + v19 = o1; + + // b = rotr64(b ^ c, 24) + xor0 = v8 ^ v18; + xor1 = v9 ^ v19; + v8 = (xor0 >> 24u) ^ (xor1 << 8u); + v9 = (xor1 >> 24u) ^ (xor0 << 8u); + + // a = a + b + o0 = v6 + v8; + o1 = v7 + v9; + o1 = o1 + select(0u, 1u, o0 < v6); + v6 = o0; + v7 = o1; + + // a = a + m[sigma[r][2*i+1]] + o0 = v6 + m6; + o1 = v7 + m7; + o1 = o1 + select(0u, 1u, o0 < v6); + v6 = o0; + v7 = o1; + + // d = rotr64(d ^ a, 16) + xor0 = v28 ^ v6; + xor1 = v29 ^ v7; + v28 = (xor0 >> 16u) ^ (xor1 << 16u); + v29 = (xor1 >> 16u) ^ (xor0 << 16u); + + // c = c + d + o0 = v18 + v28; + o1 = v19 + v29; + o1 = o1 + select(0u, 1u, o0 < v18); + v18 = o0; + v19 = o1; + + // b = rotr64(b ^ c, 63) + xor0 = v8 ^ v18; + xor1 = v9 ^ v19; + v8 = (xor1 >> 31u) ^ (xor0 << 1u); + v9 = (xor0 >> 31u) ^ (xor1 << 1u); + + + + + + /**************************************************************************** + * NONCE CHECK * + ****************************************************************************/ + + /** + * Set nonce if it passes the threshold and no other thread has set it + */ + if ((BLAKE2B_IV32_1 ^ v1 ^ v17) > threshold && atomicLoad(&work.found) == 0u) { + atomicStore(&work.found, 1u); + work.nonce.x = m0; + work.nonce.y = m1; + } + return; +} diff --git a/src/shaders/index.ts b/src/shaders/index.ts index 9629261..208a280 100644 --- a/src/shaders/index.ts +++ b/src/shaders/index.ts @@ -1,4 +1,7 @@ -import { NanoPowGpuComputeShader } from "./gpu-compute" +// SPDX-FileCopyrightText: 2025 Chris Duncan +// SPDX-License-Identifier: GPL-3.0-or-later + +import { default as NanoPowGpuComputeShader } from "./gpu-compute.wgsl" import { NanoPowGlFragmentShader } from "./gl-fragment" import { NanoPowGlVertexShader } from "./gl-vertex" diff --git a/src/shaders/shaders.d.ts b/src/shaders/shaders.d.ts new file mode 100644 index 0000000..8d06c90 --- /dev/null +++ b/src/shaders/shaders.d.ts @@ -0,0 +1,22 @@ +// SPDX-FileCopyrightText: 2025 Chris Duncan +// SPDX-License-Identifier: GPL-3.0-or-later + +declare module '*.frag' { + const value: string + export default value +} + +declare module '*.glsl' { + const value: string + export default value +} + +declare module '*.vert' { + const value: string + export default value +} + +declare module '*.wgsl' { + const value: string + export default value +} diff --git a/test/GLOBALS.mjs b/test/CONFIG.mjs similarity index 90% rename from test/GLOBALS.mjs rename to test/CONFIG.mjs index 8728f5e..4ade381 100644 --- a/test/GLOBALS.mjs +++ b/test/CONFIG.mjs @@ -1,40 +1,39 @@ -// SPDX-FileCopyrightText: 2024 Chris Duncan +// SPDX-FileCopyrightText: 2025 Chris Duncan // SPDX-License-Identifier: GPL-3.0-or-later -if (globalThis.sessionStorage == null) { - let _sessionStorage = {} - Object.defineProperty(globalThis, 'sessionStorage', { - value: { - length: Object.entries(_sessionStorage).length, - setItem: (key, value) => _sessionStorage[key] = value, - getItem: (key) => _sessionStorage[key], - removeItem: (key) => delete _sessionStorage[key], - clear: () => _sessionStorage = {} - }, - configurable: true, - enumerable: true - }) -} - export function average (times) { - let sum = 0, reciprocals = 0, logarithms = 0, count = times.length, min = 0xffff, max = 0 + let count = times.length, sum = 0, reciprocals = 0, logarithms = 0, truncated = 0, min = 0xffff, max = 0 + times.sort() for (let i = 0; i < count; i++) { sum += times[i] reciprocals += 1 / times[i] logarithms += Math.log(times[i]) min = Math.min(min, times[i]) max = Math.max(max, times[i]) + if (i > (count * 0.1) && i < (count * 0.9)) truncated += times[i] } return { total: sum, arithmetic: sum / count, harmonic: count / reciprocals, geometric: Math.exp(logarithms / count), + truncated: truncated / count, min: min, max: max } } +export function print (times) { + const { arithmetic, geometric, harmonic, min, max, total, truncated } = average(times) + console.log(`Total: ${total} ms`) + console.log(`Average: ${arithmetic} ms`) + console.log(`Harmonic: ${harmonic} ms`) + console.log(`Geometric: ${geometric} ms`) + console.log(`Truncated: ${truncated} ms`) + console.log(`Minimum: ${min} ms`) + console.log(`Maximum: ${max} ms`) +} + const failures = [] const passes = [] function fail (...args) { diff --git a/test/VECTORS.js b/test/VECTORS.js deleted file mode 100644 index 33633aa..0000000 --- a/test/VECTORS.js +++ /dev/null @@ -1,211 +0,0 @@ -// SPDX-FileCopyrightText: 2024 Chris Duncan -// SPDX-License-Identifier: GPL-3.0-or-later - -/** -* WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING -* -* Do not send any funds to the test vectors below! -* -* Sources: -* https://docs.nano.org/integration-guides/key-management/#test-vectors -* https://docs.nano.org/integration-guides/key-management/#creating-transactions -* https://github.com/trezor/python-mnemonic/blob/master/vectors.json -* https://tools.nanos.cc/?tool=seed -*/ -export const GENESIS_ADDRESS = 'nano_3t6k35gi95xu6tergt6p69ck76ogmitsa8mnijtpxm9fkcm736xtoncuohr3' -export const RAW_MAX = '340282366920938463463374607431768211455' -export const SUPPLY_MAX = '133248297920938463463374607431768211455' - -export const NANO_TEST_VECTORS = Object.freeze({ - MNEMONIC: 'edge defense waste choose enrich upon flee junk siren film clown finish luggage leader kid quick brick print evidence swap drill paddle truly occur', - PASSWORD: 'some password', - BIP39_SEED: '0DC285FDE768F7FF29B66CE7252D56ED92FE003B605907F7A4F683C3DC8586D34A914D3C71FC099BB38EE4A59E5B081A3497B7A323E90CC68F67B5837690310C', - - PRIVATE_0: '3BE4FC2EF3F3B7374E6FC4FB6E7BB153F8A2998B3B3DAB50853EABE128024143', - PUBLIC_0: '5B65B0E8173EE0802C2C3E6C9080D1A16B06DE1176C938A924F58670904E82C4', - ADDRESS_0: 'nano_1pu7p5n3ghq1i1p4rhmek41f5add1uh34xpb94nkbxe8g4a6x1p69emk8y1d', - - PRIVATE_1: 'CE7E429E683D652446261C17A96DA9ED1897AEA96C8046F2B8036F6B05CB1A83', - PUBLIC_1: 'D9F7762E9CD4E7ED632481308CDB8F54ABF0241332C0A8641F61E92E2FB03C12', - ADDRESS_1: 'nano_3phqgrqbso99xojkb1bijmfryo7dy1k38ep1o3k3yrhb7rqu1h1k47yu78gz', - - PRIVATE_2: '1257DF74609B9C6461A3F4E7FD6E3278F2DDCF2562694F2C3AA0515AF4F09E38', - PUBLIC_2: 'A46DA51986E25A14D82E32D765DCEE69B9EECCD4405411430D91DDB61B717566', - ADDRESS_2: 'nano_3b5fnnerfrkt4me4wepqeqggwtfsxu8fai4n473iu6gxprfq4xd8pk9gh1dg', - - SEND_BLOCK: { - account: "nano_1e5aqegc1jb7qe964u4adzmcezyo6o146zb8hm6dft8tkp79za3sxwjym5rx", - previous: "92BA74A7D6DC7557F3EDA95ADC6341D51AC777A0A6FF0688A5C492AB2B2CB40D", - representative: "nano_1stofnrxuz3cai7ze75o174bpm7scwj9jn3nxsn8ntzg784jf1gzn1jjdkou", - balance: "11618869000000000000000000000000", - link: "nano_1q3hqecaw15cjt7thbtxu3pbzr1eihtzzpzxguoc37bj1wc5ffoh7w74gi6p", - hash: "BB569136FA05F8CBF65CEF2EDE368475B289C4477342976556BA4C0DDF216E45", - key: "781186FB9EF17DB6E3D1056550D9FAE5D5BBADA6A6BC370E4CBB938B1DC71DA3", - signature: "74BCC59DBA39A1E34A5F75F96D6DE9154E3477AAD7DE30EA563DFCFE501A804228008F98DDF4A15FD35705102785C50EF76732C3A74B0FEC5B0DD67B574A5900", - work: "fbffed7c73b61367" - }, - RECEIVE_BLOCK: { - account: "nano_1e5aqegc1jb7qe964u4adzmcezyo6o146zb8hm6dft8tkp79za3sxwjym5rx", - previous: "92BA74A7D6DC7557F3EDA95ADC6341D51AC777A0A6FF0688A5C492AB2B2CB40D", - representative: "nano_1stofnrxuz3cai7ze75o174bpm7scwj9jn3nxsn8ntzg784jf1gzn1jjdkou", - balance: "11618869000000000000000000000000", - link: "CBC911F57B6827649423C92C88C0C56637A4274FF019E77E24D61D12B5338783", - hash: "350D145570578A36D3D5ADE58DC7465F4CAAF257DD55BD93055FF826057E2CDD", - key: "781186FB9EF17DB6E3D1056550D9FAE5D5BBADA6A6BC370E4CBB938B1DC71DA3", - signature: "EEFFE1EFCCC8F2F6F2F1B79B80ABE855939DD9D6341323186494ADEE775DAADB3B6A6A07A85511F2185F6E739C4A54F1454436E22255A542ED879FD04FEED001", - work: "c5cf86de24b24419" - }, - OPEN_BLOCK: { - account: "nano_1rawdji18mmcu9psd6h87qath4ta7iqfy8i4rqi89sfdwtbcxn57jm9k3q11", - previous: "0000000000000000000000000000000000000000000000000000000000000000", - representative: "nano_1stofnrxuz3cai7ze75o174bpm7scwj9jn3nxsn8ntzg784jf1gzn1jjdkou", - balance: "100", - link: "5B2DA492506339C0459867AA1DA1E7EDAAC4344342FAB0848F43B46D248C8E99", - hash: "ED3BE5340CC9D62964B5A5F84375A06078CBEDC45FB5FA2926985D6E27D803BB", - key: "0ED82E6990A16E7AD2375AB5D54BEAABF6C676D09BEC74D9295FCAE35439F694", - signature: "C4C1D0E25E9E1118F0E139704E9001FF54BDABAB4C3A59DE24510E5B48F269ACBC2F3393DFA46B390CA9C6831074829D91E694B81E8C0C2C9C4FA49A757ECB03", - work: "08d09dc3405d9441" - } -}) - -export const TREZOR_TEST_VECTORS = Object.freeze({ - PASSWORD: 'TREZOR', - - ENTROPY_0: "0000000000000000000000000000000000000000000000000000000000000000", - MNEMONIC_0: "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon art", - SEED_0: "bda85446c68413707090a52022edd26a1c9462295029f2e60cd7c4f2bbd3097170af7a4d73245cafa9c3cca8d561a7c3de6f5d4a10be8ed2a5e608d68f92fcc8", - BIP32_KEY_0: "xprv9s21ZrQH143K32qBagUJAMU2LsHg3ka7jqMcV98Y7gVeVyNStwYS3U7yVVoDZ4btbRNf4h6ibWpY22iRmXq35qgLs79f312g2kj5539ebPM", - BLAKE2B_PRIVATE_0: "9F0E444C69F77A49BD0BE89DB92C38FE713E0963165CCA12FAF5712D7657120F", - BLAKE2B_PUBLIC_0: "C008B814A7D269A1FA3C6528B19201A24D797912DB9996FF02A1FF356E45552B", - BLAKE2B_ADDRESS_0: "nano_3i1aq1cchnmbn9x5rsbap8b15akfh7wj7pwskuzi7ahz8oq6cobd99d4r3b7", - - ENTROPY_1: "7F7F7F7F7F7F7F7F7F7F7F7F7F7F7F7F7F7F7F7F7F7F7F7F7F7F7F7F7F7F7F7F", - MNEMONIC_1: "legal winner thank year wave sausage worth useful legal winner thank year wave sausage worth useful legal winner thank year wave sausage worth title", - SEED_1: "bc09fca1804f7e69da93c2f2028eb238c227f2e9dda30cd63699232578480a4021b146ad717fbb7e451ce9eb835f43620bf5c514db0f8add49f5d121449d3e87", - BIP32_KEY_1: "xprv9s21ZrQH143K3Y1sd2XVu9wtqxJRvybCfAetjUrMMco6r3v9qZTBeXiBZkS8JxWbcGJZyio8TrZtm6pkbzG8SYt1sxwNLh3Wx7to5pgiVFU", - BLAKE2B_1_PRIVATE_0: "C54F9F69B088B554FF494D4CE7D23EB1B13E89D338F219F83BC91F415C3F7F2D", - BLAKE2B_1_PUBLIC_0: "1573BD1B96ECF80571BF544854026E6A967F065028FBC514B548471DC60B3229", - BLAKE2B_1_ADDRESS_0: "nano_17dmqnfsfu9r1oruyo4aci38wtnphw571c9urncdck495q51pejbp3c648yo", - BLAKE2B_1_PRIVATE_1: "1B704560A0A04EAFD81E8D13481370DA458E2BB00C57F3AA00120D80F6A2BB6F", - BLAKE2B_1_PUBLIC_1: "353288BD57F98A2FC940B4D5A5CE9194EF1598611B00C629E96189320AC7409F", - BLAKE2B_1_ADDRESS_1: "nano_1fbkj4yohyec7z6n3f8onq9b579h4pe848r1rrnykreb8a7egi6z14nozo43", - - ENTROPY_2: "8080808080808080808080808080808080808080808080808080808080808080", - MNEMONIC_2: "letter advice cage absurd amount doctor acoustic avoid letter advice cage absurd amount doctor acoustic avoid letter advice cage absurd amount doctor acoustic bless", - SEED_2: "c0c519bd0e91a2ed54357d9d1ebef6f5af218a153624cf4f2da911a0ed8f7a09e2ef61af0aca007096df430022f7a2b6fb91661a9589097069720d015e4e982f", - BIP32_KEY_2: "xprv9s21ZrQH143K3CSnQNYC3MqAAqHwxeTLhDbhF43A4ss4ciWNmCY9zQGvAKUSqVUf2vPHBTSE1rB2pg4avopqSiLVzXEU8KziNnVPauTqLRo", - BLAKE2B_2_PRIVATE_0: "554BE953D1E2DAAD0F8CBC2002967FC158E57032A6C4FD107FFEB2ACA518B613", - BLAKE2B_2_PUBLIC_0: "D85DECD78A303A18CC0D7B65FB384B9C49A7E2EF3666250CBD4F6EC4791513F8", - BLAKE2B_2_ADDRESS_0: "nano_3p4xxmdrne3t5581tyu7zew6q94bnzjgyfm86n8dtmugrjwjc6zrrci4g1rc", - - ENTROPY_3: "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", - MNEMONIC_3: "zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo vote", - SEED_3: "dd48c104698c30cfe2b6142103248622fb7bb0ff692eebb00089b32d22484e1613912f0a5b694407be899ffd31ed3992c456cdf60f5d4564b8ba3f05a69890ad", - BIP32_KEY_3: "xprv9s21ZrQH143K2WFF16X85T2QCpndrGwx6GueB72Zf3AHwHJaknRXNF37ZmDrtHrrLSHvbuRejXcnYxoZKvRquTPyp2JiNG3XcjQyzSEgqCB", - BLAKE2B_3_PRIVATE_0: "F1FD8CBD15A54FABDED17C65C4DD44E1F93AAD122FCC1840B1EDEFAAA5BA2B22", - BLAKE2B_3_PUBLIC_0: "6DDE6DDEDE04254B9BC75D04017D4F4406AC7A5F7374550C1EECC8594BFB1E70", - BLAKE2B_3_ADDRESS_0: "nano_1ugyfqhfw337bgfwgqa617ynyj18ojx7ywuncn83xu8ad77zp9mip188iakf" -}) - -export const BIP32_TEST_VECTORS = Object.freeze({ - SEED_0: '000102030405060708090a0b0c0d0e0f', - m_PUB_0: 'xpub661MyMwAqRbcFtXgS5sYJABqqG9YLmC4Q1Rdap9gSE8NqtwybGhePY2gZ29ESFjqJoCu1Rupje8YtGqsefD265TMg7usUDFdp6W1EGMcet8', - m_PRV_0: 'xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi', - m_0H_PUB_0: 'xpub68Gmy5EdvgibQVfPdqkBBCHxA5htiqg55crXYuXoQRKfDBFA1WEjWgP6LHhwBZeNK1VTsfTFUHCdrfp1bgwQ9xv5ski8PX9rL2dZXvgGDnw', - m_0H_PRV_0: 'xprv9uHRZZhk6KAJC1avXpDAp4MDc3sQKNxDiPvvkX8Br5ngLNv1TxvUxt4cV1rGL5hj6KCesnDYUhd7oWgT11eZG7XnxHrnYeSvkzY7d2bhkJ7', - m_0H_1_PUB_0: 'xpub6ASuArnXKPbfEwhqN6e3mwBcDTgzisQN1wXN9BJcM47sSikHjJf3UFHKkNAWbWMiGj7Wf5uMash7SyYq527Hqck2AxYysAA7xmALppuCkwQ', - m_0H_1_PRV_0: 'xprv9wTYmMFdV23N2TdNG573QoEsfRrWKQgWeibmLntzniatZvR9BmLnvSxqu53Kw1UmYPxLgboyZQaXwTCg8MSY3H2EU4pWcQDnRnrVA1xe8fs', - m_0H_1_2H_PUB_0: 'xpub6D4BDPcP2GT577Vvch3R8wDkScZWzQzMMUm3PWbmWvVJrZwQY4VUNgqFJPMM3No2dFDFGTsxxpG5uJh7n7epu4trkrX7x7DogT5Uv6fcLW5', - m_0H_1_2H_PRV_0: 'xprv9z4pot5VBttmtdRTWfWQmoH1taj2axGVzFqSb8C9xaxKymcFzXBDptWmT7FwuEzG3ryjH4ktypQSAewRiNMjANTtpgP4mLTj34bhnZX7UiM', - m_0H_1_2H_2_PUB_0: 'xpub6FHa3pjLCk84BayeJxFW2SP4XRrFd1JYnxeLeU8EqN3vDfZmbqBqaGJAyiLjTAwm6ZLRQUMv1ZACTj37sR62cfN7fe5JnJ7dh8zL4fiyLHV', - m_0H_1_2H_2_PRV_0: 'xprvA2JDeKCSNNZky6uBCviVfJSKyQ1mDYahRjijr5idH2WwLsEd4Hsb2Tyh8RfQMuPh7f7RtyzTtdrbdqqsunu5Mm3wDvUAKRHSC34sJ7in334', - m_0H_1_2H_2_1000000000_PUB_0: 'xpub6H1LXWLaKsWFhvm6RVpEL9P4KfRZSW7abD2ttkWP3SSQvnyA8FSVqNTEcYFgJS2UaFcxupHiYkro49S8yGasTvXEYBVPamhGW6cFJodrTHy', - m_0H_1_2H_2_1000000000_PRV_0: 'xprvA41z7zogVVwxVSgdKUHDy1SKmdb533PjDz7J6N6mV6uS3ze1ai8FHa8kmHScGpWmj4WggLyQjgPie1rFSruoUihUZREPSL39UNdE3BBDu76', - - SEED_1: 'fffcf9f6f3f0edeae7e4e1dedbd8d5d2cfccc9c6c3c0bdbab7b4b1aeaba8a5a29f9c999693908d8a8784817e7b7875726f6c696663605d5a5754514e4b484542', - m_PUB_1: 'xpub661MyMwAqRbcFW31YEwpkMuc5THy2PSt5bDMsktWQcFF8syAmRUapSCGu8ED9W6oDMSgv6Zz8idoc4a6mr8BDzTJY47LJhkJ8UB7WEGuduB', - m_PRV_1: 'xprv9s21ZrQH143K31xYSDQpPDxsXRTUcvj2iNHm5NUtrGiGG5e2DtALGdso3pGz6ssrdK4PFmM8NSpSBHNqPqm55Qn3LqFtT2emdEXVYsCzC2U', - m_0_PUB_1: 'xpub69H7F5d8KSRgmmdJg2KhpAK8SR3DjMwAdkxj3ZuxV27CprR9LgpeyGmXUbC6wb7ERfvrnKZjXoUmmDznezpbZb7ap6r1D3tgFxHmwMkQTPH', - m_0_PRV_1: 'xprv9vHkqa6EV4sPZHYqZznhT2NPtPCjKuDKGY38FBWLvgaDx45zo9WQRUT3dKYnjwih2yJD9mkrocEZXo1ex8G81dwSM1fwqWpWkeS3v86pgKt', - m_0_2147483647H_PUB_1: 'xpub6ASAVgeehLbnwdqV6UKMHVzgqAG8Gr6riv3Fxxpj8ksbH9ebxaEyBLZ85ySDhKiLDBrQSARLq1uNRts8RuJiHjaDMBU4Zn9h8LZNnBC5y4a', - m_0_2147483647H_PRV_1: 'xprv9wSp6B7kry3Vj9m1zSnLvN3xH8RdsPP1Mh7fAaR7aRLcQMKTR2vidYEeEg2mUCTAwCd6vnxVrcjfy2kRgVsFawNzmjuHc2YmYRmagcEPdU9', - m_0_2147483647H_1_PUB_1: 'xpub6DF8uhdarytz3FWdA8TvFSvvAh8dP3283MY7p2V4SeE2wyWmG5mg5EwVvmdMVCQcoNJxGoWaU9DCWh89LojfZ537wTfunKau47EL2dhHKon', - m_0_2147483647H_1_PRV_1: 'xprv9zFnWC6h2cLgpmSA46vutJzBcfJ8yaJGg8cX1e5StJh45BBciYTRXSd25UEPVuesF9yog62tGAQtHjXajPPdbRCHuWS6T8XA2ECKADdw4Ef', - m_0_2147483647H_1_2147483646H_PUB_1: 'xpub6ERApfZwUNrhLCkDtcHTcxd75RbzS1ed54G1LkBUHQVHQKqhMkhgbmJbZRkrgZw4koxb5JaHWkY4ALHY2grBGRjaDMzQLcgJvLJuZZvRcEL', - m_0_2147483647H_1_2147483646H_PRV_1: 'xprvA1RpRA33e1JQ7ifknakTFpgNXPmW2YvmhqLQYMmrj4xJXXWYpDPS3xz7iAxn8L39njGVyuoseXzU6rcxFLJ8HFsTjSyQbLYnMpCqE2VbFWc', - m_0_2147483647H_1_2147483646H_2_PUB_1: 'xpub6FnCn6nSzZAw5Tw7cgR9bi15UV96gLZhjDstkXXxvCLsUXBGXPdSnLFbdpq8p9HmGsApME5hQTZ3emM2rnY5agb9rXpVGyy3bdW6EEgAtqt', - m_0_2147483647H_1_2147483646H_2_PRV_1: 'xprvA2nrNbFZABcdryreWet9Ea4LvTJcGsqrMzxHx98MMrotbir7yrKCEXw7nadnHM8Dq38EGfSh6dqA9QWTyefMLEcBYJUuekgW4BYPJcr9E7j', - - /** - * These vectors test for the retention of leading zeros. - * See bitpay / bitcore - lib#47 and iancoleman / bip39#58 for more information. - */ - SEED_2: '4b381541583be4423346c643850da4b320e46a87ae3d2a4e6da11eba819cd4acba45d239319ac14f863b8d5ab5a0d0c64d2e8a1e7d1457df2e5a3c51c73235be', - m_PUB_2: 'xpub661MyMwAqRbcEZVB4dScxMAdx6d4nFc9nvyvH3v4gJL378CSRZiYmhRoP7mBy6gSPSCYk6SzXPTf3ND1cZAceL7SfJ1Z3GC8vBgp2epUt13', - m_PRV_2: 'xprv9s21ZrQH143K25QhxbucbDDuQ4naNntJRi4KUfWT7xo4EKsHt2QJDu7KXp1A3u7Bi1j8ph3EGsZ9Xvz9dGuVrtHHs7pXeTzjuxBrCmmhgC6', - m_0H_PUB_2: 'xpub68NZiKmJWnxxS6aaHmn81bvJeTESw724CRDs6HbuccFQN9Ku14VQrADWgqbhhTHBaohPX4CjNLf9fq9MYo6oDaPPLPxSb7gwQN3ih19Zm4Y', - m_0H_PRV_2: 'xprv9uPDJpEQgRQfDcW7BkF7eTya6RPxXeJCqCJGHuCJ4GiRVLzkTXBAJMu2qaMWPrS7AANYqdq6vcBcBUdJCVVFceUvJFjaPdGZ2y9WACViL4L', - - /** - * These vectors test for the retention of leading zeros. - * See btcsuite / btcutil#172 for more information. - */ - - SEED_3: '3ddd5602285899a946114506157c7997e5444528f3003f6134712147db19b678', - m_PUB_3: 'xpub661MyMwAqRbcGczjuMoRm6dXaLDEhW1u34gKenbeYqAix21mdUKJyuyu5F1rzYGVxyL6tmgBUAEPrEz92mBXjByMRiJdba9wpnN37RLLAXa', - m_PRV_3: 'xprv9s21ZrQH143K48vGoLGRPxgo2JNkJ3J3fqkirQC2zVdk5Dgd5w14S7fRDyHH4dWNHUgkvsvNDCkvAwcSHNAQwhwgNMgZhLtQC63zxwhQmRv', - m_0H_PUB_3: 'xpub69AUMk3qDBi3uW1sXgjCmVjJ2G6WQoYSnNHyzkmdCHEhSZ4tBok37xfFEqHd2AddP56Tqp4o56AePAgCjYdvpW2PU2jbUPFKsav5ut6Ch1m', - m_0H_PRV_3: 'xprv9vB7xEWwNp9kh1wQRfCCQMnZUEG21LpbR9NPCNN1dwhiZkjjeGRnaALmPXCX7SgjFTiCTT6bXes17boXtjq3xLpcDjzEuGLQBM5ohqkao9G', - m_0H_1H_PUB_3: 'xpub6BJA1jSqiukeaesWfxe6sNK9CCGaujFFSJLomWHprUL9DePQ4JDkM5d88n49sMGJxrhpjazuXYWdMf17C9T5XnxkopaeS7jGk1GyyVziaMt', - m_0H_1H_PRV_3: 'xprv9xJocDuwtYCMNAo3Zw76WENQeAS6WGXQ55RCy7tDJ8oALr4FWkuVoHJeHVAcAqiZLE7Je3vZJHxspZdFHfnBEjHqU5hG1Jaj32dVoS6XLT1', - - /** - * These vectors test that invalid extended keys are recognized as invalid. - */ - INVALID_0: 'xpub661MyMwAqRbcEYS8w7XLSVeEsBXy79zSzH1J8vCdxAZningWLdN3zgtU6LBpB85b3D2yc8sfvZU521AAwdZafEz7mnzBBsz4wKY5fTtTQBm', // (pubkey version / prvkey mismatch) - INVALID_1: 'xprv9s21ZrQH143K24Mfq5zL5MhWK9hUhhGbd45hLXo2Pq2oqzMMo63oStZzFGTQQD3dC4H2D5GBj7vWvSQaaBv5cxi9gafk7NF3pnBju6dwKvH', // (prvkey version / pubkey mismatch) - INVALID_2: 'xpub661MyMwAqRbcEYS8w7XLSVeEsBXy79zSzH1J8vCdxAZningWLdN3zgtU6Txnt3siSujt9RCVYsx4qHZGc62TG4McvMGcAUjeuwZdduYEvFn', // (invalid pubkey prefix 04) - INVALID_3: 'xprv9s21ZrQH143K24Mfq5zL5MhWK9hUhhGbd45hLXo2Pq2oqzMMo63oStZzFGpWnsj83BHtEy5Zt8CcDr1UiRXuWCmTQLxEK9vbz5gPstX92JQ', // (invalid prvkey prefix 04) - INVALID_4: 'xpub661MyMwAqRbcEYS8w7XLSVeEsBXy79zSzH1J8vCdxAZningWLdN3zgtU6N8ZMMXctdiCjxTNq964yKkwrkBJJwpzZS4HS2fxvyYUA4q2Xe4', // (invalid pubkey prefix 01) - INVALID_5: 'xprv9s21ZrQH143K24Mfq5zL5MhWK9hUhhGbd45hLXo2Pq2oqzMMo63oStZzFAzHGBP2UuGCqWLTAPLcMtD9y5gkZ6Eq3Rjuahrv17fEQ3Qen6J', // (invalid prvkey prefix 01) - INVALID_6: 'xprv9s2SPatNQ9Vc6GTbVMFPFo7jsaZySyzk7L8n2uqKXJen3KUmvQNTuLh3fhZMBoG3G4ZW1N2kZuHEPY53qmbZzCHshoQnNf4GvELZfqTUrcv', // (zero depth with non - zero parent fingerprint) - INVALID_7: 'xpub661no6RGEX3uJkY4bNnPcw4URcQTrSibUZ4NqJEw5eBkv7ovTwgiT91XX27VbEXGENhYRCf7hyEbWrR3FewATdCEebj6znwMfQkhRYHRLpJ', // (zero depth with non - zero parent fingerprint) - INVALID_8: 'xprv9s21ZrQH4r4TsiLvyLXqM9P7k1K3EYhA1kkD6xuquB5i39AU8KF42acDyL3qsDbU9NmZn6MsGSUYZEsuoePmjzsB3eFKSUEh3Gu1N3cqVUN', // (zero depth with non - zero index) - INVALID_9: 'xpub661MyMwAuDcm6CRQ5N4qiHKrJ39Xe1R1NyfouMKTTWcguwVcfrZJaNvhpebzGerh7gucBvzEQWRugZDuDXjNDRmXzSZe4c7mnTK97pTvGS8', // (zero depth with non - zero index) - INVALID_10: 'DMwo58pR1QLEFihHiXPVykYB6fJmsTeHvyTp7hRThAtCX8CvYzgPcn8XnmdfHGMQzT7ayAmfo4z3gY5KfbrZWZ6St24UVf2Qgo6oujFktLHdHY4', // (unknown extended key version) - INVALID_11: 'DMwo58pR1QLEFihHiXPVykYB6fJmsTeHvyTp7hRThAtCX8CvYzgPcn8XnmdfHPmHJiEDXkTiJTVV9rHEBUem2mwVbbNfvT2MTcAqj3nesx8uBf9', // (unknown extended key version) - INVALID_12: 'xprv9s21ZrQH143K24Mfq5zL5MhWK9hUhhGbd45hLXo2Pq2oqzMMo63oStZzF93Y5wvzdUayhgkkFoicQZcP3y52uPPxFnfoLZB21Teqt1VvEHx', // (private key 0 not in 1..n - 1) - INVALID_13: 'xprv9s21ZrQH143K24Mfq5zL5MhWK9hUhhGbd45hLXo2Pq2oqzMMo63oStZzFAzHGBP2UuGCqWLTAPLcMtD5SDKr24z3aiUvKr9bJpdrcLg1y3G', // (private key n not in 1..n - 1) - INVALID_14: 'xpub661MyMwAqRbcEYS8w7XLSVeEsBXy79zSzH1J8vCdxAZningWLdN3zgtU6Q5JXayek4PRsn35jii4veMimro1xefsM58PgBMrvdYre8QyULY', // (invalid pubkey 020000000000000000000000000000000000000000000000000000000000000007) - INVALID_15: 'xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHL' // (invalid checksum) -}) - -export const CUSTOM_TEST_VECTORS = Object.freeze({ - ENTROPY_0: "00000000000000000000000000000000", - MNEMONIC_0: "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about", - SEED_0: "5EB00BBDDCF069084889A8AB9155568165F5C453CCB85E70811AAED6F6DA5FC19A5AC40B389CD370D086206DEC8AA6C43DAEA6690F20AD3D8D48B2D2CE9E38E4", - PRIVATE_0: "7F72C7D17BEAC5CDC249D3AEBA8BF76D640129F69DB17E584A4A98E635855D7C", - PUBLIC_0: "588FAABCE802DF8C1700BDF50F2861DE1C0FA48B38B27ECE910D7C696759BAF5", - ADDRESS_0: "nano_1p6hocygi1pzjidi3hho3wn85qiw3ykapg7khu9b45dwf7momgqoytn1c1jz", - - ENTROPY_1: "7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f", - MNEMONIC_1: "legal winner thank year wave sausage worth useful legal winner thank year wave sausage wise", - SEED_1: "D95F1FAA0F8AEA406101A81510690D781DA04C86678FC5A13A09C251B7505BB6D17EC0BB408F9D2D6BC9434ADBD79491F09F91186B1E445A392D682D8DB586AD", - PRIVATE_1: "8971838804CE4D715A9250D673EACCAEA7AF26349B6E43B50CCC5554DF0BD342", - PUBLIC_1: "D1DBB524EF0A1A56C91E2EDCE4D7E1A5814CCC45C1B18EDF657E2859BB96A1E9", - ADDRESS_1: "nano_3ngupnkgy4itcu6jwdpwwmdy5be3bm86difjjuhpczjad8xsfahbg61c7ipy", - - ENTROPY_2: "808080808080808080808080808080808080808080808080", - MNEMONIC_2: "letter advice cage absurd amount doctor acoustic avoid letter advice cage absurd amount doctor acoustic avoid letter always", - SEED_2: "04D5F77103510C41D610F7F5FB3F0BADC77C377090815CEE808EA5D2F264FDFABF7C7DED4BE6D4C6D7CDB021BA4C777B0B7E57CA8AA6DE15AEB9905DBA674D66", - PRIVATE_2: "50F76F0211E8F18D3554C6C0DD8131E75BDBB2AC392BF6FBE23698E900EFCA13", - PUBLIC_2: "9C93BD3C0796381F7562E3E14D2E3CF0F4056226149D7CAC891B241434B4285A", - ADDRESS_2: "nano_396mqny1h7jr5xtp7rz3bnq5sw9n1oj4e76xhkpak8s64itdac4t95ux7xn4", - - ENTROPY_3: "ffffffffffffffffffffffffffffffffffffffffffffffffffffffff", - MNEMONIC_3: "zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo veteran", - SEED_3: "DB4BFE5911205C0B2E048CEEF790D0433A902A070D0744AF9B5E88ED5E0AEF548246102DD6BA2313E418FD799360E2DBD8EB93EE40FE0942517555B66E89D488", - PRIVATE_3: "133F351F1EDF5B4FE86EA7849AEC2C7E4D3F5F16C0CBAB4A236ADF17ACCB98B0", - PUBLIC_3: "2D6E50265036DE634FC71A2F9BE8A336AB991B8751C15D883ACCD90BFD3BEDB6", - ADDRESS_3: "nano_1ddgc1m71fpyef9wg8jhmhnc8fodm6frgng3dp65om8s3hymqufp8jefijxu", -}) diff --git a/test/index.html b/test/index.html new file mode 100644 index 0000000..6e5156b --- /dev/null +++ b/test/index.html @@ -0,0 +1,16 @@ + + + + + + + + + + + + + diff --git a/test/perf.gpu.js b/test/perf.gpu.js deleted file mode 100644 index 28a7959..0000000 --- a/test/perf.gpu.js +++ /dev/null @@ -1,115 +0,0 @@ -// SPDX-FileCopyrightText: 20245Chris Duncan -// SPDX-License-Identifier: GPL-3.0-or-later - -'use strict' - -import { assert, average, skip, suite, test } from '#test/GLOBALS.mjs' -import { NANO_TEST_VECTORS } from '#test/VECTORS.js' -import { PowGl, NanoPowGpu } from '#dist/main.js' - -await suite('Block performance', async () => { - const COUNT = 0x20 - - await test(`PowGpu: Calculate proof-of-work for 6 unique block hashes`, async () => { - const times = [] - const hashes = [ - NANO_TEST_VECTORS.PRIVATE_0, - NANO_TEST_VECTORS.PRIVATE_1, - NANO_TEST_VECTORS.PRIVATE_2, - NANO_TEST_VECTORS.PUBLIC_0, - NANO_TEST_VECTORS.PUBLIC_1, - NANO_TEST_VECTORS.PUBLIC_2 - ] - for (let i = 0; i < 6; i++) { - const start = performance.now() - const work = await NanoPowGpu.search(hashes[i]) - const end = performance.now() - times.push(end - start) - console.log(`${work} (${end - start} ms) ${hashes[i]}`) - } - const { total, arithmetic, harmonic, geometric, min, max } = average(times) - console.log(`Total: ${total} ms`) - console.log(`Average: ${arithmetic} ms`) - console.log(`Harmonic: ${harmonic} ms`) - console.log(`Geometric: ${geometric} ms`) - console.log(`Minimum: ${min} ms`) - console.log(`Maximum: ${max} ms`) - }) - - await skip(`PowGl: Calculate proof-of-work for 6 unique block hashes`, async () => { - const times = [] - const hashes = [ - NANO_TEST_VECTORS.PRIVATE_0, - NANO_TEST_VECTORS.PRIVATE_1, - NANO_TEST_VECTORS.PRIVATE_2, - NANO_TEST_VECTORS.PUBLIC_0, - NANO_TEST_VECTORS.PUBLIC_1, - NANO_TEST_VECTORS.PUBLIC_2 - ] - for (let i = 0; i < 6; i++) { - const start = performance.now() - const work = await PowGl.search(hashes[i]) - const end = performance.now() - times.push(end - start) - console.log(`${work} (${end - start} ms) ${hashes[i]}`) - } - const { total, arithmetic, harmonic, geometric, min, max } = average(times) - console.log(`Total: ${total} ms`) - console.log(`Average: ${arithmetic} ms`) - console.log(`Harmonic: ${harmonic} ms`) - console.log(`Geometric: ${geometric} ms`) - console.log(`Minimum: ${min} ms`) - console.log(`Maximum: ${max} ms`) - }) - - await test(`libnemo: Time to calculate proof-of-work for a send block ${COUNT} times`, async () => { - const times = [] - const block = new SendBlock( - NANO_TEST_VECTORS.SEND_BLOCK.account, - NANO_TEST_VECTORS.SEND_BLOCK.balance, - NANO_TEST_VECTORS.SEND_BLOCK.link, - '0', - NANO_TEST_VECTORS.SEND_BLOCK.representative, - NANO_TEST_VECTORS.SEND_BLOCK.previous - ) - for (let i = 0; i < COUNT; i++) { - const start = performance.now() - await block.pow() - const end = performance.now() - times.push(end - start) - console.log(`${block.work} (${end - start} ms)`) - } - const { total, arithmetic, harmonic, geometric, min, max } = average(times) - console.log(`Total: ${total} ms`) - console.log(`Average: ${arithmetic} ms`) - console.log(`Harmonic: ${harmonic} ms`) - console.log(`Geometric: ${geometric} ms`) - console.log(`Minimum: ${min} ms`) - console.log(`Maximum: ${max} ms`) - }) - - await skip(`nano-webgl-pow: Time to calculate proof-of-work for a send block ${COUNT} times`, async () => { - //@ts-expect-error - window.NanoWebglPow.width = 256 * Math.max(1, Math.floor(navigator.hardwareConcurrency)) - //@ts-expect-error - window.NanoWebglPow.height = 256 * Math.max(1, Math.floor(navigator.hardwareConcurrency)) - const times = [] - for (let i = 0; i < COUNT; i++) { - const start = performance.now() - const work = await new Promise(resolve => { - //@ts-expect-error - window.NanoWebglPow(NANO_TEST_VECTORS.SEND_BLOCK.previous, resolve, undefined, '0xFFFFFFF8') - }) - const end = performance.now() - times.push(end - start) - console.log(`${work} (${end - start} ms)`) - } - const { total, arithmetic, harmonic, geometric, min, max } = average(times) - console.log(`Total: ${total} ms`) - console.log(`Average: ${arithmetic} ms`) - console.log(`Harmonic: ${harmonic} ms`) - console.log(`Geometric: ${geometric} ms`) - console.log(`Minimum: ${min} ms`) - console.log(`Maximum: ${max} ms`) - }) -}) diff --git a/test/perf.main.mjs b/test/perf.main.mjs deleted file mode 100644 index df9c5a2..0000000 --- a/test/perf.main.mjs +++ /dev/null @@ -1,6 +0,0 @@ -// SPDX-FileCopyrightText: 20245Chris Duncan -// SPDX-License-Identifier: GPL-3.0-or-later - -import './perf.gpu.js' - -console.log('%cTESTING COMPLETE', 'color:orange;font-weight:bold') diff --git a/test/test.calculate-pow.mjs b/test/test.calculate-pow.mjs deleted file mode 100644 index f712e15..0000000 --- a/test/test.calculate-pow.mjs +++ /dev/null @@ -1,45 +0,0 @@ -// SPDX-FileCopyrightText: 2024 Chris Duncan -// SPDX-License-Identifier: GPL-3.0-or-later - -'use strict' - -import { assert, suite, test } from '#test/GLOBALS.mjs' -import { NANO_TEST_VECTORS } from '#test/VECTORS.js' -import { SendBlock, Blake2b } from '#dist/main.js' - -await suite('Calculate proof-of-work', async () => { - - await test('SendBlock PoW', async () => { - const block = new SendBlock( - NANO_TEST_VECTORS.SEND_BLOCK.account, - NANO_TEST_VECTORS.SEND_BLOCK.balance, - NANO_TEST_VECTORS.SEND_BLOCK.link, - '0', - NANO_TEST_VECTORS.SEND_BLOCK.representative, - NANO_TEST_VECTORS.SEND_BLOCK.previous - ) - await block.pow() - assert.equals(block.previous.length, 64) - assert.equals(block.work?.length, 16) - - const work = block.work - ?.match(/.{2}/g) - ?.map(hex => parseInt(hex, 16)) - .reverse() - if (work == null) throw new Error('Work invalid') - const previous = block.previous - ?.match(/.{2}/g) - ?.map(hex => parseInt(hex, 16)) - if (previous == null) throw new Error('Previous block hash invalid') - - const bytes = new Uint8Array([...work, ...previous]) - assert.equals(bytes.byteLength, 40) - - const hash = new Blake2b(8) - .update(bytes) - .digest('hex') - .slice(8, 16) - assert.ok(parseInt(hash.slice(0, 2), 16) > 0xf0) - assert.equals(parseInt(hash.slice(2, 8), 16), 0xffffff) - }) -}) diff --git a/test/test.main.mjs b/test/test.main.mjs deleted file mode 100644 index 630ac3a..0000000 --- a/test/test.main.mjs +++ /dev/null @@ -1,6 +0,0 @@ -// SPDX-FileCopyrightText: 20245Chris Duncan -// SPDX-License-Identifier: GPL-3.0-or-later - -import './test.calculate-pow.mjs' - -console.log('%cTESTING COMPLETE', 'color:orange;font-weight:bold') diff --git a/test/test.mjs b/test/test.mjs new file mode 100644 index 0000000..7f805c6 --- /dev/null +++ b/test/test.mjs @@ -0,0 +1,66 @@ +// SPDX-FileCopyrightText: 20245Chris Duncan +// SPDX-License-Identifier: GPL-3.0-or-later + +'use strict' + +import { assert, average, print, skip, suite, test } from './CONFIG.mjs' +import { NanoPowGl, NanoPowGpu } from '../dist/main.min.js' + +await suite('Block performance', async () => { + const COUNT = 0x20 + + await test(`NanoPowGpu: Calculate proof-of-work for ${COUNT} unique send block hashes`, async () => { + const times = [] + const random = new Uint8Array(32) + for (let i = 0; i < COUNT; i++) { + crypto.getRandomValues(random) + const hash = random.reduce((curr, next) => { return `${curr}${next.toString(16).padStart(2, '0')}` }, '') + const start = performance.now() + const work = await NanoPowGpu.search(hash) + const end = performance.now() + times.push(end - start) + console.log(`${work} (${end - start} ms) ${hash}`) + } + print(times) + }) + + await skip(`NanoPowGl: Calculate proof-of-work for ${COUNT} unique send block hashes`, async () => { + const times = [] + const random = new Uint8Array(32) + for (let i = 0; i < COUNT; i++) { + crypto.getRandomValues(random) + const hash = random.reduce((curr, next) => { return `${curr}${next}` }, '') + const start = performance.now() + const work = await NanoPowGl.search(hash) + const end = performance.now() + times.push(end - start) + console.log(`${work} (${end - start} ms) ${hash}`) + } + print(times) + }) + + await skip(`nano-webgl-pow: Calculate proof-of-work for ${COUNT} unique send block hashes`, async () => { + //@ts-expect-error + window.NanoWebglPow.width = 256 * Math.max(1, Math.floor(navigator.hardwareConcurrency)) + //@ts-expect-error + window.NanoWebglPow.height = 256 * Math.max(1, Math.floor(navigator.hardwareConcurrency)) + const times = [] + const random = new Uint8Array(32) + for (let i = 0; i < COUNT; i++) { + crypto.getRandomValues(random) + const hash = random.reduce((curr, next) => { return `${curr}${next}` }, '') + const start = performance.now() + const work = await new Promise(resolve => { + //@ts-expect-error + window.NanoWebglPow(hash, resolve, undefined, '0xFFFFFFF8') + }) + const end = performance.now() + times.push(end - start) + console.log(`${work} (${end - start} ms)`) + } + print(times) + }) +}) + +console.log('%cTESTING COMPLETE', 'color:orange;font-weight:bold') + diff --git a/tsconfig.json b/tsconfig.json index 82d452f..12a1ae3 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -5,7 +5,7 @@ "moduleResolution": "Bundler", "declaration": true, "noEmit": false, - "outDir": "./dist", + "outDir": "./build", "alwaysStrict": true, "downlevelIteration": false, "esModuleInterop": true, diff --git a/tsconfig.json.license b/tsconfig.json.license index 36ee55c..7f56691 100644 --- a/tsconfig.json.license +++ b/tsconfig.json.license @@ -1,2 +1,2 @@ -SPDX-FileCopyrightText: 2024 Chris Duncan +SPDX-FileCopyrightText: 2025 Chris Duncan SPDX-License-Identifier: GPL-3.0-or-later