~ubuntu-branches/ubuntu/maverick/openssl/maverick

« back to all changes in this revision

Viewing changes to crypto/dsa/dsatest.c

  • Committer: Bazaar Package Importer
  • Author(s): Kurt Roeckx
  • Date: 2005-12-13 21:37:42 UTC
  • mto: (11.1.1 lenny)
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20051213213742-d0ydaylf80l16bj1
Tags: upstream-0.9.8a
ImportĀ upstreamĀ versionĀ 0.9.8a

Show diffs side-by-side

added added

removed removed

Lines of Context:
56
56
 * [including the GNU Public Licence.]
57
57
 */
58
58
 
 
59
/* Until the key-gen callbacks are modified to use newer prototypes, we allow
 
60
 * deprecated functions for openssl-internal code */
 
61
#ifdef OPENSSL_NO_DEPRECATED
 
62
#undef OPENSSL_NO_DEPRECATED
 
63
#endif
 
64
 
59
65
#include <stdio.h>
60
66
#include <stdlib.h>
61
67
#include <string.h>
68
74
#include <openssl/rand.h>
69
75
#include <openssl/bio.h>
70
76
#include <openssl/err.h>
 
77
#include <openssl/bn.h>
71
78
 
72
79
#ifdef OPENSSL_NO_DSA
73
80
int main(int argc, char *argv[])
84
91
#define MS_CALLBACK
85
92
#endif
86
93
 
87
 
static void MS_CALLBACK dsa_cb(int p, int n, void *arg);
 
94
static int MS_CALLBACK dsa_cb(int p, int n, BN_GENCB *arg);
88
95
 
89
96
/* seed, out_p, out_q, out_g are taken from the updated Appendix 5 to
90
97
 * FIPS PUB 186 and also appear in Appendix 5 to FIPS PIB 186-1 */
129
136
 
130
137
int main(int argc, char **argv)
131
138
        {
 
139
        BN_GENCB cb;
132
140
        DSA *dsa=NULL;
133
141
        int counter,ret=0,i,j;
134
142
        unsigned char buf[256];
148
156
 
149
157
        BIO_printf(bio_err,"test generation of DSA parameters\n");
150
158
 
151
 
        dsa=DSA_generate_parameters(512,seed,20,&counter,&h,dsa_cb,bio_err);
 
159
        BN_GENCB_set(&cb, dsa_cb, bio_err);
 
160
        if(((dsa = DSA_new()) == NULL) || !DSA_generate_parameters_ex(dsa, 512,
 
161
                                seed, 20, &counter, &h, &cb))
 
162
                goto end;
152
163
 
153
164
        BIO_printf(bio_err,"seed\n");
154
165
        for (i=0; i<20; i+=4)
156
167
                BIO_printf(bio_err,"%02X%02X%02X%02X ",
157
168
                        seed[i],seed[i+1],seed[i+2],seed[i+3]);
158
169
                }
159
 
        BIO_printf(bio_err,"\ncounter=%d h=%d\n",counter,h);
 
170
        BIO_printf(bio_err,"\ncounter=%d h=%ld\n",counter,h);
160
171
                
161
172
        if (dsa == NULL) goto end;
162
173
        DSA_print(bio_err,dsa,0);
194
205
                BIO_printf(bio_err,"g value is wrong\n");
195
206
                goto end;
196
207
                }
197
 
        DSA_generate_key(dsa);
198
 
        DSA_sign(0, str1, 20, sig, &siglen, dsa);
199
 
        if (DSA_verify(0, str1, 20, sig, siglen, dsa) == 1)
200
 
                ret=1;
 
208
 
 
209
        dsa->flags |= DSA_FLAG_NO_EXP_CONSTTIME;
 
210
        DSA_generate_key(dsa);
 
211
        DSA_sign(0, str1, 20, sig, &siglen, dsa);
 
212
        if (DSA_verify(0, str1, 20, sig, siglen, dsa) == 1)
 
213
                ret=1;
 
214
 
 
215
        dsa->flags &= ~DSA_FLAG_NO_EXP_CONSTTIME;
 
216
        DSA_generate_key(dsa);
 
217
        DSA_sign(0, str1, 20, sig, &siglen, dsa);
 
218
        if (DSA_verify(0, str1, 20, sig, siglen, dsa) == 1)
 
219
                ret=1;
 
220
 
201
221
end:
202
222
        if (!ret)
203
223
                ERR_print_errors(bio_err);
211
231
                BIO_free(bio_err);
212
232
                bio_err = NULL;
213
233
                }
 
234
#ifdef OPENSSL_SYS_NETWARE
 
235
    if (!ret) printf("ERROR\n");
 
236
#endif
214
237
        EXIT(!ret);
215
238
        return(0);
216
239
        }
217
240
 
218
 
static int cb_exit(int ec)
219
 
        {
220
 
        EXIT(ec);
221
 
        return(0);              /* To keep some compilers quiet */
222
 
        }
223
 
 
224
 
static void MS_CALLBACK dsa_cb(int p, int n, void *arg)
 
241
static int MS_CALLBACK dsa_cb(int p, int n, BN_GENCB *arg)
225
242
        {
226
243
        char c='*';
227
244
        static int ok=0,num=0;
230
247
        if (p == 1) c='+';
231
248
        if (p == 2) { c='*'; ok++; }
232
249
        if (p == 3) c='\n';
233
 
        BIO_write(arg,&c,1);
234
 
        (void)BIO_flush(arg);
 
250
        BIO_write(arg->arg,&c,1);
 
251
        (void)BIO_flush(arg->arg);
235
252
 
236
253
        if (!ok && (p == 0) && (num > 1))
237
254
                {
238
255
                BIO_printf((BIO *)arg,"error in dsatest\n");
239
 
                cb_exit(1);
 
256
                return 0;
240
257
                }
 
258
        return 1;
241
259
        }
242
260
#endif