Ejemplo n.º 1
0
/*
 * Run a test to check if the encryption works as expected.
 * Give an error and return FAIL when not.
 */
int blowfish_self_test(void)
{
  if (sha256_self_test() == FAIL) {
    EMSG(_("E818: sha256 test failed"));
    return FAIL;
  }
  if (bf_self_test() == FAIL) {
    EMSG(_("E819: Blowfish test failed"));
    return FAIL;
  }
  return OK;
}
Ejemplo n.º 2
0
int main( int argc, char *argv[] )
{
    int ret = 0, v;
#if defined(POLARSSL_MEMORY_BUFFER_ALLOC_C)
    unsigned char buf[1000000];
#endif

    if( argc == 2 && strcmp( argv[1], "-quiet" ) == 0 )
        v = 0;
    else
    {
        v = 1;
        printf( "\n" );
    }

#if defined(POLARSSL_SELF_TEST)

#if defined(POLARSSL_MEMORY_BUFFER_ALLOC_C)
    memory_buffer_alloc_init( buf, sizeof(buf) );
#endif

#if defined(POLARSSL_MD2_C)
    if( ( ret = md2_self_test( v ) ) != 0 )
        return( ret );
#endif

#if defined(POLARSSL_MD4_C)
    if( ( ret = md4_self_test( v ) ) != 0 )
        return( ret );
#endif

#if defined(POLARSSL_MD5_C)
    if( ( ret = md5_self_test( v ) ) != 0 )
        return( ret );
#endif

#if defined(POLARSSL_RIPEMD160_C)
    if( ( ret = ripemd160_self_test( v ) ) != 0 )
        return( ret );
#endif

#if defined(POLARSSL_SHA1_C)
    if( ( ret = sha1_self_test( v ) ) != 0 )
        return( ret );
#endif

#if defined(POLARSSL_SHA256_C)
    if( ( ret = sha256_self_test( v ) ) != 0 )
        return( ret );
#endif

#if defined(POLARSSL_SHA512_C)
    if( ( ret = sha512_self_test( v ) ) != 0 )
        return( ret );
#endif

#if defined(POLARSSL_ARC4_C)
    if( ( ret = arc4_self_test( v ) ) != 0 )
        return( ret );
#endif

#if defined(POLARSSL_DES_C)
    if( ( ret = des_self_test( v ) ) != 0 )
        return( ret );
#endif

#if defined(POLARSSL_AES_C)
    if( ( ret = aes_self_test( v ) ) != 0 )
        return( ret );
#endif

#if defined(POLARSSL_GCM_C)
    if( ( ret = gcm_self_test( v ) ) != 0 )
        return( ret );
#endif

#if defined(POLARSSL_BASE64_C)
    if( ( ret = base64_self_test( v ) ) != 0 )
        return( ret );
#endif

#if defined(POLARSSL_BIGNUM_C)
    if( ( ret = mpi_self_test( v ) ) != 0 )
        return( ret );
#endif

#if defined(POLARSSL_RSA_C)
    if( ( ret = rsa_self_test( v ) ) != 0 )
        return( ret );
#endif

#if defined(POLARSSL_X509_USE_C)
    if( ( ret = x509_self_test( v ) ) != 0 )
        return( ret );
#endif

#if defined(POLARSSL_XTEA_C)
    if( ( ret = xtea_self_test( v ) ) != 0 )
        return( ret );
#endif

#if defined(POLARSSL_CAMELLIA_C)
    if( ( ret = camellia_self_test( v ) ) != 0 )
        return( ret );
#endif

#if defined(POLARSSL_CTR_DRBG_C)
    if( ( ret = ctr_drbg_self_test( v ) ) != 0 )
        return( ret );
#endif

#if defined(POLARSSL_HMAC_DRBG_C)
    if( ( ret = hmac_drbg_self_test( v ) ) != 0 )
        return( ret );
#endif

#if defined(POLARSSL_ECP_C)
    if( ( ret = ecp_self_test( v ) ) != 0 )
        return( ret );
#endif

#if defined(POLARSSL_DHM_C)
    if( ( ret = dhm_self_test( v ) ) != 0 )
        return( ret );
#endif

/* Slow tests last */

#if defined(POLARSSL_PBKDF2_C)
    if( ( ret = pbkdf2_self_test( v ) ) != 0 )
        return( ret );
#else
#if defined(POLARSSL_PKCS5_C)
    if( ( ret = pkcs5_self_test( v ) ) != 0 )
        return( ret );
#endif
#endif

/*
 * Not reliable enough yet
 */
#if 0 && defined(POLARSSL_TIMING_C)
    if( ( ret = timing_self_test( v ) ) != 0 )
        return( ret );
#endif

#else
    printf( " POLARSSL_SELF_TEST not defined.\n" );
#endif

    if( v != 0 )
    {
#if defined(POLARSSL_MEMORY_BUFFER_ALLOC_C) && defined(POLARSSL_MEMORY_DEBUG)
        memory_buffer_alloc_status();
#endif

        printf( "  [ All tests passed ]\n\n" );
#if defined(_WIN32)
        printf( "  Press Enter to exit this program.\n" );
        fflush( stdout ); getchar();
#endif
    }
#if defined(POLARSSL_MEMORY_BUFFER_ALLOC_C)
    memory_buffer_alloc_free();
#endif

    return( ret );
}