From f143d1cd2c5793ecfb75d176167d13297ff8b613 Mon Sep 17 00:00:00 2001 From: Avril Date: Thu, 25 Jun 2020 14:15:41 +0100 Subject: [PATCH] micro-opt --- README.org | 2 +- src/mnemonic.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.org b/README.org index 573311d..866ab8f 100644 --- a/README.org +++ b/README.org @@ -234,7 +234,7 @@ The kana algorithm is a 16-bit block digest that works as follows: - The most and least significant 8 bits are each seperated into /Stage 0/ and /Stage 1/ each operating on the first and second byte respectively. - Stage 0: - 1. The byte is sign tested (bitwise ~AND~ =0x80=), store this as a boolean in /sign0/. + 1. The byte is sign tested (bitwise ~AND~ =0x80=), store this as a boolean in /sign0/ (Negative becomes =1=, positive becomes =0=.) 2. The valid first character range is looked up using the result of the sign test (either 0 or 1), store the range in /range/, and the slice ~KANA~ taken from the range in /kana/. 3. The first index is calculated as the unsigned first byte modulo the size (exclusive) of /range/. Store this as /index/. 4. Compute the value of the first byte bitwise ~XOR~ the second byte, store this as /index1/. diff --git a/src/mnemonic.rs b/src/mnemonic.rs index 9127978..74bd228 100644 --- a/src/mnemonic.rs +++ b/src/mnemonic.rs @@ -20,7 +20,7 @@ impl Digest { return d; } - let sign0 = unsafe { *reinterpret::value::(from) < 0 }; + let sign0 = from[0] & 0x80 != 0;//unsafe { *reinterpret::value::(from) < 0 }; let range = &map::KANA_SIGN[sign0 as usize]; let kana = &map::KANA[range.clone()]; let oneesan = usize::from(from[0]) % kana.len();