void sign_verify_cmac(void)
{
- // TODO rewrite it
-#if 0
- char* signature = NULL;
+ char *signature1 = NULL;
+ char *signature2 = NULL;
size_t signature_len;
yaca_ctx_h ctx = YACA_CTX_NULL;
return;
// SIGN
- // TODO: CMAC must extract the key length to select the proper evp (EVP_aes_XXX_cbc()) it should be documented
- if (yaca_sign_init(&ctx, YACA_DIGEST_CMAC, key) != 0)
+ if (yaca_sign_cmac_init(&ctx, YACA_ENC_AES, key) != 0)
goto finish;
if (yaca_sign_update(ctx, lorem4096, LOREM4096_SIZE))
if (yaca_get_sign_length(ctx, &signature_len) != 0)
goto finish;
- if ((signature = yaca_malloc(signature_len)) == NULL)
+ if ((signature1 = yaca_malloc(signature_len)) == NULL)
goto finish;
- if (yaca_sign_final(ctx, signature, &signature_len))
+ if (yaca_sign_final(ctx, signature1, &signature_len))
goto finish;
- dump_hex(signature, signature_len, "CMAC Signature of lorem4096:");
+ dump_hex(signature1, signature_len, "CMAC Signature of lorem4096:");
// CLEANUP
yaca_ctx_free(ctx);
ctx = YACA_CTX_NULL;
// VERIFY
- if (yaca_verify_init(&ctx, YACA_DIGEST_CMAC, key) != 0)
+ if (yaca_sign_cmac_init(&ctx, YACA_ENC_AES, key) != 0)
goto finish;
- if (yaca_verify_update(ctx, lorem4096, LOREM4096_SIZE) != 0)
+ if (yaca_sign_update(ctx, lorem4096, LOREM4096_SIZE))
goto finish;
- if (yaca_verify_final(ctx, signature, signature_len) != 0)
+ if (yaca_get_sign_length(ctx, &signature_len) != 0)
+ goto finish;
+
+ if ((signature2 = yaca_malloc(signature_len)) == NULL)
+ goto finish;
+
+ if (yaca_sign_final(ctx, signature2, &signature_len))
+ goto finish;
+
+ if (yaca_memcmp(signature1, signature2, signature_len) != 0)
printf("CMAC verification failed\n");
else
printf("CMAC verification succesful\n");
finish:
- yaca_free(signature);
+ yaca_free(signature1);
+ yaca_free(signature2);
yaca_key_free(key);
yaca_ctx_free(ctx);
-#endif
}
int main()