78 #ifdef OPENSSL_NO_ECDSA
79 int main(
int argc,
char * argv[])
81 puts(
"Elliptic curves are disabled.");
91 #ifndef OPENSSL_NO_ENGINE
97 static const char rnd_seed[] =
"string to make the random number generator "
98 "think it has entropy";
121 fake_rand.
add = old_rand->
add;
140 static int fbytes_counter = 0;
141 static const char *numbers[8] = {
142 "651056770906015076056810763456358567190100156695615665659",
143 "6140507067065001063065065565667405560006161556565665656654",
144 "8763001015071075675010661307616710783570106710677817767166"
146 "7000000175690566466555057817571571075705015757757057795755"
148 "1275552191113212300012030439187146164646146646466749494799",
149 "1542725565216523985789236956265265265235675811949404040041",
150 "1456427555219115346513212300075341203043918714616464614664"
152 "1712787255652165239672857892369562652652652356758119494040"
160 if (fbytes_counter >= 8)
165 if (!
BN_dec2bn(&tmp, numbers[fbytes_counter]))
184 const char message[] =
"abc";
185 unsigned char digest[20];
186 unsigned int dgst_len = 0;
190 BIGNUM *r = NULL, *s = NULL;
208 if (signature == NULL)
256 "3342403536405981729393488334694600415596881826869351677613",
257 "5735822328888155254683894997897571951568553642892029982342"))
260 "3086361431751678114926225473006680188549593787585317781474"
262 "3238135532097973577080787768312505059318910517550078427819"
265 #ifndef OPENSSL_NO_EC2M
267 "87194383164871543355722284926904419997237591535066528048",
268 "308992691965804947361541664549085895292153777025772063598"))
271 "2159633321041961198501834003903461262881815148684178964245"
273 "1970303740007316867383349976549972270528498040721988191026"
287 size_t crv_len = 0, n = 0;
288 EC_KEY *eckey = NULL, *wrong_eckey = NULL;
291 unsigned char digest[20], wrong_digest[20];
292 unsigned char *signature = NULL;
293 const unsigned char *sig_ptr;
294 unsigned char *sig_ptr2;
295 unsigned char *raw_buf = NULL;
296 unsigned int sig_len, degree, r_len, s_len, bn_len, buf_len;
303 BIO_printf(out,
"ERROR: unable to get random data\n");
309 BIO_printf(out,
"\ntesting ECDSA_sign() and ECDSA_verify() "
310 "with some internal curves:\n");
325 BIO_printf(out,
"unable to get internal curves\n");
330 for (n = 0; n < crv_len; n++)
332 unsigned char dirt, offset;
390 if (!
ECDSA_sign(0, digest, 20, signature, &sig_len, eckey))
398 if (
ECDSA_verify(0, digest, 20, signature, sig_len, eckey) != 1)
415 if (
ECDSA_verify(0, wrong_digest, 20, signature, sig_len,
437 if ((ecdsa_sig =
d2i_ECDSA_SIG(NULL, &sig_ptr, sig_len)) == NULL)
446 bn_len = (degree + 7) / 8;
447 if ((r_len > bn_len) || (s_len > bn_len))
452 buf_len = 2 * bn_len;
456 memset(raw_buf, 0, buf_len);
457 BN_bn2bin(ecdsa_sig->
r, raw_buf + bn_len - r_len);
458 BN_bn2bin(ecdsa_sig->
s, raw_buf + buf_len - s_len);
461 offset = raw_buf[10] % buf_len;
462 dirt = raw_buf[11] ? raw_buf[11] : 1;
463 raw_buf[offset] ^= dirt;
465 if ((
BN_bin2bn(raw_buf, bn_len, ecdsa_sig->
r) == NULL) ||
466 (
BN_bin2bn(raw_buf + bn_len, bn_len, ecdsa_sig->
s) == NULL))
469 sig_ptr2 = signature;
471 if (
ECDSA_verify(0, digest, 20, signature, sig_len, eckey) == 1)
477 raw_buf[offset] ^= dirt;
478 if ((
BN_bin2bn(raw_buf, bn_len, ecdsa_sig->
r) == NULL) ||
479 (
BN_bin2bn(raw_buf + bn_len, bn_len, ecdsa_sig->
s) == NULL))
482 sig_ptr2 = signature;
484 if (
ECDSA_verify(0, digest, 20, signature, sig_len, eckey) != 1)
534 if (!((getenv(
"OPENSSL_DEBUG_MEMORY") != NULL) &&
535 (0 == strcmp(getenv(
"OPENSSL_DEBUG_MEMORY"),
"off"))))