#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include <time.h>
#include <openssl/ec.h>
+#include <openssl/engine.h>
#include <openssl/err.h>
#define ABORT do { \
} while (0)
-void timings(EC_GROUP *group, int simult, BN_CTX *ctx)
+void timings(EC_GROUP *group, int multi, BN_CTX *ctx)
{
clock_t clck;
int i, j;
for (i = 0; i < 10; i++)
{
if (!BN_pseudo_rand(s, BN_num_bits(s), 0, 0)) ABORT;
- if (simult)
+ if (multi)
{
if (!BN_pseudo_rand(s0, BN_num_bits(s), 0, 0)) ABORT;
}
for (j = 0; j < 10; j++)
{
- if (!EC_POINT_mul(group, P, s, simult ? P : NULL, simult ? s0 : NULL, ctx)) ABORT;
+ if (!EC_POINT_mul(group, P, s, multi ? P : NULL, multi ? s0 : NULL, ctx)) ABORT;
}
fprintf(stdout, ".");
fflush(stdout);
#endif
fprintf(stdout, "%i %s in %.2f " UNIT "\n", i*j,
- simult ? "s*P+t*Q operations" : "point multiplications",
+ multi ? "s*P+t*Q operations" : "point multiplications",
(double)clck/CLOCKS_PER_SEC);
fprintf(stdout, "average: %.4f " UNIT "\n", (double)clck/(CLOCKS_PER_SEC*i*j));
BIGNUM *x, *y, *z;
unsigned char buf[100];
size_t i, len;
+ int k;
+ /* enable memory leak checking unless explicitly disabled */
+ if (!((getenv("OPENSSL_DEBUG_MEMORY") != NULL) && (0 == strcmp(getenv("OPENSSL_DEBUG_MEMORY"), "off"))))
+ {
+ CRYPTO_malloc_debug_init();
+ CRYPTO_set_mem_debug_options(V_CRYPTO_MDEBUG_ALL);
+ }
+ else
+ {
+ /* OPENSSL_DEBUG_MEMORY=off */
+ CRYPTO_set_mem_debug_functions(0, 0, 0, 0, 0);
+ }
CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
ERR_load_crypto_strings();
}
fprintf(stdout, "A cyclic subgroup:\n");
+ k = 100;
do
{
+ if (k-- == 0) ABORT;
+
if (EC_POINT_is_at_infinity(group, P))
fprintf(stdout, " point at infinity\n");
else
if (!EC_POINT_is_at_infinity(group, Q)) ABORT;
fprintf(stdout, ".");
fflush(stdout);
- if (!EC_GROUP_precompute(group, ctx)) ABORT;
+ if (!EC_GROUP_precompute_mult(group, ctx)) ABORT;
if (!EC_POINT_mul(group, Q, z, NULL, NULL, ctx)) ABORT;
if (!EC_POINT_is_at_infinity(group, Q)) ABORT;
fprintf(stdout, " ok\n");
if (!EC_POINT_is_at_infinity(group, Q)) ABORT;
fprintf(stdout, ".");
fflush(stdout);
- if (!EC_GROUP_precompute(group, ctx)) ABORT;
+ if (!EC_GROUP_precompute_mult(group, ctx)) ABORT;
if (!EC_POINT_mul(group, Q, z, NULL, NULL, ctx)) ABORT;
if (!EC_POINT_is_at_infinity(group, Q)) ABORT;
fprintf(stdout, " ok\n");
if (!EC_POINT_is_at_infinity(group, Q)) ABORT;
fprintf(stdout, ".");
fflush(stdout);
- if (!EC_GROUP_precompute(group, ctx)) ABORT;
+ if (!EC_GROUP_precompute_mult(group, ctx)) ABORT;
if (!EC_POINT_mul(group, Q, z, NULL, NULL, ctx)) ABORT;
if (!EC_POINT_is_at_infinity(group, Q)) ABORT;
fprintf(stdout, " ok\n");
if (!EC_POINT_is_at_infinity(group, Q)) ABORT;
fprintf(stdout, ".");
fflush(stdout);
- if (!EC_GROUP_precompute(group, ctx)) ABORT;
+ if (!EC_GROUP_precompute_mult(group, ctx)) ABORT;
if (!EC_POINT_mul(group, Q, z, NULL, NULL, ctx)) ABORT;
if (!EC_POINT_is_at_infinity(group, Q)) ABORT;
fprintf(stdout, " ok\n");
if (!EC_POINT_is_at_infinity(group, Q)) ABORT;
fprintf(stdout, ".");
fflush(stdout);
- if (!EC_GROUP_precompute(group, ctx)) ABORT;
+ if (!EC_GROUP_precompute_mult(group, ctx)) ABORT;
if (!EC_POINT_mul(group, Q, z, NULL, NULL, ctx)) ABORT;
if (!EC_POINT_is_at_infinity(group, Q)) ABORT;
fprintf(stdout, " ok\n");
scalars[0] = y; /* (group order + 1)/2, so y*Q + y*Q = Q */
scalars[1] = y;
- fprintf(stdout, "simultaneous multiplication ...");
+ fprintf(stdout, "combined multiplication ...");
fflush(stdout);
/* z is still the group order */
fflush(stdout);
if (!BN_pseudo_rand(y, BN_num_bits(y), 0, 0)) ABORT;
- if (!BN_copy(z, y)) ABORT;
+ if (!BN_add(z, z, y)) ABORT;
z->neg = 1;
scalars[0] = y;
- scalars[1] = z; /* z = -y */
+ scalars[1] = z; /* z = -(order + y) */
if (!EC_POINTs_mul(group, P, NULL, 2, points, scalars, ctx)) ABORT;
if (!EC_POINT_is_at_infinity(group, P)) ABORT;
if (P_384) EC_GROUP_free(P_384);
if (P_521) EC_GROUP_free(P_521);
+ ENGINE_cleanup();
+ CRYPTO_cleanup_all_ex_data();
ERR_free_strings();
ERR_remove_state(0);
CRYPTO_mem_leaks_fp(stderr);