aboutsummaryrefslogtreecommitdiff
path: root/modules/benchmark
diff options
context:
space:
mode:
authorLeandro A. F. Pereira <leandro@hardinfo.org>2010-05-03 21:43:07 -0300
committerLeandro A. F. Pereira <leandro@hardinfo.org>2010-05-03 21:56:09 -0300
commit36b1110fc48e3237be1fd658c503cfaae16d6c9c (patch)
treee3c95294377d35fd1a8bce5ef20ac31df18b2f9c /modules/benchmark
parent9273c075a2f993c5154614b70233d8f74515c851 (diff)
Remove outdated arch directory
Diffstat (limited to 'modules/benchmark')
-rw-r--r--modules/benchmark/blowfish.c180
-rw-r--r--modules/benchmark/cryptohash.c2
-rw-r--r--modules/benchmark/drawing.c2
-rw-r--r--modules/benchmark/fft.c6
-rw-r--r--modules/benchmark/fib.c2
-rw-r--r--modules/benchmark/nqueens.c29
-rw-r--r--modules/benchmark/raytrace.c2
7 files changed, 149 insertions, 74 deletions
diff --git a/modules/benchmark/blowfish.c b/modules/benchmark/blowfish.c
index 034315ab..b18b3570 100644
--- a/modules/benchmark/blowfish.c
+++ b/modules/benchmark/blowfish.c
@@ -1,71 +1,73 @@
-/*
-blowfish.c: C implementation of the Blowfish algorithm.
-
-Copyright (C) 1997 by Paul Kocher
-
-This library is free software; you can redistribute it and/or
-modify it under the terms of the GNU Lesser General Public
-License as published by the Free Software Foundation; either
-version 2.1 of the License, or (at your option) any later version.
-This library is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-Lesser General Public License for more details.
-You should have received a copy of the GNU Lesser General Public
-License along with this library; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-
-
-
-COMMENTS ON USING THIS CODE:
-
-Normal usage is as follows:
- [1] Allocate a BLOWFISH_CTX. (It may be too big for the stack.)
- [2] Call Blowfish_Init with a pointer to your BLOWFISH_CTX, a pointer to
- the key, and the number of bytes in the key.
- [3] To encrypt a 64-bit block, call Blowfish_Encrypt with a pointer to
- BLOWFISH_CTX, a pointer to the 32-bit left half of the plaintext
- and a pointer to the 32-bit right half. The plaintext will be
- overwritten with the ciphertext.
- [4] Decryption is the same as encryption except that the plaintext and
- ciphertext are reversed.
-
-Warning #1: The code does not check key lengths. (Caveat encryptor.)
-Warning #2: Beware that Blowfish keys repeat such that "ab" = "abab".
-Warning #3: It is normally a good idea to zeroize the BLOWFISH_CTX before
- freeing it.
-Warning #4: Endianness conversions are the responsibility of the caller.
- (To encrypt bytes on a little-endian platforms, you'll probably want
- to swap bytes around instead of just casting.)
-Warning #5: Make sure to use a reasonable mode of operation for your
- application. (If you don't know what CBC mode is, see Warning #7.)
-Warning #6: This code is susceptible to timing attacks.
-Warning #7: Security engineering is risky and non-intuitive. Have someone
- check your work. If you don't know what you are doing, get help.
-
-
-This is code is fast enough for most applications, but is not optimized for
-speed.
-
-If you require this code under a license other than LGPL, please ask. (I
-can be located using your favorite search engine.) Unfortunately, I do not
-have time to provide unpaid support for everyone who uses this code.
-
- -- Paul Kocher
-*/
-
-#include "blowfish.h"
-
-#define N 16
+/*
+blowfish.c: C implementation of the Blowfish algorithm.
+
+Copyright (C) 1997 by Paul Kocher
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Lesser General Public
+License as published by the Free Software Foundation; either
+version 2.1 of the License, or (at your option) any later version.
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Lesser General Public License for more details.
+You should have received a copy of the GNU Lesser General Public
+License along with this library; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+
+
+
+COMMENTS ON USING THIS CODE:
+
+Normal usage is as follows:
+ [1] Allocate a BLOWFISH_CTX. (It may be too big for the stack.)
+ [2] Call Blowfish_Init with a pointer to your BLOWFISH_CTX, a pointer to
+ the key, and the number of bytes in the key.
+ [3] To encrypt a 64-bit block, call Blowfish_Encrypt with a pointer to
+ BLOWFISH_CTX, a pointer to the 32-bit left half of the plaintext
+ and a pointer to the 32-bit right half. The plaintext will be
+ overwritten with the ciphertext.
+ [4] Decryption is the same as encryption except that the plaintext and
+ ciphertext are reversed.
+
+Warning #1: The code does not check key lengths. (Caveat encryptor.)
+Warning #2: Beware that Blowfish keys repeat such that "ab" = "abab".
+Warning #3: It is normally a good idea to zeroize the BLOWFISH_CTX before
+ freeing it.
+Warning #4: Endianness conversions are the responsibility of the caller.
+ (To encrypt bytes on a little-endian platforms, you'll probably want
+ to swap bytes around instead of just casting.)
+Warning #5: Make sure to use a reasonable mode of operation for your
+ application. (If you don't know what CBC mode is, see Warning #7.)
+Warning #6: This code is susceptible to timing attacks.
+Warning #7: Security engineering is risky and non-intuitive. Have someone
+ check your work. If you don't know what you are doing, get help.
+
+
+This is code is fast enough for most applications, but is not optimized for
+speed.
+
+If you require this code under a license other than LGPL, please ask. (I
+can be located using your favorite search engine.) Unfortunately, I do not
+have time to provide unpaid support for everyone who uses this code.
+
+ -- Paul Kocher
+*/
+
+#include "hardinfo.h"
+#include "benchmark.h"
+#include "blowfish.h"
+
+#define N 16
static const unsigned long ORIG_P[16 + 2] =
{ 0x243F6A88L, 0x85A308D3L, 0x13198A2EL, 0x03707344L, 0xA4093822L,
0x299F31D0L, 0x082EFA98L, 0xEC4E6C89L, 0x452821E6L, 0x38D01377L,
0xBE5466CFL, 0x34E90C6CL, 0xC0AC29B7L,
- 0xC97C50DDL, 0x3F84D5B5L, 0xB5470917L, 0x9216D5D9L, 0x8979FB1BL
+ 0xC97C50DDL, 0x3F84D5B5L, 0xB5470917L, 0x9216D5D9L, 0x8979FB1BL
};
-static const unsigned long ORIG_S[4][256] = {
+static const unsigned long ORIG_S[4][256] = {
{0xD1310BA6L, 0x98DFB5ACL, 0x2FFD72DBL, 0xD01ADFB7L, 0xB8E1AFEDL,
0x6A267E96L, 0xBA7C9045L, 0xF12C7F99L, 0x24A19947L, 0xB3916CF7L,
0x0801F2E2L, 0x858EFC16L, 0x636920D8L, 0x71574E69L, 0xA458FEA3L,
@@ -381,7 +383,7 @@ static const unsigned long ORIG_S[4][256] = {
0x85CBFE4EL, 0x8AE88DD8L, 0x7AAAF9B0L, 0x4CF9AA7EL, 0x1948C25CL,
0x02FB8A8CL, 0x01C36AE4L, 0xD6EBE1F9L, 0x90D4F869L, 0xA65CDEA0L,
0x3F09252DL, 0xC208E69FL, 0xB74E6132L, 0xCE77E25BL, 0x578FDFE3L,
- 0x3AC372E6L}
+ 0x3AC372E6L}
};
static unsigned long F(BLOWFISH_CTX * ctx, unsigned long x)
@@ -438,14 +440,14 @@ void Blowfish_Decrypt(BLOWFISH_CTX * ctx, unsigned long *xl,
for (i = N + 1; i > 1; --i) {
Xl = Xl ^ ctx->P[i];
Xr = F(ctx, Xl) ^ Xr;
-
- /* Exchange Xl and Xr */
+
+ /* Exchange Xl and Xr */
temp = Xl;
Xl = Xr;
Xr = temp;
}
-
- /* Exchange Xl and Xr */
+
+ /* Exchange Xl and Xr */
temp = Xl;
Xl = Xr;
Xr = temp;
@@ -490,4 +492,46 @@ void Blowfish_Init(BLOWFISH_CTX * ctx, unsigned char *key, int keyLen)
}
}
-
+static gpointer
+parallel_blowfish(unsigned int start, unsigned int end, void *data, gint thread_number)
+{
+ BLOWFISH_CTX ctx;
+ unsigned int i;
+ unsigned long L, R;
+
+ L = 0xBEBACAFE;
+ R = 0xDEADBEEF;
+
+ for (i = start; i <= end; i++) {
+ Blowfish_Init(&ctx, (unsigned char*)data, 65536);
+ Blowfish_Encrypt(&ctx, &L, &R);
+ Blowfish_Decrypt(&ctx, &L, &R);
+ }
+
+ return NULL;
+}
+
+void
+benchmark_fish(void)
+{
+ gdouble elapsed = 0;
+ gchar *tmpsrc;
+
+ gchar *bdata_path;
+
+ bdata_path = g_build_filename(params.path_data, "benchmark.data", NULL);
+ if (!g_file_get_contents(bdata_path, &tmpsrc, NULL, NULL)) {
+ g_free(bdata_path);
+ return;
+ }
+
+ shell_view_set_enabled(FALSE);
+ shell_status_update("Performing Blowfish benchmark...");
+
+ elapsed = benchmark_parallel_for(0, 50000, parallel_blowfish, tmpsrc);
+
+ g_free(bdata_path);
+ g_free(tmpsrc);
+
+ bench_results[BENCHMARK_BLOWFISH] = elapsed;
+}
diff --git a/modules/benchmark/cryptohash.c b/modules/benchmark/cryptohash.c
index 99a19140..d97e85c7 100644
--- a/modules/benchmark/cryptohash.c
+++ b/modules/benchmark/cryptohash.c
@@ -55,7 +55,7 @@ static gpointer cryptohash_for(unsigned int start, unsigned int end, void *data,
return NULL;
}
-static void
+void
benchmark_cryptohash(void)
{
gdouble elapsed = 0;
diff --git a/modules/benchmark/drawing.c b/modules/benchmark/drawing.c
index 6f01fe6b..67a2c264 100644
--- a/modules/benchmark/drawing.c
+++ b/modules/benchmark/drawing.c
@@ -19,7 +19,7 @@
#include "benchmark.h"
#include "guibench.h"
-static void
+void
benchmark_gui(void)
{
shell_view_set_enabled(FALSE);
diff --git a/modules/benchmark/fft.c b/modules/benchmark/fft.c
index f1a0ced8..7c5889c8 100644
--- a/modules/benchmark/fft.c
+++ b/modules/benchmark/fft.c
@@ -16,7 +16,9 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#include <fftbench.h>
+#include "hardinfo.h"
+#include "benchmark.h"
+#include "fftbench.h"
static gpointer fft_for(unsigned int start, unsigned int end, void *data, gint thread_number)
{
@@ -31,7 +33,7 @@ static gpointer fft_for(unsigned int start, unsigned int end, void *data, gint t
return NULL;
}
-static void
+void
benchmark_fft(void)
{
gdouble elapsed = 0;
diff --git a/modules/benchmark/fib.c b/modules/benchmark/fib.c
index 3ff54dba..0f88be59 100644
--- a/modules/benchmark/fib.c
+++ b/modules/benchmark/fib.c
@@ -28,7 +28,7 @@ fib(gulong n)
return fib(n - 1) + fib(n - 2);
}
-static void
+void
benchmark_fib(void)
{
GTimer *timer = g_timer_new();
diff --git a/modules/benchmark/nqueens.c b/modules/benchmark/nqueens.c
index 838731c4..a32ed8c1 100644
--- a/modules/benchmark/nqueens.c
+++ b/modules/benchmark/nqueens.c
@@ -6,6 +6,9 @@
#include <stdbool.h>
#include <stdlib.h>
+#include "hardinfo.h"
+#include "benchmark.h"
+
#define QUEENS 11
int row[QUEENS];
@@ -35,3 +38,29 @@ int nqueens(int y)
return 0;
}
+
+static gpointer nqueens_for(unsigned int start, unsigned int end, void *data, gint thread_number)
+{
+ unsigned int i;
+
+ for (i = start; i <= end; i++) {
+ nqueens(0);
+ }
+
+ return NULL;
+}
+
+void
+benchmark_nqueens(void)
+{
+ gdouble elapsed = 0;
+
+ shell_view_set_enabled(FALSE);
+ shell_status_update("Running N-Queens benchmark...");
+
+ elapsed = benchmark_parallel_for(0, 10, nqueens_for, NULL);
+
+ bench_results[BENCHMARK_NQUEENS] = elapsed;
+}
+
+
diff --git a/modules/benchmark/raytrace.c b/modules/benchmark/raytrace.c
index 9fc6361e..2ee36a93 100644
--- a/modules/benchmark/raytrace.c
+++ b/modules/benchmark/raytrace.c
@@ -32,7 +32,7 @@ parallel_raytrace(unsigned int start, unsigned int end, gpointer data, gint thre
return NULL;
}
-static void
+void
benchmark_raytrace(void)
{
gdouble elapsed = 0;