/* This code is designed to call libfko functions multiple times without * calling fko_destroy() until the very end. This allows valgrind to verify * whether memory is proerly handled between calls. */ #include #include #include #include "fko_common.h" #include "common.h" #include "fko_limits.h" #include "fwknop.h" #include "fko.h" #define ENABLE_GPG_TESTS 0 #define FCN_CALLS 5 #define CTX_DESTROY 0 #define NO_CTX_DESTROY 1 static void display_ctx(fko_ctx_t ctx); static void test_loop(int destroy_ctx_flag); int main(void) { test_loop(NO_CTX_DESTROY); test_loop(CTX_DESTROY); return 0; } static void test_loop(int destroy_ctx_flag) { fko_ctx_t ctx = NULL, decrypt_ctx = NULL; int i; char *spa_data = NULL; printf("fko_new(): %d\n", fko_new(&ctx)); for (i=0; i" : spa_data); if (destroy_ctx_flag == CTX_DESTROY) { fko_destroy(ctx); ctx = NULL; } } /* now decrypt */ printf("fko_new_with_data(): %d\n", fko_new_with_data(&decrypt_ctx, spa_data, NULL, 0, FKO_ENC_MODE_CBC, NULL, 0, 0)); for (i=0; i" : rand_val); printf(" Username: %s\n", username == NULL ? "" : username); printf(" Timestamp: %u\n", (unsigned int) timestamp); printf(" FKO Version: %s\n", version == NULL ? "" : version); printf(" Message Type: %i\n", msg_type); printf(" Message String: %s\n", spa_message == NULL ? "" : spa_message); printf(" Nat Access: %s\n", nat_access == NULL ? "" : nat_access); printf(" Server Auth: %s\n", server_auth == NULL ? "" : server_auth); printf(" Client Timeout: %d\n", client_timeout); printf(" Digest Type: %d\n", digest_type); printf(" HMAC Type: %d\n", hmac_type); printf("Encryption Mode: %d\n", encryption_mode); printf("\n Encoded Data: %s\n", enc_data == NULL ? "" : enc_data); printf("SPA Data Digest: %s\n", spa_digest == NULL ? "" : spa_digest); printf(" HMAC: %s\n", hmac_data == NULL ? "" : hmac_data); if (enc_data != NULL && spa_digest != NULL) printf(" Plaintext: %s:%s\n", enc_data, spa_digest); printf("\nFinal Packed/Encrypted/Encoded Data:\n\n%s\n\n", spa_data); }