Skip to content

Miscellaneous patches#30

Merged
tilkinsc merged 10 commits into
tilkinsc:masterfrom
freddy77:misc
Nov 24, 2025
Merged

Miscellaneous patches#30
tilkinsc merged 10 commits into
tilkinsc:masterfrom
freddy77:misc

Conversation

@freddy77
Copy link
Copy Markdown
Contributor

A bunch of not so related changes, mostly minor.

Remove misleading comment

get_current_time() is not used to seed random number generators.

Use time() to compute epoch time

Simplify get_current_time() function as time() is common to more systems.
Also is more portable allowing to support more systems.

Wrap C function for C++ in headers

This allows to include just C headers in C++ code.
This format is also more common.

Remove useless cast

POWERS items are already uint64_t.

Avoid hmac overflows in otp_generate

Returns OTP_ERROR instead.

Minor style changes

Use mnemonics to test otp_num_to_bytestring results.
Simply copy the pointer for base32_secret string.

Simplify otp_byte_secret computation

Avoids the complex shifts to compute output.

Do not rebuild tests if not changed

test_c and test_cpp are real target, so remove them from the phony list otherwise they get rebuild even if not changed.

Use proper C declaration for functions not taking arguments

For historic reasons without anything the functions are allows to take any argument, better state that there are no argument.

Make test.c a proper test

Returns success or error based on tests.

get_current_time() is not used to seed random number generators.

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Simplify get_current_time() function as time() is common to
more systems.
Also is more portable allowing to support more systems.

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
This allows to include just C headers in C++ code.
This format is also more common.

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
POWERS items are already uint64_t.

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Returns OTP_ERROR instead.

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Use mnemonics to test otp_num_to_bytestring results.
Simply copy the pointer for base32_secret string.

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Avoids the complex shifts to compute output.

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
test_c and test_cpp are real target, so remove them from the
phony list otherwise they get rebuild even if not changed.

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
For historic reasons without anything the functions are allows
to take any argument, better state that there are no argument.

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
@tilkinsc
Copy link
Copy Markdown
Owner

Thanks for the PR. I have been on a coders block for a bit. I will review this.

@tilkinsc
Copy link
Copy Markdown
Owner

tilkinsc commented Nov 23, 2025

Could you synchronize your changes with the success bool with main.cpp with main.c Also, you changed up the way otp_generate() works. I am not sure on the specifics of how I implemented it (years ago). Have you done any sort of comprehensive test against the results of its generations?

Other than that, LGTM

Returns success or error based on tests.

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
@freddy77
Copy link
Copy Markdown
Contributor Author

Could you synchronize your changes with the success bool with main.cpp with main.c Also, you changed up the way otp_generate() works. I am not sure on the specifics of how I implemented it (years ago). Have you done any sort of comprehensive test against the results of its generations?

Other than that, LGTM

Done the sync of the C++ test.
About otp_generate() I didn't change that much to be honest. They are more style changes and buffer checks. They may look more but no.
About the testing I did some manual testing using various websites and programs (like FreeOTP) confirming the tokens were correct. Also I used the test programs (that's why I added the checks). I doubt that I wrong change would make the tests pass.

@tilkinsc
Copy link
Copy Markdown
Owner

Lgtm I don't see any security vulnerabilities with your changes. I'm not sure about the complex bit shifts still but whatever. The code is generally nicer.

@tilkinsc tilkinsc merged commit 7976053 into tilkinsc:master Nov 24, 2025
@freddy77 freddy77 deleted the misc branch November 25, 2025 22:06
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