aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/char/random.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/char/random.c')
-rw-r--r--drivers/char/random.c25
1 files changed, 7 insertions, 18 deletions
diff --git a/drivers/char/random.c b/drivers/char/random.c
index 8258982b49ec..5a1aa64f4e76 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -257,6 +257,7 @@
257#define INPUT_POOL_WORDS 128 257#define INPUT_POOL_WORDS 128
258#define OUTPUT_POOL_WORDS 32 258#define OUTPUT_POOL_WORDS 32
259#define SEC_XFER_SIZE 512 259#define SEC_XFER_SIZE 512
260#define EXTRACT_SIZE 10
260 261
261/* 262/*
262 * The minimum number of bits of entropy before we wake up a read on 263 * The minimum number of bits of entropy before we wake up a read on
@@ -406,15 +407,15 @@ struct entropy_store {
406 struct poolinfo *poolinfo; 407 struct poolinfo *poolinfo;
407 __u32 *pool; 408 __u32 *pool;
408 const char *name; 409 const char *name;
409 int limit;
410 struct entropy_store *pull; 410 struct entropy_store *pull;
411 int limit;
411 412
412 /* read-write data: */ 413 /* read-write data: */
413 spinlock_t lock; 414 spinlock_t lock;
414 unsigned add_ptr; 415 unsigned add_ptr;
415 int entropy_count; 416 int entropy_count;
416 int input_rotate; 417 int input_rotate;
417 __u8 *last_data; 418 __u8 last_data[EXTRACT_SIZE];
418}; 419};
419 420
420static __u32 input_pool_data[INPUT_POOL_WORDS]; 421static __u32 input_pool_data[INPUT_POOL_WORDS];
@@ -714,8 +715,6 @@ void add_disk_randomness(struct gendisk *disk)
714} 715}
715#endif 716#endif
716 717
717#define EXTRACT_SIZE 10
718
719/********************************************************************* 718/*********************************************************************
720 * 719 *
721 * Entropy extraction routines 720 * Entropy extraction routines
@@ -862,7 +861,7 @@ static ssize_t extract_entropy(struct entropy_store *r, void *buf,
862 while (nbytes) { 861 while (nbytes) {
863 extract_buf(r, tmp); 862 extract_buf(r, tmp);
864 863
865 if (r->last_data) { 864 if (fips_enabled) {
866 spin_lock_irqsave(&r->lock, flags); 865 spin_lock_irqsave(&r->lock, flags);
867 if (!memcmp(tmp, r->last_data, EXTRACT_SIZE)) 866 if (!memcmp(tmp, r->last_data, EXTRACT_SIZE))
868 panic("Hardware RNG duplicated output!\n"); 867 panic("Hardware RNG duplicated output!\n");
@@ -951,9 +950,6 @@ static void init_std_data(struct entropy_store *r)
951 now = ktime_get_real(); 950 now = ktime_get_real();
952 mix_pool_bytes(r, &now, sizeof(now)); 951 mix_pool_bytes(r, &now, sizeof(now));
953 mix_pool_bytes(r, utsname(), sizeof(*(utsname()))); 952 mix_pool_bytes(r, utsname(), sizeof(*(utsname())));
954 /* Enable continuous test in fips mode */
955 if (fips_enabled)
956 r->last_data = kmalloc(EXTRACT_SIZE, GFP_KERNEL);
957} 953}
958 954
959static int rand_initialize(void) 955static int rand_initialize(void)
@@ -1051,12 +1047,6 @@ random_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos)
1051 /* like a named pipe */ 1047 /* like a named pipe */
1052 } 1048 }
1053 1049
1054 /*
1055 * If we gave the user some bytes, update the access time.
1056 */
1057 if (count)
1058 file_accessed(file);
1059
1060 return (count ? count : retval); 1050 return (count ? count : retval);
1061} 1051}
1062 1052
@@ -1107,7 +1097,6 @@ static ssize_t random_write(struct file *file, const char __user *buffer,
1107 size_t count, loff_t *ppos) 1097 size_t count, loff_t *ppos)
1108{ 1098{
1109 size_t ret; 1099 size_t ret;
1110 struct inode *inode = file->f_path.dentry->d_inode;
1111 1100
1112 ret = write_pool(&blocking_pool, buffer, count); 1101 ret = write_pool(&blocking_pool, buffer, count);
1113 if (ret) 1102 if (ret)
@@ -1116,8 +1105,6 @@ static ssize_t random_write(struct file *file, const char __user *buffer,
1116 if (ret) 1105 if (ret)
1117 return ret; 1106 return ret;
1118 1107
1119 inode->i_mtime = current_fs_time(inode->i_sb);
1120 mark_inode_dirty(inode);
1121 return (ssize_t)count; 1108 return (ssize_t)count;
1122} 1109}
1123 1110
@@ -1178,6 +1165,7 @@ const struct file_operations random_fops = {
1178 .poll = random_poll, 1165 .poll = random_poll,
1179 .unlocked_ioctl = random_ioctl, 1166 .unlocked_ioctl = random_ioctl,
1180 .fasync = random_fasync, 1167 .fasync = random_fasync,
1168 .llseek = noop_llseek,
1181}; 1169};
1182 1170
1183const struct file_operations urandom_fops = { 1171const struct file_operations urandom_fops = {
@@ -1185,6 +1173,7 @@ const struct file_operations urandom_fops = {
1185 .write = random_write, 1173 .write = random_write,
1186 .unlocked_ioctl = random_ioctl, 1174 .unlocked_ioctl = random_ioctl,
1187 .fasync = random_fasync, 1175 .fasync = random_fasync,
1176 .llseek = noop_llseek,
1188}; 1177};
1189 1178
1190/*************************************************************** 1179/***************************************************************
@@ -1200,7 +1189,7 @@ const struct file_operations urandom_fops = {
1200void generate_random_uuid(unsigned char uuid_out[16]) 1189void generate_random_uuid(unsigned char uuid_out[16])
1201{ 1190{
1202 get_random_bytes(uuid_out, 16); 1191 get_random_bytes(uuid_out, 16);
1203 /* Set UUID version to 4 --- truely random generation */ 1192 /* Set UUID version to 4 --- truly random generation */
1204 uuid_out[6] = (uuid_out[6] & 0x0F) | 0x40; 1193 uuid_out[6] = (uuid_out[6] & 0x0F) | 0x40;
1205 /* Set the UUID variant to DCE */ 1194 /* Set the UUID variant to DCE */
1206 uuid_out[8] = (uuid_out[8] & 0x3F) | 0x80; 1195 uuid_out[8] = (uuid_out[8] & 0x3F) | 0x80;