Subject: Re: rpc xid randomness
To: None <fvdl@netbsd.org>
From: Jun-ichiro itojun Hagino <itojun@itojun.org>
List: tech-security
Date: 09/09/2003 06:45:00
--NextPart-20030909064351-2189102
Content-Type: Text/Plain; charset=us-ascii

> > itojun[starfruit:/tmp] ./a.out 
> > begin: 1063056924.00613695
> > 
> > end: 1063056925.00897448
> > diff: 1.00283753
> 
> I meant: a comparison between the old and new code..

itojun[starfruit:/tmp] ./a.out 
new code
begin: 1063057405.00587237

end: 1063057406.00869681
diff: 1.00282444

old code
begin: 1063057406.00879029

end: 1063057406.00959380
diff: 0.00080351

itojun[starfruit:/tmp] ./a.out
new code
begin: 1063057463.00650768

end: 1063057464.00922268
diff: 1.00271500

old code
begin: 1063057464.00931389

end: 1063057465.00010380
diff: 0.00078991

	note that the frequency of the code being called is not high.

itojun

--NextPart-20030909064351-2189102
Content-Type: Text/Plain; charset=us-ascii
Content-Disposition: attachment; filename="hoge.c"

#include <sys/types.h>
#include <sys/time.h>
#include <stdio.h>

int
main()
{
	int i;
	struct timeval tv1, tv2, tv;
	u_int32_t x;

	fprintf(stderr, "new code\n");
	gettimeofday(&tv1, NULL);
	fprintf(stderr, "begin: %ld.%08ld\n", tv1.tv_sec, tv1.tv_usec);
	for (i = 0; i < 65536; i++) {
		x = __rpc_getxid();
	}
	printf("\n");
	gettimeofday(&tv2, NULL);
	fprintf(stderr, "end: %ld.%08ld\n", tv2.tv_sec, tv2.tv_usec);

	tv.tv_sec = tv2.tv_sec - tv1.tv_sec;
	tv.tv_usec = tv2.tv_usec - tv1.tv_usec;
	if (tv.tv_usec < 0) {
		tv.tv_sec--;
		tv.tv_usec += 1000000;
	}
	fprintf(stderr, "diff: %ld.%08ld\n", tv.tv_sec, tv.tv_usec);

	fprintf(stderr, "\n");
	fprintf(stderr, "old code\n");
	gettimeofday(&tv1, NULL);
	fprintf(stderr, "begin: %ld.%08ld\n", tv1.tv_sec, tv1.tv_usec);
	for (i = 0; i < 65536; i++) {
		gettimeofday(&tv, NULL);
		x = (u_int32_t)getpid() ^ (u_int32_t)tv.tv_sec ^ (u_int32_t)tv.tv_usec;
	}
	printf("\n");
	gettimeofday(&tv2, NULL);
	fprintf(stderr, "end: %ld.%08ld\n", tv2.tv_sec, tv2.tv_usec);

	tv.tv_sec = tv2.tv_sec - tv1.tv_sec;
	tv.tv_usec = tv2.tv_usec - tv1.tv_usec;
	if (tv.tv_usec < 0) {
		tv.tv_sec--;
		tv.tv_usec += 1000000;
	}
	fprintf(stderr, "diff: %ld.%08ld\n", tv.tv_sec, tv.tv_usec);
}

--NextPart-20030909064351-2189102--