Esempio n. 1
0
/* Digests a file and prints the result.
 */
static void MDFile(char *filename)
{
    apr_file_t *file;
    apr_md4_ctx_t context;
    apr_size_t len = 1024;
    unsigned char buffer[1024], digest[APR_MD4_DIGESTSIZE];

    if (apr_file_open(&file, filename, APR_READ, APR_OS_DEFAULT, local_pool) 
        != APR_SUCCESS)
        apr_file_printf(err, "%s can't be opened\n", filename);
    else {
        apr_md4_init(&context);
        while (apr_file_read(file, buffer, &len) != APR_SUCCESS)
        {
            apr_md4_update(&context, buffer, len);
            len = 1024;
        }
        apr_md4_final(digest, &context);

        apr_file_close(file);

        apr_file_printf(out, "MD4 (%s) = ", filename);
        MDPrint(digest);
        apr_file_printf(out, "\n");
    }
}
Esempio n. 2
0
/* Digests the standard input and prints the result.
 */
static void MDFilter(void)
{
    apr_md4_ctx_t context;
    apr_size_t len = 16;
    unsigned char buffer[16], digest[16];

    apr_md4_init(&context);
    while (apr_file_read(in, buffer, &len) != APR_SUCCESS)
    {
        apr_md4_update(&context, buffer, len);
        len = 16;
    }
    apr_md4_update(&context, buffer, len);
    apr_md4_final(digest, &context);

    MDPrint(digest);
    apr_file_printf(out, "\n");
}
Esempio n. 3
0
static int MDStringComp(const void *string, const void *sum)
{
        apr_md4_ctx_t context;
        unsigned char digest[APR_MD4_DIGESTSIZE];
        unsigned int len = strlen(string);

        apr_md4_init(&context);
        apr_md4_update(&context, (unsigned char *)string, len);
        apr_md4_final(digest, &context);
        return (memcmp(digest, sum, APR_MD4_DIGESTSIZE));

}
Esempio n. 4
0
/* Digests a string and prints the result.
 */
static void MDString(char *string)
{
    apr_md4_ctx_t context;
    unsigned char digest[APR_MD4_DIGESTSIZE];
    unsigned int len = strlen(string);

    apr_md4_init(&context);
    apr_md4_update(&context, (unsigned char *)string, len);
    apr_md4_final(digest, &context);

    apr_file_printf (out, "MD4 (\"%s\") = ", string);
    MDPrint(digest);
    apr_file_printf (out, "\n");
}
Esempio n. 5
0
static void test_md4sum(abts_case *tc, void *data)
{
        apr_md4_ctx_t context;
        unsigned char digest[APR_MD4_DIGESTSIZE];
        const void *string = md4sums[count].string;
        const void *sum = md4sums[count].md4sum;
        unsigned int len = strlen(string);

        ABTS_ASSERT(tc, "apr_md4_init", (apr_md4_init(&context) == 0));
        ABTS_ASSERT(tc, "apr_md4_update", 
                    (apr_md4_update(&context, 
                                    (unsigned char *)string, len) == 0));
        
        ABTS_ASSERT(tc, "apr_md4_final", (apr_md4_final(digest, &context) ==0));
        ABTS_ASSERT(tc, "check for correct md4 digest", 
                    (memcmp(digest, sum, APR_MD4_DIGESTSIZE) == 0));
}
Esempio n. 6
0
/* Measures the time to digest TEST_BLOCK_COUNT TEST_BLOCK_LEN-byte
     blocks.
 */
static void MDTimeTrial(void)
{
    apr_md4_ctx_t context;
    apr_time_t endTime, startTime;
    apr_interval_time_t timeTaken;
    unsigned char block[TEST_BLOCK_LEN], digest[APR_MD4_DIGESTSIZE];
    unsigned int i;

    apr_file_printf(out, "MD4 time trial. Digesting %d %d-byte blocks ...", 
                     TEST_BLOCK_LEN, TEST_BLOCK_COUNT);

    /* Initialize block */
    for (i = 0; i < TEST_BLOCK_LEN; i++)
        block[i] = (unsigned char)(i & 0xff);

    /* Start timer */
    startTime = apr_time_now();

    /* Digest blocks */
    apr_md4_init(&context);
    for (i = 0; i < TEST_BLOCK_COUNT; i++)
        apr_md4_update(&context, block, TEST_BLOCK_LEN);

    apr_md4_final(digest, &context);

    /* Stop timer */
    endTime = apr_time_now();
    timeTaken = endTime - startTime;

    apr_file_printf(out, " done\n");
    apr_file_printf(out, "Digest = ");
    MDPrint(digest);

    apr_file_printf(out, "\nTime = %" APR_TIME_T_FMT " seconds\n", timeTaken);
    apr_file_printf(out, "Speed = % " APR_TIME_T_FMT " bytes/second\n",
                    TEST_BLOCK_LEN * TEST_BLOCK_COUNT/timeTaken);
}