speed.c 2.52 KB
Newer Older
lwc-tester committed
1 2 3
/* Reference implementation of ACE-Hash256
 Written by:
 Kalikinkar Mandal <kmandal@uwaterloo.ca>
lwc-tester committed
4 5 6

 Currently this implementation supports hash computation when input message 
 length is a multiple of 64.
lwc-tester committed
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
 */


#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<math.h>

#include "ace.h"
#include "clock_cycle.h"

#define NUM_ITER        2000
#define NUM_TEST      	500


void print_state ( u32 *state )
{
        u8 i, j;
        
        for ( j = 0; j < 4*PARAL_INST_BY4; j++ )
        {
                for ( i = 0; i < STATEDWORD; i++ )
                        printf("%.8X", state[i+j*STATEDWORD]);
                printf("\n");
        }
        return;
}

int main()
{
        u8 num_parallel_inst;
        u32 *state;
        int i, j;
        
lwc-tester committed
41
        u64 count_cc;
lwc-tester committed
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103

	u32 *plaintext, *digest;
	u64 plen;
	u32 hlen;

        num_parallel_inst = 4*PARAL_INST_BY4;
	plen = 32; // Message length = plen*32;
	hlen = 8; //256 = 32*8 bits

	digest = (u32 *)malloc(sizeof(u32)*hlen*num_parallel_inst);

	plaintext = (u32 *)malloc(sizeof(u32)*plen*num_parallel_inst);
        
        state = (u32 *)malloc(sizeof(u32)*num_parallel_inst*STATEDWORD);
       
        
        //Randomly generating messages//
        for ( i = 0; i < num_parallel_inst; i++ )
        {
                for ( j = 0; j < plen; j++ )
                        plaintext[i*plen+j] = j%128;
        }
	
        
	//===================================================================================================================
				// HASH Mode//
	//===================================================================================================================
        
        //Testing speed for ACE-Hash
        for ( i = 0; i < NUM_ITER; i++ )
        {
                count_cc = start_rdtsc();
                crypto_hash ( digest, plaintext, plen );
                count_cc = end_rdtsc()-count_cc;
                printf("Hash speed = %f cpb\n", (double)(count_cc)/(double)(num_parallel_inst*plen*4));
        }
        printf("Hash speed = %f cbp\n", (double)(count_cc)/(double)(num_parallel_inst*plen*4));
        //Conputing hash
        crypto_hash ( digest, plaintext, plen );
	printf("Original plaintext:\n");
	for ( i = 0; i < num_parallel_inst; i++ )
	{
		for ( j = 0; j < plen; j++ )
			printf("%08X", plaintext[i*plen+j]);
		printf("\n");
	}

	printf("Digest:\n");
	for ( i = 0; i < num_parallel_inst; i++ )
	{
		for ( j = 0; j < hlen; j++ )
			printf("%08X", digest[i*hlen+j]);
		printf("\n");
	}
	
	

        free(state);
	free(plaintext);
	free(digest);
return(0);
}