Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tcl pbkdf2 function #1569

Open
wants to merge 9 commits into
base: develop
Choose a base branch
from

Conversation

michaelortmann
Copy link
Member

@michaelortmann michaelortmann commented Apr 27, 2024

Found by: grawity
Patch by: michaelortmann
Fixes:

One-line summary:
Add tcl pbkdf2 function

Additional description (if needed):
Useful for tcl scripts like https://github.com/grawity/eggdrop-sasl/blob/master/README.md#scram-sha-support that add SASL SCRAM mechanism, where the author said "which is very slow in Tcl so the server may time out". So this PR will help the author out with a fast replacement function exported by eggdrop. hope that helps and cheerz to grawity for his great work :)

The new tcl function pbkdf2() returns as hexadecimal string by default and -bin by option, which is similar, to what tcllibs sha256() does (older tcllibs md5 had it the other way around), see https://core.tcl-lang.org/tcllib/doc/trunk/embedded/md/tcllib/files/modules/sha1/sha256.md

Test cases demonstrating functionality (if applicable):
Benchmark times were measured with #1568 applied
Benchmark and Result of external tcl script providing pbkdf2():

.tcl source scripts/g_pbkdf2.tcl
[03:05:34] tcl: builtin dcc call: *dcc:tcl -HQ 1 source scripts/g_pbkdf2.tcl
[03:05:34] tcl: evaluate (.tcl): source scripts/g_pbkdf2.tcl
Tcl: 
.tcl pbkdf2::pbkdf2 sha256 hunter 42 1500
[03:05:45] tcl: builtin dcc call: *dcc:tcl -HQ 1 pbkdf2::pbkdf2 sha256 hunter 42 1500
[03:05:45] tcl: evaluate (.tcl): pbkdf2::pbkdf2 sha256 hunter 42 1500
3V_nep¡Ð¤òüÌê »^áÅÊT~3ö,

user 514.968ms sys 0.000ms
Benchmark and result of new pmkdf2 mod function providing pbkdf2():

.tcl pbkdf2 hunter 42 1500 sha256
[08:27:07] tcl: builtin dcc call: *dcc:tcl -HQ 1 pbkdf2 hunter 42 1500 sha256
[08:27:07] tcl: evaluate (.tcl): pbkdf2 hunter 42 1500 sha256
Tcl: 150D9333565F6E6570A193D0A4F2FC97CCEAA0BB5EC3A1C5CA9454067E33F62C
.tcl pbkdf2 -bin hunter 42 1500 sha256
[08:27:17] tcl: builtin dcc call: *dcc:tcl -HQ 1 pbkdf2 -bin hunter 42 1500 sha256
[08:27:17] tcl: evaluate (.tcl): pbkdf2 -bin hunter 42 1500 sha256
3V_nep¡Ð¤òüÌê »^áÅÊT~3ö,

user 0.510ms sys 0.000ms
Test and demo of replacement function for grawities script:

.tcl source scripts/g_base64.tcl
.tcl source scripts/g_pbkdf2.tcl

orig func:

.tcl set saltedPassword [::pbkdf2::pbkdf2 sha256 hunter mysalt 1500]
.tcl b64:encode $saltedPassword
Tcl: rNb2VlyBIeNaSMc9YtVcthpvUoi1fPvAcN1PcHlc1J0=

replacement func:

.tcl set saltedPassword2 [pbkdf2 -bin hunter mysalt 1500 sha256]
.tcl b64:encode $saltedPassword2
Tcl: rNb2VlyBIeNaSMc9YtVcthpvUoi1fPvAcN1PcHlc1J0=

see also:
https://github.com/grawity/eggdrop-sasl/blob/master/g_scram.tcl#L156

@vanosg
Copy link
Member

vanosg commented Apr 29, 2024

I'm starting to dig into this in-depth, but a few initial suggestions. Could you please...

  • Add this command to doc/tcl-commands.doc
  • Add encpass2 to tcl-commands.doc ;)
  • Move (and create) these Tcl comamnds into tclpbkdf2.c

Copy link
Member

@vanosg vanosg left a comment

Choose a reason for hiding this comment

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

This is a great feature to add!

src/mod/pbkdf2.mod/pbkdf2.c Outdated Show resolved Hide resolved
src/mod/pbkdf2.mod/pbkdf2.c Outdated Show resolved Hide resolved
src/mod/pbkdf2.mod/pbkdf2.c Outdated Show resolved Hide resolved
@michaelortmann
Copy link
Member Author

* Add this command to doc/tcl-commands.doc

done

* Add encpass2 to tcl-commands.doc ;)

done

* Move (and create) these Tcl comamnds into tclpbkdf2.c

not sure, thats a good idea, because then pbkdf2.c and tclpbkdf2.c would mutually depend on each other. If you still want, i could add a shared header file to make such "separation".

@michaelortmann
Copy link
Member Author

done, tcl funcs separated into tclpbkdf2.c

@vanosg
Copy link
Member

vanosg commented May 5, 2024

note for merge- run makedepend

@vanosg
Copy link
Member

vanosg commented May 5, 2024

As a real world test, can you hack this into grawity's script and confirm it works as expected?

@michaelortmann
Copy link
Member Author

michaelortmann commented May 6, 2024

note for merge- run makedepend

this PR does not need makedepend

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.

None yet

2 participants