Skip to content

Commit cca600e

Browse files
authored
Merge pull request #200 from cconlon/hmacStrKey
Support -1 HMAC key length
2 parents 70c16aa + 6d1ef1d commit cca600e

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,14 @@ as described earlier.
164164
See the scripts directory for integration tests with other applications (e.g.
165165
OpenSSH, stunnel, etc.).
166166

167+
### Commit Tests
168+
169+
For wolfEngine developers running commit tests, a custom OpenSSL installation
170+
location can be set using the `WOLFENGINE_OPENSSL_INSTALL` environment variable.
171+
When set, wolfEngine commit tests will use the specified OpenSSL installation
172+
path for commit tests, setting the path using
173+
`--with-openssl=WOLFENGINE_OPENSSL_INSTALL` at configure time.
174+
167175
## Windows
168176

169177
Refer to `windows/README.md` for instructions for building wolfEngine using

src/we_mac.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,11 @@ static int we_mac_pkey_ctrl(EVP_PKEY_CTX *ctx, int type, int num, void *ptr)
464464
* num [in] Length of key in bytes.
465465
*/
466466
WOLFENGINE_MSG(WE_LOG_MAC, "type: EVP_PKEY_CTRL_SET_MAC_KEY");
467-
if (ptr != NULL && num >= 0) {
467+
if (ptr != NULL && num >= -1) {
468+
if (num == -1) {
469+
/* App can pass -1 length, must use strlen() */
470+
num = (int)XSTRLEN(ptr);
471+
}
468472
ret = we_mac_set_key(mac, ptr, num);
469473
}
470474
else {

test/test_hmac.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,45 +135,71 @@ int test_hmac_create(ENGINE *e, void *data)
135135
if (ret == 0) {
136136
PRINT_MSG("Testing with SHA224");
137137
ret = test_hmac_create_helper(e, data, EVP_sha224(), pswd, sizeof(pswd));
138+
if (ret == 0) {
139+
/* EVP_PKEY_new_mac_key() can be called with -1, OpenSSL expects
140+
* engine implementations to use strlen() to find string length */
141+
ret = test_hmac_create_helper(e, data, EVP_sha224(), pswd, -1);
142+
}
138143
}
139144

140145
if (ret == 0) {
141146
PRINT_MSG("Testing with SHA256");
142147
ret = test_hmac_create_helper(e, data, EVP_sha256(), pswd, sizeof(pswd));
148+
if (ret == 0) {
149+
ret = test_hmac_create_helper(e, data, EVP_sha256(), pswd, -1);
150+
}
143151
}
144152

145153
if (ret == 0) {
146154
PRINT_MSG("Testing with SHA384");
147155
ret = test_hmac_create_helper(e, data, EVP_sha384(), pswd, sizeof(pswd));
156+
if (ret == 0) {
157+
ret = test_hmac_create_helper(e, data, EVP_sha384(), pswd, -1);
158+
}
148159
}
149160

150161
if (ret == 0) {
151162
PRINT_MSG("Testing with SHA512");
152163
ret = test_hmac_create_helper(e, data, EVP_sha512(), pswd, sizeof(pswd));
164+
if (ret == 0) {
165+
ret = test_hmac_create_helper(e, data, EVP_sha512(), pswd, -1);
166+
}
153167
}
154168

155169
#ifdef WE_HAVE_SHA3_224
156170
if (ret == 0) {
157171
PRINT_MSG("Testing with SHA3-224");
158172
ret = test_hmac_create_helper(e, data, EVP_sha3_224(), pswd, sizeof(pswd));
173+
if (ret == 0) {
174+
ret = test_hmac_create_helper(e, data, EVP_sha3_224(), pswd, -1);
175+
}
159176
}
160177
#endif
161178
#ifdef WE_HAVE_SHA3_256
162179
if (ret == 0) {
163180
PRINT_MSG("Testing with SHA3-256");
164181
ret = test_hmac_create_helper(e, data, EVP_sha3_256(), pswd, sizeof(pswd));
182+
if (ret == 0) {
183+
ret = test_hmac_create_helper(e, data, EVP_sha3_256(), pswd, -1);
184+
}
165185
}
166186
#endif
167187
#ifdef WE_HAVE_SHA3_384
168188
if (ret == 0) {
169189
PRINT_MSG("Testing with SHA3-384");
170190
ret = test_hmac_create_helper(e, data, EVP_sha3_384(), pswd, sizeof(pswd));
191+
if (ret == 0) {
192+
ret = test_hmac_create_helper(e, data, EVP_sha3_384(), pswd, -1);
193+
}
171194
}
172195
#endif
173196
#ifdef WE_HAVE_SHA3_512
174197
if (ret == 0) {
175198
PRINT_MSG("Testing with SHA3-512");
176199
ret = test_hmac_create_helper(e, data, EVP_sha3_512(), pswd, sizeof(pswd));
200+
if (ret == 0) {
201+
ret = test_hmac_create_helper(e, data, EVP_sha3_512(), pswd, -1);
202+
}
177203
}
178204
#endif
179205
return ret;

0 commit comments

Comments
 (0)