2016-05-17 18:51:04 +00:00
|
|
|
/*
|
2019-02-26 14:05:09 +00:00
|
|
|
* Copyright 2002-2019 The OpenSSL Project Authors. All Rights Reserved.
|
2002-12-08 05:24:31 +00:00
|
|
|
*
|
2016-05-17 18:51:04 +00:00
|
|
|
* Licensed under the OpenSSL license (the "License"). You may not use
|
|
|
|
* this file except in compliance with the License. You can obtain a copy
|
|
|
|
* in the file LICENSE in the source distribution or at
|
|
|
|
* https://www.openssl.org/source/license.html
|
2002-12-08 05:24:31 +00:00
|
|
|
*/
|
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
/*
|
|
|
|
* Support for deprecated functions goes here - static linkage will only
|
|
|
|
* slurp this code if applications are using them directly.
|
|
|
|
*/
|
2002-12-08 05:24:31 +00:00
|
|
|
|
2016-01-05 04:00:33 +00:00
|
|
|
#include <openssl/opensslconf.h>
|
2016-01-31 18:08:23 +00:00
|
|
|
#if OPENSSL_API_COMPAT >= 0x00908000L
|
|
|
|
NON_EMPTY_TRANSLATION_UNIT
|
|
|
|
#else
|
2002-12-08 05:24:31 +00:00
|
|
|
|
2016-01-31 18:08:23 +00:00
|
|
|
# include <stdio.h>
|
|
|
|
# include <time.h>
|
|
|
|
# include "internal/cryptlib.h"
|
|
|
|
# include "bn_lcl.h"
|
2003-10-29 04:06:50 +00:00
|
|
|
|
2002-12-08 05:24:31 +00:00
|
|
|
BIGNUM *BN_generate_prime(BIGNUM *ret, int bits, int safe,
|
2015-01-22 03:40:55 +00:00
|
|
|
const BIGNUM *add, const BIGNUM *rem,
|
|
|
|
void (*callback) (int, int, void *), void *cb_arg)
|
|
|
|
{
|
|
|
|
BN_GENCB cb;
|
|
|
|
BIGNUM *rnd = NULL;
|
2002-12-08 05:24:31 +00:00
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
BN_GENCB_set_old(&cb, callback, cb_arg);
|
2002-12-08 05:24:31 +00:00
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
if (ret == NULL) {
|
|
|
|
if ((rnd = BN_new()) == NULL)
|
|
|
|
goto err;
|
|
|
|
} else
|
|
|
|
rnd = ret;
|
|
|
|
if (!BN_generate_prime_ex(rnd, bits, safe, add, rem, &cb))
|
|
|
|
goto err;
|
2002-12-08 05:24:31 +00:00
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
/* we have a prime :-) */
|
2019-01-23 11:10:11 +00:00
|
|
|
return rnd;
|
2015-01-22 03:40:55 +00:00
|
|
|
err:
|
2015-05-01 01:37:06 +00:00
|
|
|
BN_free(rnd);
|
|
|
|
return NULL;
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
2002-12-08 05:24:31 +00:00
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
int BN_is_prime(const BIGNUM *a, int checks,
|
|
|
|
void (*callback) (int, int, void *), BN_CTX *ctx_passed,
|
|
|
|
void *cb_arg)
|
|
|
|
{
|
|
|
|
BN_GENCB cb;
|
|
|
|
BN_GENCB_set_old(&cb, callback, cb_arg);
|
|
|
|
return BN_is_prime_ex(a, checks, ctx_passed, &cb);
|
|
|
|
}
|
2002-12-08 05:24:31 +00:00
|
|
|
|
|
|
|
int BN_is_prime_fasttest(const BIGNUM *a, int checks,
|
2015-01-22 03:40:55 +00:00
|
|
|
void (*callback) (int, int, void *),
|
|
|
|
BN_CTX *ctx_passed, void *cb_arg,
|
|
|
|
int do_trial_division)
|
|
|
|
{
|
|
|
|
BN_GENCB cb;
|
|
|
|
BN_GENCB_set_old(&cb, callback, cb_arg);
|
|
|
|
return BN_is_prime_fasttest_ex(a, checks, ctx_passed,
|
|
|
|
do_trial_division, &cb);
|
|
|
|
}
|
2003-10-29 04:06:50 +00:00
|
|
|
#endif
|