Commit 73e6d512fe1547292b5df4405a27e2fe727a253b

Authored by Georg Hopp
1 parent 52ce40ac

Make digest handling more optimizer save by using a union

Showing 2 changed files with 24 additions and 14 deletions
@@ -16,5 +16,12 @@ coverage-html: @@ -16,5 +16,12 @@ coverage-html:
16 -$(MAKE) -C tests $(AM_MAKEFLAGS) -k $@ 16 -$(MAKE) -C tests $(AM_MAKEFLAGS) -k $@
17 endif 17 endif
18 18
  19 +REGEX_CCLASS=/^[ \t]*\(TR_CLASS\|TR_INTERFACE\)\(([a-zA-Z0-9_]+)/\2/d,definition/
19 tags: 20 tags:
20 - ctags -R -V --langdef=cclass --langmap=cclass:.h --regex-cclass='/^[ \t]*\(TR_CLASS\|TR_INTERFACE\)\(([a-zA-Z0-9_]+)/\2/d,definition/' 21 + @ctags -R -V --langdef=cclass --langmap=cclass:.h \
  22 + --regex-cclass='$(REGEX_CCLASS)'
  23 +
  24 +loc:
  25 + @find src/ include/ -not -path testers -and -name "*.[ch]" \
  26 + -exec sed '/\/\*/,/\*\//d;/\/\//d' {} \; | wc -l
  27 +
@@ -37,7 +37,10 @@ int @@ -37,7 +37,10 @@ int
37 main(int argc, char * argv []) 37 main(int argc, char * argv [])
38 { 38 {
39 unsigned char data[16384]; 39 unsigned char data[16384];
40 - unsigned char digest[20]; 40 + union {
  41 + unsigned char bytes[20];
  42 + uint32_t ints[5];
  43 + } digest;
41 size_t got; 44 size_t got;
42 int i; 45 int i;
43 clock_t start, stop; 46 clock_t start, stop;
@@ -56,16 +59,16 @@ main(int argc, char * argv []) @@ -56,16 +59,16 @@ main(int argc, char * argv [])
56 59
57 SHA1_Init(&ctx); 60 SHA1_Init(&ctx);
58 SHA1_Update(&ctx, data, got); 61 SHA1_Update(&ctx, data, got);
59 - SHA1_Final(digest, &ctx); 62 + SHA1_Final(digest.bytes, &ctx);
60 } 63 }
61 stop = clock(); 64 stop = clock();
62 printf( 65 printf(
63 "done\nResult: %08x%08x%08x%08x%08x\n", 66 "done\nResult: %08x%08x%08x%08x%08x\n",
64 - htonl(((uint32_t *)&digest)[0]),  
65 - htonl(((uint32_t *)&digest)[1]),  
66 - htonl(((uint32_t *)&digest)[2]),  
67 - htonl(((uint32_t *)&digest)[3]),  
68 - htonl(((uint32_t *)&digest)[4])); 67 + htonl(digest.ints[0]),
  68 + htonl(digest.ints[1]),
  69 + htonl(digest.ints[2]),
  70 + htonl(digest.ints[3]),
  71 + htonl(digest.ints[4]));
69 printf("CPU time OpenSSL: %f\n", 72 printf("CPU time OpenSSL: %f\n",
70 (double)(stop - start) / CLOCKS_PER_SEC); 73 (double)(stop - start) / CLOCKS_PER_SEC);
71 74
@@ -78,16 +81,16 @@ main(int argc, char * argv []) @@ -78,16 +81,16 @@ main(int argc, char * argv [])
78 81
79 TR_SHA1_Init(&ctx); 82 TR_SHA1_Init(&ctx);
80 TR_SHA1_Update(&ctx, data, got); 83 TR_SHA1_Update(&ctx, data, got);
81 - TR_SHA1_Final(digest, &ctx); 84 + TR_SHA1_Final(digest.bytes, &ctx);
82 } 85 }
83 stop = clock(); 86 stop = clock();
84 printf( 87 printf(
85 "Done\nResult: %08x%08x%08x%08x%08x\n", 88 "Done\nResult: %08x%08x%08x%08x%08x\n",
86 - htonl(((uint32_t *)&digest)[0]),  
87 - htonl(((uint32_t *)&digest)[1]),  
88 - htonl(((uint32_t *)&digest)[2]),  
89 - htonl(((uint32_t *)&digest)[3]),  
90 - htonl(((uint32_t *)&digest)[4])); 89 + htonl(digest.ints[0]),
  90 + htonl(digest.ints[1]),
  91 + htonl(digest.ints[2]),
  92 + htonl(digest.ints[3]),
  93 + htonl(digest.ints[4]));
91 printf("CPU time Ours: %f\n", (double)(stop - start) / CLOCKS_PER_SEC); 94 printf("CPU time Ours: %f\n", (double)(stop - start) / CLOCKS_PER_SEC);
92 95
93 return 0; 96 return 0;
Please register or login to post a comment