-
Notifications
You must be signed in to change notification settings - Fork 14
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 wrapper for EVP_BPE_scrypt
#246
base: v2
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for submitting. Adding Scrypt support seems like a good addition. Added some comments.
defer C.free(key) | ||
|
||
res := C.go_openssl_EVP_PBE_scrypt( | ||
cpassword, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The password content is not being modified, so there is no need to create a copy of it. unsafe
is our friend here:
cpassword, | |
base(unsafe.StringData(password)), |
res := C.go_openssl_EVP_PBE_scrypt( | ||
cpassword, | ||
C.size_t(len(password)), | ||
(*C.uchar)(csalt), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as with password
, no need to copy salt
as it is not being modified:
(*C.uchar)(csalt), | |
base(salt), |
key := C.malloc(C.size_t(keylen)) | ||
defer C.free(key) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
key
can directly be allocated in Go memory and passed to go_openssl_EVP_PBE_scrypt
using base(key)
.
key := C.malloc(C.size_t(keylen)) | |
defer C.free(key) | |
key := make([]byte, keylen) |
|
||
DEFINEFUNC_1_1_1(int, EVP_PBE_scrypt, (const char *pass, size_t passlen, const unsigned char *salt, size_t saltlen, uint64_t N, uint64_t r, uint64_t p, uint64_t maxmem, unsigned char *key, size_t keylen), (pass, passlen, salt, saltlen, N, r, p, maxmem, key, keylen)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
EVP_PBE_scrypt
is defined since OpenSSL 3.0
DEFINEFUNC_1_1_1(int, EVP_PBE_scrypt, (const char *pass, size_t passlen, const unsigned char *salt, size_t saltlen, uint64_t N, uint64_t r, uint64_t p, uint64_t maxmem, unsigned char *key, size_t keylen), (pass, passlen, salt, saltlen, N, r, p, maxmem, key, keylen)) | |
DEFINEFUNC_3_0(int, EVP_PBE_scrypt, (const char *pass, size_t passlen, const unsigned char *salt, size_t saltlen, uint64_t N, uint64_t r, uint64_t p, uint64_t maxmem, unsigned char *key, size_t keylen), (pass, passlen, salt, saltlen, N, r, p, maxmem, key, keylen)) \ | |
"unsafe" | ||
) | ||
|
||
func Scrypt(password string, salt []byte, N, r, p, maxmem, keylen uint64) ([]byte, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: use Go naming conventions
func Scrypt(password string, salt []byte, N, r, p, maxmem, keylen uint64) ([]byte, error) { | |
func Scrypt(password string, salt []byte, N, r, p, maxMem, keyLen uint64) ([]byte, error) { |
import ( | ||
"unsafe" | ||
) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
EVP_PBE_scrypt
is supported since OpenSSL 3, and maybe not for all providers. Please implement the SupportsSscrypt() bool
function. The implementation will be almost identical to
Line 15 in eb155da
func SupportsPBKDF2() bool { |
PBKDF2
with SCRYPT
and returning false
in the OpenSSL 1 case.
Then use this function in the new test cases.
Pretty simple, just a wrapper function around
EVP_BPE_scrypt
with some simple tests.