speed.c 2.54 KB
Newer Older
lwc-tester committed
1 2 3 4 5 6 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 41 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
/*Bit-slice Implementation of sycon-hash-256
   Written by:
   Kalikinkar Mandal <kmandal@uwaterloo.ca>
*/

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

#include "sycon.h"
#include "clock_cycle.h"

#define NUM_ITER        1000
#define NUM_TEST      	500
#define NUMINSTANCE	1


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

int main()
{
        u8 num_parallel_inst;
        u32 *state;
        int i, j;
        u64 t[NUM_ITER+1], count_cc;
        
        u32 *plaintext, *digest;
        u64 plen;
        u32 hlen;
        
        num_parallel_inst = 4*NUMINSTANCE;
        plen = 64; // 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);
        

        
        for ( i = 0; i < num_parallel_inst; i++ )
        {
                for ( j = 0; j < plen; j++ )
                        plaintext[i*plen+j] = j%128;
        }
        
        
        //===================================================================================================================
       	//					Sycon-Hash-256
        //===================================================================================================================
        
        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 cbp\n", (double)(count_cc)/(double)(num_parallel_inst*plen*4));
        }
        
        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");
        }
        
        printf("Hash speed = %f cbp\n", (double)(count_cc)/(double)(num_parallel_inst*plen*4));
        
        
        free(state);
        free(plaintext);
        free(digest);
        return(0);
}