File: _tinysshd-speed.c

package info (click to toggle)
tinyssh 20230101-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 2,244 kB
  • sloc: ansic: 12,106; sh: 1,168; python: 479; makefile: 42
file content (157 lines) | stat: -rw-r--r-- 5,343 bytes parent folder | download | duplicates (3)
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#include <signal.h>
#include <stdio.h>
#include <unistd.h>
#include "crypto.h"
#include "randombytes.h"

static unsigned char sk[2560];
static unsigned char pk[2560];
static unsigned char c[2560];
static unsigned char a[16];
static unsigned char n[8];
static unsigned char k[64];
static unsigned char h[64];
static unsigned char space[10240];
static unsigned char m[51200];
static unsigned char sm[51200];
static unsigned long long smlen;
static unsigned long long mlen;

static int flagtimeout;
static void timeout(int x) {
    flagtimeout = x = 1;
    signal(SIGALRM, timeout);
}

int main(void) {

    long long count;

    signal(SIGALRM, timeout);


#ifdef crypto_hash_sha512_IMPLEMENTATION
    /* sha512 test */
    alarm(1); flagtimeout = 0; count = 0;
    while (!flagtimeout) {
        if (crypto_hash_sha512(h, space, sizeof space) != 0) return 111;
        ++count;
    }
    printf("crypto_hash_sha512: %lld MB/s (%s)\n", count/100, crypto_hash_sha512_IMPLEMENTATION);
#endif

#ifdef crypto_hash_sha256_IMPLEMENTATION
    /* sha256 test */
    alarm(1); flagtimeout = 0; count = 0;
    while (!flagtimeout) {
        if (crypto_hash_sha256(h, space, sizeof space) != 0) return 111;
        ++count;
    }
    printf("crypto_hash_sha256: %lld MB/s (%s)\n", count/100, crypto_hash_sha256_IMPLEMENTATION);
#endif

#ifdef crypto_stream_chacha20_IMPLEMENTATION
	/* chacha20 test */
    alarm(1); flagtimeout = 0; count = 0;
    while (!flagtimeout) {
        if (crypto_stream_chacha20_xor(space, space, sizeof space, n, k) != 0) return 111;
        ++count;
    }
    printf("crypto_stream_chacha20_xor: %lld MB/s (%s)\n", count/100, crypto_stream_chacha20_IMPLEMENTATION);
#endif

#ifdef crypto_onetimeauth_poly1305_IMPLEMENTATION
    /* onetimeauth test */
    alarm(1); flagtimeout = 0; count = 0;
    while (!flagtimeout) {
        if (crypto_onetimeauth_poly1305(a, space, sizeof space, k) != 0) return 111;
        ++count;
    }
    printf("crypto_onetimeauth_poly1305: %lld MB/s (%s)\n", count/100, crypto_onetimeauth_poly1305_IMPLEMENTATION);
#endif

#ifdef crypto_scalarmult_curve25519_IMPLEMENTATION
    /* x25519 test */
	randombytes(sk, crypto_scalarmult_curve25519_SCALARBYTES);
    crypto_scalarmult_curve25519_base(pk, sk);

    alarm(1); flagtimeout = 0; count = 0;
    while (!flagtimeout) {
        if (crypto_scalarmult_curve25519(k, sk, pk) != 0) return 111;
        ++count;
    }
    printf("crypto_scalarmult_curve25519: %lld dh/s (%s)\n", count, crypto_scalarmult_curve25519_IMPLEMENTATION);
#endif

#ifdef crypto_sign_ed25519_IMPLEMENTATION
    /* ed25519 test */
    alarm(1); flagtimeout = 0; count = 0;
    while (!flagtimeout) {
    	if (crypto_sign_ed25519_keypair(pk, sk) != 0) return 111;
		++count;
	}
    printf("crypto_sign_ed25519_keyipair: %lld keypairs/s (%s)\n", count, crypto_sign_ed25519_IMPLEMENTATION);

    alarm(1); flagtimeout = 0; count = 0;
    while (!flagtimeout) {
        if (crypto_sign_ed25519(sm, &smlen, m + crypto_sign_ed25519_BYTES, sizeof(m) - crypto_sign_ed25519_BYTES, sk) != 0) return 111;
        ++count;
    }
    printf("crypto_sign_ed25519: %lld sigs/s (%s)\n", count, crypto_sign_ed25519_IMPLEMENTATION);

    alarm(1); flagtimeout = 0; count = 0;
    while (!flagtimeout) {
        if (crypto_sign_ed25519_open(m, &mlen, sm, sizeof sm, pk) != 0) return 111;
        ++count;
    }
    printf("crypto_sign_ed25519_open: %lld sigs/s (%s)\n", count, crypto_sign_ed25519_IMPLEMENTATION);
#endif

#ifdef crypto_kem_sntrup4591761_IMPLEMENTATION
    alarm(1); flagtimeout = 0; count = 0;
    while (!flagtimeout) {
        if (crypto_kem_sntrup4591761_keypair(pk, sk) != 0) return 111;
        ++count;
    }
    printf("crypto_kem_sntrup4591761_keypair: %lld keypairs/s (%s)\n", count, crypto_kem_sntrup4591761_IMPLEMENTATION);

    alarm(1); flagtimeout = 0; count = 0;
    while (!flagtimeout) {
        if (crypto_kem_sntrup4591761_enc(c, k, pk) != 0) return 111;
        ++count;
    }
    printf("crypto_kem_sntrup4591761_enc: %lld encryptions/s (%s)\n", count, crypto_kem_sntrup4591761_IMPLEMENTATION);

    alarm(1); flagtimeout = 0; count = 0;
    while (!flagtimeout) {
        if (crypto_kem_sntrup4591761_dec(k, c, sk) != 0) return 111;
        ++count;
    }
    printf("crypto_kem_sntrup4591761_dec: %lld decryptions/s (%s)\n", count, crypto_kem_sntrup4591761_IMPLEMENTATION);
#endif

#ifdef crypto_kem_sntrup4591761x25519_IMPLEMENTATION
    alarm(1); flagtimeout = 0; count = 0;
    while (!flagtimeout) {
        if (crypto_kem_sntrup4591761x25519_keypair(pk, sk) != 0) return 111;
        ++count;
    }
    printf("crypto_kem_sntrup4591761x25519_keypair: %lld keypairs/s (%s)\n", count, crypto_kem_sntrup4591761x25519_IMPLEMENTATION);

    alarm(1); flagtimeout = 0; count = 0;
    while (!flagtimeout) {
        if (crypto_kem_sntrup4591761x25519_enc(c, k, pk) != 0) return 111;
        ++count;
    }
    printf("crypto_kem_sntrup4591761x25519_enc: %lld encryptions/s (%s)\n", count, crypto_kem_sntrup4591761x25519_IMPLEMENTATION);

    alarm(1); flagtimeout = 0; count = 0;
    while (!flagtimeout) {
        if (crypto_kem_sntrup4591761x25519_dec(k, c, sk) != 0) return 111;
        ++count;
    }
    printf("crypto_kem_sntrup4591761x25519_dec: %lld decryptions/s (%s)\n", count, crypto_kem_sntrup4591761x25519_IMPLEMENTATION);
#endif

	return 0;
}