2016-05-18 02:51:04 +08:00
|
|
|
/*
|
2021-06-17 20:24:59 +08:00
|
|
|
* Copyright 2002-2021 The OpenSSL Project Authors. All Rights Reserved.
|
2002-12-08 13:24:31 +08:00
|
|
|
*
|
2018-12-06 20:22:12 +08:00
|
|
|
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
2016-05-18 02:51:04 +08:00
|
|
|
* 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 13:24:31 +08:00
|
|
|
*/
|
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
/*
|
|
|
|
* Support for deprecated functions goes here - static linkage will only
|
|
|
|
* slurp this code if applications are using them directly.
|
|
|
|
*/
|
2002-12-08 13:24:31 +08:00
|
|
|
|
2016-01-05 12:00:33 +08:00
|
|
|
#include <openssl/opensslconf.h>
|
2002-12-08 13:24:31 +08:00
|
|
|
|
2020-03-06 01:50:31 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include "internal/cryptlib.h"
|
|
|
|
#include "bn_local.h"
|
2003-10-29 12:06:50 +08:00
|
|
|
|
2002-12-08 13:24:31 +08:00
|
|
|
BIGNUM *BN_generate_prime(BIGNUM *ret, int bits, int safe,
|
2015-01-22 11:40:55 +08:00
|
|
|
const BIGNUM *add, const BIGNUM *rem,
|
|
|
|
void (*callback) (int, int, void *), void *cb_arg)
|
|
|
|
{
|
|
|
|
BN_GENCB cb;
|
|
|
|
BIGNUM *rnd = NULL;
|
2002-12-08 13:24:31 +08:00
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
BN_GENCB_set_old(&cb, callback, cb_arg);
|
2002-12-08 13:24:31 +08:00
|
|
|
|
2015-01-22 11:40:55 +08: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 13:24:31 +08:00
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
/* we have a prime :-) */
|
2019-01-23 19:10:11 +08:00
|
|
|
return rnd;
|
2015-01-22 11:40:55 +08:00
|
|
|
err:
|
2015-05-01 09:37:06 +08:00
|
|
|
BN_free(rnd);
|
|
|
|
return NULL;
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
2002-12-08 13:24:31 +08:00
|
|
|
|
2015-01-22 11:40:55 +08: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);
|
2021-05-25 08:31:05 +08:00
|
|
|
return ossl_bn_check_prime(a, checks, ctx_passed, 0, &cb);
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
2002-12-08 13:24:31 +08:00
|
|
|
|
|
|
|
int BN_is_prime_fasttest(const BIGNUM *a, int checks,
|
2015-01-22 11:40:55 +08: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);
|
2021-05-25 08:31:05 +08:00
|
|
|
return ossl_bn_check_prime(a, checks, ctx_passed, do_trial_division, &cb);
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|