]> git.karo-electronics.de Git - karo-tx-linux.git/blobdiff - drivers/char/random.c
random: simplify fips mode
[karo-tx-linux.git] / drivers / char / random.c
index 8258982b49ec3ab1551416ccd8e558d2f1c5e6df..8d85587b6d4f3a9693663b007b9a0778ea4d1e00 100644 (file)
 #define INPUT_POOL_WORDS 128
 #define OUTPUT_POOL_WORDS 32
 #define SEC_XFER_SIZE 512
+#define EXTRACT_SIZE 10
 
 /*
  * The minimum number of bits of entropy before we wake up a read on
@@ -414,7 +415,7 @@ struct entropy_store {
        unsigned add_ptr;
        int entropy_count;
        int input_rotate;
-       __u8 *last_data;
+       __u8 last_data[EXTRACT_SIZE];
 };
 
 static __u32 input_pool_data[INPUT_POOL_WORDS];
@@ -714,8 +715,6 @@ void add_disk_randomness(struct gendisk *disk)
 }
 #endif
 
-#define EXTRACT_SIZE 10
-
 /*********************************************************************
  *
  * Entropy extraction routines
@@ -862,7 +861,7 @@ static ssize_t extract_entropy(struct entropy_store *r, void *buf,
        while (nbytes) {
                extract_buf(r, tmp);
 
-               if (r->last_data) {
+               if (fips_enabled) {
                        spin_lock_irqsave(&r->lock, flags);
                        if (!memcmp(tmp, r->last_data, EXTRACT_SIZE))
                                panic("Hardware RNG duplicated output!\n");
@@ -951,9 +950,6 @@ static void init_std_data(struct entropy_store *r)
        now = ktime_get_real();
        mix_pool_bytes(r, &now, sizeof(now));
        mix_pool_bytes(r, utsname(), sizeof(*(utsname())));
-       /* Enable continuous test in fips mode */
-       if (fips_enabled)
-               r->last_data = kmalloc(EXTRACT_SIZE, GFP_KERNEL);
 }
 
 static int rand_initialize(void)
@@ -1051,12 +1047,6 @@ random_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos)
                                /* like a named pipe */
        }
 
-       /*
-        * If we gave the user some bytes, update the access time.
-        */
-       if (count)
-               file_accessed(file);
-
        return (count ? count : retval);
 }
 
@@ -1107,7 +1097,6 @@ static ssize_t random_write(struct file *file, const char __user *buffer,
                            size_t count, loff_t *ppos)
 {
        size_t ret;
-       struct inode *inode = file->f_path.dentry->d_inode;
 
        ret = write_pool(&blocking_pool, buffer, count);
        if (ret)
@@ -1116,8 +1105,6 @@ static ssize_t random_write(struct file *file, const char __user *buffer,
        if (ret)
                return ret;
 
-       inode->i_mtime = current_fs_time(inode->i_sb);
-       mark_inode_dirty(inode);
        return (ssize_t)count;
 }
 
@@ -1200,7 +1187,7 @@ const struct file_operations urandom_fops = {
 void generate_random_uuid(unsigned char uuid_out[16])
 {
        get_random_bytes(uuid_out, 16);
-       /* Set UUID version to 4 --- truely random generation */
+       /* Set UUID version to 4 --- truly random generation */
        uuid_out[6] = (uuid_out[6] & 0x0F) | 0x40;
        /* Set the UUID variant to DCE */
        uuid_out[8] = (uuid_out[8] & 0x3F) | 0x80;