- if (ctx == NULL) {
- printf("HMAC malloc failure (test 4)\n");
- err++;
- goto end;
- }
- if (HMAC_CTX_get_md(ctx) != NULL) {
- printf("Message digest not NULL for HMAC (test 4)\n");
- err++;
- goto test5;
- }
- if (HMAC_Init_ex(ctx, NULL, 0, NULL, NULL)) {
- printf("Should fail to initialise HMAC with empty MD and key (test 4)\n");
- err++;
- goto test5;
- }
- if (HMAC_Update(ctx, test[4].data, test[4].data_len)) {
- printf("Should fail HMAC_Update with ctx not set up (test 4)\n");
- err++;
- goto test5;
- }
- if (HMAC_Init_ex(ctx, NULL, 0, EVP_sha1(), NULL)) {
- printf("Should fail to initialise HMAC with empty key (test 4)\n");
- err++;
- goto test5;
- }
- if (HMAC_Update(ctx, test[4].data, test[4].data_len)) {
- printf("Should fail HMAC_Update with ctx not set up (test 4)\n");
- err++;
- goto test5;
- }
- printf("test 4 ok\n");
-test5:
- /* Test 5 has empty key; test that single-shot accepts a NULL key. */
- p = pt(HMAC(EVP_sha1(), NULL, 0, test[4].data, test[4].data_len,
- NULL, NULL), SHA_DIGEST_LENGTH);
- if (strcmp(p, (char *)test[4].digest) != 0) {
- printf("Error calculating HMAC on %d entry'\n", i);
- printf("got %s instead of %s\n", p, test[4].digest);
- err++;
- }
+ if (!TEST_ptr(ctx)
+ || !TEST_ptr_null(HMAC_CTX_get_md(ctx))
+ || !TEST_false(HMAC_Init_ex(ctx, NULL, 0, NULL, NULL))
+ || !TEST_false(HMAC_Update(ctx, test[4].data, test[4].data_len))
+ || !TEST_false(HMAC_Init_ex(ctx, NULL, 0, EVP_sha1(), NULL))
+ || !TEST_false(HMAC_Update(ctx, test[4].data, test[4].data_len)))
+ goto err;
+
+ ret = 1;
+err:
+ HMAC_CTX_free(ctx);
+ return ret;
+}
+
+static int test_hmac_run()
+{
+ char *p;
+ HMAC_CTX *ctx = NULL;
+ unsigned char buf[EVP_MAX_MD_SIZE];
+ unsigned int len;
+ int ret = 0;