示例#1
0
int HashTest(void)
{
    int ret = 0;

    printf(" Begin HASH Tests\n");

#ifndef NO_MD4
    if ( (ret = md4_test()) ) {
        printf( "   MD4      test failed!\n");
        return ret; 
    } else
        printf( "   MD4      test passed!\n");
#endif

#ifndef NO_MD5
    if ( (ret = md5_test()) ) {
        printf( "   MD5      test failed!\n");
        return ret; 
    } else
        printf( "   MD5      test passed!\n");
#endif
    
#ifndef NO_SHA
    if ( (ret = sha_test()) ) {
        printf( "   SHA      test failed!\n");
        return ret; 
    } else
        printf( "   SHA      test passed!\n");
#endif
    
#ifndef NO_SHA256
    if ( (ret = sha256_test()) ) {
        printf( "   SHA-256  test failed!\n");
        return ret; 
    } else
        printf( "   SHA-256  test passed!\n");
#endif

#ifdef CYASSL_SHA512
    if ( (ret = sha512_test()) ) {
        printf( "   SHA-512  test failed!\n");
        return ret; 
    } else
        printf( "   SHA-512  test passed!\n");
#endif

#ifdef CYASSL_SHA384
    if ( (ret = sha384_test()) ) {
        printf( "   SHA-384  test failed!\n");
        return ret; 
    } else
        printf( "   SHA-384  test passed!\n");
#endif

#ifdef CYASSL_RIPEMD
    if ( (ret = ripemd_test()) ) {
        printf( "   RIPEMD   test failed!\n");
        return ret; 
    } else
        printf( "   RIPEMD   test passed!\n");
#endif

#ifndef NO_HMAC
    #ifndef NO_MD5
        if ( (ret = hmac_md5_test()) ) {
            printf( "   HMAC-MD5 test failed!\n");
            return ret; 
        } else
            printf( "   HMAC-MD5 test passed!\n");
    #endif

    if ( (ret = hmac_sha_test()) ) 
        printf( "   HMAC-SHA test failed!\n");
    else
        printf( "   HMAC-SHA test passed!\n");

    #ifndef NO_SHA256
        if ( (ret = hmac_sha256_test()) ) 
            printf( "   HMAC-SHA256 test failed!\n");
        else
            printf( "   HMAC-SHA256 test passed!\n");
    #endif

    #ifdef CYASSL_SHA384
        if ( (ret = hmac_sha384_test()) ) 
            printf( "   HMAC-SHA384 test failed!\n");
        else
            printf( "   HMAC-SHA384 test passed!\n");
    #endif
#endif

    printf(" End HASH Tests\n");
    
    return 0;
}
示例#2
0
bool unabto_test_all(void) {
//    NABTO_DECLARE_LOCAL_MODULE(NABTO_LOG_APP);
    bool ret = true;
    bool r;

    NABTO_LOG_INFO(("Testing sha256 implementation"));

    r = sha256_test();
    if (!r) {
        NABTO_LOG_INFO(("sha256 test failed"));
        ret = false;
    }


#if NABTO_ENABLE_SHA256_TESTS
    NABTO_LOG_INFO(("Testing hmac_sha256"));
    r = hmac_sha256_test();
    if (!r) {
        NABTO_LOG_INFO(("hmac sha256 tests failed"));
        ret = false;
    }
#endif

    NABTO_LOG_INFO(("Testing AES implementation"));
    r = aes_test();
    if (!r) {
        NABTO_LOG_INFO(("AES test failed"));
        ret = false;
    }

    NABTO_LOG_INFO(("Testing AES cbc encrypt/decrypt"));
    r = aes_cbc_test();
    if (!r) {
        NABTO_LOG_INFO(("AES_CBC encrypt/decrypt failed"));
        ret = false;
    }

    NABTO_LOG_INFO(("Testing prfplus"));
    r = unabto_prfplus_test();
    if (!r) {
        NABTO_LOG_INFO(("Prfplus_sha256 failed"));
        ret = false;
    }

    NABTO_LOG_INFO(("Testing truncated_hmac_sha256_verify_integrity"));
    truncated_hmac_sha256_verify_integrity_test(&r);
    //NABTO_LOG_TRACE(("ret %u", r));
    if (!r) {
        NABTO_LOG_INFO(("integrity verification test failed"));
        ret = false;
    }

    NABTO_LOG_INFO(("testing unabto_crypto.c"));
    r = test_nabto_crypto_create_key_material();
    if (!r) {
        NABTO_LOG_INFO(("unabto_crypto.c test failed"));
        ret = false;
    }

    NABTO_LOG_INFO(("Testing unabto_util"));
    r = unabto_util_test();
    if (!r) {
        NABTO_LOG_INFO(("testing of unabto_util failed"));
        ret = false;
    }

    NABTO_LOG_INFO(("Testing unabto_buffer"));
    r = unabto_buffer_test();
    if (!r) {
        NABTO_LOG_ERROR(("Test of unabto_buffer failed"));
        ret = false;
    }

    {
        int i;
        NABTO_LOG_INFO(("testing unabto crypto timings"));
        i = integrity_verify_timing();
        NABTO_LOG_INFO(("%i integrity checks in one second.", i));

        i = aes_cbc_timing_test();
        NABTO_LOG_INFO(("%i aes_cbc en/decryptions in one second.", i));

        i = sha256_timing_test();
        NABTO_LOG_INFO(("%i 131bytes sha256 hashes in one second.", i));

        i = aes_timing_test();
        NABTO_LOG_INFO(("%i aes blocks en/decryptiong in one second.", i));
    }

    r = test_state_machine();
    
    if (!r) {
        NABTO_LOG_ERROR(("Test of unabto stream state machine failed."));
        ret = false;
    }

    r = unabto_base32_test();
    if (!r) {
        NABTO_LOG_ERROR(("Test of base32 failed."));
        ret = false;
    }
    
    if (ret) {
        NABTO_LOG_INFO(("All uNabto tests succeded"));
    } else {
        NABTO_LOG_INFO(("Some uNabto test failed"));
    }
    return ret;
}