|
@@ -0,0 +1,72 @@
|
|
1
|
+/*
|
|
2
|
+ * CSA functions
|
|
3
|
+ * Copyright (C) 2011-2012 Unix Solutions Ltd.
|
|
4
|
+ *
|
|
5
|
+ * This program is free software; you can redistribute it and/or modify
|
|
6
|
+ * it under the terms of the GNU General Public License version 2
|
|
7
|
+ * as published by the Free Software Foundation.
|
|
8
|
+ *
|
|
9
|
+ * This program is distributed in the hope that it will be useful,
|
|
10
|
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
+ * GNU General Public License for more details.
|
|
13
|
+ *
|
|
14
|
+ * You should have received a copy of the GNU General Public License
|
|
15
|
+ * along with this program; if not, write to the Free Software
|
|
16
|
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
|
|
17
|
+ */
|
|
18
|
+
|
|
19
|
+#include <stdio.h>
|
|
20
|
+#include <stdlib.h>
|
|
21
|
+#include <string.h>
|
|
22
|
+#include <inttypes.h>
|
|
23
|
+#include <sys/time.h>
|
|
24
|
+
|
|
25
|
+#include <dvbcsa/dvbcsa.h>
|
|
26
|
+
|
|
27
|
+#include "libfuncs/libfuncs.h"
|
|
28
|
+
|
|
29
|
+/* The following routine is taken from benchbitslice in libdvbcsa */
|
|
30
|
+void csa_benchmark(void) {
|
|
31
|
+ struct timeval t0, t1;
|
|
32
|
+ struct dvbcsa_bs_key_s *key = dvbcsa_bs_key_alloc();
|
|
33
|
+ unsigned int n, i, npackets = 0;
|
|
34
|
+ unsigned int batch_size = dvbcsa_bs_batch_size();
|
|
35
|
+ uint8_t data[batch_size + 1][188];
|
|
36
|
+ struct dvbcsa_bs_batch_s pcks[batch_size + 1];
|
|
37
|
+ uint8_t cw[8] = { 0x12, 0x34, 0x56, 0x78, 0x89, 0xab, 0xcd, 0xef, };
|
|
38
|
+
|
|
39
|
+ srand(time(0));
|
|
40
|
+ puts("Single threaded CSA decoding benchmark");
|
|
41
|
+
|
|
42
|
+ dvbcsa_bs_key_set (cw, key);
|
|
43
|
+
|
|
44
|
+ printf("Batch size %d packets.\n\n", batch_size);
|
|
45
|
+ for (i = 0; i < batch_size; i++) {
|
|
46
|
+ pcks[i].data = data[i];
|
|
47
|
+ pcks[i].len = 184;
|
|
48
|
+ memset(data[i], rand(), pcks[i].len);
|
|
49
|
+ }
|
|
50
|
+ pcks[i].data = NULL;
|
|
51
|
+
|
|
52
|
+ gettimeofday(&t0, NULL);
|
|
53
|
+ for (n = (1 << 12) / batch_size; n < (1 << 19) / batch_size; n *= 2) {
|
|
54
|
+ printf(" Decrypting %6u mpegts packets\r", n * batch_size);
|
|
55
|
+ fflush(stdout);
|
|
56
|
+ for (i = 0; i < n; i++) {
|
|
57
|
+ dvbcsa_bs_decrypt(key, pcks, 184);
|
|
58
|
+ }
|
|
59
|
+ npackets += n * batch_size;
|
|
60
|
+ }
|
|
61
|
+ gettimeofday(&t1, NULL);
|
|
62
|
+
|
|
63
|
+ unsigned long long usec = timeval_diff_usec(&t0, &t1);
|
|
64
|
+ printf("DONE: %u packets (%u bytes) decrypted in %llu ms = %.1f Mbits/s\n\n",
|
|
65
|
+ npackets,
|
|
66
|
+ npackets * 188,
|
|
67
|
+ usec / 1000,
|
|
68
|
+ (double)(npackets * 188 * 8) / (double)usec
|
|
69
|
+ );
|
|
70
|
+
|
|
71
|
+ dvbcsa_bs_key_free(key);
|
|
72
|
+}
|