~ubuntu-branches/ubuntu/natty/libgcrypt11/natty-proposed

« back to all changes in this revision

Viewing changes to src/secmem.c

  • Committer: Bazaar Package Importer
  • Author(s): Andreas Metzler
  • Date: 2009-02-21 13:46:58 UTC
  • mto: (1.1.6 upstream) (2.1.3 squeeze)
  • mto: This revision was merged to the branch mainline in revision 18.
  • Revision ID: james.westby@ubuntu.com-20090221134658-855twvcr4ezk2ron
ImportĀ upstreamĀ versionĀ 1.4.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
 * GNU Lesser General Public License for more details.
16
16
 *
17
17
 * You should have received a copy of the GNU Lesser General Public
18
 
 * License along with this program; if not, write to the Free Software
19
 
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
 
18
 * License along with this program; if not, see <http://www.gnu.org/licenses/>.
20
19
 */
21
20
 
22
21
#include <config.h>
45
44
#define MAP_ANONYMOUS MAP_ANON
46
45
#endif
47
46
 
48
 
#define DEFAULT_POOL_SIZE 16384
 
47
#define MINIMUM_POOL_SIZE 16384
 
48
#define STANDARD_POOL_SIZE 32768
49
49
#define DEFAULT_PAGE_SIZE 4096
50
50
 
51
51
typedef struct memblock
443
443
  return flags;
444
444
}
445
445
 
446
 
/* Initialize the secure memory system.  If running with the necessary
447
 
   privileges, the secure memory pool will be locked into the core in
448
 
   order to prevent page-outs of the data.  Furthermore allocated
449
 
   secure memory will be wiped out when released.  */
450
 
void
451
 
_gcry_secmem_init (size_t n)
 
446
 
 
447
/* See _gcry_secmem_init.  This function is expected to be called with
 
448
   the secmem lock held. */
 
449
static void
 
450
secmem_init (size_t n)
452
451
{
453
 
  SECMEM_LOCK;
454
 
 
455
452
  if (!n)
456
453
    {
457
454
#ifdef USE_CAPABILITIES
472
469
    }
473
470
  else
474
471
    {
475
 
      if (n < DEFAULT_POOL_SIZE)
476
 
        n = DEFAULT_POOL_SIZE;
 
472
      if (n < MINIMUM_POOL_SIZE)
 
473
        n = MINIMUM_POOL_SIZE;
477
474
      if (! pool_okay)
478
475
        {
479
476
          init_pool (n);
482
479
      else
483
480
        log_error ("Oops, secure memory pool already initialized\n");
484
481
    }
 
482
}
 
483
 
 
484
 
 
485
 
 
486
/* Initialize the secure memory system.  If running with the necessary
 
487
   privileges, the secure memory pool will be locked into the core in
 
488
   order to prevent page-outs of the data.  Furthermore allocated
 
489
   secure memory will be wiped out when released.  */
 
490
void
 
491
_gcry_secmem_init (size_t n)
 
492
{
 
493
  SECMEM_LOCK;
 
494
 
 
495
  secmem_init (n);
485
496
 
486
497
  SECMEM_UNLOCK;
487
498
}
494
505
 
495
506
  if (!pool_okay)
496
507
    {
497
 
      log_bug (_
498
 
        ("operation is not possible without initialized secure memory\n"));
 
508
      /* Try to initialize the pool if the user forgot about it.  */
 
509
      secmem_init (STANDARD_POOL_SIZE);
 
510
      if (!pool_okay)
 
511
        {
 
512
          log_info (_("operation is not possible without "
 
513
                      "initialized secure memory\n"));
 
514
          return NULL;
 
515
        }
 
516
    }
 
517
  if (not_locked && fips_mode ())
 
518
    {
 
519
      log_info (_("secure memory pool is not locked while in FIPS mode\n"));
 
520
      return NULL;
499
521
    }
500
522
  if (show_warning && !suspend_warning)
501
523
    {