summaryrefslogtreecommitdiffstats
path: root/tests/ncr.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ncr.c')
-rw-r--r--tests/ncr.c34
1 files changed, 21 insertions, 13 deletions
diff --git a/tests/ncr.c b/tests/ncr.c
index 207a233..362cdaa 100644
--- a/tests/ncr.c
+++ b/tests/ncr.c
@@ -96,14 +96,17 @@ struct hash_vectors_st {
#define HASH_DATA_SIZE 64
/* SHA1 and other hashes */
-static int test_ncr_hash()
+static int test_ncr_hash(int with_accept)
{
uint8_t data[HASH_DATA_SIZE];
int i, j;
ssize_t data_size;
/* convert it to key */
- fprintf(stdout, "Tests on Hashes\n");
+ if (with_accept)
+ fprintf(stdout, "Tests on Hashes with accept()\n");
+ else
+ fprintf(stdout, "Tests on Hashes without accept()\n");
for (i = 0; i < sizeof(hash_vectors) / sizeof(hash_vectors[0]); i++) {
struct sockaddr_alg salg;
int fd, hfd;
@@ -124,18 +127,21 @@ static int test_ncr_hash()
return 1;
}
- if (listen(fd, 1) != 0) {
- perror("listen()");
- return 1;
- }
+ if (with_accept) {
+ if (listen(fd, 1) != 0) {
+ perror("listen()");
+ return 1;
+ }
- hfd = accept(fd, NULL, NULL);
- if (hfd < 0) {
- perror("accept()");
- return 1;
- }
+ hfd = accept(fd, NULL, NULL);
+ if (hfd < 0) {
+ perror("accept()");
+ return 1;
+ }
- close(fd);
+ close(fd);
+ } else
+ hfd = fd;
errno = 0;
if (write(hfd, hash_vectors[i].plaintext,
@@ -182,7 +188,9 @@ static int test_ncr_hash()
int main()
{
- if (test_ncr_hash())
+ if (test_ncr_hash(0))
+ return 1;
+ if (test_ncr_hash(1))
return 1;
return 0;