This repository has been archived by the owner on Apr 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
passkey calculation as a C extension
given the string overhead involved in the calculation.
- Loading branch information
1 parent
bed5e38
commit d62907e
Showing
9 changed files
with
92 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
/Gemfile.lock | ||
/vendor | ||
.env | ||
/ext/Makefile | ||
|
||
*.DS_Store | ||
*.sw[po] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
require 'mkmf' | ||
create_makefile 'netsnmp_ext' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#include <ruby.h> | ||
|
||
#define USM_LENGTH_EXPANDED_PASSPHRASE (1024 * 1024) /* 1Meg. */ | ||
#define USM_LENGTH_KU_HASHBLOCK 64 | ||
|
||
static VALUE mNETSNMP; | ||
static VALUE cNETSNMP_Sec_Params; | ||
|
||
static VALUE NETSNMP_expand_passphrase(VALUE self, VALUE password) | ||
{ | ||
char *P; | ||
size_t P_len; | ||
int nbytes = USM_LENGTH_EXPANDED_PASSPHRASE; | ||
u_int pindex = 0; | ||
u_char buf[USM_LENGTH_EXPANDED_PASSPHRASE], *bufp; | ||
|
||
StringValue(password); | ||
P = RSTRING_PTR(password); | ||
P_len = RSTRING_LEN(password); | ||
|
||
bufp = buf; | ||
while (nbytes > 0) { | ||
*bufp++ = P[pindex++ % P_len]; | ||
// if (!EVP_DigestUpdate(ctx, buf, USM_LENGTH_KU_HASHBLOCK)) | ||
// ossl_raise(eDigestError, "EVP_DigestUpdate"); | ||
|
||
nbytes--; | ||
} | ||
|
||
// if (!EVP_DigestFinal_ex(ctx, &Ku, &kulen)) | ||
// ossl_raise(eDigestError, "EVP_DigestFinal_ex"); | ||
|
||
// memset(buf, 0, sizeof(buf)); | ||
|
||
// TODO: trim to 16 bytes if auth protocol is md5 | ||
|
||
return rb_usascii_str_new((const char *) buf, USM_LENGTH_EXPANDED_PASSPHRASE); | ||
} | ||
|
||
void Init_netsnmp_ext( void ) | ||
{ | ||
mNETSNMP = rb_define_module("NETSNMP"); | ||
cNETSNMP_Sec_Params = rb_define_class_under(mNETSNMP, "SecurityParameters", rb_cObject); | ||
// rb_define_method(cNETSNMP_Sec_Params, "passkey", NETSNMP_passkey, 1); | ||
rb_define_method(cNETSNMP_Sec_Params, "expand_passphrase", NETSNMP_expand_passphrase, 1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters