static void test_md4_ctx(void) { static unsigned char message[] = "In our Life there's If" "In our beliefs there's Lie" "In our business there is Sin" "In our bodies, there is Die"; int size = sizeof(message) - 1; MD4_CTX ctx; MD4_CTX ctx_initialized = { { 0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476 }, { 0, 0 } }; MD4_CTX ctx_update1 = { { 0x5e592ef7, 0xbdcb1567, 0x2b626d17, 0x7d1198bd }, { 0x00000338, 0 } }; MD4_CTX ctx_update2 = { { 0x05dcfd65, 0xb3711c0d, 0x9e3369c2, 0x903ead11 }, { 0x00000670, 0 } }; unsigned char expect[16] = { 0x5f, 0xd3, 0x9b, 0x29, 0x47, 0x53, 0x47, 0xaf, 0xa5, 0xba, 0x0c, 0x05, 0xff, 0xc0, 0xc7, 0xda }; memset( &ctx, 0, sizeof(ctx) ); pMD4Init( &ctx ); ok( !ctxcmp( &ctx, &ctx_initialized ), "invalid initialization\n" ); pMD4Update( &ctx, message, size ); ok( !ctxcmp( &ctx, &ctx_update1 ), "update doesn't work correctly\n" ); pMD4Update( &ctx, message, size ); ok( !ctxcmp( &ctx, &ctx_update2 ), "update doesn't work correctly\n" ); pMD4Final( &ctx ); ok( ctxcmp( &ctx, &ctx_initialized ), "context has changed\n" ); ok( !memcmp( ctx.digest, expect, sizeof(expect) ), "incorrect result\n" ); }
int main() { /* Repeatedly save and load the context, then compare it to the first one. */ urlctx *ctx = url_init( "http://*gooogle*\n" "ftp://fooo\n" "*adwords\n" "http*//*.php"); // Yes yes, insecure mktemp. This is a unit test. char name[] = "/tmp/bintestXXXXXX"; mktemp(name); if (url_save_optimized(ctx, name)) fail("save failed\n"); u32 i; urlctx *tmp; for (i = 0; i < 20; i++) { tmp = url_init_file(name); if (!tmp) fail("load failed\n"); if (url_save_optimized(tmp, name)) fail("save failed\n"); url_free(tmp); } tmp = url_init_file(name); if (ctxcmp(ctx, tmp)) fail("compare failed\n"); url_free(ctx); url_free(tmp); unlink(name); return 0; }