1160814Ssimon/* crypto/bn/bn_depr.c */
2160814Ssimon/* ====================================================================
3160814Ssimon * Copyright (c) 1998-2002 The OpenSSL Project.  All rights reserved.
4160814Ssimon *
5160814Ssimon * Redistribution and use in source and binary forms, with or without
6160814Ssimon * modification, are permitted provided that the following conditions
7160814Ssimon * are met:
8160814Ssimon *
9160814Ssimon * 1. Redistributions of source code must retain the above copyright
10280304Sjkim *    notice, this list of conditions and the following disclaimer.
11160814Ssimon *
12160814Ssimon * 2. Redistributions in binary form must reproduce the above copyright
13160814Ssimon *    notice, this list of conditions and the following disclaimer in
14160814Ssimon *    the documentation and/or other materials provided with the
15160814Ssimon *    distribution.
16160814Ssimon *
17160814Ssimon * 3. All advertising materials mentioning features or use of this
18160814Ssimon *    software must display the following acknowledgment:
19160814Ssimon *    "This product includes software developed by the OpenSSL Project
20160814Ssimon *    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
21160814Ssimon *
22160814Ssimon * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23160814Ssimon *    endorse or promote products derived from this software without
24160814Ssimon *    prior written permission. For written permission, please contact
25160814Ssimon *    openssl-core@openssl.org.
26160814Ssimon *
27160814Ssimon * 5. Products derived from this software may not be called "OpenSSL"
28160814Ssimon *    nor may "OpenSSL" appear in their names without prior written
29160814Ssimon *    permission of the OpenSSL Project.
30160814Ssimon *
31160814Ssimon * 6. Redistributions of any form whatsoever must retain the following
32160814Ssimon *    acknowledgment:
33160814Ssimon *    "This product includes software developed by the OpenSSL Project
34160814Ssimon *    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
35160814Ssimon *
36160814Ssimon * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37160814Ssimon * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38160814Ssimon * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39160814Ssimon * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
40160814Ssimon * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41160814Ssimon * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42160814Ssimon * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43160814Ssimon * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44160814Ssimon * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45160814Ssimon * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46160814Ssimon * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47160814Ssimon * OF THE POSSIBILITY OF SUCH DAMAGE.
48160814Ssimon * ====================================================================
49160814Ssimon *
50160814Ssimon * This product includes cryptographic software written by Eric Young
51160814Ssimon * (eay@cryptsoft.com).  This product includes software written by Tim
52160814Ssimon * Hudson (tjh@cryptsoft.com).
53160814Ssimon *
54160814Ssimon */
55160814Ssimon
56280304Sjkim/*
57280304Sjkim * Support for deprecated functions goes here - static linkage will only
58280304Sjkim * slurp this code if applications are using them directly.
59280304Sjkim */
60160814Ssimon
61160814Ssimon#include <stdio.h>
62160814Ssimon#include <time.h>
63160814Ssimon#include "cryptlib.h"
64160814Ssimon#include "bn_lcl.h"
65160814Ssimon#include <openssl/rand.h>
66160814Ssimon
67280304Sjkimstatic void *dummy = &dummy;
68160814Ssimon
69160814Ssimon#ifndef OPENSSL_NO_DEPRECATED
70160814SsimonBIGNUM *BN_generate_prime(BIGNUM *ret, int bits, int safe,
71280304Sjkim                          const BIGNUM *add, const BIGNUM *rem,
72280304Sjkim                          void (*callback) (int, int, void *), void *cb_arg)
73280304Sjkim{
74280304Sjkim    BN_GENCB cb;
75280304Sjkim    BIGNUM *rnd = NULL;
76280304Sjkim    int found = 0;
77160814Ssimon
78280304Sjkim    BN_GENCB_set_old(&cb, callback, cb_arg);
79160814Ssimon
80280304Sjkim    if (ret == NULL) {
81280304Sjkim        if ((rnd = BN_new()) == NULL)
82280304Sjkim            goto err;
83280304Sjkim    } else
84280304Sjkim        rnd = ret;
85280304Sjkim    if (!BN_generate_prime_ex(rnd, bits, safe, add, rem, &cb))
86280304Sjkim        goto err;
87160814Ssimon
88280304Sjkim    /* we have a prime :-) */
89280304Sjkim    found = 1;
90280304Sjkim err:
91280304Sjkim    if (!found && (ret == NULL) && (rnd != NULL))
92280304Sjkim        BN_free(rnd);
93280304Sjkim    return (found ? rnd : NULL);
94280304Sjkim}
95160814Ssimon
96280304Sjkimint BN_is_prime(const BIGNUM *a, int checks,
97280304Sjkim                void (*callback) (int, int, void *), BN_CTX *ctx_passed,
98280304Sjkim                void *cb_arg)
99280304Sjkim{
100280304Sjkim    BN_GENCB cb;
101280304Sjkim    BN_GENCB_set_old(&cb, callback, cb_arg);
102280304Sjkim    return BN_is_prime_ex(a, checks, ctx_passed, &cb);
103280304Sjkim}
104160814Ssimon
105160814Ssimonint BN_is_prime_fasttest(const BIGNUM *a, int checks,
106280304Sjkim                         void (*callback) (int, int, void *),
107280304Sjkim                         BN_CTX *ctx_passed, void *cb_arg,
108280304Sjkim                         int do_trial_division)
109280304Sjkim{
110280304Sjkim    BN_GENCB cb;
111280304Sjkim    BN_GENCB_set_old(&cb, callback, cb_arg);
112280304Sjkim    return BN_is_prime_fasttest_ex(a, checks, ctx_passed,
113280304Sjkim                                   do_trial_division, &cb);
114280304Sjkim}
115160814Ssimon#endif
116