Add stricter checks for netnames.
[tinc] / src / sptps_speed.c
index d03246c..bde3d69 100644 (file)
@@ -47,11 +47,16 @@ static bool receive_record(void *handle, uint8_t type, const void *data, uint16_
 }
 
 static void receive_data(sptps_t *sptps) {
-       char buf[4096];
+       char buf[4096], *bufp = buf;
        int fd = *(int *)sptps->handle;
        size_t len = recv(fd, buf, sizeof buf, 0);
-       if(!sptps_receive_data(sptps, buf, len))
-               abort();
+       while(len) {
+               size_t done = sptps_receive_data(sptps, bufp, len);
+               if(!done)
+                       abort();
+               bufp += done;
+               len -= done;
+       }
 }
 
 struct timespec start;
@@ -102,19 +107,26 @@ int main(int argc, char *argv[]) {
 
        fprintf(stderr, "Ed25519 sign for %lg seconds: ", duration);
        for(clock_start(); clock_countto(duration);)
-               ecdsa_sign(key1, buf1, 256, buf2);
-       fprintf(stderr, "%22.2lf op/s\n", rate);
+               if(!ecdsa_sign(key1, buf1, 256, buf2))
+                       return 1;
+       fprintf(stderr, "%20.2lf op/s\n", rate);
 
        fprintf(stderr, "Ed25519 verify for %lg seconds: ", duration);
        for(clock_start(); clock_countto(duration);)
-               ecdsa_verify(key1, buf1, 256, buf2);
-       fprintf(stderr, "%20.2lf op/s\n", rate);
+               if(!ecdsa_verify(key1, buf1, 256, buf2)) {
+                       fprintf(stderr, "Signature verification failed\n");
+                       return 1;
+               }
+       fprintf(stderr, "%18.2lf op/s\n", rate);
 
        ecdh1 = ecdh_generate_public(buf1);
        fprintf(stderr, "ECDH for %lg seconds: ", duration);
        for(clock_start(); clock_countto(duration);) {
                ecdh2 = ecdh_generate_public(buf2);
-               ecdh_compute_shared(ecdh2, buf1, buf3);
+               if(!ecdh2)
+                       return 1;
+               if(!ecdh_compute_shared(ecdh2, buf1, buf3))
+                       return 1;
        }
        fprintf(stderr, "%28.2lf op/s\n", rate);
        ecdh_free(ecdh1);