Skip to content

Fixed salt generation when counter == 0 for LessPass compatibility - #15

Open
myau-def wants to merge 1 commit into
71:masterfrom
myau-def:patch-1
Open

myau-def wants to merge 1 commit into
71:masterfrom
myau-def:patch-1

Conversation

@myau-def

@myau-def myau-def commented Jun 1, 2026 •

Copy link
Copy Markdown

Fixes the bug where counter = 0 produces an incorrect salt.

Description

There is a bug in salt generation when counter is set to 0. It breaks compatibility with the official LessPass implementation.

For any counter >= 1, the generated passwords match perfectly. However, for counter = 0, the generated passwords diverge.

Steps to Reproduce

With counter = 0 (Bug):

$ lesspass "site" "login" "password" -C 0
pkwuO9<-W">g,Zag

$ lesspass-rs "site" "login" "password" -c 0
7q~o>vDo6n(Rf+"g

With counter >= 1 (Works correctly):

$ lesspass "site" "login" "password" -C 1
|KTnP2D^64'`q]Er

$ lesspass-rs "site" "login" "password" -c 1
|KTnP2D^64'`q]Er

$ lesspass "site" "login" "password" -C 2
b/f@D|kl2Rs:9k\^

$ lesspass-rs "site" "login" "password" -c 2
b/f@D|kl2Rs:9k\^

Root Cause

The issue is located in the generate_salt_to_uninit function (line 138). When counter is 0, the while counter != 0 loop condition is immediately false, so the loop never executes. As a result, it returns an empty buffer instead of "0".

let mut counter_buf = [MaybeUninit::uninit(); 8];
let counter = {
    let mut counter = counter as usize;
    let mut i = counter_buf.len();
    
    // This works for counter >= 1, but fails for counter = 0
    while counter != 0 {
        counter_buf[i - 1].write(b"0123456789abcdef"[counter & 0xf]);
        counter >>= 4;
        i -= 1;
    }

    &counter_buf[i..] // Returns an empty slice &[] when counter is 0
};

@myau-def myau-def changed the title Fix salt generation when counter == 0 for LessPass compatibility Fixed salt generation when counter == 0 for LessPass compatibility Jun 1, 2026
@71

71 commented Jun 20, 2026 •

Copy link
Copy Markdown
Owner

Thank you and sorry for the slow response!

Could you add 0 in the test cases here (and regenerate the .rs test file), so the behavior is tested from now on:

for COUNTER in 1 8 32 100000; do

…ator

- Fix logical case when counter equals 0 in salt generation
- Fix CLI argument mismatch (--no-lower instead of --no-lowercase) in `make-blackbox-tests.sh`
- Regenerate `blackbox.rs` with proper boilerplates and full test vectors
@myau-def

Copy link
Copy Markdown
Author

Done! I've updated the make-blackbox-tests.sh script to include 0 in the COUNTER loops.

While I was at it, I also noticed that the generator script was using legacy CLI flags (--no-lowercase instead of --no-lower, etc.) which caused panic messages to bleed into the test vector output. I patched the bash script to properly map those arguments and updated the boilerplate template so that tests/blackbox.rs builds and tests successfully out of the box.

The test file has been fully regenerated and the entire history was cleaned up via a force-push.

@71 71 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you and sorry for the slow response again. I will squash before merging anyway, so please push new commits instead of rebasing so it's easy to see a diff between revisions.

@@ -1,4 +1,4 @@
#/bin/sh
#!/bin/bash

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: if bash is needed, I'd rather use

Suggested change
#!/bin/bash
#!/usr/bin/env -S bash -euo pipefail

I used /bin/sh to remove dependencies and keep things simple, but if that's not an option, I prefer the stricter / env-dependent shebang.

exit 2
fi

# Выводим заголовок, импорты и тестовый раннер

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remove the non-English comments, please?

Comment thread tests/blackbox.rs

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid the large diff, could you format this file please? And possibly add cargo fmt or something like that to the end of make-blackbox-tests.sh to make sure this is done automatically.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants