Code:  int test_sqr(BIO *bp, BN_CTX *ctx)
 	{
	BIGNUM a,c,d,e;
	int i;
 
	BN_init(&a);
	BN_init(&c);
	BN_init(&d);
	BN_init(&e);
 
 	for (i=0; i<num0; i++)
 		{
		BN_bntest_rand(&a,40+i*10,0,0);
		a.neg=rand_neg();
		BN_sqr(&c,&a,ctx);
 		if (bp != NULL)
 			{
 			if (!results)
 				{
				BN_print(bp,&a);
 				BIO_puts(bp," * ");
				BN_print(bp,&a);
 				BIO_puts(bp," - ");
 				}
			BN_print(bp,&c);
 			BIO_puts(bp,"\n");
 			}
		BN_div(&d,&e,&c,&a,ctx);
		BN_sub(&d,&d,&a);
		if(!BN_is_zero(&d) || !BN_is_zero(&e))
		    {
		    fprintf(stderr,"Square test failed!\n");
		    return 0;
		    }
 		}
	BN_free(&a);
	BN_free(&c);
	BN_free(&d);
	BN_free(&e);
	return(1);
 	}

Vulnerability Type: 
CWE ID: CWE-310
Summary: The BN_sqr implementation in OpenSSL before 0.9.8zd, 1.0.0 before 1.0.0p, and 1.0.1 before 1.0.1k does not properly calculate the square of a BIGNUM value, which might make it easier for remote attackers to defeat cryptographic protection mechanisms via unspecified vectors, related to crypto/bn/asm/mips.pl, crypto/bn/asm/x86_64-gcc.c, and crypto/bn/bn_asm.c.
Commit Message: Fix for CVE-2014-3570 (with minor bn_asm.c revamp).

Reviewed-by: Emilia Kasper <emilia@openssl.org>