|
@@ -27,7 +27,6 @@
|
|
|
/*
|
|
|
* Things in boring, not in openssl. TODO we should add them.
|
|
|
*/
|
|
|
-#define HAVE_BN_PADDED 0
|
|
|
#define HAVE_BN_SQRT 0
|
|
|
|
|
|
typedef struct filetest_st {
|
|
@@ -628,6 +627,51 @@ static int test_modexp_mont5(void)
|
|
|
if (!TEST_BN_eq(c, d))
|
|
|
goto err;
|
|
|
|
|
|
+ /*
|
|
|
+ * Regression test for overflow bug in bn_sqr_comba4/8 for
|
|
|
+ * mips-linux-gnu and mipsel-linux-gnu 32bit targets.
|
|
|
+ */
|
|
|
+ {
|
|
|
+ static const char *ehex[] = {
|
|
|
+ "95564994a96c45954227b845a1e99cb939d5a1da99ee91acc962396ae999a9ee",
|
|
|
+ "38603790448f2f7694c242a875f0cad0aae658eba085f312d2febbbd128dd2b5",
|
|
|
+ "8f7d1149f03724215d704344d0d62c587ae3c5939cba4b9b5f3dc5e8e911ef9a",
|
|
|
+ "5ce1a5a749a4989d0d8368f6e1f8cdf3a362a6c97fb02047ff152b480a4ad985",
|
|
|
+ "2d45efdf0770542992afca6a0590d52930434bba96017afbc9f99e112950a8b1",
|
|
|
+ "a359473ec376f329bdae6a19f503be6d4be7393c4e43468831234e27e3838680",
|
|
|
+ "b949390d2e416a3f9759e5349ab4c253f6f29f819a6fe4cbfd27ada34903300e",
|
|
|
+ "da021f62839f5878a36f1bc3085375b00fd5fa3e68d316c0fdace87a97558465",
|
|
|
+ NULL};
|
|
|
+ static const char *phex[] = {
|
|
|
+ "f95dc0f980fbd22e90caa5a387cc4a369f3f830d50dd321c40db8c09a7e1a241",
|
|
|
+ "a536e096622d3280c0c1ba849c1f4a79bf490f60006d081e8cf69960189f0d31",
|
|
|
+ "2cd9e17073a3fba7881b21474a13b334116cb2f5dbf3189a6de3515d0840f053",
|
|
|
+ "c776d3982d391b6d04d642dda5cc6d1640174c09875addb70595658f89efb439",
|
|
|
+ "dc6fbd55f903aadd307982d3f659207f265e1ec6271b274521b7a5e28e8fd7a5",
|
|
|
+ "5df089292820477802a43cf5b6b94e999e8c9944ddebb0d0e95a60f88cb7e813",
|
|
|
+ "ba110d20e1024774107dd02949031864923b3cb8c3f7250d6d1287b0a40db6a4",
|
|
|
+ "7bd5a469518eb65aa207ddc47d8c6e5fc8e0c105be8fc1d4b57b2e27540471d5",
|
|
|
+ NULL};
|
|
|
+ static const char *mhex[] = {
|
|
|
+ "fef15d5ce4625f1bccfbba49fc8439c72bf8202af039a2259678941b60bb4a8f",
|
|
|
+ "2987e965d58fd8cf86a856674d519763d0e1211cc9f8596971050d56d9b35db3",
|
|
|
+ "785866cfbca17cfdbed6060be3629d894f924a89fdc1efc624f80d41a22f1900",
|
|
|
+ "9503fcc3824ef62ccb9208430c26f2d8ceb2c63488ec4c07437aa4c96c43dd8b",
|
|
|
+ "9289ed00a712ff66ee195dc71f5e4ead02172b63c543d69baf495f5fd63ba7bc",
|
|
|
+ "c633bd309c016e37736da92129d0b053d4ab28d21ad7d8b6fab2a8bbdc8ee647",
|
|
|
+ "d2fbcf2cf426cf892e6f5639e0252993965dfb73ccd277407014ea784aaa280c",
|
|
|
+ "b7b03972bc8b0baa72360bdb44b82415b86b2f260f877791cd33ba8f2d65229b",
|
|
|
+ NULL};
|
|
|
+
|
|
|
+ if (!TEST_true(parse_bigBN(&e, ehex))
|
|
|
+ || !TEST_true(parse_bigBN(&p, phex))
|
|
|
+ || !TEST_true(parse_bigBN(&m, mhex))
|
|
|
+ || !TEST_true(BN_mod_exp_mont_consttime(d, e, p, m, ctx, NULL))
|
|
|
+ || !TEST_true(BN_mod_exp_simple(a, e, p, m, ctx))
|
|
|
+ || !TEST_BN_eq(a, d))
|
|
|
+ goto err;
|
|
|
+ }
|
|
|
+
|
|
|
/* Zero input */
|
|
|
if (!TEST_true(BN_bntest_rand(p, 1024, 0, 0)))
|
|
|
goto err;
|
|
@@ -1731,52 +1775,52 @@ static int file_gcd(STANZA *s)
|
|
|
|
|
|
static int test_bn2padded(void)
|
|
|
{
|
|
|
-#if HAVE_BN_PADDED
|
|
|
uint8_t zeros[256], out[256], reference[128];
|
|
|
- BIGNUM *n = BN_new();
|
|
|
+ size_t bytes;
|
|
|
+ BIGNUM *n;
|
|
|
int st = 0;
|
|
|
|
|
|
/* Test edge case at 0. */
|
|
|
- if (n == NULL)
|
|
|
+ if (!TEST_ptr((n = BN_new())))
|
|
|
goto err;
|
|
|
- if (!TEST_true(BN_bn2bin_padded(NULL, 0, n)))
|
|
|
+ if (!TEST_int_eq(BN_bn2binpad(n, NULL, 0), 0))
|
|
|
goto err;
|
|
|
memset(out, -1, sizeof(out));
|
|
|
- if (!TEST_true(BN_bn2bin_padded(out, sizeof(out)), n))
|
|
|
+ if (!TEST_int_eq(BN_bn2binpad(n, out, sizeof(out)), sizeof(out)))
|
|
|
goto err;
|
|
|
memset(zeros, 0, sizeof(zeros));
|
|
|
if (!TEST_mem_eq(zeros, sizeof(zeros), out, sizeof(out)))
|
|
|
goto err;
|
|
|
|
|
|
/* Test a random numbers at various byte lengths. */
|
|
|
- for (size_t bytes = 128 - 7; bytes <= 128; bytes++) {
|
|
|
+ for (bytes = 128 - 7; bytes <= 128; bytes++) {
|
|
|
# define TOP_BIT_ON 0
|
|
|
# define BOTTOM_BIT_NOTOUCH 0
|
|
|
if (!TEST_true(BN_rand(n, bytes * 8, TOP_BIT_ON, BOTTOM_BIT_NOTOUCH)))
|
|
|
goto err;
|
|
|
- if (!TEST_int_eq(BN_num_bytes(n),A) bytes
|
|
|
- || TEST_int_eq(BN_bn2bin(n, reference), bytes))
|
|
|
+ if (!TEST_int_eq(BN_num_bytes(n), bytes)
|
|
|
+ || !TEST_int_eq(BN_bn2bin(n, reference), bytes))
|
|
|
goto err;
|
|
|
/* Empty buffer should fail. */
|
|
|
- if (!TEST_int_eq(BN_bn2bin_padded(NULL, 0, n)), 0)
|
|
|
+ if (!TEST_int_eq(BN_bn2binpad(n, NULL, 0), -1))
|
|
|
goto err;
|
|
|
/* One byte short should fail. */
|
|
|
- if (BN_bn2bin_padded(out, bytes - 1, n))
|
|
|
+ if (!TEST_int_eq(BN_bn2binpad(n, out, bytes - 1), -1))
|
|
|
goto err;
|
|
|
/* Exactly right size should encode. */
|
|
|
- if (!TEST_true(BN_bn2bin_padded(out, bytes, n))
|
|
|
- || TEST_mem_eq(out, bytes, reference, bytes))
|
|
|
+ if (!TEST_int_eq(BN_bn2binpad(n, out, bytes), bytes)
|
|
|
+ || !TEST_mem_eq(out, bytes, reference, bytes))
|
|
|
goto err;
|
|
|
/* Pad up one byte extra. */
|
|
|
- if (!TEST_true(BN_bn2bin_padded(out, bytes + 1, n))
|
|
|
+ if (!TEST_int_eq(BN_bn2binpad(n, out, bytes + 1), bytes + 1)
|
|
|
|| !TEST_mem_eq(out + 1, bytes, reference, bytes)
|
|
|
|| !TEST_mem_eq(out, 1, zeros, 1))
|
|
|
goto err;
|
|
|
/* Pad up to 256. */
|
|
|
- if (!TEST_true(BN_bn2bin_padded(out, sizeof(out)), n)
|
|
|
+ if (!TEST_int_eq(BN_bn2binpad(n, out, sizeof(out)), sizeof(out))
|
|
|
|| !TEST_mem_eq(out + sizeof(out) - bytes, bytes,
|
|
|
reference, bytes)
|
|
|
- || !TEST_mem_eq(out, sizseof(out) - bytes,
|
|
|
+ || !TEST_mem_eq(out, sizeof(out) - bytes,
|
|
|
zeros, sizeof(out) - bytes))
|
|
|
goto err;
|
|
|
}
|
|
@@ -1785,9 +1829,6 @@ static int test_bn2padded(void)
|
|
|
err:
|
|
|
BN_free(n);
|
|
|
return st;
|
|
|
-#else
|
|
|
- return ctx != NULL;
|
|
|
-#endif
|
|
|
}
|
|
|
|
|
|
static int test_dec2bn(void)
|