예제 #1
0
/****************
 * This is our log function which prints all log messages to stderr or
 * using the function defined with gcry_set_log_handler().
 */
static void
_gcry_logv( int level, const char *fmt, va_list arg_ptr )
{
  if (log_handler)
    log_handler (log_handler_value, level, fmt, arg_ptr);
  else 
    {
      switch (level) 
        {
        case GCRY_LOG_CONT:  break;
        case GCRY_LOG_INFO:  break;
        case GCRY_LOG_WARN:  break;
        case GCRY_LOG_ERROR: break;
        case GCRY_LOG_FATAL: fputs("Fatal: ",stderr ); break;
        case GCRY_LOG_BUG:   fputs("Ohhhh jeeee: ", stderr); break;
        case GCRY_LOG_DEBUG: fputs("DBG: ", stderr ); break;
        default: fprintf(stderr,"[Unknown log level %d]: ", level ); break;
	}
      vfprintf(stderr,fmt,arg_ptr) ;
    }
  
  if ( level == GCRY_LOG_FATAL || level == GCRY_LOG_BUG )
    {
      fips_signal_fatal_error ("internal error (fatal or bug)");
      _gcry_secmem_term ();
      abort ();
    }
}
예제 #2
0
void
gcry_create_nonce (void *buffer, size_t length)
{
  if (!fips_is_operational ())
    {
      (void)fips_not_operational ();
      fips_signal_fatal_error ("called in non-operational state");
      fips_noreturn ();
    }
  _gcry_create_nonce (buffer, length);
}
예제 #3
0
void
gcry_randomize (void *buffer, size_t length, enum gcry_random_level level)
{
  if (!fips_is_operational ())
    {
      (void)fips_not_operational ();
      fips_signal_fatal_error ("called in non-operational state");
      fips_noreturn ();
    }
  _gcry_randomize (buffer, length, level);
}
예제 #4
0
void *
gcry_random_bytes_secure (size_t nbytes, enum gcry_random_level level)
{
  if (!fips_is_operational ())
    {
      (void)fips_not_operational ();
      fips_signal_fatal_error ("called in non-operational state");
      fips_noreturn ();
    }

  return _gcry_random_bytes_secure (nbytes, level);
}
예제 #5
0
/*
 * This function is called for fatal errors.  A caller might want to
 * set his own handler because this function simply calls abort().
 */
void
_gcry_fatal_error (int rc, const char *text)
{
  if ( !text ) /* get a default text */
    text = gpg_strerror (rc);

  if (fatal_error_handler && !fips_mode () )
    fatal_error_handler (fatal_error_handler_value, rc, text);

  fips_signal_fatal_error (text);
  write2stderr("\nFatal error: ");
  write2stderr(text);
  write2stderr("\n");
  _gcry_secmem_term ();
  abort ();
}