#include #include #include #include #include #include #include #include int main(void) { int opfd; int tfmfd; struct sockaddr_alg sa = { .salg_family = AF_ALG, .salg_type = "hash", .salg_name = "sha1" }; char *buf2; char buf[20]; int i; struct stat st; ssize_t size; tfmfd = socket(AF_ALG, SOCK_SEQPACKET, 0); bind(tfmfd, (struct sockaddr *)&sa, sizeof(sa)); opfd = accept(tfmfd, NULL, 0); int t = open("/bin/true", O_RDONLY); fstat(t, &st); size = sendfile(opfd, t, NULL, st.st_size); if (size != st.st_size) exit(1); read(opfd, &buf, 20); for (i = 0; i < 20; i++) { printf("%02x", (unsigned char)buf[i]); } printf("\n"); lseek(t, 0, SEEK_SET); buf2 = malloc(st.st_size + 1); read(t, buf2, st.st_size); write(opfd, buf2, st.st_size); read(opfd, &buf, 20); for (i = 0; i < 20; i++) { printf("%02x", (unsigned char)buf[i]); } printf("\n"); close(opfd); close(tfmfd); return 0; }