ia64/xen-unstable

view tools/vnet/vnet-module/random.c @ 6946:e703abaf6e3d

Add behaviour to the remove methods to remove the transaction's path itself. This allows us to write Remove(path) to remove the specified path rather than having to slice the path ourselves.
author emellor@ewan
date Sun Sep 18 14:42:13 2005 +0100 (2005-09-18)
parents 0a4b76b6b5a0
children 71b0f00f6344
line source
1 /*
2 * Copyright (C) 2004 Mike Wray <mike.wray@hp.com>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free software Foundation, Inc.,
16 * 59 Temple Place, suite 330, Boston, MA 02111-1307 USA
17 *
18 */
19 #include <linux/config.h>
20 #include <linux/module.h>
21 #include <linux/init.h>
22 #include <linux/sched.h>
23 #include <linux/random.h>
25 #include "hash_table.h"
27 #define MODULE_NAME "RANDOM"
28 #define DEBUG 1
29 #undef DEBUG
30 #include "debug.h"
32 /** @file
33 * Source of randomness.
34 * Current implementation is not enough.
35 * Needs to be cryptographically strong.
36 */
38 static unsigned long seed = 0;
39 static unsigned long count = 0;
41 static unsigned long stir(unsigned long *a, unsigned long b){
42 pseudo_des(a, &b);
43 return b;
44 }
46 /** Get one random byte.
47 *
48 * @return random byte
49 */
50 int get_random_byte(void){
51 return stir(&seed, ++count);
52 }
54 #if 0
55 /* Get some random bytes.
56 *
57 * @param dst destination for the bytes
58 * @param dst_n number of bytes to get
59 */
60 void get_random_bytes(void *dst, int dst_n){
61 int i;
62 char *p = (char *)dst;
63 for(i = 0; i < dst_n; i++){
64 *p++ = get_random_byte();
65 }
66 }
67 #endif
69 /** Contribute a random byte.
70 *
71 * @param b byte to contribute
72 */
73 void add_random_byte(int b){
74 stir(&seed, ++count);
75 stir(&seed, b);
76 }
78 /** Contribute some random bytes.
79 *
80 * @param src bytes to contribute
81 * @param src_n number of bytes
82 */
83 void add_random_bytes(const void *src, int src_n){
84 int i;
85 char *p = (char *)src;
86 for(i = 0; i < src_n; i++){
87 add_random_byte(*p++);
88 }
89 }
91 int __init random_module_init(void){
92 int dummy;
93 int tmp = jiffies;
94 seed = (unsigned long)&dummy;
95 add_random_byte(tmp);
96 return 0;
97 }
99 void __exit random_module_exit(void){
100 }