diff options
author | Matt Turner <mattst88@gmail.com> | 2008-11-13 03:40:02 +0000 |
---|---|---|
committer | Matt Turner <mattst88@gmail.com> | 2008-11-13 03:40:02 +0000 |
commit | 113c4ba4d6780449afd4681e56b6aba07908402f (patch) | |
tree | cd9336ae17b88153a4a1fc452ef6be1320f66ee7 /idea.c | |
parent | 37438ca202a9a1f4e782f1d1803686fc6b65e918 (diff) |
-- Still working toward killing nbench1.h
-- Removing AllocateMemory and FreeMemory calls
git-svn-id: svn://mattst88.com/svn/cleanbench/trunk@15 0d43b9a7-5ab2-4d7b-af9d-f64450cef757
Diffstat (limited to 'idea.c')
-rw-r--r-- | idea.c | 58 |
1 files changed, 31 insertions, 27 deletions
@@ -1,6 +1,13 @@ +#include <stdio.h> +#include <stdlib.h> +#include <stdint.h> +#include <math.h> +#include <limits.h> + #include "nmglobal.h" #include "nbench1.h" + /******************** ** IDEA Encryption ** ********************* @@ -55,11 +62,10 @@ IDEAkey Z,DK; uint16_t userkey[8]; unsigned long accumtime; double iterations; -char *errorcontext; -int systemerror; -unsigned char *plain1; /* First plaintext buffer */ -unsigned char *crypt1; /* Encryption buffer */ -unsigned char *plain2; /* Second plaintext buffer */ +char *context; +unsigned char *plain1 = NULL; /* First plaintext buffer */ +unsigned char *crypt1 = NULL; /* Encryption buffer */ +unsigned char *plain2 = NULL; /* Second plaintext buffer */ /* ** Link to global data @@ -69,7 +75,7 @@ locideastruct=&global_ideastruct; /* ** Set error context */ -errorcontext="CPU:IDEA"; +context="CPU:IDEA"; /* ** Re-init random-number generator. @@ -99,28 +105,25 @@ de_key_idea(Z,DK); ** So, plain1 and plain2 should match. ** Also, fill up plain1 with sample text. */ -plain1=(unsigned char *)AllocateMemory(locideastruct->arraysize,&systemerror); -if(systemerror) -{ - ReportError(errorcontext,systemerror); - ErrorExit(); +plain1 = malloc(locideastruct->arraysize); +if (!plain1) { + fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context); + exit(1); } -crypt1=(unsigned char *)AllocateMemory(locideastruct->arraysize,&systemerror); -if(systemerror) -{ - ReportError(errorcontext,systemerror); - FreeMemory((void *)plain1,&systemerror); - ErrorExit(); +crypt1 = malloc(locideastruct->arraysize); +if (!crypt1) { + fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context); + free(plain1); + exit(1); } -plain2=(unsigned char *)AllocateMemory(locideastruct->arraysize,&systemerror); -if(systemerror) -{ - ReportError(errorcontext,systemerror); - FreeMemory((void *)plain1,&systemerror); - FreeMemory((void *)crypt1,&systemerror); - ErrorExit(); +plain2 = malloc(locideastruct->arraysize); +if (!plain2) { + fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context); + free(plain1); + free(plain2); + exit(1); } /* ** Note that we build the "plaintext" by simply loading @@ -165,9 +168,10 @@ do { ** Clean up, calculate results, and go home. Be sure to ** show that we don't have to rerun adjustment code. */ -FreeMemory((void *)plain1,&systemerror); -FreeMemory((void *)crypt1,&systemerror); -FreeMemory((void *)plain2,&systemerror); +free(plain1); +free(crypt1); +free(plain2); + locideastruct->iterspersec=iterations / TicksToFracSecs(accumtime); if(locideastruct->adjust==0) |