Ejemplo n.º 1
0
void logF(unsigned indent, const char* format, const Types&... values)
{
    printIndents(indent);

#if COMPILER(GCC_OR_CLANG)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
#pragma GCC diagnostic ignored "-Wmissing-format-attribute"
#endif

    dataLogF(format, values...);

#if COMPILER(GCC_OR_CLANG)
#pragma GCC diagnostic pop
#endif
}
Ejemplo n.º 2
0
static void printif(int indentLevels, const char* format, ...)
{
    va_list argList;
    va_start(argList, format);

    if (indentLevels)
        printIndents(indentLevels);

#if COMPILER(CLANG) || COMPILER(GCC)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
#pragma GCC diagnostic ignored "-Wmissing-format-attribute"
#endif

    WTF::dataLogFV(format, argList);

#if COMPILER(CLANG) || COMPILER(GCC)
#pragma GCC diagnostic pop
#endif

    va_end(argList);
}
Ejemplo n.º 3
0
int millerrabin(BIGNUM *bn_n, int maxitr, FILE *primesfile, int num_idnt){
	int s = 0;
	BIGNUM *bn_r = NULL;
	BIGNUM *bn_n_1 = NULL;
	BN_CTX *bn_ctx = NULL;
	BIGNUM *bn_a = NULL;
	BIGNUM *bn_y = NULL;
	BIGNUM *bn_1 = NULL;
	int i = 0;
	int j = 0;

	bn_a = BN_new();
	bn_y = BN_new();
	bn_r = BN_new();
	bn_1 = BN_new();
	BN_one(bn_1);
	bn_ctx = BN_CTX_new();
	bn_n_1 = BN_new();
	BN_CTX_init(bn_ctx);
	fseek(primesfile, 0 ,SEEK_SET);
	s = compute_sr(bn_n, bn_r, bn_n_1, bn_ctx);
	if(s == -1){
		return -1;
	}
	
	if(num_idnt == 0){
		fprintf(stdout, "n = %s\n", BN_bn2dec(bn_n));
	}
	printIndents(num_idnt);
	fprintf(stdout, "  n-1 = %s\n", BN_bn2dec(bn_n_1));
	printIndents(num_idnt);
	fprintf(stdout, "  s = %d\n", s);
	printIndents(num_idnt);
	fprintf(stdout, "  r = %s\n", BN_bn2dec(bn_r));
	
	for(i = 1; i <= maxitr; i++){
		printIndents(num_idnt);
		fprintf(stdout, "  Itr %d of %d, ", i, maxitr);
		
		ithPrime(i, primesfile, bn_a);
		if(BN_cmp(bn_a, bn_n_1) == 1){
			return -1;
		}
		
		compute_y(bn_y, bn_a, bn_r, bn_n, bn_ctx);
		
		
		if(BN_cmp(bn_y, bn_1) != 0 && BN_cmp(bn_y, bn_n_1) != 0){
			fprintf(stdout, "a = %s, y = %s\n", BN_bn2dec(bn_a), BN_bn2dec(bn_y));
			for(j = 1; j <= s - 1; j++){
				BN_mod_mul(bn_y, bn_y, bn_y, bn_n, bn_ctx);
				printIndents(num_idnt);
				fprintf(stdout, "    j = %d of %d, y = %s", j, s - 1, BN_bn2dec(bn_y));
				if(BN_cmp(bn_y, bn_n_1) == 0){
					fprintf(stdout, " (which is n-1)\n");
					break;
				}
				putchar('\n');
				
				if(BN_cmp(bn_y, bn_1) == 0){
					return 0;
				}
			}
			
			if(BN_cmp(bn_y, bn_n_1) != 0){
				printIndents(num_idnt);
				fprintf(stdout, "Miller-Rabin found a strong witness %s\n", BN_bn2dec(bn_a));
				return 0;
			}
		}
		else{
			if(BN_cmp(bn_y, bn_n_1) == 0){
				fprintf(stdout, "a = %s, y = %s (which is n-1)\n", BN_bn2dec(bn_a), BN_bn2dec(bn_y));
			}
			else{
				fprintf(stdout, "a = %s, y = %s\n", BN_bn2dec(bn_a), BN_bn2dec(bn_y));
			}
		}
		
		
	}
	printIndents(num_idnt);
	fprintf(stdout, "Miller-Rabin declares n to be a prime number\n");	
	return 1;
	
	BN_free(bn_1);
	BN_free(bn_a);
	BN_free(bn_y);
	BN_free(bn_r);
	BN_CTX_free(bn_ctx);
}
Ejemplo n.º 4
0
void log(unsigned indent, const Types&... values)
{
    printIndents(indent);
    dataLog(values...);
}