speed.c 2.48 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 bits.
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 < 8*PARAL_INST_BY8; 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

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


        num_parallel_inst = 8*PARAL_INST_BY8;
	plen = 32; // Message length = plen*32 bits;
	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 Module//
	//===================================================================================================================
	
        for ( i = 0; i < NUM_ITER; i++ )
        {
                //plaintext[0] = plaintext[0]^i;
                count_cc = start_rdtsc();
                crypto_hash( digest, plaintext, plen );
                count_cc = end_rdtsc()-count_cc;
                printf("Hash speed = %f cbp\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));
        //plen = 0;
        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);
}