crypt_check_data_device_size() needs to compare values in bytes
[platform/upstream/cryptsetup.git] / lib / random.c
index b2aafa5..a0c693d 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * cryptsetup kernel RNG access functions
  *
- * Copyright (C) 2010 Red Hat, Inc. All rights reserved.
+ * Copyright (C) 2010-2011, Red Hat, Inc. All rights reserved.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -41,7 +41,8 @@ static int random_fd = -1;
 #define RANDOM_DEVICE_TIMEOUT  5
 
 /* URANDOM_DEVICE access */
-static int _get_urandom(struct crypt_device *ctx, char *buf, size_t len)
+static int _get_urandom(struct crypt_device *ctx __attribute__((unused)),
+                       char *buf, size_t len)
 {
        int r;
        size_t old_len = len;
@@ -144,6 +145,9 @@ static int _get_random(struct crypt_device *ctx, char *buf, size_t len)
 /* Initialisation of both RNG file descriptors is mandatory */
 int crypt_random_init(struct crypt_device *ctx)
 {
+       if (random_initialised)
+               return 0;
+
        /* Used for CRYPT_RND_NORMAL */
        if(urandom_fd == -1)
                urandom_fd = open(URANDOM_DEVICE, O_RDONLY);
@@ -198,7 +202,7 @@ int crypt_random_get(struct crypt_device *ctx, char *buf, size_t len, int qualit
        return status;
 }
 
-void crypt_random_exit()
+void crypt_random_exit(void)
 {
        random_initialised = 0;
 
@@ -213,7 +217,7 @@ void crypt_random_exit()
        }
 }
 
-int crypt_random_default_key_rng()
+int crypt_random_default_key_rng(void)
 {
        if (!strcmp(DEFAULT_RNG, RANDOM_DEVICE))
                return CRYPT_RNG_RANDOM;