return NULL;
}
+/*
+ * Parse BIGNUM from sparse hex-strings, return |BN_hex2bn| result.
+ */
+static int parse_bigBN(BIGNUM **out, const char *bn_strings[])
+{
+ char *bigstring = glue_strings(bn_strings, NULL);
+ int ret = BN_hex2bn(out, bigstring);
+
+ OPENSSL_free(bigstring);
+ return ret;
+}
+
/*
* Parse BIGNUM, return number of bytes parsed.
*/
NULL
};
-static char *glue(const char *list[])
-{
- size_t len = 0;
- char *p, *save;
- int i;
-
- for (i = 0; list[i] != NULL; i++)
- len += strlen(list[i]);
- if (!TEST_ptr(p = save = OPENSSL_malloc(len + 1)))
- return NULL;
- for (i = 0; list[i] != NULL; i++)
- p += strlen(strcpy(p, list[i]));
- return save;
-}
-
/*
* Test constant-time modular exponentiation with 1024-bit inputs, which on
* x86_64 cause a different code branch to be taken.
BIGNUM *a = NULL, *p = NULL, *m = NULL, *d = NULL, *e = NULL;
BIGNUM *b = NULL, *n = NULL, *c = NULL;
BN_MONT_CTX *mont = NULL;
- char *bigstring;
int st = 0;
if (!TEST_ptr(a = BN_new())
goto err;
/* Regression test for carry bug in sqr[x]8x_mont */
- bigstring = glue(bn1strings);
- BN_hex2bn(&n, bigstring);
- OPENSSL_free(bigstring);
- bigstring = glue(bn2strings);
- BN_hex2bn(&a, bigstring);
- OPENSSL_free(bigstring);
+ parse_bigBN(&n, bn1strings);
+ parse_bigBN(&a, bn2strings);
BN_free(b);
b = BN_dup(a);
BN_MONT_CTX_set(mont, n, ctx);
"FCFFFFFFFFFF000000000000000000FF0302030000000000FFFFFFFFFFFFFFFF",
"FF00FCFDFDFF030202FF00000000FFFFFFFFFFFFFFFFFF00FCFDFCFFFFFFFFFF",
NULL
- };
+ };
static const char *nhex[] = {
"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF",
"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF",
"FFFFFFFFFFFF000000000000000000000000000000000000FFFFFFFFFFFFFFFF",
"FFFFFFFFFFFFFFFFFFFF00000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF",
NULL
- };
-
- bigstring = glue(ahex);
- BN_hex2bn(&a, bigstring);
- OPENSSL_free(bigstring);
- bigstring = glue(nhex);
- BN_hex2bn(&n, bigstring);
- OPENSSL_free(bigstring);
+ };
+
+ parse_bigBN(&a, ahex);
+ parse_bigBN(&n, nhex);
}
BN_free(b);
b = BN_dup(a);
* Glue an array of strings together. Return a BIO and put the string
* into |*out| so we can free it.
*/
-static BIO *glue(const char **pem, char **out)
+static BIO *glue2bio(const char **pem, char **out)
{
- char *dest;
- int i;
size_t s = 0;
- /* Glue the strings together. */
- for (i = 0; pem[i] != NULL; ++i)
- s += strlen(pem[i]);
- dest = *out = OPENSSL_malloc(s + 1);
- if (dest == NULL)
- return NULL;
- for (i = 0; pem[i] != NULL; ++i)
- dest += strlen(strcpy(dest, pem[i]));
+ *out = glue_strings(pem, &s);
return BIO_new_mem_buf(*out, s);
}
static X509_CRL *CRL_from_strings(const char **pem)
{
char *p;
- BIO *b = glue(pem, &p);
+ BIO *b = glue2bio(pem, &p);
X509_CRL *crl = PEM_read_bio_X509_CRL(b, NULL, NULL, NULL);
OPENSSL_free(p);
static X509 *X509_from_strings(const char **pem)
{
char *p;
- BIO *b = glue(pem, &p);
+ BIO *b = glue2bio(pem, &p);
X509 *x = PEM_read_bio_X509(b, NULL, NULL, NULL);
OPENSSL_free(p);