gb.openssl: Add tests for new Pbkdf2 and Scrypt methods
[GB.OPENSSL] * NEW: Add beginning of a test suite. * OPT: Avoid doubles in integer power-of-two test.
This commit is contained in:
parent
b1fbac987e
commit
f5ca983f88
5 changed files with 48 additions and 1 deletions
2
gb.openssl/openssl-test/.directory
Normal file
2
gb.openssl/openssl-test/.directory
Normal file
|
@ -0,0 +1,2 @@
|
|||
[Desktop Entry]
|
||||
Icon=./.icon.png
|
BIN
gb.openssl/openssl-test/.icon.png
Normal file
BIN
gb.openssl/openssl-test/.icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 11 KiB |
8
gb.openssl/openssl-test/.project
Normal file
8
gb.openssl/openssl-test/.project
Normal file
|
@ -0,0 +1,8 @@
|
|||
# Gambas Project File 3.0
|
||||
Startup=Main
|
||||
Version=0.0.1
|
||||
Component=gb.openssl
|
||||
Component=gb.test
|
||||
TabSize=2
|
||||
Language=en_US
|
||||
Packager=1
|
36
gb.openssl/openssl-test/.src/Main.module
Normal file
36
gb.openssl/openssl-test/.src/Main.module
Normal file
|
@ -0,0 +1,36 @@
|
|||
' Gambas module file
|
||||
|
||||
' https://tools.ietf.org/html/draft-josefsson-scrypt-kdf-00#page-10
|
||||
Private Const PBKDF2_SHA256_80000_64 As String = ""
|
||||
"\x4d\xdc\xd8\xf6\x0b\x98\xbe\x21\x83\x0c\xee\x5e\xf2\x27\x01\xf9"
|
||||
"\x64\x1a\x44\x18\xd0\x4c\x04\x14\xae\xff\x08\x87\x6b\x34\xab\x56"
|
||||
"\xa1\xd4\x25\xa1\x22\x58\x33\x54\x9a\xdb\x84\x1b\x51\xc9\xb3\x17"
|
||||
"\x6a\x27\x2b\xde\xbb\xa1\xd0\x78\x47\x8f\x62\xb3\x97\xf3\x3c\x8d"
|
||||
|
||||
Private Const SCRYPT_1024_8_64 As String = ""
|
||||
"\xfd\xba\xbe\x1c\x9d\x34\x72\x00\x78\x56\xe7\x19\x0d\x01\xe9\xfe"
|
||||
"\x7c\x6a\xd7\xcb\xc8\x23\x78\x30\xe7\x73\x76\x63\x4b\x37\x31\x62"
|
||||
"\x2e\xaf\x30\xd9\x2e\x22\xa3\x88\x6f\xf1\x09\x27\x9d\x98\x30\xda"
|
||||
"\xc7\x27\xaf\xb9\x4a\x83\xee\x6d\x83\x60\xcb\xdf\xa2\xcc\x06\x40"
|
||||
|
||||
Public Sub Main()
|
||||
|
||||
Dim p, s As String
|
||||
Dim a As New String[]
|
||||
|
||||
Test.Plan(4)
|
||||
|
||||
p = OpenSSL.Pbkdf2("Password", "NaCl", 80000, 64, "SHA256")
|
||||
s = OpenSSL.Scrypt("password", "NaCl", 1024, 8, 16, 64)
|
||||
Assert.Equals(Base64$(p), Base64$(PBKDF2_SHA256_80000_64), "PBKDF2 matches test vector")
|
||||
Assert.Equals(Base64$(s), Base64$(SCRYPT_1024_8_64), "scrypt matches test vector")
|
||||
|
||||
Test.Note("Testing again for memory management")
|
||||
For i As Integer = 1 To 2 ^ 10
|
||||
a.Add(OpenSSL.RandomBytes(2 ^ 14))
|
||||
Next
|
||||
|
||||
Assert.Equals(Base64$(p), Base64$(PBKDF2_SHA256_80000_64), "PBKDF2 matches test vector")
|
||||
Assert.Equals(Base64$(s), Base64$(SCRYPT_1024_8_64), "scrypt matches test vector")
|
||||
|
||||
End
|
|
@ -149,7 +149,8 @@ BEGIN_METHOD(OpenSSL_Scrypt, GB_STRING password; GB_STRING salt; GB_LONG N; GB_L
|
|||
GB.Error("Invalid Parameter: N must be greater than 1");
|
||||
return;
|
||||
}
|
||||
if (ceil(log2(lN)) != floor(log2(lN))) {
|
||||
/* Bitwise power of 2 test */
|
||||
if (lN == 0 || (lN & (lN - 1)) != 0) {
|
||||
GB.Error("Invalid Parameter: N must be a power of 2");
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue