Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src add randomid(3).



details:   https://anonhg.NetBSD.org/src/rev/0c0fd4d9e7cc
branches:  trunk
changeset: 551645:0c0fd4d9e7cc
user:      itojun <itojun%NetBSD.org@localhost>
date:      Tue Sep 09 22:10:33 2003 +0000

description:
add randomid(3).

diffstat:

 distrib/sets/lists/comp/mi |    9 +-
 include/Makefile           |    4 +-
 include/randomid.h         |   83 ++++++++++++
 lib/libc/gen/Makefile.inc  |    7 +-
 lib/libc/gen/randomid.3    |  145 ++++++++++++++++++++
 lib/libc/gen/randomid.c    |  311 +++++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 553 insertions(+), 6 deletions(-)

diffs (truncated from 641 to 300 lines):

diff -r c5f5bb4e13c3 -r 0c0fd4d9e7cc distrib/sets/lists/comp/mi
--- a/distrib/sets/lists/comp/mi        Tue Sep 09 22:05:38 2003 +0000
+++ b/distrib/sets/lists/comp/mi        Tue Sep 09 22:10:33 2003 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: mi,v 1.614 2003/09/09 22:01:57 itojun Exp $
+#      $NetBSD: mi,v 1.615 2003/09/09 22:10:33 itojun Exp $
 ./usr/bin/addr2line            comp-debug-bin
 ./usr/bin/ar                   comp-util-bin
 ./usr/bin/as                   comp-util-bin
@@ -633,6 +633,7 @@
 ./usr/include/pthread_queue.h          comp-c-include
 ./usr/include/pthread_types.h          comp-c-include
 ./usr/include/pwd.h                    comp-c-include
+./usr/include/randomid.h               comp-c-include
 ./usr/include/ranlib.h                 comp-c-include
 ./usr/include/re_comp.h                        comp-c-include
 ./usr/include/readline                 comp-c-include
@@ -3073,6 +3074,9 @@
 ./usr/share/man/cat3/rand48.0  comp-c-catman
 ./usr/share/man/cat3/rand_r.0  comp-c-catman
 ./usr/share/man/cat3/random.0  comp-c-catman
+./usr/share/man/cat3/randomid.0                comp-c-catman
+./usr/share/man/cat3/randomid_delete.0         comp-c-catman
+./usr/share/man/cat3/randomid_new.0            comp-c-catman
 ./usr/share/man/cat3/raw.0             comp-c-catman
 ./usr/share/man/cat3/rcmd.0    comp-c-catman
 ./usr/share/man/cat3/rcmd_af.0 comp-c-catman
@@ -6524,6 +6528,9 @@
 ./usr/share/man/man3/rand48.3          comp-c-man
 ./usr/share/man/man3/rand_r.3          comp-c-man
 ./usr/share/man/man3/random.3          comp-c-man
+./usr/share/man/man3/randomid.3                comp-c-man
+./usr/share/man/man3/randomid_delete.3         comp-c-man
+./usr/share/man/man3/randomid_new.3            comp-c-man
 ./usr/share/man/man3/raw.3             comp-c-man
 ./usr/share/man/man3/rcmd.3            comp-c-man
 ./usr/share/man/man3/rcmd_af.3         comp-c-man
diff -r c5f5bb4e13c3 -r 0c0fd4d9e7cc include/Makefile
--- a/include/Makefile  Tue Sep 09 22:05:38 2003 +0000
+++ b/include/Makefile  Tue Sep 09 22:10:33 2003 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.112 2003/08/27 16:03:18 mrg Exp $
+#      $NetBSD: Makefile,v 1.113 2003/09/09 22:10:33 itojun Exp $
 #      @(#)Makefile    8.2 (Berkeley) 1/4/94
 
 # Doing a make includes builds /usr/include
@@ -15,7 +15,7 @@
        login_cap.h lwp.h malloc.h math.h md2.h md4.h md5.h \
        memory.h mntopts.h mpool.h \
        ndbm.h netconfig.h netdb.h netgroup.h nlist.h nl_types.h \
-       nsswitch.h paths.h pwd.h ranlib.h re_comp.h regex.h regexp.h \
+       nsswitch.h paths.h pwd.h randomid.h ranlib.h re_comp.h regex.h regexp.h \
        resolv.h rmd160.h rmt.h sa.h sched.h search.h semaphore.h setjmp.h \
        sgtty.h sha1.h signal.h stab.h stddef.h stdio.h stdlib.h string.h \
        strings.h stringlist.h struct.h sysexits.h tar.h threadlib.h time.h \
diff -r c5f5bb4e13c3 -r 0c0fd4d9e7cc include/randomid.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/include/randomid.h        Tue Sep 09 22:10:33 2003 +0000
@@ -0,0 +1,83 @@
+/*     $NetBSD: randomid.h,v 1.1 2003/09/09 22:10:33 itojun Exp $      */
+/*     $KAME: ip6_id.c,v 1.8 2003/09/06 13:41:06 itojun Exp $  */
+/*     $OpenBSD: ip_id.c,v 1.6 2002/03/15 18:19:52 millert Exp $       */
+
+/*
+ * Copyright (C) 2003 WIDE Project.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the project nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * Copyright 1998 Niels Provos <provos%citi.umich.edu@localhost>
+ * All rights reserved.
+ *
+ * Theo de Raadt <deraadt%openbsd.org@localhost> came up with the idea of using
+ * such a mathematical system to generate more random (yet non-repeating)
+ * ids to solve the resolver/named problem.  But Niels designed the
+ * actual system based on the constraints.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *      This product includes software developed by Niels Provos.
+ * 4. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _RANDOMID_H_
+#define _RANDOMID_H_
+
+struct randomid_ctx;
+
+typedef struct randomid_ctx *randomid_t;
+
+extern u_int32_t randomid(randomid_t);
+extern randomid_t randomid_new(int, long);
+extern void randomid_delete(randomid_t);
+
+#define RANDOMID_TIMEO_MIN     ((long)60)
+#define RANDOMID_TIMEO_DEFAULT ((long)180)
+
+#endif /*_RANDOMID_H_*/
diff -r c5f5bb4e13c3 -r 0c0fd4d9e7cc lib/libc/gen/Makefile.inc
--- a/lib/libc/gen/Makefile.inc Tue Sep 09 22:05:38 2003 +0000
+++ b/lib/libc/gen/Makefile.inc Tue Sep 09 22:10:33 2003 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile.inc,v 1.123 2003/09/09 22:01:56 itojun Exp $
+#      $NetBSD: Makefile.inc,v 1.124 2003/09/09 22:10:34 itojun Exp $
 #      from: @(#)Makefile.inc  8.6 (Berkeley) 5/4/95
 
 # gen sources
@@ -16,7 +16,7 @@
        isascii.c isatty.c isctype.c lockf.c nice.c nlist.c nlist_aout.c \
        nlist_coff.c nlist_ecoff.c nlist_elf32.c nlist_elf64.c opendir.c \
        pause.c popen.c psignal.c pthread_atfork.c pwcache.c pw_scan.c \
-       pw_dup.c raise.c readdir.c rewinddir.c \
+       pw_dup.c raise.c randomid.c readdir.c rewinddir.c \
        scandir.c seekdir.c setdomainname.c \
        sethostname.c setjmperr.c setmode.c setproctitle.c setprogname.c \
        shquote.c shquotev.c sighold.c sigignore.c siginterrupt.c \
@@ -53,7 +53,7 @@
        _lwp_makecontext.3 makecontext.3 \
        modf.3 nice.3 nlist.3 \
        pause.3 popen.3 psignal.3 pw_dup.3 pwcache.3 pthread_atfork.3 \
-       raise.3 realpath.3 scandir.3 setjmp.3 setmode.3 \
+       raise.3 randomid.3 realpath.3 scandir.3 setjmp.3 setmode.3 \
        setproctitle.3 shquote.3 sighold.3 sigignore.3 siginterrupt.3 \
        signal.3 sigrelse.3 sigset.3 sigsetops.3 sleep.3 \
        stringlist.3 sysconf.3 sysctl.3 syslog.3 time.3 times.3 \
@@ -107,6 +107,7 @@
 MLINKS+=pwcache.3 user_from_uid.3 pwcache.3 group_from_gid.3
 MLINKS+=pwcache.3 uid_from_user.3 pwcache.3 gid_from_group.3
 MLINKS+=pwcache.3 pwcache_userdb.3 pwcache.3 pwcache_groupdb.3
+MLINKS+=randomid.3 randomid_new.3 randomid.3 randomid_delete.3
 MLINKS+=scandir.3 alphasort.3
 MLINKS+=setjmp.3 _longjmp.3 setjmp.3 _setjmp.3 setjmp.3 longjmp.3 \
        setjmp.3 longjmperror.3 setjmp.3 sigsetjmp.3 setjmp.3 siglongjmp.3
diff -r c5f5bb4e13c3 -r 0c0fd4d9e7cc lib/libc/gen/randomid.3
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/libc/gen/randomid.3   Tue Sep 09 22:10:33 2003 +0000
@@ -0,0 +1,145 @@
+.\"    $NetBSD: randomid.3,v 1.1 2003/09/09 22:10:34 itojun Exp $
+.\"
+.\" Copyright (C) 2003 WIDE Project.
+.\" All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice, this list of conditions and the following disclaimer in the
+.\"    documentation and/or other materials provided with the distribution.
+.\" 3. Neither the name of the project nor the names of its contributors
+.\"    may be used to endorse or promote products derived from this software
+.\"    without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.Dd September 9, 2003
+.Dt RANDOMID 3
+.Os
+.Sh NAME
+.Nm randomid
+.Nm randomid_new ,
+.Nm randomid_delete ,
+.Nd make a copy of a struct passwd
+.Sh SYNOPSIS
+.Fd #include <sys/types.h>
+.Fd #include <randomid.h>
+.Ft u_int32_t
+.Fn randomid "randomid_t ctx"
+.Ft randomid_t
+.Fn randomid_new "int bits" "long timeo"
+.Ft void
+.Fn randomid_delete "randomid_t ctx"
+.Sh DESCRIPTION
+The
+.Fn randomid
+function provides pseudo-random data stream,
+which is guaranteed not to generate the same number twice during
+a certain duration.
+.Fa ctx
+is the context which holds internal state for the random number generator.
+.Pp
+To initialize context
+.Fa randomid_new
+is used.
+.Fa bits
+specifies the bitwidth of value generated by
+.Fn randomid .
+Currently 32, 20 and 16 are supported.
+.Fa timeo
+specifies reinitialization interval in seconds.
+.Fa timeo
+has to be bigger than
+.Dv RANDOMID_TIMEO_MIN .
+Return value of
+.Fa randomid_new
+is a dynamically-allocated memory region allocated by
+.Xr malloc 3 .
+.Pp
+.Fn randomid_delete
+will
+.Xr free 3
+the internal state,
+.Fa ctx .
+.Pp
+Same number may appear after two reinitialization events of the internal state,
+.Fa ctx .
+Reinitialization happens when the random number generator cycle is exhausted,
+or
+.Fa timeo
+seconds have passed since the last reinitialization.
+For instance,
+.Fa ctx
+configured to generate 16 bit data stream will reinitialize its internal state
+every 18000 calls to
+.Fn randomid
+.Po
+or after
+.Fa timeo
+seconds
+.Pc ,
+therefore same data will not appear until after 36000 calls to
+.Fn randomid
+.Po
+or after 2 times
+.Fa timeo
+seconds
+.Pc .
+.Pp
+The internal state,
+.Fa ctx ,
+determines the data stream generated by
+.Fn randomid .
+.Fa ctx
+must be allocated per data stream
+.Pq such as a specific data field .
+It must not be shared among multiple data streams with different usage.
+.\"
+.Sh EXAMPLES
+.Bd -literal -offset indent
+#include <sys/types.h>
+#include <randomid.h>
+
+u_int32_t
+genid(void)
+{



Home | Main Index | Thread Index | Old Index