]> git.codecow.com Git - nano25519.git/commitdiff
Fix documentation.
authorChris Duncan <chris@codecow.com>
Sat, 10 Oct 2026 05:43:58 +0000 (22:43 -0700)
committerChris Duncan <chris@codecow.com>
Sat, 10 Oct 2026 05:43:58 +0000 (22:43 -0700)
scripts/blake2b-gen.mjs
src/assembly/index.ts
src/lib/wasm.ts

index ef53f62df7d93e43009a24bab09794178ec9bc01..607027e95ce448721365af4a986e624b535c9584 100644 (file)
@@ -165,8 +165,7 @@ function ROUND (r) {
 
 /**
  * Builds string of code that first initializes the BLAKE2b state vectors and
- * then compresses the input message. For Nano proof-of-work, the input is
- * only 40 bytes, so compression only happens once.
+ * then compresses the input message.
  *
  * @type {string} API-specific code executing 12 rounds of G mixing
  */
index 37dda5d379c4544dc42075810e6168e608f3bdc3..921047d7ff3b34904c8c0826e80a66271c254369 100644 (file)
@@ -9,7 +9,7 @@ import { raise, } from './env'
 import { BUFFER_INPUT_MSG, BUFFER_INPUT_PRV, BUFFER_INPUT_PUB, BUFFER_INPUT_SIG, BUFFER_OUTPUT_DERIVE, BUFFER_OUTPUT_SIGN, BUFFER_OUTPUT_VERIFY, ERROR_EQUALBYTES_SELFTEST_XFAIL_ONE, ERROR_EQUALBYTES_SELFTEST_XFAIL_PAIR, ERROR_EQUALBYTES_SELFTEST_XPASS, ERROR_FE_ISZERO_SELFTEST_XFAIL, ERROR_FE_ISZERO_SELFTEST_XPASS, ERROR_GE_IS_CANONICAL_SELFTEST_XFAIL, ERROR_GE_IS_CANONICAL_SELFTEST_XPASS, ERROR_INDEX_OUT_OF_RANGE, ERROR_INVALID_BLOCK_COUNT, ERROR_INVALID_MESSAGE_LENGTH, ERROR_INVALID_PUBLIC_KEY, ERROR_UNKNOWN, } from './errors'
 import './tests'
 
-export { BLOCKHASH_BYTELENGTH, BUFFER_INPUT_MSG, BUFFER_INPUT_PRV, BUFFER_INPUT_PUB, BUFFER_INPUT_SIG, BUFFER_OUTPUT_DERIVE, BUFFER_OUTPUT_SIGN, BUFFER_OUTPUT_VERIFY, ERROR_INDEX_OUT_OF_RANGE, ERROR_INVALID_BLOCK_COUNT, ERROR_INVALID_MESSAGE_LENGTH, ERROR_INVALID_PUBLIC_KEY, ERROR_EQUALBYTES_SELFTEST_XFAIL_ONE, ERROR_EQUALBYTES_SELFTEST_XFAIL_PAIR, ERROR_EQUALBYTES_SELFTEST_XPASS, ERROR_FE_ISZERO_SELFTEST_XFAIL, ERROR_FE_ISZERO_SELFTEST_XPASS, ERROR_GE_IS_CANONICAL_SELFTEST_XFAIL, ERROR_GE_IS_CANONICAL_SELFTEST_XPASS, ERROR_UNKNOWN, KEY_BYTELENGTH, MAX_MESSAGE_BYTELENGTH, MAX_VERIFY_BLOCKS, MAX_VERIFY_BLOCKS_BYTELENGTH, SIGNATURE_BYTELENGTH }
+export { BLOCKHASH_BYTELENGTH, BUFFER_INPUT_MSG, BUFFER_INPUT_PRV, BUFFER_INPUT_PUB, BUFFER_INPUT_SIG, BUFFER_OUTPUT_DERIVE, BUFFER_OUTPUT_SIGN, BUFFER_OUTPUT_VERIFY, ERROR_EQUALBYTES_SELFTEST_XFAIL_ONE, ERROR_EQUALBYTES_SELFTEST_XFAIL_PAIR, ERROR_EQUALBYTES_SELFTEST_XPASS, ERROR_FE_ISZERO_SELFTEST_XFAIL, ERROR_FE_ISZERO_SELFTEST_XPASS, ERROR_GE_IS_CANONICAL_SELFTEST_XFAIL, ERROR_GE_IS_CANONICAL_SELFTEST_XPASS, ERROR_INDEX_OUT_OF_RANGE, ERROR_INVALID_BLOCK_COUNT, ERROR_INVALID_MESSAGE_LENGTH, ERROR_INVALID_PUBLIC_KEY, ERROR_UNKNOWN, KEY_BYTELENGTH, MAX_MESSAGE_BYTELENGTH, MAX_VERIFY_BLOCKS, MAX_VERIFY_BLOCKS_BYTELENGTH, SIGNATURE_BYTELENGTH }
 
 // Static I/O buffers
 const INPUT_MSG = new StaticArray<u8>(MAX_MESSAGE_BYTELENGTH)
@@ -142,14 +142,11 @@ export function derive (): void {
 }
 
 /**
- * Sign up to 64 KiB of data using a 64-byte secret key. Parameters are read as
- * bytes from the input buffer in the following order:
- *
- * - `[0,31]: private key`
- * - `[32,63]: public key`
- *
- * The message itself is read from a separate buffer. The signature is detached
- * from the message and written to the output buffer.
+ * Sign up to 64 KiB of data using a 32-byte private key. The 32-byte public key
+ * is also required for data integrity. Parameters are read as bytes from
+ * specific input buffers, and the message itself is read from a separate
+ * buffer. The signature is detached from the message and written to the output
+ * buffer.
  * @param {i32} mlen Byte length of message to be signed, up to 65536
  */
 export function sign (mlen: i32): void {
@@ -233,10 +230,10 @@ export function verify (mlen: i32): void {
  * concatenated value. The performance gain of verifying in bulk scales as
  * `(1-(1/n)) x (k/(k+r))` where `n` is block count, `k` is the time required to
  * verify the public key, and `r` is the time required to compute all the
- * remaining verification steps. Testing shows `k` to be ~12% the total
- * verification time, so batching up to 64 block signature/hash pairs reaches
- * ~96% of that gain; any more blocks would simply add latency returning the
- * final results.
+ * remaining verification steps. Testing shows public key derivation to be ~12%
+ * the total verification time, so batching up to 64 block signature/hash pairs
+ * reaches ~96% of that gain; any more blocks would simply add latency returning
+ * the final results.
  *
  * All pairs are verified against a single public key. The results are written
  * to the output buffer in the same order they were received.
index 4685b82fb7dcd8b4a103aedd8699d42a37eb64b2..c7997e1470c0885b4cc1a44246285f2829caeba9 100644 (file)
@@ -149,13 +149,15 @@ const setInputMsgEndian = isLE ? setInputMsgWords : setInputMsgShift
  * written in one pass rather than looped over an intermediate array because
  * allocating costs more than the copy itself.
  *
- * Whole 32-byte chunks are read a word at a time through a `Uint32Array` view.
- * A `Uint32Array` is laid out little-endian on every platform that can run
- * WASM, so a word read is already in the order the module's `store<u32>` wants
- * and needs no shifting — measured over 64 KiB, that takes the loop from ~45 µs
- * to ~13 µs, which is the cost of the 2048 boundary crossings alone. The
- * remaining bytes, fewer than 32, go through `setInputMsgBytes`, which handles
- * the zero padding.
+ * On little-endian systems, the message input is first read in 32-byte chunks
+ * as 4-byte words through a `Uint32Array` view, and any remaining bytes are
+ * read individually through a `Uint8Array`. Big-endian systems read the input
+ * one byte at a time for the entire message since byte order must be reversed
+ * to meet WASM spec which is little-endian by definition.
+ *
+ * The vast majority of hardware is little-endian and will benefit from the
+ * word-based capture: measured over 64 KiB, it reduces copy time by ~66% which
+ * is the cost of the 2048 boundary crossings alone.
  */
 function setInputMsg (message: Bytes): void {
        const mlen = byteLength(message)